2 require_once('../lib/functions.php3');
3 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
4 include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
6 echo "<b>Could not include SQL library</b><br>\n";
9 if ($config[sql_use_operators] == 'true'){
14 $link = @da_sql_pconnect($config);
16 foreach($show_attrs as $key => $desc){
17 if ($attrmap["$key"] == 'none')
19 if ($attrmap["$key"] == ''){
20 $attrmap["$key"] = $key;
21 $attr_type["key"] = 'replyItem';
22 $rev_attrmap["$key"] = $key;
26 $name = $attrmap["$key"] . $i;
30 $val = da_sql_escape_string($val);
31 $op_name = $name . '_op';
34 $name = $attrmap["$key"] . $i;
36 $sql_attr=$attrmap["$key"];
37 $query_key = ($user_type == 'group') ? 'groupname' : 'username';
38 if ($attr_type["$key"] == 'checkItem'){
39 $table = ($user_type == 'group') ? $config[sql_groupcheck_table] : $config[sql_check_table];
42 else if ($attr_type["$key"] == 'replyItem'){
43 $table = ($user_type == 'group') ? $config[sql_groupreply_table] : $config[sql_reply_table];
49 if (check_operator($op_val,$type) == -1){
50 echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
53 $op_val1 = "'$op_val'";
54 $op_val2 = ",'$op_val'";
57 // if we have operators, the operator has changed and the corresponding value exists then update
58 if ($use_ops && isset($item_vals["$key"][operator][$j]) &&
59 $op_val != $item_vals["$key"][operator][$j] ){
60 $res = @da_sql_query($link,$config,
61 "UPDATE $table SET op = '$op_val' WHERE $query_key = '$login'
62 AND attribute = '$sql_attr' AND value = '$val';");
63 if (!$res || !@da_sql_affected_rows($link,$res,$config))
64 echo "<b>Operator change failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
67 // if value is the same as that in the sql database do nothing
68 if ($val == $item_vals["$key"][$j])
70 // if value is null or equals the default value and corresponding value exists then delete
71 else if ((check_defaults($val,$op_val,$default_vals["$key"]) || $val == '') && isset($item_vals["$key"][$j])){
72 $res = @da_sql_query($link,$config,
73 "DELETE FROM $table WHERE $query_key = '$login' AND attribute = '$sql_attr';");
74 if (!$res || !@da_sql_affected_rows($link,$res,$config))
75 echo "<b>Delete failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
77 // if value is null or equals the default value then don't add it
78 else if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
80 // if value differs from the sql value then update
82 if (isset($item_vals["$key"][$j])){
83 $old_val = $item_vals["$key"][$j];
84 $res = @da_sql_query($link,$config,
85 "UPDATE $table SET value = '$val' WHERE $query_key = '$login' AND
86 attribute = '$sql_attr' AND value = '$old_val';");
89 $res = @da_sql_query($link,$config,
90 "INSERT INTO $table ($query_key,attribute,value $text2)
91 VALUES ('$login','$sql_attr','$val' $op_val2);");
92 if (!$res || !@da_sql_affected_rows($link,$res,$config))
93 echo "<b>Change failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
99 echo "<b>Could not connect to SQL database</b><br>\n";