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;
74 * ------------- Standard getAuth/get/post methods of framework.
79 function getAuth() // everyone allowed in!!!!!
81 $this->loadOwnerCompany();
86 function init($base = false)
89 if (isset($this->_hasInit)) {
92 $this->_hasInit = true;
93 // move away from doing this ... you can access bootLoader.XXXXXX in the master template..
94 $boot = HTML_FlexyFramework::get();
95 // echo'<PRE>';print_R($boot);exit;
96 $this->appName = $boot->appName;
98 $this->appNameShort = $boot->appNameShort;
100 $this->appModules = $boot->enable;
102 // echo $this->arrayToJsInclude($files);
103 $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
105 $this->css_path = empty($boot->Pman['css_path']) ? '' : $boot->Pman['css_path'];
107 $this->appDisable = $boot->disable;
108 $this->appDisabled = explode(',', $boot->disable);
109 $this->version = $boot->version;
110 $this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig'];
112 if (!empty($boot->Pman['local_autoauth']) &&
113 !empty($_SERVER['SERVER_ADDR']) &&
114 !empty($_SERVER['REMOTE_ADDR']) &&
115 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
116 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
122 !empty($_REQUEST['isDev'])
126 !empty($_SERVER['SERVER_ADDR']) &&
128 (($_SERVER['SERVER_ADDR'] == '127.0.0.1') && ($_SERVER['REMOTE_ADDR'] == '127.0.0.1'))
130 (($_SERVER['SERVER_ADDR'] == '::1') && ($_SERVER['REMOTE_ADDR'] == '::1'))
134 !empty($boot->Pman['enable_isdev_url'])
138 $boot->Pman['isDev'] = true;
142 // if a file Pman_{module}_Pman exists.. and it has an init function... - call that..
144 //var_dump($this->appModules);
150 * call a method on {module}/Pman.php
151 * * initially used on the main page load to call init();
152 * * also used for ccsIncludes??
154 * // usage: $this->callModules('init', $base)
158 function callModules($fn)
160 $args = func_get_args();
162 foreach(explode(',',$this->appModules) as $m) {
163 $cls = 'Pman_'. $m . '_Pman';
164 if (!file_exists($this->rootDir . '/'.str_replace('_','/', $cls). '.php')) {
167 require_once str_replace('_','/', $cls). '.php';
169 if (method_exists($c, $fn)) {
170 call_user_func_array(array($c,$fn),$args);
176 function get($base, $opts=array())
180 $this->callModules('init', $this, $base);
183 //$this->allowSignup= empty($opts['allowSignup']) ? 0 : 1;
184 $bits = explode('/', $base);
187 // should really be moved to Login...
189 if ($bits[0] == 'PasswordReset') {
190 $this->linkFail = $this->resetPassword(@$bits[1],@$bits[2],@$bits[3]);
191 header('Content-type: text/html; charset=utf-8');
196 $au = $this->getAuthUser();
198 $ff= HTML_FlexyFramework::get();
200 if (!empty($ff->Pman['auth_comptype']) && $au->id > 0 &&
201 ( !$au->company_id || ($ff->Pman['auth_comptype'] != $au->company()->comptype))) {
205 $this->jerr("Login not permited to outside companies - please reload");
207 $this->addEvent("RELOAD");
211 if (strlen($base) && $bits[0] != 'PasswordReset') {
212 $this->jerror("BADURL","invalid url: $base");
215 if (isset($_GET['onloadTrack'])) {
216 $this->onloadTrack = (int)$_GET['onloadTrack'];
218 // getting this to work with xhtml is a nightmare
219 // = nbsp / <img> issues screw everyting up.
220 //var_dump($this->isDev);
221 // force regeneration on load for development enviroments..
223 HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev && !empty($_REQUEST['isDev']));
225 //header('Content-type: application/xhtml+xml; charset=utf-8');
229 if ($this->company && $this->company->logo_id) {
230 $im = DB_DataObject::Factory('Images');
231 $im->get($this->company->logo_id);
232 $this->appLogo = $this->baseURL . '/Images/Thumb/x100/'. $this->company->logo_id .'/' . $im->filename;
235 header('Content-type: text/html; charset=utf-8');
238 function post($base) {
239 return $this->get($base);
243 // --------------- AUTHENTICATION or system information
246 * finds the compay with comptype=='OWNER'
247 * ?? what about comptype_id-name ?????
249 * @return {Pman_Core_DataObjects_Companies} the owner company
251 function loadOwnerCompany()
253 // only applies if authtable is person..
254 $ff = HTML_FlexyFramework::get();
255 if (!empty($ff->Pman['authTable']) && !in_array($ff->Pman['authTable'] , [ 'core_person', 'Person' ])) {
259 $this->company = DB_DataObject::Factory('core_company');
260 if (!is_a($this->company, 'DB_DataObject')) { // non-core pman projects
263 $e = DB_DataObject::Factory('core_enum')->lookupObject('COMPTYPE', 'OWNER');
265 $this->company->get('comptype_id', $e->id);
266 return $this->company;
270 static function staticGetAuthUser($t) {
271 if (!empty($t->authUser)) {
274 $ff = HTML_FlexyFramework::get();
275 $tbl = empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
277 $u = DB_DataObject::factory( $tbl );
279 if (is_a($u,'PEAR_Error') || !$u->isAuth()) {
282 $t->authUser =$u->getAuthUser();
283 return $t->authUser ;
288 * getAuthUser: - get the authenticated user..
290 * @return {DB_DataObject} of type Pman[authTable] if authenticated.
293 function getAuthUser()
295 return self::staticGetAuthUser($this);
299 * wrapper arround authuser->hasPerm
300 * @see Pman_Core_DataObject_Core_person::hasPerm
302 * @param {String} $name The permission name (eg. Projects.List)
303 * @param {String} $lvl eg. (C)reate (E)dit (D)elete ... etc.
306 function hasPerm($name, $lvl) // do we have a permission
308 static $pcache = array();
309 $au = $this->getAuthUser();
310 return $au && $au->hasPerm($name,$lvl);
314 * modulesList: List the modules in the application
316 * @return {Array} list of modules
318 function modulesList()
320 $boot = HTML_FlexyFramework::get();
321 // echo'<PRE>';print_R($boot);exit;
324 $mods = explode(',', $boot->enable);
325 if (in_array('Core',$mods)) { // core has to be the first modules loaded as it contains Pman.js
326 array_unshift($mods, 'Core');
329 if (in_array($boot->appNameShort,$mods)) { // Project has to be the last modules loaded as it contains Pman.js
330 unset($mods[array_search($boot->appNameShort, $mods)]);
331 $mods[] = $boot->appNameShort;
334 $mods = array_unique($mods);
336 $disabled = explode(',', $boot->disable ? $boot->disable : '');
338 foreach($mods as $mod) {
339 // add the css file..
340 if (in_array($mod, $disabled)) {
351 function hasModule($name)
354 if (!strpos( $name,'.') ) {
355 // use enable / disable..
356 return in_array($name, $this->modules());
359 $x = DB_DataObject::factory('core_group_right');
360 $ar = $x->defaultPermData();
361 if (empty($ar[$name]) || empty($ar[$name][0])) {
369 function jsencode($v, $header = false)
372 header("Content-type: text/javascript");
374 if (function_exists("json_encode")) {
375 $ret= json_encode($v);
376 if ($ret !== false) {
380 require_once 'Services/JSON.php';
381 $js = new Services_JSON();
382 return $js->encodeUnsafe($v);
391 * ---------------- Global Tools ---------------
393 function checkFileUploadError() // check for file upload errors.
396 empty($_FILES['File'])
397 || empty($_FILES['File']['name'])
398 || empty($_FILES['File']['tmp_name'])
399 || empty($_FILES['File']['type'])
400 || !empty($_FILES['File']['error'])
401 || empty($_FILES['File']['size'])
403 $this->jerr("File upload error: <PRE>" . print_r($_FILES,true) . print_r($_POST,true) . "</PRE>");
407 static $deleteOnExit = false;
409 * generate a tempory file with an extension (dont forget to delete it)
412 function deleteOnExitAdd($name)
414 if (self::$deleteOnExit === false) {
415 register_shutdown_function(array('Pman','deleteOnExit'));
416 self::$deleteOnExit = array();
418 self::$deleteOnExit[] = $name;
421 function tempName($ext, $deleteOnExit=false)
424 $x = tempnam(ini_get('session.save_path'), HTML_FlexyFramework::get()->appNameShort.'TMP');
426 $ret = $x .'.'. $ext;
428 $this->deleteOnExitAdd($ret);
434 static function deleteOnExit()
437 foreach(self::$deleteOnExit as $fn) {
438 if (file_exists($fn)) {
445 * ------------- Authentication password reset ------ ??? MOVEME?
453 * jerrAuth: standard auth failure - with data that let's the UI know..
457 $au = $this->authUser();
459 // is it an authfailure?
460 $this->jerr("Permission denied to view this resource", array('authFailure' => true));
462 $this->jerr("Not authenticated", array('authFailure' => true));
468 * ---------------- Standard JSON outputers. - used everywhere
471 * ---------------- Standard JSON outputers. - used everywhere
472 * JSON error - simple error with logging.
476 function jerr($str, $errors=array(), $content_type = false) // standard error reporting..
478 return $this->jerror('ERROR', $str,$errors,$content_type);
481 * Recomended JSON error indicator
484 * @param string $type - normally 'ERROR' - you can use this to track error types.
485 * @param string $message - error message displayed to user.
486 * @param array $errors - optioanl data to pass to front end.
487 * @param string $content_type - use text/plain to return plan text - ?? not sure why...
491 function jerror($type, $str, $errors=array(), $content_type = false) // standard error reporting..
493 if ($this->transObj) {
494 $this->transObj->query('ROLLBACK');
497 $cli = HTML_FlexyFramework::get()->cli;
499 echo "ERROR: " .$str . "\n"; // print the error first, as DB might fail..
502 if ($type !== false) {
505 DB_DataObject::factory('Events')->writeEventLogExtra($errors);
508 $this->addEvent($type, false, $str);
512 $cli = HTML_FlexyFramework::get()->cli;
514 exit(1); // cli --- exit code to stop shell execution if necessary.
518 if ($content_type == 'text/plain') {
519 header('Content-Disposition: attachment; filename="error.txt"');
520 header('Content-type: '. $content_type);
521 echo "ERROR: " .$str . "\n";
527 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
528 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
531 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
535 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
540 header('Content-type: text/html');
541 echo "<HTML><HEAD></HEAD><BODY>";
542 echo $this->jsencode(array(
545 'message' => $str, // compate with exeption / loadexception.
547 'errors' => $errors ? $errors : true, // used by forms to flag errors.
548 'authFailure' => !empty($errors['authFailure']),
550 echo "</BODY></HTML>";
554 if (isset($_REQUEST['_debug'])) {
555 echo '<PRE>'.htmlspecialchars(print_r(array(
559 'message' => $str, // compate with exeption / loadexception.
560 'errors' => $errors ? $errors : true, // used by forms to flag errors.
561 'authFailure' => !empty($errors['authFailure']),
567 echo $this->jsencode(array(
572 'message' => $str, // compate with exeption / loadexception.
573 'errors' => $errors ? $errors : true, // used by forms to flag errors.
574 'authFailure' => !empty($errors['authFailure']),
583 if ($this->transObj ) {
584 $this->transObj->query( connection_aborted() ? 'ROLLBACK' : 'COMMIT');
587 $cli = HTML_FlexyFramework::get()->cli;
589 echo "OK: " .$str . "\n";
593 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
594 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
597 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
601 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
605 header('Content-type: text/html');
606 echo "<HTML><HEAD></HEAD><BODY>";
607 // encode html characters so they can be read..
608 echo str_replace(array('<','>'), array('\u003c','\u003e'),
609 $this->jsencode(array('success'=> true, 'data' => $str), false));
610 echo "</BODY></HTML>";
615 echo $this->jsencode(array('success'=> true, 'data' => $str),true);
621 * output data for grids or tree
622 * @ar {Array} ar Array of data
623 * @total {Number|false} total number of records (or false to return count(ar)
624 * @extra {Array} extra key value list of data to pass as extra data.
627 function jdata($ar,$total=false, $extra=array(), $cachekey = false)
629 // should do mobile checking???
630 if ($total == false) {
633 $extra= $extra ? $extra : array();
636 $retHTML = isset($_SERVER['CONTENT_TYPE']) &&
637 preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
640 if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
644 $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] !='NO';
649 header('Content-type: text/html');
650 echo "<HTML><HEAD></HEAD><BODY>";
651 // encode html characters so they can be read..
652 echo str_replace(array('<','>'), array('\u003c','\u003e'),
653 $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra, false));
654 echo "</BODY></HTML>";
659 // see if trimming will help...
660 if (!empty($_REQUEST['_pman_short'])) {
663 foreach($ar as $as) {
665 foreach($as as $k=>$v) {
666 if (is_string($v) && !strlen(trim($v))) {
678 $ret = $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra,true);
680 if (!empty($cachekey)) {
682 $fn = ini_get('session.save_path') . '/json-cache'.date('/Y/m/d').'.'. $cachekey . '.cache.json';
683 if (!file_exists(dirname($fn))) {
684 mkdir(dirname($fn), 0777,true);
686 file_put_contents($fn, $ret);
695 /** a daily cache **/
696 function jdataCache($cachekey)
698 $fn = ini_get('session.save_path') . '/json-cache'.date('/Y/m/d').'.'. $cachekey . '.cache.json';
699 if (file_exists($fn)) {
700 header('Content-type: application/json');
701 echo file_get_contents($fn);
711 * ---------------- OUTPUT
713 function hasBg($fn) // used on front page to check if logos exist..
715 return file_exists($this->rootDir.'/Pman/'.$this->appNameShort.'/templates/images/'. $fn);
718 * outputJavascriptIncludes:
720 * output <script....> for all the modules in the applcaiton
723 function outputJavascriptIncludes()
725 // BC support - currently 1 project still relies on this.. (MO portal)
726 $o = HTML_FlexyFramework::get()->Pman_Core;
727 if (isset($o['packseed'])) {
728 return $this->outputJavascriptIncludesBC();
732 $mods = $this->modulesList();
734 $is_bootstrap = in_array('BAdmin', $mods);
736 foreach($mods as $mod) {
737 // add the css file..
740 if (!file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
741 echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
747 $this->outputJavascriptDir("Pman/$mod/widgets", "*.js");
748 $this->outputJavascriptDir("Pman/$mod", "*.js");
752 if (empty($this->disable_jstemplate)) {
753 // and finally the JsTemplate...
754 echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
757 $this->callModules('outputJavascriptIncludes', $this);
760 var $css_includes = array();
764 * output <link rel=stylesheet......> for all the modules in the applcaiton
767 * This could css minify as well.
769 function outputCSSIncludes() // includes on CSS links.
773 $mods = $this->modulesList();
774 $is_bootstrap = in_array('BAdmin', $mods);
776 $this->callModules('applyCSSIncludes', $this);
777 foreach($this->css_includes as $module => $ar) {
780 $this->assetArrayToHtml( $ar , 'css');
784 // old style... - probably remove this...
785 $this->callModules('outputCSSIncludes', $this);
787 foreach($mods as $mod) {
788 // add the css file..
789 if ($is_bootstrap && !file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
790 echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
793 $this->outputCSSDir("Pman/$mod","*.css");
794 $this->outputSCSS($mod);
817 // --- OLD CODE - in for BC on MO project.... - needs removing...
819 // used on old versions.....
820 function outputJavascriptIncludesBC()
823 $mods = $this->modulesList();
825 foreach($mods as $mod) {
826 // add the css file..
829 $files = $this->moduleJavascriptList($mod.'/widgets');
830 foreach($files as $f) {
831 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
834 $files = $this->moduleJavascriptList($mod);
835 foreach($files as $f) {
836 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
840 if (empty($this->disable_jstemplate)) {
841 // and finally the JsTemplate...
842 echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
847 * Gather infor for javascript files..
849 * @param {String} $mod the module to get info about.
850 * @return {StdClass} details about module.
852 function moduleJavascriptFilesInfo($mod)
855 static $cache = array();
857 if (isset($cache[$mod])) {
862 $ff = HTML_FlexyFramework::get();
864 $base = dirname($_SERVER['SCRIPT_FILENAME']);
865 $dir = $this->rootDir.'/Pman/'. $mod;
866 $path = $this->rootURL ."/Pman/$mod/";
868 $ar = glob($dir . '/*.js');
874 foreach($ar as $fn) {
876 // got the 'module file..'
877 $mtime = filemtime($dir . '/'. $f);
878 $maxtime = max($mtime, $maxtime);
879 $arfiles[$fn] = $mtime;
880 $files[] = $path . $f . '?ts='.$mtime;
883 ksort($arfiles); // just sort by name so it's consistant for serialize..
885 // The original idea of this was to serve the files direct from a publicly available 'cache' directory.
886 // but that doesnt really make sense - as we can just serve it from the session directory where we stick
887 // cached data anyway.
890 $compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
891 $basedir = $compile ? $ff->Pman['public_cache_dir'] : false;
892 $baseurl = $compile ? $ff->Pman['public_cache_url'] : false;
896 $basedir = session_save_path(). '/translate-cache/';
897 if (!file_exists($basedir)) {
898 mkdir($basedir,0755);
900 $baseurl = $this->baseURL . '/Admin/Translations';
902 if (PHP_VERSION_ID < 70000 ) {
903 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
904 usort($files, $lsort);
906 usort($files, function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; });
909 $smod = str_replace('/','.',$mod);
911 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
914 // why are translations done like this - we just build them on the fly frmo the database..
915 $tmtime = file_exists($this->rootDir.'/_translations_/'. $smod.'.js')
916 ? filemtime($this->rootDir.'/_translations_/'. $smod.'.js') : 0;
918 $cache[$mod] = (object) array(
919 'smod' => $smod, // module name without '/'
920 'files' => $files, // list of all files.
921 'filesmtime' => $arfiles, // map of mtime=>file
922 'maxtime' => $maxtime, // max mtime
923 'compile' => $this->isDev ? false : $compile,
924 'translation_file' => $base .'/_translations_/' . $smod . '.js',
925 'translation_mtime' => $tmtime,
927 'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
928 'translation_base' => $dir .'/', //prefix of filename (without moudle name))
929 'basedir' => $basedir,
930 'baseurl' => $baseurl,
931 'module_dir' => $dir,
938 * moduleJavascriptList: list the javascript files in a module
940 * The original version of this.. still needs more thought...
942 * Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js
943 * Translations are in Pman/_translations_/{$mod}.js
945 * if that stuff does not exist just list files in Pman/{$mod}/*.js
947 * Compiled could be done on the fly..
951 * @param {String} $mod the module to look at - eg. Pman/{$mod}/*.js
952 * @return {Array} list of include paths (either compiled or raw)
958 function moduleJavascriptList($mod)
962 $dir = $this->rootDir.'/Pman/'. $mod;
965 if (!file_exists($dir)) {
966 echo '<!-- missing directory '. htmlspecialchars($dir) .' -->';
970 $info = $this->moduleJavascriptFilesInfo($mod);
974 if (empty($info->files)) {
977 // finally sort the files, so they are in the right order..
979 // only compile this stuff if public_cache is set..
983 // public_cache_dir = /var/www/myproject_cache
984 // public_cache_url = /myproject_cache (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
987 if (!$info->compile) {
988 echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n";
992 // where are we going to write all of this..
993 // This has to be done via a
994 if (!file_exists($info->basedir.'/'.$info->output) || !filesize($info->basedir.'/'.$info->output)) {
995 require_once 'Pman/Core/JsCompile.php';
996 $x = new Pman_Core_JsCompile();
998 $x->pack($info->filesmtime,$info->basedir.'/'.$info->output, $info->translation_base);
1000 echo "<!-- file exists not exist: {$info->basedir}/{$info->output} -->\n";
1003 if (file_exists($info->basedir.'/'.$info->output) &&
1004 filesize($info->basedir.'/'.$info->output)) {
1007 $info->baseurl.'/'. $info->output,
1010 // output all the ava
1011 // fixme - this needs the max datetime for the translation file..
1012 $ret[] = $this->baseURL."/Admin/InterfaceTranslations/".$mod.".js"; //?ts=".$info->translation_mtime;
1014 //if ($info->translation_mtime) {
1015 // $ret[] = $this->rootURL."/_translations_/". $info->smod.".js?ts=".$info->translation_mtime;
1022 // give up and output original files...
1025 return $info->files;
1032 * PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
1034 function initErrorHandling()
1036 if (!class_exists('HTML_FlexyFramework2')) {
1037 // what about older code that still users PEAR?
1038 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
1040 set_exception_handler(array($this,'onException'));
1045 static $permitError = false; // static why?
1047 var $showErrorToUser = true;
1049 function onPearError($err)
1051 return $this->onException($err);
1056 function onException($ex)
1058 static $reported = false;
1063 if (Pman::$permitError) {
1070 $out = is_a($ex,'Exception') || is_a($ex, 'Error') ? $ex->getMessage() : $ex->toString();
1073 //print_R($bt); exit;
1076 $bt = is_a($ex,'Exception')|| is_a($ex, 'Error') ? $ex->getTrace() : $ex->backtrace;
1077 if (is_a($ex,'Exception')|| is_a($ex, 'Error') ) {
1078 $ret[] = $ex->getFile() . '('. $ex->getLine() . ')';
1080 foreach( $bt as $b) {
1081 $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' . @$b['class'] . '::' . @$b['function'];
1087 //convert the huge backtrace into something that is readable..
1088 $out .= "\n" . implode("\n", $ret);
1090 $this->addEvent("EXCEPTION", false, $out);
1092 if ($this->showErrorToUser) {
1095 // not sure why this is here... - perhaps doing a jerr() was actually caught by the UI, and hidden from the user..?
1096 $this->jerror(false,"An error Occured, please contact the website owner");
1098 //$this->jerr($out);
1105 * ---------------- Logging ---------------
1110 * Log an action (only if it has not been logged already.
1112 * @param {String} action - group/name of event
1113 * @param {DataObject|false} obj - dataobject action occured on.
1114 * @param {String} any remarks
1115 * @return {false|DB_DataObject} Event object.,
1118 function addEventOnce($act, $obj = false, $remarks = '')
1120 if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
1123 $e = DB_DataObject::factory('Events');
1124 $e->init($act,$obj,$remarks);
1125 if ($e->find(true)) {
1128 return $this->addEvent($act, $obj, $remarks);
1134 * @param {String} action - group/name of event
1135 * @param {DataObject|false} obj - dataobject action occured on.
1136 * @param {String} any remarks
1137 * @return {DB_DataObject} Event object.,
1140 function addEvent($act, $obj = false, $remarks = '')
1143 if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
1146 $au = $this->getAuthUser();
1148 $e = DB_DataObject::factory('Events');
1149 $e->init($act,$obj,$remarks);
1151 $e->event_when = $e->sqlValue('NOW()');
1153 $eid = $e->insert();
1155 // fixme - this should be in onInsert..
1156 $wa = DB_DataObject::factory('core_watch');
1157 if (method_exists($wa,'notifyEvent')) {
1158 $wa->notifyEvent($e); // trigger any actions..
1162 $e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
1169 function addEventNotifyOnly($act, $obj = false, $remarks = '')
1171 $au = $this->getAuthUser();
1173 $e = DB_DataObject::factory('Events');
1174 $e->init($act,$obj,$remarks);
1176 $e->event_when = $e->sqlValue('NOW()');
1177 $wa = DB_DataObject::factory('core_watch');
1178 if (method_exists($wa,'notifyEvent')) {
1179 $wa->notifyEvent($e); // trigger any actions..
1184 // ------------------ DEPERCIATED ----------------------------
1186 // DEPRECITAED - use moduleslist
1187 function modules() { return $this->modulesList(); }
1190 // DEPRICATED USE Pman_Core_Mailer
1192 function emailTemplate($templateFile, $args)
1195 require_once 'Pman/Core/Mailer.php';
1196 $r = new Pman_Core_Mailer(array(
1197 'template'=>$templateFile,
1198 'contents' => $args,
1201 return $r->toData();
1204 // DEPRICATED - USE Pman_Core_Mailer
1205 // WHAT Part about DEPRICATED Does no one understand??
1206 function sendTemplate($templateFile, $args)
1208 require_once 'Pman/Core/Mailer.php';
1209 $r = new Pman_Core_Mailer(array(
1210 'template'=>$templateFile,
1211 'contents' => array(),