function search_results() { global $vars, $db, $calendar_name, $sort_options, $order_options; $searchstring = $vars['searchstring']; $start = "{$vars['syear']}-{$vars['smonth']}-{$vars['sday']}"; $end = "{$vars['eyear']}-{$vars['emonth']}-{$vars['eday']}"; // make sure sort is valid $sort = $vars['sort']; if (array_search($sort, array_keys($sort_options)) === false) { soft_error(_('Invalid sort option') . ": {$sort}"); } // make sure order is valid $order = $vars['order']; if (array_search($order, array_keys($order_options)) === false) { soft_error(_('Invalid order option') . ": {$order}"); } $keywords = explode(" ", $searchstring); $words = array(); foreach ($keywords as $keyword) { $words[] = "(subject LIKE '%{$keyword}%' " . "OR description LIKE '%{$keyword}%')\n"; } $where = implode(' AND ', $words); $query = 'SELECT * FROM ' . SQL_PREFIX . "events " . "WHERE ({$where}) " . "AND calendar = '{$calendar_name}' " . "AND enddate >= DATE '{$start}' " . "AND startdate <= DATE '{$end}' " . "ORDER BY {$sort} {$order}"; $result = $db->Execute($query) or db_error(_('Encountered an error while searching.'), $query); $tags = array(); while ($row = $result->FetchRow()) { $name = stripslashes($row['uid']); $subject = stripslashes($row['subject']); $desc = nl2br(stripslashes($row['description'])); $desc = parse_desc($desc); $tags[] = tag('tr', tag('td', attributes('class="phpc-list"'), tag('strong', create_id_link($subject, 'display', $row['id']))), tag('td', attributes('class="phpc-list"'), $row['startdate'] . ' ' . formatted_time_string($row['starttime'], $row['eventtype'])), tag('td', attributes('class="phpc-list"'), $desc)); } if (sizeof($tags) == 0) { $html = tag('div', tag('strong', _('No events matched your search criteria.'))); } else { $html = tag('table', attributes('class="phpc-main"'), tag('caption', _('Search Results')), tag('thead', tag('tr', tag('th', _('Subject')), tag('th', _('Date Time')), tag('th', _('Description'))))); foreach ($tags as $tag) { $html->add($tag); } } return $html; }
function display_id($id) { global $db, $year, $month, $day, $config; $row = get_event_by_id($id); $year = $row['year']; $month = $row['month']; $day = $row['day']; $time_str = formatted_time_string($row['starttime'], $row['eventtype']); $date_str = formatted_date_string($row['year'], $row['month'], $row['day'], $row['end_year'], $row['end_month'], $row['end_day']); $dur_str = get_duration($row['duration'], $row['eventtype']); $subject = htmlspecialchars(strip_tags(stripslashes($row['subject']))); if (empty($subject)) { $subject = _('(No subject)'); } $name = stripslashes($row['username']); $desc = parse_desc($row['description']); if (check_user($row['uid']) || $config['anon_permission'] >= 2) { return tag('div', attributes('class="phpc-main"'), tag('h2', $subject), tag('div', 'by ', tag('cite', $name)), tag('div', create_id_link(_('Modify'), 'event_form', $id), "\n", create_id_link(_('Delete'), 'event_delete', $id)), tag('div', tag('div', _('Date') . ": {$date_str}"), tag('div', _('Time') . ": {$time_str}"), tag('div', _('Duration') . ": {$dur_str}")), tag('p', $desc)); } else { return tag('div', attributes('class="phpc-main"'), tag('h2', $subject), tag('div', 'by ', tag('cite', $name)), tag('div', tag('div', _('Date') . ": {$date_str}"), tag('div', _('Time') . ": {$time_str}"), tag('div', _('Duration') . ": {$dur_str}")), tag('p', $desc)); } }