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

Revision 3631, 23.5 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1413 - Ajuste da listagem dos contatos, devido a revisão [3630].

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->contacts_list();
68                        $this->save_session();
69                }
70               
71                public function change_letter($params) {
72                        $this->page_info['actual_letter'] = $params['letter'];
73                        $this->page_info['actual_max_contacts'] = 10;
74                        $this->contacts_list();
75                        $this->save_session();
76                }
77               
78                public function change_catalog($params) {
79
80                        $this->page_info['actual_catalog'] = $params['catalog'];
81                        $this->page_info['actual_max_contacts'] = 10;
82                        $this->page_info['actual_letter'] = 'a';
83                       
84                        $this->contacts_list();
85                       
86                        $this->save_session();
87                }
88               
89                /**
90                 * Função de inicio do módulo para escolha de um contato para outro módulo.
91                 *
92                 * @return
93                 * @param $params Object
94                 */
95                public function choose_contact($params) {
96                        $this->set_page_info_to_default();
97                        $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from
98                        $this->contacts_list();
99                        $this->save_session();
100                }
101               
102                /**
103                 * Função de inicio do módulo de cc
104                 *
105                 * @return
106                 * @param $params Object
107                 */
108                public function init_cc($params) {
109                        $this->set_page_info_to_default();
110                        $this->contacts_list();
111                        $this->save_session();
112                }
113               
114                /**
115                 * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita
116                 * busca, mostra apenas o formulário para pesquisa.
117                 *
118                 * @return
119                 */
120               
121                function contacts_list() {
122                       
123                        $this->template->set_file(
124                                Array(
125                                        'contacts_list' => 'cc_main.tpl'
126                                )
127                        );
128                        $this->template->set_block("contacts_list","catalog_row");
129                        $this->template->set_block("contacts_list","main_body");
130                        $this->template->set_block("contacts_list","pagging_block");
131
132                        //Langs gerais da página
133                        $this->template->set_var("lang_back",lang("back"));
134                        $this->template->set_var("lang_more",lang("more"));
135                        $this->template->set_var("lang_search",lang("search"));
136                        $this->template->set_var("lang_contacts",ucfirst(lang("contacts")));
137                        $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]);
138                        $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10);
139                        $this->template->set_var("show_actions",strpos($this->page_info["actual_catalog"],"ldap")===false?
140                                                                                                                "block":"none");
141                        $this->template->set_var("contacts_request_from",
142                                                                                $this->page_info["request_from"]==null?
143                                                                                "none":$this->page_info["request_from"]);
144                       
145                        //Combo de catálogos
146                        $catalogs = $this->bo->get_all_catalogs();
147                        foreach($catalogs as $catalog) {
148                                $this->template->set_var("catalog_value",$catalog["catalog"]);
149                                $this->template->set_var("catalog_name",$catalog["label"]);
150                                if($this->page_info['actual_catalog']==$catalog['catalog'])
151                                        $this->template->set_var("selected","selected");
152                                else
153                                        $this->template->set_var("selected"," ");
154                                $this->template->fp("catalogs","catalog_row",true);
155                        }
156                        $this->bo->set_catalog($this->page_info["actual_catalog"]);
157                        $contacts = $this->bo->search($this->page_info["actual_letter"]."%",
158                                                                                        $this->page_info["actual_max_contacts"]);
159                               
160                       
161                        //Letras da paginação
162                        $max_letters = 5;
163                        if ( in_array($this->page_info['actual_letter'],
164                                                  range("a","c"))){ //Letras de A à C iniciam sempre com A             
165       
166                                $this->template->set_var('show_back','none');
167                                $this->template->set_var('show_next','inline');
168                                $first_letter = "a";
169                                $this->template->set_var('href_next',"index.php?menuaction=mobile.".
170                                                                                 "ui_mobilecc.change_letter&letter=f");
171                        }
172                        else if ( in_array($this->page_info['actual_letter'],
173                                                  range("x","z"))) { //Letras de X à Z terminam sempre no Z
174                                $this->template->set_var('show_back','inline');
175                                $this->template->set_var('show_next','none');
176                                $first_letter = "v";
177                                $this->template->set_var('href_back',"index.php?menuaction=mobile.".
178                                                                                 "ui_mobilecc.change_letter&letter=u");
179                                }
180                        else { //Letras do meio
181                                $this->template->set_var('show_back','inline');
182                                $this->template->set_var('show_next','inline');
183                               
184                                $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes
185                                $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter
186                               
187                                $this->template->set_var('href_back',"index.php?menuaction=mobile.".
188                                                                                 "ui_mobilecc.change_letter&letter=".$first_letter);
189                                $this->template->set_var('href_next',"index.php?menuaction=mobile.".
190                                                                                 "ui_mobilecc.change_letter&letter=".$last_letter);
191                                $first_letter++;
192                        }
193                       
194                        for($i=1;$i<=$max_letters;$i++) { //Roda as letras
195                                        $this->template->set_var("href","index.php?menuaction=mobile.".
196                                                                                        "ui_mobilecc.change_letter&letter=".$first_letter);
197                                        $this->template->set_var("letter",strtoupper($first_letter));
198                                        if($first_letter===$this->page_info["actual_letter"])
199                                                $this->template->set_var("class_button","letter-contact-selected");
200                                        else
201                                                $this->template->set_var("class_button","btn_off");
202                                        $this->template->set_var("letter",strtoupper($first_letter));
203                                        $this->template->fp("pagging_letters","pagging_block",true);
204                                        $first_letter++;
205                        }
206                       
207
208                        if($contacts['has_more'])
209                                $this->template->set_var("show_more","block");
210                        else
211                                $this->template->set_var("show_more","none");
212                        unset($contacts['has_more']);
213                                               
214                        $this->template->set_var("contacts",$this->print_contacts($contacts,true,$this->page_info['request_from']));
215                       
216
217                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body'));
218                }
219               
220                /**
221                 * Remove os contatos selecionados
222                 *
223                 * @return
224                 * @param $contacts Object
225                 * @param $show_checkbox Object[optional]
226                 */
227               
228                function delete_contacts($params) {
229                        $this->bo->set_catalog($params['catalog']);
230                        $status = $this->bo->remove_multiple_entries($params['contacts']);
231                       
232                        $type = $this->page_info['actual_catalog']!=='bo_group_manager'?"contacts":"groups";
233                       
234                        if($status['success'])
235                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully"));
236                        else
237                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed"));
238                }
239               
240                static function print_contacts($contacts,$show_checkbox=false,$request_from = null) {
241                        $functions = CreateObject('mobile.common_functions');
242                        $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
243                                        $p->set_file(
244                                                Array(
245                                                        'cc_t' => 'contacts_list.tpl'
246                                                )
247                                        );
248                        $p->set_block('cc_t', 'rows_contacts');
249                        $p->set_block('cc_t', 'row_contacts');
250                        $p->set_block('cc_t', 'row_groups');
251                        $p->set_block('cc_t', 'no_contacts');
252
253                        $bg = "par";
254                        if(!empty($contacts)) {
255                                foreach($contacts as $id => $contact) {
256
257                                        $p->set_var('show_check',$show_checkbox?"inline":"none");
258                                        $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");
259                                                                               
260                                        if($contact["catalog"]!=="bo_group_manager") {  //Contatos             
261                                                $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id;
262
263                        $mail = '&nbsp;'; $tel = '&nbsp;';
264                        foreach($contact['connections'] as $key => $conn) {
265
266                            $test = false;
267                            if ($conn['connection_is_default']) {
268                                $test = true;
269                            }
270                           
271                            if (is_array($conn)){
272                                $test = true;
273                            }
274                           
275                            if ( $test) {
276                                if ( ($conn['id_type'] == 1) )
277                                    $mail = $conn['connection_value'];
278                                else if ( ($conn['id_type'] == 2) )
279                                    $tel = $conn['connection_value'];
280                            }
281                                                }
282
283                                               
284                        $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"];
285                        $vtel = ($tel==null || $tel=='&nbsp;')?"none":"inline";
286                                               
287                                                if(($mail=='&nbsp;' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre.
288                                                        continue;
289
290                                                $p->set_var('show_tel',$vtel);
291                                                $p->set_var('email',$mail);
292                                                $p->set_var('tel',$tel);
293                                                $p->set_var('contact_id',$id);
294                                                $p->set_var('lang_tel',lang("tel"));
295                                                $p->set_var('contact_name',$functions->strach_string($cn,17));
296
297                                                $block = "row_contacts";
298                                        }
299                                        else { //Grupos
300                                                $id=$contact["id_group"];
301                                                $mail = $cn = $contact["title"];
302                                                $p->set_var('group_id',$contact["id_group"]);
303                                                $p->set_var('group_name',$contact["title"]);
304                                                $block = "row_groups";
305                                        }
306                                       
307                                        if($request_from==null) {
308                                                $p->set_var('lang_see_details',strtoupper(lang("see details")));
309                                                $cat_encode = urlencode($contact["catalog"]);
310                                                $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"]));
311                                        }
312                                        else {
313                                                $p->set_var('lang_see_details',strtoupper(lang("select")));
314                                                $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn");
315                                        }
316                                       
317                                        $p->fp('rows',$block,True);
318
319                                }
320                               
321                        }
322                        else {
323                                $p->set_var("lang_no_results",lang("no results found"));
324                                $p->parse("rows","no_contacts");
325                        }
326                        return $p->fp('out','rows_contacts');
327                }
328
329                /**
330                 * Show details from contact selected
331                 *
332                 * @param $id int
333                 * @param $catalog String
334                 * @return $contact
335                 */
336                function contact_view($params) { // bo_people_catalog, bo_global_ldap_catalog
337
338                        if ( empty($params['id']) || empty($params['catalog']) ){
339                                header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc');
340                        }
341                       
342                        $this->template->set_file(
343                                Array(
344                                        'cc_v' => 'contact_view.tpl'
345                                )
346                        );
347
348                        $this->template->set_block('cc_v','body');
349                        $this->template->set_block('cc_v','people');
350                        $this->template->set_block('cc_v','people_ldap');
351                        $this->template->set_block('cc_v','group');
352                        $this->template->set_block('cc_v','group_row');
353                        $this->template->set_block('cc_v','buttom');
354
355                        switch ($params['catalog']){
356
357                                case 'bo_shared_people_manager';
358                                case 'bo_people_catalog':
359
360                                                                $this->bo->set_catalog($params['catalog']);
361
362                                                                $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));
363
364                                                                asort($result['connections']);
365
366                                                                $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id);
367                                                                $this->template->set_var('id',$params['id']);
368                                                                $this->template->set_var('catalog',$params['catalog']);
369                                       
370                                                                $this->template->set_var('cc_name',$result['names_ordered']);
371                                                                $this->template->set_var('lang_title_alias',lang("Alias"));
372                                                                $this->template->set_var('lang_alias',$result['alias']);
373                                                               
374                                                                $this->template->set_var('lang_title_name',lang("Name"));
375                                                                $this->template->set_var('lang_name',$result['given_names']);
376                                                               
377                                                                $this->template->set_var('lang_title_lastname',lang("Family Names"));
378                                                                $this->template->set_var('lang_lastname',$result['family_names']);
379                                                               
380                                                                $email_to = "";
381                                                                $var_phone = "";
382                                                                $var_email = "";
383                                                                foreach($result['connections'] as $conn):
384                                                                        if ( $conn['id_type'] == 1 ){
385                                                                                if ( !empty($var_email) )
386                                                                                        $var_email .= ' | ';
387                                                                                $var_email .= $conn['connection_value'];
388                                                                               
389                                                                                if ( empty($email_to) )
390                                                                                        $email_to = $var_email;
391                                                                               
392                                                                        }else if ($conn['id_type'] == 2){
393                                                                                if ( !empty($var_phone))
394                                                                                        $var_phone .= ' | ';
395                                                                                $var_phone .= $conn['connection_value'];
396                                                                        }
397                                                                endforeach;
398                                       
399                                                                $this->template->set_var('email_to', $email_to);
400                                                               
401                                                                $this->template->set_var('lang_title_email',lang("Email"));
402                                                                $this->template->set_var('lang_email',$var_email);
403                                                               
404                                                                $this->template->set_var('lang_title_phone',lang("Phone"));
405                                                                $this->template->set_var('lang_phone',$var_phone);
406                               
407                                                                $this->template->set_var('lang_edit',lang("edit"));
408                                                               
409                                                                $this->template->parse("row_body","people");
410                                                               
411                                                                if ($params['catalog'] == 'bo_people_catalog')
412                                                                        $this->template->parse("buttom_editar","buttom");
413                                                                       
414                                                        break;
415                                                       
416                                case 'bo_group_manager':
417
418                                                                $this->bo->set_catalog($params['catalog']);
419                                                                $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true));
420                                                                $data   = $this->bo->bo->get_contacts_by_group($params['id']);
421                                                               
422                                                                $this->template->set_var('gr_name', $result['title']);
423                                                                $this->template->set_var('email_to', '<'.$result['short_name'].'>');
424
425                                                                $this->template->set_var('lang_title_name',lang("Name"));
426                                                                $this->template->set_var('lang_title_email',lang("Email"));
427                                                               
428                                                                foreach($data as $dados){
429                                                                        $this->template->set_var('lang_name', $dados['names_ordered']);
430                                                                        $this->template->set_var('lang_email', $dados['connection_value']);
431                                                                       
432                                                                        $this->template->fp('group_rows','group_row',True);
433                                                                }
434                                                               
435                                                                $this->template->parse("row_body","group");
436                                                        break;
437                                               
438                                default:               
439
440                                                                if(strpos($params['catalog'],'bo_global_ldap_catalog')==false){
441
442                                                                        $this->bo->set_catalog($params['catalog']);
443
444                                                                        $fields = $this->bo->bo->get_fields(true);
445                                                                        $result = $this->bo->bo->get_single_entry($params['id'], $fields);
446
447                                                                        $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id);
448
449                                                                        $this->template->set_var('cc_name',$result['names_ordered'][0]);
450
451                                                                        $this->template->set_var('lang_title_name',lang("Name"));
452                                                                        $this->template->set_var('lang_name',$result['given_names'][0]);
453                                                                       
454                                                                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
455                                                                        $this->template->set_var('lang_lastname',$result['family_names'][0]);
456                                                                       
457                                                                        $email_to = "";
458                                                                        $var_phone = "";
459                                                                        $var_email = "";
460                                                                        foreach($result['connections'] as $conn):
461                                                                                if ( $conn['id_type'] == 1 ){
462                                                                                        if ( !empty($var_email) )
463                                                                                                $var_email .= ' | ';
464                                                                                        $var_email .= $conn['connection_value'];
465                                                                                       
466                                                                                        if ( empty($email_to) )
467                                                                                                $email_to = $var_email;
468                                                                                       
469                                                                                }else if ($conn['id_type'] == 2){
470                                                                                        if ( !empty($var_phone))
471                                                                                                $var_phone .= ' | ';
472                                                                                        $var_phone .= $conn['connection_value'];
473                                                                                }
474                                                                        endforeach;
475                                               
476                                                                        $this->template->set_var('email_to', $email_to);
477                                                                       
478                                                                        $this->template->set_var('lang_title_email',lang("Email"));
479                                                                        $this->template->set_var('lang_email',$var_email);
480                                                                       
481                                                                        $this->template->set_var('lang_title_phone',lang("Phone"));
482                                                                        $this->template->set_var('lang_phone',$var_phone);
483
484                                                                        $this->template->parse("row_body","people_ldap");
485
486                                                                }else{
487                                                                        header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc');
488                                                                }
489
490                                                        break;
491                        }
492
493                        $this->template->set_var('lang_contact_title',lang("context contact"));
494                        $this->template->set_var('lang_back',lang("back"));
495                        $this->template->set_var('lang_use_contact',lang("use contact"));
496                        $this->template->set_var('lang_selecteds',lang("selecteds"));
497
498                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
499                }
500
501                /**
502                 * View Add/Edit contact
503                 *
504                 * @param $id int
505                 * @param $catalog String
506                 * @return $contact
507                 */
508                function contact_add_edit($params) {
509
510                        $this->template->set_file(
511                                Array(
512                                        'cc_e' => 'contact_add_edit.tpl'
513                                )
514                        );
515
516                        $this->template->set_block('cc_e','body');
517
518                        if ( empty($params['id']) ){
519                                $title_contact = "title add contact";
520                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add";
521                                $confirm = lang("confirm add");
522                                $params['catalog'] = 'bo_people_catalog';
523                        }else{
524                                $title_contact = "title edit contact";
525                                $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit";
526                                $confirm = lang("confirm edit");
527                               
528                                $this->bo->set_catalog($params['catalog']);
529                                $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));
530
531                                $this->template->set_var('lang_alias',$result['alias']);
532                                $this->template->set_var('lang_name',$result['given_names']);
533                                $this->template->set_var('lang_lastname',$result['family_names']);
534       
535                                $var_phone = "";
536                                $var_email = "";
537                                foreach($result['connections'] as $conn):
538                                        if ( $conn['id_type'] == 1 ){
539                                                if ( (empty($var_email)) && ($conn['connection_is_default']) ){
540                                                        $var_email = $conn['connection_value'];
541                                                        $var_connection_email = $conn['id_connection'];
542                                                }
543                                        }else if ($conn['id_type'] == 2){
544                                                if ( (empty($var_phone)) &&  ($conn['connection_is_default'])){
545                                                        $var_phone = $conn['connection_value'];
546                                                        $var_connection_phone = $conn['id_connection'];
547                                                }
548                                        }
549                                endforeach;
550
551                                $this->template->set_var('var_connection_email', $var_connection_email);
552                                $this->template->set_var('lang_email',$var_email);
553                               
554                                $this->template->set_var('var_connection_phone', $var_connection_phone);
555                                $this->template->set_var('lang_phone',$var_phone);
556                                                               
557                        }
558                       
559                        $this->template->set_var('cc_name',$result['names_ordered']);
560                        $this->template->set_var('lang_title_alias',lang("Alias"));
561                        $this->template->set_var('lang_title_name',lang("Name"));
562                        $this->template->set_var('lang_title_lastname',lang("Family Names"));
563                        $this->template->set_var('lang_title_email',lang("Email"));
564                        $this->template->set_var('lang_title_phone',lang("Phone"));
565
566                        $this->template->set_var('catalog', $params['catalog']);
567                               
568                        $this->template->set_var('lang_title_add_edit',lang($title_contact));
569                        $this->template->set_var('form_action', $form_action);
570                       
571                        $this->template->set_var('lang_contact_title',lang("context contact"));
572                        $this->template->set_var('lang_back',lang("back"));
573                        $this->template->set_var('lang_cancel',lang("cancel"));
574                        $this->template->set_var('lang_confirm', $confirm);
575                        $this->template->set_var('lang_selecteds',lang("selecteds"));
576                        $this->template->set_var('id',$params['id']);
577                       
578                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body'));
579                }
580               
581                /**
582                 * Add contact
583                 *
584                 * @param $id int
585                 * @param $catalog String
586                 * @return $contact
587                 */
588                function contact_add($params) {
589                       
590                        $data['alias'] = $params['alias'];
591                        $data['given_names'] = $params['given_names'];
592                        $data['family_names'] = $params['family_names'];
593                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
594                        $data['is_quick_add'] = true;
595
596                        $this->bo->set_catalog($params['catalog']);
597
598                        if ( !empty($params['email']) ){
599                                $data['connections']['default_email']['connection_value'] = $params['email'];
600                        }
601                       
602                        if ( !empty($params['phone']) ){
603                                $data['connections']['default_phone']['connection_value'] = $params['phone'];
604                        }
605
606                        $this->bo->set_catalog($params['catalog']);
607                        $contact_id = $this->bo->bo->quick_add($data);
608
609                        header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog']);
610                }
611               
612                /**
613                 * Edit contact
614                 *
615                 * @param $id int
616                 * @param $catalog String
617                 * @return $contact
618                 */
619                function contact_edit($params) {
620                       
621                        $data['alias'] = $params['alias'];
622                        $data['given_names'] = $params['given_names'];
623                        $data['family_names'] = $params['family_names'];
624                        $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names'];
625                       
626                        $cont = 0;
627
628                        $this->bo->set_catalog($params['catalog']);
629                        $types = $this->bo->bo->get_all_connections_types();
630
631                        if ( !empty($params['email']) || !empty($params['id_connection_email']) ){
632                                $cont++;
633                       
634                                if (empty($params['id_connection_email'])){
635                                        $data['connections']['connection' . $cont]['connection_is_default'] = true;
636                                        $data['connections']['connection' . $cont]['connection_name'] = $types[1];
637                                }
638
639                                $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email'];
640                                $data['connections']['connection' . $cont]['id_typeof_connection'] = 1;
641                                $data['connections']['connection' . $cont]['connection_value'] = $params['email'];
642
643                        }
644
645                        if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){
646                                $cont++;
647
648                                if (empty($params['id_connection_phone'])){
649                                        $data['connections']['connection' . $cont]['connection_is_default'] = true;
650                                        $data['connections']['connection' . $cont]['connection_name'] = $types[2];
651                                }
652
653                                $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone'];
654                                $data['connections']['connection' . $cont]['id_typeof_connection'] = 2;
655                                $data['connections']['connection' . $cont]['connection_value'] = $params['phone'];
656
657                        }
658
659                        $contact_id = $this->bo->bo->update_single_info($params['id'], $data);
660
661                        header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog']);
662                       
663                }
664
665                /**
666                 * Verify if the data is valid
667                 *
668                 * @param $type String
669                 * @param $data String
670                 * @return Boolean
671                 */
672                static function validateData($type,$data){
673                       
674                        switch($type){
675                                case 'phone' :  "/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i";
676                                                break;
677                               
678                                case 'email' : $pattern = "/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i";
679                                                break;
680                        }
681                       
682                        return preg_match($pattern, $data) ? true : false;
683                       
684                }
685
686               
687        }
688       
689       
690?>
Note: See TracBrowser for help on using the repository browser.