<?php
/*=======================================================================
 *
 * jb_special.php
 *
 * Autor: Carsten Annacker
 *
 =======================================================================*/

include_once("../include/global.inc.php");
include_once("../include/auth.inc.php");
include_once("../include/caglobal.inc.php");
include_once("../include/inc_check_publicholiday.inc.php");
//if ($phpVersion >= "7.0"):
//  require_once("../PEAR/HTML/Template/IT.php");
//else:
//  require_once("HTML/IT.php");
//endif;
if ($usr_type != 1 && $usr_type != 0):
  reportDie ("$PHP_SELF: Ungültiger 'usr_type': '$usr_type'", false);
endif;

//if ($phpVersion >= "7.0"):
//  $tpl = new HTML_Template_IT();
//else:
//  $tpl = new IntegratedTemplate();
//endif;
$output = file_get_contents("jb_special.tpl.htm");
$output = str_replace("{_css_file_}", "../css/phoenix.css.php", $output);
//$tpl->loadTemplatefile("jb_special.tpl.htm", true, true);
//$tpl->setCurrentBlock("css_file");
//$tpl->setVariable("_css_file_", "../css/phoenix.css.php");
////$tpl->setVariable("_css_file_", "../css/phoenix-print.css");
//$tpl->parseCurrentBlock("css_file");

list ($cs_id, $csc_id, $action, $sort, $deljobs) = getHttpVars(array("cs_id", "csc_id", "action", "sort", "deljobs"));
getSecHttpVars("1", array("cs_id", "csc_id"));

if ($deljobs != "") {
  $sqlquery = "SELECT jb_id, jb_tourname FROM job WHERE jb_id IN (" . $deljobs . ")";
  $res = $db->query($sqlquery);
  if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery': " . $res->getMessage());
  $jb_tournames = array();
  while ($row = $res->fetch_assoc()):
    $jb_tournames[$row["jb_id"]] = $row["jb_tourname"];
  endwhile;
  $res->free();

  $sqlquery = "UPDATE job SET jb_tourname = '' WHERE jb_id IN (" . $deljobs . ")";
  writeLog_("../log/job_options_", $sqlquery . " " . json_encode($jb_tournames));
  $res = $db->query($sqlquery);
  if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery': " . $res->getMessage());
  header("Location: ../jobs/jb_special.php?csc_id=" . ec($csc_id) . "&cs_id=" . ec($cs_id) . "&action=" . $action . "&sort=" . $sort);
  exit;
}

if ($csc_id == ""):
  if ($cs_id != "" && $cs_id != "0"):
    // BARZAHLER $CS_ID ABFANGEN!!!
    if ($db->getOne("SELECT cs_id FROM costcenter WHERE csc_id = " . CSC_ID_PAYER_CASH) == $cs_id):
      $csc_id_list_sql = CSC_ID_PAYER_CASH;
    else:
      $sqlquery = "SELECT csc_id FROM costcenter WHERE cs_id = " . $cs_id . " AND csc_visible = 1";
      $res = $db->query($sqlquery);
      if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery': " . $res->getMessage());
      $csc_id_list_sql = "";
      while ($row = $res->fetch_assoc()):
        if ($csc_id_list_sql != "")
          $csc_id_list_sql .= ",";
        $csc_id_list_sql .= $row["csc_id"];
      endwhile;
      $res->free();
    endif;
  else:
//    reportDie ("$PHP_SELF: Parameter 'cs_id' fehlt", false);
  endif;
else:
  $csc_id_list_sql = $csc_id;
endif;
$hq_id = $HTTP_SESSION_VARS['hq_id'];

$sqlStmt =
  "SELECT jb.jb_id, jb.jb_ordertime, jb.jb_tourname, jb.jb_totalprice, jb.jb_permanent, jb.jb_permanent2, jb.jp_permenddat, csc_name, " .
  "tr.tr_comp, ad.ad_zipcode, ad2.ad_zipcode AS ad2_zipcode, CONCAT(ad.ad_street,' ',tr.tr_hsno) AS streethsno, " .
  "vht.mt_sort AS vht_sort, vht.mt_value AS vht_value " .
  "FROM tour AS tr, address AS ad, metatype AS vht, costcenter AS csc, job AS jb LEFT JOIN tour AS tr2 ON tr2.jb_id = jb.jb_id AND tr2.tr_sort = '2' LEFT JOIN address AS ad2 ON ad2.ad_id = tr2.ad_id " .
  "WHERE jb.vht_id = vht.mt_sort AND vht.mt_type = 'vehicletype' AND jb.jb_id = tr.jb_id AND tr.tr_sort = 1 AND tr.ad_id = ad.ad_id";
