dolibarr 22.0.5
check.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
33include_once 'inc.php';
34
49$err = 0;
50$allowinstall = 0;
51$allowupgrade = false;
52$checksok = 1;
53
54$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
55$langs->setDefaultLang($setuplang);
56
57$langs->load("install");
58
59// Now we load forced/pre-set values from install.forced.php file.
60$useforcedwizard = false;
61$forcedfile = "./install.forced.php";
62if ($conffile == "/etc/dolibarr/conf.php") {
63 $forcedfile = "/etc/dolibarr/install.forced.php";
64}
65if (@file_exists($forcedfile)) {
66 $useforcedwizard = true;
67 include_once $forcedfile;
68}
69
70dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
71
72
73/*
74 * View
75 */
76
77pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
78
79
80//print "<br>\n";
81//print $langs->trans("InstallEasy")."<br><br>\n";
82
83print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
84print '<span class="inline-block valignmiddle">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
85
86// Check browser
87$useragent = $_SERVER['HTTP_USER_AGENT'];
88if (!empty($useragent)) {
89 $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
90 $browserversion = $tmp['browserversion'];
91 $browsername = $tmp['browsername'];
92 if ($browsername == 'ie' && $browserversion < 7) {
93 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
94 }
95}
96
97
98// Check PHP version min
99$arrayphpminversionerror = array(7, 0, 0);
100$arrayphpminversionwarning = array(7, 1, 0);
101if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
102 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
103 $checksok = 0; // 0=error, 1=warning
104} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
105 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
106 $checksok = 1; // 0=error, 1=warning
107} else {
108 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
109}
110if (empty($force_install_nophpinfo)) {
111 print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
112}
113print "<br>\n";
114
115// Check PHP version max
116$arrayphpmaxversionwarning = array(8, 4, 0);
117if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
118 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
119 $checksok = 1; // 0=error, 1=warning
120 print "<br>\n";
121}
122
123
124// Check PHP support for $_GET and $_POST
125if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
126 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETKo");
127 print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
128 print "<br>\n";
129 $checksok = 0;
130} else {
131 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupportPOSTGETOk")."<br>\n";
132}
133
134
135// Check if session_id is enabled
136if (!function_exists("session_id")) {
137 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
138 $checksok = 0;
139} else {
140 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupportSessions")."<br>\n";
141}
142
143
144// Check for mbstring extension
145if (!extension_loaded("mbstring")) {
146 $langs->load("errors");
147 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "MBString")."<br>\n";
148 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
149} else {
150 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "MBString")."<br>\n";
151}
152
153// Check for json extension
154if (!extension_loaded("json")) {
155 $langs->load("errors");
156 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "JSON")."<br>\n";
157 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
158} else {
159 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "JSON")."<br>\n";
160}
161
162// Check if GD is supported (we need GD for image conversion)
163if (!function_exists("imagecreate")) {
164 $langs->load("errors");
165 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "GD")."<br>\n";
166 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
167} else {
168 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "GD")."<br>\n";
169}
170
171// Check if Curl is supported
172if (!function_exists("curl_init")) {
173 $langs->load("errors");
174 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<br>\n";
175 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
176} else {
177 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Curl")."<br>\n";
178}
179
180// Check if PHP calendar extension is available
181if (!function_exists("easter_date")) {
182 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
183} else {
184 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
185}
186
187// Check if Xml is supported
188if (!function_exists("simplexml_load_string")) {
189 $langs->load("errors");
190 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
191 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
192} else {
193 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
194}
195
196// Check if Dom is supported. Dolibarr uses DOMDocument to sanitize html, so a page can not even be rendered without it.
197if (!extension_loaded("dom")) {
198 $langs->load("errors");
199 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Dom")."<br>\n";
200 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
201} else {
202 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Dom")."<br>\n";
203}
204
205// Check if UTF8 is supported
206if (!function_exists("utf8_encode")) {
207 $langs->load("errors");
208 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
209 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
210} else {
211 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
212}
213
214// Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
215if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
216 if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
217 $langs->load("errors");
218 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
219 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
220 } else {
221 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
222 }
223}
224
225// Check if Imap is supported
226if (PHP_VERSION_ID <= 80300) {
227 if (!function_exists("imap_open")) {
228 $langs->load("errors");
229 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
230 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
231 } else {
232 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
233 }
234}
235
236// Check if Zip is supported
237if (!class_exists('ZipArchive')) {
238 $langs->load("errors");
239 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
240 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
241} else {
242 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
243}
244
245// Check memory
246$memrequiredorig = '64M';
247$memrequired = 64 * 1024 * 1024;
248$memmaxorig = @ini_get("memory_limit");
249$memmax = @ini_get("memory_limit");
250if ($memmaxorig != '') {
251 $reg = array();
252 preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
253 if ($reg[2]) {
254 if (strtoupper($reg[2]) == 'G') {
255 $memmax = (int) $reg[1] * 1024 * 1024 * 1024;
256 }
257 if (strtoupper($reg[2]) == 'M') {
258 $memmax = (int) $reg[1] * 1024 * 1024;
259 }
260 if (strtoupper($reg[2]) == 'K') {
261 $memmax = (int) $reg[1] * 1024;
262 }
263 }
264 if ($memmax >= $memrequired || $memmax == -1) {
265 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
266 } else {
267 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle paddingright"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
268 }
269}
270
271
272// If that config file is present and filled
273clearstatcache();
274if (is_readable($conffile) && filesize($conffile) > 8) {
275 dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
276 $confexists = 1;
277 include_once $conffile;
278
279 $databaseok = 1;
280 if ($databaseok) {
281 // Already installed for all parts (config and database). We can propose upgrade.
282 $allowupgrade = true;
283 } else {
284 $allowupgrade = false;
285 }
286} else {
287 // If not, we create it
288 dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
289 $confexists = 0;
290
291 // First we try by copying example
292 if (@copy($conffile.".example", $conffile)) {
293 // Success
294 dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
295 } else {
296 // If failed, we try to create an empty file
297 dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
298
299 $fp = @fopen($conffile, "w");
300 if ($fp) {
301 @fwrite($fp, '<?php');
302 @fwrite($fp, "\n");
303 fclose($fp);
304 } else {
305 dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
306 }
307 }
308
309 // First install: no upgrade necessary/required
310 $allowupgrade = false;
311}
312
313
314
315// File is missing and cannot be created
316if (!file_exists($conffile)) {
317 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
318 print '<br><br><div class="error">';
319 print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
320 print '</div><br><br>'."\n";
321
322 print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
323 $err++;
324} else {
325 if (dol_is_dir($conffile)) {
326 print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
327
328 $allowinstall = 0;
329 } elseif (!is_writable($conffile)) {
330 // File exists but cannot be modified
331 if ($confexists) {
332 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileExists", $conffiletoshow);
333 } else {
334 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
335 }
336 print "<br>";
337 print '<img src="../theme/eldy/img/tick.png" alt="Warning" class="valignmiddle paddingright"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
338 print "<br>\n";
339
340 $allowinstall = 0;
341 } else {
342 // File exists and can be modified
343 if ($confexists) {
344 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileExists", $conffiletoshow);
345 } else {
346 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
347 }
348 print "<br>";
349 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
350 print "<br>\n";
351
352 $allowinstall = 1;
353 }
354 print "<br>\n";
355
356 // Requirements met/all ok: display the next step button
357 if ($checksok) {
358 $ok = false;
359
360 // Try to create db connection
361 if (file_exists($conffile)) {
362 include_once $conffile;
363 if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
364 if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
365 print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n";
366 dol_syslog("A '".$conffiletoshow."' file exists with a dolibarr_main_document_root to ".$dolibarr_main_document_root." that seems wrong. Try to fix or remove the '".$conffiletoshow."' file.", LOG_WARNING);
367 } else {
368 require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
369
370 // If password is encoded, we decode it
371 if (preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
372 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
373 if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
374 $dolibarr_main_db_encrypted_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); // We need to set this as it is used to know the password was initially encrypted
375 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
376 } elseif (preg_match('/dolcrypt:/i', $dolibarr_main_db_pass)) {
377 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
378 $dolibarr_main_db_pass = dolDecrypt($dolibarr_main_db_pass);
379 } else {
380 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
381 }
382 }
383
384 // $conf already created in inc.php
385 $conf->db->type = $dolibarr_main_db_type;
386 $conf->db->host = $dolibarr_main_db_host;
387 $conf->db->port = $dolibarr_main_db_port;
388 $conf->db->name = $dolibarr_main_db_name;
389 $conf->db->user = $dolibarr_main_db_user;
390 $conf->db->pass = $dolibarr_main_db_pass;
391
392 $db = getDoliDBInstance($conf->db->type, $conf->db->host, (string) $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
393 if ($db->connected && $db->database_selected) {
394 $ok = true;
395 }
396 }
397 }
398 }
399
400 $dolibarrlastupgradeversionarray = array();
401 // If database access is available, we set more variables
402 if ($ok) {
403 if (empty($dolibarr_main_db_encryption)) {
404 $dolibarr_main_db_encryption = 0;
405 }
406 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
407 if (empty($dolibarr_main_db_cryptkey)) {
408 $dolibarr_main_db_cryptkey = '';
409 }
410 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
411
412 $conf->setValues($db);
413 // Reset forced setup after the setValues
414 if (defined('SYSLOG_FILE')) {
415 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
416 }
417 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
418
419 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
420 // Version to install is DOL_VERSION
421 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')));
422 $dolibarrversiontoinstallarray = versiondolibarrarray();
423 }
424
425 // Show title
426 if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) {
427 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')).'</span></b> - ';
428 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
429 //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
430 print '<br>';
431 print '<br>';
432 } else {
433 print "<br>\n";
434 }
435
436 //print $langs->trans("InstallEasy")." ";
437 print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
438
439 $foundrecommandedchoice = 0;
440
441 $available_choices = array();
442 $notavailable_choices = array();
443
444 if (empty($dolibarr_main_db_host)) { // This means install process was not run
445 $foundrecommandedchoice = 1; // To show only once
446 }
447
448 // Show line of first install choice
449 $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
450 $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
451 $choice .= '</td>';
452 $choice .= '<td class="listofchoicesdesc">';
453 $choice .= $langs->trans("FreshInstallDesc");
454 if (empty($dolibarr_main_db_host)) { // This means install process was not run
455 $choice .= '<br>';
456 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
457 $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
458 // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> ';
459 }
460
461 $choice .= '</td>';
462 $choice .= '<td class="center">';
463 if ($allowinstall) {
464 $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
465 } else {
466 $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
467 }
468 $choice .= '</td>'."\n";
469 $choice .= '</tr>'."\n";
470
471 $positionkey = ($foundrecommandedchoice ? 999 : 0);
472 if ($allowinstall) {
473 $available_choices[$positionkey] = $choice;
474 } else {
475 $notavailable_choices[$positionkey] = $choice;
476 }
477
478 // Show upgrade lines
479 $allowupgrade = true;
480 if (empty($dolibarr_main_db_host)) { // This means install process was not run
481 $allowupgrade = false;
482 }
483 if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
484 $allowupgrade = false;
485 }
486 if (GETPOST('allowupgrade')) {
487 $allowupgrade = true;
488 }
489
490 $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
491 dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
492
493 // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
494 $migrationscript = array();
495 $handle = opendir($dir);
496 if (is_resource($handle)) {
497 $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
498 while (($file = readdir($handle)) !== false) {
499 $reg = array();
500 if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
501 //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
502 if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
503 $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
504 }
505 }
506 }
507 $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
508 } else {
509 print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
510 }
511
512 $count = 0;
513 foreach ($migrationscript as $migarray) {
514 $choice = '';
515
516 $count++;
517 $recommended_choice = false;
518 $version = DOL_VERSION;
519 $versionfrom = $migarray['from'];
520 $versionto = $migarray['to'];
521 $versionarray = preg_split('/[\.-]/', $version);
522 $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
523 $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
524 // Define string newversionxxx that are used for text to show
525 $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
526 $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
527 $newversionfrombis = '';
528 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
529 $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
530 }
531
532 if ($ok) {
533 if (is_array($dolibarrlastupgradeversionarray) && count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
534 // Now we check if this is the first qualified choice
535 if ($allowupgrade && empty($foundrecommandedchoice) &&
536 (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
537 ) {
538 $foundrecommandedchoice = 1; // To show only once
539 $recommended_choice = true;
540 }
541 } else {
542 // We cannot recommend a choice.
543 // A version of install may be known, but we need last upgrade.
544 }
545 }
546
547 $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
548 $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
549 $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
550 $choice .= '<td class="listofchoicesdesc">';
551 $choice .= $langs->trans("UpgradeDesc");
552
553 if ($recommended_choice) {
554 $choice .= '<br>';
555 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
556 $choice .= '<div class="center">';
557 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
558 if ($count < count($migarray)) { // There are other choices after
559 print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
560 }
561 $choice .= '</div>';
562 }
563
564 $choice .= '</td>';
565 $choice .= '<td class="center">';
566 if ($allowupgrade) {
567 $disabled = false;
568 if ($foundrecommandedchoice == 2) {
569 $disabled = true;
570 }
571 if ($foundrecommandedchoice == 1) {
572 $foundrecommandedchoice = 2;
573 }
574 if ($disabled) {
575 $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
576 } else {
577 $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
578 }
579 } else {
580 $choice .= $langs->trans("NotAvailable");
581 }
582 $choice .= '</td>';
583 $choice .= '</tr>'."\n";
584
585 if ($allowupgrade) {
586 $available_choices[$count] = $choice;
587 } else {
588 $notavailable_choices[$count] = $choice;
589 }
590 }
591
592 // If there is no choice at all, we show all of them.
593 if (empty($available_choices)) {
594 $available_choices = $notavailable_choices;
595 $notavailable_choices = array();
596 }
597
598 // Array of install choices
599 krsort($available_choices, SORT_NATURAL);
600 print"\n";
601 print '<table width="100%" class="listofchoices">';
602 foreach ($available_choices as $choice) {
603 print $choice;
604 }
605
606 print '</table>'."\n";
607
608 if (count($notavailable_choices)) {
609 print '<br><div id="AShowChoices" style="opacity: 0.5">';
610 print '> '.$langs->trans('ShowNotAvailableOptions').'...';
611 print '</div>';
612
613 print '<div id="navail_choices" style="display:none">';
614 print "<br>\n";
615 print '<table width="100%" class="listofchoices">';
616 foreach ($notavailable_choices as $choice) {
617 print $choice;
618 }
619
620 print '</table>'."\n";
621 print '</div>';
622 }
623 }
624}
625
626print '<script type="text/javascript">
627
628$("div#AShowChoices").click(function() {
629
630 $("div#navail_choices").toggle();
631
632 if ($("div#navail_choices").css("display") == "none") {
633 $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
634 } else {
635 $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
636 }
637
638});
639
640/*
641$(".runupgrade").click(function() {
642 return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
643});
644*/
645
646</script>';
647
648dolibarr_install_syslog("- check: end");
649pFooter(1); // Never display next button
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition admin.lib.php:39
versiondolibarrarray()
Return version Dolibarr.
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:71
dol_is_dir($folder)
Test if filename is a directory.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getBrowserInfo($user_agent)
Return information about user browser.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:542
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:635
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:699
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.