|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2015 Laurent Destailleur <[email protected]> |
|
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 <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* \defgroup website Module website |
|
20
|
|
|
* \brief website module descriptor. |
|
21
|
|
|
* \file htdocs/core/modules/modWebsite.class.php |
|
22
|
|
|
* \ingroup websites |
|
23
|
|
|
* \brief Description and activation file for module Website |
|
24
|
|
|
*/ |
|
25
|
|
|
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class to describe Websites module |
|
30
|
|
|
*/ |
|
31
|
|
|
class modWebsite extends DolibarrModules |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Constructor. Define names, constants, directories, boxes, permissions |
|
36
|
|
|
* |
|
37
|
|
|
* @param DoliDB $db Database handler |
|
38
|
|
|
*/ |
|
39
|
|
|
function __construct($db) |
|
40
|
|
|
{ |
|
41
|
|
|
global $langs,$conf; |
|
42
|
|
|
|
|
43
|
|
|
$this->db = $db; |
|
44
|
|
|
$this->numero = 10000; |
|
45
|
|
|
|
|
46
|
|
|
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
|
47
|
|
|
// It is used to group modules in module setup page |
|
48
|
|
|
$this->family = "portal"; |
|
49
|
|
|
$this->module_position = 50; |
|
50
|
|
|
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
51
|
|
|
$this->name = preg_replace('/^mod/i','',get_class($this)); |
|
52
|
|
|
$this->description = "Enable to build and serve public web sites with CMS features"; |
|
53
|
|
|
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
54
|
|
|
$this->version = 'dolibarr'; |
|
55
|
|
|
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) |
|
56
|
|
|
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
57
|
|
|
// Name of image file used for this module. |
|
58
|
|
|
$this->picto='globe'; |
|
59
|
|
|
|
|
60
|
|
|
// Data directories to create when module is enabled |
|
61
|
|
|
$this->dirs = array("/website/temp"); |
|
62
|
|
|
|
|
63
|
|
|
// Config pages |
|
64
|
|
|
$this->config_page_url = array('website.php'); |
|
65
|
|
|
|
|
66
|
|
|
// Dependencies |
|
67
|
|
|
$this->hidden = ! empty($conf->global->MODULE_WEBSITE_DISABLED); // A condition to disable module |
|
68
|
|
|
$this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled |
|
69
|
|
|
$this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
70
|
|
|
$this->conflictwith = array(); // List of modules id this module is in conflict with |
|
71
|
|
|
$this->phpmin = array(5,4); // Minimum version of PHP required by module |
|
72
|
|
|
$this->langfiles = array("website"); |
|
73
|
|
|
|
|
74
|
|
|
// Constants |
|
75
|
|
|
$this->const = array(); |
|
76
|
|
|
|
|
77
|
|
|
// New pages on tabs |
|
78
|
|
|
//$this->tabs[] = array(); // To add a new tab identified by code tabname1 |
|
79
|
|
|
|
|
80
|
|
|
// Boxes |
|
81
|
|
|
$this->boxes = array(); |
|
82
|
|
|
|
|
83
|
|
|
// Permissions |
|
84
|
|
|
$this->rights = array(); // Permission array used by this module |
|
85
|
|
|
$this->rights_class = 'website'; |
|
86
|
|
|
$r=0; |
|
87
|
|
|
|
|
88
|
|
|
$this->rights[$r][0] = 10001; |
|
89
|
|
|
$this->rights[$r][1] = 'Read website content'; |
|
90
|
|
|
$this->rights[$r][3] = 0; |
|
91
|
|
|
$this->rights[$r][4] = 'read'; |
|
92
|
|
|
$r++; |
|
93
|
|
|
|
|
94
|
|
|
$this->rights[$r][0] = 10002; |
|
95
|
|
|
$this->rights[$r][1] = 'Create/modify website content'; |
|
96
|
|
|
$this->rights[$r][3] = 0; |
|
97
|
|
|
$this->rights[$r][4] = 'write'; |
|
98
|
|
|
$r++; |
|
99
|
|
|
|
|
100
|
|
|
$this->rights[$r][0] = 10003; |
|
101
|
|
|
$this->rights[$r][1] = 'Delete website content'; |
|
102
|
|
|
$this->rights[$r][3] = 0; |
|
103
|
|
|
$this->rights[$r][4] = 'delete'; |
|
104
|
|
|
$r++; |
|
105
|
|
|
|
|
106
|
|
|
// Main menu entries |
|
107
|
|
|
$r=0; |
|
108
|
|
|
$this->menu[$r]=array( 'fk_menu'=>'0', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
|
109
|
|
|
'type'=>'top', // This is a Left menu entry |
|
110
|
|
|
'titre'=>'Websites', |
|
111
|
|
|
'mainmenu'=>'website', |
|
112
|
|
|
'url'=>'/website/index.php', |
|
113
|
|
|
'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. |
|
114
|
|
|
'position'=>100, |
|
115
|
|
|
'enabled'=>'$conf->website->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. |
|
116
|
|
|
'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules |
|
117
|
|
|
'target'=>'', |
|
118
|
|
|
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both |
|
119
|
|
|
$r++; |
|
120
|
|
|
|
|
121
|
|
|
// Exports |
|
122
|
|
|
$r=1; |
|
123
|
|
|
|
|
124
|
|
|
$this->export_code[$r]=$this->rights_class.'_'.$r; |
|
125
|
|
|
$this->export_label[$r]='MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
126
|
|
|
$this->export_icon[$r]='globe'; |
|
127
|
|
|
$keyforclass = 'WebsitePage'; $keyforclassfile='/website/class/websitepage.class.php'; $keyforelement='Website'; |
|
128
|
|
|
include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; |
|
129
|
|
|
//$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra'; |
|
130
|
|
|
//include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
131
|
|
|
//$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) |
|
132
|
|
|
$this->export_sql_start[$r]='SELECT DISTINCT '; |
|
133
|
|
|
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p'; |
|
134
|
|
|
$this->export_sql_end[$r] .=' WHERE t.fk_website = p.rowid'; |
|
135
|
|
|
$this->export_sql_end[$r] .=' AND p.entity IN ('.getEntity('website').')'; |
|
136
|
|
|
$r++; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Function called when module is enabled. |
|
142
|
|
|
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
143
|
|
|
* It also creates data directories |
|
144
|
|
|
* |
|
145
|
|
|
* @param string $options Options when enabling module ('', 'noboxes') |
|
146
|
|
|
* @return int 1 if OK, 0 if KO |
|
147
|
|
|
*/ |
|
148
|
|
|
function init($options='') |
|
149
|
|
|
{ |
|
150
|
|
|
global $conf,$langs; |
|
151
|
|
|
|
|
152
|
|
|
// Remove permissions and default values |
|
153
|
|
|
$this->remove($options); |
|
154
|
|
|
|
|
155
|
|
|
// Copy flags and octicons directoru |
|
156
|
|
|
$dirarray=array('common/flags', 'common/octicons'); |
|
157
|
|
|
foreach($dirarray as $dir) |
|
158
|
|
|
{ |
|
159
|
|
|
$src=DOL_DOCUMENT_ROOT.'/theme/'.$dir; |
|
160
|
|
|
$dest=DOL_DATA_ROOT.'/medias/image/'.$dir; |
|
161
|
|
|
|
|
162
|
|
|
if (is_dir($src)) |
|
163
|
|
|
{ |
|
164
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
165
|
|
|
dol_mkdir($dest); |
|
166
|
|
|
$result=dolCopyDir($src,$dest,0,0); |
|
167
|
|
|
if ($result < 0) |
|
168
|
|
|
{ |
|
169
|
|
|
$langs->load("errors"); |
|
170
|
|
|
$this->error=$langs->trans('ErrorFailToCopyDirectory',$src,$dest); |
|
171
|
|
|
return 0; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
$sql = array(); |
|
177
|
|
|
|
|
178
|
|
|
return $this->_init($sql, $options); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|