sync
[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     function get($id, $opts = Array())
21     {   
22         $ev = DB_DataObject::Factory('Events');
23         if (!$ev->get((int)$id)) {
24             $this->jerr("invalid id");
25         }
26         
27         // verify if not admin, then they should 
28         $g = DB_DataObject::Factory('core_group_member');
29         if (is_a($g, 'DB_DataObject')) {
30             $grps = $g->listGroupMembership($this->authUser);
31            //var_dump($grps);
32             $isAdmin = $g->inAdmin;
33             
34             if (!$isAdmin && $ev->person_id != $this->authUser->id) {
35                 $this->jerrAuth();
36             }
37         }
38         
39         
40         echo '<PRE>'.htmlspecialchars(print_r($ev->toArray(),true))."</PRE>";
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         $d->event_id = $ev->id; // we can set that as the above returns error or dataobject..
46         if (is_a($d,'DB_DataObject') && $d->count()) {
47             echo "<H2>Changed Data:</H2>";
48             
49             foreach($d->fetchAll() as $d) {
50                 echo "{$d->name} SET TO: " . htmlspecialchars($d->newvalue) . "<br/>\n";
51             }
52         }
53         echo "<HR><H2>Posted Data:</H2>";
54         
55         $logdir = DB_DAtaObject::Factory('Events')->logDir();
56         
57         if (!$logdir) {
58             echo "not available (Pman[storedir] not configured)";
59             exit;
60         }
61          
62         $file = $logdir. date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".php"; 
63         if (file_exists($file)) {
64             echo '<PRE>' . htmlspecialchars(file_get_contents($file)). '</PRE>';
65             
66         } 
67           
68         $file = $logdir. date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".json"; 
69         if (!file_exists($file)) {
70             echo "not available (missing file) $file";
71             exit;
72         }
73         
74         echo '<PRE>' . htmlspecialchars(print_r(json_decode(file_get_contents($file)), true)) . '</PRE>';
75         
76         if (!empty($ev->remarks)) {
77             echo "<HR><H2>Remarks:</H2>";
78             echo '<PRE>'. htmlspecialchars($ev->remarks) . '</PRE>';
79         }
80         
81         
82         $json = json_decode($ev->remarks, JSON_PRETTY_PRINT);
83         
84         if(json_last_error() == JSON_ERROR_NONE){
85             echo "<HR><H2>JSON DECODE Data:</H2>";
86             echo '<PRE>' . print_r($json, true) . '</PRE>';
87         }
88         $filesJ = json_decode(file_get_contents($file));
89         if (!empty($filesJ->FILES )) {
90              echo "<HR><H2>Download files:</H2><ul>";
91             
92             
93             foreach($filesJ->FILES as $k=>$f){
94                 $ip = $this->baseURL."/Images/events/". $ev->id . '/'. $f->tmp_name;
95                 
96                 echo '<li><a target="_new" href="'.$ip.'/download">' . htmlspecialchars( $k . ' - ' . $f->name ) . '</a><br/>';
97             }
98             echo "</ul>";
99             
100         }
101         
102         
103         exit;
104         
105     }
106     
107     
108 }