<?php session_start();
	//If user is not signed in redirect
	if(!$user->signed && $user->data['group_id'] !== '2') redirect("?page=login");	
?>

<script>
$(document).ready(function() {
	

})
	
</script>
<div class="subcontent" id="bdry">
	<h3>COOLTOOL USERS</h3>
    <hr  class="breaklightblue" />
    <div><!--Start Grid Code Div-->
<?php

function unixToMySQL($timestamp)
{
return date('m-d-Y h:i a', $timestamp);
}


   
    ################################################################################
    ## --------------------------------------------------------------------------- #
    ##  ApPHP DataGrid Pro (AJAX enabled) version 7.7.7                            #
    ##  Developed by:  ApPHP <info@apphp.com>                                      # 
    ##  License:       GNU LGPL v.3                                                #
    ##  Site:          http://www.apphp.com/php-datagrid/                          #
    ##  Copyright:     ApPHP DataGrid (c) 2006-2012. All rights reserved.          #
    ##                                                                             # 
    ################################################################################
    ## +---------------------------------------------------------------------------+
    ## | 1. Creating & Calling:                                                    | 
    ## +---------------------------------------------------------------------------+
    ##  *** define a relative (virtual) path to datagrid.class.php file
    ##  *** (relatively to the current file)
    ##  *** RELATIVE PATH ONLY ***
      define ('DATAGRID_DIR', 'libs/ApPHP_DataGrid/');  /* Ex.: 'datagrid/' */ 
      require_once(DATAGRID_DIR.'datagrid.class.php');

    ##
    ##  *** creating variables that we need for database connection 
      $DB_USER= $user->db['user'];
      $DB_PASS= $user->db['pass'];
      $DB_HOST= $user->db['host'];
      $DB_NAME= $user->db['name'];
	  
      ob_start();
    ##
    ##  *** set needed options and create a new class instance 
      $debug_mode = false;        /* display SQL statements while processing */    
      $messaging = true;          /* display system messages on a screen */ 
      $unique_prefix = 'user_';    /* prevent overlays - must be started with a letter */
	  							 /* user -- user */
      $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
	  
	  $http_get_vars = array("page");
	  $dgrid->SetHttpGetVars($http_get_vars);
	  
    ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
      $dg_encoding = 'utf8';
      $dg_collation = 'utf8_unicode_ci';
      $dgrid->SetEncoding($dg_encoding, $dg_collation);
    ##  *** set data source with required settings
    ##  *** 1. write all fields separated by commas(,) like: field1, field2 etc.. DON'T USE table.*
    ##  *** 2. write the primary key in the first place (MUST BE AUTO-INCREMENT NUMERIC!)
	  
