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

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

[mail_supervisor] Addition of a help.

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