Browse Source

Adding new search filter in the session list see BT#3368

Julio Montoya 13 years ago
parent
commit
cd8284f471
3 changed files with 82 additions and 52 deletions
  1. 44 33
      main/admin/session_list.php
  2. 23 3
      main/inc/ajax/model.ajax.php
  3. 15 16
      main/inc/lib/sessionmanager.lib.php

+ 44 - 33
main/admin/session_list.php

@@ -46,20 +46,25 @@ $url            = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
 $columns        = array(get_lang('Name'), get_lang('NumberOfCourses'), get_lang('SessionCategoryName'), 
                         get_lang('StartDate'), get_lang('EndDate'), get_lang('Coach'),  get_lang('Status'), get_lang('Visibility'), get_lang('Actions'));
 
+//$activeurl = '?sidx=session_active';
 //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'=>'status',         'index'=>'session_active',  'width'=>'20',   'align'=>'left', 'search' => 'false'),                        
+                        array('name'=>'name',           'index'=>'name',          'width'=>'120',  'align'=>'left', 'search' => 'true'),                        
+                        array('name'=>'nbr_courses',    'index'=>'nbr_courses',   'width'=>'30',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'category_name',  'index'=>'category_name', 'width'=>'70',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'date_start',     'index'=>'date_start',    'width'=>'40',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'date_end',       'index'=>'date_end',      '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'=>'40',   'align'=>'left', 'search' => 'true'
+                        ,'stype'=>'select', 'editoptions' =>array('value' => '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')
                        );            
 //Autowidth             
 $extra_params['autowidth'] = 'true';
+
 //height auto 
 $extra_params['height'] = 'auto';
 $extra_params['excel'] = 'excel';
@@ -83,40 +88,46 @@ $(function() {
         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
-);
-/*
-// add custom button to export the data to excel
-jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
-       caption:"", 
-       onClickButton : function () { 
-           jQuery("#sessions").excelExport();
-       } 
-});
-
-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';
+    $("#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
+    );
+    /*
+    // add custom button to export the data to excel
+    jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
+           caption:"", 
+           onClickButton : function () { 
+               jQuery("#sessions").excelExport();
+           } 
+    });
+    
+    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,
     }
-},buttonicon:'ui-icon-document'})
-*/
-
+    jQuery("#sessions").jqGrid('filterToolbar',options);
 });
-</script>
 
+</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();

+ 23 - 3
main/inc/ajax/model.ajax.php

@@ -43,6 +43,9 @@ $ops = array(
 
 function get_where_clause($col, $oper, $val) {
     global $ops;
+    if (empty($col)){
+        return '';
+    } 
     if($oper == 'bw' || $oper == 'bn') $val .= '%';
     if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
     if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
@@ -51,12 +54,29 @@ function get_where_clause($col, $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_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);
+    $where_condition = ' 1 = 1 ';
+    $where_condition .= get_where_clause($search_field, $search_oper, $search_string);
+    
+    $filters   = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
+    
+    $where_condition .= ' AND ( ';
+    $counter = 0;
+    foreach ($filters->rules as $key=>$rule) {
+        $where_condition .= get_where_clause($rule->field,$rule->op, $rule->data);
+        
+        if ($counter < count($filters->rules) -1) {     
+            $where_condition .= $filters->groupOp;
+        }
+        $counter++;
+    }
+    $where_condition .= ' ) ';
+        
 }
 
 // get index row - i.e. user click to sort $sord = $_GET['sord']; 

+ 15 - 16
main/inc/lib/sessionmanager.lib.php

@@ -208,28 +208,19 @@ class SessionManager {
         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 ";
-        }
-        
-        $start_filter  = $year."-".$month."-".$day." 00:00:00";
-        $start_filter  = api_get_utc_datetime($start_filter);
-        $end_filter    = $year."-".$month."-".$day." 23:59:59";
-        $end_filter    = api_get_utc_datetime($end_filter);
-        
+        }        
+
         $today = api_get_utc_datetime();
         $today = api_strtotime($today);
         
         $today = date('Y-m-d', $today);
         
-        $select = "SELECT 
+        $select = "SELECT * FROM (SELECT 
                 IF ( 
                     (s.date_start <= '$today' AND '$today' < s.date_end) OR 
                     (s.date_start  = '0000-00-00' AND s.date_end  = '0000-00-00' ) OR
@@ -256,9 +247,17 @@ class SessionManager {
                     INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
                  $where";
             }
-        }         
-        $query .= "ORDER BY ".$options['order']." LIMIT ".$options['limit'];              
-        //echo $query;
+        }  
+        $query .= ") AS session_table";   
+        
+          
+        if (!empty($options['where'])) {
+           $query .= ' WHERE '.$options['where']; 
+        }
+            
+        $query .= " ORDER BY ".$options['order']." LIMIT ".$options['limit'];
+                 
+       // echo $query;
         $result = Database::query($query);
         $formatted_sessions = array();
         if (Database::num_rows($result)) {