<?php
App::uses('Model', 'Model');

/**
 * Application model for Cake.
 *
 * Audit Trail This save deleted data in to this model with user and time of action 
 *
 * Add your application-wide methods in the class below, your models
 * will inherit them.
 *
 * @package       app.Model
 */

class Audit extends AppModel { 
	public $belongsTo = array('User' => array('className' => 'User' ,'fields'=> array('first_name','last_name'), 'foreignKey' => 'user_id', 'type' => 'left'));

	public function saveDeletedData($model_id , $model, $user_id , $deleted_content , $action ,  $status = 0, $sales_data = null){ 
		if($user_id){
		//	$id = md5(uniqid());
			//$ip =  $_SERVER['REMOTE_ADDR'];
			//$this->query("INSERT INTO audits (model,model_id ,user_id , delete_date,deleted_content,sales_data,ip,action,status) VALUES ('$model','$model_id', '$user_id', now(), '$deleted_content','$sales_data','$ip','$action','$status')");
						
			
			$data = [
            'Audit' => [
                'Model' => $model,
                'model_id' => $model_id,
                'user_id' => $user_id,
                'delete_date' => date('Y-m-d H:i:s'),
                'deleted_content' => $deleted_content,
                'sales_data' => $sales_data,
                'ip' => $_SERVER['REMOTE_ADDR'],
                'action' => $action,
                'status' => $status
            	]
			];
			$this->create();  // Reset the model's internal state before inserting a new record
        	$this->save($data);
			
			if($user_id == 186){
				pr($model);
			}
		}
	}
}