Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.env
/vendor
.env
!sample.env
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require-dev": {
"squizlabs/php_codesniffer": "^3.13",
"phpcompatibility/php-compatibility": "^9.3"
}
}
165 changes: 165 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/*
|--------------------------------------------------------------
| Application Configuration
|--------------------------------------------------------------
| This file is intended to be committed to the repository.
| Sensitive values are read from environment variables (set via Docker, .env, or
| server configuration).
| If an environment variable is missing, a default value is used instead.
|
| Update environment variables rather than editing this file
| whenever possible.
*/

// Helper to fetch env var with optional fallback
function env_or_default(string $key, $default = '') {
$val = getenv($key);
return $val === false ? $default : $val;
}

// -----------------------------------------------------------------------------
// Core constants (populate from ENV with fallback)
// -----------------------------------------------------------------------------

define('DEBUG', filter_var(env_or_default('DEBUG', 'false'), FILTER_VALIDATE_BOOLEAN));

define('SUMASERVER_URL', env_or_default('SUMASERVER_URL', ''));

define('SUMA_REPORTS_URL', env_or_default('SUMA_REPORTS_URL', ''));

define('MYSQL_HOST', env_or_default('MYSQL_HOST', 'localhost'));

define('MYSQL_DATABASE', env_or_default('MYSQL_DATABASE', 'suma'));

define('MYSQL_USER', env_or_default('MYSQL_USER', 'suma_user'));

define('MYSQL_PASSWORD', env_or_default('MYSQL_PASSWORD', 'suma_pass'));

// -----------------------------------------------------------------------------
// UI settings (leave these as-is or override via ENV if desired)
// -----------------------------------------------------------------------------

// Available JQuery UI themes: cupertino, flick, hot-sneaks, humanity, overcast,
// pepper-grinder, redmond, smoothness, south-street, start, sunny, ui-lightness
$ui_theme = env_or_default('UI_THEME', 'pepper-grinder');

$default_init = env_or_default('DEFAULT_INIT', '');
$entries_per_page = intval(env_or_default('ENTRIES_PER_PAGE', 100));

// If true, the datepicker will not allow future dates
$prevent_datepicker_future = filter_var(env_or_default('PREVENT_DATEPICKER_FUTURE', 'true'), FILTER_VALIDATE_BOOLEAN);

/*
| If an initiative usually only has one count per hour, include it in the array
| below (by ID) to allow searching for hours with multiple entries.
| Example: $one_per_hour_inits = array(1,4);
*/
$one_per_hour_inits = array();

/*
You can use Suma Session Manager to adjust the time of previously-entered
sessions. The following array controls what options you are given for
adjusting the time. You may add, delete or comment-out lines as you wish.

The array values (e.g. "subtime 04:00:00" are given as arguments sent to
MySQL and are formatted to give a MySQL command. The amount of time to be
changed is given in HH:MM:SS format.

Time-adjustment shortcuts for the Suma Session Manager UI.
Keys are the display labels and values are the MySQL time commands.
*/
$adjust_time_options = array(
'-4 hrs' => 'subtime 04:00:00',
'-3 hrs' => 'subtime 03:00:00',
'-2 hrs' => 'subtime 02:00:00',
'-60 min' => 'subtime 01:00:00',
'-30 min' => 'subtime 00:30:00',
'-15 min' => 'subtime 00:15:00',
'-10 min' => 'subtime 00:10:00',
'-5 min' => 'subtime 00:05:00',
'+5 min' => 'addtime 00:05:00',
'+10 min' => 'addtime 00:10:00',
'+15 min' => 'addtime 00:15:00',
'+30 min' => 'addtime 00:30:00',
'+60 min' => 'addtime 01:00:00',
);
13 changes: 8 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
include ("scripts.php");

if (DEBUG === true) {
error_reporting(E_WARN);
ini_set("display_errors", true);

error_reporting(E_WARNING);
ini_set("display_errors", true);
var_dump($_REQUEST);
print "<p></p>".PHP_EOL;
print "<p></p>".PHP_EOL;
}

