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

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

[mail_supervisor] bug in traduction files

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