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