<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang.".php")) include "../lang/".$lang.".php";
     else include "../lang/ru.php";

  $title=$titlepage=$TEXT['support33'];

  require_once "../config.php";
  require_once "top.php";
  ?>
  <meta http-equiv='Refresh' content='300; URL=manager.php' />
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <?php

  if($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1) puterror2($TEXT['error-supp11']);

  if(empty($_GET['zay_id'])) $_GET['zay_id'] = "";
  if(strlen($_GET['zay_id'])>11) puterror2($TEXT['error-supp7']);
  $_GET['zay_id'] = rep($_GET['zay_id']);

  if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['k'] = rep($_GET['k']);
  if(empty($_GET['k'])) $_GET['k']=0;
  $stop_r = $_GET['k'];
  if($stop_r == 0) $lim_ogr = "20";
   else $lim_ogr = $stop_r.",20";

  $ktblvis = $stop_r+20;
  $str = $ktblvis/20;

  $query4_2 = "SELECT `position`, `sost_id` FROM `tbl_supp_sostoyanie` ORDER BY position DESC";
    $sost2_tmp = mysql_query($query4_2);
     if(!$sost2_tmp) puterror2($TEXT['error-tbl23']);
      $sost2 = mysql_fetch_array($sost2_tmp,MYSQL_ASSOC);
      $sost_id2 = $sost2['sost_id'];

