Skip to content

Commit

Permalink
Fix session list see #7719
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 1, 2015
1 parent 15dc683 commit 50a5066
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 104 deletions.
10 changes: 8 additions & 2 deletions main/inc/ajax/extra_field.ajax.php
@@ -1,7 +1,9 @@
<?php
/* For licensing terms, see /license.txt */

require_once '../global.inc.php';
$action = $_GET['a'];

$action = isset($_GET['a']) ? $_GET['a'] : '';

switch ($action) {
case 'get_second_select_options':
Expand All @@ -11,7 +13,11 @@

if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
$field_options = new ExtraFieldOption($type);
echo $field_options->get_second_select_field_options_by_field($field_id, $option_value_id, true);
echo $field_options->get_second_select_field_options_by_field(
$field_id,
$option_value_id,
true
);
}
break;
case 'search_tags':
Expand Down
5 changes: 2 additions & 3 deletions main/inc/ajax/model.ajax.php
Expand Up @@ -115,8 +115,7 @@ function getWhereClause($col, $oper, $val)
if (!empty($whereConditionInForm)) {
$whereCondition .= ' AND '.$whereConditionInForm;
}

$filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
$filters = isset($_REQUEST['filters']) && !is_array($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;

/*if (!empty($filters) && !empty($filters->rules)) {
$whereCondition .= ' AND ( ';
Expand Down Expand Up @@ -928,7 +927,7 @@ function getWhereClause($col, $oper, $val)
break;
case 'get_sessions':

$session_columns = SessionManager::get_session_columns($list_type);
$session_columns = SessionManager::getGridColumns($list_type);
$columns = $session_columns['simple_column_name'];

if ($list_type == 'simple') {
Expand Down
278 changes: 179 additions & 99 deletions main/session/session_list.php
Expand Up @@ -16,13 +16,14 @@

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
$list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';

if ($action == 'delete') {
SessionManager::delete($idChecked);
header('Location: session_list.php');
exit();
} elseif ($action == 'copy') {
SessionManager::copy_session($idChecked);
SessionManager::copy($idChecked);
header('Location: session_list.php');
exit();
}
Expand All @@ -32,17 +33,8 @@
$tool_name = get_lang('SessionList');
Display::display_header($tool_name);

$error_message = '';
// Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
$error_message = Security::remove_XSS($_GET['message']);
}

if (!empty($error_message)) {
Display::display_normal_message($error_message, false);
}

$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course';

$courseList = array();
$courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
if (!empty($courseId)) {
Expand Down Expand Up @@ -78,7 +70,6 @@
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
}


if (isset($_REQUEST['keyword'])) {
//Begin with see the searchOper param
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';
Expand All @@ -92,50 +83,31 @@
}
}

//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(
get_lang('Name'),
get_lang('NumberOfCourses'),
get_lang('NumberOfUsers'),
get_lang('SessionCategoryName'),
get_lang('StartDate'),
get_lang('EndDate'),
get_lang('Coach'),
get_lang('Status'),
get_lang('Visibility'),
get_lang('Actions')
);
$url .= '&list_type='.$list_type;

//Column config
$column_model = array(
array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
array('name'=>'nbr_courses', 'index'=>'nbr_courses', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'nbr_users', 'index'=>'nbr_users', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'category_name', 'index'=>'sc.name', 'width'=>'70', 'align'=>'left', 'search' => 'true'),
array('name'=>'access_start_date', 'index'=>'s.access_start_date', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
array('name'=>'access_end_date', 'index'=>'s.access_end_date', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'80', 'align'=>'left', 'search' => 'false'),
array('name'=>'status', 'index'=>'session_active','width'=>'50', 'align'=>'left', 'search' => 'true', 'stype'=>'select',
//for the bottom bar
'searchoptions' => array(
'defaultValue' => ':',
'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive')
),
//for the top bar
'editoptions' => array(
'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive')
)
),
array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
);
$result = SessionManager::getGridColumns($list_type);

$columns = $result['columns'];
$column_model = $result['column_model'];

//Autowidth
$extra_params['autowidth'] = 'true';

//height auto
$extra_params['height'] = 'auto';

$extra_params['postData'] =array(
'filters' => array(
"groupOp" => "AND",
"rules" => $result['rules'],
/*array(
array( "field" => "display_start_date", "op" => "gt", "data" => ""),
array( "field" => "display_end_date", "op" => "gt", "data" => "")
),*/
//'groups' => $groups
)
);

//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
Expand All @@ -145,72 +117,174 @@
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=delete&idChecked=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
}';

$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';

?>
<script>

