dolibarr  13.0.2
modWebsite.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 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 
25 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
26 
27 
32 {
33 
39  public 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 = 'website';
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 (html and javascript 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] = 'Create/modify website content (dynamic php code). Dangerous, must be reserved to restricted developers.';
102  $this->rights[$r][3] = 0;
103  $this->rights[$r][4] = 'writephp';
104  $r++;
105 
106  $this->rights[$r][0] = 10005;
107  $this->rights[$r][1] = 'Delete website content';
108  $this->rights[$r][3] = 0;
109  $this->rights[$r][4] = 'delete';
110  $r++;
111 
112  // Main menu entries
113  $r = 0;
114  $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
115  'type'=>'top', // This is a Left menu entry
116  'titre'=>'WebSites',
117  'mainmenu'=>'website',
118  'url'=>'/website/index.php',
119  'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
120  'position'=>100,
121  '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.
122  'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
123  'target'=>'',
124  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
125  $r++;
126 
127  // Exports
128  $r = 1;
129 
130  $this->export_code[$r] = $this->rights_class.'_'.$r;
131  $this->export_label[$r] = 'MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found)
132  $this->export_icon[$r] = 'globe';
133  $keyforclass = 'WebsitePage'; $keyforclassfile = '/website/class/websitepage.class.php'; $keyforelement = 'Website';
134  include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
135  //$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra';
136  //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
137  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
138  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p';
139  $this->export_sql_end[$r] .= ' WHERE t.fk_website = p.rowid';
140  $this->export_sql_end[$r] .= ' AND p.entity IN ('.getEntity('website').')';
141  $r++;
142  }
143 
144 
153  public function init($options = '')
154  {
155  global $conf, $langs;
156 
157  // Remove permissions and default values
158  $this->remove($options);
159 
160  // Copy flags and octicons directory
161  $dirarray = array('common/flags'=>'flags', 'common/octicons/build/svg'=>'octicons');
162  foreach ($dirarray as $dirfrom => $dirtarget)
163  {
164  $src = DOL_DOCUMENT_ROOT.'/theme/'.$dirfrom;
165  $dest = DOL_DATA_ROOT.'/medias/image/'.$dirtarget;
166 
167  if (is_dir($src))
168  {
169  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
170  dol_mkdir($dest);
171  $result = dolCopyDir($src, $dest, 0, 0);
172  if ($result < 0)
173  {
174  $langs->load("errors");
175  $this->error = $langs->trans('ErrorFailToCopyDir', $src, $dest);
176  return 0;
177  }
178  }
179  }
180 
181  // Website templates
182  $srcroot = DOL_DOCUMENT_ROOT.'/install/doctemplates/websites';
183  $destroot = DOL_DATA_ROOT.'/doctemplates/websites';
184 
185  dol_mkdir($destroot);
186 
187  $docs = dol_dir_list($srcroot, 'files', 0, 'website_.*(\.zip|\.jpg)$');
188  foreach ($docs as $cursorfile) {
189  $src = $srcroot.'/'.$cursorfile['name'];
190  $dest = $destroot.'/'.$cursorfile['name'];
191 
192  $result = dol_copy($src, $dest, 0, 1); // For full zip templates, we overwrite old existing files
193  if ($result < 0) {
194  $langs->load("errors");
195  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
196  }
197  }
198 
199  $sql = array();
200 
201  return $this->_init($sql, $options);
202  }
203 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0)
Copy a dir to another dir.
Definition: files.lib.php:720
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
Class to describe Websites module.
_init($array_sql, $options= '')
Enables a module.
init($options= '')
Function called when module is enabled.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
__construct($db)
Constructor.