示例#1
0
function saveNewOrganization($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    $pOrganization = new paloSantoOrganization($pDB);
    $arrFormOrgz = createFieldForm();
    $oForm = new paloForm($smarty, $arrFormOrgz);
    $error = "";
    $exito = false;
    if ($credentials['userlevel'] != "superadmin") {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You are not authorized to perform this action"));
        return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    if (!$oForm->validateForm($_POST)) {
        // Validation basic, not empty and VALIDATION_TYPE
        $smarty->assign("mb_title", _tr("Validation Error"));
        $arrErrores = $oForm->arrErroresValidacion;
        $strErrorMsg = "<b>" . _tr("The following fields contain errors") . ":</b><br/>";
        if (is_array($arrErrores) && count($arrErrores) > 0) {
            foreach ($arrErrores as $k => $v) {
                $strErrorMsg .= "{$k} [{$v['mensaje']}], ";
            }
        }
        $smarty->assign("mb_message", $strErrorMsg);
        return viewFormOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $name = trim(getParameter("name"));
        $domain = trim(getParameter("domain"));
        $country = trim(getParameter("country"));
        $state = trim(getParameter("city"));
        $address = trim(getParameter("address"));
        $country_code = trim(getParameter("country_code"));
        $area_code = trim(getParameter("area_code"));
        $quota = trim(getParameter("quota"));
        $email_contact = trim(getParameter("email_contact"));
        $num_user = isset($_POST["max_num_user_chk"]) ? "0" : getParameter("max_num_user");
        $num_exten = isset($_POST["max_num_exten_chk"]) ? "0" : getParameter("max_num_exten");
        $num_queues = isset($_POST["max_num_queues_chk"]) ? "0" : getParameter("max_num_queues");
        if ($country == "0" || !isset($country)) {
            $smarty->assign("mb_title", _tr("Error"));
            $smarty->assign("mb_message", _tr("You must select a country"));
            return viewFormOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
        if (!isset($_POST["max_num_user_chk"]) && (!ctype_digit($num_user) || $num_user + 0 == 0)) {
            $error = _tr("Field ") . _tr("Max. # of User Accounts") . _tr(" must be a integer > 0");
        } else {
            $num_user = $num_user + 0;
        }
        if (!isset($_POST["max_num_exten_chk"]) && (!ctype_digit($num_exten) || $num_exten + 0 == 0)) {
            $error = _tr("Field '") . _tr("Max. # of extensions") . _tr(" must be a integer > 0");
        } elseif ($num_exten < $num_user && $num_exten != 0 || $num_user == 0 && $num_exten != 0) {
            $error = _tr("Field ") . _tr("Max. # of extensions") . _tr(" must be greater than Field ") . _tr("Max. # of User Accounts");
        } else {
            $num_exten = $num_exten + 0;
        }
        if (!isset($_POST["max_num_queues_chk"]) && (!ctype_digit($num_queues) || $num_queues + 0 == 0)) {
            $error = _tr("Field ") . _tr("Max. # of queues") . _tr(" must be a integer > 0");
        } else {
            $num_queues = $num_queues + 0;
        }
        if ($error != "") {
            $smarty->assign("mb_title", _tr("Error"));
            $smarty->assign("mb_message", $error);
            return viewFormOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
        $admin_password = generatePassword();
        $exito = $pOrganization->createOrganization($name, $domain, $country, $state, $address, $country_code, $area_code, $quota, $email_contact, $num_user, $num_exten, $num_queues, $admin_password);
        if ($exito !== false) {
            $smarty->assign("mb_title", _tr("Message"));
            $smarty->assign("mb_message", _tr("The organization was created successfully") . "<br />" . _tr("To admin the new organization login to elastix as admin@") . $domain . $pOrganization->errMsg);
            return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            $smarty->assign("mb_title", _tr("Error"));
            $smarty->assign("mb_message", _tr($pOrganization->errMsg));
            return viewFormOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
    }
}
 function HTTP_POST()
 {
     global $arrConf;
     $jsonObject = new PaloSantoJSON();
     //solo usuario superadmin puede crear una organization
     if (!$this->isSuperAdmin()) {
         $this->invalidCredentials($jsonObject);
         return $jsonObject->createJSON();
     }
     $this->setSession();
     //validamos los parametros pasados en el cuerpo de la peticion
     $arrParam = $this->validateParams();
     if ($arrParam == false) {
         $this->badRequest($jsonObject);
         return $jsonObject->createJSON();
     }
     $pOrg = new paloSantoOrganization($arrConf['elastix_dsn']["elastix"]);
     $idOrg = $pOrg->createOrganization($arrParam["name"], $arrParam["domain"], $arrParam["country"], $arrParam["city"], $arrParam["address"], $arrParam["country_code"], $arrParam["area_code"], $arrParam["quota"], $arrParam["email_contact"], $arrParam["numUser"], $arrParam["numExtensions"], $arrParam["numQueues"], $arrParam["org_user_pswd"]);
     if ($idOrg === false) {
         header("HTTP/1.1 500 Internal Server Error");
         $jsonObject->set_status("ERROR");
         $jsonObject->set_message(array("organization" => false, "user" => false));
         $jsonObject->set_error($pOrg->errMsg);
     } else {
         header('HTTP/1.1 201 Created');
         Header('Location: /rest.php/organization/organization/' . $idOrg);
         $jsonObject->set_status("OK");
         $jsonObject->set_message(array("organization" => true, "user" => true));
     }
     return $jsonObject->createJSON();
 }