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

Revision 3825, 29.2 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1621 - Erro na visualização 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) || ($conn['id_type'] == '_NONE_')){
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
441                                                                        if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){
442                                                                                if ( $conn['type'] == 'email' ){
443                                                                                        if ( !empty($var_email) )
444                                                                                                $var_email .= ' | ';
445                                                                                        $var_email .= $conn['connection_value'];
446                                                                                       
447                                                                                        if ( empty($email_to) )
448                                                                                                $email_to = $var_email;
449                                                                                       
450                                                                                }else if ($conn['type'] == 'phone'){
451                                                                                        if ( !empty($var_phone))
452                                                                                                $var_phone .= ' | ';
453                                                                                        $var_phone .= $conn['connection_value'];
454                                                                                }
455                                                                        }
456                                                                endforeach;
457                                                               
458                                                                $this->template->set_var('lang_title_email',lang("Email"));
459                                                                $this->template->set_var('lang_email',$var_email);
460                                                               
461                                                                $this->template->set_var('lang_title_phone',lang("Phone"));
462                                                                $this->template->set_var('lang_phone',$var_phone);
463                               
464                                                                $this->template->set_var('lang_edit',lang("edit"));
465                                                               
466                                                                $this->template->parse("row_body","people");
467                                                               
468                                                                if ($params['catalog'] == 'bo_people_catalog')
469                                                                        $this->template->parse("buttom_editar","buttom");
470                                                                       
471                                                        break;
472                                                       
473                                case 'bo_group_manager':
474                                                                $this->template->set_var('lang_contact_title',lang("context group"));
475                                                                $this->bo->set_catalog($params['catalog']);
476                                                                $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true));
477                                                                $data   = $this->bo->bo->get_contacts_by_group($params['id']);
478
479                                                                $email_to = '<'.$result['short_name'].'>';
480                                                               
481                                                                $this->template->set_var('title_view_contact', $result['title']);
482                                                                $this->template->set_var('email_to', $email_to);
483
484                                                                $this->template->set_var('lang_title_name',lang("Name"));
485                                                                $this->template->set_var('lang_title_email',lang("Email"));
486                                                               
487                                                                foreach($data as $dados){
488                                                                        $this->template->set_var('lang_name', $dados['names_ordered']);
489                                                                        $this->template->set_var('lang_email', $dados['connection_value']);
490                                                                        $this->template->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul");
491                                                                       
492                                                                        $this->template->set_var('href_details',"ui_mobilecc.contact_view&id=".$dados['id_contact']."&catalog=bo_people_catalog");
493                                                                       
494                                                                        $this->template->fp('group_rows','group_row',True);
495                                                                }
496
497                                                                $this->template->set_var('email_to', $email_to);
498                                                                $this->template->parse("buttom_use","buttom_use_contact");
499                                                               
500                                                                $this->template->parse("row_body","group");
501                                                        break;
502                                               
503                                default:               
504
505                                                                if(strpos($params['catalog'],'bo_global_ldap_catalog')==false){
506
507                                                                        $this->bo->set_catalog($params['catalog']);
508
509                                                                        $fields = $this->bo->bo->get_fields(true);
510                                                                        $result = $this->bo->bo->get_single_entry($params['id'], $fields);
511
512                                                                        $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id);
513
514                                                                        $this->template->set_var('cc_name',$result['names_ordered'][0]);
515
516                                                                        $this->template->set_var('lang_title_name',lang("Name"));
517                                                                        $this->template->set_var('lang_name',$result['given_names'][0]);
518                                                                       
519                                                                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
520                                                                        $this->template->set_var('lang_lastname',$result['family_names'][0]);
521                                                                       
522                                                                        $var_phone = "";
523                                                                        $var_email = "";
524                                                                        foreach($result['connections'] as $conn):
525                                                                                if ( $conn['id_type'] == 1 ){
526                                                                                        if ( !empty($var_email) )
527                                                                                                $var_email .= ' | ';
528                                                                                        $var_email .= $conn['connection_value'];
529                                                                                       
530                                                                                        if ( empty($email_to) )
531                                                                                                $email_to = $var_email;
532                                                                                       
533                                                                                }else if ($conn['id_type'] == 2){
534                                                                                        if ( !empty($var_phone))
535                                                                                                $var_phone .= ' | ';
536                                                                                        $var_phone .= $conn['connection_value'];
537                                                                                }
538
539                                                                                if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){
540                                                                                        if ( $conn['type'] == 'email' ){
541                                                                                                if ( !empty($var_email) )
542                                                                                                        $var_email .= ' | ';
543                                                                                                $var_email .= $conn['connection_value'];
544                                                                                               
545                                                                                                if ( empty($email_to) )
546                                                                                                        $email_to = $var_email;
547                                                                                               
548                                                                                        }else if ($conn['type'] == 'phone'){
549                                                                                                if ( !empty($var_phone))
550                                                                                                        $var_phone .= ' | ';
551                                                                                                $var_phone .= $conn['connection_value'];
552                                                                                        }
553                                                                                }
554                                                                        endforeach;
555                                               
556                                                                        $this->template->set_var('email_to', $email_to);
557                                                                       
558                                                                        $this->template->set_var('lang_title_email',lang("Email"));
559                                                                        $this->template->set_var('lang_email',$var_email);
560                                                                       
561                                                                        $this->template->set_var('lang_title_phone',lang("Phone"));
562                                                                        $this->template->set_var('lang_phone',$var_phone);
563
564                                                                        $this->template->parse("row_body","people_ldap");
565
566                                                                }else{
567                                                                        header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc');
568                                                                }
569
570                                                        break;
571                        }
572
573                        if ( !empty($email_to)){
574                                $this->template->set_var('email_to', $email_to);
575                                $this->template->parse("buttom_use","buttom_use_contact");
576                                $this->template->parse("row_operacao","row_view_operacao");
577                        }else if ($params['catalog'] == 'bo_people_catalog'){
578                                $this->template->parse("row_operacao","row_view_operacao");
579                        }
580
581                        $this->template->set_var('lang_back',lang("back"));
582                        $this->template->set_var('lang_use_contact',lang("use contact"));
583                        $this->template->set_var('lang_selecteds',lang("selecteds"));
584
585                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
586                }
587
588                /**
589                 * View Add/Edit contact
590                 *
591                 * @param $id int
592                 * @param $catalog String
593                 * @return $contact
594                 */
595                function contact_add_edit($params) {
596
597                        $this->template->set_file(
598                                Array(
599                                        'cc_e' => 'contact_add_edit.tpl'
600                                )
601                        );
602
603                        $this->template->set_block('cc_e','body');
604
605                        $view = false;
606                        if ( isset($params['erro'])){
607                                $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']);
608                               
609                                $result['alias']                        = $params['alias'];
610                                $result['given_names']          = $params['given_names'];
611                                $result['family_names']         = $params['family_names'];
612                                $result['names_ordered']        = $params['names_ordered'];
613                                $var_phone                                      = $params['phone'];
614                                $var_email                                      = $params['email'];
615                                $var_connection_email           = $params['id_connection_email'];
616                                $var_connection_phone           = $params['id_connection_phone'];
617                                $view = true;
618                               
619                        }
620
621                        if ( empty($params['id']) ){
622                                $title_contact = "title add contact";
623                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add";
624                                $confirm = lang("confirm add");
625                                $params['catalog'] = 'bo_people_catalog';
626                        }else{
627                                $title_contact = "title edit contact";
628                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit";
629                                $confirm = lang("confirm edit");
630                               
631                                $view = true;
632
633                                if ( !isset($params['erro'])){
634                                        $this->bo->set_catalog($params['catalog']);
635                                        $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));
636
637                                        $var_phone = "";
638                                        $var_email = "";
639                                        foreach($result['connections'] as $conn):
640                                                if ( $conn['id_type'] == 1 ){
641                                                        if ( (empty($var_email)) && ($conn['connection_is_default']) ){
642                                                                $var_email = $conn['connection_value'];
643                                                                $var_connection_email = $conn['id_connection'];
644                                                        }
645                                                }else if ($conn['id_type'] == 2){
646                                                        if ( (empty($var_phone)) &&  ($conn['connection_is_default'])){
647                                                                $var_phone = $conn['connection_value'];
648                                                                $var_connection_phone = $conn['id_connection'];
649                                                        }
650                                                }
651                                        endforeach;
652                                }
653
654                                                               
655                        }
656                       
657                        if ($view){
658                                        $this->template->set_var('lang_alias',$result['alias']);
659                                        $this->template->set_var('lang_name',$result['given_names']);
660                                        $this->template->set_var('lang_lastname',$result['family_names']);
661                                       
662                                        $this->template->set_var('var_connection_email', $var_connection_email);
663                                        $this->template->set_var('lang_email',$var_email);
664                                       
665                                        $this->template->set_var('var_connection_phone', $var_connection_phone);
666                                        $this->template->set_var('lang_phone',$var_phone);
667
668                        }
669                       
670                        $this->template->set_var('cc_name',$result['names_ordered']);
671                        $this->template->set_var('lang_title_alias',lang("Alias"));
672                        $this->template->set_var('lang_title_name',lang("Name"));
673                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
674                        $this->template->set_var('lang_title_email',lang("Email"));
675                        $this->template->set_var('lang_title_phone',lang("Phone"));
676
677                        $this->template->set_var('catalog', $params['catalog']);
678                               
679                        $this->template->set_var('lang_title_add_edit',lang($title_contact));
680                        $this->template->set_var('form_action', $form_action);
681                       
682                        $this->template->set_var('lang_contact_title',lang("context contact"));
683                        $this->template->set_var('lang_back',lang("back"));
684                        $this->template->set_var('lang_cancel',lang("cancel"));
685                        $this->template->set_var('lang_confirm', $confirm);
686                        $this->template->set_var('lang_selecteds',lang("selecteds"));
687                        $this->template->set_var('id',$params['id']);
688                       
689                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
690                }
691               
692                /**
693                 * Add contact
694                 *
695                 * @param $id int
696                 * @param $catalog String
697                 * @return $contact
698                 */
699                function contact_add($params) {
700                       
701                        $data['alias'] = $params['alias'];
702                        $data['given_names'] = $params['given_names'];
703                        $data['family_names'] = $params['family_names'];
704                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
705                        $data['is_quick_add'] = true;
706
707                        $answer = $this->verifyData($params);
708                       
709                        if (!empty($answer)){
710                                $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names'];
711                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
712                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
713                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
714                        }
715                        else
716                        {
717                                $this->bo->set_catalog($params['catalog']);
718       
719                                if ( !empty($params['email']) ){
720                                        $data['connections']['default_email']['connection_value'] = $params['email'];
721                                }
722                               
723                                if ( !empty($params['phone']) ){
724                                        $data['connections']['default_phone']['connection_value'] = $params['phone'];
725                                }
726       
727                                $this->bo->set_catalog($params['catalog']);
728                                $contact_id = $this->bo->bo->quick_add($data);
729       
730                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1');
731                        }
732                }
733
734                /**
735                 * Edit contact
736                 *
737                 * @param $id int
738                 * @param $catalog String
739                 * @return $contact
740                 */
741                function contact_edit($params) {
742                       
743                        $data['alias'] = $params['alias'];
744                        $data['given_names'] = $params['given_names'];
745                        $data['family_names'] = $params['family_names'];
746                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
747                       
748                        $cont = 0;
749
750                        $answer = $this->verifyData($params);
751
752                        if (!empty($answer)){
753                                $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'];
754                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
755                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
756                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
757                        }
758                        else
759                        {
760
761                                $this->bo->set_catalog($params['catalog']);
762                                $types = $this->bo->bo->get_all_connections_types();
763       
764                                if ( !empty($params['email']) || !empty($params['id_connection_email']) ){
765                                        $cont++;
766                               
767                                        if (empty($params['id_connection_email'])){
768                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
769                                                $data['connections']['connection' . $cont]['connection_name'] = $types[1];
770                                        }
771       
772                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email'];
773                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 1;
774                                        $data['connections']['connection' . $cont]['connection_value'] = $params['email'];
775       
776                                }
777       
778                                if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){
779                                        $cont++;
780       
781                                        if (empty($params['id_connection_phone'])){
782                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
783                                                $data['connections']['connection' . $cont]['connection_name'] = $types[2];
784                                        }
785       
786                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone'];
787                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 2;
788                                        $data['connections']['connection' . $cont]['connection_value'] = $params['phone'];
789       
790                                }
791       
792                                $contact_id = $this->bo->bo->update_single_info($params['id'], $data);
793
794                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1');
795                               
796                        }
797                       
798                }
799
800                /**
801                 * Validate data when register contact
802                 * Validate E-mail, Phone and Name(NotEmpty)
803                 *
804                 * @param $data Array
805                 * @return Boolean
806                 */
807                static function verifyData($data){
808
809                        $valid = '';
810                        $field = false;
811
812                        // Verify if phone is valid
813                        if ( !empty($data['phone']) && empty($valid) ){
814                               
815                                $field = true;
816                               
817                                $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#";
818
819                                if (!preg_match($pattern, $data['phone'])){
820                                        $valid = lang('invalid field phone');
821                                }
822
823                        }
824
825                        // Verify if e-mail is valid
826                        if ( !empty($data['email']) ){
827
828                                $field = true;
829                               
830                                $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$";
831
832                                if (!eregi($pattern, $data['email'])){
833                                        $valid = lang('invalid field e-mail');
834                                }
835
836                        }
837
838                        // Verify if exist e-mail or phone
839                        if (!$field)
840                                $valid = lang('Tel or email is required');
841                       
842                        // Verify if name is empty
843                        if ( empty($data['given_names']) )
844                                $valid = lang('Name is mandatory');
845                       
846                        return $valid;
847                       
848                }
849
850               
851        }
852       
853       
854?>
Note: See TracBrowser for help on using the repository browser.