| 1 |
<?php
|
| 2 |
include('.lib/common.php');
|
| 3 |
include('cron2.php');
|
| 4 |
|
| 5 |
$smarty->assign('leftbar', "on");
|
| 6 |
$leftbar_menu = array();
|
| 7 |
|
| 8 |
add_leftbar($leftbar_menu, "««Cancel", "jobs.php");
|
| 9 |
|
| 10 |
|
| 11 |
$jobid = "";
|
| 12 |
|
| 13 |
# Minutes array
|
| 14 |
$minutes = array(
|
| 15 |
# "*" => "Every minute",
|
| 16 |
# "*/2" => "Every other minute",
|
| 17 |
"*/5" => "Every five minutes",
|
| 18 |
"*/10" => "Every ten minutes",
|
| 19 |
"*/15" => "Every fifteen minutes",
|
| 20 |
);
|
| 21 |
foreach (range(0,59) as $val) {
|
| 22 |
$minutes[(string)$val] = $val;
|
| 23 |
}
|
| 24 |
$minutes["other"] = "other";
|
| 25 |
|
| 26 |
# Hours array
|
| 27 |
$hours = array(
|
| 28 |
"*" => "Every hour",
|
| 29 |
"*/2" => "Every other hour");
|
| 30 |
foreach (range(0,11) as $val) {
|
| 31 |
$hours[(string)$val] = (string)$val . " A.M.";
|
| 32 |
}
|
| 33 |
$hours["12"] = "12 Noon";
|
| 34 |
foreach (range(13,23) as $val) {
|
| 35 |
$hours[(string)$val] = (string)($val-12) . " P.M.";
|
| 36 |
}
|
| 37 |
$hours["other"] = "other";
|
| 38 |
|
| 39 |
# Days
|
| 40 |
$days = array(
|
| 41 |
"*" => "Every day",
|
| 42 |
"*/2" => "Every other day");
|
| 43 |
foreach (range(1,31) as $val) {
|
| 44 |
$days[(string)$val] = (string)($val);
|
| 45 |
}
|
| 46 |
$days["other"] = "other";
|
| 47 |
|
| 48 |
# Weekdays
|
| 49 |
$weekdays = array(
|
| 50 |
"*" => "Every weekday",
|
| 51 |
"0" => "Sunday",
|
| 52 |
"1" => "Monday",
|
| 53 |
"2" => "Tuesday",
|
| 54 |
"3" => "Wednesday",
|
| 55 |
"4" => "Thursday",
|
| 56 |
"5" => "Friday",
|
| 57 |
"6" => "Saturday");
|
| 58 |
$weekdays["other"] = "other";
|
| 59 |
|
| 60 |
# Months
|
| 61 |
$months = array("*" => "Every month",
|
| 62 |
"1" => "January",
|
| 63 |
"2" => "February",
|
| 64 |
"3" => "March",
|
| 65 |
"4" => "April",
|
| 66 |
"5" => "May",
|
| 67 |
"6" => "June",
|
| 68 |
"7" => "July",
|
| 69 |
"8" => "August",
|
| 70 |
"9" => "October",
|
| 71 |
"10" => "September",
|
| 72 |
"11" => "November",
|
| 73 |
"12" => "December");
|
| 74 |
$months["other"] = "other";
|
| 75 |
|
| 76 |
|
| 77 |
function scheduleUIHelper($cronString) {
|
| 78 |
$bits = explode(" ", $cronString);
|
| 79 |
if ($bits[0] != $_POST["minutes"] and $_POST["minutes"] != "other") {
|
| 80 |
$bits[0] = $_POST["minutes"];
|
| 81 |
}
|
| 82 |
if ($bits[1] != $_POST["hours"] and $_POST["hours"] != "other") {
|
| 83 |
$bits[1] = $_POST["hours"];
|
| 84 |
}
|
| 85 |
if ($bits[2] != $_POST["days"] and $_POST["days"] != "other") {
|
| 86 |
$bits[2] = $_POST["days"];
|
| 87 |
}
|
| 88 |
if ($bits[3] != $_POST["months"] and $_POST["months"] != "other") {
|
| 89 |
$bits[3] = $_POST["months"];
|
| 90 |
}
|
| 91 |
if ($bits[4] != $_POST["weekdays"] and $_POST["weekdays"] != "other") {
|
| 92 |
$bits[4] = $_POST["weekdays"];
|
| 93 |
}
|
| 94 |
print_r($bits);
|
| 95 |
|
| 96 |
return implode(" ",$bits);
|
| 97 |
}
|
| 98 |
|
| 99 |
#####################################################
|
| 100 |
#Deal with submitted forms.
|
| 101 |
|
| 102 |
if ($_POST['ADD']) {
|
| 103 |
check_action_access("Add Job");
|
| 104 |
if ($_POST['script']) {
|
| 105 |
$script = get_scire_script($_POST['script']);
|
| 106 |
if ($_POST['permission']) {
|
| 107 |
$permission = $_POST['permission'];
|
| 108 |
$permission = get_scire_permission_by_name($permission);
|
| 109 |
$permission = $permission['permid'];
|
| 110 |
# print "Permission is: $permission";
|
| 111 |
} else {
|
| 112 |
$permission = $script['permission'];
|
| 113 |
}
|
| 114 |
if ($_POST['priority']) {
|
| 115 |
$priority = $_POST['priority'];
|
| 116 |
} else {
|
| 117 |
$priority = $script['priority'];
|
| 118 |
}
|
| 119 |
} else { $status .= "ERROR: No script selected!"; }
|
| 120 |
if ($_POST['description']) {
|
| 121 |
$description = $_POST['description'];
|
| 122 |
} else {
|
| 123 |
$description = "No description provided.";
|
| 124 |
}
|
| 125 |
$pending = sizeof($_POST['clients']) + sizeof($_POST['clientgroups']);
|
| 126 |
|
| 127 |
if (!$status and ($pending or $_POST['clientgroups'])) { #We have a script and clients;
|
| 128 |
# Get the schedule! All fields are required or else you're SOL
|
| 129 |
$scheduleComplete = $_POST["minute1"] and $_POST["hour1"] and
|
| 130 |
$_POST["day1"] and $_POST["month1"] and $_POST["weekday1"];
|
| 131 |
if ($scheduleComplete) {
|
| 132 |
$str = implode(" ", array($_POST["minute1"], $_POST["hour1"],
|
| 133 |
$_POST["day1"], $_POST["month1"], $_POST["weekday1"]));
|
| 134 |
} else {
|
| 135 |
$str = "";
|
| 136 |
}
|
| 137 |
# pre_var_dump($_POST);
|
| 138 |
# pre_var_dump($scheduleComplete);
|
| 139 |
pre_var_dump($str);
|
| 140 |
|
| 141 |
try {
|
| 142 |
$result = scire_add_job($_POST['script'], $priority, $_SESSION['userid'], $permission, $description, $pending, $_POST['clients'], $_POST['clientgroups'], $dependency, $str, $_POST['validity_period']);
|
| 143 |
|
| 144 |
if (!$result) {
|
| 145 |
$status .= "Job successfully added.";
|
| 146 |
} else {
|
| 147 |
$status .= "Error occurred during job addition. $result";
|
| 148 |
}
|
| 149 |
} catch (CronException $e) { print_r($e); }
|
| 150 |
|
| 151 |
}
|
| 152 |
}
|
| 153 |
|
| 154 |
###############################################
|
| 155 |
|
| 156 |
|
| 157 |
###############################################
|
| 158 |
# Editing a job's information.
|
| 159 |
if ($_POST['EditJobSubmit']) {
|
| 160 |
check_action_access("Edit Job");
|
| 161 |
$jobinfo = get_scire_job($_GET['jobid']);
|
| 162 |
$smarty->assign('job', $jobinfo);
|
| 163 |
|
| 164 |
if (isset($_POST['editpriority']) and ($_POST['editpriority'] != $jobinfo['priority'])) {
|
| 165 |
$fields['priority'] = $_POST['editpriority'];
|
| 166 |
}
|
| 167 |
if ($_POST['permission'] and ($_POST['permission'] != $jobinfo['permission'])){
|
| 168 |
$fields['permission'] = $_POST['permission'];
|
| 169 |
}
|
| 170 |
if ($_POST['description'] and ($_POST['description'] != $jobinfo['description'])) {
|
| 171 |
$fields['description'] = trim($_POST['description']);
|
| 172 |
}
|
| 173 |
if ($_POST['script'] and ($_POST['script'] != $jobinfo['script'])) {
|
| 174 |
$fields['script'] = $_POST['script'];
|
| 175 |
}
|
| 176 |
if ($_POST['run_schedule'] and ($_POST['run_schedule'] != $jobinfo['run_schedule'])) {
|
| 177 |
try{
|
| 178 |
$c = new CronParser($_POST['run_schedule']);
|
| 179 |
$fields['run_schedule'] = $_POST['run_schedule'];
|
| 180 |
} catch (CronException $e) {}
|
| 181 |
} else {
|
| 182 |
$isScheduleUI = $_POST["minutes"] and $_POST["hours"] and $_POST["days"] and $_POST["months"] and $_POST["weekdays"];
|
| 183 |
if ($isScheduleUI)
|
| 184 |
try{
|
| 185 |
$tmp = scheduleUIHelper($jobinfo["run_schedule"]);
|
| 186 |
$c = new CronParser($tmp);
|
| 187 |
$fields['run_schedule'] = $tmp;
|
| 188 |
} catch (CronException $e) {}
|
| 189 |
}
|
| 190 |
if ($_POST['validity_period'] and ($_POST['validity_period'] != $jobinfo['validity_period'])) {
|
| 191 |
$fields['validity_period'] = $_POST['validity_period'];
|
| 192 |
}
|
| 193 |
$status = scire_edit_job($_POST['jobid'], $fields);
|
| 194 |
$_GET['Action'] = "edit";
|
| 195 |
$_GET['jobid'] = $_POST['jobid'];
|
| 196 |
}
|
| 197 |
|
| 198 |
###############################################
|
| 199 |
# Delete a job.
|
| 200 |
if ($_POST['delete_confirm']) {
|
| 201 |
check_action_access("Delete Job");
|
| 202 |
# $status = scire_del_job($_POST['jobid']);
|
| 203 |
header('Location: ' . $baseurl . 'jobs.php');
|
| 204 |
}
|
| 205 |
if ($_POST['delete_cancel']) {
|
| 206 |
header('Location: ' . $baseurl . 'jobs.php');
|
| 207 |
}
|
| 208 |
|
| 209 |
switch($_GET['Action']) {
|
| 210 |
case "create":
|
| 211 |
check_action_access("Add Job"); #Access check
|
| 212 |
add_leftbar($leftbar_menu, "««Cancel", "jobs.php");
|
| 213 |
|
| 214 |
break;
|
| 215 |
case "edit":
|
| 216 |
check_action_access("Edit Job");#Access check
|
| 217 |
$acls = array();
|
| 218 |
#make the topbar look good
|
| 219 |
$smarty->assign('desc', "Edit client information.");
|
| 220 |
$jobinfo = get_scire_job($_GET['jobid']);
|
| 221 |
$smarty->assign('job', $jobinfo);
|
| 222 |
$smarty->assign('jobid', $_GET['jobid']);
|
| 223 |
$smarty->assign('scripts', get_scire_scripts());
|
| 224 |
// $cron = new CronParser("*/2 7-18/3 * * *");
|
| 225 |
// $smarty->assign('cron', $cron);
|
| 226 |
$smarty->assign('minutes', $minutes);
|
| 227 |
$smarty->assign('hours', $hours);
|
| 228 |
$smarty->assign('days', $days);
|
| 229 |
$smarty->assign('months', $months);
|
| 230 |
$smarty->assign('weekdays', $weekdays);
|
| 231 |
|
| 232 |
$bits = explode(" ", $jobinfo["run_schedule"]);
|
| 233 |
$smarty->assign('selectedMinute', array_key_exists($bits[0], $minutes) ? $bits[0] : "other" );
|
| 234 |
$smarty->assign('selectedHour', array_key_exists($bits[1], $hours) ? $bits[1] : "other" );
|
| 235 |
$smarty->assign('selectedDay', array_key_exists($bits[2], $days) ? $bits[2] : "other" );
|
| 236 |
$smarty->assign('selectedMonth', array_key_exists($bits[3], $months) ? $bits[3] : "other" );
|
| 237 |
$smarty->assign('selectedWeekday', array_key_exists($bits[4], $minutes) ? $bits[4] : "other" );
|
| 238 |
|
| 239 |
// $smarty->assign('gli_profiles', get_scire_gli_profiles());
|
| 240 |
// $smarty->assign('oss', get_scire_oss());
|
| 241 |
// $smarty->assign('users', get_scire_users('username', 'desc'));
|
| 242 |
|
| 243 |
// $clientgroups = array();
|
| 244 |
$groups = $acl->get_object_groups($_GET['jobid'],'AXO');
|
| 245 |
if ($groups) {
|
| 246 |
foreach ($groups as $group) {
|
| 247 |
$group_data = $acl->get_group_data($group, 'AXO');
|
| 248 |
$clientgroups_entry['name'] = $group_data[3];
|
| 249 |
$clientgroups_entry['id'] = $group_data[0];
|
| 250 |
if ($group_data[1]) {
|
| 251 |
$parent_group_data = $acl->get_group_data($group_data[1],'AXO');
|
| 252 |
$clientgroups_entry['parent'] = $parent_group_data[3];
|
| 253 |
} else {
|
| 254 |
$clientgroups_entry['parent'] = "";
|
| 255 |
}
|
| 256 |
array_push($clientgroups, $clientgroups_entry);
|
| 257 |
$result_acl_ids = $acl->search_acl(FALSE,FALSE,
|
| 258 |
FALSE,FALSE,FALSE,
|
| 259 |
FALSE,FALSE,$group_data[3],FALSE);
|
| 260 |
foreach ($result_acl_ids as $acl_id) {
|
| 261 |
array_push($acls, $acl->get_acl($acl_id));
|
| 262 |
}
|
| 263 |
}
|
| 264 |
}
|
| 265 |
$smarty->assign('groups', $clientgroups);
|
| 266 |
|
| 267 |
case "delete":
|
| 268 |
check_action_access("Delete Job");#Access check
|
| 269 |
$jobinfo = get_scire_job($_GET['jobid']);
|
| 270 |
$smarty->assign('job', $jobinfo);
|
| 271 |
#pre_var_dump($jobinfo);
|
| 272 |
$smarty->assign('jobid', $_GET['jobid']);
|
| 273 |
break;
|
| 274 |
}
|
| 275 |
|
| 276 |
|
| 277 |
$smarty->assign('leftbar_menu', $leftbar_menu);
|
| 278 |
$smarty->assign('Action', $_GET['Action']);
|
| 279 |
$smarty->assign('status', $status);
|
| 280 |
$smarty->display('job.tpl');
|
| 281 |
#pre_var_dump($_POST);
|
| 282 |
?>
|