Code clean up + format - refs BT#15515

pull/2874/head
Angel Fernando Quiroz Campos 7 years ago
parent ff66bd1712
commit ea2f8f5b24
  1. 230
      main/session/session_category_list.php

@ -27,8 +27,12 @@ $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$page = isset($_GET['page']) ? intval($_GET['page']) : null; $page = isset($_GET['page']) ? intval($_GET['page']) : null;
$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : null; $action = isset($_REQUEST['action'])
$sort = isset($_GET['sort']) && in_array($_GET['sort'], ['name', 'nbr_session', 'date_start', 'date_end']) ? Security::remove_XSS($_GET['sort']) : 'name'; ? Security::remove_XSS($_REQUEST['action'])
: null;
$sort = isset($_GET['sort']) && in_array($_GET['sort'], ['name', 'nbr_session', 'date_start', 'date_end'])
? Security::remove_XSS($_GET['sort'])
: 'name';
$idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null; $idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null;
$order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) : 'ASC'; $order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) : 'ASC';
$keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : null; $keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : null;
@ -46,7 +50,7 @@ $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionLi
if (isset($_GET['search']) && $_GET['search'] == 'advanced') { if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
$interbreadcrumb[] = ["url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory')]; $interbreadcrumb[] = ["url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory')];
$tool_name = get_lang('SearchASession'); $tool_name = get_lang('SearchASession');
Display :: display_header($tool_name); Display::display_header($tool_name);
$form = new FormValidator('advanced_search', 'get'); $form = new FormValidator('advanced_search', 'get');
$form->addElement('header', '', $tool_name); $form->addElement('header', '', $tool_name);
$active_group = []; $active_group = [];
@ -64,9 +68,9 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
//if user is crfp admin only list its sessions //if user is crfp admin only list its sessions
$where = null; $where = null;
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
$where .= (empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'"); $where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'";
} else { } else {
$where .= (empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'"); $where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'";
} }
if (empty($where)) { if (empty($where)) {
$where = " WHERE access_url_id = ".api_get_current_access_url_id()." "; $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
@ -102,27 +106,35 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
<div class="actions"> <div class="actions">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php <?php
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_add.php">'. echo Display::url(
Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), '', ICON_SIZE_MEDIUM).'</a> Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), [], ICON_SIZE_MEDIUM),
<a href="'.api_get_path(WEB_CODE_PATH).'session/session_list.php">'. api_get_path(WEB_CODE_PATH).'session/session_category_add.php'
Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>'; ?> );
echo Display::url(
Display::return_icon('session.png', get_lang('ListSession'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'session/session_list.php'
);
?>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="pull-right"> <div class="pull-right">
<form method="POST" action="session_category_list.php" class="form-inline"> <form method="POST" action="session_category_list.php" class="form-inline">
<div class="form-group"> <div class="form-group">
<input class="form-control" type="text" name="keyword" value="<?php echo $keyword; ?>" <input class="form-control" type="text" name="keyword" value="<?php echo $keyword; ?>"
aria-label="<?php echo get_lang('Search'); ?>"/> aria-label="<?php echo get_lang('Search'); ?>"/>
<button class="btn btn-default" type="submit" name="name" value="<?php echo get_lang('Search'); ?>"><em class="fa fa-search"></em> <?php echo get_lang('Search'); ?></button> <button class="btn btn-default" type="submit" name="name"
<!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> --> value="<?php echo get_lang('Search'); ?>"><em
</div> class="fa fa-search"></em> <?php echo get_lang('Search'); ?></button>
</form> <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
</div>
</form>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"> <form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>"
onsubmit="if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
<?php <?php
if (count($Sessions) == 0 && isset($_POST['keyword'])) { if (count($Sessions) == 0 && isset($_POST['keyword'])) {
echo Display::return_message(get_lang('NoSearchResults'), 'warning'); echo Display::return_message(get_lang('NoSearchResults'), 'warning');
@ -164,24 +176,28 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
} }
?> ?>
<table class="data_table" width="100%"> <table class="data_table" width="100%">
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order : 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th> <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order
<th><a href="<?php echo api_get_self(); ?>?sort=nbr_session&order=<?php echo ($sort == 'nbr_session') ? $order : 'ASC'; ?>"><?php echo get_lang('NumberOfSession'); ?></a></th> : 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
<th><a href="<?php echo api_get_self(); ?>?sort=date_start&order=<?php echo ($sort == 'date_start') ? $order : 'ASC'; ?>"><?php echo get_lang('StartDate'); ?></a></th> <th><a href="<?php echo api_get_self(); ?>?sort=nbr_session&order=<?php echo ($sort
<th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort == 'date_end') ? $order : 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th> == 'nbr_session') ? $order : 'ASC'; ?>"><?php echo get_lang('NumberOfSession'); ?></a></th>
<th><?php echo get_lang('Actions'); ?></th> <th><a href="<?php echo api_get_self(); ?>?sort=date_start&order=<?php echo ($sort == 'date_start')
</tr> ? $order : 'ASC'; ?>"><?php echo get_lang('StartDate'); ?></a></th>
<th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort == 'date_end')
? $order : 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th>
<th><?php echo get_lang('Actions'); ?></th>
</tr>
<?php <?php
$i = 0; $i = 0;
$x = 0; $x = 0;
foreach ($Sessions as $key => $enreg) { foreach ($Sessions as $key => $enreg) {
if ($key == $limit) { if ($key == $limit) {
break; break;
} }
$sql = 'SELECT COUNT(session_category_id) $sql = 'SELECT COUNT(session_category_id)
FROM '.$tbl_session.' s FROM '.$tbl_session.' s
INNER JOIN '.$table_access_url_rel_session.' us INNER JOIN '.$table_access_url_rel_session.' us
ON (s.id = us.session_id) ON (s.id = us.session_id)
@ -189,83 +205,105 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
s.session_category_id = '.intval($enreg['id']).' AND s.session_category_id = '.intval($enreg['id']).' AND
us.access_url_id = '.api_get_current_access_url_id(); us.access_url_id = '.api_get_current_access_url_id();
$rs = Database::query($sql); $rs = Database::query($sql);
list($nb_courses) = Database::fetch_array($rs); ?> list($nb_courses) = Database::fetch_array($rs); ?>
<tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>"> <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
<td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td> <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]"
<td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td> value="<?php echo $enreg['id']; ?>"></td>
<td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Session(s) </a>"; ?></td> <td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
<td><?php echo api_format_date($enreg['date_start'], DATE_FORMAT_SHORT); ?></td> <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses
<td> ." Session(s) </a>"; ?></td>
<?php <td><?php echo api_format_date($enreg['date_start'], DATE_FORMAT_SHORT); ?></td>
if (!empty($enreg['date_end']) && $enreg['date_end'] != '0000-00-00') { <td>
echo api_format_date($enreg['date_end'], DATE_FORMAT_SHORT); <?php
} else { if (!empty($enreg['date_end']) && $enreg['date_end'] != '0000-00-00') {
echo '-'; echo api_format_date($enreg['date_end'], DATE_FORMAT_SHORT);
} ?> } else {
</td> echo '-';
<td> } ?>
<a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>"> </td>
<?php Display::display_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL); ?> <td>
</a> <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
<a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&idChecked=<?php echo $enreg['id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"> <?php Display::display_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL); ?>
<?php Display::display_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL); ?> </a>
</a> <a href="<?php echo api_get_self(
</td> ); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&idChecked=<?php echo $enreg['id']; ?>"
</tr> onclick="if(!confirm('<?php echo get_lang(
<?php 'ConfirmYourChoice'
$i = $i ? 0 : 1; ); ?>')) return false;">
$x++; <?php Display::display_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL); ?>
} </a>
unset($Sessions); ?> </td>
</table> </tr>
<br /> <?php
<div> $i = $i ? 0 : 1;
<?php $x++;
if ($num > $limit) { }
if ($page) { unset($Sessions); ?>
?> </table>
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page - 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"> <br/>
<?php echo get_lang('Previous'); ?></a> <div>
<?php <?php
} else { if ($num > $limit) {
echo get_lang('Previous'); if ($page) {
} ?> ?>
| <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
<?php - 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
if ($nbr_results > $limit) { $_REQUEST['order']
?> ); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
<?php echo get_lang('Previous'); ?></a>
<?php
} else {
echo get_lang('Previous');
} ?>
|
<?php
if ($nbr_results > $limit) {
?>
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page + 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"> <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
<?php echo get_lang('Next'); ?></a> + 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
$_REQUEST['order']
); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
<?php echo get_lang('Next'); ?></a>
<?php <?php
} else { } else {
echo get_lang('Next'); echo get_lang('Next');
} }
} ?> } ?>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-4"> <div class="col-sm-4">
<div class="btn-group"> <div class="btn-group">
<a class="btn btn-default" href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll'); ?></a> <button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');">
<a class="btn btn-default" href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll'); ?></a> <?php echo get_lang('SelectAll'); ?>
</button>
<button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');">
<?php echo get_lang('UnSelectAll'); ?>
</button>
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<select class="selectpicker show-tick form-control" name="action"> <select class="selectpicker show-tick form-control" name="action">
<option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option> <option value="delete_off_session" selected="selected">
<option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option> <?php echo get_lang('DeleteSelectedSessionCategory'); ?>
</option>
<option value="delete_on_session">
<?php echo get_lang('DeleteSelectedFullSessionCategory'); ?>
</option>
</select> </select>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('Ok'); ?></button> <button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok'); ?>">
<?php echo get_lang('Ok'); ?>
</button>
</div> </div>
</div> </div>
<?php <?php
} ?> } ?>
</table> </table>
</form> </form>
<?php <?php
} }
Display::display_footer(); Display::display_footer();

Loading…
Cancel
Save