Example #1
0
/**
 * Generates users list.
 *
 * @param  iMSCP_pTemplate $tpl Template engine
 * @param  int $resellerId Reseller unique identifier
 * @return void
 */
function generate_users_list($tpl, $resellerId)
{
    $cfg = iMSCP_Registry::get('config');
    $rowsPerPage = $cfg['DOMAIN_ROWS_PER_PAGE'];
    if (isset($_POST['details']) && !empty($_POST['details'])) {
        $_SESSION['details'] = $_POST['details'];
    } else {
        if (!isset($_SESSION['details'])) {
            $_SESSION['details'] = 'hide';
        }
    }
    if (isset($_GET['psi']) && $_GET['psi'] == 'last') {
        if (isset($_SESSION['search_page'])) {
            $_GET['psi'] = $_SESSION['search_page'];
        } else {
            unset($_GET['psi']);
        }
    }
    // Search request generated?
    if (isset($_POST['search_for']) && !empty($_POST['search_for'])) {
        $_SESSION['search_for'] = trim(clean_input($_POST['search_for']));
        $_SESSION['search_common'] = $_POST['search_common'];
        $_SESSION['search_status'] = $_POST['search_status'];
        $startIndex = 0;
    } else {
        $startIndex = isset($_GET['psi']) ? (int) $_GET['psi'] : 0;
        if (isset($_SESSION['search_for']) && !isset($_GET['psi'])) {
            // He have not got scroll through patient records.
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        }
    }
    $_SESSION['search_page'] = $startIndex;
    $searchQuery = '';
    $countQuery = '';
    if (isset($_SESSION['search_for'])) {
        gen_manage_domain_query($searchQuery, $countQuery, $resellerId, $startIndex, $rowsPerPage, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        gen_manage_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
    } else {
        gen_manage_domain_query($searchQuery, $countQuery, $resellerId, $startIndex, $rowsPerPage, 'n/a', 'n/a', 'n/a');
        gen_manage_domain_search_options($tpl, 'n/a', 'n/a', 'n/a');
    }
    $stmt = execute_query($countQuery);
    $rowCount = $stmt->fields['cnt'];
    $stmt = execute_query($searchQuery);
    if ($rowCount == 0) {
        if (isset($_SESSION['search_for'])) {
            $tpl->assign(array('USR_MESSAGE' => tr('No records found matching the search criteria.'), 'USERS_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('View aliases'), 'SHOW_DETAILS' => tr('Show')));
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        } else {
            $tpl->assign(array('USERS_SEARCH' => '', 'USR_MESSAGE' => tr('No customer accounts found.'), 'USERS_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_PREV_GRAY' => '', 'SCROLL_NEXT' => '', 'SCROLL_NEXT_GRAY' => '', 'TR_VIEW_DETAILS' => tr('View aliases'), 'SHOW_DETAILS' => tr('Show')));
        }
        $tpl->parse('USR_MESSAGE', 'usr_message');
    } else {
        $prevSi = $startIndex - $rowsPerPage;
        if ($startIndex == 0) {
            $tpl->assign('SCROLL_PREV', '');
        } else {
            $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prevSi));
        }
        $nextSi = $startIndex + $rowsPerPage;
        if ($nextSi + 1 > $rowCount) {
            $tpl->assign('SCROLL_NEXT', '');
        } else {
            $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $nextSi));
        }
        while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
            if ($row['admin_status'] == 'ok' && $row['domain_status'] == 'ok') {
                $statusIcon = 'ok';
                $statusDomain = translate_dmn_status($row['domain_status']);
                $domainStatusTooltip = tr('Click to deactivate');
                $statusBool = true;
                $canChange = true;
            } else {
                if ($row['domain_status'] == 'disabled') {
                    $statusIcon = 'disabled';
                    $statusDomain = translate_dmn_status($row['domain_status']);
                    $domainStatusTooltip = tr('Click to activate');
                    $statusBool = false;
                    $canChange = true;
                } else {
                    if ($row['domain_status'] == 'toadd' || $row['domain_status'] == 'torestore' || $row['domain_status'] == 'tochange' || $row['domain_status'] == 'toenable' || $row['domain_status'] == 'todisable' || $row['domain_status'] == 'todelete') {
                        $statusIcon = 'reload';
                        $statusDomain = $domainStatusTooltip = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                        $statusBool = false;
                        $canChange = false;
                    } else {
                        $statusIcon = 'error';
                        $statusDomain = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                        $domainStatusTooltip = tr('An unexpected error occurred. Please contact your administrator.');
                        $statusBool = false;
                        $canChange = false;
                    }
                }
            }
            $domainId = $row['domain_id'];
            $tpl->assign(array('DOMAIN_STATUS' => $statusDomain, 'DOMAIN_STATUS_TOOLTIP' => $domainStatusTooltip, 'STATUS_ICON' => $statusIcon, 'DOMAIN_ID' => $domainId));
            if ($canChange) {
                $tpl->assign('DOMAIN_STATUS_NOCHANGE', '');
                $tpl->parse('DOMAIN_STATUS_CHANGE', 'domain_status_change');
            } else {
                $tpl->assign('DOMAIN_STATUS_CHANGE', '');
                $tpl->parse('DOMAIN_STATUS_NOCHANGE', 'domain_status_nochange');
            }
            $adminName = decode_idna($row['domain_name']);
            if ($statusBool == false) {
                // reload
                $tpl->assign('STATUS_RELOAD_TRUE', '');
                $tpl->assign('NAME', tohtml($adminName));
                $tpl->parse('STATUS_RELOAD_FALSE', 'status_reload_false');
            } else {
                $tpl->assign('STATUS_RELOAD_FALSE', '');
                $tpl->assign('NAME', $adminName);
                $tpl->parse('STATUS_RELOAD_TRUE', 'status_reload_true');
            }
            $domainCreated = $row['domain_created'];
            if ($domainCreated == 0) {
                $domainCreated = tr('N/A');
            } else {
                $domainCreated = date($cfg['DATE_FORMAT'], $domainCreated);
            }
            $tpl->assign(array('CREATION_DATE' => $domainCreated, 'ACTION' => tr('Delete'), 'USER_ID' => $row['domain_admin_id'], 'CHANGE_INTERFACE' => tr('Switch'), 'DISK_USAGE' => $row['domain_disk_limit'] ? tr('%1$s of %2$s', bytesHuman($row['domain_disk_usage']), mebibyteHuman($row['domain_disk_limit'])) : tr('%1$s of <b>unlimited</b>', bytesHuman($row['domain_disk_usage']))));
            gen_domain_details($tpl, $row['domain_id']);
            $tpl->parse('USER_ENTRY', '.user_entry');
        }
        $tpl->assign('USR_MESSAGE', '');
        $tpl->parse('USER_LIST', 'users_list');
    }
}
Example #2
0
/**
 * Translates '-1', 'no', 'yes', '0' or mebibyte value string into human readable string.
 *
 * @param int $value variable to be translated
 * @param bool $autosize calculate value in different unit (default false)
 * @param string $to OPTIONAL Unit to calclulate to ('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
 * @return String
 */
function translate_limit_value($value, $autosize = false, $to = null)
{
    $trEnabled = '<span style="color:green">' . tr('Enabled') . '</span>';
    $trDisabled = '<span style="color:red">' . tr('Disabled') . '</span>';
    switch ($value) {
        case '-1':
            return tr('Disabled');
        case '0':
            return tr('Unlimited');
        case '_yes_':
        case 'yes':
            return $trEnabled;
        case '_no_':
        case 'no':
            return $trDisabled;
        case 'full':
            return '<span style="color:green">' . tr('Domain and SQL databases') . '</span>';
        case 'dmn':
            return '<span style="color:green">' . tr('Web files only') . '</span>';
        case 'sql':
            return '<span style="color:green">' . tr('SQL databases only') . '</span>';
        default:
            return !$autosize ? $value : mebibyteHuman($value, $to);
    }
}