<?php
/*=======================================================================
 *
 * info.php
 *
 =======================================================================*/


include_once("../include/dbconnect.inc.php");
include_once("../include/caglobal.inc.php");
include_once("../include/auth.inc.php");
include_once("../include/inc_user.inc.php");
include_once("../include/grid.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "noResetUserStates"));

// Id of the actual employee and the costcenter (individual root-node) logged in
if ($cscIdRoot == ""): $cscIdRoot = getFieldValueFromId("employee","emp_id",$emp_id,"csc_id"); endif;
if ($customerId == ""): $customerId = getFieldValueFromId("costcenter","csc_id",$cscIdRoot,"cs_id"); endif;
if ($cscIdActual == ""): $cscIdActual = $cscIdRoot; endif;


// Reset user states data after login
// Has to be executed before including "menu.php" (!!!!)
if (!isset($noResetUserStates) || $noResetUserStates == "") :
   resetUserStates();
   $noResetUserStates = "1";
endif;


getLanguage(__FILE__);

$pageTitel = getLngt("STARTSEITE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");

getCurrentScript(__FILE__);

// GRID
// 1. Parameter: Initial column width 
// 2. Parameter: Number of rows and columns
$grid = new Grid("600px", array(3,2));
// All output has to match a special grid container
$gridJsOut = "";
// Grid container sequential number, read from left to right and then row by row from top to button 
// E.g. array(3,2) has 6 = 3 x 2 containers ([0][0] = 1)
// Reset the counter (= 0)
$grid->resetContainerPageCounter();
// Returns container page counter values
// $mode: "0" or empty <=> returns the array(row, col) regarding current container ID
//        "1" returns the page counter by itself
//        "2" returns the ID of the container
// $gridMatrix = $grid->getNextContainerPageCounter();


// Current user data
$sqlquery = "SELECT usr.usr_name, usr.usr_firstname, usr.usr_type"
            . " FROM user AS usr"
            . " WHERE usr.usr_id = " . $usr_id . " AND usr.hq_id = " . $hq_id;
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
while ($row = $result->fetch_assoc()):
       $v_usr_type = $row["usr_type"];
       $v_usr_name = $row["usr_name"];
       $v_usr_firstname = $row["usr_firstname"];
endwhile;
$result->free();

if ($v_usr_type == "1") :
   if (authCheckEmployeeRights($emp_id, "0") && authCheckEmployeeRights($emp_id, "11")) :
      include ("../groupware/calendar.php");
   endif;
endif;

// Get the emp_id of the root admin, e.g. setting new passwords of employees
$empIdRootAdmin = getEmpIdOfRootAdmin("hq");


// Company-data
$sqlquery = "";
if ($v_usr_type == "3") :
   // Courier
   $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_logo, cmp.cmp_logo_width, cmp.cmp_logo_height"
               . " FROM company AS cmp, courier AS cr"
               . " WHERE cr.usr_id = " . $usr_id
               . "   AND cmp.cmp_id = cr.cmp_id";

elseif ($v_usr_type == "2") :
   // Customer
   $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_logo, cmp.cmp_logo_width, cmp.cmp_logo_height"
               . " FROM company AS cmp, customer AS cs"
               . " WHERE cs.cs_admin = " . $emp_id
               . "   AND cmp.cmp_id = cs.cmp_id";

elseif ($v_usr_type == "1") :
   // Headquarter
   $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_logo, cmp.cmp_logo_width, cmp.cmp_logo_height"
               . " FROM company AS cmp, headquarters AS hq"
               . " WHERE hq.hq_id = " . $hq_id
               . "   AND hq.cmp_id = cmp.cmp_id";
endif;

if ($sqlquery != "") :
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   while ($row = $result->fetch_assoc()):
          $v_cmp_id = $row["cmp_id"];
          $v_cmp_comp = $row["cmp_comp"];
          $v_cmp_comp2 = $row["cmp_comp2"];
          $v_cmp_logo = $row["cmp_logo"];
          $v_cmp_logo_width = $row["cmp_logo_width"];
          $v_cmp_logo_height = $row["cmp_logo_height"];
   endwhile;
endif;
$result->free();

$companyLogo = "";
if (trim($v_cmp_logo) == "") :
   $v_cmp_id = getFieldValueFromId("headquarters", "hq_id", $hq_id, "cmp_id");
   list ($v_cmp_logo, $v_cmp_logo_width, $v_cmp_logo_height) = getFieldsValueFromId("company","cmp_id",$v_cmp_id,array("cmp_logo","cmp_logo_width","cmp_logo_height"));
endif;
if (trim($v_cmp_logo) != "") :
   $companyLogo = "<img src=\"../images/external/" . $v_cmp_logo . "\" border=\"0\" height=\"" . $v_cmp_logo_height . "\" width=\"" . $v_cmp_logo_width . "\">";
endif;

// Container 
$gridMatrix = $grid->getNextContainerPageCounter();
$gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "red"), "hl");
$gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], $v_cmp_comp . " " . $v_cmp_comp2, "hl");
$gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "14pt", "font-weight", "bold"), "bd");
$gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], "<center>" . $companyLogo . "</br></br>" . getLngt("Hallo") . " " . $v_usr_firstname . " " . $v_usr_name . "</br></br></center>", "bd");


