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

// tr_status (falls verändert von 0 auf 1, wenn Datum leer)
// cr_sid Änderung (auch tr_cs_freetext)
// tour mit nur Endadresse verhindern
// Auftrag verschieben für einzelne cr_sids
// wenn S1999 gleich Storno

define("LOG_NAME", "edit_job");

include_once("../include/dbconnect.inc.php");
include_once("../include/auth.inc.php");
define("LOG_NAME", "edit_job");
include_once("../tools/edi.inc.php");

if (trim($HTTP_GET_VARS["track_id"]) != ''):
  $track_id = $HTTP_GET_VARS["track_id"];
else:
  $f_formsubmit = isset($_POST["formsubmit"]) ? $_POST["formsubmit"] : "";  
endif;

$msg_txt = "";
$msg_txts = array();
$restore_jb_id = 0;
$restore_cr_sid = "";
if ($f_formsubmit == "Speichern"):
  $track_id = isset($_POST["f_track_id"]) ? $_POST["f_track_id"] : "";
  $f_jb_id = isset($_POST["f_jb_id"]) ? $_POST["f_jb_id"] : "";
  $f_tr_sort_max = isset($_POST["f_tr_sort_max"]) ? $_POST["f_tr_sort_max"] : "";
  $f_cr_sid = isset($_POST["f_cr_sid"]) ? $_POST["f_cr_sid"] : "";
  $f_cr_sid_old = isset($_POST["f_cr_sid_old"]) ? $_POST["f_cr_sid_old"] : "";
  $f_jb_ordertime = isset($_POST["f_jb_ordertime"]) ? $_POST["f_jb_ordertime"] : "";
  $updateStmts = array();
  $jb_status = 2;
  $f_tr_finishtime_max = "1970-01-01 00:00:00";
  for ($i = 1; $i <= $f_tr_sort_max; $i++):
    $msg_txts[$i] = "";
    $f_trat_id = isset($_POST["f_trat_id$i"]) ? $_POST["f_trat_id$i"] : "";
    $f_tr_status = isset($_POST["f_tr_status$i"]) ? $_POST["f_tr_status$i"] : "";
    $f_tr_status_ori = $f_tr_status;
    $f_tr_finishtime = isset($_POST["f_tr_finishtime$i"]) ? $_POST["f_tr_finishtime$i"] : "";
    $f_tr_finishtime_ori = $f_tr_finishtime;
    $f_tr_finishtime = ($f_tr_finishtime != "" ? sqlDate($f_tr_finishtime) . " " . substr($f_tr_finishtime, 11, 8) : "");
    $f_tr_finishtime_old = isset($_POST["f_tr_finishtime_old$i"]) ? $_POST["f_tr_finishtime_old$i"] : "";
    $f_tr_commission_no = isset($_POST["f_tr_commission_no$i"]) ? $_POST["f_tr_commission_no$i"] : "";
    $f_tr_commission_no_old = isset($_POST["f_tr_commission_no_old$i"]) ? $_POST["f_tr_commission_no_old$i"] : "";
    $f_tr_signname = isset($_POST["f_tr_signname$i"]) ? $_POST["f_tr_signname$i"] : "";
    $f_tr_signname_old = isset($_POST["f_tr_signname_old$i"]) ? $_POST["f_tr_signname_old$i"] : "";
    $f_tr_cs_freetext = isset($_POST["f_tr_cs_freetext$i"]) ? $_POST["f_tr_cs_freetext$i"] : "";
    $f_tr_cs_freetext_old = isset($_POST["f_tr_cs_freetext_old$i"]) ? $_POST["f_tr_cs_freetext_old$i"] : "";
    $restore_values[$i] = array("tr_finishtime" => $f_tr_finishtime_old, "tr_commission_no" => $f_tr_commission_no_old,
      "tr_signname" => $f_tr_signname_old, "tr_cs_freetext" => $f_tr_cs_freetext_old);
    // Auf Änderungen in `tour` checken
    if ($f_tr_status != 1):
      $restore_values[$i] = array("tr_finishtime" => $f_tr_finishtime, "tr_commission_no" => $f_tr_commission_no,
        "tr_signname" => $f_tr_signname, "tr_cs_freetext" => $f_tr_cs_freetext);
      $updateStmt = "";
      $delete_old_process = false;
      if ($f_tr_finishtime != $f_tr_finishtime_old):
        if (date('Y-m-d H:i:s', strtotime($f_tr_finishtime)) != $f_tr_finishtime):
          $msg_txts[$i] = "Ung&uuml;ltige Datums-/Zeitangabe: '" . $f_tr_finishtime_ori . "'<br>\n";
        elseif (strtotime($f_tr_finishtime) > time()):
          $msg_txts[$i] = "Datums-/Zeitangabe liegt in der Zukunft: '" . $f_tr_finishtime_ori . "'<br>\n";
  //      elseif (strtotime($f_tr_finishtime) < strtotime($f_jb_ordertime)):
  //        $msg_txts[$i] = "Datums-/Zeitangabe liegt vor dem Auftragsdatum: '" . $f_tr_finishtime_ori . "'<br>\n";
        else:
          $updateStmt .= "tr_finishtime = '$f_tr_finishtime', ";
          if ($f_tr_status_ori != 1):
            $updateStmt .= "tr_status = 1, ";
            $f_tr_status = 1;
          else:
            writeLog("'$f_tr_finishtime' != '$f_tr_finishtime_old'");
            $delete_old_process = true;
          endif;
        endif;
      endif;
      $f_tr_finishtime_max = (strtotime($f_tr_finishtime) > strtotime($f_tr_finishtime_max) ? $f_tr_finishtime : $f_tr_finishtime_max);
      if ($f_tr_commission_no != $f_tr_commission_no_old):
        $updateStmt .= "tr_commission_no = '$f_tr_commission_no:MAN', ";
        writeLog("'$f_tr_commission_no' != '$f_tr_commission_no_old'");
        $delete_old_process = true;
      endif;
      if ($f_tr_signname != $f_tr_signname_old):
        $updateStmt .= "tr_signname = '$f_tr_signname', ";
      endif;
      if ($f_tr_cs_freetext != $f_tr_cs_freetext_old):
  //      $updateStmt .= "tr_cs_freetext = '$f_tr_cs_freetext', ";
      endif;
      if ($delete_old_process && $f_trat_id != "" && $f_tr_status_ori == 1):
        $updateStmts[] = "DELETE FROM tourarticleprocess WHERE trat_id = $f_trat_id AND tratp_createtime = '$f_tr_finishtime_old'";
      endif;
      if ($updateStmt != ""):
        $updateStmts[] = "UPDATE tour SET " . substr($updateStmt, 0, -2) . " WHERE jb_id = $f_jb_id AND tr_sort = $i";
      endif;
    endif;
  //echo $i . "-" . $f_tr_status . "<br>\n";
    if ($f_tr_status != 1 && $f_tr_status != ""):
      $jb_status = 1;
    endif;
  //echo $i . "-" . $jb_status . "<br>\n";
  endfor;
  // Auf Änderungen in `job` checken
  $updateStmt = "";
  if ($f_cr_sid != $f_cr_sid_old):
    $sqlquery = "SELECT courier.cr_id FROM couriervehicle, courier WHERE couriervehicle.cr_id = courier.cr_id AND hq_id = " . $hq_id . " AND crvh_sid = '$f_cr_sid'";
    $res = $db->query($sqlquery);
    if (DB::isError($res)) die ("$PHP_SELF: [$sqlquery] " . $res->getMessage());
    if ($row = $res->fetch_assoc()):
      $updateStmt .= "cr_sid = '$f_cr_sid', cr_id = " . $row["cr_id"] . ", cr_id_order = " . $row["cr_id"] . ", ";
      $res->free();
    else:
     $msg_txt .= "Ung&uuml;ltige Fahrernummer: '" . $f_cr_sid . "'<br>\n";
     $restore_cr_sid = $f_cr_sid;
    endif;
  endif;  
  if ($jb_status == 2 && count($updateStmts) > 0):
    $updateStmt .= "jb_status = 2, jb_finishtime = '" . $f_tr_finishtime_max . "', ";
  endif;
  if ($updateStmt != ""):
    $updateStmts[] = "UPDATE job SET " . substr($updateStmt, 0, -2) . " WHERE jb_id = $f_jb_id";
  endif;
  $tmp_arr = array_count_values($msg_txts);
  if (count($msg_txts) != $tmp_arr[""] || $msg_txt != ""):
    $msg_txt = "Bitte vor dem Speichern Fehler beheben!<br>\n" . $msg_txt;
  endif;

  // UPDATE-Statements ausführen
  if ($msg_txt == ""):
    if (count($updateStmts) > 0):
      foreach ($updateStmts as $updateStmt) {
        writeLog("[$updateStmt]");
        $db->query($updateStmt);
      }
      $msg_txt = "Die &Auml;nderungen wurden gespeichert.";
    else:
      $msg_txt = "Es wurden keine &Auml;nderungen vorgenommen.";
    endif;
  else:
    $restore_jb_id = $f_jb_id;
  endif;
