Exemple #1
0
function actualizarFax($smarty, $module_name, $local_templates_dir)
{
    $smarty->assign(array('CANCEL' => _tr('Cancel'), 'APPLY_CHANGES' => _tr('Apply changes'), 'REQUIRED_FIELD' => _tr('Required field')));
    $idFax = getParameter('id');
    if (isset($_POST['cancel']) || !ctype_digit("{$idFax}")) {
        header("Location: ?menu={$module_name}");
        return;
    }
    $smarty->assign("id_fax", $idFax);
    $oFax = new paloFaxVisor();
    if (isset($_POST['save'])) {
        if (empty($_POST['name_company']) || empty($_POST['fax_company'])) {
            $smarty->assign("mb_title", _tr('ERROR') . ":");
            $smarty->assign("mb_message", _tr('ERROR'));
        } elseif (!$oFax->updateInfoFaxFromDB($idFax, $_POST['name_company'], $_POST['fax_company'])) {
            $smarty->assign("mb_title", _tr('ERROR') . ":");
            $smarty->assign("mb_message", _tr('ERROR'));
        } else {
            header("Location: ?menu={$module_name}");
            return;
        }
    }
    $arrDataFax = $oFax->obtener_fax($idFax);
    if (is_array($arrDataFax) && count($arrDataFax) > 0) {
        if (!isset($_POST['name_company'])) {
            $_POST['name_company'] = $arrDataFax['company_name'];
        }
        if (!isset($_POST['fax_company'])) {
            $_POST['fax_company'] = $arrDataFax['company_fax'];
        }
    }
    $oForm = new paloForm($smarty, getFormElements());
    $htmlForm = $oForm->fetchForm("{$local_templates_dir}/edit.tpl", _tr('Edit'), $_POST);
    return "<form  method='POST' style='margin-bottom:0;' action='?menu={$module_name}&action=edit'>" . $htmlForm . "</form>";
}
function actualizarFax($smarty, $module_name, $local_templates_dir, $pDB, $credentials)
{
    $smarty->assign(array('CANCEL' => _tr('Cancel'), 'APPLY_CHANGES' => _tr('Apply changes'), 'REQUIRED_FIELD' => _tr('Required field')));
    $idFax = getParameter('id');
    if (isset($_POST['cancel']) || !ctype_digit("{$idFax}")) {
        header("Location: ?menu={$module_name}");
        return;
    }
    $oFax = new paloFaxVisor($pDB);
    if (empty($idFax)) {
        $smarty->assign("mb_title", _tr('ERROR'));
        $smarty->assign("mb_message", _tr('Invalid Fax'));
        return listarFaxes($smarty, $module_name, $local_templates_dir, $pDB, $credentials);
    }
    if ($credentials['userlevel'] != 'superadmin') {
        if (!$oFax->fax_bellowOrganization($idFax, $credentials['id_organization'])) {
            $smarty->assign("mb_title", _tr('ERROR') . ":");
            $smarty->assign("mb_message", _tr("Invalid Fax"));
            return listarFaxes($smarty, $module_name, $local_templates_dir, $pDB, $credentials);
        }
    }
    if (isset($_POST['save'])) {
        if (!$oFax->updateInfoFaxFromDB($idFax, $_POST['name_company'], $_POST['fax_company'])) {
            $smarty->assign("mb_title", _tr('ERROR'));
            $smarty->assign("mb_message", _tr($oFax->errMsg));
        } else {
            $smarty->assign("mb_title", _tr('MESSAGE'));
            $smarty->assign("mb_message", _tr("Changes were applied successfully"));
            return listarFaxes($smarty, $module_name, $local_templates_dir, $pDB, $credentials);
        }
    }
    $smarty->assign("id_fax", $idFax);
    $arrDataFax = $oFax->obtener_fax($idFax);
    if (is_array($arrDataFax) && count($arrDataFax) > 0) {
        if (!isset($_POST['name_company'])) {
            $_POST['name_company'] = $arrDataFax['company_name'];
        }
        if (!isset($_POST['fax_company'])) {
            $_POST['fax_company'] = $arrDataFax['company_fax'];
        }
    } else {
        $smarty->assign("mb_title", _tr('ERROR'));
        $smarty->assign("mb_message", _tr('Fax does not exist'));
        return listarFaxes($smarty, $module_name, $local_templates_dir, $pDB, $credentials);
    }
    $oForm = new paloForm($smarty, getFormElements(array()));
    $htmlForm = $oForm->fetchForm("{$local_templates_dir}/edit.tpl", _tr('Edit'), $_POST);
    return "<form  method='POST' style='margin-bottom:0;' action='?menu={$module_name}&action=edit'>" . $htmlForm . "</form>";
}