Skip to content
Snippets Groups Projects
Commit 081d0e7e authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Debug module RH. Edition of user bank account is ok.

parent cf04e5a6
No related branches found
No related tags found
No related merge requests found
......@@ -145,7 +145,7 @@ function user_prepare_head($object)
{
// Bank
$head[$h][0] = DOL_URL_ROOT.'/user/bank.php?id='.$object->id;
$head[$h][1] = $langs->trans("Bank");
$head[$h][1] = $langs->trans("BankAccounts");
$head[$h][2] = 'bank';
$h++;
}
......
......@@ -38,7 +38,9 @@ $langs->load("banks");
$langs->load("bills");
$id = GETPOST('id','int');
$action = GETPOST("action");
$bankid = GETPOST('bankid','int');
$action = GETPOST("action",'alpha');
$cancel = GETPOST('cancel','alpha');
// Security check
$socid=0;
......@@ -54,16 +56,17 @@ if ($id > 0 || ! empty($ref))
$object->getrights();
}
/*
* Actions
*/
if ($action == 'update' && ! $_POST["cancel"])
if ($action == 'update' && ! $cancel)
{
// Modification
$account = new UserBankAccount($db);
$account->fetch($id);
$account->fetch($bankid);
$account->userid = $object->id;
......@@ -82,54 +85,62 @@ if ($action == 'update' && ! $_POST["cancel"])
$account->owner_address = $_POST["owner_address"];
$result = $account->update($user);
if (! $result)
if (! $result)
{
setEventMessages($account->error, $account->errors, 'errors');
$_GET["action"]='edit'; // Force chargement page edition
$action='edit'; // Force chargement page edition
}
else
{
$url=DOL_URL_ROOT.'/user/bank.php?id='.$object->id;
$url=DOL_URL_ROOT.'/user/bank.php?id='.$object->id.'&bankid='.$bankid;
header('Location: '.$url);
exit;
}
}
/*
* View
*/
$form = new Form($db);
llxHeader();
llxHeader(null, $langs->trans("BankAccounts"));
$head = user_prepare_head($object);
$account = new UserBankAccount($db);
if (! $id)
$account->fetch(0,$object->id);
if (! $bankid)
{
$account->fetch(0, '', $id);
}
else
$account->fetch($id);
{
$account->fetch($bankid);
}
if (empty($account->userid)) $account->userid=$object->id;
if ($id && $action == 'edit' && $user->rights->user->user->creer)
if ($bankid && $action == 'edit' && $user->rights->user->user->creer)
{
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.GETPOST("id",'int').'">';
print '<input type="hidden" name="bankid" value="'.$bankid.'">';
}
if ($id && $action == 'create' && $user->rights->user->user->creer)
if ($bankid && $action == 'create' && $user->rights->user->user->creer)
{
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="bankid" value="'.$bankid.'">';
}
// View
if ($id && $action != 'edit')
if ($account->id && $action != 'edit')
{
$title = $langs->trans("User");
dol_fiche_head($head, 'bank', $title, -1, 'user');
......@@ -223,7 +234,7 @@ if ($id && $action != 'edit')
if ($user->rights->user->user->creer)
{
print '<a class="butAction" href="bank.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
print '<a class="butAction" href="bank.php?id='.$object->id.'&bankid='.$account->id.'&action=edit">'.$langs->trans("Edit").'</a>';
}
print '</div>';
......@@ -309,8 +320,6 @@ if ($id && $action == 'edit' && $user->rights->user->user->creer)
print '</div>';
}
if ($id && $action == 'edit' && $user->rights->user->user->creer) print '</form>';
if ($id && $action == 'edit' && $user->rights->user->user->creer) print '</form>';
llxFooter();
......
......@@ -132,16 +132,20 @@ class UserBankAccount extends Account
* Load record from database
*
* @param int $id Id of record
* @param string $ref Ref of record
* @param int $userid User id
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
function fetch($id, $ref='', $userid=0)
{
if (empty($id)) return -1;
if (empty($id) && empty($ref) && empty($userid)) return -1;
$sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
$sql.= " owner_address, label, datec, tms as datem";
$sql.= " FROM ".MAIN_DB_PREFIX."user_rib";
$sql.= " WHERE rowid = ".$id;
if ($id) $sql.= " WHERE rowid = ".$id;
if ($ref) $sql.= " WHERE label = '".$this->db->escape($ref)."'";
if ($userid) $sql.= " WHERE fk_user = '".$userid."'";
$resql = $this->db->query($sql);
if ($resql)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment