Location: PHPKode > scripts > Benson Bank CMS > home.php
<?php
	@include_once "inc.page.php";
	@uppe();
	@main($pin);
	@down();

	function main($pin)
	{
		echo "<p class='dot'>"hide@address.com(518)." <b class='green'>[{$pin[bsb][pid]}]</b></p>";
		if (!$pin['bsb']['cat_income']) echo "<p class='red'>"hide@address.com(1001).": <a href='cat.php'>"hide@address.com(1002)."</a></p>";
		if (!$pin['bsb']['cat_invest']) echo "<p class='red'>"hide@address.com(1003).": <a href='cat.php'>"hide@address.com(1002)."</a></p>";
		else @main_invest($pin);
		@main_future($pin);
		echo "<p class='dot'>"hide@address.com(519)."</p>";
		@cout_diary_list("date");
	}
	function main_future($pin)
	{
		$sort = ($_GET['sort'] ? $_GET['sort'] : "dateto,ccy");
		echo "<p class='dot'>"hide@address.com(1007)."</p><table class='grid bb bt bl br'><tr class='bg1' title='"hide@address.com(1008)."'>
		<td><a href='home.php?sort=cat_id,dateto' class='none'>"hide@address.com(509)."</a></td>
		<td><a href='home.php?sort=category,dateto' class='none'>"hide@address.com(510)."</a></td>
		<td><a href='home.php?sort=remark,dateto' class='none'>"hide@address.com(511)."</a></td>
		<td><a href='home.php?sort=created,dateto' class='none'>"hide@address.com(1009)."</a></td>
		<td><a href='home.php' class='none'>"hide@address.com(1010)."</a></td>
		<td><a href='home.php?sort=rem,dateto' class='none'>"hide@address.com(1011)."</a></td>
		<td><a href='home.php?sort=rate_y,ccy' class='none'>"hide@address.com(1012)."</a></td>
		<td><a href='home.php?sort=ccy,dateto' class='none'>"hide@address.com(512)."</a></td>
		<td align='right'><a href='home.php?sort=ccy,amt' class='none'>"hide@address.com(515)."</a></td><td></td></tr>";
		$sql = "select a.*,b.category,c.remark rem,c.dateto,c.rate_y from bsb_book a,bsb_category b,bsb_term c
			where a.his_id=c.his_id and a.debit=b.cat_id and a.pid=b.pid
			and a.pid={$pin[bsb][pid]} and substring(c.remark,1,4)<>'HIDE' order by $sort";
		$res = @mysql_query($sql);
		while ($row = @mysql_fetch_array($res)){
			if (!$row['remark']) $amt[0] = $row['amt'];
			else $amt = @get_row("","select sum(if(credit=$row[debit],amt,0-amt)) from bsb_book
				where remark='$row[remark]' and pid=$row[pid] and (debit=$row[debit] or credit=$row[debit])");
			if (@round($amt[0],2)<>0.00){
				echo "<tr><td><a href='search.php?cat[0]=$row[debit]&#38;ccy=$row[ccy]' class='none'>$row[debit]</a></td><td>$row[category]</td>
				<td><a href='search.php?cat[0]=$row[debit]&#38;ccy=$row[ccy]&#38;rem=$row[remark]' class='none'>$row[remark]</a></td>
				<td>"hide@address.com($row['created'],0,10)."</td><td>$row[dateto]</td><td>$row[rem]</td>
				<td>$row[rate_y]</td><td>$row[ccy]</td>"hide@address.com(0-$amt[0])."
				<td><a href='add.php?his=$row[his_id]' class='green none'>"hide@address.com(516)."</a></td></tr>";
			}
		}
		echo "</table>";
	}
	function main_invest($pin)
	{
		$CAT = @sql2arr("select cat_id,category from bsb_category where pid=".$pin['bsb']['pid'],2);
		echo "<p class='dot'>"hide@address.com(1013).": "hide@address.com("Y-m-d")."</p><table class='grid bb bt bl br'>
		<tr class='bg1'><td>"hide@address.com(509)."</td><td>"hide@address.com(510)."</td><td>"hide@address.com(512)."</td><td align='right'>"hide@address.com(515)."</td><td align='right'>"hide@address.com(1014)."</td><td align='right'>"hide@address.com(1015)."</td></tr>";
		$inv = @explode(",",$pin['bsb']['cat_invest']);
		foreach ($inv as $v){
			$where_c .= " or credit like '$v%'";
			$where_d .= " or debit like '$v%'";
		}
		$sql = "select ccy,debit,sum(amt) amt from bsb_book where pid=".$pin['bsb']['pid']."
			and ("hide@address.com($where_d,4).") group by 1,2 having amt<>0 order by 1,concat('a',debit)";
		$res = @mysql_query($sql);
		while ($row = @mysql_fetch_row($res)) $data[$row[0]][$row[1]] = $row[2];
		$sql = "select ccy,credit,sum(0-amt) amt from bsb_book where pid=".$pin['bsb']['pid']."
			and ("hide@address.com($where_c,4).") group by 1,2 having amt<>0 order by 1,concat('a',credit)";
		$res = @mysql_query($sql);
		while ($row = @mysql_fetch_row($res)){
			$data[$row[0]][$row[1]] += $row[2];
			if (!$data[$row[0]][$row[1]]) unset($data[$row[0]][$row[1]]);
		}
		$cat = ""; $ccy = "";
		foreach ($data as $k=>$v){
			foreach ($v as $k2=>$v2){
				$cur_cat = @substr($k2,0,3);
				if ($cat<>$cur_cat){
					if ($cat) echo @main_amt($sub);
					$cat = $cur_cat; $sub = $v2;
				}else{
					echo "<td></td>"; $sub += $v2;
				}
				if ($ccy<>$k){
					if ($ccy) echo @main_amt($ttl)."</tr>";
					$ccy = $k; $ttl = $v2;
				}else{
					echo "<td></td></tr>"; $ttl += $v2;
				}
				echo "<tr><td><a href='search.php?cat[0]=$k2&#38;ccy=$k' class='none'>$k2</a></td>
				<td>".$CAT[$k2]."</td><td>$k</td>"hide@address.com($v2);
			}
		}
		echo @main_amt($sub)hide@address.com($ttl)."</tr></table>";
	}
?>
Return current item: Benson Bank CMS