]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-5958, code for advanced search for db module from Elijah (HSU)
authortoyomoyo <toyomoyo>
Mon, 26 Feb 2007 06:56:05 +0000 (06:56 +0000)
committertoyomoyo <toyomoyo>
Mon, 26 Feb 2007 06:56:05 +0000 (06:56 +0000)
22 files changed:
lang/en_utf8/data.php
mod/data/db/access.php
mod/data/db/install.xml
mod/data/db/upgrade.php
mod/data/field/checkbox/field.class.php
mod/data/field/date/field.class.php
mod/data/field/file/field.class.php
mod/data/field/latlong/field.class.php
mod/data/field/menu/field.class.php
mod/data/field/multimenu/field.class.php
mod/data/field/number/field.class.php
mod/data/field/picture/field.class.php
mod/data/field/radiobutton/field.class.php
mod/data/field/text/field.class.php
mod/data/field/textarea/field.class.php
mod/data/field/url/field.class.php
mod/data/lib.php
mod/data/tabs.php
mod/data/templates.php
mod/data/version.php
mod/data/view.php
theme/standard/styles_layout.css

index 18f558a4a51708bd5eb9730c3aef6a492ca7cc59..bad779e32cabfa5fa8d592bf4002b0047e7c67fa 100644 (file)
@@ -7,12 +7,14 @@ $string['add'] = 'Add entry';
 $string['addafield'] = 'Add a field';
 $string['addcomment'] = 'Add comment';
 $string['addentries'] = 'Add entries';
+$string['advancedsearch'] = 'Advanced Search';
 $string['addtemplate'] = 'Add template';
 $string['allowcomments'] = 'Allow comments?';
 $string['allowratings'] = 'Allow posts to be rated?';
 $string['alttext'] = 'Alternative text';
 $string['approve'] = 'Approve';
 $string['ascending'] = 'Ascending';
+$string['asearchtemplate'] = 'Advanced Search Template';
 $string['atmaxentry'] = 'You have entered the maximum number of entries allowed!';
 $string['autogenallforms'] = 'Generate all default templates';
 $string['autolinkurl'] = 'Autolink the URL';
@@ -102,6 +104,7 @@ $string['forcelinkname'] = 'Forced name for the link';
 $string['fromfile'] = 'Import from zip file';
 $string['header'] = 'Header';
 $string['headeraddtemplate'] = 'Defines the interface when editing entries';
+$string['headerasearchtemplate'] = 'Defines the interface for Advanced Searches';
 $string['headercsstemplate'] = 'Defines local CSS styles for the other templates';
 $string['headerjstemplate'] = 'Defines custom Javascript for the other templates';
 $string['headerlisttemplate'] = 'Defines browsing interface for multiple entries';
@@ -187,6 +190,7 @@ $string['requireapproval'] = 'Require approval?';
 $string['requiredentries'] = 'Required entries';
 $string['requiredentriestoview'] = 'Entries required before viewing';
 $string['resettemplate'] = 'Reset template';
+$string['resetsettings'] = 'Reset Fields';
 $string['resizingimages'] = 'Resizing image thumbnails...';
 $string['rows'] = 'rows';
 $string['rssglobaldisabled'] = 'Disabled. See site configuration variables.';
