Răsfoiți Sursa

Replacing old session list with a new jqgrid table see BT#3368

Julio Montoya 13 ani în urmă
părinte
comite
72ae108827

+ 69 - 327
main/admin/session_list.php

@@ -12,348 +12,90 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script(true);
 
-$htmlHeadXtra[] = '<script language="javascript">
-				function selectAll(idCheck,numRows,action) {
-					for(i=0;i<numRows;i++) {
-						idcheck = document.getElementById(idCheck+"_"+i);
-						if (action == "true"){
-							idcheck.checked = true;
-						} else {
-							idcheck.checked = false;
-						}
-					}
-				}
-				</script>';
+//Add the JS needed to use the jqgrid
+$htmlHeadXtra[] = api_get_jquery_ui_js(true);
 
-$tbl_session			= Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_session_category	= Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-$tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-$tbl_session_rel_user 	= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-$tbl_user 				= Database::get_main_table(TABLE_MAIN_USER);
-
-$page=intval($_GET['page']);
 $action=$_REQUEST['action'];
-$sort=in_array($_GET['sort'],array('name', 'nbr_courses', 'name_category', 'date_start', 'date_end','visibility'))?$_GET['sort']:'name';
 $idChecked = $_REQUEST['idChecked'];
-$id_category = intval($_REQUEST['id_category']);
-$cond_url = '';
+
 if ($action == 'delete') {
 	SessionManager::delete_session($idChecked);
-	header('Location: '.api_get_self().'?sort='.$sort);
+	header('Location: '.api_get_self());
 	exit();
 } elseif ($action == 'copy') {
 	SessionManager::copy_session($idChecked);
-    header('Location: '.api_get_self().'?sort='.$sort);
+    header('Location: '.api_get_self());
     exit();
 }
 
 $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin'));
 
-$keyword_name = isset($_GET['keyword_name']) ? Security::remove_XSS($_GET['keyword_name']) : null;
 
 //table for the search
