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

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

[mail_supervisor] update help.

File size: 14.0 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('MAIL_SUPERV_DIR')) define('MAIL_SUPERV_DIR' , basename(dirname(__FILE__)));
29if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
30
31
32include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
33include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
34
35global $lang ;
36
37include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
38include_once (MAIL_SUPERV_PATH.'include/function_test_send.php'); 
39
40global $period_search,$period_match,$lang ;
41
42
43    load_language('plugin.lang', MAIL_SUPERV_PATH);
44        $period_search=array("W","D","H","M","S");
45        array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde'));
46        array_push($period_search,l10n('Week').'s',l10n('Day').'s',l10n('Hour').'s',l10n('Minute').'s',l10n('Seconde').'s');
47       
48       
49        $period_match=array(' week',' day',' hour',' minute',' seconde');       
50        array_push($period_match,'week','day','hour','minute','seconde');
51        array_push($period_match,'week','day','hour','minute','seconde');
52       
53
54function sauve_options()
55{
56global $mails_options ;
57        $query = '
58    UPDATE '.CONFIG_TABLE.'
59    SET value="'.$mails_options[0]. ',' .$mails_options[1]. ',' .$mails_options[2].',' .$mails_options[3]. ',' .$mails_options[4]. '"
60    WHERE param="mail_superv"
61    LIMIT 1';
62 pwg_query($query);
63
64}
65//=================================================================================
66function sauve_données()
67{
68global $mails_données ;
69
70$query = '
71        UPDATE '.MAIL_SUPERV_TABLE.'
72        SET `nb_mails`         = '.$mails_données['nb_mails'].',
73                        `date_mail`        = '.$mails_données['date_mail'].',
74                        `nb_mails_maxi`    = '.$mails_données['nb_mails_maxi'].',       
75                        `nb_mails_periode`    = "'.$mails_données['nb_mails_periode'].'",       
76                                       
77                        `nb_spams`         = '.$mails_données['nb_spams'].',
78                        `date_spam`        = '.$mails_données['date_spam'].',
79                        `nb_spams_maxi`    = '.$mails_données['nb_spams_maxi'].',       
80                        `nb_spams_periode`    = "'.$mails_données['nb_spams_periode'].'",       
81                                                               
82                        `quarantaine`      = "'.$mails_données['quarantaine'].'",
83                        `date_quarantaine` = '.$mails_données['date_quarantaine'].',
84                       
85                        `quarantaine_periode`    = "'.$mails_données['quarantaine_periode'].'",                         
86                       
87                        `message`          = "'.$mails_données['message'].'",
88                        `message_test`     = "'.$mails_données['message_test'].'",
89                        `header_text`      = "'.$mails_données['header_text'].'"
90                WHERE `id` =1 LIMIT 1 ';
91               
92
93    if (  pwg_query($query)) return;
94       
95        vérif_base() ;
96        if (  pwg_query($query)) return;
97
98       
99        ;
100
101
102}
103//=================================================================================
104function affiche_message()
105{
106 global $template,$infos_message,$erreur_message ;;
107 
108  if (isset($erreur_message))
109                {       
110 
111                if ($erreur_message <> "")
112                        {
113                            $erreur_message=str_replace("\n",'<br />',$erreur_message) ;
114                                $template->assign('errors',$erreur_message);
115                                $erreur_message="";
116                        }
117                }
118               
119       
120  if (isset($infos_message))
121                {       
122               
123                if ($infos_message <> "")
124                        {
125                                $infos_message=str_replace("\n",'<br />',$infos_message) ;
126                                $template->assign('infos',$infos_message);
127                                $infos_message="";
128                        }
129                }
130                               
131               
132               
133}
134
135
136
137//=================================================================================
138function Get_Datas()
139{
140ob_start();
141
142        $data=Lire_datas();
143
144
145                        $m= ob_get_contents();
146        ob_end_clean();
147       
148        if (strlen($m)>0) {
149        vérif_base() ;
150        $data=Lire_datas();
151        }
152    return $data;
153}
154
155function Lire_datas()
156{
157global $period_search,$period_match ;
158 if (!isset($period_search)) {
159        $period_search=array("W","D","H","M","S");
160        array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde'));
161        array_push($period_search,l10n('Week').'s',l10n('Day').'s',l10n('Hour').'s',l10n('Minute').'s',l10n('Seconde').'s');
162       
163       
164        $period_match=array(' week',' day',' hour',' minute',' seconde');       
165        array_push($period_match,'week','day','hour','minute','seconde');
166        array_push($period_match,'week','day','hour','minute','seconde');
167        }
168
169 $query = "
170    SELECT *
171    FROM ".MAIL_SUPERV_TABLE."
172        ;";
173    $data = mysql_fetch_array(pwg_query($query));
174        //====================================================================================
175    $mails_periode = "+" . trim( str_replace($period_search, $period_match, $data['nb_mails_periode']));
176 
177        $next_day = $data['date_mail'] + strtotime(  $mails_periode,0);;
178        $data['rest_mail']=    $next_day - time() ;
179 
180                               
181        $spams_periode="+".str_replace($period_search, $period_match, $data['nb_spams_periode']);
182        $next_day = $data['date_spam'] + strtotime(  $spams_periode,0);
183        $data['rest_spam']=  $next_day -time() ;
184
185 
186        $quarantaine_periode="+".str_replace($period_search, $period_match, $data['quarantaine_periode']);
187        $next_day = $data['date_quarantaine'] + strtotime( $quarantaine_periode,0);     
188       
189        if ($data['quarantaine']) {
190        $data['reste'] =   ( $next_day )-time() ;
191        }else{
192        $data['reste'] = 0;
193        }
194       
195         return $data;
196}
197//===============================================
198
199function corrige_header($Carbonne,$headers,$args)
200        {
201        global $mails_options,$conf_mail,$mailto,$infos_message;
202
203 if (!empty($args[$Carbonne]))
204         {
205 
206                if ( count($args[$Carbonne]) > 0 ) 
207                {
208                 if ($mails_options[1] == 'on') {
209                        $list_mail  = str_replace(","," ,",get_strict_email_list(implode(',', $args[$Carbonne])))." \n" ;
210                        $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', $Carbonne.': '.$list_mail, $headers);
211                 }
212                }
213        } else {
214        // Raz Bcc, Cc dans headers
215                        $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers);
216        }
217               
218               
219return $headers;
220
221               
222        }
223       
224function int_to_heure($int)
225{
226
227
228
229$delta=(7*24*60*60) ;
230$week = (int) ($int/$delta); 
231
232$int= $int-($week*$delta) ; 
233
234
235$delta=(24*60*60) ;
236$day= (int) ($int/$delta); 
237$int=$int-($day*$delta);
238
239$delta=(60*60) ;
240$heures=(int) ($int/$delta);
241$int=$int-($heures*$delta);
242
243$delta=(60) ;
244$minutes=(int) ($int/$delta);
245$int= $int - ($minutes*$delta);
246
247
248$secondes=(int) ($int);
249
250$day      = substr ('00'.    $day,-2,2);   
251$heures   = substr ('00'. $heures,-2,2);   
252$minutes  = substr ('00'.$minutes,-2,2);
253$secondes = substr ('00'.$secondes,-2,2);
254
255   
256if ($week > 0 )
257{
258        return $week. " " .l10n('Week'). " " .  $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " .    $minutes. " " .l10n('minute'). "s ".  $secondes." " .l10n('seconde')."s";
259}
260return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ".  $secondes." " .l10n('Seconde')."s";
261
262}       
263
264function memo_var($variables)
265{
266                ob_start();
267                echo '<pre>';
268                print_r($variables);
269                echo '</pre>';
270                $m= ob_get_contents();
271
272        ob_end_clean();
273                return $m;
274               
275}
276
277function vérif_base()
278{
279
280global $lang;
281 load_language('plugin.lang', MAIL_SUPERV_PATH);
282
283$q = "
284    CREATE TABLE IF NOT EXISTS ".MAIL_SUPERV_TABLE." (
285                `id` SMALLINT( 5 ) NOT NULL DEFAULT '0',
286               
287                `nb_mails` INT NOT NULL DEFAULT '0',
288                `date_mail` INT NOT NULL DEFAULT '0',
289                `nb_mails_maxi` INT NOT NULL DEFAULT '2000',           
290                `nb_mails_periode` TEXT  ,     
291               
292                `nb_spams` INT NOT NULL DEFAULT '0',
293                `date_spam` INT NOT NULL DEFAULT '0',   
294               
295                `nb_spams_maxi` INT NOT NULL DEFAULT '10',     
296                `nb_spams_periode` TEXT  ,     
297               
298                `quarantaine` TEXT ,
299                `date_quarantaine` INT NOT NULL DEFAULT '0',
300                `quarantaine_periode` TEXT  ,   
301                       
302               
303                `message` TEXT  ,
304                `message_test` TEXT  ,
305                `header_text` TEXT ,
306        PRIMARY KEY  (`id` )
307         )
308  ;";
309  pwg_query($q);
310 
311    $nb = Get_colonnes_de(MAIL_SUPERV_TABLE);
312        $table=$nb[MAIL_SUPERV_TABLE];   
313//================================================================================     
314    if (!in_array( "nb_mails",$table)) {       
315                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails` INT NOT NULL default '0' ";
316                           pwg_query($query);            } 
317        if (!in_array( "date_mail",$table)) {   
318          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_mail` INT NOT NULL default '0' ";
319                           pwg_query($query);            } 
320        if (!in_array( "nb_mails_maxi",$table)) {       
321          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_maxi` INT NOT NULL default '2000' ";
322                           pwg_query($query);            } 
323        if (!in_array( "nb_mails_periode",$table)) {   
324          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_periode` TEXT ";
325                           pwg_query($query);            } 
326                                                   
327                                                   
328    if (!in_array( "nb_spams",$table)) {       
329                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams` INT NOT NULL default '0' ";
330                           pwg_query($query);            } 
331        if (!in_array( "date_spam",$table)) {   
332          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_spam` INT NOT NULL default '0' ";
333                           pwg_query($query);            }                         
334                           
335    if (!in_array( "nb_spams_maxi",$table)) {   
336                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_maxi` INT NOT NULL default '10' ";
337                           pwg_query($query); 
338        if (!in_array( "nb_spams_periode",$table)) {   
339          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_periode` TEXT ";
340                           pwg_query($query);            }                                   } 
341                                                       
342                if (!in_array( "quarantaine",$table)) { 
343          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine` TEXT  , ";
344                           pwg_query($query);            }     
345                           
346                if (!in_array( "date_quarantaine",$table)) {   
347          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_quarantaine` INT NOT NULL default '0'    ";
348                           pwg_query($query);   
349                                    }   
350                if (!in_array( "quarantaine_periode",$table)) { 
351          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine_periode` TEXT ";
352                           pwg_query($query);            }                                         
353                               
354                if (!in_array( "message",$table)) {     
355          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message` TEXT   ";
356                           pwg_query($query);            }     
357                           
358                if (!in_array( "message_test",$table)) {       
359          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message_test` TEXT   ";
360                           pwg_query($query);            }                                 
361                           
362                if (!in_array( "header_text",$table)) { 
363          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `header_text` TEXT   ";
364                           pwg_query($query);            }             
365                                                                       
366//-------------------------------------------------------                           
367
368      $query = "
369                SELECT COUNT(`id`) as total
370                FROM `".MAIL_SUPERV_TABLE."`
371                         
372                ;";     
373//==============================================================================               
374list($count) = mysql_fetch_row(pwg_query($query));
375
376
377  if ($count == 0)
378  {
379         $next_day = time()  ;
380         $date_quarantaine=time();
381
382         
383           $q = '
384    INSERT INTO '.MAIL_SUPERV_TABLE.' (id,
385        nb_mails,date_mail,nb_mails_maxi,nb_mails_periode,
386        nb_spams,date_spam,nb_spams_maxi,nb_spams_periode,
387         quarantaine, date_quarantaine,quarantaine_periode,
388         message_test,
389         message,header_text)
390    VALUES (1,
391        0,
392        '.time().',
393        2000,
394        "1 '.l10n('Week').'",
395       
396        0,
397        '.time().',
398        10,
399        "2 '.l10n('Day').'",
400       
401        false,
402        '.time().',
403        "2 '.l10n('Day').'",
404       
405        "Init.",
406        "'.l10n('supervisor').'",
407         "'.l10n('hello').'"
408         )
409         ;';
410
411
412        pwg_query($q);
413       
414        } 
415}
416
417
418function Get_colonnes_de($table)
419{
420  $columns_of = array();
421    $query = 'DESC '.$table.';';
422    $result = mysql_query($query);
423    $columns_of[$table] = array();
424    while ($row = mysql_fetch_row($result))
425    {
426      array_push($columns_of[$table], $row[0]);
427    }
428  return $columns_of;
429}
430
431function get_liste($group_id)
432{
433global $conf ;
434
435  $query = '
436SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
437                u.'.$conf['user_fields']['username'].' AS username,
438                u.'.$conf['user_fields']['email'].' AS email,
439                ui.status,
440                ui.adviser,
441                ui.enabled_high,
442                ui.level
443  FROM '.USERS_TABLE.' AS u
444    INNER JOIN '.USER_INFOS_TABLE.' AS ui
445      ON u.'.$conf['user_fields']['id'].' = ui.user_id
446    LEFT JOIN '.USER_GROUP_TABLE.' AS ug
447      ON u.'.$conf['user_fields']['id'].' = ug.user_id
448  WHERE ug.group_id='.$group_id.' ';
449
450
451 
452 $groups=array();
453  $datas = pwg_query($query);
454 
455 
456  if (!empty($datas))
457  {
458    while ($group = mysql_fetch_array($datas))
459    {
460
461       
462      if (!empty($group['email']))
463      {
464        array_push($groups, format_email($group['username'], $group['email'] ));
465      }
466    }
467  } 
468  return $groups ;
469 
470}
471
472?>
Note: See TracBrowser for help on using the repository browser.