Subversion Repositories ALCASAR

Rev

Rev 1831 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
1805 clement.si 1
<?php
2
require('../lib/sql/attrmap.php');
3
if ((isset($login) && $login != '') && (isset($user_type) && $user_type !== 'group')){
4
	if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
5
		include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
6
	else{
7
		echo "<b>Could not include SQL library</b><br>\n";
8
		exit();
9
	}
10
	if ($config['sql_use_operators'] == 'true'){
11
		$op = ',op';
12
		$use_op = 1;
13
	}else{
14
		$op = "";
15
		$use_op = 0;
16
	}
17
	$overwrite_defaults = 1;
18
	$stop = 0;
19
	$times = 0;
20
	do{
21
		unset($item_vals);
22
		unset($member_groups);
23
		unset($tmp);
24
		$times++;
25
		$link = da_sql_pconnect($config);
26
		if ($link){
27
			$res = da_sql_query($link,$config,
28
			"SELECT groupname FROM $config[sql_usergroup_table] WHERE username = '$login';");
29
			if ($res){
30
				while(($row = da_sql_fetch_array($res,$config))){
31
					$group = $row['groupname'];
32
					$member_groups[$group] = $group;
33
				}
34
				if (isset($member_groups))
35
					ksort($member_groups);
36
			}
37
			if (isset($member_groups)){
38
				$in = '(';
39
				foreach ($member_groups as $group)
40
					$in .= "'$group',";
41
				$in = substr($in,0,-1);
42
				$in .= ')';
43
				$res = da_sql_query($link,$config,
44
				"SELECT attribute,value $op FROM $config[sql_groupcheck_table]
45
				WHERE groupname IN $in;");
46
				if ($res){
47
					while(($row = da_sql_fetch_array($res,$config))){
48
						$attr = $row['attribute'];
49
						$val = $row['value'];
50
						if ($use_op){
51
							$oper = $row['op'];
52
							$tmp["$attr"]['operator'][]="$oper";
53
						}
54
						$tmp["$attr"][]="$val";
55
						$tmp["$attr"]['count']++;
56
					}
57
					$res = da_sql_query($link,$config,
58
					"SELECT attribute,value $op FROM $config[sql_groupreply_table]
59
					WHERE groupname IN $in;");
60
					if ($res){
61
						while(($row = da_sql_fetch_array($res,$config))){
62
							$attr = $row['attribute'];
63
							$val = $row['value'];
64
							if ($use_op){
65
								$oper = $row['op'];
66
								$tmp["$attr"]['operator'][]="$oper";
67
							}
68
							$tmp["$attr"][] = "$val";
69
							$tmp["$attr"]['count']++;
70
						}
71
					}
72
					else
73
						echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
74
				}
75
				else
76
					echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
77
				if (isset($tmp)){
78
					foreach(array_keys($tmp) as $val){
79
						if ($val == '')
80
							continue;
81
						$key = $rev_attrmap["$val"];
82
						if ($key == ''){
83
							$key = $val;
84
							$attrmap["$key"] = $val;
85
							$attr_type["$key"] = 'replyItem';
86
							$rev_attrmap["$val"] = $key;
87
						}
88
						if (!isset($default_vals["$key"]) || $overwrite_defaults){
89
							if ($use_op)
90
								$default_vals["$key"]['operator'] = $tmp["$val"]['operator'];
91
							if ($tmp[$val][0] != '')
92
								$default_vals["$key"] = $tmp["$val"];
93
						}
94
					}
95
				}
96
			}
97
			if ($times == 1){
98
				if (!isset($config['sql_default_user_profile']) || $config['sql_default_user_profile'] == '')
99
					$stop = 1;
100
				else{
101
					$saved_login = $login;
102
					$saved_member_groups = $member_groups;
103
					$login = $config['sql_default_user_profile'];
104
					$overwrite_defaults = 0;
105
				}
106
			}
107
			if ($times == 2){
108
				$login = $saved_login;
109
				$member_groups = $saved_member_groups;
110
				$stop = 1;
111
			}
112
		}
113
		else
114
			echo "<b>Could not connect to SQL database</b><br>\n";
115
	}while($stop == 0);
116
}
117
else{
118
	if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
119
		include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
120
	else{
121
		echo "<b>Could not include SQL library</b><br>\n";
122
		exit();
123
	}
124
	unset($member_groups);
125
	$link = da_sql_pconnect($config);
126
	if ($link){
127
		$res = da_sql_query($link,$config,
128
		"SELECT DISTINCT groupname FROM $config[sql_usergroup_table];");
129
		if ($res){
130
			while(($row = da_sql_fetch_array($res,$config)))
131
				$member_groups[] = $row['groupname'];
132
		}
133
		else
134
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
135
	}
136
	else
137
		echo "<b>Could not connect to SQL database</b><br>\n";
138
}
139
?>