<?php
/*=======================================================================
 *
 * task.php
 *
 * Autor: Marc Vollmann
 * 
 =======================================================================*/

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_filters.inc.php");
include_once ('../include/email/htmlMimeMail.php');


// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
authCheckEmployeeRights($emp_id, "0", "1");
authCheckEmployeeRights($emp_id, "11", "1");

getSecHttpVars("1", array("f_act", "viewMode", "selYear", "selMonth", "selDay",
                          "f_text", "f_hour", "f_minute", "f_hour_to", "f_minute_to", 
                          "f_apIdToRemove", "f_apIdToUpdate", "f_usr_id", "f_selUsrId", 
                          "f_hq_id", "g_cs_eid", "f_sendmail"));
getSecHttpVars("1", array("f_text_" . $f_apIdToUpdate));


// Initialisations
if ($selYear == "") : $selYear = date("Y"); endif;
if ($selMonth == "") : $selMonth = date("m"); endif;
if ($selDay == "") : $selDay = date("d"); endif;
if ($viewMode == "") : $viewMode = "1"; endif;       // Only the selected day (= 1), the selected week (= 2)

// Definiton of global parameters
include_once ("../include/inc_calendar.inc.php");


// Current number of headquarters of the mandator
$numOfHq = getCountOfTable("mandatorheadquarters", "md_id = '" . $md_id . "'");

// Mandator filter
if ($f_hq_id == "") : $f_hq_id = array(); endif;
if (count($f_hq_id) == 0) : array_push($f_hq_id, $hq_id); endif;

$f_text = trim($f_text);
$g_cs_eid = trim($g_cs_eid);
if ($f_selUsrId == "") : $f_selUsrId = $usr_id; endif;

// Flag email to participants
if ($f_sendmail == "" || count($f_sendmail) == 0) :
   $f_sendmail = "0";
else: 
   $f_sendmail = "1";
endif;

// Functions

// Prints the headline with the current day
// $selYear   : Selected year
// $selMonth  : Selected month
// $selDay  : Selected day
// $cellCol   : Colour of the cell
function printAppointmentCurrentDayHeader($selYear, $selMonth, $selDay, $cellCol = "77FF77") {
  global $calWeekDays,$calCurrentDayNumOfTheWeek, $calMonthNames;  
  global $calCurrentWeekNum, $calCurrentWeekName, $calCurrentDayNumOfTheYear;
  $out = "<tr>";	
  $out .= "<td align=\"left\" bgcolor=\"#" . $cellCol . "\"><b>";  
  $out .= $calWeekDays[$calCurrentDayNumOfTheWeek - 1] . ", ";           // Name of the week day             (E.g.: "Donnerstag")
  $out .= $selDay . ". " . $calMonthNames[$selMonth - 1] . " " . $selYear;   // Day, Name of the month and year  (E.g.: "29 Juni 2006")
  $out .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  $out .= $calCurrentWeekName . " " . $calCurrentWeekNum;                // calendar week                    (E.g.: "KW 26")
  $out .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  $out .= $calCurrentDayNumOfTheYear . ". Tag des Jahres";
  $out .= "</b></td>";
  $out .= "</tr>";
  return $out;
}

