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