[2] | 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'); |
---|
[285] | 22 | |
---|
[2] | 23 | class bo_catalog_group_catalog extends abo_catalog |
---|
| 24 | { |
---|
[284] | 25 | var $external; |
---|
[2] | 26 | var $fields = array( |
---|
| 27 | 'id_contact' => true, |
---|
| 28 | 'status' => true, |
---|
| 29 | 'photo' => true, |
---|
| 30 | 'alias' => true, |
---|
| 31 | 'prefix' => true, |
---|
| 32 | 'given_names' => true, |
---|
| 33 | 'family_names' => true, |
---|
| 34 | 'names_ordered' => true, |
---|
| 35 | 'suffix' => true, |
---|
| 36 | 'birthdate' => true, |
---|
| 37 | 'sex' => true, |
---|
| 38 | 'pgp_key' => true, |
---|
| 39 | 'notes' => true, |
---|
[285] | 40 | |
---|
[2] | 41 | /* Array fields */ |
---|
| 42 | 'companies' => true, |
---|
| 43 | 'relations' => true, |
---|
| 44 | 'addresses' => true, |
---|
| 45 | 'connections' => true |
---|
| 46 | ); |
---|
[285] | 47 | |
---|
[2] | 48 | /*! |
---|
[285] | 49 | |
---|
[2] | 50 | @function bo_people_catalog |
---|
| 51 | @abstract Constructor |
---|
| 52 | @author Raphael Derosso Pereira |
---|
[285] | 53 | |
---|
[2] | 54 | */ |
---|
[285] | 55 | function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog, $external = 0 ) |
---|
[2] | 56 | { |
---|
| 57 | $this->bo_contactcenter = & $bo_contactcenter; |
---|
| 58 | $this->catalog = & $catalog; |
---|
[284] | 59 | $this->external = $external; |
---|
[2] | 60 | } |
---|
[285] | 61 | |
---|
[2] | 62 | |
---|
| 63 | /*! |
---|
| 64 | |
---|
| 65 | @function find |
---|
| 66 | @abstract Returns all the IDs of the entries found in all child |
---|
| 67 | catalogues that corresponds to the specified rules. |
---|
| 68 | @author Raphael Derosso Pereira |
---|
| 69 | |
---|
| 70 | @param SEE class bo_contactcenter for usage |
---|
[285] | 71 | |
---|
[2] | 72 | */ |
---|
[4471] | 73 | function find($what, $rules, $other, $area=false, $recursive=false) |
---|
[2] | 74 | { |
---|
| 75 | if ($ldap_info = $this->catalog['ldap']) |
---|
| 76 | { |
---|
[284] | 77 | $meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context'], $this->external); |
---|
[5190] | 78 | if ($meta_catalog->src_info) |
---|
| 79 | { |
---|
| 80 | $recursive = $meta_catalog->src_info['recursive']; |
---|
| 81 | } |
---|
[4255] | 82 | return $meta_catalog->find($what, $rules, $other, $area, $recursive); |
---|
[2] | 83 | } |
---|
[285] | 84 | |
---|
[2] | 85 | $results = array(); |
---|
[285] | 86 | |
---|
[2] | 87 | reset($this->catalog); |
---|
| 88 | while(list(, $new_catalog) = each($this->catalog['sub_branch'])) |
---|
| 89 | { |
---|
| 90 | //print_r($new_catalog); |
---|
| 91 | //echo 'Setting catalog: <b>'.$new_catalog['name'].'</b><br>'; |
---|
| 92 | $new_catalog = $this->bo_contactcenter->set_catalog($new_catalog); |
---|
[285] | 93 | |
---|
[2] | 94 | //if($new_catalog) echo 'Setado corretamente!<br><br>'; else echo 'Erro ao setar<br><br>'; |
---|
[285] | 95 | |
---|
[2] | 96 | if ($new_catalog['type'] === 'empty') |
---|
| 97 | { |
---|
| 98 | continue; |
---|
| 99 | } |
---|
[285] | 100 | |
---|
[3211] | 101 | $temp_res = $this->bo_contactcenter->catalog->find($what, $rules, $other, false, $recursive); |
---|
[2] | 102 | if (is_array($temp_res) and count($temp_res)) |
---|
| 103 | { |
---|
| 104 | foreach ($temp_res as $id => $value) |
---|
| 105 | { |
---|
| 106 | $result[$id] = $value; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | //$this->bo_contactcenter->set_catalog($this->catalog); |
---|
| 112 | return $result; |
---|
| 113 | } |
---|
[285] | 114 | |
---|
[2] | 115 | /*! |
---|
[285] | 116 | |
---|
[2] | 117 | @function get_single_entry |
---|
| 118 | @abstract Returns all information requested about one contact |
---|
| 119 | @author Raphael Derosso Pereira |
---|
[285] | 120 | |
---|
[2] | 121 | @param integer $id_contact The contact ID |
---|
| 122 | @param array $fields The array returned by get_fields whith true |
---|
| 123 | on the fields to be taken. |
---|
[285] | 124 | |
---|
[2] | 125 | */ |
---|
| 126 | function get_single_entry ( $id_contact, $fields ) |
---|
[285] | 127 | { |
---|
| 128 | if (!is_array($fields)) |
---|
[2] | 129 | { |
---|
[285] | 130 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 131 | { |
---|
| 132 | $GLOBALS['phpgw']->log->message(array( |
---|
| 133 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 134 | 'line' => __LINE__, |
---|
| 135 | 'file' => __FILE__)); |
---|
[285] | 136 | |
---|
[2] | 137 | $GLOBALS['phpgw']->log->commit(); |
---|
| 138 | } |
---|
[285] | 139 | else |
---|
[2] | 140 | { |
---|
| 141 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 142 | } |
---|
| 143 | } |
---|
[285] | 144 | |
---|
[2] | 145 | $contact_array = $this->get_multiple_entries(array($id_contact), $fields); |
---|
[285] | 146 | |
---|
[2] | 147 | if (!count($contact_array)) |
---|
| 148 | { |
---|
| 149 | return false; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | if($contact_array[0]) |
---|
| 153 | $contact_data = $contact_array[0]; |
---|
| 154 | else |
---|
| 155 | $contact_data = $contact_array[$id_contact]; |
---|
[285] | 156 | |
---|
[2] | 157 | if (!is_array($contact_data)) |
---|
| 158 | { |
---|
| 159 | return false; |
---|
| 160 | } |
---|
[285] | 161 | |
---|
[2] | 162 | return $contact_data; |
---|
| 163 | } |
---|
[285] | 164 | |
---|
[2] | 165 | /*! |
---|
[285] | 166 | |
---|
[2] | 167 | @function get_multiple_entries |
---|
| 168 | @abstract Returns multiple Contacts data into one array |
---|
| 169 | @author Raphael Derosso Pereira |
---|
| 170 | |
---|
| 171 | @param array $id_contacts The Contacts IDs |
---|
| 172 | @param array $fields The Contacts fields to be retrieved |
---|
| 173 | @param array $other_data Other informations. The format is: |
---|
| 174 | $other_data = array( |
---|
| 175 | 'offset' => <offset>, |
---|
| 176 | 'limit' => <max_num_returns>, |
---|
| 177 | 'sort' => <sort>, |
---|
| 178 | 'order_by' => <order by> |
---|
[285] | 179 | ); |
---|
| 180 | |
---|
[2] | 181 | */ |
---|
| 182 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) |
---|
| 183 | { |
---|
| 184 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
| 185 | { |
---|
[285] | 186 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 187 | { |
---|
| 188 | $GLOBALS['phpgw']->log->message(array( |
---|
| 189 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
| 190 | 'line' => __LINE__, |
---|
| 191 | 'file' => __FILE__)); |
---|
[285] | 192 | |
---|
[2] | 193 | $GLOBALS['phpgw']->log->commit(); |
---|
| 194 | } |
---|
| 195 | else { |
---|
| 196 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 197 | } |
---|
| 198 | } |
---|
[285] | 199 | |
---|
[2] | 200 | $contacts = array(); |
---|
[285] | 201 | |
---|
[2] | 202 | if ($other_data) |
---|
| 203 | { |
---|
| 204 | //TODO |
---|
| 205 | } |
---|
[285] | 206 | |
---|
[2] | 207 | /* First check if this is a LDAP Catalog Group. In this case, just leave the |
---|
| 208 | * subtree search for the LDAP server |
---|
| 209 | */ |
---|
| 210 | if ($ldap_info = $this->catalog['ldap']) |
---|
| 211 | { |
---|
[284] | 212 | $meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context'], $this->external); |
---|
[2] | 213 | return $meta_catalog->get_multiple_entries($id_contacts, $fields, $other_data); |
---|
| 214 | } |
---|
[285] | 215 | |
---|
[2] | 216 | /* Search for the catalog of the first entry and try to get all ids from that |
---|
| 217 | * catalog. Repeat to the ones not found until there's none missing or no more |
---|
| 218 | * catalogs. |
---|
| 219 | */ |
---|
| 220 | |
---|
| 221 | $contacts = array(); |
---|
| 222 | reset($this->catalog); |
---|
| 223 | while (list($level,$branch) = each($this->catalog['sub_branch'])) |
---|
| 224 | { |
---|
| 225 | $this->bo_contactcenter->set_catalog($branch); |
---|
| 226 | $contacts += $this->bo_contactcenter->catalog->get_multiple_entries($id_contacts, $fields, $other_data); |
---|
[285] | 227 | |
---|
[2] | 228 | reset($contacts); |
---|
| 229 | while (list($id) = each($contacts)) |
---|
| 230 | { |
---|
| 231 | if ($id_contacts[$id]) |
---|
| 232 | { |
---|
| 233 | unset($id_contacts[$id]); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | if (!count($id_contacts)) |
---|
| 238 | { |
---|
| 239 | break; |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | $this->bo_contactcenter->set_catalog($this->catalog); |
---|
[285] | 244 | |
---|
[2] | 245 | return $contacts; |
---|
| 246 | } |
---|
[285] | 247 | |
---|
[2] | 248 | function get_all_entries_ids () |
---|
| 249 | { |
---|
| 250 | // TODO! |
---|
| 251 | return null; |
---|
| 252 | } |
---|
[285] | 253 | |
---|
[2] | 254 | /*********************************************************************\ |
---|
| 255 | * Methods to get general fields * |
---|
| 256 | \*********************************************************************/ |
---|
[285] | 257 | |
---|
[2] | 258 | /*********************************************************************\ |
---|
| 259 | * Methods to Include Data * |
---|
| 260 | \*********************************************************************/ |
---|
| 261 | |
---|
| 262 | /*********************************************************************\ |
---|
| 263 | * Methods to Alter Data * |
---|
| 264 | \*********************************************************************/ |
---|
| 265 | |
---|
| 266 | /*********************************************************************\ |
---|
| 267 | * Methods to Remove Data * |
---|
| 268 | \*********************************************************************/ |
---|
| 269 | |
---|
| 270 | } |
---|
| 271 | ?> |
---|