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

Revision 3811, 27.7 KB checked in by diegomoreno, 13 years ago (diff)

Ticket #1585 - Mobile - Ajuste para exibir a foto do contato na visualizacao.

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