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

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

[mail_supervisor] insert multi tabs

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