Exemplo n.º 1
0
 function HTTP_PUT()
 {
     global $arrConf;
     $jsonObject = new PaloSantoJSON();
     if (!$this->isSuperAdmin()) {
         $this->invalidCredentials($jsonObject);
         return $jsonObject->createJSON();
     }
     $this->setSession();
     if (!$this->validateContentType($jsonObject)) {
         return $jsonObject->createJSON();
     }
     $validOrgs = array();
     $domainOrgs = array();
     if (is_array($this->arrIdOrgs)) {
         foreach ($this->arrIdOrgs as $idOrg) {
             if ($this->validateIdOrg($idOrg) && $idOrg != "1") {
                 $validOrgs[] = $idOrg;
             } elseif (preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $idOrg)) {
                 $domainOrgs[] = $idOrg;
             }
         }
     } else {
         $this->methodNoAllowed(array("GET"));
         exit;
     }
     $putvars = $state = null;
     parse_str(file_get_contents('php://input'), $putvars);
     if (isset($putvars["state"])) {
         if ($putvars["state"] == "suspend" || $putvars["state"] == "unsuspend" || $putvars["state"] == "terminate") {
             $state = $putvars["state"];
         }
     }
     if (is_null($state)) {
         $this->errMsg = "Field state bad value. Supported values are (suspend|unsuspend|terminate)";
         $this->badRequest($jsonObject);
         return $jsonObject->createJSON();
     }
     $pOrg = new paloSantoOrganization($arrConf['elastix_dsn']["elastix"]);
     if (count($domainOrgs) > 0) {
         foreach ($domainOrgs as $domain) {
             $result = $pOrg->getIdOrgByDomain($domain);
             if ($result != false) {
                 $validOrgs = $result["id"];
             }
         }
     }
     if (count($validOrgs) == 0) {
         //ningun id pasado en la peticion es valido. Devolvemos 404 not found
         $this->resourceNotExis($jsonObject);
         return $jsonObject->createJSON();
     }
     if ($pOrg->getbunchOrganizationState($validOrgs) == false) {
         $this->resourceNotExis($jsonObject);
         return $jsonObject->createJSON();
     }
     $result = $pOrg->changeStateOrganization($validOrgs, $state);
     if ($result == false) {
         $this->error = $pOrg->errMsg;
         $this->errSever($jsonObject);
         return $jsonObject->createJSON();
     } else {
         header('HTTP/1.1 200 Ok');
         $jsonObject->set_status("OK");
         $jsonObject->set_message("State of request organizations have been updated successfully");
         return $jsonObject->createJSON();
     }
 }