Subversion Repositories ALCASAR

Rev

Rev 1831 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1805 clement.si 1
<?php
2
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
3
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
4
else{
5
	echo "<b>Could not include SQL library</b><br>\n";
6
	exit();
7
}
8
$link = da_sql_pconnect($config);
9
if ($link){
10
	if (isset($member_groups) && isset($edited_groups)){
11
		$del_groups = array_diff($member_groups,$edited_groups);
12
		if (isset($del_groups)){
13
			foreach ($del_groups as $del){
1831 raphael.pi 14
				$del = da_sql_escape_string($link,$del);
1805 clement.si 15
				$res = da_sql_query($link,$config,
16
			"DELETE FROM $config[sql_usergroup_table] WHERE username = '$login' AND groupname = '$del';");
17
				if (!$res)
18
					echo "<b>Could not delete user $login from group $del: " . da_sql_error($link,$config) . "</b><br>\n";
19
				else
20
					echo "<b>User $login deleted from group $del</b><br>\n";
21
			}
22
		}
23
		$new_groups = array_diff($edited_groups,$member_groups);
24
		if (isset($new_groups)){
25
			foreach($new_groups as $new){
1831 raphael.pi 26
				$new = da_sql_escape_string($link,$new);
1805 clement.si 27
				$res = da_sql_query($link,$config,
28
				"INSERT INTO $config[sql_usergroup_table] (groupname,username)
29
				VALUES ('$new','$login');");
30
				if (!$res)
31
					echo "<b>Error while adding user $login to group $login: " . da_sql_error($link,$config) . "</b><br>\n";
32
				else
33
					echo "<b>User $login added to group $new</b><br>\n";
34
			}
35
		}
36
	}
1838 raphael.pi 37
	//si l'utilisateur n'appartient a aucun groupe. 
38
	if (!isset($member_groups) && isset($edited_groups)){
39
		$new = $edited_groups[0];
40
		$new = da_sql_escape_string($link,$new);
41
		$res = da_sql_query($link,$config,
42
		"INSERT INTO $config[sql_usergroup_table] (groupname,username)
43
		VALUES ('$new','$login');");
44
		if (!$res)
45
			echo "<b>Error while adding user $login to group $login: " . da_sql_error($link,$config) . "</b><br>\n";
46
		else
47
			echo "<b>User $login added to group $new</b><br>\n";
48
	}
1805 clement.si 49
}
50
else
51
	echo "<b>Could not connect to SQL database</b><br>\n";
52
?>