Skip to content

Instantly share code, notes, and snippets.

@tmoore88
Created January 31, 2022 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmoore88/93c8ecb5ef88c734ce6008723c3e102e to your computer and use it in GitHub Desktop.
Save tmoore88/93c8ecb5ef88c734ce6008723c3e102e to your computer and use it in GitHub Desktop.
PHP Grid Settings
<?php
#DISPLAYS MASTER JOB LIST - ACTIVE/PENDING (master_job_list_ap.php)
##################
# INCLUDED FILES #
##################
include_once("assets/auth.php"); //USER PERMISSIONS
include_once("data/config.php"); //PHP GRID CONNECTION STRING
include_once("data/connect.php"); //DATA BASE CONNECTION STRING (MINE)
include("lib/inc/jqgrid_dist.php"); //GRID INCLUDE
######################
# PHP ERROR SETTINGS #
######################
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
#####################
# CHECK PERMISSIONS #
#####################
if(isset($_SESSION['user'])) { $uname = $_SESSION['user']; }
####################
# GET ADMIN STATUS #
####################
$sql = mysqli_query($conn, "SELECT * FROM tbl_users WHERE user_name = '$uname'");
$u = mysqli_fetch_array($sql);
$utype = $u['user_type'];
#############################################
# REDIRECT PAGE IF UTYPE > 800 IT TIME CARD #
#############################################
//if ( $utype > 800 ) {
// header( "Location: signup.php" ); die;
//}
#######################
# SEND DATABASE FILES #
#######################
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => PHPGRID_DBNAME
);
##################################
# SEE IF UNIT/JOB INFO IS PASSED #
##################################
if(isset($_GET['job']))
{
$jid=$_GET['job'];
}
if(isset($_GET['unit']))
{
$uid=$_GET['unit'];
} else { $uid=0; }
if(isset($_GET['tc']))
{
$tc=$_GET['tc'];
}
if(isset($_GET['export_notes']))
{
$notes=$_GET['export_notes'];
} else {
$notes=0;
}
#
#
#
$sql = mysqli_query($conn, "SELECT * FROM tbl_timecard_week LEFT JOIN tbl_users ON user_id = time_fk_user WHERE time_week_id = '$tc'");
$sdw = mysqli_fetch_array($sql);
$sd = $sdw['time_starting_date'];
$un = $sdw['user_name'];
################################
# CHECK FOR PROPER PERMISSIONS #
################################
if (strtolower($uname) == strtolower($un) OR $utype > 99) {
} else {
//die("Access Denied");
header('Location: HTTP403.html');
}
############
# SET PAGE #
############
$current = '';
$title = 'TIME CARD: ' . $sdw['full_name'] . " - " . $sdw['time_starting_date'] . " - " . $sdw['time_week_end'];
###################
# CREATE NEW GRID #
###################
$g = new jqgrid($db_conf);
################
# SET INFO BAR #
################
$desc = "<br><br>";
################
# GRID OPTIONS #
################
$grid["caption"] = $title; // GRID CAPTION NAME
$grid["cellEdit"] = false; // inline cell editing, like spreadsheet
$grid["reloadedit"] = true; // refresh
$grid["sortname"] = 'job_number, unit_number'; // sort by kodiak job number'
$grid["sortorder"] = "ASC"; //
$grid["footerrow"] = true; //
$grid["autowidth"] = false; // expand grid to screen width
$grid["shrinkToFit"] = false; //
$grid["loadComplete"] = "function(ids){ grid_onload(ids); }"; //
$grid["afterSaveCell"] = "function(){ setTimeout(()=>{ $('#list1').trigger('reloadGrid', [{current:true}]);},200) }"; //refresh
$g->set_options($grid); //
##############################
# SET GRID C.R.U.D. SETTINGS #
##############################
$g->set_actions(array(
"add"=>true, // Enable / Disable add operation on grid. Defaults to true.
"edit"=>true, // Enable / Disable edit operation on grid. Defaults to true.
"delete"=>true, // Enable / Disable delete operation on grid. Defaults to true.
"view"=>false, // Enable / Disable view operation on grid. Defaults to true.
"inline"=>true, // Enable / Disable button to perform insertion inline. Defaults to false.
"rowactions"=>true, // Enable / Disable inline edit/del/save option. Defaults to true.
"search" => "false", // Search property can have 3 values, simple, advance or false to hide.
"export"=>false, // Enable / Disable export to excel option. Defaults to false.
"export_pdf"=>false, // export pdf button
"showhidecolumns" => false, // Enable / Disable button to hide certain columns from client side. Defaults to true.
"bulkedit"=> false, // Enable / Disable bulk edit operation on grid. Defaults to false.
"clone"=> false, // Enable / Disable clone operation on grid. Defaults to false.
"import"=> false, // Enable / Disable import data option. Defaults to false.
"autofilter"=> false // Enable / Disable autofilter toolbar for search on top. Defaults to true.
)
);
###############################
# MAIN QUERY (EQUIPMENT LIST) #
###############################
$g->select_command = "SELECT * FROM tbl_timecard
LEFT JOIN tbl_job ON job_id = time_job_id
LEFT JOIN tbl_unit ON unit_id = time_unit_id WHERE time_fk_week = '$tc'";
###################################
# REMOVE BUTTONS FROM GRID HEADER #
###################################
$g->navgrid["param"]["edit"] = false; // remove edit from top menu
$g->navgrid["param"]["del"] = true; // remove delete from top menu
$g->navgrid["param"]["add"] = false; // remove add from top menu
#################
# MAIN DATABAES #
#################
$g->table = "tbl_timecard";
####################################
# SETUP COLUMNS TO DISPLAY IN GRID #
####################################
//////////////////
// TIME WEEK ID // - MAIN COLUMN
//////////////////
$col = array();
$col["title"] = "time_id";
$col["name"] = "time_id";
$col["width"] = "40";
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////////
// FK_USER_ID //
////////////////
$col = array();
$col["title"] = "time_fk_week";
$col["name"] = "time_fk_week";
$col["width"] = "20";
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////
// JOB ID //
////////////
$col = array();
$col["title"] = "time_job_id";
$col["name"] = "time_job_id";
$col["width"] = "20";
$col["hidden"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
////////////
// UNIT ID //
/////////////
$col = array();
$col["title"] = "time_unit_id";
$col["name"] = "time_unit_id";
$col["width"] = "20";
$col["hidden"] = true;
$col["editable"] = true;
$col["search"] = false;
$col["isnull"] = true;
$cols[] = $col;
////////////////
// JOB NUMBER //
////////////////
$col = array();
$col["title"] = "Job Number";
$col["name"] = "job_number_tc";
$col["link"] = "unit_list.php?job={time_job_id}";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["editoptions"]["autocomplete"] = "off";
$col["search"] = false;
$col["formatoptions"] = array("sql"=>"SELECT *, CONCAT(job_number_tc,' - ', job_description) as v, job_id as k FROM tbl_job WHERE job_status <> 'ARCHIVED'",
"search_on"=>"job_number_tc",
"callback"=>"fill_form");
$cols[] = $col;
$col = array();
$col["title"] = "Description";
$col["name"] = "job_description";
$col["width"] = "200";
$col["hidden"] = true;
$col["editable"] = false;
$col["search"] = false;
$col["isnull"] = true;
$cols[] = $col;
/////////////////
// UNIT NUMBER //
/////////////////
$col = array();
$col["title"] = "Unit Number";
$col["name"] = "unit_number";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["search"] = false;
$col["isnull"] = true;
$col["editoptions"]["autocomplete"] = "off";
$col["formatoptions"] = array("sql"=>"SELECT *, CONCAT(unit_number,' - ', unit_description) as v, unit_id as k FROM tbl_unit WHERE fk_job_id = {time_job_id} AND unit_status <> 'INACTIVE' AND unit_status <> 'ARCHIVED'",
"search_on"=>"unit_number",
"callback"=>"fill_form_unit");
$cols[] = $col;
//
//
//
$col = array();
$col["title"] = "Description";
$col["name"] = "unit_description";
$col["width"] = "200";
$col["hidden"] = true;
$col["editable"] = false;
$col["search"] = false;
$col["isnull"] = true;
$cols[] = $col;
/////////
// MON //---------------------------------------------------------------
/////////
//REG
$col = array();
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_mon";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_mon";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_mon";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_mon_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$col["editoption"]["maxlength"]="4";
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// TUE //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_tue";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_tue";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_tue";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_tue_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// WED //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_wed";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_wed";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_wed";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_wed_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// THU //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_thu";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_thu";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_thu";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_thu_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// FRI //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_fri";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_fri";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_fri";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_fri_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// SAT //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_sat";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_sat";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_sat";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_sat_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
#------------------------------------------------------------------------
/////////
// SUN //
/////////
//REG
$col = array();
$col["title"] = "REG";
$col["name"] = "rt_sun";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//OVER TIME
$col = array();
$col["title"] = "OT";
$col["name"] = "ot_sun";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//TRAVEL
$col = array();
$col["title"] = "TRAV";
$col["name"] = "tv_sun";
$col["width"] = "40";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
//$col["editoptions"] = array("defaultValue"=>'0.00');
$col["editrules"] = array("maxValue"=>24, "number"=>true);
$cols[] = $col;
//NOTES
$col = array();
$col["title"] = "NOTES";
$col["name"] = "time_sun_notes";
$col["width"] = "150";
$col["hidden"] = true;
$col["export"] = true;
$col["editable"] = true;
$col["search"] = false;
$cols[] = $col;
///////////
// TOTAL //
///////////
$col = array();
$col["title"] = "Total";
$col["name"] = "total";
$col["width"] = "100";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = false;
$col["on_data_display"] = array("calc_cost");
function calc_cost($data){
return number_format((float)$data["rt_mon"] + $data["rt_tue"] + $data["rt_wed"] + $data["rt_thu"] + $data["rt_fri"] + $data["rt_sat"] + $data["rt_sun"] + $data["tv_mon"] + $data["tv_tue"] + $data["tv_wed"] + $data["tv_thu"] + $data["tv_fri"] + $data["tv_sat"] + $data["tv_sun"], 2, '.', ''
); }
$col["formatoptions"] = array("decimalSeparator" => ".",
"decimalPlaces" => 2);
$col["search"] = false;
$cols[] = $col;
//////////////
// OT TOTAL //
//////////////
$col = array();
$col["title"] = "OT Total";
$col["name"] = "ot_total";
$col["width"] = "100";
$col["hidden"] = false;
$col["export"] = true;
$col["editable"] = false;
$col["on_data_display"] = array("calc_cost2");
function calc_cost2($data){
return number_format((float)$data["ot_mon"] + $data["ot_tue"] + $data["ot_wed"] + $data["ot_thu"] + $data["ot_fri"] + $data["ot_sat"] + $data["ot_sun"], 2, '.', ''); }
$col["formatoptions"] = array("decimalSeparator" => ".",
"decimalPlaces" => 2);
$col["search"] = false;
$cols[] = $col;
#################
# GROUP HEADERS #
#################
$g->set_group_header( array(
"useColSpanStyle"=>false,
"groupHeaders"=>array(
array(
"startColumnName"=>'job_number_tc', // group starts from this column
"numberOfColumns"=>2, // group span to next 2 columns
"titleText"=>'KODIAK JOB' // caption of group header
),
array(
"startColumnName"=>'rt_mon', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'MONDAY<br>' . date("m/d/y", strtotime($sd . ' + 0 days')) // caption of group header
),
array(
"startColumnName"=>'rt_tue', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'TUESDAY<br>' . date("m/d/y", strtotime($sd . ' + 1 days')) // caption of group header
),
array(
"startColumnName"=>'rt_wed', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'WEDNESDAY<br>' . date("m/d/y", strtotime($sd . ' + 2 days'))
),
array(
"startColumnName"=>'rt_thu', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'THURSDAY<br>' . date("m/d/y", strtotime($sd . ' + 3 days'))
),
array(
"startColumnName"=>'rt_fri', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'FRIDAY<br>' . date("m/d/y", strtotime($sd . ' + 4 days'))
),
array(
"startColumnName"=>'rt_sat', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'SATURDAY<br>' . date("m/d/y", strtotime($sd . ' + 5 days'))
),
array(
"startColumnName"=>'rt_sun', // group starts from this column
"numberOfColumns"=>4, // group span to next 2 columns
"titleText"=>'SUNDAY<br>' . date("m/d/y", strtotime($sd . ' + 6 days'))
)
)
)
);
////////////////////////
// ADD COOKED COLUMNS //
////////////////////////
$g->set_columns($cols);
##########
# EVENTS #
##########
$e["on_insert"] = array("add_", null, true);
$e["on_update"] = array("update_", null, true);
$g->set_events($e);
#########################
# ON ADD AND EDIT EVENT #
#########################
function add_($data)
{
global $tc;
global $g;
global $utype;
//SET USER TIMECARD ID
$data["params"]["time_fk_week"] = $tc;
//SEE IF IT IS NP OR JOB_NUMBER
if (is_numeric($data["params"]["job_number_tc"])) {
$jj = substr($data["params"]["job_number_tc"],0,4);
} else {
$tm = explode(" ", $data["params"]["job_number_tc"], 2);
$jj = $tm[0];
}
$uun = explode("-", $data["params"]["unit_number"]);
$uu = $uun[0];
//ARCHIVED ERROR
$ja = $g->get_one("SELECT * FROM tbl_job WHERE job_status = 'ARCHIVED' AND job_number_tc=?",array($jj));
if (!empty($ja)) {
unset($data["params"]["time_job_id"]);
unset($data["params"]["time_unit_id"]);
phpgrid_error("JOB IS ARCHIVED, NO TIME CAN BE PUT ON THE JOB (" . $jj .")");
}
//JOB DOES NOT EXIST ERROR
$jc = $g->get_one("SELECT * FROM tbl_job WHERE job_number_tc=?",array($jj));
if (!empty($jc)) {
$data["params"]["time_job_id"] = $jc['job_id'];
} else {
unset($data["params"]["time_job_id"]);
unset($data["params"]["time_unit_id"]);
phpgrid_error("JOB NUMBER DOES NOT EXIST (" . $jj . ")");
}
//CHECKS IF UNIT NUMBER EXISTS
$jn = $data["params"]["time_job_id"];
$uuc = $g->get_one("SELECT * FROM tbl_unit WHERE unit_number=? AND fk_job_id=?",array($uu,$jn));
if (!empty($uuc)) {
$data["params"]["time_unit_id"] = $uuc['unit_id'];
} else {
$data["params"]["time_unit_id"]='NULL';
unset($data["params"]["unit_number"]);
}
unset($data["params"]["job_number_tc"]);
unset($data["params"]["unit_number"]);
}
function update_($data)
{
unset($data["params"]["job_number_tc"]);
unset($data["params"]["unit_number"]);
}
#######################
# RENDER GRID (list1) #
#######################
$out = $g->render("list1");
?>
<?php
################
# INCLUDE MENU #
################
include("assets/menu.php");
echo 'PHP version: ' . phpversion();
################
# DISPLAY GRID #
################
echo $out
?>
<!-- JAVA SCRIPT -->
<script>
//FANCYBOX
$(document).ready(function() {
$('.fancybox').fancybox({
'width': '100%',
'height': '50%',
'type': 'iframe',
'fitToView' : false
});
});
//SHOW FOOTER CALCULATIONS
function grid_onload(ids)
{
// LIST1
var grid = $("#list1");
// GET SUM RT MON TOTAL
var m_sum = grid.jqGrid('getCol', 'rt_mon', false, 'sum');
var m_fsum = (Number(m_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var om_sum = grid.jqGrid('getCol', 'ot_mon', false, 'sum');
var om_fsum = (Number(om_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tm_sum = grid.jqGrid('getCol', 'tv_mon', false, 'sum');
var tm_fsum = (Number(tm_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM RT TUE TOTAL
var t_sum = grid.jqGrid('getCol', 'rt_tue', false, 'sum');
var t_fsum = (Number(t_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var otu_sum = grid.jqGrid('getCol', 'ot_tue', false, 'sum');
var otu_fsum = (Number(otu_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tt_sum = grid.jqGrid('getCol', 'tv_tue', false, 'sum');
var tt_fsum = (Number(tt_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM WED TOTAL
var w_sum = grid.jqGrid('getCol', 'rt_wed', false, 'sum');
var w_fsum = (Number(w_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var ow_sum = grid.jqGrid('getCol', 'ot_wed', false, 'sum');
var ow_fsum = (Number(ow_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tw_sum = grid.jqGrid('getCol', 'tv_wed', false, 'sum');
var tw_fsum = (Number(tw_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM THU TOTAL
var th_sum = grid.jqGrid('getCol', 'rt_thu', false, 'sum');
var th_fsum = (Number(th_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var oth_sum = grid.jqGrid('getCol', 'ot_thu', false, 'sum');
var oth_fsum = (Number(oth_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tth_sum = grid.jqGrid('getCol', 'tv_thu', false, 'sum');
var tth_fsum = (Number(tth_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM FRI TOTAL
var f_sum = grid.jqGrid('getCol', 'rt_fri', false, 'sum');
var f_fsum = (Number(f_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var of_sum = grid.jqGrid('getCol', 'ot_fri', false, 'sum');
var of_fsum = (Number(of_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tf_sum = grid.jqGrid('getCol', 'tv_fri', false, 'sum');
var tf_fsum = (Number(tf_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM SAT TOTAL
var s_sum = grid.jqGrid('getCol', 'rt_sat', false, 'sum');
var s_fsum = (Number(s_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var os_sum = grid.jqGrid('getCol', 'ot_sat', false, 'sum');
var os_fsum = (Number(os_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var ts_sum = grid.jqGrid('getCol', 'tv_sat', false, 'sum');
var ts_fsum = (Number(ts_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM SUN TOTAL
var sn_sum = grid.jqGrid('getCol', 'rt_sun', false, 'sum');
var sn_fsum = (Number(sn_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var osn_sum = grid.jqGrid('getCol', 'ot_sun', false, 'sum');
var osn_fsum = (Number(osn_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var tsn_sum = grid.jqGrid('getCol', 'tv_sun', false, 'sum');
var tsn_fsum = (Number(tsn_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
// GET SUM OF 'TOTAL'
var sum = grid.jqGrid('getCol', 'total', false, 'sum');
var fsum = (Number(sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
var ot_sum = grid.jqGrid('getCol', 'ot_total', false, 'sum');
var ot_fsum = (Number(ot_sum) ).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits : 2, minimumFractionDigits : 2 });
//TOTAL TEXT IN THE COST ROW IN FOOTER
//SUM IN THE TOTAL ROW IN FOOTER
//grid.jqGrid('footerData','set', {total: fsum }, false);
grid.jqGrid('footerData','set', {rt_mon: m_fsum }, false);
grid.jqGrid('footerData','set', {ot_mon: om_fsum }, false);
grid.jqGrid('footerData','set', {tv_mon: tm_fsum }, false);
grid.jqGrid('footerData','set', {rt_tue: t_fsum }, false);
grid.jqGrid('footerData','set', {ot_tue: otu_fsum }, false);
grid.jqGrid('footerData','set', {tv_tue: tt_fsum }, false);
grid.jqGrid('footerData','set', {rt_wed: w_fsum }, false);
grid.jqGrid('footerData','set', {ot_wed: ow_fsum }, false);
grid.jqGrid('footerData','set', {tv_wed: tw_fsum }, false);
grid.jqGrid('footerData','set', {rt_thu: th_fsum }, false);
grid.jqGrid('footerData','set', {ot_thu: oth_fsum }, false);
grid.jqGrid('footerData','set', {tv_thu: tth_fsum }, false);
grid.jqGrid('footerData','set', {rt_fri: f_fsum }, false);
grid.jqGrid('footerData','set', {ot_fri: of_fsum }, false);
grid.jqGrid('footerData','set', {tv_fri: tf_fsum }, false);
grid.jqGrid('footerData','set', {rt_sat: s_fsum }, false);
grid.jqGrid('footerData','set', {ot_sat: os_fsum }, false);
grid.jqGrid('footerData','set', {tv_sat: ts_fsum }, false);
grid.jqGrid('footerData','set', {rt_sun: sn_fsum }, false);
grid.jqGrid('footerData','set', {ot_sun: osn_fsum }, false);
grid.jqGrid('footerData','set', {tv_sun: tsn_fsum }, false);
grid.jqGrid('footerData','set', {total: 'TOTAL: ' + fsum }, false);
grid.jqGrid('footerData','set', {ot_total: 'OT: ' + ot_fsum }, false);
if(ids.rows)
jQuery.each(ids.rows,function(i) {
// USED WHEN SCROLL ON GRID
var gid = "list1";
if (typeof(jQuery('#'+gid).data('jqgrid_rows')) != 'undefined')
i = i + jQuery('#'+gid).data('jqgrid_rows');
if (parseInt(this.fk_quote_unit_id) > 0)
{
//CHANGE QUOTE NUMBER BOLD WHEN QUOTE IS ATTACHED
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_quote_number]').css('background','inherit').css({'font-weight':'bold', 'font-size':'12px', 'text-decoration':'underline'});
}
});
};
//CUSTOM CLONE BUTTON
jQuery(document).ready(function(){
//var job = "<?php echo $jid; ?>";
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var tcard = "<?php echo $tc ?>";
var notes = "<?php echo $notes ?>";
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Export Timesheet',
'buttonicon' : 'ui-icon-extlink',
'onClickButton': function()
{
$.fancybox.open({
href: 'assets/timesheet/timesheet_export.php?tc='+tcard+"&export_notes=" + notes,
type: 'iframe',
autoSize: true,
autoSize: false, // shouldn't be true ?
fitToView: false,
maxWidth: 550,
maxHeight: 600
});
$(document).ready(function () {
window.setTimeout(function(){
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard +"&export_notes="+ notes;
}, 2000);
});
},
'position': 'last'
});
});
jQuery(document).ready(function(){
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var tcard = "<?php echo $tc ?>";
var notes = "<?php echo $notes ?>";
if (notes != 0) {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Export Notes',
'buttonicon' : 'ui-icon-circle-check',
'onClickButton': function()
{
notes = 0;
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes
},
'position': 'last'
});
} else {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Export Notes',
'buttonicon' : 'ui-icon-circle-close',
'onClickButton': function()
{
notes=1;
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes
},
'position': 'last'
});
}
});
jQuery(document).ready(function(){
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var tcard = "<?php echo $tc ?>";
var notes = "<?php echo $notes ?>";
if (location.href.indexOf("list1_showcols") != -1 && location.href.indexOf("time_mon_notes") != -1) {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Hide Notes',
'buttonicon' : 'ui-icon-circle-minus',
'onClickButton': function()
{
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes
},
'position': 'last'
});
} else {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Show Notes',
'buttonicon' : 'ui-icon-circle-plus',
'onClickButton': function()
{
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes + "&list1_showcols=time_mon_notes,time_tue_notes,time_wed_notes,time_thu_notes,time_fri_notes,time_sat_notes,time_sun_notes"
},
'position': 'last'
});
}
});
jQuery(document).ready(function(){
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var tcard = "<?php echo $tc ?>";
var notes = "<?php echo $notes ?>";
if (location.href.indexOf("list1_showcols") != -1 && location.href.indexOf("unit_description") != -1) {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Hide Description',
'buttonicon' : 'ui-icon-circle-minus',
'onClickButton': function()
{
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes
},
'position': 'last'
});
} else {
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Show Description',
'buttonicon' : 'ui-icon-circle-plus',
'onClickButton': function()
{
window.location.href = "?unit=" + unit + "&job=" + job + "&tc=" + tcard + "&export_notes=" + notes + "&list1_showcols=unit_description,job_description"
},
'position': 'last'
});
}
});
//FILL EQUIPMENT INFORMATION
function fill_form(data)
{
jQuery("[name=time_job_id].FormElement,[name=time_job_id].editable").val(data.job_id);
}
//FILL EQUIPMENT INFORMATION
function fill_form_unit(data)
{
jQuery("[name=time_unit_id].FormElement,[name=time_unit_id].editable").val(data.unit_id);
}
</script>
<!-- CSS STYLE -->
<style type="text/css">
.ui-jqgrid tr.ui-row-ltr td { border-right-style:inherit !important; border: 1px solid black;}
.ui-jqgrid tr.ui-row-rtl td { border-left-style:inherit !important; border: 1px solid black;}
.ui-jqgrid .ui-jqgrid-htable th {border-left-style:inherit !important; border: 1px solid black;}
</style>
</body>
</html>
################
# GRID OPTIONS #
################
$grid["caption"] = $title; // GRID CAPTION NAME
$grid["cellEdit"] = false; // inline cell editing, like spreadsheet
$grid["reloadedit"] = true; // refresh
$grid["sortname"] = 'job_number, unit_number'; // sort by kodiak job number'
$grid["sortorder"] = "ASC"; //
$grid["footerrow"] = true; //
$grid["autowidth"] = false; // expand grid to screen width
$grid["shrinkToFit"] = false; //
$grid["loadComplete"] = "function(ids){ grid_onload(ids); }"; //
$grid["afterSaveCell"] = "function(){ setTimeout(()=>{ $('#list1').trigger('reloadGrid', [{current:true}]);},200) }"; //refresh
$g->set_options($grid); //
##############################
# SET GRID C.R.U.D. SETTINGS #
##############################
$g->set_actions(array(
"add"=>true, // Enable / Disable add operation on grid. Defaults to true.
"edit"=>true, // Enable / Disable edit operation on grid. Defaults to true.
"delete"=>true, // Enable / Disable delete operation on grid. Defaults to true.
"view"=>false, // Enable / Disable view operation on grid. Defaults to true.
"inline"=>true, // Enable / Disable button to perform insertion inline. Defaults to false.
"rowactions"=>true, // Enable / Disable inline edit/del/save option. Defaults to true.
"search" => "false", // Search property can have 3 values, simple, advance or false to hide.
"export"=>false, // Enable / Disable export to excel option. Defaults to false.
"export_pdf"=>false, // export pdf button
"showhidecolumns" => false, // Enable / Disable button to hide certain columns from client side. Defaults to true.
"bulkedit"=> false, // Enable / Disable bulk edit operation on grid. Defaults to false.
"clone"=> false, // Enable / Disable clone operation on grid. Defaults to false.
"import"=> false, // Enable / Disable import data option. Defaults to false.
"autofilter"=> false // Enable / Disable autofilter toolbar for search on top. Defaults to true.
)
);
###############################
# MAIN QUERY (EQUIPMENT LIST) #
###############################
$g->select_command = "SELECT * FROM tbl_timecard
LEFT JOIN tbl_job ON job_id = time_job_id
LEFT JOIN tbl_unit ON unit_id = time_unit_id WHERE time_fk_week = '$tc'";
###################################
# REMOVE BUTTONS FROM GRID HEADER #
###################################
$g->navgrid["param"]["edit"] = false; // remove edit from top menu
$g->navgrid["param"]["del"] = true; // remove delete from top menu
$g->navgrid["param"]["add"] = false; // remove add from top menu
#################
# MAIN DATABAES #
#################
$g->table = "tbl_timecard";
####################################
# SETUP COLUMNS TO DISPLAY IN GRID #
####################################
//////////////////
// TIME WEEK ID // - MAIN COLUMN
//////////////////
$col = array();
$col["title"] = "time_id";
$col["name"] = "time_id";
$col["width"] = "40";
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment