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

Revision 1499, 15.1 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #675 - Ajuste na exibição do link para pastas enviadas

Line 
1<?php
2        class ui_mobilecc{
3               
4                var $nextmatchs;
5                var $bo;
6                var $page_info = array (
7                                'actual_catalog' => false,
8                                'is_external_catalog' => false
9                        );
10               
11                var $public_functions = array(
12                        'contacts_list' => true,
13                );
14               
15                /**
16                 * Construtor...
17                 *
18                 */
19                public function ui_mobilecc() {
20                        $this->nextmatchs       = CreateObject('phpgwapi.nextmatchs');
21                }
22               
23                /**
24                 * Inicia um BO de catálogo do módulo de contactcenter.
25                 * @return
26                 * @param $catalog String com o catálogo
27                 */
28                private function set_catalog($catalog) {
29                        if(strpos($catalog,'bo_global_ldap_catalog')===false) //Ldap?
30                                $this->bo= CreateObject("contactcenter.".$catalog);
31                        else {
32                                $exploded = explode("#",$catalog);
33                                $this->bo= CreateObject("contactcenter.bo_global_ldap_catalog",$exploded[1],$exploded[2],$exploded[3]);
34                                if($exploded[3]==1)
35                                        $this->page_info['is_external_catalog'] = true;
36                                else {
37                                        $this->page_info['is_external_catalog'] = false;
38                                }
39                                       
40                        }
41                        $this->page_info['actual_catalog'] = $catalog;
42                }
43               
44                /**
45                 * Busca um nome a partir do catálogo. Se nenhum for informado previamente,
46                 * retorna um array vazio.
47                 *
48                 * Caso o catálogo atual seja grupos, a busca será por títulos, caso seja
49                 * contatos pessoais, será por names_ordered, se for contato no ldap, será
50                 * por cn.
51                 *
52                 * @return array, com os ids relativos a busca
53                 * @param $name string com o nome à ser buscado.
54                 */
55                public function find($name) {
56                        if(!$this->page_info["actual_catalog"])
57                                return array();
58                       
59                        if($this->page_info['actual_catalog']=="bo_group_manager") { //parametros de busca para grupos
60                                $id = 'group.id_group';
61                                $what = array('group.title',$id);
62                                $search = "group.title";
63                        }
64                        else { //parametros de busca para pessoas
65                                $id = 'contact.id_contact';
66                                $search = "contact.names_ordered";
67                                $what = array('contact.names_ordered',$id);
68                        }
69                       
70                        if ((strpos($this->page_info["actual_catalog"],'bo_global_ldap_catalog')!==false) &&
71                                        (!$this->page_info['is_external_catalog'])) { //Ldap do expresso, leva em conta alguns atributos do expresso
72
73                                array_push($what,'contact.object_class',
74                                                'contact.account_visible',
75                                                'contact.account_status'
76                                                );
77                               
78                                $rules = array(
79                                                        0 => array(
80                                                                'field' => 'contact.object_class',
81                                                                'type'  => '=',
82                                                                'value' => 'phpgwAccount'
83                                                        ),
84                                                        1 => array(
85                                                                'field' => 'contact.account_status',
86                                                                'type'  => 'iLIKE',
87                                                                'value' => '%'
88                                                        ),
89                                                        2 => array(
90                                                                'field' => 'contact.account_visible',
91                                                                'type'  => '!=',
92                                                                'value' => '-1'
93                                                        ),
94                                                        3 => array(
95                                                                'field' => 'contact.object_class',
96                                                                'type'  => '=',
97                                                                'value' => 'inetOrgPerson'
98                                                        )
99                                                );
100                        }
101                        else{
102                                $rules = array();
103                        }
104
105                       
106                       
107                        if ($name != '') { //String em branco, não preciso adicionar essa regra
108                                array_push($rules,array(
109                                                                'field' => $search,
110                                                                'type'  => 'iLIKE',
111                                                                'value' => '%'.$name.'%'
112                                                        ));             
113                        }
114                                                                                                               
115                        $ids = $this->bo->find($what,$rules);
116
117                        if(is_array($ids)) foreach($ids as $id_r) { //Quero apenas os ids, como valores nas posições do array
118                                $retorno[] = $id_r[substr($id,strpos($id,".")+1)];
119                        }
120                       
121                        return $retorno;
122                }
123               
124                /**
125                 * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita
126                 * busca, mostra apenas o formulário para pesquisa.
127                 *
128                 * @return
129                 */
130               
131                function contacts_list($from_calendar=false) {
132
133                        $entries = array();
134                        $actual_page = 0;
135
136                        if(isset($_POST['name']) && strlen($_POST['name'])<4) //Busca apenas para nomes com mais de 4 palavras
137                                $ids = false;
138                        else {
139                                /////////////// Pego os ids referente a consulta, se a mesma foi feita
140                                if(isset($_POST['name'])) {
141                                        $this->set_catalog($_POST['catalog']);
142                                        $ids = $this->find($_POST['name']);
143                                        if(is_array($ids)) {
144                                                $actual_page = 1;
145                                                $_SESSION["mobile_search_ids"] = $ids;
146                                                $_SESSION["mobile_search_catalog"] = $_POST['catalog'];
147                                                $ids = array_slice($ids,0,10); //Apenas a primeira página
148                                        }
149                                }
150                                else if(isset($_GET['page'])) {
151                                        $this->set_catalog($_SESSION["mobile_search_catalog"]);
152                                        $ids = array_slice($_SESSION["mobile_search_ids"],($_GET['page']-1)*10,10); //Página solicitada
153                                        $actual_page = $_GET['page'];
154                                }
155                                else
156                                        $ids = false;
157                        }
158
159                        ///////////// Pego os dados dos ids da página em questão.
160                        if(!is_array($ids) || count($_SESSION["mobile_search_ids"])>100 || (isset($_POST["name"]) && strlen($_POST['name'])<4)) {
161                                $entries = array();
162                        }
163                        else { //Só pego os dados completos caso haja resultado na busca
164                                if($this->page_info['actual_catalog']!="bo_group_manager") { //Se não for grupo, tenho que ordenar as connections
165                                        $entries = $this->bo->get_multiple_entries($ids,array("names_ordered"=>true,"uidnumber"=>true,"id_contact"=>true,"connections"=>true));
166                                        /**
167                                         * As entradas vindas de get_multiple_entries não vem com as connections
168                                         * ordenadas. Abaixo eu ordeno o array connections de cada entrada para ter
169                                         * sempre na frente os valores defaults, primeiro o default de email, depois
170                                         * o de telefone.
171                                         */
172                                        foreach($entries as &$valor) {
173                                                /* Sempre iniciar os arrays, pois pode interferir na
174                                                 * ordenação atual se tiverem valores antigos desnecessários
175                                                 * causando erro de tamanhos inconsistentes */
176                                                $default = array();
177                                                $type = array();
178                                               
179                                                foreach($valor['connections'] as $key => $value) {
180                                                        $default[$key] = $value['connection_is_default'];
181                                                        $type[$key] = $value['id_type'];
182                                                }
183                                                array_multisort($default, SORT_DESC, $type, SORT_ASC, $valor['connections']);
184                                        }//Fim da ordenação
185                                }
186                                else {
187                                        $entries = $this->bo->get_multiple_entries($ids,array("id_group"=>true,"title"=>true,"short_name"=>true));
188                                }
189
190                        }
191                       
192                        ///////////////// Monto os dados gerais da página no template.
193                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
194                       
195                        if(!$from_calendar)
196                                $p->set_file(Array('entries' => 'cc_main.tpl'));
197                        else if($from_calendar =='mobilecalendar')
198                                $p->set_file(Array('entries' => 'add_participants.tpl'));
199                        else   
200                                $p->set_file(Array('entries' => 'add_recipients.tpl'));
201                               
202                        $p->set_block('entries','body');
203                        $p->set_block('entries','people_header');
204                        $p->set_block('entries','group_header');
205                        $p->set_block('entries','row');
206                        $p->set_block('entries','row_group');
207                        $p->set_block('entries','row_empty');
208                        $p->set_block('entries','option');
209                        $p->set_block('entries','page');
210                        $p->set_block('entries','page_no_link');
211                        $p->set_block('entries','row_addeds');
212                       
213                       
214                        $texts = array(
215                                'lang_name' => lang("Name"),
216                                'lang_catalog' => lang("Catalog"),
217                                'lang_search' => lang("Search")
218                                );
219                        $p->set_var($texts);
220
221                        $p->set_var('lang_already_addeds:',lang('already_addeds:'));
222
223                        if($from_calendar == 'mobilecalendar')
224                                $p->set_var('lang_continue_scheduling',lang('continue scheduling'));
225                        else if($from_calendar == 'mobilemail'){
226                                $p->set_var('lang_continue',lang('continue'));
227                        }
228
229                        /////////// Preenche o combo de catálogos
230                       
231                        $bo_cc = CreateObject("contactcenter.bo_contactcenter");
232                        $branchs = $bo_cc->get_catalog_tree();
233                       
234                        if(!$from_calendar || $from_calendar == 'mobilemail') {
235                                foreach($branchs as $branch) { //Pego apenas a estrutura dos ramos vindos do banco, pois as do ldap estão confusas e com dados aparentemente inconsistentes.
236                                        if($branch['class']!="bo_global_ldap_catalog" && $branch['class']!="bo_catalog_group_catalog") {
237                                                $p->set_var(array('option_value'=>$branch['class'],'option_text'=>$branch['name']));
238       
239                                                if($this->page_info['actual_catalog']==$branch['class'])
240                                                        $p->set_var('selected','selected');
241                                                else
242                                                        $p->set_var('selected','');
243                                                $p->parse('options','option',True);
244                                        }
245                                               
246                                }
247                        }
248                       
249                        /////////// Preenche o combo, com dados do ldap
250                        $bo_ldap_manager = CreateObject("contactcenter.bo_ldap_manager");
251                        $branchs = $bo_ldap_manager->get_all_ldap_sources();
252                       
253                        foreach($branchs as $id=>$branch) { //Ldaps expresso
254                                $p->set_var(array('option_value'=>"bo_global_ldap_catalog#".
255                                                $id."#".
256                                                $branch['dn']."#".
257                                                0,
258                                                'option_text'=>$branch['name'])); //No value eu passo também o id, o contexto e se é externo, quando é um ldap
259
260                                if($this->page_info['actual_catalog']=="bo_global_ldap_catalog#".$id."#".$branch['dn']."#". 0)
261                                        $p->set_var('selected','selected');
262                                else
263                                        $p->set_var('selected','');
264                                $p->parse('options','option',True);     
265                        }
266                       
267                        if(!$from_calendar  || $from_calendar == 'mobilemail') {
268                                $branchs = $bo_ldap_manager->get_external_ldap_sources();
269                                if(is_array($branchs)) foreach($branchs as $id=>$branch) { //Ldaps externos
270                                        $p->set_var(array('option_value'=>"bo_global_ldap_catalog#".
271                                                        $id."#".
272                                                        $branch['dn']."#".
273                                                        1,
274                                                        'option_text'=>$branch['name'])); //No value eu passo também o id, o contexto e se é externo, quando é um ldap
275       
276                                        if($this->page_info['actual_catalog']=="bo_global_ldap_catalog#".$id."#".$branch['dn']."#". 1)
277                                                $p->set_var('selected','selected');
278                                        else
279                                                $p->set_var('selected','');
280                                        $p->parse('options','option',True);     
281                                }
282                        }
283
284                        /////////// Monta o resultado da pesquisa
285                        $p->set_var('th_theme',$GLOBALS['phpgw_info']['theme']['th_bg']);
286                                               
287                        if(empty($entries) && isset($_POST["name"]) && count($_SESSION["mobile_search_ids"])<=100 && strlen($_POST['name'])>=4) { //Se foi feita a busca e não teve resultados...
288                                $p->set_var('message',lang('No matches found'));
289                                $p->parse('rows','row_empty',True);
290                        }
291                        else if(count($_SESSION["mobile_search_ids"])>100) { //Muitos resultados...
292                                $p->set_var('message',lang('too many results'));
293                                $p->parse('rows','row_empty',True);                     
294                        }
295                        else if(isset($_POST["name"]) && strlen($_POST['name'])<4) { //Muitos resultados...
296                                $p->set_var('message',lang('the search argument must have at least 4 digits'));
297                                $p->parse('rows','row_empty',True);                     
298                        }
299                        else if((isset($_POST["name"])) || (isset($_GET["page"]))){ //Renderizar...
300                               
301                                /////////// Preenche o cabeçalho da consulta
302                                if($this->page_info['actual_catalog']!="bo_group_manager") {
303                                        $p->set_var(
304                                                        array('lang_people_name' => lang("Name"),
305                                                                'lang_phone' => lang("Phone"),
306                                                                'lang_mail' => lang("Email")));
307                                        $p->parse('header','people_header',True);
308                                }
309                                else {
310                                        $p->set_var(
311                                                        array('lang_group_name' => lang("Name"),
312                                                                'lang_title' => lang("Title")
313                                                                ));
314                                        $p->parse('header','group_header',True);
315                                }
316                               
317                                /////////// Preencho as linhas do resultado
318                                foreach($entries as $id => $entry) {
319                                        $this->nextmatchs->template_alternate_row_color($p);
320                                        if(($this->page_info['actual_catalog']!="bo_group_manager") &&
321                                                         (strpos($this->page_info['actual_catalog'],'bo_global_ldap_catalog')===false)){ //People
322                                                $var = array('row_nome'=>$entry['names_ordered']);
323                                                $conn1 = array_shift($entry['connections']);
324                                                if(($conn1==NULL)||($conn1['connection_is_default']!=1)) {
325                                                        $var['row_telefone'] = '&nbsp;';
326                                                        $var['row_email'] = '&nbsp;';
327                                                }
328                                                else if($conn1['id_type']==1) {
329                                                        $var['row_email'] = $conn1['connection_value'];
330                                                        $conn2=array_shift($entry['connections']);
331                                                        if(($conn2==NULL)||($conn2['connection_is_default']!=1))
332                                                                $var['row_telefone'] = '&nbsp';
333                                                        else
334                                                                $var['row_telefone'] = $conn2['connection_value'];
335                                                }
336                                                else if($conn1['id_type']==2) {
337                                                        $var['row_email'] = '&nbsp;';
338                                                        $var['row_telefone'] = $conn1['connection_value'];
339                                                }
340                                                $var['form_action'] = "index.php?menuaction=mobile.ui_mobilemail.new_msg";
341                                                $p->set_var($var);
342                                                $p->parse('rows','row',True);
343                                        }
344                                        else if($this->page_info['actual_catalog']=="bo_group_manager"){ //Grupos
345                                                $var = array(
346                                                                'row_group_name'=>$entry['short_name'],
347                                                                'row_title' => $entry['title']
348                                                                );
349                                               
350                                                $p->set_var($var);
351                                                $p->parse('rows','row_group',True);
352                                        }
353                                        else { //Ldap
354                                                $var = array('row_nome'=>$entry['names_ordered'][0]);
355                                                $conn1 = array_shift($entry['connections']);
356                                                if(($conn1==NULL)) {
357                                                        $var['row_telefone'] = '&nbsp;';
358                                                        $var['row_email'] = '&nbsp;';
359                                                }
360                                                else if($conn1['id_type']==1) {
361                                                        $var['row_email'] = $conn1['connection_value'];
362                                                        $conn2=array_shift($entry['connections']);
363                                                        if($conn2==NULL)
364                                                                $var['row_telefone'] = '&nbsp';
365                                                        else
366                                                                $var['row_telefone'] = $conn2['connection_value'];
367                                                }
368                                                else if($conn1['id_type']==2) {
369                                                        $var['row_email'] = '&nbsp;';
370                                                        $var['row_telefone'] = $conn1['connection_value'];
371                                                }
372                                                if(!$from_calendar)
373                                                        $var['form_action'] = "index.php?menuaction=mobile.ui_mobilemail.new_msg";
374                                                else if($from_calendar == 'mobilecalendar'){
375                                                        $var['id_contact'] = $entry['uidnumber'][0].'U';
376                                                        $var['form_action'] = "index.php?menuaction=mobile.ui_mobilecalendar.add_participant";
377                                                }else{
378                                                        $var['id_contact'] = $entry['uidnumber'][0].'U';
379                                                        $var['form_action'] = "index.php?menuaction=mobile.ui_mobilemail.add_recipient";
380                                                }
381                                                $var['lang_select'] = lang("select");
382                                                $p->set_var($var);
383                                                $p->parse('rows','row',True);
384                                        }
385                                }
386                        }
387                       
388                        if($from_calendar == 'mobilemail') {
389                                $p->set_var('lang_choose_the_recipients',lang("choose the recipients"));
390                                $participants = $_SESSION['mobile_mail'];
391                                reset($participants);
392                                while (($participant = current($participants))!==false) {
393                                        $p->set_var('row_contact_name',$participant);
394                                        if(next($participants)!==false)
395                                                $p->set_var('row_separate',',');
396                                        else
397                                                $p->set_var('row_separate','.');
398                                        $p->parse('rows_addeds','row_addeds',True);
399                                }
400                        }else if($from_calendar == 'mobilecalendar'){
401                                $p->set_var('lang_choose_the_participants',lang("choose the participants"));
402                                $participants = $_SESSION['mobile_calendar'];
403                                reset($participants);
404                                while (($participant = current($participants))!==false) {
405                                        $p->set_var('row_contact_name',$participant);
406                                        if(next($participants)!==false)
407                                                $p->set_var('row_separate',',');
408                                        else
409                                                $p->set_var('row_separate','.');
410                                        $p->parse('rows_addeds','row_addeds',True);
411                                }                               
412                        }
413                       
414                        ////////////////// Monto a paginação
415                        if(!empty($entries) && count($_SESSION["mobile_search_ids"])<=100) {
416                                $num_pages = count($_SESSION["mobile_search_ids"])/10;
417                               
418                                if((count($_SESSION["mobile_search_ids"])%10!=0) || ($num_pages<1))
419                                        $num_pages++;
420                                if($actual_page!=0) {
421                                        for($i=1;$i<=$num_pages;$i++) {
422                                                $p->set_var('num_page',$i);
423                                                $p->set_var('display_page',$i);
424                                                if($i!=$actual_page)
425                                                        $p->parse('pages','page',True);
426                                                else
427                                                        $p->parse('pages','page_no_link',True);
428                                        }
429                                }
430                               
431                                if($actual_page>1) {
432                                        $p->set_var('num_page',$actual_page-1);
433                                        $p->set_var('display_page','<');
434                                        $p->parse('back','page',True);
435                                }
436                               
437                                if(($actual_page!=floor($num_pages)) && (floor($num_pages)>1) && ($actual_page!=0)) {
438                                        $p->set_var('num_page',$actual_page+1);
439                                        $p->set_var('display_page','>');
440                                        $p->parse('next','page',True);
441                                }       
442                        }                       
443                       
444                        //$p->pfp('out','body');
445                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body'));
446                }
447               
448        }
449?>
Note: See TracBrowser for help on using the repository browser.