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 <http://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("Card");
  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="'.$_SESSION['newtoken'].'">';
  124. print '<input type="hidden" name="action" value="add">';
  125. print load_fiche_titre($langs->trans("NewBookmark"));
  126. dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), 0, 'bookmark');
  127. print '<table class="border" width="100%">';
  128. 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>';
  129. dol_set_focus('#titlebookmark');
  130. // Url
  131. 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>';
  132. // Target
  133. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  134. $liste=array(0=>$langs->trans("ReplaceWindow"),1=>$langs->trans("OpenANewWindow"));
  135. print $form->selectarray('target',$liste,1);
  136. print '</td><td class="hideonsmartphone">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</td></tr>';
  137. // Owner
  138. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  139. print $form->select_dolusers(isset($_POST['userid'])?$_POST['userid']:$user->id, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  140. print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
  141. // Position
  142. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  143. print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$object->position).'">';
  144. print '</td><td class="hideonsmartphone">&nbsp;</td></tr>';
  145. print '</table>';
  146. dol_fiche_end();
  147. print '<div align="center">';
  148. print '<input type="submit" class="button" value="'.$langs->trans("CreateBookmark").'" name="create"> &nbsp; ';
  149. print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
  150. print '</div>';
  151. print '</form>';
  152. }
  153. if ($id > 0 && ! preg_match('/^add/i',$action))
  154. {
  155. /*
  156. * Fact bookmark mode or visually edition
  157. */
  158. $object->fetch($id);
  159. $hselected = 'card';
  160. $head = array(
  161. array(
  162. '',
  163. $langs->trans('Card'),
  164. 'card'
  165. )
  166. );
  167. if ($action == 'edit')
  168. {
  169. print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
  170. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  171. print '<input type="hidden" name="action" value="update">';
  172. print '<input type="hidden" name="id" value="'.$object->id.'">';
  173. print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
  174. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  175. }
  176. dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
  177. $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans("BackToList").'</a>';
  178. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
  179. print '<div class="fichecenter">';
  180. print '<div class="underbanner clearboth"></div>';
  181. print '<table class="border" width="100%">';
  182. print '<tr><td class="titlefield">';
  183. if ($action == 'edit') {
  184. print '<span class="fieldrequired">';
  185. }
  186. print $langs->trans("BookmarkTitle");
  187. if ($action == 'edit') {
  188. print '</span>';
  189. }
  190. print '</td><td>';
  191. if ($action == 'edit') print '<input class="flat minwidth200" name="title" value="'.(isset($_POST["title"])?GETPOST("title",'',2):$object->title).'">';
  192. else print $object->title;
  193. print '</td></tr>';
  194. print '<tr><td>';
  195. if ($action == 'edit') {
  196. print '<span class="fieldrequired">';
  197. }
  198. print $langs->trans("UrlOrLink");
  199. if ($action == 'edit') {
  200. print '</span>';
  201. }
  202. print '</td><td>';
  203. if ($action == 'edit') print '<input class="flat" name="url" size="80" value="'.(isset($_POST["url"])?$_POST["url"]:$object->url).'">';
  204. else print '<a href="'.(preg_match('/^http/i',$object->url)?$object->url:DOL_URL_ROOT.$object->url).'"'.($object->target?' target="_blank"':'').'>'.$object->url.'</a>';
  205. print '</td></tr>';
  206. print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
  207. if ($action == 'edit')
  208. {
  209. $liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow"));
  210. print $form->selectarray('target',$liste,isset($_POST["target"])?$_POST["target"]:$object->target);
  211. }
  212. else
  213. {
  214. if ($object->target == 0) print $langs->trans("ReplaceWindow");
  215. if ($object->target == 1) print $langs->trans("OpenANewWindow");
  216. }
  217. print '</td></tr>';
  218. print '<tr><td>'.$langs->trans("Owner").'</td><td>';
  219. if ($action == 'edit' && $user->admin)
  220. {
  221. print $form->select_dolusers(isset($_POST['userid'])?$_POST['userid']:($object->fk_user?$object->fk_user:''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  222. }
  223. else
  224. {
  225. if ($object->fk_user)
  226. {
  227. $fuser=new User($db);
  228. $fuser->fetch($object->fk_user);
  229. print $fuser->getNomUrl(1);
  230. }
  231. else
  232. {
  233. print $langs->trans("Public");
  234. }
  235. }
  236. print '</td></tr>';
  237. // Position
  238. print '<tr><td>'.$langs->trans("Position").'</td><td>';
  239. if ($action == 'edit') print '<input class="flat" name="position" size="5" value="'.(isset($_POST["position"])?$_POST["position"]:$object->position).'">';
  240. else print $object->position;
  241. print '</td></tr>';
  242. // Date creation
  243. print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec,'dayhour').'</td></tr>';
  244. print '</table>';
  245. print '</div>';
  246. dol_fiche_end();
  247. if ($action == 'edit')
  248. {
  249. 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>';
  250. print '</form>';
  251. }
  252. // Buttons
  253. print "<div class=\"tabsAction\">\n";
  254. // Edit
  255. if ($user->rights->bookmark->creer && $action != 'edit')
  256. {
  257. print " <a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?id=".$object->id."&amp;action=edit\">".$langs->trans("Edit")."</a>\n";
  258. }
  259. // Remove
  260. if ($user->rights->bookmark->supprimer && $action != 'edit')
  261. {
  262. print " <a class=\"butActionDelete\" href=\"list.php?bid=".$object->id."&amp;action=delete\">".$langs->trans("Delete")."</a>\n";
  263. }
  264. print '</div>';
  265. }
  266. // End of page
  267. llxFooter();
  268. $db->close();