#!/usr/bin/perl 

# Request comes from dailyopd.html 

require "read.cgi";
require "dbconnect.cgi"; 
require "dbfinish.cgi"; 

&Read_Split;

use DBI ;

&DbConnect; 

print "content-type:text/html" ;
print "\n\n\n";  

if($dbh) {   


#$sth = $dbh->prepare("select * from DailyOPD where  Shift='M'  and ODate = curdate()") or die "Can't prepare statement:  $dbh-errstr\n";
$sth = $dbh->prepare("select * from DailyOPD where  Shift='M'  and ODate = (select max(ODate) from DailyOPD)")  or die "Can't prepare statement:  $dbh-errstr\n"; 

$rv = $sth->execute or die "Can't execute the query : $sth->errstr \n.";  
$i=0; 
while(@am  = $sth->fetchrow_array ) 
{
    	 $j=0;
	 foreach $rcd (@am)
	 {
	  $rowam[$i][$j] = $rcd ;
	  $j += 1;
	 }
	 $i += 1;
	  
	 $acount =$i;
}

#$sth = $dbh->prepare("select * from DailyOPD where  Shift='A'  and ODate = curdate()") or die "Can't prepare statement:  $dbh-errstr\n";

$sth = $dbh->prepare("select * from DailyOPD where  Shift='A'  and ODate = (select max(ODate) from DailyOPD)") or die "Can't prepare statement:  $dbh-errstr\n";
$rv = $sth->execute or die "Can't execute the query : $sth->errstr \n."; 
$i=0;    
while(@pm  = $sth->fetchrow_array )  
{
 	$j=0;
	foreach $rcd (@pm)
	{
	 $rowpm[$i][$j] = $rcd ; 
	 $j += 1; 
	}
	 $i += 1;  
	  $pcount =$i; 
}




$sth = $dbh->prepare(" select dayofmonth(ODate),monthname(ODate),year(ODate) from DailyOPD where ODate=\"$rowam[0][0]\" ") or die "Can't prepare  statement:  $dbh-errstr\n"; 

$rv = $sth->execute or die "Can't execute the query : $sth->errstr \n."; 

@tdate = $sth->fetchrow_array;


}


print ("  <html>    ");
print ("  <head>  ");
print ("  <title>Doctor's duties</title>  ");
print (" </head>    ");
print ("  <body >  ");
print ("  <center>  ");
print ("  <table border=\"0\" width=\"60%\" cellpadding=\"3\" cellspacing=\"4\" height=\"678\">    ");
#print ("  <tr>      ");
#print ("  <td width=\"100%\" height=\"145\" valign=\"top\"> ");
#print ("  <div align=\"center\">");
#print ("  <center> ");
#print ("  <table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"605\">");
#print ("  <tr>");
#print ("  <td 35%\" valign=\"top\" width=\"170\">");
#print ("   <p align=\"center\">");
#print ("   <img border=\"0\" src=\"iitlogofin.jpg\"  100\" height=\"94\" align=\"left\"></p>");
#print ("   </td>");
#print ("   <center>");
#print ("       <td width=\"423\"><b><font color=\"#800000\" face=\"Times New Roman\" size=\"5\">IIT  Hospital</font></b>");
#print ("         <p><font color=\"#000080\"><b>Indian Institute of Technology, Bombay</b></font></p>");
#print ("         <p><font color=\"#000080\">Powai , Mumbai -400 076.</font></p>");
#print ("       </td>");
#print ("      </tr>");
#print ("  </table>");
#print ("     </center>");
#print ("     </div>");
#print ("   </center>");
#print ("  </td>");
#print ("  </tr>");
print ("   <tr>      ");
print ("   <td  valign=\"top\" height=\"513\">       ");
print ("    <center>");
print ("    <table border=\"1\"  cellspacing=\"0\" cellpadding=\"0\" width=\"597\" height=\"532\"> ");
print ("   <tr>              ");
print ("   <td  bgcolor=\"#004080\" height=\"25\" width=\"599\">                ");
print ("   <div align=\"center\">");
print ("     <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"30\">");
print ("       <tr>");
print ("         <td width=\"50%\" height=\"30\">&nbsp;<b><font color=\"#FFFFFF\">Daily OPD Schedule</font></b></td>");
print ("                </center>");
print ("   </center>");
print ("   <td width=\"50%\" height=\"30\">");
print ("     <p align=\"right\"><b><font color=\"#FFFFFF\"> Date:&nbsp;</font> <font
color=\"#FFFFFF\">$tdate[0]&nbsp;$tdate[1]&nbsp;$tdate[2]</font></b>&nbsp;</td>");
print ("   </tr>");
print ("   </table>");
print ("   </div>");
print ("   </td> </tr> ");
print ("    <center>  ");
print ("    <center>");
print ("   <tr>              ");
print ("   <td  bgcolor=\"#FFFFFF\" height=\"37\" valign=\"middle\" width=\"599\">                ");
print ("   <b><u><font color=\"#000080\" face=\"Arial\">&nbsp;</font><font color=\"#800000\" face=\"Arial\">Morning Shift</font></u><font color=\"#800000\" face=\"Arial\"><u>");
print ("   </u>:</font></b>");
print ("   </td> </tr> ");
print ("   <tr>             ");
print ("    <td  bgcolor=\"#FFFFDD\" height=\"120\" width=\"599\">");
print ("    ");
print ("       <table border=\"1\" cellpadding=\"2\" width=\"598\" >");
print ("         <tr>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"261\" ><b><font color=\"#000080\">Doctor's");
print ("             Name</font></b></td>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"152\" ><font color=\"#000080\"><b>Time From</b></font></td>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"157\" ><font color=\"#000080\"><b>Time To&nbsp;</b></font></td>");
print ("         </tr>");

