2019-08-31 11:31:29 +02:00
|
|
|
#!/usr/bin/php
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
require("session_init.php");
|
|
|
|
require("config.inc.php");
|
|
|
|
require("log.php");
|
|
|
|
require("db.class.php");
|
|
|
|
|
2019-08-31 15:37:11 +02:00
|
|
|
function esp( $s )
|
|
|
|
{
|
|
|
|
$s = " $s ";
|
|
|
|
return $s;
|
|
|
|
}
|
2019-09-01 15:50:19 +02:00
|
|
|
|
2019-09-03 00:49:07 +02:00
|
|
|
function concat ($a, $b)
|
|
|
|
{
|
2019-09-03 00:53:50 +02:00
|
|
|
if ( !empty($a) && !empty($b) )
|
2019-09-03 00:49:07 +02:00
|
|
|
{
|
|
|
|
$r = $a . " " . $b;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
$r = $a . $b;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
$flag = 0;
|
2019-09-03 01:08:35 +02:00
|
|
|
$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"));
|
2019-09-03 00:49:07 +02:00
|
|
|
|
2019-08-31 12:41:48 +02:00
|
|
|
$doldb = new db("dolibarr");
|
|
|
|
$ncdb = new db("nextcloud");
|
2019-09-03 00:57:47 +02:00
|
|
|
|
2019-12-01 00:47:55 +01:00
|
|
|
$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");
|
2019-09-03 00:57:47 +02:00
|
|
|
//print_r ($ncdb);
|
2019-08-31 17:37:23 +02:00
|
|
|
while ($user = $doldb->result->fetch_assoc())
|
2019-08-31 16:13:31 +02:00
|
|
|
{
|
2019-09-03 02:04:45 +02:00
|
|
|
//$flag+=1;
|
2019-11-30 00:55:06 +01:00
|
|
|
$insert = false;
|
2019-11-30 00:30:43 +01:00
|
|
|
if ($user["fk_user_valid"] == null) $user["fk_user_valid"] = 0;
|
2019-08-31 18:00:13 +02:00
|
|
|
$ncdb->query("SELECT uid FROM oc_accounts WHERE uid='" . $user["login"] . "'");
|
2019-08-31 18:03:21 +02:00
|
|
|
echo "login:" . ($user["login"]) . EOL;
|
2019-08-31 17:54:17 +02:00
|
|
|
if ( $ncdb->result->num_rows != 0 )
|
2019-08-31 17:37:23 +02:00
|
|
|
{
|
2019-12-01 00:47:55 +01:00
|
|
|
// L'utilisateur existe déjà, on ne le crée pas, mais on vérifie sa validité et si il est à jour de cotisation.
|
2019-08-31 17:46:12 +02:00
|
|
|
$ncuser = $ncdb->result->fetch_assoc();
|
2019-08-31 18:13:04 +02:00
|
|
|
echo "uid:" . $ncuser["uid"] . "existe" . EOL;
|
2019-11-30 00:15:37 +01:00
|
|
|
$ncdb->query("SELECT configvalue FROM oc_preferences WHERE userid='" . $user["login"] . "' AND appid='core' AND configkey='enabled'");
|
2019-11-30 00:04:49 +01:00
|
|
|
if ( $ncdb->result->num_rows != 0 )
|
|
|
|
{
|
2019-12-01 00:47:55 +01:00
|
|
|
// le validité de l'utilisateur est définie
|
2019-11-30 01:04:30 +01:00
|
|
|
$r = $ncdb->result->fetch_assoc();
|
2019-11-30 00:17:53 +01:00
|
|
|
$status = $r["configvalue"] ;
|
2019-11-30 00:04:49 +01:00
|
|
|
}else
|
|
|
|
{
|
2019-12-01 00:47:55 +01:00
|
|
|
// 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
|
2019-11-30 00:04:49 +01:00
|
|
|
$status = 1;
|
|
|
|
}
|
|
|
|
if ( $user["fk_user_valid"] != $status )
|
|
|
|
{
|
2019-12-01 00:47:55 +01:00
|
|
|
// 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"] );
|
|
|
|
}
|
|
|
|
// vérification si l'utilisateur est à jour de cotisation
|
|
|
|
$datefin = DateTime::createFromFormat("Y-m-d H:i:s", $user['datefin']);
|
|
|
|
$interval = new DateInterval('P0000Y02M00D');
|
|
|
|
$datefin->add($interval);
|
|
|
|
if ( $datefin->getTimestamp() <= mktime() )
|
|
|
|
{
|
|
|
|
echo "write_status( $insert, $user['login'], 0 )";
|
|
|
|
}elseif ( $status == 0 )
|
|
|
|
{
|
|
|
|
// ré active l'utlisateur désactivé à jour de cotisation.
|
|
|
|
echo "write_status( $insert, $user['login'], 1 )";
|
2019-11-30 00:04:49 +01:00
|
|
|
}
|
2019-08-31 18:06:39 +02:00
|
|
|
}else
|
|
|
|
{
|
2019-08-31 23:59:24 +02:00
|
|
|
//echo $user["login"] . " n'existe pas";
|
2019-08-31 19:03:27 +02:00
|
|
|
if ( empty($user["phone_mobile"]) )
|
|
|
|
{
|
2019-09-03 00:49:07 +02:00
|
|
|
$data["phone"]["value"] = $user["phone_perso"];
|
2019-08-31 19:03:27 +02:00
|
|
|
}else
|
|
|
|
{
|
2019-09-03 00:49:07 +02:00
|
|
|
$data["phone"]["value"] = $user["phone_mobile"];
|
2019-08-31 19:03:27 +02:00
|
|
|
}
|
2019-09-02 23:22:45 +02:00
|
|
|
|
2019-09-03 02:34:21 +02:00
|
|
|
$data["displayname"]["value"] = addslashes(concat(utf8_encode($user["firstname"]), utf8_encode($user["lastname"])));
|
2019-09-03 01:35:53 +02:00
|
|
|
$address = concat(utf8_encode($user['address']), $user["zip"]);
|
2019-09-03 02:37:37 +02:00
|
|
|
$data["address"]["value"] = (concat ($address, utf8_encode($user["town"])));
|
2019-09-03 00:49:07 +02:00
|
|
|
$data["email"]["value"] = $user["email"];
|
2019-09-03 01:26:26 +02:00
|
|
|
print_r($data);
|
2019-11-30 00:55:06 +01:00
|
|
|
if ( ($account_data = json_encode($data)) == false )
|
2019-09-03 01:26:26 +02:00
|
|
|
{
|
|
|
|
echo json_last_error();
|
2019-09-03 01:27:43 +02:00
|
|
|
exit (0);
|
2019-09-03 01:26:26 +02:00
|
|
|
}
|
2019-09-03 00:49:07 +02:00
|
|
|
|
2019-09-03 02:39:37 +02:00
|
|
|
$oc_account_query = 'INSERT INTO oc_accounts (uid, data) VALUES ("' . $user["login"] . '","' . addslashes($account_data) .'")';
|
2019-09-03 02:34:21 +02:00
|
|
|
$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"]) . '")';
|
2019-08-31 23:59:24 +02:00
|
|
|
|
|
|
|
if ($user["fk_adherent_type"] == 2)
|
|
|
|
{
|
|
|
|
$gid="membres";
|
|
|
|
}else if ($user["fk_adherent_type"] == 3)
|
|
|
|
{
|
|
|
|
$gid="contributeurs";
|
|
|
|
}
|
|
|
|
|
2019-09-01 00:09:43 +02:00
|
|
|
$oc_group_user_query = "INSERT INTO oc_group_user(uid, gid) VALUES ('" . $user["login"] . "','" . $gid . "')";
|
2019-09-01 00:57:33 +02:00
|
|
|
|
2019-09-02 22:57:35 +02:00
|
|
|
$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"] . "')";
|
2019-09-02 22:31:48 +02:00
|
|
|
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;
|
2019-09-03 01:38:20 +02:00
|
|
|
|
2019-11-06 19:03:38 +01:00
|
|
|
if ($ncdb->query($oc_account_query))
|
2019-09-01 00:33:53 +02:00
|
|
|
{
|
2019-09-01 15:48:24 +02:00
|
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
2019-09-01 00:33:53 +02:00
|
|
|
}
|
2019-09-03 01:51:01 +02:00
|
|
|
if (!$ncdb->query($oc_users_query))
|
2019-09-01 00:33:53 +02:00
|
|
|
{
|
2019-09-01 15:48:24 +02:00
|
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
2019-09-01 00:33:53 +02:00
|
|
|
}
|
2019-09-03 01:51:01 +02:00
|
|
|
if (!$ncdb->query($oc_group_user_query))
|
2019-09-01 00:33:53 +02:00
|
|
|
{
|
2019-09-01 15:48:24 +02:00
|
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
2019-09-01 00:33:53 +02:00
|
|
|
}
|
2019-09-03 01:51:01 +02:00
|
|
|
if (!$ncdb->query($oc_preferences_query_quota))
|
2019-09-02 22:31:48 +02:00
|
|
|
{
|
|
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
|
|
|
}
|
2019-09-03 01:51:01 +02:00
|
|
|
if (!$ncdb->query($oc_preferences_query_email))
|
2019-09-02 22:31:48 +02:00
|
|
|
{
|
|
|
|
echo "Echec lors de la requete : (" . $ncdb->connect->errno . ") " . $ncdb->connect->error;
|
2019-09-03 01:38:20 +02:00
|
|
|
}
|
2019-08-31 19:06:43 +02:00
|
|
|
}
|
2019-09-03 01:08:35 +02:00
|
|
|
//$ncdb->result->close();
|
2019-09-03 02:04:45 +02:00
|
|
|
//if ($flag > 12) exit;
|
2019-08-31 16:13:31 +02:00
|
|
|
}
|
2019-09-03 01:08:35 +02:00
|
|
|
//$doldb->result->close();
|
2019-12-01 00:47:55 +01:00
|
|
|
function write_status( $insert, $uid, $status )
|
|
|
|
{
|
|
|
|
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'" ;
|
|
|
|
|
|
|
|
}
|
|
|
|
$ncdb->query( $query );
|
|
|
|
echo $query;
|
|
|
|
}
|
2019-08-31 11:31:29 +02:00
|
|
|
?>
|