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

Revision 3710, 27.6 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1412 - Ajustes finais no layout da tela de contatos

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