<?php
App::uses('AppController', 'Controller');
class OthersController extends AppController {
/**
 * Controller Others
 * @var string
 */

	public function verify_all(){
		$this->_doverification_status(ACTIVE);
	}
	
	public function unverify_all(){
		$this->_doverification_status(INACTIVE);
	}
	
	
	function _doverification_status($status){
		if (!empty($this->request->data['deleteAllValue']) && !empty($this->request->data['deleteAllValue'])){	
			$idsStr = $this->request->data['deleteAllValue'];		
			$model = $this->request->data['mdl'];
			$ids = !empty($this->request->data['deleteAllValue']) ? explode(",", $this->request->data['deleteAllValue']):array();
			$this->loadModel($model);
			$this->$model->unbindModelAll();
			if ( $status == INACTIVE){
				$data = array($model.'.status'=>INACTIVE, $model.'.verify_by' => 0);
			}else{
				$data = array($model.'.status'=>ACTIVE, $model.'.verify_by' => $this->user['id']);
			}
			$this->$model->updateAll($data, array($model.'.id'=> $ids));
			if ($model == "Order"){
				$this->$model->query("UPDATE sales SET status = $status WHERE order_id IN (".$idsStr.")");
				$this->$model->query("UPDATE free_items SET status = $status WHERE order_id IN (".$idsStr.")");
			}
			if ($model == "RedistributorSale"){
				$this->$model->query("UPDATE redistributor_saleitems SET status = $status WHERE redistributor_sale_id IN (".$idsStr.")");
			}			
		}
		exit;
	}
}