6 * - base application setup (variables etc to javascript)
8 * - authentication and permission info about user / application
9 * - json output methods.
10 * - file upload error checking - checkFileUploadError
11 * - logging to event table
12 * - sendTemplate code (normally use the Person version for sending to specific people..)
14 * - doc managment code?? - remarks and tracking??? - MOVEME
15 * - authentication link checking?? MOVEME?
16 * - authentication reset password ?? MOVEME?
17 * ?? arrayClean.. what's it doing here?!? ;)
21 * Pman['local_autoauth'] // who to login as when using localhost
22 * Pman['isDev'] // can the site show develpment info.?
23 * Pman['uiConfig'] // extra variable to export to front end..
24 * Pman['auth_comptype'] // -- if set to 'OWNER' then only users with company=OWNER can log in
25 * Pman['authTable'] // the authentication table (default 'person')
29 * DB_DataObject*:*toEventString (for logging - this is generically prefixed to all database operations.)
30 * - any data object where this method exists, the result will get prefixed to the log remarks
36 require_once 'Pman/Core/AssetTrait.php';
38 class Pman extends HTML_FlexyFramework_Page
40 use Pman_Core_AssetTrait;
41 //outputJavascriptDir()
46 var $appShortName= "";
47 var $appVersion = "1.8";
54 var $appDisabled = array(); // array of disabled modules..
55 // (based on config option disable)
57 var $authUser; // always contains the authenticated user..
59 var $disable_jstemplate = false; /// disable inclusion of jstemplate code..
62 var $css_path = ''; // can inject a specific path into the base HTML page.
65 var $transObj = false; // used to rollback or commit in JOK/JERR
67 // these are used somewhere -
68 var $builderJs = false;//
69 var $serverName = false;
71 var $allowSignup = false;
78 * ------------- Standard getAuth/get/post methods of framework.
83 function getAuth() // everyone allowed in!!!!!
85 $this->loadOwnerCompany();
90 function init($base = false)
93 if (isset($this->_hasInit)) {
96 $this->_hasInit = true;
97 // move away from doing this ... you can access bootLoader.XXXXXX in the master template..
98 $boot = HTML_FlexyFramework::get();
99 // echo'<PRE>';print_R($boot);exit;
100 $this->appName = $boot->appName;
102 $this->appNameShort = $boot->appNameShort;
104 $this->appModules = $boot->enable;
106 // echo $this->arrayToJsInclude($files);
107 $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
109 $this->css_path = empty($boot->Pman['css_path']) ? '' : $boot->Pman['css_path'];
111 $this->appDisable = $boot->disable;
112 $this->appDisabled = explode(',', $boot->disable);
113 $this->version = $boot->version;
114 $this->appVersion = $boot->version;
115 $this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig'];
117 if (!empty($boot->Pman['local_autoauth']) &&
118 !empty($_SERVER['SERVER_ADDR']) &&
119 !empty($_SERVER['REMOTE_ADDR']) &&
120 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
121 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
127 !empty($_REQUEST['isDev'])
131 !empty($_SERVER['SERVER_ADDR']) &&
133 (($_SERVER['SERVER_ADDR'] == '127.0.0.1') && ($_SERVER['REMOTE_ADDR'] == '127.0.0.1'))
135 (($_SERVER['SERVER_ADDR'] == '::1') && ($_SERVER['REMOTE_ADDR'] == '::1'))
137 (preg_match('/^192\.168/', $_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] == $_SERVER['HTTP_HOST'])
141 !empty($boot->Pman['enable_isdev_url'])
145 $boot->Pman['isDev'] = true;
149 // if a file Pman_{module}_Pman exists.. and it has an init function... - call that..
151 //var_dump($this->appModules);
157 * call a method on {module}/Pman.php
158 * * initially used on the main page load to call init();
159 * * also used for ccsIncludes??
161 * // usage: $this->callModules('init', $base)
165 function callModules($fn)
167 $args = func_get_args();
169 foreach(explode(',',$this->appModules) as $m) {
170 $cls = 'Pman_'. $m . '_Pman';
171 if (!file_exists($this->rootDir . '/'.str_replace('_','/', $cls). '.php')) {
174 require_once str_replace('_','/', $cls). '.php';
176 if (method_exists($c, $fn)) {
177 call_user_func_array(array($c,$fn),$args);
183 function get($base, $opts=array())
187 $this->callModules('init', $this, $base);
190 //$this->allowSignup= empty($opts['allowSignup']) ? 0 : 1;
191 $bits = explode('/', $base);
194 // should really be moved to Login...
196 if ($bits[0] == 'PasswordReset') {
197 $this->linkFail = $this->resetPassword(@$bits[1],@$bits[2],@$bits[3]);
198 header('Content-type: text/html; charset=utf-8');
203 $au = $this->getAuthUser();
205 $ff= HTML_FlexyFramework::get();
207 if (!empty($ff->Pman['auth_comptype']) && $au->id > 0 &&
208 ( !$au->company_id || ($ff->Pman['auth_comptype'] != $au->company()->comptype))) {
212 $this->jerr("Login not permited to outside companies - please reload");
214 $this->addEvent("RELOAD");
218 if (strlen($base) && $bits[0] != 'PasswordReset') {
219 $this->jerror("NOTICE-BADURL","invalid url: $base");
222 if (isset($_GET['onloadTrack'])) {
223 $this->onloadTrack = (int)$_GET['onloadTrack'];
225 // getting this to work with xhtml is a nightmare
226 // = nbsp / <img> issues screw everyting up.
227 //var_dump($this->isDev);
228 // force regeneration on load for development enviroments..
230 HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev && !empty($_REQUEST['isDev']));
232 //header('Content-type: application/xhtml+xml; charset=utf-8');
236 if ($this->company && $this->company->logo_id) {
237 $im = DB_DataObject::Factory('Images');
238 $im->get($this->company->logo_id);
239 $this->appLogo = $this->baseURL . '/Images/Thumb/x100/'. $this->company->logo_id .'/' . $im->filename;
242 header('Content-type: text/html; charset=utf-8');
245 function post($base) {
246 return $this->get($base);
250 // --------------- AUTHENTICATION or system information
253 * finds the compay with comptype=='OWNER'
254 * ?? what about comptype_id-name ?????
256 * @return {Pman_Core_DataObjects_Companies} the owner company
258 function loadOwnerCompany()
260 // only applies if authtable is person..
261 $ff = HTML_FlexyFramework::get();
262 if (!empty($ff->Pman['authTable']) && !in_array($ff->Pman['authTable'] , [ 'core_person', 'Person' ])) {
266 $this->company = DB_DataObject::Factory('core_company');
267 if (!is_a($this->company, 'DB_DataObject')) { // non-core pman projects
270 $e = DB_DataObject::Factory('core_enum')->lookupObject('COMPTYPE', 'OWNER');
272 $this->company->get('comptype_id', $e->id);
273 return $this->company;
277 static function staticGetAuthUser($t) {
278 if (!empty($t->authUser)) {
281 $ff = HTML_FlexyFramework::get();
282 $tbl = empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
284 $u = DB_DataObject::factory( $tbl );
286 if (is_a($u,'PEAR_Error') || !$u->isAuth()) {
289 $t->authUser =$u->getAuthUser();
290 return $t->authUser ;
295 * getAuthUser: - get the authenticated user..
297 * @return {DB_DataObject} of type Pman[authTable] if authenticated.
300 function getAuthUser()
302 return self::staticGetAuthUser($this);
306 * wrapper arround authuser->hasPerm
307 * @see Pman_Core_DataObject_Core_person::hasPerm
309 * @param {String} $name The permission name (eg. Projects.List)
310 * @param {String} $lvl eg. (C)reate (E)dit (D)elete ... etc.
313 function hasPerm($name, $lvl) // do we have a permission
315 static $pcache = array();
316 $au = $this->getAuthUser();
317 return $au && $au->hasPerm($name,$lvl);
321 * modulesList: List the modules in the application
323 * @return {Array} list of modules
325 function modulesList()
327 $boot = HTML_FlexyFramework::get();
328 // echo'<PRE>';print_R($boot);exit;
331 $mods = explode(',', $boot->enable);
332 if (in_array('Core',$mods)) { // core has to be the first modules loaded as it contains Pman.js
333 array_unshift($mods, 'Core');
336 if (in_array($boot->appNameShort,$mods)) { // Project has to be the last modules loaded as it contains Pman.js
337 unset($mods[array_search($boot->appNameShort, $mods)]);
338 $mods[] = $boot->appNameShort;
341 $mods = array_unique($mods);
343 $disabled = explode(',', $boot->disable ? $boot->disable : '');
345 foreach($mods as $mod) {
346 // add the css file..
347 if (in_array($mod, $disabled)) {
358 function hasModule($name)
361 if (!strpos( $name,'.') ) {
362 // use enable / disable..
363 return in_array($name, $this->modules());
366 $x = DB_DataObject::factory('core_group_right');
367 $ar = $x->defaultPermData();
368 if (empty($ar[$name]) || empty($ar[$name][0])) {
376 function jsencode($v, $header = false)
379 header("Content-type: text/javascript");
381 if (function_exists("json_encode")) {
382 $ret= json_encode($v);
383 if ($ret !== false) {
387 require_once 'Services/JSON.php';
388 $js = new Services_JSON();
389 return $js->encodeUnsafe($v);
398 * ---------------- Global Tools ---------------
400 function checkFileUploadError() // check for file upload errors.
403 empty($_FILES['File'])
404 || empty($_FILES['File']['name'])
405 || empty($_FILES['File']['tmp_name'])
406 || empty($_FILES['File']['type'])
407 || !empty($_FILES['File']['error'])
408 || empty($_FILES['File']['size'])
410 $this->jerr("File upload error: <PRE>" . print_r($_FILES,true) . print_r($_POST,true) . "</PRE>");
414 static $deleteOnExit = false;
416 * generate a tempory file with an extension (dont forget to delete it)
419 function deleteOnExitAdd($name)
421 if (self::$deleteOnExit === false) {
422 register_shutdown_function(array('Pman','deleteOnExit'));
423 self::$deleteOnExit = array();
425 self::$deleteOnExit[] = $name;
428 function tempName($ext, $deleteOnExit=false)
431 $x = tempnam(ini_get('session.save_path'), HTML_FlexyFramework::get()->appNameShort.'TMP');
433 $ret = $x .'.'. $ext;
435 $this->deleteOnExitAdd($ret);
441 static function deleteOnExit()
444 foreach(self::$deleteOnExit as $fn) {
445 if (file_exists($fn)) {
452 * ------------- Authentication password reset ------ ??? MOVEME?
460 * jerrAuth: standard auth failure - with data that let's the UI know..
464 $au = $this->authUser;
466 // is it an authfailure?
467 $this->jerror("LOGIN-NOPERM", "Permission denied to view this resource", array('authFailure' => true));
469 $this->jerror("LOGIN-NOAUTH", "Not authenticated", array('authFailure' => true));
475 * ---------------- Standard JSON outputers. - used everywhere
478 * ---------------- Standard JSON outputers. - used everywhere
479 * JSON error - simple error with logging.
483 function jerr($str, $errors=array(), $content_type = false) // standard error reporting..
485 return $this->jerror('ERROR', $str,$errors,$content_type);
488 * Recomended JSON error indicator
491 * @param string $type - normally 'ERROR' - you can use this to track error types.
492 * @param string $message - error message displayed to user.
493 * @param array $errors - optioanl data to pass to front end.
494 * @param string $content_type - use text/plain to return plan text - ?? not sure why...
498 function jerror($type, $str, $errors=array(), $content_type = false) // standard error reporting..
500 if ($this->transObj) {
501 $this->transObj->query('ROLLBACK');
504 $cli = HTML_FlexyFramework::get()->cli;
506 echo "ERROR: " .$str . "\n"; // print the error first, as DB might fail..
508 $pman = HTML_FlexyFramework::get();
514 if ($type !== false && empty($pman->nodatabase)) {
517 DB_DataObject::factory('Events')->writeEventLogExtra($errors);
519 // various codes that are acceptable.
521 if (!preg_match('/^(ERROR|NOTICE|LOG)/', $type )) {
522 $type = 'ERROR-' . $type;
525 $this->addEvent($type, false, $str);
529 $cli = HTML_FlexyFramework::get()->cli;
531 exit(1); // cli --- exit code to stop shell execution if necessary.
535 if ($content_type == 'text/plain') {
536 header('Content-Disposition: attachment; filename="error.txt"');
537 header('Content-type: '. $content_type);
538 echo "ERROR: " .$str . "\n";
544 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
545 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
548 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
552 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
557 header('Content-type: text/html');
558 echo "<HTML><HEAD></HEAD><BODY>";
559 echo $this->jsencode(array(
562 'message' => $str, // compate with exeption / loadexception.
564 'errors' => $errors ? $errors : true, // used by forms to flag errors.
565 'authFailure' => !empty($errors['authFailure']),
567 echo "</BODY></HTML>";
571 if (isset($_REQUEST['_debug'])) {
572 echo '<PRE>'.htmlspecialchars(print_r(array(
576 'message' => $str, // compate with exeption / loadexception.
577 'errors' => $errors ? $errors : true, // used by forms to flag errors.
578 'authFailure' => !empty($errors['authFailure']),
584 echo $this->jsencode(array(
589 'message' => $str, // compate with exeption / loadexception.
590 'errors' => $errors ? $errors : true, // used by forms to flag errors.
591 'authFailure' => !empty($errors['authFailure']),
600 if ($this->transObj ) {
601 $this->transObj->query( connection_aborted() ? 'ROLLBACK' : 'COMMIT');
604 $cli = HTML_FlexyFramework::get()->cli;
606 echo "OK: " .$str . "\n";
610 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
611 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
614 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
618 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
622 header('Content-type: text/html');
623 echo "<HTML><HEAD></HEAD><BODY>";
624 // encode html characters so they can be read..
625 echo str_replace(array('<','>'), array('\u003c','\u003e'),
626 $this->jsencode(array('success'=> true, 'data' => $str), false));
627 echo "</BODY></HTML>";
632 echo $this->jsencode(array('success'=> true, 'data' => $str),true);
638 * output data for grids or tree
639 * @ar {Array} ar Array of data
640 * @total {Number|false} total number of records (or false to return count(ar)
641 * @extra {Array} extra key value list of data to pass as extra data.
644 function jdata($ar,$total=false, $extra=array(), $cachekey = false)
646 // should do mobile checking???
647 if ($total == false) {
650 $extra= $extra ? $extra : array();
653 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
654 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
657 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
661 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
666 header('Content-type: text/html');
667 echo "<HTML><HEAD></HEAD><BODY><![CDATA[";
668 // encode html characters so they can be read..
669 echo str_replace(array('<','>'), array('\u003c','\u003e'),
670 $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra, false));
671 echo "]]></BODY></HTML>";
676 // see if trimming will help...
677 if (!empty($_REQUEST['_pman_short'])) {
680 foreach($ar as $as) {
682 foreach($as as $k=>$v) {
683 if (is_string($v) && !strlen(trim($v))) {
695 $ret = $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra,true);
697 if (!empty($cachekey)) {
699 $fn = ini_get('session.save_path') . '/json-cache'.date('/Y/m/d').'.'. $cachekey . '.cache.json';
700 if (!file_exists(dirname($fn))) {
701 mkdir(dirname($fn), 0777,true);
703 file_put_contents($fn, $ret);
712 /** a daily cache **/
713 function jdataCache($cachekey)
715 $fn = ini_get('session.save_path') . '/json-cache'.date('/Y/m/d').'.'. $cachekey . '.cache.json';
716 if (file_exists($fn)) {
717 header('Content-type: application/json');
718 echo file_get_contents($fn);
728 * ---------------- OUTPUT
730 function hasBg($fn) // used on front page to check if logos exist..
732 return file_exists($this->rootDir.'/Pman/'.$this->appNameShort.'/templates/images/'. $fn);
735 * outputJavascriptIncludes:
737 * output <script....> for all the modules in the applcaiton
740 function outputJavascriptIncludes()
742 // BC support - currently 1 project still relies on this.. (MO portal)
743 $ff = HTML_FlexyFramework::get();
744 $o = isset($ff->Pman_Core) ? $ff->Pman_Core : array();
745 if (isset($o['packseed'])) {
746 return $this->outputJavascriptIncludesBC();
750 $mods = $this->modulesList();
753 $is_bootstrap = in_array('BAdmin', $mods);
755 foreach($mods as $mod) {
756 // add the css file..
759 if (!file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
760 echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
766 $this->outputJavascriptDir("Pman/$mod/widgets", "*.js");
767 $this->outputJavascriptDir("Pman/$mod", "*.js");
771 if (empty($this->disable_jstemplate)) {
772 // and finally the JsTemplate...
773 echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
776 $this->callModules('outputJavascriptIncludes', $this);
779 var $css_includes = array();
783 * output <link rel=stylesheet......> for all the modules in the applcaiton
786 * This could css minify as well.
788 function outputCSSIncludes() // includes on CSS links.
792 $mods = $this->modulesList();
793 $is_bootstrap = in_array('BAdmin', $mods);
795 $this->callModules('applyCSSIncludes', $this);
796 foreach($this->css_includes as $module => $ar) {
799 $this->assetArrayToHtml( $ar , 'css');
803 // old style... - probably remove this...
804 $this->callModules('outputCSSIncludes', $this);
806 foreach($mods as $mod) {
807 // add the css file..
808 if ($is_bootstrap && !file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
809 echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
812 $this->outputCSSDir("Pman/$mod","*.css");
814 $this->outputSCSS($mod);
818 return ''; // needs to return something as we output it..
831 // --- OLD CODE - in for BC on MO project.... - needs removing...
833 // used on old versions.....
834 function outputJavascriptIncludesBC()
837 $mods = $this->modulesList();
839 foreach($mods as $mod) {
840 // add the css file..
843 $files = $this->moduleJavascriptList($mod.'/widgets');
844 foreach($files as $f) {
845 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
848 $files = $this->moduleJavascriptList($mod);
849 foreach($files as $f) {
850 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
854 if (empty($this->disable_jstemplate)) {
855 // and finally the JsTemplate...
856 echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
861 * Gather infor for javascript files..
863 * @param {String} $mod the module to get info about.
864 * @return {StdClass} details about module.
866 function moduleJavascriptFilesInfo($mod)
869 static $cache = array();
871 if (isset($cache[$mod])) {
876 $ff = HTML_FlexyFramework::get();
878 $base = dirname($_SERVER['SCRIPT_FILENAME']);
879 $dir = $this->rootDir.'/Pman/'. $mod;
880 $path = $this->rootURL ."/Pman/$mod/";
882 $ar = glob($dir . '/*.js');
888 foreach($ar as $fn) {
890 // got the 'module file..'
891 $mtime = filemtime($dir . '/'. $f);
892 $maxtime = max($mtime, $maxtime);
893 $arfiles[$fn] = $mtime;
894 $files[] = $path . $f . '?ts='.$mtime;
897 ksort($arfiles); // just sort by name so it's consistant for serialize..
899 // The original idea of this was to serve the files direct from a publicly available 'cache' directory.
900 // but that doesnt really make sense - as we can just serve it from the session directory where we stick
901 // cached data anyway.
904 $compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
905 $basedir = $compile ? $ff->Pman['public_cache_dir'] : false;
906 $baseurl = $compile ? $ff->Pman['public_cache_url'] : false;
910 $basedir = session_save_path(). '/translate-cache/';
911 if (!file_exists($basedir)) {
912 mkdir($basedir,0755);
914 $baseurl = $this->baseURL . '/Admin/Translations';
916 if (PHP_VERSION_ID < 70000 ) {
917 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
918 usort($files, $lsort);
920 usort($files, function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; });
923 $smod = str_replace('/','.',$mod);
925 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
928 // why are translations done like this - we just build them on the fly frmo the database..
929 $tmtime = file_exists($this->rootDir.'/_translations_/'. $smod.'.js')
930 ? filemtime($this->rootDir.'/_translations_/'. $smod.'.js') : 0;
932 $cache[$mod] = (object) array(
933 'smod' => $smod, // module name without '/'
934 'files' => $files, // list of all files.
935 'filesmtime' => $arfiles, // map of mtime=>file
936 'maxtime' => $maxtime, // max mtime
937 'compile' => $this->isDev ? false : $compile,
938 'translation_file' => $base .'/_translations_/' . $smod . '.js',
939 'translation_mtime' => $tmtime,
941 'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
942 'translation_base' => $dir .'/', //prefix of filename (without moudle name))
943 'basedir' => $basedir,
944 'baseurl' => $baseurl,
945 'module_dir' => $dir,
952 * moduleJavascriptList: list the javascript files in a module
954 * The original version of this.. still needs more thought...
956 * Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js
957 * Translations are in Pman/_translations_/{$mod}.js
959 * if that stuff does not exist just list files in Pman/{$mod}/*.js
961 * Compiled could be done on the fly..
965 * @param {String} $mod the module to look at - eg. Pman/{$mod}/*.js
966 * @return {Array} list of include paths (either compiled or raw)
972 function moduleJavascriptList($mod)
976 $dir = $this->rootDir.'/Pman/'. $mod;
979 if (!file_exists($dir)) {
980 echo '<!-- missing directory '. htmlspecialchars($dir) .' -->';
984 $info = $this->moduleJavascriptFilesInfo($mod);
988 if (empty($info->files)) {
991 // finally sort the files, so they are in the right order..
993 // only compile this stuff if public_cache is set..
997 // public_cache_dir = /var/www/myproject_cache
998 // public_cache_url = /myproject_cache (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
1001 if (!$info->compile) {
1002 echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n";
1003 return $info->files;
1006 // where are we going to write all of this..
1007 // This has to be done via a
1008 if (!file_exists($info->basedir.'/'.$info->output) || !filesize($info->basedir.'/'.$info->output)) {
1009 require_once 'Pman/Core/JsCompile.php';
1010 $x = new Pman_Core_JsCompile();
1012 $x->pack($info->filesmtime,$info->basedir.'/'.$info->output, $info->translation_base);
1014 echo "<!-- file exists not exist: {$info->basedir}/{$info->output} -->\n";
1017 if (file_exists($info->basedir.'/'.$info->output) &&
1018 filesize($info->basedir.'/'.$info->output)) {
1021 $info->baseurl.'/'. $info->output,
1024 // output all the ava
1025 // fixme - this needs the max datetime for the translation file..
1026 $ret[] = $this->baseURL."/Admin/InterfaceTranslations/".$mod.".js"; //?ts=".$info->translation_mtime;
1028 //if ($info->translation_mtime) {
1029 // $ret[] = $this->rootURL."/_translations_/". $info->smod.".js?ts=".$info->translation_mtime;
1036 // give up and output original files...
1039 return $info->files;
1046 * PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
1048 function initErrorHandling()
1050 if (!class_exists('HTML_FlexyFramework2')) {
1051 // what about older code that still users PEAR?
1052 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
1054 set_exception_handler(array($this,'onException'));
1059 static $permitError = false; // static why?
1061 var $showErrorToUser = true;
1063 function onPearError($err)
1065 return $this->onException($err);
1070 function onException($ex)
1072 static $reported = false;
1077 if (Pman::$permitError) {
1084 $out = is_a($ex,'Exception') || is_a($ex, 'Error') ? $ex->getMessage() : $ex->toString();
1087 //print_R($bt); exit;
1090 $bt = is_a($ex,'Exception')|| is_a($ex, 'Error') ? $ex->getTrace() : $ex->backtrace;
1091 if (is_a($ex,'Exception')|| is_a($ex, 'Error') ) {
1092 $ret[] = $ex->getFile() . '('. $ex->getLine() . ')';
1094 foreach( $bt as $b) {
1095 $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' . @$b['class'] . '::' . @$b['function'];
1101 //convert the huge backtrace into something that is readable..
1102 $out .= "\n" . implode("\n", $ret);
1104 $this->addEvent("EXCEPTION", false, $out);
1106 if ($this->showErrorToUser) {
1109 // not sure why this is here... - perhaps doing a jerr() was actually caught by the UI, and hidden from the user..?
1110 $this->jerror(false,"An error Occured, please contact the website owner");
1112 //$this->jerr($out);
1119 * ---------------- Logging ---------------
1124 * Log an action (only if it has not been logged already.
1126 * @param {String} action - group/name of event
1127 * @param {DataObject|false} obj - dataobject action occured on.
1128 * @param {String} any remarks
1129 * @return {false|DB_DataObject} Event object.,
1132 function addEventOnce($act, $obj = false, $remarks = '')
1134 if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
1137 $e = DB_DataObject::factory('Events');
1138 $e->init($act,$obj,$remarks);
1139 if ($e->find(true)) {
1142 return $this->addEvent($act, $obj, $remarks);
1148 * @param {String} action - group/name of event
1149 * @param {DataObject|false} obj - dataobject action occured on.
1150 * @param {String} any remarks
1151 * @return {DB_DataObject} Event object.,
1154 function addEvent($act, $obj = false, $remarks = '')
1157 $ff = HTML_FlexyFramework::get();
1160 if (!empty($ff->Pman['disable_events'])
1161 || !empty($ff->database_is_readonly)
1162 || substr($act, 0, 7) === 'NOTICE-'
1164 if (!preg_match('/^(ERROR|EXCEPTION)/', $act)) {
1167 $str = $obj !== false ? "{$obj->tableName()}:{$obj->id} " : '';
1168 $de = ini_set('display_errors', 0);
1169 trigger_error("{$act} {$str} {$remarks}" , E_USER_NOTICE);
1170 ini_set('display_errors', $de );
1174 $au = $this->getAuthUser();
1176 $e = DB_DataObject::factory('Events');
1177 $e->init($act,$obj,$remarks);
1179 $e->event_when = $e->sqlValue('NOW()');
1181 $eid = $e->insert();
1183 // fixme - this should be in onInsert..
1184 $wa = DB_DataObject::factory('core_watch');
1185 if (method_exists($wa,'notifyEvent')) {
1186 $wa->notifyEvent($e); // trigger any actions..
1190 $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
1191 if (!preg_match('/^(ERROR|EXCEPTION)/', $act)) {
1194 $str = $obj !== false ? "{$obj->tableName()}:{$obj->id} " : '';
1195 $de = ini_set('display_errors', 0);
1196 trigger_error("{$act} [event_id={$e->id}] {$str} {$remarks}" , E_USER_NOTICE);
1197 ini_set('display_errors', $de );
1203 function addEventNotifyOnly($act, $obj = false, $remarks = '')
1205 $au = $this->getAuthUser();
1207 $e = DB_DataObject::factory('Events');
1208 $e->init($act,$obj,$remarks);
1210 $e->event_when = $e->sqlValue('NOW()');
1211 $wa = DB_DataObject::factory('core_watch');
1212 if (method_exists($wa,'notifyEvent')) {
1213 $wa->notifyEvent($e); // trigger any actions..
1218 // ------------------ DEPERCIATED ----------------------------
1220 // DEPRECITAED - use moduleslist
1221 function modules() { return $this->modulesList(); }
1224 // DEPRICATED USE Pman_Core_Mailer
1226 function emailTemplate($templateFile, $args)
1229 require_once 'Pman/Core/Mailer.php';
1230 $r = new Pman_Core_Mailer(array(
1231 'template'=>$templateFile,
1232 'contents' => $args,
1235 return $r->toData();
1238 // DEPRICATED - USE Pman_Core_Mailer
1239 // WHAT Part about DEPRICATED Does no one understand??
1240 function sendTemplate($templateFile, $args)
1242 require_once 'Pman/Core/Mailer.php';
1243 $r = new Pman_Core_Mailer(array(
1244 'template'=>$templateFile,
1245 'contents' => array(),