Files
luos/workflow/engine/classes/class.sessions.php

279 lines
7.3 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
/**
* class.Sessions.php
2012-10-09 13:22:53 -04:00
*
2011-02-01 12:49:40 +00:00
* @package workflow.engine.ProcessMaker
2012-10-09 13:22:53 -04:00
*
2010-12-02 23:34:41 +00:00
* ProcessMaker Open Source Edition
2011-02-01 12:49:40 +00:00
* Copyright (C) 2004 - 2011 Colosa Inc.
2012-10-09 13:22:53 -04:00
*
2010-12-02 23:34:41 +00:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-10-09 13:22:53 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2010-12-02 23:34:41 +00:00
* GNU Affero General Public License for more details.
2012-10-09 13:22:53 -04:00
*
2010-12-02 23:34:41 +00:00
* You should have received a copy of the GNU Affero General Public License
2012-10-09 13:22:53 -04:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
2010-12-02 23:34:41 +00:00
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
2012-10-09 13:22:53 -04:00
*
2010-12-02 23:34:41 +00:00
*/
require_once 'classes/model/Session.php';
2012-10-09 13:22:53 -04:00
2010-12-02 23:34:41 +00:00
/**
* Sessions - Sessions class
2012-10-09 13:22:53 -04:00
*
2011-02-01 12:49:40 +00:00
* @package workflow.engine.ProcessMaker
2010-12-02 23:34:41 +00:00
* @author Everth S. Berrios Morales
* @copyright 2008 COLOSA
*/
2012-10-09 13:22:53 -04:00
class Sessions
{
protected $tmpfile;
private $sessionId;
private $globals;
/**
* This function is the constructor of the Sessions class
*
* @param string $sSessionId
* @return void
*/
public function __construct ($sSessionId = NULL)
{
$this->sessionId = $sSessionId;
2010-12-02 23:34:41 +00:00
}
2012-10-09 13:22:53 -04:00
/**
* This function gets the user session
*
*
* @name getSessionUser
*
* @param string sSessionId
* @return array
*/
public function getSessionUser ($sSessionId = NULL)
{
try {
if ($sSessionId != NULL) {
$this->sessionId = $sSessionId;
} else if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$oCriteria = new Criteria( 'workflow' );
$oCriteria->addSelectColumn( SessionPeer::USR_UID );
$oCriteria->addSelectColumn( SessionPeer::SES_STATUS );
$oCriteria->addSelectColumn( SessionPeer::SES_DUE_DATE );
$oCriteria->add( SessionPeer::SES_UID, $this->sessionId );
$oDataset = SessionPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
$aRow = $oDataset->getRow();
if (! is_array( $aRow )) {
$this->deleteTmpfile();
}
return $aRow;
} catch (Exception $oError) {
throw ($oError);
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 13:22:53 -04:00
/**
* This function checks the user session
*
*
* @name verifySession
*
* @param string sSessionId
* @return array
*/
public function verifySession ($sSessionId = NULL)
{
try {
if ($sSessionId != NULL) {
$this->sessionId = $sSessionId;
} else if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$date = date( 'Y-m-d H:i:s' );
$oCriteria = new Criteria( 'workflow' );
$oCriteria->addSelectColumn( SessionPeer::USR_UID );
$oCriteria->addSelectColumn( SessionPeer::SES_STATUS );
$oCriteria->addSelectColumn( SessionPeer::SES_DUE_DATE );
$oCriteria->add( SessionPeer::SES_UID, $this->sessionId );
$oCriteria->add( SessionPeer::SES_STATUS, 'ACTIVE' );
$oCriteria->add( SessionPeer::SES_DUE_DATE, $date, Criteria::GREATER_EQUAL );
$oDataset = SessionPeer::doSelectRS( $oCriteria, Propel::getDbConnection('workflow_ro') );
2012-10-09 13:22:53 -04:00
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
$aRow = $oDataset->getRow();
if (! is_array( $aRow )) {
$this->deleteTmpfile();
}
return $aRow;
} catch (Exception $oError) {
throw ($oError);
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 13:22:53 -04:00
/**
* This function registers into globals variables
*
*
* @name registerGlobal
*
* @param string $name
* @param string $value
* @return void
*/
public function registerGlobal ($name, $value)
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$tmpfile_content = '';
if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$tmpfile_content = file_get_contents( $this->tmpfile );
}
//getting the global array
if ($tmpfile_content != '') {
$this->globals = unserialize( $tmpfile_content );
} else {
$this->globals = Array ();
}
//registering the new global variable
$this->globals[$name] = $value;
//saving the global array
$tmpfile_content = serialize( $this->globals );
file_put_contents( $this->tmpfile, $tmpfile_content );
2010-12-02 23:34:41 +00:00
}
2012-10-09 13:22:53 -04:00
/**
* This function gets a global variable
*
*
* @name getGlobal
*
* @param string $name
* @return string
*/
public function getGlobal ($name)
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$tmpfile_content = '';
if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$tmpfile_content = file_get_contents( $this->tmpfile );
}
//getting the global array
if ($tmpfile_content != '') {
$this->globals = unserialize( $tmpfile_content );
} else {
$this->globals = Array ();
}
//getting the new global variable
if (isset( $this->globals[$name] )) {
return $this->globals[$name];
} else {
return '';
}
2010-12-02 23:34:41 +00:00
}
2012-10-09 13:22:53 -04:00
/**
* This function gets all globals variables
*
*
* @name getGlobals
*
* @param string $name
* @return array
*/
public function getGlobals ()
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$tmpfile_content = '';
if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$tmpfile_content = file_get_contents( $this->tmpfile );
}
//getting the global array
if ($tmpfile_content != '') {
$this->globals = unserialize( $tmpfile_content );
} else {
$this->globals = Array ();
}
return $this->globals;
}
/**
* This function removes a temporal file
*
*
* @name deleteTmpfile
*
* param
* @return void
*/
private function deleteTmpfile ()
{
if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
@unlink( $this->tmpfile );
}
2010-12-02 23:34:41 +00:00
}