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

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

[mail_supervisor] modif bug in fonctions.php

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//===============================================
182function not_is_empty($variable)
183{
184global $args;
185
186 echo $variable." ".count($args[$variable]) ;
187 if (isset($args[$variable]))
188 
189  {
190 
191     if ( count($args[$variable]) > 0) ;
192        {
193 echo count($args[$variable]) ;
194        $args[$variable]=array_filter($args[$variable]);
195 echo count($args[$variable]) ;
196 
197         }
198  }
199}
200       
201
202//=================================================================================
203function corrige_header($Carbonne,$headers)
204        {
205        global $mails_options,$conf_mail,$mailto,$args;
206        $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', $Carbonne.' : '.get_strict_email_list()."\n", $headers);
207return $headers;
208
209               
210        }
211       
212function int_to_heure($int)
213{
214$week= (int) ($int/(3600*24*7)); 
215$int=$int-($week*(3600*24*7)); 
216
217$day= (int) ($int/(3600*24));   
218$int=$int-($day*(3600*24));
219
220$heures=(int) ($int/3600);
221
222$int=$int-($heures*(3600));
223
224$minutes=(int) ($int/60);
225$int= $int - ($minutes*(60));
226
227$secondes=(int) ($int);
228
229$heures= substr ('00'. $heures,-2,2);   
230$day= substr ('00'.  $day,-2,2);   
231$minutes=substr ('00'.$minutes,-2,2);
232$secondes=substr ('00'.$secondes,-2,2);
233
234if ($week > 0 )
235{
236
237return $week. " " .l10n('Week'). " " .  $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('minute'). "s ".  $secondes." " .l10n('seconde')."s";
238}
239return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ".  $secondes." " .l10n('Seconde')."s";
240
241}       
242
243function memo_var($variables)
244{
245                ob_start();
246                echo '<pre>';
247                print_r($variables);
248                echo '</pre>';
249                $m= ob_get_contents();
250
251        ob_end_clean();
252                return $m;
253               
254}
255
256function vérif_base()
257{
258
259$q = "
260    CREATE TABLE IF NOT EXISTS ".MAIL_SUPERV_TABLE." (
261                `id` SMALLINT( 5 ) NOT NULL DEFAULT '0',
262               
263                `nb_mails` INT NOT NULL DEFAULT '0',
264                `date_mail` INT NOT NULL DEFAULT '0',
265                `nb_mails_maxi` INT NOT NULL DEFAULT '2000',           
266                `nb_mails_periode` TEXT  ,     
267               
268                `nb_spams` INT NOT NULL DEFAULT '0',
269                `date_spam` INT NOT NULL DEFAULT '0',   
270               
271                `nb_spams_maxi` INT NOT NULL DEFAULT '10',     
272                `nb_spams_periode` TEXT  ,     
273               
274                `quarantaine` TEXT ,
275                `date_quarantaine` INT NOT NULL DEFAULT '0',
276                `quarantaine_periode` TEXT  ,   
277                       
278               
279                `message` TEXT  ,
280                `message_test` TEXT  ,
281                `header_text` TEXT ,
282        PRIMARY KEY  (`id` )
283         )
284  ;";
285  pwg_query($q);
286 
287    $nb = Get_colonnes_de(MAIL_SUPERV_TABLE);
288        $table=$nb[MAIL_SUPERV_TABLE];   
289//================================================================================     
290    if (!in_array( "nb_mails",$table)) {       
291                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails` INT NOT NULL default '0' ";
292                           pwg_query($query);            } 
293        if (!in_array( "date_mail",$table)) {   
294          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_mail` INT NOT NULL default '0' ";
295                           pwg_query($query);            } 
296        if (!in_array( "nb_mails_maxi",$table)) {       
297          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_maxi` INT NOT NULL default '2000' ";
298                           pwg_query($query);            } 
299        if (!in_array( "nb_mails_periode",$table)) {   
300          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_periode` TEXT ";
301                           pwg_query($query);            } 
302                                                   
303                                                   
304    if (!in_array( "nb_spams",$table)) {       
305                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams` INT NOT NULL default '0' ";
306                           pwg_query($query);            } 
307        if (!in_array( "date_spam",$table)) {   
308          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_spam` INT NOT NULL default '0' ";
309                           pwg_query($query);            }                         
310                           
311    if (!in_array( "nb_spams_maxi",$table)) {   
312                $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_maxi` INT NOT NULL default '10' ";
313                           pwg_query($query); 
314        if (!in_array( "nb_spams_periode",$table)) {   
315          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_periode` TEXT ";
316                           pwg_query($query);            }                                   } 
317                                                       
318                if (!in_array( "quarantaine",$table)) { 
319          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine` TEXT  , ";
320                           pwg_query($query);            }     
321                           
322                if (!in_array( "date_quarantaine",$table)) {   
323          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_quarantaine` INT NOT NULL default '0'    ";
324                           pwg_query($query);   
325                                    }   
326                if (!in_array( "quarantaine_periode",$table)) { 
327          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine_periode` TEXT ";
328                           pwg_query($query);            }                                         
329                               
330                if (!in_array( "message",$table)) {     
331          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message` TEXT   ";
332                           pwg_query($query);            }     
333                           
334                if (!in_array( "message_test",$table)) {       
335          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message_test` TEXT   ";
336                           pwg_query($query);            }                                 
337                           
338                if (!in_array( "header_text",$table)) { 
339          $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `header_text` TEXT   ";
340                           pwg_query($query);            }             
341                                                                       
342                                           
343      $query = "
344                SELECT COUNT(*)
345                FROM ".MAIL_SUPERV_TABLE."
346                ;";
347//==============================================================================               
348  list($count) = mysql_fetch_row(pwg_query($query));
349  if ($count == 0)
350  {
351         $next_day = time()  ;
352         $date_quarantaine=time();
353           $q = '
354    INSERT INTO '.MAIL_SUPERV_TABLE.' (id,
355        nb_mails,date_mail,nb_mails_maxi,nb_mails_periode,
356        nb_spams,date_spam,nb_spams_maxi,nb_spams_periode,
357         quarantaine, date_quarantaine,quarantaine_periode,
358         message,header_text)
359    VALUES (1,
360        0,
361        '.time().',
362        2000,
363        "1 "'.l10n('Week').'",
364       
365        0,
366        '.time().',
367        10,
368        "2 "'.l10n('Day').'",
369       
370        false,
371        '.time().',
372        "2 "'.l10n('Day').'",
373       
374        "Init.",
375        "'.l10n('supervisor').'",
376         "'.l10n('hello').'"
377         )
378         ;';
379
380
381        pwg_query($q);
382       
383        } 
384}
385function Get_colonnes_de($table)
386{
387  $columns_of = array();
388    $query = 'DESC '.$table.';';
389    $result = mysql_query($query);
390    $columns_of[$table] = array();
391    while ($row = mysql_fetch_row($result))
392    {
393      array_push($columns_of[$table], $row[0]);
394    }
395  return $columns_of;
396}
397
398function get_liste($group_id)
399{
400global $conf ;
401
402  $query = '
403SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
404                u.'.$conf['user_fields']['username'].' AS username,
405                u.'.$conf['user_fields']['email'].' AS email,
406                ui.status,
407                ui.adviser,
408                ui.enabled_high,
409                ui.level
410  FROM '.USERS_TABLE.' AS u
411    INNER JOIN '.USER_INFOS_TABLE.' AS ui
412      ON u.'.$conf['user_fields']['id'].' = ui.user_id
413    LEFT JOIN '.USER_GROUP_TABLE.' AS ug
414      ON u.'.$conf['user_fields']['id'].' = ug.user_id
415  WHERE ug.group_id='.$group_id.' ';
416
417
418 
419 $groups=array();
420  $datas = pwg_query($query);
421 
422 
423  if (!empty($datas))
424  {
425    while ($group = mysql_fetch_array($datas))
426    {
427
428       
429      if (!empty($group['email']))
430      {
431        array_push($groups, format_email($group['username'], $group['email'] ));
432      }
433    }
434  } 
435  return $groups ;
436 
437}
438
439?>
Note: See TracBrowser for help on using the repository browser.