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

Revision 4628, 31.7 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1728 - Correção para foto do contato que não está aparecendo

Line 
1<?php
2        class ui_mobilecc{
3               
4                var $nextmatchs;
5                var $bo;
6                var $page_info = array (
7                                'actual_catalog' => false,
8                                'actual_letter' => null,
9                                'actual_max_contacts' => null,
10                                'request_from' => null
11                        );
12               
13                var $public_functions = array(
14                        'index' => true,
15                        'change_max_results' => true,
16                        'change_catalog' => true,
17                        'delete_contacts' => true,
18                        'change_letter' => true,
19                        'choose_contact' => true,
20                        'init_cc' => true,
21                        'contact_view' => true,
22                        'contact_add_edit' => true,
23                        'contact_add' => true,
24                        'contact_edit' => true,
25                        'getPhoto'  => true
26                );
27                var $template;
28               
29                /**
30                 * Construtor...
31                 *
32                 */
33                public function ui_mobilecc() {
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
47                }
48               
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
81                        if( $params['catalog'] ) $this->page_info['actual_catalog'] = $params['catalog'];
82                        $this->page_info['actual_max_contacts'] = 10;
83                        $this->page_info['actual_letter'] = 'a';
84                       
85                        $this->contacts_list($params);
86                       
87                        $this->save_session();
88                }
89               
90                /**
91                 * Função de inicio do módulo para escolha de um contato para outro módulo.
92                 *
93                 * @return
94                 * @param $params Object
95                 */
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();
101                }
102               
103                /**
104                 * Função de inicio do módulo de cc
105                 *
106                 * @return
107                 * @param $params Object
108                 */
109                public function init_cc($params) {
110                        $this->set_page_info_to_default();
111                        $this->contacts_list($params);
112                        $this->save_session();
113                }
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               
122                function contacts_list($params) {
123                       
124                        $this->template->set_file(
125                                Array(
126                                        'contacts_list' => 'cc_main.tpl',
127                                        'home_search_bar' => 'search_bar.tpl'
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");
133                        $this->template->set_block('home_search_bar','search_bar');
134
135                        //Langs gerais da página
136                        $this->template->set_var("lang_back",lang("back"));
137                        $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
138                        $this->template->set_var("selecteds",ucfirst(lang("selecteds")));
139                        $this->template->set_var("lang_more",lang("more"));
140                        $this->template->set_var("lang_search",lang("search"));
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);
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
153                        $this->template->set_var("show_add_button",$this->page_info["actual_catalog"] == "bo_group_manager" ? "none" : "");
154                       
155                        $this->template->set_var("contacts_request_from",
156                                                                                $this->page_info["request_from"]==null?
157                                                                                "none":$this->page_info["request_from"]);
158                       
159                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile')!="mini_desktop")
160                                $this->template->set_var('search',$this->template->fp('out','search_bar'));
161                       
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");
169                                else
170                                        $this->template->set_var("selected"," ");
171                                $this->template->fp("catalogs","catalog_row",true);
172                        }
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                               
177                       
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");
188                        }
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");
196                                }
197                        else { //Letras do meio
198                                $this->template->set_var('show_back','inline');
199                                $this->template->set_var('show_next','inline');
200                               
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++;
209                        }
210                       
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");
217                                        else
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++;
222                        }
223                       
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                                               
231                        $this->template->set_var("contacts",$this->print_contacts($contacts,$show_checkbox,$this->page_info['request_from']));
232                       
233
234                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body'));
235                }
236               
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']);
247
248                        if (!is_array($params['contacts']) ){
249                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("please select one contact"));
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                        }
261                }
262               
263                static function print_contacts($contacts,$show_checkbox=false,$request_from = null) {
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');
273                        $p->set_block('cc_t', 'row_groups');
274                        $p->set_block('cc_t', 'no_contacts');
275
276                        $bg = "bg-azul";
277                        if(!empty($contacts)) {
278                                foreach($contacts as $id => $contact) {
279
280                                        $p->set_var('show_check',$show_checkbox?"inline":"none");
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");       
286                                        if($contact["catalog"]!=="bo_group_manager") {  //Contatos             
287                                                $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id;
288
289                        $mail = '&nbsp;'; $tel = '&nbsp;';
290                        foreach($contact['connections'] as $key => $conn) {
291
292                            $test = false;
293                                                        if ($conn['connection_is_default']) {
294                                $test = true;
295                                                        }
296                           
297                            if (is_array($conn)){
298                                $test = true;
299                                                        }else{
300                                                                $test = false;
301                                                        }
302                            if ( $test) {
303                                if ( ($conn['id_type'] == 1) )
304                                    $mail = $conn['connection_value'];
305                                                                else if ( ($conn['id_type'] == 2) )
306                                    $tel = $conn['connection_value'];
307                                                               
308                                                                if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){
309                                                                        if ( ($conn['type'] == 'email') )
310                                        $mail = $conn['connection_value'];
311                                                                        else if ( ($conn['type'] == 'phone') )
312                                        $tel = $conn['connection_value'];       
313                                                                       
314                                                                }
315                                                        }
316                                                }
317                                               
318
319                                               
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.
324                                                        continue;
325
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) {
344                                                $p->set_var('lang_see_details',lang("details"));
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 {
349                                                $p->set_var('lang_see_details',lang("select"));
350                                                $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn");
351                                        }
352                                       
353                                        $p->fp('rows',$block,True);
354
355                                }
356                               
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                }
364
365                /**
366                 * Show details from contact selected
367                 *
368                 * @param $id int
369                 * @param $catalog String
370                 * @return $contact
371                 */
372                function contact_view($params) {
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
384                        if ( isset($params['success'])){
385                                $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg(lang('contact save successfully'));
386                        }
387
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');
394                        $this->template->set_block('cc_v','buttom_use_contact');
395                        $this->template->set_block('cc_v','row_view_operacao');
396
397                        $this->template->set_var('title_view_contact',lang("title view contact"));
398                        $email_to = "";
399
400                        switch ($params['catalog']){
401
402                                case 'bo_shared_people_manager';
403                                case 'bo_people_catalog':
404
405                                                                $this->template->set_var('lang_contact_title',lang("context contact"));
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
412                                                                $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$params['id']);
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                                                                        }
442
443                                                                        if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){
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                                                                        }
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':
476                                                                $this->template->set_var('lang_contact_title',lang("context group"));
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']);
480
481                                                                $email_to = '<'.$result['short_name'].'>';
482                                                               
483                                                                $this->template->set_var('title_view_contact', $result['title']);
484                                                                $this->template->set_var('email_to', $email_to);
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']);
492                                                                        $this->template->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul");
493                                                                       
494                                                                        $this->template->set_var('href_details',"ui_mobilecc.contact_view&id=".$dados['id_contact']."&catalog=bo_people_catalog");
495                                                                       
496                                                                        $this->template->fp('group_rows','group_row',True);
497                                                                }
498
499                                                                $this->template->set_var('email_to', $email_to);
500                                                                $this->template->parse("buttom_use","buttom_use_contact");
501                                                               
502                                                                $this->template->parse("row_body","group");
503                                                        break;
504                                               
505                                default:               
506
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                                                                {
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);
518                                                                       
519                                                                        // SessionStart
520                                                                        session_start();
521                                                                        $_SESSION['phpgw_info']['mobile']['photoCatalog'][$params['id']] = $result['photo'];
522                                                                        session_write_close();
523
524
525                                                                        $this->template->set_var('photo', '../index.php?menuaction=mobile.ui_mobilecc.getPhoto&id=' . $params["id"]);
526
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                                                                                }
551
552                                                                                if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){
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                                                                                }
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
584                        if ( !empty($email_to))
585                        {
586                                $this->template->set_var('email_to', $email_to);
587                                $this->template->parse("buttom_use","buttom_use_contact");
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");
591                        }
592
593                        $this->template->set_var('lang_back',lang("back"));
594                        $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
595                        $this->template->set_var('lang_use_contact',lang("use contact"));
596                        $this->template->set_var('lang_selecteds',lang("selecteds"));
597
598                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
599                }
600               
601                function getPhoto()
602                {
603                    $id = $_GET['id'];
604
605                    session_start();
606
607                    if( isset( $_SESSION['phpgw_info']['mobile']['photoCatalog'][$id] ) )
608                    {
609                        $photo = imagecreatefromstring($_SESSION['phpgw_info']['mobile']['photoCatalog'][$id]);
610
611                        header("Content-Type: image/jpeg");
612                        $width = imagesx($photo);
613                        $height = imagesy($photo);
614                        $twidth = 70;
615                        $theight = 90;
616                        $small_photo = imagecreatetruecolor ($twidth, $theight);
617                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
618                        imagejpeg($small_photo,'',100);
619
620                        unset( $_SESSION['phpgw_info']['mobile']['photoCatalog'][$id] );
621                    }   
622                    else
623                    {
624                        header('Content-type: image/png');
625                        echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png');
626                    }
627
628                    session_write_close();
629
630                    return;
631                }
632
633                /**
634                 * View Add/Edit contact
635                 *
636                 * @param $id int
637                 * @param $catalog String
638                 * @return $contact
639                 */
640                function contact_add_edit($params) {
641
642                        $this->template->set_file(
643                                Array(
644                                        'cc_e' => 'contact_add_edit.tpl'
645                                )
646                        );
647
648                        $this->template->set_block('cc_e','body');
649
650                        $view = false;
651                        if ( isset($params['erro'])){
652                                $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']);
653                               
654                                $result['alias']                        = $params['alias'];
655                                $result['given_names']          = $params['given_names'];
656                                $result['family_names']         = $params['family_names'];
657                                $result['names_ordered']        = $params['names_ordered'];
658                                $var_phone                                      = $params['phone'];
659                                $var_email                                      = $params['email'];
660                                $var_connection_email           = $params['id_connection_email'];
661                                $var_connection_phone           = $params['id_connection_phone'];
662                                $view = true;
663                               
664                        }
665
666                        if ( empty($params['id']) ){
667                                $title_contact = "title add contact";
668                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add";
669                                $confirm = lang("confirm add");
670                                $params['catalog'] = 'bo_people_catalog';
671                        }else{
672                                $title_contact = "title edit contact";
673                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit";
674                                $confirm = lang("confirm edit");
675                               
676                                $view = true;
677
678                                if ( !isset($params['erro'])){
679                                        $this->bo->set_catalog($params['catalog']);
680                                        $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));
681
682                                        $var_phone = "";
683                                        $var_email = "";
684                                        foreach($result['connections'] as $conn):
685                                                if ( $conn['id_type'] == 1 ){
686                                                        if ( (empty($var_email)) && ($conn['connection_is_default']) ){
687                                                                $var_email = $conn['connection_value'];
688                                                                $var_connection_email = $conn['id_connection'];
689                                                        }
690                                                }else if ($conn['id_type'] == 2){
691                                                        if ( (empty($var_phone)) &&  ($conn['connection_is_default'])){
692                                                                $var_phone = $conn['connection_value'];
693                                                                $var_connection_phone = $conn['id_connection'];
694                                                        }
695                                                }
696                                        endforeach;
697                                }
698
699                                                               
700                        }
701                       
702                        if ($view){
703                                        $this->template->set_var('lang_alias',$result['alias']);
704                                        $this->template->set_var('lang_name',$result['given_names']);
705                                        $this->template->set_var('lang_lastname',$result['family_names']);
706                                       
707                                        $this->template->set_var('var_connection_email', $var_connection_email);
708                                        $this->template->set_var('lang_email',$var_email);
709                                       
710                                        $this->template->set_var('var_connection_phone', $var_connection_phone);
711                                        $this->template->set_var('lang_phone',$var_phone);
712
713                        }
714                       
715                        $this->template->set_var('cc_name',$result['names_ordered']);
716                        $this->template->set_var('lang_title_alias',lang("Alias"));
717                        $this->template->set_var('lang_title_name',lang("Name"));
718                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
719                        $this->template->set_var('lang_title_email',lang("Email"));
720                        $this->template->set_var('lang_title_phone',lang("Phone"));
721
722                        $this->template->set_var('catalog', $params['catalog']);
723                               
724                        $this->template->set_var('lang_title_add_edit',lang($title_contact));
725                        $this->template->set_var('form_action', $form_action);
726                       
727                        $this->template->set_var('lang_contact_title',lang("context contact"));
728                        $this->template->set_var('lang_back',lang("back"));
729                        $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
730                        $this->template->set_var('lang_cancel',lang("cancel"));
731                        $this->template->set_var('lang_confirm', $confirm);
732                        $this->template->set_var('lang_selecteds',lang("selecteds"));
733                        $this->template->set_var('id',$params['id']);
734                       
735                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
736                }
737               
738                /**
739                 * Add contact
740                 *
741                 * @param $id int
742                 * @param $catalog String
743                 * @return $contact
744                 */
745                function contact_add($params) {
746                       
747                        $data['alias'] = $params['alias'];
748                        $data['given_names'] = $params['given_names'];
749                        $data['family_names'] = $params['family_names'];
750                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
751                        $data['is_quick_add'] = true;
752
753                        $answer = $this->verifyData($params);
754                       
755                        if (!empty($answer)){
756                                $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names'];
757                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
758                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
759                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
760                        }
761                        else
762                        {
763                                $this->bo->set_catalog($params['catalog']);
764       
765                                if ( !empty($params['email']) ){
766                                        $data['connections']['default_email']['connection_value'] = $params['email'];
767                                }
768                               
769                                if ( !empty($params['phone']) ){
770                                        $data['connections']['default_phone']['connection_value'] = $params['phone'];
771                                }
772       
773                                $this->bo->set_catalog($params['catalog']);
774                                $contact_id = $this->bo->bo->quick_add($data);
775       
776                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1');
777                        }
778                }
779
780                /**
781                 * Edit contact
782                 *
783                 * @param $id int
784                 * @param $catalog String
785                 * @return $contact
786                 */
787                function contact_edit($params) {
788                       
789                        $data['alias'] = $params['alias'];
790                        $data['given_names'] = $params['given_names'];
791                        $data['family_names'] = $params['family_names'];
792                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
793                       
794                        $cont = 0;
795
796                        $answer = $this->verifyData($params);
797
798                        if (!empty($answer)){
799                                $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'];
800                                $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone'];
801                                $retorno .= '&email='.$params['email'] . '&phone='.$params['phone'];
802                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno);
803                        }
804                        else
805                        {
806
807                                $this->bo->set_catalog($params['catalog']);
808                                $types = $this->bo->bo->get_all_connections_types();
809       
810                                if ( !empty($params['email']) || !empty($params['id_connection_email']) ){
811                                        $cont++;
812                               
813                                        if (empty($params['id_connection_email'])){
814                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
815                                                $data['connections']['connection' . $cont]['connection_name'] = $types[1];
816                                        }
817       
818                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email'];
819                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 1;
820                                        $data['connections']['connection' . $cont]['connection_value'] = $params['email'];
821       
822                                }
823       
824                                if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){
825                                        $cont++;
826       
827                                        if (empty($params['id_connection_phone'])){
828                                                $data['connections']['connection' . $cont]['connection_is_default'] = true;
829                                                $data['connections']['connection' . $cont]['connection_name'] = $types[2];
830                                        }
831       
832                                        $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone'];
833                                        $data['connections']['connection' . $cont]['id_typeof_connection'] = 2;
834                                        $data['connections']['connection' . $cont]['connection_value'] = $params['phone'];
835       
836                                }
837       
838                                $contact_id = $this->bo->bo->update_single_info($params['id'], $data);
839
840                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1');
841                               
842                        }
843                       
844                }
845
846                /**
847                 * Validate data when register contact
848                 * Validate E-mail, Phone and Name(NotEmpty)
849                 *
850                 * @param $data Array
851                 * @return Boolean
852                 */
853                static function verifyData($data){
854
855                        $valid = '';
856                        $field = false;
857
858                        // Verify if phone is valid
859                        if ( !empty($data['phone']) && empty($valid) ){
860                               
861                                $field = true;
862                               
863                                $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#";
864
865                                if (!preg_match($pattern, $data['phone'])){
866                                        $valid = lang('invalid field phone');
867                                }
868
869                        }
870
871                        // Verify if e-mail is valid
872                        if ( !empty($data['email']) ){
873
874                                $field = true;
875                               
876                                $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$";
877
878                                if (!eregi($pattern, $data['email'])){
879                                        $valid = lang('invalid field e-mail');
880                                }
881
882                        }
883
884                        // Verify if exist e-mail or phone
885                        if (!$field)
886                                $valid = lang('Tel or email is required');
887                       
888                        // Verify if name is empty
889                        if ( empty($data['given_names']) )
890                                $valid = lang('Name is mandatory');
891                       
892                        return $valid;
893                       
894                }
895
896               
897        }
898       
899       
900?>
Note: See TracBrowser for help on using the repository browser.