Exemple #1
0
function saveNewUser($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $arrCredentiasls)
{
    $pACL = new paloACL($pDB);
    $pORGZ = new paloSantoOrganization($pDB);
    $exito = false;
    $continuar = true;
    $errorImg = "";
    $renameFile = "";
    if ($pORGZ->getNumOrganization(array()) == 0) {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("It's necesary you create a new organization so you can create user"));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    }
    $arrOrgz = array(0 => "Select one Organization");
    if ($arrCredentiasls['userlevel'] == "superadmin") {
        $orgTmp = $pORGZ->getOrganization(array());
    } else {
        $orgTmp = $pORGZ->getOrganization(array("id" => $arrCredentiasls['id_organization']));
    }
    if ($orgTmp === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pORGZ->errMsg));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } elseif (count($orgTmp) == 0) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You need yo have at least one organization created before you can create a user"));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        foreach ($orgTmp as $value) {
            $arrOrgz[$value["id"]] = $value["name"];
        }
    }
    $arrFormOrgz = createFieldForm(array(), array());
    $oForm = new paloForm($smarty, $arrFormOrgz);
    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 viewFormUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        $password1 = getParameter("password1");
        $password2 = getParameter("password2");
        $organization = getParameter("organization");
        if ($password1 == "") {
            $error = _tr("Password can not be empty");
        } else {
            if ($password1 != $password2) {
                $error = _tr("Passwords don't match");
            } else {
                if (!isStrongPassword($password1)) {
                    $error = _tr("Secret can not be empty, must be at least 10 characters, contain digits, uppers and little case letters");
                    $continuar = false;
                }
                if ($arrCredentiasls['userlevel'] == "superadmin") {
                    if ($organization == 0 || $organization == 1) {
                        $error = _tr("You must select a organization");
                        $continuar = false;
                    } else {
                        $idOrganization = $organization;
                    }
                } else {
                    $idOrganization = $arrCredentiasls['id_organization'];
                }
                if ($continuar) {
                    $username = getParameter("username");
                    $name = getParameter("name");
                    $idGrupo = getParameter("group");
                    $extension = getParameter("extension");
                    $fax_extension = getParameter("fax_extension");
                    $md5password = md5($password1);
                    $countryCode = getParameter("country_code");
                    $areaCode = getParameter("area_code");
                    $clidNumber = getParameter("clid_number");
                    $cldiName = getParameter("clid_name");
                    $quota = getParameter("quota");
                    $exito = $pORGZ->createUserOrganization($idOrganization, $username, $name, $md5password, $password1, $idGrupo, $extension, $fax_extension, $countryCode, $areaCode, $clidNumber, $cldiName, $quota, $lastid);
                    $error = $pORGZ->errMsg;
                }
            }
        }
    }
    if ($exito) {
        //esta seccion es solo si el usuario quiere subir una imagen a su cuenta
        if (isset($_FILES['picture']['name']) && $_FILES['picture']['name'] != "") {
            uploadImage($lastid, $pDB, $errorImg);
        }
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("User has been created successfully") . "</br>" . $errorImg);
        //mostramos el mensaje para crear los archivos de ocnfiguracion
        $pAstConf = new paloSantoASteriskConfig($pDB);
        $orgTmp2 = $pORGZ->getOrganization(array("id" => $idOrganization));
        $pAstConf->setReloadDialplan($orgTmp2[0]["domain"], true);
        $content = reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", $error);
        $content = viewFormUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    }
    return $content;
}