View file wapbuilder/viewnews.php

File size: 2.7Kb
<?php
require('includes/header.php');
require('includes/utils.php');
require('includes/db.php');
require('includes/auth.php');

$max_pages = 5;
?>
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="links" title="&#x041C;&#x0435;&#x043D;&#x0435;&#x0434;&#x0436;&#x0435;&#x0440; &#x0444;&#x0430;&#x0439;&#x043B;&#x043E;&#x0432;">
<do type="options" name="main" label="&#x041C;&#x0435;&#x043D;&#x044E;"><go href="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>"/></do>
<p>
<?php
   $links_list = '';

   if(isset($_GET['from']))
      $from = $_GET['from'];
   else
      $from = 0;

   $links = mysql_query('SELECT count(*) FROM news WHERE user_id = "' . (int)($_GET['id']) . '" ORDER by date DESC ');
   list($total_links) = mysql_fetch_array($links);

   $total_pages = ceil($total_links / $max_pages);
   $links = mysql_query('SELECT id, text, date FROM news WHERE user_id = "' . (int)($_GET['id']) . '" ORDER by date DESC LIMIT ' . $from * $max_pages . ', ' . $max_pages);

   //$links = mysql_query('SELECT id, name, url FROM links WHERE user_id = "' . (int)($_GET['id']) . '"');
   $months = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня',                        'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
   if(($n = mysql_num_rows($links)) > 0)
   {
      while($link = mysql_fetch_array($links, MYSQL_ASSOC))
      {
         $raw_date = $link['date'];
         $month = (int)substr($raw_date, 5, 2);
         $month = $months[$month-1];
         $day = (int)substr($raw_date, 8, 2);
         $hour = (int)substr($raw_date, 11, 2);
         $minute = (int)substr($raw_date, 14, 2);

         $links_list .= "<a href=\"editnews.php?id=$id&amp;p=$login&amp;link_id=$link[id]\">$link[text]</a> [$day $month, $hour:$minute]\n<br/>\n";
      }
   }
?>
Всего новостей:<?php echo $total_links; ?>
 &#x0421;&#x0442;&#x0440;. <?php if($total_pages != 0) echo $from+1; else echo '0'; ?> &#x0438;&#x0437; <?php echo $total_pages; ?><br/>
<?php echo $links_list; ?>
<br/>
<?php
if(($from+1) != $total_pages && $total_pages != 0)
{
   echo "<a href=\"viewnews.php?id=$id&amp;p=$login&amp;from=" . ($from+1) . "\">Далее</a>";
   echo "<br/>";
}

if($from != 0)
{
   echo "<a href=\"viewnews.php?id=$id&amp;p=$login&amp;from=" . ($from-1) . "\">Назад</a>";
   echo "<br/>";
}

?>
<a href="addnews.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>">Добавить</a>
<br/>
</p>
<p align="center">
*********<br/>
<a href="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>">Меню</a><br/>
</p>
</card>
</wml>