endif;

if ($track_id != ""):
  $sqlquery =
    "SELECT job.jb_id, cr_sid, jb_ordertime, jb_status FROM tourarticle, job" .
    " WHERE trat_serialno = '" . $track_id . "' AND job.jb_id = tourarticle.jb_id" .
    " AND tr_sort > 1 AND csc_id_payer IN " . $csc_id_sql[$hq_id] . " ORDER BY job.jb_id desc";
  $res = $db->query($sqlquery);
  if (DB::isError($res)) die ("$PHP_SELF: [$sqlquery] " . $res->getMessage());
  $content = "";
  while ($row = $res->fetch_assoc()):
    $tmp_content = "";
    $sqlquery =
      "SELECT trat_id, trat_serialno, tr.tr_sort, tr_comp, tr_comp2, tr_person, tr_phone, tr_status, tr_signname," .
      " tr_finishtime, tr_commission_no, tr_cs_freetext, ad_street, tr_hsno, ad_zipcode, ad_city" .
      " FROM address AS ad, tour AS tr LEFT JOIN tourarticle AS ta ON (ta.jb_id = tr.jb_id AND ta.tr_sort = tr.tr_sort)" .
      " WHERE tr.jb_id = " . $row["jb_id"] . " AND tr.ad_id = ad.ad_id ORDER BY tr.tr_sort";
    $res1 = $db->query($sqlquery);
    if (DB::isError($res1)) die ("$PHP_SELF: [$sqlquery] " . $res1->getMessage());
    $i = 1;
    while ($row1 = $res1->fetch_assoc()):
      if ($row1["tr_sort"] > 1 || $i++ == 1):
        $row2 = $row1;
        if ($restore_jb_id == $row["jb_id"]):
          $row2["tr_finishtime"] = $restore_values[$row2["tr_sort"]]["tr_finishtime"];
          $row2["tr_commission_no"] = $restore_values[$row2["tr_sort"]]["tr_commission_no"];
          $row2["tr_signname"] = $restore_values[$row2["tr_sort"]]["tr_signname"];
          $row2["tr_cs_freetext"] = $restore_values[$row2["tr_sort"]]["tr_cs_freetext"];
        else:
          $tcn_parts = explode(":", $row1["tr_commission_no"]);
          if (count($tcn_parts) > 1):
            $row1["tr_commission_no"] = trim($tcn_parts[0]) . ":" . trim($tcn_parts[1]);
          endif;
        endif;
        $tmp_content .= mk_station($row2, $row1);
      endif;
      $tr_sort_max = $row1["tr_sort"];
    endwhile;
    $res1->free();

    if ($msg_txt != ""):
      $msg_txt =
        "<br><br>" . $msg_txt;
    endif;

    $content .=
      "  <tr>\n" .
      "  	<td align=\"center\" colspan=\"3\"><div class=\"f10bp1_blue\">\n" .
      "      <br>\n" .
      "      Auftrag Nr. " . $row["jb_id"] . "<br><br>Eingestellt am " . formDate($row["jb_ordertime"]) . " um " . substr($row["jb_ordertime"], 11, 8) . " Uhr<br>\n" .
      "      </div>\n" .
      "    </td>\n" .
      "  </tr>\n" .
      "  <tr>\n" .
      "  	<td align=\"center\" colspan=\"3\"><div class=\"f10bp1_blue\">\n" .
      "      <form name=\"edit_job\" action=\"edit_job.php\" method=\"post\">\n" .
      "      <input type=\"hidden\" name=\"f_track_id\" value=\"$track_id\">\n" .
      "      <input type=\"hidden\" name=\"f_jb_id\" value=\"" . $row["jb_id"] . "\">\n" .
      "      <input type=\"hidden\" name=\"f_tr_sort_max\" value=\"$tr_sort_max\">\n" .
      "      <input type=\"hidden\" name=\"f_cr_sid_old\" value=\"" . $row["cr_sid"] . "\">\n" .
      "      <input type=\"hidden\" name=\"f_jb_ordertime\" value=\"" . $row["jb_ordertime"] . "\">\n" .
      "      Fahrer: <input name=\"f_cr_sid\" type=\"text\" size=\"4\" maxlength=\"6\" class=\"input\" value=\"" . ($restore_cr_sid == "" ? $row["cr_sid"] : $restore_cr_sid) . "\">&nbsp;\n" .
      "      <span style=\"color:red\">" . $msg_txt . "</span></div>" .
      "    </td>\n" .
      "  </tr>\n" .
      "  <tr>\n" .
      "    <td align=left><div class=\"f7np1\"><span style=\"color:#1b12b9\"><b>Station</b></span>&nbsp;</div></td>" .
      "    <td align=left><div class=\"f7np1\"><span style=\"color:#1b12b9\"><b>Erledigung: Datum/Uhrzeit, Art, Klartext</b></span>&nbsp;</div></td>" .
      "    <td align=left><div class=\"f7np1\"><span style=\"color:#1b12b9\"><b>Fahrer</b>&nbsp;</span>&nbsp;</div></td>" .
      "  </tr>\n" .
      $tmp_content .
      "  <tr>\n" .
      "  	<td align=\"center\" colspan=\"3\">\n" .
      "      &nbsp;<br>\n" .
      "      <input type=\"submit\" name=\"formsubmit\" size=\"2\" value=\"Speichern\" class=\"submit\"><br>\n" .
	    "      &nbsp;<br>\n" .
	    "      &nbsp;<br>\n" .
      "      </form>\n" .
      "    </td>\n" .
      "  </tr>\n";
  endwhile;
  $res->free();
