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

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

  $title=$titlepage = $TEXT['nd-title5'];
  $helppage = $TEXT['nd-help5'];

  require_once "../config.php";
  require_once "../util/top_layer1.php";

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

  if(!isset($title)) $title = $TEXT['nd-title5'];
  if(!isset($button)) $button = $TEXT['btn_edit'];
  if(!isset($action)) $action = "editdoc2.php";

  if(strlen($_GET['razd_id'])>11) puterror2($TEXT['error-nd13']);
  if(strlen($_GET['doc_id'])>11) puterror2($TEXT['error-nd18']);
  $_GET['razd_id'] = rep($_GET['razd_id']);
  $_GET['doc_id'] = rep($_GET['doc_id']);

  $old_doc_id = $_GET['doc_id'];
  $old_razd_id = $_GET['razd_id'];

  $query = "SELECT tbl_documents.*, tbl_razdel.razd_id, tbl_razdel.razdel FROM tbl_documents JOIN tbl_razdel ON tbl_documents.razd_id=tbl_razdel.razd_id WHERE tbl_documents.doc_id='".$_GET['doc_id']."' ";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl14']);
   $result2 = mysql_fetch_array($result);
         $name = $result2['name'];
         $description = $result2['description'];
         $position = $result2['position'];
         $document = "<a href='../".$result2['path']."' target=_blank title='".$result2['description']."'' ><img alt='Document' align='left' src='../img/document.png' /></a>";
         $old_doc = $result2['path'];
         $res_razd = $result2['razdel'];
         $count_view = $result2['count_view'];
?>
<p><h3><?php echo $TEXT['nd-now2']; ?><b><?php echo $res_razd; ?></b></h3></p>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-doc']; ?></td><td class="useraddedit" align=center><?php echo $document; ?></a></td></tr>
<tr><td class="useraddedit"><nobr><?php echo $TEXT['nd-field8']; ?></nobr></td><td class="useraddedit"><input type=file name=document></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-doc-name']; ?></td><td class="useraddedit"><input size=50 maxlength=150 type=text name=name value='<?php echo $name; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-descr']; ?></td><td class="useraddedit"><textarea class=input name="description" cols="50" rows="5" ><?= $description; ?></textarea></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-position']; ?></td><td class="useraddedit"><input size=11 maxlength=11 type=text name=position value='<?php echo $position; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['count-view']; ?></td><td class="useraddedit"><input size=11 maxlength=11 type=text name=count value='<?php echo $count_view; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-razd']; ?></td>
    <td class="useraddedit"><select class="input" name="razd_id">
    <?php
        $query = "SELECT * FROM `tbl_razdel` WHERE `visible` != 'hide' ORDER BY position";
        $razdel_tmp = mysql_query($query);
          if(!$razdel_tmp) puterror2($TEXT['error-tbl14']);
              while($razdel = mysql_fetch_array($razdel_tmp))
                {
                 if($razdel['razd_id'] == $old_razd_id)
                   $chk = "<option selected value=".$razdel['razd_id'].">".$razdel['razdel']."";
                 else 
		   $chk = "<option value=".$razdel['razd_id'].">".$razdel['razdel']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=doc_id value='<?php echo $old_doc_id; ?>' />
<input type=hidden name=old_razd_id value='<?php echo $old_razd_id; ?>' />
<input type=hidden name=old_doc value='<?php echo $old_doc; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>