Webgui: filter and pagination working
This commit is contained in:
+121
-15
@@ -41,6 +41,9 @@ define ('ACT_VIEW_LIST', 13);
|
||||
|
||||
// ========== PAGE START CODE =================================================
|
||||
|
||||
// global version string
|
||||
$g_version = 'v0.1.1';
|
||||
|
||||
$g_scriptname = basename($_SERVER['SCRIPT_NAME']);
|
||||
|
||||
require 'config.inc';
|
||||
@@ -113,6 +116,7 @@ $user = User::GetInstance(); // There can be only one
|
||||
if ($g_scriptname != 'login.php') {
|
||||
$user->init_from_session();
|
||||
$user->load_vessel();
|
||||
$user->load_settings();
|
||||
}
|
||||
|
||||
$action = NULL;
|
||||
@@ -124,6 +128,7 @@ $g_doc_mimetypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf
|
||||
// form option lists
|
||||
$g_opt_all = array(-2 => _('― all ―'));
|
||||
$g_opt_none = array(-1 => _('― none ―'));
|
||||
$g_opt_unknown = array(-1 => _('― unknown ―'));
|
||||
|
||||
// Initialize message system
|
||||
$g_message = new Message;
|
||||
@@ -227,13 +232,18 @@ class User {
|
||||
public $flags;
|
||||
public $vid; // current selected vessel
|
||||
public $vessel; // name of current vessel
|
||||
public $datefmt;
|
||||
public $rows_pp;
|
||||
|
||||
private function __construct() {
|
||||
global $g_rows_pp;
|
||||
$this->loggedin = FALSE;
|
||||
$this->errormessage = NULL;
|
||||
$this->flags = [];
|
||||
$this->vid = 1;
|
||||
$this->vessel = 'Yacht';
|
||||
$this->datefmt = 'Y-m-d';
|
||||
$this->rows_pp = $g_rows_pp;
|
||||
}
|
||||
|
||||
public static function getInstance() {
|
||||
@@ -300,10 +310,10 @@ class User {
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$this->id]);
|
||||
$row = $sth->fetch();
|
||||
$this->displayname = $row['displayname'];
|
||||
$this->role = $row['role'];
|
||||
//$this->displayname = $sth->fetchColumn();
|
||||
|
||||
if ($row) {
|
||||
$this->displayname = $row['displayname'];
|
||||
$this->role = $row['role'];
|
||||
}
|
||||
}
|
||||
|
||||
function load_vessel() {
|
||||
@@ -314,8 +324,31 @@ class User {
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$this->id]);
|
||||
$row = $sth->fetch();
|
||||
$this->vid = $row['vid'];
|
||||
$this->vessel = $row['vesselname'];
|
||||
if ($row) {
|
||||
$this->vid = $row['vid'];
|
||||
$this->vessel = $row['vesselname'];
|
||||
}
|
||||
}
|
||||
|
||||
function load_settings() {
|
||||
global $pdo;
|
||||
// additional user settings
|
||||
// date format from user settings
|
||||
$sql = "SELECT valstr FROM settings WHERE userid=? AND sno=2";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$this->id]);
|
||||
$user_datefmt = $sth->fetchColumn();
|
||||
if ($user_datefmt) {
|
||||
$this->datefmt = $user_datefmt;
|
||||
}
|
||||
// pagination rows from user settings
|
||||
$sql = "SELECT valint FROM settings WHERE userid=? AND sno=10";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$this->id]);
|
||||
$user_rows_pp = $sth->fetchColumn();
|
||||
if ($user_rows_pp) {
|
||||
$this->rows_pp = $user_rows_pp;
|
||||
}
|
||||
}
|
||||
|
||||
function get_last_error() {
|
||||
@@ -643,6 +676,46 @@ function db_save_taglist($objtype, $objid, $taglist) {
|
||||
}
|
||||
}
|
||||
|
||||
function db_get_tag_target($objtype, $objid) {
|
||||
// get page name and desctiption e.g. for link creation
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
switch ($objtype) {
|
||||
case 'equip':
|
||||
$sql = "SELECT ename FROM equipment WHERE eid=?";
|
||||
$target = "equipment.php";
|
||||
break;
|
||||
case 'inv':
|
||||
$sql = "SELECT invname FROM inventory WHERE invid=?";
|
||||
$target = "inventory.php";
|
||||
break;
|
||||
case 'prov':
|
||||
$sql = "SELECT provname FROM provisions WHERE provvid=?";
|
||||
$target = "provisions.php";
|
||||
break;
|
||||
case 'doc':
|
||||
$sql = "SELECT title FROM document WHERE docid=?";
|
||||
$target = "documents.php";
|
||||
break;
|
||||
case 'proj':
|
||||
$sql = "SELECT projname FROM project WHERE projid=?";
|
||||
$target = "projects.php";
|
||||
break;
|
||||
case 'task':
|
||||
$sql = "SELECT taskname FROM task WHERE taskid=?";
|
||||
$target = "task.php";
|
||||
break;
|
||||
case 'maint':
|
||||
$sql = "SELECT activities FROM maintenance WHERE maintid=?";
|
||||
$target = 'maintenance.php';
|
||||
break;
|
||||
}
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$objid]);
|
||||
$desc = $sth->fetchColumn();
|
||||
return [$target, $desc];
|
||||
}
|
||||
|
||||
function db_get_ddtext($ddid, $ddval) {
|
||||
// returns single value for dropdown
|
||||
global $pdo;
|
||||
@@ -660,14 +733,20 @@ function db_get_ddtext($ddid, $ddval) {
|
||||
|
||||
// Functions to get option lists (key/value)
|
||||
|
||||
function db_get_options($ddid, $orderby = '', $default = NULL) {
|
||||
function db_get_options($ddid, $orderby = '', $short = False, $default = NULL) {
|
||||
// returns list for dropdown
|
||||
// if short is set the short value will be returned
|
||||
global $pdo;
|
||||
$list = array();
|
||||
if ($default != NULL) {
|
||||
$list[0] = $default;
|
||||
}
|
||||
$sql = "SELECT ddval, ddtext FROM dropdown WHERE ddid=?";
|
||||
if ($short) {
|
||||
$sql = "SELECT ddval, ddshort";
|
||||
} else {
|
||||
$sql = "SELECT ddval, ddtext";
|
||||
}
|
||||
$sql .= " FROM dropdown WHERE ddid=?";
|
||||
if ($orderby == 'ddtext') {
|
||||
$sql .= ' ORDER BY ddtext';
|
||||
} elseif ($orderby == 'sort') {
|
||||
@@ -819,7 +898,8 @@ function db_get_opt_proj($vid, $default=NULL) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_filter($user, $sno) {
|
||||
function db_get_filter($user, $sno, $fields = []) {
|
||||
// if fields supplied empting missing field are created
|
||||
global $pdo;
|
||||
global $g_warning;
|
||||
$flt = new stdClass();
|
||||
@@ -827,15 +907,22 @@ function db_get_filter($user, $sno) {
|
||||
try {
|
||||
$sth->execute([$user, $sno]);
|
||||
$json = $sth->fetchColumn();
|
||||
if (!$json) {
|
||||
if ($json === false) {
|
||||
// no settings record. create empty one for later updates
|
||||
$sth = $pdo->prepare("INSERT INTO settings (userid, sno, valstr) VALUES (?, ?, '{}')");
|
||||
$sth->execute([$user, $sno]);
|
||||
} else {
|
||||
$flt = json_decode($json);
|
||||
}
|
||||
// create missing fields
|
||||
foreach ($fields as $f) {
|
||||
if (!property_exists($flt, $f)) {
|
||||
$flt->$f = null;
|
||||
}
|
||||
}
|
||||
} catch (PDOexception $e) {
|
||||
$g_warning->Add('SQL-Error: '. $e->getMessage());
|
||||
$g_warning->PrintOut();
|
||||
}
|
||||
return $flt;
|
||||
}
|
||||
@@ -1155,7 +1242,7 @@ function get_color_brightness($color, $default=0.5) {
|
||||
function page_caption_search($caption) {
|
||||
// print page caption with searchbox
|
||||
?>
|
||||
<div class="row align-items-center">
|
||||
<div class="row row align-items-center justify-content-between">
|
||||
<div class="col">
|
||||
<h1><?=$caption?></h1>
|
||||
</div>
|
||||
@@ -1193,8 +1280,8 @@ function get_pagination($script, $param, $page, $lastpage, $small=false) {
|
||||
$out .= '<li class="page-item"><a class="page-link" href="'. $script. $psep. 'p=1">'. _('First'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item"><a class="page-link" href="'. $script. $psep. 'p='. ($page - 1). '">'. _('Previous'). '</a></li>'. "\n";
|
||||
} else {
|
||||
$out .= '<li class="page-item disabled"><a class="page-link href="#">'. _('First'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><a class="page-link href="#">'. _('Previous'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">'. _('First'). '</span></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">'. _('Previous'). '</span></li>'. "\n";
|
||||
}
|
||||
|
||||
if ($lastpage < 10) {
|
||||
@@ -1205,6 +1292,25 @@ function get_pagination($script, $param, $page, $lastpage, $small=false) {
|
||||
}
|
||||
} else {
|
||||
// start working with ... dots
|
||||
$start = max(2, $page - 2);
|
||||
$end = min($lastpage - 1, $page + 2);
|
||||
$out .= '<li class="page-item"><a class="page-link';
|
||||
if ($page == 1) $out .= ' active';
|
||||
$out .= '" href="'. $script. $psep. 'p=1">1</a></li>'. "\n";
|
||||
if ($start > 2) {
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">...</span></li>'. "\n";
|
||||
}
|
||||
for ($n = $start; $n <= $end; $n++) {
|
||||
$out .='<li class="page-item"><a class="page-link';
|
||||
if ($n == $page) $out .= ' active';
|
||||
$out .= '" href="'. $script. $psep. 'p='. $n. '">'. $n. '</a></li>'. "\n";
|
||||
}
|
||||
if ($end < $lastpage - 1) {
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">...</span></li>';
|
||||
}
|
||||
$out .= '<li class="page-item"><a class="page-link';
|
||||
if ($page == $lastpage) $out .= ' active';
|
||||
$out .= '" href="'. $script. $psep. 'p='. $lastpage. '">'. $lastpage. '</a></li>'. "\n";
|
||||
}
|
||||
|
||||
if ($page < $lastpage) {
|
||||
@@ -1212,8 +1318,8 @@ function get_pagination($script, $param, $page, $lastpage, $small=false) {
|
||||
$out .= '<li class="page-item"><a class="page-link" href="'. $script. $psep. 'p='. ($page + 1). '">'. _('Next'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item"><a class="page-link" href="'. $script. $psep. 'p='. $lastpage. '">'. _('Last'). '</a></li>'. "\n";
|
||||
} else {
|
||||
$out .= '<li class="page-item disabled"><a class="page-link href="#">'. _('Next'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><a class="page-link href="#">'. _('Last'). '</a></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">'. _('Next'). '</span></li>'. "\n";
|
||||
$out .= '<li class="page-item disabled"><span class="page-link">'. _('Last'). '</span></li>'. "\n";
|
||||
}
|
||||
|
||||
// idea: small entry to input page number
|
||||
|
||||
Reference in New Issue
Block a user