source: extensions/Mail_supervisor/admin/mail_superv_admin.php @ 4888

Last change on this file since 4888 was 4888, checked in by cljosse, 14 years ago

[Mail_supervisor] Fix Bug when the user is not french.

File size: 19.3 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
29if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
30
31global $user, $lang, $conf, $errors,$mails_données;
32global $args, $conf_mail,$infos_message,$erreur_message,$mails_options ;
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36//check_status(ACCESS_ADMINISTRATOR);
37include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
38include_once (PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
39
40
41$my_base_url = get_admin_plugin_menu_link(__FILE__);
42
43 load_language('plugin.lang', MAIL_SUPERV_PATH);
44 //=========================================================
45 $sv_Week=explode(" ",l10n('Week %d'));
46if( !isset($lang['Week'])) $lang['Week'] =   $sv_Week[0];
47
48
49$lang['Sv_format_d'] = '+1 '.$lang['Week'].'<br />
50  +1 '.$lang['Day'].'<br />
51  +1 '.$lang['Hour'].'<br />
52  +1 '.$lang['Minute'].'<br />
53  +1 '.$lang['Second'].'<br />'; 
54 //============================================================== 
55 load_language('help/plugin.lang', MAIL_SUPERV_PATH);   
56 
57        if (!isset($_GET['tab']))
58        $page['tab'] = 'mail_superv_admin';
59else
60  $page['tab'] = $_GET['tab'];
61
62 $icon_path = 'template/yoga/icon/help.png';
63
64$tabhelp=  '  <img src="'.PHPWG_ROOT_PATH. $icon_path .'" class="button" alt="(?)"> ';
65
66 
67
68$tabsheet = new tabsheet();
69$tabsheet->add('mail_superv_admin',
70               l10n('Sv_Tab_set'),
71               $my_base_url.'&amp;tab=mail_superv_admin');
72                           
73$tabsheet->add('mail_superv_test',
74               l10n('Sv_Tab_test'),
75               $my_base_url.'&amp;tab=mail_superv_test');
76                           
77$tabsheet->add( 'mail_black_liste',
78               l10n('Sv_blackliste'),
79                           $my_base_url.'&amp;tab=mail_black_liste');
80 
81                                                   
82$tabsheet->add('mail_superv_help',$tabhelp
83              ,
84               $my_base_url.'&amp;tab=mail_superv_help');
85                           
86                           
87$tabsheet->select($page['tab']);
88$tabsheet->assign();
89
90$page['global'] = array();
91$error = array();
92
93
94include_once (MAIL_SUPERV_PATH.'include/constants.php'); 
95
96        if (!isset($infos_message))
97        {
98        $infos_message = "";
99        }
100if (!isset($erreur_message))
101        {
102        $erreur_message = "";
103        }
104
105if (isset($conf['mail_superv'])) {
106
107include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 
108            global $pays,$region,$ville,$ip ;   
109
110               
111$mails_options = explode("," , $conf['mail_superv']); 
112        if (!isset($mails_options[set_id])) $mails_options[set_id] = 'off' ;  // 7
113                if (!isset($mails_options[ip])) $mails_options[ip] = $ip   ;  //6
114                if (!isset($mails_options[set_auto])) $mails_options[set_auto] = 'off' ;  //5
115                if (!isset($mails_options[no_connect])) $mails_options[no_connect] = 'off' ;  //4
116                if (!isset($mails_options[no_mail_list])) $mails_options[no_mail_list] = 'off' ;  //3
117               
118                if (!isset($mails_options[check_header_text])) $mails_options[check_header_text] = 'off' ;  //2
119                if (!isset($mails_options[check_header_carbon])) $mails_options[check_header_carbon] = 'off' ;  //1
120                if (!isset($mails_options[check_mailto])) $mails_options[check_mailto] = 'off' ;  //0
121//================================================================================================             
122$mails_données = Get_Datas();
123
124
125}else {
126die ("mail");
127}
128
129
130$aff_nb=true;
131
132
133       
134// *************************************************************************
135// |                          Sélection de l'onglet                        |
136// *************************************************************************
137
138                $modif=false ;
139                /*
140                $sql="SELECT *
141FROM `".$prefixeTable."plugins`
142WHERE `id` LIKE 'Mail_supervisor'
143";
144 $result = @pwg_query($sql);
145        if ($result) {
146            $versions = mysql_fetch_array($result,MYSQL_ASSOC);
147        }
148$version = $versions['version'];
149*/
150$plugin =  Get_Version_plugins( MAIL_SUPERV_PATH);
151$version = $plugin['version'] ;
152 //=========================================================
153
154                if (!isset($ip)) {
155                       if (getenv("HTTP_CLIENT_IP"))
156                                            {    $ip=getenv("HTTP_CLIENT_IP");  }
157                                        else{   $ip=getenv("REMOTE_ADDR");      }
158                           }
159//================================================================================
160switch ($page['tab'])
161 {
162   
163// *************************************************************************
164//                         initialisation                                  |
165// *************************************************************************
166  case 'mail_superv_admin':
167       
168//=============================================================
169if ( isset($_POST['submit']) ) {
170 
171        if ( $_POST['submit'] == l10n('Sv_refresh')   ) {
172               
173        if ($mails_données['nb_mails'] == 0 ) 
174            $mails_données['date_mail'] = time();       
175       
176        if ($mails_données['nb_spams'] == 0 )
177           $mails_données['date_spam'] = time();
178       
179       
180        if ($mails_données['quarantaine'] == false)
181        { $mails_données['reste'] = 0;
182          $mails_données['date_quarantaine']=time();
183         }
184         $infos_message .=  l10n('Sv_refresh') .'<br />';
185     sauve_données();
186         $aff_nb = false ;
187 
188       
189        }
190
191        if ( $_POST['submit'] == l10n('Sv_raz')   ) {
192
193        $mails_données['date_quarantaine']=time();
194        $mails_données['nb_mails'] = 0  ;
195        $mails_données['nb_spams'] = 0  ;
196        $mails_données['date_mail'] = time();
197        $mails_données['date_spam'] = time();
198       
199        $mails_données['reste'] = 0;
200        $mails_données['quarantaine']='false';
201       
202     sauve_données();
203         $infos_message .=  l10n('Sv_raz') .'<br />'; ;
204       
205        }
206
207 
208        if ( $_POST['submit'] == l10n('Sv_Valider') ) 
209                {
210                $mails_options[check_mailto] = isset($_POST['check_mailto']) ? $_POST['check_mailto'] : 'off' ;               
211                $mails_options[check_header_carbon] = isset($_POST['check_header_carbon']) ? $_POST['check_header_carbon'] : 'off' ; 
212                $mails_options[check_header_text] = isset($_POST['check_header_text']) ? $_POST['check_header_text'] : 'off' ;     
213 
214                //données 
215                $mails_données['nb_mails_maxi'] = isset($_POST['nb_mails_maxi']) ? $_POST['nb_mails_maxi'] :  $mails_données['nb_mails_maxi']  ;
216                $mails_données['nb_mails_periode'] = isset($_POST['nb_mails_periode']) ? $_POST['nb_mails_periode'] :  $mails_données['nb_mails_periode']  ; 
217                $mails_données['nb_spams_maxi'] = isset($_POST['nb_spams_maxi']) ? $_POST['nb_spams_maxi'] :  $mails_données['nb_spams_maxi']  ;
218                $mails_données['nb_spams_periode'] = isset($_POST['nb_spams_periode']) ? $_POST['nb_spams_periode'] :  $mails_données['nb_spams_periode']  ;
219
220                $mails_données['quarantaine_periode'] = isset($_POST['quarantaine_periode']) ? $_POST['quarantaine_periode'] :  $mails_données['quarantaine_periode']  ;
221 
222                        $mails_données['message'] = isset($_POST['content']) ? $_POST['content'] :  $mails_données['message']  ;
223                        $mails_données['header_text'] = isset($_POST['header_text']) ? $_POST['header_text'] :  $mails_données['header_text']  ;
224 //=======================================================================================================
225                        vérif_mails_données();
226                        sauve_options();
227                sauve_données();
228//=======================================================================================================
229                        $infos_message  =  l10n('Sv_save_config') . " : " . l10n('Sv_Datas') . "<br />" ;
230                        $erreur_message = "";
231                        $mails_données = Get_Datas() ;
232                        }
233       }
234       
235        $mails_données = Get_Datas();
236    vérif_mails_données();
237//===============================================================================
238 
239        $rest_mail= $mails_données['rest_mail'];       
240        $rest_spam= $mails_données['rest_spam'];       
241    $reste= $mails_données['reste'];   
242
243$quarantaine = ($mails_données['quarantaine'] == 'true') ? true : false ;       
244
245$template->assign(
246                                        array(
247   'check_mailto' => ($mails_options[check_mailto] == 'on') ? 'checked="checked"' : '' ,
248   'check_header_carbons' => ($mails_options[check_header_carbon] == 'on') ? 'checked="checked"' : '' ,
249   'check_header_text' => ($mails_options[check_header_text] == 'on') ? 'checked="checked"' : '' ,
250
251   
252        'nb_mails' => $mails_données['nb_mails'] ,
253        'date_mail' => "'".date(l10n('Sv_formatdate'),$mails_données['date_mail'])."'" ,
254        'nb_mails_maxi' => $mails_données['nb_mails_maxi'] ,   
255        'nb_mails_periode' => "'". int_to_heure($mails_données['nb_mails_periode'])."'" ,       
256        'time_mails_reste' => "'".int_to_heure( $rest_mail )."'" ,     
257       
258        'nb_spams' => $mails_données['nb_spams'] ,
259        'date_spam' => "'".date(l10n('Sv_formatdate'),$mails_données['date_spam'])."'" ,
260        'nb_spams_maxi' => $mails_données['nb_spams_maxi'] ,   
261         'nb_spams_periode' => "'".int_to_heure($mails_données['nb_spams_periode'])."'" ,
262         'time_spams_reste' => "'".int_to_heure($rest_spam)."'" ,       
263         
264         'quarantaine' => $quarantaine ,
265        'date_quarantaine' => "'".date(l10n('Sv_formatdate'),time()+$reste)."'" ,
266        'quarantaine_periode' => "'".int_to_heure($mails_données['quarantaine_periode'])."'" ,
267     'reste' => "'".int_to_heure($reste)."'",
268 
269    'message' => $mails_données['message'] ,
270        'header_text' => "'".$mails_données['header_text']."'" ,
271       
272    'PHPWG_VERSION' =>   PHPWG_VERSION ,
273         'version' =>    $version ,
274       
275                                                )
276                                );     
277
278        $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.tpl')));
279                $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
280               
281 break; 
282 
283 
284// *************************************************************************
285//                        TEST                                             |
286// *************************************************************************
287 
288   case 'mail_superv_test':
289   
290   $mails_données = Get_Datas() ;
291   
292        $group_id = isset($_POST['group']) ? $_POST['group'] :  '-1'  ;
293        if ($group_id >= 0) {
294      $query = '
295                SELECT
296                name
297                FROM '.GROUPS_TABLE.'
298                WHERE id = '.$group_id.'
299                ;';
300                list($group_name) = mysql_fetch_row(pwg_query($query));
301                }       else {
302                                $group_name="";         
303                }               
304//================================================
305
306
307       
308if ( isset($_POST['test_envoie']) ) {
309       
310                $mails_données['message_test'] = isset($_POST['content']) ? $_POST['content'] :  $mails_données['message_test']  ;
311                $message=$mails_données['message_test'];
312                sauve_données();
313                test_envoie($message,$group_name,$group_id);   
314                $mails_données = Get_Datas() ;
315               
316  } 
317
318  $groups[-1] = '---------';
319
320  $query = '
321    SELECT id, name
322                FROM '.GROUPS_TABLE.'
323                ORDER BY name ASC
324                ;';
325
326  $result = pwg_query($query);
327//----------------------------------------------------------------     
328  while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
329  {
330    $groups[$row['id']] = $row['name'];
331  }
332 //---------------------------------------------------------------
333
334  $template->assign(
335        'Group',
336                array(
337                        'group_options'=> $groups,
338                        'selected' => $group_id 
339                        )
340                );
341//=================================================================
342$destinataires= implode("<br />",get_liste($group_id));
343  $template->assign(
344                                        array(
345                                'Groupe'     => $groups,
346                        'message_test' => $mails_données['message_test'] ,
347                                'liste' => $destinataires ,
348 'version' =>    $version ,
349                                                )
350                                );     
351                               
352        $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_superv_test.tpl')));
353                $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
354   break;
355// *************************************************************************
356//              BLACK LISTE                                         |
357// *************************************************************************   
358     case 'mail_black_liste':
359                global $user_name,$mail_adresse,$ip ;
360                $aff_nb=false;
361 //------------------------------------------------------------------------------------
362        $mails_options[no_mail_list] = isset($_POST['no_mail_list']) ? $_POST['no_mail_list'] : $mails_options[no_mail_list] ;
363        $mails_options[no_connect] = isset($_POST['no_connect']) ? $_POST['no_connect'] : $mails_options[no_connect] ;
364            $mails_options[set_auto] = isset($_POST['set_auto']) ? $_POST['set_auto'] : $mails_options[set_auto] ;             
365//=======================================================================================       
366    $info_ip = (isset($info_ip)) ? $info_ip : '' ;
367    $info_ip = (isset($_POST['info1'])) ? $_POST['info1'] : $info_ip ;
368    $info_ip = (isset($_POST['info'])) ? $_POST['info'] : $info_ip ;
369    $info_ip .= ":";
370   $val=explode(":",$info_ip);
371   $info_ip = trim($val[0]) ;
372   $ip_black = trim($val[1]) ;
373
374  if (isset($_POST['ip_black']))   $ip_black = ($ip_black == "" ) ? $_POST['ip_black'] : $ip_black ;
375   
376                        $istype="";
377                 
378                 
379        if ( isset($_POST['submit']) )
380                {
381
382        if (clj_is_ip($ip_black)) $istype='IP';
383         elseif (clj_is_mail($ip_black))  $istype='MAIL';
384     else   $istype='LOGIN';
385         
386                        if (  $_POST['submit'] == l10n('Sv_Ajout') )
387                {
388                               $info_ip = 'Ajout' ;
389                   $ip_black = trim( $_POST['ip_black']) ;
390                               $infos_message .= $info_ip . '---->'. $ip_black ;   
391                        }
392                        if (  $_POST['submit'] == l10n('Sv_Valider') )
393                {
394                                $mails_options[no_mail_list] = isset($_POST['no_mail_list']) ? $_POST['no_mail_list'] : "off" ;
395                        $mails_options[no_connect] = isset($_POST['no_connect']) ? $_POST['no_connect'] : "off" ;
396                        $mails_options[set_auto] = isset($_POST['set_auto']) ? $_POST['set_auto'] : "off" ;
397                                $mails_options[set_id] = isset($_POST['set_id']) ? $_POST['set_id'] : "off" ;
398                                sauve_options();
399                            $infos_message .=  l10n('Sv_save_config') . '<br />';   
400                           
401                        }
402                }       
403
404include  (MAIL_SUPERV_PATH.'include/save_info.php');       
405
406//=======================================================================================       
407        $f_action  = $my_base_url.'&amp;tab=mail_black_liste' ;
408        $champs_ip=array();
409        $champs_bl=array();
410        if (!empty($liste_ip))          $champs_ip=array_keys($liste_ip[0]);
411        if (!empty($liste_bl))      $champs_bl=array_keys($liste_bl[0]);
412           $smile_bonjour=MAIL_SUPERV_PATH."smilies/mouche.gif" ; 
413           $img_logo=MAIL_SUPERV_PATH."smilies/logo.png" ; 
414     $template->assign(
415                                        array(
416                                            'smile_bonjour' => $smile_bonjour ,
417                                                'img_logo' => $img_logo ,
418                                'champs_ip' => $champs_ip ,                                     
419                                                'liste_ip' => $liste_ip,
420                                                'champs_bl' =>  $champs_bl       ,     
421                                                'liste_bl' => $liste_bl ,
422                                'conf_admin_layout' => $conf['admin_layout'] ,
423                                                'istype' => $istype ,
424                                                'ip_black' => $ip_black ,
425                                                'IS_SPAM' => test_spam(  $ip_black),
426                                                'ip_black_len' =>  strlen($ip_black)  ,
427                                                'MAIL_SUPERV_PATH' => MAIL_SUPERV_PATH ,
428
429                                                'F_ACTION' => $f_action ,
430                                               
431                                                'no_mail_list' => ($mails_options[no_mail_list] == 'on') ? 'checked="checked"' : '' ,
432                        'no_connect' => ($mails_options[no_connect] == 'on') ? 'checked="checked"' : '' ,
433                                                'set_auto' => ($mails_options[set_auto] == 'on') ? 'checked="checked"' : '' ,
434                                                'set_id' => ($mails_options[set_id] == 'on') ? 'checked="checked"' : '' ,
435                                                'IP' =>  $ip ,                                         
436                                                'PAYS' =>  $pays  ,
437                                'VILLE' =>  $ville ,
438                                'REGION' =>  $region , 
439                                                 'version' =>    $version ,
440                                        )
441                                );                       
442         //===============================================================     
443               
444                                 
445                $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_black_liste.tpl')));
446                $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
447   break; 
448
449// *************************************************************************
450//                      AIDE                                               |
451// *************************************************************************   
452     case 'mail_superv_help':
453
454 
455          $aff_nb=false;
456          $smile_bonjour=MAIL_SUPERV_PATH."smilies/bonjour.gif" ; 
457      $template->assign(
458                                        array(
459                                        'smile_bonjour' => $smile_bonjour ,
460                                         'version' =>    $version ,
461                                        )
462                        );             
463        $aff_nb = false;
464        ;
465         
466                $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_superv_help.tpl')));
467                $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
468   break; 
469 //====================================================================
470  }
471//================================================================================
472
473
474        if  ( $mails_données['reste'] < 0 ) {
475            $mails_données['quarantaine'] =false ;
476            $mails_données['date_quarantaine']= time()  ;       
477                $mails_données['nb_spams'] = 0 ;
478            $modif == true ;
479        }
480         
481         
482        $rest_mail =    $mails_données['rest_mail'] ;
483        if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){
484           $mails_données['nb_mails'] =0 ;
485           $mails_données['date_mail'] = time();
486           $modif = true ;
487        }
488       
489        $rest_spam =    $mails_données['rest_spam'] ;
490
491        if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){
492           $mails_données['nb_spams'] =0 ;
493           $mails_données['date_spam'] = time();
494           $modif = true ;
495        }
496        if ( $modif == true )   { 
497                                sauve_données();
498                                $modif = false ;
499                }
500
501                if ($aff_nb == true) {
502                 $infos_message .= 'Mails    : '.$mails_données['nb_mails']. '  \\  ' . $mails_données['nb_mails_maxi'];
503                 $infos_message .= "\n".'Spams : '.$mails_données['nb_spams']. '  \\  ' . $mails_données['nb_spams_maxi'];
504                }
505               
506
507                 
508                if  ($infos_message != "")  {
509                   array_push($page['infos'],  $infos_message);
510                   $infos_message="";
511                 }
512                 
513                if  ($erreur_message != "")  {
514       
515                  array_push($page['errors'], $erreur_message);
516                  $erreur_message="";
517       
518                 
519                 }               
520//========================================================================     
521?>
Note: See TracBrowser for help on using the repository browser.