forked from kivitendo/kivitendo-crm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extrafelder.php
201 lines (197 loc) · 7.91 KB
/
extrafelder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
session_start();
/*
--Das kommt in den Livebetrieb
CREATE SEQUENCE extraid
INCREMENT BY 1
MAXVALUE 2147483647
NO MINVALUE
CACHE 1;
create table extra_felder (
id integer DEFAULT nextval('extraid'::text) NOT NULL,
owner char(10), -> [CVP]id
fkey text, -> Feldname
fval text -> Wert zum Feld
);
CREATE INDEX extrafld_key ON extra_felder USING btree (owner);
*/
require_once("inc/stdLib.php");
include("inc/template.inc");
$menu = $_SESSION['menu'];
$head = mkHeader();
$owner=($_GET["owner"])?$_GET["owner"]:$_POST["owner"];
function suchFelder($data) {
$tab = substr($data['owner'],0,1);
foreach ($data as $key=>$val) {
if ($key == "suche") continue;
if ($key == "owner") continue;
if ($val) $where .= "(fkey = '$key' and fval ilike '$val%' and tab = '$tab') or ";
}
$where = substr($where,0,-3) ;
$sqle="select owner from extra_felder where ".$where;
if ($tab == "C") {
$sql = "select * from customer where id in ($sqle)";
} else if ($tab == "V") {
$sql = "select * from vendor where id in ($sqle)";
} else if ($tab == "P") {
$sql = "SELECT contacts.*,C.name as cfirma,V.name as vfirma ";
$sql.= "from contacts left join customer C on C.id=cp_cv_id ";
$sql.= "left join vendor V on V.id=cp_cv_id where cp_id in ($sqle)";
}
$rs = $_SESSION['db']->getAll($sql);
return $rs;
}
function saveFelder($data) {
$nosave=array("save","owner","suche");
$owner=$data["owner"];
$rc=$_SESSION['db']->query("BEGIN");
$tab = substr($owner,0,1);
$owner = substr($owner,1);
$sql="delete from extra_felder where tab = '$tab' and owner = '$owner'";
$rc=$_SESSION['db']->query($sql);
foreach ($data as $key=>$val) {
if (in_array($key,$nosave)) continue;
$val=trim($val);
$rc=$_SESSION['db']->insert('extra_felder',array('tab','owner','fkey','fval'),array($tab,$owner,$key,$val));
if (!$rc) { $_SESSION['db']->query("ROLLBACK"); return false; };
}
$rc=$_SESSION['db']->query("COMMIT");
return true;
}
function getFelder($owner,&$t) {
$t->set_var(array(owner => $owner));
$tab = substr($owner,0,1);
$owner = substr($owner,1);
$sql="select * from extra_felder where tab = '$tab' and owner='$owner'";
$rs=$_SESSION['db']->getAll($sql);
if ($rs) {
foreach($rs as $row) {
$key=$row["fkey"];
$val=$row["fval"];
$t->set_var(array(
$key => $val,
$key.$val => ($val)?"selected":"",
$key."_".$val => ($val)?"checked":""
));
}
}
}
$maske=substr($owner,0,1);
$t = new Template($base);
if ($_POST["save"]) saveFelder($_POST);
if ($_POST["suche"]) {
$daten = suchFelder($_POST);
if (count($daten)==1 && $daten<>false) {
if ($maske=="P") {
header ("location:kontakt.php?id=".$daten[0]["cp_id"]);
} else {
header ("location:firma1.php?Q=$maske&id=".$daten[0]["id"]);
}
} else if (count($daten)>1) {
clearCSVData();
if ($maske=="P") {
$t->set_file(array("fa1" => "personen1L.tpl"));
insertCSVData(array("ANREDE","TITEL","NAME1","NAME2","LAND","PLZ","ORT","STRASSE",
"TEL","FAX","EMAIL","FIRMA","FaID","GESCHLECHT","ID"),-1);
} else {
$t->set_file(array("fa1" => "firmen1L.tpl"));
insertCSVData(array("ANREDE","NAME1","NAME2","LAND","PLZ","ORT","STRASSE","TEL","FAX","EMAIL",
"KONTAKT","ID","KDNR","USTID","STEUERNR","KTONR","BANK","BLZ","LANG","KDTYP"),-1);
}
$t->set_block("fa1","Liste","Block");
$t->set_var(array(
'CRMCSS' => $head['CRMCSS'],
'FAART' => ($Q=="C")?"Customer":"Vendor",
'msg' => $msg,
));
$i=0;
if ($maske=="P") {
foreach ($daten as $zeile) {
if ($zeile["cp_gender"] =="f"){
if ($zeile["language_id"]) {
$zeile["cp_greeting"]= $anredenFrau[$zeile["language_id"]];
} else {
$zeile["cp_greeting"]="Frau";
}
} else if ($zeile["cp_gender"] =="m"){
if ($zeile["language_id"]) {
$zeile["cp_greeting"]= $anredenHerr[$zeile["language_id"]];
} else {
$zeile["cp_greeting"]="Herr";
}
} else {
$zeile["cp_greeting"]="";
}
insertCSVData(array($zeile["cp_greeting"],$zeile["cp_title"],$zeile["cp_name"],$zeile["cp_givenname"],
$zeile["cp_country"],$zeile["cp_zipcode"],$zeile["cp_city"],$zeile["cp_street"],
$zeile["cp_phone1"],$zeile["cp_fax"],$zeile["cp_email"],(($zeile["cfirma"])?$zeile["cfirma"]:$zeile["vfirma"]),
$zeile["cp_cv_id"],$zeile["cp_gender"]),$zeile["cp_id"]);
if ($zeile["cfirma"]) { $Quelle = "C"; }
else if ($zeile["vfirma"]) { $Quelle = "V"; }
else { $quelle = ""; };
if ($_POST["FID1"]) {
$insk="<input type='checkbox' name='kontid[]' value='".$zeile["cp_id"]."'>";
$js="";
} else {
$js='showK('.$zeile["cp_id"].',"'.$Quelle.'");'; //showK({PID},'{TBL}')
$insk="";
};
$t->set_var(array(
'js' => $js,
'LineCol' => ($i%2+1),
'Name' => $zeile["cp_name"].", ".$zeile["cp_givenname"],
'Plz' => $zeile["cp_zipcode"],
'Ort' => $zeile["cp_city"],
'Telefon' => $zeile["cp_phone1"],
'eMail' => $zeile["cp_email"],
'Firma' => ($zeile["cfirma"])?$zeile["cfirma"]:$zeile["vfirma"],
'insk' => $insk,
'DEST' => "",
'QUELLE' => $Quelle,
'Q' => $Quelle,
));
$t->parse("Block","Liste",true);
$i++;
}
} else {
foreach ($daten as $zeile) {
insertCSVData(array($zeile["greeting"],$zeile["name"],$zeile["department_1"],
$zeile["country"],$zeile["zipcode"],$zeile["city"],$zeile["street"],
$zeile["phone"],$zeile["fax"],$zeile["email"],$zeile["contact"],$zeile["id"],
($Q=="C")?$zeile["customernumber"]:$zeile["vendornumber"],
$zeile["ustid"],$zeile["taxnumber"],
$zeile["account_number"],$zeile["bank"],$zeile["bank_code"],
$zeile["language"],$zeile["business_id"]),$zeile["id"]);
$t->set_var(array(
'Q' => $maske,
'ID' => $zeile["id"],
'LineCol' => ($i%2+1),
'KdNr' => ($maske=="C")?$zeile["customernumber"]:$zeile["vendornumber"],
'Name' => $zeile["name"],
'Plz' => $zeile["zipcode"],
'Ort' => $zeile["city"],
'Telefon' => $zeile["phone"],
'eMail' => $zeile["email"]
));
$t->parse("Block","Liste",true);
}
}
$t->Lpparse("out",array("fa1"),$_SESSION['countrycode'],"firma");
exit();
} else {
$msg="Sorry, not found.";
}
}
$t->set_file(array("extra" => "extra$maske.tpl"));
$visible = 'style="visibility:visible"';
$hidden = 'style="visibility:hidden"';
$t->set_var(array(
'CRMCSS' => $head['CRMCSS'],
'STYLESHEETS' => $menu['stylesheets'],
'JQUERY' => $_SESSION['baseurl'].'crm/',
'visiblesichern' => ($owner=='P0')?$hidden:$visible,
'visiblesuchen' => ($owner=='P0')?$visible:$hidden,
));
getFelder($owner,$t);
$t->pparse("out",array("extra"));
?>