<?php

class ConfigController extends Zend_Controller_Action {

	public function init() {
	
	/*
		if( $_SERVER['REMOTE_ADDR'] != '5.172.237.90' ) die('Trwa aktualizacja systemu...');
	*/
	
		$information = new Zend_Session_Namespace('information');	
		if( Lib_Permission::CheckPermission('config') != true ){
			$information->permissionError = true;
			$this->_helper->redirector('index','index');		
		}
		
		$admin = new Zend_Session_Namespace('admin');
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','login');
		}			
	}	
	
	
	
	
	
	
	
	
	
	
	/*
	
		Moduł definiowania numerów rejestracyjnych
		27.09.2018
	
	*/
	
	
	public function carAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrclient = new Zend_Session_Namespace('filtrclient');
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		if( $information->addConfigSuccess ){
			$this->view->addConfigSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}

			
		$Car = new Car();	
		$data = $Car->fetchAll(null, 'car_nr ASC'); 		
		$this->view->dataTable = $data;			
		
	}
	
	
	public function caraddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Car = new Car();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addconfig']) ){
		
			$data = array(
				'car_nr' => $v['car_nr']
			);
			$idIns = $Car->insert($data);
			
			//var_dump($data);die();
			
			$information->addConfigSuccess = true; 
			$this->_helper->redirector('car','config');		
			
		}		

	}
	
	public function careditAction() {	
		$v = $this->_request->getParams();
		$information = new Zend_Session_Namespace('information');
		
		$Car = new Car();		
		
		if( $information->editConfigSuccess ){
			$this->view->editConfigSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['admin_editconfig']) ){		
			$data = array(
				'car_nr' => $v['car_nr']
			);
			$Car->update( $data , 'car_id='.$v['id'] );
						
			$information->editConfigSuccess = true; 
			$this->_helper->redirector('caredit','config',null,array('id' => $v['id']));			
		}		
		
		
		
		$select = $Car->select();
		$select->where('car_id = ?', $v['id']);	
		$row = $Car->fetchRow($select);
		$this->view->configData = $row;
	}
	
	public function carremoveAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$Car = new Car();
		$where = array(
			'car_id = ?' => $v['id']
		);
		$Car->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('car','config');		
	}
	
	
	public function cardocAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$information = new Zend_Session_Namespace('information');
		$filtrdocuments = new Zend_Session_Namespace('filtrdocuments');
		$filtrdocuments->documents_car_id = $v['id'];
		$this->_helper->redirector('index','documents');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
