From 956ed5d973d11fc145e79398e225f2ae1195c270 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Sun, 1 Dec 2019 00:47:55 +0100 Subject: [PATCH] =?UTF-8?q?verification=20utilisateur=20=C3=A0=20jour=20de?= =?UTF-8?q?=20cotisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nconnector.php | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/nconnector.php b/nconnector.php index 594437e..15d59c3 100755 --- a/nconnector.php +++ b/nconnector.php @@ -31,7 +31,7 @@ $data = array("displayname"=>array("value"=>"","scope"=>"contacts","verified"=>" $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 FROM llx_adherent"); +$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()) { @@ -42,32 +42,38 @@ while ($user = $doldb->result->fetch_assoc()) 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 { - $insert = true; + // 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 ) { - echo "\ndifférent\n##############################\n" . $user['fk_user_valid'] . "!=" . $status . "\n"; - if ( $insert ) - { - $query = "INSERT INTO oc_preferences (userid, appid, configkey, configvalue) VALUES ( '" . $ncuser["uid"] . "', 'core', 'enabled', '" . ($user["fk_user_valid"]==1?"true":"false") . "' ) "; - }else - { - $query = "UPDATE oc_preferences SET configvalue = '" . $user["fk_user_valid"] ."' WHERE userid='" . $user["login"] . "' AND appid='core' AND configkey='enabled'" ; - - } - $ncdb->query( $query ); - echo $query; + // 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 )"; } }else { @@ -133,4 +139,17 @@ while ($user = $doldb->result->fetch_assoc()) //if ($flag > 12) exit; } //$doldb->result->close(); +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; +} ?>