Subversion Repositories ALCASAR

Rev

Rev 2333 | 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){
2333 tom.houday 84
						unset($key);
1805 clement.si 85
						if ($val == '')
86
							continue;
87
						$key = $rev_attrmap["$val"];
2340 tom.houday 88
						if ((!isset($key)) || (empty($key))) {
1805 clement.si 89
							$key = $val;
90
							$attrmap["$key"] = $val;
91
							$attr_type["$key"] = 'replyItem';
92
							$rev_attrmap["$val"] = $key;
93
						}
94
						if (!isset($default_vals["$key"]) || $overwrite_defaults){
95
							if ($use_op)
96
								$default_vals["$key"]['operator'] = $tmp["$val"]['operator'];
97
							if ($tmp[$val][0] != '')
98
								$default_vals["$key"] = $tmp["$val"];
99
						}
100
					}
101
				}
102
			}
103
			if ($times == 1){
104
				if (!isset($config['sql_default_user_profile']) || $config['sql_default_user_profile'] == '')
105
					$stop = 1;
106
				else{
107
					$saved_login = $login;
108
					$saved_member_groups = $member_groups;
109
					$login = $config['sql_default_user_profile'];
110
					$overwrite_defaults = 0;
111
				}
112
			}
113
			if ($times == 2){
114
				$login = $saved_login;
115
				$member_groups = $saved_member_groups;
116
				$stop = 1;
117
			}
118
		}
119
		else
120
			echo "<b>Could not connect to SQL database</b><br>\n";
121
	}while($stop == 0);
122
}
123
else{
124
	if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
125
		include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
126
	else{
127
		echo "<b>Could not include SQL library</b><br>\n";
128
		exit();
129
	}
130
	unset($member_groups);
131
	$link = da_sql_pconnect($config);
132
	if ($link){
1831 raphael.pi 133
		if(isset($login) && $login != '')
134
		{	
135
			#affiche le groupe appartenant à l'utilisateur
136
			$res = da_sql_query($link,$config,
137
			"SELECT DISTINCT groupname FROM $config[sql_usergroup_table] WHERE username = '$login';");
138
		}
139
		else
140
		{
141
			#affiche la liste de groupe disponible (dans le cas de la creation d'un utilisateur)
142
			$res = da_sql_query($link,$config,
143
			"SELECT DISTINCT groupname FROM $config[sql_usergroup_table] ;");
144
		}
145
 
1805 clement.si 146
		if ($res){
1831 raphael.pi 147
			while(($row = da_sql_fetch_array($res,$config))){
1805 clement.si 148
				$member_groups[] = $row['groupname'];
1831 raphael.pi 149
			}
1805 clement.si 150
		}
151
		else
152
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
153
	}
154
	else
155
		echo "<b>Could not connect to SQL database</b><br>\n";
156
}
157
?>