示例#1
0
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);
    }
}
示例#2
0
function savePersonStamm($daten, $datei)
{
    $tmp = 0;
    $pid = $daten["PID"];
    $bildok = false;
    // Array zu jedem Formularfed: Tabelle (0=contact,1=cust/vend),  require(0=nein,1=ja), Regel
    // cp_greeting ist raus hli
    $dbfld = array("cp_name" => array(0, 1, 1, "Name", 75), "cp_givenname" => array(0, 1, 1, "Vorname", 75), "cp_gender" => array(0, 0, 1, "Geschlecht", 1), "cp_title" => array(0, 0, 1, "Titel", 75), "cp_street" => array(0, 0, 1, "Strasse", 75), "cp_zipcode" => array(0, 0, 2, "Plz", 10), "cp_city" => array(0, 0, 1, "Ort", 75), "cp_country" => array(0, 0, 8, "Land", 3), "cp_phone1" => array(0, 0, 3, "Telefon 1", 30), "cp_phone2" => array(0, 0, 3, "Telefon 2", 30), "cp_mobile1" => array(0, 0, 3, "Mobiletelefon 1", 30), "cp_mobile2" => array(0, 0, 3, "Mobiletelefon 2", 30), "cp_homepage" => array(0, 0, 4, "Homepage", 0), "cp_fax" => array(0, 0, 3, "Fax", 30), "cp_email" => array(0, 0, 5, "eMail", 0), "cp_privatemail" => array(0, 0, 5, "Private eMail", 0), "cp_notes" => array(0, 0, 1, "Bemerkungen", 0), "cp_stichwort1" => array(0, 0, 1, "Stichworte", 50), "cp_salutation" => array(0, 0, 1, "Briefanrede", 125), "cp_privatphone" => array(0, 0, 3, "Privattelefon 1", 30), "cp_birthday" => array(0, 0, 7, "Geb-Datum", 0), "cp_beziehung" => array(0, 0, 6, "Beziehung", 0), "cp_abteilung" => array(0, 0, 1, "Abteilung", 25), "cp_position" => array(0, 0, 1, "Position", 25), "cp_cv_id" => array(0, 0, 6, "FID", 0), "name" => array(1, 0, 1, "Firma", 75), "cp_owener" => array(0, 0, 6, "CRM-User", 0), "cp_grafik" => array(0, 0, 9, "Grafik", 4));
    if (!empty($datei["Datei"]["name"]["bild"])) {
        // eine Datei wird mitgeliefert
        $pictyp = array("gif", "jpeg", "png", "jpg");
        $ext = strtolower(substr($datei["Datei"]["name"]["bild"], strrpos($datei["Datei"]["name"]["bild"], ".") + 1));
        if (in_array($ext, $pictyp)) {
            $daten["cp_grafik"] = $ext;
            $datei["Datei"]['name']["bild"] = "kopf{$pid}.{$ext}";
            $bildok = true;
        }
    } else {
        $daten["cp_grafik"] = $daten["IMG_"];
    }
    if ($daten["cp_salutation_"]) {
        $daten["cp_salutation"] = $daten["cp_salutation_"];
    }
    $keys = array_keys($daten);
    $dbf = array_keys($dbfld);
    //$fid=$daten["fid"];
    $anzahl = count($keys);
    $fehler = -1;
    $tels = array();
    $query0 = '';
    for ($i = 0; $i < $anzahl; $i++) {
        if (in_array($keys[$i], $dbf)) {
            $tmpval = trim($daten[$keys[$i]]);
            if ($dbfld[$keys[$i]][0] == 1) {
                // Daten nicht für contacts
                continue;
            } else {
                if (!chkFld($tmpval, $dbfld[$keys[$i]][1], $dbfld[$keys[$i]][2], $dbfld[$keys[$i]][4])) {
                    $fehler = $dbfld[$keys[$i]][3];
                    $fehler .= "::" . $keys[$i];
                    $i = $anzahl + 1;
                }
                if ($keys[$i] == "cp_phone1" || $keys[$i] == "cp_phone2" || $keys[$i] == "cp_fax") {
                    $tels[] = $tmpval;
                }
                $query0 .= $keys[$i] . "=";
                if (in_array($dbfld[$keys[$i]][2], array(0, 1, 2, 3, 4, 5, 7, 8, 9))) {
                    //Stringwert
                    if (empty($tmpval)) {
                        $query0 .= "null,";
                    } else {
                        $query0 .= "'" . $tmpval . "',";
                    }
                } else {
                    if (empty($tmpval)) {
                        $query0 .= "null,";
                    } else {
                        $query0 .= $tmpval . ",";
                        //Zahlwert
                    }
                }
            }
        }
    }
    if ($fehler == -1) {
        //Kein Fehler aufgetreten
        if (!$daten["PID"] or $daten["PID"] < 1) {
            $pid = mknewPerson($daten["employee"]);
        }
        //Neue Person
        if (!$pid) {
            return "keine PID";
        }
        //Hat keine PID
        if ($daten["nummer"]) {
            //Gehört zu einem Cust./Vend.
            $dir = $daten["Quelle"] . $daten["nummer"] . "/" . $pid;
        } else {
            $dir = $pid;
        }
        $ok = chkdir($dir);
        if ($bildok) {
            //Ein Bild wird mitgeliefert
            require_once "documents.php";
            // db-Eintrag und upload
            $dbfile = new document();
            $dbfile->setDocData("descript", "Foto von " . $daten["cp_givenname"] . " " . $daten["cp_name"]);
            $bild["Datei"]["name"] = $datei["Datei"]["name"]["bild"];
            $bild["Datei"]["tmp_name"] = $datei["Datei"]["tmp_name"]["bild"];
            $bild["Datei"]["size"] = $datei["Datei"]["size"]["bild"];
            $bild["Datei"]["type"] = $datei["Datei"]["type"]["bild"];
            $bild["Datei"]["error"] = $datei["Datei"]["error"]["bild"];
            $dbfile->uploadDocument($bild, "/{$dir}");
        }
        if ($datei["Datei"]["name"]["visit"]) {
            $bild["Datei"]["name"] = "vcard{$pid}." . strtolower(substr($datei["Datei"]["name"]["visit"], strrpos($datei["Datei"]["name"]["visit"], ".") + 1));
            $bild["Datei"]["tmp_name"] = $datei["Datei"]["tmp_name"]["visit"];
            $bild["Datei"]["size"] = $datei["Datei"]["size"]["visit"];
            $bild["Datei"]["type"] = $datei["Datei"]["type"]["visit"];
            $bild["Datei"]["error"] = $datei["Datei"]["error"]["visit"];
            $dbfile = new document();
            $dbfile->setDocData("descript", "Visitenkarte von " . $daten["cp_givenname"] . " " . $daten["cp_name"]);
            $dbfile->uploadDocument($bild, "/{$dir}");
        }
        mkTelNummer($pid, "P", $tels);
        $sql0 = "update contacts set " . $query0 . "cp_employee=" . $_SESSION["loginCRM"] . " where cp_id={$pid}";
        if ($_SESSION['db']->query($sql0)) {
            //Erfolgreich gesichert
            return $pid;
        } else {
            return "unbekannt";
        }
    } else {
        return $fehler;
    }
}