Ignore:
Timestamp:
Apr 10, 2013, 10:58:35 AM (11 years ago)
Author:
cljosse
Message:

[extensions] mail_superviseur update to piwigo 2.5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/mail_super.inc.php

    r13572 r22118  
    2222
    2323class mail_supervisor {
    24  //============================================================
    25  /*
    26   *  admin_menu
    27  */
    28  static public function admin_menu($menu) {
    29   array_push($menu,
    30              array( 'NAME' => 'Mail supervisor',
    31                             'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')
    32                         )
    33             );
    34     return $menu;
    35  }
    36  //============================================================
    37  /*
    38   *  init
    39  */
    40  static public function init() {
    41   global  $template,$version,$icon_path,$page;
    42   $action_spam = pwg_get_session_var('action_spam') ;
    43   $theme="default";
    44   $themeconf=$template->get_template_vars('themeconf');
    45   $theme=$themeconf['id'];
    46   if (file_exists ( 'admin/themes/clear/icon/help.png')) $icon_path = 'admin/themes/clear/icon/help.png';
    47   else  $icon_path =  "admin/template/goto/theme/clear/icon/help.png";
    48   if (PHPWG_VERSION < 2.2 ) {
    49     $file =MAIL_SUPERV_PATH_ABS.'admin/header_2_1.tpl' ;
    50 
    51   } else {
    52     $file = MAIL_SUPERV_PATH_ABS.'admin/header_2_2.tpl' ;
    53 
    54   }
    55   if(isset($_GET['action_spam']) and $_GET['action_spam']=="no"){
    56     pwg_set_session_var('action_spam', "false");
    57     unset ($_SESSION['pwg_'.'action_spam']);
    58   }
    59   $action_spam=pwg_get_session_var('action_spam');
    60   $template->set_filenames(array('mail_superv_init'=> $file ));
    61   $MAIL_SUPERV_PATH=str_replace(PHPWG_ROOT_PATH,"",MAIL_SUPERV_PATH) ;
    62   $profile=array('theme' => $theme,
    63             'PHPWG_VERSION' => PHPWG_VERSION ,
    64             'MAIL_SUPERV_PATH' => $MAIL_SUPERV_PATH  ,
    65             'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS
    66           );
    67 
    68   $template->assign( $profile );
    69   $template->append('footer_elements', '<input id="action_spam" name="action_spam" type="hidden" value="'.$action_spam.'" />');
    70   $template->parse( 'mail_superv_init', false);
    71   return ;//
    72 }// function init
    73   //============================================================
    74   /*
    75   * affiche_message
    76   */
    77   //============================================================
    78   static public function affiche_message(){
    79     global $template,$infos_message,$erreur_message, $user ,$ip;
    80     global $mails_options,$conf,$lang,$page ;
    81     global $action_spam ;
    82     if (!isset($ip)) {
    83       if (getenv("HTTP_CLIENT_IP"))   {
    84         $ip=getenv("HTTP_CLIENT_IP");
    85       }else{
    86           $ip=getenv("REMOTE_ADDR");
    87       }
    88     }
    89       //  unset ($_SESSION['pwg_'.'action_spam']);
    90       $action_spam = pwg_get_session_var('action_spam') ;
    91 
    92       if  ($action_spam == null or $action_spam == 'false') {
    93         $action_spam = kill_list();
    94       }
    95 
    96       if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ;
    97       if ($action_spam == "true" ) {
    98         $erreur_message .= $ip . " "  . $action_spam  ;
    99         pwg_set_session_var('action_spam', "true");
    100         $erreur_message .= "<br />".l10n('Sv_is_a_spam') ;
    101         if ($mails_options['no_connect'] == 'on1' ){
    102                   //[status] => guest
    103                   //[status] => normal
    104                   //[status] => webmaster
    105           if ($user['status'] != 'webmaster'  )
    106             if (!isset($_GET['admin'])) {
    107               die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
    108             }elseif ($_GET['admin'] != 'piwigo'){
    109               die('blacklist Hacking attempt!');
    110             }
    111          unset ($_SESSION['pwg_'.'action_spam']);
    112       }
    113     }else{
    114       pwg_set_session_var('action_spam', "false");
    115     }
    116 
    117     if (isset($infos_message))
    118       if  ($infos_message != "")  {
    119         $infos_message = str_replace("\n",'<br />',$infos_message) ;
    120          if (!isset($page['infos'])) $page['infos']=Array($infos_message);
    121         else if(is_array($page['infos'])) array_push($page['infos'], $infos_message);
    122         else $page['infos']=Array($infos_message);
    123         $infos_message="";
    124       }
    125     if (isset($erreur_message))
    126       if  ($erreur_message != "")  {
    127         $erreur_message = str_replace("\n",'<br />',$erreur_message) ;
    128         if (!isset($page['errors'])) $page['errors']=Array($erreur_message);
    129         else if(is_array($page['errors'])) array_push($page['errors'], $erreur_message);
    130         else $page['errors']=Array($erreur_message);
    131         $erreur_message ="";
    132       }
    133     return $action_spam;
    134   } //fin Affiche_message
    135 
    136     //============================================================
    137   /*
    138     *   Get_geo
    139   */
    140   static public function Get_geo() {
    141     global  $info_geo,$ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options;
    142     //===================================================================================
    143     $info_geo = pwg_get_session_var('info_geo');
    144     if (count($info_geo) > 0){
    145         $pays  = $info_geo[0];
    146         $region  = $info_geo[1];
    147         $ville  = $info_geo[2];
    148         $latitude = $info_geo[3];
    149         $longitude = $info_geo[4];
    150         $ip = $info_geo[5];
    151         return true;
    152     }
    153     //=======================================================================
    154     if (isset($_POST['pays'])) {
    155       $pays = isset($_POST['pays']) ? $_POST['pays'] : "";
    156       $region =  isset($_POST['region']) ? $_POST['region'] :"";
    157       $ville = (isset($_POST['ville']))   ? $_POST['ville']: "";
    158       $latitude =  isset($_POST['latitude']) ? $_POST['latitude'] : "";
    159       $longitude =  isset($_POST['longitude']) ? $_POST['longitude'] : "";
    160       $info_geo = array(   $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR']  );
    161       pwg_set_session_var('info_geo', $info_geo);
    162         return true;
    163       }else{
    164 
    165      $result="";
    166       echo '<script type="text/javascript">get_script_geo();</script>';
    167    return true;
    168       }
    169     } // fin get_geo
    170     //=====================================================================================
    171     /*
    172     * Memo_Var
    173     */
    174     static public function Memo_Var($variables) {
    175     ob_start();
    176     echo '<pre>';
    177     if(count($variables)>1){
    178     foreach($variables as $key => $line){
    179       echo  $key . " =>  " . $line ;
    180       echo "<br />";
    181     }
    182     }else{
    183         echo "<i>".$variables."</i><br />";
    184     }
    185 
    186     $m= ob_get_contents();
    187     ob_end_clean();
    188     return $m;
    189     }
    190   //======================================================================================
    191    static public function Get_Version_plugins($dir){
    192       $path = $dir;
    193       $plg_data = implode( '', file($path.'main.inc.php') );
    194       if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
    195       {
    196         $plugin['name'] = trim( $val[1] );
    197       }
    198       if (preg_match("|Version: (.*)|", $plg_data, $val))
    199       {
    200         $plugin['version'] = trim($val[1]);
    201       }
    202       if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
    203       {
    204         $plugin['uri'] = trim($val[1]);
    205       }
    206       if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
    207       {
    208         $plugin['description'] = trim($desc);
    209       }
    210       elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
    211       {
    212         $plugin['description'] = trim($val[1]);
    213       }
    214       if ( preg_match("|Author: (.*)|", $plg_data, $val) )
    215       {
    216         $plugin['author'] = trim($val[1]);
    217       }
    218       if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
    219       {
    220         $plugin['author uri'] = trim($val[1]);
    221       }
    222       if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
    223       {
    224         list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
    225         if (is_numeric($extension)) $plugin['extension'] = $extension;
    226       }
    227       // IMPORTANT SECURITY !
    228       $plugin = array_map('htmlspecialchars', $plugin);
    229       return $plugin ;
    230     }
    231   //==========================================================
    232   function Get_Options(&$parametres,$str_index){
    233     global $conf ;
    234     $mails_options=  $conf[$str_index];
    235      if(isset($mails_options))
    236        if ( preg_match("|s:(.*)|", $mails_options, $val) )
    237         $parametres =  unserialize($conf['mail_superv']);
    238        else{
    239          $parametres=explode(",",$mails_options);
    240         }     
    241         //====== par defaut =======================
    242          $new_val=false;
    243 
    244   if (empty($def_para))
    245 $def_para = (object) '';
    246 
    247         $def_para->check_mailto="on";
    248         $def_para->check_header_carbon="on";
    249         $def_para->check_send_webmaster="off";
    250         $def_para->no_ipaddress="off";  // interdiction adresse ip
    251 
    252         $def_para->no_mail_list="on";
    253         $def_para->no_connect="on"; // empeche l'ip de se connecter au site.
    254         $def_para->set_auto="on";       // Test a l'ouverture et enregistrement
    255         $def_para->ip="127.0.0.1";      // derniere adresse IP
    256         $def_para->set_id="on";       // enregistrment nouvel
    257         $def_para->debug_mail="off";       // debogage
    258 
    259         foreach ($def_para as $key => $value) {
    260           if(isset($parametres[$key])){
    261               $value=$parametres[$key];
    262            } else {
    263               $new_val=true;
    264         }
    265            $new_val= isset($_POST[$key]) && $new_val ;
    266             unset( $parametres[$key]) ;
    267             $parametres[$key]= (isset($_POST[$key]))? "on" : $value ;       
    268         }
    269 
    270         if($new_val){
    271             sauve_options();
    272       }
    273     return $parametres ;
    274   }
    275   //==========================================================
    276   function Set_Options($parametres,$str_index){
    277   global $infos_message,$conf;
    278       foreach ($parametres as $key => $value) {
    279        $parametres[$key]=(isset($_POST[$key]))? "on" : $value ;
    280       }
    281       $parametres['no_connect']= 'off' ;
    282      return $parametres ;
    283   }
    284   //==========================================================
    285 
    286 function sauve_options(){
    287   global $options,$infos_message,$conf,$mails_options  ;
    288   $infos_message .=l10n("save_config")."<br>";
    289        if (empty($mail_supervisor))  {
    290       $mail_supervisor = new mail_supervisor();
    291       }
    292   $mails_parametres= $mail_supervisor->Set_Options($mails_options,"mail_superv");
    293 
    294  if ( isset($mails_parametres) )
    295     {       $query = '
    296             UPDATE '.CONFIG_TABLE.'
    297             SET value="'.addslashes(serialize($mails_parametres)).'"
    298             WHERE param = "mail_superv"
    299             LIMIT 1';
    300             pwg_query($query);
    301       }
    302 
    303  }
    304 
    305  /****************************************
    306  * sauve_donnees()
    307  ****************************************/
    308   function sauve_donnees(){
    309   global $mails_donnees,$superv_champs,$superv_type,$erreur_message ;
    310   //=====================================================================
    311   $clefs = $superv_champs ;
    312   $valeurs = array();
    313   foreach ( $clefs as $champ){
    314      $champ = trim($champ);
    315         if($champ !="id")
    316         if ( isset($mails_donnees[  $champ ]) ) {
    317           $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ;
    318           array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[  $champ ] . $sep)  ;
    319         }else{
    320           array_push($valeurs , "`".$champ."`" . ' = ' .  "0"  )  ;
    321         }
    322       }
    323 
    324   $valeurs = implode(", ",$valeurs) ;
    325   //=====================================================================
    326   $query = '
    327           UPDATE '.mail_superv_TABLE.'
    328           SET '. $valeurs .'
    329           WHERE `id` = 1 LIMIT 1 ';
    330           ;
    331   ob_start();
    332       $ret=  pwg_query($query)    ;
    333       $m= ob_get_contents();
    334       if($m!="") $m="Mail_super.inc.php sauve_donnees() l:323<br />".$m;
    335   ob_end_clean() ;
    336   $erreur_message .= $m ;
    337   }
    338 //=================================================================================
    339   function Get_Datas(){
    340     global $superv_champs ;
    341      verif_base();
    342     $champs = implode(",",$superv_champs );
    343       $query = "SELECT ".$champs."
    344       FROM ".mail_superv_TABLE."
    345       ;";
    346         $result = @pwg_query($query);
    347            
    348     if (!$result) {
    349             verif_base();
    350             $result = @pwg_query($query);
    351         }
    352     $data = mysql_fetch_array($result,MYSQL_ASSOC);
    353     //====================================================================================
    354     $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] );
    355     $next_day = ($next_day >0) ? $next_day :  (604800  + time()) ;
    356     $data['rest_mail'] =    $next_day - time() ;
    357     $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']);
    358     $next_day = ($next_day >0) ? $next_day :  (172800  + time()) ;
    359     $data['rest_spam'] =  $next_day - time() ;
    360     $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']);
    361     $next_day = ($next_day >0) ? $next_day :  (172800 + time()) ;
    362     //====================================================================================
    363     if ($data['quarantaine'] == 'true' ) {
    364             $data['reste'] =   ( $next_day )-time() ;
    365     }else{
    366             $data['reste'] = 0;
    367     }
    368 
    369         return $data;
    370   }
    371  }
     24        //============================================================
     25        /*
     26        *  admin_menu
     27        */
     28        static public function admin_menu($menu) {
     29                array_push($menu,
     30                array( 'NAME' => 'Mail supervisor',
     31                'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')
     32                )
     33                );
     34                return $menu;
     35        }
     36        //============================================================
     37        /*
     38        *  init
     39        */
     40        static public function init() {
     41                global  $template,$version,$icon_path,$page;
     42                $action_spam = pwg_get_session_var('action_spam') ;
     43                $theme="default";
     44                $themeconf=$template->get_template_vars('themeconf');
     45                $theme=$themeconf['id'];
     46                if (file_exists ( 'admin/themes/clear/icon/help.png')) $icon_path = 'admin/themes/clear/icon/help.png';
     47                else  $icon_path =  "admin/template/goto/theme/clear/icon/help.png";
     48                if (PHPWG_VERSION < 2.2 ) {
     49                        $file =MAIL_SUPERV_PATH_ABS.'admin/header_2_1.tpl' ;
     50
     51                } else {
     52                        $file = MAIL_SUPERV_PATH_ABS.'admin/header_2_2.tpl' ;
     53
     54                }
     55                if(isset($_GET['action_spam']) and $_GET['action_spam']=="no"){
     56                        pwg_set_session_var('action_spam', "false");
     57                        unset ($_SESSION['pwg_'.'action_spam']);
     58                }
     59                $action_spam=pwg_get_session_var('action_spam');
     60                $template->set_filenames(array('mail_superv_init'=> $file ));
     61                $MAIL_SUPERV_PATH=str_replace(PHPWG_ROOT_PATH,"",MAIL_SUPERV_PATH) ;
     62                $profile=array('theme' => $theme,
     63                                'PHPWG_VERSION' => PHPWG_VERSION ,
     64                                'MAIL_SUPERV_PATH' => $MAIL_SUPERV_PATH  ,
     65                                'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS
     66                );
     67
     68                $template->assign( $profile );
     69                $template->append('footer_elements', '<input id="action_spam" name="action_spam" type="hidden" value="'.$action_spam.'" />');
     70                $template->parse( 'mail_superv_init', false);
     71                return ;//
     72        }// function init
     73        //============================================================
     74        /*
     75         * affiche_message
     76        */
     77        //============================================================
     78        static public function affiche_message(){
     79                global $template,$infos_message,$erreur_message, $user ,$ip;
     80                global $mails_options,$conf,$lang,$page ;
     81                global $action_spam ;
     82                if (!isset($ip)) {
     83                        if (getenv("HTTP_CLIENT_IP"))   {
     84                                $ip=getenv("HTTP_CLIENT_IP");
     85                        }else{
     86                                $ip=getenv("REMOTE_ADDR");
     87                        }
     88                }
     89                //  unset ($_SESSION['pwg_'.'action_spam']);
     90                $action_spam = pwg_get_session_var('action_spam') ;
     91
     92                if  ($action_spam == null or $action_spam == 'false') {
     93                        $action_spam = kill_list();
     94                }
     95
     96                if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ;
     97                if ($action_spam == "true" ) {
     98                        $erreur_message .= $ip . " "  . $action_spam  ;
     99                        pwg_set_session_var('action_spam', "true");
     100                        $erreur_message .= "<br />".l10n('Sv_is_a_spam') ;
     101                        if ($mails_options['no_connect'] == 'on1' ){
     102                                //[status] => guest
     103                                //[status] => normal
     104                                //[status] => webmaster
     105                                if ($user['status'] != 'webmaster'  )
     106                                        if (!isset($_GET['admin'])) {
     107                                        die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
     108                                }elseif ($_GET['admin'] != 'piwigo'){
     109                                        die('blacklist Hacking attempt!');
     110                                }
     111                                unset ($_SESSION['pwg_'.'action_spam']);
     112                        }
     113                }else{
     114                        pwg_set_session_var('action_spam', "false");
     115                }
     116
     117                if (isset($infos_message))
     118                        if  ($infos_message != "")  {
     119                        $infos_message = str_replace("\n",'<br />',$infos_message) ;
     120                        if (!isset($page['infos'])) $page['infos']=Array($infos_message);
     121                        else if(is_array($page['infos'])) array_push($page['infos'], $infos_message);
     122                        else $page['infos']=Array($infos_message);
     123                        $infos_message="";
     124                }
     125                if (isset($erreur_message))
     126                        if  ($erreur_message != "")  {
     127                        $erreur_message = str_replace("\n",'<br />',$erreur_message) ;
     128                        if (!isset($page['errors'])) $page['errors']=Array($erreur_message);
     129                        else if(is_array($page['errors'])) array_push($page['errors'], $erreur_message);
     130                        else $page['errors']=Array($erreur_message);
     131                        $erreur_message ="";
     132                }
     133                return $action_spam;
     134        } //fin Affiche_message
     135
     136        //============================================================
     137        /*
     138        *   Get_geo
     139        */
     140        static public function Get_geo() {
     141                global  $info_geo,$ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options;
     142                //===================================================================================
     143                $info_geo = pwg_get_session_var('info_geo');
     144                if (count($info_geo) > 0){
     145                        $pays  = $info_geo[0];
     146                        $region  = $info_geo[1];
     147                        $ville  = $info_geo[2];
     148                        $latitude = $info_geo[3];
     149                        $longitude = $info_geo[4];
     150                        $ip = $info_geo[5];
     151                        return true;
     152                }
     153                //=======================================================================
     154                if (isset($_POST['pays'])) {
     155                        $pays = isset($_POST['pays']) ? $_POST['pays'] : "";
     156                        $region =  isset($_POST['region']) ? $_POST['region'] :"";
     157                        $ville = (isset($_POST['ville']))   ? $_POST['ville']: "";
     158                        $latitude =  isset($_POST['latitude']) ? $_POST['latitude'] : "";
     159                        $longitude =  isset($_POST['longitude']) ? $_POST['longitude'] : "";
     160                        $info_geo = array(   $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR']  );
     161                        pwg_set_session_var('info_geo', $info_geo);
     162                        return true;
     163                }else{
     164
     165                        $result="";
     166                        echo '<script type="text/javascript">get_script_geo();</script>';
     167                        return true;
     168                }
     169        } // fin get_geo
     170        //=====================================================================================
     171        /*
     172         * Memo_Var
     173        */
     174        static public function Memo_Var($variables) {
     175                ob_start();
     176                echo '<pre>';
     177                if(count($variables)>1){
     178                        foreach($variables as $key => $line){
     179                                echo  $key . " =>  " . $line ;
     180                                echo "<br />";
     181                        }
     182                }else{
     183                        echo "<i>".$variables."</i><br />";
     184                }
     185
     186                $m= ob_get_contents();
     187                ob_end_clean();
     188                return $m;
     189        }
     190        //======================================================================================
     191        static public function Get_Version_plugins($dir){
     192                $path = $dir;
     193                $plg_data = implode( '', file($path.'main.inc.php') );
     194                if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
     195                {
     196                        $plugin['name'] = trim( $val[1] );
     197                }
     198                if (preg_match("|Version: (.*)|", $plg_data, $val))
     199                {
     200                        $plugin['version'] = trim($val[1]);
     201                }
     202                if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
     203                {
     204                        $plugin['uri'] = trim($val[1]);
     205                }
     206                if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
     207                {
     208                        $plugin['description'] = trim($desc);
     209                }
     210                elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
     211                {
     212                        $plugin['description'] = trim($val[1]);
     213                }
     214                if ( preg_match("|Author: (.*)|", $plg_data, $val) )
     215                {
     216                        $plugin['author'] = trim($val[1]);
     217                }
     218                if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
     219                {
     220                        $plugin['author uri'] = trim($val[1]);
     221                }
     222                if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
     223                {
     224                        list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
     225                        if (is_numeric($extension)) $plugin['extension'] = $extension;
     226                }
     227                // IMPORTANT SECURITY !
     228                $plugin = array_map('htmlspecialchars', $plugin);
     229                return $plugin ;
     230        }
     231        //==========================================================
     232        function Get_Options(&$parametres,$str_index){
     233                global $conf ;
     234                $mails_options=  $conf[$str_index];
     235                if(isset($mails_options))
     236                        if ( preg_match("|s:(.*)|", $mails_options, $val) )
     237                        $parametres =  unserialize($conf['mail_superv']);
     238                else{
     239                        $parametres=explode(",",$mails_options);
     240                }
     241                //====== par defaut =======================
     242                $new_val=false;
     243
     244                if (empty($def_para))
     245                        $def_para = (object) '';
     246
     247                $def_para->check_mailto="on";
     248                $def_para->check_header_carbon="on";
     249                $def_para->check_send_webmaster="off";
     250                $def_para->no_ipaddress="off";  // interdiction adresse ip
     251
     252                $def_para->no_mail_list="on";
     253                $def_para->no_connect="on"; // empeche l'ip de se connecter au site.
     254                $def_para->set_auto="on";       // Test a l'ouverture et enregistrement
     255                $def_para->ip="127.0.0.1";      // derniere adresse IP
     256                $def_para->set_id="on";       // enregistrment nouvel
     257                $def_para->debug_mail="off";       // debogage
     258
     259                foreach ($def_para as $key => $value) {
     260                        if(isset($parametres[$key])){
     261                                $value=$parametres[$key];
     262                        } else {
     263                                $new_val=true;
     264                        }
     265                        $new_val= isset($_POST[$key]) && $new_val ;
     266                        unset( $parametres[$key]) ;
     267                        $parametres[$key]= (isset($_POST[$key]))? "on" : $value ;
     268                }
     269
     270                if($new_val){
     271                        sauve_options();
     272                }
     273                return $parametres ;
     274        }
     275        //==========================================================
     276        function Set_Options($parametres,$str_index){
     277                global $infos_message,$conf;
     278                foreach ($parametres as $key => $value) {
     279                        $parametres[$key]=(isset($_POST[$key]))? "on" : $value ;
     280                }
     281                $parametres['no_connect']= 'off' ;
     282                return $parametres ;
     283        }
     284        //==========================================================
     285
     286        function sauve_options(){
     287                global $options,$infos_message,$conf,$mails_options  ;
     288                $infos_message .=l10n("save_config")."<br>";
     289                if (empty($mail_supervisor))  {
     290                        $mail_supervisor = new mail_supervisor();
     291                }
     292                $mails_parametres= $mail_supervisor->Set_Options($mails_options,"mail_superv");
     293
     294                if ( isset($mails_parametres) )
     295                {
     296                        $query = '
     297                                        UPDATE '.CONFIG_TABLE.'
     298                                                        SET value="'.addslashes(serialize($mails_parametres)).'"
     299                                                                        WHERE param = "mail_superv"
     300                                                                        LIMIT 1';
     301                        pwg_query($query);
     302                }
     303
     304        }
     305
     306        /****************************************
     307         * sauve_donnees()
     308        ****************************************/
     309        function sauve_donnees(){
     310                global $mails_donnees,$superv_champs,$superv_type,$erreur_message ;
     311                //=====================================================================
     312                $clefs = $superv_champs ;
     313                $valeurs = array();
     314                foreach ( $clefs as $champ){
     315                        $champ = trim($champ);
     316                        if($champ !="id")
     317                                if ( isset($mails_donnees[  $champ ]) ) {
     318                                $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ;
     319                                array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[  $champ ] . $sep)  ;
     320                        }else{
     321                                array_push($valeurs , "`".$champ."`" . ' = ' .  "0"  )  ;
     322                        }
     323                }
     324
     325                $valeurs = implode(", ",$valeurs) ;
     326                //=====================================================================
     327                $query = '
     328                                UPDATE '.mail_superv_TABLE.'
     329                                                SET '. $valeurs .'
     330                                                                WHERE `id` = 1 LIMIT 1 ';
     331                ;
     332                ob_start();
     333                $ret=  pwg_query($query)    ;
     334                $m= ob_get_contents();
     335                if($m!="") $m="Mail_super.inc.php sauve_donnees() l:323<br />".$m;
     336                ob_end_clean() ;
     337                $erreur_message .= $m ;
     338        }
     339        //================================================================================
     340        function Get_Datas(){
     341                global $superv_champs ;
     342                verif_base();
     343                $champs = implode(",",$superv_champs );
     344                $query = "SELECT ".$champs."
     345                                FROM ".mail_superv_TABLE."
     346                                                ;";
     347                $result = pwg_query($query);
     348                 
     349                if (!$result) {
     350                        verif_base();
     351                        $result = pwg_query($query);
     352                }
     353                if ($result) {
     354                        $data = mysqli_fetch_array($result,MYSQL_ASSOC);
     355                }
     356                //====================================================================================
     357                $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] );
     358                $next_day = ($next_day >0) ? $next_day :  (604800  + time()) ;
     359                $data['rest_mail'] =    $next_day - time() ;
     360                $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']);
     361                $next_day = ($next_day >0) ? $next_day :  (172800  + time()) ;
     362                $data['rest_spam'] =  $next_day - time() ;
     363                $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']);
     364                $next_day = ($next_day >0) ? $next_day :  (172800 + time()) ;
     365                //====================================================================================
     366                if ($data['quarantaine'] == 'true' ) {
     367                        $data['reste'] =   ( $next_day )-time() ;
     368                }else{
     369                        $data['reste'] = 0;
     370                }
     371
     372                return $data;
     373        }
     374}
    372375?>
Note: See TracChangeset for help on using the changeset viewer.