$i=0;
while ( $acount > 0)
{

print ("         <tr>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"261\" >&nbsp;$rowam[$i][1]</td>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"152\" >&nbsp;$rowam[$i][3]&nbsp;AM</td>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"157\" >&nbsp;$rowam[$i][4]&nbsp;PM</td>");
print ("         </tr>");

$i += 1; 
$acount -= 1;

}

print ("       </table>");
print ("     ");
print ("    </td> ");
print ("      </tr>           ");
print ("   <tr>             ");
print ("    <td  bgcolor=\"#FFFFFF\" height=\"37\" width=\"599\">");
print ("    ");
print ("         <b>");
print ("         <u><font face=\"Arial\" color=\"#800000\">");
print ("    ");
print ("       &nbsp;Afternoon Shift </font></u><font face=\"Arial\" color=\"#800000\">:</font></b>");
print ("     ");
print ("    </td> ");
print ("      </tr>           ");
print ("   <tr>             ");
print ("    <td bgcolor=\"#FFFFDD\" height=\"99\" width=\"599\">");
print ("    ");
print ("       <table border=\"1\" cellpadding=\"2\"  width=\"599\">");
print ("         <tr>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"260\" ><b><font color=\"#000080\">Doctor's");
print ("             Name</font></b></td>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"154\" ><font color=\"#000080\"><b>Time From</b></font></td>");
print ("           <td bgcolor=\"#D5CBA8\" width=\"157\" ><font color=\"#000080\"><b>Time To&nbsp;</b></font></td>");
print ("         </tr>");

$i=0;
while ( $pcount > 0)
{

print ("         <tr>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"260\" >&nbsp;$rowpm[$i][1]</td>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"154\" >&nbsp;$rowpm[$i][3]&nbsp; PM</td>");
print ("           <td bgcolor=\"#FFFFDD\" width=\"157\" >&nbsp;$rowpm[$i][4]&nbsp;PM</td>");
print ("         </tr>");

$i += 1;
$pcount -= 1;
}

print ("       </table>");
print ("     ");
print (" ");
print ("     ");
print ("    </td> ");
print ("      </tr>           ");
print ("   <tr>");
print ("   <td bgcolor=\"#D5CBA8\" height=\"19\" width=\"599\">                ");
print ("   <p align=\"left\"><b><font color=\"#000080\">&nbsp;Doctors on Leave&nbsp;</font></b></td> ");
print ("   </tr>");
print ("   <tr>");
print ("   <td bgcolor=\"#FFFFDD\" height=\"19\" width=\"599\">                ");
print ("   <p align=\"left\">$rowam[0][6]</p></td>");
print ("   </tr>");
print ("   <tr>");
print ("   <td bgcolor=\"#D5CBA8\" height=\"19\" width=\"599\">                ");
print ("   <p align=\"left\"><b><font color=\"#000080\">&nbsp;Comments</font></b></td> ");
print ("   </tr>");
print ("   <tr>");
print ("    <td  height=\"80\" bgcolor=\"#FFFFDD\" width=\"599\" >");
print ("     <p align=\"center\">&nbsp;$rowam[0][5]</p>");
print ("    </td> ");
print ("   </tr>");
print ("           </table>               </center>");
#print ("  <br> <a href=\"http://www.iitb.ac.in/hospital/index.html\">Homepage </a> | "); 
#print (" <a href=\"http://webform.cc.iitb.ac.in/DailySchedule\">Daily OPD Schedule </a>| ");
#print (" <a href=\"http://www.iitb.ac.in/hospital/webform/monthlyschedule.cgi\">Monthly Schedule </a> | "); 
#print (" <a href=\"http://www.iitb.ac.in/hospital/departments.html\">Hospital Departments</a> | "); 
#print (" <a href=\"http://www.iitb.ac.in/hospital/doctors.html\">Doctors</a> | "); 
#print (" <br><a href=\"http://www.iitb.ac.in/hospital/specialists.html\">Specialists</a> |");
#print (" <a href=\"http://www.iitb.ac.in/hospital/specialclinics.html\">Special Clinics</a>| "); 
#print (" <a href=\"http://www.iitb.ac.in/hospital/vaccinations.html\">Vaccinations</a> | "); 
#print (" <a href=\"http://www.iitb.ac.in/hospital/otherinfo.html\">Other Info</a> |"); 
#print (" <a href=\"http://www.iitb.ac.in/hospital/recognisedhospitals.html\">Recognized Hospitals</a> "); 
#print ("       ");
print ("   </center> </td></tr> </table>  ");
print ("   ");
print ("       </body>    </html> ");

 &DbFinish;    
