Skip to content

Commit

Permalink
Merge pull request #2 from Coral-erm/pr68
Browse files Browse the repository at this point in the history
Session abstraction (Pr68 on previous repo)
  • Loading branch information
jsavell authored Jul 11, 2016
2 parents 9398f2d + b63857f commit 44d4880
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion resources/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
include 'templates/header.php';

//set referring page
$_SESSION['ref_script']=$currentPage;
CoralSession::set('ref_script', $currentPage);

$config = new Configuration;

Expand Down
33 changes: 33 additions & 0 deletions resources/admin/classes/common/CoralSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

class CoralSession
{
private static $opened;

private static function open_for_read() {
if (!isset(self::$opened)) {
session_start();
session_write_close();
self::$opened = true;
}
}

public static function get($key) {
self::open_for_read();
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
} else {
return null;
}
}

public static function set($key, $value) {
session_start();
$_SESSION[$key] = $value;
session_write_close();
self::$opened = true;
}

}

?>
6 changes: 3 additions & 3 deletions resources/admin/classes/domain/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,18 +996,18 @@ public static function setSearch($search) {
foreach ($search as $key => $value) {
$search[$key] = trim($value);
}
$_SESSION['resourceSearch'] = $search;
CoralSession::set('resourceSearch', $search);
}

public static function resetSearch() {
Resource::setSearch(array());
}

