<?php
defined('_IN_JOHNCMS') or die('Error: restricted access');
if($ban[1])
{
  echo functions::display_error('Siz ban olgansiz!');
  require_once ('../incfiles/end.php');
  exit;  
}
$req = mysql_query("SELECT * FROM `dnevniki` WHERE `id` = '".$id."' AND `dnid` = 'com' LIMIT 1");
if(mysql_num_rows($req))
{
  $res = mysql_fetch_assoc($req);  
  $req_user = mysql_query("SELECT * FROM `users` WHERE `id` = '".$res['userid']."' LIMIT 1");
  $uz = mysql_fetch_assoc($req_user);
  if (($user_id==$res['userid'] or (($rights >= 6) and $rights >= $uz['rights'])))  
  {
    $save = $_GET['save'];
    if($save)
    {
      $text = trim($_POST['text']);
      if(!$text)
        $err .= 'Siz xabarni kiritmadingiz!<br/>';
      else
      {
        if(mb_strlen($text) > 2000)
          $err .= 'Xabar matni 2000 belgidan oshib ketdi!<br/>';  
      }
    }
    if($save and !$err)
    {
       mysql_query("UPDATE `dnevniki` SET
       `text` = '" . mysql_real_escape_string($text) . "',
       `mod_who` = '".$login."',
       `last_mod` = '".time()."'
       WHERE `id` = '".$id."'");
        echo '<div class="phdr"><a href="./">Kundaliklar</a> | Fikrni tahrirlash</div>';   
        echo '<div class="menu">Fikr o`zgartirildi!<br />';
        echo '<a href="?act=com&amp;id='.$res['com_id'].'">Davom etish</a></div>';
        echo '<div class="phdr">&nbsp;</div>';
        echo '<a href="?act=com&amp;id='.$res['com_id'].'"><img src="./img/folder_user.png" /> Fikrlar</a><br />';
        echo '<a href="./"><img src="./img/folder.png" /> Kundaliklar</a><br />';
        require_once ('../incfiles/end.php');
        exit;
    }  
    echo '<div class="phdr"><a href="./">Kundaliklar</a> | Fikrni tahrirlash</div>';
    if($err)
      echo '<div class="rmenu">'.$err.'</div>';
    echo '<form name="mess" action="?act=editcom&amp;save=save&amp;id='.$id.'" method="post">';
    echo '<div class="menu">Matn (smayllar va bb-kodlar ruxsat etilgan):<br />'.bbcode::auto_bb('mess', 'text').'<textarea rows="' . $set_user['field_h'] . '" cols="30" name="text">'.($text ? htmlentities($text, ENT_QUOTES, 'UTF-8') : htmlentities($res['text'], ENT_QUOTES, 'UTF-8')).'</textarea><br />';
    echo '<input type="submit" name="submit" value="Tahrirlash"/></div>';
    echo '<div class="phdr">&nbsp;</div>';
    echo '</form>';
    echo '<a href="?act=com&amp;id='.$res['com_id'].'"><img src="./img/folder_user.png" /> Fikrlar</a><br />';
    echo '<a href="./"><img src="./img/folder.png" /> Kundaliklar</a><br />';
  }  
  else
  {
    echo '<div class="phdr"><a href="./">Kundaliklar</a> | Fikrni tahrirlash</div>';
    echo '<div class="menu">';
    echo 'Fikrni tahrirlab bo`lmaydi!<br/>';
    echo '<a href="./">Orqaga</a>';
    echo '</div>';
    echo '<div class="phdr">&nbsp;</div>';  
  }
}
else
{
  echo '<div class="phdr"><a href="./">Kundaliklar</a> | Fikrni tahrirlash</div>';
  echo '<div class="menu">';
  echo 'Fikrni tahrirlab bo`lmaydi!<br/>';
  echo '<a href="./">Orqaga</a>';
  echo '</div>';
  echo '<div class="phdr">&nbsp;</div>';  
}
?>