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 | 'contact_view' => true, |
---|
22 | 'contact_add_edit' => true, |
---|
23 | 'contact_add' => true, |
---|
24 | 'contact_edit' => true, |
---|
25 | 'getPhoto' => true |
---|
26 | ); |
---|
27 | var $template; |
---|
28 | |
---|
29 | /** |
---|
30 | * Construtor... |
---|
31 | * |
---|
32 | */ |
---|
33 | public function ui_mobilecc() { |
---|
34 | $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
35 | $this->bo = CreateObject('mobile.bo_mobilecc'); |
---|
36 | $page_info = $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile'); |
---|
37 | |
---|
38 | if($page_info) { |
---|
39 | $this->page_info = $page_info; |
---|
40 | } |
---|
41 | else { |
---|
42 | $this->set_page_info_to_default(); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | private function set_page_info_to_default() { //Valores default para iniciar o módulo de contatos |
---|
47 | $this->page_info['actual_catalog'] = 'bo_people_catalog'; |
---|
48 | $this->page_info['actual_letter'] = 'a'; |
---|
49 | $this->page_info['actual_max_contacts'] = 10; |
---|
50 | $this->page_info['request_from'] = null; |
---|
51 | } |
---|
52 | |
---|
53 | private function save_session() { |
---|
54 | $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile',$this->page_info); |
---|
55 | } |
---|
56 | |
---|
57 | public function index($params) { |
---|
58 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
59 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]); |
---|
60 | $this->contacts_list(); |
---|
61 | } |
---|
62 | |
---|
63 | public function change_max_results($params) { |
---|
64 | $this->page_info['actual_max_contacts'] = $params['results']; |
---|
65 | $this->save_session(); |
---|
66 | $this->contacts_list(); |
---|
67 | } |
---|
68 | |
---|
69 | public function change_letter($params) |
---|
70 | { |
---|
71 | if( $params['letter'] ) |
---|
72 | { |
---|
73 | $this->page_info['actual_letter'] = $params['letter']; |
---|
74 | } |
---|
75 | $this->page_info['actual_max_contacts'] = 10; |
---|
76 | $this->save_session(); |
---|
77 | $this->contacts_list($params); |
---|
78 | } |
---|
79 | |
---|
80 | public function change_catalog($params) |
---|
81 | { |
---|
82 | $this->page_info['actual_catalog'] = $params['catalog']; |
---|
83 | $this->page_info['actual_letter'] = 'a'; |
---|
84 | $this->page_info['actual_max_contacts'] = 10; |
---|
85 | $this->save_session(); |
---|
86 | $this->contacts_list($params); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * Função de inicio do módulo para escolha de um contato para outro módulo. |
---|
91 | * |
---|
92 | * @return |
---|
93 | * @param $params Object |
---|
94 | */ |
---|
95 | public function choose_contact($params) { |
---|
96 | $this->set_page_info_to_default(); |
---|
97 | $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from |
---|
98 | $this->save_session(); |
---|
99 | $this->contacts_list(); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Função de inicio do módulo de cc |
---|
104 | * |
---|
105 | * @return |
---|
106 | * @param $params Object |
---|
107 | */ |
---|
108 | public function init_cc($params) { |
---|
109 | $this->set_page_info_to_default(); |
---|
110 | $this->save_session(); |
---|
111 | $this->contacts_list($params); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita |
---|
116 | * busca, mostra apenas o formulário para pesquisa. |
---|
117 | * |
---|
118 | * @return |
---|
119 | */ |
---|
120 | |
---|
121 | function contacts_list($params) { |
---|
122 | |
---|
123 | $this->template->set_file( |
---|
124 | Array( |
---|
125 | 'contacts_list' => 'cc_main.tpl', |
---|
126 | 'home_search_bar' => 'search_bar.tpl' |
---|
127 | ) |
---|
128 | ); |
---|
129 | $this->template->set_block("contacts_list","catalog_row"); |
---|
130 | $this->template->set_block("contacts_list","main_body"); |
---|
131 | $this->template->set_block("contacts_list","pagging_block"); |
---|
132 | $this->template->set_block('home_search_bar','search_bar'); |
---|
133 | |
---|
134 | //Langs gerais da página |
---|
135 | $this->template->set_var("lang_back",lang("back")); |
---|
136 | $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link()); |
---|
137 | $this->template->set_var("selecteds",ucfirst(lang("selecteds"))); |
---|
138 | $this->template->set_var("lang_more",lang("more")); |
---|
139 | $this->template->set_var("lang_search",lang("search")); |
---|
140 | $this->template->set_var("lang_contacts",ucfirst(lang("contacts"))); |
---|
141 | $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]); |
---|
142 | $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10); |
---|
143 | |
---|
144 | $show_checkbox = true; |
---|
145 | if(strpos($this->page_info["actual_catalog"],"ldap")===false) { |
---|
146 | $this->template->set_var("show_actions", "block"); |
---|
147 | } else { |
---|
148 | $this->template->set_var("show_actions", "none"); |
---|
149 | $show_checkbox = false; |
---|
150 | } |
---|
151 | |
---|
152 | $this->template->set_var("show_add_button",$this->page_info["actual_catalog"] == "bo_group_manager" ? "none" : ""); |
---|
153 | |
---|
154 | $this->template->set_var("contacts_request_from", |
---|
155 | $this->page_info["request_from"]==null? |
---|
156 | "none":$this->page_info["request_from"]); |
---|
157 | |
---|
158 | if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile')!="mini_desktop") |
---|
159 | $this->template->set_var('search',$this->template->fp('out','search_bar')); |
---|
160 | |
---|
161 | //Combo de catálogos |
---|
162 | $catalogs = $this->bo->get_all_catalogs(); |
---|
163 | |
---|
164 | foreach($catalogs as $catalog) |
---|
165 | { |
---|
166 | $this->template->set_var("catalog_value",$catalog["catalog"]); |
---|
167 | $this->template->set_var("catalog_name",$catalog["label"]); |
---|
168 | |
---|
169 | if( $this->page_info['actual_catalog'] == $catalog['catalog'] ) |
---|
170 | $this->template->set_var("selected","selected"); |
---|
171 | else |
---|
172 | $this->template->set_var("selected"," "); |
---|
173 | |
---|
174 | $this->template->fp("catalogs","catalog_row",true); |
---|
175 | } |
---|
176 | |
---|
177 | $catalog = ( isset($params['catalog']) ) ? $params['catalog'] : $this->page_info['actual_catalog']; |
---|
178 | |
---|
179 | if( strpos( $catalog, "bo_global_ldap_catalog") !== false ) |
---|
180 | { |
---|
181 | $dn = $GLOBALS['phpgw_info']['user']['account_dn']; |
---|
182 | $dn = substr( $dn, strpos($dn, "ou=" ) ); |
---|
183 | $exploded = explode("#", $catalog ); |
---|
184 | $catalog = 'bo_people_catalog'; |
---|
185 | |
---|
186 | if( count($exploded) > 2 ) |
---|
187 | { |
---|
188 | $exploded[2] = $dn; |
---|
189 | $actual_catalog = implode("#", $exploded); |
---|
190 | $catalog = $actual_catalog; |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | $this->bo->set_catalog($catalog); |
---|
195 | $contacts = $this->bo->search($this->page_info["actual_letter"]."%", $this->page_info["actual_max_contacts"]); |
---|
196 | |
---|
197 | //Letras da paginação |
---|
198 | $max_letters = 5; |
---|
199 | if ( in_array($this->page_info['actual_letter'], |
---|
200 | range("a","c"))){ //Letras de A à C iniciam sempre com A |
---|
201 | |
---|
202 | $this->template->set_var('show_back','none'); |
---|
203 | $this->template->set_var('show_next','inline'); |
---|
204 | $first_letter = "a"; |
---|
205 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
206 | "ui_mobilecc.change_letter&letter=f"); |
---|
207 | } |
---|
208 | else if ( in_array($this->page_info['actual_letter'], |
---|
209 | range("x","z"))) { //Letras de X à Z terminam sempre no Z |
---|
210 | $this->template->set_var('show_back','inline'); |
---|
211 | $this->template->set_var('show_next','none'); |
---|
212 | $first_letter = "v"; |
---|
213 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
214 | "ui_mobilecc.change_letter&letter=u"); |
---|
215 | } |
---|
216 | else { //Letras do meio |
---|
217 | $this->template->set_var('show_back','inline'); |
---|
218 | $this->template->set_var('show_next','inline'); |
---|
219 | |
---|
220 | $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes |
---|
221 | $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter |
---|
222 | |
---|
223 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
224 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
225 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
226 | "ui_mobilecc.change_letter&letter=".$last_letter); |
---|
227 | $first_letter++; |
---|
228 | } |
---|
229 | |
---|
230 | for($i=1;$i<=$max_letters;$i++) { //Roda as letras |
---|
231 | $this->template->set_var("href","index.php?menuaction=mobile.". |
---|
232 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
233 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
234 | if($first_letter===$this->page_info["actual_letter"]) |
---|
235 | $this->template->set_var("class_button","letter-contact-selected"); |
---|
236 | else |
---|
237 | $this->template->set_var("class_button","btn_off"); |
---|
238 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
239 | $this->template->fp("pagging_letters","pagging_block",true); |
---|
240 | $first_letter++; |
---|
241 | } |
---|
242 | |
---|
243 | |
---|
244 | if($contacts['has_more']) |
---|
245 | $this->template->set_var("show_more","block"); |
---|
246 | else |
---|
247 | $this->template->set_var("show_more","none"); |
---|
248 | unset($contacts['has_more']); |
---|
249 | |
---|
250 | $this->template->set_var("contacts",$this->print_contacts($contacts,$show_checkbox,$this->page_info['request_from'])); |
---|
251 | |
---|
252 | |
---|
253 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body')); |
---|
254 | } |
---|
255 | |
---|
256 | /** |
---|
257 | * Remove os contatos selecionados |
---|
258 | * |
---|
259 | * @return |
---|
260 | * @param $contacts Object |
---|
261 | * @param $show_checkbox Object[optional] |
---|
262 | */ |
---|
263 | |
---|
264 | function delete_contacts($params) |
---|
265 | { |
---|
266 | $this->bo->set_catalog($params['catalog']); |
---|
267 | |
---|
268 | if (!is_array($params['contacts']) ){ |
---|
269 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("please select one contact")); |
---|
270 | }else{ |
---|
271 | |
---|
272 | $status = $this->bo->remove_multiple_entries($params['contacts']); |
---|
273 | |
---|
274 | $type = $this->page_info['actual_catalog']!=='bo_group_manager'?"contacts":"groups"; |
---|
275 | |
---|
276 | if($status['success']) |
---|
277 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully")); |
---|
278 | else |
---|
279 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed")); |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | static function print_contacts($contacts,$show_checkbox=false,$request_from = null) { |
---|
284 | $functions = CreateObject('mobile.common_functions'); |
---|
285 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
286 | $p->set_file( |
---|
287 | Array( |
---|
288 | 'cc_t' => 'contacts_list.tpl' |
---|
289 | ) |
---|
290 | ); |
---|
291 | $p->set_block('cc_t', 'rows_contacts'); |
---|
292 | $p->set_block('cc_t', 'row_contacts'); |
---|
293 | $p->set_block('cc_t', 'row_groups'); |
---|
294 | $p->set_block('cc_t', 'no_contacts'); |
---|
295 | |
---|
296 | $bg = "bg-azul"; |
---|
297 | if(!empty($contacts)) { |
---|
298 | foreach($contacts as $id => $contact) { |
---|
299 | |
---|
300 | $p->set_var('show_check',$show_checkbox?"inline":"none"); |
---|
301 | $p->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul"); |
---|
302 | if($show_checkbox) |
---|
303 | $p->set_var("details","email-corpo"); |
---|
304 | else |
---|
305 | $p->set_var("details","limpar_div margin-geral"); |
---|
306 | if($contact["catalog"]!=="bo_group_manager") { //Contatos |
---|
307 | $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id; |
---|
308 | |
---|
309 | $mail = ' '; $tel = ' '; |
---|
310 | foreach($contact['connections'] as $key => $conn) { |
---|
311 | |
---|
312 | $test = false; |
---|
313 | if ($conn['connection_is_default']) { |
---|
314 | $test = true; |
---|
315 | } |
---|
316 | |
---|
317 | if (is_array($conn)){ |
---|
318 | $test = true; |
---|
319 | }else{ |
---|
320 | $test = false; |
---|
321 | } |
---|
322 | if ( $test) { |
---|
323 | if ( ($conn['id_type'] == 1) ) |
---|
324 | $mail = $conn['connection_value']; |
---|
325 | else if ( ($conn['id_type'] == 2) ) |
---|
326 | $tel = $conn['connection_value']; |
---|
327 | |
---|
328 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){ |
---|
329 | if ( ($conn['type'] == 'email') ) |
---|
330 | $mail = $conn['connection_value']; |
---|
331 | else if ( ($conn['type'] == 'phone') ) |
---|
332 | $tel = $conn['connection_value']; |
---|
333 | |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"]; |
---|
341 | $vtel = ($tel==null || $tel==' ')?"none":"inline"; |
---|
342 | |
---|
343 | if(($mail==' ' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre. |
---|
344 | continue; |
---|
345 | |
---|
346 | $p->set_var('show_tel',$vtel); |
---|
347 | $p->set_var('email',$mail); |
---|
348 | $p->set_var('tel',$tel); |
---|
349 | $p->set_var('contact_id',$id); |
---|
350 | $p->set_var('lang_tel',lang("tel")); |
---|
351 | $p->set_var('contact_name',$functions->strach_string($cn,17)); |
---|
352 | |
---|
353 | $block = "row_contacts"; |
---|
354 | } |
---|
355 | else { //Grupos |
---|
356 | $id=$contact["id_group"]; |
---|
357 | $mail = $cn = $contact["title"]; |
---|
358 | $p->set_var('group_id',$contact["id_group"]); |
---|
359 | $p->set_var('group_name',$contact["title"]); |
---|
360 | $block = "row_groups"; |
---|
361 | } |
---|
362 | |
---|
363 | if($request_from==null) { |
---|
364 | $p->set_var('lang_see_details',lang("details")); |
---|
365 | $cat_encode = urlencode($contact["catalog"]); |
---|
366 | $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"])); |
---|
367 | } |
---|
368 | else { |
---|
369 | $p->set_var('lang_see_details',lang("select")); |
---|
370 | $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn"); |
---|
371 | } |
---|
372 | |
---|
373 | $p->fp('rows',$block,True); |
---|
374 | |
---|
375 | } |
---|
376 | |
---|
377 | } |
---|
378 | else { |
---|
379 | $p->set_var("lang_no_results",lang("no results found")); |
---|
380 | $p->parse("rows","no_contacts"); |
---|
381 | } |
---|
382 | return $p->fp('out','rows_contacts'); |
---|
383 | } |
---|
384 | |
---|
385 | /** |
---|
386 | * Show details from contact selected |
---|
387 | * |
---|
388 | * @param $id int |
---|
389 | * @param $catalog String |
---|
390 | * @return $contact |
---|
391 | */ |
---|
392 | function contact_view($params) |
---|
393 | { |
---|
394 | |
---|
395 | if ( empty($params['id']) || empty($params['catalog']) ) |
---|
396 | { |
---|
397 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
398 | } |
---|
399 | |
---|
400 | $this->template->set_file( |
---|
401 | Array( |
---|
402 | 'cc_v' => 'contact_view.tpl' |
---|
403 | ) |
---|
404 | ); |
---|
405 | |
---|
406 | if ( isset($params['success'])){ |
---|
407 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg(lang('contact save successfully')); |
---|
408 | } |
---|
409 | |
---|
410 | $this->template->set_block('cc_v','body'); |
---|
411 | $this->template->set_block('cc_v','people'); |
---|
412 | $this->template->set_block('cc_v','people_ldap'); |
---|
413 | $this->template->set_block('cc_v','group'); |
---|
414 | $this->template->set_block('cc_v','group_row'); |
---|
415 | $this->template->set_block('cc_v','buttom'); |
---|
416 | $this->template->set_block('cc_v','buttom_use_contact'); |
---|
417 | $this->template->set_block('cc_v','row_view_operacao'); |
---|
418 | |
---|
419 | $this->template->set_var('title_view_contact',lang("title view contact")); |
---|
420 | $email_to = ""; |
---|
421 | |
---|
422 | switch ($params['catalog']) |
---|
423 | { |
---|
424 | |
---|
425 | case 'bo_shared_people_manager'; |
---|
426 | case 'bo_people_catalog': |
---|
427 | |
---|
428 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
429 | $this->bo->set_catalog($params['catalog']); |
---|
430 | |
---|
431 | $result = $this->bo->bo->get_single_entry($params['id'], array("given_names"=>true,"names_ordered"=>true,"alias"=>true,"family_names"=>true,"companies"=>true,"relations"=>true,"connections"=>true)); |
---|
432 | |
---|
433 | asort($result['connections']); |
---|
434 | |
---|
435 | $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$params['id']); |
---|
436 | $this->template->set_var('id',$params['id']); |
---|
437 | $this->template->set_var('catalog',$params['catalog']); |
---|
438 | |
---|
439 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
440 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
441 | $this->template->set_var('lang_alias',$result['alias']); |
---|
442 | |
---|
443 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
444 | $this->template->set_var('lang_name',$result['given_names']); |
---|
445 | |
---|
446 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
447 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
448 | |
---|
449 | $var_phone = ""; |
---|
450 | $var_email = ""; |
---|
451 | foreach($result['connections'] as $conn): |
---|
452 | if ( $conn['id_type'] == 1 ){ |
---|
453 | if ( !empty($var_email) ) |
---|
454 | $var_email .= ' | '; |
---|
455 | $var_email .= $conn['connection_value']; |
---|
456 | |
---|
457 | if ( empty($email_to) ) |
---|
458 | $email_to = $var_email; |
---|
459 | |
---|
460 | }else if ($conn['id_type'] == 2){ |
---|
461 | if ( !empty($var_phone)) |
---|
462 | $var_phone .= ' | '; |
---|
463 | $var_phone .= $conn['connection_value']; |
---|
464 | } |
---|
465 | |
---|
466 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){ |
---|
467 | if ( $conn['type'] == 'email' ){ |
---|
468 | if ( !empty($var_email) ) |
---|
469 | $var_email .= ' | '; |
---|
470 | $var_email .= $conn['connection_value']; |
---|
471 | |
---|
472 | if ( empty($email_to) ) |
---|
473 | $email_to = $var_email; |
---|
474 | |
---|
475 | }else if ($conn['type'] == 'phone'){ |
---|
476 | if ( !empty($var_phone)) |
---|
477 | $var_phone .= ' | '; |
---|
478 | $var_phone .= $conn['connection_value']; |
---|
479 | } |
---|
480 | } |
---|
481 | endforeach; |
---|
482 | |
---|
483 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
484 | $this->template->set_var('lang_email',$var_email); |
---|
485 | |
---|
486 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
487 | $this->template->set_var('lang_phone',$var_phone); |
---|
488 | |
---|
489 | $this->template->set_var('lang_edit',lang("edit")); |
---|
490 | |
---|
491 | $this->template->parse("row_body","people"); |
---|
492 | |
---|
493 | if ($params['catalog'] == 'bo_people_catalog') |
---|
494 | $this->template->parse("buttom_editar","buttom"); |
---|
495 | |
---|
496 | break; |
---|
497 | |
---|
498 | case 'bo_group_manager': |
---|
499 | |
---|
500 | $this->template->set_var('lang_contact_title',lang("context group")); |
---|
501 | $this->bo->set_catalog($params['catalog']); |
---|
502 | $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true)); |
---|
503 | $data = $this->bo->bo->get_contacts_by_group($params['id']); |
---|
504 | |
---|
505 | $email_to = '<'.$result['short_name'].'>'; |
---|
506 | |
---|
507 | $this->template->set_var('title_view_contact', $result['title']); |
---|
508 | $this->template->set_var('email_to', $email_to); |
---|
509 | |
---|
510 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
511 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
512 | |
---|
513 | foreach($data as $dados){ |
---|
514 | $this->template->set_var('lang_name', $dados['names_ordered']); |
---|
515 | $this->template->set_var('lang_email', $dados['connection_value']); |
---|
516 | $this->template->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul"); |
---|
517 | |
---|
518 | $this->template->set_var('href_details',"ui_mobilecc.contact_view&id=".$dados['id_contact']."&catalog=bo_people_catalog"); |
---|
519 | |
---|
520 | $this->template->fp('group_rows','group_row',True); |
---|
521 | } |
---|
522 | |
---|
523 | $this->template->set_var('email_to', $email_to); |
---|
524 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
525 | |
---|
526 | $this->template->parse("row_body","group"); |
---|
527 | |
---|
528 | break; |
---|
529 | |
---|
530 | default: |
---|
531 | if( strpos($params['catalog'],'bo_global_ldap_catalog#') === false ) |
---|
532 | { |
---|
533 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | $this->bo->set_catalog($params['catalog']); |
---|
538 | $fields = $this->bo->bo->get_fields(true); |
---|
539 | $result = $this->bo->bo->get_single_entry($params['id'], $fields); |
---|
540 | |
---|
541 | // SessionStart |
---|
542 | session_start(); |
---|
543 | $_SESSION['phpgw_info']['mobile']['photoCatalog'][$params['id']] = $result['photo']; |
---|
544 | session_write_close(); |
---|
545 | |
---|
546 | $this->template->set_var('photo', '../index.php?menuaction=mobile.ui_mobilecc.getPhoto&id=' . $params["id"]); |
---|
547 | |
---|
548 | $this->template->set_var('cc_name',$result['names_ordered'][0]); |
---|
549 | |
---|
550 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
551 | $this->template->set_var('lang_name',$result['given_names'][0]); |
---|
552 | |
---|
553 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
554 | $this->template->set_var('lang_lastname',$result['family_names'][0]); |
---|
555 | |
---|
556 | $var_phone = ""; |
---|
557 | $var_email = ""; |
---|
558 | foreach($result['connections'] as $conn) |
---|
559 | { |
---|
560 | if ( $conn['id_type'] == 1 ) |
---|
561 | { |
---|
562 | if ( !empty($var_email) ) |
---|
563 | $var_email .= ' | '; |
---|
564 | |
---|
565 | $var_email .= $conn['connection_value']; |
---|
566 | |
---|
567 | if ( empty($email_to) ) |
---|
568 | $email_to = $var_email; |
---|
569 | } |
---|
570 | else if ($conn['id_type'] == 2) |
---|
571 | { |
---|
572 | if ( !empty($var_phone)) |
---|
573 | $var_phone .= ' | '; |
---|
574 | |
---|
575 | $var_phone .= $conn['connection_value']; |
---|
576 | } |
---|
577 | |
---|
578 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')) |
---|
579 | { |
---|
580 | if ( $conn['type'] == 'email' ) |
---|
581 | { |
---|
582 | if ( !empty($var_email) ) |
---|
583 | $var_email .= ' | '; |
---|
584 | |
---|
585 | $var_email .= $conn['connection_value']; |
---|
586 | |
---|
587 | if ( empty($email_to) ) |
---|
588 | $email_to = $var_email; |
---|
589 | } |
---|
590 | else if ($conn['type'] == 'phone') |
---|
591 | { |
---|
592 | if ( !empty($var_phone) ) |
---|
593 | $var_phone .= ' | '; |
---|
594 | |
---|
595 | $var_phone .= $conn['connection_value']; |
---|
596 | } |
---|
597 | } |
---|
598 | } |
---|
599 | |
---|
600 | $this->template->set_var('email_to', $email_to); |
---|
601 | |
---|
602 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
603 | $this->template->set_var('lang_email',$var_email); |
---|
604 | |
---|
605 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
606 | $this->template->set_var('lang_phone',$var_phone); |
---|
607 | |
---|
608 | $this->template->parse("row_body","people_ldap"); |
---|
609 | |
---|
610 | } |
---|
611 | |
---|
612 | break; |
---|
613 | } |
---|
614 | |
---|
615 | if ( !empty($email_to)) |
---|
616 | { |
---|
617 | $this->template->set_var('email_to', $email_to); |
---|
618 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
619 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
620 | } |
---|
621 | else if ($params['catalog'] == 'bo_people_catalog') |
---|
622 | { |
---|
623 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
624 | } |
---|
625 | |
---|
626 | $linkBack = explode("&", $GLOBALS['phpgw_info']['mobiletemplate']->get_back_link() ); |
---|
627 | $link = $linkBack[0]."&catalog=".$params['catalog']."&".$linkBack[2]; |
---|
628 | |
---|
629 | $this->template->set_var('lang_back',lang("back")); |
---|
630 | |
---|
631 | $this->template->set_var('href_back',$link); |
---|
632 | |
---|
633 | $this->template->set_var('lang_use_contact',lang("use contact")); |
---|
634 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
635 | |
---|
636 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
637 | } |
---|
638 | |
---|
639 | function getPhoto() |
---|
640 | { |
---|
641 | $id = $_GET['id']; |
---|
642 | |
---|
643 | session_start(); |
---|
644 | |
---|
645 | if( isset( $_SESSION['phpgw_info']['mobile']['photoCatalog'][$id] ) ) |
---|
646 | { |
---|
647 | $photo = imagecreatefromstring($_SESSION['phpgw_info']['mobile']['photoCatalog'][$id]); |
---|
648 | |
---|
649 | header("Content-Type: image/jpeg"); |
---|
650 | $width = imagesx($photo); |
---|
651 | $height = imagesy($photo); |
---|
652 | $twidth = 70; |
---|
653 | $theight = 90; |
---|
654 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
655 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
656 | imagejpeg($small_photo,'',100); |
---|
657 | |
---|
658 | unset( $_SESSION['phpgw_info']['mobile']['photoCatalog'][$id] ); |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | header('Content-type: image/png'); |
---|
663 | echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png'); |
---|
664 | } |
---|
665 | |
---|
666 | session_write_close(); |
---|
667 | |
---|
668 | return; |
---|
669 | } |
---|
670 | |
---|
671 | /** |
---|
672 | * View Add/Edit contact |
---|
673 | * |
---|
674 | * @param $id int |
---|
675 | * @param $catalog String |
---|
676 | * @return $contact |
---|
677 | */ |
---|
678 | function contact_add_edit($params) { |
---|
679 | |
---|
680 | $this->template->set_file( |
---|
681 | Array( |
---|
682 | 'cc_e' => 'contact_add_edit.tpl' |
---|
683 | ) |
---|
684 | ); |
---|
685 | |
---|
686 | $this->template->set_block('cc_e','body'); |
---|
687 | |
---|
688 | $view = false; |
---|
689 | if ( isset($params['erro'])){ |
---|
690 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']); |
---|
691 | |
---|
692 | $result['alias'] = $params['alias']; |
---|
693 | $result['given_names'] = $params['given_names']; |
---|
694 | $result['family_names'] = $params['family_names']; |
---|
695 | $result['names_ordered'] = $params['names_ordered']; |
---|
696 | $var_phone = $params['phone']; |
---|
697 | $var_email = $params['email']; |
---|
698 | $var_connection_email = $params['id_connection_email']; |
---|
699 | $var_connection_phone = $params['id_connection_phone']; |
---|
700 | $view = true; |
---|
701 | |
---|
702 | } |
---|
703 | |
---|
704 | if ( empty($params['id']) ){ |
---|
705 | $title_contact = "title add contact"; |
---|
706 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add"; |
---|
707 | $confirm = lang("confirm add"); |
---|
708 | $params['catalog'] = 'bo_people_catalog'; |
---|
709 | }else{ |
---|
710 | $title_contact = "title edit contact"; |
---|
711 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit"; |
---|
712 | $confirm = lang("confirm edit"); |
---|
713 | |
---|
714 | $view = true; |
---|
715 | |
---|
716 | if ( !isset($params['erro'])) |
---|
717 | { |
---|
718 | $this->bo->set_catalog($params['catalog']); |
---|
719 | $result = $this->bo->bo->get_single_entry($params['id'], array("given_names"=>true,"names_ordered"=>true,"alias"=>true,"family_names"=>true,"companies"=>true,"relations"=>true,"connections"=>true)); |
---|
720 | |
---|
721 | $var_phone = ""; |
---|
722 | $var_email = ""; |
---|
723 | foreach($result['connections'] as $conn): |
---|
724 | if ( $conn['id_type'] == 1 ){ |
---|
725 | if ( (empty($var_email)) && ($conn['connection_is_default']) ){ |
---|
726 | $var_email = $conn['connection_value']; |
---|
727 | $var_connection_email = $conn['id_connection']; |
---|
728 | } |
---|
729 | }else if ($conn['id_type'] == 2){ |
---|
730 | if ( (empty($var_phone)) && ($conn['connection_is_default'])){ |
---|
731 | $var_phone = $conn['connection_value']; |
---|
732 | $var_connection_phone = $conn['id_connection']; |
---|
733 | } |
---|
734 | } |
---|
735 | endforeach; |
---|
736 | } |
---|
737 | |
---|
738 | |
---|
739 | } |
---|
740 | |
---|
741 | if ($view){ |
---|
742 | $this->template->set_var('lang_alias',$result['alias']); |
---|
743 | $this->template->set_var('lang_name',$result['given_names']); |
---|
744 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
745 | |
---|
746 | $this->template->set_var('var_connection_email', $var_connection_email); |
---|
747 | $this->template->set_var('lang_email',$var_email); |
---|
748 | |
---|
749 | $this->template->set_var('var_connection_phone', $var_connection_phone); |
---|
750 | $this->template->set_var('lang_phone',$var_phone); |
---|
751 | |
---|
752 | } |
---|
753 | |
---|
754 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
755 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
756 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
757 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
758 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
759 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
760 | |
---|
761 | $this->template->set_var('catalog', $params['catalog']); |
---|
762 | |
---|
763 | $this->template->set_var('lang_title_add_edit',lang($title_contact)); |
---|
764 | $this->template->set_var('form_action', $form_action); |
---|
765 | |
---|
766 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
767 | $this->template->set_var('lang_back',lang("back")); |
---|
768 | $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link()); |
---|
769 | $this->template->set_var('lang_cancel',lang("cancel")); |
---|
770 | $this->template->set_var('lang_confirm', $confirm); |
---|
771 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
772 | $this->template->set_var('id',$params['id']); |
---|
773 | |
---|
774 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
775 | } |
---|
776 | |
---|
777 | /** |
---|
778 | * Add contact |
---|
779 | * |
---|
780 | * @param $id int |
---|
781 | * @param $catalog String |
---|
782 | * @return $contact |
---|
783 | */ |
---|
784 | function contact_add($params) { |
---|
785 | |
---|
786 | $data['alias'] = $params['alias']; |
---|
787 | $data['given_names'] = $params['given_names']; |
---|
788 | $data['family_names'] = $params['family_names']; |
---|
789 | $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names']; |
---|
790 | $data['is_quick_add'] = true; |
---|
791 | |
---|
792 | $answer = $this->verifyData($params); |
---|
793 | |
---|
794 | if (!empty($answer)){ |
---|
795 | $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names']; |
---|
796 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
797 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
798 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
799 | } |
---|
800 | else |
---|
801 | { |
---|
802 | $this->bo->set_catalog($params['catalog']); |
---|
803 | |
---|
804 | if ( !empty($params['email']) ){ |
---|
805 | $data['connections']['default_email']['connection_value'] = $params['email']; |
---|
806 | } |
---|
807 | |
---|
808 | if ( !empty($params['phone']) ){ |
---|
809 | $data['connections']['default_phone']['connection_value'] = $params['phone']; |
---|
810 | } |
---|
811 | $this->bo->set_catalog($params['catalog']); |
---|
812 | $contact_id = $this->bo->bo->quick_add($data); |
---|
813 | |
---|
814 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1'); |
---|
815 | } |
---|
816 | } |
---|
817 | |
---|
818 | /** |
---|
819 | * Edit contact |
---|
820 | * |
---|
821 | * @param $id int |
---|
822 | * @param $catalog String |
---|
823 | * @return $contact |
---|
824 | */ |
---|
825 | function contact_edit($params) { |
---|
826 | |
---|
827 | $data['alias'] = $params['alias']; |
---|
828 | $data['given_names'] = $params['given_names']; |
---|
829 | $data['family_names'] = $params['family_names']; |
---|
830 | $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names']; |
---|
831 | |
---|
832 | $cont = 0; |
---|
833 | |
---|
834 | $answer = $this->verifyData($params); |
---|
835 | |
---|
836 | if (!empty($answer)){ |
---|
837 | $retorno = '&catalog=' . $params['catalog'] . '&id='. $params['id'] .'&alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names']; |
---|
838 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
839 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
840 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
841 | } |
---|
842 | else |
---|
843 | { |
---|
844 | $this->bo->set_catalog($params['catalog']); |
---|
845 | $types = $this->bo->bo->get_all_connections_types(); |
---|
846 | |
---|
847 | if ( !empty($params['email']) || !empty($params['id_connection_email']) ){ |
---|
848 | $cont++; |
---|
849 | |
---|
850 | if (empty($params['id_connection_email'])){ |
---|
851 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
852 | $data['connections']['connection' . $cont]['connection_name'] = $types[1]; |
---|
853 | } |
---|
854 | |
---|
855 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email']; |
---|
856 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 1; |
---|
857 | $data['connections']['connection' . $cont]['connection_value'] = $params['email']; |
---|
858 | |
---|
859 | } |
---|
860 | |
---|
861 | if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){ |
---|
862 | $cont++; |
---|
863 | |
---|
864 | if (empty($params['id_connection_phone'])){ |
---|
865 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
866 | $data['connections']['connection' . $cont]['connection_name'] = $types[2]; |
---|
867 | } |
---|
868 | |
---|
869 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone']; |
---|
870 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 2; |
---|
871 | $data['connections']['connection' . $cont]['connection_value'] = $params['phone']; |
---|
872 | |
---|
873 | } |
---|
874 | |
---|
875 | $contact_id = $this->bo->bo->update_single_info($params['id'], $data); |
---|
876 | |
---|
877 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1'); |
---|
878 | |
---|
879 | } |
---|
880 | |
---|
881 | } |
---|
882 | |
---|
883 | /** |
---|
884 | * Validate data when register contact |
---|
885 | * Validate E-mail, Phone and Name(NotEmpty) |
---|
886 | * |
---|
887 | * @param $data Array |
---|
888 | * @return Boolean |
---|
889 | */ |
---|
890 | static function verifyData($data){ |
---|
891 | |
---|
892 | $valid = ''; |
---|
893 | $field = false; |
---|
894 | |
---|
895 | // Verify if phone is valid |
---|
896 | if ( !empty($data['phone']) && empty($valid) ){ |
---|
897 | |
---|
898 | $field = true; |
---|
899 | |
---|
900 | $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#"; |
---|
901 | |
---|
902 | if (!preg_match($pattern, $data['phone'])){ |
---|
903 | $valid = lang('invalid field phone'); |
---|
904 | } |
---|
905 | |
---|
906 | } |
---|
907 | |
---|
908 | // Verify if e-mail is valid |
---|
909 | if ( !empty($data['email']) ){ |
---|
910 | |
---|
911 | $field = true; |
---|
912 | |
---|
913 | $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$"; |
---|
914 | |
---|
915 | if (!preg_match("/$pattern/i", $data['email'])){ |
---|
916 | $valid = lang('invalid field e-mail'); |
---|
917 | } |
---|
918 | |
---|
919 | } |
---|
920 | |
---|
921 | // Verify if exist e-mail or phone |
---|
922 | if (!$field) |
---|
923 | $valid = lang('Tel or email is required'); |
---|
924 | |
---|
925 | // Verify if name is empty |
---|
926 | if ( empty($data['given_names']) ) |
---|
927 | $valid = lang('Name is mandatory'); |
---|
928 | |
---|
929 | return $valid; |
---|
930 | |
---|
931 | } |
---|
932 | } |
---|
933 | ?> |
---|