<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Productcontrol extends Controller {

    public function action_production($cat=0){
	
	if(!Auth::instance()->logged_in()){
	    Request::instance()->redirect("");
	}
        $sales = ORM::factory("sale")->where('id','=',$cat)->find();
    
        $data = array( "sales" => $sales);
	$this->request->response = View::factory('product', $data);

    }	
    public function action_sentmessage($saleId=0)
    {
	if(!Auth::instance()->logged_in()){
	    Request::instance()->redirect("");
	}
                if($_POST)
		{
		    $me 			= Auth::instance()->get_user()->id;
                    $message 			= ORM::factory('message');                                                                 
                    $message->message 		= $_POST["message"];
                    $message->time 		= gen::now();
                    $message->sender_id 	= $me;
                    $message->send_helper	= $me;
                    $message->sale_id		= $saleId;
                    $sales 			= ORM::factory("sale")->where('id','=',$saleId)->find();
                    $message->getter_id		= $sales->user_id;
		    $message->get_helper	= $sales->user_id;
		    $message->group_id 		= 0;
		    $message->last_message	= true;
		    //$message->sender_name	= Auth::instance()->get_user()->username;
                    $message->save();
		    
		    $messageId 		= $message->id;
		    $message 		= ORM::factory("message")->where('id','=',$messageId)->find();
		    $message->group_id 	= $messageId;
                    $message->save();
		    
                    Request::instance()->redirect("main/act");
                }
    }

}
