query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); while ($row = $result->fetch_assoc()): if ($zipcodeRow == "") : $zipcodeRow = $row["plz"]; endif; if ($zipcodeCol == "") : $zipcodeCol = $row["plz"]; endif; endwhile; $result->free(); endif; // ******************************************************* // * Selection of all plz of the specified submatrix-row * // ******************************************************* $sqlquery = "SELECT srvp.srvp_id, srvp.srvp_plz" . " FROM serviceplz AS srvp" . " WHERE srvp.srvp_plz >= '" . $zipcodeRow . "' AND " . " srvp.srvp_valid = '1' " . " ORDER BY " . $orderByServices . " LIMIT " . $offset; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $services = array(); $count = 0; while ($row = $result->fetch_assoc()): $count++; $services["id"][$count] = $row["srvp_id"]; $services["plz"][$count] = $row["srvp_plz"]; endwhile; $result->free(); // ********************************************************** // * Selection of all plz of the specified submatrix-column * // ********************************************************** $sqlquery = "SELECT srvp.srvp_id, srvp.srvp_plz" . " FROM serviceplz AS srvp" . " WHERE srvp.srvp_plz >= '" . $zipcodeCol . "' AND " . " srvp.srvp_valid = '1' " . " ORDER BY " . $orderByServices . " LIMIT " . $offset; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $services2 = array(); $count = 0; while ($row = $result->fetch_assoc()): $count++; $services2["id"][$count] = $row["srvp_id"]; $services2["plz"][$count] = $row["srvp_plz"]; endwhile; $result->free(); // ****************************************** // * Selection of serviceplzcustomer-values * // ****************************************** $sqlquery = "SELECT srvpc.srvp_id, srvpc.srvp2_id, srvpc.cs_id, srvpc.srvpc_price, srvpc.srvpc_discount, srvpc.srvpc_cr_price, srvpc.srvpc_cr_discount" . " FROM serviceplz AS srvp, serviceplz AS srvp2, serviceplzcustomer AS srvpc" . " WHERE srvpc.srvp_id = srvp.srvp_id" . " AND srvpc.srvp2_id = srvp2.srvp_id" . " AND srvpc.cs_id = " . $csId . " AND srvpc.vht_id = " . $vhtId . " AND srvpc.hq_id = " . $hq_id . " ORDER BY " . $orderByServices; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $servicePrices = array(); $serviceDiscounts = array(); while ($row = $result->fetch_assoc()): $servicePrices[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_price"]; $serviceDiscounts[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_discount"]; $serviceCrPrices[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_cr_price"]; $serviceCrDiscounts[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_cr_discount"]; endwhile; $result->free(); // Number of entries $lenServices = count($services["id"]); $lenServices2 = count($services2["id"]); if ($services["id"][1] == "" || $services2["id"][1] == ""): $lenServices = 0; $lenServices2 = 0; endif; // If matrix (generated above) is from a special customer ($csId != "0"), the default prices ($csId == "0") have to be shown to compare the prices // Setup a second request according to the one before with ($csId == "0") if ($csId != "0") : $sqlquery = "SELECT srvpc.srvp_id, srvpc.srvp2_id, srvpc.cs_id, srvpc.srvpc_price, srvpc.srvpc_discount, srvpc.srvpc_cr_price, srvpc.srvpc_cr_discount" . " FROM serviceplz AS srvp, serviceplz AS srvp2, serviceplzcustomer AS srvpc" . " WHERE srvpc.srvp_id = srvp.srvp_id" . " AND srvpc.srvp2_id = srvp2.srvp_id" . " AND srvpc.cs_id = '0'" . " AND srvpc.vht_id = " . $vhtId . " AND srvpc.hq_id = " . $hq_id . " ORDER BY " . $orderByServices; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $servicePricesDefault = array(); $serviceDiscountsDefault = array(); while ($row = $result->fetch_assoc()): $servicePricesDefault[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_price"]; $serviceDiscountsDefault[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_discount"]; $serviceCrPricesDefault[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_cr_price"]; $serviceCrDiscountsDefault[$row["srvp_id"]][$row["srvp2_id"]] = $row["srvpc_cr_discount"]; endwhile; $result->free(); endif; // *** Storing-processes *** // *** BEGIN *************** // Storing prices and discounts if requested // Using the results of the statements before!!! if ($f_act != "" && $f_act == "save") : // Set the current timestamp to store the data $currentTime = getDateTime("0"); TA("B"); for ($i = 1; $i <= $lenServices2; $i++) : for ($j = 1; $j <= $lenServices; $j++) : // Define current service-plz-ids $srvPlzCur = $services["id"][$j]; $srvp2PlzCur = $services2["id"][$i]; // Get current input-type-text-field with price-/dicount-value list ($newValueToBeStored) = getHttpVars(array("service_". $srvPlzCur ."_" . $srvp2PlzCur)); if ($newValueToBeStored == "") : $newValueToBeStored = "0"; endif; list ($newCrValueToBeStored) = getHttpVars(array("service_cr_". $srvPlzCur ."_" . $srvp2PlzCur)); if ($newCrValueToBeStored == "") : $newCrValueToBeStored = "0"; endif; // Allow float data with "." and "," $newValueToBeStored = str_replace (",", ".", $newValueToBeStored); $newCrValueToBeStored = str_replace (",", ".", $newCrValueToBeStored); $servicePrices[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($servicePrices[$srvPlzCur], $srvp2PlzCur); $serviceDiscounts[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceDiscounts[$srvPlzCur], $srvp2PlzCur); $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrPrices[$srvPlzCur], $srvp2PlzCur); $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrDiscounts[$srvPlzCur], $srvp2PlzCur); if ($servicePrices[$srvPlzCur][$srvp2PlzCur] == "") : $servicePrices[$srvPlzCur][$srvp2PlzCur] = "0"; endif; if ($serviceDiscounts[$srvPlzCur][$srvp2PlzCur] == "") : $serviceDiscounts[$srvPlzCur][$srvp2PlzCur] = "0"; endif; if ($serviceCrPrices[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] = "0"; endif; if ($serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] = "0"; endif; if ($mode == "price") : // Check for necessity to update or insert if ($servicePrices[$srvPlzCur][$srvp2PlzCur] != $newValueToBeStored || $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] != $newCrValueToBeStored) : if (existsEntry("serviceplzcustomer",array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId))) : // Update the new price $sqlStmt = "UPDATE serviceplzcustomer SET srvpc_price = $newValueToBeStored, srvpc_cr_price = $newCrValueToBeStored" . " WHERE srvp_id = $srvPlzCur AND srvp2_id = $srvp2PlzCur AND hq_id = $hq_id AND cs_id = $csId AND vht_id = $vhtId"; $res = $db->query($sqlStmt); if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif; else : if ($newValueToBeStored != "0" || $newCrValueToBeStored != "0") : // Insert the new price $tmpFields = array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId,"srvpc_price",$newValueToBeStored,"srvpc_discount",$serviceDiscounts[$srvPlzCur][$srvp2PlzCur],"srvpc_cr_price",$newCrValueToBeStored,"srvpc_cr_discount",$serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur]); insertStmt("serviceplzcustomer",$tmpFields); endif; endif; // Insert current prices AND (!) discounts into the servicehistory $tmpFields = array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId,"usr_id",$currentSessionUsrId,"srvph_validfrom",$currentTime,"srvph_price",$newValueToBeStored,"srvph_discount",$serviceDiscounts[$srvPlzCur][$srvp2PlzCur],"srvph_cr_price",$newCrValueToBeStored,"srvph_cr_discount",$serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur]); insertStmt("serviceplzhistory",$tmpFields); $servicePrices[$srvPlzCur][$srvp2PlzCur] = $newValueToBeStored; $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] = $newCrValueToBeStored; endif; else : // Check for necessity to update or insert if ($serviceDiscounts[$srvPlzCur][$srvp2PlzCur] != $newValueToBeStored || $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] != $newCrValueToBeStored) : if (existsEntry("serviceplzcustomer",array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId))) : // Update the new discount $sqlStmt = "UPDATE serviceplzcustomer SET srvpc_discount = $newValueToBeStored, srvpc_cr_discount = $newCrValueToBeStored" . " WHERE srvp_id = $srvPlzCur AND srvp2_id = $srvp2PlzCur AND hq_id = $hq_id AND cs_id = $csId AND vht_id = $vhtId"; $res = $db->query($sqlStmt); if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif; else : if ($newValueToBeStored != "0" || $newCrValueToBeStored != "0") : // Insert the new discount $tmpFields = array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId,"srvpc_price",$servicePrices[$srvPlzCur][$srvp2PlzCur],"srvpc_discount",$newValueToBeStored,"srvpc_cr_price",$serviceCrPrices[$srvPlzCur][$srvp2PlzCur],"srvpc_cr_discount",$newCrValueToBeStored); insertStmt("serviceplzcustomer",$tmpFields); endif; endif; // Insert current prices AND (!) discounts into the servicehistory $tmpFields = array("srvp_id",$srvPlzCur,"srvp2_id",$srvp2PlzCur,"hq_id",$hq_id,"cs_id",$csId,"vht_id",$vhtId,"usr_id",$currentSessionUsrId,"srvph_validfrom",$currentTime,"srvph_price",$servicePrices[$srvPlzCur][$srvp2PlzCur],"srvph_discount",$newValueToBeStored,"srvph_cr_price",$serviceCrPrices[$srvPlzCur][$srvp2PlzCur],"srvph_cr_discount",$newCrValueToBeStored); insertStmt("serviceplzhistory",$tmpFields); $serviceDiscounts[$srvPlzCur][$srvp2PlzCur] = $newValueToBeStored; $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] = $newCrValueToBeStored; endif; endif; endfor; endfor; TA("C"); TA("E"); endif; // Store new association between current area and entered neighbour if ($f_act != "" && $f_act == "save_newneighbourassociation" && $f_zipcode2 != "") : // Syntax of the zipcode is correct? if ($f_newneighbourforzipcode != "") : // Get the internal id of the current zipcode $srvp_id = getFieldValueFromId("serviceplz","srvp_plz",$f_zipcode2,"srvp_id"); // First make a lookup if neighbour exists and get the internal id of the new neighbour $srvp2_id = getFieldValueFromId("serviceplz","srvp_plz",$f_newneighbourforzipcode,"srvp_id"); if ($srvp_id != "" && $srvp2_id != "") : if ($srvp_id != $srvp2_id) : // The relation of the neighbourhood is symmetric but NOT transitive! // Therefore ONLY both relations (aRb AND bRa) have to be inserted into the database TA("B"); $relationOne = existsEntry("serviceplzneighbour",array("hq_id",$hq_id,"srvp_id",$srvp_id,"srvp2_id",$srvp2_id)); $relationTwo = existsEntry("serviceplzneighbour",array("hq_id",$hq_id,"srvp_id",$srvp2_id,"srvp2_id",$srvp_id)); // If neighbour exists then lookup for an existing association between the neighbour and another zipcode if (!$relationOne) : // Insert the new association $tmpFields = array("hq_id",$hq_id,"srvp_id",$srvp_id,"srvp2_id",$srvp2_id); insertStmt("serviceplzneighbour",$tmpFields); endif; if (!$relationTwo) : // Insert the new reverse association $tmpFields = array("hq_id",$hq_id,"srvp_id",$srvp2_id,"srvp2_id",$srvp_id); insertStmt("serviceplzneighbour",$tmpFields); endif; if ($relationOne && $relationTwo) : $statusMessage = "Diese Nachbarschaft besteht bereits!"; endif; TA("C"); TA("E"); else : $statusMessage = getLngt("Eine Nachbarschaft identischer PLZn liegt implizit schon vor!"); endif; else : $statusMessage = getLngt("Die PLZ ist nicht in der Datenbank verzeichnet!"); endif; else : $statusMessage = getLngt("Die PLZ wurde falsch eingegeben!"); endif; endif; // Store new association between current area and entered zipcode if ($f_act != "" && $f_act == "save_removeneighbourassociation") : // Entries to be deleted? $fieldsLength = count($f_del_neighbour_id); if ($fieldsLength > 0 && $f_del_neighbour_id[0] != "") : TA("B"); // Remove all associations according to the zipcode nested in array $f_del_zipcode_id for ($i = 0; $i < $fieldsLength; $i++) : // Get the internal id of the current area $srvp_id = getFieldValueFromId("serviceplz","srvp_plz",$f_zipcode2,"srvp_id"); deleteStmt("serviceplzneighbour","hq_id = '" . $hq_id . "' AND srvp_id = " . $srvp_id . " AND srvp2_id = " . $f_del_neighbour_id[$i]); deleteStmt("serviceplzneighbour","hq_id = '" . $hq_id . "' AND srvp_id = " . $f_del_neighbour_id[$i] . " AND srvp2_id = " . $srvp_id); endfor; TA("C"); TA("E"); else : $statusMessage = getLngt("Bitte markieren Sie zu löschenden Nachbar-PLZn durch anklicken der jeweiligen Checkbox hinter der PLZ!"); endif; endif; // *** END *************** // ***************************************************** // * Generation of the price-matrix or discount-matrix * // ***************************************************** // Table-header $serviceOutput = "\n"; $serviceOutput .= " \n"; // because of the following row-names for ($j = 1; $j <= $lenServices2; $j++) : $serviceOutput .= "" . $services2["plz"][$j] . "\n"; endfor; $serviceOutput .= "\n"; // Table-data for ($j = 1; $j <= $lenServices; $j++) : $serviceOutput .= "\n"; $serviceOutput .= "" . $services["plz"][$j] . "\n"; for ($i = 1; $i <= $lenServices2; $i++) : // Define current plz-ids $srvPlzCur = $services["id"][$j]; $srvp2PlzCur = $services2["id"][$i]; if ($mode == "price") : $servicePrices[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($servicePrices[$srvPlzCur], $srvp2PlzCur); if ($servicePrices[$srvPlzCur][$srvp2PlzCur] == "") : $servicePrices[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrPrices[$srvPlzCur], $srvp2PlzCur); if ($serviceCrPrices[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrPrices[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= ""; $serviceOutput .= "
"; $serviceOutput .= ""; if ($csId != "0") : $servicePricesDefault[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($servicePricesDefault[$srvPlzCur], $srvp2PlzCur); if ($servicePricesDefault[$srvPlzCur][$srvp2PlzCur] == "") : $servicePricesDefault[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= "(" . $servicePricesDefault[$srvPlzCur][$srvp2PlzCur] . ")  "; endif; $serviceOutput .= "
\n"; $serviceOutput .= "
"; $serviceOutput .= ""; if ($csId != "0") : $serviceCrPricesDefault[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrPricesDefault[$srvPlzCur], $srvp2PlzCur); if ($serviceCrPricesDefault[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrPricesDefault[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= "(" . $serviceCrPricesDefault[$srvPlzCur][$srvp2PlzCur] . ")  "; endif; $serviceOutput .= "

