Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
325 richard 1
<?php
2
require_once('../lib/functions.php');
3
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
4
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
5
else{
6
	echo "<b>Could not include SQL library</b><br>\n";
7
	exit();
8
}
1805 clement.si 9
if ($config['sql_use_operators'] == 'true'){
10
	include_once("../lib/operators.php");
325 richard 11
	$text = ',op';
12
	$passwd_op = ",':='";
13
}
14
$da_abort=0;
15
$op_val2 = '';
1805 clement.si 16
$link = da_sql_pconnect($config);
325 richard 17
if ($link){
18
	$Members = preg_split("/[\n\s]+/",$members,-1,PREG_SPLIT_NO_EMPTY);
19
	if (!empty($Members)){
20
		foreach ($Members as $member){
1805 clement.si 21
			$member = da_sql_escape_string($link, $member);
22
			$res = da_sql_query($link,$config,
325 richard 23
			"INSERT INTO $config[sql_usergroup_table] (username,groupname)
24
			VALUES ('$member','$login');");
1805 clement.si 25
			if (!$res || !da_sql_affected_rows($link,$res,$config)){
325 richard 26
				echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
27
				$da_abort=1;
28
			}
29
		}
30
	}
31
	else
32
		{
1805 clement.si 33
		$res = da_sql_query($link,$config,
325 richard 34
			"INSERT INTO $config[sql_usergroup_table] (username,groupname)
35
			VALUES ('$login','$login');");
1805 clement.si 36
			if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 37
				{
38
				echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
39
				$da_abort=1;
40
				}
41
			else
42
				{
43
				echo "<b>Un groupe ne pouvant &ecirc;tre vide, l'usager '$login' a &eacute;t&eacute; cr&eacute;&eacute; (usager virtuel)<br>";
44
				}
45
		}
46
	if (!$da_abort)
47
		{
48
		foreach($show_attrs as $key => $attr){
49
			if ($attrmap["$key"] == 'none')
50
				continue;
1377 richard 51
			if ($key == "Filter-Id" && $$attrmap["$key"] == "None")
52
				continue;
325 richard 53
			if ($attrmap["$key"] == ''){
54
				$attrmap["$key"] = $key;
55
				$attr_type["$key"] = 'replyItem';
56
				$rev_attrmap["$key"] = $key;
57
			}
1805 clement.si 58
			if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
325 richard 59
				$table = "$config[sql_groupcheck_table]";
60
				$type = 1;
61
			}
1805 clement.si 62
			else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
325 richard 63
				$table = "$config[sql_groupreply_table]";
64
				$type = 2;
65
			}
2843 rexy 66
			$val = $_POST[$attrmap["$key"]];
1805 clement.si 67
			$val = da_sql_escape_string($link, $val);
325 richard 68
			$op_name = $attrmap["$key"] . '_op';
69
			$op_val = $$op_name;
70
			if ($op_val != ''){
1805 clement.si 71
				$op_val = da_sql_escape_string($link, $op_val);
325 richard 72
				if (check_operator($op_val,$type) == -1){
73
					echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
74
					coninue;
75
				}
76
				$op_val2 = ",'$op_val'";
77
			}
1805 clement.si 78
			$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
79
			if ($val == '' || $chkdef)
325 richard 80
				continue;
1805 clement.si 81
			$res = da_sql_query($link,$config,
325 richard 82
			"INSERT INTO $table (attribute,value,groupname $text)
83
			VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
1805 clement.si 84
			if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 85
				echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
86
		}
87
		echo "<b>Le groupe $login a &eacute;t&eacute; correctement cr&eacute;&eacute;</b><br>\n";
88
	}
89
}
90
else
91
	echo "<b>Could not connect to SQL database</b><br>\n";
92
?>