1. Import
This commit is contained in:
338
html/import/import_RADIUSZONE.php
Normal file
338
html/import/import_RADIUSZONE.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/*=======================================================================
|
||||
*
|
||||
* import_RADIUSZONE.php
|
||||
*
|
||||
* Autor: Marc Vollmann
|
||||
*
|
||||
=======================================================================*/
|
||||
|
||||
include_once ("../import/import.php");
|
||||
|
||||
// Execution-Time for script
|
||||
set_time_limit(0);
|
||||
|
||||
|
||||
// Check HTTP-Parameters
|
||||
getSecHttpVars("1",array("f_act", "statusMessage", "importFile", "executeImportProcess", "deactivateMenu", "objType", "objId"));
|
||||
|
||||
|
||||
getLanguage(__FILE__);
|
||||
|
||||
$deactivateMenuStatic = "1";
|
||||
$pageTitel = getLngt("IMPORT RADIUS-ZONEN");
|
||||
include_once ("../admin/menu.php");
|
||||
include_once ("../include/html.inc.php");
|
||||
getCurrentScript(__FILE__);
|
||||
|
||||
// Check for authentication access
|
||||
$usrAccessArray["hq"] = "1";
|
||||
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
|
||||
if (!(authCheckEmployeeRights($emp_id, "22"))) : gotoReferer("1"); endif;
|
||||
|
||||
$empHasAdminRights = false;
|
||||
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);
|
||||
if ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin) :
|
||||
$empHasAdminRights = true;
|
||||
endif;
|
||||
|
||||
$debug = false;
|
||||
if ($empIdRootAdmin == $emp_id) :
|
||||
$debug = true;
|
||||
endif;
|
||||
|
||||
if ($f_act != "executeImport" || $executeImportProcess != "1") : $executeImportProcess = ""; endif; // Execute import after check run
|
||||
$showExecutionProcessButton = true;
|
||||
$outText = "";
|
||||
$closeWindow = "0";
|
||||
$delimiter = ";";
|
||||
$fire = true;
|
||||
|
||||
|
||||
// Current file to be imported
|
||||
$importFile = urldecode($importFile);
|
||||
$posLastSlash = strripos($importFile, "/");
|
||||
$posLastSlash++;
|
||||
$pathname = substr($importFile, 0, $posLastSlash);
|
||||
$filename = substr($importFile, $posLastSlash);
|
||||
$outText = "<span class=\"f10bp1_blue\">" . getLngt("IMPORTDATEI:") . "</span> " . $filename . "<br><br>";
|
||||
|
||||
|
||||
// Customer and headquarters references have to exist
|
||||
$hqId = "";
|
||||
$csEid = "";
|
||||
$objType = trim($objType);
|
||||
$objId = trim($objId);
|
||||
if ($objType == "CS" && is_numeric($objId)) :
|
||||
// $csId = getFieldValueFromId("phoenix.customer", "cs_id", $objId, "cs_id");
|
||||
$csId = $objId;
|
||||
endif;
|
||||
|
||||
// Get $csId (if empty) from EID out of the filename
|
||||
if ($csId == "") :
|
||||
$posLastSlash = strripos($filename, "_");
|
||||
$posLastSlash++;
|
||||
$csEid = trim(substr($filename, $posLastSlash));
|
||||
$csId = getFieldValueFromId("phoenix.customer", "cs_id", $csEid, "cs_eid");
|
||||
if (is_numeric($csId)) :
|
||||
$objId = $csId;
|
||||
$objType = "CS";
|
||||
endif;
|
||||
endif;
|
||||
// Get headquarters and EID
|
||||
if ($csId != "") :
|
||||
$hqId = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "hq_id");
|
||||
$csEid = getFieldValueFromId("phoenix.customer", "cs_id", $csId, "cs_eid");
|
||||
endif;
|
||||
if ($debug) :
|
||||
echo "f_act : " . $f_act . "<br>";
|
||||
echo "objType : " . $objType . "<br>";
|
||||
echo "objId : " . $objId . "<br>";
|
||||
echo "hqId : " . $hqId . "<br>";
|
||||
echo "csId : " . $csId . "<br>";
|
||||
echo "<br>";
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ($importFile != "") :
|
||||
|
||||
if ($hqId != "" && $csId != "") :
|
||||
|
||||
// Create internal representation
|
||||
$srvpArray = array();
|
||||
$zoneArray = array();
|
||||
|
||||
if (file_exists($importFile)) :
|
||||
|
||||
$currentTime = getDateTime("0");
|
||||
|
||||
|
||||
// ********************
|
||||
// * IMPORT FILE zone *
|
||||
// ********************
|
||||
if (!(strpos($filename, "import_RADIUSZONE_") === false)) :
|
||||
|
||||
$rowToImport = array();
|
||||
|
||||
$rowToImport[0] = "f_zone_no";
|
||||
$rowToImport[1] = "f_zipcode";
|
||||
$rowToImport[2] = "f_district";
|
||||
$rowToImport[3] = "f_dummy";
|
||||
|
||||
$rowToImportLen = count($rowToImport);
|
||||
|
||||
// read file to import
|
||||
$data = importCSV($importFile, $delimiter);
|
||||
$dataLen = count($data);
|
||||
|
||||
// loop all rows (EXCEPT header row [$j = 1])
|
||||
for ($j = 0; $j < $dataLen; $j++) {
|
||||
|
||||
// loop for all fields of $fields of the row
|
||||
for ($i = 0; $i < $rowToImportLen; $i++) {
|
||||
${$rowToImport[$i]} = $data[$j][$i];
|
||||
}
|
||||
|
||||
$f_country = "DE";
|
||||
$f_zone_no = removeFieldSigns($f_zone_no);
|
||||
$f_zipcode = removeFieldSigns($f_zipcode);
|
||||
$f_district = removeFieldSigns($f_district);
|
||||
|
||||
if ($f_zipcode != "") :
|
||||
|
||||
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
|
||||
$f_country = "DE";
|
||||
endif;
|
||||
|
||||
// Get srvp_id from serviceplz
|
||||
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
|
||||
|
||||
if ($srvpId != "") :
|
||||
|
||||
// If country "Germany" then fill zipcode with "0" up to 5 chars
|
||||
if ($f_country == "DE") :
|
||||
$f_zipcode = pad($f_zipcode, 5);
|
||||
endif;
|
||||
|
||||
// Set arrays
|
||||
$srvpArray[] = array($srvpId, $f_zipcode, $f_zone_no, $f_country, $f_district);
|
||||
$x = array_search($f_zone_no, $zoneArray);
|
||||
if ($x === FALSE) :
|
||||
$zoneArray[] = $f_zone_no;
|
||||
endif;
|
||||
|
||||
else :
|
||||
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "<br>";
|
||||
endif;
|
||||
else :
|
||||
$outText .= getLngt("Keine PLZ im Datensatz!") . "<br>";
|
||||
endif;
|
||||
}
|
||||
|
||||
if ($debug) :
|
||||
// print_r($zoneArray); echo "<br><br>";
|
||||
// print_r($srvpArray); echo "<br><br>";
|
||||
endif;
|
||||
|
||||
// Insert new zone zipcodes into the database from internal structure
|
||||
if ($fire && $executeImportProcess == "1") :
|
||||
|
||||
$zoneArrayLen = count($zoneArray);
|
||||
$srvpArrayLen = count($srvpArray);
|
||||
|
||||
TA("B");
|
||||
|
||||
// Delete zipcodes of the customer (and headquarters) and the specified zone
|
||||
for ($k = 0; $k < $zoneArrayLen; $k++) :
|
||||
deleteStmt("phoenix.serviceradius","srvz_id = '" . $zoneArray[$k] . "' AND cs_id = '" . $csId . "' AND hq_id = '" . $hqId . "'");
|
||||
$outText .= getLngt("Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde im Basisdatenbestand entfernt!") . "<br>";
|
||||
endfor;
|
||||
|
||||
// Import new zipcodes
|
||||
$executionCount = 0;
|
||||
$existingCount = 0;
|
||||
for ($k = 0; $k < $srvpArrayLen; $k++) :
|
||||
|
||||
// Check for existence of mapping entry
|
||||
if (!existsEntry("phoenix.serviceradius",array("cs_id", $csId, "hq_id", $hqId, "srvr_zipcode", $srvpArray[$k][1], "srvr_zipcode", $srvpArray[$k][4]))) :
|
||||
|
||||
insertStmt("phoenix.serviceradius", array("cs_id", $csId, "hq_id", $hqId, "srvr_zipcode", $srvpArray[$k][1], "srvr_zipcode", $srvpArray[$k][4], "srvr_radiusarea_no", $srvpArray[$k][2])));
|
||||
$executionCount++;
|
||||
else :
|
||||
$existingCount++;
|
||||
endif;
|
||||
endfor;
|
||||
|
||||
TA("C");
|
||||
TA("E");
|
||||
|
||||
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "<br>");
|
||||
$outText .= getLngt("Eingefügte Einträge: " . $executionCount . "<br>");
|
||||
$outText .= getLngt("Existierende Einträge: " . $existingCount . "<br>");
|
||||
// $closeWindow = "1";
|
||||
endif;
|
||||
endif;
|
||||
|
||||
|
||||
// ********************
|
||||
// * IMPORT FILE xxxx *
|
||||
// ********************
|
||||
// if (!(strpos($filename, "import_xxxx") === false)) :
|
||||
|
||||
|
||||
|
||||
// endif;
|
||||
|
||||
else :
|
||||
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
|
||||
endif;
|
||||
else :
|
||||
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
|
||||
endif;
|
||||
else :
|
||||
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
CREATE TABLE servicezone (
|
||||
srvz_id int(10) NOT NULL auto_increment,
|
||||
hq_id int(10) NOT NULL default '0',
|
||||
cs_id int(10) NOT NULL default '0',
|
||||
srvz_no tinyint(3) default '0',
|
||||
srvz_name varchar(50) NOT NULL default '',
|
||||
srvz_price float(10,4) NOT NULL default '0.0000',
|
||||
srvz_price2 float(10,4) NOT NULL default '0.0000',
|
||||
PRIMARY KEY (srvz_id)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE servicezonemapping (
|
||||
srvz_id int(10) NOT NULL default '0',
|
||||
srvp_id int(10) NOT NULL default '0'
|
||||
) ENGINE=InnoDB;
|
||||
*/
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo $pageTitel ?></title>
|
||||
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
|
||||
<style type="text/css">
|
||||
<?php include_once ("../css/navigation.css.php"); ?>
|
||||
</style>
|
||||
|
||||
<?php include_once ("../include/js_framework.inc.php"); ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
// NAVIGATION
|
||||
<?php echo $jsMenuOut; ?>
|
||||
|
||||
function finishPageExecuteImportProcess(f_act) {
|
||||
document.forms[0].f_act.value=f_act;
|
||||
document.forms[0].executeImportProcess.value = '1';
|
||||
document.forms[0].submit();
|
||||
};
|
||||
|
||||
function onBodyLoad() {
|
||||
displayStatusMessage();
|
||||
var closeWindow = '<?php echo $closeWindow ?>';
|
||||
if (closeWindow == '1') {
|
||||
opener.document.forms[0].submit();
|
||||
window.close();
|
||||
};
|
||||
};
|
||||
-->
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>onBodyLoad();">
|
||||
|
||||
<?php echo $phpMenuOut ?>
|
||||
<?php echo $phpReducedMenuOut ?>
|
||||
<?php echo $phpPageTitelOut ?>
|
||||
|
||||
<div class="maincontent" name="maincontent" id="maincontent">
|
||||
|
||||
<div>
|
||||
<form name="import_form" action="../import/import_ZONE.php" method="post">
|
||||
<input type="hidden" name="f_act" value="">
|
||||
<?php echo $phpCurrentNavigationInputHidden ?>
|
||||
<input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
|
||||
<input type="hidden" name="importFile" value="<?php echo $importFile; ?>">
|
||||
<input type="hidden" name="executeImportProcess" value="<?php echo $executeImportProcess; ?>">
|
||||
<input type="hidden" name="objType" value="<?php echo $objType; ?>">
|
||||
<input type="hidden" name="objId" value="<?php echo $objId; ?>">
|
||||
|
||||
<?php echo htmlDivLineSpacer("10px"); ?>
|
||||
|
||||
<?php
|
||||
if ($showExecutionProcessButton && $executeImportProcess != "1") :
|
||||
echo defineButtonType10(getLngt("Import starten"), "action_import", "finishPageExecuteImportProcess('executeImport');", "200");
|
||||
echo htmlDivLineSpacer("5px");
|
||||
echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "200");
|
||||
echo htmlDivLineSpacer("5px");
|
||||
endif;
|
||||
?>
|
||||
|
||||
<?php echo htmlDivLineSpacer("20px"); ?>
|
||||
|
||||
<div>
|
||||
<table border="1" margin="10" padding="10">
|
||||
<tr>
|
||||
<td style="vertical-align:top;">
|
||||
<?php echo $outText; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user