card.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/bookmarks/card.php
  21. * \brief Page display/creation of bookmarks
  22. * \ingroup bookmark
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array('bookmarks', 'other'));
  28. // Security check
  29. if (!$user->rights->bookmark->lire) {
  30. restrictedArea($user, 'bookmarks');
  31. }
  32. $id = GETPOST("id", 'int');
  33. $action = GETPOST("action", "alpha");
  34. $title = GETPOST("title", "alpha");
  35. $url = GETPOST("url", "alpha");
  36. $urlsource = GETPOST("urlsource", "alpha");
  37. $target = GETPOST("target", "alpha");
  38. $userid = GETPOST("userid", "int");
  39. $position = GETPOST("position", "int");
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $object = new Bookmark($db);
  42. /*
  43. * Actions
  44. */
  45. if ($action == 'add' || $action == 'addproduct' || $action == 'update')
  46. {
  47. if ($action == 'update') {
  48. $invertedaction = 'edit';
  49. } else {
  50. $invertedaction = 'create';
  51. }
  52. $error = 0;
  53. if (GETPOST('cancel', 'alpha'))
  54. {
  55. if (empty($backtopage)) $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
  56. header("Location: ".$backtopage);
  57. exit;
  58. }
  59. if ($action == 'update') $object->fetch(GETPOST("id", 'int'));
  60. // Check if null because user not admin can't set an user and send empty value here.
  61. if (!empty($userid))
  62. $object->fk_user = $userid;
  63. $object->title = $title;
  64. $object->url = $url;
  65. $object->target = $target;
  66. $object->position = $position;
  67. if (!$title) {
  68. $error++;
  69. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
  70. }
  71. if (!$url) {
  72. $error++;
  73. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
  74. }
  75. if (!$error)
  76. {
  77. $object->favicon = 'none';
  78. if ($action == 'update') $res = $object->update();
  79. else $res = $object->create();
  80. if ($res > 0)
  81. {
  82. if (empty($backtopage)) $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
  83. header("Location: ".$backtopage);
  84. exit;
  85. }
  86. else
  87. {
  88. if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  89. {
  90. $langs->load("errors");
  91. setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
  92. }
  93. else
  94. {
  95. setEventMessages($object->error, $object->errors, 'errors');
  96. }
  97. $action = $invertedaction;
  98. }
  99. }
  100. else
  101. {
  102. $action = $invertedaction;
  103. }
  104. }
  105. /*
  106. * View
  107. */
  108. llxHeader();
  109. $form = new Form($db);
  110. $head = array();
  111. $h = 1;
  112. $head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? 'id='.$object->id : '');
  113. $head[$h][1] = $langs->trans("Bookmark");
  114. $head[$h][2] = 'card';
  115. $h++;
  116. $hselected = 'card';
  117. if ($action == 'create')
  118. {
  119. /*
  120. * Fact bookmark creation mode
  121. */
  122. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
  123. print '<input type="hidden" name="token" value="'.newToken().'">';
  124. print '<input type="hidden" name="action" value="add">';
  125. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  126. print load_fiche_titre($langs->trans("NewBookmark"));
  127. dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), 0, 'bookmark');
  128. print '<table class="border centpercent tableforfieldcreate">';
  129. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("BookmarkTitle").'</td><td><input id="titlebookmark" class="flat minwidth100" name="title" value="'.$title.'"></td><td class="hideonsmartphone">'.$langs->trans("SetHereATitleForLink").'</td></tr>';
  130. dol_set_focus('#titlebookmark');
  131. // Url
  132. print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat quatrevingtpercent" name="url" value="'.dol_escape_htmltag($url).'"></td><td class="hideonsmartphone">'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</td></tr>';
  133. // Target
  134. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  135. $liste = array(0=>$langs->trans("ReplaceWindow"), 1=>$langs->trans("OpenANewWindow"));
  136. print $form->selectarray('target', $liste, 1);
  137. print '</td><td class="hideonsmartphone">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</td></tr>';
  138. // Owner
  139. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  140. print img_picto('', 'user').' '.$form->select_dolusers(isset($_POST['userid']) ? $_POST['userid'] : $user->id, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  141. print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
  142. // Position
  143. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  144. print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"]) ? $_POST["position"] : $object->position).'">';
  145. print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
  146. print '</table>';
  147. dol_fiche_end();
  148. print '<div align="center">';
  149. print '<input type="submit" class="button" value="'.$langs->trans("CreateBookmark").'" name="create"> &nbsp; ';
  150. print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
  151. print '</div>';
  152. print '</form>';
  153. }
  154. if ($id > 0 && !preg_match('/^add/i', $action))
  155. {
  156. /*
  157. * Fact bookmark mode or visually edition
  158. */
  159. $object->fetch($id);
  160. $hselected = 'card';
  161. $head = array(
  162. array(
  163. '',
  164. $langs->trans('Card'),
  165. 'card'
  166. )
  167. );
  168. if ($action == 'edit')
  169. {
  170. print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
  171. print '<input type="hidden" name="token" value="'.newToken().'">';
  172. print '<input type="hidden" name="action" value="update">';
  173. print '<input type="hidden" name="id" value="'.$object->id.'">';
  174. print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
  175. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  176. }
  177. dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
  178. $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  179. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
  180. print '<div class="fichecenter">';
  181. print '<div class="underbanner clearboth"></div>';
  182. print '<table class="border centpercent tableforfield">';
  183. print '<tr><td class="titlefield">';
  184. if ($action == 'edit') {
  185. print '<span class="fieldrequired">';
  186. }
  187. print $langs->trans("BookmarkTitle");
  188. if ($action == 'edit') {
  189. print '</span>';
  190. }
  191. print '</td><td>';
  192. if ($action == 'edit') print '<input class="flat minwidth200" name="title" value="'.(isset($_POST["title"]) ?GETPOST("title", '', 2) : $object->title).'">';
  193. else print $object->title;
  194. print '</td></tr>';
  195. print '<tr><td>';
  196. if ($action == 'edit') {
  197. print '<span class="fieldrequired">';
  198. }
  199. print $langs->trans("UrlOrLink");
  200. if ($action == 'edit') {
  201. print '</span>';
  202. }
  203. print '</td><td>';
  204. if ($action == 'edit') print '<input class="flat" name="url" size="80" value="'.(isset($_POST["url"]) ? $_POST["url"] : $object->url).'">';
  205. else print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank"' : '').'>'.$object->url.'</a>';
  206. print '</td></tr>';
  207. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  208. if ($action == 'edit')
  209. {
  210. $liste = array(1=>$langs->trans("OpenANewWindow"), 0=>$langs->trans("ReplaceWindow"));
  211. print $form->selectarray('target', $liste, isset($_POST["target"]) ? $_POST["target"] : $object->target);
  212. }
  213. else
  214. {
  215. if ($object->target == 0) print $langs->trans("ReplaceWindow");
  216. if ($object->target == 1) print $langs->trans("OpenANewWindow");
  217. }
  218. print '</td></tr>';
  219. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  220. if ($action == 'edit' && $user->admin)
  221. {
  222. print img_picto('', 'user').' '.$form->select_dolusers(isset($_POST['userid']) ? $_POST['userid'] : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  223. }
  224. else
  225. {
  226. if ($object->fk_user > 0)
  227. {
  228. $fuser = new User($db);
  229. $fuser->fetch($object->fk_user);
  230. print $fuser->getNomUrl(1);
  231. }
  232. else
  233. {
  234. print $langs->trans("Public");
  235. }
  236. }
  237. print '</td></tr>';
  238. // Position
  239. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  240. if ($action == 'edit') print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"]) ? $_POST["position"] : $object->position).'">';
  241. else print $object->position;
  242. print '</td></tr>';
  243. // Date creation
  244. print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
  245. print '</table>';
  246. print '</div>';
  247. dol_fiche_end();
  248. if ($action == 'edit')
  249. {
  250. print '<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>';
  251. print '</form>';
  252. }
  253. // Buttons
  254. print "<div class=\"tabsAction\">\n";
  255. // Edit
  256. if ($user->rights->bookmark->creer && $action != 'edit')
  257. {
  258. print " <a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?id=".$object->id."&amp;action=edit\">".$langs->trans("Edit")."</a>\n";
  259. }
  260. // Remove
  261. if ($user->rights->bookmark->supprimer && $action != 'edit')
  262. {
  263. print " <a class=\"butActionDelete\" href=\"list.php?bid=".$object->id."&amp;action=delete\">".$langs->trans("Delete")."</a>\n";
  264. }
  265. print '</div>';
  266. }
  267. // End of page
  268. llxFooter();
  269. $db->close();