source: extensions/Mail_supervisor/include/fonctions.php @ 4041

Last change on this file since 4041 was 4041, checked in by cljosse, 15 years ago

[mail_supervisor] insert multi tabs

File size: 13.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28if (!defined('MAILl_SUPERV_DIR')) define('MAILl_SUPERV_DIR' , basename(dirname(__FILE__)));
29if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
30
31load_language('plugin.lang', MAIL_SUPERV_PATH);
32include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35include_once (MAIL_SUPERV_PATH.'include/function_test_send.php'); 
36
37global $period_search,$period_match ;
38
39
40
41        $period_search=array("D","H","M","S","W");
42        array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde'));
43       
44        $period_match=array(" day"," hour"," minute"," second"," week");       
45        array_push($period_match,'week','day','hour','minute','seconde');
46
47function sauve_options()
48{
49global $mails_options ;
50        $query = '
51    UPDATE '.CONFIG_TABLE.'
52    SET value="'.$mails_options[0]. ',' .$mails_options[1]. ',' .$mails_options[2].',' .$mails_options[3]. ',' .$mails_options[4]. '"
53    WHERE param="mail_superv"
54    LIMIT 1';
55 pwg_query($query);
56
57}
58//=================================================================================
59function sauve_données()
60{
61global $mails_données ;
62
63$query = '
64        UPDATE '.MAIL_SUPERV_TABLE.'
65        SET `nb_mails`         = '.$mails_données['nb_mails'].',
66                        `date_mail`        = '.$mails_données['date_mail'].',
67                        `nb_mails_maxi`    = '.$mails_données['nb_mails_maxi'].',       
68                        `nb_mails_periode`    = "'.$mails_données['nb_mails_periode'].'",       
69                                       
70                        `nb_spams`         = '.$mails_données['nb_spams'].',
71                        `date_spam`        = '.$mails_données['date_spam'].',
72                        `nb_spams_maxi`    = '.$mails_données['nb_spams_maxi'].',       
73                        `nb_spams_periode`    = "'.$mails_données['nb_spams_periode'].'",       
74                                                               
75                        `quarantaine`      = "'.$mails_données['quarantaine'].'",
76                        `date_quarantaine` = '.$mails_données['date_quarantaine'].',
77                       
78                        `quarantaine_periode`    = "'.$mails_données['quarantaine_periode'].'",                         
79                       
80                        `message`          = "'.$mails_données['message'].'",
81                        `message_test`          = "'.$mails_données['message_test'].'",
82                        `header_text`      = "'.$mails_données['header_text'].'"
83                WHERE `id` =1 LIMIT 1 ';
84               
85
86    if (  pwg_query($query)) return;
87       
88        vérif_base() ;
89        if (  pwg_query($query)) return;
90
91       
92        ;
93
94
95}
96//=================================================================================
97function affiche_message()
98{
99 global $template,$infos_message,$erreur_message ;;
100 
101  if (isset($erreur_message))
102                {       
103 
104                if ($erreur_message <> "")
105                        {
106                            $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
107                                $template->assign('errors',$erreur_message);
108                                $erreur_message="";
109                        }
110                }
111               
112       
113  if (isset($infos_message))
114                {       
115               
116                if ($infos_message <> "")
117                        {
118                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
119                                $template->assign('infos',$infos_message);
120                                $infos_message="";
121                        }
122                }
123                               
124               
125               
126}
127
128
129
130//=================================================================================
131function Get_Datas()
132{
133ob_start();
134
135        $data=Lire_datas();
136
137
138                        $m= ob_get_contents();
139        ob_end_clean();
140       
141        if (strlen($m)>0) {
142        vérif_base() ;
143        $data=Lire_datas();
144        }
145    return $data;
146}
147
148function Lire_datas()
149{
150global $period_search,$period_match ;
151 $query = "
152    SELECT *
153    FROM ".MAIL_SUPERV_TABLE."
154        ;";
155    $data = mysql_fetch_array(pwg_query($query));
156        //====================================================================================
157       
158
159    $mails_periode="+".str_replace($period_search, $period_match, $data['nb_mails_periode']);
160        $next_day =  strtotime(  $mails_periode,$data['date_mail']);
161        $data['rest_mail']=  ( $next_day )-time() ;
162       
163                               
164        $spams_periode="+".str_replace($period_search, $period_match, $data['nb_spams_periode']);
165        $next_day =  strtotime(  $spams_periode,$data['date_spam']);
166        $data['rest_spam']=  ( $next_day )-time() ;
167
168 
169        $quarantaine_periode="+".str_replace($period_search, $period_match, $data['quarantaine_periode']);
170        $next_day =  strtotime( $quarantaine_periode,$data['date_quarantaine']);       
171        if ($data['quarantaine']) {
172        $data['reste'] =   ( $next_day )-time() ;
173        }else{
174        $data['reste'] = 0;
175        }
176       
177         return $data;
178}
179
180//=================================================================================
181function corrige_header($Carbonne,$headers)
182        {
183        global $mails_options,$conf_mail,$mailto;
184
185                $splitter="|".$Carbonne.":(.*)\n|U";
186                preg_match_all($splitter,$headers, $out,PREG_PATTERN_ORDER);
187                $val=array();
188                $match=array("<",">");
189                $string=array("","") ;
190                foreach($out as $messages)
191                {
192                $val[]=  $messages[0] ;
193                }
194 
195
196        $val[1]=  str_replace( $match,$string,$val[0] ) ;
197        $src=$val[0];
198       
199        $splitter="|\"(.*)\"|U";
200        preg_match_all($splitter,$val[1], $out,PREG_PATTERN_ORDER);
201        $string=array();
202        $string = array_fill( 0, count($out), '');
203        $dest = str_replace($out[0], $string, $val[1]) ;
204 if ($mailto <>"" ) {   
205         $dest=str_replace($mailto.',', '', $dest) ;
206         $dest=str_replace($mailto, '', $dest) ;
207       
208} 
209
210
211        $headers = str_replace( $src,$dest, $headers) ;
212        return $headers;
213
214               
215        }
216       
217function int_to_heure($int)
218{
219$week= (int) ($int/(3600*24*7)); 
220$int=$int-($week*(3600*24*7)); 
221
222$day= (int) ($int/(3600*24));   
223$int=$int-($day*(3600*24));
224
225$heures=(int) ($int/3600);
226
227$int=$int-($heures*(3600));
228
229$minutes=(int) ($int/60);
230$int= $int - ($minutes*(60));
231
232$secondes=(int) ($int);
233
234$heures= substr ('00'. $heures,-2,2);   
235$day= substr ('00'.  $day,-2,2);   
236$minutes=substr ('00'.$minutes,-2,2);
237$secondes=substr ('00'.$secondes,-2,2);
238
239if ($week > 0 )
240{
241
242return $week. " " .l10n('Week'). " " .  $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('minute'). "s ".  $secondes." " .l10n('seconde')."s";
243}
244return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ".  $secondes." " .l10n('Seconde')."s";
245
246}       
247
248function memo_var($variables)
249{
250                ob_start();
251                echo '<pre>';
252                print_r($variables);
253                echo '</pre>';
254                $m= ob_get_contents();
255
256        ob_end_clean();
257                return $m;
258               
259}
260
261function vérif_base()
262{
263
264$q = "
265    CREATE TABLE IF NOT EXISTS ".MAIL_SUPERV_TABLE." (
266                `id` SMALLINT( 5 ) NOT NULL DEFAULT '0',
267               
268                `nb_mails` INT NOT NULL DEFAULT '0',
269                `date_mail` INT NOT NULL DEFAULT '0',
270                `nb_mails_maxi` INT NOT NULL DEFAULT '2000',           
271                `nb_mails_periode` TEXT  ,     
272               
273                `nb_spams` INT NOT NULL DEFAULT '0',
274                `date_spam` INT NOT NULL DEFAULT '0',   
275               
276                `nb_spams_maxi` INT NOT NULL DEFAULT '10',     
277                `nb_spams_periode` TEXT  ,     
278               
279                `quarantaine` TEXT ,
280                `date_quarantaine` INT NOT NULL DEFAULT '0',
281                `quarantaine_periode` TEXT  ,   
282                       
283               
284                `message` TEXT  ,
285                `message_test` TEXT  ,
286                `header_text` TEXT ,
287        PRIMARY KEY  (`id` )
288         )
289  ;";
290  pwg_query($q);
291 
292    $nb = Get_colonnes_de(MAIL_SUPERV_TABLE);
293        $table=$nb[MAIL_SUPERV_TABLE];   
294//================================================================================     
295    if (!in_array( "nb_mails",$table)) {       
296                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails` INT NOT NULL default '0' ";
297                           pwg_query($query);            } 
298        if (!in_array( "date_mail",$table)) {   
299          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_mail` INT NOT NULL default '0' ";
300                           pwg_query($query);            } 
301        if (!in_array( "nb_mails_maxi",$table)) {       
302          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_maxi` INT NOT NULL default '2000' ";
303                           pwg_query($query);            } 
304        if (!in_array( "nb_mails_periode",$table)) {   
305          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_periode` TEXT ";
306                           pwg_query($query);            } 
307                                                   
308                                                   
309    if (!in_array( "nb_spams",$table)) {       
310                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams` INT NOT NULL default '0' ";
311                           pwg_query($query);            } 
312        if (!in_array( "date_spam",$table)) {   
313          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_spam` INT NOT NULL default '0' ";
314                           pwg_query($query);            }                         
315                           
316    if (!in_array( "nb_spams_maxi",$table)) {   
317                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_maxi` INT NOT NULL default '10' ";
318                           pwg_query($query); 
319        if (!in_array( "nb_spams_periode",$table)) {   
320          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_periode` TEXT ";
321                           pwg_query($query);            }                                   } 
322                                                       
323                if (!in_array( "quarantaine",$table)) { 
324          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine` TEXT  , ";
325                           pwg_query($query);            }     
326                           
327                if (!in_array( "date_quarantaine",$table)) {   
328          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_quarantaine` INT NOT NULL default '0'    ";
329                           pwg_query($query);   
330                                    }   
331                if (!in_array( "quarantaine_periode",$table)) { 
332          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine_periode` TEXT ";
333                           pwg_query($query);            }                                         
334                               
335                if (!in_array( "message",$table)) {     
336          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message` TEXT   ";
337                           pwg_query($query);            }     
338                           
339                if (!in_array( "message_test",$table)) {       
340          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message_test` TEXT   ";
341                           pwg_query($query);            }                                 
342                           
343                if (!in_array( "header_text",$table)) { 
344          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `header_text` TEXT   ";
345                           pwg_query($query);            }             
346                                                                       
347                                           
348      $query = "
349                SELECT COUNT(*)
350                FROM ".MAIL_SUPERV_TABLE."
351                ;";
352//==============================================================================               
353  list($count) = mysql_fetch_row(pwg_query($query));
354  if ($count == 0)
355  {
356         $next_day = time()  ;
357         $date_quarantaine=time();
358           $q = '
359    INSERT INTO '.MAIL_SUPERV_TABLE.' (id,
360        nb_mails,date_mail,nb_mails_maxi,nb_mails_periode,
361        nb_spams,date_spam,nb_spams_maxi,nb_spams_periode,
362         quarantaine, date_quarantaine,quarantaine_periode,
363         message,header_text)
364    VALUES (1,
365        0,
366        '.time().',
367        2000,
368        "1 week",
369       
370        0,
371        '.time().',
372        10,
373        "2 day",
374       
375        false,
376        '.time().',
377        "2 day",
378       
379        "Init.",
380         "'.l10n('hello').'"
381         )
382         ;';
383
384
385        pwg_query($q);
386       
387        } 
388}
389function Get_colonnes_de($table)
390{
391  $columns_of = array();
392    $query = 'DESC '.$table.';';
393    $result = mysql_query($query);
394    $columns_of[$table] = array();
395    while ($row = mysql_fetch_row($result))
396    {
397      array_push($columns_of[$table], $row[0]);
398    }
399  return $columns_of;
400}
401
402function get_liste($group_id)
403{
404global $conf ;
405
406  $query = '
407SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
408                u.'.$conf['user_fields']['username'].' AS username,
409                u.'.$conf['user_fields']['email'].' AS email,
410                ui.status,
411                ui.adviser,
412                ui.enabled_high,
413                ui.level
414  FROM '.USERS_TABLE.' AS u
415    INNER JOIN '.USER_INFOS_TABLE.' AS ui
416      ON u.'.$conf['user_fields']['id'].' = ui.user_id
417    LEFT JOIN '.USER_GROUP_TABLE.' AS ug
418      ON u.'.$conf['user_fields']['id'].' = ug.user_id
419  WHERE ug.group_id='.$group_id.' ';
420
421
422 
423 $groups=array();
424  $datas = pwg_query($query);
425 
426 
427  if (!empty($datas))
428  {
429    while ($group = mysql_fetch_array($datas))
430    {
431
432       
433      if (!empty($group['email']))
434      {
435        array_push($groups, format_email($group['username'], $group['email'] ));
436      }
437    }
438  } 
439  return $groups ;
440 
441}
442
443?>
Note: See TracBrowser for help on using the repository browser.