2000-12-14 14:13:37 +00:00
<?
2001-01-07 19:21:28 +00:00
$module = array("help" => "cron_help",
"admin" => "cron_admin");
function cron_help() {
?>
<P>Cron (which stands for chronograph) is a periodic command scheduler: it executes commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period of n seconds). Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.</P>
<P>Note that cron does not guarantee that the commands will be executed at the specified interval. However, the engine will make sure that the commands are run at the specified intervals as closely as possible.</P>
2001-01-13 16:33:19 +00:00
<P>Check the documentation page for more information about cron and how to setup it correctly.</P>
2001-01-07 19:21:28 +00:00
<?
}
2000-12-14 14:13:37 +00:00
2000-12-16 21:42:52 +00:00
function cron_save($edit) {
foreach ($edit as $key=>$value) {
2000-12-23 15:20:10 +00:00
db_query("UPDATE crons SET scheduled = '$value' WHERE module = '$key'");
2000-12-16 21:42:52 +00:00
}
}
2000-12-16 08:39:01 +00:00
function cron_display() {
2000-12-16 21:42:52 +00:00
$intervals = array(300, 900, 1800, 3600, 7200, 10800, 21600, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200);
2000-12-14 14:13:37 +00:00
// Perform query:
2000-12-23 15:20:10 +00:00
$result = db_query("SELECT * FROM crons");
2000-12-14 14:13:37 +00:00
// Generate output:
2000-12-16 21:42:52 +00:00
$output .= "<FORM ACTION=\"admin.php?mod=cron\" METHOD=\"post\">\n";
2000-12-16 08:39:01 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2000-12-23 15:20:10 +00:00
$output .= " <TR><TH>module</TH><TH>period</TH><TH>last execution</TH><TH>operations</TH></TR>\n";
2000-12-14 14:13:37 +00:00
while ($cron = db_fetch_object($result)) {
2000-12-16 21:42:52 +00:00
foreach ($intervals as $value) $period .= "<OPTION VALUE=\"$value\"". (($cron->scheduled == $value) ? " SELECTED" : "") .">every ". format_interval($value) ."</OPTION>\n";
2000-12-23 15:20:10 +00:00
$output .= " <TR><TD>". check_output($cron->module) ."</TD><TD><SELECT NAME=\"edit[$cron->module]\">$period</SELECT></TD><TD>". format_interval(time() - $cron->timestamp) ." ago</TD><TD ALIGN=\"center\"><A HREF=\"cron.php\">execute</A></TD></TR>\n";
2000-12-16 21:42:52 +00:00
unset($period);
2000-12-14 14:13:37 +00:00
}
2000-12-16 08:39:01 +00:00
$output .= "</TABLE>\n";
2000-12-16 21:42:52 +00:00
$output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save crons\">\n";
$output .= "</FORM>\n";
2000-12-14 14:13:37 +00:00
print $output;
}
2000-12-16 08:39:01 +00:00
function cron_admin() {
2000-12-16 21:42:52 +00:00
global $op, $edit, $name;
2000-12-16 08:39:01 +00:00
2001-01-07 19:21:28 +00:00
print "<SMALL><A HREF=\"admin.php?mod=cron\">overview</A> | <A HREF=\"admin.php?mod=cron&op=help\">help</A></SMALL><HR>\n";
2000-12-16 08:39:01 +00:00
switch($op) {
2001-01-07 19:21:28 +00:00
case "help":
cron_help();
break;
2000-12-16 21:42:52 +00:00
case "Save crons":
cron_save($edit);
2001-01-07 19:21:28 +00:00
// fall through
default:
cron_display();
2000-12-16 08:39:01 +00:00
}
}
2000-12-14 14:13:37 +00:00
?>