if (isset($_REQUEST['set_init'])) {
Expand Down Expand Up @@ -99,6 +98,10 @@

$offset = (isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0);

// Initialize optional query helpers to prevent undefined-variable notices
$and_where = null;
$hour_focus = isset($_REQUEST['hour_focus']) ? $_REQUEST['hour_focus'] : "";

if (isset($_REQUEST['action']) && $_REQUEST['action'] == "move_session") {
MoveSession($_REQUEST['session_id'], $_REQUEST['transaction_id'], $_REQUEST['time_shift']);
print '<hr>';
Expand All @@ -107,7 +110,7 @@
DeleteUndelete("delete",$_REQUEST['session_id']);
print '<hr>';
}
elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == "undelete_session") {
if (isset($_REQUEST['action']) && $_REQUEST['action'] == "undelete_session") {
DeleteUndelete("undelete",$_REQUEST['session_id']);
print '<hr>';
}
Expand Down
26 changes: 26 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ------------------------------------------------------------------------------
# Sample environment file for Suma Session Manager
# ------------------------------------------------------------------------------
# Duplicate this file to ".env" and adjust values as needed before running
# `docker compose up` so Docker can inject these into the containers.
# ------------------------------------------------------------------------------

# -------------------- Application settings ------------------------------------
DEBUG=false

# Base URLs (no trailing slash)
SUMASERVER_URL=
SUMA_REPORTS_URL=

# UI configuration
UI_THEME=pepper-grinder
DEFAULT_INIT=
ENTRIES_PER_PAGE=100
PREVENT_DATEPICKER_FUTURE=true

# -------------------- Database settings ---------------------------------------
MYSQL_HOST=db
MYSQL_DATABASE=suma
MYSQL_USER=suma_user
MYSQL_PASSWORD=
MYSQL_ROOT_PASSWORD=
25 changes: 18 additions & 7 deletions scripts.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<?php
function ConnectPDO () {
$db = new PDO('mysql:host='.MYSQL_HOST.';port='.MYSQL_PORT.';dbname='.MYSQL_DATABASE.';charset=utf8', MYSQL_USER, MYSQL_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
function ConnectPDO () : PDO {
// Build DSN using configuration constants defined in config.php
$dsn = 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DATABASE . ';charset=utf8mb4';

try {
$db = new PDO($dsn, MYSQL_USER, MYSQL_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
return $db;
} catch (PDOException $e) {
// Reuse existing helper for consistent error display/logging
HandleExceptionPDO($e);
throw $e; // re-throw so callers can handle if needed
}
}
function HandleExceptionPDO($e) {
print '<div class="alert">'.PHP_EOL;
Expand All @@ -11,7 +22,7 @@ function HandleExceptionPDO($e) {
print '</div>'.PHP_EOL;
}

function ShowEntries ($init, $offset=0, $entries_per_page=60, $and_where="", $hour_focus="") {
function ShowEntries ($init, $offset=0, $entries_per_page=60, $and_where = null, $hour_focus="") {

if (is_object($and_where)) {
$and_where_string = $and_where->AndWhereString();
Expand Down Expand Up @@ -123,7 +134,7 @@ function HiddenFieldsForDateSearch() { //used by ShowEntries
}

function MoveSession($session_id, $transaction_id, $time_shift) {
list($action, $hms) = split(" ", $time_shift);
list($action, $hms) = preg_split(" ", $time_shift);
try {
$db = ConnectPDO();

Expand Down Expand Up @@ -229,7 +240,7 @@ function SelectInitiative($default_init) {
return ($select);
} //end if good response
else {
return '<div class="alert"><h3>Unable to connect to Suma Server</h3><p>Unable to connect to the Suma Server using the url defined as <strong>$sumaserver_url = '.$sumaserver_url.'</strong> in the <strong>config.php</strong> file. Please check this url.</p> <p>A useful test of correctness is this: if you can add <strong>/clientinit</strong> to the url, you should get a list of your suma initiatives, e.g. <a href="'.$url.'">'.$url.'</a>.' . PHP_EOL;
return '<div class="alert"><h3>Unable to connect to Suma Server</h3><p>Unable to connect to the Suma Server using the url defined as <strong>$sumaserver_url = '.SUMASERVER_URL.'</strong> in the <strong>config.php</strong> file. Please check this url.</p> <p>A useful test of correctness is this: if you can add <strong>/clientinit</strong> to the url, you should get a list of your suma initiatives, e.g. <a href="'.$url.'">'.$url.'</a>.' . PHP_EOL;
} //end if unable to reach sumaserver
} //end function SelectInitiative

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$sessionmanager_version = "0.2.3";
$sessionmanager_version = "0.3.0";
?>
Loading