161 lines
5.8 KiB
PHP
Executable File
161 lines
5.8 KiB
PHP
Executable File
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
require("session_init.php");
|
|
require("config.inc.php");
|
|
require("log.php");
|
|
require("db.class.php");
|
|
|
|
function esp( $s )
|
|
{
|
|
$s = " $s ";
|
|
return $s;
|
|
}
|
|
|
|
function concat ($a, $b)
|
|
{
|
|
if ( !empty($a) && !empty($b) )
|
|
{
|
|
$r = $a . " " . $b;
|
|
}else
|
|
{
|
|
$r = $a . $b;
|
|
}
|
|
return $r;
|
|
}
|
|
|
|
$flag = 0;
|
|
$data = array("displayname"=>array("value"=>"","scope"=>"contacts","verified"=>"0"),"address"=>array("value"=>"[adresse]","scope"=>"private","verified"=>"0"),"website"=>array("value"=>"","scope"=>"private","verified"=>"0"),"email"=>array("value"=>"","scope"=>"contacts","verified"=>"1"),"avatar"=>array("scope"=>"contacts","verified"=>"0"),"phone"=>array("value"=>"","scope"=>"private","verified"=>"0"),"twitter"=>array("value"=>"","scope"=>"private","verified"=>"0"));
|
|
|
|
$doldb = new db("dolibarr");
|
|
$ncdb = new db("nextcloud");
|
|
|
|
$doldb->query("SELECT login, firstname, lastname, pass_crypted, fk_adherent_type, address, email, phone_perso, phone_mobile, zip, town, fk_user_valid, datefin FROM llx_adherent");
|
|
//print_r ($ncdb);
|
|
while ($user = $doldb->result->fetch_assoc())
|
|
{
|
|
//$flag+=1;
|
|
$insert = false;
|
|
if ($user["fk_user_valid"] == null) $user["fk_user_valid"] = 0;
|
|
$ncdb->query("SELECT uid FROM oc_accounts WHERE uid='" . $user["login"] . "'");
|
|
echo "login:" . ($user["login"]) . EOL;
|
|
if ( $ncdb->result->num_rows != 0 )
|
|
{
|
|
// L'utilisateur existe déjà, on ne le crée pas, mais on vérifie sa validité et si il est à jour de cotisation.
|
|
$ncuser = $ncdb->result->fetch_assoc();
|
|
echo "uid:" . $ncuser["uid"] . " existe" . EOL;
|
|
$ncdb->query("SELECT configvalue FROM oc_preferences WHERE userid='" . $user["login"] . "' AND appid='core' AND configkey='enabled'");
|
|
if ( $ncdb->result->num_rows != 0 )
|
|
{
|
|
// le validité de l'utilisateur est définie
|
|
$r = $ncdb->result->fetch_assoc();
|
|
$status = $r["configvalue"] ;
|
|
}else
|
|
{
|
|
// pas de définition de la validité de l'utilisateur => par défaut utilisateur valide
|
|
$insert = true; // insertion de la validité dans la table préférence
|
|
$status = 1;
|
|
}
|
|
if ( $user["fk_user_valid"] != $status )
|
|
{
|
|
// différence entre nexcloud et dolibarr
|
|
// echo "\ndifférent\n##############################\n" . $user['fk_user_valid'] . "!=" . $status . "\n";
|
|
write_status( $insert, $user["login"], $user["fk_user_valid"], $ncdb );
|
|
}
|
|
// vérification si l'utilisateur est à jour de cotisation
|
|
if( !empty($datefin) )
|
|
{
|
|
$datefin = DateTime::createFromFormat("Y-m-d H:i:s", $user['datefin']);
|
|
$interval = new DateInterval('P0000Y02M00D');
|
|
|
|
$datefin->add($interval);
|
|
print_r($datefin);
|
|
if ( $datefin->getTimestamp() <= time() )
|
|
{
|
|
write_status( $insert, " . $user['login'] . ", 0, $ncdb );
|
|
}elseif ( $status == 0 )
|
|
{
|
|
// ré active l'utlisateur désactivé à jour de cotisation.
|
|
write_status( $insert, " . $user['login'] . ", 1, $ncdb );
|
|
}
|
|
}
|
|
}else
|
|
{
|
|
//echo $user["login"] . " n'existe pas";
|
|
if ( empty($user["phone_mobile"]) )
|
|
{
|
|
$data["phone"]["value"] = $user["phone_perso"];
|
|
}else
|
|
{
|
|
$data["phone"]["value"] = $user["phone_mobile"];
|
|
}
|
|
|
|
$data["displayname"]["value"] = addslashes(concat(utf8_encode($user["firstname"]), utf8_encode($user["lastname"])));
|
|
$address = concat(utf8_encode($user['address']), $user["zip"]);
|
|
$data["address"]["value"] = (concat ($address, utf8_encode($user["town"])));
|
|
$data["email"]["value"] = $user["email"];
|
|
print_r($data);
|
|
if ( ($account_data = json_encode($data)) == false )
|
|
{
|
|
echo json_last_error();
|
|
exit (0);
|
|
}
|
|
|
|
$oc_account_query = 'INSERT INTO oc_accounts (uid, data) VALUES ("' . $user["login"] . '","' . addslashes($account_data) .'")';
|
|
$oc_users_query = 'INSERT INTO oc_users (uid, displayname, password, uid_lower) VALUES ("' . $user["login"] . '","' . $user["firstname"] . ' ' . $user["lastname"] . '","1|' . $user["pass_crypted"] . '","' . strtolower($user["login"]) . '")';
|
|
|
|
if ($user["fk_adherent_type"] == 2)
|
|
{
|
|
$gid="membres";
|
|
}else if ($user["fk_adherent_type"] == 3)
|
|
{
|
|
$gid="contributeurs";
|
|
}
|
|
|
|
$oc_group_user_query = "INSERT INTO oc_group_user(uid, gid) VALUES ('" . $user["login"] . "','" . $gid . "')";
|
|
|
|
$oc_preferences_query_quota = "INSERT INTO oc_preferences(userid, appid, configkey, configvalue) VALUES ('" . $user["login"] . "', 'files', 'quota', '10 GB')";
|
|
$oc_preferences_query_email = "INSERT INTO oc_preferences(userid, appid, configkey, configvalue) VALUES ('" . $user["login"] . "', 'settings', 'email', '" . $user["email"] . "')";
|
|
echo $account_data . EOL . $oc_account_query . EOL . $oc_users_query .EOL . $oc_group_user_query . EOL . $oc_preferences_query_quota . EOL . $oc_preferences_query_email . EOL;
|
|
|
|
if ($ncdb->query($oc_account_query))
|
|
{
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
}
|
|
if (!$ncdb->query($oc_users_query))
|
|
{
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
}
|
|
if (!$ncdb->query($oc_group_user_query))
|
|
{
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
}
|
|
if (!$ncdb->query($oc_preferences_query_quota))
|
|
{
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
}
|
|
if (!$ncdb->query($oc_preferences_query_email))
|
|
{
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
}
|
|
}
|
|
//$ncdb->result->close();
|
|
//if ($flag > 12) exit;
|
|
}
|
|
//$doldb->result->close();
|
|
function write_status( $insert, $uid, $status, $db )
|
|
{
|
|
if ( $insert )
|
|
{
|
|
$query = "INSERT INTO oc_preferences (userid, appid, configkey, configvalue) VALUES ( '" . $uid . "', 'core', 'enabled', '" . ($status==1?"true":"false") . "' ) ";
|
|
}else
|
|
{
|
|
$query = "UPDATE oc_preferences SET configvalue = '" . ($status==1?"true":"false") ."' WHERE userid='" . $uid . "' AND appid='core' AND configkey='enabled'" ;
|
|
|
|
}
|
|
$db->query( $query );
|
|
echo $query;
|
|
}
|
|
?>
|