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

Revision 3657, 27.0 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1412 - Ajuste no tipo de mensagem ao remover contato não selecionado

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