";
costcenterRequestLogFile($currentTime);
costcenterRequestLogFile($costcenterReq);
if ($selectedLanguage == "" || !is_numeric($selectedLanguage)) : $selectedLanguage = "1"; endif; // Default in English
$languageSelected = $selectedLanguage;
getLanguage(__FILE__);
getCurrentScript(__FILE__);
$err = array();
$costcenterResponse = "";
$xmlCostcenters = "";
// ---------------------------------------------------------------------------
// GLOBAL MODE OF USAGE
$globalParUseRelatedCustomer = getParameterValue("0", "GLOBAL_USE_RELATED_CUSTOMER", "0");
// *** Parse request ***
$costcenterArray = xml2array($costcenterReq);
if ($debug) :
print_r($costcenterArray); echo "
";
endif;
// *** Convert result array to usable parameters ***
// Authentication data
$csEid = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["customer"]);
$csId = getFieldValueFromId("customer","cs_eid",$csEid,"cs_id");
$usrAccount = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["account"]);
$usrPassword = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["password"]);
$sessionId = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["session_id"]);
// Optional customer group data (needed to find e.g. an article price automatically). Has to be set explicitly, because a customer could belong to more groups !!!!
$csGroupId = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["group_no"]);
$csGroupName = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["group_name"]);
if ($csGroupId != "" && is_numeric($csGroupId)) :
$csGroupName = getFieldValueFromId("groups","grp_id",$csGroupId,"grp_name");
elseif ($csGroupName != "") :
$csGroupId = getFieldValueFromId("groups","grp_name",$csGroupName,"grp_id");
endif;
// Reset customer group data if it could not be identified
if ($csGroupId == "" || $csGroupName == "") :
$csGroupId = "";
$csGroupName = "";
endif;
$debugOut .= "usrAccount: " . $usrAccount . "
\n";
$debugOut .= "usrPassword: " . $usrPassword . "
\n";
$debugOut .= "sessionId: " . $sessionId . "
\n";
if (checkRequestAuthenticationData($usrAccount, $usrPassword, $sessionId, $csId)) :
$debugOut .= "Authentication okay!
\n";
// Data
$hqId = getFieldValueFromId("customer","cs_id",$csId,"hq_id");
$cscName = convertSpecial($costcenterArray["xml"]["costcenter"]["auth"]["costcenter_name"]);
$cscId = "";
if ($cscName != "") :
$cscId = getFieldValueFromClause("costcenter","csc_id","cs_id = '" . $csId . "' AND csc_name = '" . $cscName . "'");
endif;
// if ($cscId == "" || !is_numeric($cscId)) :
// $cscId = getFieldValueFromClause("costcenter","csc_id","cs_id = '" . $csId . "' AND isnull(csc_pre_id)"); // Root costcenter
// endif;
// Get costcenter data
$operation = convertSpecial($costcenterArray["xml"]["costcenter"]["operation"]);
$debugOn = convertSpecial($costcenterArray["xml"]["costcenter"]["debug_on"]);
$adType = convertSpecial($costcenterArray["xml"]["costcenter"]["address_type"]);
$debugOut .= "operation: " . $operation . "
\n";
$debugOut .= "address_type: " . $address_type . "
\n";
if (!$debug && $debugOn == "ON" || $debugOn == "YES") :
$debug = true;
endif;
if ($adType == "") : $adType = "4"; endif; // Pick-up/Delivery address
if ($operation == "SET") :
// TO BE DONE!
else :
$whereClause = "";
if ($cscName != "" && $cscId != "") :
$whereClause = "AND csc.csc_id = '" . $cscId . "'";
endif;
$sqlquery = "SELECT ad.ad_id, ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country, csc.csc_id, csc.csc_name, csc.csc_pre_id, "
. " cscad.cscad_comp AS comp, cscad.cscad_comp2 AS comp2, cscad.cscad_comp3 AS comp3, cscad.cscad_comp4 AS comp4,"
. " cscad.cscad_hsno AS hsno, cscad.cscad_floor AS floor, cscad.cscad_remark AS remark, cscad.cscad_person AS person, cscad.cscad_phone AS phone, cscad.cscad_email AS email"
. " FROM address AS ad, costcenteraddress AS cscad, costcenter AS csc, customer AS cs"
. " WHERE cs.cs_id = '" . $csId . "' AND cs.cs_id = csc.cs_id AND " . $whereClause . " csc.csc_id = cscad.csc_id AND adt_id = '" . $adType . "' AND cscad.ad_id = ad.ad_id";
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: '$sqlquery'" . $result->getMessage());
$xmlCostcenters .= "";
while ($row = $result->fetch_assoc()):
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
$xmlCostcenters .= "";
endwhile;
$result->free();
$xmlCostcenters .= "";
endif;
else :
// Authentication data not ok
$err[] = array("101", getLngt("Die Authentifizierungsdaten sind nicht in Ordnung."));
endif;
// print_r($err);
// Check existence of at least one error
$errLen = count($err);
// Output
$costcenterResponse .= "";
if ($errLen > 0) :
costcenterRequestLogFile("ERRORS", 1);
$costcenterResponse .= "NOT OK";
$costcenterResponse .= "";
for ($i = 0; $i < $errLen; $i++) :
$costcenterResponse .= "";
$costcenterResponse .= "" . $err[$i][0] . "";
$costcenterResponse .= "";
$costcenterResponse .= "";
if ($debug) :
$costcenterResponse .= "" . $debugOut . "";
endif;
costcenterRequestLogFile($err[$i][0] . " : " . mcEncode($err[$i][1]), 1);
endfor;
$costcenterResponse .= "";
else :
$costcenterResponse .= "OK" . $xmlCostcenters;
if ($debug) :
$costcenterResponse .= "" . $debugOut . "";
endif;
endif;
$costcenterResponse .= "";
// Log entries
costcenterRequestLogFile($costcenterResponse); // Write response into log
costcenterRequestLogFile("___________________________________________________________________________________");
// Return output
echo $costcenterResponse;
/*
// REQUEST
// Request for all costcenters of the customer
// Customer to be authenticated
... // Kundennummer (EID) {"STBxxxxxx", ...} => csc_id_payer
... // Eingetragener Benutzer für den Kunden => cs.cs_admin => emp.emp_id => emp.usr_id => usr.usr_id => usr.usr_account
... // Passwort für den Benutzer => usr.usr_password
... // Zusätzliche Session-ID, die mit dem Kunden ausgehandelt wurde [mandatory]
... // Kostenstellenname {"abcd", "efgh", ...} => Mapping csc_id [optional]
... // Nummer der Kundengruppe (Bei einer automatischen Preisfindung muss entweder oder gesetzt sein)
... // Name der Kundengruppe (Bei einer automatischen Preisfindung muss entweder oder gesetzt sein)
... // Activates debug output ("ON" or "YES")
GET|SET // Operation (GET or SET costcenter(s), default is "GET" if emty tag)
... // Address type (empty tag = "4" = pickup)
// RESPONSE for GET
OK
// Kostenstelle
.... // Tag, an dem das Fahrzeug verfügbar ist. Wenn nur ein Tag im Request definiert, dann wird dieser auch nur hier in der Antwort zurückgeliefert
.... // Uhrzeit, ab wann das Fahrzeug zur Verfügung steht
.... // Anzahl Zeiteinheiten, die ab der Startzeit verfügbar sind
.... // (Interne) ID des Fahrzeugs
.... // Fahrzeugnummer (für Kunden nicht zwingend sichtbar)
.... // Tageszeit der Verfügbarkeit ("0" = 1. definierte Tageszeit für den Kunden, "1" = 2. Tageszeit, "2" = 3. Tageszeit,....)
.... // Tageszeit der Verfügbarkeit (Text z.B. "Vormittag", "Nachmittag", "Abend")
.... // Tageszeit der Verfügbarkeit (Zeitintervall, z.B. "07:00 - 12:00", "12:00 - 16:00", "16:00 - 21:00")
.... // Service = ("1" => "LI" = Lieferung, "2" => "MO" = Montage,....)
// Weitere Kostenstelle
....
*/
?>