Пример #1
0
function saveEditShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    $error = "";
    $continue = true;
    $success = false;
    $idShortcutApps = getParameter("id");
    //obtenemos la informacion del ring_group por el id dado, sino existe el ring_group mostramos un mensaje de error
    if (!isset($idShortcutApps)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Invalid ShortcutApps ID"));
        return reportShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    $domain = getParameter('organization');
    //este parametro solo es selecionable cuando es el superadmin quien hace la accion
    if ($credentials['userlevel'] != 'superadmin') {
        $domain = $credentials['domain'];
    }
    $pShortcutApps = new paloSantoShortcutApps($pDB, $domain);
    $arrShortcutApps = $pShortcutApps->getShortcutAppsById($idShortcutApps);
    if ($arrShortcutApps === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pShortcutApps->errMsg));
        return reportShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        if (count($arrShortcutApps) == 0) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("ShortcutApps doesn't exist"));
            return reportShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            if ($pShortcutApps->validateDestine($domain, getParameter("destination")) == false) {
                $error = _tr("You must select a default destination.");
                $continue = false;
            }
            if ($continue) {
                //seteamos un arreglo con los parametros configurados
                $arrProp = array();
                $arrProp["id"] = $idShortcutApps;
                $arrProp["description"] = getParameter("description");
                $arrProp["exten"] = getParameter("exten");
                $arrProp["goto"] = getParameter("goto");
                $arrProp['destination'] = getParameter("destination");
            }
            if ($continue) {
                $pDB->beginTransaction();
                $success = $pShortcutApps->updateShortcutAppsPBX($arrProp);
                if ($success) {
                    $pDB->commit();
                } else {
                    $pDB->rollBack();
                }
                $error .= $pShortcutApps->errMsg;
            }
        }
    }
    $smarty->assign("id", $idShortcutApps);
    if ($success) {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("ShortcutApps has been edited successfully"));
        //mostramos el mensaje para crear los archivos de ocnfiguracion
        $pAstConf = new paloSantoASteriskConfig($pDB);
        $pAstConf->setReloadDialplan($domain, true);
        $content = reportShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", $error);
        $content = viewFormShortcutApps($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    return $content;
}