| 1 |
<?php
|
| 2 |
// $id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_help().
|
| 6 |
*/
|
| 7 |
function views_scheduler_help($section) {
|
| 8 |
switch ($section) {
|
| 9 |
case 'admin/help#views_scheduler':
|
| 10 |
return t('Allows the scheduling of views (Req: actions, schedule and views module.)');
|
| 11 |
}
|
| 12 |
}
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Implementation of hook_perm().
|
| 16 |
* This sets out all the permission level required for the access to the call backs.
|
| 17 |
* by including it in the hook_perm it allows the admins to be able to see and set the
|
| 18 |
* permissions for user roles
|
| 19 |
*/
|
| 20 |
function views_scheduler_perm() {
|
| 21 |
return array('view my schedule', 'schedule views');
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_menu().
|
| 26 |
*/
|
| 27 |
function views_scheduler_menu($may_cache) {
|
| 28 |
$items = array();
|
| 29 |
$admin_access = user_access('schedule views');
|
| 30 |
|
| 31 |
if ($may_cache) {
|
| 32 |
$items[] = array('path' => 'admin/build/schedule_views',
|
| 33 |
'title' => t('Schedule Views'),
|
| 34 |
'callback' => 'views_scheduler_list',
|
| 35 |
'access' => $admin_access,
|
| 36 |
'type' => MENU_NORMAL_ITEM,
|
| 37 |
);
|
| 38 |
|
| 39 |
$items[] = array('path' => 'admin/build/schedule_views/list',
|
| 40 |
'title' => t('Scheduled Views'),
|
| 41 |
'callback' => 'views_scheduler_list',
|
| 42 |
'access' => $admin_access,
|
| 43 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 44 |
'weight' => '-1'
|
| 45 |
);
|
| 46 |
|
| 47 |
$items[] = array('path' => 'admin/build/schedule_views/add_schedule',
|
| 48 |
'title' => t('Add Schedule'),
|
| 49 |
'callback' => 'drupal_get_form',
|
| 50 |
'callback arguments' => array('views_scheduler_add_schedule'),
|
| 51 |
'access' => $admin_access,
|
| 52 |
'type' => MENU_LOCAL_TASK
|
| 53 |
);
|
| 54 |
|
| 55 |
$items[] = array('path' => 'admin/build/schedule_views/add_actions',
|
| 56 |
'title' => t('Add Actions'),
|
| 57 |
'callback' => 'drupal_get_form',
|
| 58 |
'callback arguments' => array('views_scheduler_actions_edit_form'),
|
| 59 |
'access' => $admin_access,
|
| 60 |
'type' => MENU_CALLBACK
|
| 61 |
);
|
| 62 |
|
| 63 |
$items[] = array('path' => 'admin/build/schedule_views/edit_schedule',
|
| 64 |
'title' => t('Edit Schedule'),
|
| 65 |
'callback' => 'drupal_get_form',
|
| 66 |
'callback arguments' => array('views_scheduler_edit_schedule'),
|
| 67 |
'access' => $admin_access,
|
| 68 |
'type' => MENU_CALLBACK
|
| 69 |
);
|
| 70 |
|
| 71 |
$items[] = array('path' => 'admin/build/schedule_views/delete',
|
| 72 |
'title' => t('edit view'),
|
| 73 |
'callback' => 'views_scheduler_actions_delete_action',
|
| 74 |
'access' => $admin_access,
|
| 75 |
'type' => MENU_CALLBACK
|
| 76 |
);
|
| 77 |
}
|
| 78 |
|
| 79 |
return $items;
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* The frontpage of the module.
|
| 84 |
* Shows existing scheduled views and any possible
|
| 85 |
* actions/options that can be taken
|
| 86 |
*/
|
| 87 |
function views_scheduler_list() {
|
| 88 |
$num_views = 10;
|
| 89 |
|
| 90 |
drupal_set_title(t('Administer scheduled views'));
|
| 91 |
|
| 92 |
$result = pager_query(
|
| 93 |
"SELECT v.name AS name, v.vid, s.schedule_title AS title, vs.vschedule_id AS vs_id, vs.node AS node,
|
| 94 |
CONCAT('Every ',s.every, ' ', s.frequency, '(s)') AS scheduled FROM {view_view} as v
|
| 95 |
LEFT JOIN ({view_schedules} vs , {schedules} s) ON (vs.vschedule_id = s.publication_id )
|
| 96 |
WHERE v.name = vs.view ORDER BY v.name", $num_views);
|
| 97 |
|
| 98 |
while ($view = db_fetch_object($result)) {
|
| 99 |
$items[] = array($view->name,
|
| 100 |
check_plain($view->title),
|
| 101 |
$view->scheduled,
|
| 102 |
theme('links', array(
|
| 103 |
array('title' => t('add actions'), 'href' => "admin/build/schedule_views/add_actions/$view->vs_id"),
|
| 104 |
array('title' => t('edit schedule'), 'href' => "admin/build/schedule_views/edit_schedule/$view->vs_id"),
|
| 105 |
array('title' => t('delete schedule'), 'href' => "admin/build/schedule_views/delete/$view->vs_id"),
|
| 106 |
array('title' => t('edit view'), 'href' => "admin/build/views/edit/$view->vid")))
|
| 107 |
);
|
| 108 |
}
|
| 109 |
|
| 110 |
if ($items) {
|
| 111 |
$output = theme('table',
|
| 112 |
array(t('View'),
|
| 113 |
t('Schedule title'),
|
| 114 |
t('Frequency'),
|
| 115 |
t('Options')),
|
| 116 |
$items, array("cellpadding" => "4"),
|
| 117 |
t('This screen shows all of the views that are currently scheduled. Once a view has been scheduled, you should add actions to it by going to "Add Actions" option.')
|
| 118 |
);
|
| 119 |
$output .= theme('pager', NULL, $numViews);
|
| 120 |
}
|
| 121 |
else {
|
| 122 |
$output .= t('<p>No views have currently been scheduled. You can schedule a view by going to "Add Schedule" tab</p>');
|
| 123 |
}
|
| 124 |
|
| 125 |
return $output;
|
| 126 |
}
|
| 127 |
|
| 128 |
/*
|
| 129 |
* Provide a form to schedule a view.
|
| 130 |
*/
|
| 131 |
function views_scheduler_add_schedule() {
|
| 132 |
$op = $_POST['op'];
|
| 133 |
if ($op == t('Cancel')) {
|
| 134 |
return drupal_goto('admin/build/schedule_views');
|
| 135 |
}
|
| 136 |
|
| 137 |
$schedule = _views_scheduler_get_default_values();
|
| 138 |
drupal_set_title(t('Schedule a View'));
|
| 139 |
return _views_scheduler_form($schedule, $op);
|
| 140 |
}
|
| 141 |
|
| 142 |
function views_scheduler_edit_schedule($vs_id= null) {
|
| 143 |
$op = $_POST['op'];
|
| 144 |
if ($op == t('Cancel') || !$vs_id) {
|
| 145 |
return drupal_goto('admin/build/schedule_views');
|
| 146 |
}
|
| 147 |
if ($op == t('Delete')) {
|
| 148 |
return drupal_goto("admin/build/schedule_views/delete/$vs_id");
|
| 149 |
}
|
| 150 |
|
| 151 |
if (!($schedule = _views_scheduler_get_edit_schedule($vs_id))) {
|
| 152 |
return drupal_goto('admin/build/schedule_views');
|
| 153 |
}
|
| 154 |
|
| 155 |
drupal_set_title(t('Edit scheduled View: %n', array('%n' => $schedule->schedule_title)));
|
| 156 |
|
| 157 |
return _views_scheduler_form($schedule, $op);
|
| 158 |
}
|
| 159 |
|
| 160 |
/*
|
| 161 |
* Set the default values for a new schedule
|
| 162 |
*/
|
| 163 |
function _views_scheduler_get_default_values() {
|
| 164 |
|
| 165 |
$schedule = new stdClass();
|
| 166 |
$schedule->hour = date("G")+1;
|
| 167 |
$schedule->date = date("m/d/y");
|
| 168 |
$schedule->frequency = 'manual';
|
| 169 |
$schedule->every = '';
|
| 170 |
$schedule->view = array('NULL' => t('Select a View'));
|
| 171 |
$schedule->schedule_title = '';
|
| 172 |
$schedule->node = 0;
|
| 173 |
$schedule->vschedule_id = NULL;
|
| 174 |
$schedule->schedule_id = NULL;
|
| 175 |
return $schedule;
|
| 176 |
}
|
| 177 |
|
| 178 |
/*
|
| 179 |
* retrieve scheduler view data
|
| 180 |
*/
|
| 181 |
function _views_scheduler_get_edit_schedule($vs_id) {
|
| 182 |
|
| 183 |
$query = db_query("SELECT v. * , vs. * FROM {schedules} v LEFT JOIN {view_schedules} vs ON ( v.publication_id = vs.vschedule_id ) WHERE vs.vschedule_id =%d LIMIT 1", $vs_id);
|
| 184 |
$result =db_fetch_object($query);
|
| 185 |
|
| 186 |
$result->hour = date("H", $result->next);
|
| 187 |
$result->date = date("m/d/y", $result->next);
|
| 188 |
return $result;
|
| 189 |
}
|
| 190 |
|
| 191 |
/* The main form for linking a view to a schedule aswell
|
| 192 |
* as editing/editing scheduled views
|
| 193 |
*/
|
| 194 |
function _views_scheduler_form($schedule, $op = '') {
|
| 195 |
|
| 196 |
// Description section
|
| 197 |
$form['details'] = array(
|
| 198 |
'#type' => 'fieldset',
|
| 199 |
'#title' => t('schedule description'),
|
| 200 |
'#collapsible' => TRUE,
|
| 201 |
'#collapsed' => FALSE,
|
| 202 |
'#tree' => TRUE,
|
| 203 |
);
|
| 204 |
|
| 205 |
$form['details']['name'] = array(
|
| 206 |
'#type' => 'textfield',
|
| 207 |
'#title' => t('Name'),
|
| 208 |
'#size' => 30,
|
| 209 |
'#maxlength' => 64,
|
| 210 |
'#default_value' => $schedule->schedule_title,
|
| 211 |
'#required' => TRUE,
|
| 212 |
'#description' => t('Name of the schedule'),
|
| 213 |
);
|
| 214 |
|
| 215 |
$result = db_query("SELECT name, description FROM {view_view}");
|
| 216 |
$views[NULL] = 'Select a view';
|
| 217 |
while ($view = db_fetch_object($result)) {
|
| 218 |
$views[$view->name] = $view->name;
|
| 219 |
}
|
| 220 |
|
| 221 |
$form['details']['view'] = array(
|
| 222 |
'#type' => 'select',
|
| 223 |
'#title' => t('Existing views'),
|
| 224 |
'#default_value' => $schedule->view,
|
| 225 |
'#options' => $views,
|
| 226 |
'#description' => t('Select a view to link this schedule to.'),
|
| 227 |
);
|
| 228 |
|
| 229 |
$form['details']['node'] = array(
|
| 230 |
'#type' => 'textfield',
|
| 231 |
'#title' => t('Number of nodes'),
|
| 232 |
'#default_value' => $schedule->node,
|
| 233 |
'#size' => 2,
|
| 234 |
'#maxlength' => 3,
|
| 235 |
'#required' => TRUE,
|
| 236 |
'#description' => t('Number of nodes to be scheduled each time (0 means all nodes)'),
|
| 237 |
);
|
| 238 |
//END
|
| 239 |
|
| 240 |
// Schedule Timing Details
|
| 241 |
$form['schedule'] = array(
|
| 242 |
'#type' => 'fieldset',
|
| 243 |
'#title' => t('Frequency'),
|
| 244 |
'#collapsible' => TRUE,
|
| 245 |
'#collapsed' => FALSE,
|
| 246 |
'#tree' => TRUE,
|
| 247 |
);
|
| 248 |
$form['schedule']['every'] = array(
|
| 249 |
'#type' => 'textfield',
|
| 250 |
'#title' => t('Every'),
|
| 251 |
'#default_value' => $schedule->every,
|
| 252 |
'#size' => 5,
|
| 253 |
'#maxlength' => 3,
|
| 254 |
'#required' => TRUE,
|
| 255 |
);
|
| 256 |
$form['schedule']['frequency'] = array(
|
| 257 |
'#type' => 'radios',
|
| 258 |
'#title' => t('Frequency'),
|
| 259 |
'#default_value' => $schedule->frequency,
|
| 260 |
'#options' => array(
|
| 261 |
'hour' => t('Hour(s)'),
|
| 262 |
'day' => t('Day(s)'),
|
| 263 |
'month' => t('Month(s)'),
|
| 264 |
'manual' => t('Manual Publication')),
|
| 265 |
|
| 266 |
);
|
| 267 |
// END
|
| 268 |
|
| 269 |
// First Sending Takes Place.
|
| 270 |
$form['next'] = array(
|
| 271 |
'#type' => 'fieldset',
|
| 272 |
'#collapsible' => TRUE,
|
| 273 |
'#collapsed' => FALSE,
|
| 274 |
'#tree' => TRUE,
|
| 275 |
'#title' => t('Next Send'),
|
| 276 |
'#description' => t('Begin running this schedule on.'),
|
| 277 |
);
|
| 278 |
$form['next']['date'] = array(
|
| 279 |
'#type' => 'textfield',
|
| 280 |
'#title' => t('Date'),
|
| 281 |
'#default_value' => $schedule->date,
|
| 282 |
'#size' => 10,
|
| 283 |
'#maxlength' => 10,
|
| 284 |
'#required' => TRUE,
|
| 285 |
'#description' => t('(mm/dd/yy)'),
|
| 286 |
);
|
| 287 |
$form['next']['hour'] = array(
|
| 288 |
'#type' => 'select',
|
| 289 |
'#title' => t('Time'),
|
| 290 |
'#default_value' => $schedule->hour,
|
| 291 |
'#options' => views_scheduler_list_hours(),
|
| 292 |
);
|
| 293 |
//END
|
| 294 |
|
| 295 |
// Initiliase sendtime element to be used during the validation
|
| 296 |
// stage with form_set_value
|
| 297 |
|
| 298 |
$form['sendtime'] = array('#type' => 'value', '#value' => 0);
|
| 299 |
// END
|
| 300 |
|
| 301 |
//set publicaton and view_schedule id to be used for editing form
|
| 302 |
$form['view_schedule_id'] = array('#type' => 'value', '#value' => $schedule->vschedule_id);
|
| 303 |
$form['schedule_id'] = array('#type' => 'value', '#value' => $schedule->schedule_id);
|
| 304 |
//END
|
| 305 |
|
| 306 |
$form['save'] = array(
|
| 307 |
'#type' => 'submit',
|
| 308 |
'#value' => t('Save'),
|
| 309 |
);
|
| 310 |
if ($schedule->schedule_id && $schedule->vschedule_id) {
|
| 311 |
$form['delete'] = array(
|
| 312 |
'#type' => 'submit',
|
| 313 |
'#value' => t('Delete'),
|
| 314 |
);
|
| 315 |
}
|
| 316 |
$form['cancel'] = array(
|
| 317 |
'#type' => 'submit',
|
| 318 |
'#value' => t('Cancel'),
|
| 319 |
);
|
| 320 |
|
| 321 |
$form['#base'] = 'views_scheduler_form';
|
| 322 |
return $form;
|
| 323 |
}
|
| 324 |
|
| 325 |
function views_scheduler_form_validate($form_id, $form_values, $form) {
|
| 326 |
|
| 327 |
if ($form_values['details']['view'] ==NULL) {
|
| 328 |
form_error($form['details']['view'], t('Please select a view.'));
|
| 329 |
}
|
| 330 |
if (!is_numeric($form_values['details']['node'])) {
|
| 331 |
form_error($form_values['details']['node'], t('Please enter the numbe of nodes that you would like to be scheduled each time.'));
|
| 332 |
}
|
| 333 |
|
| 334 |
if (!is_numeric($form_values['schedule']['every'])) {
|
| 335 |
form_error($form_values['schedule']['every'], t('Please enter a number for every.'));
|
| 336 |
}
|
| 337 |
if ($form_values['schedule']['frequency'] == 'manual') {
|
| 338 |
form_set_value ($form['schedule']['every'], 0);
|
| 339 |
}
|
| 340 |
|
| 341 |
// check whether date/time is valid or has already passed
|
| 342 |
$date_array=getdate(strtotime($form_values['next']['date']));
|
| 343 |
|
| 344 |
if (checkdate( $date_array['mon'], $date_array['mday'], $date_array['year'] == TRUE )) {
|
| 345 |
$send_time=mktime($form_values['next']['hour'],0,0,$date_array['mon'], $date_array['mday'], $date_array['year']);
|
| 346 |
|
| 347 |
if ($send_time<= time()) {
|
| 348 |
form_set_error('next', t('The date/time has already passed '));
|
| 349 |
}
|
| 350 |
}
|
| 351 |
else {
|
| 352 |
form_set_error('next', t('The date entered is wrong, Please make sure to enter the date in following format: mm/dd/yy.'));
|
| 353 |
}
|
| 354 |
form_set_value ($form['sendtime'], $send_time);
|
| 355 |
}
|
| 356 |
|
| 357 |
function views_scheduler_form_submit($form_id, $form_values) {
|
| 358 |
if ($form_values['schedule_id'] && $form_values['view_schedule_id']) {
|
| 359 |
db_query("UPDATE {view_schedules} SET view = '%s', node = '%d' WHERE `vschedule_id` ='%d' ", $form_values['details']['view'], $form_values['details']['node'],$form_values[view_schedule_id]);
|
| 360 |
|
| 361 |
|
| 362 |
db_query("UPDATE {schedules} SET schedule_title = '%s', next = '%d', every = '%d', frequency = '%s' WHERE schedule_id = '%d' AND publication_id = '%d'", $form_values['details']['name'], $form_values['sendtime'], $form_values['schedule']['every'], $form_values['schedule']['frequency'], $form_values['schedule_id'], $form_values['view_schedule_id']);
|
| 363 |
|
| 364 |
drupal_set_message(t('The schedule <em>%n</em> has been updated.', array('%n' => $form_values['details']['name'])));
|
| 365 |
drupal_goto('admin/build/schedule_views');
|
| 366 |
}
|
| 367 |
else{
|
| 368 |
db_query("INSERT INTO {view_schedules} (vschedule_id , view , node) VALUES (NULL, '%s', '%d')", $form_values['details']['view'], $form_values['details']['node']);
|
| 369 |
$view_schedule_id=db_result(db_query("SELECT LAST_INSERT_ID()"));
|
| 370 |
|
| 371 |
db_query("INSERT INTO {schedules} (schedule_id, schedule_title, type, publication_id, start, first, next, last, every, frequency) VALUES (NULL, '%s','view', '%d', '%d', '%d', '%d', '%d', '%d', '%s')", $form_values['details']['name'], $view_schedule_id, 0, 0, $form_values['sendtime'],0 ,$form_values['schedule']['every'], $form_values['schedule']['frequency']);
|
| 372 |
|
| 373 |
drupal_set_message(t('The schedule <em>%n</em> has been created.', array('%n' => $form_values['details']['name'])));
|
| 374 |
drupal_goto('admin/build/schedule_views');
|
| 375 |
}
|
| 376 |
}
|
| 377 |
|
| 378 |
|
| 379 |
// Get the scheduled views from database
|
| 380 |
function views_scheduler_select_views($vschedule_id = NULL) {
|
| 381 |
|
| 382 |
if ($vschedule_id) {
|
| 383 |
$view_schedule = db_fetch_array(db_query("SELECT * FROM {view_schedules} WHERE vschedule_id = '%d' LIMIT 1", $vschedule_id));
|
| 384 |
|
| 385 |
} else {
|
| 386 |
$results = db_query("SELECT * FROM {view_schedules}");
|
| 387 |
while ($row = db_fetch_array($results)) {
|
| 388 |
$view_schedule[] = $row;
|
| 389 |
}
|
| 390 |
}
|
| 391 |
|
| 392 |
return $view_schedule;
|
| 393 |
}
|
| 394 |
|
| 395 |
function views_scheduler_actions_edit_form($vs_id = NULL) {
|
| 396 |
$form = array();
|
| 397 |
$form['#tree'] = TRUE; // make sure we preserve all hierarchial values.
|
| 398 |
$form['set'] = array(
|
| 399 |
'#type' => 'hidden',
|
| 400 |
'#value' => $vs_id,
|
| 401 |
);
|
| 402 |
|
| 403 |
|
| 404 |
foreach (views_scheduler_get_actions($vs_id) as $aid => $description) {
|
| 405 |
$form['actions']['old'][ $aid]['aid'] = array(
|
| 406 |
'#type' => 'value',
|
| 407 |
'#value' => $description,
|
| 408 |
);
|
| 409 |
|
| 410 |
$form['actions']['old'][$aid]['delete'] = array(
|
| 411 |
'#type' => 'checkbox',
|
| 412 |
'#default_value' => 0,
|
| 413 |
'#return_value' => 1,
|
| 414 |
);
|
| 415 |
}
|
| 416 |
|
| 417 |
actions_synchronize(); // Make sure all the actions are in the db.
|
| 418 |
$available_actions = array();
|
| 419 |
$available_actions[] = '--select an action to add--';
|
| 420 |
$result = db_query("SELECT * FROM {actions}");
|
| 421 |
while ($action = db_fetch_object($result)) {
|
| 422 |
$available_actions[$action->aid] = $action->description;
|
| 423 |
}
|
| 424 |
|
| 425 |
|
| 426 |
$form['actions']['new']['aid'] = array(
|
| 427 |
'#type' => 'select',
|
| 428 |
'#options' => $available_actions,
|
| 429 |
'#default_value' => 'NULL',
|
| 430 |
);
|
| 431 |
|
| 432 |
$form['submit'] = array(
|
| 433 |
'#type' => 'submit',
|
| 434 |
'#value' => t('Save')
|
| 435 |
);
|
| 436 |
|
| 437 |
|
| 438 |
return $form;
|
| 439 |
}
|
| 440 |
|
| 441 |
function theme_views_scheduler_actions_edit_form(&$form) {
|
| 442 |
|
| 443 |
$output .= theme('table', $header, $rows);
|
| 444 |
|
| 445 |
$output .= '<h3>' . t('Actions') . '</h3>';
|
| 446 |
$output .= '<p>' . t('These actions will be performed on the scheduled views.') . '</p>';
|
| 447 |
|
| 448 |
$header = array(t('action'), t('delete'));
|
| 449 |
|
| 450 |
foreach (element_children($form['actions']['old']) as $aid) {
|
| 451 |
$row = array();
|
| 452 |
$row[] = $form['actions']['old'][$aid]['aid']['#value'];
|
| 453 |
$row[] = drupal_render($form['actions']['old'][$aid]['delete']);
|
| 454 |
$rows[] = $row;
|
| 455 |
}
|
| 456 |
|
| 457 |
if (!$rows) {
|
| 458 |
$rows[] = array(array('data' => t('No actions have been defined.'), 'colspan' => '6'));
|
| 459 |
}
|
| 460 |
|
| 461 |
$row = array();
|
| 462 |
$row[] = drupal_render($form['actions']['new']['aid']);
|
| 463 |
$row[] = '';
|
| 464 |
$rows[] = $row;
|
| 465 |
|
| 466 |
$output .= theme('table', $header, $rows);
|
| 467 |
|
| 468 |
$output .= drupal_render($form);
|
| 469 |
|
| 470 |
return $output;
|
| 471 |
}
|
| 472 |
|
| 473 |
function views_scheduler_actions_edit_form_submit($form_id, $form_values) {
|
| 474 |
|
| 475 |
//update actions, delete the requested actions
|
| 476 |
foreach (element_children($form_values['actions']['old']) as $aid) {
|
| 477 |
if ($form_values['actions']['old'][$aid]['delete']) {
|
| 478 |
db_query("DELETE FROM {view_schedules_actions_registry} WHERE aid = '%s' AND vsid = %d", $aid, $form_values['set']);
|
| 479 |
}
|
| 480 |
}
|
| 481 |
|
| 482 |
// insert the new actions.
|
| 483 |
if ($form_values['actions']['new']['aid']) {
|
| 484 |
$sql = "INSERT INTO {view_schedules_actions_registry} (aid, vsid, weight) VALUES ('%s', %d, %d)";
|
| 485 |
db_query($sql, $form_values['actions']['new']['aid'], $form_values['set'], 0);
|
| 486 |
}
|
| 487 |
|
| 488 |
return 'admin/build/schedule_views/add_actions/'.$form_values['set'];
|
| 489 |
}
|
| 490 |
|
| 491 |
|
| 492 |
/**
|
| 493 |
* Get the actions associated with a given view.
|
| 494 |
* @param int vs_id (viewschedule_id from view_schedules tbl)
|
| 495 |
* @return array
|
| 496 |
* Actions as aid=>description pairs.
|
| 497 |
*/
|
| 498 |
function views_scheduler_get_actions($vs_id) {
|
| 499 |
$view_scheduled_actions = array();
|
| 500 |
$result = db_query("SELECT a.description, a.aid from {view_schedules} as vs ,{view_schedules_actions_registry} as vsar, {actions} as a WHERE vs.vschedule_id = vsar.vsid AND vsar.aid = a.aid AND vsar.vsid = %d ORDER BY vsar.weight ASC" , $vs_id);
|
| 501 |
while ($data = db_fetch_object($result)) {
|
| 502 |
$view_scheduled_actions[$data->aid] = $data->description;
|
| 503 |
}
|
| 504 |
return $view_scheduled_actions;
|
| 505 |
}
|
| 506 |
|
| 507 |
function views_scheduler_actions_delete_action($vs_id) {
|
| 508 |
$form['vs_id'] = array(
|
| 509 |
'#type' => 'hidden',
|
| 510 |
'#value' => $vs_id,
|
| 511 |
);
|
| 512 |
|
| 513 |
$output = confirm_form(
|
| 514 |
'views_scheduler_delete_confirm',
|
| 515 |
$form,
|
| 516 |
t('Are you sure you want to delete this scheduled view?'),
|
| 517 |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/schedule_views',
|
| 518 |
t('This action cannot be undone.'),
|
| 519 |
t('Delete schedule'),
|
| 520 |
t('Cancel')
|
| 521 |
);
|
| 522 |
return $output;
|
| 523 |
}
|
| 524 |
|
| 525 |
|
| 526 |
function views_scheduler_delete_confirm_submit($form_id, $form_values) {
|
| 527 |
if ($form_values['confirm']) {
|
| 528 |
$vs_id = $form_values['vs_id'];
|
| 529 |
|
| 530 |
db_query('DELETE FROM {view_schedules_actions_registry} WHERE vsid = %d', $vs_id);
|
| 531 |
db_query('DELETE FROM {view_schedules} WHERE vschedule_id = %d', $vs_id);
|
| 532 |
db_query('DELETE FROM {schedules} WHERE type = "view" AND publication_id = %d', $vs_id);
|
| 533 |
|
| 534 |
drupal_set_message(t('Scheduled view has been deleted.'));
|
| 535 |
drupal_goto('admin/build/schedule_views');
|
| 536 |
|
| 537 |
}
|
| 538 |
}
|
| 539 |
|
| 540 |
/**
|
| 541 |
* Run the schedule using cron hook
|
| 542 |
*/
|
| 543 |
function views_scheduler_cron() {
|
| 544 |
include_once 'views_scheduler_process.inc';
|
| 545 |
views_scheduler_process_schedule('view');
|
| 546 |
return;
|
| 547 |
}
|
| 548 |
|
| 549 |
/**
|
| 550 |
* Get the actions associated with a given view.
|
| 551 |
* @param int vs_id (viewschedule_id )
|
| 552 |
* @param int nid to load the node values
|
| 553 |
* @return null, runs through the actions only
|
| 554 |
*/
|
| 555 |
function views_scheduler_carry_out_actions($vs_id,$nid) {
|
| 556 |
|
| 557 |
if ($vs_id) {
|
| 558 |
//get all the actions linked to the schedule
|
| 559 |
$actions_array = views_scheduler_get_actions($vs_id);
|
| 560 |
|
| 561 |
//run through the actions+nodes
|
| 562 |
if ($actions_array) {
|
| 563 |
$node = node_load($nid);
|
| 564 |
actions_do(array_keys($actions_array), $node);
|
| 565 |
}
|
| 566 |
}
|
| 567 |
}
|
| 568 |
|
| 569 |
function views_scheduler_list_hours() {
|
| 570 |
$time = array(
|
| 571 |
'01' => '1 am',
|
| 572 |
'02' => '2 am',
|
| 573 |
'03' => '3 am',
|
| 574 |
'04' => '4 am',
|
| 575 |
'05' => '5 am',
|
| 576 |
'06' => '6 am',
|
| 577 |
'07' => '7 am',
|
| 578 |
'08' => '8 am',
|
| 579 |
'09' => '9 am',
|
| 580 |
'10' => '10 am',
|
| 581 |
'11' => '11 am',
|
| 582 |
'12' => '12 am',
|
| 583 |
'13' => '1 pm',
|
| 584 |
'14' => '2 pm',
|
| 585 |
'15' => '3 pm',
|
| 586 |
'16' => '4 pm',
|
| 587 |
'17' => '5 pm',
|
| 588 |
'18' => '6 pm',
|
| 589 |
'19' => '7 pm',
|
| 590 |
'20' => '8 pm',
|
| 591 |
'21' => '9 pm',
|
| 592 |
'22' => '10 pm',
|
| 593 |
'23' => '11 pm',
|
| 594 |
'00' => '12 pm');
|
| 595 |
return $time;
|
| 596 |
}
|
| 597 |
|
| 598 |
function views_scheduler_activate($next) {
|
| 599 |
$activate = ($next != 0 && $next <= time()) ? TRUE : FALSE;
|
| 600 |
return $activate;
|
| 601 |
}
|
| 602 |
|
| 603 |
function views_scheduler_select_schedules($type, $schedule_id) {
|
| 604 |
|
| 605 |
$schedule = db_fetch_array(db_query("SELECT * FROM {schedules} WHERE schedule_id = '%d' AND type = '%s'", $schedule_id, $type));
|
| 606 |
return $schedule;
|
| 607 |
}
|