[4020] | 1 | <?php |
---|
[4029] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die('Hacking attempt!'); |
---|
| 27 | } |
---|
[4041] | 28 | if (!defined('MAILl_SUPERV_DIR')) define('MAILl_SUPERV_DIR' , basename(dirname(__FILE__))); |
---|
| 29 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[4029] | 30 | |
---|
[4049] | 31 | |
---|
[4020] | 32 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[4040] | 33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 34 | |
---|
| 35 | include_once (MAIL_SUPERV_PATH.'include/function_test_send.php'); |
---|
| 36 | |
---|
[4049] | 37 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
| 38 | |
---|
[4029] | 39 | global $period_search,$period_match ; |
---|
[4040] | 40 | |
---|
| 41 | |
---|
| 42 | |
---|
[4029] | 43 | $period_search=array("D","H","M","S","W"); |
---|
| 44 | array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde')); |
---|
| 45 | |
---|
| 46 | $period_match=array(" day"," hour"," minute"," second"," week"); |
---|
| 47 | array_push($period_match,'week','day','hour','minute','seconde'); |
---|
[4020] | 48 | |
---|
| 49 | function sauve_options() |
---|
| 50 | { |
---|
| 51 | global $mails_options ; |
---|
| 52 | $query = ' |
---|
| 53 | UPDATE '.CONFIG_TABLE.' |
---|
| 54 | SET value="'.$mails_options[0]. ',' .$mails_options[1]. ',' .$mails_options[2].',' .$mails_options[3]. ',' .$mails_options[4]. '" |
---|
| 55 | WHERE param="mail_superv" |
---|
| 56 | LIMIT 1'; |
---|
| 57 | pwg_query($query); |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | //================================================================================= |
---|
| 61 | function sauve_données() |
---|
| 62 | { |
---|
| 63 | global $mails_données ; |
---|
[4029] | 64 | |
---|
| 65 | $query = ' |
---|
[4020] | 66 | UPDATE '.MAIL_SUPERV_TABLE.' |
---|
| 67 | SET `nb_mails` = '.$mails_données['nb_mails'].', |
---|
| 68 | `date_mail` = '.$mails_données['date_mail'].', |
---|
| 69 | `nb_mails_maxi` = '.$mails_données['nb_mails_maxi'].', |
---|
[4029] | 70 | `nb_mails_periode` = "'.$mails_données['nb_mails_periode'].'", |
---|
| 71 | |
---|
[4020] | 72 | `nb_spams` = '.$mails_données['nb_spams'].', |
---|
| 73 | `date_spam` = '.$mails_données['date_spam'].', |
---|
| 74 | `nb_spams_maxi` = '.$mails_données['nb_spams_maxi'].', |
---|
[4029] | 75 | `nb_spams_periode` = "'.$mails_données['nb_spams_periode'].'", |
---|
[4020] | 76 | |
---|
| 77 | `quarantaine` = "'.$mails_données['quarantaine'].'", |
---|
| 78 | `date_quarantaine` = '.$mails_données['date_quarantaine'].', |
---|
| 79 | |
---|
[4029] | 80 | `quarantaine_periode` = "'.$mails_données['quarantaine_periode'].'", |
---|
| 81 | |
---|
[4020] | 82 | `message` = "'.$mails_données['message'].'", |
---|
[4049] | 83 | `message_test` = "'.$mails_données['message_test'].'", |
---|
[4020] | 84 | `header_text` = "'.$mails_données['header_text'].'" |
---|
| 85 | WHERE `id` =1 LIMIT 1 '; |
---|
[4029] | 86 | |
---|
| 87 | |
---|
[4040] | 88 | if ( pwg_query($query)) return; |
---|
| 89 | |
---|
| 90 | vérif_base() ; |
---|
| 91 | if ( pwg_query($query)) return; |
---|
[4029] | 92 | |
---|
[4040] | 93 | |
---|
| 94 | ; |
---|
[4029] | 95 | |
---|
[4040] | 96 | |
---|
[4020] | 97 | } |
---|
| 98 | //================================================================================= |
---|
| 99 | function affiche_message() |
---|
| 100 | { |
---|
| 101 | global $template,$infos_message,$erreur_message ;; |
---|
| 102 | |
---|
| 103 | if (isset($erreur_message)) |
---|
| 104 | { |
---|
| 105 | |
---|
| 106 | if ($erreur_message <> "") |
---|
| 107 | { |
---|
[4029] | 108 | $erreur_message=str_replace("\n",'<br />',$erreur_message) ; |
---|
[4020] | 109 | $template->assign('errors',$erreur_message); |
---|
| 110 | $erreur_message=""; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | if (isset($infos_message)) |
---|
| 116 | { |
---|
| 117 | |
---|
| 118 | if ($infos_message <> "") |
---|
| 119 | { |
---|
[4029] | 120 | $infos_message=str_replace("\n",'<br />',$infos_message) ; |
---|
[4020] | 121 | $template->assign('infos',$infos_message); |
---|
| 122 | $infos_message=""; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | //================================================================================= |
---|
| 133 | function Get_Datas() |
---|
| 134 | { |
---|
[4029] | 135 | ob_start(); |
---|
[4020] | 136 | |
---|
[4029] | 137 | $data=Lire_datas(); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | $m= ob_get_contents(); |
---|
| 141 | ob_end_clean(); |
---|
| 142 | |
---|
| 143 | if (strlen($m)>0) { |
---|
| 144 | vérif_base() ; |
---|
| 145 | $data=Lire_datas(); |
---|
| 146 | } |
---|
| 147 | return $data; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | function Lire_datas() |
---|
| 151 | { |
---|
| 152 | global $period_search,$period_match ; |
---|
| 153 | $query = " |
---|
[4020] | 154 | SELECT * |
---|
| 155 | FROM ".MAIL_SUPERV_TABLE." |
---|
| 156 | ;"; |
---|
| 157 | $data = mysql_fetch_array(pwg_query($query)); |
---|
[4029] | 158 | //==================================================================================== |
---|
| 159 | |
---|
[4020] | 160 | |
---|
[4029] | 161 | $mails_periode="+".str_replace($period_search, $period_match, $data['nb_mails_periode']); |
---|
| 162 | $next_day = strtotime( $mails_periode,$data['date_mail']); |
---|
| 163 | $data['rest_mail']= ( $next_day )-time() ; |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | $spams_periode="+".str_replace($period_search, $period_match, $data['nb_spams_periode']); |
---|
| 167 | $next_day = strtotime( $spams_periode,$data['date_spam']); |
---|
| 168 | $data['rest_spam']= ( $next_day )-time() ; |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | $quarantaine_periode="+".str_replace($period_search, $period_match, $data['quarantaine_periode']); |
---|
| 172 | $next_day = strtotime( $quarantaine_periode,$data['date_quarantaine']); |
---|
| 173 | if ($data['quarantaine']) { |
---|
| 174 | $data['reste'] = ( $next_day )-time() ; |
---|
| 175 | }else{ |
---|
| 176 | $data['reste'] = 0; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | return $data; |
---|
[4020] | 180 | } |
---|
[4049] | 181 | //=============================================== |
---|
[4020] | 182 | |
---|
[4050] | 183 | function corrige_header($Carbonne,$headers) |
---|
| 184 | { |
---|
| 185 | global $mails_options,$conf_mail,$mailto,$args,$infos_message; |
---|
[4049] | 186 | |
---|
[4050] | 187 | if (!empty($args[$Carbonne])) |
---|
| 188 | { |
---|
[4049] | 189 | |
---|
[4050] | 190 | if ( count($args[$Carbonne]) > 0 ) |
---|
| 191 | { |
---|
| 192 | if ($mails_options[1] == 'on') { |
---|
| 193 | // Correction "< >" |
---|
| 194 | $list_mail = get_strict_email_list(implode(',', $args[$Carbonne])) ; |
---|
| 195 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', $Carbonne.' : '.$list_mail."\n", $headers); |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } else { |
---|
| 199 | // Raz Bcc, Cc dans headers |
---|
| 200 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
[4049] | 204 | |
---|
| 205 | return $headers; |
---|
[4020] | 206 | |
---|
| 207 | |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | function int_to_heure($int) |
---|
| 211 | { |
---|
| 212 | $week= (int) ($int/(3600*24*7)); |
---|
| 213 | $int=$int-($week*(3600*24*7)); |
---|
| 214 | |
---|
| 215 | $day= (int) ($int/(3600*24)); |
---|
| 216 | $int=$int-($day*(3600*24)); |
---|
| 217 | |
---|
| 218 | $heures=(int) ($int/3600); |
---|
| 219 | |
---|
| 220 | $int=$int-($heures*(3600)); |
---|
| 221 | |
---|
| 222 | $minutes=(int) ($int/60); |
---|
| 223 | $int= $int - ($minutes*(60)); |
---|
| 224 | |
---|
| 225 | $secondes=(int) ($int); |
---|
| 226 | |
---|
| 227 | $heures= substr ('00'. $heures,-2,2); |
---|
| 228 | $day= substr ('00'. $day,-2,2); |
---|
| 229 | $minutes=substr ('00'.$minutes,-2,2); |
---|
| 230 | $secondes=substr ('00'.$secondes,-2,2); |
---|
[4029] | 231 | |
---|
[4020] | 232 | if ($week > 0 ) |
---|
| 233 | { |
---|
[4029] | 234 | |
---|
[4020] | 235 | return $week. " " .l10n('Week'). " " . $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('minute'). "s ". $secondes." " .l10n('seconde')."s"; |
---|
| 236 | } |
---|
[4029] | 237 | return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ". $secondes." " .l10n('Seconde')."s"; |
---|
[4020] | 238 | |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | function memo_var($variables) |
---|
| 242 | { |
---|
| 243 | ob_start(); |
---|
| 244 | echo '<pre>'; |
---|
| 245 | print_r($variables); |
---|
| 246 | echo '</pre>'; |
---|
| 247 | $m= ob_get_contents(); |
---|
| 248 | |
---|
| 249 | ob_end_clean(); |
---|
| 250 | return $m; |
---|
| 251 | |
---|
| 252 | } |
---|
| 253 | |
---|
[4029] | 254 | function vérif_base() |
---|
| 255 | { |
---|
| 256 | |
---|
| 257 | $q = " |
---|
| 258 | CREATE TABLE IF NOT EXISTS ".MAIL_SUPERV_TABLE." ( |
---|
| 259 | `id` SMALLINT( 5 ) NOT NULL DEFAULT '0', |
---|
| 260 | |
---|
| 261 | `nb_mails` INT NOT NULL DEFAULT '0', |
---|
| 262 | `date_mail` INT NOT NULL DEFAULT '0', |
---|
| 263 | `nb_mails_maxi` INT NOT NULL DEFAULT '2000', |
---|
| 264 | `nb_mails_periode` TEXT , |
---|
| 265 | |
---|
| 266 | `nb_spams` INT NOT NULL DEFAULT '0', |
---|
| 267 | `date_spam` INT NOT NULL DEFAULT '0', |
---|
| 268 | |
---|
| 269 | `nb_spams_maxi` INT NOT NULL DEFAULT '10', |
---|
| 270 | `nb_spams_periode` TEXT , |
---|
| 271 | |
---|
[4040] | 272 | `quarantaine` TEXT , |
---|
[4029] | 273 | `date_quarantaine` INT NOT NULL DEFAULT '0', |
---|
| 274 | `quarantaine_periode` TEXT , |
---|
| 275 | |
---|
| 276 | |
---|
[4040] | 277 | `message` TEXT , |
---|
| 278 | `message_test` TEXT , |
---|
| 279 | `header_text` TEXT , |
---|
[4029] | 280 | PRIMARY KEY (`id` ) |
---|
| 281 | ) |
---|
| 282 | ;"; |
---|
| 283 | pwg_query($q); |
---|
| 284 | |
---|
| 285 | $nb = Get_colonnes_de(MAIL_SUPERV_TABLE); |
---|
| 286 | $table=$nb[MAIL_SUPERV_TABLE]; |
---|
| 287 | //================================================================================ |
---|
| 288 | if (!in_array( "nb_mails",$table)) { |
---|
| 289 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails` INT NOT NULL default '0' "; |
---|
| 290 | pwg_query($query); } |
---|
| 291 | if (!in_array( "date_mail",$table)) { |
---|
| 292 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_mail` INT NOT NULL default '0' "; |
---|
| 293 | pwg_query($query); } |
---|
| 294 | if (!in_array( "nb_mails_maxi",$table)) { |
---|
| 295 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_maxi` INT NOT NULL default '2000' "; |
---|
| 296 | pwg_query($query); } |
---|
| 297 | if (!in_array( "nb_mails_periode",$table)) { |
---|
| 298 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_mails_periode` TEXT "; |
---|
| 299 | pwg_query($query); } |
---|
| 300 | |
---|
| 301 | |
---|
| 302 | if (!in_array( "nb_spams",$table)) { |
---|
| 303 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams` INT NOT NULL default '0' "; |
---|
| 304 | pwg_query($query); } |
---|
| 305 | if (!in_array( "date_spam",$table)) { |
---|
| 306 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_spam` INT NOT NULL default '0' "; |
---|
| 307 | pwg_query($query); } |
---|
| 308 | |
---|
| 309 | if (!in_array( "nb_spams_maxi",$table)) { |
---|
| 310 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_maxi` INT NOT NULL default '10' "; |
---|
| 311 | pwg_query($query); |
---|
| 312 | if (!in_array( "nb_spams_periode",$table)) { |
---|
| 313 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `nb_spams_periode` TEXT "; |
---|
| 314 | pwg_query($query); } } |
---|
| 315 | |
---|
| 316 | if (!in_array( "quarantaine",$table)) { |
---|
[4040] | 317 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine` TEXT , "; |
---|
[4029] | 318 | pwg_query($query); } |
---|
| 319 | |
---|
| 320 | if (!in_array( "date_quarantaine",$table)) { |
---|
| 321 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `date_quarantaine` INT NOT NULL default '0' "; |
---|
| 322 | pwg_query($query); |
---|
| 323 | } |
---|
| 324 | if (!in_array( "quarantaine_periode",$table)) { |
---|
| 325 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `quarantaine_periode` TEXT "; |
---|
| 326 | pwg_query($query); } |
---|
| 327 | |
---|
| 328 | if (!in_array( "message",$table)) { |
---|
| 329 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message` TEXT "; |
---|
| 330 | pwg_query($query); } |
---|
| 331 | |
---|
[4040] | 332 | if (!in_array( "message_test",$table)) { |
---|
| 333 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `message_test` TEXT "; |
---|
| 334 | pwg_query($query); } |
---|
| 335 | |
---|
[4029] | 336 | if (!in_array( "header_text",$table)) { |
---|
| 337 | $query = "ALTER TABLE `".MAIL_SUPERV_TABLE."` ADD `header_text` TEXT "; |
---|
| 338 | pwg_query($query); } |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | $query = " |
---|
| 342 | SELECT COUNT(*) |
---|
| 343 | FROM ".MAIL_SUPERV_TABLE." |
---|
| 344 | ;"; |
---|
| 345 | //============================================================================== |
---|
| 346 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
| 347 | if ($count == 0) |
---|
| 348 | { |
---|
| 349 | $next_day = time() ; |
---|
| 350 | $date_quarantaine=time(); |
---|
| 351 | $q = ' |
---|
| 352 | INSERT INTO '.MAIL_SUPERV_TABLE.' (id, |
---|
| 353 | nb_mails,date_mail,nb_mails_maxi,nb_mails_periode, |
---|
| 354 | nb_spams,date_spam,nb_spams_maxi,nb_spams_periode, |
---|
| 355 | quarantaine, date_quarantaine,quarantaine_periode, |
---|
| 356 | message,header_text) |
---|
| 357 | VALUES (1, |
---|
| 358 | 0, |
---|
| 359 | '.time().', |
---|
| 360 | 2000, |
---|
[4049] | 361 | "1 "'.l10n('Week').'", |
---|
[4029] | 362 | |
---|
| 363 | 0, |
---|
| 364 | '.time().', |
---|
| 365 | 10, |
---|
[4049] | 366 | "2 "'.l10n('Day').'", |
---|
[4029] | 367 | |
---|
| 368 | false, |
---|
| 369 | '.time().', |
---|
[4049] | 370 | "2 "'.l10n('Day').'", |
---|
[4029] | 371 | |
---|
| 372 | "Init.", |
---|
[4049] | 373 | "'.l10n('supervisor').'", |
---|
[4029] | 374 | "'.l10n('hello').'" |
---|
| 375 | ) |
---|
| 376 | ;'; |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | pwg_query($q); |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | function Get_colonnes_de($table) |
---|
| 384 | { |
---|
| 385 | $columns_of = array(); |
---|
| 386 | $query = 'DESC '.$table.';'; |
---|
| 387 | $result = mysql_query($query); |
---|
| 388 | $columns_of[$table] = array(); |
---|
| 389 | while ($row = mysql_fetch_row($result)) |
---|
| 390 | { |
---|
| 391 | array_push($columns_of[$table], $row[0]); |
---|
| 392 | } |
---|
| 393 | return $columns_of; |
---|
| 394 | } |
---|
| 395 | |
---|
[4040] | 396 | function get_liste($group_id) |
---|
[4020] | 397 | { |
---|
[4040] | 398 | global $conf ; |
---|
[4029] | 399 | |
---|
[4040] | 400 | $query = ' |
---|
| 401 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 402 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 403 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 404 | ui.status, |
---|
| 405 | ui.adviser, |
---|
| 406 | ui.enabled_high, |
---|
| 407 | ui.level |
---|
| 408 | FROM '.USERS_TABLE.' AS u |
---|
| 409 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 410 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 411 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 412 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 413 | WHERE ug.group_id='.$group_id.' '; |
---|
[4029] | 414 | |
---|
| 415 | |
---|
[4040] | 416 | |
---|
| 417 | $groups=array(); |
---|
[4020] | 418 | $datas = pwg_query($query); |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | if (!empty($datas)) |
---|
| 422 | { |
---|
[4040] | 423 | while ($group = mysql_fetch_array($datas)) |
---|
[4020] | 424 | { |
---|
[4040] | 425 | |
---|
| 426 | |
---|
| 427 | if (!empty($group['email'])) |
---|
[4020] | 428 | { |
---|
[4040] | 429 | array_push($groups, format_email($group['username'], $group['email'] )); |
---|
[4020] | 430 | } |
---|
| 431 | } |
---|
[4040] | 432 | } |
---|
| 433 | return $groups ; |
---|
[4020] | 434 | |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | ?> |
---|