if ($dept == "") {
    $dept = "plast";
}
if ($pmonth == "") {
    $pmonth = date('n');
}
if ($pyear == "") {
    $pyear = date('Y');
}
$thisfile = basename($_SERVER['PHP_SELF']);
require_once $root_path . 'include/care_api_classes/class_department.php';
$dept_obj = new Department();
$dept_obj->preloadDept($dept_nr);
require_once $root_path . 'include/care_api_classes/class_personell.php';
$pers_obj = new Personell();
$dutyplan =& $pers_obj->getDOCDutyplan($dept_nr, $pyear, $pmonth);
$firstday = date("w", mktime(0, 0, 0, $pmonth, 1, $pyear));
$maxdays = date("t", mktime(0, 0, 0, $pmonth, 1, $pyear));
switch ($retpath) {
    case "menu":
        $rettarget = 'doctors.php' . URL_APPEND;
        break;
    case "qview":
        $rettarget = 'doctors-dienst-schnellsicht.php' . URL_APPEND . '&hilitedept=' . $dept_nr;
        break;
    default:
        $rettarget = "javascript:window.history.back()";
}
# Prepare page title
$sTitle = "{$LDDoctors}::{$LDDutyPlan}::";
$LDvar = $dept_obj->LDvar();
 //echo $ward_obj->LastRecordCount();
 $ward_ok = true;
 # Create the waiting inpatients' list
 $wnr = isset($w_waitlist) && $w_waitlist ? 0 : $ward_nr;
 $waitlist = $ward_obj->createWaitingInpatientList($wnr);
 $waitlist_count = $ward_obj->LastRecordCount();
 # Get the doctor's on duty information
 #### Start of routine to fetch doctors on duty
 $elem = 'duty_1_pnr';
 if (SHOW_DOC_2) {
     $elem .= ',duty_2_pnr';
 }
 # Create personnel object
 include_once $root_path . 'include/care_api_classes/class_personell.php';
 $pers_obj = new Personell();
 if ($result = $pers_obj->getDOCDutyplan($ward_info['dept_nr'], $pyear, $pmonth, $elem)) {
     $duty1 =& unserialize($result['duty_1_pnr']);
     if (SHOW_DOC_2) {
         $duty2 =& unserialize($result['duty_2_pnr']);
     }
     //echo $sql."<br>";
 }
 //echo $sql;
 # Adjust the day index
 $offset_day = $pday - 1;
 # Consider the early morning hours to belong to the past day
 if (date('H.i') < DOC_CHANGE_TIME) {
     $offset_day--;
 }
 if ($pnr1 = $duty1['ha' . $offset_day]) {
     $person1 =& $pers_obj->getPersonellInfo($pnr1);
 # Create the waiting outpatients� list
 $dnr = isset($w_waitlist) && $w_waitlist ? 0 : $dept_nr;
 //echo '<p>'.$enc_obj->getLastQuery();
 $waitlist =& $enc_obj->createWaitingOutpatientList($dnr);
 $waitlist_count = $enc_obj->LastRecordCount();
 //echo $waitlist_count.'<p>'.$enc_obj->getLastQuery();
 # Get the doctor�s on duty information
 #### Start of routine to fetch doctors on duty
 $elem = 'duty_1_pnr';
 if (SHOW_DOC_2) {
     $elem .= ',duty_2_pnr';
 }
 # Create personnel object
 include_once $root_path . 'include/care_api_classes/class_personell.php';
 $pers_obj = new Personell();
 if ($result = $pers_obj->getDOCDutyplan($dept_nr, $pyear, $pmonth, $elem)) {
     $duty1 =& unserialize($result['duty_1_pnr']);
     if (SHOW_DOC_2) {
         $duty2 =& unserialize($result['duty_2_pnr']);
     }
     //echo $sql."<br>";
 }
 //echo $pers_obj->getLastQuery();
 # Adjust the day index. This is necessary since change of duty usually happens early morning  not midnight
 $offset_day = $pday - 1;
 # Consider the early morning hours to belong to the past day
 if (date('H.i') < DOC_CHANGE_TIME) {
     $offset_day--;
 }
 if ($pnr1 = $duty1['ha' . $offset_day]) {
     $person1 =& $pers_obj->getPersonellInfo($pnr1);
    /*	echo '<tr>
    	<td colspan=6><font face="verdana,arial" size=2> <img '.createComIcon($root_path,'warn.gif','0').'> <font color=red>'.$LDCachedInfo.'</font> <a href="'.$thisfile.URL_APPEND.'&force_no_cache=1&retpath='.$retpath.'">'.$LDClkNoCache.'</a>
    	</td>
    	</tr>';
    */
    $cached_plan = str_replace('URLAPPEND', URL_APPEND, $cached_plan);
    $cached_plan = str_replace('IMGALT', $LDShowActualPlan, $cached_plan);
    $cached_plan = str_replace('SHOWBUTTON', $LDShow, $cached_plan);
    echo str_replace('URLREDIRECTAPPEND', URL_REDIRECT_APPEND, $cached_plan);
} else {
    $toggler = 0;
    # Start generating the DOC list
    $temp_out = '';
    while (list($x, $v) = each($dept_DOC)) {
        if (in_array($v['nr'], $quicklist)) {
            if ($dutyplan = $pers_obj->getDOCDutyplan($v['nr'], $pyear, $pmonth)) {
                $a = unserialize($dutyplan['duty_1_txt']);
                $r = unserialize($dutyplan['duty_2_txt']);
                $s = unserialize($dutyplan['duty_3_txt']);
                $ha = unserialize($dutyplan['duty_1_pnr']);
                $hr = unserialize($dutyplan['duty_2_pnr']);
                $hs = unserialize($dutyplan['duty_3_pnr']);
                if ($ha['ha' . ($plan_day - 1)]) {
                    $DOC_1 = $pers_obj->getPersonellInfo($ha['ha' . ($plan_day - 1)]);
                }
                if ($hr['hr' . ($plan_day - 1)]) {
                    $DOC_2 = $pers_obj->getPersonellInfo($hr['hr' . ($plan_day - 1)]);
                }
                if ($hs['hs' . ($plan_day - 1)]) {
                    $DOC_3 = $pers_obj->getPersonellInfo($hs['hs' . ($plan_day - 1)]);
                }