<?php

/************************************************************************/
/* هذا البرنامج من تصميم قهوة نت                                        */
/* ===========================                                          */
/*                                                                      */
/* http://www.coffee4arab.com                                           */
/* coffee4arab@yahoo.com                                                */
/* ver: 1.6                                                             */
/************************************************************************/


if ( !defined('MODULE_FILE') )
{
	die("You can't access this file directly...");
}



require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));


$artperpage = "30";

if (!isset($curpage) or $curpage=="") $curpage=1;

if (!isset($topicid)) {
    Header("Location: modules.php?name=Mygroups");
}

// just in case somebody is injecting sql code here
$topicid = intval(trim($topicid));

global $bgcolor1, $bgcolor2, $prefix;
$theorder = " order by sid desc";

include ("header.php");
echo "<br>";

$nexlimit = $curpage * $artperpage - $artperpage;

$result = mysql_query ("select sid,aid,title,time,counter,informant from " . $prefix . "_stories where topic=$topicid " . $theorder . " limit $nexlimit,$artperpage");

$totrows = mysql_num_rows ($result);

if ($totrows==0) {
	echo "<br>";
	OpenTable ();
	echo "لا يوجد مقالات في هذا الموضوع<br>";
	CloseTable ();
	include ("footer.php");
	exit;
}

$result1 = mysql_query ("select topictext from " . $prefix . "_topics where topicid=$topicid");
list ($topictext) = mysql_fetch_row ($result1);

OpenTable ();

echo "<center><br><b>$topictext</b></center><br>";
echo "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"1\" bgcolor=\"$bgcolor2\">"
	."<tr><td align=\"center\" bgcolor=\"$bgcolor2\">العنوان</td><td align=\"center\" bgcolor=\"$bgcolor2\">الكاتب</td>"
	."<td align=\"center\" bgcolor=\"$bgcolor2\">التاريخ</td><td align=\"center\" bgcolor=\"$bgcolor2\">القراءات</td></tr>";

while (list ($sid,$aid,$title,$time,$counter,$informant) = mysql_fetch_row ($result)) {

	if ($informant=="") {
		$thewriter=$aid;
	} else {
		$thewriter=$informant;
	}
	echo "<tr><td align=\"center\" bgcolor=\"$bgcolor1\"><a href=\"modules.php?name=News&amp;file=article&amp;sid=$sid\">$title</a></td>"
		."<td align=\"center\" bgcolor=\"$bgcolor1\">$thewriter</td><td align=\"center\" bgcolor=\"$bgcolor1\">$time</td>"
		."<td align=\"center\" bgcolor=\"$bgcolor1\">$counter</td></tr>";
}
echo "</table>";


// get pages:
$result = mysql_query ("select sid,aid,title,time,counter from " . $prefix . "_stories where topic=$topicid");
$allrows = mysql_num_rows ($result);
$totpages = ceil($allrows/$artperpage);
for ($i=1;$i<=$totpages;$i++) {
	if ($i==$curpage) {
		$pages .= "$i ";
	} else {
		$pages .= "<a href=\"modules.php?name=Mygroups&amp;file=articles&amp;topicid=$topicid&amp;gid=$gid&amp;curpage=$i\">$i</a> ";
	}
}

echo "<br><br><center>الصفحات: $pages<br><br>";


$result = mysql_query ("select groupname from " . $prefix . "_mygroups where id=$gid");
list ($gname) = mysql_fetch_row ($result);
echo "عودة الى <a href=\"modules.php?name=Mygroups&amp;gid=$gid\"> $gname </a></center><br>";

CloseTable ();

echo "حقوق البرنامج : <a href=\"http://www.coffee4arab.com\">قهوة نت</a>";

include ("footer.php");

?>