source: branches/2.3/ac/inc/class.ui_mobilecc.inc.php @ 5107

Revision 5107, 15.3 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #2286 - Adicionado modulo acessivel ao Expresso.

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}
32                        else {
33                                $exploded = explode("#",$catalog);
34                                $this->bo= CreateObject("contactcenter.bo_global_ldap_catalog",$exploded[1],$exploded[2],$exploded[3]);
35                                if($exploded[3]==1)
36                                        $this->page_info['is_external_catalog'] = true;
37                                else {
38                                        $this->page_info['is_external_catalog'] = false;
39                                }
40                                       
41                        }
42                        $this->page_info['actual_catalog'] = $catalog;
43                }
44               
45                /**
46                 * Busca um nome a partir do catálogo. Se nenhum for informado previamente,
47                 * retorna um array vazio.
48                 *
49                 * Caso o catálogo atual seja grupos, a busca será por títulos, caso seja
50                 * contatos pessoais, será por names_ordered, se for contato no ldap, será
51                 * por cn.
52                 *
53                 * @return array, com os ids relativos a busca
54                 * @param $name string com o nome à ser buscado.
55                 */
56                public function find($name) {
57                        if(!$this->page_info["actual_catalog"])
58                                return array();
59                       
60                        if($this->page_info['actual_catalog']=="bo_group_manager") { //parametros de busca para grupos
61                                $id = 'group.id_group';
62                                $what = array('group.title',$id);
63                                $search = "group.title";
64                        }
65                        else { //parametros de busca para pessoas
66                                $id = 'contact.id_contact';
67                                $search = "contact.names_ordered";
68                                $what = array('contact.names_ordered',$id);
69                        }
70                       
71                        if ((strpos($this->page_info["actual_catalog"],'bo_global_ldap_catalog')!==false) &&
72                                        (!$this->page_info['is_external_catalog'])) { //Ldap do expresso, leva em conta alguns atributos do expresso
73
74                                array_push($what,'contact.object_class',
75                                                'contact.account_visible',
76                                                'contact.account_status'
77                                                );
78                               
79                                $rules = array(
80                                                        0 => array(
81                                                                'field' => 'contact.object_class',
82                                                                'type'  => '=',
83                                                                'value' => 'phpgwAccount'
84                                                        ),
85                                                        1 => array(
86                                                                'field' => 'contact.account_status',
87                                                                'type'  => 'iLIKE',
88                                                                'value' => '%'
89                                                        ),
90                                                        2 => array(
91                                                                'field' => 'contact.account_visible',
92                                                                'type'  => '!=',
93                                                                'value' => '-1'
94                                                        ),
95                                                        3 => array(
96                                                                'field' => 'contact.object_class',
97                                                                'type'  => '=',
98                                                                'value' => 'inetOrgPerson'
99                                                        )
100                                                );
101                        }
102                        else{
103                                $rules = array();
104                        }
105
106                       
107                       
108                        if ($name != '') { //String em branco, não preciso adicionar essa regra
109                                array_push($rules,array(
110                                                                'field' => $search,
111                                                                'type'  => 'iLIKE',
112                                                                'value' => '%'.$name.'%'
113                                                        ));             
114                        }
115                                                                                                               
116                        $ids = $this->bo->find($what,$rules);
117
118                        if(is_array($ids)) foreach($ids as $id_r) { //Quero apenas os ids, como valores nas posições do array
119                                $retorno[] = $id_r[substr($id,strpos($id,".")+1)];
120                        }
121                       
122                        return $retorno;
123                }
124               
125                /**
126                 * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita
127                 * busca, mostra apenas o formulário para pesquisa.
128                 *
129                 * @return
130                 */
131               
132                function contacts_list($from_calendar=false) {
133                        $entries = array();
134                        $actual_page = 0;
135
136                        if(isset($_POST['name']) && strlen($_POST['name'])<2) //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'])<2)) {
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'])>=2) { //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'])<2) { //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_mobile'           => "Celular",
307                                                                'lang_mail'             => lang("Email")));
308                                        $p->parse('header','people_header',True);
309                                }
310                                else {
311                                        $p->set_var(
312                                                        array('lang_group_name' => lang("Name"),
313                                                                'lang_title' => lang("Title")
314                                                                ));
315                                        $p->parse('header','group_header',True);
316                                }
317                               
318                                /////////// Preencho as linhas do resultado
319                                foreach($entries as $id => $entry) {
320                                        $this->nextmatchs->template_alternate_row_color($p);
321                                        if(($this->page_info['actual_catalog']!="bo_group_manager") &&
322                                                         (strpos($this->page_info['actual_catalog'],'bo_global_ldap_catalog')===false)){ //People
323                                                $var = array(
324                                                                'row_nome'      => $entry['names_ordered'],
325                                                                'row_mobile'    => $entry['contact']['business_info']['celPhone']
326                                                        );
327                                                $conn1 = array_shift($entry['connections']);
328                                                if(($conn1==NULL)||($conn1['connection_is_default']!=1)) {
329                                                        $var['row_telefone'] = '&nbsp;';
330                                                        $var['row_email'] = '&nbsp;';
331                                                }
332                                                else if($conn1['id_type']==1) {
333                                                        $var['row_email'] = $conn1['connection_value'];
334                                                        $conn2=array_shift($entry['connections']);
335                                                        if(($conn2==NULL)||($conn2['connection_is_default']!=1))
336                                                                $var['row_telefone'] = '&nbsp';
337                                                        else
338                                                                $var['row_telefone'] = $conn2['connection_value'];
339                                                }
340                                                else if($conn1['id_type']==2) {
341                                                        $var['row_email'] = '&nbsp;';
342                                                        $var['row_telefone'] = $conn1['connection_value'];
343                                                }
344                                                $var['form_action'] = "index.php?menuaction=ac.ui_mobilemail.new_msg";
345                                                $p->set_var($var);
346                                                $p->parse('rows','row',True);
347                                        }
348                                        else if($this->page_info['actual_catalog']=="bo_group_manager"){ //Grupos
349                                                $var = array(
350                                                                'row_group_name'=>$entry['short_name'],
351                                                                'row_title' => $entry['title']
352                                                                );
353                                               
354                                                $p->set_var($var);
355                                                $p->parse('rows','row_group',True);
356                                        }
357                                        else { //Ldap
358                                                $var = array('row_nome'=>$entry['names_ordered'][0],'row_mobile'=>$entry['companies']['company1']['celPhone']);
359
360                                                $conn1 = array_shift($entry['connections']);
361                                                if(($conn1==NULL)) {
362                                                        $var['row_telefone'] = '&nbsp;';
363                                                        $var['row_email'] = '&nbsp;';
364                                                }
365                                                else if($conn1['id_type']==1) {
366                                                        $var['row_email'] = $conn1['connection_value'];
367                                                        $conn2=array_shift($entry['connections']);
368                                                        if($conn2==NULL)
369                                                                $var['row_telefone'] = '&nbsp';
370                                                        else
371                                                                $var['row_telefone'] = $conn2['connection_value'];
372                                                }
373                                                else if($conn1['id_type']==2) {
374                                                        $var['row_email'] = '&nbsp;';
375                                                        $var['row_telefone'] = $conn1['connection_value'];
376                                                }
377                                                if(!$from_calendar)
378                                                        $var['form_action'] = "index.php?menuaction=ac.ui_mobilemail.new_msg";
379                                                else if($from_calendar == 'mobilecalendar'){
380                                                        $var['id_contact'] = $entry['uidnumber'][0].'U';
381                                                        $var['form_action'] = "index.php?menuaction=mobile.ui_mobilecalendar.add_participant";
382                                                }else{
383                                                        $var['id_contact'] = $entry['uidnumber'][0].'U';
384                                                        $var['form_action'] = "index.php?menuaction=ac.ui_mobilemail.add_recipient";
385                                                }
386                                                $var['lang_select'] = lang("select");
387                                                $p->set_var($var);
388                                                $p->parse('rows','row',True);
389                                        }
390                                }
391                        }
392                       
393                        if($from_calendar == 'mobilemail') {
394                                $p->set_var('lang_choose_the_recipients',lang("choose the recipients"));
395                                $participants = $_SESSION['mobile_mail'];
396                                reset($participants);
397                                while (($participant = current($participants))!==false) {
398                                        $p->set_var('row_contact_name',$participant);
399                                        if(next($participants)!==false)
400                                                $p->set_var('row_separate',',');
401                                        else
402                                                $p->set_var('row_separate','.');
403                                        $p->parse('rows_addeds','row_addeds',True);
404                                }
405                        }else if($from_calendar == 'mobilecalendar'){
406                                $p->set_var('lang_choose_the_participants',lang("choose the participants"));
407                                $participants = $_SESSION['mobile_calendar'];
408                                @reset($participants);
409                                while (($participant = current($participants))!==false) {
410                                        $p->set_var('row_contact_name',$participant);
411                                        if(next($participants)!==false)
412                                                $p->set_var('row_separate',',');
413                                        else
414                                                $p->set_var('row_separate','.');
415                                        $p->parse('rows_addeds','row_addeds',True);
416                                }
417                        }
418                       
419                        ////////////////// Monto a paginação
420                        if(!empty($entries) && count($_SESSION["mobile_search_ids"])<=100) {
421                                $num_pages = count($_SESSION["mobile_search_ids"])/10;
422                               
423                                if((count($_SESSION["mobile_search_ids"])%10!=0) || ($num_pages<1))
424                                        $num_pages++;
425                                if($actual_page!=0) {
426                                        for($i=1;$i<=$num_pages;$i++) {
427                                                $p->set_var('num_page',$i);
428                                                $p->set_var('display_page',$i);
429                                                if($i!=$actual_page)
430                                                        $p->parse('pages','page',True);
431                                                else
432                                                        $p->parse('pages','page_no_link',True);
433                                        }
434                                }
435                               
436                                if($actual_page>1) {
437                                        $p->set_var('num_page',$actual_page-1);
438                                        $p->set_var('display_page','<');
439                                        $p->parse('back','page',True);
440                                }
441                               
442                                if(($actual_page!=floor($num_pages)) && (floor($num_pages)>1) && ($actual_page!=0)) {
443                                        $p->set_var('num_page',$actual_page+1);
444                                        $p->set_var('display_page','>');
445                                        $p->parse('next','page',True);
446                                }       
447                        }                       
448                       
449                        //$p->pfp('out','body');
450                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body'));
451                }
452               
453        }
454?>
Note: See TracBrowser for help on using the repository browser.