// **********************************************
// *** Birthdays, newsticker and appointments ***
// **********************************************

$currentTime = getDateTime("0");

$birthdateOut = "";
$newstickerOut = "";
$appointmentOut = "";


// FOR HEADQUARTERS ONLY
if ($v_usr_type == "1") :

   // Birthday data   
   $sqlquery = "SELECT DISTINCT hq.hq_mnemonic, usr.usr_name, usr.usr_firstname, usr.usr_type"
               . " FROM user AS usr, headquarters AS hq"
               . " WHERE usr.hq_id = hq.hq_id AND RIGHT(usr.usr_birthdate, 5) = RIGHT(CURDATE(), 5)"
               . " ORDER BY usr.usr_type, usr.usr_name";

   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   $tmpUsrTypeArray = array(0,0,0,0);
   while ($row = $result->fetch_assoc()):
          if ($tmpUsrTypeArray[$row["usr_type"]] == "0") :
             $tmpUsrTypeArray[$row["usr_type"]] = "1";
             if ($row["usr_type"] == "1") : $birthdateOut .= "<tr><td colspan=\"2\">" . getLngt("Mitarbeiter") . ":</td></tr>"; endif;
             if ($row["usr_type"] == "2") : $birthdateOut .= "<tr><td colspan=\"2\">" . getLngt("Kunden") . ":</td></tr>"; endif;
             if ($row["usr_type"] == "3") : $birthdateOut .= "<tr><td colspan=\"2\">" . getLngt("Transporteure") . ":</td></tr>"; endif;
          endif;
          $birthdateOut .= "<tr>";
          $birthdateOut .= "<td>(" . $row["hq_mnemonic"] . ")&nbsp;&nbsp;</td>";
          $birthdateOut .= "<td>" . $row["usr_firstname"] . "&nbsp;" . $row["usr_name"] . "</td>";
          $birthdateOut .= "</tr>";
   endwhile;
   $result->free();

   // Container birthdays
   $gridMatrix = $grid->getNextContainerPageCounter();
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "green"), "hl");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], getLngt("Wir gratulieren herzlich zum Geburtstag!"), "hl");
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "14pt", "font-weight", "bold"), "bd");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], "<center></br>" . "<table>" . $birthdateOut . "</table>" . "</br></center>", "bd");


   // DIRECT SEARCH
   $bdOut = "<div><center></br><b>" . getLngt("Auftrag, Kunde, Fahrer, Fahrzeug") . ":</b>&nbsp;&nbsp;"
          . "<input type=\"text\" id=\"metaSearch\" name=\"metaSearch\" value=\"\" size=\"15\">&nbsp;&nbsp;"
          . "<button type=\"button\" class=\"buttonIcon\" onClick=\"metasearch();\">" . "&nbsp;" . "</button></br></div>"
          . "<div style=\"padding:10px\" id=\"metaSearchResult_01\"></div>"
          . "<div style=\"padding:10px\" id=\"metaSearchResult_02\"></div>"
          . "<div style=\"padding:10px\" id=\"metaSearchResult_03\"></div>"
          . "<div style=\"padding:10px\" id=\"metaSearchResult_04\"></div>";
  
   // Container meta search   
   $gridMatrix = $grid->getNextContainerPageCounter();
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "green"), "hl");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], getLngt("DIREKTSUCHE"), "hl");
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "12pt", "font-weight", "normal"), "bd");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], $bdOut, "bd");


   // SPECIAL RIGHTS FOR reports !!!!!!!!!!!!!!!!!!!!!!!!!!!!
   $newCsReportsOut = "";
   $newCrReportsOut = "";
   $presetDays = 7;
   if (authCheckEmployeeRights($emp_id, "0") && authCheckEmployeeRights($emp_id, "16")) :
      $numOfNewCsReports = 0;
      $listOfLoginsArray = getListOfLogEntries(array('52','53'), array(0,0,0,0,-($presetDays),0), array("log_createtime"), $emp_id, "log_createtime DESC");
      $listOfLoginsArrayLen = count($listOfLoginsArray);
      if ($listOfLoginsArrayLen > 0) :
         $lastLoginTime = $listOfLoginsArray[1][0];
         if ($lastLoginTime != "") :
            $numOfNewCsReports = getCountOfTable("phoenix_group.report_process", "hq_id = '" . $hq_id . "' AND rp_objtype = 'cs' AND rp_createtime >= '" . $lastLoginTime . "'");
            if ($numOfNewCsReports == -1) : $numOfNewCsReports = 0; endif;
            $numOfNewCrReports = getCountOfTable("phoenix_group.report_process", "hq_id = '" . $hq_id . "' AND rp_objtype = 'cr' AND rp_createtime >= '" . $lastLoginTime . "'");
            if ($numOfNewCsReports == -1) : $numOfNewCsReports = 0; endif;
         endif;
      endif;
      $newCsReportsOut = "<a href=\"../groupware/report.php?currentNavigationItem=vertrieb&rpObjType=cs&day_from=". ec(substr($lastLoginTime,8,2)) . "&month_from=". ec(substr($lastLoginTime,5,2)) . "&year_from=". ec(substr($lastLoginTime,0,4)) . "&day_to=" . ec(getDateTime("day")) . "&month_to=". ec(getDateTime("month")) . "&year_to=". ec(getDateTime("year")) . "\" target=\"_blank\">" . getLngt("[Kundenberichte]") . "</a>";
      $newCrReportsOut = "<a href=\"../groupware/report.php?currentNavigationItem=vertrieb&rpObjType=cr&day_from=". ec(substr($lastLoginTime,8,2)) . "&month_from=". ec(substr($lastLoginTime,5,2)) . "&year_from=". ec(substr($lastLoginTime,0,4)) . "&day_to=" . ec(getDateTime("day")) . "&month_to=". ec(getDateTime("month")) . "&year_to=". ec(getDateTime("year")) . "\" target=\"_blank\">" . getLngt("[Transporteursberichte]") . "</a>";
   endif;  // SPECIAL RIGHTS FOR reports !!!!!!!!!!!!!!!!!!!!!!!!!!!!

   // Number of reports
   $reportOut = "";
   $lastLoginTimestamp = substr($lastLoginTime,8,2) . "." . substr($lastLoginTime,5,2) . "." . substr($lastLoginTime,0,4). "&nbsp;&nbsp;" . substr($lastLoginTime,11,2) . "." . substr($lastLoginTime,14,2) . "." . substr($lastLoginTime,17,2);
   if ($newCsReportsOut != "" || $newCrReportsOut != "") :
      $reportOut .= "<div><table>";
      $reportOut .= "<tr><td align=\"center\"><b>" . getLngt("BERICHTE seit letztem Login") . "&nbsp;[" . $lastLoginTimestamp . "]&nbsp;" . getLngt("(max. eine Woche)") . "<br><br></td></tr>";
      if ($newCsReportsOut != "") :
          $reportOut .= "<tr><td align=\"center\">" . $newCsReportsOut . "&nbsp;&nbsp;[" . getLngt("Anzahl") . "&nbsp;" . $numOfNewCsReports . "]<br><br></td></tr>";
      endif;
      if ($newCrReportsOut != "") :
          $reportOut .= "<tr><td align=\"center\">" . $newCrReportsOut . "&nbsp;&nbsp;[" . getLngt("Anzahl") . "&nbsp;" . $numOfNewCrReports . "]<br><br></td></tr>";
      endif;
      $reportOut .= "</table></div>";
      
      // Container reports
      $gridMatrix = $grid->getNextContainerPageCounter();
      // $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "blue"), "hl");
      $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], getLngt("BERICHTE seit letztem Login") . "&nbsp;[" . $lastLoginTimestamp . "]&nbsp;" . getLngt("(max. eine Woche)"), "hl");
      $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "10pt", "font-weight", "normal"), "bd");
      $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], "<center></br>" . $reportOut . "</center>", "bd");
   endif;
      

   // SPECIAL RIGHTS FOR calendar !!!!!!!!!!!!!!!!!!!!!!!!!!!!
   if (authCheckEmployeeRights($emp_id, "0") && authCheckEmployeeRights($emp_id, "11")) :
   
      // Appointment data
      $f_hq_id = array($hq_id);
      $f_selUsrId = $usr_id;
   
      // Monitored appointments
      $f_ap_cat_search_4 = "1";  // Get only appointments with activated "alarm"
      $tmpApRangeStarttime = getDateTime("date_plus_offset", array(-1,0,0), "Ymd");
      $tmpApRangeEndtime = getDateTime("date_plus_offset", array(0,7,0), "Ymd");
      $apArray = getAppointmentsFromDB(substr($tmpApRangeStarttime,0,4), substr($tmpApRangeStarttime,4,2) , substr($tmpApRangeStarttime,6,2), substr($tmpApRangeEndtime,0,4), substr($tmpApRangeEndtime,4,2) , substr($tmpApRangeEndtime,6,2));
      
      // Normal appointments
      $f_ap_cat_search_4 = "0";  // Get normal appointments
      $tmpApRangeStarttime = getDateTime("date_plus_offset", array(0,0,0), "Ymd");
      $tmpApRangeEndtime = getDateTime("date_plus_offset", array(0,1,0), "Ymd");
      $apArray2 = getAppointmentsFromDB(substr($tmpApRangeStarttime,0,4), substr($tmpApRangeStarttime,4,2) , substr($tmpApRangeStarttime,6,2), substr($tmpApRangeEndtime,0,4), substr($tmpApRangeEndtime,4,2) , substr($tmpApRangeEndtime,6,2));
      
      // Merge arrays
      $apArray = array_merge($apArray, $apArray2);
      $lenApArray = count($apArray);
     
      for ($j = 0; $j < $lenApArray; $j++) :
          $tmpId = $apArray[$j][0];
          $tmpText = $apArray[$j][1];
          $tmpExecDateTime = $apArray[$j][2];
            $tmpExecDate = substr($tmpExecDateTime,8,2) . "." . substr($tmpExecDateTime,5,2) . "." . substr($tmpExecDateTime,0,4);
            $tmpExecTime = substr($tmpExecDateTime,11,5);
            $tmpExecDateYear = substr($apArray[$j][2],0,4);
            $tmpExecDateMonth = substr($apArray[$j][2],5,2);
            $tmpExecDateDay = substr($apArray[$j][2],8,2);         
          $tmpCmpId = trim($apArray[$j][3]);
          $tmpCmpComp = trim($apArray[$j][4]);
          $tmpCmpComp2 = trim($apArray[$j][5]);
          $tmpCsId = $apArray[$j][6];
          $tmpCsEid = $apArray[$j][7];
          $tmpEndDateTime = $apArray[$j][8];
            $tmpEndDate = substr($tmpEndDateTime,8,2) . "." . substr($tmpEndDateTime,5,2) . "." . substr($tmpEndDateTime,0,4);
            $tmpEndTime = substr($tmpEndDateTime,11,5);
          $tmpUsrId = trim($apArray[$j][9]);
          $tmpUsrFirstname = trim($apArray[$j][10]);
          $tmpUsrName = trim($apArray[$j][11]);
          $tmpParticipants = trim($apArray[$j][12]);
            $tmpParticipants = substr($tmpParticipants,1,-1);     // Remove commata from db-field
          $tmpConfirmed = trim($apArray[$j][13]);
            $tmpConfirmed = substr($tmpConfirmed,1,-1);           // Remove commata from db-field
          $tmpPtCmpComp = trim($apArray[$j][14]);
          $tmpPtCmpComp2 = trim($apArray[$j][15]);
          $tmpPtCsEid = $apArray[$j][16];
          $tmpPtId = $apArray[$j][17];
          $tmpApCat1 = $apArray[$j][18];
          $tmpApCat2 = $apArray[$j][19];
          $tmpApCat3 = $apArray[$j][20];
          $tmpApCat4 = $apArray[$j][21];
          
          $cellCol = "FFFFFF";
          $apOut .= "<tr><td>" . getLngt("Beginn") . "</td><td>" . getLngt("Ende") . "</td><td>" . getLngt("Ersteller") . "</td><td>" . getLngt("Teilnehmer") . "</td><td>" . getLngt("Beschreibung") . "</td><td>" . getLngt("Kunde") . "</td><td>&nbsp;</td></tr>";
          $apOut .= "<tr>";
   
          // Dates (From, To)
          $apOut .= "<td width=\"90\" align=\"center\" valign=\"center\" bgcolor=\"#" . $cellCol . "\"><b>" . $tmpExecDate . "<br>" . ($tmpApCat4 == "1" ? "<img src=\"../images/ap_clock.png\" width=\"15\" height=\"15\" style=\"border:none;\">" : "") . "<br>" . $tmpExecTime . "</b></td>";
          if ($tmpEndTime != "00:00") :
             $apOut .= "<td width=\"90\" align=\"center\" valign=\"center\" bgcolor=\"#" . $cellCol . "\"><b>" . $tmpEndDate . "<br><br>" . $tmpEndTime . "</b></td>";
          else :
             $apOut .= "<td width=\"90\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
          endif;
      
          // User      
          if ($tmpUsrId != "") :
             $apOut .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpUsrFirstname . "<br>" . $tmpUsrName . "</td>";
          else :
             $apOut .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
          endif;
          
          // Participants
          $apOut .= "<td width=\"150\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">";
          if ($tmpParticipants != "") : 
             $tmpParticipants = spliti(",", $tmpParticipants);   // It has to be an array
             $tmpParticipantsLen = count($tmpParticipants);
             
             // Needs array of users confirmed the appointment
             $tmpConfirmed = spliti(",", $tmpConfirmed);
             
             for ($k = 0; $k < $tmpParticipantsLen; $k++) :
                 $participantName = $db->getOne("SELECT CONCAT(usr_name,', ',usr_firstname) AS name FROM user WHERE usr_id = '" . $tmpParticipants[$k] . "'");
      
                 $participantConfirmed = "[?]";
                 $l = array_search($tmpParticipants[$k], $tmpConfirmed);
                 if (!($l === FALSE)) :
                    $participantConfirmed = getLngt("[OK]");
                 else :
                    if ($tmpParticipants[$k] == $tmpUsrId) :
                       $participantConfirmed = getLngt("[OK]");
                    elseif ($tmpParticipants[$k] == $usr_id) :   // Only the user has a link to confirm his/her own entry
                       // $participantConfirmed =  "<a href=\"javascript:confirmAppointmentFinishPage('" . $tmpId . "');\">" . getLngt("[Bestätigen]") . "</a>";
                       $participantConfirmed = getLngt("[Bestätigen]");
                    endif;
                 endif;
                 $apOut .= $participantName . "&nbsp;" . $participantConfirmed . "<br>";
             endfor;
          else :
             $apOut .= "&nbsp;";
          endif;
          $apOut .= "</td>";
          
          // Text
          $apOut .= "<td align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpText . "</td>";
          
          // Potential customer relation (Company name and EID)
          if ($tmpCsId != "") :
             $apOut .= "<td width=\"205\" 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=\"Berichte\" onClick=\"getCsHistory('" . $tmpCsEid . "');\">"
          //          . "<input type=\"button\" name=\"action\" value=\"Statistik\" onClick=\"openCustomerStatistics('" . $tmpCsEid . "');\">"
          //          . "</td>";
          // elseif ($tmpPtId != "") :
          //    $apOut .= "<td width=\"205\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">" . $tmpPtCmpComp . "<br>" . ($tmpPtCmpComp2 != "" ? $tmpPtCmpComp2 . "<br>" : "") . $tmpPtCsEid . "<br>"
          //          . "<input type=\"button\" name=\"action\" value=\"Details\" onClick=\"openProspectSpecial('" . $tmpPtId . "');\">"
          //          . "<input type=\"button\" name=\"action\" value=\"Berichte\" onClick=\"getPtHistory('','" . $tmpPtCsEid . "');\">"
          //          . "</td>";
          else :
             $apOut .= "<td width=\"200\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">&nbsp;</td>";
          endif;
   
          $apOut .= "<td width=\"100\" align=\"left\" valign=\"center\" bgcolor=\"#" . $cellCol . "\">";
          $apOut .= "&nbsp;&nbsp;<a href=\"../groupware/appointment.php?currentNavigationItem=vertrieb&f_selUsrId=" . ec($usr_id) . "&viewMode=" . ec(0) . "&selYear=" . ec($tmpExecDateYear) . "&selMonth=" . ec($tmpExecDateMonth) . "&selDay=" . ec($tmpExecDateDay) . "\">" . getLngt("[Zum Termin]") . "</a>";
          $apOut .= "</td>";
      
          // if ($j < $lenApArray - 1) : $apOut .= "</tr><tr>"; endif;
          $apOut .= "</tr>";
      endfor;
      if (true || $lenApArray > 0) :
         // Container appointments
         $gridMatrix = $grid->getNextContainerPageCounter();
         $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "blue"), "hl");
         $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], getLngt("AKTUELLE TERMINE") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type=\"button\" class=\"buttonMenuUserInfo\" onClick=\"document.location.href = \'../groupware/appointment.php?currentNavigationItem=vertrieb&f_selUsrId=" . ec($usr_id) . "\';\">" . getLngt("Kalender") . "</button>", "hl");
         $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "10pt", "font-weight", "normal"), "bd");
         $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], "<center></br>" . "<table>" . $apOut . "</table>" . "</center>", "bd");
      endif;
   endif;  // SPECIAL RIGHTS FOR calendar !!!!!!!!!!!!!!!!!!!!!!!!!!!!