public static function getSearch() {
if (!isset($_SESSION['resourceSearch'])) {
if (!CoralSession::get('resourceSearch')) {
Resource::resetSearch();
}
return $_SESSION['resourceSearch'];
return CoralSession::get('resourceSearch');
}

public static function getSearchDetails() {
Expand Down
4 changes: 2 additions & 2 deletions resources/admin/classes/domain/ResourceStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function completeStep(){

//mark this step complete
$this->stepEndDate = date( 'Y-m-d' );
$this->endLoginID = $_SESSION['loginID'];
$this->save();
$this->endLoginID = CoralSession::get('loginID');
$this->save;

$this->startNextStepsOrComplete();

Expand Down
2 changes: 0 additions & 2 deletions resources/ajax_htmldata.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
**************************************************************************************************************************
*/

session_start();

include_once 'directory.php';
include_once 'user.php';

Expand Down
2 changes: 0 additions & 2 deletions resources/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/


session_start();

include_once 'directory.php';
include_once 'util.php';

Expand Down
2 changes: 1 addition & 1 deletion resources/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function searchForShortName($shortName, $array)
}
return null;
}
session_start();

include_once 'directory.php';
$pageTitle=_('Resources import');
include 'templates/header.php';
Expand Down
49 changes: 23 additions & 26 deletions resources/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@
*/


session_start();

include_once 'directory.php';

//print header
$pageTitle=_('Home');
include 'templates/header.php';

//used for creating a "sticky form" for back buttons
//except we don't want it to retain if they press the 'index' button
//check what referring script is

if ($_SESSION['ref_script'] != "resource.php"){
if (CoralSession::get('ref_script') != "resource.php"){
Resource::resetSearch();
}

CoralSession::set('ref_script', $currentPage);
$search = Resource::getSearch();

$_SESSION['ref_script']=$currentPage;

//print header
$pageTitle=_('Home');
include 'templates/header.php';


?>
Expand Down Expand Up @@ -614,24 +611,24 @@
<script type="text/javascript" src="js/index.js"></script>
<script type='text/javascript'>
<?php
//used to default to previously selected values when back button is pressed
//if the startWith is defined set it so that it will default to the first letter picked
if ((isset($_SESSION['res_startWith'])) && ($reset != 'Y')){
echo "startWith = '" . $_SESSION['res_startWith'] . "';";
echo "$(\"#span_letter_" . $_SESSION['res_startWith'] . "\").removeClass('searchLetter').addClass('searchLetterSelected');";
}

if ((isset($_SESSION['res_pageStart'])) && ($reset != 'Y')){
echo "pageStart = '" . $_SESSION['res_pageStart'] . "';";
}

if ((isset($_SESSION['res_recordsPerPage'])) && ($reset != 'Y')){
echo "recordsPerPage = '" . $_SESSION['res_recordsPerPage'] . "';";
}

if ((isset($_SESSION['res_orderBy'])) && ($reset != 'Y')){
echo "orderBy = \"" . $_SESSION['res_orderBy'] . "\";";
}
//used to default to previously selected values when back button is pressed
//if the startWith is defined set it so that it will default to the first letter picked
if ((CoralSession::get('res_startWith')) && ($reset != 'Y')){
echo "startWith = '" . CoralSession::get('res_startWith') . "';";
echo "$(\"#span_letter_" . CoralSession::get('res_startWith') . "\").removeClass('searchLetter').addClass('searchLetterSelected');";
}

if ((CoralSession::get('res_pageStart')) && ($reset != 'Y')){
echo "pageStart = '" . CoralSession::get('res_pageStart') . "';";
}

if ((CoralSession::get('res_recordsPerPage')) && ($reset != 'Y')){
echo "recordsPerPage = '" . CoralSession::get('res_recordsPerPage') . "';";
}

if ((CoralSession::get('res_orderBy')) && ($reset != 'Y')){
echo "orderBy = \"" . CoralSession::get('res_orderBy') . "\";";
}

This comment has been minimized.

Copy link
@tuxayo

tuxayo Jul 12, 2016

Contributor

@jsavell
Watch out for your text editor settings, it replaced tabs (which are 90% of the indentation of Coral) by two spaces indents.

This comment has been minimized.

Copy link
@jsavell

jsavell Jul 12, 2016

Author Contributor

The code changes aren't mine. I resolved the merge conflicts and merged the request.

My text editor is using tabs.

This comment has been minimized.

Copy link
@tuxayo

tuxayo Jul 12, 2016

Contributor

Oh sorry, thanks for having taken care of this PR before is got lost in the old repo ;-)


echo "</script>";

Expand Down
2 changes: 1 addition & 1 deletion resources/install/CORALInstaller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
session_start();
require_once('../directory.php');

if (!function_exists('debug')) {
Expand All @@ -9,6 +8,7 @@ function debug($value) {
}

class CORALInstaller {
session_start();

public $db; // because CORALInstaller::query does unwanted things with result
public $error;
Expand Down
6 changes: 3 additions & 3 deletions resources/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

include_once 'directory.php';

$pageTitle=_('My Queue');
include 'templates/header.php';

//set referring page
$_SESSION['ref_script']=$currentPage;
CoralSession::set('ref_script', $currentPage);

$pageTitle=_('My Queue');
include 'templates/header.php';



Expand Down
13 changes: 6 additions & 7 deletions resources/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
**************************************************************************************************************************
*/

session_start();
include_once 'directory.php';

$resourceID = $_GET['resourceID'];
Expand All @@ -27,18 +26,18 @@
//used to get default email address for feedback link in the right side panel
$config = new Configuration();

//set this to turn off displaying the title header in header.php
$pageTitle=$resource->titleText;;
include 'templates/header.php';


//set referring page
if ((isset($_GET['ref'])) && ($_GET['ref'] == 'new')){
$_SESSION['ref_script']="new";
CoralSession::set('ref_script', 'new');
}else{
$_SESSION['ref_script']=$currentPage;
CoralSession::set('ref_script', $currentPage);
}

//set this to turn off displaying the title header in header.php
$pageTitle=$resource->titleText;;
include 'templates/header.php';


if ($resource->titleText){
?>
Expand Down
2 changes: 0 additions & 2 deletions resources/resources/cataloging.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
**************************************************************************************************************************
*/

session_start();

include_once '../directory.php';
include_once '../user.php';

Expand Down
1 change: 0 additions & 1 deletion resources/resources/cataloging_update.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
session_start();

include_once '../directory.php';
include_once '../user.php';
Expand Down
1 change: 0 additions & 1 deletion resources/sendAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
**************************************************************************************************************************
*/

session_start();
include_once 'directory.php';

$util = new Utility();
Expand Down
1 change: 0 additions & 1 deletion resources/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
**************************************************************************************************************************
*/

session_start();
include_once 'directory.php';

$util = new Utility();
Expand Down
15 changes: 4 additions & 11 deletions resources/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

//if the user has an open session
if (($loginID) && ($user->hasOpenSession())){

session_start();
$_SESSION['loginID'] = $loginID;
CoralSession::set('loginID', $loginID);

//no open session
}else{
Expand All @@ -61,9 +59,7 @@
}else{

//get login id from server
if (!isset($_SESSION['loginID']) || ($_SESSION['loginID'] == '')){


if (!CoralSession::get('loginID') || (CoralSession::get('loginID') == '')){
$varName = $config->settings->remoteAuthVariableName;

//the following code takes the remote auth variable name from the config settings and evaluates it to get the actual value from web server
Expand All @@ -77,15 +73,12 @@
//use the split in case the remote login is supplied as an email address
list ($loginID,$restofAddr) = explode("@", $remoteAuth);



session_start();
$_SESSION['loginID'] = $loginID;
CoralSession::set('loginID', $loginID);


}else{

$loginID = $_SESSION['loginID'];
$loginID = CoralSession::get('loginID');

}

Expand Down

1 comment on commit 44d4880

@tuxayo
Copy link
Contributor

@tuxayo tuxayo commented on 44d4880 Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, notices about the already started sessions represented about 10% of the noise that was in the logs. Hopefully none of these will remain :-D

Please sign in to comment.