query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
$resultArray = array();
$csIdArray = array();
$csArray = array();
while ($row = $result->fetch_assoc()):
$csIdArray[] = $row["cs_id"];
$csArray[$row["cs_id"]] = array($row["cmp_comp"], $row["cmp_comp2"], $row["cmp_comp4"], $row["cs_id_parent"], $row["cs_eid"]);
$resultArray[$row["cs_id"]] = array(0, 0, 0, 0, 0, 0);
endwhile;
$result->free();
$csIdArrayLen = count($csIdArray);
$customerOutput = "";
// Iterate all customers
for ($i = 0; $i < $csIdArrayLen; $i++) :
$csId = $csIdArray[$i];
// At least one entry per weekday
$tmpCsWeekday = array(0, 0, 0, 0, 0, 0);
// Get array of day times of the current customer
$dayTimes = getColVectorFromDB2ArrayByClause("metatype", "mt_sort", "mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csId . "'", "", "mt_sort", "");
$dayTimeNames = getColVectorFromDB2ArrayByClause("metatype", "mt_value", "mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csId . "'", "", "mt_sort", "");
$dayTimeMappedValues = getColVectorFromDB2ArrayByClause("metatype", "mt_mapped_value", "mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $csId . "'", "", "mt_sort", "");
$dayTimesLen = count($dayTimes);
// Get the vehicles for the current customer
$crvhList = array();
$sqlquery = getStmtCustomerVehicleRelation("", $csId);
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
while ($row = $result->fetch_assoc()):
$crvhList[] = $row["crvh_id"];
endwhile;
$result->free();
$crvhListLen = count($crvhList);
// Check for each vehicle displayed the existence of entries in "vehicledisposition", "vehicleavailability" and "vehicleavailabilitytimeunits".
// If it does not exist then generate it to handle the drag and dropping the jobs etc.
for ($v = 0; $v < $crvhListLen; $v++) :
$crvhId = $crvhList[$v];
$count = 0;
if ($crvhId != "") :
// Get the vehicle-customer relations of a specified courier for selection
$sqlquery = getStmtCustomerVehicleRelation($crvhId, $csId); // THIS customer only !!!!
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
while ($row = $result->fetch_assoc()):
$f_cmp_comp[$count] = $row["cmp_comp"];
$f_cmp_comp2[$count] = $row["cmp_comp2"];
$f_cs_id[$count] = $row["cs_id"];
$f_cs_eid[$count] = $row["cs_eid"];
$f_cs_hq_id[$count] = $row["hq_id"];
$f_csvh_relation[$count] = $row["csvh_relation"];
$f_csvh_day_times[$count] = $row["csvh_day_times"];
$f_csvh_description[$count] = $row["csvh_description"];
$count++;
endwhile;
$result->free();
endif;
// Only for output
$tmpFields = getFieldsValueFromId("couriervehicle", "crvh_id", $crvhId, array("cr_id","crvh_sid"));
$tmp_cr_id = $tmpFields[0];
$tmp_crvh_sid = $tmpFields[1];
$tmp_usr_id = getFieldValueFromId("courier", "cr_id", $tmp_cr_id, "usr_id");
$tmpFields = getFieldsValueFromId("user","usr_id",$tmp_usr_id,array("usr_name","usr_firstname"));
$tmp_usr_name = $tmpFields[0];
$tmp_usr_firstname = $tmpFields[1];
// Output of the existing relations of the current selected area
// $customerOutput = "";
for ($j = 0; $j < $count; $j++) :
// Overwrite array of day times if does exist for this special customer
/*
if (existsEntry("metatype",array("mt_type", "day_time", "mt_objtype", "cs", "mt_objid", $f_cs_id[$j]))) :
$dayTimes = getColVectorFromDB2ArrayByClause("metatype", "mt_sort", "mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $f_cs_id[$j] . "'", "", "mt_sort", "");
$dayTimeNames = getColVectorFromDB2ArrayByClause("metatype", "mt_value", "mt_type = 'day_time' AND mt_objtype = 'cs' AND mt_objid = '" . $f_cs_id[$j] . "'", "", "mt_sort", "");
else :
$dayTimes = getColVectorFromDB2ArrayByClause("metatype", "mt_sort", "mt_type = 'day_time' AND mt_objtype = '' AND mt_objid = '0'", "", "mt_sort", "");
$dayTimeNames = getColVectorFromDB2ArrayByClause("metatype", "mt_value", "mt_type = 'day_time' AND mt_objtype = '' AND mt_objid = '0'", "", "mt_sort", "");
endif;
$dayTimesLen = count($dayTimes);
*/
$customerOutput .= $f_cmp_comp[$j] . "
";
if ($f_cmp_comp2[$j] != "") : $customerOutput .= $f_cmp_comp2[$j] . "
"; endif;
$customerOutput .= $f_cs_eid[$j] . " - ";
$customerOutput .= $tmp_crvh_sid . " ";
$customerOutput .= $f_csvh_description[$j];
$customerOutput .= "
\n";
// Get day time values to be checked for the current customer regarding the current vehicle
$dayTimesArrayOfTheWeek = getKeyValueArrayFromString($f_csvh_day_times[$j], "|", "=");
$customerOutput .= "
\n";
// Table header with names of the weekdays
$customerOutput .= "\n";
$customerOutput .= "| " . " " . " | \n";
for ($l = 0; $l < $weekDaysLen; $l++) :
$customerOutput .= "" . $weekDayNames[$l] . " | \n";
endfor;
// Table body
$customerOutput .= "
\n";
for ($k = 0; $k < $dayTimesLen; $k++) :
$customerOutput .= "\n";
$customerOutput .= "| " . $dayTimeNames[$k] . " | \n";
for ($l = 0; $l < $weekDaysLen; $l++) :
$tmpDayTimes = $dayTimesArrayOfTheWeek[$l + 1];
$tmpDayTimesArray = spliti(",", $tmpDayTimes);
// Select special zone for each day time of each week day
$tmpSelectedValue = "";
$tmpDayTimesArrayLen = count($tmpDayTimesArray);
for ($m = 0; $m < $tmpDayTimesArrayLen; $m++) :
$tmp2 = spliti("-", $tmpDayTimesArray[$m]);
if ($tmp2[0] == $dayTimes[$k]) :
$tmpSelectedValue = $tmp2[1];
endif;
endfor;
$customerOutput .= "\n";
/*
$customerOutput .= " ";
*/
$tmptext = getLngt("Alle Zonen");
if (is_numeric($tmpSelectedValue)) :
if ($tmpSelectedValue == 9999) :
$tmptext = getLngt("Nicht aktiv");
elseif ($tmpSelectedValue > 0) :
$tmptext = getLngt("Zone") . " " . $tmpSelectedValue;
$tmpCsWeekday[$l] = 1;
endif;
else :
$tmpCsWeekday[$l] = 1;
endif;
$customerOutput .= $tmptext . "\n";
$customerOutput .= " | \n";
endfor;
$customerOutput .= "
\n";
endfor;
$customerOutput .= "
\n";
$customerOutput .= "
\n";
endfor;
if ($customerOutput == "") :
$customerOutput = getLngt("Zur Zeit sind keine Verknüpfungen eingetragen!");
endif;
endfor;
$tmpCsWeekdayLen = count($tmpCsWeekday);
for ($z = 0; $z < $tmpCsWeekdayLen; $z++) :
if ($tmpCsWeekday[$z] == 1) :
$resultArray[$csId][$z]++;
endif;
endfor;
endfor;
// **** Statistic output ****
$statisticOutputCSV = "";
$statisticOutputHTML = "";
if ($doStatistic) :
$customerOutput = ""; // Avoid standard HTML output of all vehicles as tables (!!!!)
if ($statisticOutputMode == "1") :
$statisticOutputCSV .= "KST;EID;Preisgruppe;Markt;Montag;Dienstag;Mittwoch;Donnerstag;Freitag;Sonnabend;\n";
for ($i = 0; $i < $csIdArrayLen; $i++) :
$csId = $csIdArray[$i];
$pg = "1";
if ($csArray[$csId][3] == "40513") : $pg = "2"; endif;
if ($csArray[$csId][3] == "40514") : $pg = "3"; endif;
$statisticOutputCSV .= $csArray[$csId][2] . ";" . $csArray[$csId][4] . ";" . $pg . ";" . $csArray[$csId][1] . ";"
. $resultArray[$csId][0] . ";" . $resultArray[$csId][1] . ";" . $resultArray[$csId][2] . ";" . $resultArray[$csId][3] . ";" . $resultArray[$csId][4] . ";" . $resultArray[$csId][5] . ";\n";
endfor;
else :
$statisticOutputHTML .= "\n";
$statisticOutputHTML .= "\n";
$statisticOutputHTML .= "| " . "KST" . " | \n";
$statisticOutputHTML .= "" . "EID" . " | \n";
$statisticOutputHTML .= "" . "Preisgruppe" . " | \n";
$statisticOutputHTML .= "" . "Markt" . " | \n";
$statisticOutputHTML .= "" . "Montag" . " | \n";
$statisticOutputHTML .= "" . "Dienstag" . " | \n";
$statisticOutputHTML .= "" . "Mittwoch" . " | \n";
$statisticOutputHTML .= "" . "Donnerstag" . " | \n";
$statisticOutputHTML .= "" . "Freitag" . " | \n";
$statisticOutputHTML .= "" . "Sonnabend" . " | \n";
$statisticOutputHTML .= "
\n";
// Iterate all customers
for ($i = 0; $i < $csIdArrayLen; $i++) :
$csId = $csIdArray[$i];
$pg = "1";
if ($csArray[$csId][3] == "40513") : $pg = "2"; endif;
if ($csArray[$csId][3] == "40514") : $pg = "3"; endif;
$statisticOutputHTML .= "\n";
$statisticOutputHTML .= "| " . $csArray[$csId][2] . " | \n"; // cmp_comp4
$statisticOutputHTML .= "" . $csArray[$csId][4] . " | \n"; // cs_eid
$statisticOutputHTML .= "" . $pg . " | \n";
$statisticOutputHTML .= "" . $csArray[$csId][1] . " | \n"; // cmp_comp2
$statisticOutputHTML .= "" . $resultArray[$csId][0] . " | \n";
$statisticOutputHTML .= "" . $resultArray[$csId][1] . " | \n";
$statisticOutputHTML .= "" . $resultArray[$csId][2] . " | \n";
$statisticOutputHTML .= "" . $resultArray[$csId][3] . " | \n";
$statisticOutputHTML .= "" . $resultArray[$csId][4] . " | \n";
$statisticOutputHTML .= "" . $resultArray[$csId][5] . " | \n";
$statisticOutputHTML .= "
\n";
endfor;
$statisticOutputHTML .= "
";
endif;
endif;
if ($statisticOutputMode == "1") :
echo $statisticOutputCSV;
endif;
?>