// gespeicherte Tournamen der übergebenen Kostenstelle holen
// wenn Kostenstelle Barzahler, dann nur Touren, in denen kein Zahler (in csc_id_payer_cash) eingetragen ist!

if ($action == "")
  $action = 1;
switch ($action) {
  case 2:
  case 3:
    // Wenn alle Daueraufträge der Zentrale (wenn $csc_id/$cs_id leer), dann Datum aus DB nehmen (auf diese Weise können alte Dumps analysiert werden)
    $today = getdate();
    if ($csc_id_list_sql != ""):
      $today_date = $today['year'] . "-" . sprintf("%02d", $today['mon']) . "-" . sprintf("%02d", $today['mday']);
    else:      
      list($tmpJahr, $tmpMonat, $tmpTag, $dummy1, $dummy2) = getValsFromDate($db->getOne("SELECT MAX(ka_lastexecutiontime) FROM keepalive"));
      $today_date = $tmpJahr . "-" . $tmpMonat . "-" . $tmpTag;
    endif;
    // Daueraufträge holen
    $sqlStmt .=
      " AND (jb.jb_ordertime >= '$today_date" . " 00:00:00')" .
      " AND ((jb.jb_storno != 3 AND jb.jb_storno != 4) OR jb.jb_storno IS NULL) " .
      " AND jb.jb_status != 2 AND (jb.jb_permanent IN (4, 5, 6, 7, 8, 9) OR (jb.jb_permanent IN (1, 2, 3) AND jb.jb_permanent2 != '0000000'))" .
      " AND (jb.jb_id_copy_permanent IS NULL OR jb.jb_id_copy_permanent = 0) " .
      " AND (jb.jp_permenddat >= '$today_date" . " 00:00:00' OR jb.jp_permenddat IS NULL OR jb.jp_permenddat = '00.00.0000 00:00:00')";
    $actionStr = "Dauerauftr&auml;ge";
    $actionStrAlt2 = "Gespeicherte Touren";  
    $actionAlt2 = "1";
    $actionStrAlt1 = ($action == 2 ? "ein" : "aus");
    $actionAlt1 = ($action == 2 ? 3 : 2);
    // Dauerauftragsrhythmus-Typen holen
    $sqlquery = "SELECT mt_sort, mt_value FROM metatype WHERE mt_type = 'permanent' ORDER BY mt_sort";
    $res = $db->query($sqlquery);
    if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery': " . $res->getMessage());
    $permanent_types = array();
    while ($row = $res->fetch_assoc()):
      $permanent_types[$row['mt_sort']] = $row['mt_value'];
    endwhile;
    $res->free();
    // alle Vorgänger-Daueraufträge (bis Anfang des letzten Jahres) für die Darstellung der Historie holen
    $sqlquery = "SELECT jb_id, jb_id_copy_permanent, jb_ordertime FROM job WHERE NOT (jb_id_copy_permanent IS NULL) AND jb_ordertime > " .
      ($today['year'] - 1) . "-01-01 AND (csc_id_payer IN (" . $csc_id_list_sql . ") OR csc_id_payer_cash IN (" . $csc_id_list_sql . ")) ORDER BY jb_id ASC";
    $res = $db2->query($sqlquery);
    if (DB::isError($res)) reportDie ("$PHP_SELF: '$sqlquery': " . $res->getMessage());   
    $permanent_jobs = array();
    while ($row = $res->fetch_assoc()):
      $permanent_jobs[$row['jb_id_copy_permanent']] = array($row['jb_id'], $row['jb_ordertime']);
    endwhile;
    $res->free();
    break;
  default:    
    // Konserven holen
    $sqlStmt .=
      " AND LENGTH(jb.jb_tourname) > 0";
    $actionStr = "Gespeicherte Touren";  
    $actionStrAlt2 = "Dauerauftr&auml;ge";
    $actionAlt2 = "2";
    $actionStrAlt1 = "undefined";
    $actionAlt1 = "undefined";
}

