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

Revision 6105, 23.8 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2695 - Agenda do usuario nao e exibida na importacao do evento via ExpressoMail?

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