source: trunk/mobile/inc/class.ui_mobilecc.inc.php @ 5037

Revision 5037, 29.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2260 - Sincronismo do branch2.2(versão 2.2.8) do modulo mobile para 2.4

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