/**
  *  Load data control
  *
  *  @param	string	$action    Type of action
  *  @param	int		$id			Id of object
  *	@return	void
  */
 function doActions(&$action, $id)
 {
     global $conf, $user, $langs;
     // Creation utilisateur depuis Adherent
     if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes') {
         // Recuperation adherent actuel
         $result = $this->object->fetch($id);
         if ($result > 0) {
             $this->db->begin();
             // Creation user
             $nuser = new User($this->db);
             $result = $nuser->create_from_member($this->object, $_POST["login"]);
             if ($result > 0) {
                 $result2 = $nuser->setPassword($user, $_POST["password"], 0, 1, 1);
                 if ($result2) {
                     $this->db->commit();
                 } else {
                     $this->db->rollback();
                 }
             } else {
                 $this->errors[] = $nuser->error;
                 $this->db->rollback();
             }
         } else {
             $this->errors = $this->object->errors;
         }
     }
     // Creation adherent
     if ($action == 'add') {
         $this->assign_post();
         if (!$_POST["name"]) {
             array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname") . ' / ' . $langs->transnoentities("Label")));
             $action = 'create';
         }
         if ($_POST["name"]) {
             $id = $this->object->create($user);
             if ($id > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'create';
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->fetch($id);
         $this->object->old_name = $_POST["old_name"];
         $this->object->old_firstname = $_POST["old_firstname"];
         $result = $this->object->delete();
         if ($result > 0) {
             header("Location: list.php");
             exit;
         } else {
             $this->errors = $this->object->errors;
         }
     }
     if ($action == 'update') {
         if ($_POST["cancel"]) {
             header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
             exit;
         }
         if (empty($_POST["name"])) {
             $this->error = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name") . ' / ' . $langs->transnoentities("Label")));
             $action = 'edit';
         }
         if (empty($this->error)) {
             $this->object->fetch($_POST["adherentid"]);
             $this->object->oldcopy = clone $this->object;
             $this->assign_post();
             $result = $this->object->update($_POST["adherentid"], $user);
             if ($result > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'edit';
             }
         }
     }
 }
Beispiel #2
0
/**
 * Migrate link stored into fk_xxxx into fk_element and elementtype
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_actioncomm_element($db, $langs, $conf)
{
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationActioncommElement') . "</b><br>\n";
    $elements = array('propal' => 'propalrowid', 'order' => 'fk_commande', 'invoice' => 'fk_facture', 'contract' => 'fk_contract', 'order_supplier' => 'fk_supplier_order', 'invoice_supplier' => 'fk_supplier_invoice');
    foreach ($elements as $type => $field) {
        $result = $db->DDLDescTable(MAIN_DB_PREFIX . "actioncomm", $field);
        $obj = $db->fetch_object($result);
        if ($obj) {
            dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=" . $field);
            $db->begin();
            $sql = "UPDATE " . MAIN_DB_PREFIX . "actioncomm SET ";
            $sql .= "fk_element = " . $field . ", elementtype = '" . $type . "'";
            $sql .= " WHERE " . $field . " IS NOT NULL";
            $sql .= " AND fk_element IS NULL";
            $sql .= " AND elementtype IS NULL";
            $resql = $db->query($sql);
            if ($resql) {
                $db->commit();
                // DDL commands must not be inside a transaction
                // We will drop at next version because a migrate should be runnable several times if it fails.
                //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
                //$db->query($sqlDrop);
                //print ". ";
            } else {
                dol_print_error($db);
                $db->rollback();
            }
        } else {
            print $langs->trans('AlreadyDone') . "<br>\n";
        }
    }
    print '</td></tr>';
}