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

Revision 5063, 31.1 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2265 - Implementado um checkbox para permitir o salvamento da senha em dispositivos móveis

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