From 0a40da52426bacb92f60a21763720e1ce027293c Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Wed, 8 Jul 2009 12:01:06 +0000 Subject: [PATCH] Bit of work on admin -> crons --- e107_admin/cron.php | 587 +++++++++++++++++++++++++++----------------- 1 file changed, 366 insertions(+), 221 deletions(-) diff --git a/e107_admin/cron.php b/e107_admin/cron.php index eaac5dd95..fefd194d9 100644 --- a/e107_admin/cron.php +++ b/e107_admin/cron.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/cron.php,v $ -| $Revision: 1.1 $ -| $Date: 2008-06-17 05:39:22 $ +| $Revision: 1.2 $ +| $Date: 2009-07-08 12:01:06 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -25,227 +25,372 @@ if (!getperms('U')) $e_sub_cat = 'cron'; require_once('auth.php'); - -if(isset($_POST['submit'])) -{ - foreach($_POST['cron'] as $key=>$val) - { - if(!$val['active']) - { - $val['active'] = 0; - } - - $t['minute'] = implode(",",$_POST['tab'][$key]['minute']); - $t['hour'] = implode(",",$_POST['tab'][$key]['hour']); - $t['day'] = implode(",",$_POST['tab'][$key]['day']); - $t['month'] = implode(",",$_POST['tab'][$key]['month']); - $t['weekday'] = implode(",",$_POST['tab'][$key]['weekday']); - - $val['tab'] = implode(" ",$t); - $tabs .= $val['tab']."
"; - $cron[$key] = $val; - } - - $pref['e_cron_pref'] = $cron; - save_prefs(); - $ns -> tablerender(LAN_SAVED,"
".LAN_SETSAVED."
"); -} - - -$cronpref = $pref['e_cron_pref']; - -// ----------- Grab All e_cron parameters ----------------------------------- - -$count = 0; -foreach($pref['e_cron_list'] as $key=>$val) -{ - $eplug_cron = array(); - if(is_readable(e_PLUGIN.$key."/e_cron.php")) - { - require_once(e_PLUGIN.$key."/e_cron.php"); - foreach($eplug_cron as $v) - { - $e_cron[$count]['name'] = $v['name']; - $e_cron[$count]['function'] = $v['function']; - $e_cron[$count]['description'] = $v['description']; - $e_cron[$count]['path'] = $key; - $count++; - } - } - -} - -// ---------------------- List All Functions ----------------------------- - -$text = "
-
- - - - - - - - - - - "; - - -foreach($e_cron as $cron) -{ - $c = $cron['function']; - $sep = array(); - - list($sep['minute'],$sep['hour'],$sep['day'],$sep['month'],$sep['weekday']) = explode(" ",$cronpref[$c]['tab']); - - foreach($sep as $key=>$value) - { - if($value=="") - { - $sep[$key] = "*"; - } - } - - $minute = explode(",",$sep['minute']); - $hour = explode(",",$sep['hour']); - $day = explode(",",$sep['day']); - $month = explode(",",$sep['month']); - $weekday = explode(",",$sep['weekday']); - - $min_options = array( - "*" => LAN_CRON_11, - "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58" => LAN_CRON_12, - "0,5,10,15,20,25,30,35,40,45,50,55" => LAN_CRON_13, - "0,10,20,30,40,50" => LAN_CRON_14, - "0,15,30,45" => LAN_CRON_15 - ); - - $hour_options = array( - "*" => LAN_CRON_16, - "0,2,4,6,8,10,12,14,16,18,20,22" => LAN_CRON_17, - "0,3,6,9,12,15,18,21" => LAN_CRON_18, - "0,6,12,18" => LAN_CRON_19 - ); - - $text .= " - - - - - - - - - "; -} - -$text .= " - - - - -
".LAN_CRON_1."".LAN_CRON_2."".LAN_CRON_3."".LAN_CRON_4."".LAN_CRON_5."".LAN_CRON_6."".LAN_CRON_7."".LAN_CRON_8."
".$cron['name']."".$cron['description']." - - - - - - - - - - - "; - $checked = ($cronpref[$c]['active'] == 1) ? "checked='checked'" : ""; - $text .= " -
"; - $text .= ""; - $text .= "
-
-
"; - - $ns -> tablerender(PAGE_NAME, $text); - +require_once (e_HANDLER.'message_handler.php'); +require_once(e_HANDLER."form_handler.php"); +$frm = new e_form(true); +$cron = new cron; require_once(e_ADMIN."footer.php"); exit; +class cron +{ + var $coreCrons = array(); + var $cronAction; + + function cron() + { + + $this->cronAction = e_QUERY; + + if(isset($_POST['submit'])) + { + $this -> cronSave(); + } + + if(isset($_POST['save_prefs'])) + { + $this -> cronSavePrefs(); + } + + // Set Core Cron Options. + + $this->coreCrons[] = array('name'=>'User Purge','function' => 'user_purge', 'description'=>'Purge Unactivated Users'); + $this->coreCrons[] = array('name'=>'User UnActivated','function' => 'user_unactivated', 'description'=>'Resend activation email to unactivated users.'); + $this->coreCrons[] = array('name'=>'News Sticky','function' => 'news_purge', 'description'=>'Remove Sticky News Items'); + + // These core functions need to be put into e_BASE/cron.php ie. news_purge() + + if($this->cronAction == "" || $this->cronAction == "main") + { + $this -> cronRenderPage(); + } + + if($this->cronAction == "pref") + { + $this -> cronRenderPrefs(); + } + } + + function cronSavePref() + { + // Store the USERID with the password. + // This way only the one password is needed, and the user login can be looked up in e_base/cron.php + + } + + function cronSave() + { + global $pref; + foreach($_POST['cron'] as $key=>$val) + { + if(!$val['active']) + { + $val['active'] = 0; + } + + $t['minute'] = implode(",",$_POST['tab'][$key]['minute']); + $t['hour'] = implode(",",$_POST['tab'][$key]['hour']); + $t['day'] = implode(",",$_POST['tab'][$key]['day']); + $t['month'] = implode(",",$_POST['tab'][$key]['month']); + $t['weekday'] = implode(",",$_POST['tab'][$key]['weekday']); + + $val['tab'] = implode(" ",$t); + $tabs .= $val['tab']."
"; + $cron[$key] = $val; + } + + $pref['e_cron_pref'] = $cron; + $emessage = &eMessage::getInstance(); + if(save_prefs()) + { + $emessage->add(LAN_SETSAVED, E_MESSAGE_SUCCESS); + } + else + { + $emessage->add("There was a problem saving your settings.", E_MESSAGE_ERROR); + } + + } +// -------------------------------------------------------------------------- + function cronRenderPrefs() + { + global $frm,$ns; + + $text = "
+
+ + + + + + + + + + + + + + +
Cron Password + ".$frm->password('cron_password',100)." +
bcc: + +
"; + $text .= $frm->admin_button('save_prefs',LAN_SAVE, 'update'); + $text .= "
+
+
"; + + $ns -> tablerender(LAN_PREFS, $text); + + } + + + + + +// ----------- Grab All e_cron parameters ----------------------------------- + + function cronRenderPage() + { + global $pref,$ns,$frm; + $cronpref = $pref['e_cron_pref']; + + // $count = 0; + + $e_cron = $this->coreCrons; + $count = count($this->coreCrons); + + foreach($pref['e_cron_list'] as $key=>$val) + { + $eplug_cron = array(); + if(is_readable(e_PLUGIN.$key."/e_cron.php")) + { + require_once(e_PLUGIN.$key."/e_cron.php"); + foreach($eplug_cron as $v) + { + $e_cron[$count]['name'] = $v['name']; + $e_cron[$count]['function'] = $v['function']; + $e_cron[$count]['description'] = $v['description']; + $e_cron[$count]['path'] = $key; + $count++; + } + } + + } + + // ---------------------- List All Functions ----------------------------- + + $text = "
+
+ + + + + + + + + + + + + + + + + + + + + + + + "; + + + foreach($e_cron as $cron) + { + $c = $cron['function']; + $sep = array(); + + list($sep['minute'],$sep['hour'],$sep['day'],$sep['month'],$sep['weekday']) = explode(" ",$cronpref[$c]['tab']); + + foreach($sep as $key=>$value) + { + if($value=="") + { + $sep[$key] = "*"; + } + } + + $minute = explode(",",$sep['minute']); + $hour = explode(",",$sep['hour']); + $day = explode(",",$sep['day']); + $month = explode(",",$sep['month']); + $weekday = explode(",",$sep['weekday']); + + $min_options = array( + "*" => LAN_CRON_11, + "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58" => LAN_CRON_12, + "0,5,10,15,20,25,30,35,40,45,50,55" => LAN_CRON_13, + "0,10,20,30,40,50" => LAN_CRON_14, + "0,15,30,45" => LAN_CRON_15 + ); + + $hour_options = array( + "*" => LAN_CRON_16, + "0,2,4,6,8,10,12,14,16,18,20,22" => LAN_CRON_17, + "0,3,6,9,12,15,18,21" => LAN_CRON_18, + "0,6,12,18" => LAN_CRON_19 + ); + + $text .= " + + + + + + + + + "; + } + + $text .= " + + + + + +
".LAN_CRON_1."".LAN_CRON_2."".LAN_CRON_3."".LAN_CRON_4."".LAN_CRON_5."".LAN_CRON_6."".LAN_CRON_7."".LAN_CRON_8."
".$cron['name']."".$cron['description']." + + + + + + + + + + + "; + $checked = ($cronpref[$c]['active'] == 1) ? "checked='checked'" : ""; + $text .= " +
+
"; + // $text .= ""; + $text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update'); + $text .= "
+
+
"; + + $emessage = &eMessage::getInstance(); + $ns -> tablerender(PAGE_NAME, $emessage->render() . $text); + } + + function cronOptions() + { + $e107 = &e107::getInstance(); + + $var['main']['text'] = PAGE_NAME; + $var['main']['link'] = e_SELF; + + $var['pref']['text'] = LAN_PREFS; + $var['pref']['link'] = e_SELF."?pref"; + $var['pref']['perm'] = "N"; + + $action = ($this->cronAction) ? $this->cronAction : "main"; + + e_admin_menu(PAGE_NAME, $action, $var); + } +} + + +function cron_adminmenu() +{ + global $cron; + $cron->cronOptions(); +} + + ?> \ No newline at end of file