1 | <?php |
---|
2 | class ui_mobilecc{ |
---|
3 | |
---|
4 | var $nextmatchs; |
---|
5 | var $bo; |
---|
6 | var $page_info = array ( |
---|
7 | 'actual_catalog' => false, |
---|
8 | 'actual_letter' => null, |
---|
9 | 'actual_max_contacts' => null, |
---|
10 | 'request_from' => null |
---|
11 | ); |
---|
12 | |
---|
13 | var $public_functions = array( |
---|
14 | 'index' => true, |
---|
15 | 'change_max_results' => true, |
---|
16 | 'change_catalog' => true, |
---|
17 | 'delete_contacts' => true, |
---|
18 | 'change_letter' => true, |
---|
19 | 'choose_contact' => true, |
---|
20 | 'init_cc' => true |
---|
21 | ); |
---|
22 | var $template; |
---|
23 | |
---|
24 | /** |
---|
25 | * Construtor... |
---|
26 | * |
---|
27 | */ |
---|
28 | public function ui_mobilecc() { |
---|
29 | $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
30 | $this->bo = CreateObject('mobile.bo_mobilecc'); |
---|
31 | $page_info = $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile'); |
---|
32 | |
---|
33 | if($page_info) { |
---|
34 | $this->page_info = $page_info; |
---|
35 | } |
---|
36 | else { |
---|
37 | $this->set_page_info_to_default(); |
---|
38 | } |
---|
39 | |
---|
40 | //if() |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | private function set_page_info_to_default() { //Valores default para iniciar o módulo de contatos |
---|
45 | $this->page_info['actual_catalog'] = 'bo_people_catalog'; |
---|
46 | $this->page_info['actual_letter'] = 'a'; |
---|
47 | $this->page_info['actual_max_contacts'] = 10; |
---|
48 | $this->page_info['request_from'] = null; |
---|
49 | } |
---|
50 | |
---|
51 | private function save_session() { |
---|
52 | $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile',$this->page_info); |
---|
53 | } |
---|
54 | |
---|
55 | public function index($params) { |
---|
56 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
57 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]); |
---|
58 | $this->contacts_list(); |
---|
59 | } |
---|
60 | |
---|
61 | public function change_max_results($params) { |
---|
62 | $this->page_info['actual_max_contacts'] = $params['results']; |
---|
63 | $this->contacts_list(); |
---|
64 | $this->save_session(); |
---|
65 | } |
---|
66 | |
---|
67 | public function change_letter($params) { |
---|
68 | $this->page_info['actual_letter'] = $params['letter']; |
---|
69 | $this->page_info['actual_max_contacts'] = 10; |
---|
70 | $this->contacts_list(); |
---|
71 | $this->save_session(); |
---|
72 | } |
---|
73 | |
---|
74 | public function change_catalog($params) { |
---|
75 | |
---|
76 | $this->page_info['actual_catalog'] = $params['catalog']; |
---|
77 | $this->page_info['actual_max_contacts'] = 10; |
---|
78 | $this->page_info['actual_letter'] = 'a'; |
---|
79 | |
---|
80 | $this->contacts_list(); |
---|
81 | |
---|
82 | $this->save_session(); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * Função de inicio do módulo para escolha de um contato para outro módulo. |
---|
87 | * |
---|
88 | * @return |
---|
89 | * @param $params Object |
---|
90 | */ |
---|
91 | public function choose_contact($params) { |
---|
92 | $this->set_page_info_to_default(); |
---|
93 | $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from |
---|
94 | $this->contacts_list(); |
---|
95 | $this->save_session(); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Função de inicio do módulo de cc |
---|
100 | * |
---|
101 | * @return |
---|
102 | * @param $params Object |
---|
103 | */ |
---|
104 | public function init_cc($params) { |
---|
105 | $this->set_page_info_to_default(); |
---|
106 | $this->contacts_list(); |
---|
107 | $this->save_session(); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita |
---|
112 | * busca, mostra apenas o formulário para pesquisa. |
---|
113 | * |
---|
114 | * @return |
---|
115 | */ |
---|
116 | |
---|
117 | function contacts_list() { |
---|
118 | |
---|
119 | $this->template->set_file( |
---|
120 | Array( |
---|
121 | 'contacts_list' => 'cc_main.tpl' |
---|
122 | ) |
---|
123 | ); |
---|
124 | $this->template->set_block("contacts_list","catalog_row"); |
---|
125 | $this->template->set_block("contacts_list","main_body"); |
---|
126 | $this->template->set_block("contacts_list","pagging_block"); |
---|
127 | |
---|
128 | //Langs gerais da página |
---|
129 | $this->template->set_var("lang_back",lang("back")); |
---|
130 | $this->template->set_var("lang_more",lang("more")); |
---|
131 | $this->template->set_var("lang_contacts",ucfirst(lang("contacts"))); |
---|
132 | $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]); |
---|
133 | $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10); |
---|
134 | $this->template->set_var("contacts_request_from", |
---|
135 | $this->page_info["request_from"]==null? |
---|
136 | "none":$this->page_info["request_from"]); |
---|
137 | |
---|
138 | //Combo de catálogos |
---|
139 | $catalogs = $this->bo->get_all_catalogs(); |
---|
140 | foreach($catalogs as $catalog) { |
---|
141 | $this->template->set_var("catalog_value",$catalog["catalog"]); |
---|
142 | $this->template->set_var("catalog_name",$catalog["label"]); |
---|
143 | if($this->page_info['actual_catalog']==$catalog['catalog']) |
---|
144 | $this->template->set_var("selected","selected"); |
---|
145 | else |
---|
146 | $this->template->set_var("selected"," "); |
---|
147 | $this->template->fp("catalogs","catalog_row",true); |
---|
148 | } |
---|
149 | $this->bo->set_catalog($this->page_info["actual_catalog"]); |
---|
150 | $contacts = $this->bo->search($this->page_info["actual_letter"]."%", |
---|
151 | $this->page_info["actual_max_contacts"]); |
---|
152 | |
---|
153 | |
---|
154 | //Letras da paginação |
---|
155 | $max_letters = 5; |
---|
156 | if ( in_array($this->page_info['actual_letter'], |
---|
157 | range("a","c"))){ //Letras de A à C iniciam sempre com A |
---|
158 | |
---|
159 | $this->template->set_var('show_back','none'); |
---|
160 | $this->template->set_var('show_next','inline'); |
---|
161 | $first_letter = "a"; |
---|
162 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
163 | "ui_mobilecc.change_letter&letter=f"); |
---|
164 | } |
---|
165 | else if ( in_array($this->page_info['actual_letter'], |
---|
166 | range("x","z"))) { //Letras de X à Z terminam sempre no Z |
---|
167 | $this->template->set_var('show_back','inline'); |
---|
168 | $this->template->set_var('show_next','none'); |
---|
169 | $first_letter = "v"; |
---|
170 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
171 | "ui_mobilecc.change_letter&letter=u"); |
---|
172 | } |
---|
173 | else { //Letras do meio |
---|
174 | $this->template->set_var('show_back','inline'); |
---|
175 | $this->template->set_var('show_next','inline'); |
---|
176 | |
---|
177 | $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes |
---|
178 | $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter |
---|
179 | |
---|
180 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
181 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
182 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
183 | "ui_mobilecc.change_letter&letter=".$last_letter); |
---|
184 | $first_letter++; |
---|
185 | } |
---|
186 | |
---|
187 | for($i=1;$i<=$max_letters;$i++) { //Roda as letras |
---|
188 | $this->template->set_var("href","index.php?menuaction=mobile.". |
---|
189 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
190 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
191 | if($first_letter===$this->page_info["actual_letter"]) |
---|
192 | $this->template->set_var("class_button","letter-contact-selected"); |
---|
193 | else |
---|
194 | $this->template->set_var("class_button","btn_off"); |
---|
195 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
196 | $this->template->fp("pagging_letters","pagging_block",true); |
---|
197 | $first_letter++; |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | if($contacts['has_more']) |
---|
202 | $this->template->set_var("show_more","block"); |
---|
203 | else |
---|
204 | $this->template->set_var("show_more","none"); |
---|
205 | unset($contacts['has_more']); |
---|
206 | |
---|
207 | $this->template->set_var("contacts",$this->print_contacts($contacts,true,$this->page_info['request_from'])); |
---|
208 | |
---|
209 | |
---|
210 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body')); |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * Remove os contatos selecionados |
---|
215 | * |
---|
216 | * @return |
---|
217 | * @param $contacts Object |
---|
218 | * @param $show_checkbox Object[optional] |
---|
219 | */ |
---|
220 | |
---|
221 | function delete_contacts($params) { |
---|
222 | $this->bo->set_catalog($params['catalog']); |
---|
223 | $status = $this->bo->remove_multiple_entries($params['contacts']); |
---|
224 | |
---|
225 | $type = $this->page_info['actual_catalog']==='bo_people_catalog'?"contacts":"groups"; |
---|
226 | |
---|
227 | if($status['success']) |
---|
228 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully")); |
---|
229 | else |
---|
230 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed")); |
---|
231 | } |
---|
232 | |
---|
233 | static function print_contacts($contacts,$show_checkbox=false,$request_from = null) { |
---|
234 | $functions = CreateObject('mobile.common_functions'); |
---|
235 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
236 | $p->set_file( |
---|
237 | Array( |
---|
238 | 'cc_t' => 'contacts_list.tpl' |
---|
239 | ) |
---|
240 | ); |
---|
241 | $p->set_block('cc_t', 'rows_contacts'); |
---|
242 | $p->set_block('cc_t', 'row_contacts'); |
---|
243 | $p->set_block('cc_t', 'row_groups'); |
---|
244 | $p->set_block('cc_t', 'no_contacts'); |
---|
245 | |
---|
246 | $bg = "par"; |
---|
247 | if(!empty($contacts)) { |
---|
248 | foreach($contacts as $id => $contact) { |
---|
249 | |
---|
250 | $p->set_var('show_check',$show_checkbox?"inline":"none"); |
---|
251 | $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par"); |
---|
252 | |
---|
253 | if($contact["catalog"]!=="bo_group_manager") { //Contatos |
---|
254 | $id=$contact["catalog"]==="bo_people_catalog"?$contact["id_contact"]:$contact['uidnumber'][0]; |
---|
255 | |
---|
256 | $mail = $contact["connections"]["connection1"]["connection_value"];//Preciso o mail depois |
---|
257 | $cn = is_array($contact["names_ordered"])? |
---|
258 | $contact["names_ordered"][0]:$contact["names_ordered"]; |
---|
259 | if(($contact["connections"]["connection1"]["connection_value"]==null || |
---|
260 | $contact["connections"]["connection1"]["id_type"]!=="1") |
---|
261 | && isset($request_from)) //Se vier de outro módulo e não possuir e-mail, não mostre. |
---|
262 | continue; |
---|
263 | |
---|
264 | $p->set_var('contact_id',$id); |
---|
265 | $p->set_var('lang_tel',lang("tel")); |
---|
266 | $p->set_var('show_tel',$contact["connections"]["connection2"]["connection_value"]!=null?"inline":"none"); |
---|
267 | $p->set_var('contact_name',$functions->strach_string($cn,17)); |
---|
268 | $p->set_var('email', |
---|
269 | $functions->strach_string( |
---|
270 | ($contact["connections"]["connection1"]["connection_value"]!=null && |
---|
271 | $contact["connections"]["connection1"]["id_type"]==="1")? |
---|
272 | $contact["connections"]["connection1"]["connection_value"]:" ",20)); |
---|
273 | $p->set_var('tel',$functions->strach_string($contact["connections"]["connection1"]["id_type"]==="2"? |
---|
274 | $contact["connections"]["connection1"]["connection_value"]: |
---|
275 | $contact["connections"]["connection2"]["connection_value"],19)); |
---|
276 | |
---|
277 | $block = "row_contacts"; |
---|
278 | } |
---|
279 | else { //Grupos |
---|
280 | $id=$contact["id_group"]; |
---|
281 | $mail = $cn = $contact["title"]; |
---|
282 | $p->set_var('group_id',$contact["id_group"]); |
---|
283 | $p->set_var('group_name',$contact["title"]); |
---|
284 | $block = "row_groups"; |
---|
285 | } |
---|
286 | |
---|
287 | if($request_from==null) { |
---|
288 | $p->set_var('lang_see_details',strtoupper(lang("see details"))); |
---|
289 | $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".$contact["catalog"]); |
---|
290 | } |
---|
291 | else { |
---|
292 | $p->set_var('lang_see_details',strtoupper(lang("select"))); |
---|
293 | $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn"); |
---|
294 | } |
---|
295 | |
---|
296 | $p->fp('rows',$block,True); |
---|
297 | } |
---|
298 | |
---|
299 | } |
---|
300 | else { |
---|
301 | $p->set_var("lang_no_results",lang("no results found")); |
---|
302 | $p->parse("rows","no_contacts"); |
---|
303 | } |
---|
304 | return $p->fp('out','rows_contacts'); |
---|
305 | } |
---|
306 | |
---|
307 | } |
---|
308 | |
---|
309 | |
---|
310 | |
---|
311 | |
---|
312 | ?> |
---|