<?php
/*
* Block Class
*
* Copyright (c) 2003-4 St. Christopher House
*
* Developed by The Working Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @version $Id: Cln_Process_Manager.php,v 1.30 2005/01/24 21:45:25 darcy Exp $
*
*/
class Cln_Process_Manager
{
/*
*
* Class Attributes: Cln_Process_Manager
*
* The attributes for this class are:
*
* TBD
*
*/
var $processStack;
var $processCount;
/*
*
* Function: Cln_Process_Manager()
*
* Class Constructor
*
* @access public
* @return TBD
*
*/
function Cln_Process_Manager()
{
$this->processStack = Array();
$this->processCount = 0;
}
/*
*
* Function: clearStack()
*
* Clears the stack completely
*
* @access public
* @return TBD
*
*/
function clearStack()
{
d('PM: clearStack',3);
$this->processStack = Array();
$this->processCount = 0;
}
/*
*
* Function: push()
*
* Pushes a new process onto the stack
*
* @access public
* @return TBD
*
*/
function push($passedProcess, $passedData = '')
{
d("PM: Pushing $passedProcess",3);
// If there's nothing on the stack, push it
if (empty($this->processStack)) {
d("PM: Nothing was on the stack, pushing $passedProcess",3);
$this->processCount = array_push($this->processStack,
Array('process' => $passedProcess,
'processData' => $passedData));
}
// Else, figure out what to do
else {
d('PM: Stack isn\'t empty',3);
$currentProcessNum = $this->processCount - 1;
$currentProcess = $this->processStack[$currentProcessNum]['process'];
$currentProcessData = $this->processStack[$currentProcessNum]['processData'];
$sameProcess = FALSE;
$sameProcessData = FALSE;
if ($currentProcess == $passedProcess) {
$sameProcess = TRUE;
}
if ($currentProcessData == $passedData) {
$sameProcessData = TRUE;
}
else if (is_array($passedData) && is_array($currentProcessData)) {
$match = TRUE;
foreach ($passedData as $key => $value) {
if (!array_key_exists($key, $currentProcessData)) {
$match = FALSE;
}
else if ($currentProcessData[$key] != $value) {
$match = FALSE;
}
}
$sameProcessData = $match;
if ($sameProcessData) {
}
}
// If nothing's the same, push it
if (!$sameProcess || ($sameProcess && !$sameProcessData)) {
d('PM: Not the same process, pushing it',3);
$this->processCount = array_push($this->processStack,
Array('process' => $passedProcess,
'processData' => $passedData));
}
// Else, do nothing, it's just a refresh or something
else {
d('PM: Same process, not pushing',3);
}
}
return TRUE;
}
/*
*
* Function: pop()
*
* Pops a process off the stak
*
* @access public
* @return TBD
*
*/
function pop()
{
d('PM: pop',3);
$returnVal = array_pop($this->processStack);
$this->processCount = count($this->processStack);
return $returnVal;
}
/*
*
* Function: popAndGoToNext()
*
* Pops the current process, and then goes to the next (now current)
* You can optionally pass this a path, and it will go to that path
*
* @access public
* @return TBD
*
*/
function popAndGoToNext($passedPath = FALSE)
{
d('PM: popAndGoToNext()',3);
$this->pop();
$this->goToCurrentProcess($passedPath);
}
/*
*
* Function: goToCurrentProcess()
*
* Forwards to the current process
*
* @access public
* @return TBD
*
*/
function goToCurrentProcess($passedPath = FALSE)
{
d('PM: goToCurrentProcess',3);
d('PM: current process is:',3);
d($_SESSION['ProcessManager'],3);
$currentProcess = $this->processCount - 1;
$data = $this->getCurrentData();
if ($data['koId'] == 'NEW') {
$queryString = 'editKoId=' . $data['koId'] . '&modId=' . $data['modId'] . '&parentId=' . $data['parentId'];
if (isset($data['passThruData'])) {
$queryString .= '&' . $data['passThruData'];
}
}
else {
$queryString = 'editKoId=' . $data['koId'];
}
// If they're pushing an edit process
if (isset($data['editProcess'])) {
$queryString .= '&editProcess=' . $data['editProcess'];
}
d("PM: queryString to go to is: $queryString",3);
if (!$passedPath) {
$processUrl = appendToURL(cleanURL($GLOBALS['path']), $queryString, TRUE);
}
else {
$processUrl = appendToURL(cleanURL($passedPath), $queryString, TRUE);
}
if (isset($data['queryAppend'])) {
d('Appending more stuff to the query string', 3);
$processUrl = $processUrl . '&' . $data['queryAppend'];
d("PM: now URL to go to is: $processUrl",3);
}
if (strPos($processUrl, 'http://') === 0) {
$go_to = $processUrl;
}
else {
$go_to = 'http://' . $_SERVER['HTTP_HOST'] . $processUrl;
}
d("PM: --> $go_to",3);
clnRedirect($go_to);
exit;
}
/*
*
* Function: appendData()
*
* Stores some data with the process
*
* @access public
* @return TBD
*
*/
function appendData($name, $data)
{
d("PM: appendData name {$name} data {$data}",3);
$currentProcess = $this->processCount -1;
$this->processStack[$currentProcess]['processData'][$name] = $data;
}
/*
*
* Function: getCurrentProcess()
*
* returns the current process
*
* @access public
* @return TBD
*
*/
function getCurrentProcess()
{
d('PM: getCurrentProcess',3);
$currentProcess = $this->processCount - 1;
return $this->processStack[$currentProcess]['process'];
}
/*
*
* Function: getCurrentData()
*
* Gets stored data from the process
*
* @access public
* @return TBD
*
*/
function getCurrentData($keyName = '')
{
d("PM: getCurrentData called for keyname $keyName",3);
$currentProcess = $this->processCount -1;
if (!empty($keyName) && isset($this->processStack[$currentProcess]['processData'][$keyName])) {
return $this->processStack[$currentProcess]['processData'][$keyName];
}
else if (empty($keyName)) {
return $this->processStack[$currentProcess]['processData'];
}
else {
return FALSE;
}
}
}
?>