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

Revision 3822, 28.2 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1589 - Erro na listagem dos contatos telefone e email não listados

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