public function add($code, $type, $valeur, $mini, $actif, $limite, $nombre_limite, $expiration, $date_expiration) { $this->code = $code; $this->type = in_array($type, array(1, 2)) ? $type : ''; $this->valeur = is_numeric($valeur) ? $valeur : ''; $this->mini = is_numeric($mini) ? $mini : ''; $this->utilise = 0; $this->form_use_type = $limite; $this->limite = $limite === '0' ? 0 : (filter_var($nombre_limite, FILTER_VALIDATE_INT === false) ? '' : $nombre_limite); $this->form_expiration_type = $expiration; $this->datefin = $expiration === '0' ? '00-00-0000' : (preg_match('#^[0-9]{2}\\-[0-9]{2}\\-[0-9]{4}$#', $date_expiration) ? $date_expiration : ''); $this->actif = $actif === '0' || $actif === '1' ? $actif : ''; if ($this->code !== "" && !self::testCodeExists($this->code) && $this->type !== "" && $this->valeur !== "" && $this->mini !== "" && $this->limite !== "" && $this->datefin !== "" && $this->actif !== "") { $this->datefin = date('Y-m-d', strtotime($this->datefin)); $this->id = parent::add(); ActionsModules::instance()->appel_module("ajoutpromo", new Promo($this->code)); redirige("promo.php"); } else { throw new TheliaAdminException("impossible to add new promo", TheliaAdminException::PROMO_ADD_ERROR, null, $this); } }
function ajouter($code, $type, $valeur, $mini, $actif, $limite, $nombre_limite, $jour, $mois, $annee) { $promo = new Promo(); $promo->code = $code; $promo->type = $type; $promo->actif = $actif; $promo->valeur = $valeur; $promo->mini = $mini; $promo->limite = $limite == 0 ? 0 : $nombre_limite; $promo->datefin = $annee . "-" . $mois . "-" . $jour; $promo->actif = 1; $promo->add(); ActionsModules::instance()->appel_module("ajoutpromo", $promo); }