1<?php
2  /**************************************************************************\
3  * phpGroupWare - boaddressbook                                             *
4  * http://www.phpgroupware.org                                              *
5  * This program is part of the GNU project, see http://www.gnu.org/         *
6  *                                                                          *
7  * Copyright 2003 Free Software Foundation, Inc.                            *
8  *                                                                          *
9  * Originally Written by Jonathan Alberto Rivera Gomez - jarg at co.com.mx  *
10  * Current Maintained by Jonathan Alberto Rivera Gomez - jarg at co.com.mx  *
11  * --------------------------------------------                             *
12  * Development of this application was funded by http://www.sogrp.com       *
13  * --------------------------------------------                             *
14  *  This program is Free Software; you can redistribute it and/or modify it *
15  *  under the terms of the GNU General Public License as published by the   *
16  *  Free Software Foundation; either version 2 of the License, or (at your  *
17  *  option) any later version.                                              *
18  \**************************************************************************/
19
20/* $Id: class.boaddressbook.inc.php 19092 2009-02-22 00:12:18Z skwashd $ */
21
22	class boaddressbook
23	{
24 		var $debug = False;
25		var $so;
26		var $rights;
27		var $grants;
28		var $comm_type;
29		var $addr_type;
30		var $note_type;
31		var $tab_main_persons;
32		var $tab_main_organizations;
33		var $use_session = False;
34		var $start;
35		var $limit;
36		var $query;
37		var $sort;
38		var $order;
39		var $filter;
40		var $cat_id;
41		var $total;
42		var $bday_internformat;
43		var $public_functions = array(
44			'add_vcard' => True  // call from addressbook.uivcard.in to import a vcard
45		);
46
47		function boaddressbook($session=True)
48		{
49			$this->so = CreateObject('addressbook.soaddressbook');
50			$this->rights = $this->so->rights;
51			$this->grants = $this->so->grants;
52			$this->contact_type = $this->so->contact_type;
53			$this->comm_descr = $this->so->comm_descr;
54			$this->comm_type = $this->so->comm_type;
55			$this->addr_type = $this->so->addr_type;
56			$this->note_type = $this->so->note_type;
57			$this->tab_main_persons = $this->so->tab_main_persons;
58			$this->tab_main_organizations = $this->so->tab_main_organizations;
59			$this->bday_internformat = "Y-m-d"; // use ISO 8601 for internal bday represantation
60
61 			if($session)
62 			{
63				$this->read_sessiondata();
64				$this->use_session = True;
65 			}
66			$this->_set_session_data();
67		}
68
69		//used
70		function save_sessiondata($data)
71		{
72			if ($this->use_session)
73			{
74				if($this->debug) { echo '<br />Save:'; _debug_array($data); }
75 				$GLOBALS['phpgw']->session->appsession('session_data','addressbook',$data);
76			}
77		}
78
79		//used
80		function read_sessiondata()
81		{
82			$data = $GLOBALS['phpgw']->session->appsession('session_data','addressbook');
83			if($this->debug) { echo '<br />Read:'; _debug_array($data); }
84
85			$this->start  = $data['start'];
86			$this->limit  = $data['limit'];
87			$this->query  = $data['query'];
88			$this->sort   = $data['sort'];
89			$this->order  = $data['order'];
90			$this->filter = $data['filter'];
91			$this->cat_id = $data['cat_id'];
92			$this->qfield = $data['qfield'];
93			if($this->debug) { echo '<br />read_sessiondata();'; $this->_debug_sqsof(); }
94		}
95
96		function _set_session_data()
97		{
98			/* _debug_array($GLOBALS['HTTP_POST_VARS']); */
99			/* Might change this to '' at the end---> */
100			$_start   = get_var('start',Array('GET','POST'));
101			$_query   = get_var('query',Array('GET','POST'));
102			$_qfield  = get_var('qfield',Array('GET','POST'));
103			$_sort    = get_var('sort',Array('GET','POST'));
104			$_order   = get_var('order',Array('GET','POST'));
105			$_filter  = get_var('filter',Array('GET','POST'));
106			$_cat_id  = get_var('cat_id',Array('GET','POST'));
107			$_fcat_id = get_var('fcat_id',Array('GET','POST'));
108
109			if(!empty($_start) || ($_start == '0') || ($_start == 0))
110			{
111				if($this->debug) { echo '<br />overriding $start: "' . $this->start . '" now "' . $_start . '"'; }
112				$this->start = $_start;
113			}
114			if($_limit)
115			{
116				$this->limit  = $_limit;
117			}
118			if((empty($_query) && !empty($this->query)) || !empty($_query))
119			{
120				if($this->debug) { echo '<br />overriding $query: "' . $this->query . '" now "' . urldecode(addslashes($_query)) . '"'; }
121				if($this->query != urldecode(addslashes($_query)))
122				{
123					$this->start = 0;
124				}
125				$this->query  = $_query;
126			}
127
128			if(isset($_fcat_id) && $_fcat_id!='')
129			{
130				if($this->debug) { echo '<br />overriding $cat_id: "' . $this->cat_id . '" now "' . $_fcat_id . '"'; }
131				if($this->cat_id != $_fcat_id)
132				{
133					$this->start = 0;
134				}
135				$this->cat_id = $_fcat_id;
136			}
137
138			if(isset($_sort)   && !empty($_sort))
139			{
140				if($this->debug) { echo '<br />overriding $sort: "' . $this->sort . '" now "' . $_sort . '"'; }
141				$this->sort   = $_sort;
142			}
143
144			if(isset($_order)  && !empty($_order))
145			{
146				if($this->debug) { echo '<br />overriding $order: "' . $this->order . '" now "' . $_order . '"'; }
147				$this->order  = $_order;
148			}
149
150			if(isset($_filter) && !empty($_filter))
151			{
152				if($this->debug) { echo '<br />overriding $filter: "' . $this->filter . '" now "' . $_filter . '"'; }
153				if($this->filter != $_filter)
154				{
155					$this->start = 0;
156				}
157				$this->filter = $_filter;
158			}
159
160			if(isset($_qfield) && !empty($_qfield))
161			{
162				$this->qfield = $_qfield;
163			}
164
165			if($this->debug) { $this->_debug_sqsof(); }
166		}
167
168		/*************************************************************\
169		* Person Functions Section                                    *
170		\*************************************************************/
171
172		/**
173		* Call to add_person function in soaddressbook object
174		*
175		* @param array $fields The array with all data of the person
176		* @return integer The person_id of the new person
177		*/
178		function add_person($fields)
179		{
180			return $this->so->add_person($fields);
181		}
182
183		/**
184		* Get the principal person data for the psrson_id what you want
185		*
186		* @param integer $person_id The person id what you want to find
187		* @param bolean $get_org Flag for get or not org_data for this person
188		* @return array The array with all data from person, this also
189		* separate the cats and extra tab
190		*/
191		function get_principal_persons_data($person_id, $get_org=True)
192		{
193			$entry = $this->so->get_principal_persons_data($person_id, $get_org);
194
195			$entry[0]['tab_cats']['my_cats'] = explode(",", $entry[0]['cat_id']);
196			$entry[0]['tab_extra']['per_suffix'] = $entry[0]['per_suffix'];
197			$entry[0]['tab_extra']['per_sound'] = $entry[0]['per_sound'];
198			$entry[0]['tab_extra']['per_pubkey'] = $entry[0]['per_pubkey'];
199
200			unset($entry[0]['cat_id']);
201			unset($entry[0]['per_suffix']);
202			unset($entry[0]['per_sound']);
203			unset($entry[0]['per_pubkey']);
204
205			return $entry[0];
206		}
207
208		/**
209		* Get the organizations for the  person what you want
210		*
211		* @param integer $person_i The person id what you want to find
212		* @return array The array with all organizations for this person,
213		* this also return in this array the preferred organization
214		*/
215		function get_orgs_person_data($person_id)
216		{
217			$entry = $this->so->get_organizations_by_person($person_id);
218			if($entry)
219			{
220				foreach($entry as $k => $v)
221				{
222					if ($v['my_preferred'] == 'Y')
223					{
224						$entry['preferred_org'] = $v['my_org_id'];
225					}
226					$entry['my_orgs'][$k] = $v['my_org_id'];
227				}
228			}
229			return $entry;
230		}
231
232		/**
233		* Get the the person data what you want
234		*
235		* @param array $fields The fields that you can see from person
236		* @param integer $limit Limit of records that you want
237		* @param integer $ofset Ofset of record that you want start
238		* @param string $orderby The field which you want order
239		* @param string $sort ASC | DESC depending what you want
240		* @param mixed $criteria All criterias what you want
241		* @param mixed $criteria_token same like $criteria but builded<br />with sql_criteria class, more powerfull
242		* @return array with records
243		*/
244		function get_persons($fields, $start='', $limit='', $orderby='', $sort='', $criteria='', $token_criteria='')
245		{
246			$entries =  $this->so->get_persons($fields, $start, $limit, $orderby, $sort, $criteria, $token_criteria);
247			if(is_array($entries))
248			{
249				foreach($entries as $data)
250				{
251					$persons[$data['contact_id']] = $data;
252				}
253			}
254			else
255			{
256				$persons = array();
257			}
258			$this->total = $this->so->contacts->total_records;
259			return $persons;
260		}
261
262		/**
263		* Edit the person data what you want
264		*
265		* @param integer $person_id The person what you want to edit
266		* @param array $fields The fields that you want
267		* @return
268		*/
269		function edit_person($person_id, $fields)
270		{
271 			$old_orgs= $fields['old_my_orgs']['my_orgs'];
272 			$new_orgs = $fields['tab_orgs']['my_orgs'];
273 			$fields['edit_orgs'] = $this->diff_arrays($old_orgs, $new_orgs);
274
275			$old_comm = $fields['old_comm'];
276			$new_comm = $fields['tab_comms']['comm_data'];
277			$fields['edit_comms'] = $this->diff_arrays($old_comm, $new_comm, 'keys');
278
279			$old_others = $fields['old_others'];
280			$new_others = $fields['others_data'];
281			$fields['edit_others'] = $this->diff_arrays($old_others, $new_others, 'keys');
282 			return $this->so->edit_person($person_id, $fields);
283		}
284
285		//used
286		function get_count_persons($criteria='')
287		{
288			return $this->so->get_count_persons($criteria);
289		}
290
291		/*************************************************************\
292		* Organization Functions Section                              *
293		\*************************************************************/
294
295		/**
296		* Call to add_org function in soaddressbook object
297		*
298		* @param array $fields The array with all data of the org
299		* @return integer The org_id of the new org
300		*/
301		function add_org($fields)
302		{
303			return $this->so->add_org($fields);
304		}
305
306		/**
307		* Get the principal organization data for the org_id what you want
308		*
309		* @param integer $org_id The organization id what you want to find
310		* @return array The array with all data from person, this also
311		* separate the cats and extra tab
312		*/
313		function get_principal_organizations_data($org_id)
314		{
315			$entry = $this->so->get_principal_organizations_data($org_id);
316			$entry[0]['tab_cats']['my_cats'] = explode(",", $entry[0]['cat_id']);
317			unset($entry[0]['cat_id']);
318			return $entry[0];
319		}
320
321		/**
322		* Get the persons for the organization what you want
323		*
324		* @param integer $org_id The org id what you want to find
325		* @return array The array with all persons for this organization
326		*/
327		function get_person_orgs_data($org_id)
328		{
329			$entry = $this->so->get_people_by_organizations($org_id);
330			if($entry)
331			{
332				foreach($entry as $k => $v)
333				{
334					$entry['my_person'][$k] = $v['my_person_id'];
335				}
336			}
337			return $entry;
338		}
339
340		/**
341		* Retrieve all organizations data which you specify, this can use
342		* limit and order.
343		*
344		* @param array $fields The fields that you can see from person
345		* @param integer $limit Limit of records that you want
346		* @param integer $ofset Ofset of record that you want start
347		* @param string $orderby The field which you want order
348		* @param string $sort ASC | DESC depending what you want
349		* @param array $criteria All criterias what you want
350		* @param mixed $criteria_token same like $criteria but builded<br />with sql_criteria class, more powerfull
351		* @return array with records
352		*/
353		function get_orgs($fields, $start='', $limit='', $orderby='', $sort='', $criteria='', $token_criteria='')
354		{
355			$entries =  $this->so->get_orgs($fields, $start, $limit, $orderby, $sort, $criteria, $token_criteria);
356			if(is_array($entries))
357			{
358				foreach($entries as $data)
359				{
360					$orgs[$data['contact_id']] = $data;
361				}
362			}
363			else
364			{
365				$orgs = array();
366			}
367			$this->total = $this->so->contacts->total_records;
368			return $orgs;
369		}
370
371		/**
372		* Edit the org data what you want
373		*
374		* @param integer $org_id The org what you want to edit
375		* @param array $fields The fields that you want
376		* @return
377		*/
378		function edit_org($org_id, $fields)
379		{
380			$old_person= $fields['old_my_person']['my_person'];
381			$new_person = $fields['tab_persons']['my_person'];
382			$fields['edit_persons'] = $this->diff_arrays($old_person, $new_person);
383
384			$old_comm = $fields['old_comm'];
385			$new_comm = $fields['tab_comms']['comm_data'];
386			$fields['edit_comms'] = $this->diff_arrays($old_comm, $new_comm, 'keys');
387
388			$old_others = $fields['old_others'];
389			$new_others = $fields['others_data'];
390			$fields['edit_others'] = $this->diff_arrays($old_others, $new_others, 'keys');
391
392			return $this->so->edit_org($org_id, $fields);
393		}
394
395		//used
396		function get_count_orgs($criteria='')
397		{
398			return $this->so->get_count_orgs($criteria);
399		}
400
401		/*************************************************************\
402		* Retrive Contact Data Functions Section                      *
403		\*************************************************************/
404
405		/**
406		* Get the others fields data for this contact
407		*
408		* @param integer $contact_id The contact id what you want to find
409		* @return array The array with all others data for this contact
410		*/
411 		function get_others_contact_data($contact_id)
412		{
413			return $this->so->get_others_contact_data($contact_id);
414		}
415
416		/**
417		* Get the addresses data for this contact
418		*
419		* @param integer $contact_id The contact id what you want to find
420		* @return array The array with all addresses data for this contact
421		*/
422		function get_addr_contact_data($contact_id, $criteria='')
423		{
424			return $this->so->get_addr_contact_data($contact_id, $criteria);
425		}
426
427		/**
428		* Get the communications media data for this contact
429		*
430		* @param integer $contact_id The contact id what you want to find
431		* @return array The array with all communications media for this contact
432		*/
433		function get_comm_contact_data($contacts, $fields_comms='', $simple=False)
434		{
435			$data = $this->so->get_comm_contact_data($contacts, $fields_comms);
436			if($simple==True)
437			{
438				return $data;
439			}
440
441			if(is_array($data))
442			{
443				foreach($data as $key => $value)
444				{
445					$comm_data[$value['comm_contact_id']][$value['comm_description']] = $value['comm_data'];
446					if($value['comm_preferred']=='Y')
447					{
448						$comm_data[$value['comm_contact_id']]['preferred'] = $value['comm_description'];
449					}
450				}
451			}
452			else
453			{
454				$comm_data = array();
455			}
456			return $comm_data;
457		}
458
459		//used
460		function get_sub_cats($cat_to_find)
461		{
462			return $this->so->get_sub_cats($cat_to_find);
463		}
464
465		//used
466		function get_persons_by_cat($cats)
467		{
468			return $this->so->get_persons_by_cat($cats);
469		}
470
471		//used
472		function get_type_contact($contact_id)
473		{
474			return $this->so->get_type_contact($contact_id);
475		}
476
477		/*************************************************************\
478		* Others Contacts Actions Functions Section                   *
479		\*************************************************************/
480
481		//used
482		function delete($contact_id, $contact_type)
483		{
484			return $this->so->delete($contact_id, $contact_type);
485		}
486
487		//used
488		function copy_contact($contact_id)
489		{
490			return $this->so->copy_contact($contact_id);
491		}
492
493		/**
494		 * Criteria for index primordially
495		 *
496		 * return string criteria for search.
497		 */
498		function criteria_contacts($access, $category, $field, $pattern, $show_fields)
499		{
500			if ($pattern)
501			{
502				switch ($field)
503				{
504					case 'person':
505						$fields = array
506						(
507							'per_full_name',
508							'per_prefix',
509							'per_suffix',
510							'per_initials'
511						);
512						break;
513
514					case 'org':
515						$fields = array ('org_name' );
516						break;
517
518					case 'comms':
519						$fields['comm_media'] = array();
520						foreach ( $this->comm_descr as $data )
521						{
522							$fields['comm_media'][] = $data ['comm_description'];
523						}
524						break;
525
526					case 'location':
527						$fields = array
528						(
529							'addr_add1',
530							'addr_add2',
531							'addr_add3',
532							'addr_city',
533							'addr_state',
534							'addr_postal_code',
535							'addr_country'
536						);
537						break;
538
539					case 'other':
540						$fields = array ('other_value');
541						break;
542
543					case 'note':
544						$fields = array ('note_text');
545						break;
546
547					default :
548						$fields = array ();
549				}
550			}
551			return $this->so->criteria_contacts($GLOBALS['phpgw_info']['user']['account_id'],
552				$access, $category, $fields, $pattern, $show_fields );
553		}
554
555		/**
556		* Delete the specified communication media.
557		*
558		* @param integer|array $id Key of the comm media what you want
559		*/
560		function delete_specified_comm($id)
561		{
562			return $this->so->delete_specified_comm($id);
563		}
564
565		/**
566		* Delete the specified address.
567		*
568		* @param integer|array $id Key of the address what you want
569		*/
570		function delete_specified_location($id)
571		{
572			return $this->so->delete_specified_location($id);
573		}
574		/**
575		* Delete the specified others field.
576		*
577		* @param integer|array $id Key of the other field what you want
578		*/
579		function delete_specified_other($id)
580		{
581			return $this->so->delete_specified_other($id);
582		}
583
584		/**
585		* Delete the specified note.
586		*
587		* @param integer|array $id Key of the note what you want
588		*/
589		function delete_specified_note($id)
590		{
591			return $this->so->delete_specified_note($id);
592		}
593
594		function get_insert_others($contact_id, $fields)
595		{
596			return $this->so->add_others($fields, $contact_id);
597		}
598
599		function get_update_others($contact_id, $fields)
600		{
601			unset($fields['key_other_id']);
602			return $this->so->edit_other($contact_id, $fields);
603		}
604
605		function get_insert_comm($contact_id, $fields)
606		{
607			return $this->so->add_communication_media($fields, $contact_id);
608		}
609
610		function get_update_comm($contact_id, $fields)
611		{
612			unset($fields['key_comm_id']);
613			return $this->so->edit_comms($contact_id, $fields);
614		}
615
616		function get_insert_addr($contact_id, $fields)
617		{
618			return $this->so->add_location($fields, $contact_id);
619		}
620
621		function get_update_addr($contact_id, $fields)
622		{
623			unset($fields['key_addr_id']);
624			return $this->so->edit_location($contact_id, $fields);
625		}
626
627		/*************************************************************\
628		* Search Functions Section                                    *
629		\*************************************************************/
630
631		//used
632		function search_contact_type_id($id)
633		{
634			return $this->so->search_contact_type_id($id);
635		}
636
637		/**
638		* Search location id in location catalog
639		*
640		* @param integer $id The location id to find
641		* @return string The description of id
642		*/
643		function search_location_type_id($id)
644		{
645			return $this->so->search_location_type_id($id);
646		}
647
648		/*************************************************************\
649		* Check ACL Functions Section                                 *
650		\*************************************************************/
651
652		/**
653		* Check if the contact has add permissions.
654		*
655		* @param integer $contact_id The contact_id which you want to check
656		* @param integer $owner_id The owner_id of the contact which you want to check
657		*/
658		function check_add($contact_id, $owner_id='')
659		{
660			return $this->so->check_add($contact_id, $owner_id);
661		}
662
663		/**
664		* Check if the contact has edit permissions.
665		*
666		* @param integer $contact_id The contact_id which you want to check
667		* @param integer $owner_id The owner_id of the contact which you want to check
668		*/
669		function check_edit($contact_id, $owner_id='')
670		{
671			return $this->so->check_edit($contact_id, $owner_id);
672		}
673
674		/**
675		* Check if the contact has read permissions.
676		*
677		* @param integer $contact_id The contact_id which you want to check
678		* @param integer $owner_id The owner_id of the contact which you want to check
679		*/
680		function check_read($contact_id, $owner_id='')
681		{
682			return $this->so->check_read($contact_id, $owner_id);
683		}
684
685		/**
686		* Check if the contact has delete permissions.
687		*
688		* @param integer $contact_id The contact_id which you want to check
689		* @param integer $owner_id The owner_id of the contact which you want to check
690		*/
691		function check_delete($contact_id, $owner_id='')
692		{
693			return $this->so->check_delete($contact_id, $owner_id);
694		}
695
696		/*************************************************************\
697		* Others Functions Section                                    *
698		\*************************************************************/
699
700		//used
701		function add_vcard()
702		{
703			if(!is_array($_FILES['uploadedfile']) || ($_FILES['uploadedfile']['error'] != UPLOAD_ERR_OK))
704			{
705				Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uivcard.in&action=GetFile'));
706			}
707			else
708			{
709				$uploadedfile = $_FILES['uploadedfile']['tmp_name'];
710				$uploaddir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
711
712				srand((double)microtime()*1000000);
713				$random_number = rand(100000000,999999999);
714				$newfilename = md5($_FILES['uploadedfile'] . $_FILES['uploadedfile']['name']
715					. time() . $_SERVER['REMOTE_ADDR'] . $random_number );
716
717				move_uploaded_file($uploadedfile, $uploaddir . $newfilename);
718				$ftp = fopen($uploaddir . $newfilename . '.info','w');
719				fputs($ftp,$_FILES['uploadedfile']['type'] . "\n" . $_FILES['uploadedfile']['name']."\n");
720				fclose($ftp);
721
722				$filename = $uploaddir . $newfilename;
723
724				$vcard = CreateObject('phpgwapi.vcard');
725				$entry = $vcard->in_file($filename);
726				/* _debug_array($entry);exit; */
727				$entry['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
728				$entry['access'] = 'private';
729				/* _debug_array($entry);exit; */
730
731				$ab_id = $this->so->contact_import($entry);
732
733				/* Delete the temp file. */
734				unlink($filename);
735				unlink($filename . '.info');
736				Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view_person&ab_id=' . $ab_id));
737				exit();
738			}
739		}
740
741		//used
742		function add_email($name, $email)
743		{
744			return $this->so->add_contact_with_email($name, $email);
745		}
746
747		/*************************************************************\
748		* Preferences Functions Section                               *
749		\*************************************************************/
750
751		//used
752		function save_preferences($prefs,$other,$qfields,$fcat_id)
753		{
754			$GLOBALS['phpgw']->preferences->read_repository();
755			if (is_array($prefs))
756			{
757				/* _debug_array($prefs);exit; */
758				while (list($pref,$x) = each($qfields))
759				{
760					/* echo '<br />checking: ' . $pref . '=' . $prefs[$pref]; */
761					if ($prefs[$pref] == 'on')
762					{
763						$GLOBALS['phpgw']->preferences->add('addressbook',$pref,'addressbook_on');
764					}
765					else
766					{
767						$GLOBALS['phpgw']->preferences->delete('addressbook',$pref);
768					}
769				}
770			}
771
772			if(is_array($other))
773			{
774				$GLOBALS['phpgw']->preferences->delete('addressbook','mainscreen_showbirthdays');
775	 			if ($other['mainscreen_showbirthdays'])
776				{
777					$GLOBALS['phpgw']->preferences->add('addressbook','mainscreen_showbirthdays',True);
778				}
779
780				$GLOBALS['phpgw']->preferences->delete('addressbook','default_filter');
781	 			if ($other['default_filter'])
782				{
783					$GLOBALS['phpgw']->preferences->add('addressbook','default_filter',$other['default_filter']);
784				}
785
786				$GLOBALS['phpgw']->preferences->delete('addressbook','autosave_category');
787	 			if ($other['autosave_category'])
788				{
789			 		$GLOBALS['phpgw']->preferences->add('addressbook','autosave_category',True);
790				}
791			}
792
793			$GLOBALS['phpgw']->preferences->delete('addressbook','default_category');
794			$GLOBALS['phpgw']->preferences->add('addressbook','default_category',$fcat_id);
795
796			$GLOBALS['phpgw']->preferences->save_repository(True);
797			/* _debug_array($prefs);exit; */
798			Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php'));
799		}
800
801		//used
802		function get_preferences_for_organizations()
803		{
804			return $this->so->read_preferences($this->tab_main_organizations);
805		}
806
807		//used
808		function get_preferences_for_persons()
809		{
810			return $this->so->read_preferences($this->tab_main_persons);
811
812		}
813
814		//used
815		function get_generic_preferences()
816		{
817			return false;
818		}
819
820		/*************************************************************\
821		* Misc Functions Section                                      *
822		\*************************************************************/
823
824		//used
825		function get_columns_to_display($contact_type)
826		{
827			return $this->so->read_preferences($contact_type);
828		}
829
830		//used
831		function display_name($column)
832		{
833			$newcol = $this->so->display_name($column);
834			return $newcol!='*'?$newcol:$column;
835		}
836
837		//used
838		function execute_queries($queries)
839		{
840			return $this->so->execute_queries($queries);
841		}
842
843		//used
844		function diff_arrays($old_array=array(), $new_array=array(), $type='values')
845		{
846			if(!is_array($old_array))
847			{
848				$old_array =  array();
849			}
850
851			if(!is_array($new_array))
852			{
853				$new_array =  array();
854			}
855
856			if($type=='values')
857			{
858				$result['delete'] = array_diff($old_array, $new_array);
859				$result['insert'] = array_diff($new_array, $old_array);
860				$result['edit'] = array_intersect($old_array, $new_array);
861			}
862			elseif($type=='keys')
863			{
864				$bc_old_array = $old_array;
865				$bc_new_array = $new_array;
866
867				$delete = array_diff(array_keys($old_array), array_keys($new_array));
868				$insert = array_diff(array_keys($new_array), array_keys($old_array));
869				$edit = array_intersect(array_keys($old_array), array_keys($new_array));
870
871				foreach($delete as $key)
872				{
873					$result['delete'][$key] = $bc_old_array[$key];
874				}
875				foreach($insert as $key)
876				{
877					$result['insert'][$key] = $bc_new_array[$key];
878				}
879				foreach($edit as $key)
880				{
881					$result['edit'][$key] = $bc_new_array[$key];
882				}
883			}
884
885			return $result;
886		}
887
888		function _debug_sqsof()
889		{
890			$data = array(
891				'start'  => $this->start,
892				'limit'  => $this->limit,
893				'query'  => $this->query,
894				'sort'   => $this->sort,
895				'order'  => $this->order,
896				'filter' => $this->filter,
897				'cat_id' => $this->cat_id,
898				'qfield' => $this->qfield
899			);
900			echo '<br />BO:';
901			_debug_array($data);
902		}
903
904		//used
905		function can_delete($contact_id, $owner='')
906		{
907			if ($this->so->contacts->check_perms($this->grants[$owner],PHPGW_ACL_DELETE) ||
908			    $owner == $GLOBALS['phpgw_info']['user']['account_id'])
909			{
910				return True;
911			}
912			else
913			{
914				return False;
915			}
916		}
917
918		//used
919		function can_delete_hooks($hook_response)
920		{
921			$negative_apps=false;
922			foreach($hook_response as $application => $response)
923			{
924				if(is_array($response))
925				{
926					if(!$response['can_delete'])
927					{
928						$negative_apps[$application]=$response['reason'];
929					}
930				}
931			}
932			if(!$negative_apps)
933			{
934				return true;
935			}
936
937			$this->negative_responses=$negative_apps;
938		}
939	}
940?>
941