/** * 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) { dol_syslog(__METHOD__, LOG_DEBUG); global $user; $error = 0; $object = new Skeleton_Class($this->db); $this->db->begin(); // Load source object $object->fetch($fromid); // Reset object $object->id = 0; // Clear fields // ... // Create clone $result = $object->create($user); // Other options if ($result < 0) { $error++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
// Get parameters $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $backtopage = GETPOST('backtopage'); $myparam = GETPOST('myparam', 'alpha'); $search_field1 = GETPOST("search_field1"); $search_field2 = GETPOST("search_field2"); // Protection if external user if ($user->societe_id > 0) { //accessforbidden(); } if (empty($action) && empty($id) && empty($ref)) { $action = 'list'; } // Load object if id or ref is provided as parameter $object = new Skeleton_Class($db); if (($id > 0 || !empty($ref)) && $action != 'add') { $result = $object->fetch($id, $ref); if ($result < 0) { dol_print_error($db); } } // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('skeleton')); $extrafields = new ExtraFields($db); /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ $parameters = array();
$sortorder = "ASC"; } // Protection if external user $socid = 0; if ($user->societe_id > 0) { $socid = $user->societe_id; //accessforbidden(); } // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('skeletonlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label('mymodule'); $search_array_options = $extrafields->getOptionalsFromPost($extralabels, '', 'search_'); // Load object if id or ref is provided as parameter $object = new Skeleton_Class($db); if (($id > 0 || !empty($ref)) && $action != 'add') { $result = $object->fetch($id, $ref); if ($result < 0) { dol_print_error($db); } } // Definition of fields for list $arrayfields = array('t.field1' => array('label' => $langs->trans("Field1"), 'checked' => 1), 't.field2' => array('label' => $langs->trans("Field2"), 'checked' => 1), 't.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500), 't.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 500)); // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { foreach ($extrafields->attribute_label as $key => $val) { $arrayfields["ef." . $key] = array('label' => $extrafields->attribute_label[$key], 'checked' => $extrafields->attribute_list[$key], 'position' => $extrafields->attribute_pos[$key], 'enabled' => $extrafields->attribute_perms[$key]); } } /*******************************************************************
$langs->load("other"); // Get parameters $id = GETPOST('id', 'int'); $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') { $myobject = new Skeleton_Class($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('', 'Dolimail', '');
$langs->load("other"); // Get parameters $id = GETPOST('id', 'int'); $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') { $myobject = new Skeleton_Class($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', '');
/** * 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 Skeleton_Class($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; } }