function saveFirmaStamm($daten, $datei, $typ = "C", $neu = false) { $kenz = array("C" => "K", "V" => "L"); $tab = array("C" => "customer", "V" => "vendor"); if ($neu && $_SESSION['feature_unique_name_plz'] == 't') { $sql = "SELECT id FROM " . $tab[$typ] . " WHERE name = '" . strtr($daten['name'], array("'" => "''")) . "' AND zipcode = '" . $daten['zipcode'] . "'"; $rs = $_SESSION['db']->getAll($sql); if ($rs[0]['id']) { return array(-1, ".:Customer / Vendor exist with same zipcode:."); } } if (!empty($datei["Datei"]["name"])) { // eine Datei wird mitgeliefert $pictyp = array("gif", "jpeg", "png", "jpg"); $ext = substr($datei["Datei"]["name"], strrpos($datei["Datei"]["name"], ".") + 1); if (in_array($ext, $pictyp)) { $daten["grafik"] = $ext; $datei["Datei"]['name'] = "logo.{$ext}"; $bildok = true; } } // Array zu jedem Formularfed: Tabelle (0=customer/vendor,1=shipto), require(0=nein,1=ja), Spaltenbezeichnung, Regel $dbfld = array(name => array(0, 1, 1, "Name", 75), greeting => array(0, 0, 1, "Anrede", 75), department_1 => array(0, 0, 1, "Zusatzname", 75), department_2 => array(0, 0, 1, "Abteilung", 75), country => array(0, 0, 8, "Land", 25), zipcode => array(0, 1, 2, "Plz", 10), city => array(0, 1, 1, "Ort", 75), street => array(0, 1, 1, "Strasse", 75), fax => array(0, 0, 3, "Fax", 30), phone => array(0, 0, 3, "Telefon", 30), email => array(0, 0, 5, "eMail", 0), homepage => array(0, 0, 4, "Homepage", 0), contact => array(0, 0, 1, "Kontakt", 75), v_customer_id => array(0, 0, 1, "Kundennummer", 50), sw => array(0, 0, 1, "Stichwort", 50), notes => array(0, 0, 0, "Bemerkungen", 0), ustid => array(0, 0, 0, "UStId", 0), taxnumber => array(0, 0, 0, "Steuernummer", 0), bank => array(0, 0, 1, "Bankname", 50), bank_code => array(0, 0, 6, "Bankleitzahl", 15), iban => array(0, 0, 1, "IBAN", 24), bic => array(0, 0, 1, "BIC", 15), account_number => array(0, 0, 6, "Kontonummer", 15), language_id => array(0, 0, 6, "Sprache", 0), payment_id => array(0, 0, 6, "Zahlungsbedingungen", 0), employee => array(0, 0, 6, "Bearbeiter", 0), branche => array(0, 0, 1, "Branche", 25), business_id => array(0, 0, 6, "Kundentyp", 0), owener => array(0, 0, 6, "CRM-User", 0), grafik => array(0, 0, 9, "Grafik", 4), lead => array(0, 0, 6, "Leadquelle", 0), leadsrc => array(0, 0, 1, "Leadquelle", 15), bland => array(0, 0, 6, "Bundesland", 0), taxzone_id => array(0, 1, 6, "Steuerzone", 0), salesman_id => array(0, 0, 6, "Vertriebler", 0), konzern => array(0, 0, 6, "Konzern", 0), shiptoname => array(1, 0, 1, "Liefername", 75), shiptostreet => array(1, 0, 1, "Lieferstrasse", 75), shiptobland => array(1, 0, 6, "Liefer-Bundesland", 0), shiptocountry => array(1, 0, 8, "Lieferland", 3), shiptozipcode => array(1, 0, 2, "Liefer-Plz", 10), shiptocity => array(1, 0, 1, "Lieferort", 75), shiptocontact => array(1, 0, 1, "Kontakt", 75), shiptophone => array(1, 0, 3, "Liefer Telefon", 30), shiptofax => array(1, 0, 3, "Lieferfax", 30), shiptoemail => array(1, 0, 5, "Liefer-eMail", 0), shiptodepartment_1 => array(1, 0, 1, "Lieferzusatzname", 75), shiptodepartment_2 => array(1, 0, 1, "Lieferabteilung", 75), headcount => array(0, 0, 6, "Anzahl Mitarbeiter", 10), currency_id => array(0, 0, 6, "Currency", 0)); $keys = array_keys($daten); $dbf = array_keys($dbfld); $anzahl = count($keys); $fid = $daten["id"]; $fehler = "ok"; $ala = false; if ($daten["greeting_"] != "") { $daten["greeting"] = $daten["greeting_"]; } if ($daten["branche_"] != "") { $daten["branche"] = $daten["branche_"]; } $tels1 = array(); $tels2 = array(); for ($i = 0; $i < $anzahl; $i++) { if (in_array($keys[$i], $dbf)) { $tmpval = trim($daten[$keys[$i]]); if ($dbfld[$keys[$i]][0] == 1) { // select für Lieferanschrift bilden if ($tmpval) { $ala = true; } if (!chkFld($tmpval, $dbfld[$keys[$i]][1], $dbfld[$keys[$i]][2], $dbfld[$keys[$i]][4])) { $fehler = $dbfld[$keys[$i]][3]; $i = $anzahl; } else { if (in_array($dbfld[$keys[$i]][2], array(0, 1, 2, 3, 4, 5, 7, 8, 9))) { //Daten == Zeichenkette if (empty($tmpval)) { $query1 .= $keys[$i] . "=null,"; } else { $query1 .= $keys[$i] . "='" . $tmpval . "',"; } } else { //Daten == Zahl if (empty($tmpval) && !$tmpval === 0) { $query1 .= $keys[$i] . "=null,"; } else { $query1 .= $keys[$i] . "=" . $tmpval . ","; } } if ($keys[$i] == "shiptophone" || $keys[$i] == "shiptofax") { $tels2[] = $tmpval; } } } else { // select für Rechnungsanschrift bilden if (!chkFld($tmpval, $dbfld[$keys[$i]][1], $dbfld[$keys[$i]][2], $dbfld[$keys[$i]][4])) { $fehler = $dbfld[$keys[$i]][3]; $i = $anzahl; } else { if (in_array($dbfld[$keys[$i]][2], array(0, 1, 2, 3, 4, 5, 7, 8, 9))) { if (empty($tmpval)) { $query0 .= $keys[$i] . "=null,"; } else { $query0 .= $keys[$i] . "='" . $tmpval . "',"; } } else { //Daten == Zahl if (empty($tmpval) && !$tmpval === 0) { $query0 .= $keys[$i] . "=null,"; } else { $query0 .= $keys[$i] . "=" . $tmpval . ","; } } if ($keys[$i] == "phone" || $keys[$i] == "fax") { $tels1[] = $tmpval; } } } } } if ($daten["direct_debit"] == "t") { if (empty($daten["bank"]) or empty($daten["account_number"]) or empty($daten["bank_code"])) { $fehler = "Lastschrift: Bankverbindung fehlt"; } else { $query0 .= "direct_debit='t',"; } } else { $query0 .= "direct_debit='f',"; } if ($fehler == "ok") { if ($daten["customernumber"]) { $query0 = substr($query0, 0, -1); $DIR = "C" . $daten["customernumber"]; } else { if ($daten["vendornumber"]) { $query0 = substr($query0, 0, -1); $DIR = "V" . $daten["vendornumber"]; } else { $tmpnr = newnr($tab[$typ], $daten["business_id"]); if ($typ == "C") { $DIR = "C" . $tmpnr; $query0 = $query0 . "customernumber='{$tmpnr}' "; } else { $DIR = "V" . $tmpnr; $query0 = $query0 . "vendornumber='{$tmpnr}' "; } } } include "links.php"; if (!is_dir($dir_abs . "/" . $DIR)) { // Wird wo definiert??? mkdir($dir_abs . "/" . $DIR); } chmod($dir_abs . "/" . $DIR, $_SESSION['dir_mode']); if ($_SESSION['dir_group']) { chgrp($dir_abs . "/" . $DIR, $_SESSION['dir_group']); } $link_dir_cv = $typ == "C" ? $link_dir_cust : $link_dir_vend; if (!$dir_abs . $link_dir_cv . "/" . mkDirName($daten['name']) . "_" . $DIR) { if (is_dir($dir_abs . $link_dir_cv)) { if ($dh = opendir($dir_abs . $link_dir_cv)) { while (($link = readdir($dh)) !== false) { $split = preg_split("/(_" . $typ . ")([\\d]{1,})/", $link, 2, PREG_SPLIT_DELIM_CAPTURE); if ($split[1] . $split[2] == "_" . $DIR) { unlink($dir_abs . $link_dir_cv . "/" . $link); } } } closedir($dh); } symlink($dir_abs . "/" . $DIR, $dir_abs . $link_dir_cv . "/" . mkDirName($daten['name']) . "_" . $DIR); } $query1 = substr($query1, 0, -1) . " "; $sql0 = "update " . $tab[$typ] . " set {$query0} where id={$fid}"; mkTelNummer($fid, $typ, $tels1); if ($bildok) { require_once "documents.php"; $dbfile = new document(); $dbfile->setDocData("descript", "Firmenlogo von " . $daten["name"]); $dbfile->uploadDocument($datei, "/{$DIR}"); } $rc1 = true; if ($ala) { if ($daten["shipto_id"] > 0) { $sql1 = "update shipto set {$query1} where shipto_id=" . $daten["shipto_id"]; $rc1 = $_SESSION['db']->query($sql1); } else { $sid = newShipto($fid); if ($sid) { $sql1 = "update shipto set {$query1} where shipto_id=" . $sid; $rc1 = $_SESSION['db']->query($sql1); } } if ($rc1) { mkTelNummer($fid, "S", $tels2); } } $rc0 = $_SESSION['db']->query($sql0); if ($rc0 and $rc1) { $rc = $fid; //ab hier CVARS //Alle möglichen Vars holen $sql = "SELECT id,name,type from custom_variable_configs where module = 'CT'"; $vars = $_SESSION['db']->getAll($sql); if ($vars) { foreach ($vars as $row) { $vartype[$row["name"]] = array("id" => $row["id"], "type" => $row["type"]); } } $sqltpl = "insert into custom_variables (config_id,trans_id,bool_value,timestamp_value,text_value,number_value)"; $sqltpl .= "values (%d,%d,%s,%s,%s,%s)"; //bisherige Einträge löschen. $sql = "delete from custom_variables where trans_id = " . $daten["id"]; $rcc = $_SESSION['db']->query($sql); //Insert bilden foreach ($daten as $key => $val) { if (substr($key, 0, 8) == "vc_cvar_") { //eine CVar $name = substr($key, 8); //Values erzeugen $date = "null"; $num = "null"; $bool = "null"; $text = "null"; switch ($vartype[$name]["type"]) { case "select": case "textfield": case "text": $text = "'{$val}'"; break; case "number": $num = sprintf("%0.2f", $val); break; case "customer": $num = $val; break; case "date": $date = "'" . date2db($val) . "'"; break; case "bool": $bool = $val == 't' ? "'t'" : "'f'"; break; default: $text = "'{$val}'"; break; } $sql = sprintf($sqltpl, $vartype[$name]["id"], $daten["id"], $bool, $date, $text, $num); $rcc = $_SESSION['db']->query($sql); } } } else { $rc = -1; $fehler = ".:unknown:."; } return array($rc, $fehler); } else { if ($daten["saveneu"]) { $sql = "delete from " . $tab[$typ] . " where id=" . $daten["id"]; $rc0 = $_SESSION['db']->query($sql); } return array(-1, $fehler); } }
} echo "Erzeuge Symlink: " . $dir_abs . $link_dir_cust . "/" . mkDirName($rs[$key]['name']) . "_C" . $rs[$key]['customernumber'] . "</br>"; symlink($dir_abs . "/C" . $rs[$key]['customernumber'], $dir_abs . $link_dir_cust . "/" . mkDirName($rs[$key]['name']) . "_C" . $rs[$key]['customernumber']); //lchgrp( $dir_abs.$link_dir_cust."/".mkDirName($rs[$key]['name'])."_C".$rs[$key]['customernumber'], $_SESSION['dir_group']); //funktioniert nicht.. warum??? } } $sql = "SELECT name, vendornumber FROM vendor ORDER BY vendornumber"; //::INT "; $rs = $_SESSION['db']->getall($sql); if ($rs) { foreach ($rs as $key => $value) { if (!is_dir($dir_abs . "/V" . $rs[$key]['vendornumber'])) { echo "Erzeuge Verzeichnis: " . $dir_abs . "/V" . $rs[$key]['vendornumber'] . " </br>"; mkdir($dir_abs . "/V" . $rs[$key]['vendornumber']); } chmod($dir_abs . "/V" . $rs[$key]['vendornumber'], $_SESSION['dir_mode']); if ($_SESSION['dir_group']) { chgrp($dir_abs . "/V" . $rs[$key]['vendornumber'], $_SESSION['dir_group']); } echo "Erzeuge Symlink: " . $dir_abs . $link_dir_vend . "/" . mkDirName($rs[$key]['name']) . "_V" . $rs[$key]['vendornumber'] . "</br>"; symlink($dir_abs . "/V" . $rs[$key]['vendornumber'], $dir_abs . $link_dir_vend . "/" . mkDirName($rs[$key]['name']) . "_V" . $rs[$key]['vendornumber']); } } echo "...done"; echo ' <form action="#"> <p> <input type="button" name="Next" value="Next" onclick="window.location.href = \'' . $_SERVER["HTTP_REFERER"] . '\'"> </p> </form>'; }