switch ($sort) {
  case 1:
    $sqlSortField = "jb_id";
    break;
  case 2:
    $sqlSortField = "jb_totalprice";
    break;
  case 3:
    $sqlSortField = "csc_name";
    break;
  case 4:
    $sqlSortField = "jb_tourname";
    break;
  case 5:
    $sqlSortField = "tr_comp";
    break;
  case 6:
    $sqlSortField = "streethsno";
    break;
  case 7:
    $sqlSortField = "ad_zipcode";
    break;
  case 8:
    $sqlSortField = "ad2_zipcode";
    break;
  case 9:
    $sqlSortField = "vht_value";
    break;
  case 10:
    $sqlSortField = "jb_ordertime";
    break;
  default:
    $sqlSortField = "jb_tourname";
}

//if ($csc_id_list_sql == CSC_ID_PAYER_CASH):
//  $sqlStmt .=
//   " AND (jb.csc_id_payer = '$csc_id_list_sql' AND jb.csc_id_payer_cash != 0)";
if ($csc_id_list_sql != ""):
  $sqlStmt = "(" . 
    $sqlStmt . " AND (csc.csc_id = jb.csc_id_payer)" . " AND jb.csc_id_payer IN ($csc_id_list_sql)" .
    ") UNION (" .  
    $sqlStmt . " AND (csc.csc_id = jb.csc_id_payer_cash)" . " AND (jb.csc_id_payer_cash IN ($csc_id_list_sql) AND jb.csc_id_payer_cash != '0')" .
    ")";
endif;
$sqlStmt .=
  " ORDER BY $sqlSortField";

if ($csc_id != ""):
  // wenn Root-Kostenstelle, dann Name aus company nehmen      
  if (trim($db->getOne("SELECT csc_pre_id FROM costcenter WHERE csc_id = '" . $csc_id . "'")) == ""):
    $csc_name = $db->getOne(
      "SELECT company.cmp_comp FROM company, customer, costcenter" .
      " WHERE customer.cs_id = costcenter.cs_id AND company.cmp_id = customer.cmp_id " .
      " AND costcenter.csc_id = '" . $csc_id . "'");
  else:
    // wenn Unterkostenstelle, dann Kostenstellennamen
    $csc_name = $db->getOne("SELECT csc_name FROM costcenter WHERE csc_id = '" . $csc_id . "'");
  endif;
elseif ($cs_id != ""):
  $csc_name = $db->getOne(
    "SELECT company.cmp_comp FROM company, customer" .
    " WHERE customer.cs_id = $cs_id AND company.cmp_id = customer.cmp_id");
else:
  $cmp_id = getFieldValueFromId("headquarters", "hq_id", "$hq_id", "cmp_id");
  $cmp_comp = getFieldValueFromId("company", "cmp_id", "$cmp_id", "cmp_comp");
  $csc_name = getFieldValueFromId("company", "cmp_id", "$cmp_id", "cmp_comp2");
endif;

$tableHeader_output =
  "<td align=\"left\" colspan=\"2\">&nbsp;</td>" .
  "<td align=\"center\" colspan=\"7\">" .
  "<span class=\"verysmall\"> &nbsp;<br>&nbsp;<br></span>" .
  "<b>$csc_name: $actionStr" . "</b>" .
  ($actionStrAlt1 == "undefined" ? "" :
    "&nbsp;&nbsp;&nbsp;" .
    "<input type=\"button\" name=\"actionButton1\" class=\"f8np1\" size=\"1\" value=\"Historie ${actionStrAlt1}\" title=\"Historie ${actionStrAlt1}blenden (alt+h)\" accesskey=\"h\" onClick=\"finishPage(1)\">"
  ) .
  "<br><br></td>" .
  "<td align=\"right\" colspan=\"2\">" .
  "<input type=\"button\" name=\"actionButton2\" class=\"f8np1\" size=\"2\" value=\"$actionStrAlt2\" title=\"$actionStrAlt2 anzeigen (alt+a)\" accesskey=\"a\" onClick=\"finishPage(2)\">" .
  "</td>";