endif;

// A text, transmitted by ajax from client to server with "encodeURI(escape(content))" in javascript, 
// stored - urldecoded in PHP - into the DB and read by PHP from the database again like here for (editable) output
function my_str_check_ajax($aStr, $nl2br_enabled = true)
{
	while (strpos($aStr, "\\")) :
        $aStr = str_replace("\\n", "\n", $aStr);
        $aStr = str_replace("\\r", "\r", $aStr);
	endwhile;
	if ($nl2br_enabled) :
	   $aStr = str_replace("\n\r", "</br>", $aStr);
	   $aStr = str_replace("\r\n", "</br>", $aStr);
     $aStr = str_replace("\n", "</br>", $aStr);
     $aStr = str_replace("\r", "</br>", $aStr);
  endif;
  return $aStr;
}

// CUSTOMER NEWS, visible for headquarter and customers, editable by headquarters only regarding access rights
if ($v_usr_type == "1" || $v_usr_type == "2") :

   $csGlobalInfoByHq = "";
   if (existsEntry("genericdatacontainer",array("gdc_obj_type","hq2cs","gdc_obj_id",$hq_id,"gdc_gen_fieldname","global_cs_info"))) :
      $csGlobalInfoByHq = getFieldValueFromClause("genericdatacontainer","gdc_content","gdc_obj_type = 'hq2cs' AND gdc_obj_id = '" . $hq_id . "' AND gdc_gen_fieldname = 'global_cs_info'");
   endif;
   // Check for access right to edit the text
   if ($v_usr_type == "1") :
      $outCsGlobalInfoByHqHeadline = getLngt("Aktuelle Infos für die Kunden");
   else :
      $outCsGlobalInfoByHqHeadline = getLngt("Aktuelle Informationen für Sie");
   endif;
   if ($v_usr_type == "1" && authCheckEmployeeRights($emp_id, "0") && authCheckEmployeeRights($emp_id, "35")) :
      $outCsGlobalInfoByHqHeadline .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . "<button type=\"button\" class=\"buttonMenuUserInfo\" onClick=\"storeCsGlobalInfo(\'global_cs_info\');\">" . getLngt("Speichern") . "</button>";
      $outCsGlobalInfoByHqBody = "<center><textarea id=\"global_cs_info\" name=\"global_cs_info\" cols=\"70\" rows=\"5\" style=\"resize:vertical;\">" . my_str_check_http($csGlobalInfoByHq) . "</textarea></center>";
   else :
     $outCsGlobalInfoByHqBody = my_str_check_ajax($csGlobalInfoByHq);
   endif;
   
   // Container customer news
   $gridMatrix = $grid->getNextContainerPageCounter();
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("background-color", "green"), "hl");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], $outCsGlobalInfoByHqHeadline, "hl");
   $gridJsOut .= $grid->gridSetCss($gridMatrix[0], $gridMatrix[1], array("font-size", "10pt", "font-weight", "normal", "color", "black"), "bd");
   $gridJsOut .= $grid->gridSetHtml($gridMatrix[0], $gridMatrix[1], "</br>" . $outCsGlobalInfoByHqBody, "bd");
