Rev 1377 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log
<?php
require_once('../lib/functions.php');
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
else{
echo "<b>Could not include SQL library</b><br>\n";
exit();
}
if ($config['sql_use_operators'] == 'true'){
include_once("../lib/operators.php");
$text = ',op';
$passwd_op = ",':='";
}
$da_abort=0;
$op_val2 = '';
$link = da_sql_pconnect($config);
if ($link){
$Members = preg_split("/[\n\s]+/",$members,-1,PREG_SPLIT_NO_EMPTY);
if (!empty($Members)){
foreach ($Members as $member){
$member = da_sql_escape_string($link, $member);
$res = da_sql_query($link,$config,
"INSERT INTO $config[sql_usergroup_table] (username,groupname)
VALUES ('$member','$login');");
if (!$res || !da_sql_affected_rows($link,$res,$config)){
echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
$da_abort=1;
}
}
}
else
{
$res = da_sql_query($link,$config,
"INSERT INTO $config[sql_usergroup_table] (username,groupname)
VALUES ('$login','$login');");
if (!$res || !da_sql_affected_rows($link,$res,$config))
{
echo "<b>Unable to add user $member in group $login: " . da_sql_error($link,$config) . "</b><br>\n";
$da_abort=1;
}
else
{
echo "<b>Un groupe ne pouvant être vide, l'usager '$login' a été créé (usager virtuel)<br>";
}
}
if (!$da_abort)
{
foreach($show_attrs as $key => $attr){
if ($attrmap["$key"] == 'none')
continue;
if ($key == "Filter-Id" && $$attrmap["$key"] == "None")
continue;
if ($attrmap["$key"] == ''){
$attrmap["$key"] = $key;
$attr_type["$key"] = 'replyItem';
$rev_attrmap["$key"] = $key;
}
if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
$table = "$config[sql_groupcheck_table]";
$type = 1;
}
else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
$table = "$config[sql_groupreply_table]";
$type = 2;
}
$val = $$attrmap["$key"];
$val = da_sql_escape_string($link, $val);
$op_name = $attrmap["$key"] . '_op';
$op_val = $$op_name;
if ($op_val != ''){
$op_val = da_sql_escape_string($link, $op_val);
if (check_operator($op_val,$type) == -1){
echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
coninue;
}
$op_val2 = ",'$op_val'";
}
$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
if ($val == '' || $chkdef)
continue;
$res = da_sql_query($link,$config,
"INSERT INTO $table (attribute,value,groupname $text)
VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
if (!$res || !da_sql_affected_rows($link,$res,$config))
echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
}
echo "<b>Le groupe $login a été correctement créé</b><br>\n";
}
}
else
echo "<b>Could not connect to SQL database</b><br>\n";
?>