dol_include_once('/immobilier/class/immeuble.class.php');
// Langs
$langs->load("immobilier@immobilier");
$mesg = '';
$id = GETPOST('id', 'int');
$action = GETPOST('action');
$html = new Form($db);
$htmlimmo = new FormImmobilier($db);
/*
 * Action
 */
if ($action == 'addcompteur') {
    $nom_compteur = GETPOST('nom_compteur', 'alpha');
    $type_compteur = GETPOST('type_compteur', 'int');
    //Create Compteur
    $compteur = new Immocompteur($db);
    $compteur->label = $nom_compteur;
    $compteur->type = $type_compteur;
    $result = $compteur->create($user);
    if ($result < 0) {
        setEventMessage($compteur->error, 'errors');
    }
    //Link compteur to local
    $compteur_local = new Immocompteurlocal($db);
    $compteur_local->fk_local = $id;
    $compteur_local->fk_compteur = $compteur->id;
    $result = $compteur_local->create($user);
    if ($result < 0) {
        setEventMessage($compteur_local->error, 'errors');
    }
} elseif ($action == 'addrelever') {
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@param	int		$fromid     Id of object to clone
  * 	@return	int					New id of clone
  */
 function createFromClone($fromid)
 {
     global $user, $langs;
     $error = 0;
     $object = new Immocompteur($this->db);
     $this->db->begin();
     // Load source object
     $object->fetch($fromid);
     $object->id = 0;
     $object->statut = 0;
     // Clear fields
     // ...
     // Create clone
     $result = $object->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $object->error;
         $error++;
     }
     if (!$error) {
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $object->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }