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

Revision 4762, 31.8 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2127 - Corrigido erro quando o link de voltar é clicado

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