sql_use_operators configuration directive. Hope everything works.
* Fixed a bug in sql/change_attrs which did not allow multi valued attributes in sql.
* unset item_vals before adding info in ldap and sql user_info files.
+* Add support for the rest of the operators. Created the lib/operators.php3 file containing helper functions
Ver 1.28:
* Make user_delete.php3 print something when a user is deleted
* Cache nas hostname lookups in user_accounting
if ($config[general_lib_type] == 'sql' && $config[sql_use_operators] == 'true'){
$colspan=2;
$show_ops = 1;
- $op_eq = '=';
- $op_set = ':=';
- $op_add = '+=';
+ include("../lib/operators.php3");
}
else{
$show_ops = 0;
<option $selected[$op_eq] value="=">=
<option $selected[$op_set] value=":=">:=
<option $selected[$op_add] value="+=">+=
+<option $selected[$op_eq2] value="==">==
+<option $selected[$op_ne] value="!=">!=
+<option $selected[$op_gt] value=">">>
+<option $selected[$op_ge] value=">=">>=
+<option $selected[$op_lt] value="<"><
+<option $selected[$op_le] value="<="><=
+<option $selected[$op_regeq] value="=~">=~
+<option $selected[$op_regne] value="!~">!~
</select>
</td>
EOM;
if ($config[general_lib_type] == 'sql' && $config[sql_use_operators] == 'true'){
$colspan=2;
$show_ops=1;
- $op_eq = '=';
- $op_set = ':=';
- $op_add = '+=';
}else{
$show_ops = 0;
$colspan=1;
<option selected value="=">=
<option value=":=">:=
<option value="+=">+=
+<option value="==">==
+<option value="!=">!=
+<option value=">">>
+<option value=">=">>=
+<option value="<"><
+<option value="<="><=
+<option value="=~">=~
+<option value="!~">!~
+
</select>
</td>
EOM;
--- /dev/null
+<?php
+$op_eq = '=';
+$op_set = ':=';
+$op_add = '+=';
+$op_eq2 = '==';
+$op_ne = '!=';
+$op_gt = '>';
+$op_ge = '>=';
+$op_lt = '<';
+$op_le = '<=';
+$op_regeq = '=~';
+$op_regne = '!~';
+
+// Check the operator if it is allowed for this type of
+// attribute (check or reply).
+// Arguments:
+// $op: The operator
+// $type: 1(check),2(reply)
+// Return value:0 for OK, -1 for error
+function check_operator($op,$type)
+{
+ switch($op){
+ case '=':
+ case ':=':
+ case '+=':
+ return 0;
+ case '==':
+ case '!=':
+ case '>':
+ case '>=':
+ case '<':
+ case '<=':
+ case '=~':
+ case '!~':
+ return ($type == 1) ? 0 : -1;
+ }
+}
+?>
while(isset($$name)){
$val=$$name;
$op_name = $name . '_op';
- $op_val = $$op_name;
- if ($op_val != ''){
- $op_val1 = "'$op_val'";
- $op_val2 = ",'$op_val'";
- }
$i++;
$j++;
$name = $attrmap["$key"] . $i;
$sql_attr=$attrmap["$key"];
- if ($attr_type["$key"] == 'checkItem')
+ if ($attr_type["$key"] == 'checkItem'){
$table = $config[sql_check_table];
- else if ($attr_type["$key"] == 'replyItem')
+ $type = 1;
+ }
+ else if ($attr_type["$key"] == 'replyItem'){
$table = $config[sql_reply_table];
- // if we have operators the operator has changed and the corresponding value exists then update
+ $type = 2;
+ }
+ if ($use_ops){
+ $op_val = $$op_name;
+ if ($op_val != ''){
+ if (check_operator($op_val,$type) == -1){
+ echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
+ continue;
+ }
+ $op_val1 = "'$op_val'";
+ $op_val2 = ",'$op_val'";
+ }
+ }
+ // if we have operators, the operator has changed and the corresponding value exists then update
if ($use_ops && isset($item_vals["$key"][operator][$j]) &&
$op_val != $item_vals["$key"][operator][$j] ){
$res = @da_sql_query($link,$config,
exit();
}
if ($config[sql_use_operators] == 'true'){
+ include("../lib/operators.php3");
$text = ',op';
$passwd_op = ",':='";
}
foreach($show_attrs as $key => $attr){
if ($attrmap["$key"] == 'none')
continue;
- if ($attr_type[$key] == 'checkItem')
+ if ($attr_type[$key] == 'checkItem'){
$table = "$config[sql_check_table]";
- else if ($attr_type[$key] == 'replyItem')
+ $type = 1;
+ }
+ else if ($attr_type[$key] == 'replyItem'){
$table = "$config[sql_reply_table]";
+ $type = 2;
+ }
$val = $$attrmap["$key"];
$op_name = $attrmap["$key"] . '_op';
$op_val = $$op_name;
- if ($op_val != '')
+ if ($op_val != ''){
+ if (check_operator($op_val,$type) == -1){
+ echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
+ coninue;
+ }
$op_val = ",'$op_val'";
+ }
if ($val == '' || $val == $default_vals["$key"])
continue;
$res = @da_sql_query($link,$config,