<?php
if (!session_is_registered ("member_id")){
	?>
	<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td><img src="<?=$path;?>images/navigation/featured_box/featured_left.gif" width="14" height="29"></td>
									<td class="featuredHeader">Post a Job</td>
									<td><img src="<?=$path;?>images/navigation/featured_box/featured_cor.gif" width="29" height="29"></td>
								</tr>
							</table>
						</td>
						<td align="right">.</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table align=center border=0 cellpadding=0 cellspacing=0 width="100%">
					<tr>
						<td height=10 width=10>
							<img height=10 src="<?=$path;?>images/navigation/featured_box/box_1.gif" width=10>
						</td>
						<td background="<?=$path;?>images/navigation/featured_box/box_top.gif"></td>
						<td width=10>
							<img height=10 src="<?=$path;?>images/navigation/featured_box/box_2.gif" width=12>
						</td>
					</tr>
					<tr>
						<td background="<?=$path;?>images/navigation/featured_box/box_left.gif"></td>
						<td align="center" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td valign="top">
										<TABLE Align="Center" Width="100%" BORDER="0" CellPadding="5" CellSpacing="1">
											<TR>
												<TD> <B>To post a job you must be registered member. Please <a href="index.php?module_page=add_member">register</a>. It is absolutely free. </B></TD>
											</TR>
										</Table>
									</td>
								</tr>
							</table>
	          			</td>
						<td background="<?=$path;?>images/navigation/featured_box/box_right.gif"></td>
					</tr>
					<tr>
						<td height=12 width=10><img height=12 src="<?=$path;?>images/navigation/featured_box/box_3.gif" width=10></td>
						<td background="<?=$path;?>images/navigation/featured_box/box_bot.gif"></td>
						<td><img height=12 src="<?=$path;?>images/navigation/featured_box/box_4.gif" width=12></td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
<?php 
}
else{
	?>
	<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td><img src="<?=$path;?>images/navigation/featured_box/featured_left.gif" width="14" height="29"></td>
									<td class="featuredHeader">Post a Job</td>
									<td><img src="<?=$path;?>images/navigation/featured_box/featured_cor.gif" width="29" height="29"></td>
								</tr>
							</table>
						</td>
						<td align="right">.</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table align=center border=0 cellpadding=0 cellspacing=0 width="100%">
					<tr>
						<td height=10 width=10>
							<img height=10 src="<?=$path;?>images/navigation/featured_box/box_1.gif" width=10>
						</td>
						<td background="<?=$path;?>images/navigation/featured_box/box_top.gif"></td>
						<td width=10><img height=10 src="<?=$path;?>images/navigation/featured_box/box_2.gif" width=12></td>
					</tr>
      				<tr>
						<td background="<?=$path;?>images/navigation/featured_box/box_left.gif"></td>
						<td align="center" valign=top>
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td valign="top">
										<TABLE Align="Center" Width="100%" BORDER="0" CellPadding="5" CellSpacing="1">
											<TR>
							                    <TD> 
							                    	<span class="darkBlueBold">
							                        <?php 
							                        if($_GET["Submit"]=="Renew"){
														$job_jobs_id_to_renew=$_GET["job_jobs_id"];
														mysql_query("UPDATE job_jobs SET added_on=NOW(), added_on_time=NOW() WHERE job_jobs_id='$job_jobs_id_to_renew'") or die(mysql_error());
														?>
														Your Posted Job was Renewed successfully. Thank you!!<br>
														<?php 
							                        }
							                        ?>
							                        <?php 
							                        	$query_member_advert = "SELECT * FROM job_jobs WHERE member_id='$_SESSION[member_id]'";
														$result_member_advert = mysql_query ($query_member_advert);
														$table="job_jobs";
														$rows_array= array ("job_cat_id", "CompanyName", "Address", "Town", "Phone", "Mobile", "Fax", "ContactPerson", "EmailAdd", "JobTitle", "JobDescription", "NumberOfPersons", "Qualifications", "Other", "Location", "Conditions");
														$id="job_jobs_id";
														$member_id=$_SESSION["member_id"];
														if($Town=="other"){
															$Town=$othertown;
														}
														$Location=$Locations[0];
														for($i=1;$i<=count($Locations)-1;$i++){
															$Location .=";";
															$Location .=$Locations[$i];
														}
														if(isset($chcAction) && strlen($Location)<4){
															?>
															Some required fields have not been completed. Please try again.<br>
															<?php 
														}
														else{
															switch ($chcAction){
																case "Add":
																	$catdom_id=$domain_id;
																	$active="no";
																	$added_on=date("Y-m-d");
																	$rows="";
																	$variables="";
																	for ($i=0;$i<=(count($rows_array)-2);$i++){
																		$rows .=$rows_array[$i];
																		$variables .="'";
																		$variables .=$$rows_array[$i];
																		$variables .="'";
																		$rows .=", ";
																		$variables .=", ";
																	}
																	$rows .=$rows_array[count($rows_array)-1];
																	$variables .="'";
																	$variables .=$$rows_array[count($rows_array)-1];
																	$variables .="'";
																	$query1 = "INSERT INTO $table ($rows,catdom_id,active,member_id,added_on,added_on_time) VALUES ($variables,'$catdom_id','$active','$member_id','$added_on', NOW())";
																	$result1 = mysql_query ($query1) or die (mysql_error());
																	$job_jobs_id=mysql_insert_id();
																	?>
																	Your Job was Posted successfully. Thank you!!<br>
																	<?php
																break;
																
																case "Edit":
																	$rows="";
																	$variables="";
																	for ($i=0;$i<=(count($rows_array)-2);$i++){
																		$rows .=$rows_array[$i];
																		$rows .="=";
																		$rows .="'";
																		$rows .=$$rows_array[$i];
																		$rows .="'";
																		$rows .=", ";
																	}
																	$rows .=$rows_array[count($rows_array)-1];
																	$rows .="=";
																	$rows .="'";
																	$rows .=$$rows_array[count($rows_array)-1];
																	$rows .="'";
																	$query2 = "UPDATE $table SET $rows WHERE $id='".${$id}."'";
																	$result2 = mysql_query ($query2) or die(mysql_error());
																	?>
																	Your Posted Job Updated successfully. Thank you!!<br>
																	<? 
																break;
																
																case "Delete":
																	$query1 = "SELECT * FROM $table WHERE $id='${$id}'";
																	$result1 = mysql_query ($query1);
																	$line1 = mysql_fetch_array($result1);
																	$query1 = "DELETE FROM $table WHERE $id='${$id}'";
																	$result1 = mysql_query ($query1) or die(mysql_error());
																	$job_jobs_id=0;
																	?>
																	Your Posted Job Deleted successfully. Thank you!!<br>
																	<? 
																break;
															}
														}
														
														$query_job_cvs = "SELECT * FROM job_cvs WHERE job_cat_id=$_GET[job_cat_id] AND JobLocation='$_GET[Town]'";
														$line_config=mysql_fetch_assoc(mysql_query("SELECT * FROM job_config"));
														$NeedActivation=$line_config["NeedActivation"];
														$DaysToLive=$line_config["DaysToLive"];
														$Expiration=$line_config["Expiration"];
														if($NeedActivation=="yes"){
															?>
															Attention your Job Listings may not be displayed as the Administrator of the site should activate them.<br>
															<?php 
														}
														
														$result_member_advert = mysql_query ($query_member_advert);
														if(mysql_num_rows($result_member_advert)>0){
															?>
															<p>You have already posted the following Jobs:</p>
															</span>
															<table width="300"  border="0" cellpadding="3" cellspacing="2">
																<tr bgcolor="#D9ECFF">
																	<td class="darkBlueBold">Job Title </td>
																	<td align="right" class="darkBlueBold">Clicks</td>
																	<?php 
																	if($Expiration=="yes"){
																		?>
																		<td align="center" nowrap class="darkBlueBold">Expires on </td>
																		<td align="right" class="darkBlueBold">&nbsp;</td>
																		<? 
																	}
																	?>
																</tr>
																<?php	
																$formcount=1;
																$count=1;
																while($line_member_advert = mysql_fetch_array($result_member_advert)){
																	?>
																	<tr <?php if($count>1){echo " bgcolor=#F5FAFF";$count=0;}?>>
																		<td>
																			<span class="darkBlueBold">
																				<a href="index.php?module_page=my_jobs&amp;jobs_step=jobs_add&amp;job_jobs_id=<?=$line_member_advert["job_jobs_id"];?>">
																				<?php print $line_member_advert["JobTitle"];?>
																				</a>
																			</span>
																		</td>
																		<td align="right">
																			<span class="darkBlueBold">
																				<?php print $line_member_advert["clicks"];?>
																			</span>
																		</td>
																		<? 
																		if($Expiration=="yes"){
																			?>
																			<td align="center">
																				<span class="darkBlueBold">
																					<?php 
																					$date_for_format=$line_member_advert["added_on"];
																					$date_for_format=explode("-",$date_for_format);
																					$expire  = mktime(0, 0, 0, $date_for_format[1]  , $date_for_format[2]+$DaysToLive, $date_for_format[0]);
																					echo $ExpiresOn=date("d/m/Y", $expire);
																					?>
																				</span>
																			</td>
																			<td align="right">
																				<?php 
																				if($expire<=mktime(0, 0, 0, date("m"), date("d"), date("Y"))){
																					?>
																					<form name="form<?=$formcount;?>" method="get" action="index.php">
																						<input type="submit" name="Submit" value="Renew" class="input">
																						<input name="module_page" type="hidden" id="module_page" value="my_jobs">
																						<input type="hidden" name="jobs_step" value="jobs_add">
																						<input type="hidden" name="job_jobs_id" value="<?=$line_member_advert["job_jobs_id"];?>">
																					</form>
																					<?php 
																				}
																				else{
																					print "&nbsp;";
																				}
																				?>
																			</td>
																			<? 
																		}
																		?>
																	</tr>
																	<? 
																	$formcount++;
																	$count++;
																}
																?>
															</table>
															<span class="darkBlueBold">
															<?php 
														}
														?>
														<? 
														if($job_jobs_id>0){
															$query1 = "SELECT * FROM job_jobs";
															$query1 .=" WHERE job_jobs_id='$job_jobs_id' AND member_id='$_SESSION[member_id]'";
															$result1 = mysql_query ($query1);
															if(mysql_num_rows($result1)<1){
																?>
																<u><i>You have no right to edit this Posted Job. Please select from your own ones.</i></u>
																<? 
															}
															else{
																$line_job_jobs = mysql_fetch_array($result1);
															}
															?>
															<br>
															<?
														}
														?>
														</span>
													</TD>
												</TR>
												<tr>
													<td>
														<script language="JavaScript">
															function Confirm_delete() {
																alert("ATTENTION!! If you press Submit, your Posted Job will be DELETED.")
															}
															function checkFields() {
																missinginfo = "";
																if (document.form_job_jobs.job_cat_id.value == "") {
																missinginfo += "\n     -  Job Category";
																}
																if (document.form_job_jobs.CompanyName.value == "") {
																missinginfo += "\n     -  Company Name";
																}
																if (document.form_job_jobs.Address.value == "") {
																missinginfo += "\n     -  Address";
																}
																if (document.form_job_jobs.Town.value == "") {
																missinginfo += "\n     -  Town";
																}
																if (document.form_job_jobs.Town.value == "other" && (document.form_job_jobs.othertown.value == "other town" || document.form_job_jobs.othertown.value == "")) {
																missinginfo += "\n     -  Other Town";
																}
																if (document.form_job_jobs.Phone.value == "") {
																missinginfo += "\n     -  Phone";
																}
																if (document.form_job_jobs.ContactPerson.value == "") {
																missinginfo += "\n     -  Contact Person";
																}
																if (document.form_job_jobs.JobTitle.value == "") {
																missinginfo += "\n     -  Job Title";
																}
																if (document.form_job_jobs.JobDescription.value == "") {
																missinginfo += "\n     -  Job Description";
																}
		
		
																if (missinginfo != "") {
																missinginfo ="_____________________________\n" +
																"You failed to correctly fill in your:\n" +
																missinginfo + "\n_____________________________" +
																"\nPlease re-enter and submit again!";
																alert(missinginfo);
																return false;
																}
																else 
																return true;
															}
														</script>

														<form action="index.php" method="post" enctype="multipart/form-data" name="form_job_jobs" id="form_job_jobs" onSubmit="return checkFields();">
														<table width="100%" border="0" cellspacing="0" cellpadding="2">
															<tr>
																<td class="darkBlueBold">Note: * fields required</td>
																<td valign="top">&nbsp;</td>
															</tr>
																<tr>
																<td>&nbsp;</td>
																<td valign="top">&nbsp;</td>
															</tr>
															<tr>
																<td>Job category:</td>
																<td valign="top">
																	<?php 
																	$queryjob_cat = "SELECT * FROM  job_cat WHERE active='yes' ORDER BY order_seq ASC";
																	$resultjob_cat = mysql_query ($queryjob_cat);
																	$NumberOfFieldsjob_cat=mysql_num_rows($resultjob_cat);
																	if ($NumberOfFieldsjob_cat <> 0){
																		?>
																		<select name="job_cat_id" class="input" id="job_cat_id">
																			<option value="" selected>CHOOSE CATEGORY</option>
																			<? 
																			while($linejob_cat = mysql_fetch_array($resultjob_cat)){
																				?>
																				<option value="<? echo $linejob_cat["job_cat_id"];?>"<? if($linejob_cat["job_cat_id"]==$line_job_jobs["job_cat_id"]) echo " selected";?>><? echo $linejob_cat["title_en"];?></option>
																				<? 
																			}
																			?>
																		</select> *
																		<? 
																	}
	                                    							else{
	                                    								?>
									                                    No Categories exist yet
									                                    <? 
	                                    							}
	                                    							?>
																</td>
															</tr>
															<tr>
																<td class="darkBlueBold">&nbsp;</td>
																<td valign="top">&nbsp;</td>
															</tr>
															<tr>
																<td class="darkBlueBold">Mailing details : </td>
																<td valign="top">&nbsp;</td>
															</tr>
															<tr>
																<td>Company name:</td>
																<td valign="top"><input name="CompanyName" type="text" class="input" id="CompanyName" value="<?=$line_job_jobs["CompanyName"];?>" size="30" maxlength="100"> *</td>
															</tr>
															<tr>
																<td valign="top">Address:</td>
																<td valign="top"><textarea name="Address" cols="30" rows="2" wrap="VIRTUAL" class="input" id="Address"><?=$line_job_jobs["Address"];?></textarea> *</td>
															</tr>
															<tr>
																<td>Town:</td>
																<td valign="top">
																	<span class="right">
																		<span class="moreInfo">
																		<?php 
																		$querydistricts = "SELECT * FROM  districts WHERE active='yes' ORDER BY order_seq ASC";
																		$resultdistricts = mysql_query ($querydistricts);
																		if (mysql_num_rows($resultdistricts) <> 0){?>
																			<select class="input" name="Town" id="Town">
																				<option value="" selected>Select</option>
																				<?php 
																				while($linedistricts = mysql_fetch_array($resultdistricts)){
																					?>
																					<option value="<?=$linedistricts["title_en"];?>"<? if($linedistricts["title_en"]==$line_job_jobs["Town"]){echo " selected";$TownFound++;}?>>
																						<?php print $linedistricts["title_en"]; ?>
																					</option>
																					<? 
																				}
																				?>
																				<option value="other"<? if(isset($line_job_jobs["Town"]) && $TownFound<1)echo " selected";?>>Other</option>
																			</select>
																			<? 
																		}
																		else{
																			?>
																			No districts added yet.
																			<? 
																		}
																		?>* 
																		<input class="input" name="othertown" type="text" id="othertown" value="<? if(isset($line_job_jobs["Town"]) && $TownFound<1){echo $line_job_jobs["Town"];}else{?>other town<? }?>" size="30" maxlength="50">
																		</span>
																	</span>
																</td>
															</tr>
                                  							<tr>
																<td>Phone:</td>
																<td valign="top"><input name="Phone" type="text" class="input" value="<?=$line_job_jobs["Phone"];?>" size="15" maxlength="15">*</td>
															</tr>
															<tr>
																<td>Mobile:</td>
																<td valign="top"><input name="Mobile" type="text" class="input" value="<?=$line_job_jobs["Mobile"];?>" size="15" maxlength="15"></td>
															</tr>
															<tr>
																<td>Fax:</td>
																<td valign="top"><input name="Fax" type="text" class="input" id="Fax" value="<?=$line_job_jobs["Fax"];?>" size="15" maxlength="15"></td>
															</tr>
															<tr>
																<td>Contact person:</td>
																<td valign="top"><input name="ContactPerson" type="text" class="input" id="ContactPerson" value="<?=$line_job_jobs["ContactPerson"];?>" size="30" maxlength="100">*</td>
															</tr>
															<tr>
																<td>E-mail address:</td>
																<td valign="top"><input name="EmailAdd" type="text" class="input" id="EmailAdd" value="<?=$line_job_jobs["EmailAdd"];?>" size="30" maxlength="100">
															</td>
															</tr>
															<tr>
																<td class="darkBlueBold">&nbsp;</td>
																<td valign="top">&nbsp;</td>
															</tr>
															<tr>
																<td class="darkBlueBold">Position details:</td>
																<td valign="top">&nbsp;</td>
															</tr>
															<tr>
																<td>Job title :</td>
																<td valign="top"><input name="JobTitle" type="text" class="input" id="JobTitle" value="<?=$line_job_jobs["JobTitle"];?>" size="30" maxlength="100">*</td>
															</tr>
															<tr>
																<td valign="top">Job description:</td>
																<td valign="top"><textarea name="JobDescription" cols="50" rows="3" wrap="VIRTUAL" class="input" id="JobDescription"><?=$line_job_jobs["JobDescription"];?></textarea>*</td>
															</tr>
															<tr>
																<td valign="top">Number of persons required: </td>
																<td valign="top"><input name="NumberOfPersons" type="text" class="input" id="NumberOfPersons" value="<?=$line_job_jobs["NumberOfPersons"];?>" size="3" maxlength="3"></td>
															</tr>
															<tr>
																<td valign="top">Qualifications required:</td>
																<td valign="top"><textarea name="Qualifications" cols="50" rows="3" wrap="VIRTUAL" class="input" id="Qualifications"><?=$line_job_jobs["Qualifications"];?></textarea></td>
															</tr>
															<tr>
																<td valign="top">Other requirements:</td>
																<td valign="top"><textarea name="Other" cols="50" rows="3" wrap="VIRTUAL" class="input" id="Other"><?=$line_job_jobs["Other"];?></textarea></td>
															</tr>
															<tr>
																<td valign="top">Location(s):</td>
																<td valign="top">
																	<span class="right">
																		<span class="moreInfo">
																			<?php 
																			$querydistricts = "SELECT * FROM  districts WHERE active='yes' ORDER BY order_seq ASC";
																			$resultdistricts = mysql_query ($querydistricts);
																			if (mysql_num_rows($resultdistricts) <> 0){
																				while($linedistricts = mysql_fetch_array($resultdistricts)){
																					?>
																					<input type="checkbox" name="Locations[]" value="<?=$linedistricts["title_en"];?>"<? if(strstr($line_job_jobs["Location"],$linedistricts["title_en"])){echo " checked";}?>>
																					<?php print $linedistricts["title_en"]; ?>
																					<? 
																				}
																			}
																			else{
																				?>
																				No districts added yet.
																				<?php 
																			}
																			?> * 
																		</span>
																	</span>
																</td>
															</tr>
															<tr>
																<td valign="top">Employment conditions: </td>
																<td valign="top">
																	<select name="Conditions" class="input">
																		<option value="" selected>Select</option>
																		<option value="Full Time"<? if($line_job_jobs["Conditions"]=="Full Time"){echo " selected";}?>>Full Time</option>
																		<option value="Half Time"<? if($line_job_jobs["Conditions"]=="Half Time"){echo " selected";}?>>Half Time</option>
																		<option value="Temporary"<? if($line_job_jobs["Conditions"]=="Temporary"){echo " selected";}?>>Temporary</option>
																		<option value="Permanent"<? if($line_job_jobs["Conditions"]=="Permanent"){echo " selected";}?>>Permanent</option>
																		<option value="Any"<? if($line_job_jobs["Conditions"]=="Any"){echo " selected";}?>>Any</option>
																	</select>
																</td>
															</tr>
															<tr align="center">
																<td colspan="2">
																	<input name="module_page" type="hidden" id="module_page" value="my_jobs">
																	<input type="hidden" name="jobs_step" value="jobs_add">
																	<input name="job_jobs_id" type="hidden" id="job_jobs_id" value="<?=$job_jobs_id;?>">
																	<?php 
																	if ($job_jobs_id>0 && mysql_num_rows($result1)>0){
																		?>
																		<table width="0%" border="0" cellspacing="2" cellpadding="2">
																			<tr>
																				<td>
																					<input class="input" name="chcAction" type="radio" value="Edit" checked> Edit
																				</td>
																				<td>
																					<input class="input" type="radio" name="chcAction" value="Add">Add New
																				</td>
																				<td>
																					<input class="input" type="radio" name="chcAction" value="Delete" onClick="Confirm_delete();">Delete
																				</td>
																			</tr>
																		</table>
																		<br>
																		<span class="red"> </span>
																		<input type="submit" name="Submit2" value="Submit">
																		<? 
																	}
																	else{
																		?>
																		<input type="submit" name="Submit22" value="Add">
																		<input name="chcAction" type="hidden" id="chcAction" value="Add">
																		<? 
																	}
																	?>
																</td>
															</tr>
														</table>
                            							</form>
                            						</td>
                          						</tr>
                      						</Table>
										</td>
									</tr>
								</table>
							</td>
							<td background="<?=$path;?>images/navigation/featured_box/box_right.gif"></td>
						</tr>
						<tr>
							<td height=12 width=10><img height=12 src="<?=$path;?>images/navigation/featured_box/box_3.gif" width=10></td>
							<td background="<?=$path;?>images/navigation/featured_box/box_bot.gif"></td>
							<td><img height=12 src="<?=$path;?>images/navigation/featured_box/box_4.gif" width=12></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
    	<? 
}

?>

