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     
624     /**
625      *  moduleJavascriptList: list the javascript files in a module
626      *
627      *  The original version of this.. still needs more thought...
628      *
629      *  Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js
630      *  Translations are in Pman/_translations_/{$mod}.js
631      *  
632      *  if that stuff does not exist just list files in  Pman/{$mod}/*.js
633      *
634      *  Compiled could be done on the fly..
635      * 
636      *
637      *
638      *  @param {String} $mod  the module to look at - eg. Pman/{$mod}/*.js
639      *  @return {Array} list of include paths (either compiled or raw)
640      *
641      */
642
643     
644     
645     function moduleJavascriptList($mod)
646     {
647         
648         $ff = HTML_FlexyFramework::get();
649         
650         $dir =   $this->rootDir.'/Pman/'. $mod;
651             
652         $path =    $this->rootURL."/Pman/$mod/";
653         $base = dirname($_SERVER['SCRIPT_FILENAME']);
654         $cfile = realpath($base .'/_compiled_/' . $mod);
655         $lfile = realpath($base .'/_translations_/' . $mod .  '.js');
656         //    var_dump($cfile);
657         if (!file_exists($dir)) {
658         
659             return array();
660         }
661         $maxtime = 0;
662         $ctime = 0;
663         $files = array();
664         
665         // compiled directory exists...
666         if (file_exists($cfile)) {
667            // $ctime = max(filemtime($cfile), filectime($cfile));
668             // otherwise use compile dfile..
669             $maxm = 0;
670             $ar = glob($cfile . '/' . $mod . '*.js');
671             // default to first..
672             $cfile = basename($ar[count($ar) -1]);
673             foreach($ar as $fn) {
674                 if (filemtime($fn) > $maxm) {
675                     $cfile = basename($fn);
676                     $maxm = filemtime($fn);
677                 }
678             }
679             
680              
681             $files = array( $this->rootURL. "/_compiled_/".$mod . "/" . $cfile);
682             if (file_exists($lfile)) {
683                 array_push($files, $this->rootURL."/_translations_/$mod.js");
684             }
685             return $files;
686         }
687         // works out if stuff has been updated..
688         // technically the non-dev version should output compiled only?!!?
689         $ar = glob($dir . '/*.js');
690         
691         foreach($ar as $fn) {
692             $f = basename($fn);
693             // got the 'module file..'
694             $mtime = filemtime($dir . '/'. $f);
695             $maxtime = max($mtime, $maxtime);
696             $arfiles[$mtime] = $fn;
697             $files[] = $path . $f . '?ts='.$mtime;
698         }
699         
700         if (empty($files)) {
701             return $files;
702         }
703         // finally sort the files, so they are in the right order..
704         
705         // only compile this stuff if public_cache is set..
706         
707         $compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
708         
709         // suggestions...
710         //  public_cache_dir =   /var/www/myproject_cache
711         //  public_cache_url =   /myproject_cache    (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
712        
713         $basedir = $ff->Pman['public_cache_dir'];
714         $baseurl = $ff->Pman['public_cache_url'];
715         
716         
717         $output = date('Y-m-d-H-i-s-').$mod.'-'.md5(serialize($arfiles)) .'.js';
718         
719         // where are we going to write all of this..
720         // This has to be done via a 
721         if ( $compile && !file_exists($basedir.'/'.$output)) {
722             $this->pack($arfiles,$basedir.'/'.$output);
723         }
724         
725         if ($compile && file_exists($basedir.'/_cache_/'.$output)) {
726             
727             return array(
728                 $baseurl.'/'. $output,
729                 $this->rootURL."/_translations_/$mod.js"
730             );
731         }
732         
733         
734         
735         // give up and output original files...
736         $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
737         usort($files, $lsort);
738          
739         return $files;
740
741         
742     }
743     
744     
745     
746     /**
747      * ---------------- Logging ---------------   
748      */
749     
750     /**
751      * addEventOnce:
752      * Log an action (only if it has not been logged already.
753      * 
754      * @param {String} action  - group/name of event
755      * @param {DataObject|false} obj - dataobject action occured on.
756      * @param {String} any remarks 
757      */
758     
759     function addEventOnce($act, $obj = false, $remarks = '') 
760     {
761         $au = $this->getAuthUser();
762         $e = DB_DataObject::factory('Events');
763         $e->init($act,$obj,$remarks); 
764         if ($e->find(true)) {
765             return;
766         }
767         return $this->addEvent($act, $obj, $remarks);
768     }
769     /**
770      * addEvent:
771      * Log an action.
772      * 
773      * @param {String} action  - group/name of event
774      * @param {DataObject|false} obj - dataobject action occured on.
775      * @param {String} any remarks
776      * @return {Number} Event id.,
777      */
778     
779     function addEvent($act, $obj = false, $remarks = '') 
780     {
781         $au = $this->getAuthUser();
782         $e = DB_DataObject::factory('Events');
783         $e->init($act,$obj,$remarks); 
784          
785         $e->event_when = date('Y-m-d H:i:s');
786         
787         $eid = $e->insert();
788         $ff  = HTML_FlexyFramework::get();
789         if (empty($ff->Pman['event_log_dir'])) {
790             return $eid;
791         }
792         $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
793         if (!file_exists(dirname($file))) {
794             mkdir(dirname($file),0700,true);
795         }
796         file_put_contents($file, var_export(array(
797             'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
798             'GET' => empty($_GET) ? array() : $_GET,
799             'POST' => empty($_POST) ? array() : $_POST,
800         ), true));
801         
802         return $eid;
803         
804     }
805
806     
807      
808     
809 }