/**
  * Plug-in pour creation de comptes CAS
  */
 function main($content, $conf)
 {
     $this->conf = $conf;
     $this->pi_setPiVarDefaults();
     $this->pi_USER_INT_obj = 1;
     // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
     $this->pi_loadLL();
     $this->ldapParam = array('server' => "10.211.162.20", 'port' => "10389", 'basedn' => "ou=utilisateurs,dc=haras-nationaux-dev,dc=fr");
     session_start();
     $content = '';
     if (!isset($this->piVars["action"])) {
         $content = $this->getFormulaireVide();
     } else {
         if (isset($this->piVars["action"]) && $this->piVars["action"] == "insert") {
             if (!$this->checkLogin($this->piVars["login"])) {
                 $content = '<h3>' . nl2br(htmlspecialchars($this->pi_getLL("error_login_format"))) . '<br/></h3>';
                 $content .= $this->getFormulaireVide();
                 return $this->pi_wrapInBaseClass($content);
             }
             if ($this->piVars["action"] == "" || $this->piVars["login"] == "" || $this->piVars["passwd1"] == "" || $this->piVars["passwd2"] == "") {
                 $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_missing_field")) . '<br/></h3>';
                 $content .= $this->getFormulaireVide();
             } else {
                 if (!$this->checkLogin($this->piVars["login"])) {
                     $content = '<h3>' . nl2br(htmlspecialchars($this->pi_getLL("error_login_format"))) . '<br/></h3>';
                     $content .= $this->getFormulaireVide();
                 } else {
                     if (strlen($this->piVars["passwd1"]) < 6 || strlen($this->piVars["login"]) < 6) {
                         $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_min_field")) . '<br/></h3>';
                         $content .= $this->getFormulaireVide();
                     } else {
                         if ($this->piVars["passwd1"] != $this->piVars["passwd2"]) {
                             $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_passwd_not_match")) . '<br/></h3>';
                             $content .= $this->getFormulaireVide();
                         } else {
                             $ws = new WebservicesCompte($this->typeExecution);
                             if (!$ws->connectServices()) {
                                 $content = "ERROR:" . $ws->getErrorMessage();
                             } else {
                                 if ($this->loginExistinLdap($this->piVars["login"])) {
                                     $content = $this->errorLoginExiste();
                                 } else {
                                     $md5 = "{MD5}" . base64_encode(mhash(MHASH_MD5, $this->piVars["passwd1"]));
                                     //$md5 = $this->piVars["passwd1"];
                                     $param = array("in0" => $this->piVars["login"], "in1" => $md5, "in2" => "");
                                     $result = $ws->createCompte($param)->out;
                                     if ($ws->getErrorMessage() != "") {
                                         $content = '<font color="red">' . $ws->getErrorMessage . '</font><br/>';
                                     }
                                     if ($result == "0" || $result == "") {
                                         $content = $this->success();
                                     } else {
                                         if ($result == "1945") {
                                             $content = $this->errorLoginExiste();
                                         } else {
                                             if ($result == "1944") {
                                                 $content = "ERREUR SERVEUR LOGIN ET OU MOT DE PASSE VIDENT<br/>";
                                                 /*$content.="--------TRACE-------<br/>";
                                                 		$content.="login:"******"login"]."<br/>";
                                                 		$content.="passwd:".$this->piVars["passwd1"]."<br/>";
                                                 		$content.="passwd_md5:".$md5."<br/>";
                                                 		$content.="resultat du WS:".$result["createCompteCasForPortailReturn"];*/
                                             } else {
                                                 $content = "ERREUR INCONNUE" . $result . ":<br/>";
                                                 /*$content.="--------TRACE-------<br/>";
                                                 		$content.="login:"******"login"]."<br/>";
                                                 		$content.="passwd:".$this->piVars["passwd1"]."<br/>";
                                                 		$content.="passwd_md5:".$md5."<br/>";
                                                 		$content.="resultat du WS:".$result["createCompteCasForPortailReturn"];*/
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $content = "<h1>error</h1>";
         }
     }
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * Plug-in pour modification du mot de passe pour CAS
  */
 function main($content, $conf)
 {
     $this->conf = $conf;
     $this->pi_setPiVarDefaults();
     $this->pi_USER_INT_obj = 1;
     // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
     $this->pi_loadLL();
     session_start();
     $content = '';
     if (!isset($this->piVars["action"])) {
         $content = $this->getFormulaireVide();
     } else {
         if (isset($this->piVars["action"]) && $this->piVars["action"] == "insert") {
             if ($this->piVars["passwd_old"] == "" || $this->piVars["login"] == "" || $this->piVars["passwd1"] == "" || $this->piVars["passwd2"] == "") {
                 $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_missing_field")) . '<br/></h3>';
                 $content .= $this->getFormulaireVide();
             } else {
                 if (strlen($this->piVars["passwd1"]) < 6 || strlen($this->piVars["login"]) < 6) {
                     $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_min_field")) . '<br/></h3>';
                     $content .= $this->getFormulaireVide();
                 } else {
                     if ($this->piVars["passwd1"] != $this->piVars["passwd2"]) {
                         $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_passwd_not_match")) . '<br/></h3>';
                         $content .= $this->getFormulaireVide();
                     } else {
                         $param = array("in0" => $this->piVars["login"], "in1" => null);
                         $ws = new WebservicesCompte($this->typeExecution);
                         if (!$ws->connectIdent()) {
                             $content = "ERROR:" . $ws->getErrorMessage();
                             return $content;
                         }
                         $personne = $ws->getPersonneByLogin($param)->out;
                         /**
                          * Si ancien mot de passe saisi == mot de passe BDD alors on traite la demande
                          */
                         //print_r($personne);
                         $old_md5 = "{MD5}" . base64_encode(mhash(MHASH_MD5, $this->piVars["passwd_old"]));
                         $new_md5 = "{MD5}" . base64_encode(mhash(MHASH_MD5, $this->piVars["passwd1"]));
                         //echo "CID:".$personne["findPersonneByLoginReturn"]["password"]."<br/>";
                         //echo "portail:".$old_md5."<br/>";
                         if ($personne->password == $old_md5) {
                             $paramUpdate = array("in0" => $this->piVars["login"], "in1" => $new_md5, "in2" => null);
                             $wsUpdate = new WebservicesCompte($this->typeExecution);
                             if (!$wsUpdate->connectServices()) {
                                 $content = "ERROR:" . $ws->getErrorMessage();
                             } else {
                                 $result = $wsUpdate->updateCompte($paramUpdate)->out;
                                 if ($result == "0" || $result == "") {
                                     $this->sendMail($personne->coordonnees->email, $personne, $this->piVars["passwd1"]);
                                     $content = $this->success();
                                 } else {
                                     if ($result == "1947") {
                                         $content = $this->errorLoginExiste();
                                     } else {
                                         if ($result == "1946") {
                                             $content = "ERREUR SERVEUR<br/>";
                                             /*$content.="--------TRACE-------<br/>";
                                             		$content.="login:"******"login"]."<br/>";
                                             		$content.="passwd:".$this->piVars["passwd1"]."<br/>";
                                             		$content.="md5".$new_md5."<br/>";
                                             		$content.="resultat du WS:".$result["createCompteCasForPortailReturn"];*/
                                         }
                                     }
                                 }
                             }
                         } else {
                             $content = $this->errorLoginExiste();
                         }
                     }
                 }
             }
         } else {
             $content = "<h1>error</h1>";
         }
     }
     return $this->pi_wrapInBaseClass($content);
 }
 /**
  * Plug-in pour modification du mot de passe pour CAS
  */
 function main($content, $conf)
 {
     $this->conf = $conf;
     $this->pi_setPiVarDefaults();
     $this->pi_USER_INT_obj = 1;
     // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
     $this->pi_loadLL();
     $content = "";
     if (!isset($this->piVars["action"])) {
         $content = $this->getFormulaireVide();
     } else {
         if (isset($this->piVars["action"]) && $this->piVars["action"] == "calcul") {
             if ($this->piVars["login"] == "") {
                 $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_missing_field")) . '<br/></h3>';
                 $content .= $this->getFormulaireVide();
             }
             if (strlen($this->piVars["login"]) < 5) {
                 $content = '<h3>' . htmlspecialchars($this->pi_getLL("error_min_field")) . '<br/></h3>';
                 $content .= $this->getFormulaireVide();
             } else {
                 $param = array("in0" => $this->piVars["login"], "in1" => null);
                 $ws = new WebservicesCompte($this->typeExecution);
                 if (!$ws->connectIdent()) {
                     $content = "ERROR:" . $ws->getErrorMessage();
                     return $content;
                 }
                 $personne = $ws->getPersonneByLogin($param)->out;
                 if ($personne == "" || $personne == null) {
                     $content = $this->errorLoginExiste();
                 } else {
                     if ($personne->coordonnees->email == "") {
                         $content = $this->errorMailExiste();
                     } else {
                         $pwd = $this->calculPassword();
                         $md5 = "{MD5}" . base64_encode(mhash(MHASH_MD5, $pwd));
                         /**
                          * Mise a jour du compte
                          */
                         $paramUpdate = array("in0" => $personne->login, "in1" => $md5, "in2" => null);
                         $wsUpdate = new WebservicesCompte($this->typeExecution);
                         if (!$wsUpdate->connectServices()) {
                             $content = "ERROR:" . $ws->getErrorMessage();
                         } else {
                             $result = $wsUpdate->updateCompte($paramUpdate)->out;
                             if ($result == "0") {
                                 $this->sendMail($personne->coordonnees->email, $personne, $pwd);
                                 $content = $this->success();
                             } else {
                                 if ($result == "1947") {
                                     $content = $this->errorLoginExiste();
                                 } else {
                                     if ($result == "1946") {
                                         $content = "ERREUR SERVEUR<br/>";
                                         $content .= "login:"******"<br/>";
                                         $content .= "--------TRACE-------<br/>";
                                         $content .= "passwd:" . $pwd . "<br/>";
                                         $content .= "resultat du WS:" . $result;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->pi_wrapInBaseClass($content);
 }