Pman.php
[Pman.Base] / Pman.php
1 <?php 
2 /**
3  * Pman Base class
4  * 
5  * Provides:
6  *  - base application setup (variables etc to javascript)
7  * 
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..)
13  * 
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?!? ;)
18  * 
19  * Usefull implemetors
20  * DB_DataObject*:*toEventString (for logging - this is generically prefixed to all database operations.)
21  *   - any data object where this method exists, the result will get prefixed to the log remarks
22  */
23
24 class Pman extends HTML_FlexyFramework_Page 
25 {
26     var $appName= "";
27     var $appShortName= "";
28     var $appVersion = "1.8";
29     var $version = 'dev';
30     var $onloadTrack = 0;
31     var $linkFail = "";
32     var $showNewPass = 0;
33     var $logoPrefix = '';
34     var $appModules = '';
35     var $appDisabled = array(); // array of disabled modules..
36                     // (based on config option disable)
37     
38     var $authUser; // always contains the authenticated user..
39     
40    
41     
42     /**
43      * ------------- Standard getAuth/get/post methods of framework.
44      * 
45      * 
46      */
47     
48     function getAuth() // everyone allowed in!!!!!
49     {
50         $this->loadOwnerCompany();
51         
52         return true;
53         
54     }
55     
56     function init() 
57     {
58         if (isset($this->_hasInit)) {
59             return;
60         }
61         $this->_hasInit = true;
62           
63         $boot = HTML_FlexyFramework::get();
64         // echo'<PRE>';print_R($boot);exit;
65         $this->appName= $boot->appName;
66         $this->appNameShort= $boot->appNameShort;
67         $this->appModules= $boot->enable;
68         $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
69         $this->appDisable = $boot->disable;
70         $this->appDisabled = explode(',', $boot->disable);
71         $this->version = $boot->version;
72         
73         if (!empty($ff->Pman['local_autoauth']) && 
74             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
75             ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') 
76         ) {
77             $this->isDev = true;
78         }
79         
80     }
81     
82     function get($base) 
83     {
84         $this->init();
85             //$this->allowSignup= empty($opts['allowSignup']) ? 0 : 1;
86         $bits = explode('/', $base);
87         //print_R($bits);
88         if ($bits[0] == 'Link') {
89             $this->linkFail = $this->linkAuth(@$bits[1],@$bits[2]);
90             header('Content-type: text/html; charset=utf-8');
91             return;
92         } 
93         if ($bits[0] == 'PasswordReset') {
94             $this->linkFail = $this->resetPassword(@$bits[1],@$bits[2],@$bits[3]);
95             header('Content-type: text/html; charset=utf-8');
96             return;
97         } 
98         
99         
100         if ($this->getAuthUser()) {
101             $this->addEvent("RELOAD");
102         }
103         
104         
105         if (strlen($base)) {
106             $this->addEvent("BADURL", false, $base);
107             $this->jerr("invalid url");
108         }
109         // deliver template
110         if (isset($_GET['onloadTrack'])) {
111             $this->onloadTrack = (int)$_GET['onloadTrack'];
112         }
113         // getting this to work with xhtml is a nightmare
114         // = nbsp / <img> issues screw everyting up.
115          //var_dump($this->isDev);
116         // force regeneration on load for development enviroments..
117         
118         HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev);
119         
120         //header('Content-type: application/xhtml+xml; charset=utf-8');
121         header('Content-type: text/html; charset=utf-8');
122          
123     }
124     function post($base) {
125         return $this->get($base);
126     }
127     
128     /**
129      * ------------- Authentication and permission info about logged in user!!!
130      * 
131      * 
132      */
133     
134     function loadOwnerCompany()
135     {
136         $this->company = DB_DataObject::Factory('Companies');
137         if ($this->company) { // non-core pman projects
138             return; 
139         }
140         $this->company->get('comptype', 'OWNER');
141         
142     }
143     function staticGetAuthUser()
144     {
145         $ff = HTML_FlexyFramework::get();
146         $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
147         
148         $u = DB_DataObject::factory($tbl);
149         if (!$u->isAuth()) {
150             return false;
151         }
152         return $u->getAuthUser();
153     }
154     function getAuthUser()
155     {
156         if (!empty($this->authUser)) {
157             return $this->authUser;
158         }
159         $ff = HTML_FlexyFramework::get();
160         $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
161         
162         $u = DB_DataObject::factory( $tbl );
163         if (!$u->isAuth()) {
164             return false;
165         }
166         $this->authUser =$u->getAuthUser();
167         return $this->authUser ;
168     }
169     function hasPerm($name, $lvl)  // do we have a permission
170     {
171         static $pcache = array();
172         $au = $this->getAuthUser();
173         return $au->hasPerm($name,$lvl);
174         
175     }
176     
177     function modules()
178     {
179         // appModules/appDisable contain a comma limited list of
180         // both modules and components that can be enabled/disabled..
181          $boot = HTML_FlexyFramework::get();
182
183         // the modules call just lists the modules
184         $enabled =  array('Core' => true);
185          $am = !empty($boot->enable) ? explode(',',  $boot->enable) : array();
186         foreach($am as $k) {
187             if (strpos( $k ,'.') ) {
188                 continue;
189             }
190             $enabled[$k] = true;
191         }
192         
193         
194         $disabled =  !empty($boot->disable) ?  explode(',', $boot->disable) : array();
195         foreach($disabled as $k) {
196             if ( strpos( $k ,'.') ) {
197                 continue;
198             }
199             if (isset($enabled[$k])) {
200                 unset($enabled[$k]);
201             }   
202         }
203          //echo '<PRE>';       var_Dump($enabled);
204
205         return array_keys($enabled); 
206     }
207     
208     function hasModule($name) 
209     {
210         $this->init();
211         if (!strpos( $name,'.') ) {
212             // use enable / disable..
213             return in_array($name, $this->modules()); 
214         }
215         
216         $x = DB_DataObject::factory('Group_Rights');
217         $ar = $x->defaultPermData();
218         if (empty($ar[$name]) || empty($ar[$name][0])) {
219             return false;
220         }
221         return true;
222     }
223     
224     
225     
226     
227     /**
228      * ---------------- Global Tools ---------------   
229      */
230     
231     
232     
233     /**
234      * send a template to the user
235      * rcpts are read from the resulting template.
236      * 
237      * @arg $templateFile  - the file in mail/XXXXXX.txt
238      * @arg $args  - variables available to the form as {t.*} over and above 'this'
239      * 
240      * 
241      */
242     
243     function sendTemplate($templateFile, $args)
244     {
245         
246         
247         
248         $content  = clone($this);
249         
250         foreach((array)$args as $k=>$v) {
251             $content->$k = $v;
252         }
253         $content->msgid = md5(time() . rand());
254         
255         $content->HTTP_HOST = $_SERVER["HTTP_HOST"];
256         /* use the regex compiler, as it doesnt parse <tags */
257         require_once 'HTML/Template/Flexy.php';
258         $template = new HTML_Template_Flexy( array(
259                  'compiler'    => 'Regex',
260                  'filters' => array('SimpleTags','Mail'),
261             //     'debug'=>1,
262             ));
263         
264         // this should be done by having multiple template sources...!!!
265          
266         $template->compile('mail/'. $templateFile.'.txt');
267         
268         /* use variables from this object to ouput data. */
269         $mailtext = $template->bufferedOutputObject($content);
270         //echo "<PRE>";print_R($mailtext);
271         
272         /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
273         require_once 'Mail/mimeDecode.php';
274         require_once 'Mail.php';
275         
276         $decoder = new Mail_mimeDecode($mailtext);
277         $parts = $decoder->getSendArray();
278         if (PEAR::isError($parts)) {
279             return $parts;
280             //echo "PROBLEM: {$parts->message}";
281             //exit;
282         } 
283         list($recipents,$headers,$body) = $parts;
284         ///$recipents = array($this->email);
285         $mailOptions = PEAR::getStaticProperty('Mail','options');
286         $mail = Mail::factory("SMTP",$mailOptions);
287         $headers['Date'] = date('r');
288         if (PEAR::isError($mail)) {
289             return $mail;
290         } 
291         $oe = error_reporting(E_ALL ^ E_NOTICE);
292         $ret = $mail->send($recipents,$headers,$body);
293         error_reporting($oe);
294        
295         return $ret;
296     
297     }
298     
299     function checkFileUploadError()  // check for file upload errors.
300     {    
301         if (
302             empty($_FILES['File']) 
303             || empty($_FILES['File']['name']) 
304             || empty($_FILES['File']['tmp_name']) 
305             || empty($_FILES['File']['type']) 
306             || !empty($_FILES['File']['error']) 
307             || empty($_FILES['File']['size']) 
308         ) {
309             $this->jerr("File upload error: <PRE>" . print_r($_FILES,true) . print_r($_POST,true) . "</PRE>");
310         }
311     }
312     
313     
314     /**
315      * generate a tempory file with an extension (dont forget to delete it)
316      */
317     
318     function tempName($ext)
319     {
320         $x = tempnam(ini_get('session.save_path'), HTML_FlexyFramework::get()->appNameShort.'TMP');
321         unlink($x);
322         return $x .'.'. $ext;
323     }
324     /**
325      * ------------- Authentication testing ------ ??? MOVEME?
326      * 
327      * 
328      */
329     function linkAuth($trid, $trkey) 
330     {
331         $tr = DB_DataObject::factory('Documents_Tracking');
332         if (!$tr->get($trid)) {
333             return "Invalid URL";
334         }
335         if (strtolower($tr->authkey) != strtolower($trkey)) {
336             $this->AddEvent("ERROR-L", false, "Invalid Key");
337             return "Invalid KEY";
338         }
339         // check date..
340         $this->onloadTrack = (int) $tr->doc_id;
341         if (strtotime($tr->date_sent) < strtotime("NOW - 14 DAYS")) {
342             $this->AddEvent("ERROR-L", false, "Key Expired");
343             return "Key Expired";
344         }
345         // user logged in and not
346         $au = $this->getAuthUser();
347         if ($au && $au->id && $au->id != $tr->person_id) {
348             $au->logout();
349             
350             return "Logged Out existing Session\n - reload to log in with correct key";
351         }
352         if ($au) { // logged in anyway..
353             $this->AddEvent("LOGIN", false, "With Key (ALREADY)");
354             header('Location: ' . $this->baseURL.'?onloadTrack='.$this->onloadTrack);
355             exit;
356             return false;
357         }
358         
359         // authenticate the user...
360         // slightly risky...
361         $u = DB_DataObject::factory('Person');
362          
363         $u->get($tr->person_id);
364         $u->login();
365         $this->AddEvent("LOGIN", false, "With Key");
366         
367         // we need to redirect out - otherwise refererer url will include key!
368         header('Location: ' . $this->baseURL.'?onloadTrack='.$this->onloadTrack);
369         exit;
370         
371         return false;
372         
373         
374         
375         
376     }
377     
378     
379     /**
380      * ------------- Authentication password reset ------ ??? MOVEME?
381      * 
382      * 
383      */
384     
385     
386     function resetPassword($id,$t, $key)
387     {
388         
389         $au = $this->getAuthUser();
390         if ($au) {
391             return "Already Logged in - no need to use Password Reset";
392         }
393         
394         $u = DB_DataObject::factory('Person');
395         //$u->company_id = $this->company->id;
396         $u->active = 1;
397         if (!$u->get($id) || !strlen($u->passwd)) {
398             return "invalid id";
399         }
400         
401         // validate key.. 
402         if ($key != $u->genPassKey($t)) {
403             return "invalid key";
404         }
405         $uu = clone($u);
406         $u->no_reset_sent = 0;
407         $u->update($uu);
408         
409         if ($t < strtotime("NOW - 1 DAY")) {
410             return "expired";
411         }
412         $this->showNewPass = implode("/", array($id,$t,$key));
413         return false;
414     }
415     
416     /**
417      * jerrAuth: standard auth failure - with data that let's the UI know..
418      */
419     function jerrAuth()
420     {
421         $this->jerr("Not authenticated", array('authFailure' => true));
422     }
423      
424     /**
425      * ---------------- Standard JSON outputers. - used everywhere
426      */
427     
428     function jerr($str, $errors=array()) // standard error reporting..
429     {
430         
431         $cli = HTML_FlexyFramework::get()->cli;
432         if ($cli) {
433             echo "ERROR:\n" .$str . "\n";
434             exit;
435         }
436         
437         require_once 'Services/JSON.php';
438         $json = new Services_JSON();
439         
440         // log all errors!!!
441         $this->addEvent("ERROR", false, $str);
442         
443         if (!empty($_REQUEST['returnHTML']) || 
444             (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
445         ) {
446             header('Content-type: text/html');
447             echo "<HTML><HEAD></HEAD><BODY>";
448             echo  $json->encodeUnsafe(array(
449                     'success'=> false, 
450                     'errorMsg' => $str,
451                     'message' => $str, // compate with exeption / loadexception.
452
453                     'errors' => $errors ? $errors : true, // used by forms to flag errors.
454                     'authFailure' => !empty($errors['authFailure']),
455                 ));
456             echo "</BODY></HTML>";
457             exit;
458         }
459         
460         echo $json->encode(array(
461             'success'=> false, 
462             'data'=> array(), 
463             'errorMsg' => $str,
464             'message' => $str, // compate with exeption / loadexception.
465             'errors' => $errors ? $errors : true, // used by forms to flag errors.
466             'authFailure' => !empty($errors['authFailure']),
467         ));
468         exit;
469         
470     }
471     function jok($str)
472     {
473         
474         require_once 'Services/JSON.php';
475         $json = new Services_JSON();
476         
477         if (!empty($_REQUEST['returnHTML']) || 
478             (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
479         
480         ) {
481             header('Content-type: text/html');
482             echo "<HTML><HEAD></HEAD><BODY>";
483             // encode html characters so they can be read..
484             echo  str_replace(array('<','>'), array('\u003c','\u003e'),
485                         $json->encodeUnsafe(array('success'=> true, 'data' => $str)));
486             echo "</BODY></HTML>";
487             exit;
488         }
489          
490         
491         echo  $json->encode(array('success'=> true, 'data' => $str));
492         exit;
493         
494     }
495     /**
496      * output data for grids or tree
497      * @ar {Array} ar Array of data
498      * @total {Number|false} total number of records (or false to return count(ar)
499      * @extra {Array} extra key value list of data to pass as extra data.
500      * 
501      */
502     function jdata($ar,$total=false, $extra=array())
503     {
504         // should do mobile checking???
505         if ($total == false) {
506             $total = count($ar);
507         }
508         $extra=  $extra ? $extra : array();
509         require_once 'Services/JSON.php';
510         $json = new Services_JSON();
511         if (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE'])) {
512             
513             header('Content-type: text/html');
514             echo "<HTML><HEAD></HEAD><BODY>";
515             // encode html characters so they can be read..
516             echo  str_replace(array('<','>'), array('\u003c','\u003e'),
517                         $json->encodeUnsafe(array('success' =>  true, 'total'=> $total, 'data' => $ar) + $extra));
518             echo "</BODY></HTML>";
519             exit;
520         }
521         
522       
523         
524         
525         
526         
527        
528         echo $json->encode(array('success' =>  true, 'total'=> $total, 'data' => $ar) + $extra);    
529         exit;
530         
531         
532     }
533     
534     
535    
536    
537       
538     /**
539      * ---------------- Page output?!?!?
540      */
541     
542     
543     function hasBg($fn) // used on front page to check if logos exist..
544     {
545         return file_exists($this->rootDir.'/Pman/'.$this->appNameShort.'/templates/images/'.  $fn);
546     }
547     
548     function outputJavascriptIncludes() // includes on devel version..
549     {
550         
551         $mods = explode(',', $this->appModules);
552         if (in_array('Core',$mods)) { // core has to be the first  modules loaded as it contains Pman.js
553             array_unshift($mods,   'Core');
554         }
555         
556         $mods = array_unique($mods);
557          
558         $disabled =  explode(',', $this->appDisable ? $this->appDisable: '');
559         
560         foreach($mods as $mod) {
561             // add the css file..
562             if (in_array($mod, $disabled)) {
563                 continue;
564             }
565             
566             
567             $files = $this->moduleJavascriptList($mod.'/widgets');
568             foreach($files as $f) {
569                 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
570             }
571             
572             $files = $this->moduleJavascriptList($mod);
573             foreach($files as $f) {
574                 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
575             }
576             
577         }
578          
579     }
580     
581     function outputCSSIncludes() // includes on CSS links.
582     {
583         
584         $mods = explode(',', $this->appModules);
585         array_unshift($mods,   'Core');
586         $mods = array_unique($mods);
587         
588         foreach($mods as $mod) {
589             // add the css file..
590             $css = $this->rootDir.'/Pman/'.$mod.'/'.strtolower($mod).'.css';
591             if (file_exists( $css)){
592                 $css = $this->rootURL .'/Pman/'.$mod.'/'.strtolower($mod).'.css';
593                 echo '<link rel="stylesheet" type="text/css" href="'.$css.'" />'."\n";
594             }
595              
596             
597         }
598          
599     }
600     /**
601      * packJS:
602      *
603      * @file path to 
604      *
605      *
606      */
607     
608      function packJS($dir)
609     {
610        
611         // target has to be 'aliased'
612         // target filename can be an md5..
613         
614         require_once 'Pman/Core/JsCompile.php';
615         $x = new Pman_Core_JsCompile();
616         $x->packScript(dirname(__FILE__).'/Hex/templates/images', 
617                        array($dir),
618                         $this->rootURL . '/Hex/templates/images');
619         
620         
621     }
622     /**
623      * Gather infor for javascript files..
624      *
625      * @param {String} $mod the module to get info about.
626      * @return {StdClass}  details about module.
627      */
628     function moduleJavascriptFilesInfo($mod)
629     {
630         $ff = HTML_FlexyFramework::get();
631         
632         $base = dirname($_SERVER['SCRIPT_FILENAME']);
633         $dir =   $this->rootDir.'/Pman/'. $mod;
634             
635         
636         $ar = glob($dir . '/*.js');
637         
638         $files = array();
639         $arfiles = array();
640         $maxtime = 0;
641         $mtime = 0;
642         foreach($ar as $fn) {
643             $f = basename($fn);
644             // got the 'module file..'
645             $mtime = filemtime($dir . '/'. $f);
646             $maxtime = max($mtime, $maxtime);
647             $arfiles[$fn] = $mtime;
648             $files[] = $path . $f . '?ts='.$mtime;
649         }
650         $compile  = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
651         $basedir = $ff->Pman['public_cache_dir'];
652         $baseurl = $ff->Pman['public_cache_url'];
653         
654         return (object) array(
655             'files' => $files,
656             'filesmtime' => $arfiles,
657             'maxtime' => $maxtime,
658             'compile' => $compile,
659             'translation_file' =>  realpath($base .'/_translations_/' . str_replace('/','.', $mod) .  '.js'),
660             'output' => date('Y-m-d-H-i-s-', $maxtime). str_replace('/','.',$mod).'-'.md5(serialize($arfiles)) .'.js',
661             'basedir' => $basedir,
662             'baseurl' => $baseurl,
663         );
664     }
665     
666     
667     
668     
669     /**
670      *  moduleJavascriptList: list the javascript files in a module
671      *
672      *  The original version of this.. still needs more thought...
673      *
674      *  Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js
675      *  Translations are in Pman/_translations_/{$mod}.js
676      *  
677      *  if that stuff does not exist just list files in  Pman/{$mod}/*.js
678      *
679      *  Compiled could be done on the fly..
680      * 
681      *
682      *
683      *  @param {String} $mod  the module to look at - eg. Pman/{$mod}/*.js
684      *  @return {Array} list of include paths (either compiled or raw)
685      *
686      */
687
688     
689     
690     function moduleJavascriptList($mod)
691     {
692         
693         
694         $dir =   $this->rootDir.'/Pman/'. $mod;
695         if (!file_exists($dir)) {
696             return array();
697         }
698         
699         $info = $this->moduleJavascriptFilesInfo($mod);
700         
701         
702          
703         
704         if (empty($info->files)) {
705             return array();
706         }
707         // finally sort the files, so they are in the right order..
708         
709         // only compile this stuff if public_cache is set..
710         
711         $compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
712         
713         // suggestions...
714         //  public_cache_dir =   /var/www/myproject_cache
715         //  public_cache_url =   /myproject_cache    (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
716        
717         $basedir = empty($ff->Pman['public_cache_dir']) ? false : $ff->Pman['public_cache_dir'];
718         $baseurl = empty($ff->Pman['public_cache_url']) ? false : $ff->Pman['public_cache_url'];
719         
720         
721         $output = date('Y-m-d-H-i-s-', $maxtime). str_replace('/','.',$mod).'-'.md5(serialize($arfiles)) .'.js';
722         
723         // where are we going to write all of this..
724         // This has to be done via a 
725         if ( $compile && !file_exists($basedir.'/'.$output)) {
726             require_once 'Pman/Core/JsCompile.php';
727             $x = new Pman_Core_JsCompile();
728             
729             $x->pack($arfiles,$basedir.'/'.$output );
730         }
731         
732         if ($compile && file_exists($basedir.'/'.$output) && filesize($basedir.'/'.$output)) {
733             
734             return array(
735                 $baseurl.'/'. $output,
736                 $this->rootURL."/_translations_/". str_replace('/','.', $mod).".js"
737             );
738         }
739         
740         
741         
742         // give up and output original files...
743         $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
744         usort($files, $lsort);
745          
746         return $files;
747
748         
749     }
750     
751     
752     
753     /**
754      * ---------------- Logging ---------------   
755      */
756     
757     /**
758      * addEventOnce:
759      * Log an action (only if it has not been logged already.
760      * 
761      * @param {String} action  - group/name of event
762      * @param {DataObject|false} obj - dataobject action occured on.
763      * @param {String} any remarks 
764      */
765     
766     function addEventOnce($act, $obj = false, $remarks = '') 
767     {
768         $au = $this->getAuthUser();
769         $e = DB_DataObject::factory('Events');
770         $e->init($act,$obj,$remarks); 
771         if ($e->find(true)) {
772             return;
773         }
774         return $this->addEvent($act, $obj, $remarks);
775     }
776     /**
777      * addEvent:
778      * Log an action.
779      * 
780      * @param {String} action  - group/name of event
781      * @param {DataObject|false} obj - dataobject action occured on.
782      * @param {String} any remarks
783      * @return {Number} Event id.,
784      */
785     
786     function addEvent($act, $obj = false, $remarks = '') 
787     {
788         $au = $this->getAuthUser();
789         $e = DB_DataObject::factory('Events');
790         $e->init($act,$obj,$remarks); 
791          
792         $e->event_when = date('Y-m-d H:i:s');
793         
794         $eid = $e->insert();
795         $ff  = HTML_FlexyFramework::get();
796         if (empty($ff->Pman['event_log_dir'])) {
797             return $eid;
798         }
799         $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
800         if (!file_exists(dirname($file))) {
801             mkdir(dirname($file),0700,true);
802         }
803         file_put_contents($file, var_export(array(
804             'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
805             'GET' => empty($_GET) ? array() : $_GET,
806             'POST' => empty($_POST) ? array() : $_POST,
807         ), true));
808         
809         return $eid;
810         
811     }
812
813     
814      
815     
816 }