same values for ALL mandators $currentHqId = $hq_id; if ($serviceMode >= "1") : $constHqId = getParameterValue("0", "MANDATOR_SERVICE2_ENABLED", $hq_id); else : $constHqId = getParameterValue("0", "MANDATOR_SERVICE_ENABLED", $hq_id); endif; if ($constHqId == "" || $constHqId == "0") : $currentHqId = "0"; endif; // *** Storing-processes *** // *** BEGIN *************** // Change name of a service if ($f_act == "save_service_change") : if ($f_service_id != "") : TA(B); updateStmt("service", "srv_id", $f_service_id, array("srv_name", $f_service_change)); writeToLogDB("57",$hq_id,"",$usr_id,"","","","DBOP=Update_service|SRV_MODE=".$serviceMode); TA(C); TA(E); else : $statusMessage = getLngt("Der gewünschte Name existiert leider schon!"); endif; endif; // Insert new service if ($f_act == "save_service_new") : if ($f_service_new != "") : TA(B); $tmpFields = array("srv_mode",$serviceMode,"hq_id",$currentHqId,"cs_id",$csId,"srv_name",$f_service_new); insertStmt("service",$tmpFields); writeToLogDB("58",$hq_id,"",$usr_id,"","","","DBOP=Insert_service|SRV_MODE=".$serviceMode); TA(C); TA(E); else : $statusMessage = getLngt("Vergeben Sie bitte einen Namen!"); endif; endif; // Change name of a servicetype if ($f_act == "save_servicetype_change") : if ($f_servicetype_id != "") : TA(B); updateStmt("servicetype", "srvt_id", $f_servicetype_id, array("srvt_name", $f_servicetype_change)); writeToLogDB("59",$hq_id,"",$usr_id,"","","","DBOP=Update_servicetype|SRV_MODE=".$serviceMode); TA(C); TA(E); else : $statusMessage = getLngt("Der gewünschte Name existiert leider schon!"); endif; endif; // Insert new servicetype if ($f_act == "save_servicetype_new") : if ($f_servicetype_new != "") : TA(B); $tmpFields = array("srvt_mode",$serviceMode,"hq_id",$currentHqId,"cs_id",$csId,"srvt_name",$f_servicetype_new); insertStmt("servicetype",$tmpFields); writeToLogDB("60",$hq_id,"",$usr_id,"","","","DBOP=Insert_servicetype|SRV_MODE=".$serviceMode); TA(C); TA(E); else : $statusMessage = getLngt("Vergeben Sie bitte einen Namen!"); endif; endif; // Removal of a service if ($f_act == "remove_service_single") : if ($f_service_id != "") : TA(B); $tmpSrvName .= getFieldValueFromId("service", "srv_id", $f_service_id, "srv_name"); deleteStmt("service","srv_id = " . $f_service_id); writeToLogDB("131",$hq_id,"",$usr_id,"","","","DBOP=Delete_service|SRV_MODE=".$serviceMode."|SRV_ID=".$f_service_id."|SRV_NAME=".$tmpSrvName); TA(C); TA(E); else : $statusMessage = getLngt("Eine Löschung konnte nicht erfolgen!"); endif; endif; // Removal of a service type if ($f_act == "remove_service_type_single") : if ($f_servicetype_id != "") : TA(B); $tmpSrvtName .= getFieldValueFromId("servicetype", "srvt_id", $f_servicetype_id, "srvt_name"); deleteStmt("servicetype","srvt_id = " . $f_servicetype_id); writeToLogDB("132",$hq_id,"",$usr_id,"","","","DBOP=Delete_servicetype|SRV_MODE=".$serviceMode."|SRVT_ID=".$f_servicetype_id."|SRVT_NAME=".$tmpSrvtName); TA(C); TA(E); else : $statusMessage = getLngt("Eine Löschung konnte nicht erfolgen!"); endif; endif; // *** END *************** // ***************************** // * Selection of all services * // ***************************** if ($csId > "0" && $serviceMode >= "1") : $sqlquery = "SELECT srv.srv_id, srv.srv_name, srv.srv_sort, srv.srv_group, srv.cs_id" . " FROM service AS srv, customerservice AS cssrv" . " WHERE srv.hq_id = '" . $currentHqId . "' AND srv.cs_id = '0' AND srv.srv_mode = '" . $serviceMode . "' AND" . " srv.srv_id = cssrv.srv_id AND cssrv.cs_id = '" . $csId . "'"; $sqlquery2 = "SELECT srv_id, srv_name, srv_sort, srv_group, cs_id" . " FROM service" . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '" . $csId . "' AND srv_mode = '" . $serviceMode . "'"; $sqlquery = "(" . $sqlquery . ") UNION (" . $sqlquery2 . ") ORDER BY " . $orderByService; else : // Default $sqlquery = "SELECT srv_id, srv_name, srv_sort, srv_group, cs_id" . " FROM service" . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '0' AND srv_mode = '" . $serviceMode . "'" . " ORDER BY " . $orderByService; endif; $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[srv_id]; $services["name"][$count] = $row[srv_name]; $services["sort"][$count] = $row[srv_sort]; $services["group"][$count] = $row[srv_group]; $services["cs_id"][$count] = $row[cs_id]; endwhile; $result->free(); // ********************************* // * Selection of all servicetypes * // ********************************* if ($csId > "0" && $serviceMode >= "1") : $sqlquery = "SELECT srvt.srvt_id, srvt.srvt_name, srvt.srvt_group, srvt.cs_id" . " FROM servicetype AS srvt, customerservicetype AS cssrvt" . " WHERE srvt.hq_id = '" . $currentHqId . "' AND srvt.cs_id = '0' AND srvt.srvt_mode = '" . $serviceMode . "' AND" . " srvt.srvt_id = cssrvt.srvt_id AND cssrvt.cs_id = '" . $csId . "'"; $sqlquery2 = "SELECT srvt_id, srvt_name, srvt_group, cs_id" . " FROM servicetype" . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '" . $csId . "' AND srvt_mode = '" . $serviceMode . "'"; // $sqlquery = "(" . $sqlquery . ") UNION (" . $sqlquery2 . ")"; $sqlquery = "(" . $sqlquery . ") UNION ALL (" . $sqlquery2 . ") ORDER BY " . $orderByServiceType; else : // Default $sqlquery = "SELECT srvt_id, srvt_name, srvt_group, cs_id" . " FROM servicetype" . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '0' AND srvt_mode = '" . $serviceMode . "'" . " ORDER BY " . $orderByServiceType; endif; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $serviceTypes = array(); $count = 0; while ($row = $result->fetch_assoc()): $count++; $serviceTypes["id"][$count] = $row[srvt_id]; $serviceTypes["name"][$count] = $row[srvt_name]; $serviceTypes["group"][$count] = $row[srvt_group]; $serviceTypes["cs_id"][$count] = $row[cs_id]; endwhile; $result->free(); // *************************************** // * Selection of servicecustomer-values * // *************************************** $sqlquery = "SELECT srvc.srv_id, srvc.srvt_id, srvc.cs_id, srvc.srvc_price, srvc.srvc_discount" . " FROM service AS srv, servicetype AS srvt, servicecustomer AS srvc" . " WHERE srvc.srv_id = srv.srv_id" . " AND srv.srv_mode = '" . $serviceMode . "'" . " AND srvc.srvt_id = srvt.srvt_id" . " AND srvt.srvt_mode = '" . $serviceMode . "'" . " AND srvc.cs_id = " . $csId . " AND srvc.hq_id = " . $currentHqId . " ORDER BY " . $orderByServiceCustomer; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $servicePrices = array(); $serviceDiscounts = array(); while ($row = $result->fetch_assoc()): $servicePrices[$row[srv_id]][$row[srvt_id]] = $row[srvc_price]; $serviceDiscounts[$row[srv_id]][$row[srvt_id]] = $row[srvc_discount]; endwhile; $result->free(); // Number of entries $lenServices = count($services["id"]); $lenServiceTypes = count($serviceTypes["id"]); // ************************************************* // * 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 <= $lenServiceTypes; $i++) : for ($j = 1; $j <= $lenServices; $j++) : // Define current service-id and service-type-id $srvCur = $services["id"][$j]; $srvtCur = $serviceTypes["id"][$i]; // Get current input-type-text-field with price-/dicount-value list ($newValueToBeStored) = getHttpVars(array("service_". $srvCur ."_" . $srvtCur)); if ($newValueToBeStored == "") : $newValueToBeStored = "0"; endif; // Allow float data with "." and "," $newValueToBeStored = str_replace (",", ".", $newValueToBeStored); if ($servicePrices[$srvCur][$srvtCur] == "") : $servicePrices[$srvCur][$srvtCur] = "0"; endif; if ($serviceDiscounts[$srvCur][$srvtCur] == "") : $serviceDiscounts[$srvCur][$srvtCur] = "0"; endif; if ($mode == "price") : // Check for necessity to update or insert if ($servicePrices[$srvCur][$srvtCur] != $newValueToBeStored) : if (existsEntry("servicecustomer",array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId))) : // Update the new price $sqlStmt = "UPDATE servicecustomer SET srvc_price = $newValueToBeStored" . " WHERE srv_id = $srvCur AND srvt_id = $srvtCur AND hq_id = $currentHqId AND cs_id = $csId"; $res = $db->query($sqlStmt); if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif; else : if ($newValueToBeStored != "0") : // Insert the new price $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"srvc_price",$newValueToBeStored,"srvc_discount",$serviceDiscounts[$srvCur][$srvtCur]); insertStmt("servicecustomer",$tmpFields); endif; endif; // Insert current prices AND (!) discounts into the servicehistory $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"usr_id",$currentSessionUsrId,"srvh_validfrom",$currentTime,"srvh_price",$newValueToBeStored,"srvh_discount",$serviceDiscounts[$srvCur][$srvtCur]); insertStmt("servicehistory",$tmpFields); $servicePrices[$srvCur][$srvtCur] = $newValueToBeStored; endif; else : // Check for necessity to update or insert if ($serviceDiscounts[$srvCur][$srvtCur] != $newValueToBeStored) : if (existsEntry("servicecustomer",array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId))) : // Update the new discount $sqlStmt = "UPDATE servicecustomer SET srvc_discount = $newValueToBeStored" . " WHERE srv_id = $srvCur AND srvt_id = $srvtCur AND hq_id = $currentHqId AND cs_id = $csId"; $res = $db->query($sqlStmt); if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif; else : if ($newValueToBeStored != "0") : // Insert the new discount $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"srvc_price",$servicePrices[$srvCur][$srvtCur],"srvc_discount",$newValueToBeStored); insertStmt("servicecustomer",$tmpFields); endif; endif; // Insert current prices AND (!) discounts into the servicehistory $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"usr_id",$currentSessionUsrId,"srvh_validfrom",$currentTime,"srvh_price",$servicePrices[$srvCur][$srvtCur],"srvh_discount",$newValueToBeStored); insertStmt("servicehistory",$tmpFields); $serviceDiscounts[$srvCur][$srvtCur] = $newValueToBeStored; endif; endif; endfor; endfor; TA("C"); TA("E"); endif; // ***************************************************** // * Generation of the price-matrix or discount-matrix * // ***************************************************** // Table-header $serviceOutput = "