index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("admin", "other", "website"));
  29. if (!$user->admin) {
  30. accessforbidden();
  31. }
  32. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
  33. $error = 0;
  34. $website = GETPOST('website', 'alpha');
  35. $page = GETPOST('page', 'alpha');
  36. $pageid = GETPOST('pageid', 'int');
  37. $action = GETPOST('action', 'aZ09');
  38. if (GETPOST('delete')) {
  39. $action = 'delete';
  40. }
  41. if (GETPOST('preview')) {
  42. $action = 'preview';
  43. }
  44. if (GETPOST('create')) {
  45. $action = 'create';
  46. }
  47. if (GETPOST('editmedia')) {
  48. $action = 'editmedia';
  49. }
  50. if (GETPOST('editcss')) {
  51. $action = 'editcss';
  52. }
  53. if (GETPOST('editmenu')) {
  54. $action = 'editmenu';
  55. }
  56. if (GETPOST('setashome')) {
  57. $action = 'setashome';
  58. }
  59. if (GETPOST('editmeta')) {
  60. $action = 'editmeta';
  61. }
  62. if (GETPOST('editcontent')) {
  63. $action = 'editcontent';
  64. }
  65. if (empty($action)) {
  66. $action = 'preview';
  67. }
  68. /*
  69. * Actions
  70. */
  71. if (GETPOST('refreshsite')) {
  72. $pageid = 0; // If we change the site, we reset the pageid.
  73. }
  74. if (GETPOST('refreshpage')) {
  75. $action = 'preview';
  76. }
  77. // Add a collab page
  78. if ($action == 'add') {
  79. $db->begin();
  80. $objectpage->title = GETPOST('WEBSITE_TITLE');
  81. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
  82. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
  83. $objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
  84. if (empty($objectpage->title)) {
  85. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  86. $error++;
  87. }
  88. if (!$error) {
  89. $res = $objectpage->create($user);
  90. if ($res <= 0) {
  91. $error++;
  92. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  93. }
  94. }
  95. if (!$error) {
  96. $db->commit();
  97. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  98. $action = '';
  99. } else {
  100. $db->rollback();
  101. }
  102. $action = 'preview';
  103. $id = $objectpage->id;
  104. }
  105. // Update page
  106. if ($action == 'delete') {
  107. $db->begin();
  108. $res = $object->fetch(0, $website);
  109. $res = $objectpage->fetch($pageid, $object->fk_website);
  110. if ($res > 0) {
  111. $res = $objectpage->delete($user);
  112. if (!($res > 0)) {
  113. $error++;
  114. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  115. }
  116. if (!$error) {
  117. $db->commit();
  118. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
  119. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
  120. exit;
  121. } else {
  122. $db->rollback();
  123. }
  124. } else {
  125. dol_print_error($db);
  126. }
  127. }
  128. /*
  129. * View
  130. */
  131. $form = new Form($db);
  132. $help_url = '';
  133. llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, '', '', '', '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
  134. print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
  135. print '<input type="hidden" name="token" value="'.newToken().'">';
  136. if ($action == 'create') {
  137. print '<input type="hidden" name="action" value="add">';
  138. }
  139. // Add a margin under toolbar ?
  140. $style = '';
  141. if ($action != 'preview' && $action != 'editcontent') {
  142. $style = ' margin-bottom: 5px;';
  143. }
  144. //var_dump($objectpage);exit;
  145. print '<div class="centpercent websitebar">';
  146. print "</div>\n</form>\n";
  147. // End of page
  148. llxFooter();
  149. $db->close();