1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * eGroupWare - Contacts Center * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by: * |
---|
6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
7 | * ------------------------------------------------------------------------- * |
---|
8 | * This program is free software; you can redistribute it and/or modify it * |
---|
9 | * under the terms of the GNU General Public License as published by the * |
---|
10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
11 | * option) any later version. * |
---|
12 | \***************************************************************************/ |
---|
13 | |
---|
14 | include_once('class.abo_catalog.inc.php'); |
---|
15 | |
---|
16 | class bo_company_manager extends abo_catalog |
---|
17 | { |
---|
18 | |
---|
19 | var $fields = array( |
---|
20 | 'id_company' => true, |
---|
21 | 'company_name' => true, |
---|
22 | 'company_notes' => true, |
---|
23 | |
---|
24 | /* Array fields */ |
---|
25 | 'contacts' => true, |
---|
26 | 'relations' => true, |
---|
27 | 'addresses' => true, |
---|
28 | 'connections' => true, |
---|
29 | 'legals' => true |
---|
30 | ); |
---|
31 | |
---|
32 | /*! |
---|
33 | |
---|
34 | @function bo_contact_manager |
---|
35 | @abstract Constructor |
---|
36 | @author Raphael Derosso Pereira |
---|
37 | |
---|
38 | */ |
---|
39 | function bo_company_manager() |
---|
40 | { |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | /*********************************************************************\ |
---|
45 | * Methods to Get Companies Info * |
---|
46 | \*********************************************************************/ |
---|
47 | |
---|
48 | /*! |
---|
49 | |
---|
50 | @function get_single_info |
---|
51 | @abstract Returns all information requested about one company |
---|
52 | @author Raphael Derosso Pereira |
---|
53 | @param integer $id_company The company ID |
---|
54 | @param array $fields The array returned by get_fields whith true |
---|
55 | on the fields to be taken. |
---|
56 | */ |
---|
57 | function get_single_info ( $id_company, $fields ) |
---|
58 | { |
---|
59 | if (!is_integer($id_company) or !is_array($fields)) |
---|
60 | { |
---|
61 | if (is_object($GLOBALS['phpgw']->log)) |
---|
62 | { |
---|
63 | $GLOBALS['phpgw']->log->message(array( |
---|
64 | 'text' => 'F-BadcontactcenterParam, wrong get_single_info parameters type.', |
---|
65 | 'line' => __LINE__, |
---|
66 | 'file' => __FILE__)); |
---|
67 | |
---|
68 | $GLOBALS['phpgw']->log->commit(); |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | // Verify permitions |
---|
77 | $permitions = $this->security->get_permissions($id_company); |
---|
78 | |
---|
79 | if (!$permitions['read']) |
---|
80 | { |
---|
81 | return false; |
---|
82 | } |
---|
83 | |
---|
84 | $company_data = $this->fields; |
---|
85 | |
---|
86 | $company = CreateObject('contactcenter.so_company', $id_company); |
---|
87 | |
---|
88 | foreach ($fields as $field => $trueness) |
---|
89 | { |
---|
90 | if (!$trueness) |
---|
91 | { |
---|
92 | unset($company_data[$field]); |
---|
93 | continue; |
---|
94 | } |
---|
95 | |
---|
96 | switch ($field) |
---|
97 | { |
---|
98 | case 'contacts': |
---|
99 | $company_data['contacts'] = $this->get_contacts($id_company); |
---|
100 | break; |
---|
101 | |
---|
102 | case 'relations': |
---|
103 | $company_data['relations'] = $this->get_relations($id_company); |
---|
104 | break; |
---|
105 | |
---|
106 | case 'addresses': |
---|
107 | $company_data['addresses'] = $this->get_addresses($id_company); |
---|
108 | break; |
---|
109 | |
---|
110 | case 'connections': |
---|
111 | $company_data['connections'] = $this->get_connections($id_company); |
---|
112 | break; |
---|
113 | |
---|
114 | case 'legals': |
---|
115 | $company_data['legals'] = $this->get_legals($id_company); |
---|
116 | break; |
---|
117 | |
---|
118 | default: |
---|
119 | $func_name = 'company->get_'.$field; |
---|
120 | $company_data[$field] = $this->$func_name(); |
---|
121 | break; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | if (!is_array($company_data)) |
---|
126 | { |
---|
127 | return false; |
---|
128 | } |
---|
129 | |
---|
130 | return $company_data; |
---|
131 | } |
---|
132 | |
---|
133 | /*! |
---|
134 | |
---|
135 | @function get_multiple_info |
---|
136 | @abstract Returns multiple companies data into one array |
---|
137 | @author Raphael Derosso Pereira |
---|
138 | |
---|
139 | @param array $id_companies The companies IDs |
---|
140 | @param array $fields The companies fields to be retrieved |
---|
141 | @param array $other_data Other informations. The format is: |
---|
142 | $other_data = array( |
---|
143 | 'offset' => <offset>, |
---|
144 | 'limit' => <max_num_returns> |
---|
145 | ); |
---|
146 | |
---|
147 | */ |
---|
148 | function get_multiple_info ( $id_companies, $fields, $other_data = false ) |
---|
149 | { |
---|
150 | if (!is_array($id_companies) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
151 | { |
---|
152 | if (is_object($GLOBALS['phpgw']->log)) |
---|
153 | { |
---|
154 | $GLOBALS['phpgw']->log->message(array( |
---|
155 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_companies_info parameter type.', |
---|
156 | 'line' => __LINE__, |
---|
157 | 'file' => __FILE__)); |
---|
158 | |
---|
159 | $GLOBALS['phpgw']->log->commit(); |
---|
160 | } |
---|
161 | else { |
---|
162 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | $companies = array(); |
---|
167 | |
---|
168 | if ($other_data) |
---|
169 | { |
---|
170 | //TODO |
---|
171 | } |
---|
172 | |
---|
173 | foreach ($id_companies as $id) |
---|
174 | { |
---|
175 | $companies[$id] = $this->get_single_info($id,$fields[$id]); |
---|
176 | } |
---|
177 | |
---|
178 | return $companies; |
---|
179 | } |
---|
180 | |
---|
181 | /*! |
---|
182 | |
---|
183 | @function get_relations |
---|
184 | @abstract Returns the IDs of all companies relations |
---|
185 | @author Raphael Derosso Pereira |
---|
186 | |
---|
187 | @param integer $id_company The company ID |
---|
188 | |
---|
189 | @return The following array: |
---|
190 | $return = array( |
---|
191 | 'relation1' => array( |
---|
192 | 'id_relation' => <id_relation>, |
---|
193 | 'id_type' => <id_type>, |
---|
194 | 'type' => '<type_name>', |
---|
195 | 'is_subordinated' => <trueness> |
---|
196 | ), |
---|
197 | 'relation2' => array(...), |
---|
198 | ... |
---|
199 | ); |
---|
200 | |
---|
201 | */ |
---|
202 | function get_relations ($id_company) |
---|
203 | { |
---|
204 | $company =& CreateObject('contactcenter.so_company', $id_company); |
---|
205 | $relations = $company->get_relations(); |
---|
206 | |
---|
207 | $count = 1; |
---|
208 | foreach($relations as $id => $type) |
---|
209 | { |
---|
210 | $relation =& CreateObject('contactcenter.so_company_relation_type',$type); |
---|
211 | $return['relation'.$count]['id_relation'] = $id; |
---|
212 | $return['relation'.$count]['id_type'] = $type; |
---|
213 | $return['relation'.$count]['type'] = $relation->get_type_name(); |
---|
214 | $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated(); |
---|
215 | $count++; |
---|
216 | } |
---|
217 | |
---|
218 | return $return; |
---|
219 | } |
---|
220 | |
---|
221 | /*! |
---|
222 | |
---|
223 | @function get_addresses |
---|
224 | @abstract Returns all companies Address Information |
---|
225 | @author Raphael Derosso Pereira |
---|
226 | |
---|
227 | @param integer $id_company The company ID |
---|
228 | |
---|
229 | @return The following array: |
---|
230 | $return = array( |
---|
231 | 'address1' => array( |
---|
232 | 'id_address' => <id_address>, |
---|
233 | 'id_type' => <id_type>, |
---|
234 | 'type' => '<type_name>', |
---|
235 | 'address1' => '<address1>', |
---|
236 | 'address2' => '<address2>', |
---|
237 | 'complement' => '<complement>', |
---|
238 | 'address_other' => '<address_other>', |
---|
239 | 'postal_code' => '<postal_code>', |
---|
240 | 'po_box' => '<po_box>', |
---|
241 | 'id_city' => '<city>', |
---|
242 | 'city_name' => '<city_name>', |
---|
243 | 'city_timezone' => '<city_timezone>', |
---|
244 | 'city_geo_location' => '<city_geo_location>', |
---|
245 | 'id_state' => '<id_state>', |
---|
246 | 'state_name' => '<state_name>', |
---|
247 | 'state_symbol' => '<state_symbol>', |
---|
248 | 'id_country' => '<id_country>', |
---|
249 | 'country_name' => '<country_name>', |
---|
250 | 'address_is_default' => <trueness> |
---|
251 | ), |
---|
252 | 'address2' => array(...), |
---|
253 | ... |
---|
254 | ); |
---|
255 | |
---|
256 | */ |
---|
257 | function get_addresses ( $id_company ) |
---|
258 | { |
---|
259 | $company =& CreateObject('contactcenter.so_company', $id_company); |
---|
260 | $addresses = $company->get_addresses(); |
---|
261 | |
---|
262 | $count = 1; |
---|
263 | foreach($addresses as $id => $type) |
---|
264 | { |
---|
265 | $address =& CreateObject('contactcenter.so_address',$id); |
---|
266 | $address_type =& CreateObject('contactcenter.so_company_address_type',$type); |
---|
267 | |
---|
268 | $return['address'.$count]['id_address'] = $id; |
---|
269 | $return['address'.$count]['id_type'] = $type; |
---|
270 | $return['address'.$count]['type'] = $address_type->get_type_name(); |
---|
271 | $return['address'.$count]['address1'] = $address->get_address1(); |
---|
272 | $return['address'.$count]['address2'] = $address->get_address2(); |
---|
273 | $return['address'.$count]['complement'] = $address->get_complement(); |
---|
274 | $return['address'.$count]['address_other'] = $address->get_address_other(); |
---|
275 | $return['address'.$count]['postal_code'] = $address->get_postal_code(); |
---|
276 | $return['address'.$count]['po_box'] = $address->get_po_box(); |
---|
277 | $return['address'.$count]['address_is_default'] = $address->is_default(); |
---|
278 | $return['address'.$count]['id_city'] = $address->get_id_city(); |
---|
279 | $return['address'.$count]['city_name'] = $address->get_city_name(); |
---|
280 | $return['address'.$count]['city_timezone'] = $address->get_city_timezone(); |
---|
281 | $return['address'.$count]['city_geo_location'] = $address->get_geo_location(); |
---|
282 | $return['address'.$count]['id_state'] = $address->get_id_state(); |
---|
283 | $return['address'.$count]['state_name'] = $address->get_state_name(); |
---|
284 | $return['address'.$count]['state_symbol'] = $address->get_state_symbol(); |
---|
285 | $return['address'.$count]['id_country'] = $address->get_id_country(); |
---|
286 | $return['address'.$count]['country_name'] = $address->get_country_name(); |
---|
287 | $count++; |
---|
288 | } |
---|
289 | |
---|
290 | return $return; |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | /*! |
---|
295 | |
---|
296 | @function get_connections |
---|
297 | @abstract Returns all companies connections information |
---|
298 | @author Raphael Derosso Pereira |
---|
299 | |
---|
300 | @param integer $id_company The company ID |
---|
301 | |
---|
302 | @return The following array: |
---|
303 | $return = array( |
---|
304 | 'connection1' => array( |
---|
305 | 'id_connection' => <id_connection>, |
---|
306 | 'id_type' => <id_type>, |
---|
307 | 'type' => '<type_name>', |
---|
308 | 'connection_name' => '<connection_name>', |
---|
309 | 'connection_value' => '<connection_value>', |
---|
310 | 'connection_is_default' => '<connection_is_default>' |
---|
311 | ), |
---|
312 | 'connection2' => array(...), |
---|
313 | ... |
---|
314 | ); |
---|
315 | |
---|
316 | */ |
---|
317 | function get_connections ( $id_company, $types ) |
---|
318 | { |
---|
319 | $company =& CreateObject('contactcenter.so_company', $id_company); |
---|
320 | $connections = $company->get_connections(); |
---|
321 | |
---|
322 | $count = 1; |
---|
323 | foreach($connections as $id => $type) |
---|
324 | { |
---|
325 | $connection =& CreateObject('contactcenter.so_connection',$id); |
---|
326 | $connection_type =& CreateObject('contactcenter.so_company_connection_type',$type); |
---|
327 | $return['connection'.$count]['id_connection'] = $id; |
---|
328 | $return['connection'.$count]['id_type'] = $type; |
---|
329 | $return['connection'.$count]['type'] = $connection_type->get_type_name(); |
---|
330 | $return['connection'.$count]['connection_name'] = $connection->get_name(); |
---|
331 | $return['connection'.$count]['connection_value'] = $connection->get_value(); |
---|
332 | $return['connection'.$count]['connection_is_default'] = $connection->is_default(); |
---|
333 | $count++; |
---|
334 | } |
---|
335 | |
---|
336 | return $return; |
---|
337 | } |
---|
338 | |
---|
339 | /*! |
---|
340 | |
---|
341 | @function get_companies |
---|
342 | @abstract Returns all Companies Employees information |
---|
343 | @author Raphael Derosso Pereira |
---|
344 | |
---|
345 | @param integer $id_company The company ID |
---|
346 | |
---|
347 | @return The following array: |
---|
348 | $return = array( |
---|
349 | 'contact1' => array( |
---|
350 | 'id_contact' => <id_company>, |
---|
351 | 'title' => '<company_name>', |
---|
352 | 'department' => '<company_value>', |
---|
353 | ), |
---|
354 | 'contact2' => array(...), |
---|
355 | ... |
---|
356 | ); |
---|
357 | |
---|
358 | */ |
---|
359 | function get_contacts ( $id_company ) |
---|
360 | { |
---|
361 | $company =& CreateObject('contactcenter.so_company', $id_company); |
---|
362 | $companies = $company->get_contacts(); |
---|
363 | |
---|
364 | $count = 1; |
---|
365 | foreach($companies as $id => $value) |
---|
366 | { |
---|
367 | $return['contact'.$count]['id_contact'] = $id; |
---|
368 | $return['contact'.$count]['title'] = $value['title']; |
---|
369 | $return['contact'.$count]['department'] = $value['department']; |
---|
370 | $count++; |
---|
371 | } |
---|
372 | |
---|
373 | return $return; |
---|
374 | } |
---|
375 | |
---|
376 | /*! |
---|
377 | |
---|
378 | @function get_legals |
---|
379 | @abstract Returns all companies legals information |
---|
380 | @author Raphael Derosso Pereira |
---|
381 | |
---|
382 | @param integer $id_company The company ID |
---|
383 | |
---|
384 | @return The following array: |
---|
385 | $return = array( |
---|
386 | 'legal1' => array( |
---|
387 | 'id_legal' => <id_legal>, |
---|
388 | 'id_type' => <id_type>, |
---|
389 | 'type' => '<type_name>', |
---|
390 | 'legal_info_name' => '<legal_name>', |
---|
391 | 'legal_info_value' => '<legal_value>' |
---|
392 | ), |
---|
393 | 'legal2' => array(...), |
---|
394 | ... |
---|
395 | ); |
---|
396 | |
---|
397 | */ |
---|
398 | function get_legals ( $id_company, $types ) |
---|
399 | { |
---|
400 | $company =& CreateObject('contactcenter.so_company', $id_company); |
---|
401 | $legals = $company->get_legals(); |
---|
402 | |
---|
403 | $count = 1; |
---|
404 | foreach($legals as $id => $type) |
---|
405 | { |
---|
406 | $legal =& CreateObject('contactcenter.so_legal',$id); |
---|
407 | $legal_type =& CreateObject('contactcenter.so_company_legal_type',$type); |
---|
408 | $return['legal'.$count]['id_legal'] = $id; |
---|
409 | $return['legal'.$count]['id_type'] = $type; |
---|
410 | $return['legal'.$count]['type'] = $legal_type->get_type_name(); |
---|
411 | $return['legal'.$count]['legal_info_name'] = $legal->get_name(); |
---|
412 | $return['legal'.$count]['legal_info_value'] = $legal->get_value(); |
---|
413 | $return['legal'.$count]['legal_is_default'] = $legal->is_default(); |
---|
414 | $count++; |
---|
415 | } |
---|
416 | |
---|
417 | return $return; |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | /*********************************************************************\ |
---|
422 | * Methods to get general fields * |
---|
423 | \*********************************************************************/ |
---|
424 | |
---|
425 | |
---|
426 | /*! |
---|
427 | |
---|
428 | @function get_all_relations_types |
---|
429 | @abstract Returns all companies relations types |
---|
430 | @author Raphael Derosso Pereira |
---|
431 | |
---|
432 | @return array The format of the return is: |
---|
433 | $return = array( |
---|
434 | <id_type1> => '<type1_name>', |
---|
435 | <id_type2> => '<type2_name>', |
---|
436 | ...); |
---|
437 | */ |
---|
438 | function get_all_relations_types ( ) |
---|
439 | { |
---|
440 | $fields = array('id_typeof_company_relation', 'company_relation_name'); |
---|
441 | |
---|
442 | $relation_types = $this->find($fields); |
---|
443 | |
---|
444 | if (!is_array($relation_types)) |
---|
445 | { |
---|
446 | return false; |
---|
447 | } |
---|
448 | |
---|
449 | while ($relation_type = each($relation_types)) |
---|
450 | { |
---|
451 | $result[$relation_type['id_typeof_company_relation']] = $relation_type['company_relation_name']; |
---|
452 | } |
---|
453 | |
---|
454 | return $result; |
---|
455 | } |
---|
456 | |
---|
457 | /*! |
---|
458 | |
---|
459 | @function get_all_addresses_types |
---|
460 | @abstract Returns all companies addresses types |
---|
461 | @author Raphael Derosso Pereira |
---|
462 | |
---|
463 | @return array The format of the return is: |
---|
464 | $return = array( |
---|
465 | <id_type1> => '<type1_name>', |
---|
466 | <id_type2> => '<type2_name>', |
---|
467 | ...); |
---|
468 | */ |
---|
469 | function get_all_addresses_types ( ) |
---|
470 | { |
---|
471 | $fields = array('id_typeof_company_address', 'company_address_type_name'); |
---|
472 | |
---|
473 | $address_types = $this->find($fields); |
---|
474 | |
---|
475 | if (!is_array($address_types)) |
---|
476 | { |
---|
477 | return false; |
---|
478 | } |
---|
479 | |
---|
480 | while ($address_type = each($address_types)) |
---|
481 | { |
---|
482 | $result[$address_type['id_typeof_company_address']] = $address_type['company_address_name']; |
---|
483 | } |
---|
484 | |
---|
485 | return $result; |
---|
486 | } |
---|
487 | |
---|
488 | /*! |
---|
489 | |
---|
490 | @function get_all_connections_types |
---|
491 | @abstract Returns all companies connections types |
---|
492 | @author Raphael Derosso Pereira |
---|
493 | |
---|
494 | @return array The format of the return is: |
---|
495 | $return = array( |
---|
496 | <id_type1> => '<type1_name>', |
---|
497 | <id_type2> => '<type2_name>', |
---|
498 | ...); |
---|
499 | */ |
---|
500 | function get_all_connections_types ( ) |
---|
501 | { |
---|
502 | $fields = array('id_typeof_company_relation', 'company_connections_type_name'); |
---|
503 | |
---|
504 | $relation_types = $this->find($fields); |
---|
505 | |
---|
506 | if (!is_array($relation_types)) |
---|
507 | { |
---|
508 | return false; |
---|
509 | } |
---|
510 | |
---|
511 | while ($relation_type = each($relation_types)) |
---|
512 | { |
---|
513 | $result[$relation_type['id_typeof_company_relation']] = $relation_type['company_connections_type_name']; |
---|
514 | } |
---|
515 | |
---|
516 | return $result; |
---|
517 | } |
---|
518 | |
---|
519 | /*! |
---|
520 | |
---|
521 | @function get_all_legals_types |
---|
522 | @abstract Returns all companies legals types |
---|
523 | @author Raphael Derosso Pereira |
---|
524 | |
---|
525 | @return array The format of the return is: |
---|
526 | $return = array( |
---|
527 | <id_type1> => '<type1_name>', |
---|
528 | <id_type2> => '<type2_name>', |
---|
529 | ...); |
---|
530 | */ |
---|
531 | function get_all_legals_types ( ) |
---|
532 | { |
---|
533 | $fields = array('id_typeof_company_legal', 'legal_type_name'); |
---|
534 | |
---|
535 | $relation_types = $this->find($fields); |
---|
536 | |
---|
537 | if (!is_array($relation_types)) |
---|
538 | { |
---|
539 | return false; |
---|
540 | } |
---|
541 | |
---|
542 | while ($relation_type = each($relation_types)) |
---|
543 | { |
---|
544 | $result[$relation_type['id_typeof_company_legal']] = $relation_type['legal_type_name']; |
---|
545 | } |
---|
546 | |
---|
547 | return $result; |
---|
548 | } |
---|
549 | |
---|
550 | |
---|
551 | /*********************************************************************\ |
---|
552 | * Methods to Include Data * |
---|
553 | \*********************************************************************/ |
---|
554 | |
---|
555 | /*! |
---|
556 | |
---|
557 | @function add |
---|
558 | @abstract Insert a new company record in the DB |
---|
559 | @author Raphael Derosso Pereira |
---|
560 | |
---|
561 | @param array $data The company Information. |
---|
562 | |
---|
563 | Format: |
---|
564 | |
---|
565 | $data = array( |
---|
566 | 'company_name' => '<company_name>', |
---|
567 | 'company_notes' => '<company_notes>', |
---|
568 | |
---|
569 | 'contacts' => array( |
---|
570 | contact1 => array( |
---|
571 | 'id_contact' => <id_company>, |
---|
572 | 'title' => <title>, |
---|
573 | 'department' => <department> |
---|
574 | ), |
---|
575 | company2 => array(...), |
---|
576 | ... |
---|
577 | ), |
---|
578 | |
---|
579 | 'relations' => array( |
---|
580 | 'relation1' => array( |
---|
581 | 'id_relation' => <id_relation>, |
---|
582 | 'id_typeof_relation' => <id_typeof_relation>, |
---|
583 | ), |
---|
584 | 'relation2' => array(...), |
---|
585 | ... |
---|
586 | ), |
---|
587 | |
---|
588 | 'addresses' => array( |
---|
589 | 'address1' => array( |
---|
590 | 'id_typeof_address' => <id_typeof_address>, |
---|
591 | 'address1' => '<address1>', |
---|
592 | 'address2' => '<address2>', |
---|
593 | 'complement' => '<complement>', |
---|
594 | 'address_other' => '<address_other>', |
---|
595 | 'postal_code' => '<postal_code>', |
---|
596 | 'po_box' => '<po_box>', |
---|
597 | 'id_city' => '<city>', |
---|
598 | 'id_state' => '<id_state>', |
---|
599 | 'id_country' => '<id_country>', |
---|
600 | 'address_is_default' => <trueness> |
---|
601 | ), |
---|
602 | 'address2' => array(...), |
---|
603 | ... |
---|
604 | ), |
---|
605 | |
---|
606 | 'connections' => array( |
---|
607 | 'connection1' => array( |
---|
608 | 'id_typeof_connection' => <id_typeof_connection>, |
---|
609 | 'connection_name' => <connection_name>, |
---|
610 | 'connection_value' => <connection_value>, |
---|
611 | 'connection_is_default' => <trueness> |
---|
612 | ), |
---|
613 | 'connection2' => array(...), |
---|
614 | ... |
---|
615 | ), |
---|
616 | |
---|
617 | 'legals' => array( |
---|
618 | 'legal1' => array( |
---|
619 | 'id_typeof_legal' => <id_typeof_connection>, |
---|
620 | 'legal_info_name' => <connection_name>, |
---|
621 | 'legal_info_value' => <connection_value> |
---|
622 | ), |
---|
623 | 'legal2' => array(...), |
---|
624 | ... |
---|
625 | ) |
---|
626 | |
---|
627 | ); |
---|
628 | |
---|
629 | If any of the above fields doesn't have a value, it should hold false. |
---|
630 | In the case of the multiple-values fields, instead of the array, there |
---|
631 | should be a false. |
---|
632 | */ |
---|
633 | function add ( $data ) |
---|
634 | { |
---|
635 | $permissions = $this->security->get_permissions(); |
---|
636 | |
---|
637 | if (!$permissions['create']) |
---|
638 | { |
---|
639 | return false; |
---|
640 | } |
---|
641 | |
---|
642 | $company =& CreateObject('contactcenter.so_company'); |
---|
643 | $company->reset_fields(); |
---|
644 | |
---|
645 | foreach($data as $field => $value) |
---|
646 | { |
---|
647 | if ($value === false) |
---|
648 | { |
---|
649 | continue; |
---|
650 | } |
---|
651 | |
---|
652 | switch($field) |
---|
653 | { |
---|
654 | case 'company_name': |
---|
655 | case 'company_notes': |
---|
656 | $func = 'set_'.$field; |
---|
657 | $company->$func(); |
---|
658 | break; |
---|
659 | |
---|
660 | case 'contacts': |
---|
661 | foreach($value as $contact_fields) |
---|
662 | { |
---|
663 | $company->set_contact($contact_fields['id_contact'], |
---|
664 | $company_fields['title'], $company_fields['department']); |
---|
665 | } |
---|
666 | break; |
---|
667 | |
---|
668 | case 'relations': |
---|
669 | foreach($value as $relation_fields) |
---|
670 | { |
---|
671 | $company->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']); |
---|
672 | } |
---|
673 | break; |
---|
674 | |
---|
675 | case 'addresses': |
---|
676 | foreach($value as $address_fields) |
---|
677 | { |
---|
678 | $address =& CreateObject('contactcenter.so_address'); |
---|
679 | $address->reset_values(); |
---|
680 | foreach($address_fields as $a_field => $a_value) |
---|
681 | { |
---|
682 | if ($a_field !== 'id_typeof_address') |
---|
683 | { |
---|
684 | $func = 'set_'.$a_field; |
---|
685 | $address->$func($a_value); |
---|
686 | } |
---|
687 | } |
---|
688 | $address->commit(); |
---|
689 | $id_address = $address->get_id(); |
---|
690 | $company->set_address($id_address, $address_fields['id_typeof_address']); |
---|
691 | } |
---|
692 | break; |
---|
693 | |
---|
694 | case 'connections': |
---|
695 | foreach($value as $connection_fields) |
---|
696 | { |
---|
697 | $connection =& CreateObject('contactcenter.so_connection'); |
---|
698 | $connection->reset_values(); |
---|
699 | foreach($connection_fields as $a_field => $a_value) |
---|
700 | { |
---|
701 | if ($a_field !== 'id_typeof_connection') |
---|
702 | { |
---|
703 | $func = 'set_'.$a_field; |
---|
704 | $connection->$func($a_value); |
---|
705 | } |
---|
706 | } |
---|
707 | $connection->commit(); |
---|
708 | $id_connection = $connection->get_id(); |
---|
709 | $company->set_connection($id_connection, $connection_fields['id_typeof_connection']); |
---|
710 | } |
---|
711 | break; |
---|
712 | |
---|
713 | case 'legals': |
---|
714 | foreach($value as $connection_fields) |
---|
715 | { |
---|
716 | $legal =& CreateObject('contactcenter.so_legal'); |
---|
717 | $legal->reset_values(); |
---|
718 | foreach($legal_fields as $a_field => $a_value) |
---|
719 | { |
---|
720 | if ($a_field !== 'id_typeof_legal') |
---|
721 | { |
---|
722 | $func = 'set_'.$a_field; |
---|
723 | $legal->$func($a_value); |
---|
724 | } |
---|
725 | } |
---|
726 | $legal->commit(); |
---|
727 | $id_legal = $legal->get_id(); |
---|
728 | $company->set_legal($id_legal, $legal_fields['id_typeof_legal']); |
---|
729 | } |
---|
730 | break; |
---|
731 | |
---|
732 | default: |
---|
733 | return false; |
---|
734 | break; |
---|
735 | } |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | |
---|
740 | /*! |
---|
741 | |
---|
742 | @function add_relation_type |
---|
743 | @abstract Insert a new Relation Type in the DB |
---|
744 | @author Raphael Derosso Pereira |
---|
745 | |
---|
746 | @param string $type_name The Relation Type |
---|
747 | @return integer The new ID |
---|
748 | |
---|
749 | */ |
---|
750 | function add_relation_type ( $type_name ) |
---|
751 | { |
---|
752 | $permissions = $this->security->get_type_permissions(); |
---|
753 | |
---|
754 | if (!$permissions['create']) |
---|
755 | { |
---|
756 | return false; |
---|
757 | } |
---|
758 | } |
---|
759 | |
---|
760 | /*! |
---|
761 | |
---|
762 | @function add_address_type |
---|
763 | @abstract Insert a new Address Type in the DB |
---|
764 | @author Raphael Derosso Pereira |
---|
765 | |
---|
766 | @param string $type_name The Address Type |
---|
767 | @return integer The new ID |
---|
768 | |
---|
769 | */ |
---|
770 | function add_address_type ( $type_name ) |
---|
771 | { |
---|
772 | $permissions = $this->security->get_type_permissions(); |
---|
773 | |
---|
774 | if (!$permissions['create']) |
---|
775 | { |
---|
776 | return false; |
---|
777 | } |
---|
778 | } |
---|
779 | |
---|
780 | /*! |
---|
781 | |
---|
782 | @function add_connection_type |
---|
783 | @abstract Insert a new Connection Type in the DB |
---|
784 | @author Raphael Derosso Pereira |
---|
785 | |
---|
786 | @param string $type_name The Connection Type |
---|
787 | @return integer The new ID |
---|
788 | |
---|
789 | */ |
---|
790 | function add_connection_type ( $type_name ) |
---|
791 | { |
---|
792 | $permissions = $this->security->get_type_permissions(); |
---|
793 | |
---|
794 | if (!$permissions['create']) |
---|
795 | { |
---|
796 | return false; |
---|
797 | } |
---|
798 | } |
---|
799 | |
---|
800 | /*! |
---|
801 | |
---|
802 | @function add_legal_type |
---|
803 | @abstract Insert a new legal Type in the DB |
---|
804 | @author Raphael Derosso Pereira |
---|
805 | |
---|
806 | @param string $type_name The legal Type |
---|
807 | @return integer The new ID |
---|
808 | |
---|
809 | */ |
---|
810 | function add_legal_type ( $type_name ) |
---|
811 | { |
---|
812 | $permissions = $this->security->get_type_permissions(); |
---|
813 | |
---|
814 | if (!$permissions['create']) |
---|
815 | { |
---|
816 | return false; |
---|
817 | } |
---|
818 | } |
---|
819 | |
---|
820 | |
---|
821 | /*********************************************************************\ |
---|
822 | * Methods to Alter Data * |
---|
823 | \*********************************************************************/ |
---|
824 | |
---|
825 | /*! |
---|
826 | |
---|
827 | @function update_company_info |
---|
828 | @abstract Update information of an existing company |
---|
829 | @author Raphael Derosso Pereira |
---|
830 | |
---|
831 | @param integer $id_status The company ID |
---|
832 | @param string $status The new Status value |
---|
833 | |
---|
834 | */ |
---|
835 | function update_single_info ( $id_company, $data ) |
---|
836 | { |
---|
837 | $permissions = $this->security->get_permissions($id_company); |
---|
838 | |
---|
839 | if (!$permissions['alter']) |
---|
840 | { |
---|
841 | return false; |
---|
842 | } |
---|
843 | } |
---|
844 | |
---|
845 | /*! |
---|
846 | |
---|
847 | @function update_prefix |
---|
848 | @abstract Update an existing Prefix |
---|
849 | @author Raphael Derosso Pereira |
---|
850 | |
---|
851 | @param integer $id_prefix The Prefix ID |
---|
852 | @param string $prefix The new Prefix value |
---|
853 | |
---|
854 | */ |
---|
855 | function update_prefix ( $id_prefix, $prefix ) |
---|
856 | { |
---|
857 | $permissions = $this->security->get_type_permissions(); |
---|
858 | |
---|
859 | if (!$permissions['alter']) |
---|
860 | { |
---|
861 | return false; |
---|
862 | } |
---|
863 | } |
---|
864 | |
---|
865 | /*! |
---|
866 | |
---|
867 | @function update_suffix |
---|
868 | @abstract Update an existing Sulfix |
---|
869 | @author Raphael Derosso Pereira |
---|
870 | |
---|
871 | @param integer $id_suffix The Sulfix ID |
---|
872 | @param string $suffix The new Sulfix value |
---|
873 | |
---|
874 | */ |
---|
875 | function update_suffix ( $id_suffix, $suffix ) |
---|
876 | { |
---|
877 | $permissions = $this->security->get_type_permissions(); |
---|
878 | |
---|
879 | if (!$permissions['alter']) |
---|
880 | { |
---|
881 | return false; |
---|
882 | } |
---|
883 | } |
---|
884 | |
---|
885 | /*! |
---|
886 | |
---|
887 | @function update_status |
---|
888 | @abstract Update an existing Status |
---|
889 | @author Raphael Derosso Pereira |
---|
890 | |
---|
891 | @param integer $id_status The Status ID |
---|
892 | @param string $status The new Status value |
---|
893 | |
---|
894 | */ |
---|
895 | function update_status ( $id_status, $status ) |
---|
896 | { |
---|
897 | $permissions = $this->security->get_type_permissions(); |
---|
898 | |
---|
899 | if (!$permissions['alter']) |
---|
900 | { |
---|
901 | return false; |
---|
902 | } |
---|
903 | } |
---|
904 | |
---|
905 | /*! |
---|
906 | |
---|
907 | @function update_relation_type |
---|
908 | @abstract Update an existing Relation Type |
---|
909 | @author Raphael Derosso Pereira |
---|
910 | |
---|
911 | @param integer $id_type The Type ID |
---|
912 | @param string $type The new type value |
---|
913 | |
---|
914 | */ |
---|
915 | function update_relation_type ( $old_name, $relation_name ) |
---|
916 | { |
---|
917 | } |
---|
918 | |
---|
919 | /*! |
---|
920 | |
---|
921 | @function update_address_type |
---|
922 | @abstract Update an existing Address Type |
---|
923 | @author Raphael Derosso Pereira |
---|
924 | |
---|
925 | @param integer $id_type The Type ID |
---|
926 | @param string $type The new type value |
---|
927 | |
---|
928 | */ |
---|
929 | function update_address_type ( $id_type, $type ) |
---|
930 | { |
---|
931 | } |
---|
932 | |
---|
933 | /*! |
---|
934 | |
---|
935 | @function update_connection_type |
---|
936 | @abstract Update an existing Connection Type |
---|
937 | @author Raphael Derosso Pereira |
---|
938 | |
---|
939 | @param integer $id_type The Type ID |
---|
940 | @param string $type The new type value |
---|
941 | |
---|
942 | */ |
---|
943 | function update_connection_type ( $id_type, $type ) |
---|
944 | { |
---|
945 | } |
---|
946 | |
---|
947 | /*! |
---|
948 | |
---|
949 | @function update_legal_type |
---|
950 | @abstract Update an existing legal Type |
---|
951 | @author Raphael Derosso Pereira |
---|
952 | |
---|
953 | @param integer $id_type The Type ID |
---|
954 | @param string $type The new type value |
---|
955 | |
---|
956 | */ |
---|
957 | function update_legal_type ( $id_type, $type ) |
---|
958 | { |
---|
959 | } |
---|
960 | } |
---|
961 | ?> |
---|