endif;

// Hide remaining containers without content
$gridJsOut .= $grid->gridHideRemaining();
?>


<html>
<head>
<title><?php echo $pageTitel ?></title>
<script>
//Quelle: https://msdn.microsoft.com/en-us/library/cc197053%28v=vs.85%29.aspx
window.onerror=fnErrorTrap;
function fnErrorTrap(sMsg,sUrl,sLine){
//parent.job_tour.document.tourForm.
//parent.job_options.document.tourOptions.

    var tmp_jb_id = "";
    if(typeof(jb_id)!='undefined')    
      tmp_jb_id = jb_id;
    var out = '';
//    if(typeof(parent.job_options.document.tourOptions) != 'undefined') {
//      for (var i = 0; i <= parent.job_options.document.tourOptions.elements.length; i++) {
////        out += i + ": " + parent.job_options.document.tourOptions.elements[i].name + " = " + parent.job_options.document.tourOptions.elements[i].value + "\n";
//        out += parent.job_options.document.forms[0].elements[i].value + "\n";
//      }
//    }
    iframe = document.createElement("IFRAME");
    iframe.setAttribute("src", "../include/ajaxJsError.php?url="+escape(sUrl) + "&line=" + escape(sLine) + "&message=" + escape(sMsg) + "&user_agent=" + escape(navigator.userAgent) + "&jb_id=" + tmp_jb_id + "&out=" + escape(out));
    iframe.width = 1;
    iframe.height = 1;
    iframe.style.display = 'none';
    setTimeout(function(){
      document.body.appendChild(iframe);
    },10);
  return false;
}
//alert('test');
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="votian"> <meta name="keywords" content="votian">
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">