-if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
-
-	$interbreadcrumb[] = array ("url" => 'session_list.php', "name" => get_lang('SessionList'));
-	$tool_name = get_lang('SearchASession');
-	Display :: display_header($tool_name);
-	$form = new FormValidator('advanced_search','get');
-	$form->addElement('header', '', $tool_name);
-	$form->add_textfield('keyword_name', get_lang('NameOfTheSession'), false);
-	$form->add_textfield('keyword_category', get_lang('CategoryName'), false);
-	$form->add_textfield('keyword_firstname', get_lang('FirstName'), false);
-	$form->add_textfield('keyword_lastname', get_lang('LastName'), false);
-	$status_options = array();
-	$status_options['%'] = get_lang('All');
-	$status_options[SESSION_VISIBLE_READ_ONLY] 	= get_lang('SessionReadOnly');
-	$status_options[SESSION_VISIBLE] 			= get_lang('SessionAccessible');
-	$status_options[SESSION_INVISIBLE] 			= get_lang('SessionNotAccessible');
-	$form->addElement('select','keyword_visibility',get_lang('Status'),$status_options);
-	$active_group = array();
-	$active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
-	$active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
-	$form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
-	$defaults['active'] = 0;
-	$defaults['inactive'] = 0;
-	$form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
-	$form->setDefaults($defaults);
-	$form->display();
-
-} else {
-
-	$limit=20;
-	$from=$page * $limit;
-	$where = 'WHERE 1=1 ';
-
-	//Prevent hacking keyword
-	if ( isset ($_GET['keyword'])) {
-		$keyword = Database::escape_string(trim($_GET['keyword']));
-    } else if (isset ($_GET['keyword_name'])) {
-        $keyword_name = Database::escape_string(trim($_GET['keyword_name']));
-        $keyword_category = Database::escape_string(trim($_GET['keyword_category']));
-        $keyword_visibility = Database::escape_string(trim($_GET['keyword_visibility']));
-        $keyword_firstname = Database::escape_string(trim($_GET['keyword_firstname']));
-        $keyword_lastname = Database::escape_string(trim($_GET['keyword_lastname']));
-    }
-
-	//Process for the search advanced
-	if (!empty($_REQUEST['keyword_name'])) {
-		$where .= " AND s.name LIKE '%".$keyword_name."%'";
-	}
-
-	if (!empty($_REQUEST['keyword_category'])) {
-		$where .= " AND sc.name LIKE '%".$keyword_category."%'";
-	}
-
-	if (!empty($_REQUEST['keyword_visibility']) AND $_REQUEST['keyword_visibility']!='%') {
-		$where .= " AND s.visibility LIKE '%".$keyword_visibility."%'";
-	}
-
-	if (!empty($_REQUEST['keyword_firstname'])) {
-		$where .= " AND u.firstname LIKE '%".$keyword_firstname."%'";
-	}
-
-	if (!empty($_REQUEST['keyword_lastname'])) {
-		$where .= " AND u.lastname LIKE '%".$keyword_lastname."%'";
-	}
-
-	if (isset($_REQUEST['active']) && isset($_REQUEST['inactive'] )) {
-		// if both are set we search all sessions
-		$cond_url = '&amp;active='.Security::remove_XSS($_REQUEST['active']);
-		$cond_url .= '&amp;inactive='.Security::remove_XSS($_REQUEST['inactive']);
-	} else {
-		if (isset($_REQUEST['active'])) {
-			$where .= ' AND ( (s.date_start <= CURDATE() AND s.date_end >= CURDATE()) OR s.date_start="0000-00-00" ) ';
-			$cond_url = '&amp;active='.Security::remove_XSS($_REQUEST['active']);
-		}
-		if (isset($_REQUEST['inactive'])) {
-			$where .= ' AND ( (s.date_start > CURDATE() AND s.date_end < CURDATE()) AND s.date_start<>"0000-00-00" ) ';
-			$cond_url = '&amp;inactive='.Security::remove_XSS($_REQUEST['inactive']);
-		}
-	}
-
-	if(isset($_GET['id_category'])){
-		$where.= ' AND ';
-		$id_category = Security::remove_XSS($id_category);
-		$where.= ' session_category_id = "'.$id_category.'" ';
-		$cond_url.= '&amp;id_category='.$id_category;
-	}
-
-	$user_id= $_user['user_id'];
-	if (api_is_session_admin()==true) {
-		$where.=" AND s.session_admin_id = $user_id ";
-	}
 
-	//Get list sessions
-	$sort = ($sort != "name_category")?  's.'.$sort : 'category_name';
-	$query = "SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name, s.visibility, u.user_id ".
-			" FROM $tbl_session s ".
-			 	" LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id ".
-			 	" INNER JOIN $tbl_user u ON s.id_coach = u.user_id ".
-			 $where.
-			 " ORDER BY $sort LIMIT $from,".($limit+1);
-	//query which allows me to get a record without taking into account the page
-	$query_rows = "SELECT count(*) as total_rows
-			 FROM $tbl_session s
-			 	LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
-			 	INNER JOIN $tbl_user u ON s.id_coach = u.user_id
-			 $where ";
-
-    //filtering the session list by access_url
-    
-	if ($_configuration['multiple_access_urls']) {
-		$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
-		$access_url_id = api_get_current_access_url_id();
-		if ($access_url_id != -1) {
-			$where.= " AND ar.access_url_id = $access_url_id ";
-			$query = "SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name , s.visibility, u.user_id
-			 FROM $tbl_session s
-			 	LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
-			 	INNER JOIN $tbl_user u ON s.id_coach = u.user_id
-				INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
-			 $where
-			 ORDER BY $sort LIMIT $from,".($limit+1);
-
-			$query_rows = "SELECT count(*) as total_rows
-			 FROM $tbl_session s
-			 	LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
-			 	INNER JOIN $tbl_user u ON s.id_coach = u.user_id
-			 	INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
-			 $where ";
-		}
-	}
-
-
-	$result_rows = Database::query($query_rows);
-	$recorset = Database::fetch_array($result_rows);
-	$num = $recorset['total_rows'];
-	$result=Database::query($query);
-	$sessions=Database::store_result($result);
-	$nbr_results=sizeof($sessions);
-	$tool_name = get_lang('SessionList');
-	Display::display_header($tool_name);
-	//api_display_tool_title($tool_name);
-
-    if (!empty($_GET['warn'])) {
-        Display::display_warning_message(urldecode($_GET['warn']),false);
-    }
-    if(isset($_GET['action'])) {
-        Display::display_normal_message(stripslashes($_GET['message']),false);
-    }
-	?>
-	<div class="actions">
-	<?php
-	echo '<div style="float:right;">';
-		if (!isset($_GET['id_category'])) {
-			echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').'</a>';
-		} 
-		echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'','32').'</a>';
-		
-		
-		echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'','32').'</a>';
-	echo '</div>';
-	?>
-	<form method="POST" action="session_list.php">
-		<input type="text" name="keyword_name" value="<?php echo $keyword_name; ?>"/>
-		<button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
-		<a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a>
-		</form>
-	<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;">
-	 </div><br />
-
-	<div align="left">
-	<?php
-	//if(count($sessions)==0 && isset($_POST['keyword'])) {
-	if(count($sessions)==0) {
-		if (isset($_GET['id_category'])) {
-			Display::display_warning_message(get_lang('NoSession'));
-		} else {
-			Display::display_warning_message(get_lang('NoSearchResults'));
-		}
-		echo '	</div>';
-	} else {
-		if($num>$limit){
-			if($page) {
-			?>
-			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo Security::remove_XSS($_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; ?>&keyword=<?php echo Security::remove_XSS($_REQUEST['keyword']); ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
-				<?php
-			} else {
-				echo get_lang('Next');
-			}
-		}
-		?>
-	</div>
-		<br />
-		<table class="data_table" width="100%">
-		<tr>
-		  <th>&nbsp;</th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=name"><?php echo get_lang('Name'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=nbr_courses"><?php echo get_lang('NumberOfCourses'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=name_category<?php echo $cond_url; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=date_start"><?php echo get_lang('StartDate'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=date_end"><?php echo get_lang('EndDate'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=coach_name"><?php echo get_lang('Coach'); ?></a></th>
-		  <th><a href="<?php echo api_get_self(); ?>?sort=visibility<?php echo $cond_url; ?>"><?php echo get_lang('Visibility'); ?></a></th>
-		  <th width="120px"><?php echo get_lang('Actions'); ?></th>
-		</tr>
-
-		<?php
-		$i=0;
-		$x=0;
-		foreach ($sessions as $key=>$enreg) {
-			if($key == $limit) {
-				break;
-			}
-			$sql = 'SELECT COUNT(course_code) FROM '.$tbl_session_rel_course.' WHERE id_session='.intval($enreg['id']);
-
-		  	$rs = Database::query($sql);
-		  	list($nb_courses) = Database::fetch_array($rs);
-            $user_link = '';
-            if (!empty($enreg['user_id'])) {
-                $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($enreg['user_id']).'">'.api_htmlentities(api_get_person_name($enreg['firstname'], $enreg['lastname']),ENT_QUOTES,$charset).'</a>';
-            }
-		?>
-
-		<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><a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></a></td>
-	      <td><a href="session_course_list.php?id_session=<?php echo $enreg['id']; ?>"><?php echo $nb_courses; ?></a></td>
-	      <td><?php echo api_htmlentities($enreg['category_name'],ENT_QUOTES,$charset); ?></td>
-	      <td><?php echo ($enreg['date_start'] != '0000-00-00')? api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset): '-'; ?></td>
-	      <td><?php echo ($enreg['date_end'] != '0000-00-00')?api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset): '-'; ?></td>
-	      <td><?php echo $user_link; ?></td>
-		  <td><?php
-		  switch (intval($enreg['visibility'])) {
-				case SESSION_VISIBLE_READ_ONLY: //1
-					echo get_lang('ReadOnly');
-				break;
-				case SESSION_VISIBLE:			//2
-					echo get_lang('Visible');
-				break;
-				case SESSION_INVISIBLE:			//3
-					echo api_ucfirst(get_lang('Invisible'));
-				break;
-		  }
-		  ?></td>
-		  <td>
-		  	<a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.png', get_lang('Edit'), array(), 22); ?></a>
-			<a href="add_users_to_session.php?page=session_list.php&id_session=<?php echo $enreg['id']; ?>"><?php Display::display_icon('user_subscribe_session.png', get_lang('SubscribeUsersToSession'),'','22'); ?></a>
-			<a href="add_courses_to_session.php?page=session_list.php&id_session=<?php echo $enreg['id']; ?>"><?php Display::display_icon('courses_to_session.png', get_lang('SubscribeCoursesToSession'),'','22'); ?></a>			
-            <a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=copy&idChecked=<?php echo $enreg['id'];?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"><?php Display::display_icon('copy.gif', get_lang('Copy'), array(), 22); ?></a>
-            <a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=delete&idChecked=<?php echo $enreg['id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"><?php Display::display_icon('delete.png', get_lang('Delete'), array(), 22); ?></a>
-		  </td>
-		</tr>
-		<?php
-			$i=$i ? 0 : 1;
-			$x++;
-		}
-		unset($sessions);
-		?>
-		</table>
-		<br />
-		<div align="left">
-		<?php
-
-		if ($num>$limit) {
-    		if ($page) {
-    			?>
-    			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo Security::remove_XSS($_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; ?>&keyword=<?php echo Security::remove_XSS($_REQUEST['keyword']); ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>    
-    			<?php
-    			} else {
-    				echo get_lang('Next');
-    			}
-    		}
-		?>
-		</div>
-
-		<a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
-		<a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
-		<select name="action">
-		<option value="delete"><?php echo get_lang('DeleteSelectedSessions'); ?></option>
-		</select>
-		<button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
+$tool_name = get_lang('SessionList');
+Display::display_header($tool_name);
+
+
+
+//jqgrid will use this URL to do the selects
+
+$url            = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
+
+//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('SessionCategoryName'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Coach'),  get_lang('Visibility'), get_lang('Actions'));
+
+//Column config
+$column_model   = array(
+                        array('name'=>'name',           'index'=>'s.name',          'width'=>'120',  'align'=>'left', 'search' => 'true'),                        
+                        array('name'=>'nbr_courses',    'index'=>'s.nbr_courses',   'width'=>'30',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'category_name',  'index'=>'sc.name',         'width'=>'80',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'date_start',     'index'=>'s.date_start',    'width'=>'40',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'date_end',       'index'=>'s.date_end',      'width'=>'40',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'coach_name',     'index'=>'coach_name',      'width'=>'80',   'align'=>'left', 'search' => 'false'),                        
+                        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')
+                       );            
+//Autowidth             
+$extra_params['autowidth'] = 'true';
+//height auto 
+$extra_params['height'] = 'auto';
+
+$extra_params['rowList'] = array(10, 20 ,30);
+
+
+//With this function we can add actions to the jgrid (edit, delete, etc)
+$action_links = 'function action_formatter(cellvalue, options, rowObject) {
+                         return \'<a href="resume_session.php?id_session=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>'.
+                         '&nbsp;<a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('user_subscribe_session.png',get_lang('SubscribeUsersToSession'),'',22).'</a>'.
+                         '&nbsp;<a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('courses_to_session.png',get_lang('SubscribeCoursesToSession'),'',22).'</a>'.
+                         '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="session_list.php?action=copy&idChecked=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',22).'</a>'.
+                         '&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'),'',22).'</a>'.
+                         '\'; 
+                 }';
+?>
+<script>
+$(function() {
+    <?php 
+        echo Display::grid_js('sessions', $url,$columns,$column_model,$extra_params, array(), $action_links,true);      
+    ?>
+
+$("#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
+);
+
+});
+</script>
+
+<div class="actions">
 <?php 
