first draft, only one (main) page

This commit is contained in:
2014-06-02 11:53:18 +02:00
parent c25d541a7d
commit 8be00a6c46
17 changed files with 1312 additions and 33 deletions

234
classmanagement.php Normal file
View File

@@ -0,0 +1,234 @@
<?php
/**
* Manage includes
* @author franzz
* @version 1.0
*/
class ClassManagement extends PhpObject
{
const INC_FOLDER = 'inc/';
const INC_EXT = '.php';
const SETTINGS_FILE = 'settings.php';
const TOOLBOX_CLASS = 'toolbox';
private $asIncFiles;
function __construct($sMainClass)
{
parent::__construct(__CLASS__, true);
$this->asIncFiles = array();
//try to include default files
$this->incFile(self::SETTINGS_FILE);
$this->incClass(self::TOOLBOX_CLASS);
//Include main class
$this->incClass($sMainClass);
}
function __destruct()
{
parent::__destruct();
}
public function incClass($sClassName)
{
return $this->incFile(self::INC_FOLDER.$sClassName.self::INC_EXT);
}
public function incFile($sFilePath, $bMandatory=true)
{
$bIncluded = false;
if(!in_array($sFilePath, $this->asIncFiles))
{
$sMissingFile = 'File "'.$sFilePath.'" missing.';
if(file_exists($sFilePath))
{
$bIncluded = require_once($sFilePath);
$this->asIncFiles[] = $sFilePath;
}
elseif($bMandatory)
{
die($sMissingFile.' Stopping process.');
}
else
{
$this->addError($sMissingFile);
}
}
return $bIncluded;
}
}
/**
*
* @author franzz
* @version 1.0a
*/
class PhpObject
{
//Log file name
const LOG_FILENAME = 'log.html';
//Message types
const NOTICE_TAB = 'Notice';
const WARNING_TAB = 'Warning';
const ERROR_TAB = 'Error';
const ALL_TAB = 'All';
//Extraction mode
const MODE_ARRAY = 0;
const MODE_TEXT = 1;
const MODE_HTML = 2;
const MODE_FILE = 3;
//Class variables
private $asMessageStack;
private $iExtractMode;
private $sChildClass;
protected $bDebug;
function __construct($sClass='', $bDebug=false, $iExtractMode=self::MODE_FILE)
{
$this->resetMessageStack();
$this->iExtractMode = $iExtractMode;
$this->sChildClass = $sClass;
$this->bDebug = $bDebug;
}
private static function getLogPath()
{
return dirname(__FILE__).'/'.self::LOG_FILENAME;
}
private function resetMessageStack($sType=self::ALL_TAB)
{
if($sType==self::ALL_TAB)
{
$this->resetMessageStack(self::NOTICE_TAB);
$this->resetMessageStack(self::WARNING_TAB);
$this->resetMessageStack(self::ERROR_TAB);
}
else
{
$this->asMessageStack[$sType] = array();
}
}
protected function addNotice($sNotice)
{
$this->addMessage(self::NOTICE_TAB, $sNotice);
}
protected function addWarning($sWarning)
{
$this->addMessage(self::WARNING_TAB, $sWarning);
}
protected function addError($sError)
{
$this->addMessage(self::ERROR_TAB, $sError);
}
private function addMessage($sType, $sMessage)
{
$this->asMessageStack[$sType][] = $sMessage;
}
protected function getCleanMessageStack($sType=self::ALL_TAB)
{
$asMessages = ($sType==self::ALL_TAB)?$this->asMessageStack:$this->asMessageStack[$sType];
$this->resetMessageStack($sType);
return $this->glueMessages($asMessages);
}
protected function cleanMessageStack()
{
$sErrorStack = $this->getCleanMessageStack($this->bDebug?self::ALL_TAB:self::ERROR_TAB);
if($sErrorStack!='')
{
switch($this->iExtractMode)
{
case self::MODE_TEXT:
echo $sErrorStack;
break;
case self::MODE_HTML:
echo $sErrorStack;
break;
case self::MODE_ARRAY:
break;
case self::MODE_FILE:
@file_put_contents(self::getLogPath(), "\n\n".$this->sChildClass.' - '.date('r')."\n".$sErrorStack, FILE_APPEND);
break;
}
}
}
protected function getCleanMessageStacks($aoExtsources, $sType=self::ALL_TAB)
{
$aoExtsources[] = $this;
$aoMessages = array();
foreach($aoExtsources as $oExtSource)
{
$oMessages = $oExtSource->getCleanMessageStack($sType);
if($oMessages!='')
{
$aoMessages[get_class($oExtSource)] = $oMessages;
}
}
return $this->glueMessages($aoMessages);
}
private function glueMessages($asMessages)
{
switch($this->iExtractMode)
{
case self::MODE_TEXT:
$oMessageStack = self::recursiveImplode("\n", $asMessages);
break;
case self::MODE_HTML:
$oMessageStack = self::recursiveImplode('<br />', $asMessages);
break;
case self::MODE_ARRAY:
$oMessageStack = $asMessages;
break;
case self::MODE_FILE:
$oMessageStack = self::recursiveImplode("\n", $asMessages);
break;
}
return $oMessageStack;
}
private static function flattenMessageStack($asTab, $sGlobalKey='')
{
$asFlatTab = array();
foreach($asTab as $oKey=>$oRow)
{
$sKey = is_numeric($oKey)?$sGlobalKey:$oKey.' - ';
if(is_array($oRow))
{
$asFlatTab = array_merge($asFlatTab, self::flattenMessageStack($oRow, $sKey));
}
else
{
$asFlatTab[] = $sKey.$oRow;
}
}
return $asFlatTab;
}
private static function recursiveImplode($sGlue, $asTab)
{
$asTab = self::flattenMessageStack($asTab);
return implode($sGlue, $asTab);
}
function __destruct()
{
$this->cleanMessageStack();
}
}
?>