<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
</style>

<style type="text/css">

<?php echo $grid->getGridItemParameter("output_css") ?>

.bar1
    { width:100%; height:100px;
      font-size:12pt; font-family:Helvetica,Arial; font-style:normal; font-weight:normal;
      background:#1b12b9; color:white;
    }
.bar2
    { width:100%; height:100px;
      font-size:14pt; font-family:Helvetica,Arial; font-style:normal; font-weight:normal;
      background:#4e45ec; color:white;
    }
.bar3
    { width:100%;
      font-size:10pt; font-family:Helvetica,Arial; font-style:normal; font-weight:normal;
      background:#4e45ec; color:white;
    }
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>

<script src="../include/checkFormTags.js" type="text/javascript"></script>

<script language="JavaScript">
<!--

var searchResult = '';

function checkStartTickerOut () {
	myhide('startTickerOut');
	if (max > 0) {
		 tickerActive = true;
	   myshow('startTickerOut');
	   ticker('startTickerOut');
  }
}

function metasearchSpecial (objType, containerNo = '1') {
  var searchVal = $("#metaSearch").val();  
  var searchProcessOk = false;  
  var ctNum = padl(containerNo.toString(),2,'0');
  if (!objType) {objType = ''};
  searchVal = searchVal.trim();
  searchValLen = searchVal.length;
  if (objType != '' && searchVal != ''&& searchValLen >= 4) {
// alert('JS.objType = ' + objType);
	   ajaxRequestGet('../include/ajaxReqSearch.php', 'retMode=0&objType=' + objType + '&searchValue=' + encodeURI(escape(searchVal)));
	   searchProcessOk = true;
	   if (searchResult != '') {
	   	  $('#metaSearchResult_' + ctNum).html(searchResult);
	   }
  } else {
  	$('#metaSearchResult_' + ctNum).html('<center><span style="color:red"><?php echo getLngt("Bitte mindestens 4 Zeichen eingeben!") ?></span></center>');
  }
  return searchProcessOk;
}