-	}
-}
+echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').'</a>';
+echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'','32').'</a>';
+echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'','32').'</a>';
+echo '</div>';
+
+echo Display::grid_html('sessions');
 Display::display_footer();

+ 53 - 5
main/inc/ajax/model.ajax.php

@@ -1,7 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-//@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file, is not very well tested yet!
+//@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file
+
 require_once '../global.inc.php';
 
 api_protect_admin_script(true);
@@ -18,6 +19,46 @@ $sord  = $_REQUEST['sord'];         //asc or desc
 if (!in_array($sord, array('asc','desc'))) {
     $sord = 'desc'; 
 }
+
+//Search features
+
+$ops = array(
+    'eq'=>'=', //equal
+    'ne'=>'<>',//not equal
+    'lt'=>'<', //less than
+    'le'=>'<=',//less than or equal
+    'gt'=>'>', //greater than
+    'ge'=>'>=',//greater than or equal
+    'bw'=>'LIKE', //begins with
+    'bn'=>'NOT LIKE', //doesn't begin with
+    'in'=>'LIKE', //is in
+    'ni'=>'NOT LIKE', //is not in
+    'ew'=>'LIKE', //ends with
+    'en'=>'NOT LIKE', //doesn't end with
+    'cn'=>'LIKE', // contains
+    'nc'=>'NOT LIKE'  //doesn't contain
+);
+
+//@todo move this in the display_class
+
+function get_where_clause($col, $oper, $val) {
+    global $ops;
+    if($oper == 'bw' || $oper == 'bn') $val .= '%';
+    if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
+    if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
+    $val = Database::escape_string($val);
+    return " $col {$ops[$oper]} '$val' ";
+}
+
+$where_condition = ""; //if there is no search request sent by jqgrid, $where should be empty
+$search_field    = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
+$search_oper     = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper']: false;
+$search_string   = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
+
+if ($_REQUEST['_search'] == 'true') {
+    $where_condition = get_where_clause($search_field, $search_oper, $search_string);
+}
+
 // get index row - i.e. user click to sort $sord = $_GET['sord']; 
 // get the direction 
 if (!$sidx) $sidx = 1;
