Subversion Repositories ALCASAR

Rev

Rev 1805 | Rev 1882 | 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";
56
						$tmp["$attr"]['count']++;
57
					}
58
					$res = da_sql_query($link,$config,
59
					"SELECT attribute,value $op FROM $config[sql_groupreply_table]
60
					WHERE groupname IN $in;");
61
					if ($res){
62
						while(($row = da_sql_fetch_array($res,$config))){
63
							$attr = $row['attribute'];
64
							$val = $row['value'];
65
							if ($use_op){
66
								$oper = $row['op'];
67
								$tmp["$attr"]['operator'][]="$oper";
68
							}
69
							$tmp["$attr"][] = "$val";
1831 raphael.pi 70
							if(isset($tmp["$attr"]['count']))
71
							{
72
								$tmp["$attr"]['count']++;
73
							}
1805 clement.si 74
						}
75
					}
76
					else
77
						echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
78
				}
79
				else
80
					echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
81
				if (isset($tmp)){
82
					foreach(array_keys($tmp) as $val){
83
						if ($val == '')
84
							continue;
85
						$key = $rev_attrmap["$val"];
86
						if ($key == ''){
87
							$key = $val;
88
							$attrmap["$key"] = $val;
89
							$attr_type["$key"] = 'replyItem';
90
							$rev_attrmap["$val"] = $key;
91
						}
92
						if (!isset($default_vals["$key"]) || $overwrite_defaults){
93
							if ($use_op)
94
								$default_vals["$key"]['operator'] = $tmp["$val"]['operator'];
95
							if ($tmp[$val][0] != '')
96
								$default_vals["$key"] = $tmp["$val"];
97
						}
98
					}
99
				}
100
			}
101
			if ($times == 1){
102
				if (!isset($config['sql_default_user_profile']) || $config['sql_default_user_profile'] == '')
103
					$stop = 1;
104
				else{
105
					$saved_login = $login;
106
					$saved_member_groups = $member_groups;
107
					$login = $config['sql_default_user_profile'];
108
					$overwrite_defaults = 0;
109
				}
110
			}
111
			if ($times == 2){
112
				$login = $saved_login;
113
				$member_groups = $saved_member_groups;
114
				$stop = 1;
115
			}
116
		}
117
		else
118
			echo "<b>Could not connect to SQL database</b><br>\n";
119
	}while($stop == 0);
120
}
121
else{
122
	if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
123
		include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
124
	else{
125
		echo "<b>Could not include SQL library</b><br>\n";
126
		exit();
127
	}
128
	unset($member_groups);
129
	$link = da_sql_pconnect($config);
130
	if ($link){
1831 raphael.pi 131
		if(isset($login) && $login != '')
132
		{	
133
			#affiche le groupe appartenant à l'utilisateur
134
			$res = da_sql_query($link,$config,
135
			"SELECT DISTINCT groupname FROM $config[sql_usergroup_table] WHERE username = '$login';");
136
		}
137
		else
138
		{
139
			#affiche la liste de groupe disponible (dans le cas de la creation d'un utilisateur)
140
			$res = da_sql_query($link,$config,
141
			"SELECT DISTINCT groupname FROM $config[sql_usergroup_table] ;");
142
		}
143
 
1805 clement.si 144
		if ($res){
1831 raphael.pi 145
			while(($row = da_sql_fetch_array($res,$config))){
1805 clement.si 146
				$member_groups[] = $row['groupname'];
1831 raphael.pi 147
			}
1805 clement.si 148
		}
149
		else
150
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
151
	}
152
	else
153
		echo "<b>Could not connect to SQL database</b><br>\n";
154
}
155
?>