<?php
if(!function_exists('b_waiting_links'))
{

	function b_waiting_links($mydirname)
	{
		$db = icms_db_Factory::instance();

		$block = array();
		$adminlink = XOOPS_URL."/modules/$mydirname/admin/index.php";
		$approval_link = "?c=approval&amp;s=";

		// APPROVAL NEW
		$sql = "SELECT COUNT(*) FROM ". $db->prefix($mydirname."_links") ." WHERE status=0" ;
		if ( $result = $db->query($sql) ) {
			list($pendingnum) = $db->fetchRow($result);
			$block[] = array(
				'adminlink'     => $adminlink . $approval_link . 0,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_NEW ,
			);
		}
		// APPROVAL EDIT
		$sql = "SELECT COUNT(*) FROM ". $db->prefix($mydirname."_links") ." WHERE status=-1" ;
		if ($result = $db->query($sql)) {
			list($pendingnum) = $db->fetchRow($result);
			$block[] = array(
				'adminlink'     => $adminlink . $approval_link . 1,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_MOD ,
			);
		}
		// APPROVAL DELETE
		$sql = "SELECT COUNT(*) FROM ". $db->prefix($mydirname."_links") ." WHERE status=-2" ;
		if ($result = $db->query($sql)) {
			list($pendingnum) = $db->fetchRow($result);
			$block[] = array(
				'adminlink'     => $adminlink . $approval_link . 2,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_DEL ,
			);
		}
		// APPROVAL EASYPOST
		$sql = "SELECT COUNT(*) FROM ". $db->prefix($mydirname."_links") ." WHERE status=-3";
		if ($result = $db->query($sql)) {
			list($pendingnum) = $db->fetchRow($result);
			$block[] = array(
				'adminlink'     => $adminlink . $approval_link . 3,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_EP ,
			);
		}

		// BROKEN
		$sql = "SELECT DISTINCT lid FROM ". $db->prefix($mydirname."_broken") ." WHERE status=0";
		if ($result = $db->query($sql)) {
			$pendingnum = $db->getRowsNum($result);
			$block[] = array(
				'adminlink'     => $adminlink . "?c=broken" ,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_BROKEN ,
			);
		}

		// REQUEST
		$sql = "SELECT COUNT(*) FROM ". $db->prefix($mydirname."_request") ." WHERE status=0";
		if ($result = $db->query($sql) ){
			list($pendingnum) = $db->fetchRow($result);
			$block[] = array(
				'adminlink'     => $adminlink . "?c=request" ,
				'pendingnum'    => $pendingnum ,
				'lang_linkname' => _WT_LINKS_WAITING_REQUEST ,
			);
		}

		return $block;
	}

}