@@ -25,6 +66,10 @@ if (!$sidx) $sidx = 1;
 //2. Selecting the count FIRST
 //@todo rework this
 switch ($action) {
+    case 'get_sessions':
+        require_once $libpath.'sessionmanager.lib.php';        
+        $count = SessionManager::get_count_admin();
+        break;
     case 'get_gradebooks':
         require_once $libpath.'gradebook.lib.php';
         $obj        = new Gradebook();
@@ -49,8 +94,7 @@ switch ($action) {
         exit;   
 }
 
-//3. Calculating first, end, etc
-        
+//3. Calculating first, end, etc       
 $total_pages = 0;
 if ($count > 0) { 
     if (!empty($limit)) {
@@ -74,7 +118,11 @@ if ($_REQUEST['oper'] == 'del') {
 
 //4. Querying the DB for the elements
 $columns = array();
-switch ($action) {
+switch ($action) {    
+    case 'get_sessions':
+        $columns = array('name', 'nbr_courses','category_name', 'date_start','date_end', 'coach_name', 'visibility');        
+        $result = SessionManager::get_sessions_admin(array('where'=> $where_condition, 'order'=>"$sidx $sord", 'limit'=> "$start , $limit"));        
+        break;
     case 'get_gradebooks': 
         $columns = array('name', 'skills', 'actions');                
         if (!in_array($sidx, $columns)) {
@@ -163,7 +211,7 @@ switch ($action) {
 //var_dump($result);
 
 //5. Creating an obj to return a json
-if (in_array($action, array('get_careers','get_promotions','get_usergroups','get_gradebooks'))) { 
+if (in_array($action, array('get_careers','get_promotions','get_usergroups','get_gradebooks', 'get_sessions'))) { 
     $response = new stdClass();           
     $response->page     = $page; 
     $response->total    = $total_pages; 

+ 1 - 1
main/inc/lib/display.lib.php

@@ -818,7 +818,7 @@ class Display {
 
         $obj->colNames      = $column_names;
         $obj->colModel      = $column_model;
-        $obj->pager         = $div_id.'_pager';
+        $obj->pager         = '#'.$div_id.'_pager';
 
         $obj->datatype  = 'json';
         

+ 111 - 1
main/inc/lib/sessionmanager.lib.php

@@ -157,7 +157,117 @@ class SessionManager {
         $result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
         return $result['count'] > 0;
 	}
-	
+    
+    function get_count_admin() {
+        $tbl_session            = Database::get_main_table(TABLE_MAIN_SESSION);
+        $tbl_session_category   = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);        
+        $tbl_user               = Database::get_main_table(TABLE_MAIN_USER);
+
+        $where = '';
+        $user_id = api_get_user_id();
+        if (api_is_session_admin()==true) {
+            $where.=" WHERE s.session_admin_id = $user_id ";
+        }
+        
+        $query_rows = "SELECT count(*) as total_rows
+         FROM $tbl_session s
+            LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
+            INNER JOIN $tbl_user u ON s.id_coach = u.user_id
+         $where ";
+         
+        global $_configuration;
+        if ($_configuration['multiple_access_urls']) {
+            $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
+            $access_url_id = api_get_current_access_url_id();
+            if ($access_url_id != -1) {
+                $query_rows = "SELECT count(*) as total_rows
+                 FROM $tbl_session s
+                    LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
+                    INNER JOIN $tbl_user u ON s.id_coach = u.user_id
+                    INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
+                 $where ";
+            }
+        }
+        $result_rows = Database::query($query_rows);
+        $recorset = Database::fetch_array($result_rows);
+        $num = $recorset['total_rows'];
+        return $num;    
+    }
+    /**
+     * Gets the admin session list callback of the admin/session_list.php page
+     * @param array order and limit keys
+     */
+    function get_sessions_admin($options) {
+        $tbl_session            = Database::get_main_table(TABLE_MAIN_SESSION);
+        $tbl_session_category   = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);        
+        $tbl_user               = Database::get_main_table(TABLE_MAIN_USER);        
+        
+        $where = 'WHERE 1=1 ';
+        $user_id = api_get_user_id();
+        if (api_is_session_admin()==true) {
+            $where.=" AND s.session_admin_id = $user_id ";
+        }        
+        
+        if (!empty($options['where'])) {
+           $where .= ' AND '.$options['where']; 
+        }
+        
+        $coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
+        if (api_is_western_name_order()) {            
+            $coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name ";
+        }
+        $query = "SELECT s.name, nbr_courses, s.date_start, s.date_end, $coach_name , sc.name as category_name, s.visibility, u.user_id, s.id   ".
+            " FROM $tbl_session s ".
+                " LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id ".
+                " INNER JOIN $tbl_user u ON s.id_coach = u.user_id ".
+             $where;
+             
+        if ($_configuration['multiple_access_urls']) {
+            $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
+            $access_url_id = api_get_current_access_url_id();
+            if ($access_url_id != -1) {
+                $where.= " AND ar.access_url_id = $access_url_id ";
+                $query = "SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name , s.visibility, u.user_id
+                 FROM $tbl_session s
+                    LEFT JOIN  $tbl_session_category sc ON s.session_category_id = sc.id
+                    INNER JOIN $tbl_user u ON s.id_coach = u.user_id
+                    INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
+                 $where";
+            }
+        }         
+        $query .= "ORDER BY ".$options['order']." LIMIT ".$options['limit'];              
+       
+        $result     = Database::query($query);
+        $formatted_sessions = array();
+        if (Database::num_rows($result)) {
+            $sessions   = Database::store_result($result);
+            foreach ($sessions as $session) {
+                $session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']); 
+                
+                if ($session['date_start'] == '0000-00-00') {
+                    $session['date_start'] = '';
+                }
+                if ($session['date_end'] == '0000-00-00') {
+                    $session['date_end'] = '';
+                }                
+                switch ($session['visibility']) {
+                    case SESSION_VISIBLE_READ_ONLY: //1
+                        $session['visibility'] =  get_lang('ReadOnly');
+                    break;
+                    case SESSION_VISIBLE:           //2
+                        $session['visibility'] =  get_lang('Visible');
+                    break;
+                    case SESSION_INVISIBLE:         //3
+                        $session['visibility'] =  api_ucfirst(get_lang('Invisible'));
+                    break;
+              }
+              $formatted_sessions[] = $session;
+            }
+        }
+        return $formatted_sessions;
+    }
+    
+    	
     /**
      * Creates a new course code based in given code
      *