Пример #1
0
function saveNewList($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    $pEmailList = new paloSantoEmailList($pDB);
    if ($credentials['userlevel'] == 'superadmin') {
        $domain = getParameter('domain');
    } else {
        $domain = $credentials['domain'];
    }
    $namelist = getParameter("namelist");
    $namelist = strtolower($namelist);
    $password = getParameter("password");
    $passwordconfirm = getParameter("passwordconfirm");
    $emailadmin = getParameter("emailadmin");
    $arrForm = createFieldForm(array());
    $oForm = new paloForm($smarty, $arrForm);
    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 viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    //validaciones
    if ($password != $passwordconfirm) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("The Password List and Confirm Password List do not match"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    $pDB->beginTransaction();
    if (!$pEmailList->createEmailList($domain, $namelist, $password, $emailadmin)) {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", _tr("List could not be created.") . " " . $pEmailList->getError());
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $pDB->commit();
        $smarty->assign("mb_title", _tr("Message"));
        $smarty->assign("mb_message", _tr("The List was created successfully "));
        return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
}
Пример #2
0
function saveNewList($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf)
{
    $pEmaillist = new paloSantoEmaillist($pDB);
    $pEmail = new paloEmail($pDB);
    $arrDominios = array("0" => '-- ' . _tr("Select a domain") . ' --');
    $arrDomains = $pEmail->getDomains();
    foreach ($arrDomains as $domain) {
        $arrDominios[$domain[0]] = $domain[1];
    }
    $arrFormEmaillist = createFieldForm($arrDominios);
    $oForm = new paloForm($smarty, $arrFormEmaillist);
    $emailmailman = getParameter("emailmailman") ? getParameter("emailmailman") : null;
    $passwdmailman = getParameter("passwdmailman") ? getParameter("passwdmailman") : null;
    $id_domain = getParameter("domain");
    $namelist = getParameter("namelist");
    $password = getParameter("password");
    $passwordconfirm = getParameter("passwordconfirm");
    $emailadmin = getParameter("emailadmin");
    $namelist = strtolower($namelist);
    if (!$oForm->validateForm($_POST)) {
        // Falla la validación básica del formulario
        $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>";
        $arrErrores = $oForm->arrErroresValidacion;
        if (is_array($arrErrores) && count($arrErrores) > 0) {
            foreach ($arrErrores as $k => $v) {
                $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> ";
            }
        }
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", $strErrorMsg);
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    } elseif (!preg_match("/^[[:alpha:]]+([\\-_\\.]?[[:alnum:]]+)*\$/", $namelist)) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("Wrong List Name"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    } elseif ($password != $passwordconfirm) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("The Password List and Confirm Password List do not match"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    } elseif (!$pEmaillist->domainExists($id_domain)) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("The domain selected does not exist"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    } elseif ($pEmaillist->listExistsbyName($namelist)) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("The List entered already exists"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    if (isset($emailmailman) && isset($passwdmailman) && !$pEmaillist->isMailmanListCreated()) {
        if (!$pEmaillist->mailmanCreateList("mailman", $emailmailman, $passwdmailman)) {
            $smarty->assign("mb_title", _tr("Error"));
            $smarty->assign("mb_message", _tr("Could not create the list") . " mailman");
            return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
        }
    }
    $pDB->beginTransaction();
    if (!$pEmaillist->saveEmailList($id_domain, $namelist, $password, $emailadmin)) {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", $pEmaillist->getError());
        return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    $domainName = $pEmaillist->getDomainName($id_domain);
    if (!isset($domainName)) {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("The domain selected does not exist"));
        return viewFormEmaillist($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    if (!$pEmaillist->mailmanCreateList($namelist, $emailadmin, $password, $domainName)) {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", _tr("Could not create the list") . " {$namelist}");
        return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    if (!$pEmaillist->mailmanCreateVirtualAliases($namelist, $domainName)) {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", _tr("Could not create the virtual alias"));
        return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    $pDB->commit();
    $smarty->assign("mb_title", _tr("Message"));
    $smarty->assign("mb_message", _tr("The List was successfully created"));
    return reportEmailList($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
}