<?php
/**
 * importid_int.php - Used for assigning importid_int value from importid. Mainly for data import.
 * 						 This can be run any time even after data was entered by the users.
 * 						 It will always overwrite existing importid_int values.
 * 						 FILE IS OBSOLETE.
 *
 * @author $Author: dtong $
 * @version $Id: importid_int.php,v 1.4 2011/05/09 11:59:59 dtong Exp $
 * @copyright Copyright (c) 2010, Tiller Software Co., Ltd.
*/
echo __METHOD__ . ' is obsolete, aborted.';
exit;

class Importid_int extends CI_Controller{
	function __construct() {
		parent::__construct();
		//$this->load->library('cms/osa_dotnum2int');
		$this->load->model('cms/common_db_model');
		//Have to login first and then run this controller manually.
		$this->access_model->checkaccess_any('admin_system_management', FALSE, FALSE);
	}

	function index() {
		set_time_limit(1000);
		$tables = array('strand', 'standard', 'benchmark');
		//Loop thru each table
		foreach ($tables as $this_table) {
			echo "<br /><br />****************** Updating table $this_table *********************<br />";
			$res = $this->common_db_model->select($this_table);
			if ( $res ) {
				//Loop thru each record for a table
				foreach ($res as $record) {
					if ( !empty($record->importid) ) {
						//Get the bigint value for the importid.
						//Default format for input importid is 1.2.3.4, Default padding is 4 digits
						$bigint = osa_dotnum2int($record->importid);
						if ( $bigint !== FALSE ) {
							$this->common_db_model->update($this_table,$record->id,array('importid_int'=>$bigint));
							echo "ID:{$record->id} Type:{$record->type}, {$record->importid} => $bigint<br />";
						}
					}
					else {
						$this->common_db_model->update($this_table,$record->id,array('importid_int'=>NULL));
						echo "ID:{$record->id} Type:{$record->type}, {$record->importid} => NULL<br />";
					}
				}
			}
		}
	}
}