From 7b478fc6f2381c1ac32b474ace29c2e43a0211db Mon Sep 17 00:00:00 2001 From: kkalev Date: Thu, 7 Feb 2002 17:58:36 +0000 Subject: [PATCH] * Added operator support in sql. The eq(=),set(:=) and add(+=) operators are supported. Added an 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. --- Changelog | 6 +++++ conf/admin.conf | 3 +++ htdocs/user_edit.php3 | 49 +++++++++++++++++++++++++++++++++----- htdocs/user_new.php3 | 43 ++++++++++++++++++++++++++------- lib/ldap/user_info.php3 | 1 + lib/sql/change_attrs.php3 | 31 ++++++++++++++++++++---- lib/sql/change_passwd.php3 | 11 ++++++--- lib/sql/create_user.php3 | 16 +++++++++---- lib/sql/user_info.php3 | 24 +++++++++++++++++-- 9 files changed, 157 insertions(+), 27 deletions(-) diff --git a/Changelog b/Changelog index ef4b06f..9d0b751 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,12 @@ Ver 1.29: * Fix a bug in config.php3 when we have a directive containing ':' * Fix a bug in lib/ldap/change_attrs.php3 that did not allow changing more than one value of a multivalued attribute simultaneously. +* Added selection of ordering in user_accounting.php3. Now it can be either ascending (older records + first) or descending (most recent records first). Added a corresponding configuration directive. +* Added operator support in sql. The eq(=),set(:=) and add(+=) operators are supported. Added an + 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. Ver 1.28: * Make user_delete.php3 print something when a user is deleted * Cache nas hostname lookups in user_accounting diff --git a/conf/admin.conf b/conf/admin.conf index 0d3d9f4..b07f517 100644 --- a/conf/admin.conf +++ b/conf/admin.conf @@ -95,6 +95,9 @@ sql_user_info_table: userinfo # true or false # sql_use_user_info_table: true +sql_use_operators: true +# +# sql_password_attribute: Crypt-Password sql_date_format: Y-m-d sql_full_date_format: Y-m-d H:i:s diff --git a/htdocs/user_edit.php3 b/htdocs/user_edit.php3 index 6057199..765e2f9 100644 --- a/htdocs/user_edit.php3 +++ b/htdocs/user_edit.php3 @@ -4,6 +4,18 @@ require('../lib/attrshow.php3'); require('../lib/defaults.php3'); if (is_file("../lib/$config[general_lib_type]/user_info.php3")) include("../lib/$config[general_lib_type]/user_info.php3"); +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; +} + echo << @@ -69,7 +81,7 @@ else if ($badusers == 1){ - +EOM; + + if ($show_ops) + print << + + +EOM; + + print << @@ -109,7 +146,7 @@ EOM; } ?> - - - - - - - - +EOM; + + if ($show_ops) + print << + + +EOM; + + print << diff --git a/lib/ldap/user_info.php3 b/lib/ldap/user_info.php3 index 73242fd..34fd632 100644 --- a/lib/ldap/user_info.php3 +++ b/lib/ldap/user_info.php3 @@ -15,6 +15,7 @@ if ($ds) { $user_exists = 'no'; else{ $user_exists = 'yes'; + unset($item_vals); $k = init_decoder(); $cn = ($info[0]['cn'][0]) ? $info[0]['cn'][0] : '-'; $cn_lang = $info[0]["cn;lang-$config[general_prefered_lang]"][0]; diff --git a/lib/sql/change_attrs.php3 b/lib/sql/change_attrs.php3 index de8f76e..f12fd1f 100644 --- a/lib/sql/change_attrs.php3 +++ b/lib/sql/change_attrs.php3 @@ -5,6 +5,11 @@ else{ echo "Could not include SQL library
\n"; exit(); } +if ($config[sql_use_operators] == 'true'){ + $use_ops=1; + $text1 = 'AND op ='; + $text2 = ',op'; +} $link = @da_sql_pconnect($config); if ($link){ foreach($show_attrs as $key => $desc){ @@ -16,6 +21,12 @@ if ($link){ 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; @@ -25,6 +36,16 @@ if ($link){ $table = $config[sql_check_table]; 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 + if ($use_ops && isset($item_vals["$key"][operator][$j]) && + $op_val != $item_vals["$key"][operator][$j] ){ + $res = @da_sql_query($link,$config, + "UPDATE $table SET op = '$op_val' WHERE UserName = '$login' + AND Attribute = '$sql_attr' AND Value = '$val';"); + if (!$res || !@da_sql_affected_rows($link,$res,$config)) + echo "Operator change failed for attribute $key
\n"; + } + // if value is the same as that in the sql database do nothing if ($val == $item_vals["$key"][$j]) continue; @@ -40,14 +61,16 @@ if ($link){ continue; // if value differs from the sql value then update else{ - if (isset($item_vals["$key"][$j])) + if (isset($item_vals["$key"][$j])){ + $old_val = $item_vals["$key"][$j]; $res = @da_sql_query($link,$config, "UPDATE $table SET Value = '$val' WHERE UserName = '$login' AND - Attribute = '$sql_attr';"); + Attribute = '$sql_attr' AND Value = '$old_val';"); + } else $res = @da_sql_query($link,$config, - "INSERT INTO $table (UserName,Attribute,Value) - VALUES ('$login','$sql_attr','$val');"); + "INSERT INTO $table (UserName,Attribute,Value $text2) + VALUES ('$login','$sql_attr','$val' $op_val2);"); if (!$res || !@da_sql_affected_rows($link,$res,$config)) echo "Change failed for attribute $key
\n"; } diff --git a/lib/sql/change_passwd.php3 b/lib/sql/change_passwd.php3 index 77c5f9e..dbe9080 100644 --- a/lib/sql/change_passwd.php3 +++ b/lib/sql/change_passwd.php3 @@ -5,6 +5,11 @@ else{ echo "Could not include SQL library
\n"; exit(); } +if ($config[sql_use_operator] == 'true'){ + $text1 = ',op'; + $text2 = ",':='"; + $text3 = "AND op = ':='"; +} $link = @da_sql_pconnect($config); if ($link){ if (is_file("../lib/crypt/$config[general_encryption_method].php3")){ @@ -17,15 +22,15 @@ if ($link){ $row = @da_sql_fetch_array($res,$config); if ($row){ $res = @da_sql_query($link,$config, - "UPDATE $config[sql_check_table] SET Value = '$passwd' WHERE + "UPDATE $config[sql_check_table] SET Value = '$passwd' $text3 WHERE Attribute = '$config[sql_password_attribute]' AND UserName = '$login';"); if (!$res || !@da_sql_affected_rows($link,$res,$config)) echo "Error while changing password
\n"; } else{ $res = @da_sql_query($link,$config, - "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName) - VALUES ('$config[sql_password_attribute]','$passwd','$login');"); + "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName $text1) + VALUES ('$config[sql_password_attribute]','$passwd','$login' $text2);"); if (!$res || !@da_sql_affected_rows($link,$res,$config)) echo "Error while changing password
\n"; } diff --git a/lib/sql/create_user.php3 b/lib/sql/create_user.php3 index 5c580ac..7cc5185 100644 --- a/lib/sql/create_user.php3 +++ b/lib/sql/create_user.php3 @@ -5,6 +5,10 @@ else{ echo "Could not include SQL library
\n"; exit(); } +if ($config[sql_use_operators] == 'true'){ + $text = ',op'; + $passwd_op = ",':='"; +} $da_abort=0; $link = @da_sql_pconnect($config); if ($link){ @@ -12,8 +16,8 @@ if ($link){ include("../lib/crypt/$config[general_encryption_method].php3"); $passwd = da_encrypt($passwd); $res = @da_sql_query($link,$config, - "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName) - VALUES ('$config[sql_password_attribute]','$passwd','$login');"); + "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName $text) + VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);"); if (!$res || !@da_sql_affected_rows($link,$res,$config)){ echo "Unable to add user $login. SQL error
\n"; $da_abort=1; @@ -44,11 +48,15 @@ if ($link){ else if ($attr_type[$key] == 'replyItem') $table = "$config[sql_reply_table]"; $val = $$attrmap["$key"]; + $op_name = $attrmap["$key"] . '_op'; + $op_val = $$op_name; + if ($op_val != '') + $op_val = ",'$op_val'"; if ($val == '' || $val == $default_vals["$key"]) continue; $res = @da_sql_query($link,$config, - "INSERT INTO $table (Attribute,Value,UserName) - VALUES ('$attrmap[$key]','$val','$login');"); + "INSERT INTO $table (Attribute,Value,UserName $text) + VALUES ('$attrmap[$key]','$val','$login' $op_val);"); if (!$res || !@da_sql_affected_rows($link,$res,$config)) echo "Query failed for attribute $key
\n"; } diff --git a/lib/sql/user_info.php3 b/lib/sql/user_info.php3 index 9abae66..0a99248 100644 --- a/lib/sql/user_info.php3 +++ b/lib/sql/user_info.php3 @@ -6,26 +6,43 @@ else{ echo "Could not include SQL library
\n"; exit(); } +if ($config[sql_use_operators] == 'true'){ + $op = ',op'; + $use_op = 1; +}else{ + $op = ""; + $use_op = 0; +} $user_exists = 'no'; +unset($item_vals); +unset($tmp); $link = @da_sql_pconnect($config); if ($link){ $res = @da_sql_query($link,$config, - "SELECT Attribute,Value FROM $config[sql_check_table] WHERE UserName = '$login';"); + "SELECT Attribute,Value $op FROM $config[sql_check_table] WHERE UserName = '$login';"); if ($res){ if (@da_sql_num_rows($res,$config)) $user_exists = 'yes'; while(($row = @da_sql_fetch_array($res,$config))){ $attr = $row[Attribute]; $val = $row[Value]; + if ($use_op){ + $oper = $row[op]; + $tmp["$attr"][operator][]="$oper"; + } $tmp["$attr"][]="$val"; $tmp["$attr"][count]++; } $res = @da_sql_query($link,$config, - "SELECT Attribute,Value FROM $config[sql_reply_table] WHERE UserName = '$login';"); + "SELECT Attribute,Value $op FROM $config[sql_reply_table] WHERE UserName = '$login';"); if ($res){ while(($row = @da_sql_fetch_array($res,$config))){ $attr = $row[Attribute]; $val = $row[Value]; + if ($use_op){ + $oper = $row[op]; + $tmp["$attr"][operator][]="$oper"; + } $tmp["$attr"][] = "$val"; $tmp["$attr"][count]++; } @@ -50,6 +67,9 @@ if ($link){ if (isset($tmp[$val])){ $item_vals["$key"] = $tmp[$val]; $item_vals["$key"][count] = $tmp[$val][count]; + if ($use_op) + $item_vals["$key"][operator] = $tmp[$val][operator]; + } } -- 2.39.5
+ bgcolor="#d0ddb0"> User Password (changes only) @@ -82,24 +94,49 @@ User Password (changes only) if ($name == 'none') continue; unset($vals); - if (count($item_vals["$key"])){ - for($i=0;$i<$item_vals["$key"][count];$i++) + unset($selected); + unset($ops); + if ($item_vals["$key"][count]){ + for($i=0;$i<$item_vals["$key"][count];$i++){ $vals[] = $item_vals["$key"][$i]; + $ops[] = $item_vals["$key"][operator][$i]; + } } - else + else{ $vals[] = $default_vals["$key"]; - if ($add && $name == $add_attr) + $ops[] = '='; + } + if ($add && $name == $add_attr){ array_push($vals, $default_vals["$key"]); + array_push($ops, '='); + } $i = 0; foreach($vals as $val){ $name1 = $name . $i; + $oper_name = $name1 . '_op'; + $oper = $ops[$i]; + $selected[$oper] = 'selected'; $i++; print << $desc
+ bgcolor="#d0ddb0"> Add Attribute diff --git a/htdocs/user_new.php3 b/htdocs/user_new.php3 index ede6691..90104bb 100644 --- a/htdocs/user_new.php3 +++ b/htdocs/user_new.php3 @@ -6,6 +6,18 @@ if ($show == 1){ require('../conf/config.php3'); require('../lib/attrshow.php3'); require('../lib/defaults.php3'); + +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; +} + ?> @@ -63,56 +75,56 @@ EOM; - + Username
+ Password
+ Name (First Name Surname)
+ Mail
+ Departement
+ Home Phone
+ Work Phone
+ Mobile Phone @@ -123,12 +135,27 @@ EOM; $name = $attrmap["$key"]; if ($name == 'none') continue; + $oper_name = $name . '_op'; $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"]; print << $desc