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

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

[mail_supervisor] bug in corrige_header

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