Esempio n. 1
0
function viewFormAccount($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $arrLang)
{
    $pEmail = new paloEmail($pDB);
    $oGrid = new paloSantoGrid($smarty);
    $id_domain = 0;
    /*if (isset($_POST['domain'])) $id_domain=$_POST['domain'];
      if (isset($_GET['id_domain'])) $id_domain=$_GET['id_domain'];*/
    if (isset($_POST['domain']) || isset($_GET['domain'])) {
        $id_domain = getParameter('domain');
        if ($id_domain == null) {
            $id_domain = 0;
        }
    }
    $_POST['domain'] = $id_domain;
    $arrDominios = array("0" => '-- ' . $arrLang["Select a domain"] . ' --');
    $arrDomains = $pEmail->getDomains();
    foreach ($arrDomains as $domain) {
        $arrDominios[$domain[0]] = $domain[1];
    }
    $arrFormElements = createFieldFormAccount($arrLang, $arrDominios);
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    $smarty->assign("SHOW", $arrLang["Show"]);
    $smarty->assign("CREATE_ACCOUNT", $arrLang["Create Account"]);
    // $oGrid->pagingShow(true);
    $url = array("menu" => $module_name);
    if ($id_domain == 0) {
        $url = array("menu" => $module_name);
    } else {
        $url = array("menu" => $module_name, "domain" => $id_domain);
    }
    $oGrid->setURL($url);
    $oGrid->setTitle(_tr("Email Account List"));
    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    $arrData = array();
    $pACL = new paloACL(new paloDB($arrConf['elastix_dsn']['acl']));
    $userAccount = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : "";
    $isAdministrator = $pACL->isUserAdministratorGroup($userAccount);
    $reconstruir = _tr("Reconstruct");
    if ($id_domain > 0) {
        $arrAccounts = $pEmail->getAccountsByDomain($id_domain);
    } else {
        $arrAccounts = $pEmail->getAccountsByDomain();
    }
    if (is_array($arrAccounts)) {
        //username, password, id_domain, quota
        $end = count($arrAccounts);
        //$configPostfix2 = isPostfixToElastix2();// in misc.lib.php
        foreach ($arrAccounts as $account) {
            $arrTmp = array();
            $username = $account[0];
            $arrTmp[0] = "&nbsp;<a href='?menu={$module_name}&action=view&username={$username}'>{$username}</a>";
            $arrTmp[1] = obtener_quota_usuario($pEmail, $username, $module_name, $arrLang, $id_domain);
            if ($isAdministrator) {
                $arrTmp[2] = "&nbsp;<a href='?menu={$module_name}&action=reconstruir&username={$username}&domain={$id_domain}'>{$reconstruir}</a>";
            }
            $link_agregar_direccion = "<a href='?action=add_address&id_domain={$id_domain}&username={$username}'>Add Address</a>";
            $link_modificar_direccion = "<a href='?action=edit_addresses&id_domain={$id_domain}&username={$username}'>Addresses</a>";
            //$arrTmp[3]=$link_agregar_direccion."&nbsp;&nbsp; ".$link_modificar_direccion;
            $arrData[] = $arrTmp;
        }
    } else {
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", $pEmail->errMsg);
    }
    $total = count($arrData);
    $limit = 20;
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $inicio = $total == 0 ? 0 : $offset + 1;
    $fin = $offset + $limit <= $total ? $offset + $limit : $total;
    $leng = $fin - $inicio;
    $arrDatosGrid = array_slice($arrData, $inicio - 1, $leng + 1);
    if ($isAdministrator) {
        $oGrid->setColumns(array(_tr("Account Name"), _tr("Used Space"), _tr("Reconstruct MailBox")));
    } else {
        $oGrid->setColumns(array(_tr("Account Name"), _tr("Used Space")));
    }
    $arrGrid = array("width" => "99%", "start" => $inicio, "end" => $fin, "total" => $total);
    $oGrid->addComboAction("domain", _tr("Create Account"), $arrDominios, $id_domain, "submit_create_account", "this.form.submit();");
    if ($id_domain != 0) {
        $oGrid->addLinkAction("?menu={$module_name}&action=export&domain={$id_domain}&rawmode=yes", _tr("Export Accounts"));
        $smarty->assign("id_domain", $id_domain);
    }
    $content = $oGrid->fetchGrid($arrGrid, $arrDatosGrid, $arrLang);
    return $content;
}