<?php
#######################################
#                                                                                                                #
#  adaptetion for AntiSlaed  42 Vladimir Sulatskov aka Sulla_l_k   #
#                                                                                                                #
#######################################
if (!defined('MODULE_FILE')) {
	Header("Location: ../../index.php");
	exit;
}
get_lang($conf['name']);
require_once("config/config_vakancy.php");
require_once("modules/".$conf['name']."/comment.php");


function color($sourse, $textsout) {
	if ($textsout)  {
	  $textoutser = "#".$textsout."#i";
	  $textoutser2 = "<font style=\"background-color: #FFFF00; color: #FF0000;\">".$textsout."</font>";
	  $sourse = text_filter($sourse);
	  $sourse = preg_replace ($textoutser, $textoutser2, $sourse);
	}
	return $sourse;
}

function menu() {
	global $prefix, $db, $add, $addquest, $conf;
	open();
	echo "<center><font class=\"title\"><b>"._WORK."</b></font><br><br>"
		."<form action=\"index.php?name=".$conf['name']."\" method=\"post\">
		<input type=\"hidden\" name=\"op\" value=\"searchs\"><input type=\"text\" size=\"30\" name=\"query\" value=\"".$_POST['query']."\">&nbsp;<select name='type' style='width=150px;'>"
		."<option value=\"2\">"._WORK40."</option>"
		."<option value=\"3\">"._WORK41."</option>"
		."<option value=\"0\">"._WORK42."</option>"
		."<option value=\"1\">"._WORK43."</option>"
		."</select>"
		."&nbsp;<input type=\"submit\" title=\""._SEARCH."\" value=\""._SEARCH."\"><br>"
		."<input type='radio' name='xoffer' value='1' checked>&nbsp;"._WORK30." &nbsp;<input type='radio' name='xoffer' value='0'>&nbsp;"._WORK26." </form>"
		."[ <a href=\"index.php?name=".$conf['name']."\" title=\""._HOME."\">"._HOME."</a>";
	if ((is_user($user) && $add == 1) || (!is_user($user) && $addquest == 1)) echo " | <a href=\"index.php?name=".$conf['name']."&op=add\" title=\""._ADD."\">"._ADD."</a>";
	echo " ]</center>";
	close();
}

