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, $opts = Array())
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('core_group_member');
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         
41         echo '<PRE>'.htmlspecialchars(print_r($ev->toArray(),true))."</PRE>";
42         // we have 2 bits of data available at present:
43         // core_event_audit
44         // the event file..
45         $d= DB_DataObject::factory('core_event_audit');
46         $d->event_id = $ev->id; // we can set that as the above returns error or dataobject..
47         if (is_a($d,'DB_DataObject') && $d->count()) {
48             echo "<H2>Changed Data:</H2>";
49             
50             foreach($d->fetchAll() as $d) {
51                 echo "{$d->name} SET TO: " . htmlspecialchars($d->newvalue) . "<br/>\n";
52             }
53         }
54         echo "<HR><H2>Posted Data:</H2>";
55         
56         $logdir = DB_DAtaObject::Factory('Events')->logDir();
57         
58         if (!$logdir) {
59             echo "not available (Pman[storedir] not configured)";
60             exit;
61         }
62          
63         $file = $logdir. date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".php"; 
64         if (file_exists($file)) {
65             echo '<PRE>' . htmlspecialchars(file_get_contents($file)). '</PRE>';
66             
67         } 
68           
69         $file = $logdir. date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".json"; 
70         if (!file_exists($file)) {
71             echo "not available (missing file) $file";
72             exit;
73         }
74         
75         echo '<PRE>' . htmlspecialchars(print_r(json_decode(file_get_contents($file)), true)) . '</PRE>';
76         
77         if (!empty($ev->remarks)) {
78             echo "<HR><H2>Remarks:</H2>";
79             echo '<BR/><PRE>'. htmlspecialchars($ev->remarks) . '</PRE>';
80         }
81         
82         
83         $json = json_decode($ev->remarks, JSON_PRETTY_PRINT);
84         
85         if(json_last_error() == JSON_ERROR_NONE){
86             echo "<HR><H2>JSON DECODE Data:</H2>";
87             echo '<PRE>' . print_r($json, true) . '</PRE>';
88         }
89         
90         if (!empty($filesJ->FILES )) {
91             $filesJ = json_decode(file_get_contents($file));
92             echo '<br /><PRE>Download files</PRE>';
93             
94             
95             foreach($filesJ->FILES as $k=>$f){
96                 $ip = $this->baseURL."/Images/events/". $ev->id . '/'. $f->tmp_name;
97                 echo '<a target="_new" href="'.$ip.'/download">' . htmlspecialchars( $k . ' - ' . $f->name ) . '</a><br/>';
98             }
99             
100         }
101         
102         
103         exit;
104         
105     }
106     
107     
108 }