<?php
/**
 * searchsort_model.php - search sort model
 *
 * TODO: Completely take this out.
 *
 * @author $Author: dtong $
 * @version $Id: searchsort_model.php,v 1.21 2011/05/09 04:48:53 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

class Searchsort_model extends CI_Model {

	function __construct() {
		parent::__construct();

   }

	private function load_session_start() {
		osa_php_session_start();
	}

	function roundUp( $value, $precision=0 ) {
	    if ( $precision == 0 )
	        $precisionFactor = 1;
	    else
	        $precisionFactor = pow( 10, $precision );
	    return ceil( $value * $precisionFactor )/$precisionFactor;
	}

	function getSort($divid) {
		$this->load->library('search/searchutil');
		$ret = & $this->searchutil->get_session($divid, FALSE);
		return $ret;
		/*
		$this->load_session_start();
		if ( !array_key_exists('searchsort_'.$divid, $_SESSION) ) {
			echo '<br /><br /><br /><center><h2><font color="red">' . lang('gen_search_session_timedout') . '</font><h2></center>';
			exit;
		}
		return $_SESSION['searchsort_'.$divid];
		*/
    }

 	function setSqlSession($divid, $array) {
 		$this->load_session_start();
    //	$divid = FALSE;
	//	if (isset($display->divid))
	//	    $divid = $display->divid ;
    //	$_SESSION['SEARCHSORT_PDF_'.$divid] = $display;

    	$_SESSION['searchsort_sql_'.$divid] = $array;
    }

	function getSqlSession($divid) {
		$this->load_session_start();
		if (isset($_SESSION['searchsort_sql_'.$divid]) == FALSE)
			return FALSE;
		$data = $_SESSION['searchsort_sql_'.$divid];
    	return $data;
    }

	function setSortSession( $display, $searchdata=FALSE) {
		$this->load_session_start();
		$divid = FALSE;
		if (isset($display->divid))
		    $divid = $display->divid ;

		if ( $divid==FALSE  ) {
			return $display;
		}

		$_default_col = 0;
		$_default_img = 0;

		if ($searchdata != FALSE) {
			if (isset($searchdata['_data'])) {
				//if (isset($searchdata['_data']['_divid'])) {
					//echo '$searchdata ' . $divid . '<br />';
					//$divid = $searchdata['_data']['_divid'] ;
				//}
				$_default_col = $searchdata['_data']['_default_col'];
				$_default_img = $searchdata['_data']['_default_img'];
			}
			$display->searchid    = $searchdata['_uniqueid'];
			$display->is_sorting  = TRUE;
		}

		$_SESSION['searchsort_'.$divid] = $display;
      return $display;
    }
}