/** * Retrieve the $value from the $parameters array checking for * $parameters[$value] and $params[$id.$value]. Returns $default * if $value is not in $params array. * Note: This function will also trim() string values. * * @param array $parameters * @param string $value * @param mixed $default_value * @param string $session_key * @return mixed * Rolf: looks like not used */ function get_parameter_value($parameters, $value, $default_value = '', $session_key = '') { if ($session_key != '') { if (isset($_SESSION['parameter_values'][$session_key])) { $default_value = $_SESSION['parameter_values'][$session_key]; } } // set our return value to the default initially and overwrite with $value if we like it. $return_value = $default_value; if (isset($parameters[$value])) { if (is_bool($default_value)) { // want a boolean return_value if (isset($parameters[$value])) { $return_value = (bool) $parameters[$value]; } } else { // is $default_value a number? $is_number = false; if (is_numeric($default_value)) { $is_number = true; } if (is_array($parameters[$value])) { // $parameters[$value] is an array - validate each element. $return_value = array(); foreach ($parameters[$value] as $element) { $return_value[] = get_value_with_default($element, $default_value); } } else { if (is_numeric($default_value)) { // default value is a number, we only like $parameters[$value] if it's a number too. if (is_numeric($parameters[$value])) { $return_value = $parameters[$value]; } } elseif (is_string($default_value)) { $return_value = trim($parameters[$value]); } else { $return_value = $parameters[$value]; } } } } if ($session_key != '') { $_SESSION['parameter_values'][$session_key] = $return_value; } return $return_value; }
<?php function get_value_with_default($array, $key, $default) { $value = $array[$key]; if (!$value) { $value = $default; } return $value; } # FIXME: Add a navigation bar for when there are more than 50 jobs. $uncompleted_jobs = $db->query_and_fetch_all('SELECT * FROM jobs WHERE job_completed_at IS NULL LIMIT 50'); if ($uncompleted_jobs) { foreach ($uncompleted_jobs as $job) { $id = $job['job_id']; $started_at = get_value_with_default($job, 'job_started_at', ''); $pid = get_value_with_default($job, 'job_started_by_pid', ''); echo <<<EOF <tr> <td>{$id}</td> <td>{$job['job_type']}</td> <td>{$job['job_created_at']}</td> <td>{$started_at}</td><td>{$pid}</td> <td>{$job['job_attempts']}</td> <td><pre class="payload">{$job['job_payload']}</pre></td> <td><pre>{$job['job_log']}</pre></td> <td><form method='POST'><button type='submit' name='action' value='delete'>Delete</button><input type='hidden' name='id' value='{$id}'></form></td> </tr> EOF; } } ?>