// Prints the title of the output table
// $cellCol   : Colour of the cell
function printAppointmentTitle($cellCol = "FFFFFF") {
  global $emp_id, $usr_id, $f_selUsrId, $f_hq_id;
  
  $out = "<tr>";	
  $out .= "<td width=\"50\" align=\"center\" bgcolor=\"#" . $cellCol . "\"><b>Beginn</b></td>";
  $out .= "<td width=\"50\" align=\"center\" bgcolor=\"#" . $cellCol . "\"><b>Ende</b></td>";
  $out .= "<td width=\"150\" align=\"left\" bgcolor=\"#" . $cellCol . "\"><b>Ersteller</b></td>";
  $out .= "<td width=\"150\" align=\"left\" bgcolor=\"#" . $cellCol . "\"><b>Teilnehmer</b></td>";
  $out .= "<td align=\"left\" bgcolor=\"#" . $cellCol . "\"><b>Beschreibung</b></td>";
  $out .= "<td width=\"200\" align=\"left\" bgcolor=\"#" . $cellCol . "\"><b>Kunde</b></td>";
  $out .= "<td width=\"80\" align=\"center\" bgcolor=\"#" . $cellCol . "\"><b>Aktion</b></td>";
  $out .= "</tr>";
  
  if (authCheckEmployeeRights($emp_id, "10")) :
     $out .= "<tr>";
     $out .= "<td width=\"50\" align=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "<td width=\"50\" align=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "<td width=\"150\" align=\"left\" bgcolor=\"#" . $cellCol . "\"><select name=\"f_selUsrId\" onChange=\"submit();\"><option value=\"all\">Alle</option>\n" . addOptionsFromTable("user","usr_id","CONCAT(usr_name,', ',usr_firstname)","usr_name","usr_type = '1' AND hq_id IN " . getSQLMandatorArray($f_hq_id),$f_selUsrId) . "</select></td>";
     $out .= "<td width=\"150\" align=\"left\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "<td align=\"left\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "<td width=\"200\" align=\"left\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "<td width=\"80\" align=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
     $out .= "</tr>";
  endif;
  return $out;
}

// Gets exactly the value of one specified field from the specified row by key of a certain table
function getAppointmentsFromDB($selYearFrom, $selMonthFrom, $selDayFrom, $selYearTo = "", $selMonthTo = "", $selDayTo = "", $csId = "") {
  global $db, $PHP_SELF;
  global $emp_id, $f_selUsrId, $f_hq_id;
  
  $retArray = array();
  $dayStringFrom = $selYearFrom . "-" . pad($selMonthFrom,2,"0") . "-" . pad($selDayFrom,2,"0");
  $dayStringTo = $selYearTo . "-" . pad($selMonthTo,2,"0") . "-" . pad($selDayTo,2,"0");
  if ($selYearTo == "" || $selYearTo == "" || $selYearTo == "") :
     $dayStringTo = $dayStringFrom;
  endif;

  // Filter to display appointments of other users
  $whereClauseCreatorFilter = " AND ap.usr_id = '" . $f_selUsrId . "'";  
  if (authCheckEmployeeRights($emp_id, "10") && $f_selUsrId == "all") :
     $whereClauseCreatorFilter = "";
  endif;
  
  $sqlStmt = "SELECT ap.ap_id, ap.ap_text, ap.ap_execdate, ap.ap_enddate,"
             . "     cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cs.cs_id, cs.cs_eid,"
             . "     ap.usr_id, usr.usr_firstname, usr.usr_name, ap.ap_participants"
             . " FROM phoenix_group.appointment AS ap" 
             . "      LEFT JOIN customer AS cs ON ap.cs_id = cs.cs_id"
             . "      LEFT JOIN company AS cmp ON cs.cmp_id = cmp.cmp_id"
             . "      LEFT JOIN user AS usr ON ap.usr_id = usr.usr_id"
             . " WHERE ap.ap_execdate >= ' " . $dayStringFrom . " 00:00:00' AND"
             . "       ap.ap_execdate <= ' " . $dayStringTo . " 23:59:59'"
             .         $whereClauseCreatorFilter . " AND"
             . "       ap.hq_id IN " . getSQLMandatorArray($f_hq_id) 
             . " ORDER BY ap.ap_execdate";
// echo $sqlStmt . "<br>";
  $result = $db->query($sqlStmt);
  if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $result->getMessage());
  while ($row = $result->fetch_assoc()):
        $retArray[] = array($row["ap_id"], $row["ap_text"], $row["ap_execdate"], $row["cmp_id"], $row["cmp_comp"], $row["cmp_comp2"], $row["cs_id"], $row["cs_eid"], $row["ap_enddate"], $row["usr_id"], $row["usr_firstname"], $row["usr_name"], $row["ap_participants"]);
  endwhile;
  $result->free();
  
  return $retArray;
}     

