index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/collab/index.php
  19. * \ingroup collab
  20. * \brief Page to work on a shared document (PAD)
  21. */
  22. define('NOSCANPOSTFORINJECTION', 1);
  23. define('NOSTYLECHECK', 1);
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("admin", "other", "website"));
  30. if (!$user->admin) {
  31. accessforbidden();
  32. }
  33. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
  34. $error = 0;
  35. $website = GETPOST('website', 'alpha');
  36. $page = GETPOST('page', 'alpha');
  37. $pageid = GETPOST('pageid', 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. if (GETPOST('delete')) {
  40. $action = 'delete';
  41. }
  42. if (GETPOST('preview')) {
  43. $action = 'preview';
  44. }
  45. if (GETPOST('create')) {
  46. $action = 'create';
  47. }
  48. if (GETPOST('editmedia')) {
  49. $action = 'editmedia';
  50. }
  51. if (GETPOST('editcss')) {
  52. $action = 'editcss';
  53. }
  54. if (GETPOST('editmenu')) {
  55. $action = 'editmenu';
  56. }
  57. if (GETPOST('setashome')) {
  58. $action = 'setashome';
  59. }
  60. if (GETPOST('editmeta')) {
  61. $action = 'editmeta';
  62. }
  63. if (GETPOST('editcontent')) {
  64. $action = 'editcontent';
  65. }
  66. if (empty($action)) {
  67. $action = 'preview';
  68. }
  69. /*
  70. * Actions
  71. */
  72. if (GETPOST('refreshsite')) {
  73. $pageid = 0; // If we change the site, we reset the pageid.
  74. }
  75. if (GETPOST('refreshpage')) {
  76. $action = 'preview';
  77. }
  78. // Add a collab page
  79. if ($action == 'add') {
  80. $db->begin();
  81. $objectpage->title = GETPOST('WEBSITE_TITLE');
  82. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
  83. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
  84. $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
  85. if (empty($objectpage->title)) {
  86. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  87. $error++;
  88. }
  89. if (!$error) {
  90. $res = $objectpage->create($user);
  91. if ($res <= 0) {
  92. $error++;
  93. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  94. }
  95. }
  96. if (!$error) {
  97. $db->commit();
  98. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  99. $action = '';
  100. } else {
  101. $db->rollback();
  102. }
  103. $action = 'preview';
  104. $id = $objectpage->id;
  105. }
  106. // Update page
  107. if ($action == 'delete') {
  108. $db->begin();
  109. $res = $object->fetch(0, $website);
  110. $res = $objectpage->fetch($pageid, $object->fk_website);
  111. if ($res > 0) {
  112. $res = $objectpage->delete($user);
  113. if (!($res > 0)) {
  114. $error++;
  115. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  116. }
  117. if (!$error) {
  118. $db->commit();
  119. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
  120. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
  121. exit;
  122. } else {
  123. $db->rollback();
  124. }
  125. } else {
  126. dol_print_error($db);
  127. }
  128. }
  129. /*
  130. * View
  131. */
  132. $form = new Form($db);
  133. $help_url = '';
  134. llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
  135. print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
  136. print '<input type="hidden" name="token" value="'.newToken().'">';
  137. if ($action == 'create') {
  138. print '<input type="hidden" name="action" value="add">';
  139. }
  140. // Add a margin under toolbar ?
  141. $style = '';
  142. if ($action != 'preview' && $action != 'editcontent') {
  143. $style = ' margin-bottom: 5px;';
  144. }
  145. //var_dump($objectpage);exit;
  146. print '<div class="centpercent websitebar">';
  147. print "</div>\n</form>\n";
  148. // End of page
  149. llxFooter();
  150. $db->close();