Skip to content

Commit

Permalink
Fix database field from 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 28, 2021
1 parent a52eb22 commit 005dc8e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
16 changes: 6 additions & 10 deletions public/main/inc/ajax/model.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ function getWhereClause($col, $oper, $val)
'nc' => 'NOT LIKE', //doesn't contain
];

$col = Database::escapeField($col);

if (empty($col)) {
return '';
}
Expand Down Expand Up @@ -1442,8 +1444,9 @@ function getWhereClause($col, $oper, $val)
}

$whereCondition = " AND $whereCondition ";
$columnOrderValidList = array_merge(['firstname', 'lastname'], $columns);
$sidx = in_array($sidx, $columnOrderValidList) ? $sidx : 'title';

$sidx = in_array($sidx, $columns) ? $sidx : 'title';
$result = get_work_user_list(
$start,
$limit,
Expand Down Expand Up @@ -2505,18 +2508,11 @@ function getWhereClause($col, $oper, $val)
}
$result = $obj->getUserGroupNotInCourse(
$options,
$groupFilter,
false,
true
$groupFilter
);
break;
case 'registered':
$result = $obj->getUserGroupInCourse(
$options,
$groupFilter,
false,
true
);
$result = $obj->getUserGroupInCourse($options, $groupFilter);
break;
}

Expand Down
5 changes: 5 additions & 0 deletions public/main/inc/lib/database.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,9 @@ public static function listTableColumns($table)
{
return self::getManager()->getConnection()->getSchemaManager()->listTableColumns($table);
}

public static function escapeField($field)
{
return self::escape_string(preg_replace("/[^a-zA-Z0-9_]/", '', $field));
}
}
18 changes: 11 additions & 7 deletions public/main/inc/lib/extra_field.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ public function set_extra_fields_in_form(
if ($freezeElement) {
$form->freeze('extra_'.$variable);
}
break;
break;
case self::FIELD_TYPE_FILE:
$fieldVariable = "extra_{$variable}";
$fieldTexts = [
Expand Down Expand Up @@ -2608,6 +2608,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
}
} else {
// Extra fields
$ruleField = Database::escapeField($rule->field);
if (false === strpos($rule->field, '_second')) {
//No _second
$original_field = str_replace($stringToSearch, '', $rule->field);
Expand All @@ -2630,7 +2631,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
$conditionArray[] = ' ('
.$this->get_where_clause($rule->field, $rule->op, $rule->data)
.') ';
$extraFields[] = ['field' => $rule->field, 'id' => $field_option['id']];
$extraFields[] = ['field' => $ruleField, 'id' => $field_option['id']];
}
break;
case self::FIELD_TYPE_TAG:
Expand All @@ -2639,10 +2640,11 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
break;
}

// Where will be injected in the parseConditions()
//$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR');
//$conditionArray[] = " ( $where ) ";
$extraFields[] = [
'field' => $rule->field,
'field' => $ruleField,
'id' => $field_option['id'],
'data' => $rule->data,
];
Expand All @@ -2656,7 +2658,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR');
$conditionArray[] = " ( $where ) ";
$extraFields[] = [
'field' => $rule->field,
'field' => $ruleField,
'id' => $field_option['id'],
'data' => $rule->data,
];
Expand All @@ -2668,7 +2670,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
$original_field = str_replace($stringToSearch, '', $my_field);
$field_option = $this->get_handler_field_info_by_field_variable($original_field);
$extraFields[] = [
'field' => $rule->field,
'field' => $ruleField,
'id' => $field_option['id'],
];
}
Expand All @@ -2689,6 +2691,8 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit
*/
public function get_where_clause($col, $oper, $val, $conditionBetweenOptions = 'OR')
{
$col = Database::escapeField($col);

if (empty($col)) {
return '';
}
Expand Down Expand Up @@ -2755,7 +2759,7 @@ public function parseConditions($options, $alias = 's')
$inject_extra_fields .= " fvo$counter.display_text as {$extra['field']}, ";
break;
case self::FIELD_TYPE_TAG:
//$inject_extra_fields .= " tag$counter.tag as {$extra['field']}, ";
// If using OR
// If using AND
$newCounter = 1;
$fields = [];
Expand Down Expand Up @@ -3201,7 +3205,7 @@ private function addSelectElement(FormValidator $form, array $fieldDetails, $def
);

if (empty($defaultValueId)) {
$slct->addOption(get_lang('Please select an option'), '');
$slct->addOption(get_lang('Please select an option'));
}

foreach ($options as $value => $text) {
Expand Down

0 comments on commit 005dc8e

Please sign in to comment.