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

Revision 3700, 27.4 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1413 - Mobile - Ajuste da tela com o novo layout.

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