\n"; $serviceOutput .= "\n"; else : $serviceDiscounts[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceDiscounts[$srvPlzCur], $srvp2PlzCur); if ($serviceDiscounts[$srvPlzCur][$srvp2PlzCur] == "") : $serviceDiscounts[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrDiscounts[$srvPlzCur], $srvp2PlzCur); if ($serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrDiscounts[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= ""; $serviceOutput .= "
"; $serviceOutput .= ""; if ($csId != "0") : $serviceDiscountsDefault[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceDiscountsDefault[$srvPlzCur], $srvp2PlzCur); if ($serviceDiscountsDefault[$srvPlzCur][$srvp2PlzCur] == "") : $serviceDiscountsDefault[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= "(" . $serviceDiscountsDefault[$srvPlzCur][$srvp2PlzCur] . ")  "; endif; $serviceOutput .= "
\n"; $serviceOutput .= "
"; $serviceOutput .= ""; if ($csId != "0") : $serviceCrDiscountsDefault[$srvPlzCur][$srvp2PlzCur] = mcArrMultiDimIsSet($serviceCrDiscountsDefault[$srvPlzCur], $srvp2PlzCur); if ($serviceCrDiscountsDefault[$srvPlzCur][$srvp2PlzCur] == "") : $serviceCrDiscountsDefault[$srvPlzCur][$srvp2PlzCur] = "0.00"; endif; $serviceOutput .= "(" . $serviceCrDiscountsDefault[$srvPlzCur][$srvp2PlzCur] . ")  "; endif; $serviceOutput .= "