?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr align="center"><td class="supp_iniz">&nbsp;<?php echo $TEXT['support44']; ?></td></tr>
<tr>
    <td>
      <table align="center" class="table" border="1" width="99%" cellpadding="1" cellspacing="1">
       <tr class='tableheadercat'>
        <td><?php echo $TEXT['support1']; ?></td>
        <td><?php echo $TEXT['support105']; ?></td>
        <td><?php echo $TEXT['sost1']; ?></td>
        <td><?php echo $TEXT['vazh1']; ?></td>
        <td><?php echo $TEXT['support30']; ?></td>
        <td><?php echo $TEXT['support13']; ?></td>
        <td><?php echo $TEXT['support53']; ?></td>
        <td><?php echo $TEXT['support42']; ?></td>
        <td><?php echo $TEXT['support43']; ?></td>
       </tr>
       <?php
       $query_2 = "SELECT `par_zay_id` FROM `tbl_ob_zay` WHERE `root_zay_id`='".$_GET['zay_id']."' ORDER BY par_zay_id";
       $result_zay_tmp = mysql_query($query_2);
        if(!$result_zay_tmp) puterror2($TEXT['error-tbl36']);
         if(mysql_num_rows($result_zay_tmp)>0)
          {
          while($query_zay = mysql_fetch_array($result_zay_tmp,MYSQL_ASSOC))
           {
       $query = "SELECT tbl_supp_zayavka.*, 
		tbl_users.familiya, 
		tbl_users.name, 
		tbl_users.otchestvo, 
		tbl_supp_srochnost.srochnost, 
		tbl_supp_srochnost.pic_sr, 
		tbl_supp_sostoyanie.sostoyanie, 
		tbl_supp_sostoyanie.pic_sost, 
		tbl_supp_tema.tema 
		FROM tbl_supp_zayavka 
		LEFT JOIN tbl_users ON tbl_supp_zayavka.usr_id=tbl_users.user_id
		JOIN tbl_supp_srochnost ON tbl_supp_zayavka.sroch_id=tbl_supp_srochnost.sroch_id 
		JOIN tbl_supp_sostoyanie ON tbl_supp_zayavka.sost_id=tbl_supp_sostoyanie.sost_id 
		JOIN tbl_supp_tema ON tbl_supp_zayavka.tema_id=tbl_supp_tema.tema_id 
		WHERE tbl_supp_zayavka.zay_id = '".$query_zay['par_zay_id']."'
		ORDER BY tbl_supp_zayavka.zay_id LIMIT ".$lim_ogr."";
       $users = mysql_query($query);
         if(!$users) puterror2($TEXT['error-tbl26']);
            while($user = mysql_fetch_array($users,MYSQL_ASSOC))
            {
               $data_post = $user['data_post'];
               $usrolder = $user['familiya']." ".$user['name']." ".$user['otchestvo'];
               if(trim($usrolder) == "") $usrolder = $TEXT['support120'];
                else $usrolder = $usrolder;

               if(!empty($user['pic_sr']) && $user['pic_sr']!="-") $sroch_image = "<img alt='picture' title='".$user['srochnost']."' src='".$user['pic_sr']."' />";
                else $sroch_image = $user['srochnost'];

               if(!empty($user['pic_sost']) && $user['pic_sost']!="-") $sost_image = "<img alt='picture' title='".$user['sostoyanie']."' src='".$user['pic_sost']."' />";
                else $sost_image = $user['sostoyanie'];

               if($sost_id2 !== $user['sost_id']) $zay_id = "<a href='zayavka.php?zay_id=".$user['zay_id']."' title='".$TEXT['support14']."'><font color=green>".$user['zay_id']."</font></a>";
                 else $zay_id = "<a href='zayavka_close.php?zay_id=".$user['zay_id']."' title='".$TEXT['support51']."'><font color=green>".$user['zay_id']."</font></a>";

               $ob_type = $user['ob_type'];
               if($ob_type == 0) $ob_type="<img alt='picture' src='../img/ob_free.png' height='16' width='16' align='top' />";
                elseif ($ob_type == 1) $ob_type="<img alt='picture' src='../img/ob_root.png' height='16' width='16' align='top' />";
                elseif ($ob_type == 2) $ob_type="<img alt='picture' src='../img/ob_par.png' height='16' width='16' align='top' />";
                elseif ($ob_type == 3) $ob_type="<img alt='picture' src='../img/ob_parall.png' height='16' width='16' align='top' />";
                elseif ($ob_type == 4) $ob_type="<img alt='picture' src='../img/ob_man.png' height='16' width='16' align='top' />";

               $tema2 = $user['tema'];

               if(!empty($user['man_id']))
                {
               $query6 = "SELECT `fullname` FROM `tbl_logins` WHERE `login_id` = '".$user['man_id']."'";
                $man_tmp = mysql_query($query6);
                  if(!$man_tmp) puterror2($TEXT['error-tbl20']);
                   $manager = mysql_fetch_array($man_tmp,MYSQL_ASSOC);
                    $manager2 = $manager['fullname'];
                 } else $manager2 = $TEXT['support28'];

               if(!empty($user['mast_id']))
                {
               $query7 = "SELECT `fullname` FROM `tbl_logins` WHERE `login_id` = '".$user['mast_id']."'";
                $mast_tmp = mysql_query($query7);
                  if(!$mast_tmp) puterror2($TEXT['error-tbl20']);
                   $master = mysql_fetch_array($mast_tmp,MYSQL_ASSOC);
                    $master2 = $master['fullname'];
                 } else $master2 = $TEXT['support28'];
            ?>
            <tr class='tabledata'>
              <td><?php echo $zay_id; ?></td>
              <td><?php echo $ob_type; ?></td>
              <td><?php echo $sost_image; ?></td>
              <td><?php echo $sroch_image; ?></td>
              <td><?php echo $usrolder; ?></td>
              <td><?php echo $tema2; ?></td>
              <td><?php echo $data_post; ?></td>
              <td><?php echo $manager2; ?></td>
              <td><?php echo $master2; ?></td>
            </tr>
            <?php
            }
            }
            $query_count = mysql_query("SELECT COUNT(zay_id) FROM tbl_supp_zayavka WHERE tbl_supp_zayavka.zay_id = '".$query_zay['par_zay_id']."' ");
	        $coun_rows = mysql_result($query_count, 0);
            ?>
           <tr class='tableheadercat'>
            <td colspan="9" align="right"><?php echo $TEXT['support66']; ?> - <?php echo $coun_rows; ?></td>
           </tr>
           <?php
            } else puterror2($TEXT['support113']);
           ?>
         </table>
      </td>
   </tr>
</table>
<?php
            $pag = $coun_rows/20;
               if($pag<=1) $pag = ceil($pag);
                else
                {
                 ?>
                  <table align="center" border="0" cellpadding="0" cellspacing="0" width="98%" >
                   <tr align="center">
                    <td>
                <?php
                $pag=ceil($pag);
                $strn = $str-5;
                if($strn<1) $strn=1;
                $strk = $str+5;
                for($i=$strn; $i<=$pag; $i++)
                 {
                  if($i<=$strk)
                  {
                    if($i==$str)
                    {
                      $k = $i*20-20;
                      $kvis=$k+20;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='manager2.php?k=".$k."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*20-20;
                    $kvis=$k+20;
                    $nvis=$k;
                    echo $pg = " <a href='manager2.php?k=".$k."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>[".$i."]</a>";
                    }
                  }
                 }
                 ?>
                    <select name='k' onchange=window.location.href=this.options[this.selectedIndex].value;>
                    <?php
                    for($j=1; $j<=$pag; $j++)
                    {
                     $k = $j*20-20;
                     if($k == $_GET['k']) echo "<option selected value=manager2.php?k=".$k.">".$j."</option>";
                       else echo "<option value=manager2.php?k=".$k.">".$j."</option>";
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
?>
</body>
</html>