PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tiki-edit_banner.php

https://gitlab.com/ElvisAns/tiki
PHP | 372 lines | 299 code | 56 blank | 17 comment | 65 complexity | 40613876ad7b507ce4d943f18f718553 MD5 | raw file
  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. require_once('tiki-setup.php');
  11. $tikilib = TikiLib::lib('tiki');
  12. $bannerlib = TikiLib::lib('banner');
  13. $access->check_feature('feature_banners');
  14. $access->check_permission('tiki_p_admin_banners');
  15. //Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
  16. $userprefslib = TikiLib::lib('userprefs');
  17. $smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
  18. if (isset($_REQUEST["bannerId"]) && $_REQUEST["bannerId"] > 0) {
  19. $info = $bannerlib->get_banner($_REQUEST["bannerId"]);
  20. if (! $info) {
  21. $smarty->assign('msg', tra("Banner not found"));
  22. $smarty->display("error.tpl");
  23. die;
  24. }
  25. // Check user is admin or the client
  26. if (($user != $info["client"]) && ($tiki_p_admin_banners != 'y')) {
  27. $smarty->assign('errortype', 401);
  28. $smarty->assign('msg', tra("You do not have permission to edit this banner"));
  29. $smarty->display("error.tpl");
  30. die;
  31. }
  32. $fromTime = substr($info["hourFrom"], 0, 2) . ":" . substr($info["hourFrom"], 2, 2);
  33. $toTime = substr($info["hourTo"], 0, 2) . ":" . substr($info["hourTo"], 2, 2);
  34. $smarty->assign('bannerId', $info["bannerId"]);
  35. $smarty->assign('client', $info["client"]);
  36. $smarty->assign('maxImpressions', $info["maxImpressions"]);
  37. $smarty->assign('maxUserImpressions', $info["maxUserImpressions"]);
  38. $smarty->assign('maxClicks', $info["maxClicks"]);
  39. $smarty->assign('fromDate', $info["fromDate"]);
  40. $smarty->assign('toDate', $info["toDate"]);
  41. $smarty->assign('useDates', $info["useDates"]);
  42. $smarty->assign("fromTime", $fromTime);
  43. $smarty->assign("toTime", $toTime);
  44. $smarty->assign("Dmon", $info["mon"]);
  45. $smarty->assign("Dtue", $info["tue"]);
  46. $smarty->assign("Dwed", $info["wed"]);
  47. $smarty->assign("Dthu", $info["thu"]);
  48. $smarty->assign("Dfri", $info["fri"]);
  49. $smarty->assign("Dsat", $info["sat"]);
  50. $smarty->assign("Dsun", $info["sun"]);
  51. $smarty->assign("use", $info["which"]);
  52. $smarty->assign('onlyInURIs', $info['onlyInURIs']);
  53. $smarty->assign('exceptInURIs', $info['exceptInURIs']);
  54. $smarty->assign("zone", $info["zone"]);
  55. if ($info["which"] == 'useFlash') {
  56. $movie = unserialize($info['HTMLData']);
  57. $smarty->assign_by_ref('movie', $movie);
  58. }
  59. $smarty->assign("HTMLData", $info["HTMLData"]);
  60. $smarty->assign("fixedURLData", $info["fixedURLData"]);
  61. $smarty->assign("textData", $info["textData"]);
  62. $smarty->assign("url", $info["url"]);
  63. $smarty->assign("imageName", $info["imageName"]);
  64. $smarty->assign("imageData", urlencode($info["imageData"]));
  65. $smarty->assign("imageType", $info["imageType"]);
  66. $smarty->assign("hasImage", 'n');
  67. if (strlen($info["imageData"]) > 0) {
  68. $tmpfname = $prefs['tmpDir'] . "/bannerimage" . "." . $_REQUEST["bannerId"];
  69. $fp = fopen($tmpfname, "wb");
  70. if ($fp) {
  71. fwrite($fp, $data);
  72. fclose($fp);
  73. $smarty->assign('tempimg', $tmpfname);
  74. $smarty->assign('hasImage', 'y');
  75. } else {
  76. $smarty->assign('tempimg', 'n');
  77. $smarty->assign('hasImage', 'n');
  78. }
  79. }
  80. } else {
  81. $smarty->assign('client', '');
  82. $smarty->assign('maxImpressions', -1);
  83. $smarty->assign('maxUserImpressions', -1);
  84. $smarty->assign('maxClicks', -1);
  85. $smarty->assign('fromDate', $tikilib->now);
  86. $cur_time = explode(',', $tikilib->date_format('%Y,%m,%d,%H,%M,%S', $publishDate));
  87. $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));
  88. $smarty->assign('useDates', 'n');
  89. $smarty->assign('fromTime', '00:00');
  90. $smarty->assign('toTime', '23:59');
  91. // Variables for dates are fromDate_ and toDate_ plus fromTime_ and toTime_
  92. $smarty->assign('Dmon', 'y');
  93. $smarty->assign('Dtue', 'y');
  94. $smarty->assign('Dwed', 'y');
  95. $smarty->assign('Dthu', 'y');
  96. $smarty->assign('Dfri', 'y');
  97. $smarty->assign('Dsat', 'y');
  98. $smarty->assign('Dsun', 'y');
  99. $smarty->assign('bannerId', 0);
  100. $smarty->assign('zone', '');
  101. $smarty->assign('onlyInURIS', '');
  102. $smarty->assign('exceptInURIS', '');
  103. $smarty->assign('use', 'useHTML');
  104. $smarty->assign('HTMLData', '');
  105. $smarty->assign('fixedURLData', '');
  106. $smarty->assign('textData', '');
  107. $smarty->assign('url', '');
  108. $smarty->assign('imageData', '');
  109. $smarty->assign('hasImage', 'n');
  110. $smarty->assign('imageName', '');
  111. $smarty->assign('imageType', '');
  112. }
  113. if (isset($_REQUEST["removeZone"])) {
  114. $access->checkCsrf(tra("Do you want to delete this zone")." ?");
  115. $bannerlib->banner_remove_zone($_REQUEST["removeZone"]);
  116. }
  117. // Now assign if the set button was pressed
  118. if (isset($_REQUEST["save"]) || isset($_REQUEST["create_zone"])) {
  119. check_ticket('edit-banner');
  120. //Convert 12-hour clock hours to 24-hour scale to compute time
  121. if (! empty($_REQUEST['fromTimeMeridian'])) {
  122. $_REQUEST['fromTimeHour'] = date('H', strtotime($_REQUEST['fromTimeHour'] . ':00 ' . $_REQUEST['fromTimeMeridian']));
  123. }
  124. if (! empty($_REQUEST['toTimeMeridian'])) {
  125. $_REQUEST['toTimeHour'] = date('H', strtotime($_REQUEST['toTimeHour'] . ':00 ' . $_REQUEST['toTimeMeridian']));
  126. }
  127. $fromDate = mktime(0, 0, 0, $_REQUEST["fromDate_Month"], $_REQUEST["fromDate_Day"], $_REQUEST["fromDate_Year"]);
  128. $toDate = mktime(0, 0, 0, $_REQUEST["toDate_Month"], $_REQUEST["toDate_Day"], $_REQUEST["toDate_Year"]);
  129. $fromTime = '' . $_REQUEST["fromTimeHour"] . $_REQUEST["fromTimeMinute"] . '';
  130. $toTime = '' . $_REQUEST["toTimeHour"] . $_REQUEST["toTimeMinute"] . '';
  131. $smarty->assign('fromDate', $fromDate);
  132. $smarty->assign('toDate', $toDate);
  133. $smarty->assign('fromTime', $_REQUEST["fromTimeHour"] . ':' . $_REQUEST["fromTimeMinute"]);
  134. $smarty->assign('toTime', $_REQUEST["toTimeHour"] . ':' . $_REQUEST["toTimeMinute"]);
  135. $smarty->assign('client', $_REQUEST["client"]);
  136. $smarty->assign('maxImpressions', $_REQUEST["maxImpressions"]);
  137. $smarty->assign('maxUserImpressions', $_REQUEST["maxUserImpressions"]);
  138. $smarty->assign('maxClicks', $_REQUEST["maxClicks"]);
  139. $smarty->assign('HTMLData', $_REQUEST["HTMLData"]);
  140. $smarty->assign('fixedURLData', $_REQUEST["fixedURLData"]);
  141. $smarty->assign('textData', $_REQUEST["textData"]);
  142. if (isset($_REQUEST["zone"])) {
  143. $smarty->assign('zone', $_REQUEST["zone"]);
  144. } else {
  145. $smarty->assign('zone', '');
  146. }
  147. $smarty->assign('onlyInURIs', $_REQUEST['onlyInURIs']);
  148. $smarty->assign('exceptInURIs', $_REQUEST['exceptInURIs']);
  149. $smarty->assign('url', $_REQUEST["url"]);
  150. if (isset($_REQUEST["use"])) {
  151. $smarty->assign('use', $_REQUEST["use"]);
  152. }
  153. if (isset($_REQUEST["useDates"]) && $_REQUEST["useDates"] == 'on') {
  154. $smarty->assign('useDates', 'y');
  155. $useDates = 'y';
  156. } else {
  157. $smarty->assign('useDates', 'n');
  158. $useDates = 'n';
  159. }
  160. if (isset($_REQUEST["Dmon"]) && $_REQUEST["Dmon"] == 'on') {
  161. $smarty->assign('Dmon', 'y');
  162. $Dmon = 'y';
  163. } else {
  164. $smarty->assign('Dmon', 'n');
  165. $Dmon = 'n';
  166. }
  167. if (isset($_REQUEST["Dtue"]) && $_REQUEST["Dtue"] == 'on') {
  168. $smarty->assign('Dtue', 'y');
  169. $Dtue = 'y';
  170. } else {
  171. $smarty->assign('Dtue', 'n');
  172. $Dtue = 'n';
  173. }
  174. if (isset($_REQUEST["Dwed"]) && $_REQUEST["Dwed"] == 'on') {
  175. $smarty->assign('Dwed', 'y');
  176. $Dwed = 'y';
  177. } else {
  178. $smarty->assign('Dwed', 'n');
  179. $Dwed = 'n';
  180. }
  181. if (isset($_REQUEST["Dthu"]) && $_REQUEST["Dthu"] == 'on') {
  182. $smarty->assign('Dthu', 'y');
  183. $Dthu = 'y';
  184. } else {
  185. $smarty->assign('Dthu', 'n');
  186. $Dthu = 'n';
  187. }
  188. if (isset($_REQUEST["Dfri"]) && $_REQUEST["Dfri"] == 'on') {
  189. $smarty->assign('Dfri', 'y');
  190. $Dfri = 'y';
  191. } else {
  192. $smarty->assign('Dfri', 'n');
  193. $Dfri = 'n';
  194. }
  195. if (isset($_REQUEST["Dsat"]) && $_REQUEST["Dsat"] == 'on') {
  196. $smarty->assign('Dsat', 'y');
  197. $Dsat = 'y';
  198. } else {
  199. $smarty->assign('Dsat', 'n');
  200. $Dsat = 'n';
  201. }
  202. if (isset($_REQUEST["Dsun"]) && $_REQUEST["Dsun"] == 'on') {
  203. $smarty->assign('Dsun', 'y');
  204. $Dsun = 'y';
  205. } else {
  206. $smarty->assign('Dsun', 'n');
  207. $Dsun = 'n';
  208. }
  209. $smarty->assign('bannerId', $_REQUEST["bannerId"]);
  210. if (isset($_REQUEST["create_zone"])) {
  211. $bannerlib->banner_add_zone($_REQUEST["zoneName"]);
  212. }
  213. // If we have an upload then process the upload and setup the data in a field
  214. // that will be hidden is this is a nightmare?
  215. $imgname = $_REQUEST["imageName"];
  216. $imgtype = $_REQUEST["imageType"];
  217. if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
  218. $filegallib = TikiLib::lib('filegal');
  219. try {
  220. $filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
  221. } catch (Exception $e) {
  222. $smarty->assign('errortype', 403);
  223. $smarty->assign('msg', $e->getMessage());
  224. $smarty->display("error.tpl");
  225. die;
  226. }
  227. $fp = fopen($_FILES['userfile1']['tmp_name'], "rb");
  228. $data = fread($fp, filesize($_FILES['userfile1']['tmp_name']));
  229. fclose($fp);
  230. $imgtype = $_FILES['userfile1']['type'];
  231. $imgsize = $_FILES['userfile1']['size'];
  232. $imgname = $_FILES['userfile1']['name'];
  233. $smarty->assign('imageData', urlencode($data));
  234. $smarty->assign('imageName', $imgname);
  235. $smarty->assign('imageType', $imgtype);
  236. $_REQUEST["imageData"] = urlencode($data);
  237. $_REQUEST["imageName"] = $imgname;
  238. $_REQUEST["imageType"] = $imgtype;
  239. }
  240. $smarty->assign('imageData', $_REQUEST["imageData"]);
  241. $smarty->assign('tempimg', 'n');
  242. if (strlen($_REQUEST["imageData"]) > 0) {
  243. $tmpfname = tempnam($prefs['tmpDir'], "TMPIMG") . $imgname;
  244. $fp = fopen($tmpfname, "w");
  245. if ($fp) {
  246. fwrite($fp, urldecode($_REQUEST["imageData"]));
  247. fclose($fp);
  248. $smarty->assign('tempimg', $tmpfname);
  249. $smarty->assign('hasImage', 'y');
  250. } else {
  251. $smarty->assign('hasImage', 'n');
  252. }
  253. }
  254. if (! isset($_REQUEST["create_zone"])) {
  255. if ($_REQUEST["use"] == "useFlash") {
  256. $params = [
  257. 'width' => 425,
  258. 'height' => 350,
  259. 'quality' => 'high',
  260. 'version' => '9.0.0',
  261. ];
  262. $params['movie'] = $_REQUEST['movieUrl'];
  263. if (! empty($_REQUEST['movieWidth'])) {
  264. $params['width'] = $_REQUEST['movieWidth'];
  265. }
  266. if (! empty($_REQUEST['movieHeight'])) {
  267. $params['height'] = $_REQUEST['movieHeight'];
  268. }
  269. if (! empty($_REQUEST['movieVersion'])) {
  270. $params['version'] = $_REQUEST['movieVersion'];
  271. }
  272. $_REQUEST['HTMLData'] = serialize($params);
  273. }
  274. $bannerId = $bannerlib->replace_banner(
  275. $_REQUEST["bannerId"],
  276. $_REQUEST["client"],
  277. $_REQUEST["url"],
  278. '',
  279. '',
  280. $_REQUEST["use"],
  281. $_REQUEST["imageData"],
  282. $_REQUEST["imageType"],
  283. $_REQUEST["imageName"],
  284. $_REQUEST["HTMLData"],
  285. $_REQUEST["fixedURLData"],
  286. $_REQUEST["textData"],
  287. $fromDate,
  288. $toDate,
  289. $useDates,
  290. $Dmon,
  291. $Dtue,
  292. $Dwed,
  293. $Dthu,
  294. $Dfri,
  295. $Dsat,
  296. $Dsun,
  297. $fromTime,
  298. $toTime,
  299. $_REQUEST["maxImpressions"],
  300. $_REQUEST["maxClicks"],
  301. $_REQUEST["zone"],
  302. $_REQUEST["maxUserImpressions"],
  303. $_REQUEST['onlyInURIs'],
  304. $_REQUEST['exceptInURIs']
  305. );
  306. header("location:tiki-list_banners.php");
  307. }
  308. }
  309. $zones = $bannerlib->banner_get_zones();
  310. $smarty->assign_by_ref('zones', $zones);
  311. ask_ticket('edit-banner');
  312. // disallow robots to index page:
  313. $smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
  314. // Display the template
  315. $smarty->assign('mid', 'tiki-edit_banner.tpl');
  316. $smarty->display("tiki.tpl");