//$tpl->setCurrentBlock("tableHeader");
//$tpl->setVariable("_tableHeader_",
//  "<td align=\"left\" colspan=\"2\">&nbsp;</td>" .
//  "<td align=\"center\" colspan=\"7\">" .
//  "<span class=\"verysmall\"> &nbsp;<br>&nbsp;<br></span>" .
//  "<b>$csc_name: $actionStr" . "</b>" .
//  ($actionStrAlt1 == "undefined" ? "" :
//    "&nbsp;&nbsp;&nbsp;" .
//    "<input type=\"button\" name=\"actionButton1\" class=\"f8np1\" size=\"1\" value=\"Historie ${actionStrAlt1}\" title=\"Historie ${actionStrAlt1}blenden (alt+h)\" accesskey=\"h\" onClick=\"finishPage(1)\">"
//  ) .
//  "<br><br></td>" .
//  "<td align=\"right\" colspan=\"2\">" .
//  "<input type=\"button\" name=\"actionButton2\" class=\"f8np1\" size=\"2\" value=\"$actionStrAlt2\" title=\"$actionStrAlt2 anzeigen (alt+a)\" accesskey=\"a\" onClick=\"finishPage(2)\">" .
//  "</td>"
//);
//$tpl->parseCurrentBlock("tableHeader");

$sortLinkStart = "<a href=\"../jobs/jb_special.php?csc_id=" . ec($csc_id) . "&cs_id=" . ec($cs_id) . "&action=$action&sort=";
$sortLinkMid = "\">";
$sortLinkEnd = "</a>";
$tableHeader_output .= "</tr><tr><td align=\"left\">Lfd. Nr." .  
  "</td><td align=\"left\">" . $sortLinkStart . "1" . $sortLinkMid . "Auftr.-Nr." . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "2" . $sortLinkMid . "Preis" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "3" . $sortLinkMid . "Kostenstelle" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "4" . $sortLinkMid . "Tourenname" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "5" . $sortLinkMid . "Firma" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "6" . $sortLinkMid . "Startadresse" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "7" . $sortLinkMid . "S.PLZ" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "8" . $sortLinkMid . "Z.PLZ" . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "9" . $sortLinkMid . "Fahrz." . $sortLinkEnd .
  "</td><td align=\"left\">" . $sortLinkStart . "10" . $sortLinkMid . "Auftragszeit" . $sortLinkEnd .
  "<td align=\"left\">Bearb." . ($action == 1 ? " / <input type=\"button\" name=\"actionButton3\" class=\"f8np1\" size=\"2\" value=\"Löschen\" title=\"Löschen\" onClick=\"del_jobs()\">" : "") .
  "</td>";
$output = str_replace("{_tableHeader_}", $tableHeader_output, $output);
//$tpl->setCurrentBlock("tableHeader");
//$tpl->setVariable("_tableHeader_",
//  "<td align=\"left\">Lfd. Nr." .  
//  "</td><td align=\"left\">" . $sortLinkStart . "1" . $sortLinkMid . "Auftr.-Nr." . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "2" . $sortLinkMid . "Preis" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "3" . $sortLinkMid . "Kostenstelle" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "4" . $sortLinkMid . "Tourenname" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "5" . $sortLinkMid . "Firma" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "6" . $sortLinkMid . "Startadresse" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "7" . $sortLinkMid . "S.PLZ" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "8" . $sortLinkMid . "Z.PLZ" . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "9" . $sortLinkMid . "Fahrz." . $sortLinkEnd .
//  "</td><td align=\"left\">" . $sortLinkStart . "10" . $sortLinkMid . "Auftragszeit" . $sortLinkEnd .
//  "<td align=\"left\">Bearb." . ($action == 1 ? " / <input type=\"button\" name=\"actionButton3\" class=\"f8np1\" size=\"2\" value=\"Löschen\" title=\"Löschen\" onClick=\"del_jobs()\">" : "") .
//  "</td>"
//);
//$tpl->parseCurrentBlock("tableHeader");

// Jetzt die Daueraufträge bzw. Konserven holen
// echo "[$sqlStmt]";
$result = $db2->query($sqlStmt);
if (DB::isError($result))
  reportDie ("$PHP_SELF: <br>$sqlStmt<br>" . $result->getMessage());

