source: branches/2.2/mobile/inc/class.ui_mobilecc.inc.php @ 3821

Revision 3821, 28.0 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1590 - Corrigido visualização do checkbox na listagem de contatos do expresso mini.

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