edit link lines function

This commit is contained in:
Cédric Salvador 2013-07-31 16:21:24 +02:00 committed by Raphaël Doursenaud
parent b158e8bb74
commit f2535d74ea
3 changed files with 66 additions and 28 deletions

View File

@ -1018,7 +1018,7 @@ class FormFile
} }
public function list_of_links($object, $permtodelete=1) public function list_of_links($object, $permtodelete=1, $action=null, $selected=null)
{ {
global $user, $conf, $langs, $hookmanager, $user; global $user, $conf, $langs, $hookmanager, $user;
@ -1059,6 +1059,24 @@ class FormFile
foreach($links as $link) { foreach($links as $link) {
$var =! $var; $var =! $var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
//edit mode
if ($action == 'update' && $selected === $link->id) {
print '<form action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="linkid" value="' . $link->id . '">';
print '<input type="hidden" name="action" value="confirm_updateline">';
print '<td>';
print $langs->trans('Link') . ': <input type="text" name="link" value = "' . $link->url . '">';
print '</td>';
print '<td align="right">';
print $langs->trans('Label') . ': <input type="text" name="label" value = "' . $link->label . '">';
print '</td>';
print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
print '<td align="right"></td>';
print '<td align="right" colspan="2"><input type="submit" name="save" class="button" value="' . $langs->trans('Save') . '">';
print '<input type="submit" name="cancel" class="button" value="' . $langs->trans('Cancel') . '"></td>';
print '</form>';
}
else {
print '<td>'; print '<td>';
//print "XX".$file['name']; //$file['name'] must be utf8 //print "XX".$file['name']; //$file['name'] must be utf8
print '<a data-ajax="false" href="'. $link->url . '">'; print '<a data-ajax="false" href="'. $link->url . '">';
@ -1085,6 +1103,7 @@ class FormFile
if ($permtodelete) print '<a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid='. $link->id . '&id=' . $object->id . '" class="deletefilelink" >'.img_delete().'</a>'; if ($permtodelete) print '<a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid='. $link->id . '&id=' . $object->id . '" class="deletefilelink" >'.img_delete().'</a>';
else print '&nbsp;'; else print '&nbsp;';
print "</td>"; print "</td>";
}
print "</tr>\n"; print "</tr>\n";
} }
if ($nboflinks == 0) if ($nboflinks == 0)

View File

@ -38,5 +38,5 @@ $formfile->list_of_documents($filearray,
print "<br>"; print "<br>";
//List of links //List of links
$formfile->list_of_links($object, $permission); $formfile->list_of_links($object, $permission, $action, GETPOST('linkid', 'int'));
print "<br>"; print "<br>";

View File

@ -47,5 +47,24 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') {
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
exit; exit;
} }
} elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha')) {
require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php';
$langs->load('link');
$link = new Link($db);
$link->id = GETPOST('linkid', 'int');
$f = $link->fetch();
if ($f) {
$link->url = GETPOST('link', 'alpha');
if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://') {
$link->url = 'http://' . $link->url;
}
$link->label = GETPOST('label', 'alpha');
$res = $link->update($user);
if (!$res) {
setEventMessage($langs->trans("ErrorFailedToUpdateLink", $link->label));
}
} else {
//error fetching
}
} }