//  else:
//    $msg_txt .= "<span style=\"color:red\">" . "Tracking-ID nicht gefunden: '$track_id'" . "</span><br>\n";
//  endif;
else:
  $content = "<span style=\"color:red\">" . "Parameter 'track_id' fehlt" . "</span><br>\n";
endif;

function mk_station($row1, $row2) {
  global $track_id, $msg_txts;

	$tmp_content = "";
  if ($row1["tr_sort"] == 1):
    $row1["trat_serialno"] = "";
  endif;
  $tr_commission_no_deactivated = "";
  $tr_cs_freetext_deactivated = "";
  if ($row1["tr_status"] != 1):
    if ($row1["tr_sort"] % 2 == 0) : $cellColor = "#FFBBBB"; $cellColor2 = "#FFCCCC"; endif;
    if ($row1["tr_sort"] % 2 == 1) : $cellColor = "#FF9999"; $cellColor2 = "#FFAAAA"; endif;
  else:
    if ($row1["tr_sort"] % 2 == 0) : $cellColor = "#DDDDDD"; $cellColor2 = "#EEEEEE"; endif;
    if ($row1["tr_sort"] % 2 == 1) : $cellColor = "#BBBBFF"; $cellColor2 = "#CCCCFF"; endif;
    $tr_commission_no_deactivated = "disabled";
    $tr_finishtime_deactivated = "disabled";
  endif;
  $tmp_content .= 
    "  <tr>" .
    "    <td bgcolor=\"$cellColor\" align=\"left\">";
  if ($track_id == $row1["trat_serialno"])
    $tmp_content .= "<span style=\"color:red\">";
  $tmp_content .= $row1["tr_sort"] . ": " . (trim($row1["trat_serialno"]) != "" ? ($row1["trat_serialno"] . " - " . $row1["tr_comp2"]) : "");
  $tmp_content .= "<br>\n";
  $tmp_content .= "<b>" . $row1["tr_comp"];
  if (trim($row1["tr_person"]) != ""):
    $tmp_content .= ", " . $row1["tr_person"];
  endif;
  $tmp_content .= "<br>\n";
  $tmp_content .= $row1["ad_zipcode"] . " " . $row1["ad_city"];
  $tmp_content .= ", " . $row1["ad_street"] . " " . $row1["tr_hsno"] . "</b><br>\n";
  if (trim($row1["tr_phone"]) != ""):
    $tmp_content .= "Tel.: " . $row1["tr_phone"] . "<br>\n";
  endif;
  if ($track_id == $row1["trat_serialno"])
    $tmp_content .= "</span>";
  $tr_commission_no = "";
  if ($row1["ad_zipcode"] . $row1["ad_city"] . $row1["ad_street"] . $row1["tr_hsno"] == "71229LeonbergHertichstraße10"):
    $tr_commission_no_deactivated = "disabled";
//    $tr_cs_freetext_deactivated = "disabled";
  else:
    $tcn_parts = explode(":", $row1["tr_commission_no"]);
    $tr_commission_no = trim($tcn_parts[0]) . ":" . trim($tcn_parts[1]);
  endif;
$tr_cs_freetext_deactivated = "disabled";
  $tr_commission_no_select = 
    "<select name=\"f_tr_commission_no" . $row1["tr_sort"] . "\" size=\"1\" class=\"input\" " . $tr_commission_no_deactivated . ">\n" .
    "  <option value=\"\"" . ($tr_commission_no == ":" ? " selected" : "") . "></option>\n" .
    "  <option value=\"301:AS_INSTRUCTED\"" . ($tr_commission_no == "301:AS_INSTRUCTED" ? " selected" : "") . ">laut Anweisung</option>\n" .
    "  <option value=\"301:CARPORT\"" . ($tr_commission_no == "301:CARPORT" ? " selected" : "") . ">Carport</option>\n" .
    "  <option value=\"301:DECK\"" . ($tr_commission_no == "301:DECK" ? " selected" : "") . ">Terasse</option>\n" .
    "  <option value=\"301:DOCK\"" . ($tr_commission_no == "301:DOCK" ? " selected" : "") . ">Verladerampe</option>\n" .
    "  <option value=\"301:FRONT_DESK\"" . ($tr_commission_no == "301:FRONT_DESK" ? " selected" : "") . ">Rezeption</option>\n" .
    "  <option value=\"301:FRONT_DOOR\"" . ($tr_commission_no == "301:FRONT_DOOR" ? " selected" : "") . ">Haustür</option>\n" .
    "  <option value=\"301:GARAGE\"" . ($tr_commission_no == "301:GARAGE" ? " selected" : "") . ">Garage</option>\n" .
    "  <option value=\"301:GUARD\"" . ($tr_commission_no == "301:GUARD" ? " selected" : "") . ">Wachmann</option>\n" .
    "  <option value=\"301:MAILBOX\"" . ($tr_commission_no == "301:MAILBOX" ? " selected" : "") . ">Briefkasten</option>\n" .
    "  <option value=\"301:MAIL_ROOM\"" . ($tr_commission_no == "301:MAIL_ROOM" ? " selected" : "") . ">Poststelle</option>\n" .
    "  <option value=\"301:MAIL_SLOT\"" . ($tr_commission_no == "301:MAIL_SLOT" ? " selected" : "") . ">Briefschlitz</option>\n" .
    "  <option value=\"301:MC_BOY\"" . ($tr_commission_no == "301:MC_BOY" ? " selected" : "") . ">Junge</option>\n" .
    "  <option value=\"301:MC_GIRL\"" . ($tr_commission_no == "301:MC_GIRL" ? " selected" : "") . ">Mädchen</option>\n" .
    "  <option value=\"301:MC_MAN\"" . ($tr_commission_no == "301:MC_MAN" ? " selected" : "") . ">Mann</option>\n" .
    "  <option value=\"301:MC_WOMAN\"" . ($tr_commission_no == "301:MC_WOMAN" ? " selected" : "") . ">Frau</option>\n" .
    "  <option value=\"301:NEIGHBOR\"" . ($tr_commission_no == "301:NEIGHBOR" ? " selected" : "") . ">Nachbar</option>\n" .
    "  <option value=\"301:OFFICE\"" . ($tr_commission_no == "301:OFFICE" ? " selected" : "") . ">Büro</option>\n" .
    "  <option value=\"301:OUTBUILDING\"" . ($tr_commission_no == "301:OUTBUILDING" ? " selected" : "") . ">Nebengebäude</option>\n" .
    "  <option value=\"301:PATIO\"" . ($tr_commission_no == "301:PATIO" ? " selected" : "") . ">Innenhof</option>\n" .
    "  <option value=\"301:PORCH\"" . ($tr_commission_no == "301:PORCH" ? " selected" : "") . ">Veranda</option>\n" .
    "  <option value=\"301:REAR_DOOR\"" . ($tr_commission_no == "301:REAR_DOOR" ? " selected" : "") . ">Hintereingang</option>\n" .
    "  <option value=\"301:RECEIVER\"" . ($tr_commission_no == "301:RECEIVER" ? " selected" : "") . ">Bewohner</option>\n" .
    "  <option value=\"301:RECEPTIONIST\"" . ($tr_commission_no == "301:RECEPTIONIST" ? " selected" : "") . ">Empfang</option>\n" .
    "  <option value=\"301:SECURE_LOCATION\"" . ($tr_commission_no == "301:SECURE_LOCATION" ? " selected" : "") . ">sicherer Ort</option>\n" .
    "  <option value=\"301:SIDE_DOOR\"" . ($tr_commission_no == "301:SIDE_DOOR" ? " selected" : "") . ">Nebeneingang</option>\n" .
    "  <option value=\"301:LEASING_OFFICE\"" . ($tr_commission_no == "301:LEASING_OFFICE" ? " selected" : "") . ">Leasing-Büro</option>\n" .
    "  <option value=\"304:\"" . ($tr_commission_no == "304:" ? " selected" : "") . ">Lieferversuch, gescheitert</option>\n" .
    "  <option value=\"401:\"" . ($tr_commission_no == "401:" ? " selected" : "") . ">Adresse falsch</option>\n" .
    "  <option value=\"403:\"" . ($tr_commission_no == "403:" ? " selected" : "") . ">Unbekannt verzogen</option>\n" .
    "  <option value=\"407:\"" . ($tr_commission_no == "407:" ? " selected" : "") . ">Annahme verweigert</option>\n" .
    "</select>\n";
  $row1_tr_sort = $row1["tr_sort"];
  $tmp_content .=
    "    </td>\n" .
    "    <td bgcolor=\"$cellColor2\" align=\"left\">\n" .
    "<input type=\"hidden\" name=\"f_trat_id" . $row1["tr_sort"] . "\" value=\"" . $row1["trat_id"] . "\">\n" .
    "<input type=\"hidden\" name=\"f_tr_status" . $row1["tr_sort"] . "\" value=\"" . $row1["tr_status"] . "\">\n" .
    "<input type=\"hidden\" name=\"f_tr_finishtime_old" . $row1["tr_sort"] . "\" value=\"" . $row2["tr_finishtime"] . "\">\n" .
    "<input type=\"hidden\" name=\"f_tr_commission_no_old" . $row1["tr_sort"] . "\" value=\"" . $row2["tr_commission_no"] . "\">\n" .
    "<input type=\"hidden\" name=\"f_tr_signname_old" . $row1["tr_sort"] . "\" value=\"" . $row2["tr_signname"] . "\">\n" .
    "<input type=\"hidden\" name=\"f_tr_cs_freetext_old" . $row1["tr_sort"] . "\" value=\"" . $row2["tr_cs_freetext"] . "\">\n" .
    "<input name=\"f_tr_finishtime" . $row1["tr_sort"] . "\" type=\"text\" size=\"18\" maxlength=\"19\" class=\"input\" value=\"" .
    ($row1["tr_finishtime"] != "" ? formDate($row1["tr_finishtime"]) . " " . substr($row1["tr_finishtime"], 11, 8) : "") .
    "\" " . $tr_finishtime_deactivated . ">&nbsp;" .
    $tr_commission_no_select . "&nbsp;\n" .
    "<input name=\"f_tr_signname" . $row1["tr_sort"] . "\" type=\"text\" size=\"20\" maxlength=\"50\" class=\"input\" value=\"" . $row1["tr_signname"] .
    "\" " . $tr_finishtime_deactivated . ">&nbsp;\n" .    
    (isset($msg_txts[$row1_tr_sort]) ? "<br>\n<b><span style=\"color:red\">" . $msg_txts[$row1_tr_sort] . "</b></span>" : "") .
    "    </td>\n" .
    "    <td bgcolor=\"$cellColor\" align=\"left\">\n" .
    "<input name=\"f_tr_cs_freetext" . $row1["tr_sort"] . "\" type=\"text\" size=\"4\" maxlength=\"6\" class=\"input\" value=\"" . $row1["tr_cs_freetext"] . "\" " . $tr_cs_freetext_deactivated . ">&nbsp;\n" .
    "    </td>\n" .
    "  </tr>\n";
  return $tmp_content;
}

