<?php defined('SYSPATH') or die('No direct script access.');
 class Controller_Contact extends Controller_Application {

public $template = 'template';
 
    public function action_index()
    {

       $content = View::factory('pages/session');
$content->bind_global('menu_curent', $menu_curent );
$menu_curent = 'panier';
$commandes = Model::factory( 'Commande');

$message_count = $commandes->count_all();
$pagination = Pagination::factory(array(
'total_items' => $message_count,
'items_per_page' => 50,
));

$pager_links = $pagination->render();

$commandes = $commandes->get_all(session::instance()->get('id_client'),$pagination->items_per_page,$pagination->offset);


        $form = array
            (
                'name'    => '',
                'email'   => '',
                'message' => '',
            );
      //  $this->template->content->errors = array();
        if ( ! $_POST)
        {
           // $this->template->content->form = $form;
		
		    mail("k_harkat@esi.dz", "Commande de ".session::instance()->get('nom_utilisateur'), "message","header","k_harkat@esi.dz");
        }
        else
        {
            $post =  Validation::factory($_POST);
           // $post->pre_filter('trim', TRUE) ;
            //$post->add_rules('name','required', 'length[3,20]', 'alpha');
           // $post->add_rules('email', 'required', 'valid::email');
           // $post->add_rules('message', 'length[0,500]');
          //  $post->add_callbacks('message', array($this, '_msg_check'));
           // $post->post_filter('ucfirst', 'name');
           // $form = $post->as_array();
            if ( ! $post)
            {
                // repopulate form fields and show errors
               // $this->template->content->form = $form;
                $this->template->content->errors = $post->errors('form_error');
			    mail("contiel@hotmail.com", "objet", "message","header","-f k_harkat@esi.dz");
            }
            else            {
                // send the email
                
              mail("contiel@hotmail.com", "objet", "message","header","-f k_harkat@esi.dz");
      
            }
        }
		$this->template->bind_global('content', $content); 
    }

    public function _msg_check(Validation $post)
    {
        if (array_key_exists('message', $post->errors()))
            return;

        if (strlen($post->message) < 5)
        {
            $post->add_error( 'message', 'msg_check');
        }
    	
}
}

?>