function setSearchSelect(columnName) {
$("#sessions").jqGrid(
'setColProp',
columnName,
{
searchoptions: {
dataInit:function(el) {
$("option[value='2']",el).attr("selected", "selected");
setTimeout(function() {
$(el).trigger('change');
}, 1000);
}
$("#sessions").jqGrid('setColProp', columnName, {
/*searchoptions:{
dataInit:function(el){
$("option[value='1']",el).attr("selected", "selected");
setTimeout(function(){
$(el).trigger('change');
}, 1000);
}
}
);
}*/
});
}
var added_cols = [];
var original_cols = [];

function clean_cols(grid, added_cols) {
//Cleaning
for (key in added_cols) {
//console.log('hide: ' + key);
grid.hideCol(key);
};
grid.showCol('name');
grid.showCol('display_start_date');
grid.showCol('display_end_date');
grid.showCol('course_title');
}

function show_cols(grid, added_cols) {
grid.showCol('name').trigger('reloadGrid');
for (key in added_cols) {
//console.log('show: ' + key);
grid.showCol(key);
};
}

var second_filters = [];

$(function() {
<?php
echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
?>

date_pick_today = function(elem) {
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
$(elem).datetimepicker('setDate', (new Date()));
}
date_pick_one_month = function(elem) {
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
next_month = Date.today().next().month();
$(elem).datetimepicker('setDate', next_month);
}

//Great hack
register_second_select = function(elem) {
second_filters[$(elem).val()] = $(elem);
}

fill_second_select = function(elem) {
$(elem).on("change", function() {
composed_id = $(this).val();
field_id = composed_id.split("#")[0];
id = composed_id.split("#")[1];

$.ajax({
url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
dataType: "json",
data: "type=session&field_id="+field_id+"&option_value_id="+id,
success: function(data) {
my_select = second_filters[field_id];
my_select.empty();
$.each(data, function(index, value) {
my_select.append($("<option/>", {
value: index,
text: value
}));
});
}
});
});
}

<?php
echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
?>

setSearchSelect("status");

$("#sessions").jqGrid(
'navGrid',
'#sessions_pager',
{ edit: false, add: false, del: false},
{ height:280, reloadAfterSubmit:false }, // edit options
{ height:280, reloadAfterSubmit:false }, // add options
{ reloadAfterSubmit:false }, // del options
{ width:500 } // search options
var grid = $("#sessions"),
prmSearch = {
multipleSearch : true,
overlay : false,
width: 'auto',
caption: '<?php echo addslashes(get_lang('Search')); ?>',
formclass:'data_table',
onSearch : function() {
var postdata = grid.jqGrid('getGridParam', 'postData');

if (postdata && postdata.filters) {
filters = jQuery.parseJSON(postdata.filters);
clean_cols(grid, added_cols);
added_cols = [];
$.each(filters, function(key, value){
//console.log('key: ' + key );
if (key == 'rules') {
$.each(value, function(subkey, subvalue) {
if (subvalue.data == undefined) {
}

//if (added_cols[value.field] == undefined) {
added_cols[subvalue.field] = subvalue.field;
//}
//grid.showCol(value.field);
});
}
});
show_cols(grid, added_cols);
}
},
onReset: function() {
clean_cols(grid, added_cols);
}
};

original_cols = grid.jqGrid('getGridParam', 'colModel');

grid.jqGrid('navGrid','#sessions_pager',
{edit:false,add:false,del:false},
{height:280,reloadAfterSubmit:false}, // edit options
{height:280,reloadAfterSubmit:false}, // add options
{reloadAfterSubmit:false},// del options
prmSearch
);

/*
// add custom button to export the data to excel
jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
caption:"",
onClickButton : function () {
jQuery("#sessions").excelExport();
}
// Create the searching dialog.
grid.searchGrid(prmSearch);

// Fixes search table.
var searchDialogAll = $("#fbox_"+grid[0].id);
searchDialogAll.addClass("table");
var searchDialog = $("#searchmodfbox_"+grid[0].id);
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})
var gbox = $("#gbox_"+grid[0].id);
gbox.before(searchDialog);
gbox.css({clear:"left"});

//Select first elements by default
$('.input-elm').each(function(){
$(this).find('option:first').attr('selected', 'selected');
});

jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
{
try {
jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
} catch (e) {
window.location= 'grid.php?oper=csv';
}
},buttonicon:'ui-icon-document'})
*/

// Adding search options
var options = {
'stringResult': true,
'autosearch' : true,
'searchOnEnter':false
}
$('.delete-rule').each(function(){
$(this).click(function(){
$('.input-elm').each(function(){
$(this).find('option:first').attr('selected', 'selected');
});
});
});

jQuery("#sessions").jqGrid('filterToolbar', options);
var sgrid = $("#sessions")[0];
sgrid.triggerToolbar();
/*
$('.delete-rule').on('click', function(){
console.log('deleted');
$('.input-elm').each(function(){
$(this).find('option:first').attr('selected', 'selected');
});
});*/
});
</script>
<div class="actions">
Expand All @@ -225,6 +299,12 @@ function setSearchSelect(columnName) {
Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
}

if ($list_type == 'complete') {
echo '<a href="'.api_get_self().'?list_type=simple">'.Display::return_icon('view_remove.png',get_lang('Simple'),'',ICON_SIZE_MEDIUM).'</a>';
} else {
echo '<a href="'.api_get_self().'?list_type=complete">'.Display::return_icon('view_text.png',get_lang('Complete'),'',ICON_SIZE_MEDIUM).'</a>';
}

echo $actions;
if (api_is_platform_admin()) {
echo '<div class="pull-right">';
Expand Down

0 comments on commit 50a5066

Please sign in to comment.