tiki-edit_banner.php 11 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
10

rjsmelo's avatar
rjsmelo committed
11
require_once('tiki-setup.php');
12

13
$tikilib = TikiLib::lib('tiki');
14
$bannerlib = TikiLib::lib('banner');
15

16 17
$access->check_feature('feature_banners');
$access->check_permission('tiki_p_admin_banners');
18
//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
19
$userprefslib = TikiLib::lib('userprefs');
20
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
21

22 23 24
if (isset($_REQUEST["bannerId"]) && $_REQUEST["bannerId"] > 0) {
	$info = $bannerlib->get_banner($_REQUEST["bannerId"]);

rjsmelo's avatar
rjsmelo committed
25
	if (! $info) {
26 27
		$smarty->assign('msg', tra("Banner not found"));

28
		$smarty->display("error.tpl");
29 30 31 32 33
		die;
	}

	// Check user is admin or the client
	if (($user != $info["client"]) && ($tiki_p_admin_banners != 'y')) {
34
		$smarty->assign('errortype', 401);
35
		$smarty->assign('msg', tra("You do not have permission to edit this banner"));
36

37
		$smarty->display("error.tpl");
38 39 40
		die;
	}

rjsmelo's avatar
rjsmelo committed
41 42
	$fromTime = substr($info["hourFrom"], 0, 2) . ":" . substr($info["hourFrom"], 2, 2);
	$toTime = substr($info["hourTo"], 0, 2) . ":" . substr($info["hourTo"], 2, 2);
43 44 45
	$smarty->assign('bannerId', $info["bannerId"]);
	$smarty->assign('client', $info["client"]);
	$smarty->assign('maxImpressions', $info["maxImpressions"]);
46
	$smarty->assign('maxUserImpressions', $info["maxUserImpressions"]);
47
	$smarty->assign('maxClicks', $info["maxClicks"]);
48 49 50
	$smarty->assign('fromDate', $info["fromDate"]);
	$smarty->assign('toDate', $info["toDate"]);
	$smarty->assign('useDates', $info["useDates"]);
51 52
	$smarty->assign("fromTime", $fromTime);
	$smarty->assign("toTime", $toTime);
53 54 55 56 57 58 59 60
	$smarty->assign("Dmon", $info["mon"]);
	$smarty->assign("Dtue", $info["tue"]);
	$smarty->assign("Dwed", $info["wed"]);
	$smarty->assign("Dthu", $info["thu"]);
	$smarty->assign("Dfri", $info["fri"]);
	$smarty->assign("Dsat", $info["sat"]);
	$smarty->assign("Dsun", $info["sun"]);
	$smarty->assign("use", $info["which"]);
61
	$smarty->assign('onlyInURIs', $info['onlyInURIs']);
62
	$smarty->assign('exceptInURIs', $info['exceptInURIs']);
63
	$smarty->assign("zone", $info["zone"]);
64
	if ($info["which"] == 'useFlash') {
65 66
		$movie = unserialize($info['HTMLData']);
		$smarty->assign_by_ref('movie', $movie);
67
	}
68
	$smarty->assign("HTMLData", $info["HTMLData"]);
sylvieg's avatar
sylvieg committed
69
	$smarty->assign("fixedURLData", $info["fixedURLData"]);
70 71 72 73 74 75 76 77
	$smarty->assign("textData", $info["textData"]);
	$smarty->assign("url", $info["url"]);
	$smarty->assign("imageName", $info["imageName"]);
	$smarty->assign("imageData", urlencode($info["imageData"]));
	$smarty->assign("imageType", $info["imageType"]);
	$smarty->assign("hasImage", 'n');

	if (strlen($info["imageData"]) > 0) {
78
		$tmpfname = $prefs['tmpDir'] . "/bannerimage" . "." . $_REQUEST["bannerId"];
79 80
		$fp = fopen($tmpfname, "wb");
		if ($fp) {
dheltzel's avatar
dheltzel committed
81
			fwrite($fp, $data);
82
			fclose($fp);
83 84 85
			$smarty->assign('tempimg', $tmpfname);
			$smarty->assign('hasImage', 'y');
		} else {
dheltzel's avatar
dheltzel committed
86
			$smarty->assign('tempimg', 'n');
87 88 89
			$smarty->assign('hasImage', 'n');
		}
	}
90
} else {
91
	$smarty->assign('client', '');
92
	$smarty->assign('maxImpressions', -1);
93
	$smarty->assign('maxUserImpressions', -1);
94
	$smarty->assign('maxClicks', -1);
mose's avatar
mose committed
95
	$smarty->assign('fromDate', $tikilib->now);
96
	$cur_time = explode(',', $tikilib->date_format('%Y,%m,%d,%H,%M,%S', $publishDate));
rjsmelo's avatar
rjsmelo committed
97
	$smarty->assign('toDate', $tikilib->make_time($cur_time[3], $cur_time[4], $cur_time[5], $cur_time[1], $cur_time[2], $cur_time[0] + 1));
98
	$smarty->assign('useDates', 'n');
99 100
	$smarty->assign('fromTime', '00:00');
	$smarty->assign('toTime', '23:59');
101 102 103 104 105 106 107 108 109 110
	// Variables for dates are fromDate_ and toDate_ plus fromTime_ and toTime_
	$smarty->assign('Dmon', 'y');
	$smarty->assign('Dtue', 'y');
	$smarty->assign('Dwed', 'y');
	$smarty->assign('Dthu', 'y');
	$smarty->assign('Dfri', 'y');
	$smarty->assign('Dsat', 'y');
	$smarty->assign('Dsun', 'y');
	$smarty->assign('bannerId', 0);
	$smarty->assign('zone', '');
sylvieg's avatar
sylvieg committed
111
	$smarty->assign('onlyInURIS', '');
112
	$smarty->assign('exceptInURIS', '');
113 114 115 116 117 118 119 120 121
	$smarty->assign('use', 'useHTML');
	$smarty->assign('HTMLData', '');
	$smarty->assign('fixedURLData', '');
	$smarty->assign('textData', '');
	$smarty->assign('url', '');
	$smarty->assign('imageData', '');
	$smarty->assign('hasImage', 'n');
	$smarty->assign('imageName', '');
	$smarty->assign('imageType', '');
122 123
}

