<?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__));


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

if (!isset($gid)) {
	$result = mysql_query ("select * from " . $prefix . "_mygroups");
	$totrows=mysql_num_rows($result);
	if ($totrows==0) {
		echo "لا يوجد مجموعات";
		include ("footer.php");
		exit;
	}

	OpenTable ();
	echo "<br>";
	echo "<center><b>قائمة المجموعات</b></center><br><br>";
	while (list ($gid,$gname) = mysql_fetch_row ($result)) {
		echo "<li><a href=\"modules.php?name=Mygroups&amp;gid=$gid\">$gname</a><br>\n";
	}
	CloseTable ();
	mysql_free_result ($result);
	exit;
}
$gid = intval(trim($gid));
$result = mysql_query ("select * from " . $prefix . "_mygroups where id=$gid");
if (mysql_num_rows($result)==0) {
	echo "هذه المجموعة غير موجودة";
	include ("footer.php");
	exit;
}

list ($gid,$gname,$topics) = mysql_fetch_row ($result);

$topicids = explode ("|",$topics);

$counter=0;
$sqltxt = "";
foreach ($topicids as $onetopic) {
    if ($counter==0) {
		$sqltxt = "where topicid=$onetopic ";
	} else {
		$sqltxt .= "or topicid=$onetopic ";	
	}
	$counter++;
}

// ++++++++++++++++++++++++++++++++
$result = mysql_query("select topicid, topicname, topicimage, topictext from ".$prefix."_topics ".$sqltxt);
if (mysql_num_rows($result)==0) {
	echo "المواضيع غير موجودة";
    include("footer.php");
	exit;
}

OpenTable();
    echo "<center><font class=\"title\"><b>$gname</b></font><br>\n"
	."<font class=\"content\">اضغط على الموضوع لاستعراض مقالاته</font><br><br>\n"
	."</center><br><br>"
	."<table border=\"0\" width=\"100%\" align=\"center\" cellpadding=\"2\"><tr>\n";
    while(list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_row($result)) {
    	if ($count == 2) {
	    echo "<tr>\n";
	    $count = 0;
	}
	echo "<td align=\"center\">\n"
	    ."<a href=\"modules.php?name=Mygroups&amp;file=articles&amp;topicid=$topicid&amp;gid=$gid\"><img src=\"images/topics/$topicimage\" border=\"0\" alt=\"$topictext\"></a><br>\n"
	    ."<font class=\"content\"><b>$topictext</b></font>\n"
	    ."</td>\n";
	$count++;
	if ($count == 2) {
	    echo "</tr>\n";
	}
    }
    if ($count == 2) {
	echo "</table>\n";
    } else {
	echo "</tr></table>\n";
    } 
CloseTable();

include("footer.php");

?>