<?php
/**
 * Manually Developed CI View - access_wb.php
 *
 * @package			AIR\views
 * @version			2.7
 * @uses
 * @see
 * @copyright		2015, BizyCorp Internal Systems Development
 * @license			private, All rights reserved
 * @author			Mohamed Roshan <roshan@ekwa.com>
 *
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Manually Developed CI View
 *
 * This is the main view file of accesslog grid wb  file
 *
 * @package			AIR\views
 * @version			2.7
 * @uses
 * @see
 * @copyright		2015, BizyCorp Internal Systems Development
 * @license			private, All rights reserved
 * @author			Mohamed Roshan <roshan@ekwa.com>
 * @created			Jul 18, 2016
 * @modified        Jul 18, 2016
 * @modification   Fixed bug id 21506,21388,21390,21389,21504
 *
*/
class Access_wb{
	// Just a dummy clas for phpdoc to catch the doc header.
}

$user_id = '';
$user_name = '';
$user_type = '';

if(isset($_SESSION['user_name'])){
	$user_id = $_SESSION['user_id'];
	$user_name = $_SESSION['user_name'];
	$user_type = $_SESSION['user_type'];
}
elseif(isset($_COOKIE['user_name'])){
	$user_id = $_COOKIE['user_id'];
	$user_name = $_COOKIE['user_name'];
	$user_type = $_COOKIE['user_type'];
}

/**
 * Common js/css file header file
 */
require_once('js-css-loader.php');

$logDate = $this->input->get_post('logDate');
$this->load->helper('file');
$logFiles = get_filenames('./application/logs/access/');
sort($logFiles);
$logFiles = array_reverse($logFiles);
$log_create = new log_object();
$log_create->set_userDetails($user_name, $user_type);
$log_create->set_otherDetails(array('Mode'=>'Access Log','Data'=>'-'));
$log_create->init();
?>

<style>
body{ margin:0;}
</style>


<div id="divBench" style="width:98%;height:99.9%;"></div>
<script>

//CORS handling 
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event){
	switch (event.data){
	case "setSize":
		wb.getWb().setSizes();
	  	break;
  	}
}
//---------------------------

var wbContainer;
var wb;
var dataGrid;
var rowid;
var viewEvent = null;
<?php echo "var options =[" ;
  foreach($logFiles as $k => $v) {
    $v = substr($v,3,10) ;
    echo "['$v','obj','$v'],";
  }
  echo "];"
?>

//now initiate work bench and attache it to page layout.
var wb = new workbenchObj();
wb.workBench = document.getElementById("divBench"); //assigning wb container of this page to wb object
wb.url = '<?php echo site_url()?>/accesslog_controller/view/access_log_wb_intro';
wb.gridreloadurl = '';

//can pass properties to manuputate toolbar objects
wb.gridLayoutWidth = 400;
wb.toolBarComponent='grid'; 
wb.toolBarDefaultitems=false;      //add defult items
//wb.toolBarItems=[{id:'formView',type:'button',img:'page.gif',imgdis:'page_dis.gif',text:'View in Form'}];
wb.toolBarNotSet=['add','edit','delete','refresh'];
wb.toolBarVar='gridtoolbar';
wb.defFrmSaveHandling = false; //Save will be handled by callback
wb.toolBarIconpath = '<?php echo base_url('public/img/common/imgs/'),'/';?>';

//after setting up all wb properties finallay initiat wb.
wb.init();

//Hide 'search' button
wb.toolBarVar.hideItem('search');
//Add Log Date selection to toolbar
wb.toolBarVar.addButtonSelect('logDate',0, 'Select Log Date', options, '', '',true,false,10);
//now attache events for new selec button
if (!viewEvent) {
  	viewEvent = wb.toolBarVar.attachEvent('onClick', function(buttonid){
		if(buttonid !='refresh' && buttonid!='helpFile') {
            if (buttonid != 'logDate'){
      			wb.toolBarVar.setItemText('logDate', 'Selected Log Date: '+buttonid );
              	wb.url = '<?php echo site_url()?>/accesslog_controller/view/access_gridview?logDate='+buttonid;
              	wb.gridreloadurl = '<?php echo site_url()?>/accesslog_controller/view/access_log_gridfeed?logDate='+buttonid;
            }
            else{
              	wb.toolBarVar.setItemText('logDate', 'Select Log Date' );
              	wb.url = '<?php echo site_url()?>/accesslog_controller/view/access_log_gridfeed';
              	wb.gridreloadurl = '';
            }
        	wb.workBench.cells('a').attachURL(wb.url,true);
    	}   
	});
}
</script>