function gen_user_list(&$tpl, &$sql)
{
    global $cfg;
    $start_index = 0;
    $rows_per_page = $cfg['DOMAIN_ROWS_PER_PAGE'];
    if (isset($_GET['psi'])) {
        $start_index = $_GET['psi'];
    }
    //
    //  Search requet generated ?!
    //
    if (isset($_POST['uaction']) && $_POST['uaction'] !== '') {
        $_SESSION['search_for'] = trim($_POST['search_for']);
        $_SESSION['search_common'] = $_POST['search_common'];
        $_SESSION['search_status'] = $_POST['search_status'];
        $start_index = 0;
    } else {
        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']);
        }
    }
    $search_query = '';
    $count_query = '';
    if (isset($_SESSION['search_for'])) {
        gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        gen_admin_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        $rs = exec_query($sql, $count_query, array());
    } else {
        gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, 'n/a', 'n/a', 'n/a');
        gen_admin_domain_search_options($tpl, 'n/a', 'n/a', 'n/a');
        $rs = exec_query($sql, $count_query, array());
    }
    $records_count = $rs->fields['cnt'];
    // print "records count: ".$records_count."<br>";
    $rs = execute_query($sql, $search_query);
    $i = 0;
    if ($rs->RecordCount() == 0) {
        if (isset($_SESSION['search_for'])) {
            $tpl->assign(array('USR_MESSAGE' => tr('Not found user records matching the search criteria!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => "show"));
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        } else {
            $tpl->assign(array('USR_MESSAGE' => tr('Users list is empty!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => "show"));
        }
        $tpl->parse('USR_MESSAGE', 'usr_message');
    } 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));
        }
        $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));
        }
        $tpl->assign(array('TR_USR_USERNAME' => tr('Username'), 'TR_USR_CREATED_BY' => tr('Created by'), 'TR_USR_OPTIONS' => tr('Options'), 'TR_USER_STATUS' => tr('S'), 'TR_D' => tr('D'), 'TR_DETAILS' => tr('Details')));
        while (!$rs->EOF) {
            if ($i % 2 == 0) {
                $tpl->assign(array('USR_CLASS' => 'content'));
            } else {
                $tpl->assign(array('USR_CLASS' => 'content2'));
            }
            // user status icon
            $domain_created_id = $rs->fields['domain_created_id'];
            $query = <<<SQL_QUERY
        select
            admin_id,
            admin_name
        from
            admin
        where
            admin_id=?
\t\torder by
\t\t\tadmin_name
\t\tasc
SQL_QUERY;
            $rs2 = exec_query($sql, $query, array($domain_created_id));
            if ($rs2->fields['admin_name'] == '') {
                $tpl->assign(array('TR_DELETE' => tr('Delete'), 'USR_DELETE_LINK' => ''));
                $tpl->parse('USR_DELETE_SHOW', 'usr_delete_show');
            } else {
                $tpl->assign(array('USR_DELETE_SHOW' => '', 'DOMAIN_ID' => $rs->fields['domain_id'], 'TR_DELETE' => tr('Delete'), 'URL_DELETE_USR' => "delete_user.php?delete_id=" . $rs->fields['domain_admin_id'] . "&delete_username="******"change_user_interface.php?to_id=" . $rs->fields['domain_admin_id']));
                $tpl->parse('USR_DELETE_LINK', 'usr_delete_link');
            }
            global $cfg;
            if ($rs->fields['domain_status'] == $cfg['ITEM_OK_STATUS']) {
                $status_icon = "ok.gif";
                $status_url = "change_status.php?domain_id=" . $rs->fields['domain_id'];
            } else {
                if ($rs->fields['domain_status'] == $cfg['ITEM_DISABLED_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_DELETE_STATUS']) {
                    $status_icon = "disabled.gif";
                    $status_url = "change_status.php?domain_id=" . $rs->fields['domain_id'];
                } else {
                    if ($rs->fields['domain_status'] == $cfg['ITEM_ADD_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_RESTORE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_CHANGE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_TOENABLE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_TODISABLED_STATUS']) {
                        $status_icon = "reload.gif";
                        $status_url = "#";
                    } else {
                        $status_icon = "error.gif";
                        $status_url = "domain_details.php?domain_id=" . $rs->fields['domain_id'];
                    }
                }
            }
            $tpl->assign(array('STATUS_ICON' => $status_icon, 'URL_CHNAGE_STATUS' => $status_url));
            // end of user status icon
            $admin_name = decode_idna($rs->fields['domain_name']);
            $domain_created = $rs->fields['domain_created'];
            if ($domain_created == 0) {
                $domain_created = tr('N/A');
            } else {
                global $cfg;
                $date_formt = $cfg['DATE_FORMAT'];
                $domain_created = date($date_formt, $domain_created);
            }
            $tpl->assign(array('USR_USERNAME' => $admin_name, 'USER_CREATED_ON' => $domain_created, 'USR_CREATED_BY' => $rs2->fields['admin_name'], 'USR_OPTIONS' => '', 'URL_EDIT_USR' => "edit_user.php?edit_id=" . $rs->fields['domain_admin_id'], 'TR_MESSAGE_CHANGE_STATUS' => tr('Are you sure you want to change the status of domain account?'), 'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete this account?')));
            gen_domain_details($tpl, $sql, $rs->fields['domain_id']);
            $tpl->parse('USR_ITEM', '.usr_item');
            $rs->MoveNext();
            $i++;
        }
        $tpl->parse('USR_LIST', 'usr_list');
        $tpl->assign('USR_MESSAGE', '');
    }
}
Example #2
0
/**
 * @param EasySCP_TemplateEngine $tpl
 * @param EasySCP_Database $sql
 */
