disconnect; exit; function load_index($dbh, $smarty, $invals){ $limits['all'] = 'All Services'; $limits['is_free'] = 'Free Services'; $limits['subscriber'] = 'Subscriber Services'; $smarty->assign('limits', $limits); $smarty->assign('limit', 'all'); $smarty->display('index.tpl'); } function search($dbh, $smarty, $invals){ $start = $invals['start'] ? $invals['start'] :1; $num_display = 5; $query_string = 'mode=search'; // set up the query $query = 'select * from task_search'; if($invals['limit'] == 'is_free'){ $where[] = ' is_fee = 0 '; $query_string .= '&limit=is_free'; }else if($invals['limit'] == 'subscriber'){ $where[] = ' subscriber = 1 '; $query_string .= '&limit=subscriber'; } $criteria = preg_replace('/[|;%<>]/', '', $criteria); $criteria = $invals['criteria']; if($criteria){ $query = 'select *, match(name, description) against (?) as score from task_search'; $where[] = ' (match(name, description) against (? in boolean mode) or name like ? or description like ?) order by score desc'; $query_string .= '&criteria=' . urlencode($criteria); $vals[] = $criteria; $vals[] = '+' . preg_replace('/\s/', '* +', $criteria) . '*'; $vals[] = '%' . $criteria . '%'; $vals[] = '%' . $criteria . '%'; } if($where){$query = $query . ' where ' . implode('and', $where);} // run the query if($vals){$res = $dbh->Execute($query, $vals);} else{$res = $dbh->Execute($query);} $row_count = $res->RowCount(); // get this page results if($row_count > $num_display){ $res->Move($start - 1); for($i = 0; $i < $num_display; $i++){ if(!$res->EOF){ $results[] = $res->fields; $res->MoveNext(); } } }else{ $results = $res->GetAll(); } $end = $row_count; // build the paging links if($row_count > $num_display){ if($start != 1){ $links['First'] = $query_string . '&start=1'; $links['Prev'] = $query_string . '&start=' . ($start - $num_display); } $end = $start + $num_display - 1; if(($start + $num_display) <= $row_count){ $links['Next'] = $query_string . '&start=' . ($start + $num_display); $last = ($row_count % $num_display); if($last){ $last = $row_count - $last + 1; }else{ $last = $row_count - $num_display + 1; } $links['Last'] = $query_string . '&start=' . $last; }else{ $end = $row_count; } $smarty->assign('links', $links); } $smarty->assign('row_count', $row_count); $smarty->assign('end', $end); $smarty->assign('start', $start); $smarty->assign('results', $results); $smarty->display('results.tpl'); } ?>