source: sandbox/2.4.1-3/expressoMail1_2/inc/class.db_functions.inc.php @ 6512

Revision 6512, 23.8 KB checked in by gustavo, 12 years ago (diff)

Ticket #2766 - implementacao da dfd0065 e correcao de bugs da dfd0099

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2                /***************************************************************************
3                * Expresso Livre                                                           *
4                * http://www.expressolivre.org                                             *
5                * --------------------------------------------                             *
6                *  This program is free software; you can redistribute it and/or modify it *
7                *  under the terms of the GNU General Public License as published by the   *
8                *  Free Software Foundation; either version 2 of the License, or (at your  *
9                *  option) any later version.                                              *
10                \**************************************************************************/
11               
12if(!isset($_SESSION['phpgw_info']['expressomail']['server']['db_name'])) {
13        include_once('../header.inc.php');
14        $_SESSION['phpgw_info']['expressomail']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
15        $_SESSION['phpgw_info']['expressomail']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host'];
16        $_SESSION['phpgw_info']['expressomail']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port'];
17        $_SESSION['phpgw_info']['expressomail']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user'];
18        $_SESSION['phpgw_info']['expressomail']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass'];
19        $_SESSION['phpgw_info']['expressomail']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type'];
20}
21else{
22        define('PHPGW_INCLUDE_ROOT','../');     
23        define('PHPGW_API_INC','../phpgwapi/inc');       
24        include_once(PHPGW_API_INC.'/class.db.inc.php');
25}
26       
27class db_functions
28{       
29       
30        var $db;
31        var $user_id;
32        var $related_ids;
33       
34        function db_functions(){
35                $this->db = new db();           
36                $this->db->Halt_On_Error = 'no';
37                $this->db->connect(
38                                $_SESSION['phpgw_info']['expressomail']['server']['db_name'],
39                                $_SESSION['phpgw_info']['expressomail']['server']['db_host'],
40                                $_SESSION['phpgw_info']['expressomail']['server']['db_port'],
41                                $_SESSION['phpgw_info']['expressomail']['server']['db_user'],
42                                $_SESSION['phpgw_info']['expressomail']['server']['db_pass'],
43                                $_SESSION['phpgw_info']['expressomail']['server']['db_type']
44                );             
45                $this -> user_id = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];       
46        }
47
48        // BEGIN of functions.
49        function get_cc_contacts()
50        {                               
51                $result = array();
52                $stringDropDownContacts = '';           
53               
54                $query_related = $this->get_query_related('A.id_owner'); // field name for owner
55                       
56                // Traz os contatos pessoais e compartilhados
57                $query = 'select A.names_ordered, C.connection_value from phpgw_cc_contact A, '.
58                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
59                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
60                        'and B.id_typeof_contact_connection = 1 and ('.$query_related.') group by '.
61                        'A.names_ordered,C.connection_value     order by lower(A.names_ordered)';
62               
63        if (!$this->db->query($query))
64                return null;
65                while($this->db->next_record())
66                        $result[] = $this->db->row();
67
68                if (count($result) != 0)
69                {
70                        // Monta string                         
71                        foreach($result as $contact)
72                                $stringDropDownContacts = $stringDropDownContacts . urldecode(urldecode($contact['names_ordered'])). ';' . $contact['connection_value'] . ',';
73                        //Retira ultima virgula.
74                        $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1));
75                }
76                else
77                        return null;
78
79                return $stringDropDownContacts;
80        }
81        // Get Related Ids for sharing contacts or groups.
82        function get_query_related($field_name){               
83                $query_related = $field_name .'='.$this -> user_id;
84                // Only at first time, it gets all related ids...
85                if(!$this->related_ids) {
86                        $query = 'select id_related from phpgw_cc_contact_rels where id_contact='.$this -> user_id.' and id_typeof_contact_relation=1';         
87                        if (!$this->db->query($query)){
88                return $query_related;
89                        }
90                       
91                        $result = array( );
92                        while($this->db->next_record()){
93                                $row = $this->db->row();
94                                $result[] = $row['id_related'];
95                        }
96                        if($result)
97                                $this->related_ids = implode(",",$result);
98                }
99                if($this->related_ids)
100                        $query_related .= ' or '.$field_name.' in ('.$this->related_ids.')';
101               
102                return $query_related;
103        }
104        function get_cc_groups()
105        {
106                // Pesquisa no CC os Grupos Pessoais.
107                $stringDropDownContacts = '';                   
108                $result = array();
109                $query_related = $this->get_query_related('owner'); // field name for 'owner'           
110                $query = 'select title, short_name, owner from phpgw_cc_groups where '.$query_related.' order by lower(title)';
111
112                // Executa a query
113                if (!$this->db->query($query))
114                return null;
115                // Retorna cada resultado               
116                while($this->db->next_record())
117                        $result[] = $this->db->row();
118
119                // Se houver grupos ....                               
120                if (count($result) != 0)
121                {
122                        // Create Ldap Object, if exists related Ids for sharing groups.
123                        if($this->related_ids){
124                                $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids']= array();
125                                include_once("class.ldap_functions.inc.php");
126                                $ldap = new ldap_functions();
127                        }
128                        $owneruid = '';
129                        foreach($result as $group){
130                                // Searching uid (LDAP), if exists related Ids for sharing groups.
131                                // Save into user session. It will used before send mail (verify permission).
132                                if(!isset($_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']]) && isset($ldap)){                                 
133                                        $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']] = $ldap -> uidnumber2uid($group['owner']);
134                                }
135                                if($this->user_id != $group['owner'])
136                                        $owneruid = "::".$_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']];
137                                else
138                                        $owneruid = '';
139
140                                $stringDropDownContacts .=  $group['title']. ';' . ($group['short_name'].$owneruid) . ',';
141                        }
142                        //Retira ultima virgula.
143                        $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1));
144                }
145                else
146                        return null;           
147                return $stringDropDownContacts;
148        }
149       
150        function getContactsByGroupAlias($alias)
151        {
152                list($alias,$uid) = explode("::",$alias);               
153                $cc_related_ids = $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'];           
154                // Explode personal group, If exists related ids (the user has permission to send email).
155                if(is_array($cc_related_ids) && $uid){
156                        $owner =  array_search($uid,$cc_related_ids);                   
157                }
158               
159                $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ".
160                "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ".
161                "A.id_contact = B.id_contact and B.id_connection = C.id_connection ".
162                "and B.id_typeof_contact_connection = 1 and ".
163                "A.id_owner =".($owner ? $owner : $this->user_id)." and ".                     
164                "D.id_group = E.id_group and ".
165                "D.id_connection = C.id_connection and E.short_name = '".$alias."'";
166
167                if (!$this->db->query($query))
168                {
169                        exit ('Query failed! File: '.__FILE__.' on line'.__LINE__);
170                }
171
172                $return = false;
173
174                while($this->db->next_record())
175                {
176                        $return[] = $this->db->row();
177                }
178
179                return $return;
180        }
181
182        function getAddrs($array_addrs) {
183                $array_addrs_final = array();                           
184
185                for($i = 0; $i < count($array_addrs); $i++){
186                        $j = count($array_addrs_final);
187
188                        if(preg_replace('/\s+/', '', $array_addrs[$i]) != ""){
189
190                                if(strchr($array_addrs[$i],'@') == "") {               
191                                        if(strpos($array_addrs[$i],'<') && strpos($array_addrs[$i],'>')){
192                                                $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>'));
193                                                $alias = str_replace('<','', str_replace('>','',$alias));
194
195                                        }
196                                        else{
197                                                $alias = $array_addrs[$i];                     
198                                                $alias = preg_replace('/\s/', '', $alias);
199                                        }       
200
201                                        $arrayContacts = $this -> getContactsByGroupAlias($alias);
202
203
204                                        if($arrayContacts) {
205                                                foreach($arrayContacts as $index => $contact){
206                                                        if($contact['names_ordered']) {
207                                                                $array_addrs_final[$j] = '"'.$contact['names_ordered'].'" <'.$contact['connection_value'].'>';
208                                                        }
209                                                        else
210                                                                $array_addrs_final[$j] = $contact['connection_value'];
211
212                                                        $j++;
213                                                }
214                                        }else{
215                                                return array("False" => "$alias");
216                                        }
217                                }
218//-- validação email --
219                                else{
220                                        $array_addrs[$i] = trim($array_addrs[$i]);
221                                        preg_match('/<([^>]+)>/', $array_addrs[$i], $match);
222                                        if(count($match) == 2){
223                                        $ex_arr = explode('@', $match[1]);
224                                        }else{
225                                         $ex_arr = explode('@', $array_addrs[$i]);
226                                         }
227                                        if(count($ex_arr) == 2){
228                                                if($ex_arr[0] !== '' && $ex_arr[1] !== ''){
229                                                        if(preg_match("/[^0-9a-zA-Z._-]+/", $ex_arr[0]) == 0 && preg_match("/[^0-9a-zA-Z._-]+/", $ex_arr[1]) == 0){
230                                                                $array_addrs_final[$j] = $array_addrs[$i];
231                                                        }else{
232                                                                return array("False" => "$alias");
233                                                         }
234                                                }else{
235                                                        return array("False" => "$alias");
236                                                 }
237                                        }else{
238                                                return array("False" => "$alias");
239                                         }
240                                }
241//-- fim --
242                        }else{
243                                $array_addrs_final[$j] = $array_addrs[$i];
244                        }
245                }
246                return $array_addrs_final;
247        }
248
249        //Gera lista de contatos para ser gravado e acessado pelo expresso offline.
250        /*function get_dropdown_contacts_to_cache() {
251                return $this->get_dropdown_contacts();
252        }
253       
254        function get_dropdown_contacts(){
255                $contacts = $this->get_cc_contacts();
256                $groups = $this->get_cc_groups();
257               
258                if(($contacts) && ($groups))
259                        $stringDropDownContacts = $contacts . ',' . $groups;
260                elseif ((!$contacts) && (!$groups))
261                        $stringDropDownContacts = '';
262                elseif (($contacts) && (!$groups))
263                        $stringDropDownContacts = $contacts;
264                elseif ((!$contacts) && ($groups))
265                        $stringDropDownContacts = $groups;
266                                       
267                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) {
268                        // Free others requests
269                        session_write_close();
270                        $dynamic_contact = new dynamic_contacts();
271                        $dynamic = $dynamic_contact->dynamic_contact_toString();
272                        if ($dynamic)
273                                $stringDropDownContacts .= ($stringDropDownContacts ? ',' : '') . $dynamic;
274                }
275                return $stringDropDownContacts;
276        }*/
277        function getUserByEmail($params){       
278                // Follow the referral
279                $email = $params['email'];
280                $query = 'select A.names_ordered, C.connection_name, C.connection_value, A.photo'.
281                                ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, '.
282                                'phpgw_cc_connections C where A.id_contact = B.id_contact'.
283                                ' and B.id_connection = C.id_connection and A.id_contact ='.
284                                '(select A.id_contact from phpgw_cc_contact A, phpgw_cc_contact_conns B,'.
285                                'phpgw_cc_connections C where A.id_contact = B.id_contact'.
286                                ' and B.id_connection = C.id_connection and A.id_owner = '.$this -> user_id.
287                                ' and C.connection_value = \''.$email.'\') and '.
288                                'C.connection_is_default = true and B.id_typeof_contact_connection = 2';
289
290        if (!$this->db->query($query))
291                return null;
292
293
294                if($this->db->next_record()) {
295                        $result = $this->db->row();
296
297                        $obj =  array("cn" => $result['names_ordered'],
298                                          "email" => $email,
299                                          "type" => "personal",
300                                          "telefone" =>  $result['connection_value']);
301
302                        if($result['photo'])
303                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] =  array($result['photo']);                           
304
305                        return $obj;
306                }
307                return $result;
308        }
309        /*
310        function get_dynamic_contacts()
311        {                               
312                // Pesquisa os emails e ultima inserção nos contatos dinamicos.
313                if(!$this->db->select('phpgw_expressomail_contacts','data','id_owner ='.$this->user_id,__LINE__,__FILE__))
314                {
315                return $this->db->Error;
316}
317                while($this->db->next_record())
318                {
319                        $result[] = $this->db->row();
320                }
321                if($result) foreach($result as $item)
322                {
323                        $contacts = unserialize($item['data']);
324                }
325                if (count($contacts) == 0)
326                {                       
327                        return null;
328                }       
329                //Sort by email
330                function cmp($a, $b) { return strcmp($a["email"], $b["email"]);}
331                usort($contacts,"cmp");
332                return $contacts;
333        }
334        */
335        /*
336        function update_contacts($contacts=array())
337        {                       
338               
339       
340                if(!$this->db->select('phpgw_expressomail_contacts','data','id_owner ='.$this->user_id,__LINE__,__FILE__))
341        {
342            $result['dberr1'] = $this->db->Error;
343        }
344                $regs = array();
345                while($this->db->next_record())
346        {
347            $regs[] = $this->db->row();
348        }
349                $old_contatacts = array();
350                foreach($regs as $old){
351                        $old_contatacts = unserialize($old['data']);
352                }
353                 
354                foreach($old_contatacts as $i => $v)
355                        foreach($contacts as $ii => $vv)
356                                if(trim($v['email']) == trim($vv['email']))
357                                        unset($old_contatacts[$i]);
358               
359                 
360                 $old_contatacts = array_merge( $old_contatacts , $contacts);           
361                // Atualiza um email nos contatos dinamicos.
362                if(!$this->db->update('phpgw_expressomail_contacts ','data=\''.serialize($old_contatacts).'\'','id_owner ='.$this->user_id,__LINE__,__FILE__))
363                {
364                        return $this->db->Error;
365                }
366                return $contacts;
367        }       */
368       
369        function update_preferences($params){
370                $string_serial = urldecode($params['prefe_string']);                           
371                $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial);
372                $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'".
373                        " and preference_owner = '".$this->user_id."'";
374
375                if (!$this->db->query($query))
376                        return $this->db->error;
377                else
378                        return array("success" => true);
379        }
380       
381        /*
382        function insert_contact($contact)       
383        {
384                $contacts[] = array( 'timestamp'        => time(),
385                                                                'email'         => $contact );
386
387                // Insere um email nos contatos dinamicos.     
388                $query = 'INSERT INTO phpgw_expressomail_contacts (data, id_owner)  ' .
389                                        'values ( \''.serialize($contacts).'\', '.$this->user_id.')';
390               
391                if(!$this->db->query($query,__LINE__,__FILE__))
392                return $this->db->Error;
393        return $contacts;
394        }
395       
396        function remove_dynamic_contact($user_id,$line,$file)
397        {
398                $where = $user_id.' = id_owner';
399                $this->db->delete('phpgw_expressomail_contacts',$where,$line,$file);   
400        }
401        */
402        function import_vcard($params){
403            include_once('class.imap_functions.inc.php');
404            $objImap = new imap_functions();
405            $msg_number = $params['msg_number'];
406            $idx_file = $params['idx_file'];
407            $msg_part = $params['msg_part'];
408            $msg_folder = $params['msg_folder'];
409            $from_ajax = $params['from_ajax'];
410            $encoding = strtolower($params['encoding']);
411            $fileContent = "";
412            $cirus_delimiter = $params['cirus_delimiter'];
413            $expFolder = explode($cirus_delimiter, $msg_folder);
414
415            if($msg_number != null && $msg_part != null && $msg_folder != null && (intval($idx_file == '0' ? '1' : $idx_file)))
416            {
417                require_once PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.attachment.inc.php';
418                $attachmentObj = new attachment();
419                $attachmentObj->setStructureFromMail($msg_folder,$msg_number);
420                $fileContent = $attachmentObj->getAttachment($msg_part);
421                $info = $attachmentObj->getAttachmentInfo($msg_part);
422                $filename = $info['name'];
423            }
424            else
425                    $filename = $idx_file;
426                   
427            // It's necessary to access calendar method.
428            $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
429            $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
430            $GLOBALS['phpgw_info']['flags']['currentapp'] = 'calendar';
431
432                        if($params['selected'] || $params['readable']){
433                                $user = $params['id_user'];
434                               
435                                $_REQUEST['data'] = $fileContent;
436                                $_REQUEST['type'] = 'iCal';
437                                $_REQUEST['params']['calendar'] = $params['selected'];
438                                $_REQUEST['readable'] = $params['readable'] ? true : false;
439                $_REQUEST['analize'] = isset($params['analize']) ? true : false;
440                                $_REQUEST['params']['status'] = $params['status'];
441                                $_REQUEST['params']['owner'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];
442                                if(isset($params['acceptedSuggestion'])){
443                                        $_REQUEST['params']['acceptedSuggestion'] = $params['acceptedSuggestion'];
444                                        $_REQUEST['params']['from'] = $params['from'];
445                                }
446                               
447                                ob_start();
448                                include_once(PHPGW_INCLUDE_ROOT.'/prototype/converter.php');
449                                $output = ob_get_clean();                       
450                                $valid = json_decode($output, true);
451
452                                if($_REQUEST['readable']){     
453                                        if(!is_array($valid))
454                                        {
455                                                $output = unserialize($output);
456                                                foreach($output as $key => $value)
457                                                        return $value;
458                                        }
459                                        return false;
460                                }                               
461                                if(empty($output))
462                                        return "error";
463                                return "ok";
464                        }
465                       
466            include_once(PHPGW_INCLUDE_ROOT.'/header.inc.php');
467            $uiicalendar = CreateObject("calendar.uiicalendar");       
468            if(strtoupper($expFolder[0]) == 'USER' && $expFolder[1]) // IF se a conta o ical estiver em uma conta compartilhada
469            {
470                include_once('class.ldap_functions.inc.php');
471                $ldap = new ldap_functions();
472                $account['uid'] = $expFolder[1];
473                $account['uidnumber']  = $ldap->uid2uidnumber($expFolder[1]);
474                $account['mail']  = $ldap->getMailByUid($expFolder[1]);
475
476                return $uiicalendar->import_from_mail($fileContent, $from_ajax,$account);
477            }
478            else
479                return $uiicalendar->import_from_mail($fileContent, $from_ajax);
480
481        }
482
483    function insert_certificate($email,$certificate,$serialnumber,$authoritykeyidentifier=null)
484        {
485                if(!$email || !$certificate || !$serialnumber || !$authoritykeyidentifier)
486                        return false;
487                // Insere uma chave publica na tabela phpgw_certificados.
488                $data = array   ('email' => $email,
489                                                 'chave_publica' => $certificate,
490                                                 'serialnumber' => $serialnumber,
491                                                 'authoritykeyidentifier' => $authoritykeyidentifier);
492
493                if(!$this->db->insert('phpgw_certificados',$data,array(),__LINE__,__FILE__)){
494                return $this->db->Error;
495        }
496        return true;
497        }
498
499        function get_certificate($email=null)
500        {
501                if(!$email) return false;
502                $result = array();
503
504                $where = array ('email' => $email,
505                                                'revogado' => 0,
506                                                'expirado' => 0);
507
508                if(!$this->db->select('phpgw_certificados','chave_publica', $where, __LINE__,__FILE__))
509        {
510            $result['dberr1'] = $this->db->Error;
511            return $result;
512        }
513                $regs = array();
514                while($this->db->next_record())
515        {
516            $regs[] = $this->db->row();
517        }
518                if (count($regs) == 0)
519        {
520            $result['dberr2'] = ' Certificado nao localizado.';
521            return $result;
522        }
523                $result['certs'] = $regs;
524                return $result;
525        }
526
527        function update_certificate($serialnumber=null,$email=null,$authoritykeyidentifier,$expirado,$revogado)
528        {
529                if(!$email || !$serialnumber) return false;
530                if(!$expirado)
531                        $expirado = 0;
532                if(!$revogado)
533                        $revogado = 0;
534
535                $data = array   ('expirado' => $expirado,
536                                                 'revogado' => $revogado);
537
538                $where = array  ('email' => $email,
539                                                 'serialnumber' => $serialnumber,
540                                                 'authoritykeyidentifier' => $authoritykeyidentifier);
541
542                if(!$this->db->update('phpgw_certificados',$data,$where,__LINE__,__FILE__))
543                {
544                        return $this->db->Error;
545                }
546                return true;
547        }
548
549       
550        /**
551     * @abstract Recupera o valor da regra padrão.
552     * @return retorna o valor da regra padrão.
553     */
554        function get_default_max_size_rule()
555        {
556                $query = "SELECT config_value FROM phpgw_config WHERE config_name = 'expressoAdmin_default_max_size'";
557                if(!$this->db->query($query))
558            return false;
559
560        $return = array();
561                       
562                while($this->db->next_record())
563            array_push($return, $this->db->row());
564                       
565                return $return;
566        }
567       
568        /**
569     * @abstract Recupera a regra de um usuário.
570     * @return retorna a regra que o usuário pertence. Caso o usuário não participe de nenhuma regra, retorna false.
571     */
572        function get_rule_by_user($id_user)
573        {
574                $return = array();     
575                $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user='$id_user' AND configuration_type='MessageMaxSize'";
576               
577                if(!$this->db->query($query))
578            return false;
579               
580                while($this->db->next_record())
581            array_push($return, $this->db->row());
582                       
583                return $return;
584        }
585       
586       
587        function get_rule_by_user_in_groups($id_group)
588        {
589                $return = array();
590                $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE configuration_type='MessageMaxSize' AND email_user_type='G' AND email_user='".$id_group."'";
591
592                if(!$this->db->query($query))   
593                        return false;   
594                       
595                while($this->db->next_record())
596                        array_push($return, $this->db->row());
597
598                return $return;
599        }
600        function getMaximumRecipientsUser($pUserUID)
601        {
602
603           $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$pUserUID.'\' AND configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' ';
604           $this->db->query($query);
605
606           $return = array();
607
608            while($this->db->next_record())
609              $return =  $this->db->row();
610
611            return $return['email_max_recipient'];
612        }
613
614        function getMaximumRecipientsGroup($pGroupsGuidnumbers)
615        {
616           $groupsGuidNumbers = '';
617
618           foreach ($pGroupsGuidnumbers as $guidNumber => $cn)
619             $groupsGuidNumbers .= $guidNumber.', ';
620
621           $groupsGuidNumbers = substr($groupsGuidNumbers,0,-2);
622
623           $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user IN ('.$groupsGuidNumbers.') AND configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' ';
624           $this->db->query($query);
625
626           $return = array();
627
628            while($this->db->next_record())
629              $return[] =  $this->db->row();
630
631            $maxSenderReturn = 0;
632
633            foreach ($return as $maxSender)
634            {
635                if($maxSender['email_max_recipient'] > $maxSenderReturn)
636                    $maxSenderReturn = $maxSender['email_max_recipient'];
637            }
638
639            return $maxSenderReturn;
640        }
641
642        function validadeSharedAccounts($user,$grups,$accountsMails)
643        {
644
645             $arrayMailsBlocked = array();
646
647             $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$user.'\' AND email_recipient = \'*\'  AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' ';
648             $this->db->query($query);
649             $this->db->next_record();
650                 if($this->db->row())
651                   return $arrayMailsBlocked;
652
653            foreach ($grups as $guidNumber => $cn)
654            {
655                 $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$guidNumber.'\' AND email_recipient = \'*\'  AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' ';
656                 $this->db->query($query);
657                 $this->db->next_record();
658                 if($this->db->row())
659                     return $arrayMailsBlocked;
660
661            }
662
663            foreach ($accountsMails as $mail)
664            {
665               
666               $blocked = true;
667
668               $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_recipient = \''.$mail.'\' AND configuration_type = \'InstitutionalAccountException\' ';
669               $this->db->query($query);
670           
671                while($this->db->next_record())
672                {
673                    $row =  $this->db->row();
674                   
675                    if(($row['email_user'] == '*' ||  $row['email_user'] == $user) && ($row['email_user_type'] == 'T' || $row['email_user_type'] == 'U'))
676                        $blocked = false;
677                    else if(array_key_exists($row['email_user'], $grups) && $row['email_user_type'] == 'G')
678                         $blocked = false;
679
680                }
681
682                if($blocked == true)
683                    array_push ($arrayMailsBlocked, $mail);
684            }
685
686            return $arrayMailsBlocked;
687        }
688
689                function write_log($action, $about)
690                {
691                        $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) "
692                                . "VALUES('now','" . $_SESSION['phpgw_info']['expressomail']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')";
693                        if (!$this->db->query($sql)) {
694                        return false;
695                }
696        return true;
697       }
698}
699?>
Note: See TracBrowser for help on using the repository browser.