/** * 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 Bails($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; } }
$action = GETPOST('action', 'alpha'); $myparam = GETPOST('myparam', 'alpha'); // Protection if external user if ($user->societe_id > 0) { //accessforbidden(); } /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ if ($action == 'add') { $object = new Bails($db); $object->prop1 = $_POST["field1"]; $object->prop2 = $_POST["field2"]; $result = $object->create($user); if ($result > 0) { // Creation OK } // Creation KO $mesg = $object->error; } /*************************************************** * VIEW * * Put here all code to build page ****************************************************/ llxHeader('', 'MyPageName', ''); $form = new Form($db); // Put here content of your page // Example 1 : Adding jquery code
// Pour rensegner les valeurs du bails $staticmandat = new Mandat($db); $idmandat = GETPOST('fk_mandat'); $staticresult = $staticmandat->fetch($idmandat); // print $staticmandat->id; // todo champs pour la creation du bail $gestimmo->fk_prop = $staticmandat->fk_soc; $gestimmo->fk_loc = GETPOST('fk_loc', 'int'); $gestimmo->fk_logement = $staticmandat->fk_biens; $gestimmo->fk_mandat = GETPOST('fk_mandat', 'int'); $gestimmo->Type = GETPOST('Type', 'alpha'); $gestimmo->Date_location = GETPOST('Date_location', 'alpha'); $gestimmo->Depot_garantie = GETPOST('Depot_garantie', 'alpha'); $gestimmo->date_fin = GETPOST('date_fin', 'alpha'); $gestimmo->entity = getpost('entity'); $result = $gestimmo->create($user); if ($result > 0) { if ($url_return) { Header("Location: " . $url_return); } else { Header("Location: " . $_SERVER['PHP_SELF'] . "?action=edit&id=" . $result); } exit; } else { dol_syslog("gestimmo::bails::card error=" . $gestimmo->error, LOG_ERR); $mesg = '<div class="error">' . $gestimmo->error . '</div>'; } } else { Header("Location: list.php"); exit; }