<?php 
class ControllerProductaviseme extends Controller {
	//private $error = array(); 
	    
  	public function index() {
		$this->language->load('product/avise_me');
		$this->load->model('catalog/avise_me');
		
		$json=array();
		$json="";
	    if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
      		$json['error']['name'] = $this->language->get('error_name');
    	}
		
		if (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
      		$json['error']['email'] = $this->language->get('error_email');
    	}

    	if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
      		$json['error']['captcha'] = $this->language->get('error_captcha');
    	}
		
		if(!$json){ 
		 
			if (($this->request->server['REQUEST_METHOD'] == 'POST') ) {
			    $pr_id=preg_replace("/[^0-9]/", "",$this->request->post['product_id']);
				$this->data['link']=$this->url->link('product/product','product_id='.$pr_id);
                if ($this->data['link'] != "UTF-8"):
					$this->data['link']=utf8_encode($this->data['link']);
			    endif;
			    			    
                $this->model_catalog_avise_me->AddNotify($this->request->post,$this->data['link']);
				$json['success']=1;
	        }  
		}
		 $this->response->setOutput(json_encode($json));
    }

  	

	public function captcha() {
		$this->load->library('captcha');
		
		$captcha = new Captcha();
		
		$this->session->data['captcha'] = $captcha->getCode();
		
		$captcha->showImage();
	}	
}
?>
