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