Subversion Repositories ALCASAR

Rev

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