dolibarr  19.0.0-dev
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 
30 define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
31 include_once 'inc.php';
32 
33 global $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";
48 if ($conffile == "/etc/dolibarr/conf.php") {
49  $forcedfile = "/etc/dolibarr/install.forced.php";
50 }
51 if (@file_exists($forcedfile)) {
52  $useforcedwizard = true;
53  include_once $forcedfile;
54 }
55 
56 dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
57 
58 
59 /*
60  * View
61  */
62 
63 pHeader('', ''); // 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 
69 print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
70 print '<span class="inline-block">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
71 
72 // Check browser
73 $useragent = $_SERVER['HTTP_USER_AGENT'];
74 if (!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(5, 6, 0);
86 $arrayphpminversionwarning = array(7, 1, 0);
87 if (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 = 0; // 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 }
96 if (empty($force_install_nophpinfo)) {
97  print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
98 }
99 print "<br>\n";
100 
101 // Check PHP version max
102 $arrayphpmaxversionwarning = array(8, 1, 0);
103 if (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
111 if (!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
122 if (!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
131 if (!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
140 if (!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)
149 if (!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 // Check if Curl is supported
158 if (!function_exists("curl_init")) {
159  $langs->load("errors");
160  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<br>\n";
161  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
162 } else {
163  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Curl")."<br>\n";
164 }
165 
166 // Check if PHP calendar extension is available
167 if (!function_exists("easter_date")) {
168  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
169 } else {
170  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
171 }
172 
173 // Check if Xml is supported
174 if (!function_exists("simplexml_load_string")) {
175  $langs->load("errors");
176  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
177  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
178 } else {
179  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
180 }
181 
182 // Check if UTF8 is supported
183 if (!function_exists("utf8_encode")) {
184  $langs->load("errors");
185  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
186  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
187 } else {
188  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
189 }
190 
191 // Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
192 if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
193  if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
194  $langs->load("errors");
195  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
196  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
197  } else {
198  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
199  }
200 }
201 
202 // Check if Imap is supported
203 if (!function_exists("imap_open")) {
204  $langs->load("errors");
205  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
206  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
207 } else {
208  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
209 }
210 
211 // Check if Zip is supported
212 if (!class_exists('ZipArchive')) {
213  $langs->load("errors");
214  print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
215  // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
216 } else {
217  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
218 }
219 
220 // Check memory
221 $memrequiredorig = '64M';
222 $memrequired = 64 * 1024 * 1024;
223 $memmaxorig = @ini_get("memory_limit");
224 $memmax = @ini_get("memory_limit");
225 if ($memmaxorig != '') {
226  preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
227  if ($reg[2]) {
228  if (strtoupper($reg[2]) == 'G') {
229  $memmax = $reg[1] * 1024 * 1024 * 1024;
230  }
231  if (strtoupper($reg[2]) == 'M') {
232  $memmax = $reg[1] * 1024 * 1024;
233  }
234  if (strtoupper($reg[2]) == 'K') {
235  $memmax = $reg[1] * 1024;
236  }
237  }
238  if ($memmax >= $memrequired || $memmax == -1) {
239  print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
240  } else {
241  print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
242  }
243 }
244 
245 
246 // If that config file is present and filled
247 clearstatcache();
248 if (is_readable($conffile) && filesize($conffile) > 8) {
249  dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
250  $confexists = 1;
251  include_once $conffile;
252 
253  $databaseok = 1;
254  if ($databaseok) {
255  // Already installed for all parts (config and database). We can propose upgrade.
256  $allowupgrade = true;
257  } else {
258  $allowupgrade = false;
259  }
260 } else {
261  // If not, we create it
262  dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
263  $confexists = 0;
264 
265  // First we try by copying example
266  if (@copy($conffile.".example", $conffile)) {
267  // Success
268  dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
269  } else {
270  // If failed, we try to create an empty file
271  dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
272 
273  $fp = @fopen($conffile, "w");
274  if ($fp) {
275  @fwrite($fp, '<?php');
276  @fputs($fp, "\n");
277  fclose($fp);
278  } else {
279  dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
280  }
281  }
282 
283  // First install: no upgrade necessary/required
284  $allowupgrade = false;
285 }
286 
287 
288 
289 // File is missing and cannot be created
290 if (!file_exists($conffile)) {
291  print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
292  print '<br><br><div class="error">';
293  print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
294  print '</div><br><br>'."\n";
295 
296  print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
297  $err++;
298 } else {
299  if (dol_is_dir($conffile)) {
300  print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
301 
302  $allowinstall = 0;
303  } elseif (!is_writable($conffile)) {
304  // File exists but cannot be modified
305  if ($confexists) {
306  print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
307  } else {
308  print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
309  }
310  print "<br>";
311  print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
312  print "<br>\n";
313 
314  $allowinstall = 0;
315  } else {
316  // File exists and can be modified
317  if ($confexists) {
318  print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
319  } else {
320  print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
321  }
322  print "<br>";
323  print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
324  print "<br>\n";
325 
326  $allowinstall = 1;
327  }
328  print "<br>\n";
329 
330  // Requirements met/all ok: display the next step button
331  if ($checksok) {
332  $ok = 0;
333 
334  // Try to create db connection
335  if (file_exists($conffile)) {
336  include_once $conffile;
337  if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
338  if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
339  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";
340  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);
341  } else {
342  require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
343 
344  // If password is encoded, we decode it
345  if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
346  require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
347  if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
348  $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
349  $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
350  } else {
351  $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
352  }
353  }
354 
355  // $conf already created in inc.php
356  $conf->db->type = $dolibarr_main_db_type;
357  $conf->db->host = $dolibarr_main_db_host;
358  $conf->db->port = $dolibarr_main_db_port;
359  $conf->db->name = $dolibarr_main_db_name;
360  $conf->db->user = $dolibarr_main_db_user;
361  $conf->db->pass = $dolibarr_main_db_pass;
362  $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
363  if ($db->connected && $db->database_selected) {
364  $ok = true;
365  }
366  }
367  }
368  }
369 
370  // If database access is available, we set more variables
371  if ($ok) {
372  if (empty($dolibarr_main_db_encryption)) {
373  $dolibarr_main_db_encryption = 0;
374  }
375  $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
376  if (empty($dolibarr_main_db_cryptkey)) {
377  $dolibarr_main_db_cryptkey = '';
378  }
379  $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
380 
381  $conf->setValues($db);
382  // Reset forced setup after the setValues
383  if (defined('SYSLOG_FILE')) {
384  $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
385  }
386  $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
387 
388  // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
389  // Version to install is DOL_VERSION
390  $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 : ''));
391  $dolibarrversiontoinstallarray = versiondolibarrarray();
392  }
393 
394  // Show title
395  if (!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || !empty($conf->global->MAIN_VERSION_LAST_INSTALL)) {
396  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> - ';
397  print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
398  //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
399  print '<br>';
400  print '<br>';
401  } else {
402  print "<br>\n";
403  }
404 
405  //print $langs->trans("InstallEasy")." ";
406  print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
407 
408  $foundrecommandedchoice = 0;
409 
410  $available_choices = array();
411  $notavailable_choices = array();
412 
413  if (empty($dolibarr_main_db_host)) { // This means install process was not run
414  $foundrecommandedchoice = 1; // To show only once
415  }
416 
417  // Show line of first install choice
418  $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
419  $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
420  $choice .= '</td>';
421  $choice .= '<td class="listofchoicesdesc">';
422  $choice .= $langs->trans("FreshInstallDesc");
423  if (empty($dolibarr_main_db_host)) { // This means install process was not run
424  $choice .= '<br>';
425  //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
426  $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
427  // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ';
428  }
429 
430  $choice .= '</td>';
431  $choice .= '<td class="center">';
432  if ($allowinstall) {
433  $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
434  } else {
435  $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
436  }
437  $choice .= '</td>'."\n";
438  $choice .= '</tr>'."\n";
439 
440  $positionkey = ($foundrecommandedchoice ? 999 : 0);
441  if ($allowinstall) {
442  $available_choices[$positionkey] = $choice;
443  } else {
444  $notavailable_choices[$positionkey] = $choice;
445  }
446 
447  // Show upgrade lines
448  $allowupgrade = true;
449  if (empty($dolibarr_main_db_host)) { // This means install process was not run
450  $allowupgrade = false;
451  }
452  if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
453  $allowupgrade = false;
454  }
455  if (GETPOST('allowupgrade')) {
456  $allowupgrade = true;
457  }
458 
459  $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
460  dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
461 
462  // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
463  $migrationscript = array();
464  $handle = opendir($dir);
465  if (is_resource($handle)) {
466  $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
467  while (($file = readdir($handle)) !== false) {
468  $reg = array();
469  if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
470  //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
471  if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
472  $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
473  }
474  }
475  }
476  $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
477  } else {
478  print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
479  }
480 
481  $count = 0;
482  foreach ($migrationscript as $migarray) {
483  $choice = '';
484 
485  $count++;
486  $recommended_choice = false;
487  $version = DOL_VERSION;
488  $versionfrom = $migarray['from'];
489  $versionto = $migarray['to'];
490  $versionarray = preg_split('/[\.-]/', $version);
491  $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
492  $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
493  // Define string newversionxxx that are used for text to show
494  $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
495  $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
496  $newversionfrombis = '';
497  if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
498  $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
499  }
500 
501  if ($ok) {
502  if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
503  // Now we check if this is the first qualified choice
504  if ($allowupgrade && empty($foundrecommandedchoice) &&
505  (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
506  ) {
507  $foundrecommandedchoice = 1; // To show only once
508  $recommended_choice = true;
509  }
510  } else {
511  // We cannot recommend a choice.
512  // A version of install may be known, but we need last upgrade.
513  }
514  }
515 
516  $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
517  $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
518  $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
519  $choice .= '<td class="listofchoicesdesc">';
520  $choice .= $langs->trans("UpgradeDesc");
521 
522  if ($recommended_choice) {
523  $choice .= '<br>';
524  //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
525  $choice .= '<div class="center">';
526  $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
527  if ($count < count($migarray)) { // There are other choices after
528  print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
529  }
530  $choice .= '</div>';
531  }
532 
533  $choice .= '</td>';
534  $choice .= '<td class="center">';
535  if ($allowupgrade) {
536  $disabled = false;
537  if ($foundrecommandedchoice == 2) {
538  $disabled = true;
539  }
540  if ($foundrecommandedchoice == 1) {
541  $foundrecommandedchoice = 2;
542  }
543  if ($disabled) {
544  $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
545  } else {
546  $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>';
547  }
548  } else {
549  $choice .= $langs->trans("NotAvailable");
550  }
551  $choice .= '</td>';
552  $choice .= '</tr>'."\n";
553 
554  if ($allowupgrade) {
555  $available_choices[$count] = $choice;
556  } else {
557  $notavailable_choices[$count] = $choice;
558  }
559  }
560 
561  // If there is no choice at all, we show all of them.
562  if (empty($available_choices)) {
563  $available_choices = $notavailable_choices;
564  $notavailable_choices = array();
565  }
566 
567  // Array of install choices
568  krsort($available_choices, SORT_NATURAL);
569  print"\n";
570  print '<table width="100%" class="listofchoices">';
571  foreach ($available_choices as $choice) {
572  print $choice;
573  }
574 
575  print '</table>'."\n";
576 
577  if (count($notavailable_choices)) {
578  print '<br><div id="AShowChoices" style="opacity: 0.5">';
579  print '> '.$langs->trans('ShowNotAvailableOptions').'...';
580  print '</div>';
581 
582  print '<div id="navail_choices" style="display:none">';
583  print "<br>\n";
584  print '<table width="100%" class="listofchoices">';
585  foreach ($notavailable_choices as $choice) {
586  print $choice;
587  }
588 
589  print '</table>'."\n";
590  print '</div>';
591  }
592  }
593 }
594 
595 print '<script type="text/javascript">
596 
597 $("div#AShowChoices").click(function() {
598 
599  $("div#navail_choices").toggle();
600 
601  if ($("div#navail_choices").css("display") == "none") {
602  $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
603  } else {
604  $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
605  }
606 
607 });
608 
609 /*
610 $(".runupgrade").click(function() {
611  return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
612 });
613 */
614 
615 </script>';
616 
617 dolibarr_install_syslog("- check: end");
618 pFooter(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.
Definition: admin.lib.php:140
versionphparray()
Return version PHP.
Definition: admin.lib.php:129
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.
Definition: files.lib.php:453
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.