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

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

[mail_supervisor] delete warning message during test_envoie

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