124
if (isset($_REQUEST["removeZone"])) {
125 126
	$access->check_authenticity();
	$bannerlib->banner_remove_zone($_REQUEST["removeZone"]);
127 128 129
}

// Now assign if the set button was pressed
130
if (isset($_REQUEST["save"]) || isset($_REQUEST["create_zone"])) {
131
	check_ticket('edit-banner');
132
	//Convert 12-hour clock hours to 24-hour scale to compute time
rjsmelo's avatar
rjsmelo committed
133
	if (! empty($_REQUEST['fromTimeMeridian'])) {
134 135
		$_REQUEST['fromTimeHour'] = date('H', strtotime($_REQUEST['fromTimeHour'] . ':00 ' . $_REQUEST['fromTimeMeridian']));
	}
rjsmelo's avatar
rjsmelo committed
136
	if (! empty($_REQUEST['toTimeMeridian'])) {
137 138
		$_REQUEST['toTimeHour'] = date('H', strtotime($_REQUEST['toTimeHour'] . ':00 ' . $_REQUEST['toTimeMeridian']));
	}
139 140
	$fromDate = mktime(0, 0, 0, $_REQUEST["fromDate_Month"], $_REQUEST["fromDate_Day"], $_REQUEST["fromDate_Year"]);
	$toDate = mktime(0, 0, 0, $_REQUEST["toDate_Month"], $_REQUEST["toDate_Day"], $_REQUEST["toDate_Year"]);
rjsmelo's avatar
rjsmelo committed
141 142
	$fromTime = '' . $_REQUEST["fromTimeHour"] . $_REQUEST["fromTimeMinute"] . '';
	$toTime = '' . $_REQUEST["toTimeHour"] . $_REQUEST["toTimeMinute"] . '';
143 144
	$smarty->assign('fromDate', $fromDate);
	$smarty->assign('toDate', $toDate);
rjsmelo's avatar
rjsmelo committed
145 146
	$smarty->assign('fromTime', $_REQUEST["fromTimeHour"] . ':' . $_REQUEST["fromTimeMinute"]);
	$smarty->assign('toTime', $_REQUEST["toTimeHour"] . ':' . $_REQUEST["toTimeMinute"]);
147 148
	$smarty->assign('client', $_REQUEST["client"]);
	$smarty->assign('maxImpressions', $_REQUEST["maxImpressions"]);
149
	$smarty->assign('maxUserImpressions', $_REQUEST["maxUserImpressions"]);
150
	$smarty->assign('maxClicks', $_REQUEST["maxClicks"]);
151 152 153
	$smarty->assign('HTMLData', $_REQUEST["HTMLData"]);
	$smarty->assign('fixedURLData', $_REQUEST["fixedURLData"]);
	$smarty->assign('textData', $_REQUEST["textData"]);
154

155 156 157 158 159
	if (isset($_REQUEST["zone"])) {
		$smarty->assign('zone', $_REQUEST["zone"]);
	} else {
		$smarty->assign('zone', '');
	}
160
	$smarty->assign('onlyInURIs', $_REQUEST['onlyInURIs']);
161
	$smarty->assign('exceptInURIs', $_REQUEST['exceptInURIs']);
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
	$smarty->assign('url', $_REQUEST["url"]);

	if (isset($_REQUEST["use"])) {
		$smarty->assign('use', $_REQUEST["use"]);
	}

	if (isset($_REQUEST["useDates"]) && $_REQUEST["useDates"] == 'on') {
		$smarty->assign('useDates', 'y');

		$useDates = 'y';
	} else {
		$smarty->assign('useDates', 'n');

		$useDates = 'n';
	}

	if (isset($_REQUEST["Dmon"]) && $_REQUEST["Dmon"] == 'on') {
		$smarty->assign('Dmon', 'y');

		$Dmon = 'y';
	} else {
		$smarty->assign('Dmon', 'n');

		$Dmon = 'n';
	}

	if (isset($_REQUEST["Dtue"]) && $_REQUEST["Dtue"] == 'on') {
		$smarty->assign('Dtue', 'y');

		$Dtue = 'y';
	} else {
		$smarty->assign('Dtue', 'n');

		$Dtue = 'n';
	}
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
	if (isset($_REQUEST["Dwed"]) && $_REQUEST["Dwed"] == 'on') {
		$smarty->assign('Dwed', 'y');

		$Dwed = 'y';
	} else {
		$smarty->assign('Dwed', 'n');

		$Dwed = 'n';
	}

	if (isset($_REQUEST["Dthu"]) && $_REQUEST["Dthu"] == 'on') {
		$smarty->assign('Dthu', 'y');

		$Dthu = 'y';
	} else {
		$smarty->assign('Dthu', 'n');

		$Dthu = 'n';
	}

	if (isset($_REQUEST["Dfri"]) && $_REQUEST["Dfri"] == 'on') {
		$smarty->assign('Dfri', 'y');

		$Dfri = 'y';
	} else {
		$smarty->assign('Dfri', 'n');

		$Dfri = 'n';
	}

	if (isset($_REQUEST["Dsat"]) && $_REQUEST["Dsat"] == 'on') {
		$smarty->assign('Dsat', 'y');

		$Dsat = 'y';
	} else {
		$smarty->assign('Dsat', 'n');

		$Dsat = 'n';
	}

	if (isset($_REQUEST["Dsun"]) && $_REQUEST["Dsun"] == 'on') {
		$smarty->assign('Dsun', 'y');

		$Dsun = 'y';
	} else {
		$smarty->assign('Dsun', 'n');

		$Dsun = 'n';
	}

	$smarty->assign('bannerId', $_REQUEST["bannerId"]);

	if (isset($_REQUEST["create_zone"])) {
		$bannerlib->banner_add_zone($_REQUEST["zoneName"]);
	}

	// If we have an upload then process the upload and setup the data in a field
	// that will be hidden is this is a nightmare?
	$imgname = $_REQUEST["imageName"];
	$imgtype = $_REQUEST["imageType"];

	if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
260 261
		$filegallib = TikiLib::lib('filegal');
		try {
262
			$filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
263 264 265 266 267 268
		} catch (Exception $e) {
			$smarty->assign('errortype', 403);
			$smarty->assign('msg', $e->getMessage());
			$smarty->display("error.tpl");
			die;
		}
269 270 271
		$fp = fopen($_FILES['userfile1']['tmp_name'], "rb");

		$data = fread($fp, filesize($_FILES['userfile1']['tmp_name']));
272
		fclose($fp);
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
		$imgtype = $_FILES['userfile1']['type'];
		$imgsize = $_FILES['userfile1']['size'];
		$imgname = $_FILES['userfile1']['name'];
		$smarty->assign('imageData', urlencode($data));
		$smarty->assign('imageName', $imgname);
		$smarty->assign('imageType', $imgtype);
		$_REQUEST["imageData"] = urlencode($data);
		$_REQUEST["imageName"] = $imgname;
		$_REQUEST["imageType"] = $imgtype;
	}

	$smarty->assign('imageData', $_REQUEST["imageData"]);
	$smarty->assign('tempimg', 'n');

	if (strlen($_REQUEST["imageData"]) > 0) {
rjsmelo's avatar
rjsmelo committed
288
		$tmpfname = tempnam($prefs['tmpDir'], "TMPIMG") . $imgname;
289 290 291 292 293 294

		$fp = fopen($tmpfname, "w");

		if ($fp) {
			fwrite($fp, urldecode($_REQUEST["imageData"]));

295
			fclose($fp);
296 297 298 299 300 301 302
			$smarty->assign('tempimg', $tmpfname);
			$smarty->assign('hasImage', 'y');
		} else {
			$smarty->assign('hasImage', 'n');
		}
	}

