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

Revision 3641, 26.5 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1475 - Barra em arquivo de template único

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                        $status = $this->bo->remove_multiple_entries($params['contacts']);
235                       
236                        $type = $this->page_info['actual_catalog']!=='bo_group_manager'?"contacts":"groups";
237                       
238                        if($status['success'])
239                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully"));
240                        else
241                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed"));
242                }
243               
244                static function print_contacts($contacts,$show_checkbox=false,$request_from = null) {
245                        $functions = CreateObject('mobile.common_functions');
246                        $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
247                                        $p->set_file(
248                                                Array(
249                                                        'cc_t' => 'contacts_list.tpl'
250                                                )
251                                        );
252                        $p->set_block('cc_t', 'rows_contacts');
253                        $p->set_block('cc_t', 'row_contacts');
254                        $p->set_block('cc_t', 'row_groups');
255                        $p->set_block('cc_t', 'no_contacts');
256
257                        $bg = "par";
258                        if(!empty($contacts)) {
259                                foreach($contacts as $id => $contact) {
260
261                                        $p->set_var('show_check',$show_checkbox?"inline":"none");
262                                        $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");
263                                                                               
264                                        if($contact["catalog"]!=="bo_group_manager") {  //Contatos             
265                                                $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id;
266
267                        $mail = '&nbsp;'; $tel = '&nbsp;';
268                        foreach($contact['connections'] as $key => $conn) {
269
270                            $test = false;
271                            if ($conn['connection_is_default']) {
272                                $test = true;
273                            }
274                           
275                            if (is_array($conn)){
276                                $test = true;
277                            }
278                           
279                            if ( $test) {
280                                if ( ($conn['id_type'] == 1) )
281                                    $mail = $conn['connection_value'];
282                                else if ( ($conn['id_type'] == 2) )
283                                    $tel = $conn['connection_value'];
284                            }
285                                                }
286
287                                               
288                        $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"];
289                        $vtel = ($tel==null || $tel=='&nbsp;')?"none":"inline";
290                                               
291                                                if(($mail=='&nbsp;' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre.
292                                                        continue;
293
294                                                $p->set_var('show_tel',$vtel);
295                                                $p->set_var('email',$mail);
296                                                $p->set_var('tel',$tel);
297                                                $p->set_var('contact_id',$id);
298                                                $p->set_var('lang_tel',lang("tel"));
299                                                $p->set_var('contact_name',$functions->strach_string($cn,17));
300
301                                                $block = "row_contacts";
302                                        }
303                                        else { //Grupos
304                                                $id=$contact["id_group"];
305                                                $mail = $cn = $contact["title"];
306                                                $p->set_var('group_id',$contact["id_group"]);
307                                                $p->set_var('group_name',$contact["title"]);
308                                                $block = "row_groups";
309                                        }
310                                       
311                                        if($request_from==null) {
312                                                $p->set_var('lang_see_details',strtoupper(lang("see details")));
313                                                $cat_encode = urlencode($contact["catalog"]);
314                                                $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"]));
315                                        }
316                                        else {
317                                                $p->set_var('lang_see_details',strtoupper(lang("select")));
318                                                $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn");
319                                        }
320                                       
321                                        $p->fp('rows',$block,True);
322
323                                }
324                               
325                        }
326                        else {
327                                $p->set_var("lang_no_results",lang("no results found"));
328                                $p->parse("rows","no_contacts");
329                        }
330                        return $p->fp('out','rows_contacts');
331                }
332
333                /**
334                 * Show details from contact selected
335                 *
336                 * @param $id int
337                 * @param $catalog String
338                 * @return $contact
339                 */
340                function contact_view($params) {
341
342                        if ( empty($params['id']) || empty($params['catalog']) ){
343                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc');
344                        }
345                       
346                        $this->template->set_file(
347                                Array(
348                                        'cc_v' => 'contact_view.tpl'
349                                )
350                        );
351
352                        if ( isset($params['success'])){
353                                $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg(lang('contact save successfully'));
354                        }
355
356                        $this->template->set_block('cc_v','body');
357                        $this->template->set_block('cc_v','people');
358                        $this->template->set_block('cc_v','people_ldap');
359                        $this->template->set_block('cc_v','group');
360                        $this->template->set_block('cc_v','group_row');
361                        $this->template->set_block('cc_v','buttom');
362                        $this->template->set_block('cc_v','buttom_use_contact');
363
364                        switch ($params['catalog']){
365
366                                case 'bo_shared_people_manager';
367                                case 'bo_people_catalog':
368
369                                                                $this->bo->set_catalog($params['catalog']);
370
371                                                                $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));
372
373                                                                asort($result['connections']);
374
375                                                                $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id);
376                                                                $this->template->set_var('id',$params['id']);
377                                                                $this->template->set_var('catalog',$params['catalog']);
378                                       
379                                                                $this->template->set_var('cc_name',$result['names_ordered']);
380                                                                $this->template->set_var('lang_title_alias',lang("Alias"));
381                                                                $this->template->set_var('lang_alias',$result['alias']);
382                                                               
383                                                                $this->template->set_var('lang_title_name',lang("Name"));
384                                                                $this->template->set_var('lang_name',$result['given_names']);
385                                                               
386                                                                $this->template->set_var('lang_title_lastname',lang("Family Names"));
387                                                                $this->template->set_var('lang_lastname',$result['family_names']);
388                                                               
389                                                                $email_to = "";
390                                                                $var_phone = "";
391                                                                $var_email = "";
392                                                                foreach($result['connections'] as $conn):
393                                                                        if ( $conn['id_type'] == 1 ){
394                                                                                if ( !empty($var_email) )
395                                                                                        $var_email .= ' | ';
396                                                                                $var_email .= $conn['connection_value'];
397                                                                               
398                                                                                if ( empty($email_to) )
399                                                                                        $email_to = $var_email;
400                                                                               
401                                                                        }else if ($conn['id_type'] == 2){
402                                                                                if ( !empty($var_phone))
403                                                                                        $var_phone .= ' | ';
404                                                                                $var_phone .= $conn['connection_value'];
405                                                                        }
406                                                                endforeach;
407                                                               
408                                                                if ( !empty($email_to)){
409                                                                        $this->template->set_var('email_to', $email_to);
410                                                                        $this->template->parse("buttom_use","buttom_use_contact");
411                                                                }
412                                                               
413                                                                $this->template->set_var('lang_title_email',lang("Email"));
414                                                                $this->template->set_var('lang_email',$var_email);
415                                                               
416                                                                $this->template->set_var('lang_title_phone',lang("Phone"));
417                                                                $this->template->set_var('lang_phone',$var_phone);
418                               
419                                                                $this->template->set_var('lang_edit',lang("edit"));
420                                                               
421                                                                $this->template->parse("row_body","people");
422                                                               
423                                                                if ($params['catalog'] == 'bo_people_catalog')
424                                                                        $this->template->parse("buttom_editar","buttom");
425                                                                       
426                                                        break;
427                                                       
428                                case 'bo_group_manager':
429
430                                                                $this->bo->set_catalog($params['catalog']);
431                                                                $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true));
432                                                                $data   = $this->bo->bo->get_contacts_by_group($params['id']);
433                                                               
434                                                                $this->template->set_var('gr_name', $result['title']);
435                                                                $this->template->set_var('email_to', '<'.$result['short_name'].'>');
436
437                                                                $this->template->set_var('lang_title_name',lang("Name"));
438                                                                $this->template->set_var('lang_title_email',lang("Email"));
439                                                               
440                                                                foreach($data as $dados){
441                                                                        $this->template->set_var('lang_name', $dados['names_ordered']);
442                                                                        $this->template->set_var('lang_email', $dados['connection_value']);
443                                                                       
444                                                                        $this->template->fp('group_rows','group_row',True);
445                                                                }
446                                                               
447                                                                $this->template->parse("row_body","group");
448                                                        break;
449                                               
450                                default:               
451
452                                                                if(strpos($params['catalog'],'bo_global_ldap_catalog')==false){
453
454                                                                        $this->bo->set_catalog($params['catalog']);
455
456                                                                        $fields = $this->bo->bo->get_fields(true);
457                                                                        $result = $this->bo->bo->get_single_entry($params['id'], $fields);
458
459                                                                        $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id);
460
461                                                                        $this->template->set_var('cc_name',$result['names_ordered'][0]);
462
463                                                                        $this->template->set_var('lang_title_name',lang("Name"));
464                                                                        $this->template->set_var('lang_name',$result['given_names'][0]);
465                                                                       
466                                                                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
467                                                                        $this->template->set_var('lang_lastname',$result['family_names'][0]);
468                                                                       
469                                                                        $email_to = "";
470                                                                        $var_phone = "";
471                                                                        $var_email = "";
472                                                                        foreach($result['connections'] as $conn):
473                                                                                if ( $conn['id_type'] == 1 ){
474                                                                                        if ( !empty($var_email) )
475                                                                                                $var_email .= ' | ';
476                                                                                        $var_email .= $conn['connection_value'];
477                                                                                       
478                                                                                        if ( empty($email_to) )
479                                                                                                $email_to = $var_email;
480                                                                                       
481                                                                                }else if ($conn['id_type'] == 2){
482                                                                                        if ( !empty($var_phone))
483                                                                                                $var_phone .= ' | ';
484                                                                                        $var_phone .= $conn['connection_value'];
485                                                                                }
486                                                                        endforeach;
487                                               
488                                                                        $this->template->set_var('email_to', $email_to);
489                                                                       
490                                                                        $this->template->set_var('lang_title_email',lang("Email"));
491                                                                        $this->template->set_var('lang_email',$var_email);
492                                                                       
493                                                                        $this->template->set_var('lang_title_phone',lang("Phone"));
494                                                                        $this->template->set_var('lang_phone',$var_phone);
495
496                                                                        $this->template->parse("row_body","people_ldap");
497
498                                                                }else{
499                                                                        header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc');
500                                                                }
501
502                                                        break;
503                        }
504
505                        $this->template->set_var('lang_contact_title',lang("context contact"));
506                        $this->template->set_var('lang_back',lang("back"));
507                        $this->template->set_var('lang_use_contact',lang("use contact"));
508                        $this->template->set_var('lang_selecteds',lang("selecteds"));
509
510                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
511                }
512
513                /**
514                 * View Add/Edit contact
515                 *
516                 * @param $id int
517                 * @param $catalog String
518                 * @return $contact
519                 */
520                function contact_add_edit($params) {
521
522                        $this->template->set_file(
523                                Array(
524                                        'cc_e' => 'contact_add_edit.tpl'
525                                )
526                        );
527
528                        $this->template->set_block('cc_e','body');
529
530                        $view = false;
531                        if ( isset($params['erro'])){
532                                $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']);
533                               
534                                $result['alias']                        = $params['alias'];
535                                $result['given_names']          = $params['given_names'];
536                                $result['family_names']         = $params['family_names'];
537                                $result['names_ordered']        = $params['names_ordered'];
538                                $var_phone                                      = $params['phone'];
539                                $var_email                                      = $params['email'];
540                                $var_connection_email           = $params['id_connection_email'];
541                                $var_connection_phone           = $params['id_connection_phone'];
542                                $view = true;
543                               
544                        }
545
546                        if ( empty($params['id']) ){
547                                $title_contact = "title add contact";
548                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add";
549                                $confirm = lang("confirm add");
550                                $params['catalog'] = 'bo_people_catalog';
551                        }else{
552                                $title_contact = "title edit contact";
553                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit";
554                                $confirm = lang("confirm edit");
555                               
556                                $view = true;
557
558                                if ( !isset($params['erro'])){
559                                        $this->bo->set_catalog($params['catalog']);
560                                        $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));
561
562                                        $var_phone = "";
563                                        $var_email = "";
564                                        foreach($result['connections'] as $conn):
565                                                if ( $conn['id_type'] == 1 ){
566                                                        if ( (empty($var_email)) && ($conn['connection_is_default']) ){
567                                                                $var_email = $conn['connection_value'];
568                                                                $var_connection_email = $conn['id_connection'];
569                                                        }
570                                                }else if ($conn['id_type'] == 2){
571                                                        if ( (empty($var_phone)) &&  ($conn['connection_is_default'])){
572                                                                $var_phone = $conn['connection_value'];
573                                                                $var_connection_phone = $conn['id_connection'];
574                                                        }
575                                                }
576                                        endforeach;
577                                }
578
579                                                               
580                        }
581                       
582                        if ($view){
583                                        $this->template->set_var('lang_alias',$result['alias']);
584                                        $this->template->set_var('lang_name',$result['given_names']);
585                                        $this->template->set_var('lang_lastname',$result['family_names']);
586                                       
587                                        $this->template->set_var('var_connection_email', $var_connection_email);
588                                        $this->template->set_var('lang_email',$var_email);
589                                       
590                                        $this->template->set_var('var_connection_phone', $var_connection_phone);
591                                        $this->template->set_var('lang_phone',$var_phone);
592
593                        }
594                       
595                        $this->template->set_var('cc_name',$result['names_ordered']);
596                        $this->template->set_var('lang_title_alias',lang("Alias"));
597                        $this->template->set_var('lang_title_name',lang("Name"));
598                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
599                        $this->template->set_var('lang_title_email',lang("Email"));
600                        $this->template->set_var('lang_title_phone',lang("Phone"));
601
602                        $this->template->set_var('catalog', $params['catalog']);
603                               
604                        $this->template->set_var('lang_title_add_edit',lang($title_contact));
605                        $this->template->set_var('form_action', $form_action);
606                       
607                        $this->template->set_var('lang_contact_title',lang("context contact"));
608                        $this->template->set_var('lang_back',lang("back"));
609                        $this->template->set_var('lang_cancel',lang("cancel"));
610                        $this->template->set_var('lang_confirm', $confirm);
611                        $this->template->set_var('lang_selecteds',lang("selecteds"));
612                        $this->template->set_var('id',$params['id']);
613                       
614                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
615                }
616               
617                /**
618                 * Add contact
619                 *
620                 * @param $id int
621                 * @param $catalog String
622                 * @return $contact
623                 */
624                function contact_add($params) {
625                       
626                        $data['alias'] = $params['alias'];
627                        $data['given_names'] = $params['given_names'];
628                        $data['family_names'] = $params['family_names'];
629                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
630                        $data['is_quick_add'] = true;
631
632                        $answer = $this->verifyData($params);
633                       
634                        if (!empty($answer)){
635                                $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names'];
636                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
637                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
638                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
639                        }
640                        else
641                        {
642                                $this->bo->set_catalog($params['catalog']);
643       
644                                if ( !empty($params['email']) ){
645                                        $data['connections']['default_email']['connection_value'] = $params['email'];
646                                }
647                               
648                                if ( !empty($params['phone']) ){
649                                        $data['connections']['default_phone']['connection_value'] = $params['phone'];
650                                }
651       
652                                $this->bo->set_catalog($params['catalog']);
653                                $contact_id = $this->bo->bo->quick_add($data);
654       
655                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1');
656                        }
657                }
658
659                /**
660                 * Edit contact
661                 *
662                 * @param $id int
663                 * @param $catalog String
664                 * @return $contact
665                 */
666                function contact_edit($params) {
667                       
668                        $data['alias'] = $params['alias'];
669                        $data['given_names'] = $params['given_names'];
670                        $data['family_names'] = $params['family_names'];
671                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
672                       
673                        $cont = 0;
674
675                        $answer = $this->verifyData($params);
676
677                        if (!empty($answer)){
678                                $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'];
679                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
680                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
681                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
682                        }
683                        else
684                        {
685
686                                $this->bo->set_catalog($params['catalog']);
687                                $types = $this->bo->bo->get_all_connections_types();
688       
689                                if ( !empty($params['email']) || !empty($params['id_connection_email']) ){
690                                        $cont++;
691                               
692                                        if (empty($params['id_connection_email'])){
693                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
694                                                $data['connections']['connection' . $cont]['connection_name'] = $types[1];
695                                        }
696       
697                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email'];
698                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 1;
699                                        $data['connections']['connection' . $cont]['connection_value'] = $params['email'];
700       
701                                }
702       
703                                if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){
704                                        $cont++;
705       
706                                        if (empty($params['id_connection_phone'])){
707                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
708                                                $data['connections']['connection' . $cont]['connection_name'] = $types[2];
709                                        }
710       
711                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone'];
712                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 2;
713                                        $data['connections']['connection' . $cont]['connection_value'] = $params['phone'];
714       
715                                }
716       
717                                $contact_id = $this->bo->bo->update_single_info($params['id'], $data);
718
719                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1');
720                               
721                        }
722                       
723                }
724
725                /**
726                 * Validate data when register contact
727                 * Validate E-mail, Phone and Name(NotEmpty)
728                 *
729                 * @param $data Array
730                 * @return Boolean
731                 */
732                static function verifyData($data){
733
734                        $valid = '';
735                        $field = false;
736
737                        // Verify if phone is valid
738                        if ( !empty($data['phone']) && empty($valid) ){
739                               
740                                $field = true;
741                               
742                                $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#";
743
744                                if (!preg_match($pattern, $data['phone'])){
745                                        $valid = lang('invalid field phone');
746                                }
747
748                        }
749
750                        // Verify if e-mail is valid
751                        if ( !empty($data['email']) ){
752
753                                $field = true;
754                               
755                                $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$";
756
757                                if (!eregi($pattern, $data['email'])){
758                                        $valid = lang('invalid field e-mail');
759                                }
760
761                        }
762
763                        // Verify if exist e-mail or phone
764                        if (!$field)
765                                $valid = lang('Tel or email is required');
766                       
767                        // Verify if name is empty
768                        if ( empty($data['given_names']) )
769                                $valid = lang('Name is mandatory');
770                       
771                        return $valid;
772                       
773                }
774
775               
776        }
777       
778       
779?>
Note: See TracBrowser for help on using the repository browser.