PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/bookmarks/fiche.php

https://github.com/asterix14/dolibarr
PHP | 287 lines | 184 code | 64 blank | 39 comment | 57 complexity | b51067698108c16d72e2db6ae648bb2c MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/bookmarks/fiche.php
  20. * \brief Page display/creation of bookmarks
  21. * \ingroup bookmark
  22. */
  23. require("../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/bookmarks/class/bookmark.class.php");
  25. $langs->load("other");
  26. $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
  27. $title=isset($_GET["title"])?$_GET["title"]:$_POST["title"];
  28. $url=isset($_GET["url"])?$_GET["url"]:$_POST["url"];
  29. $target=isset($_GET["target"])?$_GET["target"]:$_POST["target"];
  30. $userid=isset($_GET["userid"])?$_GET["userid"]:$_POST["userid"];
  31. $position=isset($_GET["position"])?$_GET["position"]:$_POST["position"];
  32. /*
  33. * Actions
  34. */
  35. if ($action == 'add' || $action == 'addproduct' || $action == 'update')
  36. {
  37. if ($_POST["cancel"])
  38. {
  39. $urlsource=(! empty($_REQUEST["urlsource"]))?$_REQUEST["urlsource"]:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/liste.php');
  40. header("Location: ".$urlsource);
  41. exit;
  42. }
  43. $mesg='';
  44. $bookmark=new Bookmark($db);
  45. if ($action == 'update') $bookmark->fetch($_POST["id"]);
  46. $bookmark->fk_user=$userid;
  47. $bookmark->title=$title;
  48. $bookmark->url=$url;
  49. $bookmark->target=$target;
  50. $bookmark->position=$position;
  51. if (! $title) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("BookmarkTitle"));
  52. if (! $url) $mesg.=($mesg?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("UrlOrLink"));
  53. if (! $mesg)
  54. {
  55. $bookmark->favicon='none';
  56. if ($action == 'update') $res=$bookmark->update();
  57. else $res=$bookmark->create();
  58. if ($res > 0)
  59. {
  60. $urlsource=! empty($_REQUEST["urlsource"])?urldecode($_REQUEST["urlsource"]):DOL_URL_ROOT.'/bookmarks/liste.php';
  61. header("Location: ".$urlsource);
  62. exit;
  63. }
  64. else
  65. {
  66. if ($bookmark->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  67. {
  68. $langs->load("errors");
  69. $mesg='<div class="warning">'.$langs->trans("WarningBookmarkAlreadyExists").'</div>';
  70. }
  71. else
  72. {
  73. $mesg='<div class="error">'.$bookmark->error.'</div>';
  74. }
  75. $action='create';
  76. }
  77. }
  78. else
  79. {
  80. $mesg='<div class="error">'.$mesg.'</div>';
  81. $action='create';
  82. }
  83. }
  84. if ($_GET["action"] == 'delete')
  85. {
  86. $bookmark=new Bookmark($db);
  87. $bookmark->id=$_GET["bid"];
  88. $bookmark->url=$user->id;
  89. $bookmark->target=$user->id;
  90. $bookmark->title='xxx';
  91. $bookmark->favicon='xxx';
  92. $res=$bookmark->remove();
  93. if ($res > 0)
  94. {
  95. header("Location: ".$_SERVER["PHP_SELF"]);
  96. exit;
  97. }
  98. else
  99. {
  100. $mesg='<div class="error">'.$bookmark->error.'</div>';
  101. }
  102. }
  103. /*
  104. * View
  105. */
  106. llxHeader();
  107. $form=new Form($db);
  108. if ($action == 'create')
  109. {
  110. /*
  111. * Fact bookmark creation mode
  112. */
  113. print '<form action="fiche.php" method="post" enctype="multipart/form-data">'."\n";
  114. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  115. print '<input type="hidden" name="action" value="add">';
  116. print_fiche_titre($langs->trans("NewBookmark"));
  117. if ($mesg) print "$mesg<br>";
  118. print '<table class="border" width="100%">';
  119. print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("BookmarkTitle").'</td><td><input class="flat" name="title" size="30" value="'.$title.'"></td><td>'.$langs->trans("SetHereATitleForLink").'</td></tr>';
  120. print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat" name="url" size="50" value="'.$url.'"></td><td>'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</td></tr>';
  121. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  122. $liste=array(0=>$langs->trans("ReplaceWindow"),1=>$langs->trans("OpenANewWindow"));
  123. print $form->selectarray('target',$liste,1);
  124. print '</td><td>'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</td></tr>';
  125. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  126. $form->select_users(isset($_POST['userid'])?$_POST['userid']:$user->id,'userid',1);
  127. print '</td><td>&nbsp;</td></tr>';
  128. // Position
  129. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  130. print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$bookmark->position).'">';
  131. print '</td></tr>';
  132. print '<tr><td colspan="3" align="center">';
  133. print '<input type="submit" class="button" value="'.$langs->trans("CreateBookmark").'" name="create"> &nbsp; ';
  134. print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
  135. print '</td></tr>';
  136. print '</table>';
  137. print '</form>';
  138. }
  139. if ($_GET["id"] > 0 && ! preg_match('/^add/i',$_GET["action"]))
  140. {
  141. /*
  142. * Fact bookmark mode or visually edition
  143. */
  144. $bookmark=new Bookmark($db);
  145. $bookmark->fetch($_GET["id"]);
  146. dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark');
  147. if ($_GET["action"] == 'edit')
  148. {
  149. print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
  150. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  151. print '<input type="hidden" name="action" value="update">';
  152. print '<input type="hidden" name="id" value="'.$bookmark->id.'">';
  153. print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/fiche.php?id='.$bookmark->id.'">';
  154. }
  155. print '<table class="border" width="100%">';
  156. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>'.$bookmark->ref.'</td></tr>';
  157. print '<tr><td>'.$langs->trans("BookmarkTitle").'</td><td>';
  158. if ($_GET["action"] == 'edit') print '<input class="flat" name="title" size="30" value="'.(isset($_POST["title"])?$_POST["title"]:$bookmark->title).'">';
  159. else print $bookmark->title;
  160. print '</td></tr>';
  161. print '<tr><td>'.$langs->trans("UrlOrLink").'</td><td>';
  162. if ($_GET["action"] == 'edit') print '<input class="flat" name="url" size="80" value="'.(isset($_POST["url"])?$_POST["url"]:$bookmark->url).'">';
  163. else print '<a href="'.(preg_match('/^http/i',$bookmark->url)?$bookmark->url:DOL_URL_ROOT.$bookmark->url).'"'.($bookmark->target?' target="_blank"':'').'>'.$bookmark->url.'</a>';
  164. print '</td></tr>';
  165. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  166. if ($_GET["action"] == 'edit')
  167. {
  168. $liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow"));
  169. print $form->selectarray('target',$liste,isset($_POST["target"])?$_POST["target"]:$bookmark->target);
  170. }
  171. else
  172. {
  173. if ($bookmark->target == 0) print $langs->trans("ReplaceWindow");
  174. if ($bookmark->target == 1) print $langs->trans("OpenANewWindow");
  175. }
  176. print '</td></tr>';
  177. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  178. if ($_GET["action"] == 'edit' && $user->admin)
  179. {
  180. $form->select_users(isset($_POST['userid'])?$_POST['userid']:($bookmark->fk_user?$bookmark->fk_user:''),'userid',1);
  181. }
  182. else
  183. {
  184. if ($bookmark->fk_user)
  185. {
  186. $fuser=new User($db);
  187. $fuser->fetch($bookmark->fk_user);
  188. //$fuser->nom=$fuser->login; $fuser->prenom='';
  189. print $fuser->getNomUrl(1);
  190. }
  191. else
  192. {
  193. print $langs->trans("Public");
  194. }
  195. }
  196. print '</td></tr>';
  197. // Position
  198. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  199. if ($_GET["action"] == 'edit') print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$bookmark->position).'">';
  200. else print $bookmark->position;
  201. print '</td></tr>';
  202. // Date creation
  203. print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($bookmark->datec,'dayhour').'</td></tr>';
  204. if ($_GET["action"] == 'edit') print '<tr><td colspan="2" 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").'"></td></tr>';
  205. print '</table>';
  206. if ($_GET["action"] == 'edit') print '</form>';
  207. print "</div>\n";
  208. print "<div class=\"tabsAction\">\n";
  209. // Edit
  210. if ($user->rights->bookmark->creer && $_GET["action"] != 'edit')
  211. {
  212. print " <a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?id=".$bookmark->id."&amp;action=edit\">".$langs->trans("Edit")."</a>\n";
  213. }
  214. // Remove
  215. if ($user->rights->bookmark->supprimer && $_GET["action"] != 'edit')
  216. {
  217. print " <a class=\"butActionDelete\" href=\"liste.php?bid=".$bookmark->id."&amp;action=delete\">".$langs->trans("Delete")."</a>\n";
  218. }
  219. print '</div>';
  220. }
  221. $db->close();
  222. llxFooter();
  223. ?>