public function action_index() { $steps = self::$steps; // error verification if (empty($steps)) { throw new Exception('No steps?'); } // building form first $input = request::input(); $ms = '<div class="form">'; $ms .= '<table width="100%" class="simple">'; if (sizeof($steps) > 1) { $ms .= '<tr><td width="1%">' . h::radio(array('name' => 'execute_step', 'class' => 'radio', 'value' => 'all', 'checked' => @$input['execute_step'] == 'all' ? true : false)) . '</td><td>All steps</td></tr>'; } foreach ($steps as $k => $v) { $ms .= '<tr><td width="1%">' . h::radio(array('name' => 'execute_step', 'class' => 'radio', 'value' => $k, 'checked' => @$input['execute_step'] == $k ? true : false)) . '</td><td>Step ' . $k . ' ' . $v['name'] . '</td></tr>'; // appending extra html if (!empty($v['html'])) { $ms .= '<tr><td width="1%"></td><td>' . $v['html'] . '</td></tr>'; } } $ms .= '</table>'; $ms .= '<br />'; $ms .= h::submit(array('name' => 'submit', 'class' => 'button yellow')); $ms .= '</div>'; $ms = h::form(array('name' => 'executioner', 'value' => $ms)); echo h::frame($ms, 'simple'); // executing steps if (!empty($input['execute_step'])) { $time_start = time(); //echo '<hr />'; foreach ($steps as $k => $v) { // double check if (!isset($v['execute'])) { throw new Exception('execute?'); } // executing if ($input['execute_step'] == 'all' || $input['execute_step'] == $k) { echo '<hr /><h4>Step [' . $k . '. ' . $v['name'] . ']: </h4>'; // redirecting request if set $params = array(); if (!empty($input['redirect_request'][$k])) { $params = $input['redirect_request'][$k]; } else { if (!empty($v['params'])) { $params = $v['params']; } } // we will be keeping alive alive::start(); $result2 = call_user_func_array($v['execute'], $params); alive::stop(); // processing result if (is_scalar($result2)) { echo $result2; } else { if (is_array($result2)) { if (@$result2['hint']) { layout::add_message($result2['hint'], 'info'); } if (@$result2['error']) { layout::add_message($result2['error'], 'error'); // important: we terminate batch echo 'Batch terminated due to error!'; break; } } } } } // time $time_end = time(); echo '<hr />'; echo '<b>Run time: ' . ($time_end - $time_start) . 'sec</b>'; } }
public function render() { $input = request::input(); $settings = array(); $settings['limit'] = @$input['limit'] ? @intval($input['limit']) : 20; $settings['offset'] = @intval(@$input['offset']); // show starting from this row $settings['orderby'] = isset($input['orderby']) ? $input['orderby'] : $this->list_orderby; // order by column $settings['orderdesc'] = isset($input['orderdesc']) ? $input['orderdesc'] : $this->list_orderdesc; // order direction $settings['took'] = microtime(true); // building sql for select $from = ' FROM ' . $this->list_table . @$this->left_join . ' WHERE 1=1'; // full text search $full_text_search = array(); $gist_columns = array(); if (!empty($input['full_text_search']) && !empty($this->full_text_search_column)) { $full_text_search = db::tsquery($this->full_text_search_column, $input['full_text_search'], '|', true, array(), $this->link); $from .= $full_text_search['where']; } // other where if (!empty($this->where)) { $from .= $this->where; } // getting number of records if (@$this->list_count_rows) { $sql = 'SELECT COUNT(*) as rows_count ' . $from; $result = db::query($sql, '', array(), $this->link); if (@$result['error']) { layout::add_message($result['error'], 'error'); } // use this variable to get number of rows, isset for verification $settings['count_rows'] = @$result['rows'][0]['rows_count'] ? $result['rows'][0]['rows_count'] : 0; } else { // EXPERIMENTAL: increase number of rows fetched by 1 to check whether next row exists $settings['limit']++; } // quering $sql = 'SELECT ' . $this->select . (!empty($full_text_search['rank']) ? ', ' . $full_text_search['rank'] . ' ts_rank2' : '') . $from; $sql .= ' ORDER BY ' . (@$full_text_search['orderby'] ? @$full_text_search['orderby'] . ", " : "") . $settings['orderby'] . ($settings['orderdesc'] ? ' DESC' : ''); $sql .= $settings['limit'] ? ' LIMIT ' . $settings['limit'] : ''; $sql .= $settings['offset'] ? ' OFFSET ' . $settings['offset'] : ''; $result = db::query($sql, '', array(), $this->link); $settings['took'] = round(microtime(true) - $settings['took'], 2); // processing count if (!@$this->list_count_rows) { if (isset($result['rows'][$settings['limit'] - 1])) { $settings['flag_next_row_exists'] = true; } unset($result['rows'][$settings['limit'] - 1]); $settings['limit']--; } $settings['num_rows'] = count($result['rows']); // rendering list $ms = ''; // Hidden elements $ms .= h::hidden(array('name' => 'orderby', 'id' => 'orderby', 'value' => $settings['orderby'])); $ms .= h::hidden(array('name' => 'orderdesc', 'id' => 'orderdesc', 'value' => $settings['orderdesc'])); $ms .= h::hidden(array('name' => 'offset', 'id' => 'offset', 'value' => $settings['offset'])); $ms .= h::hidden(array('name' => 'limit', 'id' => 'limit', 'value' => $settings['limit'])); // if we have no rows if (empty($result['rows'])) { $ms .= 'No records found!'; } else { // main container $header = $this->header($settings); $ms .= $header; $ms .= '<br/>'; $ms .= '<table cellpadding="0" cellspacing="0" class="editor table" width="100%">'; // types $types = model_presets::get('he_post_type'); // rows $row_counter = 1; foreach ($result['rows'] as $k => $v) { $ms .= '<tr>'; $ms .= '<td class="editor cell numeration" valign="top">' . $row_counter . '. </td>'; $ms .= '<td class="editor cell regular" align="left">'; // generating urls $url_post = call_user_func_array($this->url_posts, array($v['type'], $v['post_id'], $v['uri'])); $url_type = call_user_func_array($this->url_type, array($v['type'])); // title with icon goes first $value = $v['title']; if ($v['type'] == 20) { $v['icon'] = 'help16.png'; } else { if ($v['type'] == 10) { $v['icon'] = 'faq16.png'; } } if (!empty($v['icon'])) { $value = icon::render($v['icon']) . ' ' . $value; } $ms .= h::a(array('href' => $url_post, 'value' => $value)); if (isset($v['ts_rank2'])) { $ms .= ' [' . $v['ts_rank2'] . ']'; } // entry type $ms .= ' ' . h::a(array('href' => $url_type, 'value' => $types[$v['type']]['name'], 'style' => 'color:black;')); $ms .= '<br/>'; $ms .= h::a(array('href' => $url_post, 'value' => $url_post, 'style' => 'color: green;')); if (!empty($input['full_text_search'])) { $ms .= '<br/>'; $temp = keywords::highlight($v['body'], $input['full_text_search'], array('<b style="color:red;">', '</b>')); } else { $ms .= '<br/>'; $temp = $v['body']; } $ms .= $temp; $ms .= '<br/>'; $ms .= '<br/>'; $ms .= '</td>'; $ms .= '</tr>'; $row_counter++; } $ms .= '</table>'; $ms .= $header; $ms .= '<br class="clearfloat">'; } return $ms; }