// Prints the headline with the current day
// $selYear  : Selected year
// $selMonth : Selected month
// $selDay   : Selected day
// $cellCol  : Colour of the cell
// $csId     : Special customer
function printAppointmentsOfOneDay($selYear, $selMonth, $selDay, $cellCol = "FFFFFF", $csId = "") {
  global $db, $PHP_SELF;
  global $f_apIdToUpdate;

  $apArray = getAppointmentsFromDB($selYear, $selMonth, $selDay);  
  $lenApArray = count($apArray);

  $out = "<tr>";
  for ($j = 0; $j < $lenApArray; $j++) :
      $tmpId = $apArray[$j][0];
      $tmpText = $apArray[$j][1];
      $tmpExecDate = substr($apArray[$j][2],11,5);
      $tmpCmpId = trim($apArray[$j][3]);
      $tmpCmpComp = trim($apArray[$j][4]);
      $tmpCmpComp2 = trim($apArray[$j][5]);
      $tmpCsId = $apArray[$j][6];
      $tmpCsEid = $apArray[$j][7];
      $tmpEndDate = substr($apArray[$j][8],11,5);
      $tmpUsrId = trim($apArray[$j][9]);
      $tmpUsrFirstname = trim($apArray[$j][10]);
      $tmpUsrName = trim($apArray[$j][11]);
      $tmpParticipants = trim($apArray[$j][12]);      

      // Dates (From, To)
      $out .= "<td width=\"50\" align=\"center\" valign=\"center\" bgcolor=\"#" . $cellCol . "\"><b>" . $tmpExecDate . "</b></td>";
      if ($tmpEndDate != "00:00") :
         $out .= "<td width=\"50\" align=\"center\" valign=\"center\" bgcolor=\"#" . $cellCol . "\"><b>" . $tmpEndDate . "</b></td>";
      else :
         $out .= "<td width=\"50\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
      endif;

      // User      
      if ($tmpUsrId != "") :
         $out .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpUsrFirstname . "<br>" . $tmpUsrName . "</td>";
      else :
         $out .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
      endif;
      
      // Participants
      $out .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">";
      if ($tmpParticipants != "") : 
         $tmpParticipants = spliti(",", $tmpParticipants);   // It has to be an array
         $tmpParticipantsLen = count($tmpParticipants);
         for ($k = 0; $k < $tmpParticipantsLen; $k++) :
             $participantName = $db->getOne("SELECT CONCAT(usr_name,', ',usr_firstname) AS name FROM user WHERE usr_id = '" . $tmpParticipants[$k] . "'");
             $out .= $participantName . "<br>";
         endfor;
      else :
         $out .= "&nbsp;";
      endif;
      $out .= "</td>";
      
      // Text (Edit, read only)
      if ($f_apIdToUpdate == $tmpId) :
         $out .= "<td align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\"><textarea name=\"f_text_" . $tmpId . "\" cols=\"50\" rows=\"5\">" . $tmpText . "</textarea></td>";
      else :
         $out .= "<td align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpText . "</td>";
      endif;
      
      // Potential customer relation (Company name and EID)
      if ($tmpCsId != "") :
         $out .= "<td width=\"200\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpCmpComp . "<br>" . ($tmpCmpComp2 != "" ? $tmpCmpComp2 . "<br>" : "") . $tmpCsEid . "<br>"
               . "<input type=\"button\" name=\"action\" value=\"Details\" onClick=\"openCustomerSpecial('" . $tmpCmpId . "');\">"
               . "<input type=\"button\" name=\"action\" value=\"Historie\" onClick=\"getCsHistory('" . $tmpCsEid . "');\">"
               . "<input type=\"button\" name=\"action\" value=\"Statistik\" onClick=\"openCustomerStatistics('" . $tmpCsEid . "');\">"
               . "</td>";
      else :
         $out .= "<td width=\"200\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
      endif;

      // Actions
      $out .= "<td width=\"80\" align=\"center\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">";
      if ($f_apIdToUpdate == $tmpId) :
         $out .= "<input type=\"button\" name=\"action\" value=\"Speichern\" onClick=\"updateAppointmentFinishPage('" . $tmpId . "');\">";
      else :
         $out .= "<input type=\"button\" name=\"action\" value=\"Bearbeiten\" onClick=\"updateAppointment('" . $tmpId . "');\">";
      endif;
      $out .= "<br>";
      $out .= "<input type=\"button\" name=\"action\" value=\"Entfernen\" onClick=\"removeAppointmentFinishPage('" . $tmpId . "');\">";      
      $out .= "</td>";
      if ($j < $lenApArray - 1) : $out .= "</tr><tr>"; endif;
  endfor;
  $out .= "</tr>";
  return $out;
}

