diff --git a/tests/php/test_snapshot_event_links.php b/tests/php/test_snapshot_event_links.php
new file mode 100644
index 0000000000..d5d92a9668
--- /dev/null
+++ b/tests/php/test_snapshot_event_links.php
@@ -0,0 +1,116 @@
+id = $id;
+ $this->viewable = $viewable;
+ }
+ function Id() { return $this->id; }
+ function canView() { return $this->viewable; }
+ function getThumbnailSrc($args = array(), $querySep = '&') {
+ return '?view=image&eid='.$this->id.'&fid=snapshot';
+ }
+ }
+}
+
+namespace {
+ $root = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__.'/../../web';
+
+ // The view requires these; empty stubs keep the real classes out of the way.
+ $stubdir = sys_get_temp_dir().'/zm_snapshot_links_stubs_'.getmypid();
+ @mkdir($stubdir.'/includes', 0700, true);
+ foreach (array('Event', 'Filter', 'Snapshot') as $f) {
+ file_put_contents($stubdir.'/includes/'.$f.'.php', " '5');
+ $user = new StubUser();
+ $view = '';
+ ob_start();
+ include $root.'/skins/classic/views/snapshot.php';
+ return ob_get_clean();
+ }
+
+ $failures = 0;
+ function check($name, $got, $want) {
+ global $failures;
+ if ($got === $want) {
+ echo "ok - $name\n";
+ } else {
+ $failures++;
+ echo "FAIL - $name (got ".var_export($got, true).", want ".var_export($want, true).")\n";
+ }
+ }
+
+ $html = render_snapshot(array(new ZM\Event(11, true), new ZM\Event(12, true)));
+ check('viewable event 11 links to its event view',
+ strpos($html, '') !== false, true);
+ check('viewable event 12 links to its event view',
+ strpos($html, '') !== false, true);
+ check('event 11 thumbnail is still shown',
+ strpos($html, '?view=image&eid=11&fid=snapshot') !== false, true);
+ check('event 12 thumbnail is still shown',
+ strpos($html, '?view=image&eid=12&fid=snapshot') !== false, true);
+
+ $html = render_snapshot(array(new ZM\Event(21, true), new ZM\Event(22, false)));
+ check('viewable event 21 links to its event view',
+ strpos($html, '') !== false, true);
+ check('unviewable event 22 is not linked',
+ strpos($html, 'eid=22">') === false, true);
+ check('unviewable event 22 thumbnail is still shown',
+ strpos($html, '?view=image&eid=22&fid=snapshot') !== false, true);
+
+ @unlink($stubdir.'/includes/Event.php');
+ @unlink($stubdir.'/includes/Filter.php');
+ @unlink($stubdir.'/includes/Snapshot.php');
+ @rmdir($stubdir.'/includes');
+ @rmdir($stubdir);
+ exit($failures ? 1 : 0);
+}
diff --git a/web/skins/classic/views/snapshot.php b/web/skins/classic/views/snapshot.php
index 312a382813..bd1bcabd0c 100644
--- a/web/skins/classic/views/snapshot.php
+++ b/web/skins/classic/views/snapshot.php
@@ -33,10 +33,6 @@ require_once('includes/Snapshot.php');
$id = isset($_REQUEST['id']) ? validInt($_REQUEST['id']) : null;
$snapshot = new ZM\Snapshot($id);
-$monitors = array();
-if ( count($user->unviewableMonitorIds())) {
- $monitor_ids = $user->viewableMonitorIds();
-}
xhtmlHeaders(__FILE__, translate('Snapshot').' '.$snapshot->Id());
getBodyTopHTML();
echo getNavBarHTML();
@@ -91,7 +87,13 @@ if ( !$snapshot->Id() ) {
$width = 100 / ( count($events) < 2 ? 1 : ( ( count($events) < 4 ) ? count($events) : 4 ) )-1;
foreach ( $snapshot->Events() as $event ) {
$imgSrc = $event->getThumbnailSrc(array(), '&');
- echo '
';
+ $eid = validInt($event->Id());
+ $img = '
';
+ if ( $event->canView() ) {
+ echo ''.$img.'';
+ } else {
+ echo $img;
+ }
}
?>