dolibarr/htdocs/bookmarks/card.php

309 lines
9.1 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2009-01-23 17:03:24 +01:00
/**
* \file htdocs/bookmarks/card.php
2010-02-18 15:03:48 +01:00
* \brief Page display/creation of bookmarks
* \ingroup bookmark
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
$langs->load("bookmarks");
2005-09-11 03:31:37 +02:00
$langs->load("other");
// Security check
if (! $user->rights->bookmark->lire) {
restrictedArea($user, 'bookmarks');
}
2012-10-19 17:28:18 +02:00
$id=GETPOST("id");
$action=GETPOST("action","alpha");
$title=GETPOST("title","alpha");
$url=GETPOST("url","alpha");
$target=GETPOST("target","alpha");
$userid=GETPOST("userid","int");
$position=GETPOST("position","int");
$backtopage=GETPOST('backtopage','alpha');
2005-09-11 03:31:37 +02:00
/*
* Actions
*/
2005-09-11 03:31:37 +02:00
2009-02-01 14:30:33 +01:00
if ($action == 'add' || $action == 'addproduct' || $action == 'update')
2009-01-28 16:53:08 +01:00
{
if ($action == 'update') {
$invertedaction = 'edit';
} else {
$invertedaction = 'create';
}
$error = 0;
2012-10-19 17:28:18 +02:00
if (GETPOST("cancel"))
2009-01-23 17:03:24 +01:00
{
if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php'));
2012-10-19 17:28:18 +02:00
header("Location: ".$backtopage);
2011-09-14 23:29:04 +02:00
exit;
2009-01-23 17:03:24 +01:00
}
2011-09-14 23:29:04 +02:00
$bookmark=new Bookmark($db);
if ($action == 'update') $bookmark->fetch($_POST["id"]);
$bookmark->fk_user=$userid;
$bookmark->title=$title;
$bookmark->url=$url;
$bookmark->target=$target;
$bookmark->position=$position;
2009-01-23 17:03:24 +01:00
if (! $title) {
$error++;
setEventMessage($langs->transnoentities("ErrorFieldRequired",$langs->trans("BookmarkTitle")), 'errors');
}
if (! $url) {
$error++;
setEventMessage($langs->transnoentities("ErrorFieldRequired",$langs->trans("UrlOrLink")), 'errors');
}
2005-09-11 03:31:37 +02:00
if (! $error)
2011-09-14 23:29:04 +02:00
{
$bookmark->favicon='none';
2009-01-23 17:03:24 +01:00
2011-09-14 23:29:04 +02:00
if ($action == 'update') $res=$bookmark->update();
else $res=$bookmark->create();
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
if ($res > 0)
{
if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):DOL_URL_ROOT.'/bookmarks/list.php');
2012-10-19 17:28:18 +02:00
header("Location: ".$backtopage);
2011-09-14 23:29:04 +02:00
exit;
}
else
{
if ($bookmark->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
setEventMessage($langs->transnoentities("WarningBookmarkAlreadyExists"), 'warnings');
2011-09-14 23:29:04 +02:00
}
else
{
setEventMessage($bookmark->error, 'errors');
2011-09-14 23:29:04 +02:00
}
$action = $invertedaction;
2011-09-14 23:29:04 +02:00
}
}
else
{
$action = $invertedaction;
2011-09-14 23:29:04 +02:00
}
}
2012-10-19 17:28:18 +02:00
if ($action == 'delete')
{
2011-09-14 23:29:04 +02:00
$bookmark=new Bookmark($db);
$bookmark->id=$_GET["bid"];
$bookmark->url=$user->id;
$bookmark->target=$user->id;
$bookmark->title='xxx';
$bookmark->favicon='xxx';
$res=$bookmark->remove();
if ($res > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
setEventMessage($bookmark->error, 'errors');
2011-09-14 23:29:04 +02:00
}
}
/*
* View
*/
llxHeader();
$form=new Form($db);
2005-09-11 03:31:37 +02:00
if ($action == 'create')
{
2011-09-14 23:29:04 +02:00
/*
* Fact bookmark creation mode
*/
2005-09-11 03:31:37 +02:00
2012-10-19 17:28:18 +02:00
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
2011-09-14 23:29:04 +02:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
2012-10-19 17:28:18 +02:00
2011-09-14 23:29:04 +02:00
print_fiche_titre($langs->trans("NewBookmark"));
2005-09-11 03:31:37 +02:00
2011-09-14 23:29:04 +02:00
print '<table class="border" width="100%">';
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("BookmarkTitle").'</td><td><input class="flat" name="title" size="30" value="'.$title.'"></td><td class="hideonsmartphone">'.$langs->trans("SetHereATitleForLink").'</td></tr>';
2009-02-01 14:30:33 +01:00
print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat" name="url" size="50" value="'.$url.'"></td><td class="hideonsmartphone">'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</td></tr>';
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
$liste=array(0=>$langs->trans("ReplaceWindow"),1=>$langs->trans("OpenANewWindow"));
print $form->selectarray('target',$liste,1);
print '</td><td class="hideonsmartphone">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</td></tr>';
2009-01-23 17:03:24 +01:00
2011-09-14 23:29:04 +02:00
print '<tr><td>'.$langs->trans("Owner").'</td><td>';
$form->select_users(isset($_POST['userid'])?$_POST['userid']:$user->id,'userid',1);
print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
// Position
print '<tr><td>'.$langs->trans("Position").'</td><td>';
print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$bookmark->position).'">';
print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
print '</table><br>';
print '<div align="center">';
2011-09-14 23:29:04 +02:00
print '<input type="submit" class="button" value="'.$langs->trans("CreateBookmark").'" name="create"> &nbsp; ';
print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
print '</div>';
2009-01-23 17:03:24 +01:00
2011-09-14 23:29:04 +02:00
print '</form>';
2005-09-11 03:31:37 +02:00
}
2012-10-19 17:28:18 +02:00
if ($id > 0 && ! preg_match('/^add/i',$action))
2005-09-11 03:31:37 +02:00
{
2011-09-14 23:29:04 +02:00
/*
* Fact bookmark mode or visually edition
*/
$bookmark=new Bookmark($db);
2012-10-19 17:28:18 +02:00
$bookmark->fetch($id);
2011-09-14 23:29:04 +02:00
$head = array(
array(
'',
$langs->trans('Card'),
'card'
)
);
2011-09-14 23:29:04 +02:00
dol_fiche_head($head, 'card', $langs->trans("Bookmark"),0,'bookmark');
2011-09-14 23:29:04 +02:00
2012-10-19 17:28:18 +02:00
if ($action == 'edit')
2011-09-14 23:29:04 +02:00
{
print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$bookmark->id.'">';
print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$bookmark->id.'">';
2012-10-19 17:28:18 +02:00
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2011-09-14 23:29:04 +02:00
}
print '<table class="border" width="100%">';
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>'.$bookmark->ref.'</td></tr>';
2014-11-23 16:44:49 +01:00
print '<tr><td><span class="fieldrequired">'.$langs->trans("BookmarkTitle").'</span></td><td>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit') print '<input class="flat" name="title" size="30" value="'.(isset($_POST["title"])?$_POST["title"]:$bookmark->title).'">';
2011-09-14 23:29:04 +02:00
else print $bookmark->title;
print '</td></tr>';
2014-11-23 16:44:49 +01:00
print '<tr><td><span class="fieldrequired">'.$langs->trans("UrlOrLink").'</span></td><td>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit') print '<input class="flat" name="url" size="80" value="'.(isset($_POST["url"])?$_POST["url"]:$bookmark->url).'">';
2011-09-14 23:29:04 +02:00
else print '<a href="'.(preg_match('/^http/i',$bookmark->url)?$bookmark->url:DOL_URL_ROOT.$bookmark->url).'"'.($bookmark->target?' target="_blank"':'').'>'.$bookmark->url.'</a>';
print '</td></tr>';
print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit')
2011-09-14 23:29:04 +02:00
{
$liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow"));
print $form->selectarray('target',$liste,isset($_POST["target"])?$_POST["target"]:$bookmark->target);
2011-09-14 23:29:04 +02:00
}
else
{
if ($bookmark->target == 0) print $langs->trans("ReplaceWindow");
if ($bookmark->target == 1) print $langs->trans("OpenANewWindow");
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Owner").'</td><td>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit' && $user->admin)
2011-09-14 23:29:04 +02:00
{
$form->select_users(isset($_POST['userid'])?$_POST['userid']:($bookmark->fk_user?$bookmark->fk_user:''),'userid',1);
2011-09-14 23:29:04 +02:00
}
else
{
if ($bookmark->fk_user)
{
$fuser=new User($db);
$fuser->fetch($bookmark->fk_user);
print $fuser->getNomUrl(1);
2009-02-01 14:30:33 +01:00
}
else
{
print $langs->trans("Public");
}
2011-09-14 23:29:04 +02:00
}
print '</td></tr>';
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
// Position
print '<tr><td>'.$langs->trans("Position").'</td><td>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit') print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$bookmark->position).'">';
2011-09-14 23:29:04 +02:00
else print $bookmark->position;
print '</td></tr>';
2011-09-14 23:29:04 +02:00
// Date creation
print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($bookmark->datec,'dayhour').'</td></tr>';
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
print '</table>';
2005-09-11 03:31:37 +02:00
2012-10-19 17:28:18 +02:00
if ($action == 'edit') print '<br><div align="center"><input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; <input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
2012-10-19 17:28:18 +02:00
if ($action == 'edit') print '</form>';
2009-02-01 14:30:33 +01:00
dol_fiche_end();
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
print "<div class=\"tabsAction\">\n";
2005-09-11 03:31:37 +02:00
2011-09-14 23:29:04 +02:00
// Edit
2012-10-19 17:28:18 +02:00
if ($user->rights->bookmark->creer && $action != 'edit')
2011-09-14 23:29:04 +02:00
{
print " <a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?id=".$bookmark->id."&amp;action=edit\">".$langs->trans("Edit")."</a>\n";
}
2009-02-01 14:30:33 +01:00
2011-09-14 23:29:04 +02:00
// Remove
2012-10-19 17:28:18 +02:00
if ($user->rights->bookmark->supprimer && $action != 'edit')
2011-09-14 23:29:04 +02:00
{
print " <a class=\"butActionDelete\" href=\"list.php?bid=".$bookmark->id."&amp;action=delete\">".$langs->trans("Delete")."</a>\n";
2011-09-14 23:29:04 +02:00
}
2005-09-11 03:31:37 +02:00
2011-09-14 23:29:04 +02:00
print '</div>';
2005-09-11 03:31:37 +02:00
}
2005-09-11 03:31:37 +02:00
llxFooter();
2012-10-19 17:28:18 +02:00
$db->close();