function formDate($sqlDate) {
	if (trim($sqlDate) == "")
	  return "";
  return substr($sqlDate, 8, 2) . "." . substr($sqlDate, 5, 2) . "." . substr($sqlDate, 0, 4);
}

function sqlDate($germanDate) {
	if (trim($germanDate) == "")
	  return "";
  return substr($germanDate, 6, 4) . "-" . substr($germanDate, 3, 2) . "-" . substr($germanDate, 0, 2);
}

//function writeLog($log_text)
//{
//  $today = getdate();
//  $fileHandle = @fopen("../log/amazon_" . $today['year'] . sprintf("%02d", $today['mon']) . ".log", 'a');
//  @fwrite($fileHandle, "[" . date("Y-m-d H:i:s") . "] [" . LOG_NAME . "] " . $log_text .  "\n");
//  @fclose($fileHandle);
//  return;
//}

?>

<html>
<head>
  <title>AUFTRAGSBEARBEITUNG</title>
  <link rel="stylesheet" type="text/css" href="../css/phoenix.css"> 
</head>
<body>
  <table border="0" width="100%" cellspacing="0" cellpadding="0" vspace="0" hspace="0">
    <tr>
      <td>
        &nbsp;
      </td>
      <td align="center">
        <table border="0" cellspacing="0" cellpadding="4" vspace="0" hspace="0">
          <?php echo $content;?>
        </table>
      </td>
      <td>
        &nbsp;
      </td>
    </tr>
  </table>
</body>
</html>
