1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11require_once('tiki-setup.php');
12
13$access->check_feature('feature_banners');
14
15$bannerlib = TikiLib::lib('banner');
16
17if (! isset($_REQUEST["bannerId"])) {
18	$smarty->assign('msg', tra("No banner indicated"));
19	$smarty->display("error.tpl");
20	die;
21}
22$info = $bannerlib->get_banner($_REQUEST["bannerId"]);
23if (! $info) {
24	$smarty->assign('msg', tra("Banner not found"));
25	$smarty->display("error.tpl");
26	die;
27}
28// Check user is admin or the client
29if (($user != $info["client"]) && ($tiki_p_admin_banners != 'y')) {
30	$smarty->assign('errortype', 401);
31	$smarty->assign('msg', tra("You do not have permission to edit this banner"));
32	$smarty->display("error.tpl");
33	die;
34}
35$smarty->assign('bannerId', $info["bannerId"]);
36$smarty->assign('created', $info["created"]);
37$smarty->assign('client', $info["client"]);
38$smarty->assign('maxImpressions', $info["maxImpressions"]);
39$smarty->assign('maxClicks', $info["maxClicks"]);
40$impressions = $info["impressions"];
41$clicks = $info["clicks"];
42$smarty->assign('impressions', $impressions);
43$smarty->assign('clicks', $clicks);
44if ($impressions) {
45	$smarty->assign('ctr', ($clicks / $impressions) * 100);
46} else {
47	$smarty->assign('ctr', 0);
48}
49$smarty->assign('fromDate', $info["fromDate"]);
50$smarty->assign('toDate', $info["toDate"]);
51$smarty->assign('useDates', $info["useDates"]);
52$smarty->assign("fromTime_h", substr($info["hourFrom"], 0, 2));
53$smarty->assign("fromTime_m", substr($info["hourFrom"], 2, 2));
54$smarty->assign("toTime_h", substr($info["hourTo"], 0, 2));
55$smarty->assign("toTime_m", substr($info["hourTo"], 2, 2));
56$smarty->assign("Dmon", $info["mon"]);
57$smarty->assign("Dtue", $info["tue"]);
58$smarty->assign("Dwed", $info["wed"]);
59$smarty->assign("Dthu", $info["thu"]);
60$smarty->assign("Dfri", $info["fri"]);
61$smarty->assign("Dsat", $info["sat"]);
62$smarty->assign("Dsun", $info["sun"]);
63$smarty->assign("use", $info["which"]);
64$smarty->assign("zone", $info["zone"]);
65$smarty->assign("HTMLData", $info["HTMLData"]);
66$smarty->assign("fixedURLdata", $info["fixedURLData"]);
67$smarty->assign("textData", $info["textData"]);
68$smarty->assign("url", $info["url"]);
69$smarty->assign("imageName", $info["imageName"]);
70$smarty->assign("imageData", urlencode($info["imageData"]));
71$smarty->assign("imageType", $info["imageType"]);
72$smarty->assign("hasImage", 'n');
73if (strlen($info["imageData"]) > 0) {
74	$tmpfname = $prefs['tmpDir'] . "/bannerimage" . "." . $_REQUEST["bannerId"];
75	$fp = fopen($tmpfname, "wb");
76	if ($fp) {
77		fwrite($fp, $data);
78		fclose($fp);
79		$smarty->assign('tempimg', $tmpfname);
80		$smarty->assign('hasImage', 'y');
81	} else {
82		$smarty->assign('tempimg', 'n');
83		$smarty->assign('hasImage', 'n');
84	}
85}
86$bannerId = $info["bannerId"];
87$foo = parse_url($_SERVER["REQUEST_URI"]);
88$foo1 = str_replace("tiki-view_banner", "display_banner", $foo["path"]);
89$raw = '';
90if ($fp = @fopen($tikilib->httpPrefix() . $foo1 . "?id=$bannerId", "r")) {
91	while (! feof($fp)) {
92		$raw .= fread($fp, 8192);
93	}
94	fclose($fp);
95}
96$smarty->assign_by_ref('raw', $raw);
97ask_ticket('view-banner');
98$smarty->assign('mid', 'tiki-view_banner.tpl');
99$smarty->display("tiki.tpl");
100