<?php

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

function block_view_other_links($params) {
  global $dbConn, $theme_name, $theme_path, $msg;

  if (!$params['template']) {
    $params['template'] = 'block.view_other_links.html';
  }

  if (!$params['template_rows']) {
    $params['template_rows'] = 'block.view_other_links_rows.html';
  }

  if (!$params['max_item']) {
    $params['max_item'] = '20';
  }
	
	if (!$params['order_by']) {
    $params['order_by'] = 'rand()';
  }

  $tpl = new Template;
  
  // you can pass one of 3 params: link_id, username, category_id
	$id       = $params['link_id'];
	$username = $params['username'];
	$cat_id   = $params['category_id'];

	if(!empty($params['link_id'])) {
  	// get username
  	$id    = $params['link_id'];
  	$query = "select username from idx_link_user
              where link_id = '$id'";
  	$result = $dbConn->Execute($query); 
  	$username = $result->Fields("username");

	  // get all links by this username
  	$query = "select link_id from idx_link_user
    	        where username = '$username'  order by " . $params['order_by'] . " limit 0," . $params['max_item'];
  	$result = $dbConn->Execute($query);
	}
	elseif (!empty($params['username'])) {
	  // get all links by this username
  	$query = "select link_id from idx_link_user
    	        where username = '$username'  order by " . $params['order_by'] . " limit 0," . $params['max_item'];
  	$result = $dbConn->Execute($query);	
	}
	elseif (!empty($params['category_id'])) {
	  // get all links by category_id
  	$query = "select link_id from idx_link
    	        where category_id = '$cat_id' order by " . $params['order_by'] . "
						  limit 0," . $params['max_item'];
  	$result = $dbConn->Execute($query);	
	}
	else {
		print "Please pass one of the following parameter: link_id, username, category_id";
		RunPostFilter();
	}	
	
  // get them all
  $query = "select * from idx_link where 0!=0 ";
  while (!$result->EOF) {
    $lid = $result->Fields('link_id');
    $query .= "	or link_id = '$lid' ";
    $result->MoveNext();
  }
  $query .= "	and suspended = 0
	          order by ". $params['order_by'];

  $result = $dbConn->Execute($query);

  $links_obj = new clsLink;
  $links_obj->query                 = $query;
  $links_obj->table_name            = "idx_link";
  $links_obj->category_table_name   = "idx_category";
  $links_obj->max_rows              = $params['max_item'];
  $links_obj->rating_image_path     = "themes/" . $theme_name . "/images/rating/";
  $links_obj->rev_rating_image_path = "themes/" . $theme_name . "/images/review/";
  $links_obj->date_format           = $msg["10161"];
  $links_obj->template_file         = $theme_path . "/blocks/{$params['template_rows']}";
  $link                             = $links_obj->Display();

  $tpl->assign("link",$link);
  $tpl->assign("title", $params['title']);
  $tpl->display("blocks/" . $params['template']);
}


?>