Example #1
0
/**
 * @param EasySCP_TemplateEngine $tpl
 * @param int $reseller_id
 * @param string $reseller_name
 */
function generate_page($tpl, $reseller_id, $reseller_name)
{
    $sql = EasySCP_Registry::get('Db');
    $cfg = EasySCP_Registry::get('Config');
    $rows_per_page = (int) ($cfg->DOMAIN_ROWS_PER_PAGE / 2);
    if (isset($_GET['psi'])) {
        $start_index = (int) trim($_GET['psi']);
    } else {
        if (isset($_POST['psi'])) {
            $start_index = (int) trim($_POST['psi']);
        } else {
            $start_index = 0;
        }
    }
    if (!is_numeric($start_index)) {
        $start_index = 0;
    }
    $tpl->assign(array('POST_PREV_PSI' => $start_index));
    // count query
    $count_query = "\n\t\tSELECT\n\t\t\tCOUNT(`admin_id`) AS cnt\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_type` = 'user'\n\t\tAND\n\t\t\t`created_by` = ?\n\t";
    $rs = exec_query($sql, $count_query, $reseller_id);
    $records_count = $rs->fields['cnt'];
    $query = "\n\t\tSELECT\n\t\t\t`admin_id`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_type` = 'user'\n\t\tAND\n\t\t\t`created_by` = ?\n\t\tORDER BY\n\t\t\t`admin_name` ASC\n\t\tLIMIT\n\t\t\t{$start_index}, {$rows_per_page}\n\t\t";
    $rs = exec_query($sql, $query, $reseller_id);
    $tpl->assign(array('RESELLER_NAME' => tohtml($reseller_name), 'RESELLER_ID' => $reseller_id));
    if ($rs->rowCount() == 0) {
        $tpl->assign(array('DOMAIN_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => ''));
    } else {
        $tpl->assign('NO_DOMAINS', '');
        $prev_si = $start_index - $rows_per_page;
        if ($start_index == 0) {
            $tpl->assign('SCROLL_PREV', '');
        } else {
            $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prev_si));
        }
        $next_si = $start_index + $rows_per_page;
        if ($next_si + 1 > $records_count) {
            $tpl->assign('SCROLL_NEXT', '');
        } else {
            $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $next_si));
        }
        $row = 1;
        while (!$rs->EOF) {
            $admin_id = $rs->fields['admin_id'];
            $query = "\n\t\t\t\tSELECT\n\t\t\t\t\t`domain_id`\n\t\t\t\tFROM\n\t\t\t\t\t`domain`\n\t\t\t\tWHERE\n\t\t\t\t\t`domain_admin_id` = ?\n\t\t\t";
            $dres = exec_query($sql, $query, $admin_id);
            generate_domain_entry($tpl, $dres->fields['domain_id'], $row++);
            $rs->moveNext();
        }
    }
}
function generate_page(&$tpl, $reseller_id, $reseller_name)
{
    global $sql, $cfg, $rid;
    $start_index = 0;
    $rows_per_page = $cfg['DOMAIN_ROWS_PER_PAGE'];
    if (isset($_GET['psi'])) {
        $start_index = $_GET['psi'];
    } else {
        if (isset($_POST['psi'])) {
            $start_index = $_POST['psi'];
        }
    }
    $tpl->assign(array('POST_PREV_PSI' => $start_index));
    // count query
    $count_query = <<<SQL_QUERY
                select
                    count(admin_id) as cnt
                from
                    admin
                where
                    admin_type = 'user'
                and
                    created_by = ?
SQL_QUERY;
    $query = <<<SQL_QUERY
        select
            admin_id
        from
            admin
        where
            admin_type = 'user'
          and
            created_by = ?
        order by
            admin_id desc
        limit
            {$start_index}, {$rows_per_page}
SQL_QUERY;
    $rs = exec_query($sql, $count_query, array($reseller_id));
    $records_count = $rs->fields['cnt'];
    $rs = exec_query($sql, $query, array($reseller_id));
    $tpl->assign(array('RESELLER_NAME' => $reseller_name, 'RESELLER_ID' => $reseller_id));
    if ($rs->RowCount() == 0) {
        $tpl->assign(array('DOMAIN_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => ''));
    } else {
        $prev_si = $start_index - $rows_per_page;
        if ($start_index == 0) {
            $tpl->assign('SCROLL_PREV', '');
        } else {
            $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prev_si, 'RID' => $rid));
        }
        $next_si = $start_index + $rows_per_page;
        if ($next_si + 1 > $records_count) {
            $tpl->assign('SCROLL_NEXT', '');
        } else {
            $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $next_si, 'RID' => $rid));
        }
        $tpl->assign(array('PAGE_MESSAGE' => ''));
        $tpl->assign('NO_DOMAINS', '');
        $row = 1;
        while (!$rs->EOF) {
            $admin_id = $rs->fields['admin_id'];
            $query = <<<SQL_QUERY
                select
                    domain_id
                from
                    domain
                where
                    domain_admin_id = ?
SQL_QUERY;
            $dres = exec_query($sql, $query, array($admin_id));
            generate_domain_entry($tpl, $dres->fields['domain_id'], $row++);
            $tpl->parse('DOMAIN_ENTRY', '.domain_entry');
            $rs->MoveNext();
        }
    }
}