Exemple #1
0
function saveEditUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls)
{
    $pACL = new paloACL($pDB);
    $pORGZ = new paloSantoOrganization($pDB);
    $exito = false;
    $idUser = getParameter("id");
    $errorImg = "";
    $renameFile = "";
    $reAsterisk = false;
    //obtenemos la informacion del usuario por el id dado, sino existe el usuario mostramos un mensaje de error
    if (!isset($idUser)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Invalid User"));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        if ($arrCredentiasls['userlevel'] == "superadmin") {
            $arrUsers = $pACL->getUsers($idUser);
        } else {
            $arrUsers = $pACL->getUsers($idUser, $arrCredentiasls['id_organization']);
        }
    }
    if ($arrUsers === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pACL->errMsg));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        if (count($arrUsers) == 0) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("User doesn't exist"));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
        } else {
            $idOrgz = $arrUsers[0][4];
            //una vez creado un usuario este no se puede cambiar de organizacion
            $arrOrgz = array();
            $temp = $pACL->getGroupsPaging(null, null, $idOrgz);
            if ($temp === false) {
                $smarty->assign("mb_title", _tr("ERROR"));
                $smarty->assign("mb_message", _tr($pACL->errMsg));
                return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
            }
            foreach ($temp as $value) {
                $arrGrupos[$value[0]] = $value[1];
            }
            $arrFormOrgz = createFieldForm($arrGrupos, $arrOrgz);
            $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");
                $quota = getParameter("email_quota");
                $countryCode = getParameter("country_code");
                $areaCode = getParameter("area_code");
                $idGrupo = getParameter("group");
                $extension = getParameter("extension");
                $fax_extension = getParameter("fax_extension");
                $name = getParameter("name");
                $md5password = md5($password1);
                $clidNumber = getParameter("clid_number");
                $cldiName = getParameter("clid_name");
                if ($pACL->isUserSuperAdmin($arrUsers[0][1])) {
                    $idGrupo = $arrUsers[0][7];
                    $email_contact = getParameter("email_contact");
                    $exito = $pORGZ->updateUserSuperAdmin($idUser, $name, $md5password, $password1, $email_contact, $arrCredentiasls['userlevel']);
                    $error = $pORGZ->errMsg;
                } else {
                    if ($password1 != $password2) {
                        $error = _tr("Passwords don't match");
                    } elseif ($password1 != "" && !isStrongPassword($password1)) {
                        $error = _tr("Secret can not be empty, must be at least 10 characters, contain digits, uppers and little case letters");
                    } elseif (!isset($quota) || $quota == "") {
                        $error = _tr("Qouta must not be empty");
                    } elseif (!isset($countryCode) || $countryCode == "") {
                        $error = _tr("Country Code must not be empty");
                    } elseif (!isset($areaCode) || $areaCode == "") {
                        $error = _tr("Area Code must not be empty");
                    } elseif (!isset($clidNumber) || $clidNumber == "") {
                        $error = _tr("C er Id Number must not be empty");
                    } elseif (!isset($cldiName) || $cldiName == "") {
                        $error = _tr("Caller Id Name must not be empty");
                    } else {
                        $exito = $pORGZ->updateUserOrganization($idUser, $name, $md5password, $password1, $extension, $fax_extension, $countryCode, $areaCode, $clidNumber, $cldiName, $idGrupo, $quota, $arrCredentiasls['userlevel'], $reAsterisk);
                        $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($idUser, $pDB, $errorImg);
        }
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("User has been edited successfully") . "<br>{$errorImg}");
        if ($reAsterisk) {
            //mostramos el mensaje para crear los archivos de ocnfiguracion
            $pAstConf = new paloSantoASteriskConfig($pDB);
            $orgTmp2 = $pORGZ->getOrganization(array("id" => $idOrgz));
            $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;
}