/**
  * 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
  */
 public function createFromClone($fromid)
 {
     global $user, $langs;
     $error = 0;
     $object = new SkeletonClass($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) {
         // Do something
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $object->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Exemplo n.º 2
0
// Get parameters
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$myparam = GETPOST('myparam', 'alpha');
// Access control
if ($user->societe_id > 0) {
    // External user
    accessforbidden();
}
/*
 * ACTIONS
 *
 * Put here all code to do according to value of "action" parameter
 */
if ($action == 'add') {
    $myobject = new SkeletonClass($db);
    $myobject->prop1 = $_POST["field1"];
    $myobject->prop2 = $_POST["field2"];
    $result = $myobject->create($user);
    if ($result > 0) {
        // Creation OK
    }
    // Creation KO
    $mesg = $myobject->error;
}
/*
 * VIEW
 *
 * Put here all code to build page
 */
llxHeader('', 'MyPageName', '');