<?php
$module_css_path = ($line_domain['theme'] != "" && $line_domain['theme'] != "default") ? ($path . ('assets/themes/' . $line_domain['theme'] . '/')) : $path;

$optres['css'][] = $path . "assets/plugins/fileinput/css/fileinput.min.css";
$optres['js'][] = $path . "assets/plugins/fileinput/js/plugins/canvas-to-blob.min.js";
$optres['js'][] = $path . "assets/plugins/fileinput/js/fileinput.min.js";
$optres['css'][] = $module_css_path . "amodules/freelisting/css/freelisting.css";
$optres['js'][] = $path . "amodules/freelisting/js/freelisting.js";
/******************************************************************************************************/
// Get Districts
$d = array();
$districts = array();
$q = "select * from cyprus_districts order by district asc;";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	while ($row = mysql_fetch_assoc($r)) {
		$d [] = array_map('stripslashes', $row);
		$districts [$row['dcode']] = stripslashes($row['district']);
	}
}

// Get Locations
$a = array();
$locations = array();
$q = "select * from cyprus_locations order by location asc;";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	while ($row = mysql_fetch_assoc($r)) {
		$dcode = $row['dcode'];
		$lcode = $row['lcode'];
		
		if(isset($locations[$dcode])) {
			$locations[$dcode][$lcode] = stripslashes($row['location']);
		}
		else {
			$locations[$dcode] = array();
			$locations[$dcode][$lcode] = stripslashes($row['location']);
		}
		
	}
}
/******************************************************************************************************/


if(!function_exists("NewAdvGuid")) {
	// Generate Guid 
	function NewAdvGuid($pref = "AD") {
	    $s = strtoupper(md5(uniqid(rand(),true))); 
	    $guidText = $pref . 
	    	(1010 + intval(date("Y"))) . 
	        date("mdHis") .  
	        substr($s,0,16); 
	    return $guidText;
	}
}

if(!function_exists("makeFriendlyUrl")) {
	function makeFriendlyUrl($string) {
		$friendly_url = trim(preg_replace('#[^\p{L}\p{N}]+#u', ' ', trim($string)));
		$frp = explode(" ", $friendly_url);
		if(count($frp)) {
			$glue = array();
			foreach ($frp as $fpart) {
				if(trim($fpart) != "") $glue[] = trim($fpart);
			}
			
			$friendly_url = implode("-", $glue);
		}
		
		//$friendly_url .= "-" . date("Hs");
		
		return strtolower($friendly_url);
	}
}

$err = "";
$msg = "";



// Get current directory
$dirname_curr = dirname(__FILE__);
$dirname_curr = str_replace("\\", "/", $dirname_curr);
$dirname_parts = explode("/", $dirname_curr);
$cur_dir = ($dirname_parts[count($dirname_parts)-1] != "") ? $dirname_parts[count($dirname_parts)-1] : $dirname_parts[count($dirname_parts)-2];

require_once(dirname(__FILE__) . "/../classes/class.upload.php");
require_once(dirname(__FILE__) . "/../classes/httpParser.php");

if(isset($_POST['chcAction'])) {
    require_once(dirname(__FILE__) . "/freelisting_actions.php");
}


$advert_fields = array("adv_code", "cust_code", "title_en", "title_el", "title_tr", "short_title_en", "description_en", "description_el", "description_tr",  "register", "advertisment", "website", "open_window", "active", "catdom_id", "filter_id", "added_on", "ContactPerson", "Directors", "YearOfEstablishment", "NumberOfEmployees",  "MemberOf", "member_id", "views", "clicks", "clicks_on_www", "meta_description");
$advert_location_fields = array("location_title", "street", "street_no", "building_name", "floor", "flat", "city", "postalcode", "area", "district", "dcode", "lcode", "country", "pobox", "pobox_postalcode", "contact_name", "contact_title", "tel1", "tel2", "mobile1", "mobile2", "fax", "email", "main_location", "active", "created", "created_by", "updated", "updated_by");

