function updateUserOrganization($idUser, $name, $md5password, $password1, $extension, $fax_extension, $countryCode, $areaCode, $clidNumber, $cldiName, $idGrupo, $quota, $userLevel1, &$reAsterisk) { require_once "apps/general_settings/libs/paloSantoGlobalsPBX.class.php"; $pACL = new paloACL($this->_DB); $pEmail = new paloEmail($this->_DB); $pFax = new paloFax($this->_DB); $continuar = true; $Exito = false; $error = ""; $cExten = false; $cFExten = false; $arrBackup = array(); $editFax = false; $faxProperties = array(); $arrUser = $pACL->getUsers2($idUser); if ($arrUser === false || count($arrUser) == 0 || !isset($idUser)) { $this->errMsg = _tr("User dosen't exist"); return false; } if ($pACL->isUserSuperAdmin($arrUser[0]['username'])) { $this->errMsg = _tr("Invalid Action"); return false; } $arrOrgz = $this->getOrganizationById($arrUser[0]['id_organization']); $username = $arrUser[0]['username']; $oldExten = $arrUser[0]['extension']; $oldFaxExten = $arrUser[0]['fax_extension']; $pDevice = new paloDevice($arrOrgz["domain"], "sip", $this->_DB); $arrExtUser = $pDevice->getExtension($oldExten); $listFaxs = $pFax->getFaxList(array("exten" => $oldFaxExten, "organization_domain" => $arrOrgz['domain'])); $faxUser = $listFaxs[0]; if ($name == "") { $name = $username; } if ($userLevel1 == "other") { $extension = $arrUser[0]['extension']; $fax_extension = $arrUser[0]['fax_extension']; $quota = $pACL->getUserProp($idUser, "email_quota"); $idGrupo = $arrUser[0]['id_group']; $modificarExts = false; } else { //verificar si el usuario cambio de extension y si es asi que no este siendo usado por otro usuario if ($extension != $oldExten) { if ($pDevice->existDevice($extension, "{$arrOrgz["code"]}_{$extension}", $arrExtUser["tech"]) == true) { $this->errMsg = $pDevice->errMsg; return false; } else { $cExten = true; } } if ($fax_extension != $oldFaxExten) { //si el usairo quiere cambiar el patron de marcado asociado al fax verificar que el nuevo //patron de marcado no este siendo usado dentro de la organizacion if ($pDevice->tecnologia->existExtension($fax_extension, $pDevice->getDomain())) { $this->errMsg = $pDevice->errMsg; return false; } else { $cFExten = true; } } //para cambiar al usuario de extension o faxextension es necesario que se haya llenado el campo password para //poder crear las extensiones con la clave correcta if ($cExten || $cFExten) { if (is_null($md5password) || $md5password == "" || is_null($password1) || $password1 == "") { $this->errMsg = _tr("Please set a password"); return false; } } } if (empty($clidNumber) && $clidNumber != 0) { $clidNumber = $faxUser['clid_number']; } if (empty($cldiName) && $cldiName != 0) { $cldiName = $faxUser['clid_name']; } if (empty($country_code)) { $country_code = $faxUser['country_code']; } if (empty($area_code)) { $area_code = $faxUser['area_code']; } $this->_DB->beginTransaction(); //actualizamos la informacion de usuario que esta en la tabla acl_user if ($pACL->updateUser($idUser, $name, $extension, $fax_extension)) { //actualizamos el grupo al que pertennece el usuario if ($pACL->addToGroup($idUser, $idGrupo)) { $old_quota = $pACL->getUserProp($idUser, "email_quota"); if ($old_quota === false) { $old_quota = 1; } //actualizamos la quota de correo if (isset($quota) && $quota != "" && $continuar) { if ($pEmail->updateQuota($old_quota * 1024, $quota * 1024, $username)) { if (!$pACL->setUserProp($idUser, "email_quota", $quota, "email")) { $error = _tr("Error setting email quota") . $pACL->errMsg; $pEmail->updateQuota($quota, $old_quota); $this->_DB->rollBack(); $continuar = false; } } else { $error = _tr("Error setting email quota") . $pEmail->errMsg; $continuar = false; } } if ($continuar) { if ($cExten && $userLevel1 != "other") { if (!$this->modificarExtensionUsuario($arrOrgz["domain"], $oldExten, $extension, $password1, $name, $username, $arrBackup)) { $error = "Couldn't updated user extension. " . $this->errMsg; $continuar = false; } } } //actualizamos el password del usuario if ($password1 !== "" && $continuar) { if ($pACL->changePassword($idUser, $md5password)) { //en caso que no se hayan modificado la extensiones del usuario //entonces es necesario actualizar el passoword para la extension y el fax if (!$cExten) { if (!$pDevice->changePasswordExtension($password1, $extension)) { $this->errMsg = _tr("Extension password couldn't be updated") . $pDevice->errMsg; $continuar = false; } } //editamos la configuracion del fax if ($continuar) { if ($cFExten && $userLevel1 != "other") { //cuando se cambia el patron de marcado asociado al fax del usuario //es necesario incluir el parametro oldFaxExten entre los parametros para //la actualizacion correcta de los datos if (!$pFax->editFaxToUser(array("idUser" => $idUser, "oldFaxExten" => $oldFaxExten, "country_code" => $countryCode, "area_code" => $areaCode, "clid_name" => $cldiName, "clid_number" => $clidNumber))) { $error = "Couldn't updated user fax. " . $pFax->errMsg; $continuar = false; } } else { if (!$pFax->editFaxToUser(array("idUser" => $idUser, "country_code" => $countryCode, "area_code" => $areaCode, "clid_name" => $cldiName, "clid_number" => $clidNumber))) { $error = "Couldn't updated user fax. " . $pFax->errMsg; $continuar = false; } } } if ($continuar) { if (!$pEmail->setAccountPassword($username, $password1)) { $continuar = false; $error = _tr("Password couldn't be updated") . " " . $pEmail->errMsg; $editFax = true; } } //debemos actualizar el password en las variable de session if ($continuar && $_SESSION['elastix_user'] == $username) { $_SESSION['elastix_pass'] = $md5password; $_SESSION['elastix_pass2'] = $password1; } } else { $error = _tr("Password couldn't be updated") . " " . $pACL->errMsg; $continuar = false; } } else { //editamos la configuracion del fax if ($continuar) { if ($cFExten && $userLevel1 != "other") { //cuando se cambia el patron de marcado asociado al fax del usuario //es necesario incluir el parametro oldFaxExten entre los parametros para //la actualizacion correcta de los datos if (!$pFax->editFaxToUser(array("idUser" => $idUser, "oldFaxExten" => $oldFaxExten, "country_code" => $countryCode, "area_code" => $areaCode, "clid_name" => $cldiName, "clid_number" => $clidNumber))) { $error = "Couldn't updated user fax. " . $pFax->errMsg; $continuar = false; } } else { if (!$pFax->editFaxToUser(array("idUser" => $idUser, "country_code" => $countryCode, "area_code" => $areaCode, "clid_name" => $cldiName, "clid_number" => $clidNumber))) { $error = "Couldn't updated user fax. " . $pFax->errMsg; $continuar = false; } } } } if ($continuar) { $Exito = true; $this->_DB->commit(); //recargamos la configuracion en realtime de los dispositivos para que tomen efectos los cambios if ($cExten) { //se cambio la extension del usuario hay que eliminar de cache la anterior $pDevice->tecnologia->prunePeer($arrExtUser["device"], $arrExtUser["tech"]); } else { $pDevice->tecnologia->prunePeer($arrExtUser["device"], $arrExtUser["tech"]); $pDevice->tecnologia->loadPeer($arrExtUser["device"], $arrExtUser["tech"]); } if ($cFExten) { //se cambio la faxextension del usuario hay que eliminar de cache la anterior $pDevice->tecnologia->prunePeer($faxUser["device"], $faxUser["tech"]); } else { //se recarga la faxextension del usuario por los cambios que pudo haber $pDevice->tecnologia->prunePeer($faxUser["device"], $faxUser["tech"]); $pDevice->tecnologia->loadPeer($faxUser["device"], $faxUser["tech"]); } $pFax->restartService(); } else { $this->_DB->rollBack(); if ($editFax == true) { $pFax->editFaxFileConfig($faxUser['dev_id'], $faxUser['country_code'], $faxUser['area_code'], $faxUser['clid_name'], $faxUser['clid_number'], $arrUser[0]['md5_password'], 0, $arrOrgz['domain']); } if ($cExten == true) { $pDevice->deleteAstDBExt($extension, "sip"); $pDevice->restoreBackupAstDBEXT($arrBackup); } } } else { $error = _tr("Failed Updated Group") . " " . $pACL->errMsg; $this->_DB->rollBack(); } } else { $error = _tr("User couldn't be update") . " " . $pACL->errMsg; $this->_DB->rollBack(); } if ($cExten || $cFExten) { $reAsterisk = true; } $this->errMsg = $error . " " . $this->errMsg; return $Exito; }
function _moduleContent(&$smarty, $module_name) { include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoConfig.class.php"; include_once "libs/paloSantoGrid.class.php"; include_once "libs/paloSantoACL.class.php"; include_once "modules/{$module_name}/configs/default.conf.php"; //include file language agree to elastix configuration //if file language not exists, then include language by default (en) $lang = get_language(); $base_dir = dirname($_SERVER['SCRIPT_FILENAME']); $lang_file = "modules/{$module_name}/lang/{$lang}.lang"; if (file_exists("{$base_dir}/{$lang_file}")) { include_once "{$lang_file}"; } else { include_once "modules/{$module_name}/lang/en.lang"; } //global variables global $arrConf; global $arrConfModule; global $arrLang; global $arrLangModule; $arrConf = array_merge($arrConf, $arrConfModule); $arrLang = array_merge($arrLang, $arrLangModule); //conexion acl.db $pDB = new paloDB($arrConf['elastix_dsn']['acl']); //folder path for custom templates $base_dir = dirname($_SERVER['SCRIPT_FILENAME']); $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes'; $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme']; $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asterisk"; $pDBa = new paloDB($dsn); //////////////////// if (!empty($pDB->errMsg)) { echo "ERROR DE DB: {$pDB->errMsg} <br>"; } $arrData = array(); $arrData[""] = $arrLang["no extension"]; $pACL = new paloACL($pDB); if (!empty($pACL->errMsg)) { echo "ERROR DE ACL: {$pACL->errMsg} <br>"; } /*******/ $typeUser = ""; $userLevel1 = ""; $extOther = ""; $userAccount = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $idUserAccount = $pACL->isUserAdministratorGroup($userAccount); $idUserInt = $pACL->getIdUser($userAccount); if ($idUserAccount) { $userLevel1 = "admin"; } else { $userLevel1 = "other"; } $smarty->assign("userLevel1", $userLevel1); /*******/ $sQuery = "select extension from users order by extension;"; $arrayResult = $pDBa->fetchTable($sQuery, true); if (!$arrayResult) { $error = $pDBa->errMsg; } else { if (is_array($arrayResult) && count($arrayResult) > 0) { //$arrData[$item["null"]] = "No extension"; if ($idUserAccount) { foreach ($arrayResult as $item) { $arrData[$item["extension"]] = $item["extension"]; } } else { $idOther = $pACL->getIdUser($userAccount); $arrUserOther = $pACL->getUsers($idOther); $extOther = $arrUserOther[0][3]; $arrData[$extOther] = $extOther; } } } $arrGruposACL = $pACL->getGroups(); for ($i = 0; $i < count($arrGruposACL); $i++) { if ($arrGruposACL[$i][1] == 'administrator') { $arrGruposACL[$i][1] = $arrLang['administrator']; } else { if ($arrGruposACL[$i][1] == 'operator') { $arrGruposACL[$i][1] = $arrLang['operator']; } else { if ($arrGruposACL[$i][1] == 'extension') { $arrGruposACL[$i][1] = $arrLang['extension']; } } } if ($idUserAccount) { $arrGrupos[$arrGruposACL[$i][0]] = $arrGruposACL[$i][1]; } else { $arrUserPer = $pACL->getMembership($idUserInt); foreach ($arrUserPer as $key => $value) { if ($arrGruposACL[$i][1] == $key) { $arrGrupos[$arrGruposACL[$i][0]] = $arrGruposACL[$i][1]; } } } } $arrFormElements = array("description" => array("LABEL" => "{$arrLang['Name']} {$arrLang['(Ex. John Doe)']}", "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "name" => array("LABEL" => $arrLang["Login"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "EDITABLE" => "no"), "password1" => array("LABEL" => $arrLang["Password"], "REQUIRED" => "yes", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "password2" => array("LABEL" => $arrLang["Retype password"], "REQUIRED" => "yes", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "group" => array("LABEL" => $arrLang["Group"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrGrupos, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "extension" => array("LABEL" => $arrLang["Extension"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrData, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmailpassword1" => array("LABEL" => $arrLang["Webmail Password"], "REQUIRED" => "no", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmailuser" => array("LABEL" => $arrLang["Webmail User"], "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmaildomain" => array("LABEL" => $arrLang["Webmail Domain"], "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "")); $contenidoModulo = ""; $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $smarty->assign("CANCEL", $arrLang["Cancel"]); $smarty->assign("APPLY_CHANGES", $arrLang["Apply changes"]); $smarty->assign("SAVE", $arrLang["Save"]); $smarty->assign("EDIT", $arrLang["Edit"]); $smarty->assign("DELETE", $arrLang["Delete"]); $smarty->assign("CONFIRM_CONTINUE", $arrLang["Are you sure you wish to continue?"]); $smarty->assign("icon", "images/user.png"); $smarty->assign("title_webmail", $arrLang["Mail Profile"]); if (isset($_POST['submit_create_user'])) { // Implementar include_once "libs/paloSantoForm.class.php"; $arrFillUser['description'] = ''; $arrFillUser['name'] = ''; $arrFillUser['group'] = ''; $arrFillUser['extension'] = ''; $arrFillUser['password1'] = ''; $arrFillUser['password2'] = ''; $oForm = new paloForm($smarty, $arrFormElements); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $arrFillUser); } else { if (!is_null(getParameter("edit"))) { $contenidoModulo = editUser($userAccount, $pACL, $pDB, $arrFormElements, $smarty, $local_templates_dir, $arrLang, $idUserAccount, $userLevel1); } else { if (isset($_POST['submit_save_user'])) { include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); if ($oForm->validateForm($_POST)) { // Exito, puedo procesar los datos ahora. $pACL = new paloACL($pDB); if (empty($_POST['password1']) or $_POST['password1'] != $_POST['password2']) { // Error claves $smarty->assign("mb_message", $arrLang["The passwords are empty or don't match"]); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } else { if ($userLevel1 == "admin") { // Creo al usuario $md5_password = md5($_POST['password1']); $pACL->createUser($_POST['name'], $_POST['description'], $md5_password, $_POST['extension']); $idUser = $pACL->getIdUser($_POST['name']); // Versiones viejas del archivo acl.db tienen una fila con una // tupla que asocia al usuario inexistente con ID 2, con el // grupo 2 (Operadores). Se limpia cualquier membresía extraña. $listaMembresia = $pACL->getMembership($idUser); if (is_array($listaMembresia) && count($listaMembresia) > 0) { foreach ($listaMembresia as $idGrupo) { $pACL->delFromGroup($idUser, $idGrupo); } } // Creo la membresia $pACL->addToGroup($idUser, $_POST['group']); $bExito = TRUE; if (empty($pACL->errMsg)) { $nuevasPropiedades = array(); if (!empty($_POST['webmailuser'])) { $nuevasPropiedades['login'] = $_POST['webmailuser']; } if (!empty($_POST['webmailpassword1'])) { $nuevasPropiedades['password'] = $_POST['webmailpassword1']; } if (!empty($_POST['webmaildomain'])) { $nuevasPropiedades['domain'] = $_POST['webmaildomain']; } $bExito = actualizarPropiedades($pDB, $smarty, $idUser, 'webmail', 'default', $nuevasPropiedades); } if (!empty($pACL->errMsg)) { // Ocurrio algun error aqui $smarty->assign("mb_message", "ERROR: {$pACL->errMsg}"); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } else { if ($bExito) { header("Location: ?menu=userlist"); } } } else { $smarty->assign("mb_message", $arrLang["userNoAllowed"]); } } } else { // Error $smarty->assign("mb_title", $arrLang["Validation Error"]); $arrErrores = $oForm->arrErroresValidacion; $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br>"; foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}, "; } $strErrorMsg .= ""; $smarty->assign("mb_message", $strErrorMsg); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } } else { if (isset($_POST['submit_apply_changes'])) { $arrayContent = applyChanges($userAccount, $pACL, $smarty, $arrLang, $idUserAccount, $userLevel1, $arrFormElements, $pDB, $local_templates_dir, $idUserInt, $extOther); if (isset($arrayContent["mb_title"]) && isset($arrayContent["mb_message"])) { $smarty->assign("mb_title", $arrayContent["mb_title"]); $smarty->assign("mb_message", $arrayContent["mb_message"]); } if ($arrayContent["success"]) { header("Location: ?menu=userlist"); } else { if (isset($arrayContent["id_user"])) { $smarty->assign("id_user", $_POST['id_user']); } if (isset($arrayContent["fill_user"])) { $contenidoModulo = $arrayContent["form"]->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["Edit User"], $arrayContent["fill_user"]); } else { $contenidoModulo = $arrayContent["content"]; } } } else { if (isset($_GET['action']) && $_GET['action'] == "view") { if (!$pACL->isUserAdministratorGroup($userAccount)) { if ($pACL->getIdUser($userAccount) != $_GET['id']) { $smarty->assign("mb_title", $arrLang["ERROR"]); $smarty->assign("mb_message", $arrLang["You are not authorized to access to information of that user"]); return reportUserList($arrLang, $pACL, $idUserAccount, $smarty, $userLevel1, $userAccount); } } include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); //- TODO: Tengo que validar que el id sea valido, si no es valido muestro un mensaje de error $oForm->setViewMode(); // Esto es para activar el modo "preview" $arrUser = $pACL->getUsers($_GET['id']); // Conversion de formato $arrTmp['name'] = $arrUser[0][1]; $arrTmp['description'] = $arrUser[0][2]; $arrTmp['password1'] = "****"; $arrTmp['password2'] = "****"; $arrTmp['extension'] = $arrUser[0][3]; //- TODO: Falta llenar el grupo $arrMembership = $pACL->getMembership($_GET['id']); $id_group = ""; if (is_array($arrMembership)) { foreach ($arrMembership as $groupName => $groupId) { $id_group = $groupId; // Asumo que cada usuario solo puede pertenecer a un grupo break; } } $arrTmp['group'] = $id_group; $listaPropiedades = leerPropiedadesWebmail($pDB, $smarty, $_GET['id']); if (isset($listaPropiedades['login'])) { $arrTmp['webmailuser'] = $listaPropiedades['login']; } if (isset($listaPropiedades['domain'])) { $arrTmp['webmaildomain'] = $listaPropiedades['domain']; } if (isset($listaPropiedades['password'])) { $arrTmp['webmailpassword1'] = '****'; } //if (isset($listaPropiedades['imapsvr'])) $arrTmp['webmailimapsvr'] = $listaPropiedades['imapsvr']; $smarty->assign("id_user", $_GET['id']); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["View User"], $arrTmp); // hay que pasar el arreglo } else { if (getParameter('action') == "edit_userExtension") { $smarty->assign("editUserExtension", "yes"); $html = editUser($userAccount, $pACL, $pDB, $arrFormElements, $smarty, $local_templates_dir, $arrLang, $idUserAccount, $userLevel1); $smarty->assign("CONTENT", $html); $smarty->assign("THEMENAME", $arrConf['mainTheme']); $smarty->assign("MODULE_NAME", $module_name); $smarty->assign("path", ""); $contenidoModulo = $smarty->display("{$local_templates_dir}/edit_userExtension.tpl"); } else { if (getParameter('action') == "apply_changes_UserExtension") { include_once "libs/paloSantoJSON.class.php"; $jsonObject = new PaloSantoJSON(); $result = applyChanges($userAccount, $pACL, $smarty, $arrLang, $idUserAccount, $userLevel1, $arrFormElements, $pDB, $local_templates_dir, $idUserInt, $extOther); $arrMessage["mb_title"] = isset($result["mb_title"]) ? $result["mb_title"] : null; $arrMessage["mb_message"] = isset($result["mb_message"]) ? $result["mb_message"] : null; $arrMessage["success"] = $result["success"]; $jsonObject->set_message($arrMessage); $contenidoModulo = $jsonObject->createJSON(); } else { $contenidoModulo = reportUserList($arrLang, $pACL, $idUserAccount, $smarty, $userLevel1, $userAccount); } } } } } } } return $contenidoModulo; }