class Pman extends HTML_FlexyFramework_Page
{
var $appName= "";
+ var $appLogo= "";
var $appShortName= "";
var $appVersion = "1.8";
var $version = 'dev';
// echo'<PRE>';print_R($boot);exit;
$this->appName= $boot->appName;
$this->appNameShort= $boot->appNameShort;
+
+
$this->appModules= $boot->enable;
$this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
$this->appDisable = $boot->disable;
$this->isDev = true;
}
+
+
+
}
function get($base)
HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
//header('Content-type: application/xhtml+xml; charset=utf-8');
+
+
+
+ if ($this->company->logo_id) {
+ $im = DB_DataObject::Factory('Images');
+ $im->get($this->company->logo_id);
+ $this->appLogo = $this->baseURL . '/Images/Thumb/400x100/'. $this->company->logo_id .'/' . $im->filename;
+ }
+
header('Content-type: text/html; charset=utf-8');
}
return $this->get($base);
}
+
+ // --------------- AUTHENTICATION or system information
/**
- * ------------- Authentication and permission info about logged in user!!!
- *
- *
+ * loadOwnerCompany:
+ * finds the compay with comptype=='OWNER'
+ *
+ * @return {Pman_Core_DataObjects_Companies} the owner company
*/
-
function loadOwnerCompany()
{
+
$this->company = DB_DataObject::Factory('Companies');
- if ($this->company) { // non-core pman projects
- return;
+ if (!is_a($this->company, 'DB_DataObject')) { // non-core pman projects
+ return false;
}
$this->company->get('comptype', 'OWNER');
-
- }
- function staticGetAuthUser()
- {
- $ff = HTML_FlexyFramework::get();
- $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
-
- $u = DB_DataObject::factory($tbl);
- if (!$u->isAuth()) {
- return false;
- }
- return $u->getAuthUser();
+ return $this->company;
}
+
+
+
+ /**
+ * getAuthUser: - get the authenticated user..
+ *
+ * @return {DB_DataObject} of type Pman[authTable] if authenticated.
+ */
+
function getAuthUser()
{
if (!empty($this->authUser)) {
$this->authUser =$u->getAuthUser();
return $this->authUser ;
}
+ /**
+ * hasPerm:
+ * wrapper arround authuser->hasPerm
+ * @see Pman_Core_DataObjects_User::hasPerm
+ *
+ * @param {String} $name The permission name (eg. Projects.List)
+ * @param {String} $lvl eg. (C)reate (E)dit (D)elete ... etc.
+ *
+ */
function hasPerm($name, $lvl) // do we have a permission
{
static $pcache = array();
$au = $this->getAuthUser();
- return $au->hasPerm($name,$lvl);
+ return $au && $au->hasPerm($name,$lvl);
}
-
- function modules()
+
+ /**
+ * modulesList: List the modules in the application
+ *
+ * @return {Array} list of modules
+ */
+ function modulesList()
{
- // appModules/appDisable contain a comma limited list of
- // both modules and components that can be enabled/disabled..
- $boot = HTML_FlexyFramework::get();
-
- // the modules call just lists the modules
- $enabled = array('Core' => true);
- $am = !empty($boot->enable) ? explode(',', $boot->enable) : array();
- foreach($am as $k) {
- if (strpos( $k ,'.') ) {
- continue;
- }
- $enabled[$k] = true;
- }
+ $this->init();
+ $mods = explode(',', $this->appModules);
+ if (in_array('Core',$mods)) { // core has to be the first modules loaded as it contains Pman.js
+ array_unshift($mods, 'Core');
+ }
- $disabled = !empty($boot->disable) ? explode(',', $boot->disable) : array();
- foreach($disabled as $k) {
- if ( strpos( $k ,'.') ) {
+ $mods = array_unique($mods);
+
+ $disabled = explode(',', $this->appDisable ? $this->appDisable: '');
+ $ret = array();
+ foreach($mods as $mod) {
+ // add the css file..
+ if (in_array($mod, $disabled)) {
continue;
}
- if (isset($enabled[$k])) {
- unset($enabled[$k]);
- }
+ $ret[] = $mod;
}
- //echo '<PRE>'; var_Dump($enabled);
-
- return array_keys($enabled);
+ return $ret;
}
+
+
+
function hasModule($name)
{
$this->init();
return true;
}
+
*/
function jerrAuth()
{
+ $au = $this->authUser();
+ if ($au) {
+ // is it an authfailure?
+ $this->jerr("Permission denied to view this resource", array('authFailure' => true));
+ }
$this->jerr("Not authenticated", array('authFailure' => true));
}
+
+
/**
* ---------------- Standard JSON outputers. - used everywhere
*/
- /**
- * modulesList: List the modules in the application
- *
- * @return {Array} list of modules
- */
- function modulesList()
- {
- $mods = explode(',', $this->appModules);
- if (in_array('Core',$mods)) { // core has to be the first modules loaded as it contains Pman.js
- array_unshift($mods, 'Core');
- }
-
- $mods = array_unique($mods);
-
- $disabled = explode(',', $this->appDisable ? $this->appDisable: '');
- $ret = array();
- foreach($mods as $mod) {
- // add the css file..
- if (in_array($mod, $disabled)) {
- continue;
- }
- $ret[] = $mod;
- }
- return $ret;
- }
-
/**
- * ---------------- Page output?!?!?
+ * ---------------- OUTPUT
*/
function hasBg($fn) // used on front page to check if logos exist..
{
foreach($mods as $mod) {
// add the css file..
- if (in_array($mod, $disabled)) {
- continue;
- }
-
+
$files = $this->moduleJavascriptList($mod.'/widgets');
- foreach($files as $f) {
+ foreach($files as $f) {
echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
}
*/
function moduleJavascriptFilesInfo($mod)
{
+
+ static $cache = array();
+
+ if (isset($cache[$mod])) {
+ return $cache[$mod];
+ }
+
+
$ff = HTML_FlexyFramework::get();
$base = dirname($_SERVER['SCRIPT_FILENAME']);
$dir = $this->rootDir.'/Pman/'. $mod;
-
+ $path = $this->rootURL ."/Pman/$mod/";
$ar = glob($dir . '/*.js');
$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
usort($files, $lsort);
- $output = date('Y-m-d-H-i-s-', $maxtime). str_replace('/','.',$mod).'-'.md5(serialize($arfiles)) .'.js';
-
- return (object) array(
- 'files' => $files,
- 'filesmtime' => $arfiles,
- 'maxtime' => $maxtime,
- 'compile' => $compile,
- 'translation_file' => realpath($base .'/_translations_/' . str_replace('/','.', $mod) . '.js'),
- 'output' => $output,
- 'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
- 'translation_base' => dirname($dir) . '/',
- 'basedir' => $basedir,
- 'baseurl' => $baseurl,
+ $smod = str_replace('/','.',$mod);
+
+ $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
+
+ $tmtime = file_exists($this->rootDir.'/_translations_/'. $smod.'.js')
+ ? filemtime($this->rootDir.'/_translations_/'. $smod.'.js') : 0;
+
+ $cache[$mod] = (object) array(
+ 'smod' => $smod, // module name without '/'
+ 'files' => $files, // list of all files.
+ 'filesmtime' => $arfiles, // map of mtime=>file
+ 'maxtime' => $maxtime, // max mtime
+ 'compile' => $this->isDev ? false : $compile,
+ 'translation_file' => $base .'/_translations_/' . $smod . '.js',
+ 'translation_mtime' => $tmtime,
+ 'output' => $output,
+ 'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
+ 'translation_base' => $dir .'/', //prefix of filename (without moudle name))
+ 'basedir' => $basedir,
+ 'baseurl' => $baseurl,
+ 'module_dir' => $dir,
);
+ return $cache[$mod];
}
-
-
-
+
/**
* moduleJavascriptList: list the javascript files in a module
$dir = $this->rootDir.'/Pman/'. $mod;
+
+
if (!file_exists($dir)) {
+ echo '<!-- missing directory '. htmlspecialchars($dir) .' -->';
return array();
}
$info = $this->moduleJavascriptFilesInfo($mod);
-
+
if (empty($info->files)) {
// only compile this stuff if public_cache is set..
- $compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
-
+
// suggestions...
// public_cache_dir = /var/www/myproject_cache
// public_cache_url = /myproject_cache (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
-
-
+
+ // bit of debugging
+ if (!$info->compile) {
+ echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n";
+ return $info->files;
+ }
// where are we going to write all of this..
// This has to be done via a
- if ( $info->compile && !file_exists($info->basedir.'/'.$info->output)) {
+ if (!file_exists($info->basedir.'/'.$info->output)) {
require_once 'Pman/Core/JsCompile.php';
$x = new Pman_Core_JsCompile();
$x->pack($info->filesmtime,$info->basedir.'/'.$info->output, $info->translation_base);
}
- if ($info->compile && file_exists($info->basedir.'/'.$info->output) && filesize($info->basedir.'/'.$info->output)) {
+ if (file_exists($info->basedir.'/'.$info->output) &&
+ filesize($info->basedir.'/'.$info->output)) {
- return array(
+ $ret =array(
$info->baseurl.'/'. $info->output,
- $this->rootURL."/_translations_/". str_replace('/','.', $mod).".js"
+
);
+ if ($info->translation_mtime) {
+ $ret[] = $this->rootURL."/_translations_/". $info->smod.".js?ts=".$info->translation_mtime;
+ }
+ return $ret;
}
// give up and output original files...
- return $files;
+ return $info->files;
}
*
* @param {String} action - group/name of event
* @param {DataObject|false} obj - dataobject action occured on.
- * @param {String} any remarks
+ * @param {String} any remarks
+ * @return {false|DB_DataObject} Event object.,
*/
function addEventOnce($act, $obj = false, $remarks = '')
{
- $au = $this->getAuthUser();
+
$e = DB_DataObject::factory('Events');
$e->init($act,$obj,$remarks);
if ($e->find(true)) {
- return;
+ return false;
}
return $this->addEvent($act, $obj, $remarks);
}
* @param {String} action - group/name of event
* @param {DataObject|false} obj - dataobject action occured on.
* @param {String} any remarks
- * @return {Number} Event id.,
+ * @return {DB_DataObject} Event object.,
*/
function addEvent($act, $obj = false, $remarks = '')
{
$au = $this->getAuthUser();
+
$e = DB_DataObject::factory('Events');
$e->init($act,$obj,$remarks);
$e->event_when = date('Y-m-d H:i:s');
$eid = $e->insert();
+
+ $wa = DB_DataObject::factory('core_watch');
+ $wa->notifyEvent($e); // trigger any actions..
+
+
$ff = HTML_FlexyFramework::get();
if (empty($ff->Pman['event_log_dir'])) {
- return $eid;
+ return $e;
}
$file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
if (!file_exists(dirname($file))) {
'GET' => empty($_GET) ? array() : $_GET,
'POST' => empty($_POST) ? array() : $_POST,
), true));
+
+ return $e;
- return $eid;
+ }
+ // ------------------ DEPERCIATED ---
+
+ function modules() // DEPRECITAED
+ {
+ return $this->modulesList();
+ }
+ function staticGetAuthUser() // DEPRECIATED..
+ {
+
+ $x = new Pman();
+ return $x->getAuthUser();
}
-
-
}