// ***********
// * Actions *
// ***********

if ($f_act == "insertAppointment") :
   if ($f_text != "") :
      $currentTime = getDateTime("0");
      $execDatetime = getDateTime("format",array($f_hour,$f_minute,0,$selMonth,$selDay,$selYear),"Y-m-d H:i:s");
      $endDatetime = getDateTime("format",array($f_hour_to,$f_minute_to,0,$selMonth,$selDay,$selYear),"Y-m-d H:i:s");
      $csId = "";
      if ($g_cs_eid != "") :
         $csId = getFieldValueFromId("customer", "cs_eid", $g_cs_eid, "cs_id");
      endif;
      insertStmt("phoenix_group.appointment", array("usr_id", $usr_id, "hq_id", $hq_id, "ap_participants", implode(",", $f_usr_id), "ap_text", $f_text, 
                                                    "ap_execdate", $execDatetime, "ap_enddate", $endDatetime, 
                                                    "ap_modifytime", $currentTime, "cs_id", $csId, "csc_id", ""));
      $ap_id_new = getLastInsertId();
      
      // Send email to participants if requested
      if ($f_sendmail == "1" && $f_usr_id != "" && count($f_usr_id) > 0) :

         $mailAddresses = array();
         // Get email address of the creator of the appointment
         $fromEmailAddress = getFieldValueFromId("user", "usr_id", $usr_id, "usr_email");
         if (checkEmailFormat($fromEmailAddress)) : 
            array_push($mailAddresses, $fromEmailAddress);
         endif;
         // Get email addresses of the participants
         $lenTmp = count($f_usr_id);
         for ($i = 0; $i < $lenTmp; $i++) :
             $toEmailAddress = getFieldValueFromId("user", "usr_id", $f_usr_id[$i], "usr_email");
             if (checkEmailFormat($toEmailAddress)) :
                array_push($mailAddresses, $toEmailAddress);
             // else :
             //   $statusMessage .= "Nicht alle Empfänger haben eine gültige Emailadresse!";
             endif;
         endfor;
         $mailAddressesString = implode(",", $mailAddresses);
         
         $mailObj = new htmlMimeMail();
         $mailObj->setHtml($f_text, null, "./");

         $mailObj->setFrom($fromEmailAddress);
         // $mailObj->setCc($mailCcAddress);
         // $mailObj->setBcc($mailBccAddress);
         $mailObj->setSubject("Neuer Termin: " . $execDatetime);
         $mailResult = $mailObj->send(array($mailAddressesString), 'smtp');
         if (!$mailResult) :
            $statusMessage .= "Die Nachricht konnte nicht gesendet werden! ";
         endif;
         $mailObj = NULL;
      endif;
   else:
     $statusMessage = "Erfassen Sie bitte einen Text zum Termin!";
   endif;
endif;

if ($f_act == "removeAppointment") :
   if ($f_apIdToRemove != "") :
      deleteStmt("phoenix_group.appointment","ap_id = ".$f_apIdToRemove);
      $f_apIdToRemove = "";  // Reset ID
   else:
     $statusMessage = "Es wurde kein Termin zum Löschen selektiert!";
   endif;
endif;

if ($f_act == "updateAppointment") :
   if ($f_apIdToUpdate != "") :
      $f_text_update = ${"f_text_" . $f_apIdToUpdate};
      updateStmt("phoenix_group.appointment", "ap_id", $f_apIdToUpdate, array("usr_id", $usr_id, "ap_text", $f_text_update));
      $f_apIdToUpdate = "";  // Reset ID
   else:
     $statusMessage = "Eine Aktualisierung fand nicht statt!";
   endif;
