dolibarr 21.0.0-beta
editinline.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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 3 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 <https://www.gnu.org/licenses/>.
17 */
18
25if (!defined('NOTOKENRENEWAL')) {
26 define('NOTOKENRENEWAL', '1'); // Disables token renewal
27}
28if (!defined('NOREQUIREMENU')) {
29 define('NOREQUIREMENU', '1');
30}
31if (!defined('NOREQUIREAJAX')) {
32 define('NOREQUIREAJAX', '1');
33}
34if (!defined('NOREQUIRESOC')) {
35 define('NOREQUIRESOC', '1');
36}
37
38// Load Dolibarr environment
39require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
41require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
43
52$action = GETPOST('action', 'alpha');
53$website_ref = GETPOST('website_ref');
54$page_id = GETPOST('page_id');
55$content = GETPOST('content', 'restricthtml');
56$element_id = GETPOST('element_id');
57$element_type = GETPOST('element_type');
58
59$usercanmodify = $user->hasRight('website', 'write');
60if (!$usercanmodify) {
61 print "You don't have permission for this action.";
62 exit;
63}
64
65
66/*
67 * View
68 */
69
71
72if (!empty($action) && $action === 'updatedElementContent' && $usercanmodify && !empty($content) && !empty($element_id) && !empty($website_ref) && !empty($page_id)) {
73 // Page object
74 $objectpage = new WebsitePage($db);
75 $res = $objectpage->fetch($page_id);
76 if (!$res) {
77 print "Cannot find page with ID = " . $page_id . ".";
78 exit;
79 }
80
81 // Website object
82 $objectwebsite = new Website($db);
83 $res = $objectwebsite->fetch($objectpage->fk_website);
84 if (!$res) {
85 print "Cannot find website with REF " . $objectpage->fk_website . ".";
86 exit;
87 }
88
89 $db->begin();
90 $error = 0;
91
92 // Replace element content into database and tpl file
93 $objectpage->content = preg_replace('/<' . $element_type . '[^>]*id="' . $element_id . '"[^>]*>\K(.*?)(?=<\/' . $element_type . '>)/s', $content, $objectpage->content, 1);
94 $res = $objectpage->update($user);
95 if ($res) {
96 global $dolibarr_main_data_root;
97 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website_ref;
98 $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
99
100 $result = dolSavePageContent($filetpl, $objectwebsite, $objectpage, 1);
101 if (!$result) {
102 print "Failed to write file " . $filetpl . ".";
103 $error++;
104 }
105 } else {
106 print "Failed to save changes error " . $objectpage->error . ".";
107 $error++;
108 }
109
110 if (!$error) {
111 $db->commit();
112 print "Changes are saved for " . $element_type . " with id " . $element_id;
113 } else {
114 $db->rollback();
115 }
116
117 $db->close();
118}
Class Website.
Class Websitepage.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).