$ph = getPublicHolidays(getDateTime("year"), "1", "0");
$js_dates_list = "var specialDates=[\n";
$i = 1;
$jobentry_output = "";
while ($row = $result->fetch_assoc()):
//  $tpl->setCurrentBlock("jobentry");
  if ($i % 2 == 0) : $cellColor = "DDDDDD"; $cellColor2 = "EEEEEE"; endif;
  if ($i % 2 == 1) : $cellColor = "BBBBFF"; $cellColor2 = "CCCCFF"; endif;
 
  $firstLineFiller = "";
  if ($action == 3)
    $firstLineFiller = "&nbsp;<br>";    
  $jb_idLink = $firstLineFiller .
      "<a href=\"javascript:popupWindow('../admin/jb_detail.php?job_id=" . $row['jb_id'] . "','Auftrag','');\">" . $row['jb_id'] . "</a>";
  $jb_tournameLink = "";
  if (trim($row['jb_tourname']) != "")
    $jb_tournameLink = 
      "<a href=\"javascript:popupWindow('../admin/jb_detail.php?job_id=" . $row['jb_id'] . "','Auftrag','');\">" . $row['jb_tourname'] . "</a>";
  $jb_ordertimeLink = my_datum_zeit_format_datetime($row['jb_ordertime'], " ");
  if ($action == 2 || $action == 3) {
    $jb_permanent2_str = "";
    if ($row['jb_permanent'] == 1 || $row['jb_permanent'] == 2 || $row['jb_permanent'] == 3) {
      if (substr($row['jb_permanent2'], 0, 1) == "1") $jb_permanent2_str .= ", Mo";
      if (substr($row['jb_permanent2'], 1, 1) == "1") $jb_permanent2_str .= ", Di";
      if (substr($row['jb_permanent2'], 2, 1) == "1") $jb_permanent2_str .= ", Mi";
      if (substr($row['jb_permanent2'], 3, 1) == "1") $jb_permanent2_str .= ", Do";
      if (substr($row['jb_permanent2'], 4, 1) == "1") $jb_permanent2_str .= ", Fr";
      if (substr($row['jb_permanent2'], 5, 1) == "1") $jb_permanent2_str .= ", Sa";
      if (substr($row['jb_permanent2'], 6, 1) == "1") $jb_permanent2_str .= ", So";
      if ($jb_permanent2_str != "")  $jb_permanent2_str = ": " . substr($jb_permanent2_str, 2);
    }
    // Daueraufträge: Link zu einem Extra-Fenster mit den Ausführungsdaten
    $jb_ordertimeLink =
      "[" . $permanent_types[$row['jb_permanent']] . $jb_permanent2_str . "]<br>" .
      "<a href=\"javascript:mkYearCalendarWin(" . $today['year'] . "," . ($i - 1) . ");\">" .
        my_datum_zeit_format_datetime($row['jb_ordertime'], " ") . "</a><br>";
    // Zu dem aktuellen Dauerauftrag alle ordertimes der Vorgängeraufträge holen
    if ($j > 1)
      $js_dates_list .= ",\n";
    $js_dates_list .= "[";
    $j = 0;
    $jb_id_prev = $row["jb_id"];
    do {
      list($jahr, $monat, $tag, $stunde, $minute) = getValsFromDate($permanent_jobs[$jb_id_prev][1]);   // jb_ordertime des Vorgängers
      if ($j > 0)
        $js_dates_list .= ",\n";
      $js_dates_list .= "\"" . $jahr . sprintf("%02d", $monat) . sprintf("%02d", $tag) . "\"";
      if ($action == 3) {
        $jb_idLink .=
          "<br><a href=\"javascript:popupWindow('../admin/jb_detail.php?job_id=" . $permanent_jobs[$jb_id_prev][0] . "','Auftrag','');\">" . $permanent_jobs[$jb_id_prev][0] . "</a>";
        $jb_ordertimeLink .= my_datum_zeit_format_datetime($permanent_jobs[$jb_id_prev][1], " ") . "<br>";
      }
      $jb_id_prev = $permanent_jobs[$jb_id_prev][0];                   // jb_id des Vorgängers
      $j++;
    } while(array_key_exists($jb_id_prev, $permanent_jobs));           // solange bis der Vorgänger selbst keinen weiteren Vorgänger hat
    if (trim($row['jp_permenddat']) != "")
      $jb_ordertimeLink .= "<i>Enddatum: " . my_datum_zeit_format_datetime($row['jp_permenddat'], " ") . "</i><br>";
    // Zu dem aktuellen Dauerauftrag alle Ausführungsdaten berechnen, damit sie im Extra-Fenster angezeigt werden können
    list($jahr, $monat, $tag, $stunde, $minute) = getValsFromDate($row['jb_ordertime']);
    $tempDate = array($jahr, sprintf("%d", $monat), sprintf("%d", $tag));
    while($tempDate[0] <= $jahr + 1) {
      if ($j > 0)
        $js_dates_list .= ",\n";
      $js_dates_list .= "\"" . $tempDate[0] . sprintf("%02d", $tempDate[1]) . sprintf("%02d", $tempDate[2]) . "\"";
      $tempDate = getNextOrderDate($tempDate[0], $tempDate[1], $tempDate[2], $row['jb_permanent'], $row['jb_permanent2'], false);
      list($endejahr, $endemonat, $endetag, $dummy1, $dummy2) = getValsFromDate($row['jp_permenddat']);
      if (!(mktime(0, 0, 0, $tempDate[1], $tempDate[2], $tempDate[0])
        < mktime(0, 0, 0, $endemonat, $endetag, $endejahr) || trim($row['jp_permenddat']) == ""))
        break;
      $j++;
    }
    $js_dates_list .= "]\n";
  }
  if ($action == 1)
    $delBox = "&nbsp;<input type=\"checkbox\" name=\"del_" . $jb_id . "\" value=\"1\" onclick=\"toggle_del('" . $row['jb_id'] . "')\">";
  $jobentry_output .= ($jobentry_output == "" ? "" : "</tr><tr>") .
  "<td class=\"$cellColor\" align=\"center\" valign=\"top\">" . $i .
    "</td><td class=\"$cellColor2\" align=\"center\" valign=\"top\">" . $jb_idLink .
    "</td><td class=\"$cellColor\" align=\"right\" valign=\"top\">" . str_replace(".", ",", sprintf("%01.2f", $row['jb_totalprice'])) .
    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['csc_name'] .
    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $jb_tournameLink .
    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['tr_comp'] .
    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $row['streethsno'] .
    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['ad_zipcode'] .
    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $row['ad2_zipcode'] .
    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['vht_value'] .
    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $jb_ordertimeLink .
    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $firstLineFiller .
      "<a href=\"../jobs/job_edit.php?jb_id=" . ec($row['jb_id']) . "\" target=_blank>" . $row['jb_id'] . "</a>" . $delBox .
    "</td>";
