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

Revision 3629, 11.6 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1412 - Melhoria na lógica de connections do contato.

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                );
22                var $template;
23               
24                /**
25                 * Construtor...
26                 *
27                 */
28                public function ui_mobilecc() {
29                        $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
30                        $this->bo = CreateObject('mobile.bo_mobilecc');
31                        $page_info = $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile');
32                       
33                        if($page_info) {
34                                $this->page_info = $page_info;
35                        }
36                        else {
37                                $this->set_page_info_to_default();
38                        }
39                       
40                        //if()
41
42                }
43               
44                private function set_page_info_to_default() { //Valores default para iniciar o módulo de contatos
45                        $this->page_info['actual_catalog'] = 'bo_people_catalog';
46                        $this->page_info['actual_letter'] = 'a';
47                        $this->page_info['actual_max_contacts'] = 10;
48                        $this->page_info['request_from'] = null;
49                }
50               
51                private function save_session() {
52                        $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile',$this->page_info);
53                }
54               
55                public function index($params) {
56                        $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
57                        $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]);
58                        $this->contacts_list();
59                }
60               
61                public function change_max_results($params) {
62                        $this->page_info['actual_max_contacts'] = $params['results'];
63                        $this->contacts_list();
64                        $this->save_session();
65                }
66               
67                public function change_letter($params) {
68                        $this->page_info['actual_letter'] = $params['letter'];
69                        $this->page_info['actual_max_contacts'] = 10;
70                        $this->contacts_list();
71                        $this->save_session();
72                }
73               
74                public function change_catalog($params) {
75
76                        $this->page_info['actual_catalog'] = $params['catalog'];
77                        $this->page_info['actual_max_contacts'] = 10;
78                        $this->page_info['actual_letter'] = 'a';
79                       
80                        $this->contacts_list();
81                       
82                        $this->save_session();
83                }
84               
85                /**
86                 * Função de inicio do módulo para escolha de um contato para outro módulo.
87                 *
88                 * @return
89                 * @param $params Object
90                 */
91                public function choose_contact($params) {
92                        $this->set_page_info_to_default();
93                        $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from
94                        $this->contacts_list();
95                        $this->save_session();
96                }
97               
98                /**
99                 * Função de inicio do módulo de cc
100                 *
101                 * @return
102                 * @param $params Object
103                 */
104                public function init_cc($params) {
105                        $this->set_page_info_to_default();
106                        $this->contacts_list();
107                        $this->save_session();
108                }
109               
110                /**
111                 * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita
112                 * busca, mostra apenas o formulário para pesquisa.
113                 *
114                 * @return
115                 */
116               
117                function contacts_list() {
118                       
119                        $this->template->set_file(
120                                Array(
121                                        'contacts_list' => 'cc_main.tpl'
122                                )
123                        );
124                        $this->template->set_block("contacts_list","catalog_row");
125                        $this->template->set_block("contacts_list","main_body");
126                        $this->template->set_block("contacts_list","pagging_block");
127
128                        //Langs gerais da página
129                        $this->template->set_var("lang_back",lang("back"));
130                        $this->template->set_var("lang_more",lang("more"));
131                        $this->template->set_var("lang_search",lang("search"));
132                        $this->template->set_var("lang_contacts",ucfirst(lang("contacts")));
133                        $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]);
134                        $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10);
135                        $this->template->set_var("show_actions",strpos($this->page_info["actual_catalog"],"ldap")===false?
136                                                                                                                "block":"none");
137                        $this->template->set_var("contacts_request_from",
138                                                                                $this->page_info["request_from"]==null?
139                                                                                "none":$this->page_info["request_from"]);
140                       
141                        //Combo de catálogos
142                        $catalogs = $this->bo->get_all_catalogs();
143                        foreach($catalogs as $catalog) {
144                                $this->template->set_var("catalog_value",$catalog["catalog"]);
145                                $this->template->set_var("catalog_name",$catalog["label"]);
146                                if($this->page_info['actual_catalog']==$catalog['catalog'])
147                                        $this->template->set_var("selected","selected");
148                                else
149                                        $this->template->set_var("selected"," ");
150                                $this->template->fp("catalogs","catalog_row",true);
151                        }
152                        $this->bo->set_catalog($this->page_info["actual_catalog"]);
153                        $contacts = $this->bo->search($this->page_info["actual_letter"]."%",
154                                                                                        $this->page_info["actual_max_contacts"]);
155                               
156                       
157                        //Letras da paginação
158                        $max_letters = 5;
159                        if ( in_array($this->page_info['actual_letter'],
160                                                  range("a","c"))){ //Letras de A à C iniciam sempre com A             
161       
162                                $this->template->set_var('show_back','none');
163                                $this->template->set_var('show_next','inline');
164                                $first_letter = "a";
165                                $this->template->set_var('href_next',"index.php?menuaction=mobile.".
166                                                                                 "ui_mobilecc.change_letter&letter=f");
167                        }
168                        else if ( in_array($this->page_info['actual_letter'],
169                                                  range("x","z"))) { //Letras de X à Z terminam sempre no Z
170                                $this->template->set_var('show_back','inline');
171                                $this->template->set_var('show_next','none');
172                                $first_letter = "v";
173                                $this->template->set_var('href_back',"index.php?menuaction=mobile.".
174                                                                                 "ui_mobilecc.change_letter&letter=u");
175                                }
176                        else { //Letras do meio
177                                $this->template->set_var('show_back','inline');
178                                $this->template->set_var('show_next','inline');
179                               
180                                $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes
181                                $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter
182                               
183                                $this->template->set_var('href_back',"index.php?menuaction=mobile.".
184                                                                                 "ui_mobilecc.change_letter&letter=".$first_letter);
185                                $this->template->set_var('href_next',"index.php?menuaction=mobile.".
186                                                                                 "ui_mobilecc.change_letter&letter=".$last_letter);
187                                $first_letter++;
188                        }
189                       
190                        for($i=1;$i<=$max_letters;$i++) { //Roda as letras
191                                        $this->template->set_var("href","index.php?menuaction=mobile.".
192                                                                                        "ui_mobilecc.change_letter&letter=".$first_letter);
193                                        $this->template->set_var("letter",strtoupper($first_letter));
194                                        if($first_letter===$this->page_info["actual_letter"])
195                                                $this->template->set_var("class_button","letter-contact-selected");
196                                        else
197                                                $this->template->set_var("class_button","btn_off");
198                                        $this->template->set_var("letter",strtoupper($first_letter));
199                                        $this->template->fp("pagging_letters","pagging_block",true);
200                                        $first_letter++;
201                        }
202                       
203
204                        if($contacts['has_more'])
205                                $this->template->set_var("show_more","block");
206                        else
207                                $this->template->set_var("show_more","none");
208                        unset($contacts['has_more']);
209                                               
210                        $this->template->set_var("contacts",$this->print_contacts($contacts,true,$this->page_info['request_from']));
211                       
212
213                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body'));
214                }
215               
216                /**
217                 * Remove os contatos selecionados
218                 *
219                 * @return
220                 * @param $contacts Object
221                 * @param $show_checkbox Object[optional]
222                 */
223               
224                function delete_contacts($params) {
225                        $this->bo->set_catalog($params['catalog']);
226                        $status = $this->bo->remove_multiple_entries($params['contacts']);
227                       
228                        $type = $this->page_info['actual_catalog']!=='bo_group_manager'?"contacts":"groups";
229                       
230                        if($status['success'])
231                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully"));
232                        else
233                                header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed"));
234                }
235               
236                static function print_contacts($contacts,$show_checkbox=false,$request_from = null) {
237                        $functions = CreateObject('mobile.common_functions');
238                        $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
239                                        $p->set_file(
240                                                Array(
241                                                        'cc_t' => 'contacts_list.tpl'
242                                                )
243                                        );
244                        $p->set_block('cc_t', 'rows_contacts');
245                        $p->set_block('cc_t', 'row_contacts');
246                        $p->set_block('cc_t', 'row_groups');
247                        $p->set_block('cc_t', 'no_contacts');
248
249                        $bg = "par";
250                        if(!empty($contacts)) {
251                                foreach($contacts as $id => $contact) {
252                                       
253                                        $p->set_var('show_check',$show_checkbox?"inline":"none");
254                    $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");
255                                       
256                    if($contact["catalog"]!=="bo_group_manager") {    //Contatos       
257                        $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id;
258
259                        $mail = '&nbsp;'; $tel = '&nbsp;';
260                        foreach($contact['connections'] as $key => $conn) {
261
262                            $test = false;
263                            if ($conn['connection_is_default']) {
264                                $test = true;
265                            }
266                           
267                            if (is_array($conn)){
268                                $test = true;
269                            }
270                           
271                            if ( $test) {
272                                if ( ($conn['id_type'] == 1) )
273                                    $mail = $conn['connection_value'];
274                                else if ( ($conn['id_type'] == 2) )
275                                    $tel = $conn['connection_value'];
276                            }
277                                                }
278
279                                               
280                        $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"];
281                        $vtel = ($tel==null || $tel=='&nbsp;')?"none":"inline";
282                                               
283                                                if(($mail=='&nbsp;' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre.
284                                                        continue;
285
286                        $p->set_var('show_tel',$vtel);
287                        $p->set_var('email',$mail);
288                        $p->set_var('tel',$tel);
289                        $p->set_var('contact_id',$id);
290                        $p->set_var('lang_tel',lang("tel"));
291                        $p->set_var('contact_name',$functions->strach_string($cn,14));
292
293                        $block = "row_contacts";
294                    }
295                    else { //Grupos
296                        $id=$contact["id_group"];
297                        $mail = $cn = $contact["title"];
298                        $p->set_var('group_id',$contact["id_group"]);
299                        $p->set_var('group_name',$contact["title"]);
300                        $block = "row_groups";
301                    }
302                   
303                    if($request_from==null) {
304                        $p->set_var('lang_see_details',strtoupper(lang("see details")));
305                        $cat_encode = urlencode($contact["catalog"]);
306                        $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"]));
307                    }
308                    else {
309                        $p->set_var('lang_see_details',strtoupper(lang("select")));
310                        $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn");
311                    }
312                   
313                    $p->fp('rows',$block,True);
314                                }
315                               
316                        }
317                        else {
318                                $p->set_var("lang_no_results",lang("no results found"));
319                                $p->parse("rows","no_contacts");
320                        }
321                        return $p->fp('out','rows_contacts');
322                }
323               
324        }
325       
326       
327       
328       
329?>
Note: See TracBrowser for help on using the repository browser.