endif;
?>


<html>
<head>
<title>Appointments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
var statusMessage = "<?php echo $statusMessage ?>";

function displayStatusMessage() {
 if (statusMessage != "") {
    alert(statusMessage);
 }
};

function finishPage() {
  document.forms[0].submit();
};

function removeAppointmentFinishPage(apIdToRemove) {
  if (confirm('Möchten Sie den Termin wirklich löschen?')) {
     document.forms[0].f_act.value='removeAppointment';
     document.forms[0].f_apIdToRemove.value=apIdToRemove;
     document.forms[0].submit();
  }
};

function insertAppointmentFinishPage() {
  // if (confirm('Möchten Sie den Termin wirklich einfügen?')) {
     document.forms[0].f_act.value='insertAppointment';
     document.forms[0].submit();
  // }
};

function updateAppointmentFinishPage(apIdToUpdate) {
	if (confirm('Änderungen wirklich speichern?')) {
     document.forms[0].f_act.value='updateAppointment';
     document.forms[0].f_apIdToUpdate.value=apIdToUpdate;
     document.forms[0].submit();
  }
}	

function updateAppointment(apIdToUpdate) {
     document.forms[0].f_apIdToUpdate.value=apIdToUpdate;
     document.forms[0].submit();
};

function searchCsCsc() {
  var f_act = 'search';
  
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act + "&generic=0000000000001",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearSpecialCustomer() {	
  document.forms[0].g_cs_eid.value='';
};

function hqCheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = true;
	}
}

function hqUncheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = false;
  }
}

function getCsHistory(gCsEid) {
	if (gCsEid == '') {
     gCsEid = document.forms[0].g_cs_eid.value;
  };
  if (gCsEid != '') {
     var widthPopupWin = 1024;
     var heightPopupWin = 768;
     var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
     var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
     var popupWin;
     popupWin = window.open("../groupware/cs_process.php?g_cs_eid=" + gCsEid,
       "","dependent=yes,width=" + widthPopupWin + ",height=" +
       heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
       ",scrollbars=yes");
  } else {
  	 alert('Wählen Sie bitte einen Kunden aus!');
  };
};

