|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Handles a contact |
|
4
|
|
|
* |
|
5
|
|
|
* I think we should distinguish between company and contact |
|
6
|
|
|
* |
|
7
|
|
|
|
|
8
|
|
|
// www, email, cvr, ean hoerer ikke hertil |
|
9
|
|
|
abstract class Address |
|
10
|
|
|
{ |
|
11
|
|
|
private $types; |
|
12
|
|
|
|
|
13
|
|
|
// istedet for belong_to og belong_to_id |
|
14
|
|
|
// skal vaere den samme maade som tags |
|
15
|
|
|
|
|
16
|
|
|
public function __construct($data) { |
|
17
|
|
|
$this->init(); |
|
18
|
|
|
// data is put into variables |
|
19
|
|
|
// this can be done either from a database or from some form input (remember to validate from forminput) |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function registerType($id, $type) |
|
23
|
|
|
{ |
|
24
|
|
|
// some rules for id and type |
|
25
|
|
|
$this->types[$id] = $type; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
function getTypes() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->types; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
abstract function init(); |
|
34
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// this is the one we use for our application |
|
38
|
|
|
class MyAddress extends Address |
|
39
|
|
|
{ |
|
40
|
|
|
function init() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->registerType(1, 'intranet'); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
class Contact |
|
47
|
|
|
{ |
|
48
|
|
|
public $name; |
|
49
|
|
|
public $occupation: |
|
50
|
|
|
public $birthday; |
|
51
|
|
|
|
|
52
|
|
|
// et eller andet med et keyword |
|
53
|
|
|
// work, home, delivery, billing etc. |
|
54
|
|
|
function addAddress() {} |
|
55
|
|
|
|
|
56
|
|
|
function setPrimaryAddress() {} |
|
57
|
|
|
|
|
58
|
|
|
function getPrimaryAddress() {} |
|
59
|
|
|
|
|
60
|
|
|
function getAddresses() {} |
|
61
|
|
|
|
|
62
|
|
|
//////////////////////////// |
|
63
|
|
|
|
|
64
|
|
|
function addEmail() {} |
|
65
|
|
|
|
|
66
|
|
|
function getEmails() {} |
|
67
|
|
|
|
|
68
|
|
|
function setPrimaryEmail() {} |
|
69
|
|
|
|
|
70
|
|
|
function getPrimaryEmail() {} |
|
71
|
|
|
|
|
72
|
|
|
//////////////////////////// |
|
73
|
|
|
|
|
74
|
|
|
function getBirthday() { // return date object } |
|
75
|
|
|
|
|
76
|
|
|
///////////////////////////// |
|
77
|
|
|
|
|
78
|
|
|
function addPicture() {} |
|
79
|
|
|
|
|
80
|
|
|
function setPrimaryPicture() {} |
|
81
|
|
|
|
|
82
|
|
|
function getPictures() {} |
|
83
|
|
|
|
|
84
|
|
|
/////////////////////////////// |
|
85
|
|
|
|
|
86
|
|
|
function addWebsite() {} |
|
87
|
|
|
|
|
88
|
|
|
function getWebsites() {} |
|
89
|
|
|
|
|
90
|
|
|
//////////////////////////////// |
|
91
|
|
|
|
|
92
|
|
|
// maaske med mobile eller landline, work |
|
93
|
|
|
function addPhone() {} |
|
94
|
|
|
|
|
95
|
|
|
function getPhones() {} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
class Company extends Contact |
|
100
|
|
|
{ |
|
101
|
|
|
public $ean; |
|
102
|
|
|
public $cvr; |
|
103
|
|
|
|
|
104
|
|
|
function addContact() {} |
|
105
|
|
|
|
|
106
|
|
|
function getContacts() |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
* |
|
112
|
|
|
* @package Intraface_Contact |
|
113
|
|
|
* @author Lars Olesen <[email protected]> |
|
114
|
|
|
* @author Sune Jensen <[email protected]> |
|
115
|
|
|
* @copyright Lars Olesen |
|
116
|
|
|
*/ |
|
117
|
|
|
require_once dirname(__FILE__) . '/ContactPerson.php'; |
|
118
|
|
|
require_once 'Intraface/functions.php'; |
|
119
|
|
|
|
|
120
|
|
|
class Contact extends Intraface_Standard |
|
121
|
|
|
{ |
|
122
|
|
|
/** |
|
123
|
|
|
* @var object |
|
124
|
|
|
*/ |
|
125
|
|
|
public $kernel; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @var integer |
|
129
|
|
|
*/ |
|
130
|
|
|
protected $id; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @var array |
|
134
|
|
|
*/ |
|
135
|
|
|
public $value; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @var object |
|
139
|
|
|
*/ |
|
140
|
|
|
public $address; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @var object |
|
144
|
|
|
*/ |
|
145
|
|
|
public $delivery_address; |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @var object |
|
149
|
|
|
*/ |
|
150
|
|
|
public $error; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @var object |
|
154
|
|
|
*/ |
|
155
|
|
|
public $contactperson; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @var object |
|
159
|
|
|
*/ |
|
160
|
|
|
protected $message; |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @var object |
|
164
|
|
|
*/ |
|
165
|
|
|
public $keywords; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @var object |
|
169
|
|
|
*/ |
|
170
|
|
|
protected $lock; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @var array |
|
174
|
|
|
*/ |
|
175
|
|
|
protected $addresses = array( |
|
176
|
|
|
0 => 'standard', |
|
177
|
|
|
1 => 'delivery', |
|
178
|
|
|
2 => 'invoice'); |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @var array |
|
182
|
|
|
*/ |
|
183
|
|
|
protected $types = array( |
|
184
|
|
|
0 => 'private', |
|
185
|
|
|
1 => 'corporation'); |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @todo has to be made private |
|
189
|
|
|
*/ |
|
190
|
|
|
public $dbquery; |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Constructor |
|
194
|
|
|
* |
|
195
|
|
|
* @param object $kernel |
|
196
|
|
|
* @param integer $id Contact id |
|
197
|
|
|
* |
|
198
|
|
|
* @return void |
|
|
|
|
|
|
199
|
|
|
*/ |
|
200
|
71 |
|
public function __construct($kernel, $id = 0) |
|
201
|
|
|
{ |
|
202
|
71 |
|
$this->kernel = $kernel; |
|
203
|
|
|
//$contact_module = $this->kernel->getModule('contact'); |
|
|
|
|
|
|
204
|
|
|
//$this->types = $contact_module->getSetting('type'); |
|
|
|
|
|
|
205
|
|
|
|
|
206
|
71 |
|
$this->error = new Intraface_Error; |
|
207
|
71 |
|
$this->id = (int)$id; |
|
208
|
|
|
|
|
209
|
71 |
|
$this->fields = array('type_key', 'paymentcondition', 'number', 'preferred_invoice', 'openid_url', 'username', 'code'); |
|
|
|
|
|
|
210
|
|
|
|
|
211
|
71 |
|
if ($this->id > 0) { |
|
212
|
69 |
|
$this->load(); |
|
213
|
69 |
|
} |
|
214
|
71 |
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Used by Keyword |
|
218
|
|
|
* |
|
219
|
|
|
* @see Keyword |
|
220
|
|
|
* |
|
221
|
|
|
* @return string |
|
222
|
|
|
*/ |
|
223
|
|
|
function identify() |
|
224
|
|
|
{ |
|
225
|
|
|
return 'contact'; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
function getKernel() |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->kernel; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
function getError() |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->error; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
View Code Duplication |
public function getDBQuery() |
|
|
|
|
|
|
239
|
|
|
{ |
|
240
|
|
|
if ($this->dbquery) { |
|
241
|
|
|
return $this->dbquery; |
|
242
|
|
|
} |
|
243
|
|
|
$this->dbquery = new Intraface_DBQuery($this->kernel, "contact", "contact.active = 1 AND contact.intranet_id = ".$this->kernel->intranet->get("id")); |
|
244
|
|
|
$this->dbquery->setJoin("LEFT", "address", "address.belong_to_id = contact.id", "address.active = 1 AND address.type = 3"); |
|
245
|
|
|
$this->dbquery->useErrorObject($this->error); |
|
246
|
|
|
|
|
247
|
|
|
return $this->dbquery; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Constructor |
|
252
|
|
|
* |
|
253
|
|
|
* @param object $kernel |
|
254
|
|
|
* @param string $type What should the contact object be created from |
|
255
|
|
|
* @param string $id The value which corresponds to the type |
|
|
|
|
|
|
256
|
|
|
* |
|
257
|
|
|
* @return object |
|
258
|
|
|
*/ |
|
259
|
68 |
|
public function factory($kernel, $type, $value) |
|
260
|
|
|
{ |
|
261
|
|
|
// Husk noget validering af de forskellige values og typer |
|
262
|
3 |
|
$gateway = new Intraface_modules_contact_ContactGateway($kernel, new DB_Sql); |
|
263
|
|
|
try { |
|
264
|
|
|
switch ($type) { |
|
265
|
3 |
|
case 'email': |
|
266
|
68 |
|
$emails = $gateway->findByEmail($value); |
|
267
|
3 |
|
return $emails[0]; |
|
268
|
|
|
case 'code': |
|
269
|
|
|
return $gateway->findByCode($value); |
|
270
|
|
|
case 'username': |
|
271
|
|
|
return $gateway->findByUsername($value); |
|
272
|
|
|
case 'openid_url': |
|
273
|
|
|
return $gateway->findByOpenId($value); |
|
274
|
|
|
// Her b�r vel v�re et tjek p� hvor mange - og hvis mange give en fejl |
|
275
|
|
|
break; |
|
|
|
|
|
|
276
|
|
|
default: |
|
277
|
|
|
throw new Exception('Contact::factory() skal bruge en type'); |
|
278
|
|
|
break; |
|
|
|
|
|
|
279
|
|
|
} |
|
280
|
|
|
} catch (Exception $e) { |
|
281
|
|
|
return $contact = new Contact($kernel); |
|
|
|
|
|
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/* |
|
|
|
|
|
|
285
|
|
|
$db = new DB_Sql; |
|
286
|
|
|
switch($type) { |
|
287
|
|
|
case 'email': |
|
288
|
|
|
$db->query("SELECT address.belong_to_id AS id FROM contact INNER JOIN address ON address.belong_to_id = contact.id WHERE address.email = '".$value."' AND contact.intranet_id = " . $kernel->intranet->get('id') . " AND address.active = 1 AND contact.active = 1"); |
|
289
|
|
|
break; |
|
290
|
|
|
case 'code': |
|
291
|
|
|
$db->query("SELECT id FROM contact WHERE code = '".$value."' AND contact.intranet_id = " . $kernel->intranet->get('id')); |
|
292
|
|
|
break; |
|
293
|
|
|
case 'username': |
|
294
|
|
|
$db->query("SELECT id FROM contact WHERE username = '".$value['username']."' AND password = '".$value['password']."' AND contact.intranet_id = " . $kernel->intranet->get('id')); |
|
295
|
|
|
break; |
|
296
|
|
|
case 'openid_url': |
|
297
|
|
|
$db->query("SELECT id FROM contact WHERE openid_url = '".$value."' AND contact.intranet_id = " . $kernel->intranet->get('id')); |
|
298
|
|
|
// Her b�r vel v�re et tjek p� hvor mange - og hvis mange give en fejl |
|
299
|
|
|
break; |
|
300
|
|
|
default: |
|
301
|
|
|
throw new Exception('Contact::factory() skal bruge en type'); |
|
302
|
|
|
break; |
|
303
|
|
|
} |
|
304
|
|
|
if (!$db->nextRecord()) { |
|
305
|
|
|
return $contact = new Contact($kernel); |
|
306
|
|
|
} |
|
307
|
|
|
$id = $db->f('id'); |
|
308
|
|
|
|
|
309
|
|
|
return ($contact = new Contact($kernel, $id)); |
|
310
|
|
|
*/ |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Loads values for the contact into an array |
|
315
|
|
|
* |
|
316
|
|
|
* @return true on success |
|
317
|
|
|
*/ |
|
318
|
70 |
|
private function load() |
|
319
|
|
|
{ |
|
320
|
70 |
|
$db = new DB_Sql; |
|
321
|
70 |
|
$this->value = array(); |
|
322
|
|
|
|
|
323
|
70 |
|
$db->query("SELECT id, ".implode(',', $this->fields).", password |
|
324
|
|
|
FROM contact |
|
325
|
70 |
|
WHERE contact.id=".$this->id." |
|
326
|
70 |
|
AND intranet_id =".$this->kernel->intranet->get('id')); |
|
327
|
|
|
|
|
328
|
70 |
View Code Duplication |
if (!$db->nextRecord()) { |
|
329
|
3 |
|
$this->id = 0; |
|
330
|
3 |
|
$this->value['id'] = 0; |
|
331
|
3 |
|
return false; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
68 |
|
$this->value['id'] = $db->f('id'); |
|
335
|
|
|
|
|
336
|
68 |
|
foreach ($this->fields as $field) { |
|
337
|
68 |
|
$this->value[$field] = $db->f($field); |
|
338
|
68 |
|
} |
|
339
|
68 |
|
$this->value['type_key'] = $db->f('type_key'); |
|
340
|
68 |
|
$this->value['type'] = $this->getType(); |
|
341
|
68 |
|
$this->value['password'] = $db->f('password'); |
|
342
|
68 |
|
$this->value['username'] = $db->f('username'); |
|
343
|
68 |
|
$this->value['number'] = $db->f('number'); |
|
344
|
68 |
|
$this->value['code'] = $db->f('code'); |
|
345
|
|
|
|
|
346
|
68 |
|
if ($this->get('type') == 'corporation') { |
|
347
|
3 |
|
$this->contactperson = new ContactPerson($this); |
|
348
|
3 |
|
} |
|
349
|
|
|
|
|
350
|
68 |
|
$this->address = Intraface_Address::factory('contact', $db->f('id')); |
|
|
|
|
|
|
351
|
68 |
|
$this->delivery_address = Intraface_Address::factory('contact_delivery', $db->f('id')); |
|
|
|
|
|
|
352
|
|
|
|
|
353
|
|
|
// name m� ikke fjernes - bruges af keywords |
|
354
|
68 |
|
$this->value['name'] = $this->address->get('name'); |
|
355
|
68 |
|
$this->value['openid_url'] = $this->get('openid_url'); |
|
356
|
|
|
|
|
357
|
68 |
|
$this->value['id'] = $db->f('id'); // m� ikke fjernes |
|
358
|
|
|
|
|
359
|
68 |
|
return true; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* Gets the address |
|
364
|
|
|
* |
|
365
|
|
|
* @return object |
|
366
|
|
|
*/ |
|
367
|
2 |
|
public function getAddress() |
|
368
|
|
|
{ |
|
369
|
2 |
|
if (!is_object($this->address)) { |
|
370
|
|
|
$this->address = Intraface_Address::factory('contact', $this->id); |
|
|
|
|
|
|
371
|
|
|
} |
|
372
|
2 |
|
return $this->address; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Gets the login url for the contact |
|
377
|
|
|
* |
|
378
|
|
|
* @return string |
|
379
|
|
|
*/ |
|
380
|
11 |
|
public function getLoginUrl() |
|
381
|
|
|
{ |
|
382
|
|
|
// HACK NECCESSARY FOR THE NEWSLETTERSUBSCRIBER |
|
383
|
11 |
|
$this->kernel->useModule('contact'); |
|
384
|
11 |
|
return ($this->value['login_url'] = 'http://' . $this->kernel->getSetting()->get('intranet', 'contact.login_url') . '/' .$this->kernel->intranet->get('identifier') . '/login?code='. $this->get('code')); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Validates values |
|
389
|
|
|
* |
|
390
|
|
|
* @param array $var Values to validate |
|
391
|
|
|
* |
|
392
|
|
|
* @return true on success |
|
393
|
|
|
*/ |
|
394
|
68 |
|
public function validate($var) |
|
395
|
|
|
{ |
|
396
|
68 |
|
$var = $var; |
|
|
|
|
|
|
397
|
|
|
|
|
398
|
68 |
|
if (array_key_exists('number', $var) and !$this->isNumberFree($var['number'])) { |
|
|
|
|
|
|
399
|
|
|
$this->error->set('Kundenummeret er ikke frit'); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
68 |
|
$validator = new Intraface_Validator($this->error); |
|
403
|
68 |
|
if (!empty($var['type_key'])) { |
|
404
|
3 |
|
$validator->isNumeric($var['type_key'], 'Fejl i typen', 'allow_empty'); |
|
405
|
3 |
|
} |
|
406
|
68 |
|
if (!empty($var['openid_url'])) { |
|
407
|
|
|
$validator->isUrl($var['openid_url'], 'Openid_url', 'allow_empty'); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
// address |
|
411
|
68 |
|
$validator->isString($var['name'], 'Navnet er ikke en gyldig streng'); |
|
412
|
68 |
|
if (!empty($var['address'])) { |
|
413
|
|
|
$validator->isString($var['address'], 'Adressen er ikke en streng', '', 'allow_empty'); |
|
414
|
|
|
} |
|
415
|
68 |
|
if (!empty($var['postcode'])) { |
|
416
|
|
|
$validator->isString($var['postcode'], 'Postkoden er ikke gyldig', '', 'allow_empty'); |
|
417
|
|
|
} |
|
418
|
68 |
|
if (!empty($var['city'])) { |
|
419
|
|
|
$validator->isString($var['city'], 'Byen er ikke en by', '', 'allow_empty'); |
|
420
|
|
|
} |
|
421
|
68 |
|
if (!empty($var['country'])) { |
|
422
|
|
|
$validator->isString($var['country'], 'Der er fejl i landet', '', 'allow_empty'); |
|
423
|
|
|
} |
|
424
|
68 |
|
if (!empty($var['phone'])) { |
|
425
|
55 |
|
$validator->isString($var['phone'], 'Telefonnummeret et ikke rigtigt.', '', 'allow_empty'); |
|
426
|
55 |
|
} |
|
427
|
68 |
|
if (!empty($var['email'])) { |
|
428
|
68 |
|
$validator->isEmail($var['email'], 'E-mailen er ikke en rigtig e-mail', 'allow_empty'); |
|
429
|
68 |
|
} |
|
430
|
68 |
|
if (!empty($var['website'])) { |
|
431
|
|
|
$validator->isUrl($var['website'], 'Der er fejl i urlen', 'allow_empty'); |
|
432
|
|
|
} |
|
433
|
68 |
|
if (!empty($var['cvr'])) { |
|
434
|
|
|
$validator->isNumeric($var['cvr'], 'Fejl i cvr-nummeret', 'allow_empty'); |
|
435
|
|
|
} |
|
436
|
68 |
|
settype($var['ean'], 'string'); |
|
437
|
68 |
|
if (!empty($var['ean'])) { |
|
438
|
5 |
|
$validator->isNumeric($var['ean'], 'Fejl i ean-nummeret', 'allow_empty'); |
|
439
|
5 |
|
} |
|
440
|
|
|
|
|
441
|
68 |
|
if (!empty($var['ean']) and strlen($var['ean']) != 13) { |
|
|
|
|
|
|
442
|
|
|
$this->error->set('EAN-nummeret skal pr�cis v�re 13 tal'); |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
//deliveryaddress |
|
446
|
68 |
|
if (!empty($var['delivery_name'])) { |
|
447
|
|
|
$validator->isString($var['delivery_name'], 'Leveringsadressen forkert', '', 'allow_empty'); |
|
448
|
|
|
} |
|
449
|
68 |
|
if (!empty($var['delivery_address'])) { |
|
450
|
|
|
$validator->isString($var['delivery_address'], 'Leveringsadressen forkert', '', 'allow_empty'); |
|
451
|
|
|
} |
|
452
|
68 |
|
if (!empty($var['delivery_postcode'])) { |
|
453
|
|
|
$validator->isString($var['delivery_postcode'], 'Leveringsadressens postnummer', '', 'allow_empty'); |
|
454
|
|
|
} |
|
455
|
68 |
|
if (!empty($var['delivery_city'])) { |
|
456
|
|
|
$validator->isString($var['delivery_city'], 'Leveringsadressens by', '', 'allow_empty'); |
|
457
|
|
|
} |
|
458
|
68 |
|
if (!empty($var['delivery_country'])) { |
|
459
|
|
|
$validator->isString($var['delivery_country'], 'Leveringsadressens land', '', 'allow_empty'); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
// other |
|
463
|
68 |
|
if (!empty($var['paymentcondition'])) { |
|
464
|
|
|
$var['paymentcondition'] = 0; |
|
465
|
|
|
} |
|
466
|
68 |
|
settype($var['paymentcondition'], 'integer'); |
|
467
|
68 |
|
$validator->isNumeric($var['paymentcondition'], 'Betalingsbetingelserne er ikke sat', 'allow_empty'); |
|
468
|
68 |
|
if (empty($var['paymentcondition'])) { |
|
469
|
|
|
//$var['paymentcondition'] = $this->kernel->setting->get('intranet', 'contact.standard_paymentcondition'); |
|
|
|
|
|
|
470
|
68 |
|
$var['paymentcondition'] = 8; |
|
471
|
68 |
|
} |
|
472
|
|
|
|
|
473
|
68 |
|
if (empty($var['preferred_invoice'])) { |
|
474
|
58 |
|
$var['preferred_invoice'] = 0; |
|
475
|
58 |
|
} |
|
476
|
68 |
|
settype($var['preferred_invoice'], 'integer'); |
|
477
|
68 |
|
$validator->isNumeric($var['preferred_invoice'], 'Fejl i preferred_invoice', 'allow_empty'); |
|
478
|
|
|
/* |
|
|
|
|
|
|
479
|
|
|
if ($var['preferred_invoice'] == 3 AND empty($var['ean'])) { |
|
480
|
|
|
// @todo this creates problems from the shop when EAN has been chosen |
|
481
|
|
|
$this->error->set('Du skal udfylde EAN-nummeret, hvis du v�lger en elektronisk faktura'); |
|
482
|
|
|
} |
|
483
|
|
|
*/ |
|
484
|
|
|
|
|
485
|
68 |
|
if ($var['preferred_invoice'] == 2 and empty($var['email'])) { |
|
|
|
|
|
|
486
|
|
|
$this->error->set('E-mailen skal udfyldes, hvis kontakten foretr�kker e-mail.'); |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
68 |
|
if ($this->error->isError()) { |
|
490
|
|
|
//$this->error->view(); |
|
|
|
|
|
|
491
|
1 |
|
return false; |
|
492
|
|
|
} |
|
493
|
68 |
|
return true; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Saves the contact |
|
499
|
|
|
* |
|
500
|
|
|
* @param int $var['id'] Kundeid |
|
|
|
|
|
|
501
|
|
|
* @param string $var['company'] |
|
|
|
|
|
|
502
|
|
|
* @param string $var['address'] |
|
|
|
|
|
|
503
|
|
|
* @param string $var['postalcode'] |
|
|
|
|
|
|
504
|
|
|
* @param string $var['town'] |
|
|
|
|
|
|
505
|
|
|
* @param string $var['country'] |
|
|
|
|
|
|
506
|
|
|
* @param string $var['email'] |
|
|
|
|
|
|
507
|
|
|
* @param string $var['website'] |
|
|
|
|
|
|
508
|
|
|
* @param string $var['phone'] |
|
|
|
|
|
|
509
|
|
|
* @param string $var['deliveryaddress'] |
|
|
|
|
|
|
510
|
|
|
* @param string $var['deliverypostalcode'] |
|
|
|
|
|
|
511
|
|
|
* @param string $var['deliverytown'] |
|
|
|
|
|
|
512
|
|
|
* @param string $var['deliverycountry'] |
|
|
|
|
|
|
513
|
|
|
* @param string $var['paymentcondition'] |
|
|
|
|
|
|
514
|
|
|
* |
|
515
|
|
|
* @return void |
|
516
|
|
|
*/ |
|
517
|
68 |
|
public function save($var) |
|
518
|
|
|
{ |
|
519
|
|
|
// safeToDb must not be run on all the values, as it is run |
|
520
|
|
|
// again in Address. Make sure to run it on the fields being saved here. |
|
521
|
|
|
|
|
522
|
68 |
|
$sql_items = ''; |
|
523
|
|
|
|
|
524
|
68 |
|
if ($this->id == 0 and empty($var['number'])) { |
|
|
|
|
|
|
525
|
68 |
|
$var['number'] = $this->getMaxNumber() + 1; |
|
|
|
|
|
|
526
|
68 |
|
} |
|
527
|
|
|
|
|
528
|
68 |
|
if (isset($var['type'])) { |
|
529
|
7 |
|
$type_key = array_search($var['type'], $this->types); |
|
530
|
7 |
|
if ($type_key === false) { |
|
531
|
|
|
$this->error->set('invalid type for the contact'); |
|
532
|
|
|
} else { |
|
533
|
7 |
|
$var['type_key'] = $type_key; |
|
534
|
|
|
} |
|
535
|
7 |
|
} |
|
536
|
|
|
|
|
537
|
68 |
|
if (!$this->validate($var)) { |
|
538
|
|
|
return 0; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
// skrive sql |
|
542
|
68 |
|
foreach ($this->fields as $field) { |
|
543
|
68 |
|
if (!array_key_exists($field, $var)) { |
|
544
|
68 |
|
continue; |
|
545
|
|
|
} |
|
546
|
68 |
|
if (isset($var[$field])) { |
|
547
|
68 |
|
$sql_items .= $field." = '".safeToDb($var[$field])."', "; |
|
548
|
68 |
|
} |
|
549
|
68 |
|
} |
|
550
|
|
|
|
|
551
|
|
|
|
|
552
|
|
|
// prepare sql to update or insert |
|
553
|
68 |
|
if ($this->id > 0) { |
|
554
|
|
|
$sql="UPDATE contact "; |
|
555
|
|
|
$sql_after=" WHERE id='".$this->id."'"; |
|
556
|
|
|
$sql_create = ""; |
|
557
|
|
|
} else { |
|
558
|
68 |
|
$sql="INSERT INTO contact "; |
|
559
|
68 |
|
$sql_after = ", code='".safeToDb(md5(date('Y-m-d H:i:s') . $sql_items))."'"; |
|
560
|
68 |
|
$sql_create = "date_created = NOW(),"; |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
68 |
|
$sql .= " SET ".$sql_create. " |
|
564
|
68 |
|
intranet_id = '". $this->kernel->intranet->get('id')."'," |
|
565
|
68 |
|
.$sql_items. |
|
566
|
|
|
"date_changed = NOW() |
|
567
|
68 |
|
$sql_after"; |
|
568
|
|
|
|
|
569
|
68 |
|
$db = new DB_Sql; |
|
570
|
68 |
|
$db->query($sql); |
|
571
|
68 |
|
if ($this->id == 0) { |
|
572
|
68 |
|
$this->id = $db->insertedId(); |
|
573
|
68 |
|
} |
|
574
|
|
|
|
|
575
|
|
|
// Standardadresse |
|
576
|
68 |
|
$address_object = Intraface_Address::factory('contact', $this->id); |
|
|
|
|
|
|
577
|
68 |
|
$address_fields = $address_object->fields; |
|
578
|
|
|
|
|
579
|
68 |
|
foreach ($address_fields as $key => $value) { |
|
580
|
68 |
|
if (array_key_exists($value, $var)) { |
|
581
|
68 |
|
$standard_address_to_save[$value] = $var[$value]; |
|
|
|
|
|
|
582
|
68 |
|
} |
|
583
|
68 |
|
} |
|
584
|
68 |
|
if (!empty($standard_address_to_save)) { |
|
585
|
68 |
|
if (!$address_object->save($standard_address_to_save)) { |
|
586
|
|
|
return 0; |
|
587
|
|
|
} |
|
588
|
68 |
|
} |
|
589
|
|
|
|
|
590
|
|
|
// Delivery Address |
|
591
|
68 |
|
foreach ($address_fields as $key => $value) { |
|
592
|
68 |
|
if (array_key_exists('delivery_'.$value, $var)) { |
|
593
|
|
|
$delivery_address_to_save[$value] = $var['delivery_' . $value]; |
|
|
|
|
|
|
594
|
|
|
} |
|
595
|
68 |
|
} |
|
596
|
|
|
|
|
597
|
68 |
|
$delivery_address_object = Intraface_Address::factory('contact_delivery', $this->id); |
|
|
|
|
|
|
598
|
|
|
|
|
599
|
68 |
|
if (!empty($delivery_address_to_save)) { |
|
600
|
|
|
if (!$delivery_address_object->save($delivery_address_to_save)) { |
|
601
|
|
|
return 0; |
|
602
|
|
|
} |
|
603
|
|
|
} |
|
604
|
68 |
|
$this->load(); |
|
605
|
|
|
|
|
606
|
68 |
|
return $this->id; |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* Deletes a contact |
|
611
|
|
|
* |
|
612
|
|
|
* Never delete a contact entirely. Should only be deactivated. |
|
613
|
|
|
* |
|
614
|
|
|
* @return integer 0 = false eller 1 = true |
|
615
|
|
|
*/ |
|
616
|
|
View Code Duplication |
public function delete() |
|
|
|
|
|
|
617
|
|
|
{ |
|
618
|
|
|
if ($this->get('locked') == 1) { |
|
619
|
|
|
$this->error->set('Posten er l�st og kan ikke slettes'); |
|
620
|
|
|
return false; |
|
621
|
|
|
} |
|
622
|
|
|
if ($this->id == 0) { |
|
623
|
|
|
$this->error->set('Kender ikke id, s� kan ikke slette kunden'); |
|
624
|
|
|
return false; |
|
625
|
|
|
} |
|
626
|
|
|
$db = new DB_Sql; |
|
627
|
|
|
$db->query("UPDATE contact SET active = 0, date_changed = NOW() WHERE intranet_id = " . $this->kernel->intranet->get("id") . " AND id = " . $this->id); |
|
628
|
|
|
return true; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
/** |
|
632
|
|
|
* Undelete |
|
633
|
|
|
* |
|
634
|
|
|
* @return boolean |
|
635
|
|
|
*/ |
|
636
|
|
View Code Duplication |
public function undelete() |
|
|
|
|
|
|
637
|
|
|
{ |
|
638
|
|
|
if ($this->get('locked') == 1) { |
|
639
|
|
|
$this->error->set('Posten er l�st og kan ikke slettes'); |
|
640
|
|
|
return false; |
|
641
|
|
|
} |
|
642
|
|
|
if ($this->id == 0) { |
|
643
|
|
|
$this->error->set('Kender ikke id, s� kan ikke slette kunden'); |
|
644
|
|
|
return false; |
|
645
|
|
|
} |
|
646
|
|
|
$db = new DB_Sql; |
|
647
|
|
|
$db->query("UPDATE contact SET active = 1, date_changed = NOW() WHERE intranet_id = " . $this->kernel->intranet->get("id") . " AND id = " . $this->id); |
|
648
|
|
|
|
|
649
|
|
|
return true; |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
/** |
|
653
|
|
|
* Tjekke om kundenummeret er frit |
|
654
|
|
|
* |
|
655
|
|
|
* @param string $number |
|
656
|
|
|
* |
|
657
|
|
|
* @return true hvis det er frit |
|
658
|
|
|
*/ |
|
659
|
68 |
|
public function isNumberFree($number) |
|
660
|
|
|
{ |
|
661
|
68 |
|
$number = (int)$number; |
|
662
|
68 |
|
$db = new DB_Sql(); |
|
663
|
|
|
$sql = "SELECT id |
|
664
|
|
|
FROM contact |
|
665
|
68 |
|
WHERE intranet_id = " . $this->kernel->intranet->get("id") . " |
|
666
|
68 |
|
AND number = " . (int)$number . " |
|
667
|
68 |
|
AND id <> " . $this->id . " |
|
668
|
|
|
AND active = 1 |
|
669
|
68 |
|
LIMIT 1"; |
|
670
|
68 |
|
$db->query($sql); |
|
671
|
68 |
|
if ($db->numRows() == 0) { |
|
672
|
68 |
|
return true; |
|
673
|
|
|
} |
|
674
|
|
|
return false; |
|
675
|
|
|
} |
|
676
|
|
|
|
|
677
|
|
|
/** |
|
678
|
|
|
* Hente det maksimale kundenummer |
|
679
|
|
|
* |
|
680
|
|
|
* @deprecated moved to gateway |
|
681
|
|
|
* |
|
682
|
|
|
* @return integer |
|
683
|
|
|
*/ |
|
684
|
|
View Code Duplication |
public function getMaxNumber() |
|
|
|
|
|
|
685
|
|
|
{ |
|
686
|
|
|
$db = new DB_Sql(); |
|
687
|
|
|
$db->query("SELECT number FROM contact WHERE intranet_id = " . $this->kernel->intranet->get("id") . " ORDER BY number DESC"); |
|
688
|
|
|
if (!$db->nextRecord()) { |
|
689
|
|
|
return 0; |
|
690
|
|
|
} |
|
691
|
|
|
return $db->f("number"); |
|
692
|
|
|
} |
|
693
|
|
|
|
|
694
|
|
|
/** |
|
695
|
|
|
* Public: Finde data til en liste |
|
696
|
|
|
* |
|
697
|
|
|
* @deprecated moved to gateway |
|
698
|
|
|
* |
|
699
|
|
|
* @param string $parameter hvad er det? |
|
700
|
|
|
* |
|
701
|
|
|
* @return array indeholdende kundedata til liste |
|
702
|
|
|
*/ |
|
703
|
|
View Code Duplication |
public function getList($parameter = "") |
|
|
|
|
|
|
704
|
|
|
{ |
|
705
|
|
|
if ($this->getDBQuery()->checkFilter("search")) { |
|
706
|
|
|
$search = $this->getDBQuery()->getFilter("search"); |
|
707
|
|
|
$this->getDBQuery()->setCondition(" |
|
708
|
|
|
contact.number = '".$search."' OR |
|
709
|
|
|
address.name LIKE '%".$search."%' OR |
|
710
|
|
|
address.address LIKE '%".$search."%' OR |
|
711
|
|
|
address.email LIKE '%".$search."%' OR |
|
712
|
|
|
address.phone = '".$search."'"); |
|
713
|
|
|
} |
|
714
|
|
|
|
|
715
|
|
|
$this->getDBQuery()->setSorting("address.name"); |
|
716
|
|
|
|
|
717
|
|
|
$i = 0; // til at give arrayet en key |
|
718
|
|
|
|
|
719
|
|
|
$db = $this->getDBQuery()->getRecordset("contact.id, contact.number, contact.paymentcondition, address.name, address.email, address.phone, address.address, address.postcode, address.city", "", false); |
|
720
|
|
|
|
|
721
|
|
|
$contacts = array(); |
|
722
|
|
|
while ($db->nextRecord()) { |
|
723
|
|
|
// |
|
724
|
|
|
$contacts[$i]['id'] = $db->f("id"); |
|
725
|
|
|
$contacts[$i]['number'] = $db->f("number"); |
|
726
|
|
|
$contacts[$i]['paymentcondition'] = $db->f("paymentcondition"); |
|
727
|
|
|
$contacts[$i]['name'] = $db->f("name"); |
|
728
|
|
|
$contacts[$i]['address'] = $db->f("address"); |
|
729
|
|
|
$contacts[$i]['postcode'] = $db->f("postcode"); |
|
730
|
|
|
$contacts[$i]['city'] = $db->f("city"); |
|
731
|
|
|
$contacts[$i]['phone'] = $db->f("phone"); |
|
732
|
|
|
$contacts[$i]['email'] = $db->f("email"); |
|
733
|
|
|
|
|
734
|
|
|
if ($parameter == "use_address") { |
|
735
|
|
|
$address = Intraface_Address::factory("contact", $db->f("id")); |
|
|
|
|
|
|
736
|
|
|
$contacts[$i]['address'] = $address->get(); |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
$i++; |
|
740
|
|
|
} |
|
741
|
|
|
return $contacts; |
|
742
|
|
|
} |
|
743
|
|
|
|
|
744
|
|
|
/** |
|
745
|
|
|
* has contact any similar contacts based on phonenumber and email |
|
746
|
|
|
* |
|
747
|
|
|
* @return boolean |
|
748
|
|
|
*/ |
|
749
|
1 |
|
public function hasSimilarContacts() |
|
750
|
|
|
{ |
|
751
|
1 |
|
$contacts = $this->getSimilarContacts(); |
|
752
|
1 |
|
return (count($contacts) > 0); |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
/** |
|
756
|
|
|
* Return an array with similar contacts |
|
757
|
|
|
* |
|
758
|
|
|
* @return array |
|
759
|
|
|
*/ |
|
760
|
1 |
|
public function getSimilarContacts() |
|
761
|
|
|
{ |
|
762
|
1 |
|
$this->address = $this->getAddress(); |
|
763
|
|
|
|
|
764
|
1 |
|
$similar_contacts = array(); |
|
|
|
|
|
|
765
|
|
|
|
|
766
|
1 |
|
if ($this->id == 0) { |
|
767
|
|
|
return array(); |
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
1 |
|
$this->load(); |
|
771
|
|
|
|
|
772
|
1 |
|
$db = MDB2::singleton(DB_DSN); |
|
773
|
|
|
$sql = "SELECT DISTINCT(contact.id), contact.number, address.name, address.id AS address_id, address.address, address.postcode, address.phone, address.email, address.city FROM contact |
|
774
|
|
|
INNER JOIN address |
|
775
|
|
|
ON contact.id = address.belong_to_id |
|
776
|
|
|
WHERE address.type=3 |
|
777
|
|
|
AND contact.active = 1 |
|
778
|
|
|
AND address.active = 1 |
|
779
|
1 |
|
AND contact.intranet_id = " . $db->quote($this->kernel->intranet->get('id'), 'integer') . " |
|
780
|
1 |
|
AND contact.id != " . $db->quote($this->id, 'integer') . " |
|
781
|
|
|
AND ( |
|
782
|
1 |
|
(address.email = " . $db->quote($this->address->get('email'), 'text') . " AND address.email != '') |
|
783
|
1 |
|
OR (address.phone = " . $db->quote($this->address->get('phone'), 'text') . " AND address.phone != '')) |
|
784
|
|
|
|
|
785
|
1 |
|
"; |
|
786
|
|
|
|
|
787
|
1 |
|
$result = $db->query($sql); |
|
788
|
1 |
|
if (PEAR::isError($result)) { |
|
789
|
|
|
throw new Exception($result->getMessage().' '.$result->getUserInfo()); |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
1 |
|
if ($result->numRows() == 0) { |
|
793
|
|
|
return array(); |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
1 |
|
return $result->fetchAll(); |
|
797
|
|
|
} |
|
798
|
|
|
|
|
799
|
|
|
/** |
|
800
|
|
|
* Merges a contact to one contact |
|
801
|
|
|
* |
|
802
|
|
|
* - debtor |
|
803
|
|
|
* - newsletter |
|
804
|
|
|
* - procurement |
|
805
|
|
|
* - intranet |
|
806
|
|
|
* |
|
807
|
|
|
* These needs to implement a common function changeContact($old, $new) |
|
808
|
|
|
*/ |
|
809
|
|
|
function merge() |
|
810
|
|
|
{ |
|
811
|
|
|
die('Contact::merge(): Ikke implementeret'); |
|
|
|
|
|
|
812
|
|
|
} |
|
813
|
|
|
|
|
814
|
|
|
/** |
|
815
|
|
|
* Start keywordmodulet op |
|
816
|
|
|
* Denne metode kr�ves af keyword |
|
817
|
|
|
* |
|
818
|
|
|
* TODO M�ske burde denne metode hedde loadKeywords()? |
|
819
|
|
|
* |
|
820
|
|
|
* @return object |
|
821
|
|
|
*/ |
|
822
|
|
|
function getKeywords() |
|
823
|
|
|
{ |
|
824
|
|
|
return $this->keywords = new Keyword($this); |
|
825
|
|
|
} |
|
826
|
|
|
|
|
827
|
|
|
function getKeyword() |
|
828
|
|
|
{ |
|
829
|
|
|
return $this->getKeywords(); |
|
830
|
|
|
} |
|
831
|
|
|
|
|
832
|
|
|
function getKeywordAppender() |
|
833
|
|
|
{ |
|
834
|
|
|
return new Intraface_Keyword_Appender($this); |
|
835
|
|
|
} |
|
836
|
|
|
|
|
837
|
|
|
/** |
|
838
|
|
|
* Start message op |
|
839
|
|
|
* |
|
840
|
|
|
* @deprecated |
|
841
|
|
|
* |
|
842
|
|
|
* @param integer $id Optional id for the message |
|
843
|
|
|
* |
|
844
|
|
|
* @return object |
|
845
|
|
|
*/ |
|
846
|
|
|
private function loadMessage($id = 0) |
|
|
|
|
|
|
847
|
|
|
{ |
|
848
|
|
|
return $this->message = new ContactMessage($this, (int)$id); |
|
849
|
|
|
} |
|
850
|
|
|
|
|
851
|
|
|
/** |
|
852
|
|
|
* Hvis kontakten er et firma, skal den loade og inkludere kontaktpersonerne |
|
853
|
|
|
* |
|
854
|
|
|
* @param integer $id Optional id of the contact person |
|
855
|
|
|
* |
|
856
|
|
|
* @return object |
|
857
|
|
|
*/ |
|
858
|
3 |
|
function loadContactPerson($id = 0) |
|
859
|
|
|
{ |
|
860
|
3 |
|
return ($this->contactperson = new ContactPerson($this, (int)$id)); |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
/** |
|
864
|
|
|
* Funktionen skal tjekke om der er tastet nogen kontaktpersoner ind overhovedet. |
|
865
|
|
|
* Funktionen er tilt�nkt et tjek, s� man hurtigt kan tjekke om brugeren har nogen. |
|
866
|
|
|
* |
|
867
|
|
|
* @return integer |
|
868
|
|
|
*/ |
|
869
|
|
View Code Duplication |
function isFilledIn() |
|
|
|
|
|
|
870
|
|
|
{ |
|
871
|
|
|
$db = new DB_Sql; |
|
872
|
|
|
$db->query("SELECT count(*) AS antal FROM contact WHERE intranet_id = " . $this->kernel->intranet->get('id')); |
|
873
|
|
|
if ($db->nextRecord()) { |
|
874
|
|
|
return $db->f('antal'); |
|
875
|
|
|
} |
|
876
|
|
|
return 0; |
|
877
|
|
|
} |
|
878
|
|
|
|
|
879
|
|
|
/** |
|
880
|
|
|
* Generates a password for the contact |
|
881
|
|
|
* |
|
882
|
|
|
* @return boolean |
|
883
|
|
|
*/ |
|
884
|
|
View Code Duplication |
function generateCode() |
|
|
|
|
|
|
885
|
|
|
{ |
|
886
|
|
|
if ($this->id == 0) { |
|
887
|
|
|
return false; |
|
888
|
|
|
} |
|
889
|
|
|
$db = new DB_Sql; |
|
890
|
|
|
$db->query("UPDATE contact SET code = '".md5($this->id . date('Y-m-d H:i:s') . $this->kernel->intranet->get('id'))."' WHERE id = " . $this->id); |
|
891
|
|
|
$this->load(); |
|
892
|
|
|
return true; |
|
893
|
|
|
} |
|
894
|
|
|
|
|
895
|
|
|
|
|
896
|
|
|
/** |
|
897
|
|
|
* Generates a password for the contact |
|
898
|
|
|
* |
|
899
|
|
|
* @return boolean |
|
900
|
|
|
*/ |
|
901
|
|
View Code Duplication |
function generatePassword() |
|
|
|
|
|
|
902
|
|
|
{ |
|
903
|
|
|
if ($this->id == 0) { |
|
904
|
|
|
return false; |
|
905
|
|
|
} |
|
906
|
|
|
$db = new DB_Sql; |
|
907
|
|
|
$db->query("UPDATE contact SET password = '".md5($this->id . date('Y-m-d H:i:s') . $this->kernel->intranet->get('id'))."' WHERE id = " . $this->id); |
|
908
|
|
|
$this->load(); |
|
909
|
|
|
return true; |
|
910
|
|
|
} |
|
911
|
|
|
|
|
912
|
|
|
/** |
|
913
|
|
|
* Gets the contacts newsletter subscriptions |
|
914
|
|
|
* |
|
915
|
|
|
* @return array |
|
916
|
|
|
*/ |
|
917
|
|
|
function getNewsletterSubscriptions() |
|
918
|
|
|
{ |
|
919
|
|
|
$db = new DB_Sql; |
|
920
|
|
|
$db->query("SELECT * FROM newsletter_subscriber WHERE optin = 1 AND active = 1 AND contact_id = " . $this->id . " AND intranet_id =" . $this->kernel->intranet->get('id')); |
|
921
|
|
|
$lists = array(); |
|
922
|
|
|
while ($db->nextRecord()) { |
|
923
|
|
|
$lists[] = $db->f('list_id'); |
|
924
|
|
|
} |
|
925
|
|
|
return $lists; |
|
926
|
|
|
} |
|
927
|
|
|
|
|
928
|
|
|
/** |
|
929
|
|
|
* Checks whether the contact needs to accept subscriptions |
|
930
|
|
|
* |
|
931
|
|
|
* @return array |
|
932
|
|
|
*/ |
|
933
|
1 |
View Code Duplication |
function needNewsletterOptin() |
|
|
|
|
|
|
934
|
|
|
{ |
|
935
|
1 |
|
$db = new DB_Sql; |
|
936
|
1 |
|
$db->query("SELECT list_id, code FROM newsletter_subscriber WHERE optin = 0 AND contact_id = " . $this->id . " AND intranet_id =" . $this->kernel->intranet->get('id')); |
|
937
|
1 |
|
$lists = array(); |
|
938
|
1 |
|
$i = 0; |
|
939
|
1 |
|
while ($db->nextRecord()) { |
|
940
|
|
|
$lists[$i]['list_id'] = $db->f('list_id'); |
|
941
|
|
|
$lists[$i]['code'] = $db->f('code'); |
|
942
|
|
|
$i++; |
|
943
|
|
|
} |
|
944
|
1 |
|
return $lists; |
|
945
|
|
|
} |
|
946
|
|
|
|
|
947
|
|
|
/** |
|
948
|
|
|
* Kontakten kan slettes, hvis man kun er indskrevet i nyhedsbrevet. |
|
949
|
|
|
* Der b�r sikkert ogs� v�re en indstilling som ejeren af intranettet kan s�tte |
|
950
|
|
|
* efter al sandsynlighed skal denne v�re med som tjek i delete |
|
951
|
|
|
* |
|
952
|
|
|
* @return boolean |
|
953
|
|
|
*/ |
|
954
|
|
|
function canBeDeleted() |
|
955
|
|
|
{ |
|
956
|
|
|
$db = new DB_Sql; |
|
957
|
|
|
$db->query("SELECT * FROM debtor WHERE contact_id = " . $this->id . " AND intranet_id = " . $this->kernel->intranet->get('id')); |
|
958
|
|
|
if (!$db->nextRecord()) { |
|
959
|
|
|
return true; |
|
960
|
|
|
} |
|
961
|
|
|
return false; |
|
962
|
|
|
} |
|
963
|
|
|
|
|
964
|
|
|
/** |
|
965
|
|
|
* skal tage h�jde for om intranettet tillader kundelogin |
|
966
|
|
|
* |
|
967
|
|
|
* @return boolean |
|
968
|
|
|
*/ |
|
969
|
|
|
function canLogin() |
|
970
|
|
|
{ |
|
971
|
|
|
if ($this->get('active') == 0) { |
|
972
|
|
|
return false; |
|
973
|
|
|
} |
|
974
|
|
|
return true; |
|
975
|
|
|
} |
|
976
|
|
|
|
|
977
|
|
|
function getId() |
|
978
|
|
|
{ |
|
979
|
|
|
return $this->id; |
|
980
|
|
|
} |
|
981
|
|
|
|
|
982
|
68 |
|
function getType() |
|
983
|
|
|
{ |
|
984
|
68 |
|
return $this->types[$this->value['type_key']]; |
|
985
|
|
|
} |
|
986
|
|
|
} |
|
987
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.