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

Revision 3820, 27.8 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1591 - Corrigido visualização do botão adicionar contatos do expresso mini.

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