function openCustomerStatistics(gCsEid) {
	if (gCsEid == '') {
     gCsEid = document.forms[0].g_cs_eid.value;
  };
  if (gCsEid != '') {
  	 // Current date
     var now = new Date();
     var currentDay = now.getDate();
     var currentMonth = now.getMonth();
     var currentYear = now.getFullYear();  	
  	 // Popup
     var widthPopupWin = 900;
     var heightPopupWin = 700;
     var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
     var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
     var popupWin;
     popupWin = window.open("../statistic/statistic.php?f_act=calculate&f_category=3&f_statistic=61&g_cs_eid=" + gCsEid + "&day_from=01&month_from=01&year_from=2004&day_to=" + currentDay + "&month_to=" + currentMonth + "&year_to=" + currentYear + "&noStatisticMenu=1&outputColumnMode=0&outputTitle=Kundenstatistik&specialAligns=l,l,l,l","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
  } else {
  	 alert('Wählen Sie bitte einen Kunden aus!');
  }
}

function openCustomerSpecial(cmpId) {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/customer_special.php?companyId=" + cmpId ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000" onLoad="displayStatusMessage();">

<form action="../groupware/appointment.php" method="post">

<input type="hidden" name="f_act" value="">
<input type="hidden" name="selYear" value="<?php echo ec($selYear) ?>">
<input type="hidden" name="selMonth" value="<?php echo ec($selMonth) ?>">
<input type="hidden" name="selDay" value="<?php echo ec($selDay) ?>">
<input type="hidden" name="f_apIdToRemove" value="">
<input type="hidden" name="f_apIdToUpdate" value="">

<center>

<table align="left" border="0" width="100%">
  <tr>
    <td>
      <table align="left" bgcolor="#000000" border="0" width="100%">
      <?php
        echo printAppointmentCurrentDayHeader($selYear, $selMonth, $selDay);  
      ?>
      </table>
    </td>
  </tr>
  <?php if (authCheckEmployeeRights($emp_id, "10")) : ?>
    <tr>
      <td valign="center">&nbsp;Niederlassungen:&nbsp;&nbsp;&nbsp;
         <?php echo addCheckboxesFromTable("f_hq_id","headquarters","hq_id","hq_name","hq_name","",$f_hq_id, "&nbsp;&nbsp;&nbsp;"); ?>&nbsp;
         <input type="button" name="f_hq_check_all" value="Alle" onClick="hqCheckAll(<?php echo $numOfHq; ?>);">&nbsp;
         <input type="button" name="f_hq_uncheck_all" value="Keine" onClick="hqUncheckAll(<?php echo $numOfHq; ?>);">&nbsp;&nbsp;&nbsp;
         <input type="button" name="action" value="Aktualisieren" onClick="finishPage();">
         <br><br>
      </td>
    </tr>          
  <?php endif; ?>  
  <tr>
    <td>  
      <table align="left" bgcolor="#000000" border="0" width="100%">
      <?php
        echo printAppointmentTitle("FFFFFF");
        echo printAppointmentsOfOneDay($selYear, $selMonth, $selDay);
      ?>
      </table>
    </td>
  </tr>
  <tr>
    <td>  
     <br><br>
    </td>
  </tr>  
  <tr>
    <td>
      <table align="left" bgcolor="#FFFFFF" border="0" width="100%">
        <tr>
          <td colspan="2">
             <b><u>Termin erstellen</u></b><br><br>
          </td>
        </tr>
        <tr>
          <td align="left" valign="top">
            <b>Zeiten:</b><br><br>
            Von: 
            <select name="f_hour"> <?php echo addOptionsFromRange(0, 23, date("H"), "", 2, "0"); ?> </select>&nbsp;
            <select name="f_minute"> <?php echo addOptionsFromRange(0, 59, date("i"), "", 2, "0"); ?> </select> Uhr<br><br>
            Bis: &nbsp;
            <select name="f_hour_to"> <?php echo addOptionsFromRange(0, 23, "", "1", 2, "0"); ?> </select>&nbsp;
            <select name="f_minute_to"> <?php echo addOptionsFromRange(0, 59, "", "1", 2, "0"); ?> </select> Uhr&nbsp;&nbsp;
          </td>
          <td align="left" valign="top">
            <b>Teilnehmer:</b><br><br>
              <?php // echo addCheckboxesFromTable("f_usr_id","user","usr_id","CONCAT(usr_name,', ',usr_firstname)","usr_name","usr_type = '1' AND hq_id IN " . getSQLMandatorArray($f_hq_id) ,"", "<br>"); ?>
              <?php echo addCheckboxesFromTable("f_usr_id","user AS usr, headquarters AS hq","usr.usr_id","CONCAT(usr_name,', ',usr_firstname,' [',hq_name,']')","usr.usr_name","usr.usr_type = '1' AND usr.hq_id = hq.hq_id AND usr.hq_id IN " . getSQLMandatorArray($f_hq_id) ,"", "<br>"); ?>
          </td>
          <td align="center" valign="top">
            <b>Text:</b><br><br>
            <textarea name="f_text" cols="50" rows="5"></textarea>
          </td>
          <td align="center" valign="top">
            <b>Kunde zuordnen:</b><br><br>
            <input type="text" name="g_cs_eid" value="" size="10" readonly>
            <input class="smaller" type="button" value="..." onClick="searchCsCsc();">
            <a href="javascript:clearSpecialCustomer();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a>
            <br><br>
            <!-- <input type="button" name="action" value="Details" onClick="openCustomerSpecial('');"> -->
            <input type="button" name="action" value="Historie" onClick="getCsHistory('');">
            <input type="button" name="action" value="Statistik" onClick="openCustomerStatistics('');">
            <br><br><br>
            <input type="button" name="action" value="Termin einfügen" onClick="insertAppointmentFinishPage();">
            <br><br>
            Email an Teilnehmer versenden&nbsp;<input type="checkbox" name="f_sendmail[]" value="1">
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

</center>

</form>

</body>
</html>
