public function listAction() { if (isset($this->params['searchfor'])) { if ($this->params['searchfor'] === 'id') { $this->params['id'] = $this->params['seachtext']; $this->readAction(); exit; } } $this->params['page_title'] = $this->params['members_list_text']; $str = View::render('depositors_table/sort', $this->params, true); $str .= View::render('depositors_table/table_header', $this->params, true); $api_params = @array('controller' => 'depositor', 'action' => 'list', 'sortby' => $this->params['sortby'], 'sortorder' => $this->params['sortorder'], 'state' => $this->params['state'], 'page' => $this->params['page'], 'perpage' => $this->params['perpage'], 'search' => $this->params['search'], 'searchfor' => $this->params['searchfor'], 'seachtext' => $this->params['seachtext']); try { $data = $this->_API->sendRequest($api_params); } catch (Exception $e) { #catch any exceptions and report the problem @ErrorHandling::APIException('depo:list', $data, $api_params, $e, $this->params); } if (!empty($data['result'])) { foreach ($data['result'] as $d) { $col = function (&$str, $params, $field) { $str .= View::render('depositors_table/column', $params, true); $str .= $field; $str .= View::render('depositors_table/column_end', $params, true); }; $str .= View::render('depositors_table/row', $this->params, true); $col($str, $this->params, urldecode($d['depositor no.'])); $col($str, $this->params, urldecode($d['name'])); $col($str, $this->params, urldecode($d['surname'])); $col($str, $this->params, urldecode($d['mobile'])); $col($str, $this->params, urldecode($d['email'])); $col($str, $this->params, urldecode($d['hours no.'])); $col($str, $this->params, urldecode($d['state'])); $this->params['depositor_id'] = $d['depositor no.']; $col($str, $this->params, View::render('depositors_table/button', $this->params, true)); #details button $str .= View::render('depositors_table/row_end', $this->params, true); } } else { $str .= View::render('depositors_table/nodata', $this->params, true); } $str .= View::render('depositors_table/table_footer', $this->params, true); if ($data['pages'] > 1) { $url = 'index.php?' . $_SERVER['QUERY_STRING'] . '&page=1'; $page_url = 'index.php?' . $_SERVER['QUERY_STRING'] . '&page='; if (empty($this->params['perpage'])) { $this->params['perpage'] = 20; } Pagination::set($this->params, $data['page'], $data['pages'], $this->params['perpage'], $url, $page_url); $str .= Pagination::display(); } $this->render($str); }
function index() { global $path; global $template; $conditionspre = ''; $conditionspost = ''; $conditionsselect = ''; $extratitle = ''; $orderby = "newest"; $order = 'created desc'; $defaultorder = 1; $nopagination = 0; $page = 1; $searchstringoriginal = ''; if (!empty($_GET['search'])) { $searchstringoriginal = sanitize($_GET['search'], "string"); } if (!empty($_GET['order'])) { if ($_GET['order'] == "votes") { $order = "votes desc"; $orderby = "votes"; $defaultorder = 0; } else { if ($_GET['order'] == "oldest") { $order = "created asc"; $orderby = "oldest"; $defaultorder = 0; } else { if ($_GET['order'] == "relevance") { $order = "score desc"; $orderby = "relevance"; $defaultorder = 0; } else { if ($_GET['order'] == "newest") { $defaultorder = 0; } } } } } if (!empty($_GET['page'])) { $page = sanitize($_GET['page'], "int"); } $type = ''; if (!empty($_GET['type'])) { $type = "&type=" . sanitize($_GET['type'], "string"); if (sanitize($_GET['type'], "string") == "unanswered") { // $conditionspost .= " questions.id NOT IN (select questions.id from questions,answers where questions.id = answers.questionid and answers.accepted = 1) and "; $conditionspost .= " questions.accepted = 0 and questions.kb = 0 and "; $extratitle = " " . _("not yet answered"); } else { $extratitle = " " . _("active"); $order = " updated desc "; $nopagination = 1; } } $template->set('nopagination', $nopagination); $search = ''; $searchstring = urldecode($searchstringoriginal); if (!empty($searchstringoriginal)) { $search = "&search=" . urlencode($searchstring); $conditionspost .= " MATCH(title, description) AGAINST ('" . escape($searchstring) . "') and "; $conditionsselect .= ",MATCH(title, description) AGAINST ('" . escape($searchstring) . "') AS score "; $extratitle = " " . _("showing") . " " . $searchstring; if ($defaultorder == 1) { $orderby = "relevance"; $order = 'score desc'; } } $template->set('searchstring', $searchstring); $tag = ''; if (!empty($_GET['tag'])) { $tag = "&tag=" . createSlug($_GET['tag']); $conditionspre .= ",tags_questions, tags"; $conditionspost .= " tags_questions.questionid = questions.id and tags.id = tags_questions.tagid and tags.tag LIKE '" . escape(createSlug($_GET['tag'])) . "' and "; $extratitle = " " . _("tagged") . " " . createSlug($_GET['tag']); } $offset = ($page - 1) * QUESTIONS_PER_PAGE; $sql = "select count(questions.id) count from questions {$conditionspre} WHERE {$conditionspost} 1"; $query = mysql_query($sql); $result = mysql_fetch_array($query); $template->set('questionscount', $result['count']); $paging = new Pagination(); $paging->set('urlscheme', '?order=' . $orderby . $tag . $type . $search . '&page=%page%'); $paging->set('perpage', QUESTIONS_PER_PAGE); $paging->set('page', $page); $paging->set('total', $result['count']); $paging->set('order', $orderby); $paging->set('search', $search); $template->set('pagination', $paging->display()); $paging->set('urlscheme', '?order=%label%' . $tag . $type . $search . '&page=1'); $template->set('orderOptions', $paging->displayOptions()); $template->set('extratitle', $extratitle); $sql = "select questions.* {$conditionsselect} from questions {$conditionspre} WHERE {$conditionspost} 1 order by {$order}, created desc LIMIT " . QUESTIONS_PER_PAGE . " OFFSET {$offset}"; $query = mysql_query($sql); $questions = array(); while ($result = mysql_fetch_array($query)) { $sql_nest = "select tag from tags_questions, tags where questionid = '" . escape($result['id']) . "' and tags.id = tags_questions.tagid order by tag"; $query_nest = mysql_query($sql_nest); $tags = array(); while ($result_nest = mysql_fetch_array($query_nest)) { $tags[] = $result_nest['tag']; } $description = truncate(trim(sanitize(Markdown($result['description']), "string"))); if (!empty($searchstring)) { $description = highlight(excerpt(trim(sanitize(Markdown($result['description']), "string")), $searchstring), $searchstring); $result['title'] = highlight($result['title'], $searchstring); } $questions[] = array("title" => $result['title'], "created" => $result['created'], "updated" => $result['updated'], "userid" => $result['userid'], "link" => $result['link'], "slug" => $result['slug'], "answers" => $result['answers'], "accepted" => $result['accepted'], "kb" => $result['kb'], "votes" => $result['votes'], "id" => $result['id'], "tags" => $tags, "description" => $description); } $template->set('questions', $questions); }