source: trunk/contactcenter/inc/class.bo_catalog_group_catalog.inc.php @ 284

Revision 284, 7.7 KB checked in by rafaelraymundo, 16 years ago (diff)

Vide Trac - #197, #166, #198, #199

  1. Correção de problema na leitura do arquivo configuração.
  2. Permissão do click2dial também no contactcenter.
  3. Visualização de matricula, e nro celular no resultado da pesquisa(se estiverem populados)
  4. Adicionada a leitura a Catálogos Externos
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  sponsored by Thyamad - http://www.thyamad.com
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15
16        /* This is a special class that handles requests to a catalog that is actually
17         * a catalog group. So this class actually performs all the requests in its
18         * catalog childs.
19         */
20
21        include_once('class.abo_catalog.inc.php');
22
23        class bo_catalog_group_catalog extends abo_catalog
24        {
25
26                var $external;
27
28                var $fields = array(
29                        'id_contact'    => true,
30                        'status'        => true,
31                        'photo'         => true,
32                        'alias'         => true,
33                        'prefix'        => true,
34                        'given_names'   => true,
35                        'family_names'  => true,
36                        'names_ordered' => true,
37                        'suffix'        => true,
38                        'birthdate'     => true,
39                        'sex'           => true,
40                        'pgp_key'       => true,
41                        'notes'         => true,
42
43                        /* Array fields */
44                        'companies'     => true,
45                        'relations'     => true,
46                        'addresses'     => true,
47                        'connections'   => true
48                );
49
50                /*!
51
52                 @function bo_people_catalog
53                 @abstract Constructor
54                 @author Raphael Derosso Pereira
55
56                */
57                function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog, $external = 0)
58                {
59                        $this->bo_contactcenter = & $bo_contactcenter;
60                        $this->catalog = & $catalog;
61                        $this->external = $external;
62                }
63
64
65                /*!
66
67                 @function find
68                 @abstract Returns all the IDs of the entries found in all child
69                        catalogues that corresponds to the specified rules.
70                 @author Raphael Derosso Pereira
71
72                 @param SEE class bo_contactcenter for usage
73
74                */
75                function find($what, $rules, $other)
76                {
77                        if ($ldap_info = $this->catalog['ldap'])
78                        {
79
80                                $meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context'], $this->external);
81                                return $meta_catalog->find($what, $rules, $other);
82                        }
83
84                        $results = array();
85
86                        reset($this->catalog);
87                        while(list(, $new_catalog) = each($this->catalog['sub_branch']))
88                        {
89                                //print_r($new_catalog);
90                                //echo 'Setting catalog: <b>'.$new_catalog['name'].'</b><br>';
91                                $new_catalog = $this->bo_contactcenter->set_catalog($new_catalog);
92
93                                //if($new_catalog) echo 'Setado corretamente!<br><br>'; else echo 'Erro ao setar<br><br>';
94
95                                if ($new_catalog['type'] === 'empty')
96                                {
97                                        continue;
98                                }
99
100                                $temp_res = $this->bo_contactcenter->catalog->find($what, $rules, $other);
101                                if (is_array($temp_res) and count($temp_res))
102                                {
103                                        foreach ($temp_res as $id => $value)
104                                        {
105                                                $result[$id] = $value;
106                                        }
107                                }
108                        }
109
110                        //$this->bo_contactcenter->set_catalog($this->catalog);
111                        return $result;
112                }
113
114                /*!
115
116                 @function get_single_entry
117                 @abstract Returns all information requested about one contact
118                 @author Raphael Derosso Pereira
119
120                 @param integer $id_contact The contact ID
121                 @param array $fields The array returned by get_fields whith true
122                        on the fields to be taken.
123
124                */
125                function get_single_entry ( $id_contact, $fields )
126                {
127                        if (!is_array($fields))
128                        {
129                                if (is_object($GLOBALS['phpgw']->log))
130                                {
131                                        $GLOBALS['phpgw']->log->message(array(
132                                                'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.',
133                                                'line' => __LINE__,
134                                                'file' => __FILE__));
135
136                                        $GLOBALS['phpgw']->log->commit();
137                                }
138                                else
139                                {
140                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
141                                }
142                        }
143
144                        $contact_array = $this->get_multiple_entries(array($id_contact), $fields);
145
146                        if (!count($contact_array))
147                        {
148                                return false;
149                        }
150
151                        if($contact_array[0])
152                                $contact_data = $contact_array[0];
153                        else
154                                $contact_data = $contact_array[$id_contact];
155
156                        if (!is_array($contact_data))
157                        {
158                                return false;
159                        }
160
161                        return $contact_data;
162                }
163
164                /*!
165
166                 @function get_multiple_entries
167                 @abstract Returns multiple Contacts data into one array
168                 @author Raphael Derosso Pereira
169
170                 @param array $id_contacts The Contacts IDs
171                 @param array $fields The Contacts fields to be retrieved
172                 @param array $other_data Other informations. The format is:
173                        $other_data = array(
174                                'offset'    => <offset>,
175                                'limit'     => <max_num_returns>,
176                                'sort'      => <sort>,
177                                'order_by'  => <order by>
178                        );
179
180                */
181                function get_multiple_entries ( $id_contacts, $fields, $other_data = false )
182                {
183                        if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data)))
184                        {
185                                if (is_object($GLOBALS['phpgw']->log))
186                                {
187                                        $GLOBALS['phpgw']->log->message(array(
188                                                'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.',
189                                                'line' => __LINE__,
190                                                'file' => __FILE__));
191
192                                        $GLOBALS['phpgw']->log->commit();
193                                }
194                                else {
195                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
196                                }
197                        }
198
199                        $contacts = array();
200
201                        if ($other_data)
202                        {
203                                //TODO
204                        }
205
206                        //error_log("bo_ldap_catalog_group_catalog->get_multiple_entries \n", 3, '/var/www/teste.log');
207
208                        /* First check if this is a LDAP Catalog Group. In this case, just leave the
209                         * subtree search for the LDAP server
210                         */
211                        if ($ldap_info = $this->catalog['ldap'])
212                        {
213                                $meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context'], $this->external);
214                                return $meta_catalog->get_multiple_entries($id_contacts, $fields, $other_data);
215                        }
216
217                        /* Search for the catalog of the first entry and try to get all ids from that
218                         * catalog. Repeat to the ones not found until there's none missing or no more
219                         * catalogs.
220                         */
221
222                        $contacts = array();
223                        reset($this->catalog);
224                        while (list($level,$branch) = each($this->catalog['sub_branch']))
225                        {
226                                $this->bo_contactcenter->set_catalog($branch);
227                                $contacts += $this->bo_contactcenter->catalog->get_multiple_entries($id_contacts, $fields, $other_data);
228
229                                reset($contacts);
230                                while (list($id) = each($contacts))
231                                {
232                                        if ($id_contacts[$id])
233                                        {
234                                                unset($id_contacts[$id]);
235                                        }
236                                }
237
238                                if (!count($id_contacts))
239                                {
240                                        break;
241                                }
242                        }
243
244                        $this->bo_contactcenter->set_catalog($this->catalog);
245
246                        return $contacts;
247                }
248
249                function get_all_entries_ids ()
250                {
251                        // TODO!
252                        return null;
253                }
254
255                /*********************************************************************\
256                 *                Methods to get general fields                      *
257                \*********************************************************************/
258
259                /*********************************************************************\
260                 *                   Methods to Include Data                         *
261                \*********************************************************************/
262
263                /*********************************************************************\
264                 *                   Methods to Alter Data                           *
265                \*********************************************************************/
266
267                /*********************************************************************\
268                 *                   Methods to Remove Data                          *
269                \*********************************************************************/
270
271        }
272?>
Note: See TracBrowser for help on using the repository browser.