function gen_user_list($tpl, $sql)
{
    $cfg = EasySCP_Registry::get('Config');
    $start_index = 0;
    $rows_per_page = $cfg->DOMAIN_ROWS_PER_PAGE;
    if (isset($_GET['psi'])) {
        $start_index = $_GET['psi'];
    }
    // Search request generated ?!
    if (isset($_POST['uaction']) && !empty($_POST['uaction'])) {
        $_SESSION['search_for'] = trim(clean_input($_POST['search_for']));
        $_SESSION['search_common'] = $_POST['search_common'];
        $_SESSION['search_status'] = $_POST['search_status'];
        $start_index = 0;
    } elseif (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']);
    }
    $search_query = '';
    $count_query = '';
    if (isset($_SESSION['search_for'])) {
        gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        gen_admin_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        $rs = exec_query($sql, $count_query);
    } else {
        gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, 'n/a', 'n/a', 'n/a');
        gen_admin_domain_search_options($tpl, 'n/a', 'n/a', 'n/a');
        $rs = exec_query($sql, $count_query);
    }
    $records_count = $rs->fields['cnt'];
    $rs = execute_query($sql, $search_query);
    if ($rs->recordCount() == 0) {
        if (isset($_SESSION['search_for'])) {
            $tpl->assign(array('USR_MESSAGE' => tr('Not found user records matching the search criteria!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => 'show'));
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        } else {
            $tpl->assign(array('USR_MESSAGE' => tr('Users list is empty!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => 'show'));
        }
    } 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));
        }
        $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));
        }
        $tpl->assign(array('TR_USR_USERNAME' => tr('Username'), 'TR_USR_CREATED_BY' => tr('Created by'), 'TR_USR_OPTIONS' => tr('Options'), 'TR_USER_STATUS' => tr('Status'), 'TR_DETAILS' => tr('Details'), 'TR_EDIT_DOMAIN' => tr('Edit domain'), 'TR_EDIT_USR' => tr('Edit user')));
        while (!$rs->EOF) {
            // user status icon
            $domain_created_id = $rs->fields['domain_created_id'];
            $query = "\n\t\t\t\tSELECT\n\t\t\t\t\t`admin_name`\n\t\t\t\tFROM\n\t\t\t\t\t`admin`\n\t\t\t\tWHERE\n\t\t\t\t\t`admin_id` = ?\n\t\t\t\tORDER BY\n\t\t\t\t\t`admin_name`\n\t\t\t\tASC\n\t\t\t\t;\n\t\t\t";
            $rs2 = exec_query($sql, $query, $domain_created_id);
            if (!isset($rs2->fields['admin_name'])) {
                $created_by_name = tr('N/A');
            } else {
                $created_by_name = $rs2->fields['admin_name'];
            }
            // Get disk usage by user
            $tpl->append(array('USR_DELETE_SHOW' => '', 'DOMAIN_ID' => $rs->fields['domain_id'], 'URL_DELETE_USR' => 'user_delete.php?domain_id=' . $rs->fields['domain_id'], 'URL_CHANGE_INTERFACE' => 'change_user_interface.php?to_id=' . $rs->fields['domain_admin_id']));
            if ($rs->fields['status'] == $cfg->ITEM_OK_STATUS) {
                $status_icon = 'ok';
                $status_url = 'domain_status_change.php?domain_id=' . $rs->fields['domain_id'];
            } elseif ($rs->fields['status'] == $cfg->ITEM_DISABLED_STATUS) {
                $status_icon = 'disabled';
                $status_url = 'domain_status_change.php?domain_id=' . $rs->fields['domain_id'];
            } elseif ($rs->fields['status'] == $cfg->ITEM_ADD_STATUS || $rs->fields['status'] == $cfg->ITEM_RESTORE_STATUS || $rs->fields['status'] == $cfg->ITEM_CHANGE_STATUS || $rs->fields['status'] == $cfg->ITEM_TOENABLE_STATUS || $rs->fields['status'] == $cfg->ITEM_TODISABLED_STATUS || $rs->fields['status'] == $cfg->ITEM_DELETE_STATUS) {
                $status_icon = 'reload';
                $status_url = '#';
            } else {
                $status_icon = 'error';
                $status_url = 'domain_details.php?domain_id=' . $rs->fields['domain_id'];
            }
            $tpl->append(array('STATUS_ICON' => $status_icon, 'URL_CHANGE_STATUS' => $status_url));
            // end of user status icon
            $admin_name = decode_idna($rs->fields['domain_name']);
            $domain_created = $rs->fields['domain_created'];
            if ($domain_created == 0) {
                $domain_created = tr('N/A');
            } else {
                $date_formt = $cfg->DATE_FORMAT;
                $domain_created = date($date_formt, $domain_created);
            }
            $domain_expires = $rs->fields['domain_expires'];
            if ($domain_expires == 0) {
                $domain_expires = tr('Not Set');
            } else {
                $date_formt = $cfg->DATE_FORMAT;
                $domain_expires = date($date_formt, $domain_expires);
            }
            $tpl->append(array('USR_USERNAME' => tohtml($admin_name), 'USER_CREATED_ON' => tohtml($domain_created), 'USER_EXPIRES_ON' => $domain_expires, 'USR_CREATED_BY' => tohtml($created_by_name), 'USR_OPTIONS' => '', 'URL_EDIT_USR' => 'admin_edit.php?edit_id=' . $rs->fields['domain_admin_id']));
            gen_domain_details($tpl, $sql, $rs->fields['domain_id']);
            $rs->moveNext();
        }
    }
}
Example #3
0
/**
 * Helper function to generate a user list
 *
 * @param iMSCP_pTemplate $tpl iMSCP_pTemplate instance
 * @return void
 */