//  $tpl->setVariable("_jobentry_",
//    "<td class=\"$cellColor\" align=\"center\" valign=\"top\">" . $i .
//    "</td><td class=\"$cellColor2\" align=\"center\" valign=\"top\">" . $jb_idLink .
//    "</td><td class=\"$cellColor\" align=\"right\" valign=\"top\">" . str_replace(".", ",", sprintf("%01.2f", $row['jb_totalprice'])) .
//    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['csc_name'] .
//    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $jb_tournameLink .
//    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['tr_comp'] .
//    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $row['streethsno'] .
//    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['ad_zipcode'] .
//    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $row['ad2_zipcode'] .
//    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $row['vht_value'] .
//    "</td><td class=\"$cellColor\" align=\"left\" valign=\"top\">" . $jb_ordertimeLink .
//    "</td><td class=\"$cellColor2\" align=\"left\" valign=\"top\">" . $firstLineFiller .
//      "<a href=\"../jobs/job_edit.php?jb_id=" . ec($row['jb_id']) . "\" target=_blank>" . $row['jb_id'] . "</a>" . $delBox .
//    "</td>"
//  );
  $i++;
//  $tpl->parseCurrentBlock("jobentry");
endwhile;
$result->free();
$js_dates_list .= "];\n";
$javascript = $js_dates_list .
  "\n" .
  "function finishPage(no)\n" .
  "{\n" .
  ($actionStrAlt1 == "undefined" ? "" :
    "  document.getElementsByName(\"actionButton1\")[0].disabled = true;\n"
  ) .
  "  document.getElementsByName(\"actionButton2\")[0].disabled = true;\n" .
  "  if (no == 1)\n" .
  "    self.location.href=\"../jobs/jb_special.php?csc_id=" . ec($csc_id) . "&cs_id=" . ec($cs_id) . "&action=$actionAlt1&sort=$sort\";\n" .
  "  if (no == 2)\n" .
  "    self.location.href=\"../jobs/jb_special.php?csc_id=" . ec($csc_id)  . "&cs_id=" . ec($cs_id). "&action=$actionAlt2&sort=$sort\";\n" .
  "}\n" .
  "\n" .
  "var curloc = \"../jobs/jb_special.php?csc_id=" . ec($csc_id) . "&cs_id=" . ec($cs_id) . "&action=" . $action . "&sort=" . $sort ."\"\n;" .
  "\n";

$output = str_replace("{_jobentry_}", $jobentry_output, $output);
$output = str_replace("{_javascript_}", $javascript, $output);
echo $output;
//$tpl->setCurrentBlock("javascript");
//$tpl->setVariable("_javascript_", $javascript);
//$tpl->parseCurrentBlock("javascript");

//$tpl->show();

?>