if (isset($_SESSION['member_id'])){
	$member_id = intval($_SESSION['member_id']);
	$q = "select * from members where member_id='$member_id';";
	$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
	if($r && mysql_num_rows($r) == 1) {
		$row = mysql_fetch_assoc($r);
		$cust_code = trim($row['cust_code']);
        $kind_ind = intval($row['kind_ind']);
		
		
		if($cust_code == "") {
			$cust_code = NewAdvGuid("CU");
			
			
			$q = "update members set cust_code='$cust_code' where member_id='$member_id';";
			$r = @mysql_query($q);
			if(!$r || mysql_affected_rows() == -1) {
				$cust_code = "";
			}
			
		}
	}
	
	
	$q = "select * from advertisment where member_id='$member_id';";
	$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
	if($r && mysql_num_rows($r)>0) {
		$row = mysql_fetch_assoc($r);
		$advertisment_id = $row['advertisment_id'];
		$advertisment = trim($row['advertisment']);
		$chcAction = "edit";
		if(isset($_REQUEST['chcAction']) && $_REQUEST['chcAction'] != "") {
			$chcAction = $_REQUEST['chcAction'];
		}
	}
	else {
		$chcAction = "add";
	}


	
	if($chcAction == "add") {
		$show_form = true;
		$cust_code = (isset($cust_code) && strlen($cust_code) == 32) ? $cust_code : NewAdvGuid("CU");
		//$intranet_code = isset($_REQUEST['intranet_code']) ? $_REQUEST['intranet_code'] : "";
		$member_id = isset($_SESSION['member_id']) ? intval($_SESSION['member_id']) : "";
		
		///echo "UID: $cust_code";
		
		$q = "select * from members where member_id='$member_id';";
		$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
		if($r && mysql_num_rows($r)>0) {
			$row = mysql_fetch_assoc($r);
			$cust_code = $row['cust_code'];
			$show_form = true;
			// It is ok to start creating the New Advert
			$advert_data = array();
			foreach ($advert_fields as $fld) {
				$advert_data[$fld] = "";
				
			}
			
			foreach ($advert_location_fields as $fld) {
				$advert_data[$fld] = "";
				
			}
			
			// Set Default Values
			$advert_data ['member_id'] = $member_id;
			$advert_data ['adv_code'] = NewAdvGuid();
			$advert_data ['cust_code'] = $cust_code;
			$advert_data ['open_window'] = "no";
			$advert_data ['NumberOfEmployees'] = "1-50";
			$advert_data ['added_on'] = date("Y-m-d", time());
			
			$advert_action = "add";
		
		}
		else {
			$err .= "<br/>You need to first create an account.";
		}
	}
	
	//echo '<pre>', print_r($advert_data), '</pre>';
	

	if(isset($advertisment_id) && intval($advertisment_id)>0) {
		$q = "select * from advertisment where advertisment_id='$advertisment_id';";
		$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
		if($r && mysql_num_rows($r) == 1) {
			$show_form = true;
			$adv_data = mysql_fetch_assoc($r);
			if(trim($adv_data['cust_code']) == "") $adv_data['cust_code'] = $cust_code;
			//echo '<pre>', print_r($adv_data), '</pre>';
			$advert_data = array();
			foreach ($advert_fields as $i=>$fld) {
				//echo "<br>$fld";
				$advert_data[$fld] = stripslashes(trim($adv_data[$fld]));
			}
			if($advert_data['adv_code'] == "") $advert_data ['adv_code'] = NewAdvGuid();
			
			$ql = "select * from advertisment_locations where advertisment_id='$advertisment_id';";
			
			$rl = mysql_query($ql) or die("<strong>$ql</strong>".mysql_error());
			if($rl && mysql_num_rows($rl)>0) {
				$rowl = mysql_fetch_assoc($rl);
				$location_id = $rowl['location_id'];
				foreach ($advert_location_fields as $fld) {
					$advert_data[$fld] = $rowl[$fld];
					
				}
				
				//echo '<pre>', print_r($advert_data), '</pre>';
			}
			$chcAction = "edit";

		}
		else {
			$err .= "<br/>There is no such Free Listing in our database!";
		}
	}
	if($err != "") {
		echo '<div class="alert alert-danger"><strong>Errors Occured</strong><br/>', $err, '</div>';
	}
	
	if(isset($msg) && $msg != "") {
		echo '<div class="alert alert-success"><strong>Successfull Operation</strong><br/>', $msg, '</div>';
	}
	
	if($show_form) {
		
		//echo '<pre>', print_r($advert_data), '</pre>';
		
		if(isset($_POST['chcAction']) && $err != "") {
			foreach ($_POST as $key=>$val) {
				if($key != "cust_code") {
					if(isset($advert_data[$key])) $advert_data[$key] = $val;
				}
			}
		}
		
		foreach ($advert_data as $key=>$val) {
			${$key} = $val;
			
			if($key == "location_title" && trim($val) == "") ${$key} = "Address Details";
			
		}

        $form_title = "Create Free Listing";
        if($chcAction == "edit") $form_title = "Edit Free Listing";
		
		?>
        <article class="article green">
            <header>
                <h1><?php echo $form_title;?></h1>
                <!--[/SocialShareButtons/]-->
            </header>
            <div class="article-body">
                <?php
                if(!isset($advertisment_id) || $chcAction != "edit") {
                    ?>
                    <div class="alert alert-info">
                        <p>If you wish to list your business or service in our Vertical Portal Network please feel free
                            to do so by filling in the form provided below. Your listing will be found through our
                            Search / Advanced Search sections only.</p>

                        <p>If you wish to be advertised in our Network with a banner or your logo please contact <a
                                href="mailto:info@cyprusnet.com">info@cyprusnet.com</a></p>

                        <p>Please note that only one Free Listing is allowed for each member.</p>

                        <p>Fields marked with an asterisk <span class="red">*</span> are required.</p>
                    </div>
                    <?php
                }
                ?>

                <?php
                if(isset($advertisment_id) && $chcAction == "edit") {
                    ?>
                    <div class="box box-primary box-solid">
                        <div class="box-header with-border">
                            <b>Statistics</b>
                        </div>
                        <div class="box-body no-padding">
                            <table class="table">
                                <tbody>
                                <tr>
                                    <td class="th">Views</td>
                                    <td>
                                        <strong><?php echo number_format(intval($views), 0, '.', ' ');?></strong>
                                    </td>
                                </tr>
                                <?php
                                if($kind_ind != 0) {
                                    ?>
                                    <tr>
                                        <td class="th">Clicks</td>
                                        <td>
                                            <strong><?php echo number_format(intval($clicks), 0, '.', ' ');?></strong>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                <tr>
                                    <td class="th">Clicks on your website</td>
                                    <td>
                                        <strong><?php echo number_format(intval($clicks_on_www), 0, '.', ' ');?></strong>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>


                    <?php
                }
                ?>

                <form method="post" enctype="multipart/form-data" name="add_advert_frm" id="add_advert_frm" class="form-horizontal" role="form" action="account/my_listing.html">
                <fieldset>

                    <legend>
                        <b>Free Listing Details</b>
                    </legend>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Website URL <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="url" name="website" id="website" placeholder="http://" value="<?php echo $website; ?>" required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Name to be displayed <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="short_title_en" id="short_title_en" value="<?php echo $short_title_en; ?>" required="required" class="form-control input-sm">
                            <span class="help-block">The name to be displayed on the Advertisment (Free Listing) has to be short (up to 24 characters) and you must try to write it as close as possible to what people would write in the Search Engines when trying to find you on internet. </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Description <span class="req">*</span></label>

                        <div class="col-sm-7">
                            <textarea name="description_en" id="description_en" rows="5" required="required" class="form-control input-sm"><?php echo $description_en; ?></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Short Description <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <textarea name="meta_description" id="meta_description" rows="2" required="required" class="form-control input-sm"><?php echo $meta_description; ?></textarea>
                            <span class="help-block">Please enter a short but objective description of your business. This text will be displayed by the search engines in the results list. </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Contact Person <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="ContactPerson" id="ContactPerson" value="<?php echo $ContactPerson; ?>" required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Directors</label>
                        <div class="col-sm-7">
                            <input type="text" name="Directors" id="Directors" value="<?php echo $Directors; ?>"  class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Year Of Establishment</label>

                        <div class="col-sm-7">
                            <input type="number" min="1900" max="<?=intval(date("Y"));?>" name="YearOfEstablishment" id="YearOfEstablishment" value="<?php echo $YearOfEstablishment; ?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Number Of Employees</label>

                        <div class="col-sm-7">
                            <input name="NumberOfEmployees" type="radio" value="1-50" <?php if ($NumberOfEmployees == "1-50") { echo " checked"; } ?>> 1-50
                            <input type="radio" name="NumberOfEmployees" value="51-100" <?php if ($NumberOfEmployees == "51-100") { echo " checked"; } ?>> 51-100
                            <input type="radio" name="NumberOfEmployees" value="101-1000" <?php if ($NumberOfEmployees == "101-1000") { echo " checked";} ?>> 101-1000
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Member Of</label>
                        <div class="col-sm-7">
                            <input type="text" name="MemberOf" id="MemberOf" value="<?php echo $MemberOf; ?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Registration Date</label>
                        <div class="col-sm-7">
                            <input type="hidden" name="added_on" id="added_on" value="<?php echo $added_on; ?>">
                            <?php echo date("F d, Y", strtotime($added_on)); ?>
                        </div>
                    </div>

                    <legend><b>Location Details</b></legend>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Location Title <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="location_title" id="location_title" value="<?php echo $location_title;?>" required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Street Name <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="street" id="street" value="<?php echo $street;?>" required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Street Number</label>
                        <div class="col-sm-7">
                            <input type="text" name="street_no" id="street_no" value="<?php echo $street_no;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Postal Code <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="postalcode" id="postalcode" value="<?php echo $postalcode;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Building Name</label>
                        <div class="col-sm-7">
                            <input type="text" name="building_name" id="building_name" value="<?php echo $building_name;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Floor</label>
                        <div class="col-sm-7">
                            <input type="text" name="floor" id="floor" value="<?php echo $floor;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Office/Flat</label>
                        <div class="col-sm-7">
                            <input type="text" name="flat" id="flat" value="<?php echo $flat;?>" class="form-control input-sm">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-3">P.O. Box</label>
                        <div class="col-sm-7">
                            <input type="text" name="pobox" id="pobox" value="<?php echo $pobox;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">P.O. Box Postal Code</label>
                        <div class="col-sm-7">
                            <input type="text" name="pobox_postalcode" id="pobox_postalcode" value="<?php echo $pobox_postalcode;?>" class="form-control input-sm">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-3">District <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <select name="dcode" id="dcode" class="form-control input-sm" required="required">
                                <option value="" selected="selected">Please Select</option>
                                <?php
                                foreach ($districts as $t_dcode=>$t_district) {
                                    $selected = "";
                                    if($dcode == $t_dcode) $selected = 'selected="selected"';
                                    echo '<option value="', $t_dcode, '" ', $selected, '>', $t_district, '</option>';
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Location <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <select name="lcode" id="lcode" class="form-control input-sm" required="required">
                                <option value="" selected="selected">Please Select</option>
                                <?php
                                if($dcode != "") {
                                    foreach ($locations[$dcode] as $t_lcode=>$t_location) {
                                        $selected = "";
                                        if($lcode == $t_lcode) $selected = 'selected="selected"';
                                        echo '<option value="', $t_lcode, '" ', $selected, '>', $t_location, '</option>';
                                    }
                                }

                                ?>
                            </select>
                        </div>
                    </div>
                    <?php
                    if(isset($advertisment_id) && $chcAction == "edit" && $lcode == "") {
                        ?>
                        <div class="form-group">
                            <label class="control-label col-sm-3">OLD Town/Village value</label>
                            <div class="col-sm-7">
                                <input type="text" readonly name="city" id="city" value="<?php echo $city;?>" class="form-control input-sm">
                            </div>
                        </div>
                        <!--
                        <tr>
                            <td class="control-label col-sm-3">Area</td>
                            <td nowrap class="right">
                                <input type="text" name="area" id="area" value="<?php echo $area;?>" size="32" style="width:90%;">
                            </td>
                        </tr>
                        -->
                        <div class="form-group">
                            <label class="control-label col-sm-3">OLD District value</label>
                            <div class="col-sm-7">
                                <input type="text" readonly name="district" id="district" value="<?php echo $district;?>" class="form-control input-sm">
                            </div>
                        </div>
                        <?php
                    }
                    ?>

                    <div class="form-group">
                        <label class="control-label col-sm-3">Country <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <select name="country" id="country" class="form-control input-sm">
                                <option value="cy" selected="selected">Cyprus</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Contact Name <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="contact_name" id="contact_name" value="<?php echo $contact_name;?>"  required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Contact Title</label>
                        <div class="col-sm-7">
                            <input type="text" name="contact_title" id="contact_title" value="<?php echo $contact_title;?>" class="form-control input-sm">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-3">Email <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="email" id="email" value="<?php echo $email;?>"  required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Fixed Phone 1 <span class="req">*</span></label>
                        <div class="col-sm-7">
                            <input type="text" name="tel1" id="tel1" value="<?php echo $tel1;?>" required="required" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Fixed Phone 2</label>
                        <div class="col-sm-7">
                            <input type="text" name="tel2" id="tel2" value="<?php echo $tel2;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Mobile Phone 1</label>
                        <div class="col-sm-7">
                            <input type="text" name="mobile1" id="mobile1" value="<?php echo $mobile1;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Mobile Phone 2</label>
                        <div class="col-sm-7">
                            <input type="text" name="mobile2" id="mobile2" value="<?php echo $mobile2;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Fax</label>
                        <div class="col-sm-7">
                            <input type="text" name="fax" id="fax" value="<?php echo $fax;?>" class="form-control input-sm">
                        </div>
                    </div>
                    <legend><b>Logo Image  <span class="req">*</span></b></legend>
                    <?php
                    $has_logo = false;
                    if(trim($advert_data['advertisment']) != ""){
                        $logo_file_path = $full_uri . "images/advertisments/" . $advert_data['advertisment'];

                        $logo_file = dirname(__FILE__) . "/../../images/advertisments/" . $advert_data['advertisment'];


                        if(file_exists($logo_file)) {
                            $has_logo = true;
                            ?>
                            <div class="form-group">
                                <label class="control-label col-sm-3">Current Logo Image</label>
                                <div class="col-sm-7">
                                    <?php
                                    echo '<img src="', $logo_file_path, '" class="img-thumbnail">';
                                    echo '<input type="hidden" name="old_logo" value="', $advert_data['advertisment'], '">';
                                    ?>
                                </div>
                            </div>
                            <?php
                        }
                    }
                    ?>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Upload New Logo Image</label>
                        <div class="col-sm-7">
                            <input type="file" name="logo_image" id="logo_image" class="form-control input-sm">
                            <span class="help-block">Note 1: Accepted image formats: JPG/JPEG, GIF, PNG
                            <br/>Note 2: Try to upload 85x74 pixels images to avoid automatic resizing.</span>
                        </div>
                    </div>

                    <?php
                    if(isset($advertisment_id) && intval($advertisment_id) > 0) {
                        ?>
                        <div class="form-group">
                            <label class="control-label col-sm-3">Actions</label>
                            <div class="col-sm-7">

                                    <input type="radio" name="chcAction" value="edit" checked="checked"> Edit
                                    <input type="radio" name="chcAction" value="delete"> Delete

                            </div>
                        </div>
                        <?php
                    }
                    else {
                        ?>
                        <input type="hidden" name="chcAction" value="add">
                        <?php
                    }
                    ?>

                </fieldset>
                <input type="hidden" name="main_location" value="1">
                <input type="hidden" name="cust_code" id="cust_code" value="<?php echo $cust_code;?>">
                <input type="hidden" name="adv_code" id="adv_code" value="<?php echo $adv_code;?>">
                <input type="hidden" name="register" value="yes">
                <input type="hidden" name="open_window" value="no">
                <input type="hidden" name="member_id" value="<?php echo $member_id;?>">
                <?php
                if($chcAction == "edit" && isset($advertisment_id) && intval($advertisment_id)>0) {
                    ?>
                    <input type="hidden" name="advertisment_id" value="<?php echo $advertisment_id;?>">
                    <?php
                }

                if(isset($location_id) && intval($location_id) > 0) {
                    ?>
                    <input type="hidden" name="location_id" value="<?php echo $location_id;?>">
                    <?php
                }

                if(!$has_logo) {
                    ?>
                    <input type="hidden" name="no_logo" value="1">
                    <?php
                }
                ?>
                <div class="box-footer">
                    <div class="text-center">
                        <button type="submit" name="submit" class="btn btn-success btn-sm">Submit</button>
                    </div>
                </div>
                </form>
            </div>

        </article>

		<?php
		
	}
}
else {
	
	//$logmsg = '<h2>Free Listing Requirements</h2>';
	//$logmsg .= '<p>You must be a registered user in order to add a free listing. Please log in or register in order to add or edit your free listing.</p>';
	
	$logmsg = '<div itemtype="http://schema.org/Article" itemscope="" class="article cyprus">
					<header>
					<h1><span itemprop="name">Free Listing</span></h1>
					<!--[/SocialShareButtons/]-->
				</header>
				<div itemprop="articleBody" class="article-body">
					<div class="alert alert-warning">
						<p>You must be a registered user in order to add a free listing. Please log in or register in order to add or edit your free listing.</p>
					</div>
				</div>
			</div>';
	
	
	echo $logmsg;
	
	$webpage_title_en = stripslashes($line_domain['title_en']) . " | Post Free Listing";
	
	/*
	$logmsg_id= $line_domain['UnauthMsg'];	
	$querymsg = "SELECT * FROM  main_article WHERE article_id = '$logmsg_id'";
	
	$resultmsg = @mysql_query ($querymsg);
	if($resultmsg && mysql_num_rows($resultmsg) == 1) {

		$row = mysql_fetch_assoc($resultmsg);
		$middle_article_id = $row['article_id'];
		$logmsg_file = dirname(__FILE__) . "/main_article/main_article.php";
		if(file_exists($logmsg_file)) {
			require_once($logmsg_file);
		}
		
		unset($middle_article_id);
	}
	else {
		$querymsg = "SELECT * FROM  article WHERE article_id = '$logmsg_id'";
		$resultmsg = @mysql_query ($querymsg);
		if($resultmsg && mysql_num_rows($resultmsg) == 1) {
			$linemsg = mysql_fetch_assoc($resultmsg);
			$logmsg = "<p>";
			if($linemsg["url"]<>""){
				$logmsg .= "<a href=\"$linemsg[url]\""; 
				if($linemsg["_blank"]=="yes"){
					$logmsg .= " target=\"_blank\"";
				} 
				$logmsg .= ">";
				$logmsg .="<strong>"; 
				$logmsg .= $linemsg["title_en"]; 
				$logmsg .="</strong></a>"; 
			}
			else{
				if ($linemsg["active_title_en"]=="yes"){ 
					$logmsg .="<span class=darkBlueBold>{$linemsg['title_en']}</span><br><br>"; 
				}
				$logmsg .= $linemsg["description_en"]; 
			}
			$logmsg .="</p>";
		}
		else {
			$logmsg = '<h2>Free Listing Requirements</h2>';
			$logmsg .= '<p>You must be a registered user in order to add a free listing. Please log in or register in order to add or edit your free listing.</p>';

		}
		
		
		echo $logmsg;
	}
	*/
}
?>