Permalink
Browse files

MDL-25692 make search template to work for mssql + oracle

  • Loading branch information...
1 parent 3703965 commit 5dd05d5a215c6d0aba62d7da44ed7ad10d5e4762 @stronk7 stronk7 committed Dec 15, 2010
@@ -70,17 +70,19 @@ function display_add_field($recordid=0) {
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');
+ $varcharlat = sql_compare_text('content');
+ $varcharlong= sql_compare_text('content1');
+ $latlongsrs = get_recordset_sql(
+ "SELECT DISTINCT $varcharlat AS la, $varcharlong AS lo
+ FROM {$CFG->prefix}data_content
+ WHERE fieldid = {$this->field->id}
+ ORDER BY $varcharlat, $varcharlong");
$options = array();
- if(!empty($lats) && !empty($longs)) {
- $options[''] = '';
- // Make first index blank.
- foreach($lats as $key => $temp) {
- $options[$temp.','.$longs[$key]] = $temp.','.$longs[$key];
- }
+ while ($latlong = rs_fetch_next_record($latlongsrs)) {
+ $options[$latlong->la . ',' . $latlong->lo] = $latlong->la . ',' . $latlong->lo;
}
- return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
+ rs_close($latlongsrs);
+ return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
}
function parse_search_field() {
@@ -56,14 +56,16 @@ function display_add_field($recordid=0) {
return $str;
}
-
+
function display_search_field($content = '') {
global $CFG;
- $usedoptions = array();
- $sql = "SELECT DISTINCT content
+ $varcharcontent = sql_compare_text('content', 255);
+ $sql = "SELECT DISTINCT $varcharcontent AS content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
+
+ $usedoptions = array();
if ($used = get_records_sql($sql)) {
foreach ($used as $data) {
$value = $data->content;
@@ -87,7 +89,7 @@ function display_search_field($content = '') {
return '';
}
- return choose_from_menu($options, 'f_'.$this->field->id, stripslashes($content), ' ', '', 0, true);
+ return choose_from_menu($options, 'f_'.$this->field->id, stripslashes($content), 'choose', '', 0, true);
}
function parse_search_field() {
@@ -78,10 +78,12 @@ function display_search_field($value = '') {
$str = '<select name="f_'.$this->field->id.'[]" multiple="multiple">';
// display only used options
- $usedoptions = array();
- $sql = "SELECT DISTINCT content
+ $varcharcontent = sql_compare_text('content', 255);
+ $sql = "SELECT DISTINCT $varcharcontent AS content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
+
+ $usedoptions = array();
if ($used = get_records_sql($sql)) {
foreach ($used as $data) {
$valuestr = $data->content;
@@ -66,15 +66,21 @@ function display_add_field($recordid=0) {
$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');
+
+ $varcharcontent = sql_compare_text('content', 255);
+ $used = get_records_sql(
+ "SELECT DISTINCT $varcharcontent AS content
+ FROM {$CFG->prefix}data_content
+ WHERE fieldid={$this->field->id}
+ ORDER BY $varcharcontent");
+
$options = array();
- if(!empty($temp)) {
- $options[''] = ''; //Make first index blank.
- foreach ($temp as $key) {
- $options[$key] = $key; //Build following indicies from the sql.
+ if(!empty($used)) {
+ foreach ($used as $rec) {
+ $options[$rec->content] = $rec->content; //Build following indicies from the sql.
}
}
return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
@@ -83,9 +89,9 @@ function display_search_field($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 = '$value') ";
+ return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') ";
}
}

0 comments on commit 5dd05d5

Please sign in to comment.