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