PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/core/ads/form.php

https://bitbucket.org/kucing2k/ediassoc
PHP | 267 lines | 193 code | 48 blank | 26 comment | 27 complexity | ee53976fc663a344e7dd5a827f3487f9 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, BSD-2-Clause, GPL-2.0
  1. <?php
  2. // File Location: /core/ads/form.php
  3. require_once("tpl_secure.php");
  4. require_once("handlers.php");
  5. require_once("class.ads.php");
  6. // instantiate ads class
  7. $oAds = new ads;
  8. // check for id
  9. if ($id) {
  10. // assign unique id
  11. $oAds->setId($id);
  12. }
  13. if ($_POST) { // if form was posted
  14. // assign page variables
  15. $iClientId = $_POST["clientid"];
  16. $sTitle = $_POST["title"];
  17. $sUrl = $_POST["url"];
  18. $sPath = "";
  19. $sClient = $_POST["client"];
  20. $sContact = $_POST["contact"];
  21. $sEmail = $_POST["email"];
  22. $sPhone = $_POST["phone"];
  23. // validate ad title
  24. if (!validInput($sTitle, 1, 200)) {
  25. catchErr("Enter a valid advertisement title");
  26. $FORMOK = false;
  27. }
  28. // validate ad url
  29. if (!validUrl($sUrl)) {
  30. catchErr("Enter a advertisement URL");
  31. $FORMOK = false;
  32. }
  33. // check for uploaded file
  34. if (is_uploaded_file($_FILES["banner"]["tmp_name"])) {
  35. // get file extension
  36. if (!$sExt = validFile("banner")) {
  37. $FORMOK = false;
  38. } else {
  39. // generate random unique file name
  40. $iRand = rand(100001, 999999);
  41. $sImgName = md5(strtotime(date("Y-m-d H:i:s")).$iRand).".".$sExt;
  42. $sPath = SITE_URL."/_img/_banners/".$sImgName;
  43. }
  44. } else { // file noy uploaded
  45. // if the operation is add catch an error
  46. if (!strcmp("add", $op)) {
  47. catchErr("Upload a banner image file");
  48. $FORMOK = false;
  49. }
  50. }
  51. // validate client id
  52. if ($iClientId < 1 && !strcmp("add", $op)) {
  53. // validate client name
  54. if (!validInput($_POST["client"], 1, 100)) {
  55. catchErr("Enter a client name");
  56. $FORMOK = false;
  57. }
  58. // validate client contact
  59. if (!validInput($sContact, 1, 100)) {
  60. catchErr("Enter a client contact name");
  61. $FORMOK = false;
  62. }
  63. // validate client contact email
  64. if (!validEmail($sEmail)) {
  65. catchErr("Enter a client contact email address");
  66. $FORMOK = false;
  67. }
  68. // validate client contact phone
  69. if (!validInput($sPhone, 1, 20)) {
  70. catchErr("Enter a client contact phone number");
  71. $FORMOK = false;
  72. }
  73. } elseif ($iClientId < 1 && !strcmp("edit", $op)) {
  74. catchErr("Select a client");
  75. $FORMOK = false;
  76. }
  77. if ($FORMOK) { // form vlaidated ok
  78. // assign item values
  79. $aArgs["Client Id"] = $iClientId;
  80. $aArgs["Title"] = $sTitle;
  81. $aArgs["URL"] = $sUrl;
  82. $aArgs["Path"] = $sPath;
  83. $aArgs["Client"]["Name"] = $sClient;
  84. $aArgs["Client"]["Contact"] = $sContact;
  85. $aArgs["Client"]["Email"] = $sEmail;
  86. $aArgs["Client"]["Phone"] = $sPhone;
  87. // check operation type
  88. if (!strcmp("edit", $op)) {
  89. // try edit ad
  90. $FORMOK = $oAds->editAd($aArgs);
  91. } elseif (!strcmp("add", $op)) {
  92. // try add ad
  93. $FORMOK = $oAds->addAd($aArgs);
  94. }
  95. // redirect if successful
  96. if ($FORMOK) {
  97. // copy file
  98. copy($_FILES["banner"]["tmp_name"], "../../_img/_banners/".$sImgName);
  99. // redirect if successful
  100. header("Location: index.php");
  101. }
  102. }
  103. } else {
  104. // initialize page vars
  105. if (!strcmp("edit", $op)) {
  106. // get ad
  107. $aAd = $oAds->getAd();
  108. // initialize page variables
  109. $iClientId = $aAd["Client Id"];
  110. $sTitle = $aAd["Title"];
  111. $sUrl = $aAd["URL"];
  112. $sClient = $aAd["Client"]["Name"];
  113. $sContact = $aAd["Client"]["Contact"];
  114. $sEmail = $aAd["Client"]["Email"];
  115. $sPhone = $aAd["Client"]["Phone"];
  116. }
  117. }
  118. setHeader();
  119. openPage();
  120. ?>
  121. <table border="0" cellpadding="0" cellspacing="0">
  122. <tr>
  123. <td><div class="header"><?php print ENTITY ?> Advertisements Administration</div></td>
  124. </tr>
  125. <tr>
  126. <td><div class="copy">To <?php print $op ?> this item in the system, please complete the form below.</div></td>
  127. </tr>
  128. <tr>
  129. <td><div class="error"><?php writeErrors() ?></div></td>
  130. </tr>
  131. </table>
  132. <form action="<?php print SELF ?>?op=<?php print $op ?>&id=<?php print $id ?>" method="post" name="apressform" enctype="multipart/form-data">
  133. <table border="0" cellpadding="0" cellspacing="0">
  134. <?php
  135. $aClients = $oAds->getClientsList();
  136. if (count($aClients)) {
  137. ?>
  138. <tr>
  139. <td><div class="formlabel">Client:</div></td>
  140. <td><select name="clientid" class="textfield" />
  141. <option value="">Choose a client</option>
  142. <?php
  143. $i = 0;
  144. while ($i < count($aClients)) {
  145. if (!strcmp($aClients[$i]["Client Id"] , $iClientId)) {
  146. ?>
  147. <option value="<?php print $aClients[$i]["Client Id"] ?>" selected><?php print clean($aClients[$i]["Client"]) ?></option>
  148. <?php } else { ?>
  149. <option value="<?php print $aClients[$i]["Client Id"] ?>"><?php print clean($aClients[$i]["Client"]) ?></option>
  150. <?php } ?>
  151. <?php
  152. ++$i;
  153. }
  154. ?>
  155. </select></td>
  156. </tr>
  157. <?php } ?>
  158. <tr>
  159. <td><div class="formlabel">Banner Title:</div></td>
  160. <td><input type="text" name="title" value="<?php print clean($sTitle) ?>" class="textfield" /></td>
  161. </tr>
  162. <tr>
  163. <td><div class="formlabel">Banner URL:</div></td>
  164. <td><input type="text" name="url" value="<?php print clean($sUrl) ?>" class="textfield" /></td>
  165. </tr>
  166. <tr>
  167. <td><div class="formlabel">Banner File:</div></td>
  168. <td><input type="file" name="banner" class="textfield" /></td>
  169. </tr>
  170. <tr>
  171. <td class="dotrule" colspan="2"><img src="../../_img/spc.gif" width="1" height="15" alt="" border="0" /></td>
  172. </tr>
  173. <?php if (!strcmp("add", $op)) { ?>
  174. <tr>
  175. <td><div class="formlabel">Client Name:</div></td>
  176. <td><input type="text" name="client" value="<?php print clean($sClient) ?>" class="textfield" /></td>
  177. </tr>
  178. <tr>
  179. <td><div class="formlabel">Client Contact:</div></td>
  180. <td><input type="text" name="contact" value="<?php print clean($sContact) ?>" class="textfield" /></td>
  181. </tr>
  182. <tr>
  183. <td><div class="formlabel">Contact Email:</div></td>
  184. <td><input type="text" name="email" value="<?php print clean($sEmail) ?>" class="textfield" /></td>
  185. </tr>
  186. <tr>
  187. <td><div class="formlabel">Contact Phone:</div></td>
  188. <td><input type="text" name="phone" value="<?php print clean($sPhone) ?>" class="textfield" /></td>
  189. </tr>
  190. <tr>
  191. <td class="dotrule" colspan="2"><img src="../../_img/spc.gif" width="1" height="15" alt="" border="0" /></td>
  192. </tr>
  193. <?php } else { ?>
  194. <tr>
  195. <td><div class="formlabel">Client Name:</div></td>
  196. <td><?php print format($sClient) ?></td>
  197. </tr>
  198. <tr>
  199. <td><div class="formlabel">Client Contact:</div></td>
  200. <td><?php print format($sContact) ?></td>
  201. </tr>
  202. <tr>
  203. <td><div class="formlabel">Contact Email:</div></td>
  204. <td><?php print format($sEmail) ?></td>
  205. </tr>
  206. <tr>
  207. <td><div class="formlabel">Contact Phone:</div></td>
  208. <td><?php print format($sPhone) ?></td>
  209. </tr>
  210. <tr>
  211. <td class="dotrule" colspan="2"><img src="../../_img/spc.gif" width="1" height="15" alt="" border="0" /></td>
  212. </tr>
  213. <?php } ?>
  214. <tr>
  215. <td align="right" colspan="2"><input type="image" src="../../_img/buttons/btn_submit.gif" width="58" height="15" alt="" border="0" onfocus="this.blur();" /></td>
  216. </tr>
  217. </table>
  218. </form>
  219. <?php closePage(); ?>