/** Este procedimiento se encarga de crear un usuario que pertenece a una organizacion, al usuario se le crea una cuenta de correo dentro de la organizacion una extension telefonica dentro de asterisk un fax con hylafax y la extension para el fax dentro de asterisk */ function createUserOrganization($idOrganization, $username, $name, $md5password, $password, $idGroup, $extension, $fax_extension, $countryCode, $areaCode, $clidNumber, $cldiName, $quota, &$lastId, $transaction = true) { 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 = ""; // 1) valido que la organizacion exista // 2) trato de crea el usuario en la base -- aqui se hacen validaciones con respecto al usuario // --Se valida que no exista otro usuario con el mismo username // --Se valida que no exista otro usuario dentro de la misma organizacion con la misma sip_extension // --Se valida que no exista otro usuario dentro de la misma organizacion con la misma fax_extension // --Que no se supere el maximo numeros de usuarios por organizacion de existir esa propiedad // 3) creo la cuenta de fax // 4) creo la cuenta de mail // 5) se crea la extension dentro del plan de marcado para el usuario if ($name == "") { $name = $username; } $arrOrgz = $this->getOrganizationById($idOrganization); if (is_array($arrOrgz) && count($arrOrgz) > 0) { // 1) $emailUser = $username; $username = $emailUser . "@" . $arrOrgz["domain"]; $peer_name = $emailUser . "_" . $arrOrgz["code"]; $peer_fax = $fax_extension . "_" . $arrOrgz["code"]; //validamos que no exista otro usuario con la misma sip_extension //validamos que no exista otro usuario con la misma fax_extension //TODO: en un futuro las extensiones podran ser sip o iax, eso lo define el administrador entre las //opciones generales y habra que preguntar que tipo de extension se va a crear if ($fax_extension == $extension) { $this->errMsg = _tr("Extension number and Fax number can not be equal"); return false; } $pDevice = new paloDevice($arrOrgz["domain"], "sip", $this->_DB); if ($pDevice->existDevice($extension, $peer_name, "sip") == true) { $this->errMsg = "Error Extension Number. " . $pDevice->errMsg; return false; } //las extensiones usadas para el fax siempre son de tipo iax if ($pDevice->existDevice($fax_extension, $peer_fax, "iax2") == true) { $this->errMsg = "Error Extension Number. " . $pDevice->errMsg; return false; } $max_num_user = $this->getOrganizationProp($idOrganization, "max_num_user"); if (ctype_digit($max_num_user)) { if ($max_num_user != 0) { $numUser = $this->getNumUserByOrganization($idOrganization); if ($numUser >= $max_num_user) { $this->errMsg = _tr("Err: You can't create new users because you have reached the max numbers of users permitted") . " ({$max_num_user}). " . _tr("Contact with the server's admin"); return false; } } } if ($transaction) { $this->_DB->beginTransaction(); } if ($pACL->createUser($username, $name, $md5password, $idGroup, $extension, $fax_extension, $idOrganization)) { //creamos usuario //seteamos los registros en la tabla user_properties if ($countryCode == "" || $countryCode == null) { $countryCode = $this->getOrganizationProp($idOrganization, "country_code"); } if ($areaCode == "" || $areaCode == null) { $areaCode = $this->getOrganizationProp($idOrganization, "area_code"); } if ($clidNumber == "" || $clidNumber == null) { $clidNumber = $fax_extension; } if ($cldiName == "" || $cldiName == null) { $cldiName = $name; } $fax_subject = $this->getOrganizationProp($idOrganization, "fax_subject"); $fax_content = $this->getOrganizationProp($idOrganization, "fax_content"); $fax_subject = empty($fax_subject) ? "Fax attached (ID: {NAME_PDF})" : $fax_subject; $fax_content = empty($fax_content) ? "Fax sent from '{COMPANY_NAME_FROM}'. The phone number is {COMPANY_NUMBER_FROM}. \n This email has a fax attached with ID {NAME_PDF}." : $fax_content; //obtenemos el id del usuario que acabmos de crear $idUser = $pACL->getIdUser($username); $lastId = $idUser; if ($quota == "" || $quota == null) { $quota = $this->getOrganizationProp($idOrganization, "email_quota"); } //seteamos la quota if ($quota !== false && $continuar) { if (!$pACL->setUserProp($idUser, "email_quota", $quota, "email")) { $error = _tr("Error setting quota") . $pACL->errMsg; if ($transaction) { $this->_DB->rollBack(); } $continuar = false; } } else { $error = _tr("Property quota is not set") . $this->errMsg; $continuar = false; } $arrSysProp = $this->getOrganizationPropByCategory($idOrganization, "system"); if (is_array($arrSysProp) && $continuar) { foreach ($arrSysProp as $tmp) { if (!$pACL->setUserProp($idUser, $tmp["property"], $tmp["value"], "system")) { $error = _tr("Error setting user properties") . $pACL->errMsg; if ($transaction) { $this->_DB->rollBack(); } $continuar = false; break; } } } if ($continuar) { //creamos la extension del usuario $arrProp = $this->setParameterUserExtension($arrOrgz["domain"], "sip", $extension, $password, $name, $username, $this->_DB); if ($arrProp == false) { $error = $this->errMsg; if ($transaction) { $this->_DB->rollBack(); } $continuar = false; } else { if ($pDevice->createNewDevice($arrProp, "sip") == false) { $error = $pDevice->errMsg; if ($transaction) { $this->_DB->rollBack(); } $pDevice->deleteAstDBExt($extension, "sip"); $continuar = false; } } } //creamos fax y el email del usuario if ($continuar) { //$idUser,$countryCode,$areaCode,$cldiName,$clidNumber if ($pFax->createFaxToUser(array("idUser" => $idUser, "country_code" => $countryCode, "area_code" => $areaCode, "clid_name" => $cldiName, "clid_number" => $clidNumber, "fax_content" => $fax_content, "fax_subject" => $fax_subject))) { //si se crea exitosamente el fax creamos el email if ($pEmail->createAccount($arrOrgz["domain"], $emailUser, $password, $quota * 1024)) { $Exito = true; if ($transaction) { $this->_DB->commit(); } $pFax->restartService(); } else { $error = _tr("Error trying create email_account") . $pEmail->errMsg; $devId = $pACL->getUserProp($idUser, "dev_id"); if ($transaction) { $this->_DB->rollBack(); } $pDevice->deleteAstDBExt($extension, "sip"); $pFax->deleteFaxConfiguration($devId); } } else { $error = _tr("Error trying create new fax") . $pFax->errMsg; $pDevice->deleteAstDBExt($extension, "sip"); if ($transaction) { $this->_DB->rollBack(); } } } } else { $error = _tr("User couldn't be created") . ". " . $pACL->errMsg; if ($transaction) { $this->_DB->rollBack(); } } } else { $error = _tr("Invalid Organization") . $this->errMsg; } $this->errMsg = $error; 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; }