Jump to content

problème création module prestashop 1.4


erwancodep

Recommended Posts

Bonjour,

 

J'ai un problème avec mon formulaire de mon module j'arrive pas faire une action lorsque je valide mon formulaire,

voici mon code la partie qui fonctionne pas est ma fonction insert_odr.

 

Merci d'avance de votre aide.

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
 
class OdrTab extends AdminTab{
    
    private $module = 'odr';
    
    public function __construct(){
        $this->table = 'odr';
        $this->className = 'OdrTab';
        $this->lang = false;
        $this->edit = true;
        $this->delete = true;
        $this->fieldsDisplay = array(
                                    'id' => array(
                                      'title' => $this->l('ID'),
                                      'align' => 'center',
                                      'width' => 25),
                                    'description' => array(
                                      'title' => $this->l('Description'),
                                      'width' => 200),
                                    'download' => array(
                                      'title' => $this->l('Téléchargement'),
                                      'width' => 200),
                                    'date_debut' => array(
                                      'title' => $this->l('Début de l\'offre'),
                                      'type' => 'date',
                                      'align' => 'right',
                                      'width' => 100),
                                    'date_fin' => array(
                                      'title' => $this->l('Fin de l\'offre'),
                                      'type' => 'date',
                                      'align' => 'right',
                                      'width' => 100),
                                );
     
        $this->identifier = 'id';
        
        parent::__construct();
    }
    public function postProcess()
	{
		global $currentIndex;
		
        if (Tools::isSubmit('delete'.$this->table))
		{
            $id_list_odr = $_GET['id'];
			$this->deleted_odr($id_list_odr);
		}
        elseif (Tools::isSubmit('add'.$this->table))
		{
			$this->insert_odr();
		}
		
		//return parent::postProcess();
	}


	public function displayForm($isMainTab = true)
	{
		global $currentIndex;
        $category = $this->getList_categories();
		//parent::displayForm();
        
		if (!($obj = $this->loadObject(true)))
			return;
        
        echo '
		<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" autocomplete="off">
		'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
			<fieldset><legend>'.$this->l('Odr').'</legend>';

		echo '<label>'.$this->l('Description <sup>*</sup> :').' </label>
				<div class="margin-form">
					<textarea rows="4" cols="50" name="description" value="'.htmlentities($this->getFieldValue($obj, 'description'), ENT_COMPAT, 'UTF-8').'"></textarea>
				</div>
               <!-- <label>'.$this->l('ODR <sup>*</sup> :').' </label>
                <div class="margin-form">
                    <input type="hidden" />
                    <input type="file" name="odr" />
                </div> -->
                <label>'.$this->l('Début de l\'offre <sup>*</sup> :').' </label>
				<div class="margin-form">
					<input type="date" name="date_debut" />
				</div>
                <label>'.$this->l('Fin de l\'offre <sup>*</sup> :').' </label>
				<div class="margin-form">
					<input type="date" name="date_fin" />
				</div>
                <label>'.$this->l('CSP <sup>*</sup> :').' </label>
				<div class="margin-form">
					<input type="text" size="5" name="csp" value="'.htmlentities($this->getFieldValue($obj, 'CSP'), ENT_COMPAT, 'UTF-8').'" />
					<span class="hint" name="help_box">'.$this->l('Invalid characters:').' !<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>
				</div>
                <label>'.$this->l('Catégries <sup>*</sup> :').' </label>
				<div class="margin-form">
					<select name="id_categories">';
                        foreach ($category as $categories)
                            echo '<option value="'.(int)($categories['id']).'"'.($categories['id'] == $obj->id ? ' selected="selected"' : '').'>'.htmlentities($categories['category'], ENT_NOQUOTES, 'utf-8').'</option>'; 
                        echo '
					</select>
				</div>
                
				<div class="margin-form">
					<input type="submit" value="'.$this->l('Save').'" name="submitAdd'.$this->table.'" class="button" />
				</div>
				<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
			</fieldset>
		</form>';

	}

	public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)
	{
		global $cookie;
		return parent::getList((int)($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'id' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
	}
	
    public function getList_categories()
	{
		$sql = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'odr_category`');
        
        return $sql; 
	}
    
    public function deleted_odr($id_list_odr)
	{
		$sql = Db::getInstance()->ExecuteS('DELETE FROM `'._DB_PREFIX_.'odr` WHERE `id` = "'.$id_list_odr.'"');
        
        return $sql; 
	}
    
    public function insert_odr()
	{
        if (Tools::getValue('submitAdd'.$this->table)){  
            /*$description = Tools::getValue('description');
            $date_debut = Tools::getValue('date_debut');
            $date_debut_bon_format = str_replace('/', '-', $date_debut);
            $date_fin = Tools::getValue('date_fin');
            $date_fin_bon_format = str_replace('/', '-', $date_fin);
            $csp = Tools::getValue('csp');
            $categories = Tools::getValue('id_categories');*/
            
            Db::getInstance()->Execute('INSERT INTO `edm_odr`
                                                (
                                                    `description`,`download`,
                                                    `date_debut`,`date_fin`,
                                                    `category`,`csp`
                                                )
                                                VALUES (
                                                            "dec","test",
                                                            "2017-09-28","2017-09-28",
                                                            "4","aa"
                                                            
                                                        )'
                                                );
            
        }
    }
}
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...