function searchs($query, $type, $xoffer) {
global $prefix, $db, $admin, $delwork, $tabcolumn, $showsubkat, $admin_file, $pagetitle, $conf, $stop;
	$pagetitle = "".$conf['defis'].""._WORK." ".$conf['defis'].""._SEARCH."";
	head();
	$e = explode(" ", $query);
	for ($a = 0; $a < sizeof($e); $a++) {
		$o = strlen($e[$a]);
	}
	if ($o < 3) $stop = "<font class=\"option\"><b>"._ERROR_2."</b></font>";
	if ($query == "")$stop = "<font class=\"option\"><b>"._ERROR_1."</b></font>";
	if (!$stop) {

		if ($type == 0) {
			$result = $db->sql_query("SELECT lid, cid, author, authormail, title, description, offer, telefone, address, contact, salary, information, ip, hits, date FROM ".$prefix."_vakancy WHERE title LIKE '%$query%' AND offer= '$xoffer'");
		} elseif ($type == 1) {
			$result = $db->sql_query("SELECT lid, cid, author, authormail, title, description, offer, telefone, address, contact, salary, information, ip, hits, date FROM ".$prefix."_vakancy WHERE description LIKE '%$query%' AND offer= '$xoffer'");
		} elseif ($type == 2) {
			$result = $db->sql_query("SELECT lid, cid, author, authormail, title, description, offer, telefone, address, contact, salary, information, ip, hits, date FROM ".$prefix."_vakancy WHERE salary LIKE '%$query%' AND status!='0' AND offer= '$xoffer'");
		} elseif ($type == 3) {
			$result = $db->sql_query("SELECT lid, cid, author, authormail, title, description, offer, telefone, address, contact, salary, information, ip, hits, date FROM ".$prefix."_vakancy WHERE author LIKE '%$query%' OR title LIKE '%$query%' OR description LIKE '%$query%' OR address LIKE '%$query%' OR salary LIKE '%$query%' OR information LIKE '%$query%' AND offer= '$xoffer'");
		}
		$nrows = $db->sql_numrows($result);
		$lid = intval($lid);
		$cid = intval(trim($cid));
		$x=0;
		$the_query = stripslashes($query);
		$the_query = str_replace("\'", "'", $the_query);
		menu();
		if ($nrows>0) {
		open();
		$a = 1;
		echo "<center><font class=\"option\">"._SEARC."</font></center><br>" ;
			while(list($lid, $cid, $author, $authormail, $title, $description, $offer, $telefone, $address, $contact, $salary, $information, $ip, $hits, $date) = $db->sql_fetchrow($result)) {
				$linkstrip = stripslashes($description);
				if (strlen($linkstrip) > $strip) {
					$linkstrip = substr($linkstrip, 0, $strip);
					$linkstrip .= "...";
				}
				echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" class=\"bgcolor4\"><tr><th width=\"70%\"><div align=\"left\"><a href=\"index.php?name=".$conf['name']."&op=view&lid=$lid\" title=\"$title\"><b>".color($title,$query)."</b></a></div></th><th width=\"30%\"><div align=\"right\">"._DATE.": ".date("d.m.Y, H:i",$date)."</div></th></tr>"
				."<tr class=\"bgcolor1\"><td colspan=\"3\">".color(cutstr(bb_decode($description, $conf['name']), 250), $query)."</td></tr>"
				."<tr class=\"bgcolor1\"><td colspan=\"3\">"
				."<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\"100%\">"
				."<td align=\"left\"><a href=\"index.php?name=".$conf['name']."&op=view&lid=$lid\" title=\""._WORK24."\"><b>"._WORK24."</b></a> | "._WORK15.":&nbsp;<b>".color($salary,$query)."</b></a></td><td align=\"right\"> "._WORK23.":<a href=index.php?name=Account&op=userinfo&user_name=$author>$author</a> |"._WORK17.": <b>$hits</b></td></table></td></tr>";


				if($delwork ==1){
					if ($expire && $expire < time()) $db->sql_query("DELETE FROM ".$prefix."_vakancy WHERE lid='$lid'");
				}else{
					if ($expire && $expire < time()) $db->sql_query("UPDATE ".$prefix."_vakancy SET status='0', expire='0' WHERE lid='$lid'");
				}
				if (is_admin($admin)) {
					echo "<tr class=\"bgcolor1\"><td colspan=\"3\" align=\"center\">[ <a href=\"index.php?name=".$conf['name']."&op=delite&lid=$lid&type=1\">"._DELETE."</a> | <a href=\"index.php?name=".$conf['name']."&op=edit&lid=$lid\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=SecurityBlocker&new_ip=$ip\" title=\""._BANIPSENDER."\">"._BANIPSENDER."</a> ]</td></tr>";
				}
				echo "</table><br />";
			}
		close();
		} else {
			warning(""._NOMATCHES."", "?name=".$conf['name'], 10, 2);
		}
	} else {
		menu();
		warning("".$stop."", "?name=".$conf['name'], 10, 2);
	}

 foot();
}
function categ($id="") {
        global $prefix, $db, $conf, $tabcolumn, $showsubkat;
        static $massiv, $massiv2;
        $id = (intval($id)) ? $id : 0;
        $where = ($id) ? "WHERE parentid = '$id'" : "";
        $tdwidth = intval(100/$tabcolumn);
        if (!is_array($massiv)) {
                $result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_vakancy_categories ".$where."");
                while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv[] = array($cid, $title, $parentid);
        }
        if (!is_array($massiv2)) {
                $result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_vakancy_categories");
                while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv2[] = array($cid, $title, $parentid);
        }
        if ($massiv) {
            foreach ($massiv as $key => $val) {
                if ($val[2] == $id) {
                   $ccontent .= "<td valign=\"top\" width=\"".$tdwidth."%\">"
						."<table border=\"0\">"
						."<tr>"
							."<td><img border=\"0\" src=\"modules/".$conf['name']."/images/navi.gif\" title=\"$title\"></td>"
							."<td><a href=\"index.php?name=".$conf['name']."&op=cat&id=$val[0]\" title=\"$val[1]\"><b>$val[1]</b></a></td>"
						."</tr>";
                    if ($showsubkat == 1 && $massiv2) {
                        foreach ($massiv2 as $key => $val2) {
                            if ($val[0] == $val2[2]) {
                                $ccontent .= "<tr><td colspan=\"2\"><img border=\"0\" src=\"images/navi.gif\" title=\"$val2[1]\"> <a href=\"index.php?name=".$conf['name']."&op=cat&id=$val2[0]\" title=\"$val2[1]\">$val2[1]</a></td></tr>";
                            }
                        }
                    }
                    $ccontent .= "</table></td>";
                    if ($cont == ($tabcolumn - 1)) {
                        $ccontent .= "</tr><tr>";
                        $cont = 0;
                    } else {
                        $cont++;
                    }
                }
            }
        }
        if ($ccontent) {
            open();
                echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\"><tr>".$ccontent."</td></tr></table>";
                list($s_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_vakancy WHERE offer='0' AND status!='0'"));
				list($l_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_vakancy WHERE offer='1' AND status!='0'"));
				list($cat_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) FROM ".$prefix."_vakancy_categories"));
				echo "<hr><center>"._WORK39." | "._WORK25.": <b>$s_num</b> | "._WORK26.": <b>$l_num</b> | "._WORK27." <b>$cat_num</b> "._WORK28."</center>";
            close();
        }
}

function cat() {
	global $prefix, $db, $admin, $delwork, $pag, $admin_file, $pagetitle, $conf;
	$cid = intval($_GET['id']);
$num = isset($_GET['num']) ? intval($_GET['num']) : "1";
	if ($num == "") $num = 1;
$offset = ($num-1) * $pag;
	list($cat_title) = $db->sql_fetchrow($db->sql_query("SELECT title FROM ".$prefix."_vakancy_categories  WHERE cid='$cid'"));
	$pagetitle = "".$conf['defis'].""._WORK." ".$conf['defis']." $cat_title";
	head();
menu();
	open();
	echo "<center><font class=\"option\">".$cat_title."</font></center>";
	close();
	categ($cid);
open();
$offset = intval($offset);
	$pag = intval($pag);
$result = $db->sql_query("SELECT lid,  author, authormail, title, description, telefone, address, contact, salary, information, ip, hits, date FROM ".$prefix."_vakancy  WHERE cid = '$cid' AND status !='0' ORDER BY lid DESC LIMIT  $offset, $pag");
while(list($lid, $author, $authormail, $title, $description, $telefone, $address, $contact, $salary, $information, $ip, $hits, $date) = $db->sql_fetchrow($result)) {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" class=\"bgcolor4\"><tr><th width=\"70%\"><div align=\"left\"><a href=index.php?name=".$conf['name']."&op=view&lid=$lid title=\"$title\"><b>$title</b></a></div></th><th width=\"30%\"><div align=\"right\">"._DATE.": ".date("d.m.Y, H:i",$date)."</div></th></tr>"
   ."<tr class=\"bgcolor1\"><td colspan=\"3\">".cutstr(bb_decode($description, $conf['name']), 250)."</td></tr>"
   ."<tr class=\"bgcolor1\"><td colspan=\"3\">
   <table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\"100%\">
   <td align=\"left\"><a href=\"index.php?name=".$conf['name']."&op=view&lid=$lid\" title=\""._WORK24."\"><b>"._WORK24."</b></a> | "._WORK15.":&nbsp;<b>$salary</b></a></td><td align=\"right\"> "._WORK23.":<a href=index.php?name=Account&op=userinfo&user_name=$author>$author</a> |"._WORK17.": <b>$hits</b></td></table></td></tr>";
 	if (is_admin($admin)) {
	echo "<tr class=\"bgcolor1\"><td colspan=\"3\" align=\"center\">[ <a href=index.php?name=".$conf['name']."&op=delite&lid=$lid&p_cid=$cid&type=2&num=$num>"._DELETE."</a> | <a href=\"index.php?name=".$conf['name']."&op=edit&lid=$lid&p_cid=$cid&type=2&num=$num\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=SecurityBlocker&new_ip=$ip\" title=\""._BANIPSENDER."\">"._BANIPSENDER."</a> ]</td></tr>";
	}
echo "</table><br />";
if($delwork ==1){
if ($expire && $expire < time()) $db->sql_query("DELETE FROM ".$prefix."_vakancy WHERE lid='$lid'");
 }else{
if ($expire && $expire < time()) $db->sql_query("UPDATE ".$prefix."_vakancy SET status='0', expire='0' WHERE lid='$lid'");
}
	}

close();
list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) AS ccid FROM ".$prefix."_vakancy AS c WHERE cid = '$cid' AND status !='0'"));
	$numpages = ceil($numstories / $pag);
	num_page($conf['name'], $numstories, $numpages, $pag, "op=cat&id=".$cid."&");
	get_page($conf['name']);
	foot();
}

function boardwork($parentid,$title) {
	global $prefix, $db;
	list($cid, $filetitle, $pparentid) = $db->sql_fetchrow($db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_vakancy_categories WHERE cid=$parentid"));
	if ($filetitle != "") $title = $filetitle."/".$title;
	if ($pparentid != 0) $title = boardwork($pparentid, $title);
	return $title;
}

function mains() {
global $prefix, $db, $admin, $num, $admin_file, $delwork, $pagetitle, $conf, $pagh;
$pagetitle = "".$conf['defis'].""._WORK."";
head();
   menu();
   categ();
   open();
   	$storynum = $pagh;
	$num = (!intval($num)) ? 1 : intval($num);
	$offset = ($num-1) * $storynum;
	$offset = intval($offset);
   $sql = "SELECT lid, cid, author, authormail, title, description, telefone, address, contact, salary, information, ip, hits, date, expire FROM ".$prefix."_vakancy WHERE status !='0' ORDER BY lid DESC LIMIT $offset, $storynum";
   $result = $db->sql_query($sql);
   while(list($lid, $cid, $author, $authormail, $title, $description, $telefone, $address, $contact, $salary, $information, $ip, $hits, $date, $expire) = $db->sql_fetchrow($result)) {
		echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" class=\"bgcolor4\"><tr><th width=\"70%\"><div align=\"left\"><a href=index.php?name=".$conf['name']."&op=view&lid=$lid title=\"$title\"><b>$title</b></a></div></th><th width=\"30%\"><div align=\"right\">"._DATE.": ".date("d.m.Y, H:i",$date)."</div></th></tr>"
		   ."<tr class=\"bgcolor1\"><td colspan=\"3\">".cutstr(bb_decode($description, $conf['name']), 250)."</td></tr>"
		   ."<tr class=\"bgcolor1\"><td colspan=\"3\">
		   <table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\"100%\">
		   <td align=\"left\"><a href=\"index.php?name=".$conf['name']."&op=view&lid=$lid\" title=\""._WORK24."\"><b>"._WORK24."</b></a> | "._WORK15.":&nbsp;<b>$salary</b></a></td><td align=\"right\"> "._WORK23.":<a href=index.php?name=Account&op=userinfo&user_name=$author>$author</a> |"._WORK17.": <b>$hits</b></td></table></td></tr>";
	 	if (is_admin($admin)) {
			echo "<tr class=\"bgcolor1\"><td colspan=\"3\" align=\"center\">[ <a href=index.php?name=".$conf['name']."&op=delite&lid=$lid&type=1&num=$num>"._DELETE."</a> | <a href=\"index.php?name=".$conf['name']."&op=edit&lid=$lid&num=$num&type=1\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=SecurityBlocker&new_ip=$ip\" title=\""._BANIPSENDER."\">"._BANIPSENDER."</a> ]</td></tr>";
		}
		echo "</table><br />";
		 if($delwork ==1){
		   if ($expire && $expire < time()) $db->sql_query("DELETE FROM ".$prefix."_vakancy WHERE lid='$lid'");
		 }else{
		   if ($expire && $expire < time()) $db->sql_query("UPDATE ".$prefix."_vakancy SET status='0', expire='0' WHERE lid='$lid'");
		  }
	}

	close();
		list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_vakancy WHERE status !='0'"));
		$numpages = ceil($numstories / $storynum);
		num_page($conf['name'], $numstories, $numpages, $storynum, "op=mains&");
	foot();
}

function delite($lid, $type, $num, $p_cid) {
global $prefix, $db, $conf;
	$db->sql_query("DELETE FROM ".$prefix."_vakancy WHERE lid='$lid'");
		if($type ==1){
			Header("Location: index.php?name=".$conf['name']."&op=mains&num=$num");
		}elseif($type ==2){
			Header("Location: index.php?name=".$conf['name']."&op=cat&id=$p_cid&num=$num");
		}
}

function add($cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information) {
global $db, $prefix, $add, $addquest, $user, $anonymous, $pagetitle, $conf, $userinfo, $stop;
	$pagetitle = "".$conf['defis'].""._WORK."".$conf['defis'].""._WORK4."";
	if ((is_user($user) && $add == 1) || (!is_user($user) && $addquest == 1)){
		head();
		menu();
		if (is_user($user)) {
			getusrinfo($user);
			$author = $userinfo['user_name'];
			$authormail = $userinfo['user_email'];
		} elseif (!is_user($user) AND $addquest == "1") {
			$author = $anonymous;
		} else {
			Header("Location: index.php?name=".$conf['name']."");
			exit;
		}
		open();
			echo "<center><font class=\"option\"><b>"._WORK4."</b></font>";
		close();
		if ($stop) warning($stop, "", "", 1);
		open();
		echo "<form name=\"post\" action=\"index.php?name=".$conf['name']."\" method=\"post\">
			<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\" class=\"bgcolor4\">
			<tr><th colspan=\"2\">"._WORK4."</th></tr>
			<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK1.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\"><input type=\"text\" name=\"title\" value=\"$title\" maxlength=\"100\" size=\"65\" style=\"width:400px;\"></td></tr>
			<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK3.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\">".textarea("1", "description", replace_break($description),  "vakancy", "5")."</td></tr>
<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK2.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\"><select name=\"cid\" style=\"width:400px;\"><option value=\"\">"._WORK14."</option>";
			$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_vakancy_categories ORDER BY parentid, title");
			while (list($cid2, $ctitle, $parentid2) = $db->sql_fetchrow($result)) {
					if ($cid2 == $cid) echo "<option value=\"$cid2\" selected>$ctitle</option>";
					echo "<option value=\"$cid2\">$ctitle</option>";
			}
		echo "</select></td></tr>";
		echo "<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK33.":</div></td><td class=\"bgcolor1\"><select name=\"add_expire\" style=\"width:400px;\">"
			 ."<option name=\"add_expire\" value=\"3\">"._WORK34."</option>"
			 ."<option name=\"add_expire\" value=\"5\">"._WORK35."</option>"
			 ."<option name=\"add_expire\" value=\"7\">"._WORK36."</option>"
			 ."<option name=\"add_expire\" value=\"15\">"._WORK37."</option>"
			 ."<option name=\"add_expire\" value=\"30\">"._WORK38."</option>"
			 ."</select></td></tr>";

		if($offer !=""){
			$sel1 = (!$offer) ? "checked" : "";
			$sel2 = ($offer) ? "checked" : "";
		}else{
			$sel1 = (!$offer) ? "" : "";
			$sel2 = ($offer) ? "" : "";
		}
		echo "<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK31.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\">"
			."<input type=\"radio\" name=\"offer\" value=\"0\" $sel1>"._WORK30." &nbsp;&nbsp; <input type=\"radio\" name=\"offer\" value=\"1\" $sel2>"._WORK29."</td></tr>";

		echo"<tr><th colspan=\"2\">"._WORK5."</th></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK8.":<font color=\"red\">*</font></div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"author\"  value=\"$author\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK9.":<font color=\"red\">*</font></div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"authormail\"  value=\"$authormail\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK6.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"telefone\" value=\"$telefone\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK7.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"address\" value=\"$address\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK12.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"contact\" value=\"$contact\" size=\"65\" style=\"width:400px;\"></td></tr>";
		echo"<tr><th colspan=\"2\">"._WORK13."</th></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK15.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"salary\"  value=\"$salary\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK16.":</div></td><td class=\"bgcolor1\"><textarea name=\"information\" cols=\"65\" rows=\"3\" style=\"width:400px;\">$information</textarea></td></tr>";
		echo "<tr><td colspan=\"2\" class=\"bgcolor1\"><center><input type=\"hidden\" name=\"op\" value=\"send\">"
			."<input type=\"submit\" value=\""._WORK4."\"></center></td></tr></form></table>";
		close();
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function edit($type, $num, $p_cid, $lid, $cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information) {
global $db, $prefix, $user, $editwork, $anonymous, $pagetitle, $conf, $stop;
	$pagetitle = "".$conf['defis'].""._WORK."".$conf['defis'].""._WORK4."";
		head();
		menu();
		$result = $db->sql_query("SELECT * FROM ".$prefix."_vakancy WHERE lid = '$lid'");
		if ($db->sql_numrows($result) > 0){
			$row = $db->sql_fetchrow($result);
			$description = $row['description'];
			$w_cid = $row['cid'];
			$author = $row['author'];
			$authormail = $row['authormail'];
			$title = $row['title'];
			$description = $row['description'];
			$offer = $row['offer'];
			$telefone  = $row['telefone'];
			$address = $row['address'];
			$contact = $row['contact'];
			$salary = $row['salary'];
			$information = $row['information'];
			$expire =$row['expire'];
		}

	if ((is_admin($admin) || ($author == $user[1]) && $editwork == 1)){
		open();
		echo "<center><font class=\"option\"><b>"._WORK4."</b></font></center>";
		close();
		if ($stop) warning($stop, "", "", 1);
		open();
		echo "<form name=\"post\" enctype=\"multipart/form-data\" action=\"index.php?name=".$conf['name']."\" method=\"post\">"
			."<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\" class=\"bgcolor4\">"
			."<tr><th colspan=\"2\">"._WORK4."</th></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK1.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\"><input type=\"text\" name=\"title\" value=\"$title\" maxlength=\"100\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK3.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\">".textarea("1", "description", replace_break($description), "vakancy", "5")."</td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK2.":<font color=\"red\">*</div></font></td><td class=\"bgcolor1\"><select name=\"cid\" style=\"width:400px;\"><option value=\"\">"._WORK14."</option>";
				$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_vakancy_categories ORDER BY parentid, title");
				while (list($cid2, $ctitle, $parentid2) = $db->sql_fetchrow($result)) {
					if ($parentid2 != 0) $ctitle = boardwork($parentid2, $ctitle);
					if ($cid2 == $w_cid) echo "<option value=\"$cid2\" selected>$ctitle</option>";
					echo "<option value=\"$cid2\">$ctitle</option>";
				}
		echo "</select></td></tr>";
		echo"<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK33.":</div></td><td class=\"bgcolor1\"><select name=\"add_expire\" style=\"width:400px;\">"
			."<option value=\"3\">"._WORK34."</option>"
			."<option value=\"5\">"._WORK35."</option>"
			."<option value=\"7\">"._WORK36."</option>"
			."<option value=\"15\">"._WORK37."</option>"
			."<option value=\"30\">"._WORK38."</option>"
			."</select></td></tr>";
		echo "</td></tr><tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK31."<font color=\"red\">*</div></font></td><td class=\"bgcolor1\">";

		if ($offer == 0) {
			echo "<input type='radio' name='offer' value='0' checked>&nbsp;"._WORK30." &nbsp;<input type='radio' name='offer' value='1'>&nbsp;"._WORK29."";
		} else {
			echo "<input type='radio' name='offer' value='0'>&nbsp;"._WORK30." &nbsp;<input type='radio' name='offer' value='1' checked>&nbsp;"._WORK29."";
		}
		echo"<tr><th colspan=\"2\">"._WORK5."</th></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK8.":<font color=\"red\">*</font></div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"author\"  value=\"$author\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK9.":<font color=\"red\">*</font></div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"authormail\"  value=\"$authormail\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK6.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"telefone\" value=\"$telefone\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK7.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"address\" value=\"$address\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK12.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"contact\" value=\"$contact\" size=\"65\" style=\"width:400px;\"></td></tr>";
		echo"<tr><th colspan=\"2\">"._WORK13."</th></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK15.":</div></td><td class=\"bgcolor1\"><input type=\"text\" name=\"salary\"  value=\"$salary\" size=\"65\" style=\"width:400px;\"></td></tr>"
			."<tr><td class=\"bgcolor1\"><div align=\"right\">"._WORK16.":</div></td><td class=\"bgcolor1\"><textarea name=\"information\" cols=\"65\" rows=\"3\" style=\"width:400px;\">$information</textarea></td></tr>";
		echo "<tr><td colspan=\"2\" class=\"bgcolor1\"><center>"
			."<input name=\"p_cid\" type=\"hidden\" value=\"$p_cid\">"
			."<input name=\"type\" type=\"hidden\" value=\"$type\">"
			."<input name=\"num\" type=\"hidden\" value=\"$num\">"
			."<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
			."<input type=\"hidden\" name=\"op\" value=\"update\">"
			."<input type=\"submit\" value=\""._SAVE."\"></center></td></tr></form></table>";
		close();
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function send($type, $num, $p_cid, $title, $lid, $description, $offer, $cid, $author, $authormail, $telefone, $address, $contact, $salary, $information, $add_expire) {
	global $prefix, $db, $add, $conf, $stop, $moder;
	if ($add == "1") {
		$time = time() + ($TIME_DIFFERENCE * 3600);
		$author = text_filter($author);
		$title  = text_filter($title);
		$description  = text_filter($description);
		$address  = text_filter($address);
		$contact = text_filter($contact);
		$salary = text_filter($salary);
		$information = text_filter($information);
		if ($add_expire == "" || $add_expire == 0) {
			$add_expire = 0;
		} else {
			$add_expire = time() + ($add_expire * 86400);
		}
		$ip = getenv("REMOTE_ADDR");
		if ($title == "") $stop = ""._WORK18."!";
			if ($description == "") $stop = ""._WORK19."!";
		if ($cid == "") $stop = ""._WORK20."!";
		if ($author == "") $stop = ""._WORK21."!";
		if ($authormail == ""){ 
			$stop = ""._WORK22."!";
		}else{
			checkemail($authormail);
		}
		if ($offer == "") $stop = ""._WORK32."!";
		if (!is_user($user)) {
			$stop_name = "";
			$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT user_id FROM ".$prefix."_users WHERE user_name = '$author' ") );
			$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT user_id FROM ".$prefix."_users_temp WHERE user_name = '$author' ") );
			$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT id FROM ".$prefix."_admins  WHERE name = '$author' ") );
			if ($stop_name != "") {
			 $stop = ""._ERROR_3."";
			}
		}

		if (!$stop) {
			if($moder==0){
				$db->sql_query("INSERT INTO ".$prefix."_vakancy VALUES (NULL, '$cid', '$author', '$authormail', '$title', '$description', '$offer', '$telefone', '$address', '$contact', '$salary', '$information', '$ip', '0', '$time', '1', '$add_expire')");
			}else{
				$db->sql_query("INSERT INTO ".$prefix."_vakancy VALUES (NULL, '$cid', '$author', '$authormail', '$title', '$description', '$offer', '$telefone', '$address', '$contact', '$salary', '$information', '$ip', '0', '$time', '0', '$add_expire')");
			}

			Header("Location: index.php?name=".$conf['name']);
			
		} else {
			add($cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information);
		}
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function update($num, $type, $p_cid, $lid, $title, $description, $offer, $cid, $author, $authormail, $telefone, $address, $contact, $salary, $information, $add_expire) {
global $prefix, $db,  $conf, $editwork, $stop;

	$time = time() + ($TIME_DIFFERENCE * 3600);
	$author = text_filter($author);
	$title  = text_filter($title);
	$description  = text_filter($description);
	$address  = text_filter($address);
	$contact = text_filter($contact);
	$salary = text_filter($salary);
	$information = text_filter($information);

	$ip = getenv("REMOTE_ADDR");
	if ($add_expire == "" || $add_expire == 0) {
		$add_expire = 0;
	} else {
		$add_expire = time() + ($add_expire * 86400);
	}
	if ($title == "") $stop = ""._WORK18."!";
	if ($description == "") $stop = ""._WORK19."!";
	if ($cid == "") $stop = ""._WORK20."!";
	if ($author == "") $stop = ""._WORK21."!";
	if ($authormail == ""){
		$stop = ""._WORK22."!";
	}else{
		checkemail($authormail);
	}		
	if ($offer == "") $stop = ""._WORK32."!";
	if (!is_user($user)) {
		$stop_name = "";
		$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT user_id FROM ".$prefix."_users WHERE user_name = '$author' ") );
		$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT user_id FROM ".$prefix."_users_temp WHERE user_name = '$author' ") );
		$stop_name .= list($stop_name1) = $db->sql_fetchrow( $db->sql_query("SELECT id FROM ".$prefix."_admins  WHERE name = '$author' ") );
		if ($stop_name != "") {
		 $stop = ""._ERROR_3."";
		}
	}

	if (!$stop) {
		$res=$db->sql_query("UPDATE ".$prefix."_vakancy SET cid='$cid', author='$author', authormail='$authormail', title='$title', description='$description', offer='$offer', telefone='$telefone', address='$address', contact='$contact', salary='$salary', information='$information', expire='$add_expire' WHERE lid='$lid'");
		if (!$res){
			echo "UPDATE ".$prefix."_vakancy SET cid='$cid', author='$author', authormail='$authormail', title='$title', description='$description', offer='$offer', telefone='$telefone', address='$address', contact='$contact', salary='$salary', information='$information', expire='$add_expire' WHERE lid='$lid'";
		}
			if($type ==1){
				Header("Location: index.php?name=".$conf['name']."&op=mains&num=$num");
			}elseif($type ==2){
				Header("Location: index.php?name=".$conf['name']."&op=cat&id=$p_cid&num=$num");
			}elseif($type ==3){
				Header("Location: index.php?name=".$conf['name']."&op=view&lid=$lid");
			}
	} else {
		edit($type, $num, $p_cid, $lid, $cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information);
	}
}

function view($lid) {
global $pagetitle, $prefix, $db, $admin, $user, $editwork, $comment, $delwork, $admin_file, $conf;
	$result = $db->sql_query("SELECT lid, cid, author, authormail, title, description, telefone, address, contact, salary, information, ip, hits, date, expire FROM ".$prefix."_vakancy WHERE lid='$lid'");
	if ($db->sql_numrows($result) > 0) {
		list($lid, $cid, $author, $authormail, $title, $description, $telefone, $address, $contact, $salary, $information, $ip, $hits, $date, $expire) = $db->sql_fetchrow($result);
		$hometext = $description;
		$pagetitle = "".$conf['defis'].""._WORK." ".$conf['defis']." $title";
		format_time($date);
	head();
	menu();
	open();
		if($information !=""){
			$information = "<hr><b>"._WORK16."</b><br>$information";
		}else{
			$information="";
		}

		if($editwork == 1){
			if ($author == $user[1]) {
				$edit = " | <a href=\"index.php?name=".$conf['name']."&op=edit&lid=$lid\" title=\""._EDIT."\">"._EDIT."</a>";
			} else {
				$edit = "";
			}

	}
	echo "<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"3\" class=\"bgcolor4\"><tr><th width=\"70%\"><div align=\"left\"><a href=index.php?name=".$conf['name']."&op=view&lid=$lid title=\"$title\"><b>$title</b></a></div></th><th width=\"30%\"><div align=\"right\">"._DATE.": ".date("d.m.Y, H:i",$date)."</div></th></tr>"
	   ."<tr class=\"bgcolor1\"><td colspan=\"3\">".bb_decode($description, $conf['name'])."$information</td></tr>"
	   ."<tr class=\"bgcolor1\"><td colspan=\"3\">
	   <table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\"100%\">
	   <td align=\"left\"><a href=\"index.php?name=".$conf['name']."&op=view&lid=$lid\" title=\""._WORK24."\"><b>"._WORK24."</b></a> | "._WORK15.":&nbsp;<b>$salary</b></a></td><td align=\"right\"> "._WORK23.":<a href=index.php?name=Account&op=userinfo&user_name=$author>$author</a> |"._WORK17.": <b>$hits</b> $edit</td></table></td></tr>";
 	
	if (is_admin($admin)) {
		echo "<tr class=\"bgcolor1\"><td colspan=\"3\" align=\"center\">[ <a href=\"index.php?name=".$conf['name']."&op=delite&lid=$lid&type=1\">"._DELETE."</a> | <a href=\"index.php?name=".$conf['name']."&op=edit&lid=$lid&type=3\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=SecurityBlocker&new_ip=$ip\" title=\""._BANIPSENDER."\">"._BANIPSENDER."</a> ]</td></tr>";
	}

	echo "</table><br />";

	if($delwork ==1){
		if ($expire && $expire < time()) {
			$db->sql_query("DELETE FROM ".$prefix."_vakancy WHERE lid='$lid'");
		}
	}else{
		if ($expire && $expire < time()){
			$db->sql_query("UPDATE ".$prefix."_vakancy SET status='0', expire='0' WHERE lid='$lid'");
		}
	}


	$db->sql_query("UPDATE ".$prefix."_vakancy SET hits=hits+1 WHERE lid='$lid'");
	close();

		if (!$acomm) {
			echo "<a name=\"c$lid\"></a>";
			board_show_com($lid, "", "");
		}
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']);
	}
}


//  параметр для определния
$op = isset($_POST['op']) ? $_POST['op'] : $_GET['op'];

switch($op) {
	case "cat":
		cat();
	break;

	case "searchs":
		//###########################################
			$query=$_POST['query'];
			$type=$_POST['type'];
			$xoffer=$_POST['xoffer'];
		//###########################################
		searchs($query, $type, $xoffer);
	break;

	case "view":
		$lid = intval($_GET['lid']);
		view($lid);
	break;

	case "add":
		//###########################################
			$cid = $_GET['cid'];
			$title = $_POST['title'];
			$description = $_POST['description'];
			$offer = $_POST['offer'];
			$author = $_POST['author'];
			$authormail = $_POST['authormail'];
			$telefone = $_POST['telefone'];
			$address = $_POST['address'];
			$contact = $_POST['contact'];
			$salary = $_POST['salary'];
			$information = $_POST['information'];
		//###########################################
		
		add($cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information);
	break;

	case "edit":
	    //###########################################
			$type = $_GET['type'];
			$num = $_GET['num'];
			$p_cid = $_GET['p_cid'];
			$lid = $_GET['lid'];
			$cid = $_POST['cid'];
			$title = $_POST['title'];
			$description = $_POST['description'];
			$offer = $_POST['offer'];
			$author = $_POST['author'];
			$authormail = $_POST['authormail'];
			$telefone = $_POST['telefone'];
			$address = $_POST['address'];
			$contact = $_POST['contact'];
			$salary = $_POST['salary'];
			$information = $_POST['information'];
			
	    //###########################################
		
		edit($type, $num, $p_cid, $lid, $cid, $title, $description, $offer, $author, $authormail, $telefone, $address, $contact, $salary, $information);
	break;

	case "delite":
		//###########################################
			$lid = $_GET['lid'];
			$type = $_GET['type'];
			$num = $_GET['num'];
			$p_cid = $_GET['p_cid'];
		//###########################################
		delite($lid, $type, $num, $p_cid);
	break;

	case "send":
		//###########################################
			$cid = $_POST['cid'];
			$title = $_POST['title'];
			$description = $_POST['description'];
			$offer = $_POST['offer'];
			$author = $_POST['author'];
			$authormail = $_POST['authormail'];
			$telefone = $_POST['telefone'];
			$address = $_POST['address'];
			$contact = $_POST['contact'];
			$salary = $_POST['salary'];
			$information = $_POST['information'];
			$add_expire = $_POST['add_expire'];
		//=============================
			$type = isset($_POST['type']) ? $_POST['type'] : $_GET['type'];
			$num = isset($_POST['num']) ? $_POST['num'] : $_GET['num'];
			$p_cid = $_GET['p_cid'];
			$lid = isset($_POST['lid']) ? $_POST['lid'] : $_GET['lid'];
	    //###########################################
		send($type, $num, $p_cid, $title, $lid, $description, $offer, $cid, $author, $authormail, $telefone, $address, $contact, $salary, $information, $add_expire);
	break;

	case "update":
		// для точного получения данных
			$num = $_POST['num'];
			$type = $_POST['type'];
			$p_cid = $_POST['p_cid'];
			$lid = $_POST['lid'];
			$cid = $_POST['cid'];
			$title = $_POST['title'];
			$description = $_POST['description'];
			$offer = $_POST['offer'];
			$author = $_POST['author'];
			$authormail = $_POST['authormail'];
			$telefone = $_POST['telefone'];
			$address = $_POST['address'];
			$contact = $_POST['contact'];
			$salary = $_POST['salary'];
			$information = $_POST['information'];
			$status = $_POST['status'];
			$add_expire = $_POST['add_expire'];
		//=============================
		
		update($num, $type, $p_cid, $lid, $title, $description, $offer, $cid, $author, $authormail, $telefone, $address, $contact, $salary, $information, $add_expire);
	break;

	case "view":
		view();
	break;
	
		case "board_save_com":
			$postname = text_filter(substr($_POST['postname'], 0, 25));
			$comment = $_POST['comment'];
			$cid = intval($_POST['cid']);
			board_save_com($postname, $comment, $cid);
		break;
		
		case "board_comm_edit":
			$id = intval($_GET['id']);
			board_comm_edit($id);
		break;
		
		case "board_comm_edit_save":
			$id = intval($_POST['id']);
			$cid = intval($_POST['cid']);
			$com_name = nl2br(text_filter($_POST['com_name'], 2));
			$com_text = nl2br(text_filter($_POST['comment'], 2));
			$db->sql_query("UPDATE ".$prefix."_vakancy_comment SET name='$com_name', comment='$com_text' WHERE id='$id'");
			Header("Location: index.php?name=".$conf['name']."&op=view&lid=$cid");
		break;
		
		case "board_comm_del":
			$id = intval($_GET['id']);
			$cid = intval($_GET['cid']);
			if ($id && $cid) {
				$db->sql_query("DELETE FROM ".$prefix."_vakancy_comment WHERE id='$id'");
			}
			Header("Location: index.php?name=".$conf['name']."&op=view&lid=".$cid);
		break;

	default:
		mains();
	break;
}
?>