Subversion Repositories ALCASAR

Rev

Rev 1805 | Rev 2096 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1805 clement.si 1
<?php
325 richard 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
include_once('../lib/functions.php');
1805 clement.si 9
if ($config['sql_use_operators'] == 'true'){
1091 stephane 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){
1878 raphael.pi 18
	mysqli_set_charset($link,"utf8");
325 richard 19
	if (is_file("../lib/crypt/$config[general_encryption_method].php")){
1091 stephane 20
		include_once("../lib/crypt/$config[general_encryption_method].php");
509 richard 21
		/*Ajout en vue de l'impression des données (thank's to Geoffroy MUSITELLI)*/
508 richard 22
		$passwd_imp = $passwd;
23
		/*Fin Ajout*/
325 richard 24
		$passwd = da_encrypt($passwd);
1805 clement.si 25
		$passwd = da_sql_escape_string($link, $passwd);
26
		$res = da_sql_query($link,$config,
325 richard 27
		"INSERT INTO $config[sql_check_table] (attribute,value,username $text)
28
		VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);");
1805 clement.si 29
		if (!$res || !da_sql_affected_rows($link,$res,$config)){
325 richard 30
			echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
31
			$da_abort=1;
32
		}
1805 clement.si 33
		if ($config['sql_use_user_info_table'] == 'true' && !$da_abort){
34
			$res = da_sql_query($link,$config,
325 richard 35
			"SELECT username FROM $config[sql_user_info_table] WHERE
36
			username = '$login';");
37
			if ($res){
1805 clement.si 38
				if (!da_sql_num_rows($res,$config)){
39
					$Fcn = (isset($Fcn)) ? da_sql_escape_string($link, $Fcn) : '';
40
					$Fmail = (isset($Fmail)) ? da_sql_escape_string($link, $Fmail) : '';
41
					$Fou = (isset($Fou)) ? da_sql_escape_string($link, $Fou) : '';
42
					$Fhomephone = (isset($Fhomephone)) ? da_sql_escape_string($link, $Fhomephone) : '';
43
					$Ftelephonenumber = (isset($Ftelephonenumber)) ? da_sql_escape_string($link, $Ftelephonenumber) : '';
44
					$Fmobile = (isset($Fmobile)) ? da_sql_escape_string($link, $Fmobile) : '';
45
					$res = da_sql_query($link,$config,
325 richard 46
					"INSERT INTO $config[sql_user_info_table]
47
					(username,name,mail,department,homephone,workphone,mobile) VALUES
48
					('$login','$Fcn','$Fmail','$Fou','$Fhomephone','$Ftelephonenumber','$Fmobile');");
1805 clement.si 49
					if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 50
						echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
51
				}
52
				else
53
					echo "<b>Cet usager existe d&eacute;j&agrave; dans la table 'info'</b><br>\n";
54
			}
55
			else
56
				echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
57
		}
1805 clement.si 58
		if (isset($Fgroup) && $Fgroup != ''){
59
			$Fgroup = da_sql_escape_string($link, $Fgroup);
60
			$res = da_sql_query($link,$config,
325 richard 61
			"SELECT username FROM $config[sql_usergroup_table]
62
			WHERE username = '$login' AND groupname = '$Fgroup';");
63
			if ($res){
1805 clement.si 64
				if (!da_sql_num_rows($res,$config)){
65
					$res = da_sql_query($link,$config,
325 richard 66
					"INSERT INTO $config[sql_usergroup_table]
67
					(username,groupname) VALUES ('$login','$Fgroup');");
1805 clement.si 68
					if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 69
						echo "<b>Could not add user to group $Fgroup. SQL Error</b><br>\n";
70
				}
71
				else
72
					echo "<b>User already is a member of group $Fgroup</b><br>\n";
73
			}
74
			else
75
				echo "<b>Could not add user to group $Fgroup: " . da_sql_error($link,$config) . "</b><br>\n";
76
		}
77
		if (!$da_abort){
1805 clement.si 78
			if (isset($Fgroup) && $Fgroup != '')
325 richard 79
				require('../lib/defaults.php');
80
			foreach($show_attrs as $key => $attr){
81
				if ($attrmap["$key"] == 'none')
82
					continue;
1377 richard 83
				if ($key == "Filter-Id" && $$attrmap["$key"] == "None")
84
					continue;
325 richard 85
				if ($attrmap["$key"] == ''){
86
					$attrmap["$key"] = $key;
87
					$attr_type["$key"] = 'replyItem';
88
					$rev_attrmap["$key"] = $key;
89
				}
1805 clement.si 90
				if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
325 richard 91
					$table = "$config[sql_check_table]";
92
					$type = 1;
93
				}
1805 clement.si 94
				else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
325 richard 95
					$table = "$config[sql_reply_table]";
96
					$type = 2;
97
				}
1805 clement.si 98
				$val = (isset($$attrmap["$key"])) ? $$attrmap["$key"] : '';
509 richard 99
				/*Ajout en vue de l'impression des données (thank's to Geoffroy MUSITELLI)*/
508 richard 100
				if($key == "Session-Timeout") $sto_imp = $val;
901 richard 101
				if($key == "Max-All-Session") $mas_imp = $val;
508 richard 102
				if($key == "Max-Daily-Session") $mds_imp = $val;
103
				if($key == "Max-Monthly-Session") $mms_imp = $val;
104
				/*Fin Ajout*/
1805 clement.si 105
				$val = da_sql_escape_string($link, $val);
325 richard 106
				$op_name = $attrmap["$key"] . '_op';
1805 clement.si 107
				$op_val = (isset($$op_name)) ? $$op_name : '';
325 richard 108
				if ($op_val != ''){
1805 clement.si 109
					$op_val = da_sql_escape_string($link, $op_val);
325 richard 110
					if (check_operator($op_val,$type) == -1){
111
						echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
508 richard 112
						continue;
325 richard 113
					}
114
					$op_val2 = ",'$op_val'";
115
				}
1805 clement.si 116
				$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
117
				if ($val == '' || $chkdef)
325 richard 118
					continue;
1805 clement.si 119
				$sqlquery = "INSERT INTO $table (attribute,value,username $text)
120
					VALUES ('$attrmap[$key]','$val','$login' $op_val2);";
121
				$res = da_sql_query($link,$config,$sqlquery);
122
				if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 123
					echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
124
			}
125
		}
126
		echo "<b>Usager correctement cr&eacute;&eacute;</b><br>\n";
127
	}
128
	else
129
		echo "<b>Could not open encryption library file</b><br>\n";
130
}
131
else
132
	echo "<b>Could not connect to SQL database</b><br>\n";
133
?>