<?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['new-title4'];
  $helppage = $TEXT['new-help4'];

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

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

  if(empty($_POST['data'])) $_POST['data'] = "";
  if(empty($_POST['org_id'])) $_POST['org_id'] = "";
  if(empty($_GET['onorg'])) $_GET['onorg'] = "";
  if(empty($_POST['onorg'])) $_POST['onorg'] = "";
  if(strlen($_POST['data'])>20) puterror2($TEXT['error-log6']);
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org1']);
  if(strlen($_GET['org_id'])>11) puterror2($TEXT['error-org1']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $_POST['data'] = rep($_POST['data']);
  $_POST['org_id'] = rep($_POST['org_id']);
  $onchb = "";

  $data=$_POST['data'];

  if(!isset($button)) $button = $TEXT['btn_filter'];
  if(!isset($action)) $action = "index.php";

  if($_GET['onorg'] == "on")
    {
   $_POST['org_id'] = $_GET['org_id'];
   $onchb = "checked";
    }
  else
  {
  if($_POST['onorg'] !== "on") $_POST['org_id'] = "";
    else
    {
    $_POST['org_id'] = $_POST['org_id'];
    $onchb = "checked";
    }
  }
?>
<img alt="<?php echo $TEXT['new-add-new']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="addform.php" title="<?php echo $TEXT['new-add-new-tit']; ?>"><?php echo $TEXT['new-add-new']; ?></a>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="50%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['log-tit7']; ?>"><?php echo $TEXT['btn_filter']; ?></legend>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="zag2"><td><?php echo $TEXT['tbl-org']; ?></td><td><?php echo $TEXT['tbl-date']; ?></td></tr>
<tr><td><select class="input" name="org_id">
    <?php
        $query4 = "SELECT * FROM `tbl_organizaciya` ORDER BY position";
        $organizaciya_tmp = mysql_query($query4);
          if(!$organizaciya_tmp) puterror2($TEXT['error-tbl7']);
              while($organizaciya = mysql_fetch_array($organizaciya_tmp,MYSQL_ASSOC))
                {
                 if($organizaciya['org_id'] == $_POST['org_id'])
                   {
                   $chk = "<option selected value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                   }
                 else $chk = "<option value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                 echo $chk;
                }
    ?>
    </select><input type=checkbox name=onorg <?php echo $onchb; ?></td>
<td><input size=10 maxlength=19 type=text name=data title='<?php echo $TEXT['log-tit8']; ?>' value='<?php echo $data; ?>'></td>
<td><input class="button" type=submit value='<?php echo $button; ?>' /></td>
</tr>
</table>
</fieldset>
</td></tr>
</table>
</form>
 <br />
 <span class="tabledata"><?php echo $TEXT['new-text1']; ?></span>
<table class="table" border="1" cellpadding="3" cellspacing="0" width="95%">
<?php
   if(!empty($_POST['org_id'])) $organizaciya = "AND tbl_news.org_id='".$_POST['org_id']."' ";
    else $organizaciya = "";

   if(!empty($_POST['data'])) $data = "AND tbl_news.data REGEXP '".$_POST['data']."' ";
    else $data = "";

     $query = "SELECT 
         tbl_news.new_id,
         tbl_news.org_id,
         tbl_news.header,
         SUBSTRING_INDEX(tbl_news.news, ' ', 15) AS news,
         tbl_news.position,
         tbl_news.description,
         tbl_news.url,
         tbl_news.url_text,
         tbl_news.picture,
         tbl_news.picture_big,
         tbl_news.data,
         tbl_news.visible,
         tbl_organizaciya.org_id,
         tbl_organizaciya.organizaciya
         FROM tbl_news
         JOIN tbl_organizaciya ON tbl_news.org_id=tbl_organizaciya.org_id
         WHERE tbl_news.new_id!='' ".$organizaciya." ".$data."
         ORDER BY tbl_organizaciya.organizaciya, tbl_news.position, tbl_news.data DESC";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl17']);
       if(mysql_num_rows($result)>0);
         {
           ?>
           <tr class="tableheadercat">
             <td><?php echo $TEXT['tbl-header']; ?></td>
             <td width="10"><?php echo $TEXT['tbl-news']; ?></td>
             <td><?php echo $TEXT['tbl-position']; ?></td>
             <td><?php echo $TEXT['tbl-descr']; ?></td>
             <td><?php echo $TEXT['tbl-org']; ?></td>
             <td><?php echo $TEXT['tbl-date']; ?></td>
             <td><?php echo $TEXT['tbl-visible']; ?></td>
             <td colspan=3><?php echo $TEXT['tbl-action']; ?></td>
           </tr>
           <?php
             while($result_news = mysql_fetch_array($result,MYSQL_ASSOC))
              {
              $result_news['news'] = str_replace(":smile:","<img alt='picture' src='../img/smile.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":tongue:","<img alt='picture' src='../img/tongue.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":wink:","<img alt='picture' src='../img/wink.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":wassat:","<img alt='picture' src='../img/wassat.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":sad:","<img alt='picture' src='../img/sad.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":crying:","<img alt='picture' src='../img/crying.png' align=middle border=0 />",$result_news['news']);
              $result_news['news'] = str_replace(":angry:","<img alt='picture' src='../img/angry.png' align=middle border=0 />",$result_news['news']);

              if($result_news['visible']=='show') $res_news="<a href=hide.php?news_id=".$result_news['new_id']." title='".$TEXT['tbl-hide-tit']."'><img alt='".$TEXT['tbl-show']."' src='../img/show.png' height='16' width='16' align='top' /></a>";
                else $res_news="<a href=show.php?news_id=".$result_news['new_id']." title='".$TEXT['tbl-show-tit']."'><img alt='".$TEXT['tbl-hide']."' src='../img/hide.png' height='16' width='16' align='top' /></a>";
//
//              if($result_news['picture_big'] == "") $picture = $TEXT['error-new19'] ;
//                  else $picture = "<a href='../".$result_news['picture_big']."' target=_blank title='".$TEXT['tbl-pic-tit']."' >".$TEXT['tbl-pic']."</a>";
//
              $url = "<a href=../../news.php?news_id=".$result_news['new_id']." target='_blank' title='".$TEXT['ssilka-otobr7']."'><img alt='view' src='../../img/fon-est.png' height='16' width='16' align='top' /></a>";

              $edit = "<a href=editform.php?news_id=".$result_news['new_id']." title='".$TEXT['tbl-edit-tit-news']."'>".$TEXT['tbl-edit']."</a>";
              $delete = "<a href=deleteform.php?news_id=".$result_news['new_id']." title='".$TEXT['tbl-delete-tit-news']."'>".$TEXT['tbl-delete']."</a>";
              $move_up = "<a href=up-down.php?new_id=".$result_news['new_id']."&amp;org_id=".$result_news['org_id']."&amp;position=".$result_news['position']."&amp;moving=up title='".$TEXT['global-up-down-tit']."'><img alt='up' src='../img/up.png' height='16' width='16' align='top' /></a>";
              $move_down = "<a href=up-down.php?new_id=".$result_news['new_id']."&amp;org_id=".$result_news['org_id']."&amp;position=".$result_news['position']."&amp;moving=down title='".$TEXT['global-up-down-tit']."'><img alt='down' src='../img/down.png' height='16' width='16' align='top' /></a>";
           ?>
           <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $result_news['header']; ?></td>
              <td><?php echo nl2br($result_news['news']); ?>...</td>
              <td><?php echo $result_news['position']; ?></td>
              <td><?php echo $result_news['description']; ?></td>
              <td><?php echo $result_news['organizaciya']; ?></td>
              <td><?php echo $result_news['data']; ?></td>
              <td><?php echo $res_news; ?><br /><?php echo $url; ?></td>
              <td><?php echo $move_up; ?> <?php echo $move_down; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
                 </tr>
           <?php
              }
         }
?>
</table>
<?php
  require_once "../util/bottom.php";
?>