Guest User

Untitled

a guest
Jun 15th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.06 KB | None | 0 0
  1. <?php
  2. include ("header.php");
  3. include("db_connect.php");
  4. $options = null;
  5. //$connection = null;
  6.  
  7. $sender = "form_add_add.php";
  8.  
  9.  
  10. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. //////////////////////////// Donations check
  12. ////////////////////////// Compute remaining time of comm org user
  13.  
  14. $com_days = null;
  15. $com_days_remaining = null;
  16.  
  17. if($_SESSION["usertype"] == 3){
  18.  
  19. $row = mysql_fetch_array(mysql_query("SELECT com_free_days FROM current_prices order by date_created DESC limit 0,1"));
  20. $com_days = $row["com_free_days"];
  21.  
  22.  
  23. $users = "select distinct a.id_ad, start_day, end_day
  24. from advertisements a, community_organisation c, users u
  25. where
  26. u.netname = '".$_SESSION['username']."' and
  27. u.id_user = a.id_user and
  28. a.active = 1
  29. ";
  30.  
  31. $result = mysql_query($users) or die("Could not execute query #2<br/>");
  32. $totalTime = 0;
  33.  
  34. while($row = mysql_fetch_array($result)){
  35.  
  36. $start = $row["start_day"];
  37. $end = $row["end_day"];
  38.  
  39. $totalTime += (strtotime($end)-strtotime($start));
  40.  
  41. }
  42.  
  43. $sum = $com_days - $totalTime/3600/24;
  44. if($sum > 0){
  45.  
  46. $com_days_remaining = round($sum);
  47.  
  48. } else {
  49.  
  50. $com_days_remaining = 0;
  51.  
  52. }
  53.  
  54.  
  55.  
  56. }
  57. /////////////////////////////////////////////////////////////////////////////////END COMM ORG CHECK
  58. ?>
  59.  
  60.  
  61. <title>Create an Advertisement</title>
  62. <link href="style.css" rel="stylesheet" type="text/css" />
  63. <script type="text/javascript" src="handlers.js"></script>
  64. <script type="text/javascript">
  65.  
  66. <!--
  67. function startUpload(){
  68. document.getElementById('f1_upload_process').style.visibility = 'visible';
  69. document.getElementById('f1_upload_form').style.visibility = 'hidden';
  70. return true;
  71. }
  72.  
  73. function stopUpload(success,fileid){
  74. var result = '';
  75. if (success == 1){
  76. result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
  77. addImage("thumbnail.php?id=" + fileid);
  78. }
  79. else {
  80. result = '<span class="emsg">There was an error during file upload!' + success + '<\/span><br/><br/>';
  81. }
  82. document.getElementById('f1_upload_process').style.visibility = 'hidden';
  83. document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" onchange="startUpload();document.pictureform.submit();" /><\/label>';
  84. document.getElementById('f1_upload_form').style.visibility = 'visible';
  85.  
  86. return true;
  87.  
  88. }
  89.  
  90. function formValidation(){
  91.  
  92.  
  93. displayMsg = false;
  94. alertContent = "";
  95.  
  96. if(form1.short_description.value == ""){
  97.  
  98. displayMsg = true;
  99. alertContent += "The ad title. ";
  100.  
  101. }
  102. if(form1.title.value == "") {
  103.  
  104. displayMsg = true;
  105. alertContent += "The main category. ";
  106.  
  107. }
  108. if(form1.duration.value == "") {
  109.  
  110. displayMsg = true;
  111. alertContent += "The duration in days. ";
  112.  
  113. }
  114. if(form1.contact_info.value == ""){
  115.  
  116. displayMsg = true;
  117. alertContent += "Your contact info. ";
  118. }
  119.  
  120. if(displayMsg == false){
  121.  
  122. if(form1.duration.value > <?php echo $com_days_remaining; ?>){
  123.  
  124. alert("The number of days is "+form1.duration.value+" , please choose a number smaller than "+"<?php echo $com_days_remaining; ?>");
  125.  
  126. } else {
  127.  
  128. form1.submit();
  129.  
  130. }
  131.  
  132.  
  133. } else {
  134.  
  135. alertContent = "Please fill in the following form element(s): "+alertContent;
  136. alert(alertContent);
  137.  
  138. }
  139.  
  140.  
  141.  
  142. }
  143.  
  144. -->
  145. </script>
  146.  
  147. <body>
  148.  
  149. <?php
  150. if($com_days_remaining > 0 || $_SESSION["usertype"] != 3){
  151. ?>
  152.  
  153. <h1>Create an Advertisement</h1 >
  154.  
  155. <?php
  156. echo "<br/>Please note all fields marked with a star (*) are mandatory. <br/>";
  157.  
  158. //////////////////////////////////////////////////////////////////////////
  159. /*query to select current prices*/
  160. $prices = "SELECT MAX(date_created) AS date_created FROM current_prices";
  161.  
  162. if (!($result = @mysql_query($prices, $connection))) {
  163. showerror();
  164. } else {
  165. $prices=mysql_query($prices);
  166. if($row =mysql_fetch_array($prices)){
  167. $current_prices = $row;
  168. }
  169.  
  170.  
  171. ?>
  172.  
  173. <!--
  174. //end current_prices query
  175. ///////////////////////////////////////////////////////////////////////////
  176.  
  177.  
  178. //////////////////////////////////////////////////////////////////////////
  179. //select current price for image per day -->
  180. <?php
  181. $add_image = "SELECT add_image FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
  182. if (!($result = @mysql_query($add_image, $connection))){
  183. showerror();
  184. }
  185. ?>
  186.  
  187.  
  188. <div>
  189. <form name="form1" method="post" action="action_add_add.php">
  190.  
  191.  
  192. <?php
  193. /*query to select current prices*/
  194. $prices = "SELECT MAX(date_created) AS date_created FROM current_prices";
  195.  
  196. if (!($result = @mysql_query($prices, $connection))) {
  197.  
  198. showerror();
  199.  
  200. } else {
  201.  
  202. $prices=mysql_query($prices);
  203.  
  204. if($row =mysql_fetch_array($prices)){
  205. $current_prices = $row;
  206. }
  207.  
  208. }//end current_prices query
  209. ?>
  210.  
  211. <?php//select current price for image per day
  212. $add_image = "SELECT add_image FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
  213.  
  214. if (!($result = @mysql_query($add_image, $connection))){
  215.  
  216. showerror();
  217.  
  218. }
  219. ?>
  220.  
  221. <INPUT TYPE="hidden" NAME= "add_image" value= "<?php echo mysql_result($result, "add_image")?>"/>
  222.  
  223. <!-- text Areas-->
  224.  
  225. <label for="short_description">
  226. Short Description <img src="req.gif" alt= "Required"/>
  227. </label>
  228. <br/>
  229. <input type="text" name="short_description" class="reqShort_description" id="short_description" value="<?php if(isset($_POST["short_description"])){echo htmlentities($_POST["short_description"]);} ?>" />
  230. <br/>
  231. <br/>
  232.  
  233. <label for="description">
  234. Enter Item Description
  235. </label>
  236. <br/>
  237. <textarea cols="40" rows = "10" name="description" class="reqDescription" id="description" value ="<?php if(isset($_POST['description'])) { echo htmlentities($_POST['description']); }?>" wrap="physical">
  238. </textarea>
  239. <br/>
  240. <br/>
  241.  
  242.  
  243. <!--Display dropdown menu
  244. <label for="category">Select a category <img src="req.gif" alt="Required"/></label><br/>
  245.  
  246. <SELECT name="title" class="reqCategory" id="category"><OPTION VALUE=''$options </SELECT><br/><br/>
  247. -->
  248.  
  249. <?php
  250. /*Query to display cost of add per day*/
  251.  
  252. $add_day = "SELECT add_day FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
  253.  
  254. if (!($result = @mysql_query($add_day, $connection))){
  255. showerror();
  256. }//end show error
  257.  
  258. /* display cost for add per day*/?>
  259. <INPUT TYPE="hidden" NAME= "add_day" value= "<?php echo mysql_result($result, "add_day");?>"/>
  260.  
  261.  
  262.  
  263. <!-- Set user session for registered user -->
  264.  
  265. <?php if ($_SESSION["usertype"] == 1){
  266.  
  267. $num_free_days = "SELECT num_free_days FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
  268. if (!($result = @mysql_query($num_free_days, $connection))){
  269. showerror();
  270. }//end error
  271.  
  272. echo "As registered user you have " . mysql_result($result, "num_free_days") ." free days for your advertisement.<br/>";
  273.  
  274. $add_day = "SELECT add_day FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
  275. if (!($result = @mysql_query($add_day, $connection))){
  276. showerror();
  277. }//end
  278.  
  279. echo " You may add extra days. Each extra day costs " . mysql_result($result, "add_day")." per day<br/>
  280. Choose the duration for your advertisement <br/>";?>
  281. <INPUT TYPE="hidden" NAME= "add_day" value= "<?php echo mysql_result($result, "add_day");
  282. ?>"/>
  283.  
  284. <?php
  285.  
  286. }//end session user type 1
  287.  
  288. if ($_SESSION["usertype"] == 2){
  289.  
  290. echo "<br/> Choooe the duration of Advertisement. Each day costs " . mysql_result($result, "add_day")." per day<br/>";
  291.  
  292. } /* end sesion usertype == 2 */
  293.  
  294. if ($_SESSION["usertype"] == 3){
  295.  
  296.  
  297. echo "<br/> Choose the duration of your advertisement. <br/> (As a Community Organisation you have " .$com_days_remaining." days remaining for the year.)<br/>";
  298.  
  299. }//end seesion 3
  300.  
  301.  
  302. ?>
  303.  
  304. <!--input text for number days for add -->
  305. <label for="duration"> Enter number of days <img src="req.gif" alt="Required" /></label><br/>
  306. <input type= "text" name="duration" class="reqDuration" id="duration" value="" ></p>
  307.  
  308. <?php if ($_SESSION["usertype"] < 3){?>
  309.  
  310. <!--input price for item -->
  311. <br/> Enter the amount you want to charge for your item. <br/>
  312. <input type= 'text' name='price'</p>
  313.  
  314. <?php }?>
  315.  
  316.  
  317. <label for="contact_info"><br/> Enter your contact information <br/>
  318. (This information will be displayed in your advertisement as your prefered way to be contacted) <img src="req.gif" alt="Required" /></label><br/>
  319.  
  320. <textarea cols="40" rows = "5" name="contact_info" class="reqContact_info" id="contact_info" value="" wrap="physical"></textarea><br/>
  321.  
  322. <br/>
  323.  
  324.  
  325. <input type = "hidden" name = "add_category" value ="<?php echo mysql_result($result, "add_category")?>"/>
  326.  
  327.  
  328. <?php
  329. /*Select front page option*/
  330. $frontpage = "SELECT frontpage FROM current_prices WHERE date_created = '".$current_prices['date_created']."'";
  331.  
  332. if (!($result = @mysql_query($frontpage, $connection))){
  333. showerror();
  334. }//end
  335.  
  336. $price_frontpage=mysql_result($result, "frontpage");
  337. $row = mysql_fetch_array($result);
  338. $pass = $row["frontpage"];?>
  339.  
  340. <input type = "hidden" name= "price_frontpage" value="<?php echo $price_frontpage?>"/>
  341.  
  342. <?php
  343. echo"<p> Place your add on front page. Cost ". mysql_result($result, "frontpage"). " per day. ";
  344. ?>
  345.  
  346. <input type="checkbox" name="frontpage" value="frontpage"><br/><br/>
  347.  
  348.  
  349. <?php
  350. }// end session < 3
  351.  
  352. /*Query for prices for side panel placement*/
  353. if ($_SESSION["usertype"] == 2) {
  354.  
  355. $sp_add_day = "SELECT sp_add_day FROM current_prices WHERE date_created = '".$current_prices['date_created']."'";
  356.  
  357. if (!($result = @mysql_query($sp_add_day, $connection))){
  358. showerror();
  359. }//end
  360.  
  361. echo"<p> Place your add on the side panel. Cost ". mysql_result($result, "sp_add_day"). " per day. ";
  362.  
  363. ?>
  364.  
  365. <input type = "hidden" name = "price_sp_add_day" value ="<?php echo mysql_result($result, "sp_add_day")?>"/>
  366.  
  367. <!--Check box for sp add day -->
  368. <input type="checkbox" name="sp_add_day" value="sp_add_day"><br/>
  369.  
  370. <?php
  371. /*Query for cost for front page*/
  372. $sp_frontpage = "SELECT sp_frontpage FROM current_prices WHERE date_created ='".$current_prices['date_created']."' ";
  373.  
  374. if (!($result = @mysql_query($sp_frontpage, $connection))){
  375. showerror();
  376. }
  377.  
  378. echo"<p> Place your add on front page, side panel. Cost ". mysql_result($result, "sp_frontpage"). " per day. ";
  379. ?>
  380. <input type = "hidden" name = "price_sp_frontpage" value ="<?php echo mysql_result($result, "sp_frontpage")?>"/>
  381. <input type="checkbox" name="sp_frontpage" value="sp_frontpage"><br/>
  382. <br/>
  383. <?php }
  384.  
  385.  
  386. /*--------Session Registered User-------------------*/
  387. if ($_SESSION["usertype"] == 1 || $_SESSION["usertype"] == 2) {
  388.  
  389. echo "<br/>Choose how many images you wish to upload.
  390. You may upload mutliple images but after the first,<br/>
  391. an additional cost of ". mysql_result($result, "add_image")."$ for each
  392. image per day will be charged to your account.<br/>
  393. You will be asked to upload the images on the next page.<br/><br/>";
  394. }//end 1
  395.  
  396.  
  397. /*--------Session Community Org-------------------*/
  398. if ($_SESSION["usertype"] == 3) {
  399.  
  400. echo "<br/>Choose how many images you wish to upload. You will be asked to upload for the images on the next page.</br>";
  401. }//end 3
  402.  
  403. ?>
  404.  
  405. Image(s):
  406. <input type="text" value="1" id="img_num" class="reqShort_description" name="img_num" size=1 /> <br/>
  407. <br/><br/>
  408.  
  409. <?php
  410. if ($_SESSION["usertype"] < 3) {
  411.  
  412. echo "<br/>Choose how many categories you wish your add to be in. You will be asked to select them on the next page.</br>";
  413. echo '<br/>Categories(s):
  414. <input type="text" value="1" id="img_num" class="reqShort_description" name="img_num" size=1 /> <br/>
  415. <br/><br/><br/>';
  416. }
  417.  
  418.  
  419. ?>
  420.  
  421.  
  422. <input type="button" name="create_add" value="Create Add" onClick="formValidation()"/>
  423. <input type="reset" value="Reset"/><br/>
  424.  
  425.  
  426.  
  427.  
  428.  
  429. </form>
  430. </div>
  431. <?php
  432. }else{
  433. echo "<br/>";
  434. echo "Your community organisation have 0 remaining days of advertisement available. Please, come back next year!";
  435.  
  436. }
  437.  
  438.  
  439. include("db_close.php");?>
  440. </body>
  441. <?php include("footer.php");?>
Add Comment
Please, Sign In to add comment