rjsmelo's avatar
rjsmelo committed
303
	if (! isset($_REQUEST["create_zone"])) {
304
		if ($_REQUEST["use"] == "useFlash") {
rjsmelo's avatar
rjsmelo committed
305
			$params = [
306 307 308 309
						  'width' => 425,
						  'height' => 350,
						  'quality' => 'high',
						  'version' => '9.0.0',
rjsmelo's avatar
rjsmelo committed
310
						  ];
311
			$params['movie'] = $_REQUEST['movieUrl'];
rjsmelo's avatar
rjsmelo committed
312 313 314 315 316 317 318 319 320
			if (! empty($_REQUEST['movieWidth'])) {
				$params['width'] = $_REQUEST['movieWidth'];
			}
			if (! empty($_REQUEST['movieHeight'])) {
				$params['height'] = $_REQUEST['movieHeight'];
			}
			if (! empty($_REQUEST['movieVersion'])) {
				$params['version'] = $_REQUEST['movieVersion'];
			}
321
			$_REQUEST['HTMLData'] = serialize($params);
322
		}
323
		$bannerId = $bannerlib->replace_banner(
324 325
			$_REQUEST["bannerId"],
			$_REQUEST["client"],
rjsmelo's avatar
rjsmelo committed
326 327
			$_REQUEST["url"],
			'',
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
			'',
			$_REQUEST["use"],
			$_REQUEST["imageData"],
			$_REQUEST["imageType"],
			$_REQUEST["imageName"],
			$_REQUEST["HTMLData"],
			$_REQUEST["fixedURLData"],
			$_REQUEST["textData"],
			$fromDate,
			$toDate,
			$useDates,
			$Dmon,
			$Dtue,
			$Dwed,
			$Dthu,
			$Dfri,
			$Dsat,
			$Dsun,
			$fromTime,
			$toTime,
			$_REQUEST["maxImpressions"],
			$_REQUEST["maxClicks"],
			$_REQUEST["zone"],
			$_REQUEST["maxUserImpressions"],
			$_REQUEST['onlyInURIs'],
			$_REQUEST['exceptInURIs']
354
		);
355

356
		header("location:tiki-list_banners.php");
357 358 359 360 361
	}
}

$zones = $bannerlib->banner_get_zones();
$smarty->assign_by_ref('zones', $zones);
362

363
ask_ticket('edit-banner');
364

365 366 367
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

368
// Display the template
369
$smarty->assign('mid', 'tiki-edit_banner.tpl');
370
$smarty->display("tiki.tpl");