<?php
//$Id$ 
//gen openMairie le 25/01/2024 10:42

require_once "../gen/obj/om_contraintes.class.php";

class om_contraintes extends om_contraintes_gen {

    function init_class_actions() {
        parent::init_class_actions();
		// modifier
        $this->class_actions[1] = array(); // pas de méthode modifier
	}

    function setType(&$form,$maj) {
        parent::setType($form, $maj);       
        $form->setType("table_name", "hiddenstatic");       
    }


    function setLib(&$form,$maj) {
        parent :: setLib($form,$maj);
		$form->setLib('table_name',_("Table"));
		$form->setLib('table_schema',_("Schema"));
		$form->setLib('constraint_name',_("Contrainte"));
		$form->setLib('column_name',_("Champs"));
		$form->setLib('foreign_table_name',_("Foreign table"));
		$form->setLib('foreign_column_name',_("Foreign champ"));
	}

   function supprimer($val = array(), &$dnu1 = null, $dnu2 = null) {
        // Begin
        $this->begin_treatment(__METHOD__);
        // Mutateur de valF
        $this->setValF($val);
        // verifier si existe des champs 
        $this->verifier($val, $this->f->db, null);
        if ($this->correct) {
			// destruction de la table -> CASCADE ?
			$sql  = "alter table ".DB_PREFIXE.$this->valF['table_name']." ";
			$sql .= " drop constraint ".$this->valF['constraint_name'];
			$res = $this->f->db->query($sql);    
			if ($this->f->isDatabaseError($res, true)) {
				// Appel de la methode de recuperation des erreurs
				$this->addToMessage($res->getDebugInfo());
				$this->correct = false;
				// Return
				return $this->end_treatment(__METHOD__, false);
			}else{
                if($this->triggersupprimerapres($id, $this->f->db, $val, null) === false) {
                    $this->correct = false;
                    $this->addToLog(__METHOD__."(): ERROR", DEBUG_MODE);
                    // Return
                    return $this->end_treatment(__METHOD__, false);
                }
				$this->addToMessage("destruction de la contrainte ".$this->valF['constraint_name']);
			} 
		}else {
            // Message d'echec (saut d'une ligne supplementaire avant le
            // message pour qu'il soit mis en evidence)
            $this->addToMessage("<br/>".__("destruction de la contrainte ")." ".
								$this->valF['constraint_name']." ".__("non effectué"));
            $this->addToLog(__METHOD__."(): ".$message, VERBOSE_MODE);
            // Return
            return $this->end_treatment(__METHOD__, false);
        }	
        return $this->end_treatment(__METHOD__, true);
    }
 
}
