[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 | include_once('class.abo_catalog.inc.php'); |
---|
| 16 | class bo_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_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 | function find($what, $rules=false, $other=false) |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | if (is_array($what) and count($what)) |
---|
| 49 | { |
---|
| 50 | $found = false; |
---|
| 51 | |
---|
| 52 | foreach ($what as $value) |
---|
| 53 | { |
---|
| 54 | if (strpos($value, 'group') === 0) |
---|
| 55 | { |
---|
| 56 | $found = true; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if (!$found) |
---|
| 61 | { |
---|
[1287] | 62 | |
---|
[2] | 63 | return $this->sql_find($what, $rules, $other); |
---|
| 64 | } |
---|
[1287] | 65 | if ($rules and is_array($rules)) |
---|
| 66 | { |
---|
| 67 | array_push($rules, array( |
---|
| 68 | 'field' => 'group.owner', |
---|
| 69 | 'type' => '=', |
---|
| 70 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 71 | )); |
---|
| 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | $rules = array( |
---|
| 76 | 0 => array( |
---|
| 77 | 'field' => 'group.owner', |
---|
| 78 | 'type' => '=', |
---|
| 79 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 80 | ) |
---|
| 81 | ); |
---|
| 82 | } |
---|
[2] | 83 | |
---|
| 84 | } |
---|
[1287] | 85 | |
---|
[2] | 86 | return $this->sql_find($what, $rules, $other); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /*! |
---|
| 90 | |
---|
| 91 | @function get_multiple_entries |
---|
| 92 | @abstract Returns multiple Contacts data into one array |
---|
| 93 | @author Raphael Derosso Pereira |
---|
| 94 | |
---|
| 95 | @param array $id_contacts The Contacts IDs |
---|
| 96 | @param array $fields The Contacts fields to be retrieved |
---|
| 97 | @param array $other_data Other informations. The format is: |
---|
| 98 | $other_data = array( |
---|
| 99 | 'offset' => <offset>, |
---|
| 100 | 'limit' => <max_num_returns>, |
---|
| 101 | 'sort' => <sort>, |
---|
| 102 | 'order_by' => <order by> |
---|
| 103 | ); |
---|
| 104 | |
---|
| 105 | */ |
---|
| 106 | function get_multiple_entries ( $id_groups, $fields, $other_data = false ) |
---|
| 107 | { |
---|
| 108 | |
---|
| 109 | $groups = array(); |
---|
| 110 | |
---|
| 111 | foreach ($id_groups as $id) |
---|
| 112 | { |
---|
| 113 | $group = $this->get_single_entry($id,$fields); |
---|
| 114 | |
---|
| 115 | if ($group) |
---|
| 116 | { |
---|
| 117 | $groups[] = $group; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | return $groups; |
---|
| 122 | |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | /*! |
---|
| 126 | |
---|
| 127 | @function get_all_entries_ids |
---|
| 128 | @abstract Returns the IDs of all the entries in this catalog |
---|
| 129 | @author Raphael Derosso Pereira |
---|
| 130 | |
---|
| 131 | */ |
---|
| 132 | function get_all_entries_ids () |
---|
| 133 | { |
---|
| 134 | |
---|
| 135 | $search_fields = array('group.id_group', 'group.title'); |
---|
| 136 | $search_other = array('order' => 'group.title'); |
---|
| 137 | |
---|
| 138 | $search_rules = array(); |
---|
| 139 | array_push($search_rules, array( |
---|
| 140 | 'field' => 'group.owner', |
---|
| 141 | 'type' => '=', |
---|
| 142 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 143 | )); |
---|
| 144 | |
---|
| 145 | $result_i = $this->find($search_fields, $search_rules, $search_other); |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | if (is_array($result_i) and count($result_i)) |
---|
| 149 | { |
---|
| 150 | $result = array(); |
---|
| 151 | foreach($result_i as $result_part) |
---|
| 152 | { |
---|
| 153 | $result[] = $result_part['id_group']; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | return $result; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | return null; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | function get_single_entry ( $id, $fields ) |
---|
| 163 | { |
---|
| 164 | |
---|
| 165 | if (!is_array($fields)) |
---|
| 166 | { |
---|
| 167 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 168 | { |
---|
| 169 | $GLOBALS['phpgw']->log->message(array( |
---|
| 170 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 171 | 'line' => __LINE__, |
---|
| 172 | 'file' => __FILE__)); |
---|
| 173 | |
---|
| 174 | $GLOBALS['phpgw']->log->commit(); |
---|
| 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
| 183 | $group = $soGroup -> select($id); |
---|
| 184 | |
---|
| 185 | return $group[0]; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | function add_group ( $data ) |
---|
| 189 | { |
---|
| 190 | $permissions = $this->security->get_permissions(); |
---|
| 191 | |
---|
| 192 | if (!$permissions['create']) |
---|
| 193 | { |
---|
| 194 | return false; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
| 198 | |
---|
| 199 | if(! $data['id_group']) |
---|
| 200 | $id = $soGroup -> insert($data); |
---|
| 201 | else |
---|
| 202 | $id = $soGroup -> update($data); |
---|
| 203 | |
---|
| 204 | return $id; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | function get_contacts_by_group ( $id ) |
---|
| 208 | { |
---|
| 209 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
| 210 | return $soGroup -> selectContactsByGroup($id); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | } |
---|
| 214 | ?> |
---|