function gen_user_list($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $startIndex = 0;
    $rowsPerPage = $cfg['DOMAIN_ROWS_PER_PAGE'];
    if (isset($_GET['psi']) && $_GET['psi'] == 'last') {
        if (isset($_SESSION['search_page'])) {
            $_GET['psi'] = $_SESSION['search_page'];
        } else {
            unset($_GET['psi']);
        }
    }
    if (isset($_GET['psi'])) {
        $startIndex = $_GET['psi'];
    }
    // Search request generated ?
    if (isset($_POST['uaction']) && !empty($_POST['uaction'])) {
        $_SESSION['search_for'] = clean_input($_POST['search_for']);
        $_SESSION['search_common'] = $_POST['search_common'];
        $_SESSION['search_status'] = $_POST['search_status'];
        $startIndex = 0;
    } elseif (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']);
    }
    $searchQuery = $countQuery = '';
    if (isset($_SESSION['search_for'])) {
        gen_admin_domain_query($searchQuery, $countQuery, $startIndex, $rowsPerPage, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        gen_admin_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        $stmt = exec_query($countQuery);
    } else {
        gen_admin_domain_query($searchQuery, $countQuery, $startIndex, $rowsPerPage, 'n/a', 'n/a', 'n/a');
        gen_admin_domain_search_options($tpl, 'n/a', 'n/a', 'n/a');
        $stmt = exec_query($countQuery);
    }
    $recordCount = $stmt->fields['cnt'];
    $stmt = execute_query($searchQuery);
    if (!$stmt->rowCount()) {
        if (isset($_SESSION['search_for'])) {
            $tpl->assign(array('USR_MESSAGE' => tr('No records found matching the search criteria.'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => 'show'));
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        } else {
            $tpl->assign(array('SEARCH_FORM' => '', 'USR_MESSAGE' => tr('No customer accounts found.'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => '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 > $recordCount) {
            $tpl->assign('SCROLL_NEXT', '');
        } else {
            $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $nextSi));
        }
        $tpl->assign(array('TR_USR_USERNAME' => tr('Username'), 'TR_USR_CREATED_BY' => tr('Created by'), 'TR_USR_ACTIONS' => tr('Actions'), 'TR_USER_STATUS' => tr('Status'), 'TR_DETAILS' => tr('Details')));
        while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
            // user status icon
            $domainCreatedBy = $row['created_by'];
            $stmt2 = exec_query('SELECT admin_name, admin_status FROM admin WHERE admin_id = ?', $domainCreatedBy);
            if (!isset($stmt2->fields['admin_name'])) {
                $createdByName = tr('N/A');
            } else {
                $createdByName = $stmt2->fields['admin_name'];
            }
            $tpl->assign(array('USR_DELETE_SHOW' => '', 'USER_ID' => $row['admin_id'], 'DOMAIN_ID' => $row['domain_id'], 'TR_DELETE' => tr('Delete'), 'URL_DELETE_USR' => 'user_delete.php?domain_id=' . $row['domain_id'], 'TR_CHANGE_USER_INTERFACE' => tr('Switch to user interface'), 'GO_TO_USER_INTERFACE' => tr('Switch'), 'URL_CHANGE_INTERFACE' => 'change_user_interface.php?to_id=' . $row['domain_admin_id'], 'USR_USERNAME' => tohtml($row['domain_name']), 'TR_EDIT_DOMAIN' => tr('Edit domain'), 'TR_EDIT_USR' => tr('Edit user')));
            $tpl->parse('USR_DELETE_LINK', 'usr_delete_link');
            if ($row['admin_status'] == 'ok' && $row['domain_status'] == 'ok') {
                $status = 'ok';
                $statusTooltip = tr('Click to deactivate');
                $statusTxt = translate_dmn_status($row['domain_status']);
                $statusBool = true;
                $canChange = true;
            } elseif ($row['domain_status'] == 'disabled') {
                $status = 'disabled';
                $statusTooltip = tr('Click to activate');
                $statusTxt = translate_dmn_status($row['domain_status']);
                $statusBool = false;
                $canChange = true;
            } elseif ($row['domain_status'] == 'toadd' || $row['domain_status'] == 'torestore' || $row['domain_status'] == 'tochange' || $row['domain_status'] == 'toenable' || $row['domain_status'] == 'todisable' || $row['domain_status'] == 'todelete') {
                $status = 'reload';
                $statusTxt = $statusTooltip = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                $statusBool = false;
                $canChange = false;
            } else {
                $status = 'error';
                $statusTooltip = tr('An unexpected error occurred. Go to the debugger interface for more details.');
                $statusTxt = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                $statusBool = false;
                $canChange = false;
            }
            $tpl->assign(array('STATUS' => $status, 'STATUS_TOOLTIP' => $statusTooltip, 'TR_STATUS' => $statusTxt));
            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']);
            $domainCreated = $row['domain_created'];
            if ($domainCreated == 0) {
                $domainCreated = tr('N/A');
            } else {
                $date_formt = $cfg['DATE_FORMAT'];
                $domainCreated = date($date_formt, $domainCreated);
            }
            $domainExpires = $row['domain_expires'];
            if ($domainExpires == 0) {
                $domainExpires = tr('Not Set');
            } else {
                $date_formt = $cfg['DATE_FORMAT'];
                $domainExpires = date($date_formt, $domainExpires);
            }
            if ($statusBool == false) {
                // reload
                $tpl->assign('USR_STATUS_RELOAD_TRUE', '');
                $tpl->assign('USR_USERNAME', tohtml($adminName));
                $tpl->parse('USR_STATUS_RELOAD_FALSE', 'usr_status_reload_false');
            } else {
                $tpl->assign('USR_STATUS_RELOAD_FALSE', '');
                $tpl->assign('USR_USERNAME', tohtml($adminName));
                $tpl->parse('USR_STATUS_RELOAD_TRUE', 'usr_status_reload_true');
            }
            $tpl->assign(array('USER_CREATED_ON' => tohtml($domainCreated), 'USER_EXPIRES_ON' => $domainExpires, 'USR_CREATED_BY' => tohtml($createdByName), 'USR_OPTIONS' => '', 'URL_EDIT_USR' => 'admin_edit.php?edit_id=' . $row['domain_admin_id'], 'TR_MESSAGE_DELETE' => tojs(tr('Are you sure you want to delete %s?', '%s'))));
            gen_domain_details($tpl, $row['domain_id']);
            $tpl->parse('USR_ITEM', '.usr_item');
        }
        $tpl->parse('USR_LIST', 'usr_list');
        $tpl->assign('USR_MESSAGE', '');
    }
}