source: trunk/expressoMail1_2/inc/class.db_functions.inc.php @ 6528

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

Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk

  • 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(isset($params['selected']) || isset($params['readable'])){
433                               
434                                $_REQUEST['data'] = $fileContent;
435                                $_REQUEST['type'] = 'iCal';
436                                $_REQUEST['params']['calendar'] = isset($params['selected']) ? $params['selected'] : false;
437                                $_REQUEST['readable'] = (isset($params['readable']) && $params['readable']) ? true : false;
438                                $_REQUEST['analize'] = isset($params['analize']) ? true : false;
439                                $_REQUEST['params']['status'] = isset($params['status']) ? $params['status'] : false;
440                                $_REQUEST['params']['owner'] = $params['uidAccount'];
441                                if(isset($params['acceptedSuggestion'])){
442                                        $_REQUEST['params']['acceptedSuggestion'] = $params['acceptedSuggestion'];
443                                        $_REQUEST['params']['from'] = $params['from'];
444                                }
445                               
446                                ob_start();
447                                include_once(PHPGW_INCLUDE_ROOT.'/prototype/converter.php');
448                                $output = ob_get_clean();                       
449                                $valid = json_decode($output, true);
450
451                                if($_REQUEST['readable']){     
452                                        if(!is_array($valid))
453                                        {
454                                                $output = unserialize($output);
455                                                foreach($output as $key => $value)
456                                                        return $value;
457                                        }
458                                        return false;
459                                }                               
460                                if(empty($output))
461                                        return "error";
462                                return "ok";
463                        }
464                       
465            include_once(PHPGW_INCLUDE_ROOT.'/header.inc.php');
466            $uiicalendar = CreateObject("calendar.uiicalendar");       
467            if(strtoupper($expFolder[0]) == 'USER' && $expFolder[1]) // IF se a conta o ical estiver em uma conta compartilhada
468            {
469                include_once('class.ldap_functions.inc.php');
470                $ldap = new ldap_functions();
471                $account['uid'] = $expFolder[1];
472                $account['uidnumber']  = $ldap->uid2uidnumber($expFolder[1]);
473                $account['mail']  = $ldap->getMailByUid($expFolder[1]);
474
475                return $uiicalendar->import_from_mail($fileContent, $from_ajax,$account);
476            }
477            else
478                return $uiicalendar->import_from_mail($fileContent, $from_ajax);
479
480        }
481
482    function insert_certificate($email,$certificate,$serialnumber,$authoritykeyidentifier=null)
483        {
484                if(!$email || !$certificate || !$serialnumber || !$authoritykeyidentifier)
485                        return false;
486                // Insere uma chave publica na tabela phpgw_certificados.
487                $data = array   ('email' => $email,
488                                                 'chave_publica' => $certificate,
489                                                 'serialnumber' => $serialnumber,
490                                                 'authoritykeyidentifier' => $authoritykeyidentifier);
491
492                if(!$this->db->insert('phpgw_certificados',$data,array(),__LINE__,__FILE__)){
493                return $this->db->Error;
494        }
495        return true;
496        }
497
498        function get_certificate($email=null)
499        {
500                if(!$email) return false;
501                $result = array();
502
503                $where = array ('email' => $email,
504                                                'revogado' => 0,
505                                                'expirado' => 0);
506
507                if(!$this->db->select('phpgw_certificados','chave_publica', $where, __LINE__,__FILE__))
508        {
509            $result['dberr1'] = $this->db->Error;
510            return $result;
511        }
512                $regs = array();
513                while($this->db->next_record())
514        {
515            $regs[] = $this->db->row();
516        }
517                if (count($regs) == 0)
518        {
519            $result['dberr2'] = ' Certificado nao localizado.';
520            return $result;
521        }
522                $result['certs'] = $regs;
523                return $result;
524        }
525
526        function update_certificate($serialnumber=null,$email=null,$authoritykeyidentifier,$expirado,$revogado)
527        {
528                if(!$email || !$serialnumber) return false;
529                if(!$expirado)
530                        $expirado = 0;
531                if(!$revogado)
532                        $revogado = 0;
533
534                $data = array   ('expirado' => $expirado,
535                                                 'revogado' => $revogado);
536
537                $where = array  ('email' => $email,
538                                                 'serialnumber' => $serialnumber,
539                                                 'authoritykeyidentifier' => $authoritykeyidentifier);
540
541                if(!$this->db->update('phpgw_certificados',$data,$where,__LINE__,__FILE__))
542                {
543                        return $this->db->Error;
544                }
545                return true;
546        }
547
548       
549        /**
550     * @abstract Recupera o valor da regra padrão.
551     * @return retorna o valor da regra padrão.
552     */
553        function get_default_max_size_rule()
554        {
555                $query = "SELECT config_value FROM phpgw_config WHERE config_name = 'expressoAdmin_default_max_size'";
556                if(!$this->db->query($query))
557            return false;
558
559        $return = array();
560                       
561                while($this->db->next_record())
562            array_push($return, $this->db->row());
563                       
564                return $return;
565        }
566       
567        /**
568     * @abstract Recupera a regra de um usuário.
569     * @return retorna a regra que o usuário pertence. Caso o usuário não participe de nenhuma regra, retorna false.
570     */
571        function get_rule_by_user($id_user)
572        {
573                $return = array();     
574                $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user='$id_user' AND configuration_type='MessageMaxSize'";
575               
576                if(!$this->db->query($query))
577            return false;
578               
579                while($this->db->next_record())
580            array_push($return, $this->db->row());
581                       
582                return $return;
583        }
584       
585       
586        function get_rule_by_user_in_groups($id_group)
587        {
588                $return = array();
589                $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE configuration_type='MessageMaxSize' AND email_user_type='G' AND email_user='".$id_group."'";
590
591                if(!$this->db->query($query))   
592                        return false;   
593                       
594                while($this->db->next_record())
595                        array_push($return, $this->db->row());
596
597                return $return;
598        }
599        function getMaximumRecipientsUser($pUserUID)
600        {
601
602           $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$pUserUID.'\' AND configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' ';
603           $this->db->query($query);
604
605           $return = array();
606
607            while($this->db->next_record())
608              $return =  $this->db->row();
609
610            return $return['email_max_recipient'];
611        }
612
613        function getMaximumRecipientsGroup($pGroupsGuidnumbers)
614        {
615           $groupsGuidNumbers = '';
616
617           foreach ($pGroupsGuidnumbers as $guidNumber => $cn)
618             $groupsGuidNumbers .= $guidNumber.', ';
619
620           $groupsGuidNumbers = substr($groupsGuidNumbers,0,-2);
621
622           $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user IN ('.$groupsGuidNumbers.') AND configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' ';
623           $this->db->query($query);
624
625           $return = array();
626
627            while($this->db->next_record())
628              $return[] =  $this->db->row();
629
630            $maxSenderReturn = 0;
631
632            foreach ($return as $maxSender)
633            {
634                if($maxSender['email_max_recipient'] > $maxSenderReturn)
635                    $maxSenderReturn = $maxSender['email_max_recipient'];
636            }
637
638            return $maxSenderReturn;
639        }
640
641        function validadeSharedAccounts($user,$grups,$accountsMails)
642        {
643
644             $arrayMailsBlocked = array();
645
646             $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$user.'\' AND email_recipient = \'*\'  AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' ';
647             $this->db->query($query);
648             $this->db->next_record();
649                 if($this->db->row())
650                   return $arrayMailsBlocked;
651
652            foreach ($grups as $guidNumber => $cn)
653            {
654                 $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$guidNumber.'\' AND email_recipient = \'*\'  AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' ';
655                 $this->db->query($query);
656                 $this->db->next_record();
657                 if($this->db->row())
658                     return $arrayMailsBlocked;
659
660            }
661
662            foreach ($accountsMails as $mail)
663            {
664               
665               $blocked = true;
666
667               $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_recipient = \''.$mail.'\' AND configuration_type = \'InstitutionalAccountException\' ';
668               $this->db->query($query);
669           
670                while($this->db->next_record())
671                {
672                    $row =  $this->db->row();
673                   
674                    if(($row['email_user'] == '*' ||  $row['email_user'] == $user) && ($row['email_user_type'] == 'T' || $row['email_user_type'] == 'U'))
675                        $blocked = false;
676                    else if(array_key_exists($row['email_user'], $grups) && $row['email_user_type'] == 'G')
677                         $blocked = false;
678
679                }
680
681                if($blocked == true)
682                    array_push ($arrayMailsBlocked, $mail);
683            }
684
685            return $arrayMailsBlocked;
686        }
687
688                function write_log($action, $about)
689                {
690                        $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) "
691                                . "VALUES('now','" . $_SESSION['phpgw_info']['expressomail']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')";
692                        if (!$this->db->query($sql)) {
693                        return false;
694                }
695        return true;
696       }
697}
698?>
Note: See TracBrowser for help on using the repository browser.