\n"; $serviceOutput .= "\n"; endif; endfor; $serviceOutput .= "\n"; endfor; // Output if ($mode == "price") : $title = getLngt("Allgemeine Preise und Frachtvergütungen für PLZ-Bereiche"); else : $title = getLngt("Allgemeine Rabatte und Frachtvergütungsrabatte für PLZ-Bereiche [in %]"); endif; if ($csId != "0") : if ($mode == "price") : $title = getLngt("PLZ-Bereichspreise/-frachtvergütungen speziell für den Kunden") . " " . $cmpComp . " " . $cmpComp2; else : $title = getLngt("PLZ-Bereichsrabatte speziell für den Kunden") . " " . $cmpComp . " " . $cmpComp2; endif; endif; $title2 = getLngt("Verwaltung der Bereichsnachbarschaft"); $title4 = getLngt("Verwaltung der Bereichsaddressen"); // BEGINNING OF ADMINISTRATION OF NEIGHBOURS if ($f_zipcode2 == "") : $f_zipcode2 = $zipcodeRow; endif; // ************************************************** // * Get all neighbours for the current zipcodearea * // ************************************************** $sqlquery = "SELECT srvp2.srvp_id, srvp2.srvp_plz, srvpn.srvpn_sort" . " FROM serviceplzneighbour AS srvpn, serviceplz AS srvp, serviceplz AS srvp2" . " WHERE srvp.srvp_plz = '" . $f_zipcode2 . "' AND" . " srvp.srvp_id = srvpn.srvp_id AND" . " srvpn.hq_id = '" . $hq_id . "' AND" . " srvpn.srvp2_id = srvp2.srvp_id" . " ORDER BY srvpn.srvpn_sort"; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $services2 = ""; $count = 0; while ($row = $result->fetch_assoc()): $count++; $areaneighbours["id"][$count] = $row["srvp_id"]; $areaneighbours["name"][$count] = $row["srvp_plz"]; $areaneighbours["sort"][$count] = $row["srvpn_sort"]; endwhile; $result->free(); // Length of the array containing the zipcodes according to the current selected area $lenAreaNeighbours = count($areaneighbours["id"]); // *************************************************************** // * Display all neighbours based on the filter set in $areaRow. * // * It is the same filter like for the matrix above! * // *************************************************************** // Select-Box $serviceOutput3 = "


\n"; // Output of the existing neighbours of the current selected area for ($j = 1; $j <= $lenAreaNeighbours; $j++) : $serviceOutput3 .= "
\n"; $serviceOutput3 .= $areaneighbours["name"][$j]; $serviceOutput3 .= ""; $serviceOutput3 .= "
\n"; endfor; $serviceOutput3 .= "
"; // Button to remove associations between area and zipcode(s). Only show if at least one zipcode is associated to the current area. if ($lenAreaNeighbours > 0) : $serviceOutput3 .= defineButtonType10(getLngt("Markierte Nachbar-PLZn entfernen"), "action_remove", "finishPage('save_removeneighbourassociation');", "250"); endif; ?> <?php echo $pageTitel; ?>
>
>:
>:
>:
   >    >
: