<?php

App::uses('AppModel', 'Model');

/**
 * Term
 *
 * PHP version 5
 *
 * @category Model
 * @package  Bemmelhor
 * @version  1.0
 * @author   Fabricio S Costa <fabriciojf@gmail.com>
 * 
 * @link     http://www.bemmelhor.org
 */

/**

CREATE TABLE phone_operators
(
  id serial,
  name character varying(255) DEFAULT NULL::character varying,
  code character varying(255) DEFAULT NULL::character varying,
  CONSTRAINT phoneops_pkey PRIMARY KEY (id)
);

 */

class PhoneOperator extends AppModel {

/**
 * Model name
 *
 * @var string
 * @access public
 */
	public $name = 'PhoneOperator';	
	
	/**
	 * Modelo do arquivo csv (SMS)
	 *
	 * Telefone
	 */
	function import($filename) {
		
		$filedata = WWW_ROOT . 'uploads' . DS . $filename;
		$handle = fopen($filedata, "r");
		 
		while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
			$PhoneOperator = ClassRegistry::init('PhoneOperator');
			$PhoneOperator->create();
			$PhoneOperator->set('name', $data[0]);
			$PhoneOperator->set('code', $data[1]);
			$PhoneOperator->save();		
		}
		 
		fclose($handle);	
		$file = new File($filedata);
		$file->delete();
	}
	

}
