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;
@ -1057,34 +1057,53 @@ class FormFile
$var = true;
foreach($links as $link) {
$var=!$var;
$var =! $var;
print '<tr '.$bc[$var].'>';
print '<td>';
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a data-ajax="false" href="'. $link->url . '">';
print $link->label;
print '</a>';
print "</td>\n";
print '<td align="right"></td>';
print '<td align="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
// Preview
/*if (empty($useinecm))
{
print '<td align="center">';
$tmp=explode('.',$file['name']);
$minifile=$tmp[0].'_mini.'.$tmp[1];
if (image_format_supported($file['name']) > 0) print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.'thumbs/'.$minifile).'" title="">';
else print '&nbsp;';
//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="center"></td>';
// Delete or view link
// ($param must start with &)
print '<td align="right" colspan="2">';
print '<a href="'. $_SERVER['PHP_SELF'] .'?action=update&linkid='. $link->id .'&id=' . $object->id . '" class="editfilelink" >'.img_edit().'</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;';
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 "XX".$file['name']; //$file['name'] must be utf8
print '<a data-ajax="false" href="'. $link->url . '">';
print $link->label;
print '</a>';
print "</td>\n";
print '<td align="right"></td>';
print '<td align="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
// Preview
/*if (empty($useinecm))
{
print '<td align="center">';
$tmp=explode('.',$file['name']);
$minifile=$tmp[0].'_mini.'.$tmp[1];
if (image_format_supported($file['name']) > 0) print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.'thumbs/'.$minifile).'" title="">';
else print '&nbsp;';
print '</td>';
}*/
print '<td align="center"></td>';
// Delete or view link
// ($param must start with &)
print '<td align="right" colspan="2">';
print '<a href="'. $_SERVER['PHP_SELF'] .'?action=update&linkid='. $link->id .'&id=' . $object->id . '" class="editfilelink" >'.img_edit().'</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;';
print "</td>";
}
print "</tr>\n";
}
if ($nboflinks == 0)

View File

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

View File

@ -47,5 +47,24 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') {
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
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
}
}