source: branches/2.2.0.1/mobile/inc/class.ui_mobilecc.inc.php @ 3974

Revision 3974, 29.5 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Visualizacao do Mobile. Tickets #1730, #1728, #1733, #1734

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