/*	  $my_field = isset($_REQUEST['user__ff_usr_users_first_name']) ? $_REQUEST['user__ff_usr_users_first_name'] : "";
	 
	  if(!empty($my_field)){
		  
	  	
		
		
		
	  }
 */
	  
	  $sql=" SELECT "
    ." usr_users.user_id, "
	." usr_users.title, "	
	." usr_users.first_name, "
	." usr_users.last_name, "
	.' CONCAT(usr_users.first_name, " ", usr_users.last_name) as full_name, '
	." usr_users.phone_number, "
	." usr_users.email, "	
	." usr_users.company, "
	." usr_users.website, "	
	." usr_users.state, "
	." usr_users.country, "	
	." usr_users.activated, "	
	." usr_users.reg_date, "	
	." usr_users.last_login, "	
	." usr_users.on_email_list, "
	." (SELECT COUNT(Distinct usr_activity.session_id) FROM usr_activity WHERE usr_activity.user_id = usr_users.user_id) as numlaunches "				
    ."FROM usr_users";   
	
	
	
      $default_order = array('reg_date'=>'DESC');   /* Ex.: array('field_1'=>'ASC', 'field_2'=>'DESC') */
    ##  *** first parameter 'PEAR' or 'PDO' (default)
      $dgrid->DataSource('PDO', 'mysql', $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);
    ##
    ##
    ## +---------------------------------------------------------------------------+
    ## | 2. General Settings:                                                      | 
    ## +---------------------------------------------------------------------------+
    ## +-- PostBack Submission Method ---------------------------------------------+
    ##  *** defines postback submission method for DataGrid: AJAX, POST(default) or GET
    $postback_method = 'post';
    $dgrid->SetPostBackMethod($postback_method);
   
	$dgrid->controlsDisplayingType = "grouped";   
    $modes = array(
    'edit'	  =>array('view'=>true, 'edit'=>true,  'type'=>'image',  'show_button'=>true),
    'details' =>array('view'=>true, 'edit'=>false, 'type'=>'image',  'show_button'=>true),
    );
    $dgrid->SetModes($modes);
    ##  *** set DataGrid caption
    $dg_caption = 'Current MicroCoolTool Users';
    $dgrid->SetCaption($dg_caption);
    ##
    ## +-- Scrolling --------------------------------------------------------------+
    ##  *** allow scrolling on datagrid
    $scrolling_option = true;
    $dgrid->AllowScrollingSettings($scrolling_option);  
    ##  *** set scrolling settings (optional) 
    $scrolling_height = '400px'; /* ex.: '190px' or '190' */
    $dgrid->SetScrollingSettings($scrolling_height);
    ## +---------------------------------------------------------------------------+
    ## | 3. Printing & Exporting Settings:                                         | 
    ## +---------------------------------------------------------------------------+
    ## +-- Printing ---------------------------------------------------------------+
    ##  *** set printing option: true(default) or false 
    /// $printing_option = true;
    /// $dgrid->AllowPrinting($printing_option);
    ##
    ## +-- Exporting --------------------------------------------------------------+
    ##  *** initialize the session with session_start();
    ##  *** default exporting directory (requires write permissions): tmp/export/ 
   
	$exporting_option = true;
    $export_all = true;
    $dgrid->AllowExporting($exporting_option, $export_all);
    $exporting_types = array('csv'=>'true', 'xls'=>'true', 'pdf'=>'true', 'xml'=>'false', 'doc'=>'true');
    $dgrid->AllowExportingTypes($exporting_types);
    ##
    ##
    ## +---------------------------------------------------------------------------+
    ## | 4. Sorting & Paging Settings:                                             | 
    ## +---------------------------------------------------------------------------+
    ##  *** set sorting option: true(default) or false 
    $sorting_option = true;
    $dgrid->AllowSorting($sorting_option);               
    ##  *** set paging option: true(default) or false 
    /// $paging_option = true;
    /// $rows_numeration = false;
    /// $numeration_sign = 'N #';
    /// $dropdown_paging = false;
    /// $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign, $dropdown_paging);
    ##  *** set paging settings
    /// $bottom_paging = array('results'=>true, 'results_align'=>'left', 'pages'=>true, 'pages_align'=>'center', 'page_size'=>true, 'page_size_align'=>'right');
    /// $top_paging = array('results'=>true, 'results_align'=>'left', 'pages'=>true, 'pages_align'=>'center', 'page_size'=>true, 'page_size_align'=>'right');
    /// $pages_array = array('10'=>'10', '25'=>'25', '50'=>'50', '100'=>'100', '250'=>'250', '500'=>'500', '1000'=>'1000');
    /// $default_page_size = 10;
    /// $paging_arrows = array('first'=>'|&lt;&lt;', 'previous'=>'&lt;&lt;', 'next'=>'&gt;&gt;', 'last'=>'&gt;&gt;|');
    /// $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
   
    ## +---------------------------------------------------------------------------+
    ## | 6. View Mode Settings:                                                    | 
    ## +---------------------------------------------------------------------------+
    ##  *** set view mode table properties
    /// $vm_table_properties = array('width'=>'90%');
    /// $dgrid->SetViewModeTableProperties($vm_table_properties);  
    ##  *** set columns in view mode
    ##  *** Ex.: 'on_js_event'=>'onclick="alert(\'Yes!!!\');"'
    ##  ***      'barchart' : number format in SELECT SQL must be equal with number format of max_value
    /// $fill_from_array = array('0'=>'Banned', '1'=>'Active', '2'=>'Closed', '3'=>'Removed'); /* as 'value'=>'option' */
	$vm_columns = array(
    'full_name'  =>array('header'=>'Name', 'type'=>'label', 'align'=>'left','wrap'=>'wrap'),
	'company'  =>array('header'=>'Company', 'type'=>'label', 'align'=>'left','wrap'=>'wrap'),
	'email'  =>array('header'=>'Email', 'type'=>'label', 'align'=>'left','wrap'=>'wrap'),
	'phone_number'  =>array('header'=>'Phone Number', 'type'=>'label', 'align'=>'left','wrap'=>'wrap'),
	'activated'  =>array('header'=>'Activated', 'type'=>'enum','source'=>array('0'=>'No','1'=>'Yes')),
	'numlaunches'  =>array('header'=>'Uses', 'type'=>'label', 'align'=>'left','wrap'=>'wrap')
	);

	$vm_table_properties = array('width'=>'100%');
    $dgrid->SetViewModeTableProperties($vm_table_properties);  
    $dgrid->SetColumnsInViewMode($vm_columns);
	
    ##  *** set CSS class for datagrid
    ##  *** 'default|blue|gray|green|pink|empty|x-blue|x-gray|x-green' or your own css style
    $css_class = 'x-blue';
    $dgrid->SetCssClass($css_class);
	
    ## +---------------------------------------------------------------------------+
    ## | 7. Add/Edit/Details Mode Settings:                                        |
    ## +---------------------------------------------------------------------------+
    ##  *** set add/edit mode table properties
    /// $em_table_properties = array('width'=>'70%');
    /// $dgrid->SetEditModeTableProperties($em_table_properties);
    ##  *** set details mode table properties
    /// $dm_table_properties = array('width'=>'70%');
    /// $dgrid->SetDetailsModeTableProperties($dm_table_properties);
    ##  ***  define settings for add/edit/details modes
    $table_name  = 'usr_users';
    $primary_key = 'user_id';
    ##  for ex.: 'table_name.field = '.$_REQUEST['abc_rid'];
    $condition   = '';
    $dgrid->SetTableEdit($table_name, $primary_key, $condition);

    $em_columns = array(
    'first_name'  =>array('header'=>'First Name', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
	'last_name'  =>array('header'=>'Last Name', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
	'company'  =>array('header'=>'Company', 'type'=>'textbox', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
	'title'  =>array('header'=>'Title', 'type'=>'textbox', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
	'email'  =>array('header'=>'Email', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),	
	'state'  =>array('header'=>'State', 'type'=>'textbox', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),	
	'country'  =>array('header'=>'Country', 'type'=>'textbox', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),	
	'website'  =>array('header'=>'Website', 'type'=>'textbox', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),	
'activated'  =>array('header'=>'Activated', 'type'=>'enum', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'','source'=>array('0'=>'No','1'=>'Yes')),
'reg_date'  =>array('header'=>'Registration Date', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'','on_item_created'=>'unixToMySQL'),
'last_login'  =>array('header'=>'Last Login', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'','on_item_created'=>'unixToMySQL'),
	'on_email_list'  =>array('header'=>'Last Login', 'type'=>'textbox', 'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'true', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
	'on_email_list'  =>array('header'=>'On Email List', 'type'=>'enum', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'','source'=>array('0'=>'No','1'=>'Yes'))
	);

## +---------------------------------------------------------------------------+
## | 5. Filter Settings:                                                       |
## +---------------------------------------------------------------------------+
##  *** set filtering option: true or false(default)
$filtering_option = true;
$show_search_type = false;
$dgrid->AllowFiltering($filtering_option, $show_search_type);
##  *** set additional filtering settings
$filtering_fields = array(
  "First Name" => array("type"=>"textbox",     "table"=>"usr_users", "table_alias"=>"usr_users", "field"=>"first_name", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"%like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>"", "default"=>"", "source"=>"self", "field_view"=>"name", "order_by_field"=>"first_name", "order_type"=>"ASC", "condition"=>"", "show_count"=>false, "multiple"=>"false",'width'=>'100px'),
   "Last Name" => array("type"=>"textbox",     "table"=>"usr_users", "table_alias"=>"usr_users", "field"=>"last_name", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"%like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>"", "default"=>"", "source"=>"self", "field_view"=>"name", "order_by_field"=>"last_name", "order_type"=>"ASC", "condition"=>"", "show_count"=>false, "multiple"=>"false",'width'=>'100px'),
 "Company" => array("type"=>"textbox", "table"=>"usr_users", "table_alias"=>"usr_users", "field"=>"company", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"%like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>"", "default"=>"", "source"=>"self", "field_view"=>"company", "order_by_field"=>"company", "order_type"=>"ASC", "condition"=>"", "show_count"=>false, "multiple"=>"false",'width'=>'100px')  
);
$dgrid->SetFieldsFiltering($filtering_fields);	
    
$dgrid->SetColumnsInEditMode($em_columns);

$layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"2"); 
$dgrid->SetLayouts($layouts);




    ## put call of this method between HTML <HEAD> tags (recommended)
        $dgrid->WriteCssClass();

    ################################################################################   
    ## +---------------------------------------------------------------------------+
    ## | 9. Bind the DataGrid:                                                     | 
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
    ##  *** you may use $dgrid->Bind(false) and then $dgrid->Show() to separate
    ##  *** binding and displaying id datagrid
    $dgrid->Bind();
    ob_end_flush();
    ################################################################################   
	
    
?>

     
    
    
</div>