index 341f0dae173a985de22528170cf29791519b38ee..29ba9fc2fc2a9073fc8daa7a21f1992db271d7c1 100644 (file)
@@ -42,6 +42,7 @@ $mod_data_capabilities = array(
             'student' => CAP_ALLOW,
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -56,6 +57,7 @@ $mod_data_capabilities = array(
             'student' => CAP_ALLOW,
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -70,6 +72,7 @@ $mod_data_capabilities = array(
             'student' => CAP_ALLOW,
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -81,6 +84,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -92,6 +96,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -103,6 +108,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -116,6 +122,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -129,6 +136,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -142,6 +150,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
@@ -153,6 +162,7 @@ $mod_data_capabilities = array(
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
     ),
index d71f92eafd4c9d117dd5af5c8b9a4627b28d17c9..02e428a9945632ed1a5d49a4669b1ec04f6ef944 100644 (file)
@@ -27,8 +27,9 @@
         <FIELD NAME="rsstemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="addtemplate" NEXT="rsstitletemplate"/>
         <FIELD NAME="rsstitletemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="rsstemplate" NEXT="csstemplate"/>
         <FIELD NAME="csstemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="rsstitletemplate" NEXT="jstemplate"/>
-        <FIELD NAME="jstemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="csstemplate" NEXT="approval"/>
-        <FIELD NAME="approval" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="jstemplate" NEXT="scale"/>
+        <FIELD NAME="jstemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="csstemplate" NEXT="asearchtemplate"/>
+        <FIELD NAME="asearchtemplate" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="jstemplate" NEXT="approval"/>
+        <FIELD NAME="approval" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="asearchtemplate" NEXT="scale"/>
         <FIELD NAME="scale" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="approval" NEXT="assessed"/>
         <FIELD NAME="assessed" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="scale" NEXT="defaultsort"/>
         <FIELD NAME="defaultsort" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="assessed" NEXT="defaultsortdir"/>
index 94c9754c9f44de3d4eed181a0d911d27f8e6fb5c..f6b5aaa89153057cb063f60e33df3abc0208bcd5 100644 (file)
@@ -43,6 +43,16 @@ function xmldb_data_upgrade($oldversion=0) {
         $result = $result && add_field($table, $field);
 
     }
+    
+    if ($result && $oldversion < 2007022600) {
+    /// Define field asearchtemplate to be added to data
+        $table = new XMLDBTable('data');
+        $field = new XMLDBField('asearchtemplate');
+        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
+
+    /// Launch add field asearchtemplate
+        $result = $result && add_field($table, $field);
+    }
 
     return $result;
 }
index 61afa0dc752631c5423c7a2bfe0050d076eaa307..6574c3f417e9d4dce3bc977adcf62bba117d4aeb 100755 (executable)
@@ -65,6 +65,27 @@ class data_field_checkbox extends data_field_base {
         return $str;
     }
 
+    function display_search_field($value='') {
+        global $CFG;
+        $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $options = array();
+        if(!empty($temp)) {
+            $options[''] = '';              //Make first index blank.
+            foreach ($temp as $key) {
+                $options[$key] = $key;  //Build following indicies from the sql.
+            }
+        }
+        return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true); 
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
+
     function update_content($recordid, $value, $name='') {
         $content = new object();
         $content->fieldid = $this->field->id;
index 9717faec04149425d2628e4ab9fa4a662ac4b65c..bc35d4aea25491b9db734a42d18819853dcbfa42 100755 (executable)
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
+//2/19/07:  Advanced search of the date field is currently disabled because it does not track
+// pre 1970 dates and does not handle blank entrys.  Advanced search functionality for this field
+// type can be enabled once these issues are addressed in the core API.
+
 class data_field_date extends data_field_base {
 
     var $type = 'date';
@@ -49,6 +53,32 @@ class data_field_date extends data_field_base {
 
         return $str;
     }
+    
+    //Enable the following three functions once core API issues have been addressed.
+    function display_search_field($value=0) {
+        return false;
+        //return print_date_selector('f_'.$this->field->id.'_d', 'f_'.$this->field->id.'_m', 'f_'.$this->field->id.'_y', $value, true);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return ' 1=1 ';
+        //return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
+    
+    function parse_search_field() {
+        return '';
+       /* 
+        $day   = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT);
+        $month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT);
+        $year  = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT);
+        if (!empty($day) && !empty($month) && !empty($year)) {
+            return make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
+        }
+        else {
+            return 0;
+        }
+        */
+    }
 
     function update_content($recordid, $value, $name='') {
 
index 0376a3f804c1034fd24d44f4e82545077073629b..37bb83065c08a534af5fb735e4fa23b7147b5682 100755 (executable)
@@ -80,6 +80,19 @@ class data_field_file extends data_field_base {
         return $str;
     }
 
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+    }
+    
+
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+
     function display_browse_field($recordid, $template) {
 
         global $CFG;
index 8e9d14af7d440db4654c49cdf6be3c1a47cc7ae3..b9e4e9d988e6323d101a631fd012ad52dbe0b408 100755 (executable)
@@ -63,7 +63,7 @@ class data_field_latlong extends data_field_base {
                 $long = $content->content1;
             }
         }
-
+        
         $str = '<div title="'.s($this->field->description).'">';
         $str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
         $str .= '<table><tr><td align="right">';
@@ -75,6 +75,31 @@ class data_field_latlong extends data_field_base {
 
         return $str;
     }
+    
+    function display_search_field($value = '') {
+        global $CFG;
+        $lats = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $longs = get_records_sql_menu('SELECT id, content1 from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $options = array();
+        if(!empty($lats) && !empty($longs)) {
+            $options[''] = '';              //Make first index blank.
+            foreach($lats as $key => $temp) {
+                $options[$temp.','.$longs[$key]] = $temp.','.$longs[$key];
+            }
+        }
+       return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        $latlong[0] = '';
+        $latlong[1] = '';
+        $latlong = explode (',', $value, 2);
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$latlong[0]' AND {$tablealias}.content1 = '$latlong[1]') "; 
+    }
 
     function display_browse_field($recordid, $template) {
         global $CFG;
index ca260223906d24deaeaeb617ef003d9e48f7c303..9526519273283652f16ed528973fecdb86a33bcf 100755 (executable)
@@ -56,6 +56,27 @@ class data_field_menu extends data_field_base {
 
         return $str;
     }
+    
+    function display_search_field($value = '') {
+        global $CFG;
+        $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $options = array();
+        if(!empty($temp)) {
+            $options[''] = '';              //Make first index blank.
+            foreach ($temp as $key) {
+                $options[$key] = $key;  //Build following indicies from the sql.
+            }
+        }
+        return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);    
+    }
+
+     function parse_search_field() {
+            return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+     }
+
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
 
 }
 
index 28707e0b149f3a4b0e1dd82bee4a37801029ceea..ec37adb8e54675f82234d0f65fc9f6c426bd0a86 100755 (executable)
@@ -60,6 +60,27 @@ class data_field_multimenu extends data_field_base {
 
         return $str;
     }
+    
+    function display_search_field($value = '') {
+        global $CFG;
+        $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $options = array();
+        if(!empty($temp)) {
+            $options[''] = '';              //Make first index blank.
+            foreach ($temp as $key) {
+                $options[$key] = $key;  //Build following indicies from the sql.
+            }
+        }
+        return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '',  0, true);
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
 
     function update_content($recordid, $value, $name='') {
         $content = new object;
index 3bb34649b682757bbc20830ac17f0a516578f9fd..073a091ad6b68579af3e487d8d69da941eb4b493 100755 (executable)
@@ -43,7 +43,20 @@ class data_field_number extends data_field_base {
             return insert_record('data_content', $content);
         }
     }
+    
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
 
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    // need to cast?
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
+    
     function get_sort_sql($fieldname) {
         global $CFG;
 
index 46038811655ba86debac1ec3305abf2616cdd55b..39cff6a01681b1812da411f086d95d37757acf99 100755 (executable)
@@ -72,6 +72,18 @@ class data_field_picture extends data_field_file {
         return $str;
     }
 
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
+
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+    }
+
     function display_browse_field($recordid, $template) {
         global $CFG;
 
index 9b40e9cff1fbef61fad0cefa63a24cf83d7e55ce..0ed463184f10a6d712a21dff46ed79a159211a05 100755 (executable)
@@ -66,6 +66,27 @@ class data_field_radiobutton extends data_field_base {
         $str .= '</div>';
         return $str;
     }
+    
+     function display_search_field($value = '') {
+        global $CFG;
+        $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+        $options = array();
+        if(!empty($temp)) {
+            $options[''] = '';              //Make first index blank.
+            foreach ($temp as $key) {
+                $options[$key] = $key;  //Build following indicies from the sql.
+            }
+        }
+        return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
+    }
+
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; 
+    }
 
 }
 ?>
index e613f764a3b81519af77b89f7ffa766017d7eeb5..ba13558a5f514049b3ff509c525392eff6b9d064 100755 (executable)
@@ -29,6 +29,19 @@ class data_field_text extends data_field_base {
     function data_field_text($field=0, $data=0) {
         parent::data_field_base($field, $data);
     }
+    
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+    }
+    
 }
 
 ?>
index 44ebf79798086b98e4563eb9a95e1d2845a4dd37..92183f06a767f3e0c2e13fbfa213c840c461feb8 100755 (executable)
@@ -68,8 +68,20 @@ class data_field_textarea extends data_field_base {
         $str .= '</div>';
         return $str;
     }
-
-
+    
+    
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+    }
+    
     function gen_textarea($usehtmleditor, $text='') {
         return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2,
                               '', '', 'field_'.$this->field->id, $text, '', true, 'field_' . $this->field->id);
index 124d9e3c0dcb5c406fd8ff06dc2f4f28c71220d1..23c9138b4d62ed7261e91c4ef821634776d745af 100755 (executable)
@@ -58,6 +58,18 @@ class data_field_url extends data_field_base {
         return $str;
     }
 
+    function display_search_field($value = '') {
+        return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';   
+    }
+    
+    function parse_search_field() {
+        return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
+    }
+    
+    function generate_sql($tablealias, $value) {
+        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+    }
+
     function display_browse_field($recordid, $template) {
         if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
             $url = empty($content->content)? '':$content->content;
index 8ed6196a34eee65808b4057625a7452c1e0e23a2..ecfe84eec22189f7f67e5775083945de19e47df1 100755 (executable)
@@ -904,42 +904,44 @@ function data_print_template($template, $records, $data, $search='',$page=0, $re
 }
 
 
-function data_print_show_all_form($data, $perpage, $sort, $order, $mode) {
-    echo '<div align="center">';
-    echo '<form id="options" action="view.php" method="get">';
-    echo '<fieldset class="invisiblefieldset">';
-    echo '<input type="hidden" name="d" value="'.$data->id.'" />';
-    echo '<input type="hidden" name="perpage" value="'.$perpage.'" />';
-    echo '<input type="hidden" name="search" value="" />'; // clear search
-    echo '<input type="hidden" name="sort" value="'.$sort.'" />';
-    echo '<input type="hidden" name="order" value="'.$order.'" />';    
-    echo '<input type="hidden" name="mode" value="'.$mode.'" />';   
-    echo '<input type="submit" value="'.get_string('showall','data').'" />';
-
-    echo '</fieldset>';
-    echo '</form>';
-    echo '</div>';      
-}
-
-
 /************************************************************************
  * function that takes in the current data, number of items per page,   *
  * a search string and prints a preference box in view.php              *
+ *                                                                      *
+ * This preference box prints a searchable advanced search template if  *
+ *     a) A template is defined                                                                                        *
+ *  b) The advanced search checkbox is checked.                                                        *
+ *                                                                                                                                             *
  * input @param object $data                                            *
  *       @param int $perpage                                            *
  *       @param string $search                                          *
  * output null                                                          *
  ************************************************************************/
-function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC', $mode='single'){
-    echo '<br /><div class="datapreferences" style="text-align:center">';
+function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC', $search_array = '', $advanced = 0, $mode= ''){
+    global $CFG;
+    
+    $cm = get_coursemodule_from_instance('data', $data->id);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    echo '<br /><div class="datapreferences">';
     echo '<form id="options" action="view.php" method="get">';
-    echo '<fieldset class="invisiblefieldset">';
+    echo '<div>';
     echo '<input type="hidden" name="d" value="'.$data->id.'" />';
+    if ($mode =='asearch') {
+        $advanced = 1;
+        echo '<input type="hidden" name="mode" value="list" />';
+    }
     echo '<label for="pref_perpage">'.get_string('pagesize','data').'</label> ';
     $pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,
                        20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
     choose_from_menu($pagesizes, 'perpage', $perpage, '', '', '0', false, false, 0, 'pref_perpage');
-    echo '&nbsp;&nbsp;&nbsp;<label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" />';
+     echo '<div id="reg_search" style="display: ';
+    if ($advanced) {
+        echo 'none';
+    }
+    else {
+        echo 'inline';
+    }
+    echo ';" >&nbsp;&nbsp;&nbsp;<label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
     echo '&nbsp;&nbsp;&nbsp;<label for="pref_sortby">'.get_string('sortby').'</label> ';
     //foreach field, print the option
     $fields = get_records('data_fields','dataid',$data->id, 'name');
@@ -965,13 +967,120 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
         echo '<option value="DESC">'.get_string('descending','data').'</option>';
     }
     echo '</select>';
-    //print ASC or DESC
-    echo '&nbsp;&nbsp;&nbsp;';
-    echo '<input type="hidden" name="mode" value="'.$mode.'" />';  
-    echo '<input type="submit" value="'.get_string('savesettings','data').'" />';
-    echo '</fieldset>';
-    echo '</form>';
+    
+    if ($advanced) {
+        $checked = ' checked="checked" ';
+    }
+    else {
+        $checked = '';
+    }
+    print '
+        
+        <script type="text/javascript">
+        //<![CDATA[
+        <!-- Start
+        // javascript for hiding/displaying advanced search form
+
+        function showHideAdvSearch(checked) {
+            var divs = document.getElementsByTagName(\'div\');
+            for(i=0;i<divs.length;i++) {
+                if(divs[i].id.match(\'data_adv_form\')) {
+                    if(checked) {
+                        divs[i].style.display = \'inline\';
+                    }
+                    else {
+                        divs[i].style.display = \'none\';
+                    }
+                }
+                else if (divs[i].id.match(\'reg_search\')) {
+                    if (!checked) {
+                        divs[i].style.display = \'inline\';
+                    }
+                    else {
+                        divs[i].style.display = \'none\';
+                    }
+                }
+            }
+        }
+        //  End -->
+        //]]>
+        </script>';
+        
+    echo '&nbsp;<input type="checkbox" name="advanced" value="1" '.$checked.' onchange="showHideAdvSearch(this.checked);" />'.get_string('advancedsearch', 'data');
+    echo '&nbsp;<input type="submit" value="'.get_string('savesettings','data').'" />';
+    
+    echo '<br />';
+    echo '<div class="dataadvancedsearch" id="data_adv_form" style="display: ;margin-left:auto;margin-right:auto';
+    if ($advanced) {
+        echo 'inline';
+    }
+    else {
+        echo 'none';
+    }
+    echo ';" >';
+
+    echo '<table class="boxaligncenter">';
+    
+    // print ASC or DESC
+    echo '<tr><td colspan="2">&nbsp;</td></tr>';
+    $i = 0;
+
+    // Determine if we are printing all fields for advanced search, or the template for advanced search
+    // If a template is not defined, use the deafault template and display all fields.
+    if(empty($data->asearchtemplate)) {
+        data_generate_default_template($data, 'asearchtemplate');
+    }
+
+    static $fields = NULL;
+    static $isteacher;
+    static $dataid = NULL;
+
+    if (empty($dataid)) {
+        $dataid = $data->id;
+    } else if ($dataid != $data->id) {
+        $fields = NULL;
+    }
+
+    if (empty($fields)) {
+        $fieldrecords = get_records('data_fields','dataid', $data->id);
+        foreach ($fieldrecords as $fieldrecord) {
+            $fields[]= data_get_field($fieldrecord, $data);
+        }
+
+        $isteacher = has_capability('mod/data:managetemplates', $context);
+    }
+
+    /// Replacing tags
+    $patterns = array();
+    $replacement = array();
+
+    /// Then we generate strings to replace for normal tags
+    foreach ($fields as $field) {
+        $patterns[]='/\[\['.$field->field->name.'\]\]/i';
+        $searchfield = data_get_field_from_id($field->field->id, $data); 
+        if (!empty($search_array[$field->field->id]->data)) {
+            $replacement[] = $searchfield->display_search_field($search_array[$field->field->id]->data);
+        } else {
+            $replacement[] = $searchfield->display_search_field();
+        }
+    }
+    
+    ///actual replacement of the tags
+    $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);
+    $options->para=false;
+    $options->noclean=true;
+    echo '<tr><td>';
+    echo format_text($newtext, FORMAT_HTML, $options);
+    echo '</td></tr>';
+
+    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="'.get_string('savesettings','data').'" /><input type="reset" value="'.get_string('resetsettings','data').'" /></td></tr>';
+    echo '</table>';
     echo '</div>';
+    echo '</div>';
+    echo '</form>';
+    echo '</div>'; 
+
+    
 }
 
 function data_print_ratings($data, $record) {
@@ -980,8 +1089,7 @@ function data_print_ratings($data, $record) {
     $cm = get_coursemodule_from_instance('data', $data->id);
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    if ($data->assessed and !empty($USER->id)
-      and (has_capability('mod/data:rate', $context) or has_capability('mod/data:viewrating', $context) or data_isowner($record->id))) {
+    if ($data->assessed and !empty($USER->id) and (has_capability('mod/data:rate', $context) or has_capability('mod/data:viewrating', $context) or data_isowner($record->id))) {
         if ($ratingsscale = make_grades_menu($data->scale)) {
             $ratingsmenuused = false;
 
index 037abeabb41d3c9628dd2beb3bc33418e96a95fe..a3f9071cf8ab01817479fbff1fa8e7486910fbeb 100755 (executable)
     $row = array();
 
     $row[] = new tabobject('list', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id, get_string('list','data'), '', true);
-
+    
+    //Add an advanced search tab.
+    $row[] = new tabobject('asearch', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;mode=asearch', get_string('advancedsearch', 'data'), '', true);
+    
     if (isset($record)) {
         $row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$record->id, get_string('single','data'), '', true);
     } else {
@@ -52,6 +55,8 @@
                 $defaultemplate = 'listtemplate';
             } else if ($currenttab == 'add') {
                 $defaultemplate = 'addtemplate';
+                       } else if ($currenttab == 'asearch') {
+                               $defaultemplate = 'asearchtemplate';
             } else {
                 $defaultemplate = 'singletemplate';
             }
@@ -70,8 +75,9 @@
     * stolen code from quiz report
     *****************************/
     if ($currenttab == 'templates' and isset($mode)) {
+
         $inactive[] = 'templates';
-        $templatelist = array ('listtemplate', 'singletemplate', 'addtemplate', 'rsstemplate', 'csstemplate', 'jstemplate');
+        $templatelist = array ('listtemplate', 'asearchtemplate' , 'singletemplate', 'addtemplate', 'rsstemplate', 'csstemplate', 'jstemplate');
 
         $row  = array();
         $currenttab ='';
             }
         }
         $tabs[] = $row;
+        $activetwo = array('templates');
+    } else {
+        $activetwo = array();
     }
 
-
 /// Print out the tabs and continue!
 
-    print_tabs($tabs, $currenttab, $inactive);
+    print_tabs($tabs, $currenttab, $inactive, $activetwo);
 
 ?>
index e6f09dde17f4816633017f225a4e43e83f42e782..fc78f0d9d65c9f782581e23940295d4837af7b8f 100755 (executable)
     $currenttab = 'templates';
     include('tabs.php');
 
-
 /// Processing submitted data, i.e updating form.
     $resettemplate = false;
 
         data_generate_default_template($data, 'singletemplate');
         data_generate_default_template($data, 'listtemplate');
         data_generate_default_template($data, 'addtemplate');
+        data_generate_default_template($data, 'asearchtemplate');           //Template for advanced searches.
         data_generate_default_template($data, 'rsstemplate');
     }
 
 
     echo '<form id="tempform" action="templates.php?d='.$data->id.'&amp;mode='.$mode.'" method="post">';
-    echo '<fieldset class="invisiblefieldset">';
+    echo '<div>';
     echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
     // Print button to autogen all forms, if all templates are empty
 
         }
 
         // Print special tags. fix for MDL-7031
-        if ($mode != 'addtemplate') {
+        if ($mode != 'addtemplate' && $mode != 'asearchtemplate') {             //Don't print special tags when viewing the advanced search template and add template.
             echo '<optgroup label="'.get_string('buttons', 'data').'">';
             echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>';
             echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>';
 
 
     print_simple_box_end();
-    echo '</fieldset>';
+    echo '</div>';
     echo '</form>';
     if ($usehtmleditor) {
         use_html_editor('template');
index 966e4ed0a281922ef3134fcdca9dde880ea2cdc9..edbb95be03987461a65b04794829719aef826577 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2007020200;
+$module->version  = 2007022600;
 $module->requires = 2007020200;  // Requires this Moodle version
 $module->cron     = 60;
 
index 46037815f67d985243e1cdb2dfb46e5306b6d674..69e95ecafed2037ef355615639c6b510cd072c70 100755 (executable)
@@ -28,8 +28,8 @@
     require_once("$CFG->libdir/rsslib.php");
 
     require_once('pagelib.php');
-
-
+    
+    
 /// One of these is necessary!
     $id    = optional_param('id', 0, PARAM_INT);  // course module id
     $d     = optional_param('d', 0, PARAM_INT);   // database id
@@ -38,7 +38,7 @@
     $mode  = optional_param('mode', '', PARAM_ALPHA);    // Force the browse mode  ('single')
 
     $edit = optional_param('edit', -1, PARAM_BOOL);
-
+    $page = optional_param('page', 0, PARAM_INT);
 /// These can be added to perform an action on a record
     $approve = optional_param('approve', 0, PARAM_INT);    //approval recordid
     $delete = optional_param('delete', 0, PARAM_INT);    //delete recordid
     if (!isset($SESSION->dataprefs[$data->id])) {
         $SESSION->dataprefs[$data->id] = array();
         $SESSION->dataprefs[$data->id]['search'] = '';
+        $SESSION->dataprefs[$data->id]['search_array'] = array();
         $SESSION->dataprefs[$data->id]['sort'] = $data->defaultsort;
+        $SESSION->dataprefs[$data->id]['advanced'] = 0;
         $SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
     }
-    $search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS);
+    $advanced = optional_param('advanced', $SESSION->dataprefs[$data->id]['advanced'], PARAM_INT);
+    $search_array = $SESSION->dataprefs[$data->id]['search_array'];
+    
+    if (!empty($advanced)) {
+        $search = '';
+        $fields = get_records('data_fields', 'dataid', $data->id);
+        
+        //Added to ammend paging error. This error would occur when attempting to go from one page of advanced
+        //search results to another.  All fields were reset in the page transfer, and there was no way of determining
+        //whether or not the user reset them.  This would cause a blank search to execute whenever the user attempted
+        //to see any page of results past the first.
+        //This fix works as follows:
+        //$paging flag is set to false when page 0 of the advanced search results is viewed for the first time.
+        //Viewing any page of results after page 0 passes the false $paging flag though the URL (see line 523) and the
+        //execution falls through to the second condition below, allowing paging to be set to true.
+        //Paging remains true and keeps getting passed though the URL until a new search is performed
+        //(even if page 0 is revisited).
+        //A false $paging flag generates advanced search results based on the fields input by the user. 
+        //A true $paging flag generates davanced search results from the $SESSION global.
+        //(See lines 147-158)
+        
+        $paging = optional_param('paging', NULL, PARAM_BOOL);
+        if($page == 0 && !isset($paging)) {
+            $paging = false;
+        }
+        else {
+            $paging = true;
+        }
+        if (!empty($fields)) {        
+            foreach($fields as $field) {
+                $searchfield = data_get_field_from_id($field->id, $data);
+                //Get field data to build search sql with.  If paging is false, get from user.
+                //If paging is true, get data from $search_array which is obtained from the $SESSION (see line 116).
+                if(!$paging) {
+                    $val = $searchfield->parse_search_field();
+                }
+                else {
+                    //Set value from session if there is a value @ the required index.
+                    if(isset($search_array[$field->id])) {
+                        $val = $search_array[$field->id]->data;
+                    }
+                    else {             //If there is not an entry @ the required index, set value to blank.
+                        $val = '';
+                    }
+                }    
+                if (!empty($val)) {
+                    $search_array[$field->id] = new stdClass;
+                    $search_array[$field->id]->sql = $searchfield->generate_sql('c'.$field->id, $val);
+                    $search_array[$field->id]->data = $val;             
+                    $search .= ' '.$val;          
+                }
+                else {
+                    if (isset($search_array[$field->id])) {
+                        // clear it out
+                        unset($search_array[$field->id]);
+                    }
+                }
+            }
+        }
+        $SESSION->dataprefs[$data->id]['search_array'] = $search_array;     // Make it sticky
+    }
+    else {
+        $search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS);
+        //Paging variable not used for standard search. Set it to null.
+        $paging = NULL;
+    }
+
     $textlib = new textlib();
     if ($textlib->strlen($search) < 2) {
         $search = '';
         set_user_preference('data_perpage_'.$data->id, $perpage);
     }
 
-    $page = optional_param('page', 0, PARAM_INT);
-
     add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
 
 
 
     if ($record or $mode == 'single') {
         $currenttab = 'single';
-    } else {
+    } elseif($mode == 'asearch') {
+        $currenttab = 'asearch';
+    }
+    else {
         $currenttab = 'list';
     }
     include('tabs.php');
 
+    if ($mode != 'asearch') {
+    /// Approve any requested records
 
-/// Approve any requested records
-
-    if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) {
-        if ($approverecord = get_record('data_records', 'id', $approve)) {   // Need to check this is valid
-            if ($approverecord->dataid == $data->id) {                       // Must be from this database
-                $newrecord->id = $approverecord->id;
-                $newrecord->approved = 1;
-                if (update_record('data_records', $newrecord)) {
-                    notify(get_string('recordapproved','data'), 'notifysuccess');
+        if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) {
+            if ($approverecord = get_record('data_records', 'id', $approve)) {   // Need to check this is valid
+                if ($approverecord->dataid == $data->id) {                       // Must be from this database
+                    $newrecord->id = $approverecord->id;
+                    $newrecord->approved = 1;
+                    if (update_record('data_records', $newrecord)) {
+                        notify(get_string('recordapproved','data'), 'notifysuccess');
+                    }
                 }
             }
         }
-    }
 
-// If not teacher, check whether user has sufficient records to view
-    if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){
-        notify (($data->requiredentriestoview - data_numentries($data)).'&nbsp;'.get_string('insufficiententries','data'));
-        echo '</td></tr></table>';
-        print_footer($course);
-        exit;
-    }
+    // If not teacher, check whether user has sufficient records to view
+        if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){
+            notify (($data->requiredentriestoview - data_numentries($data)).'&nbsp;'.get_string('insufficiententries','data'));
+            echo '</td></tr></table>';
+            print_footer($course);
+            exit;
+        }
 
 
-/// We need to examine the whole dataset to produce the correct paging
+    /// We need to examine the whole dataset to produce the correct paging
 
-    if ((!has_capability('mod/data:managetemplates', $context)) && ($data->approval)) {
-        if (isloggedin()) {
-            $approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
+        if ((!has_capability('mod/data:managetemplates', $context)) && ($data->approval)) {
+            if (isloggedin()) {
+                $approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
+            } else {
+                $approveselect = ' AND r.approved=1 ';
+            }
         } else {
-            $approveselect = ' AND r.approved=1 ';
+            $approveselect = ' ';
         }
-    } else {
-        $approveselect = ' ';
-    }
-
-    if ($currentgroup) {
-        $groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
-    } else {
-        $groupselect = ' ';
-    }
 
-/// Find the field we are sorting on
-    if ($sort and $sortfield = data_get_field_from_id($sort, $data)) {
-
-        $sortcontent = $sortfield->get_sort_field();
-        $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
-
-        $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname, c.'.$sortcontent.' ';
-        $count = ' COUNT(DISTINCT c.recordid) ';
-        $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u ';
-        $where =  'WHERE c.recordid = r.id
-                     AND c.fieldid = '.$sort.'
-                     AND r.dataid = '.$data->id.'
-                     AND r.userid = u.id
-                     AND c1.recordid = r.id ';
-        $sortorder = ' ORDER BY '.$sortcontentfull.' '.$order.' , r.id ASC ';
-        if ($search) {
-            $searchselect = " AND (c1.content LIKE '%$search%') ";
+        if ($currentgroup) {
+            $groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
         } else {
-            $searchselect = ' ';
+            $groupselect = ' ';
         }
 
-    } else if ($search) {
-        $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
-        $count = ' COUNT(DISTINCT c.recordid) ';
-        $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
-        $where =  'WHERE c.recordid = r.id
-                     AND r.userid = u.id
-                     AND r.dataid = '.$data->id;
-        $sortorder = ' ORDER BY r.id ASC ';
-        $searchselect = " AND (c.content LIKE '%$search%') ";
+    /// Find the field we are sorting on
+        if ($sort and $sortfield = data_get_field_from_id($sort, $data)) {
+
+            $sortcontent = $sortfield->get_sort_field();
+            $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
+
+            $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname, c.'.$sortcontent.' ';
+            $count = ' COUNT(DISTINCT c.recordid) ';
+            $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u ';
+            $where =  'WHERE c.recordid = r.id
+                         AND c.fieldid = '.$sort.'
+                         AND r.dataid = '.$data->id.'
+                         AND r.userid = u.id
+                         AND c1.recordid = r.id ';
+            $sortorder = ' ORDER BY '.$sortcontentfull.' '.$order.' , r.id ASC ';
+            $searchselect = '';
+            
+            if (!empty($advanced)) {                                                                                           //If advanced box is checked.
+                foreach($search_array as $key => $val) {                                                       //what does $search_array hold?
+                    $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
+                    $where .= ' AND c'.$key.'.recordid = r.id';
+                    $searchselect .= ' AND ('.$val->sql.') ';
+                }
+            }
+            elseif ($search) {
+                $searchselect = ' AND (dc.content LIKE "%'.$search.'%") ';
+            } else {
+                $searchselect = ' ';
+            } 
+        } else if ($search) {
+            $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
+            $count = ' COUNT(DISTINCT c.recordid) ';
+            $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
+            $where =  'WHERE c.recordid = r.id
+                         AND r.userid = u.id
+                         AND r.dataid = '.$data->id;
+            $sortorder = ' ORDER BY r.id ASC ';
+            $searchselect = '';
+            
+            if (!empty($advanced)) {                                                                                           //Advanced search box again.
+                foreach($search_array as $key => $val) {
+                    $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
+                    $where .= ' AND c'.$key.'.recordid = r.id ';
+                    $searchselect .= ' AND ('.$val->sql.') ';
+                }
+            }
+            else {
+                $searchselect = ' AND (c.content LIKE "%'.$search.'%") ';
+            }
 
-    } else {
-        $what = ' DISTINCT r.id, r.approved, r.timecreated, r.userid, u.firstname, u.lastname ';
-        $count = ' COUNT(r.id) ';
-        $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
-        $where =  'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
-        $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
-        $searchselect = ' ';
-    }
+            
+        } else {
+            $what = ' DISTINCT r.id, r.approved, r.timecreated, r.userid, u.firstname, u.lastname ';
+            $count = ' COUNT(r.id) ';
+            $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
+            $where =  'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
+            $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
+            $searchselect = ' ';
+        }
 
 
-/// To actually fetch the records
+    /// To actually fetch the records
 
-    $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
+        $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
 
-    $sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
+        $sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
 
-    $sqlcount  = 'SELECT '.$count.$fromsql;   // Total number of records
+        $sqlcount  = 'SELECT '.$count.$fromsql;   // Total number of records
 
-/// Work out the paging numbers
+    /// Work out the paging numbers
 
-    $totalcount = count_records_sql($sqlcount);
+        $totalcount = count_records_sql($sqlcount);
 
-    if ($record) {     // We need to just show one, so where is it in context?
-        $nowperpage = 1;
-        $mode = 'single';
+        if ($record) {     // We need to just show one, so where is it in context?
+            $nowperpage = 1;
+            $mode = 'single';
 
-#  Following code needs testing to make it work
-#        if ($sort) {   // We need to search by that field
-#            if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
-#                $content = addslashes($content);
-#                if ($order == 'ASC') {
-#                    $lessthan = " AND $sortcontentfull < '$content'
-#                                   OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
-#                } else {
-#                    $lessthan = " AND $sortcontentfull > '$content'
-#                                   OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
-#                }
-#            } else {   // Failed to find data (shouldn't happen), so fall back to something easy
-#                $lessthan = " r.id < '$record->id' ";
-#            }
-#        } else {
-#            $lessthan = " r.id < '$record->id' ";
-#        }
-#        $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
-#        $page = count_records_sql($sqlindex);
+    #  Following code needs testing to make it work
+    #        if ($sort) {   // We need to search by that field
+    #            if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
+    #                $content = addslashes($content);
+    #                if ($order == 'ASC') {
+    #                    $lessthan = " AND $sortcontentfull < '$content'
+    #                                   OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
+    #                } else {
+    #                    $lessthan = " AND $sortcontentfull > '$content'
+    #                                   OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
+    #                }
+    #            } else {   // Failed to find data (shouldn't happen), so fall back to something easy
+    #                $lessthan = " r.id < '$record->id' ";
+    #            }
+    #        } else {
+    #            $lessthan = " r.id < '$record->id' ";
+    #        }
+    #        $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
+    #        $page = count_records_sql($sqlindex);
 
 
-        $allrecords = get_records_sql($sqlselect);      // Kludgey but accurate at least!
-        $page = 0;
-        foreach ($allrecords as $key => $allrecord) {
-            if ($key == $record->id) {
-                break;
+            $allrecords = get_records_sql($sqlselect);      // Kludgey but accurate at least!          
+            $page = 0;
+            foreach ($allrecords as $key => $allrecord) {
+                if ($key == $record->id) {
+                    break;
+                }
+                $page++;
             }
-            $page++;
-        }
 
-    } else if ($mode == 'single') {  // We rely on ambient $page settings
-        $nowperpage = 1;
+        } else if ($mode == 'single') {  // We rely on ambient $page settings
+            $nowperpage = 1;
 
-    } else {
-        $nowperpage = $perpage;
-    }
-
-/// Get the actual records
+        } else {
+            $nowperpage = $perpage;
+        }
 
-    $records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);
+    /// Get the actual records
+        
+        $records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);
 
-    if (empty($records)) {     // Nothing to show!
-        if ($record) {         // Something was requested so try to show that at least (bug 5132)
-            if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
-                     $record->approved || (isloggedin() && $record->userid == $USER->id)) {
-                if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
-                    $records[] = $record;
+        if (empty($records)) {     // Nothing to show!
+            if ($record) {         // Something was requested so try to show that at least (bug 5132)
+                if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
+                         $record->approved || (isloggedin() && $record->userid == $USER->id)) {
+                    if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
+                        $records[] = $record;
+                    }
                 }
             }
-        }
-        if ($records) {  // OK, we can show this one
-            data_print_template('singletemplate', $records, $data, $search, $page);
-        } else if ($search){
-            notify(get_string('nomatch','data'));
-            data_print_show_all_form($data, $perpage, $sort, $order, $mode);  
-        } else {
-            notify(get_string('norecords','data'));
-        }
+            if ($records) {  // OK, we can show this one
+                data_print_template('singletemplate', $records, $data, $search, $page);
+            } else if ($search){
+                notify(get_string('nomatch','data'));
+            } else {
+                notify(get_string('norecords','data'));
+            }
 
-    } else {                   //  We have some records to print
+        } else {                   //  We have some records to print
 
-        if ($mode == 'single') {                  // Single template
-            $baseurl = 'view.php?d='.$data->id.'&amp;mode=single&amp;';
+            if ($mode == 'single') {                  // Single template
+                $baseurl = 'view.php?d='.$data->id.'&amp;mode=single&amp;';
 
-            print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
+                print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
 
-            if (empty($data->singletemplate)){
-                notify(get_string('nosingletemplate','data'));
-                data_generate_default_template($data, 'singletemplate', 0, false, false);
-            }
+                if (empty($data->singletemplate)){
+                    notify(get_string('nosingletemplate','data'));
+                    data_generate_default_template($data, 'singletemplate', 0, false, false);
+                }
 
-            data_print_template('singletemplate', $records, $data, $search, $page);
+                data_print_template('singletemplate', $records, $data, $search, $page);
 
-            print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
+                print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
 
-        } else {                                  // List template
-            $baseurl = 'view.php?d='.$data->id.'&amp;';
+            } else {                                  // List template
+                $baseurl = 'view.php?d='.$data->id.'&amp;';
+                //send the advanced flag through the URL so it is remembered while paging.
+                $baseurl .= 'advanced='.$advanced.'&amp;';
+                //pass variable to allow determining whether or not we are paging through results.
+                $baseurl .= 'paging='.$paging.'&amp;';
 
-            print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
+                print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
 
-            if (empty($data->listtemplate)){
-                notify(get_string('nolisttemplate','data'));
-                data_generate_default_template($data, 'listtemplate', 0, false, false);
+                if (empty($data->listtemplate)){
+                    notify(get_string('nolisttemplate','data'));
+                    data_generate_default_template($data, 'listtemplate', 0, false, false);
+                }
+                echo $data->listtemplateheader;
+                data_print_template('listtemplate', $records, $data, $search, $page);
+                echo $data->listtemplatefooter;
+
+                print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
             }
-            echo $data->listtemplateheader;
-            data_print_template('listtemplate', $records, $data, $search, $page);
-            echo $data->listtemplatefooter;
 
-            print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
         }
-
+    }
+    
+    $search = trim($search);
+    if (empty($records)) {
+        $records = array();
     }
 
-    if ($records || $search || $page) {
-        data_print_preference_form($data, $perpage, $search, $sort, $order, $mode);
+    //Advanced search form doesn't make sense for single (redirects list view)
+    if ($records || $search || $page ||  $mode = 'asearch'  && $mode != 'single') {
+        data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
     }
 
 /// If we have blocks, then print the left side here
index 7e7f69aba8f1679fffc2f0cdcd3b8b5aebcbd283..6fb43f5a258bedc52202d8fb3081fe1a38995163 100644 (file)
@@ -2490,7 +2490,9 @@ body#user-index .rolesform {
 .defaulttemplate {
   text-align:center;
 }
-
+.datapreferences {
+    text-align:center;
+}
 /***
  *** Modules: Forum
  ***/