<?php
// $Id: wfdownloads310_data.inc.php,v 1.2 2006/09/19 03:53:35 ohwada Exp $

// 2006-09-18 K.OHWADA
// BUG 4260: forget to remove debug print

//================================================================
// What's New Module
// get aritciles from module
// for WFdownloads 3.10 <http://www.smartfactory.ca/>
// 2006-08-07 K.OHWADA
//================================================================

function wfdownloads_new($limit=0, $offset=0)
{
	global $xoopsDB, $xoopsModule, $xoopsUser;

	$URL_MOD = XOOPS_URL."/modules/wfdownloads";

	$myts =& MyTextSanitizer::getInstance();

	$modhandler = &xoops_gethandler('module');
	$xoopsModule = &$modhandler->getByDirname("wfdownloads");
	$mid = $xoopsModule->getVar('mid');

	$config_handler = &xoops_gethandler('config');
	$xoopsModuleConfig = &$config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));

	$groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
	$gperm_handler = &xoops_gethandler('groupperm'); 

// WFD 3.1
	$allowed_cats = $gperm_handler->getItemIds("WFDownCatPerm", $groups, $mid);
	$perm = "d.cid IN (". implode(',', $allowed_cats) .")";

	$sql  = "SELECT d.lid, d.title as dtitle, d.date, d.updated, d.published, d.description, d.hits, d.submitter, d.cid, c.title as ctitle ";
	$sql .= "FROM " . $xoopsDB->prefix('wfdownloads_downloads')." d, ".$xoopsDB->prefix("wfdownloads_cat")." c ";
	$sql .= "WHERE d.cid=c.cid AND d.status > 0 AND d.offline = 0 AND ".$perm." ";
	$sql .= "ORDER BY d.date DESC";

	$result = $xoopsDB->query($sql, $limit,$offset);

	$i = 0;
	$ret = array();

 	while( $row = $xoopsDB->fetchArray($result) )
 	{
 		$lid = $row['lid'];
		$ret[$i]['link']     = $URL_MOD."/singlefile.php?lid=".$lid;
		$ret[$i]['cat_link'] = $URL_MOD."/viewcat.php?cid=".$row['cid'];

		$ret[$i]['title']    = $row['dtitle'];
		$ret[$i]['cat_name'] = $row['ctitle'];

		$ret[$i]['hits'] = $row['hits'];

// atom feed
		$ret[$i]['id'] = $lid;
		$ret[$i]['description'] = $myts->makeTareaData4Show( $row['description'], 0 );	//no html

// time
		if ($row['updated'] > $row['date'])
		{
			$time = $row['updated'];
		}
		else
		{
			$time = $row['date'];
	   	}

	   	$ret[$i]['time']     = $time;
		$ret[$i]['modified'] = $time;
		$ret[$i]['issued']   = $row['published'];

		$ret[$i]['uid'] = $row['submitter'];

		$i++;

// check limit
		if ( ($limit > 0) && ($i >= $limit) )  break;
	}

	return $ret;
}

?>
