Subversion Repositories ALCASAR

Rev

Rev 2010 | Rev 2044 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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