header('location:../index.php'); //regresar al formulario break; /*FIN INSERTAR...................................................................................*/ /*FIN INSERTAR...................................................................................*/ case '2': /*MODIFICAR O ELIMINAR.........................................................................*/ echo "entree"; foreach ($_POST['seleccion'] as $indice => $valor) { $opcion = $_POST['seleccion'][$indice]; //extraemos cadena elimina o modifica switch ($opcion) { //generamos la sentencia para la modificación filtrando por el id para que solo cambie ese registro case 'Actualizar': $frequency = pg_escape_string($_POST['frequency'][$indice]); $resultado = query("UPDATE data_control_portal.data_control SET \n section_name='" . pg_escape_string($_POST['section_name'][$indice]) . "', \n sub_section='" . pg_escape_string($_POST['sub_section'][$indice]) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata_type ='" . pg_escape_string($_POST['data_type'][$indice]) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlast_update='" . pg_escape_string($_POST['last_update'][$indice]) . "',\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnext_update='" . date('Y-m-d', strtotime($last_update . ' + ' . next_time($frequency) . 'days')) . "', \n frequency='" . $frequency . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsource ='" . pg_escape_string($_POST['source'][$indice]) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\turl_portal='" . pg_escape_string($_POST['url_portal'][$indice]) . "',\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgtp_database='" . pg_escape_string($_POST['gtp_database'][$indice]) . "', \n managers='" . pg_escape_string($_POST['managers'][$indice]) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnote='" . pg_escape_string($_POST['note'][$indice]) . "'\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n WHERE id=" . $_POST['id'][$indice]); break; //sql para eliminar //sql para eliminar case 'Eliminar': $resultado = query("DELETE FROM data_control_portal.data_control WHERE id=" . $_POST['id'][$indice]); // break; } pg_free_result($resultado); header('location:../index.php'); //regresar al formulario } break; /* FINNN MODIFICAR O ELIMINAR.........................................................................*/ } /*Fin SWITCH*/
function CalculateNextTrigger($tasks = array(), $forceUpdate = false) { global $modSettings, $smcFunc; $task_query = ''; if (!is_array($tasks)) { $tasks = array($tasks); } // Actually have something passed? if (!empty($tasks)) { if (!isset($tasks[0]) || is_numeric($tasks[0])) { $task_query = ' AND id_task IN ({array_int:tasks})'; } else { $task_query = ' AND task IN ({array_string:tasks})'; } } $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time']; // Get the critical info for the tasks. $request = smf_db_query(' SELECT id_task, next_time, time_offset, time_regularity, time_unit FROM {db_prefix}scheduled_tasks WHERE disabled = {int:no_disabled} ' . $task_query, array('no_disabled' => 0, 'tasks' => $tasks)); $tasks = array(); while ($row = mysql_fetch_assoc($request)) { $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); // Only bother moving the task if it's out of place or we're forcing it! if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) { $tasks[$row['id_task']] = $next_time; } else { $next_time = $row['next_time']; } // If this is sooner than the current next task, make this the next task. if ($next_time < $nextTaskTime) { $nextTaskTime = $next_time; } } mysql_free_result($request); // Now make the changes! foreach ($tasks as $id => $time) { smf_db_query(' UPDATE {db_prefix}scheduled_tasks SET next_time = {int:next_time} WHERE id_task = {int:id_task}', array('next_time' => $time, 'id_task' => $id)); } // If the next task is now different update. if ($modSettings['next_task_time'] != $nextTaskTime) { updateSettings(array('next_task_time' => $nextTaskTime)); } }
/** * Process the next tasks, one by one, and update the results. * * @package ScheduledTasks * @param int $ts = 0 */ function processNextTasks($ts = 0) { $db = database(); // We'll run tasks, or so we hope. require_once SUBSDIR . '/ScheduledTask.class.php'; // Select the next task to do. $request = $db->query('', ' SELECT id_task, task, next_time, time_offset, time_regularity, time_unit FROM {db_prefix}scheduled_tasks WHERE disabled = {int:not_disabled} AND next_time <= {int:current_time} ORDER BY next_time ASC LIMIT 1', array('not_disabled' => 0, 'current_time' => time())); if ($db->num_rows($request) != 0) { // The two important things really... $row = $db->fetch_assoc($request); // When should this next be run? $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); // How long in seconds is the gap? $duration = $row['time_regularity']; if ($row['time_unit'] == 'm') { $duration *= 60; } elseif ($row['time_unit'] == 'h') { $duration *= 3600; } elseif ($row['time_unit'] == 'd') { $duration *= 86400; } elseif ($row['time_unit'] == 'w') { $duration *= 604800; } // If we were really late running this task actually skip the next one. if (time() + $duration / 2 > $next_time) { $next_time += $duration; } // Update it now, so no others run this! $db->query('', ' UPDATE {db_prefix}scheduled_tasks SET next_time = {int:next_time} WHERE id_task = {int:id_task} AND next_time = {int:current_next_time}', array('next_time' => $next_time, 'id_task' => $row['id_task'], 'current_next_time' => $row['next_time'])); $affected_rows = $db->affected_rows(); // Do also some timestamp checking, // and do this only if we updated it before. if ((empty($ts) || $ts == $row['next_time']) && $affected_rows) { ignore_user_abort(true); run_this_task($row['id_task'], $row['task']); } } $db->free_result($request); }