Revision: 1974
http://mrbs.svn.sourceforge.net/mrbs/?rev=1974&view=rev
Author: cimorrison
Date: 2011-09-21 14:05:51 +0000 (Wed, 21 Sep 2011)
Log Message:
-----------
Made search results into a datatable
Modified Paths:
--------------
mrbs/branches/datatables/web/Themes/default/header.inc
mrbs/branches/datatables/web/mrbs.css.php
mrbs/branches/datatables/web/search.php
Modified: mrbs/branches/datatables/web/Themes/default/header.inc
===================================================================
--- mrbs/branches/datatables/web/Themes/default/header.inc 2011-09-21
09:20:38 UTC (rev 1973)
+++ mrbs/branches/datatables/web/Themes/default/header.inc 2011-09-21
14:05:51 UTC (rev 1974)
@@ -171,7 +171,7 @@
<?php
// dataTables initialisation
- if (in_array($page, array('admin', 'edit_users', 'pending', 'report')))
+ if (in_array($page, array('admin', 'edit_users', 'pending', 'report',
'search')))
{
// Include the JavaScript for those pages that use dataTables
?>
@@ -951,9 +951,6 @@
?>
-$(document).ready(function() {
- $('.datatable_container').css('visibility', 'none');
-});
$(window).load(function() {
@@ -965,6 +962,21 @@
logonForm.NewUserName.focus();
}
+ <?php
+ // Add in a hidden input to the header search form so that we can tell if we
are using DataTables
+ // (which will be if JavaScript is enabled and we're not running IE6 or
below). We
+ // need to know this because when we're using an Ajax data source we don't
want to send
+ // the HTML version of the table data.
+ ?>
+ if (!lteIE6)
+ {
+ $('<input>').attr({
+ type: 'hidden',
+ name: 'datatable',
+ value: '1'
+ }).appendTo('#header_search');
+ }
+
<?php
// ADMIN.PHP
@@ -1538,17 +1550,68 @@
// SEARCH.PHP
if ($page == 'search')
{
- // put the search string field in focus
+ // put the search string field in focus
+ ?>
+ var searchForm = $('#search_form');
+ searchForm.find('#search_str').focus();
+
+ <?php
+ // Turn the list of users into a dataTable, provided that we can use
+ // an Ajax source. Otherwise they just get the old style search page
+ // with "Next" and "Prev" buttons to get new pages from the server.
+ // [We could of course use dataTables with server side processing, but
+ // that's a lot of work. A better option would probably be to write one's
+ // own json_encode function for PHP versions that don't have it]
+ if (function_exists('json_encode'))
+ {
+ // Add in a hidden input to the search form so that we can tell if we
are using DataTables
+ // (which will be if JavaScript is enabled and we're not running IE6 or
below). We
+ // need to know this because when we're using an Ajax data source we
don't want to send
+ // the HTML version of the table data.
+ ?>
+ if (!lteIE6)
+ {
+ $('<input>').attr({
+ type: 'hidden',
+ name: 'datatable',
+ value: '1'
+ }).appendTo(searchForm);
+ }
+
+ var tableOptions = new Object();
+ <?php
+ // Use an Ajax source - gives much better performance for large tables
+
+ $ajax_url = "http://" . $HTTP_HOST . $PHP_SELF . "?" . $QUERY_STRING .
"&ajax=1";
+ ?>
+ tableOptions.sAjaxSource = "<?php echo $ajax_url ?>";
+ tableOptions.aoColumnDefs = [{"sType": "title-numeric", "aTargets":
[2]}];
+ <?php
+ // Fix the left hand column. This has to be done when initialisation
+ // is complete as the language files are loaded asynchronously
+ ?>
+ tableOptions.fnInitComplete = function(){
+ var oFC = new FixedColumns(searchTable, {"iLeftColumns": 1,
+ "iLeftWidth": 25,
+ "sLeftWidth": "relative"});
+ $('.js div.datatable_container').css('visibility', 'visible');
+ };
+ <?php
+ // Remove the first column from the column visibility
+ // list because it is fixed
+ ?>
+ tableOptions.oColVis = {aiExclude: [0]};
+ <?php
+ // and stop the first column being reordered
+ ?>
+ tableOptions.oColReorder = {"iFixedColumns": 1};
+
+ var searchTable = makeDataTable('#search_results', tableOptions);
+
+ <?php
+ } // if (function_exists('json_encode'))
+ } // if ($page == 'search')
?>
- var form = document.getElementById('search_form');
- if (form && form.search_str)
- {
- form.search_str.focus();
- }
-
- <?php
- }
- ?>
});
Modified: mrbs/branches/datatables/web/mrbs.css.php
===================================================================
--- mrbs/branches/datatables/web/mrbs.css.php 2011-09-21 09:20:38 UTC (rev
1973)
+++ mrbs/branches/datatables/web/mrbs.css.php 2011-09-21 14:05:51 UTC (rev
1974)
@@ -113,7 +113,6 @@
.admin h2 {clear: left}
div#area_form, div#room_form {float: left; padding: 0 0 2em 1em}
div#area_form {width: auto}
-div#room_form {width: 98%}
div#room_info {width: 100%; float: left}
div#custom_html {float: left; padding: 0 0 3em 1em}
#area_form form {float: left; margin-right: 1em}
@@ -684,7 +683,7 @@
#form_delete_users input.submit {left: 2.0em}
/* and put the Delete on the left */
#form_edit_users input.checkbox {width: auto; margin-left: <?php echo
$edit_users_gap ?>em}
form.edit_users_error {width: 10em; margin-top: 2.0em}
-div#user_list {width: 98%; padding: 2em 0 2em 1em}
+div#user_list {padding: 2em 0 2em 1em}
form#add_new_user {margin-left: 1em}
@@ -740,7 +739,6 @@
td.mincals_week_number { opacity: 0.5; font-size: 60%; }
/* ------------ PENDING.PHP ------------------*/
-div#pending_list {width: 98%; padding: 2em 0 2em 1em}
#pending_list form {display: inline-block}
#pending_list td.table_container, #pending_list td.sub_table {padding: 0;
border: 0; margin: 0}
#pending_list .control {padding-left: 0; padding-right: 0; text-align: center;
@@ -754,32 +752,6 @@
border-left-color: <?php echo $admin_table_border_color ?>}
div.div_buttons {float: left; height: 2em}
#pending_list form {margin: 2px 4px}
-<?php
-/*
-#pending_list form {float: left; margin: 0 0.5em}
-#pending_list table {width: 100%; border-spacing: 0px; border-collapse:
collapse; border: 0}
-#pending_list td.sub_table {padding: 0; margin: 0}
-#pending_list table.minimised tbody {display: none}
-#pending_list table th {border-top: 1px solid <?php echo
$admin_table_header_sep_color ?>;
- background-color: <?php echo
$pending_header_back_color ?>}
-#pending_list td {border-top-width: 1px}
-#pending_list .control {padding-left: 0; padding-right: 0; text-align: center;
- color: <?php echo $standard_font_color ?>}
-#pending_list th.control + th {border-left-width: 0}
-#pending_list td.control + td {border-left-width: 0}
-#pending_list table th.control{background-color: <?php echo
$pending_control_color ?>; cursor: default}
-#pending_list table th a {color: <?php echo $admin_table_header_font_color ?>}
-#pending_list table td {border-color: <?php echo $admin_table_border_color ?>;
- background-color: <?php echo $series_entry_back_color
?>}
-#pending_list .control {width: 1.2em}
-#pending_list th.header_name {width: 10%}
-#pending_list th.header_create {width: 10%}
-#pending_list th.header_area {width: 10%}
-#pending_list th.header_room {width: 10%}
-#pending_list th.header_action {width: 20em}
-#pending_list table th.header_start_time {text-transform: uppercase}
-*/
-?>
/* ------------ REPORT.PHP ----------------------*/
@@ -797,7 +769,6 @@
#div_summary td {text-align: right}
#div_summary tbody td:nth-child(even), #div_summary tfoot th:nth-child(even)
{border-right-width: 0}
#div_summary td:first-child {font-weight: bold}
-div#report_output {width: 98%}
p.report_entries {font-weight: bold}
.report .form_general fieldset fieldset {padding-top: 0.5em; padding-bottom:
0.5em}
.report .form_general fieldset fieldset legend {font-size: small; font-style:
italic; font-weight: normal}
@@ -814,8 +785,6 @@
p#nothing_found {font-weight: bold}
div#record_numbers {font-weight: bold}
div#record_nav {font-weight: bold; margin-bottom: 1.0em}
-table#search_results {border-spacing: 1px; border-collapse: collapse}
-#search_results td, #search_results th {border: 1px solid <?php echo
$search_table_border_color ?>; padding: 0.1em 0.2em 0.1em 0.2em}
/* ------------ SITE_FAQ ------------------------*/
.help q {font-style: italic}
@@ -860,6 +829,9 @@
#approve_buttons td#note form {width: 100%}
#approve_buttons td#note textarea {width: 100%; height: 6em}
+/*-------------DtaTables-------------------------*/
+div.datatable_container {width: 98%; padding: 2em 0 2em 1em}
+
/* ------------ jQuery UI additions -------------*/
.ui-autocomplete {
Modified: mrbs/branches/datatables/web/search.php
===================================================================
--- mrbs/branches/datatables/web/search.php 2011-09-21 09:20:38 UTC (rev
1973)
+++ mrbs/branches/datatables/web/search.php 2011-09-21 14:05:51 UTC (rev
1974)
@@ -3,15 +3,116 @@
require_once "defaultincludes.inc";
+
+function generate_search_nav_html($search_pos, $total, $num_records,
$search_str)
+{
+ global $day, $month, $year;
+ global $search;
+
+ $html = '';
+
+ $has_prev = $search_pos > 0;
+ $has_next = $search_pos < ($total-$search["count"]);
+
+ if ($has_prev || $has_next)
+ {
+ $html .= "<div id=\"record_numbers\">\n";
+ $html .= get_vocab("records") . ($search_pos+1) . get_vocab("through") .
($search_pos+$num_records) . get_vocab("of") . $total;
+ $html .= "</div>\n";
+
+ $html .= "<div id=\"record_nav\">\n";
+ $base_query_string = "search_str=" . urlencode($search_str) . "&" .
+ "total=$total&" .
+ "from_year=$year&" .
+ "from_month=$month&" .
+ "from_day=$day";
+ // display a "Previous" button if necessary
+ if($has_prev)
+ {
+ $query_string = $base_query_string . "&search_pos=" . max(0,
$search_pos-$search["count"]);
+ $html .= "<a href=\"search.php?$query_string\">";
+ }
+
+ $html .= get_vocab("previous");
+
+ if ($has_prev)
+ {
+ $html .= "</a>";
+ }
+
+ // add a separator for Next and Previous
+ $html .= (" | ");
+
+ // display a "Previous" button if necessary
+ if ($has_next)
+ {
+ $query_string = $base_query_string . "&search_pos=" . max(0,
$search_pos+$search["count"]);
+ $html .= "<a href=\"search.php?$query_string\">";
+ }
+
+ $html .= get_vocab("next");
+
+ if ($has_next)
+ {
+ $html .= "</a>";
+ }
+ $html .= "</div>\n";
+ }
+
+ return $html;
+}
+
+
+function output_row($row)
+{
+ global $ajax, $json_data;
+
+ $values = array();
+ // booking name
+ $values[] = "<a href=\"view_entry.php?id=".$row['entry_id']."\">" .
htmlspecialchars($row['name']) . "</a>";
+ // created by
+ $values[] = htmlspecialchars($row['create_by']);
+ // start time and link to day view
+ $date = getdate($row['start_time']);
+ $link = "<a
href=\"day.php?day=$date[mday]&month=$date[mon]&year=$date[year]&area=".$row['area_id']."\">";
+ if(empty($row['enable_periods']))
+ {
+ $link_str = time_date_string($row['start_time']);
+ }
+ else
+ {
+ list(,$link_str) = period_date_string($row['start_time']);
+ }
+ $link .= "$link_str</a>";
+ // add a span with the numeric start time in the title for sorting
+ $values[] = "<span title=\"" . $row['start_time'] . "\"></span>" . $link;
+ // description
+ $values[] = htmlspecialchars($row['description']);
+
+ if ($ajax)
+ {
+ $json_data['aaData'][] = $values;
+ }
+ else
+ {
+ echo "<tr>\n<td>\n";
+ echo implode("</td>\n<td>", $values);
+ echo "</td>\n</tr>\n";
+ }
+}
+
// Get non-standard form variables
$search_str = get_form_var('search_str', 'string');
$search_pos = get_form_var('search_pos', 'int');
$total = get_form_var('total', 'int');
$advanced = get_form_var('advanced', 'int');
+$ajax = get_form_var('ajax', 'int'); // Set if this is an Ajax request
+$datatable = get_form_var('datatable', 'int'); // Will only be set if we're
using DataTables
// Get the start day/month/year and make them the current day/month/year
$day = get_form_var('from_day', 'int');
$month = get_form_var('from_month', 'int');
$year = get_form_var('from_year', 'int');
+
// If we haven't been given a sensible date then use today's
if (!isset($day) || !isset($month) || !isset($year) || !checkdate($month,
$day, $year))
{
@@ -27,51 +128,66 @@
$user = getUserName();
$is_admin = (isset($user) && authGetUserLevel($user)>=2) ;
-// Need all these different versions with different escaping.
-if (isset($search_str) && ($search_str != ''))
+// Set up for Ajax. We need to know whether we're capable of dealing with
Ajax
+// requests, which will only be if (a) the browser is using DataTables and (b)
+// we can do JSON encoding. We also need to initialise the JSON data array.
+$ajax_capable = $datatable && function_exists('json_encode');
+
+if ($ajax)
{
- $search_url = urlencode($search_str);
- $search_html = htmlspecialchars($search_str);
+ $json_data['aaData'] = array();
}
-print_header($day, $month, $year, $area, isset($room) ? $room : "");
-
-if (!empty($advanced))
+if (!isset($search_str))
{
- ?>
- <form class="form_general" id="search_form" method="get" action="search.php">
- <fieldset>
- <legend><?php echo get_vocab("advanced_search") ?></legend>
- <div id="div_search_str">
- <label for="search_str"><?php echo get_vocab("search_for") ?>:</label>
- <input type="text" id="search_str" name="search_str">
- </div>
- <div id="div_search_from">
- <?php
- echo "<label for=\"from_datepicker\">" . get_vocab("from") .
":</label>\n";
- genDateSelector ("from_", $day, $month, $year);
- ?>
- </div>
- <div id="search_submit">
- <input class="submit" type="submit" value="<?php echo
get_vocab("search_button") ?>">
- </div>
- </fieldset>
- </form>
- <?php
- require_once "trailer.inc";
- exit;
+ $search_str = '';
}
-
-if (!isset($search_str) || ($search_str == ''))
+
+if (!$ajax)
{
- echo "<p class=\"error\">" . get_vocab("invalid_search") . "</p>";
- require_once "trailer.inc";
- exit;
-}
+ print_header($day, $month, $year, $area, isset($room) ? $room : "");
-// now is used so that we only display entries newer than the current time
-echo "<h3>" . get_vocab("search_results") . ": \"<span
id=\"search_str\">$search_html</span>\"</h3>\n";
+ if (!empty($advanced))
+ {
+ ?>
+ <form class="form_general" id="search_form" method="get"
action="search.php">
+ <fieldset>
+ <legend><?php echo get_vocab("advanced_search") ?></legend>
+ <div id="div_search_str">
+ <label for="search_str"><?php echo get_vocab("search_for")
?>:</label>
+ <input type="text" id="search_str" name="search_str">
+ </div>
+ <div id="div_search_from">
+ <?php
+ echo "<label for=\"from_datepicker\">" . get_vocab("from") .
":</label>\n";
+ genDateSelector ("from_", $day, $month, $year);
+ ?>
+ </div>
+ <div id="search_submit">
+ <input class="submit" type="submit" value="<?php echo
get_vocab("search_button") ?>">
+ </div>
+ </fieldset>
+ </form>
+ <?php
+ require_once "trailer.inc";
+ exit;
+ }
+ if (!isset($search_str) || ($search_str == ''))
+ {
+ echo "<p class=\"error\">" . get_vocab("invalid_search") . "</p>";
+ require_once "trailer.inc";
+ exit;
+ }
+
+ // now is used so that we only display entries newer than the current time
+ echo "<h3>";
+ echo get_vocab("search_results") . ": ";
+ echo "\"<span id=\"search_str\">" . htmlspecialchars($search_str) .
"</span>\"";
+ echo "</h3>\n";
+} // if (!$ajax)
+
+
$now = mktime(0, 0, 0, $month, $day, $year);
// This is the main part of the query predicate, used in both queries:
@@ -153,7 +269,7 @@
trigger_error(sql_error(), E_USER_WARNING);
fatal_error(FALSE, get_vocab("fatal_db_error"));
}
-if ($total <= 0)
+if (($total <= 0) && !$ajax)
{
echo "<p id=\"nothing_found\">" . get_vocab("nothing_found") . "</p>\n";
require_once "trailer.inc";
@@ -169,13 +285,18 @@
$search_pos = $total - ($total % $search["count"]);
}
-// Now we set up the "real" query using LIMIT to just get the stuff we want.
+// Now we set up the "real" query
$sql = "SELECT E.id AS entry_id, E.create_by, E.name, E.description,
E.start_time,
R.area_id, A.enable_periods
FROM $tbl_entry E, $tbl_room R, $tbl_area A
WHERE $sql_pred
- ORDER BY E.start_time asc "
- . sql_syntax_limit($search["count"], $search_pos);
+ ORDER BY E.start_time asc";
+// If it's an Ajax query we want everything. Otherwise we use LIMIT to just
get
+// the stuff we want.
+if (!$ajax)
+{
+ $sql .= " " . sql_syntax_limit($search["count"], $search_pos);
+}
// this is a flag to tell us not to display a "Next" link
@@ -187,85 +308,46 @@
}
$num_records = sql_count($result);
-$has_prev = $search_pos > 0;
-$has_next = $search_pos < ($total-$search["count"]);
+if (!$ajax_capable)
+{
+ echo generate_search_nav_html($search_pos, $total, $num_records,
$search_str);
+}
-if ($has_prev || $has_next)
+if (!$ajax)
{
- echo "<div id=\"record_numbers\">\n";
- echo get_vocab("records") . ($search_pos+1) . get_vocab("through") .
($search_pos+$num_records) . get_vocab("of") . $total;
- echo "</div>\n";
-
- echo "<div id=\"record_nav\">\n";
- $base_query_string =
"search_str=$search_url&total=$total&from_year=$year&from_month=$month&from_day=$day";
- // display a "Previous" button if necessary
- if($has_prev)
- {
- $query_string = $base_query_string . "&search_pos=" . max(0,
$search_pos-$search["count"]);
- echo "<a href=\"search.php?$query_string\">";
- }
+ echo "<div id=\"search_output\" class=\"datatable_container\">\n";
+ echo "<table id=\"search_results\" class=\"admin_table display\">\n";
+ echo "<thead>\n";
+ echo "<tr>\n";
+ echo "<th>" . get_vocab("namebooker") . "</th>\n";
+ echo "<th>" . get_vocab("createdby") . "</th>\n";
+ echo "<th>" . get_vocab("start_date") . "</th>\n";
+ echo "<th>" . get_vocab("description") . "</th>\n";
+ echo "</tr>\n";
+ echo "</thead>\n";
+ echo "<tbody>\n";
+}
- echo get_vocab("previous");
-
- if ($has_prev)
+// If we're Ajax capable and this is not an Ajax request then don't ouput
+// the table body, because that's going to be sent later in response to
+// an Ajax request
+if (!$ajax_capable || $ajax)
+{
+ for ($i = 0; ($row = sql_row_keyed($result, $i)); $i++)
{
- echo "</a>";
+ output_row($row);
}
-
- // print a separator for Next and Previous
- echo(" | ");
-
- // display a "Previous" button if necessary
- if ($has_next)
- {
- $query_string = $base_query_string . "&search_pos=" . max(0,
$search_pos+$search["count"]);
- echo "<a href=\"search.php?$query_string\">";
- }
-
- echo get_vocab("next");
-
- if ($has_next)
- {
- echo "</a>";
- }
- echo "</div>\n";
}
-?>
- <table id="search_results">
- <thead>
- <tr>
- <th><?php echo get_vocab("namebooker") ?></th>
- <th><?php echo get_vocab("createdby") ?></th>
- <th><?php echo get_vocab("start_date") ?></th>
- <th><?php echo get_vocab("description") ?></th>
-
- </tr>
- </thead>
-
- <tbody>
-<?php
-for ($i = 0; ($row = sql_row_keyed($result, $i)); $i++)
+if ($ajax)
{
- echo "<tr>\n";
- echo "<td><a href=\"view_entry.php?id=".$row['entry_id']."\">" .
htmlspecialchars($row['name']) . "</a></td>\n";
- echo "<td>" . htmlspecialchars($row['create_by']) . "</td>\n";
- // generate a link to the day.php
- $link = getdate($row['start_time']);
- echo "<td><a
href=\"day.php?day=$link[mday]&month=$link[mon]&year=$link[year]&area=".$row['area_id']."\">";
- if(empty($row['enable_periods']))
- {
- $link_str = time_date_string($row['start_time']);
- }
- else
- {
- list(,$link_str) = period_date_string($row['start_time']);
- }
- echo "$link_str</a></td>";
- echo "<td>" . htmlspecialchars($row['description']) . "</td>\n";
- echo "</tr>\n";
+ echo json_encode($json_data);
}
-echo "</tbody>\n";
-echo "</table>\n";
-require_once "trailer.inc";
+else
+{
+ echo "</tbody>\n";
+ echo "</table>\n";
+ echo "</div>\n";
+ require_once "trailer.inc";
+}
?>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits