source: trunk/expressoAdmin1_2/inc/class.boconfiguration.inc.php @ 5144

Revision 5144, 32.6 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus. ExpressoAdmin: adicionando arquivos.

Line 
1<?php
2require_once 'class.soconfiguration.inc.php';
3require_once 'class.ldap_functions.inc.php';
4require_once 'class.functions.inc.php';
5require_once 'class.db_functions.inc.php';
6
7    class boconfiguration
8    {
9
10        var $soConfiguration;
11        var $ldapFunctions;
12        var $functions;
13        var $dbFunctions;
14
15        function boconfiguration()
16        {
17                    $this->soConfiguration = new soconfiguration();
18                    $this->ldapFunctions = new ldap_functions();
19                    $this->functions = new functions();
20                    $this->dbFunctions = new db_functions();
21        }
22                   
23        /**
24         * Busca as organizações do ldap
25         * @param string $context
26         * @param string $selected
27         * @param bool $recursive
28         * @return string Ex. <option value='xxx'>xxx</option>
29         */
30       function getSelectOrganizations($context, $selected='', $recursive = true)
31       {
32           $s = CreateObject('phpgwapi.sector_search_ldap');
33           return ($recursive ?
34                        $s->get_organizations($context, $selected, false ,false) :
35                        $s->get_sectors($selected, false, false));
36       }
37
38       /**
39        * Busca usuarios e retorna em options para o select
40        * @param <array> $params [filter] = busca, [context] = contexto do ldap
41        * @return string Ex. <option value='xxx'>xxx</option>
42        */
43       function searchUsersForSelect($params)
44       {
45
46          $retornoLDAP = $this->ldapFunctions->get_available_users3($params);
47
48          return $retornoLDAP['users'];
49       }
50
51       /**
52        * Busca Grupos e retorna em options para o select
53        * @param <array> $params [filter] = busca, [context] = contexto do ldap
54        * @return string Ex. <option value='xxx'>xxx</option>
55        */
56       function searchGroupsForSelect($params)
57       {
58
59          $retornoLDAP = $this->ldapFunctions->get_available_users3($params);
60
61          return $retornoLDAP['groups'];
62       }
63
64        /**
65        * Busca usuarios e Grupos e retorna em options para o select
66        * @param <array> $params [filter] = busca, [context] = contexto do ldap
67        * @return string Ex. <option value='xxx'>xxx</option>
68        */
69       function searchUsersAndGroupsForSelect($params)
70       {
71
72          $returnLDAP = $this->ldapFunctions->get_available_users3($params);
73          $options = '';
74          if($returnLDAP['users2'] != null)
75          {
76              $options .= '<option value ="-1" disabled>----------------------'.$this->functions->lang('users').'----------------------- </option>';
77              $options .=$returnLDAP['users2'];
78          }
79          if($returnLDAP['groups2'] != null )
80          {
81              $options .= '<option value ="-1" disabled>----------------------'.$this->functions->lang('groups').'----------------------- </option>';
82              $options .= $returnLDAP['groups2'];
83          }
84          return $options;
85       }
86
87       /**
88        * Busca Contas Institucionais e retorna em options para o select
89        * @param <array> $params [filter] = busca, [context] = contexto do ldap
90        * @return string Ex. <option value='xxx'>xxx</option>
91        */
92       function searchInstitutionalAccountsForSelect($params)
93       {
94          $retornoLDAP = $this->ldapFunctions->get_available_shared_account($params);
95
96          return $retornoLDAP;
97       }
98
99       /**
100        * Cria ou sobrescreve regra de limit de destinatarios por usuario.
101        * @param <array> $params
102        * @return <array> ['status'] = True ou False, ['msg'] = Mensagem de erro;
103        */
104       function createLimitRecipientsByUser($params)
105       {
106
107           if(!$params['selectUsersInRule'])
108                return array('status' => false , 'msg' => 'no user  selected');
109
110           if(!$params['inputTextMaximumRecipientsUserModal'])
111               $params['inputTextMaximumRecipientsUserModal'] = 0 ;
112
113            foreach ($params['selectUsersInRule'] as $userInRule)
114            {
115                //Verifica se este usuario Já tem uma regra
116                $userInRuleDB = $this->soConfiguration->getRuleInDb('where configuration_type = \'LimitRecipient\' AND email_user = \''.$userInRule.'\' AND email_user_type = \'U\' ');
117               
118                if(count($userInRuleDB) > 0)
119                {
120                     $fields = array(
121                            'email_user' => $userInRule,
122                            'configuration_type' => 'LimitRecipient',
123                            'email_max_recipient' => $params['inputTextMaximumRecipientsUserModal'],
124                            'email_user_type' => 'U'
125                           );
126
127                      if(!$this->soConfiguration->updatetRuleInDb($userInRuleDB[0]['id'],$fields))
128                            return array('status' => false , 'msg' => 'Error on Updating');
129                      else
130                            $this->dbFunctions->write_log ('Update Limit Recipients By User', $userInRule);
131
132                }
133                else
134                {
135                    $fields = array(
136                                'email_user' => $userInRule,
137                                'configuration_type' => 'LimitRecipient',
138                                'email_max_recipient' => $params['inputTextMaximumRecipientsUserModal'],
139                                'email_user_type' => 'U'
140                               );
141
142                    if(!$this->soConfiguration->insertRuleInDb($fields))
143                            return array('status' => false , 'msg' => 'Error on insert');
144                    else
145                            $this->dbFunctions->write_log ('Create Limit Recipients By User', $userInRule);
146               
147                }
148
149            }
150
151           return array('status' => true);
152       }
153
154        /**
155        * Cria ou sobrescreve regra de limit de destinatarios por Grupo.
156        * @param <array> $params
157        * @return <array> ['status'] = True ou False, ['msg'] = Mensagem de erro;
158        */
159       function createLimitRecipientsByGroup($params)
160       {
161
162           if(!$params['selectGroupsInRule'])
163                return array('status' => false , 'msg' => 'no user  selected');
164
165           if(!$params['inputTextMaximumRecipientsGroupModal'])
166               $params['inputTextMaximumRecipientsGroupModal'] = 0 ;
167
168            foreach ($params[selectGroupsInRule] as $groupInRule)
169            {
170                //Verifica se este usuario Já tem uma regra
171                $groupInRuleDB = $this->soConfiguration->getRuleInDb('where configuration_type = \'LimitRecipient\' AND email_user = \''.$groupInRule.'\' AND email_user_type = \'G\' ');
172
173                if(count($groupInRuleDB) > 0)
174                {
175                     $fields = array(
176                            'email_user' => $groupInRule,
177                            'configuration_type' => 'LimitRecipient',
178                            'email_max_recipient' => $params['inputTextMaximumRecipientsGroupModal'],
179                            'email_user_type' => 'G'
180                           );
181
182                      if(!$this->soConfiguration->updatetRuleInDb($groupInRuleDB[0]['id'],$fields))
183                            return array('status' => false , 'msg' => 'Error on Updating');
184                      else
185                            $this->dbFunctions->write_log ('Update Limit Recipients By Group', $groupInRule);
186
187                }
188                else
189                {
190                    $fields = array(
191                                'email_user' => $groupInRule,
192                                'configuration_type' => 'LimitRecipient',
193                                'email_max_recipient' => $params['inputTextMaximumRecipientsGroupModal'],
194                                'email_user_type' => 'G'
195                               );
196
197                    if(!$this->soConfiguration->insertRuleInDb($fields))
198                            return array('status' => false , 'msg' => 'Error on insert');
199                    else
200                            $this->dbFunctions->write_log ('Create Limit Recipients By Group', $groupInRule);
201
202
203                }
204
205            }
206
207           return array('status' => true);
208       }
209
210       /**
211        * Busca todas as regras LimitRecipientsByUser para a tabela
212        * @return string Linhas e celulas de tabela
213        */
214       function getTableRulesLimitRecipientsByUser($edit = false)
215       {
216           $filter = 'WHERE configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' ORDER BY email_user';
217           $fields = array('id','email_user','email_max_recipient');
218           $rules = $this->soConfiguration->getRuleInDb($filter, $fields);
219
220           $return = '';
221           $zebra = 1;
222           foreach ($rules as $rule)
223           {
224               //Resgata informaçoes do usuario do ldap
225               if($zebra == 0)
226               {
227                    $return.= '<tr bgcolor='.$GLOBALS['phpgw_info']['theme']['row_on'].' >';
228                    $zebra = 1;
229               }
230               else
231               {
232                   $return.= '<tr bgcolor='.$GLOBALS['phpgw_info']['theme']['row_off'].' >';
233                   $zebra = 0;
234               }
235               $return.= '<td>'.utf8_encode($this->ldapFunctions->get_user_cn_by_uid($rule['email_user'])).'</td>';
236
237               if($rule['email_max_recipient'] > 0)
238                    $return.= '<td>'.$rule['email_max_recipient'].'</td>';
239               else
240                    $return.= '<td>'.$this->functions->make_lang('lang_no_limit').'</td>';
241               if($edit == true)
242               {
243                   $return.= '<td><a href="javascript:editLimitRecipientesByUser(\''.$rule['id'].'\')" >'.$this->functions->make_lang('lang_edit').'</a></td>';
244                   $return.= '<td><a href="javascript:removeLimitRecipientsByUser(\''.$rule['id'].'\')" >'.$this->functions->make_lang('lang_remove').'</a></td>';
245               }
246               else
247               {
248                   $return.= '<td>'.$this->functions->make_lang('lang_edit').'</td>';
249                   $return.= '<td>'.$this->functions->make_lang('lang_remove').'</td>';
250
251               }
252
253                   $return.= '</tr>';
254           }
255       
256           return utf8_decode($return);
257       }
258
259        /**
260        * Busca todas as regras LimitRecipientsByGroup para a tabela
261        * @return string tabela
262        */
263       function getTableRulesLimitRecipientsByGroup($edit = false)
264       {
265           $filter = 'WHERE configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' ORDER BY email_user';
266           $fields = array('id','email_user','email_max_recipient');
267           $rules = $this->soConfiguration->getRuleInDb($filter, $fields);
268
269           $return = '';
270           $zebra = 1;
271           foreach ($rules as $rule)
272           {
273               //Resgata informaçoes do usuario do ldap
274                if($zebra == 0)
275               {
276                    $return.= '<tr bgcolor='.$phpgw_info['theme']['row_on'].' >';
277                    $zebra = 1;
278               }
279               else
280               {
281                   $return.= '<tr bgcolor='.$phpgw_info['theme']['row_off'].' >';
282                   $zebra = 0;
283               }
284               $return.= '<td>'.utf8_encode($this->ldapFunctions->get_group_cn_by_gidnumber($rule['email_user'])).'</td>';
285
286               if($rule['email_max_recipient'] > 0)
287                    $return.= '<td>'.$rule['email_max_recipient'].'</td>';
288               else
289                    $return.= '<td>'.$this->functions->make_lang('lang_no_limit').'</td>';
290
291               if($edit == true)
292               {
293                   $return.= '<td><a href="javascript:editLimitRecipientesByGroup(\''.$rule['id'].'\')" >'.$this->functions->make_lang('lang_edit').'</a></td>';
294                   $return.= '<td><a href="javascript:removeLimitRecipientsByGroup(\''.$rule['id'].'\')" >'.$this->functions->make_lang('lang_remove').'</a></td>';
295               }
296               else
297               {
298                   $return.= '<td>'.$this->functions->make_lang('lang_edit').'</td>';
299                   $return.= '<td>'.$this->functions->make_lang('lang_remove').'</td>';
300     
301               }
302               $return.= '</tr>';
303           }
304                     
305           return utf8_decode($return);
306       }
307
308       /**
309        * Remove regra
310        * @param array $params [id]
311        * @return array [status] = true or false,[msg] = mensagem de erro
312        */
313       function removeLimitRecipientsByUser($params)
314       {
315
316           $rule = $this->soConfiguration->getRuleInDb('Where id = \''.$params['id'].'\'');
317
318          if($this->soConfiguration->removeRuleInDb($params['id']))
319          {
320            $this->dbFunctions->write_log ('Removed Limit Recipients By User', $rule['0']['email_user']);
321            return array('status' => true);
322          }
323          else
324            return array('status' => false , 'msg' => 'Error on remove');
325       }
326
327       /**
328        * Remove regra
329        * @param array $params [id]
330        * @return array [status] = true or false,[msg] = mensagem de erro
331        */
332       function removeLimitRecipientsByGroup($params)
333       {
334
335          $rule = $this->soConfiguration->getRuleInDb('Where id = \''.$params['id'].'\'');
336
337          if($this->soConfiguration->removeRuleInDb($params['id']))
338          {
339            $this->dbFunctions->write_log ('Removed Limit Recipients By Group', $rule['0']['email_user']);
340            return array('status' => true);
341          }
342          else
343            return array('status' => false , 'msg' => 'Error on remove');
344       }
345
346       /**
347        * Remove regra
348        * @param array $params [id]
349        * @return array [status] = true or false,[msg] = mensagem de erro
350        */
351       function removeBlockEmailForInstitutionalAcounteExeption($params)
352       {
353          $recipient = explode(',', $params['recipient']);
354
355          if($params['recipient'] == '*')
356              $recipient['1'] = 'A';
357
358          $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\' AND email_user_type = \''.$recipient['1'].'\' ';
359          $fields = array('id','email_user');
360          $rules = $this->soConfiguration->getRuleInDb($filter, $fields);         
361
362          foreach ($rules as $rule)
363          {
364             if(!$this->soConfiguration->removeRuleInDb($rule['id']))
365                  return array('status' => false , 'msg' => 'Error on remove');
366             else
367                  $this->dbFunctions->write_log ('Removed BlockEmail For Institutional AcounteExeption', $rule['email_user']);
368          }
369         
370            return array('status' => true);
371       
372       }
373       
374       /**
375        * Carrega as informaçoes da regra para ser editada
376        * @param array $params [id] = Id da regra
377        * @return array retorna a rule em um array
378        */
379       function editLimitRecipientesByUser($params)
380       {
381
382           $filter = 'WHERE id = \''.$params['id'].'\'';
383           $rules = $this->soConfiguration->getRuleInDb($filter);
384
385           if($rules)
386           {
387              //Resgata informaçoes do usuario do ldap
388              $rules[0]['userCn'] = $this->ldapFunctions->get_user_cn_by_uid($rules[0]['email_user']);
389              $rules[0]['status'] = true;
390              return $rules[0];
391           }
392           else
393              return array('status' => false , 'msg' => 'Error on read rule');
394       }
395
396         /**
397        * Carrega as informaçoes da regra para ser editada
398        * @param array $params [id] = Id da regra
399        * @return array retorna a rule em um array
400        */
401       function editLimitRecipientesByGroup($params)
402       {
403
404           $filter = 'WHERE id = \''.$params['id'].'\'';
405           $rules = $this->soConfiguration->getRuleInDb($filter);
406
407           if($rules)
408           {
409              //Resgata informaçoes do usuario do ldap
410              $rules[0]['groupCn'] = $this->ldapFunctions->get_group_cn_by_gidnumber($rules[0]['email_user']);
411              $rules[0]['status'] = true;
412              return $rules[0];
413           }
414           else
415              return array('status' => false , 'msg' => 'Error on read rule');
416       }
417
418       /**
419        * Cria ou sobrescreve resgras de Institutional Account Exception
420        * @param array $params
421        * @return array [status] = true or false,[msg] = mensagem de erro
422        */
423       function createBlockEmailForInstitutionalAcounteExeption($params)
424       {
425         
426           if(!$params['selectUsersOrGroupsInRule'] &&  !$params['inputCheckAllRecipientsInstitutionalAccountRule'])
427                return array('status' => false , 'msg' => 'no recipients selecteds');
428
429           if(!$params['selecSendersInRule'] &&  !$params['inputCheckAllSendersInstitutionalAccountRule'])
430                return array('status' => false , 'msg' => 'no senders selecteds');
431
432           if($params['inputCheckAllRecipientsInstitutionalAccountRule'] && $params['inputCheckAllSendersInstitutionalAccountRule'])
433                return array('status' => false , 'msg' => 'all senders and all recipients selecteds');
434
435
436
437
438           if($params['inputCheckAllRecipientsInstitutionalAccountRule'])
439           {
440
441                 //resgata todas as regras de all Recipients
442                 $condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'A\' ';
443                 $fields = array('id');
444                 $rules = $this->soConfiguration->getRuleInDb($condition,$fields);
445
446                 //Remove todas as regras de all Recipients
447                 foreach ($rules as $rule)
448                     $this->soConfiguration->removeRuleInDb($rule['id']);
449
450                 //Insere as novas Regras
451                 foreach($params['selecSendersInRule'] as $senderInRule)
452                 {
453                     $fields = array(
454                            'email_user' => '*',
455                            'email_recipient' => $senderInRule,
456                            'configuration_type' => 'InstitutionalAccountException',
457                            'email_user_type' => 'A'
458                           );
459
460                      if(!$this->soConfiguration->insertRuleInDb($fields))
461                        return array('status' => false , 'msg' => 'Error on insert');
462                      else
463                        $this->dbFunctions->write_log ('Create BlockEmail For Institutional AcounteExeption', 'All');
464                   
465                 }
466
467           }
468           else
469           {
470                 //intera todos os usuarios ou grupos selecionados
471                 foreach($params['selectUsersOrGroupsInRule'] as $userOrGroupT)
472                 {
473
474                     $userOrGroupA = explode(',', $userOrGroupT);
475                     $userOrGroup = $userOrGroupA['0'];
476
477                     if($userOrGroupA['1'] == 'G')
478                     {
479                      //Caso seja um grupo
480
481                         //resgata todas as regras
482                         $condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' AND email_user = \''.$userOrGroup.'\' ';
483                         $fields = array('id');
484                         $rules = $this->soConfiguration->getRuleInDb($condition,$fields);
485
486                         //Remove todas as regras
487                         foreach ($rules as $rule)
488                             $this->soConfiguration->removeRuleInDb($rule['id']);
489
490                         //Se todos os senders estiverem selecionados
491                         if($params['inputCheckAllSendersInstitutionalAccountRule'])
492                         {
493                             $fields = array(
494                                    'email_user' => $userOrGroup,
495                                    'email_recipient' => '*',
496                                    'configuration_type' => 'InstitutionalAccountException',
497                                    'email_user_type' => 'G'
498                                   );
499
500                              if(!$this->soConfiguration->insertRuleInDb($fields))
501                                return array('status' => false , 'msg' => 'Error on insert');
502
503                         }
504                         else
505                         {
506                             //Insere as novas Regras
507                             foreach($params['selecSendersInRule'] as $senderInRule)
508                             {
509                                 $fields = array(
510                                        'email_user' => $userOrGroup,
511                                        'email_recipient' => $senderInRule,
512                                        'configuration_type' => 'InstitutionalAccountException',
513                                        'email_user_type' => 'G'
514                                       );
515
516                                  if(!$this->soConfiguration->insertRuleInDb($fields))
517                                    return array('status' => false , 'msg' => 'Error on insert');
518
519                             }
520                         }
521                     }
522                     else
523                     {
524                      //Caso seja um usuario
525
526                         //resgata todas as regras
527                         $condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' AND email_user = \''.$userOrGroup.'\' ';
528                         $fields = array('id');
529                         $rules = $this->soConfiguration->getRuleInDb($condition,$fields);
530
531                         //Remove todas as regras
532                         foreach ($rules as $rule)
533                             $this->soConfiguration->removeRuleInDb($rule['id']);
534
535                         //Se todos os senders estiverem selecionados
536                         if($params['inputCheckAllSendersInstitutionalAccountRule'])
537                         {
538                             $fields = array(
539                                    'email_user' => $userOrGroup,
540                                    'email_recipient' => '*',
541                                    'configuration_type' => 'InstitutionalAccountException',
542                                    'email_user_type' => 'U'
543                                   );
544
545                              if(!$this->soConfiguration->insertRuleInDb($fields))
546                                return array('status' => false , 'msg' => 'Error on insert');
547
548                         }
549                         else
550                         {
551                             //Insere as novas Regras
552                             foreach($params['selecSendersInRule'] as $senderInRule)
553                             {
554                                 $fields = array(
555                                        'email_user' => $userOrGroup,
556                                        'email_recipient' => $senderInRule,
557                                        'configuration_type' => 'InstitutionalAccountException',
558                                        'email_user_type' => 'U'
559                                       );
560
561                                 if(!$this->soConfiguration->insertRuleInDb($fields))
562                                    return array('status' => false , 'msg' => 'Error on insert');
563
564
565
566                             }
567                         }
568
569                     }
570
571                    $this->dbFunctions->write_log ('Create BlockEmail For Institutional AcounteExeption', $userOrGroup);
572                 }
573           }
574       
575           
576           return array('status' => true);
577
578
579       }
580
581       /**
582        * Retorna todas as regras BlockEmailForInstitutionalAcounteExeption
583        * @return string
584        */
585       function getOptionsBlockEmailForInstitutionalAcounteExeption()
586       {
587           $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\'  GROUP BY email_user  ORDER BY email_user ';
588           $fields = array('email_user');
589           $rulesUsers = $this->soConfiguration->getRuleInDb($filter, $fields);
590
591           
592           $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' GROUP BY email_user  ORDER BY email_user ';
593           $fields = array('email_user');
594           $rulesGroups = $this->soConfiguration->getRuleInDb($filter, $fields);
595
596           $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'A\' GROUP BY email_user  ORDER BY email_user ';
597           $fields = array('email_user');
598           $rulesAll = $this->soConfiguration->getRuleInDb($filter, $fields);
599
600           $return = '';
601
602           if(count($rulesAll) > 0)
603           {
604             $return .= '<option  value="-1" disabled>---------------------------------'.$this->functions->make_lang('lang_all').'----------------------------------</option>';
605
606             foreach ($rulesAll as $all)
607                 $return .= '<option  value="'.$all['email_user'].'" >'.$this->functions->make_lang('lang_all').'</option>';
608
609           }
610
611           if(count($rulesUsers) > 0)
612           {
613             $return .= '<option  value="-1" disabled>-------------------------------'.$this->functions->make_lang('lang_users').'-------------------------------</option>';
614
615             foreach ($rulesUsers as $user)
616                 $return .= '<option  value="'.$user['email_user'].',U" >'.utf8_decode($this->ldapFunctions->get_user_cn_by_uid($user['email_user'])).'</option>';
617
618           }
619
620           if(count($rulesGroups) > 0)
621           {
622             $return .= '<option  value="-1" disabled>---------------------------------'.$this->functions->make_lang('lang_groups').'--------------------------------</option>';
623
624             foreach ($rulesGroups as $group)
625                 $return .= '<option  value="'.$group['email_user'].',G">'.utf8_decode($this->ldapFunctions->get_group_cn_by_gidnumber($group['email_user'])).'</option>';
626
627           }
628   
629
630           return $return;
631       }
632
633       /**
634        * Retorna todos os destinatarios da regra BlockInstitutionalAcounteExeptio
635        * @param <type> $params
636        * @return string
637        */
638       function getOptionsSenderInstitutionalAcounteExeption($params)
639       {
640
641           $recipient = explode(',', $params['recipient']);
642           $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\'  ORDER BY email_recipient ';
643           $fields = array('email_recipient');
644           $rules = $this->soConfiguration->getRuleInDb($filter, $fields);
645
646           $return = '';
647
648           if(count($rules) > 0)
649           {
650             foreach ($rules as $rule)
651             {
652                    $return .= '<option  value="'.$rule['email_recipient'].'">'.$rule['email_recipient'].'</option>';
653             }
654           }
655
656           return $return;
657       }
658       /**
659        * Busca os destinatarios das regras de excessao block institutional account
660        * @param <type> $params
661        * @return <type>
662        */
663       function getRecipientsInstitutionalAcounteExeption($params)
664       {
665
666
667           $recipient = explode(',', $params['recipient']);
668
669           $filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\'  ORDER BY email_recipient ';
670           $rules = $this->soConfiguration->getRuleInDb($filter);
671
672           $return = '';
673           $allSenders = false;
674           $optionRecipient = '';
675
676           if(count($rules) > 0)
677           {
678             foreach ($rules as $rule)
679             {
680                    if($rule['email_recipient'] == '*')
681                    {
682                       $allSenders = true;                     
683                    }
684
685                    $return .= '<option  value="'.$rule['email_recipient'].'">'.$rule['email_recipient'].'</option>';
686             }
687           }
688
689
690           return array('status' => true, 'options' => $return, 'allSender' => $allSenders );
691       }
692
693       /**
694        * Cria ou atualiza regras globais de bloqueios
695        * @param array $params
696        * @return array [status] = true or false,[msg] = mensagem de erro
697        */
698       function saveGlobalConfiguration($params)
699       {
700
701           //Valida se maximum sender é do tipo numero
702            if(!is_numeric($params['maximumRecipient']) && $params['maximumRecipient'])
703                 return array('status' => false , 'msg' => 'maximumRecipient not number');
704
705
706     
707           //Atualiza Regra Bloquei de comunicação de contas institucionais ou compartilhadas
708           $filter = 'WHERE config_app = \'expressoMail1_2\' AND config_name = \'expressoMail_block_institutional_comunication\'';
709           $fields = array('oid','config_value');
710           $rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
711
712
713           $params['blockComunication'] = (string)$params['blockComunication'];
714
715           //Verifica se ouve alteração
716           if($rules[0]['config_value'] != $params['blockComunication'])
717           {
718               if(count($rules) > 0)
719               {
720                //Update
721                    $fields = array(
722                            'config_app' => 'expressoMail1_2',
723                            'config_name' => 'expressoMail_block_institutional_comunication',
724                            'config_value' => $params['blockComunication'],
725                           );
726
727                     if(!$this->soConfiguration->updatetRuleGlobalInDb($rules['0']['oid'], $fields))
728                        return array('status' => false , 'msg' => 'Error on update block comunication ');
729                     else
730                        $this->dbFunctions->write_log ('Block Institutional Comunication Global Update', 'All');
731               }
732               else
733               {
734                //Insert
735                    $fields = array(
736                            'config_app' => 'expressoMail1_2',
737                            'config_name' => 'expressoMail_block_institutional_comunication',
738                            'config_value' => $params['blockComunication'],
739                           );
740
741                     if(!$this->soConfiguration->insertRuleGlobalInDb($fields))
742                        return array('status' => false , 'msg' => 'Error on insert block comunication ');
743                     else
744                        $this->dbFunctions->write_log ('Block Institutional Comunication Global Update', 'All');
745
746               }
747           }
748
749           //Atualiza Regra Maximo Destinatarios
750           $filter = 'WHERE config_app = \'expressoMail1_2\' AND config_name = \'expressoAdmin_maximum_recipients\'';
751           $fields = array('oid','config_value');
752           $rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
753
754
755            if($params['maximumRecipient'] < 1)
756                $params['maximumRecipient'] = '0';
757
758
759           //Verifica se ouve alteração
760           if($rules[0]['config_value'] != $params['maximumRecipient'])
761           {
762               if(count($rules) > 0)
763               {
764                    //Update
765                    $fields = array(
766                            'config_app' => 'expressoMail1_2',
767                            'config_name' => 'expressoAdmin_maximum_recipients',
768                            'config_value' => $params['maximumRecipient'],
769                           );
770
771                     if(!$this->soConfiguration->updatetRuleGlobalInDb($rules['0']['oid'], $fields))
772                        return array('status' => false , 'msg' => 'Error on update maximum Recipient ');
773                     else
774                        $this->dbFunctions->write_log ('Maximum RecipientsGlobal Update', 'All');
775               }
776               else
777               {
778                    //Insert
779                    $fields = array(
780                            'config_app' => 'expressoMail1_2',
781                            'config_name' => 'expressoAdmin_maximum_recipients',
782                            'config_value' => $params['maximumRecipient'],
783                           );
784
785                     if(!$this->soConfiguration->insertRuleGlobalInDb($fields))
786                        return array('status' => false , 'msg' => 'Error on insert maximum Recipient ');
787                     else
788                        $this->dbFunctions->write_log ('Maximum RecipientsGlobal Update', 'All');
789
790               }
791           }
792           return array('status' => true );
793       }
794
795       /**
796        * Retorna Todas as regras do modulo expressoAdmin
797        * @return array
798        */
799       function getGlobalConfiguratons()
800       {
801     
802           $filter = 'WHERE config_app = \'expressoMail1_2\' ';
803           $fields = array('config_name','config_value');
804           $rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
805
806           $config = array();
807
808           foreach ($rules as $rule)
809           {
810               $config[$rule['config_name']] = $rule['config_value'] ;
811           }
812
813           return $config;
814       }
815
816    }
817
818?>
Note: See TracBrowser for help on using the repository browser.