<?php
$_SESSION['listParams']['searchVisible'] = 1;
$_SESSION['listParams']['addAccess'] = SABLE_ACCESS_ADMIN;
if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0] = 'company_name';
	$_SESSION['listParams']['searchField'][1] = 'user_name';
	$_SESSION['listParams']['searchField'][2] = 'user_surname';
	$_SESSION['listParams']['searchField'][3] = 'user_email';
	$_SESSION['listParams']['searchField'][4]['title'] = 'user_cellphone';
	$_SESSION['listParams']['searchField'][4][0] = 'user_cell';
	$_SESSION['listParams']['searchField'][4][1] = 'user_phone';
	$_SESSION['listParams']['searchField'][5] = 'position_title';

	/**
	$_SESSION['listParams']['searchField'][4]['title'] = 'user_cellphone';
	$_SESSION['listParams']['searchField'][4][0] = 'user_cell';
	$_SESSION['listParams']['searchField'][4][1] = 'user_phone';
	**/
}

$sql = "select user.user_code, company_name, user_name, user_surname, user_email, coalesce(user_cell, user_phone) as user_cellphone,
		position_title 
		from user 
		inner join position on position.position_id = user.position_id 
		inner join company on company.company_id = user.company_id 
		where (user.user_code > 0) and (user.deleted = 0) and (company_type_id < 3)";

$_SESSION['listParams']['listSql']	= $sql;
$_SESSION['listParams']['module']	= "User";
 
$_SESSION['listParams']['page']				= 0;
$_SESSION['listParams']['offset']			= 50; //the number of records to display per page
$_SESSION['listParams']['parentId']			= ""; //
$_SESSION['listParams']['moduleFolder']		= "user";
$_SESSION['listParams']['modulePage']		= "index.php"; //MacpropDemo
$_SESSION['listParams']['moduleIdField']	= "user_code";
$_SESSION['listParams']['moduleDescField']	= "user_surname";
$_SESSION['listParams']['orderField']		= 2;
$_SESSION['listParams']['orderDirection']	= 0;
$_SESSION['listParams']['allowExport']		= 1;
$_SESSION['listParams']['exportAccess']		= ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER);
 
$_SESSION['listParams']['listHeadings'][0]  = "Employer";
$_SESSION['listParams']['listHeadings'][1]  = "Name";
$_SESSION['listParams']['listHeadings'][2]  = "Surname";
$_SESSION['listParams']['listHeadings'][3]  = "Email";
$_SESSION['listParams']['listHeadings'][4]  = "Phone";
$_SESSION['listParams']['listHeadings'][5]  = "Role";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK)   $_SESSION['listParams']['listHeadings'][6] = ""; //view
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) $_SESSION['listParams']['listHeadings'][7] = ""; //edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN)   $_SESSION['listParams']['listHeadings'][8] = ""; //delete

$_SESSION['listParams']['listHeadingWidth'][0]  = "10%";
$_SESSION['listParams']['listHeadingWidth'][1]  = "10%";
$_SESSION['listParams']['listHeadingWidth'][2]  = "10%";
$_SESSION['listParams']['listHeadingWidth'][3]  = "10%";
$_SESSION['listParams']['listHeadingWidth'][4]  = "10%";
$_SESSION['listParams']['listHeadingWidth'][5]  = "10%";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK)   $_SESSION['listParams']['listHeadingWidth'][6] = "5%"; //view
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) $_SESSION['listParams']['listHeadingWidth'][7] = "5%"; //edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN)   $_SESSION['listParams']['listHeadingWidth'][8] = "5%"; //delete

$_SESSION['listParams']['listFields'][0]['field'] = "company_name";
$_SESSION['listParams']['listFields'][1]['field'] = "user_name";
$_SESSION['listParams']['listFields'][2]['field'] = "user_surname";
$_SESSION['listParams']['listFields'][3]['field'] = "user_email";
$_SESSION['listParams']['listFields'][3]['emailLink'] = "1";
$_SESSION['listParams']['listFields'][4]['field'] = "user_cellphone";
$_SESSION['listParams']['listFields'][4]['phoneLink'] = "1";
$_SESSION['listParams']['listFields'][5]['field'] = "position_title";

if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK) 
{
  $_SESSION['listParams']['listFields'][6]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_VIEW."' title='View --!--'></i>";
  $_SESSION['listParams']['listFields'][6]['onClick'] = " onClick='viewUser(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) 
{
  $_SESSION['listParams']['listFields'][7]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_EDIT."' title='Modify --!--'></i>";
  $_SESSION['listParams']['listFields'][7]['onClick'] = " onClick='editUser(\"--#--\")' ";	
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN) 
{
  $_SESSION['listParams']['listFields'][8]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_DELETE."' title='Delete --!--'></i>";
  $_SESSION['listParams']['listFields'][8]['onClick'] = " onClick='deleteUser(\"--#--\",\"--!--\")' ";
}
SableGeneralFunctions::callDataList();