diff --git a/bureau/class/m_cron.php b/bureau/class/m_cron.php index 446baf5b..fbd342b5 100644 --- a/bureau/class/m_cron.php +++ b/bureau/class/m_cron.php @@ -1,5 +1,10 @@ 1440, 'name'=>_("Daily")), - Array('unit'=>60, 'name'=>_("Hour")), - Array('unit'=>30, 'name'=>_("Half Hour")), - ); - + return Array( + Array('unit'=>1440, 'name'=>_("Daily")), + Array('unit'=>60, 'name'=>_("Hour")), + Array('unit'=>30, 'name'=>_("Half Hour")), + ); } + + /*---------------------------------------------------------------------------*/ + /** List the crontab for the current user. + * @return array an hash for each crontab. + */ function lst_cron() { global $cuid,$db,$err; $err->log("cron","lst_cron"); - $db->query("select * from cron where uid = $cuid order by url;"); + $db->query("SELECT * FROM cron WHERE uid = $cuid ORDER BY url;"); $r=Array(); while ($db->next_record()) { $tmp=Array(); @@ -59,25 +66,42 @@ class m_cron { return $r; } + + /*---------------------------------------------------------------------------*/ + /** update the crontab + * @param $arr array the crontab information, including its ID + * @return boolean TRUE if the crontab has been edited + */ function update($arr) { $ok=true; foreach ($arr as $a) { if (! isset($a['id'])) $a['id']=null; if (empty($a['url']) && is_null($a['id'])) continue; - if (! $this->update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id']) ) { + if (! $this->_update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id']) ) { $ok=false; } } return $ok; } + + /*---------------------------------------------------------------------------*/ + /** delete a crontab + * @param $id the id of the crontab to delete + * @return boolean TRUE if the crontab has been deleted + */ function delete_one($id) { global $db,$err,$cuid; $err->log("cron","delete_one"); - return $db->query("delete from cron where id=".intval($id)." and uid=$cuid limit 1;"); + return $db->query("DELETE FROM cron WHERE id=".intval($id)." AND uid=$cuid LIMIT 1;"); } + - function update_one($url, $user, $password, $email, $schedule, $id=null) { + /*---------------------------------------------------------------------------*/ + /** update a crontab, + * @return boolean TRUE if the crontab has been edited + */ + private function _update_one($url, $user, $password, $email, $schedule, $id=null) { global $db,$err,$quota,$cuid; $err->log("cron","update_one"); @@ -85,8 +109,7 @@ class m_cron { return $this->delete_one($id); } - // FIXME check que l'url est une vrai URL - + // FIXME check the url property $url=mysql_real_escape_string(urlencode($url)); $user=mysql_real_escape_string(urlencode($user)); if (empty($user)) $password=''; @@ -102,19 +125,23 @@ class m_cron { return false; } } else { // if not a new insert, check the $cuid - $db->query("select uid from cron where id = $id;"); + $db->query("SELECT uid FROM cron WHERE id = $id;"); if (! $db->next_record()) { return "false"; } // return false if pb if ( $db->f('uid') != $cuid ) { $err->log("cron","update_one","bad uid"); return false; } } - - $query = "INSERT INTO cron (id, uid, url, user, password, schedule, email) values ('$id', '$cuid', '$url', '$user', '$password', '$schedule', '$email') on duplicate key update url='$url', user='$user', password='$password', schedule='$schedule', email='$email', uid='$cuid';"; + $query = "INSERT INTO cron (id, uid, url, user, password, schedule, email) VALUES ('$id', '$cuid', '$url', '$user', '$password', '$schedule', '$email') ON DUPLICATE KEY UPDATE url='$url', user='$user', password='$password', schedule='$schedule', email='$email', uid='$cuid';"; return $db->query("$query"); - } + + /*---------------------------------------------------------------------------*/ + /** validate a crontab schedule + * @param $s array schedule paramters + * @return boolean TRUE if the schedule is valid + */ function valid_schedule($s) { $s2 = intval($s); if ($s2 != $s) return false; @@ -125,23 +152,27 @@ class m_cron { return $r; } - function alternc_quota_names() { - return "cron"; + + /*---------------------------------------------------------------------------*/ + /** hook for quota name + */ + function hook_quota_names() { + return array("cron"=>_("Scheduled tasks")); } - // return the used quota - function alternc_get_quota() { + + /*---------------------------------------------------------------------------*/ + /** hook for quota computation + */ + function hook_quota_get() { global $cuid,$db,$err; $err->log("cron","alternc_get_quota"); $db->query("select count(*) as cnt from cron where uid = $cuid;"); - if ($db->next_record()) { return $db->f('cnt'); } return false; - } -} /* Class cron */ -?> +} /* Class cron */