function change_state($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials) { $jsonObject = new PaloSantoJSON(); $idOrgs = getParameter("idOrgs"); $state = getParameter("state"); if ($credentials['userlevel'] != "superadmin") { $jsonObject->set_error(_tr("You are not authorized to perform this action")); return $jsonObject->createJSON(); } $arrOrgs = array_diff(explode(",", $idOrgs), array("")); if (!is_array($arrOrgs) || count($arrOrgs) == 0) { $jsonObject->set_error(_tr("Err: Any valid organization has been selected")); return $jsonObject->createJSON(); } $pOrg = new paloSantoOrganization($pDB); if ($pOrg->changeStateOrganization($arrOrgs, $state)) { $jsonObject->set_message(_tr("State of selected organizations have been updated successfully")); } else { $jsonObject->set_error($pOrg->errMsg); } return $jsonObject->createJSON(); }
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(); } }