EventView.php
[Pman.Admin] / EventView.php
1 <?php
2
3
4 require_once 'Pman.php';
5
6 class Pman_Admin_EventView extends Pman
7 {
8     
9     function getAuth()
10     {
11         parent::getAuth();
12         $au = $this->getAuthUser();
13         if (!$au || $au->company()->comptype != 'OWNER') {
14             $this->jerrAuth();
15         }
16         return true;
17         
18         
19     }
20     
21     function get($id)
22     {
23         $ev = DB_DataObject::Factory('Events');
24         if (!$ev->get((int)$id)) {
25             $this->jerr("invalid id");
26         }
27         
28         // verify if not admin, then they should 
29         $g = DB_DataObject::Factory('group_members');
30         if (is_a($g, 'DB_DataObject')) {
31             $grps = $g->listGroupMembership($this->authUser);
32            //var_dump($grps);
33             $isAdmin = $g->inAdmin;
34             
35             if (!$isAdmin && $ev->person_id != $this->authUser->id) {
36                 $this->jerrAuth();
37             }
38         }
39         
40         echo htmlspecialchars(print_r($ev,true));
41         // we have 2 bits of data available at present:
42         // core_event_audit
43         // the event file..
44         $d= DB_DataObject::factory('core_event_audit');
45         if (is_a($d,'DB_DataObject')) {
46             echo "<H2>Changed Data:</H2>";
47             $d->event_id = $ev->id;
48             foreach($d->fetchAll() as $d) {
49                 echo "{$d->name} SET TO: " . htmlspecialchars($d->newvalue) . "<br/>\n";
50             }
51         }
52         echo "<HR><H2>Posted Data:</H2>";
53         
54         $ff  = HTML_FlexyFramework::get();
55         if (empty($ff->Pman['event_log_dir'])) {
56             echo "not available (not configured)";
57             exit;
58         }
59         if (function_exists('posix_getpwuid')) {
60             $uinfo = posix_getpwuid( posix_getuid () ); 
61          
62             $user = $uinfo['name'];
63         } else {
64             $user = getenv('USERNAME'); // windows.
65         }
66          
67         $file = $ff->Pman['event_log_dir']. "/{$user}" . date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".php"; 
68         if (file_exists($file)) {
69             echo '<PRE>' . htmlspecialchars(file_get_contents($file)). '</PRE>';
70             
71         } 
72           
73         $file = $ff->Pman['event_log_dir']. "/{$user}" . date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".json"; 
74         if (!file_exists($file)) {
75             echo "not available (missing file) $file";
76             exit;
77         }
78         echo '<PRE>' . htmlspecialchars(print_r(json_decode(file_get_contents($file)), true)) . '</PRE>';
79         
80         echo '<BR/><PRE>'. htmlspecialchars($ev->remarks) . '</PRE>';
81         
82         $filesJ = json_decode(file_get_contents($file));
83         echo '<br /><PRE>Download files</PRE>';
84         
85         
86         foreach($filesJ->FILES as $k=>$f){
87             $ip = $ff->baseURL."/Images/events/". $ev->id . '/'. $f->tmp_name;
88             echo '<a href="'.$ip.'/download">' . htmlspecialchars( $k . ' - ' . $f->name ) . '</a><br/>';
89         }
90         
91         
92         
93         exit;
94         
95     }
96     
97     
98 }