Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include ("header.php");
- include("db_connect.php");
- $options = null;
- //$connection = null;
- $sender = "form_add_add.php";
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////// Donations check
- ////////////////////////// Compute remaining time of comm org user
- $com_days = null;
- $com_days_remaining = null;
- if($_SESSION["usertype"] == 3){
- $row = mysql_fetch_array(mysql_query("SELECT com_free_days FROM current_prices order by date_created DESC limit 0,1"));
- $com_days = $row["com_free_days"];
- $users = "select distinct a.id_ad, start_day, end_day
- from advertisements a, community_organisation c, users u
- where
- u.netname = '".$_SESSION['username']."' and
- u.id_user = a.id_user and
- a.active = 1
- ";
- $result = mysql_query($users) or die("Could not execute query #2<br/>");
- $totalTime = 0;
- while($row = mysql_fetch_array($result)){
- $start = $row["start_day"];
- $end = $row["end_day"];
- $totalTime += (strtotime($end)-strtotime($start));
- }
- $sum = $com_days - $totalTime/3600/24;
- if($sum > 0){
- $com_days_remaining = round($sum);
- } else {
- $com_days_remaining = 0;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////END COMM ORG CHECK
- ?>
- <title>Create an Advertisement</title>
- <link href="style.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="handlers.js"></script>
- <script type="text/javascript">
- <!--
- function startUpload(){
- document.getElementById('f1_upload_process').style.visibility = 'visible';
- document.getElementById('f1_upload_form').style.visibility = 'hidden';
- return true;
- }
- function stopUpload(success,fileid){
- var result = '';
- if (success == 1){
- result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
- addImage("thumbnail.php?id=" + fileid);
- }
- else {
- result = '<span class="emsg">There was an error during file upload!' + success + '<\/span><br/><br/>';
- }
- document.getElementById('f1_upload_process').style.visibility = 'hidden';
- document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" onchange="startUpload();document.pictureform.submit();" /><\/label>';
- document.getElementById('f1_upload_form').style.visibility = 'visible';
- return true;
- }
- function formValidation(){
- displayMsg = false;
- alertContent = "";
- if(form1.short_description.value == ""){
- displayMsg = true;
- alertContent += "The ad title. ";
- }
- if(form1.title.value == "") {
- displayMsg = true;
- alertContent += "The main category. ";
- }
- if(form1.duration.value == "") {
- displayMsg = true;
- alertContent += "The duration in days. ";
- }
- if(form1.contact_info.value == ""){
- displayMsg = true;
- alertContent += "Your contact info. ";
- }
- if(displayMsg == false){
- if(form1.duration.value > <?php echo $com_days_remaining; ?>){
- alert("The number of days is "+form1.duration.value+" , please choose a number smaller than "+"<?php echo $com_days_remaining; ?>");
- } else {
- form1.submit();
- }
- } else {
- alertContent = "Please fill in the following form element(s): "+alertContent;
- alert(alertContent);
- }
- }
- -->
- </script>
- <body>
- <?php
- if($com_days_remaining > 0 || $_SESSION["usertype"] != 3){
- ?>
- <h1>Create an Advertisement</h1 >
- <?php
- echo "<br/>Please note all fields marked with a star (*) are mandatory. <br/>";
- //////////////////////////////////////////////////////////////////////////
- /*query to select current prices*/
- $prices = "SELECT MAX(date_created) AS date_created FROM current_prices";
- if (!($result = @mysql_query($prices, $connection))) {
- showerror();
- } else {
- $prices=mysql_query($prices);
- if($row =mysql_fetch_array($prices)){
- $current_prices = $row;
- }
- ?>
- <!--
- //end current_prices query
- ///////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////
- //select current price for image per day -->
- <?php
- $add_image = "SELECT add_image FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
- if (!($result = @mysql_query($add_image, $connection))){
- showerror();
- }
- ?>
- <div>
- <form name="form1" method="post" action="action_add_add.php">
- <?php
- /*query to select current prices*/
- $prices = "SELECT MAX(date_created) AS date_created FROM current_prices";
- if (!($result = @mysql_query($prices, $connection))) {
- showerror();
- } else {
- $prices=mysql_query($prices);
- if($row =mysql_fetch_array($prices)){
- $current_prices = $row;
- }
- }//end current_prices query
- ?>
- <?php//select current price for image per day
- $add_image = "SELECT add_image FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
- if (!($result = @mysql_query($add_image, $connection))){
- showerror();
- }
- ?>
- <INPUT TYPE="hidden" NAME= "add_image" value= "<?php echo mysql_result($result, "add_image")?>"/>
- <!-- text Areas-->
- <label for="short_description">
- Short Description <img src="req.gif" alt= "Required"/>
- </label>
- <br/>
- <input type="text" name="short_description" class="reqShort_description" id="short_description" value="<?php if(isset($_POST["short_description"])){echo htmlentities($_POST["short_description"]);} ?>" />
- <br/>
- <br/>
- <label for="description">
- Enter Item Description
- </label>
- <br/>
- <textarea cols="40" rows = "10" name="description" class="reqDescription" id="description" value ="<?php if(isset($_POST['description'])) { echo htmlentities($_POST['description']); }?>" wrap="physical">
- </textarea>
- <br/>
- <br/>
- <!--Display dropdown menu
- <label for="category">Select a category <img src="req.gif" alt="Required"/></label><br/>
- <SELECT name="title" class="reqCategory" id="category"><OPTION VALUE=''$options </SELECT><br/><br/>
- -->
- <?php
- /*Query to display cost of add per day*/
- $add_day = "SELECT add_day FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
- if (!($result = @mysql_query($add_day, $connection))){
- showerror();
- }//end show error
- /* display cost for add per day*/?>
- <INPUT TYPE="hidden" NAME= "add_day" value= "<?php echo mysql_result($result, "add_day");?>"/>
- <!-- Set user session for registered user -->
- <?php if ($_SESSION["usertype"] == 1){
- $num_free_days = "SELECT num_free_days FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
- if (!($result = @mysql_query($num_free_days, $connection))){
- showerror();
- }//end error
- echo "As registered user you have " . mysql_result($result, "num_free_days") ." free days for your advertisement.<br/>";
- $add_day = "SELECT add_day FROM current_prices WHERE date_created ='".$current_prices['date_created']."'";
- if (!($result = @mysql_query($add_day, $connection))){
- showerror();
- }//end
- echo " You may add extra days. Each extra day costs " . mysql_result($result, "add_day")." per day<br/>
- Choose the duration for your advertisement <br/>";?>
- <INPUT TYPE="hidden" NAME= "add_day" value= "<?php echo mysql_result($result, "add_day");
- ?>"/>
- <?php
- }//end session user type 1
- if ($_SESSION["usertype"] == 2){
- echo "<br/> Choooe the duration of Advertisement. Each day costs " . mysql_result($result, "add_day")." per day<br/>";
- } /* end sesion usertype == 2 */
- if ($_SESSION["usertype"] == 3){
- echo "<br/> Choose the duration of your advertisement. <br/> (As a Community Organisation you have " .$com_days_remaining." days remaining for the year.)<br/>";
- }//end seesion 3
- ?>
- <!--input text for number days for add -->
- <label for="duration"> Enter number of days <img src="req.gif" alt="Required" /></label><br/>
- <input type= "text" name="duration" class="reqDuration" id="duration" value="" ></p>
- <?php if ($_SESSION["usertype"] < 3){?>
- <!--input price for item -->
- <br/> Enter the amount you want to charge for your item. <br/>
- <input type= 'text' name='price'</p>
- <?php }?>
- <label for="contact_info"><br/> Enter your contact information <br/>
- (This information will be displayed in your advertisement as your prefered way to be contacted) <img src="req.gif" alt="Required" /></label><br/>
- <textarea cols="40" rows = "5" name="contact_info" class="reqContact_info" id="contact_info" value="" wrap="physical"></textarea><br/>
- <br/>
- <input type = "hidden" name = "add_category" value ="<?php echo mysql_result($result, "add_category")?>"/>
- <?php
- /*Select front page option*/
- $frontpage = "SELECT frontpage FROM current_prices WHERE date_created = '".$current_prices['date_created']."'";
- if (!($result = @mysql_query($frontpage, $connection))){
- showerror();
- }//end
- $price_frontpage=mysql_result($result, "frontpage");
- $row = mysql_fetch_array($result);
- $pass = $row["frontpage"];?>
- <input type = "hidden" name= "price_frontpage" value="<?php echo $price_frontpage?>"/>
- <?php
- echo"<p> Place your add on front page. Cost ". mysql_result($result, "frontpage"). " per day. ";
- ?>
- <input type="checkbox" name="frontpage" value="frontpage"><br/><br/>
- <?php
- }// end session < 3
- /*Query for prices for side panel placement*/
- if ($_SESSION["usertype"] == 2) {
- $sp_add_day = "SELECT sp_add_day FROM current_prices WHERE date_created = '".$current_prices['date_created']."'";
- if (!($result = @mysql_query($sp_add_day, $connection))){
- showerror();
- }//end
- echo"<p> Place your add on the side panel. Cost ". mysql_result($result, "sp_add_day"). " per day. ";
- ?>
- <input type = "hidden" name = "price_sp_add_day" value ="<?php echo mysql_result($result, "sp_add_day")?>"/>
- <!--Check box for sp add day -->
- <input type="checkbox" name="sp_add_day" value="sp_add_day"><br/>
- <?php
- /*Query for cost for front page*/
- $sp_frontpage = "SELECT sp_frontpage FROM current_prices WHERE date_created ='".$current_prices['date_created']."' ";
- if (!($result = @mysql_query($sp_frontpage, $connection))){
- showerror();
- }
- echo"<p> Place your add on front page, side panel. Cost ". mysql_result($result, "sp_frontpage"). " per day. ";
- ?>
- <input type = "hidden" name = "price_sp_frontpage" value ="<?php echo mysql_result($result, "sp_frontpage")?>"/>
- <input type="checkbox" name="sp_frontpage" value="sp_frontpage"><br/>
- <br/>
- <?php }
- /*--------Session Registered User-------------------*/
- if ($_SESSION["usertype"] == 1 || $_SESSION["usertype"] == 2) {
- echo "<br/>Choose how many images you wish to upload.
- You may upload mutliple images but after the first,<br/>
- an additional cost of ". mysql_result($result, "add_image")."$ for each
- image per day will be charged to your account.<br/>
- You will be asked to upload the images on the next page.<br/><br/>";
- }//end 1
- /*--------Session Community Org-------------------*/
- if ($_SESSION["usertype"] == 3) {
- echo "<br/>Choose how many images you wish to upload. You will be asked to upload for the images on the next page.</br>";
- }//end 3
- ?>
- Image(s):
- <input type="text" value="1" id="img_num" class="reqShort_description" name="img_num" size=1 /> <br/>
- <br/><br/>
- <?php
- if ($_SESSION["usertype"] < 3) {
- 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>";
- echo '<br/>Categories(s):
- <input type="text" value="1" id="img_num" class="reqShort_description" name="img_num" size=1 /> <br/>
- <br/><br/><br/>';
- }
- ?>
- <input type="button" name="create_add" value="Create Add" onClick="formValidation()"/>
- <input type="reset" value="Reset"/><br/>
- </form>
- </div>
- <?php
- }else{
- echo "<br/>";
- echo "Your community organisation have 0 remaining days of advertisement available. Please, come back next year!";
- }
- include("db_close.php");?>
- </body>
- <?php include("footer.php");?>
Add Comment
Please, Sign In to add comment