<?
### Автор модулья Somon Ashuraliev ###
### Платное ###
### http://justwm.ru/us1 ###
$title = 'Биржа труда';
require_once ('../system/function.php');
require_once ('../system/header.php');
switch($_GET['act']) {
default:
$id = abs(intval($_GET['id']));

if($user['level'] >1) echo '<div class="menudiv"> <a href="/birga/nr"> Добавить раздел</a></div>';
echo '<div class="podmenu"><a href="/birga/my"> Мои предложения</a> | <img src="/design/vipolnil.png"> <a href="/birga/my_rob">Мои выполнения</a></div>';
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `birga_r`"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$pc_r = mysql_query("SELECT * FROM `birga_r` ORDER BY `id` DESC LIMIT $start, $max");
$birga_r = mysql_fetch_array(mysql_query('select * from `birga_r` where `id` = "'.$id.'"'));
$birga_ra = mysql_query('select * from `birga` where `r` = "'.$id.'"');
  while($birga_ra2 = mysql_fetch_array($birga_ra)){
  mysql_query("DELETE FROM `birga` WHERE `id` = '".$birga_ra2['id']."'");
  }

  mysql_query("DELETE FROM `birga_r` WHERE `id` = '$id'");


  
  while($pc_r2 = mysql_fetch_assoc($pc_r)){
  echo '<div class="menudiv"><img src="/design/rob.png"/> <a href="/birga/r'.$pc_r2['id'].'"><b>'.$pc_r2['name'].'</b></a> ('.mysql_result(mysql_query('select count(`id`) from `birga` where `r` = "'.$pc_r2['id'].'"'),0).')';
  
  if($user['level'] >= 1) echo ' [<a href="/birga?dr&amp;id='.$pc_r2['id'].'">уд</a>]';
  
  echo '</div>';
  }
 
break;

case 'my':
echo '<div class="title"><a href="'.$HOME.'/porte/">Портфолио</a> / Добавить портфолио</div>';
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `birga` where `author` = '".$user['id']."'"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$my = mysql_query("SELECT * FROM `birga` where `author` = '".$user['id']."' ORDER BY `id` DESC LIMIT $start, $max");
if(mysql_result(mysql_query('select count(`id`) from `birga` where `author` = "'.$user['id'].'" '),0) != 0)
  { 
  
  while($my2 = mysql_fetch_assoc($my)){
  echo '<div class="podmenu"><b>Дата:</b>  '.times($my2['time']).'</br>
  <b>Задание: </b> '.$my2['opis'].'</br>
  <b>Бюджет:</b> '.$my2['cena'].' p.
  </br> <a href="/birga/rob'.$my2['id'].'">Полная информация <b>»</b></a></br>';
  if($my2['status'] == 1){echo '<font color="red"><b>Заказ не актуален</b></font>';
  }else{
  echo '<font color="green"><b>Заказ актуален</b></font>';} 
  echo '</div>';
  }
  
  }else{
  echo '<div class="podmenu"><b>Вы еще не делали предложений..</b></div>';
  }
  if($k_page>1) echo str(''.$HOME.'/birga/my'.$id.'?',$k_page,$page); // Вывод страниц
break;
case 'myrob':
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `birga` where `login2` = '".$user['id']."'"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$my = mysql_query("SELECT * FROM `birga` where `login2` = '".$user['id']."' ORDER BY `id` DESC LIMIT $start, $max");
if(mysql_result(mysql_query('select count(`id`) from `birga` where `login2` = "'.$user['id'].'" '),0) != 0)
  { 
  
  while($my2 = mysql_fetch_assoc($my)){
  echo '<div class="lst"><b> Роботу предложил:</b>'.nick($my2['author']).'</a></br>
  <b>Дата:</b>  '.times($my2['time']).'</br>
  <b>Задание: </b> '.$my2['opis'].'</br>
  <b>Бюджет:</b> '.$my2['cena'].' p.
  </br> <a href="/birga/rob'.$my2['id'].'">Полная информация <b>»</b></a></br>';
  if($my2['status'] == 1){echo '<font color="red"><b>Заказ не актуален</b></font>';
  }else{
  echo '<font color="green"><b>Заказ актуален</b></font>';} 
  echo '</div>';
  }
  
  }else{
  echo '<div class="podmenu"><b>Вы еще не выполняли заказы..</b></div>';
  }
    if($k_page>1) echo str(''.$HOME.'/birga/myrob'.$id.'?',$k_page,$page); // Вывод страниц
break;

case 'r':
$id = abs(intval($_GET['id']));
$pc_r = mysql_fetch_array(mysql_query('select * from `birga_r` where `id` = '.$id.' limit 1'));
  if(empty($id) or !is_numeric($id) or $pc_r == 0){
  header('Location: /pc'); exit;
  }
echo '<div class="podmenu"><img src="/design/addcod.png"/> <a href="/birga/r'.$id.'/add">Предложить работу</a></div>';
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `birga` where `login2` = '".$user['id']."'"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$pc_code = mysql_query("SELECT * FROM `birga` where `r` = '".$id."' ORDER BY `id` DESC LIMIT $start, $max");
if(isset($_REQUEST['submit'])) {
$cid = abs(intval($_GET['cid']));
$pc_code = mysql_fetch_array(mysql_query('select * from `birga` where `id` = "'.$cid.'"'));

  $pc_r = mysql_fetch_array(mysql_query('select * from `birga_r` where `id` = "'.$id.'"'));

  if($pc_r == 0 or $pc_code == 0){
  header('Location: /birga/r'.$id.''); exit;
  }

  mysql_query("DELETE FROM `birga` WHERE `id` = '$cid'");

  header('Location: /birga/r'.$id.''); exit;

  }
  
  while($pc_code2 = mysql_fetch_assoc($pc_code)){
  echo '<div class="podmenu"><b> Роботу предложил:</b>'.nick($pc_code2['author']).'</a></br>
  <b>Дата:</b>  '.times($pc_code2['time']).'</br>
  <b>Задание: </b> '.$pc_code2['opis'].'</br>
  <b>Бюджет:</b> '.$pc_code2['cena'].' p.
  </br> <a href="/birga/rob'.$pc_code2['id'].'">Полная информация <b>»</b></a></br>';
  if($pc_code2['status'] == 1){echo '<font color="red"><b>Заказ не актуален</b></font>';
  }else{
  echo '<font color="green"><b>Заказ актуален</b></font>';} 
  echo '</div>';
  }
      if($k_page>1) echo str(''.$HOME.'/birga/r'.$id.'?',$k_page,$page); // Вывод страниц
break;
  
case 'rob':
$id = abs(intval($_GET['id']));


if (empty($user['max'])) $user['max']=10;
$birga_ro = mysql_fetch_array(mysql_query('select * from `birga` where `id` = '.$id.' limit 1'));
$birga_r = mysql_fetch_array(mysql_query('select * from `birga` where `id` = '.$id.' limit 1'));
if(empty($id) or !is_numeric($id) or $birga_ro == 0 or $birga_r == 0){
header('Location: /birga'); exit;
}
echo '<div class="title"><a href="'.$HOME.'/birga/">Биржа труда</a> / Просмотр задание</div>';
if(isset($_GET['del']) ){
mysql_query("DELETE FROM `birga` WHERE `id` = '$id'");
header('Location: /birga/c'.$id.''); exit;
}
  if($birga_ro['author'] == $user['id']){ 
  
  if($birga_ro['status'] == 0){
  echo '<div class="podmenu"><center><form action="" method="post">
  <input type="submit" value="Не актуально" name="neakt"/></center></div>';
  }
  
  if($birga_ro['status'] == 1){
  echo '<div class="podmenu"><center><form action="" method="post">
  <input type="submit" value="Актуально" name="akt"/></center></div>';
  }
  
  if(isset($_POST['neakt'])){
  $akt = strong($_POST['akt']);
  mysql_query("UPDATE `birga` SET `status`='1',`login2`='0' WHERE `id`='".$id."' limit 1");
  header('Location: /birga/rob'.$id.''); exit;
  }
  
  if(isset($_POST['akt'])){
  $akt = strong($_POST['akt']);
  mysql_query("UPDATE `birga` SET `status`='0',`login2`='0' WHERE `id`='".$id."' limit 1");
  header('Location: /birga/rob'.$id.''); exit;
  }
  
  }

echo '<div class="podmenu"><b> Роботу предложил:</b>'.nick($birga_ro['author']).'</br>
  <b>Дата:</b>  '.times($birga_ro['time']).'</br>
  <b>Задание: </b> '.$birga_ro['opis'].'</br>
  <b>Полное ТЗ: </b> '.$birga_ro['tz'].'</br>
  <b>Бюджет: <font color="green"></b>'.$birga_ro['cena'].' p.</font></br>'; 
  if($birga_ro['status'] == 1){echo '<font color="red"><b>Заказ не актуален</b></font><br>';
  }else{
  echo '<font color="green"><b>Заказ актуален</b></font>';} 
  
  if($birga_ro['status'] == 1){
  if(!$birga_ro['login2'] == 0){
  echo '<font color="green"><b>Исполнитель:</b></font>'.nick($birga_ro['login2']).'</br>';
  }
  }
  echo '</div>';
  if($birga_ro['status'] == 0){

  if(isset($_POST['submit'])){
  $status = strong($_POST['status']);
  mysql_query("UPDATE `birga` SET `status`='1',`login2`='".$user['id']."' WHERE `id`='".$id."' limit 1");
  header('Location: /birga/rob'.$id.''); exit;
  }
  
  if($birga_ro['author'] != $user['id']){
  echo '<form action="" method="post">
  <div class="podmenu"> <input type="submit" value="Принять предложение" name="submit"/></div>';
  }
  }
break;
case 'add':
$id = abs(intval($_GET['id']));
$pc_r = mysql_fetch_array(mysql_query('select * from `birga_r` where `id` = '.$id.' limit 1'));
if(empty($id) or !is_numeric($id) or $pc_r == 0){
header('Location: /birga'); exit;
}
if(isset($_REQUEST['submit'])) {

$opis = strong($_POST['opis']);
$tz = strong($_POST['tz']);
$cena = strong($_POST['cena']);
mysql_query("INSERT INTO `birga` SET `r` = '".$id."', `cena` = '".$cena."', `time` = '".time()."',  `author` = '".$user['id']."',  `opis` = '".$opis."', `tz` = '".$tz."', `status` = '0' ");
echo '<div class="podmenu"><b><center>Работа добавлена!</center></b></div>';
}


echo '<div class="podmenu">
  <form action="" method="post">
  Задание (кратко):<br><input name="opis"/><br>
  Задание (полное ТЗ):<br><textarea name="tz" style="width:98%;" rows="3"></textarea></br></br>
  Бюджет:<br/>
<input type="text" name="cena" size="10"/> р.<br/> 
  <input type="submit" value="Заказать" name="submit"/>
  </form></div>';
break;
case 'nr':
if(isset($_POST['submit'])){
$name = strong($_POST['name']);

mysql_query("INSERT INTO `birga_r` SET `name` = '".$name."'");
echo '<div class="podmenu"><b><center>Папка создан!</center></b></div>';
}
echo '
  <div class="podmenu">
  <form action="" method="post">
  Название:<br><input name="name"/><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>
  ';
break;
}
require_once ('../system/footer.php');
?>