$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';
$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';
$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.';
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
+ 'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
<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"/>
$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;
}
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;
// //
///////////////////////////////////////////////////////////////////////////
+//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';
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='') {
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;
$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">';
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;
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') ";
+ }
}
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;
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;
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;
$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') ";
+ }
}
?>
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}%') ";
+ }
+
}
?>
$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);
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;
}
-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 ' <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 ';" > <label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
echo ' <label for="pref_sortby">'.get_string('sortby').'</label> ';
//foreach field, print the option
$fields = get_records('data_fields','dataid',$data->id, 'name');
echo '<option value="DESC">'.get_string('descending','data').'</option>';
}
echo '</select>';
- //print ASC or DESC
- echo ' ';
- 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 ' <input type="checkbox" name="advanced" value="1" '.$checked.' onchange="showHideAdvSearch(this.checked);" />'.get_string('advancedsearch', 'data');
+ echo ' <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"> </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) {
$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;
$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.'&mode=asearch', get_string('advancedsearch', 'data'), '', true);
+
if (isset($record)) {
$row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id, get_string('single','data'), '', true);
} else {
$defaultemplate = 'listtemplate';
} else if ($currenttab == 'add') {
$defaultemplate = 'addtemplate';
+ } else if ($currenttab == 'asearch') {
+ $defaultemplate = 'asearchtemplate';
} else {
$defaultemplate = 'singletemplate';
}
* 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);
?>
$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.'&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');
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2007020200;
+$module->version = 2007022600;
$module->requires = 2007020200; // Requires this Moodle version
$module->cron = 60;
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
$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)).' '.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)).' '.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.'&mode=single&';
+ if ($mode == 'single') { // Single template
+ $baseurl = 'view.php?d='.$data->id.'&mode=single&';
- 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.'&';
+ } else { // List template
+ $baseurl = 'view.php?d='.$data->id.'&';
+ //send the advanced flag through the URL so it is remembered while paging.
+ $baseurl .= 'advanced='.$advanced.'&';
+ //pass variable to allow determining whether or not we are paging through results.
+ $baseurl .= 'paging='.$paging.'&';
- 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
.defaulttemplate {
text-align:center;
}
-
+.datapreferences {
+ text-align:center;
+}
/***
*** Modules: Forum
***/