check.php 25 KB

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