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 = "