function metasearch () {
	// Init container
	$('#metaSearchResult_01').html('');
	$('#metaSearchResult_02').html('');
	$('#metaSearchResult_03').html('');
	$('#metaSearchResult_04').html('');
	// Search in categories
	var searchProcessOk = true;
	searchProcessOk = metasearchSpecial('jb',1);
	if (searchProcessOk) {
		 searchProcessOk = metasearchSpecial('cs',2);
	}
	if (searchProcessOk) {
		 searchProcessOk = metasearchSpecial('cr',3);
	}
	if (searchProcessOk) {
		 searchProcessOk = metasearchSpecial('crvh',4);
	}
  <?php 
    if ($v_usr_type == "1") :
       // echo "$('#metaSearch').focus();";
    endif;
  ?>
}

function storeCsGlobalInfo (elem) {
  var content = $('#' + elem).val();
  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=500&wrap_html=1&value_01=hq2cs&value_02=<?php echo ec($hq_id) ?>&value_03=' + elem + '&value_04=' + encodeURI(escape(content)) + '&value_05=');
}

// Opens a new (popup-)window with specified parameters
function popupSearch (url,title,config) {
  var widthPopupWin = screen.width - 80;
  var heightPopupWin = screen.height - 180;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2);
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2);
  var popup;
  popup = window.open(url,title, "dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
}

function openLinkByObject (objType, objValue) {
	// alert(objType + ' ' + objValue);
	if (objType == 'jb') {
	   popupSearch('../admin/jb_detail.php?job_id=' + objValue,'','');
	} 
	if (objType == 'cs') {
		popupSearch('../admin/customer_special.php?companyId=' + objValue,'','');
	}
	if (objType == 'cr') {
		popupSearch('../admin/courier_special.php?companyId=' + objValue,'','');
	}
	if (objType == 'crvh') {
		popupSearch('../admin/courier_vehicle.php?courierId=' + objValue,'','');
	}
}

function execBodyOnLoad() {
  <?php echo $gridJsOut ?>
  // checkStartTickerOut();
  <?php 
    if ($v_usr_type == "1") :
       echo "$('#metaSearch').focus();";
    endif;
  ?>
}

$(document).keypress(function(e) {
  if (e.keyCode === 13 && e.target.nodeName == 'INPUT') {
     e.preventDefault(); //prevent default if it is INPUT
     var focused = $(':focus');
     if ($(focused).attr('id') == "metaSearch") {
     	  metasearch();
     };
  }
});

// -->
</script>

<noscript>
  <center>
    <b><br>JavaScript ist nicht verf&uuml;gbar. Bitte aktivieren Sie JavaScript<br><br>

        in Ihrem Browser, damit diese Seite ordnungsgem&auml;&szlig; funktioniert!</b><br><br>

  </center>
</noscript>
</head>

<body leftmargin="1" topmargin="1" marginwidth="0" marginheight="0" link="#990000" vlink="#990000" alink="#990000" onLoad="<?php echo $phpCurrentNavigationOnLoad ?>execBodyOnLoad();">

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="maincontent" name="maincontent" id="maincontent">

  <?php echo htmlDivLineSpacer("10px"); ?>

  <form name="start" action="../admin/info.php" method="post">

  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="noResetUserStates" value="<?php echo ec($noResetUserStates) ?>">

  <div>  	
  	<?php echo $grid->getGridItemParameter("output_html") ?>
  </div>

  </form>
  
</div>

</body>

</html>

