<?php

class Default_IndexController extends Ec_Controller_DefaultAction
{

    public function preDispatch()
    {
        $this->view->errMsg = '';
        $this->tplDirectory = "default/views/default/";
    }

    public function indexAction()
    {	
    	$this->_redirect('/login');
    	exit;
        $wh=Service_Warehouse::getAll();
        $this->view->msg = 'www.oms.com';
       // echo $this->view->render($this->tplDirectory . 'index.tpl');//不使用布局文件
        echo Ec::renderTpl($this->tplDirectory . "index.tpl", 'layout');//使用布局文件
    }

    public function loginAction()
    {
        die('login');
    }

    public function logoutAction()
    {
        $session = new Zend_Session_Namespace('customerAuth');
        $session->unsetAll();
        session_destroy();
    }

    /*
     * @输出验证码
     */
    public function verifyCodeAction()
    {
        $verifyCode = new Common_Verifycode();
        $verifyCode->set_sess_name('AdminVerifyCode');
        echo $verifyCode->render();
    }
    /**
     * @author william-fan
     * @todo 条码
     */
    public function barcodeAction(){
    	Common_Barcode::barcode($this->_request->code);
    	exit;
    }
    /**
     * author william-fan
     * @todo 用于改变语言
     */
    public function changeLangAction(){
    	if($this->_request->isPost()){
    		$langCode = $this->_request->getParam('langCode');
    		if($langCode){
    			$sessionUser = new Zend_Session_Namespace("userAuthorization");
    			$sessionUser->lang = $langCode;
    			echo json_encode('1');
    			die();
    		}
    	}

    }
    public function headerInnerAction(){
        echo $this->view->render($this->tplDirectory . 'header-inner.tpl');
    }
    public function headerAction(){
        //$session			= new Zend_Session_Namespace('RegisterStep');
        //$session->step = '4';
        //$this->view->step = $session->step;
        echo $this->view->render($this->tplDirectory ."header.tpl");
    }
	
    /* 上传图片查看 */
    public function viewUploadImageAction ()
    {
        $fileName = $this->_request->getParam('fileName', "");
		$customerCode = $this->_request->getParam('customerCode', "");
        $path = APPLICATION_PATH . "/../data/images/register/" .$customerCode.'/'. $fileName;
   //echo $path;exit;
        if (file_exists($path)) {
            header('Content-Type: image/jpeg');
            echo file_get_contents($path);
    
        } else {
            header("Location: /images/noimg.jpg");
        }
    
        exit();
    } 
	
	/*客人LOGO*/
    public function viewLogoImageAction(){        
		$customerCode = $this->_request->getParam('customerCode', "");
		if(empty($customerCode)){ exit;}
		$customer_array = Service_Customer::getByField($customerCode, 'customer_code');
		$fileName = $customer_array['customer_logo'];
        $path = APPLICATION_PATH . "/../data/images/register/" .$customerCode.'/'. $fileName;
   //echo $path;exit;
        if (file_exists($path)) {
            header('Content-Type: image/jpeg');
            echo file_get_contents($path);
    
        } else {
            header("Location: /images/noimg.jpg");
        }
    
        exit();
    } 
	
    /**
     * @查看产品图片
     * @desc WMS 全站使用
     */
    public function viewProductImgAction()
    {
        $productId = $this->_request->getParam('id', "");
        if ($productId) {
            $productAttach = Service_ProductAttached::getByField($productId, 'product_id');
            if ($productAttach) {
                if ($productAttach['pa_file_type'] == 'link') {
                    header("Location: " . $productAttach ['pa_path']);
                    exit ();
                }
                if ($productAttach['pa_file_type'] == 'img') {
                    header("Location: http://develop-oms.ez-wms.com/product-image/view-attach/productId/" . $productId);
                    exit ();
                }
            }
        }
        header("Location: /images/noimg.jpg");
        exit ();
    }	
	/**
	 * @author william-fan
	 * @todo 备案
	 */
    public function beianAction(){
    	echo 'sss';
    	echo "<pre>";
    	$db =  Common_Common::getAdapter();
		//$db->beginTransaction();
		set_time_limit(0);
		$sql = "select * from product_ba";
		
		$result = $db->fetchAll($sql);
    	print_r($result);
		//Service_Product::handleRecord(2705);
		//exit;
		//exit;
		//exit;
		//exit;
		foreach($result as $key=>$value){
			if($value['product_id']=='2705'){
				continue;
			}
			if($value['customer_code']=='E0110'){
				continue;
			}
			print_r($value);
			//exit;
			Service_Product::handleRecord($value['product_id']);
		}
		
		echo "run over";
		
		//print_r($result);
		
    	
    }			
}