[752] | 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 | include_once('class.abo_catalog.inc.php'); |
---|
| 16 | class bo_shared_group_manager extends abo_catalog |
---|
| 17 | { |
---|
| 18 | |
---|
| 19 | var $fields = array( |
---|
| 20 | 'id_group' => true, |
---|
| 21 | 'title' => true, |
---|
| 22 | 'short_name' => true, |
---|
| 23 | 'owner' => true |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | /*! |
---|
| 27 | |
---|
| 28 | @function bo_group_manager |
---|
| 29 | @abstract Constructor |
---|
| 30 | @author Raphael Derosso Pereira |
---|
| 31 | |
---|
| 32 | */ |
---|
| 33 | function bo_shared_group_manager() |
---|
| 34 | { |
---|
| 35 | $this->init(); |
---|
| 36 | |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /*! |
---|
| 40 | @function find |
---|
| 41 | @abstract Find function for this catalog |
---|
| 42 | @author Raphael Derosso Pereira |
---|
| 43 | |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | function find($what, $rules=false, $other=false) |
---|
| 47 | { |
---|
| 48 | $so_contact = CreateObject('contactcenter.so_contact', $GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 49 | $relacionados = $so_contact->get_relations(); |
---|
| 50 | |
---|
| 51 | $array_retorno = array(); |
---|
| 52 | $array_map = array(); |
---|
| 53 | $rules_inicio = $rules; |
---|
| 54 | |
---|
| 55 | foreach($relacionados as $uid_relacionado => $tipo_relacionamento) { |
---|
| 56 | $aclTemp = CreateObject("phpgwapi.acl",$uid_relacionado); |
---|
| 57 | $aclTemp->read(); |
---|
| 58 | // Preciso verificar as permissões que o contato relacionado deu para o atual |
---|
| 59 | $perms_relacao = $aclTemp->get_specific_rights($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); |
---|
| 60 | // Se não tiver permissão de leitura, nem se preocupe em listá-los |
---|
| 61 | if(!(($perms_relacao&1) && $tipo_relacionamento == 1)) { |
---|
| 62 | continue; |
---|
| 63 | } |
---|
| 64 | $found = false; |
---|
| 65 | |
---|
| 66 | if (is_array($what) && count($what)) { |
---|
| 67 | foreach ($what as $id => $value) { |
---|
| 68 | if (strpos($value, 'group') === 0) { |
---|
| 69 | $found = true; |
---|
| 70 | break; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | if (!$found) { |
---|
| 75 | return $this->sql_find($what, $rules, $other); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | if(!$rules) |
---|
| 79 | $rules = array(); |
---|
| 80 | |
---|
| 81 | array_push($rules, array( |
---|
| 82 | 'field' => 'group.owner', |
---|
| 83 | 'type' => '=', |
---|
| 84 | 'value' => $uid_relacionado ) |
---|
| 85 | ); |
---|
| 86 | |
---|
| 87 | $array_temp = $this->sql_find($what, $rules, $other); |
---|
| 88 | if(count($array_retorno)==0) { |
---|
| 89 | $array_map = $this->cria_aux($array_temp); |
---|
| 90 | if($array_map) foreach($array_temp as $valor_retorno) { |
---|
| 91 | $valor_retorno['perms'] = $perms_relacao; |
---|
| 92 | $valor_retorno['owner'] = $uid_relacionado; |
---|
| 93 | array_push($array_retorno,$valor_retorno); |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | else { |
---|
| 97 | if($array_temp) foreach($array_temp as $value) { |
---|
| 98 | $value['perms'] = $perms_relacao; |
---|
| 99 | $value['owner'] = $uid_relacionado; |
---|
| 100 | $array_map[$value["title"]] = 1; |
---|
| 101 | array_push($array_retorno,$value); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | $rules = $rules_inicio; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | usort($array_retorno, array($this, "compareTreeNodes")); |
---|
| 108 | return $array_retorno; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | function compareTreeNodes($a, $b) { |
---|
| 112 | return strnatcasecmp($a['title'], $b['title']); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | function cria_aux($array) { |
---|
| 116 | $retorno = array(); |
---|
| 117 | if($array) foreach($array as $valor) { |
---|
| 118 | $retorno[$valor["title"]] = 1; |
---|
| 119 | } |
---|
| 120 | return $retorno; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /*! |
---|
| 125 | |
---|
| 126 | @function get_multiple_entries |
---|
| 127 | @abstract Returns multiple Contacts data into one array |
---|
| 128 | @author Raphael Derosso Pereira |
---|
| 129 | |
---|
| 130 | @param array $id_contacts The Contacts IDs |
---|
| 131 | @param array $fields The Contacts fields to be retrieved |
---|
| 132 | @param array $other_data Other informations. The format is: |
---|
| 133 | $other_data = array( |
---|
| 134 | 'offset' => <offset>, |
---|
| 135 | 'limit' => <max_num_returns>, |
---|
| 136 | 'sort' => <sort>, |
---|
| 137 | 'order_by' => <order by> |
---|
| 138 | ); |
---|
| 139 | |
---|
| 140 | */ |
---|
| 141 | function get_multiple_entries ( $id_groups, $fields, $other_data = false ) |
---|
| 142 | { |
---|
| 143 | |
---|
| 144 | $groups = array(); |
---|
| 145 | foreach ($id_groups as $id) |
---|
| 146 | { |
---|
| 147 | $group = $this->get_single_entry($id,$fields); |
---|
| 148 | if ($group) |
---|
| 149 | { |
---|
| 150 | $groups[] = $group; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | return $groups; |
---|
| 155 | |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /*! |
---|
| 159 | |
---|
| 160 | @function get_all_entries_ids |
---|
| 161 | @abstract Returns the IDs of all the entries in this catalog |
---|
| 162 | @author Raphael Derosso Pereira |
---|
| 163 | |
---|
| 164 | */ |
---|
| 165 | function get_all_entries_ids () |
---|
| 166 | { |
---|
| 167 | |
---|
| 168 | $search_fields = array('group.id_group', 'group.title'); |
---|
| 169 | $search_other = array('order' => 'group.title'); |
---|
| 170 | |
---|
| 171 | $search_rules = array(); |
---|
| 172 | array_push($search_rules, array( |
---|
| 173 | 'field' => 'group.owner', |
---|
| 174 | 'type' => '=', |
---|
| 175 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 176 | )); |
---|
| 177 | |
---|
| 178 | $result_i = $this->find($search_fields, $search_rules, $search_other); |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | if (is_array($result_i) and count($result_i)) |
---|
| 182 | { |
---|
| 183 | $result = array(); |
---|
| 184 | foreach($result_i as $result_part) |
---|
| 185 | { |
---|
| 186 | $result[] = $result_part['id_group']; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | return $result; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | return null; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | function get_single_entry ( $id, $fields ) |
---|
| 196 | { |
---|
| 197 | |
---|
| 198 | if (!is_array($fields)) |
---|
| 199 | { |
---|
| 200 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 201 | { |
---|
| 202 | $GLOBALS['phpgw']->log->message(array( |
---|
| 203 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 204 | 'line' => __LINE__, |
---|
| 205 | 'file' => __FILE__)); |
---|
| 206 | |
---|
| 207 | $GLOBALS['phpgw']->log->commit(); |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | { |
---|
| 211 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
| 216 | $group = $soGroup -> select($id); |
---|
| 217 | return $group[0]; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | function get_contacts_by_group ( $id ) |
---|
| 222 | { |
---|
| 223 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
| 224 | return $soGroup -> selectContactsByGroup($id); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | } |
---|
| 228 | ?> |
---|