dolibarr 24.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 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.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
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1'); // Disables token renewal
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREAJAX')) {
33 define('NOREQUIREAJAX', '1');
34}
35if (!defined('NOREQUIRESOC')) {
36 define('NOREQUIRESOC', '1');
37}
38
39// Load Dolibarr environment
40require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
42require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
44
53$action = GETPOST('action', 'alpha');
54$website_ref = GETPOST('website_ref');
55$page_id = GETPOST('page_id');
56$content = GETPOST('content', 'restricthtml');
57$element_id = GETPOST('element_id');
58$element_type = GETPOST('element_type');
59
60$usercanmodify = $user->hasRight('website', 'write');
61if (!$usercanmodify) {
62 print "You don't have permission for this action.";
63 exit;
64}
65
66
67/*
68 * View
69 */
70
72
73if (!empty($action) && $action === 'updatedElementContent' && $usercanmodify && !empty($content) && !empty($element_id) && !empty($website_ref) && !empty($page_id)) {
74 // Page object
75 $objectpage = new WebsitePage($db);
76 $res = $objectpage->fetch((int) $page_id);
77 if (!$res) {
78 print "Cannot find page with ID = " . $page_id . ".";
79 exit;
80 }
81
82 // Website object
83 $objectwebsite = new Website($db);
84 $res = $objectwebsite->fetch($objectpage->fk_website);
85 if (!$res) {
86 print "Cannot find website with REF " . $objectpage->fk_website . ".";
87 exit;
88 }
89
90 $db->begin();
91 $error = 0;
92
93 // Replace element content into database and tpl file
94 $objectpage->content = preg_replace('/<' . $element_type . '[^>]*id="' . $element_id . '"[^>]*>\K(.*?)(?=<\/' . $element_type . '>)/s', $content, $objectpage->content, 1);
95 $res = $objectpage->update($user);
96 if ($res) {
97 global $dolibarr_main_data_root;
98 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website_ref;
99 $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
100
101 $result = dolSavePageContent($filetpl, $objectwebsite, $objectpage, 1);
102 if (!$result) {
103 print "Failed to write file " . $filetpl . ".";
104 $error++;
105 }
106 } else {
107 print "Failed to save changes error " . $objectpage->error . ".";
108 $error++;
109 }
110
111 if (!$error) {
112 $db->commit();
113 print "Changes are saved for " . $element_type . " with id " . $element_id;
114 } else {
115 $db->rollback();
116 }
117
118 $db->close();
119}
Class Website.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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).