Subversion Repositories ALCASAR

Rev

Rev 1379 | Rev 1838 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1379 Rev 1805
Line 4... Line 4...
4
        include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
4
        include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
5
else{
5
else{
6
	echo "<b>Could not include SQL library</b><br>\n";
6
	echo "<b>Could not include SQL library</b><br>\n";
7
	exit();
7
	exit();
8
}
8
}
9
if ($config[sql_use_operators] == 'true'){
9
if ($config['sql_use_operators'] == 'true'){
10
	$use_ops=1;
10
	$use_ops=1;
11
	$text1 = 'AND op =';
11
	$text1 = 'AND op =';
12
	$text2 = ',op';
12
	$text2 = ',op';
13
}
13
}
14
$link = @da_sql_pconnect($config);
14
$link = da_sql_pconnect($config);
15
if ($link){
15
if ($link){
16
	foreach($show_attrs as $key => $desc){
16
	foreach($show_attrs as $key => $desc){
17
		if ($attrmap["$key"] == 'none')
17
		if ($attrmap["$key"] == 'none')
18
			continue;
18
			continue;
19
		if ($attrmap["$key"] == ''){
19
		if ($attrmap["$key"] == ''){
Line 24... Line 24...
24
		$i = 0;
24
		$i = 0;
25
		$j = -1;
25
		$j = -1;
26
		$name = $attrmap["$key"] . $i;
26
		$name = $attrmap["$key"] . $i;
27
		while(isset($$name)){
27
		while(isset($$name)){
28
			$val=$$name;
28
			$val=$$name;
29
			$val = da_sql_escape_string($val);
29
			$val = da_sql_escape_string($link, $val);
30
			$op_name = $name . '_op';
30
			$op_name = $name . '_op';
31
			$i++;
31
			$i++;
32
			$j++;
32
			$j++;
33
			$name = $attrmap["$key"] . $i;
33
			$name = $attrmap["$key"] . $i;
34
			$sql_attr=$attrmap["$key"];
34
			$sql_attr=$attrmap["$key"];
35
			$query_key = ($user_type == 'group') ? 'groupname' : 'username';
35
			$query_key = ($user_type == 'group') ? 'groupname' : 'username';
36
			if ($attr_type["$key"] == 'checkItem'){
36
			if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
37
				$table = ($user_type == 'group') ? $config[sql_groupcheck_table] : $config[sql_check_table];
37
				$table = ($user_type == 'group') ? $config['sql_groupcheck_table'] : $config['sql_check_table'];
38
				$type = 1;
38
				$type = 1;
39
			}
39
			}
40
			else if ($attr_type["$key"] == 'replyItem'){
40
			else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
41
				$table = ($user_type == 'group') ? $config[sql_groupreply_table] : $config[sql_reply_table];
41
				$table = ($user_type == 'group') ? $config['sql_groupreply_table'] : $config['sql_reply_table'];
42
				$type = 2;
42
				$type = 2;
43
			}
43
			}
44
			if ($use_ops){
44
			if ($use_ops){
45
				$op_val = $$op_name;
45
				$op_val = $$op_name;
46
				if ($op_val != ''){
46
				if ($op_val != ''){
47
					$op_val = da_sql_escape_string($op_val);
47
					$op_val = da_sql_escape_string($link, $op_val);
48
					if (check_operator($op_val,$type) == -1){
48
					if (check_operator($op_val,$type) == -1){
49
						echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
49
						echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
50
						continue;
50
						continue;
51
					}
51
					}
52
					$op_val2 = ",'$op_val'";
52
					$op_val2 = ",'$op_val'";
53
				}
53
				}
54
			}
54
			}
55
			$sql_attr = da_sql_escape_string($sql_attr);
55
			$sql_attr = da_sql_escape_string($link, $sql_attr);
56
			$val = da_sql_escape_string($val);
56
			$val = da_sql_escape_string($link, $val);
57
	// if we have operators, the operator has changed and the corresponding value exists then update
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]) &&
58
			if ($use_ops && isset($item_vals["$key"]['operator'][$j]) &&
59
				$op_val != $item_vals["$key"][operator][$j] ){
59
				$op_val != $item_vals["$key"]['operator'][$j] ){
60
				$res = @da_sql_query($link,$config,
60
				$res = da_sql_query($link,$config,
61
				"UPDATE $table SET op = '$op_val' WHERE $query_key = '$login'
61
				"UPDATE $table SET op = '$op_val' WHERE $query_key = '$login'
62
				AND attribute = '$sql_attr' AND value = '$val';");
62
				AND attribute = '$sql_attr' AND value = '$val';");
63
				if (!$res || !@da_sql_affected_rows($link,$res,$config))
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";
64
					echo "<b>Operator change failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
65
			}
65
			}
-
 
66
			$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
66
	// 	if value is the same as that in the sql database do nothing
67
	// 	if value is the same as that in the sql database do nothing
67
			if ($val == $item_vals["$key"][$j])
68
			if (isset($item_vals["$key"]) && $val == $item_vals["$key"][$j])
68
				continue;
69
				continue;
69
	//	if value is null or equals the default value and corresponding value exists then delete
70
	//	if value is null or equals the default value and corresponding value exists then delete
70
			else if ((check_defaults($val,$op_val,$default_vals["$key"]) || $val == '' || ($sql_attr == "Filter-Id" && $val == "None")) && isset($item_vals["$key"][$j])){
71
			else if (($chkdef || $val == '' || ($sql_attr == "Filter-Id" && $val == "None")) && isset($item_vals["$key"][$j])){
71
				$res = @da_sql_query($link,$config,
72
				$res = da_sql_query($link,$config,
72
				"DELETE FROM $table WHERE $query_key = '$login' AND attribute = '$sql_attr';");
73
				"DELETE FROM $table WHERE $query_key = '$login' AND attribute = '$sql_attr';");
73
				if (!$res || !@da_sql_affected_rows($link,$res,$config))
74
				if (!$res || !da_sql_affected_rows($link,$res,$config))
74
					echo "<b>Delete failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
75
					echo "<b>Delete failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
75
			}
76
			}
76
	//	if value is null or equals the default value then don't add it
77
	//	if value is null or equals the default value then don't add it
77
			else if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
78
			else if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
78
				continue;
79
				continue;
79
	//	if value differs from the sql value then update
80
	//	if value differs from the sql value then update
80
			else{
81
			else{
81
				if (isset($item_vals["$key"][$j])){
82
				if (isset($item_vals["$key"][$j])){
82
					$old_val = $item_vals["$key"][$j];
83
					$old_val = $item_vals["$key"][$j];
83
					$old_val = da_sql_escape_string($old_val);
84
					$old_val = da_sql_escape_string($link, $old_val);
84
					$res = @da_sql_query($link,$config,
85
					$res = da_sql_query($link,$config,
85
					"UPDATE $table SET value = '$val' WHERE $query_key = '$login' AND
86
					"UPDATE $table SET value = '$val' WHERE $query_key = '$login' AND
86
					attribute = '$sql_attr' AND value = '$old_val';");
87
					attribute = '$sql_attr' AND value = '$old_val';");
87
				}
88
				}
88
				else
89
				else
89
					$res = @da_sql_query($link,$config,
90
					$res = da_sql_query($link,$config,
90
					"INSERT INTO $table ($query_key,attribute,value $text2)
91
					"INSERT INTO $table ($query_key,attribute,value $text2)
91
					VALUES ('$login','$sql_attr','$val' $op_val2);");
92
					VALUES ('$login','$sql_attr','$val' $op_val2);");
92
				if (!$res || !@da_sql_affected_rows($link,$res,$config))
93
				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";
94
					echo "<b>Change failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
94
			}
95
			}
95
		}
96
		}
96
	}
97
	}
97
}
98
}