repair.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/install/repair.php
  22. * \brief Run repair script
  23. */
  24. include_once 'inc.php';
  25. if (file_exists($conffile)) include_once $conffile;
  26. require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
  27. include_once $dolibarr_main_document_root.'/core/lib/images.lib.php';
  28. require_once $dolibarr_main_document_root.'/core/class/extrafields.class.php';
  29. require_once 'lib/repair.lib.php';
  30. $grant_query='';
  31. $step = 2;
  32. $ok = 0;
  33. // Cette page peut etre longue. On augmente le delai autorise.
  34. // Ne fonctionne que si on est pas en safe_mode.
  35. $err=error_reporting();
  36. error_reporting(0);
  37. @set_time_limit(120);
  38. error_reporting($err);
  39. $setuplang=GETPOST("selectlang",'az09',3)?GETPOST("selectlang",'az09',3):'auto';
  40. $langs->setDefaultLang($setuplang);
  41. $langs->loadLangs(array("admin","install","other"));
  42. if ($dolibarr_main_db_type == "mysqli") $choix=1;
  43. if ($dolibarr_main_db_type == "pgsql") $choix=2;
  44. if ($dolibarr_main_db_type == "mssql") $choix=3;
  45. dolibarr_install_syslog("--- repair: entering upgrade.php page");
  46. if (! is_object($conf)) dolibarr_install_syslog("repair: conf file not initialized", LOG_ERR);
  47. /*
  48. * View
  49. */
  50. pHeader('',"upgrade2",GETPOST('action','aZ09'));
  51. // Action to launch the repair script
  52. $actiondone=1;
  53. print '<h3>'.$langs->trans("Repair").'</h3>';
  54. print 'Option standard (0 or \'confirmed\') is '.(GETPOST('standard','alpha')?GETPOST('standard','alpha'):'0').'<br>'."\n";
  55. print 'Option restore_thirdparties_logos (0 or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos','alpha')?GETPOST('restore_thirdparties_logos','alpha'):'0').'<br>'."\n";
  56. print 'Option clean_linked_elements (0 or \'confirmed\') is '.(GETPOST('clean_linked_elements','alpha')?GETPOST('clean_linked_elements','alpha'):'0').'<br>'."\n";
  57. print 'Option clean_menus (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_menus','alpha')?GETPOST('clean_menus','alpha'):'0').'<br>'."\n";
  58. print 'Option clean_orphelin_dir (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir','alpha')?GETPOST('clean_orphelin_dir','alpha'):'0').'<br>'."\n";
  59. print 'Option clean_product_stock_batch (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch','alpha')?GETPOST('clean_product_stock_batch','alpha'):'0').'<br>'."\n";
  60. print 'Option set_empty_time_spent_amount (0 or \'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount','alpha')?GETPOST('set_empty_time_spent_amount','alpha'):'0').'<br>'."\n";
  61. print 'Option rebuild_product_thumbs (0 or \'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs','alpha')?GETPOST('rebuild_product_thumbs','alpha'):'0').'<br>'."\n";
  62. print 'Option force_disable_of_modules_not_found (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_disable_of_modules_not_found','alpha')?GETPOST('force_disable_of_modules_not_found','alpha'):'0').'<br>'."\n";
  63. print 'Option clean_perm_table (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table','alpha')?GETPOST('clean_perm_table','alpha'):'0').'<br>'."\n";
  64. print 'Option force_utf8_on_tables, for mysql/mariadb only (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_utf8_on_tables','alpha')?GETPOST('force_utf8_on_tables','alpha'):'0').'<br>'."\n";
  65. print '<br>';
  66. print '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
  67. $error=0;
  68. // If password is encoded, we decode it
  69. if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass))
  70. {
  71. require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
  72. if (preg_match('/crypted:/i',$dolibarr_main_db_pass))
  73. {
  74. $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
  75. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
  76. $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
  77. }
  78. else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  79. }
  80. // $conf is already instancied inside inc.php
  81. $conf->db->type = $dolibarr_main_db_type;
  82. $conf->db->host = $dolibarr_main_db_host;
  83. $conf->db->port = $dolibarr_main_db_port;
  84. $conf->db->name = $dolibarr_main_db_name;
  85. $conf->db->user = $dolibarr_main_db_user;
  86. $conf->db->pass = $dolibarr_main_db_pass;
  87. // For encryption
  88. $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption)?$dolibarr_main_db_encryption:'';
  89. $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey)?$dolibarr_main_db_cryptkey:'';
  90. $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
  91. if ($db->connected)
  92. {
  93. print '<tr><td class="nowrap">';
  94. print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>";
  95. dolibarr_install_syslog("repair: " . $langs->transnoentities("ServerConnection") . ": " . $dolibarr_main_db_host . $langs->transnoentities("OK"));
  96. $ok = 1;
  97. }
  98. else
  99. {
  100. print "<tr><td>".$langs->trans("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)."</td><td align=\"right\">".$langs->transnoentities("Error")."</td></tr>";
  101. dolibarr_install_syslog("repair: " . $langs->transnoentities("ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
  102. $ok = 0;
  103. }
  104. if ($ok)
  105. {
  106. if($db->database_selected)
  107. {
  108. print '<tr><td class="nowrap">';
  109. print $langs->trans("DatabaseConnection")." : ".$dolibarr_main_db_name."</td><td align=\"right\">".$langs->trans("OK")."</td></tr>";
  110. dolibarr_install_syslog("repair: database connection successful: " . $dolibarr_main_db_name);
  111. $ok=1;
  112. }
  113. else
  114. {
  115. print "<tr><td>".$langs->trans("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)."</td><td align=\"right\">".$langs->trans("Error")."</td></tr>";
  116. dolibarr_install_syslog("repair: " . $langs->transnoentities("ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
  117. $ok=0;
  118. }
  119. }
  120. // Show database version
  121. if ($ok)
  122. {
  123. $version=$db->getVersion();
  124. $versionarray=$db->getVersionArray();
  125. print '<tr><td>'.$langs->trans("ServerVersion").'</td>';
  126. print '<td align="right">'.$version.'</td></tr>';
  127. dolibarr_install_syslog("repair: " . $langs->transnoentities("ServerVersion") . ": " . $version);
  128. //print '<td align="right">'.join('.',$versionarray).'</td></tr>';
  129. }
  130. $conf->setValues($db);
  131. // Reset forced setup after the setValues
  132. if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE=constant('SYSLOG_FILE');
  133. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  134. /* Start action here */
  135. $oneoptionset=0;
  136. $oneoptionset=(GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_logos','alpha') || GETPOST('clean_linked_elements','alpha') || GETPOST('clean_menus','alpha')
  137. || GETPOST('clean_orphelin_dir','alpha') || GETPOST('clean_product_stock_batch','alpha') || GETPOST('set_empty_time_spent_amount','alpha') || GETPOST('rebuild_product_thumbs','alpha')
  138. || GETPOST('clean_perm_table','alpha')
  139. || GETPOST('force_disable_of_modules_not_found','alpha') || GETPOST('force_utf8_on_tables','alpha'));
  140. if ($ok && $oneoptionset)
  141. {
  142. // Show wait message
  143. print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'<br><br></td></tr>';
  144. flush();
  145. }
  146. // run_sql: Run repair SQL file
  147. if ($ok && GETPOST('standard', 'alpha'))
  148. {
  149. $dir = "mysql/migration/";
  150. $filelist=array();
  151. $i = 0;
  152. $ok = 0;
  153. // Recupere list fichier
  154. $filesindir=array();
  155. $handle=opendir($dir);
  156. if (is_resource($handle))
  157. {
  158. while (($file = readdir($handle))!==false)
  159. {
  160. if (preg_match('/\.sql$/i',$file)) $filesindir[]=$file;
  161. }
  162. }
  163. sort($filesindir);
  164. foreach($filesindir as $file)
  165. {
  166. if (preg_match('/repair/i',$file))
  167. {
  168. $filelist[]=$file;
  169. }
  170. }
  171. // Loop on each file
  172. foreach($filelist as $file)
  173. {
  174. print '<tr><td class="nowrap">*** ';
  175. print $langs->trans("Script").'</td><td align="right">'.$file.'</td></tr>';
  176. $name = substr($file, 0, dol_strlen($file) - 4);
  177. // Run sql script
  178. $ok=run_sql($dir.$file, 0, '', 1);
  179. }
  180. }
  181. // sync_extrafields: Search list of fields declared and list of fields created into databases, then create fields missing
  182. if ($ok && GETPOST('standard', 'alpha'))
  183. {
  184. $extrafields=new ExtraFields($db);
  185. $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product',
  186. 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture',
  187. 'supplier_proposal'=>'supplier_proposal', 'commande_fournisseur'=>'commande_fournisseur', 'facture_fourn'=>'facture_fourn',
  188. 'actioncomm'=>'actioncomm',
  189. 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task');
  190. print '<tr><td colspan="2"><br>*** Check fields into extra table structure match table of definition. If not add column into table</td></tr>';
  191. foreach($listofmodulesextra as $tablename => $elementtype)
  192. {
  193. // Get list of fields
  194. $tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields';
  195. // Define $arrayoffieldsdesc
  196. $arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype);
  197. // Define $arrayoffieldsfound
  198. $arrayoffieldsfound=array();
  199. $resql=$db->DDLDescTable($tableextra);
  200. if ($resql)
  201. {
  202. print '<tr><td>Check availability of extra field for '.$tableextra."<br>\n";
  203. $i=0;
  204. while($obj=$db->fetch_object($resql))
  205. {
  206. $fieldname=$fieldtype='';
  207. if (preg_match('/mysql/',$db->type))
  208. {
  209. $fieldname=$obj->Field;
  210. $fieldtype=$obj->Type;
  211. }
  212. else
  213. {
  214. $fieldname = isset($obj->Key)?$obj->Key:$obj->attname;
  215. $fieldtype = isset($obj->Type)?$obj->Type:'varchar';
  216. }
  217. if (empty($fieldname)) continue;
  218. if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue;
  219. $arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype);
  220. }
  221. // If it does not match, we create fields
  222. foreach($arrayoffieldsdesc as $code => $label)
  223. {
  224. if (! in_array($code,array_keys($arrayoffieldsfound)))
  225. {
  226. print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> ";
  227. $type=$extrafields->attributes[$elementtype]['type'][$code]; $length=$extrafields->attributes[$elementtype]['size'][$code]; $attribute=''; $default=''; $extra=''; $null='null';
  228. if ($type=='boolean') {
  229. $typedb='int';
  230. $lengthdb='1';
  231. } elseif($type=='price') {
  232. $typedb='double';
  233. $lengthdb='24,8';
  234. } elseif($type=='phone') {
  235. $typedb='varchar';
  236. $lengthdb='20';
  237. }elseif($type=='mail') {
  238. $typedb='varchar';
  239. $lengthdb='128';
  240. } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){
  241. $typedb='text';
  242. $lengthdb='';
  243. } elseif ($type=='link') {
  244. $typedb='int';
  245. $lengthdb='11';
  246. } else {
  247. $typedb=$type;
  248. $lengthdb=$length;
  249. }
  250. $field_desc=array(
  251. 'type'=>$typedb,
  252. 'value'=>$lengthdb,
  253. 'attribute'=>$attribute,
  254. 'default'=>$default,
  255. 'extra'=>$extra,
  256. 'null'=>$null
  257. );
  258. //var_dump($field_desc);exit;
  259. $result=$db->DDLAddField($tableextra,$code,$field_desc,"");
  260. if ($result < 0)
  261. {
  262. print "KO ".$db->lasterror."<br>\n";
  263. }
  264. else
  265. {
  266. print "OK<br>\n";
  267. }
  268. }
  269. }
  270. print "</td><td>&nbsp;</td></tr>\n";
  271. }
  272. else
  273. {
  274. dol_print_error($db);
  275. }
  276. }
  277. }
  278. // clean_data_ecm_dir: Clean data into ecm_directories table
  279. if ($ok && GETPOST('standard', 'alpha'))
  280. {
  281. clean_data_ecm_directories();
  282. }
  283. /* From here, actions need a parameter */
  284. // restore_thirdparties_logos: Move logos to correct new directory.
  285. if ($ok && GETPOST('restore_thirdparties_logos'))
  286. {
  287. //$exts=array('gif','png','jpg');
  288. $ext='';
  289. print '<tr><td colspan="2"><br>*** Restore thirdparties logo<br>';
  290. //foreach($exts as $ext)
  291. //{
  292. $sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom";
  293. $resql=$db->query($sql);
  294. if ($resql)
  295. {
  296. $num=$db->num_rows($resql);
  297. $i=0;
  298. while($i < $num)
  299. {
  300. $obj=$db->fetch_object($resql);
  301. /*
  302. $name=preg_replace('/é/','',$obj->name);
  303. $name=preg_replace('/ /','_',$name);
  304. $name=preg_replace('/\'/','',$name);
  305. */
  306. $tmp=explode('.',$obj->logo);
  307. $name=$tmp[0];
  308. if (isset($tmp[1])) $ext='.'.$tmp[1];
  309. if (! empty($name))
  310. {
  311. $filetotest=$dolibarr_main_data_root.'/societe/logos/'.$name.$ext;
  312. $filetotestsmall=$dolibarr_main_data_root.'/societe/logos/thumbs/'.$name.$ext;
  313. $exists=dol_is_file($filetotest);
  314. print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."<br>\n";
  315. if ($exists)
  316. {
  317. $filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext;
  318. $filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext;
  319. $existt=dol_is_file($filetarget);
  320. if (! $existt)
  321. {
  322. dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos');
  323. print " &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotest." -> ".$filetarget."<br>\n";
  324. dol_copy($filetotest, $filetarget, '', 0);
  325. }
  326. $existtt=dol_is_file($filetargetsmall);
  327. if (! $existtt)
  328. {
  329. dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs');
  330. print " &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."<br>\n";
  331. dol_copy($filetotestsmall, $filetargetsmall, '', 0);
  332. }
  333. }
  334. }
  335. $i++;
  336. }
  337. }
  338. else
  339. {
  340. $ok=0;
  341. dol_print_error($db);
  342. }
  343. print '</td></tr>';
  344. //}
  345. }
  346. // rebuild_product_thumbs: Rebuild thumbs for product files
  347. if ($ok && GETPOST('rebuild_product_thumbs','alpha'))
  348. {
  349. $ext='';
  350. global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
  351. print '<tr><td colspan="2"><br>*** Rebuild product thumbs<br>';
  352. $sql="SELECT s.rowid, s.ref FROM ".MAIN_DB_PREFIX."product as s ORDER BY s.ref";
  353. $resql=$db->query($sql);
  354. if ($resql)
  355. {
  356. $num=$db->num_rows($resql);
  357. $i=0;
  358. while($i < $num)
  359. {
  360. $obj=$db->fetch_object($resql);
  361. if (! empty($obj->ref))
  362. {
  363. $files=dol_dir_list($dolibarr_main_data_root.'/produit/'.$obj->ref, 'files', 0);
  364. foreach($files as $file)
  365. {
  366. // Generate thumbs.
  367. if (image_format_supported($file['fullname']) == 1)
  368. {
  369. $imgThumbSmall='notbuild';
  370. if (GETPOST('rebuild_product_thumbs','alpha') == 'confirmed')
  371. {
  372. // Used on logon for example
  373. $imgThumbSmall = vignette($file['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
  374. }
  375. print 'Check product '.$obj->rowid.", file ".$file['fullname']." -> ".$imgThumbSmall." maxwidthsmall=".$maxwidthsmall." maxheightsmall=".$maxheightsmall."<br>\n";
  376. $imgThumbMini='notbuild';
  377. if (GETPOST('rebuild_product_thumbs','alpha') == 'confirmed')
  378. {
  379. // Create mini thumbs for image (Ratio is near 16/9)
  380. // Used on menu or for setup page for example
  381. $imgThumbMini = vignette($file['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
  382. }
  383. print 'Check product '.$obj->rowid.", file ".$file['fullname']." -> ".$imgThumbMini." maxwidthmini=".$maxwidthmini." maxheightmini=".$maxheightmini."<br>\n";
  384. }
  385. }
  386. }
  387. $i++;
  388. }
  389. }
  390. else
  391. {
  392. $ok=0;
  393. dol_print_error($db);
  394. }
  395. print '</td></tr>';
  396. }
  397. // clean_linked_elements: Check and clean linked elements
  398. if ($ok && GETPOST('clean_linked_elements','alpha'))
  399. {
  400. print '<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>';
  401. // propal => order
  402. print '<tr><td colspan="2">'.checkLinkedElements('propal', 'commande')."</td></tr>\n";
  403. // propal => invoice
  404. print '<tr><td colspan="2">'.checkLinkedElements('propal', 'facture')."</td></tr>\n";
  405. // order => invoice
  406. print '<tr><td colspan="2">'.checkLinkedElements('commande', 'facture')."</td></tr>\n";
  407. // order => shipping
  408. print '<tr><td colspan="2">'.checkLinkedElements('commande', 'shipping')."</td></tr>\n";
  409. // shipping => delivery
  410. print '<tr><td colspan="2">'.checkLinkedElements('shipping', 'delivery')."</td></tr>\n";
  411. // order_supplier => invoice_supplier
  412. print '<tr><td colspan="2">'.checkLinkedElements('order_supplier', 'invoice_supplier')."</td></tr>\n";
  413. }
  414. // clean_menus: Check orphelins menus
  415. if ($ok && GETPOST('clean_menus','alpha'))
  416. {
  417. print '<tr><td colspan="2"><br>*** Clean menu entries coming from disabled modules</td></tr>';
  418. $sql ="SELECT rowid, module";
  419. $sql.=" FROM ".MAIN_DB_PREFIX."menu as c";
  420. $sql.=" WHERE module IS NOT NULL AND module <> ''";
  421. $sql.=" ORDER BY module";
  422. $resql = $db->query($sql);
  423. if ($resql)
  424. {
  425. $num = $db->num_rows($resql);
  426. if ($num)
  427. {
  428. $i = 0;
  429. while ($i < $num)
  430. {
  431. $obj=$db->fetch_object($resql);
  432. $modulecond=$obj->module;
  433. $modulecondarray = explode('|',$obj->module); // Name of module
  434. print '<tr><td>';
  435. print $modulecond;
  436. $db->begin();
  437. if ($modulecond) // And menu entry for module $modulecond was found in database.
  438. {
  439. $moduleok=0;
  440. foreach($modulecondarray as $tmpname)
  441. {
  442. if ($tmpname == 'margins') $tmpname='margin'; // TODO Remove this when normalized
  443. $result = 0;
  444. if (! empty($conf->$tmpname)) $result = $conf->$tmpname->enabled;
  445. if ($result) $moduleok++;
  446. }
  447. if (! $moduleok && $modulecond)
  448. {
  449. print ' - Module condition '.$modulecond.' seems ko, we delete menu entry.';
  450. if (GETPOST('clean_menus') == 'confirmed')
  451. {
  452. $sql2 ="DELETE FROM ".MAIN_DB_PREFIX."menu WHERE module = '".$modulecond."'";
  453. $resql2=$db->query($sql2);
  454. if (! $resql2)
  455. {
  456. $error++;
  457. dol_print_error($db);
  458. }
  459. else
  460. print ' - <span class="warning">Cleaned</span>';
  461. }
  462. else
  463. {
  464. print ' - <span class="warning">Canceled (test mode)</span>';
  465. }
  466. }
  467. else
  468. {
  469. print ' - Module condition '.$modulecond.' is ok, we do nothing.';
  470. }
  471. }
  472. if (!$error) $db->commit();
  473. else $db->rollback();
  474. print'</td></tr>';
  475. if ($error) break;
  476. $i++;
  477. }
  478. }
  479. else
  480. {
  481. print '<tr><td>No menu entries of disabled menus found</td></tr>';
  482. }
  483. }
  484. else
  485. {
  486. dol_print_error($db);
  487. }
  488. }
  489. // clean_orphelin_dir: Run purge of directory
  490. if ($ok && GETPOST('clean_orphelin_dir','alpha'))
  491. {
  492. $listmodulepart=array('company','invoice','invoice_supplier','propal','order','order_supplier','contract','tax');
  493. foreach ($listmodulepart as $modulepart)
  494. {
  495. $filearray=array();
  496. $upload_dir = isset($conf->$modulepart->dir_output)?$conf->$modulepart->dir_output:'';
  497. if ($modulepart == 'company') $upload_dir = $conf->societe->dir_output; // TODO change for multicompany sharing
  498. if ($modulepart == 'invoice') $upload_dir = $conf->facture->dir_output;
  499. if ($modulepart == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output;
  500. if ($modulepart == 'order') $upload_dir = $conf->commande->dir_output;
  501. if ($modulepart == 'order_supplier') $upload_dir = $conf->fournisseur->commande->dir_output;
  502. if ($modulepart == 'contract') $upload_dir = $conf->contrat->dir_output;
  503. if (empty($upload_dir)) continue;
  504. print '<tr><td colspan="2"><br>*** Clean orphelins files into files '.$upload_dir.'</td></tr>';
  505. $filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','(\.meta|_preview.*\.png)$','^temp$','^payments$','^CVS$','^thumbs$'),'',SORT_DESC,1,true);
  506. // To show ref or specific information according to view to show (defined by $module)
  507. if ($modulepart == 'company')
  508. {
  509. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  510. $object_instance=new Societe($db);
  511. }
  512. if ($modulepart == 'invoice')
  513. {
  514. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  515. $object_instance=new Facture($db);
  516. }
  517. else if ($modulepart == 'invoice_supplier')
  518. {
  519. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  520. $object_instance=new FactureFournisseur($db);
  521. }
  522. else if ($modulepart == 'propal')
  523. {
  524. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  525. $object_instance=new Propal($db);
  526. }
  527. else if ($modulepart == 'order')
  528. {
  529. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  530. $object_instance=new Commande($db);
  531. }
  532. else if ($modulepart == 'order_supplier')
  533. {
  534. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  535. $object_instance=new CommandeFournisseur($db);
  536. }
  537. else if ($modulepart == 'contract')
  538. {
  539. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  540. $object_instance=new Contrat($db);
  541. }
  542. else if ($modulepart == 'tax')
  543. {
  544. include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  545. $object_instance=new ChargeSociales($db);
  546. }
  547. foreach($filearray as $key => $file)
  548. {
  549. if (!is_dir($file['name'])
  550. && $file['name'] != '.'
  551. && $file['name'] != '..'
  552. && $file['name'] != 'CVS'
  553. )
  554. {
  555. // Define relative path used to store the file
  556. $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
  557. //var_dump($file);
  558. $id=0; $ref=''; $object_instance->id=0; $object_instance->ref=''; $label='';
  559. // To show ref or specific information according to view to show (defined by $module)
  560. if ($modulepart == 'invoice') {
  561. preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
  562. }
  563. if ($modulepart == 'invoice_supplier') {
  564. preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=empty($reg[1])?'':$reg[1];
  565. }
  566. if ($modulepart == 'propal') {
  567. preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
  568. }
  569. if ($modulepart == 'order') {
  570. preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
  571. }
  572. if ($modulepart == 'order_supplier') {
  573. preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
  574. }
  575. if ($modulepart == 'contract') {
  576. preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
  577. }
  578. if ($modulepart == 'tax') {
  579. preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1];
  580. }
  581. if ($id || $ref)
  582. {
  583. //print 'Fetch '.$id.' or '.$ref.'<br>';
  584. $result=$object_instance->fetch($id,$ref);
  585. //print $result.'<br>';
  586. if ($result == 0) // Not found but no error
  587. {
  588. // Clean of orphelins directories are done into repair.php
  589. print '<tr><td colspan="2">';
  590. print 'Delete orphelins file '.$file['fullname'].'<br>';
  591. if (GETPOST('clean_orphelin_dir','alpha') == 'confirmed')
  592. {
  593. dol_delete_file($file['fullname'],1,1,1);
  594. dol_delete_dir(dirname($file['fullname']),1);
  595. }
  596. print "</td></tr>";
  597. }
  598. else if ($result < 0) print 'Error in '.get_class($object_instance).'.fetch of id'.$id.' ref='.$ref.', result='.$result.'<br>';
  599. }
  600. }
  601. }
  602. }
  603. }
  604. // clean_linked_elements: Check and clean linked elements
  605. if ($ok && GETPOST('clean_product_stock_batch','alpha'))
  606. {
  607. $methodtofix=GETPOST('methodtofix','alpha')?GETPOST('methodtofix','alpha'):'updatestock';
  608. print '<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>';
  609. $sql ="SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
  610. $sql.=" FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_stock as ps LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb ON ps.rowid = pb.fk_product_stock";
  611. $sql.=" WHERE p.rowid = ps.fk_product";
  612. $sql.=" AND p.tobatch = 1";
  613. $sql.=" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
  614. $sql.=" HAVING reel != SUM(pb.qty) or SUM(pb.qty) IS NULL";
  615. print $sql;
  616. $resql = $db->query($sql);
  617. if ($resql)
  618. {
  619. $num = $db->num_rows($resql);
  620. if ($num)
  621. {
  622. $i = 0;
  623. while ($i < $num)
  624. {
  625. $obj=$db->fetch_object($resql);
  626. print '<tr><td>Product '.$obj->rowid.'-'.$obj->ref.' in warehose '.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' (product_stock.reel) != '.($obj->reelbatch?$obj->reelbatch:'0').' (sum product_batch)';
  627. // Fix
  628. if ($obj->reel != $obj->reelbatch)
  629. {
  630. if ($methodtofix == 'updatebatch')
  631. {
  632. // Method 1
  633. print ' -> Insert qty '.($obj->reel - $obj->reelbatch).' with lot 000000 linked to fk_product_stock='.$obj->psrowid;
  634. if (GETPOST('clean_product_stock_batch') == 'confirmed')
  635. {
  636. $sql2 ="INSERT INTO ".MAIN_DB_PREFIX."product_batch(fk_product_stock, batch, qty)";
  637. $sql2.="VALUES(".$obj->psrowid.", '000000', ".($obj->reel - $obj->reelbatch).")";
  638. $resql2=$db->query($sql2);
  639. if (! $resql2)
  640. {
  641. // TODO If it fails, we must make update
  642. //$sql2 ="UPDATE ".MAIN_DB_PREFIX."product_batch";
  643. //$sql2.=" SET ".$obj->psrowid.", '000000', ".($obj->reel - $obj->reelbatch).")";
  644. //$sql2.=" WHERE fk_product_stock = ".$obj->psrowid"
  645. }
  646. }
  647. }
  648. if ($methodtofix == 'updatestock')
  649. {
  650. // Method 2
  651. print ' -> Update qty of product_stock with qty = '.($obj->reelbatch?$obj->reelbatch:'0').' for ps.rowid = '.$obj->psrowid;
  652. if (GETPOST('clean_product_stock_batch') == 'confirmed')
  653. {
  654. $error=0;
  655. $db->begin();
  656. $sql2 ="UPDATE ".MAIN_DB_PREFIX."product_stock";
  657. $sql2.=" SET reel = ".($obj->reelbatch?$obj->reelbatch:'0')." WHERE rowid = ".$obj->psrowid;
  658. $resql2=$db->query($sql2);
  659. if ($resql2)
  660. {
  661. // We update product_stock, so we must field stock into product too.
  662. $sql3='UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid)';
  663. $resql3=$db->query($sql3);
  664. if (! $resql3)
  665. {
  666. $error++;
  667. dol_print_error($db);
  668. }
  669. }
  670. else
  671. {
  672. $error++;
  673. dol_print_error($db);
  674. }
  675. if (!$error) $db->commit();
  676. else $db->rollback();
  677. }
  678. }
  679. }
  680. print'</td></tr>';
  681. $i++;
  682. }
  683. }
  684. else
  685. {
  686. print '<tr><td colspan="2">Nothing to do</td></tr>';
  687. }
  688. }
  689. else
  690. {
  691. dol_print_error($db);
  692. }
  693. }
  694. // clean_product_stock_negative_if_batch
  695. if ($ok && GETPOST('clean_product_stock_negative_if_batch','alpha'))
  696. {
  697. print '<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.' (possible values: updatestock or updatebatch)</td></tr>';
  698. $sql ="SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
  699. $sql.=" FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product_batch as pb";
  700. $sql.=" WHERE p.rowid = ps.fk_product AND ps.rowid = pb.fk_product_stock";
  701. $sql.=" AND p.tobatch = 1";
  702. $sql.=" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
  703. $sql.=" HAVING reel != SUM(pb.qty)";
  704. $resql = $db->query($sql);
  705. if ($resql)
  706. {
  707. $num = $db->num_rows($resql);
  708. if ($num)
  709. {
  710. $i = 0;
  711. while ($i < $num)
  712. {
  713. $obj=$db->fetch_object($resql);
  714. print '<tr><td>'.$obj->rowid.'-'.$obj->ref.'-'.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' != '.$obj->reelbatch;
  715. // TODO
  716. }
  717. }
  718. }
  719. }
  720. // set_empty_time_spent_amount
  721. if ($ok && GETPOST('set_empty_time_spent_amount','alpha'))
  722. {
  723. print '<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>';
  724. $sql ="SELECT COUNT(ptt.rowid) as nb, u.rowid as user_id, u.login, u.thm as user_thm";
  725. $sql.=" FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."user as u";
  726. $sql.=" WHERE ptt.fk_user = u.rowid";
  727. $sql.=" AND ptt.thm IS NULL and u.thm > 0";
  728. $sql.=" GROUP BY u.rowid, u.login, u.thm";
  729. $resql = $db->query($sql);
  730. if ($resql)
  731. {
  732. $num = $db->num_rows($resql);
  733. if ($num)
  734. {
  735. $i = 0;
  736. while ($i < $num)
  737. {
  738. $obj=$db->fetch_object($resql);
  739. print '<tr><td>'.$obj->login.'-'.$obj->user_id.' ('.$obj->nb.' lines to fix) -> '.$obj->user_thm;
  740. $db->begin();
  741. if (GETPOST('set_empty_time_spent_amount') == 'confirmed')
  742. {
  743. $sql2 ="UPDATE ".MAIN_DB_PREFIX."projet_task_time";
  744. $sql2.=" SET thm = ".$obj->user_thm." WHERE thm IS NULL AND fk_user = ".$obj->user_id;
  745. $resql2=$db->query($sql2);
  746. if (! $resql2)
  747. {
  748. $error++;
  749. dol_print_error($db);
  750. }
  751. }
  752. if (!$error) $db->commit();
  753. else $db->rollback();
  754. print'</td></tr>';
  755. if ($error) break;
  756. $i++;
  757. }
  758. }
  759. else
  760. {
  761. print '<tr><td>No time spent with empty line on users with a hourly rate defined</td></tr>';
  762. }
  763. }
  764. else
  765. {
  766. dol_print_error($db);
  767. }
  768. }
  769. // force_disable_of_modules_not_found
  770. if ($ok && GETPOST('force_disable_of_modules_not_found','alpha'))
  771. {
  772. print '<tr><td colspan="2"><br>*** Force modules not found to be disabled (only modules adding js, css or hooks can be detected as removed)</td></tr>';
  773. $arraylistofkey=array('hooks','js','css');
  774. foreach($arraylistofkey as $key)
  775. {
  776. $sql ="SELECT DISTINCT name, value";
  777. $sql.=" FROM ".MAIN_DB_PREFIX."const as c";
  778. $sql.=" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key)."'";
  779. $sql.=" ORDER BY name";
  780. $resql = $db->query($sql);
  781. if ($resql)
  782. {
  783. $num = $db->num_rows($resql);
  784. if ($num)
  785. {
  786. $i = 0;
  787. while ($i < $num)
  788. {
  789. $obj=$db->fetch_object($resql);
  790. $constantname = $obj->name; // Name of constant for hook or js or css declaration
  791. print '<tr><td>';
  792. print $constantname;
  793. $db->begin();
  794. if (preg_match('/MAIN_MODULE_(.*)_'.strtoupper($key).'/i', $constantname, $reg))
  795. {
  796. $name=strtolower($reg[1]);
  797. if ($name) // And entry for key $key and module $name was found in database.
  798. {
  799. if ($key == 'hooks') $reloffile=$name.'/class/actions_'.$name.'.class.php';
  800. if ($key == 'js')
  801. {
  802. $value=$obj->value;
  803. $valuearray=json_decode($value);
  804. $reloffile=$valuearray[0];
  805. $reloffile=preg_replace('/^\//','',$valuearray[0]);
  806. }
  807. if ($key == 'css')
  808. {
  809. $value=$obj->value;
  810. $valuearray=json_decode($value);
  811. if ($value && count($valuearray)==0) $valuearray[0]=$value; // If value was not a json array but a string
  812. $reloffile=preg_replace('/^\//','',$valuearray[0]);
  813. }
  814. //var_dump($key.' - '.$value.' - '.$reloffile);
  815. try {
  816. $result = dol_buildpath($reloffile, 0, 2);
  817. }
  818. catch(Exception $e)
  819. {
  820. // No catch yet
  821. }
  822. if (! $result)
  823. {
  824. print ' - File of '.$key.' ('.$reloffile.') NOT found, we disable the module.';
  825. if (GETPOST('force_disable_of_modules_not_found') == 'confirmed')
  826. {
  827. $sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."_".strtoupper($key)."'";
  828. $resql2=$db->query($sql2);
  829. if (! $resql2)
  830. {
  831. $error++;
  832. dol_print_error($db);
  833. }
  834. $sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."'";
  835. $resql2=$db->query($sql2);
  836. if (! $resql2)
  837. {
  838. $error++;
  839. dol_print_error($db);
  840. }
  841. else
  842. print ' - <span class="warning">Cleaned</span>';
  843. }
  844. else
  845. {
  846. print ' - <span class="warning">Canceled (test mode)</span>';
  847. }
  848. }
  849. else
  850. {
  851. print ' - File of '.$key.' ('.$reloffile.') found, we do nothing.';
  852. }
  853. }
  854. if (!$error) $db->commit();
  855. else $db->rollback();
  856. }
  857. print'</td></tr>';
  858. if ($error) break;
  859. $i++;
  860. }
  861. }
  862. else
  863. {
  864. print '<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).'</td></tr>';
  865. }
  866. }
  867. else
  868. {
  869. dol_print_error($db);
  870. }
  871. }
  872. }
  873. // clean_old_module_entries: Clean data into const when files of module were removed without being
  874. if ($ok && GETPOST('clean_perm_table','alpha'))
  875. {
  876. print '<tr><td colspan="2"><br>*** Clean table user_rights from lines of external modules no more enabled</td></tr>';
  877. $listofmods='';
  878. foreach($conf->modules as $key => $val)
  879. {
  880. $listofmods.=($listofmods?',':'')."'".$val."'";
  881. }
  882. $sql = 'SELECT id, libelle, module from '.MAIN_DB_PREFIX.'rights_def WHERE module not in ('.$listofmods.') AND id > 100000';
  883. $resql = $db->query($sql);
  884. if ($resql)
  885. {
  886. $num = $db->num_rows($resql);
  887. if ($num)
  888. {
  889. $i = 0;
  890. while ($i < $num)
  891. {
  892. $obj=$db->fetch_object($resql);
  893. if ($obj->id > 0)
  894. {
  895. print '<tr><td>Found line with id '.$obj->id.', label "'.$obj->libelle.'" of module "'.$obj->module.'" to delete';
  896. if (GETPOST('clean_perm_table','alpha') == 'confirmed')
  897. {
  898. $sqldelete = 'DELETE FROM '.MAIN_DB_PREFIX.'rights_def WHERE id = '.$obj->id;
  899. $resqldelete = $db->query($sqldelete);
  900. if (! $resqldelete)
  901. {
  902. dol_print_error($db);
  903. }
  904. print ' - deleted';
  905. }
  906. print '</td></tr>';
  907. }
  908. $i++;
  909. }
  910. }
  911. else
  912. {
  913. print '<tr><td>No lines of a disabled external module (with id > 100000) found into table rights_def</td></tr>';
  914. }
  915. }
  916. else
  917. {
  918. dol_print_error($db);
  919. }
  920. }
  921. // force utf8 on tables
  922. if ($ok && GETPOST('force_utf8_on_tables','alpha'))
  923. {
  924. print '<tr><td colspan="2"><br>*** Force page code and collation of tables into utf8/utf8_unicode_ci (for mysql/mariadb only)</td></tr>';
  925. if ($db->type == "mysql" || $db->type == "mysqli")
  926. {
  927. $force_utf8_on_tables = GETPOST('force_utf8_on_tables','alpha');
  928. $listoftables = $db->DDLListTables($db->database_name);
  929. // Disable foreign key checking for avoid errors
  930. if ($force_utf8_on_tables == 'confirmed')
  931. {
  932. $sql='SET FOREIGN_KEY_CHECKS=0';
  933. print '<!-- '.$sql.' -->';
  934. $resql = $db->query($sql);
  935. }
  936. foreach($listoftables as $table)
  937. {
  938. // do not convert llx_const if mysql encrypt/decrypt is used
  939. if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match('/\_const$/', $table)) continue;
  940. print '<tr><td colspan="2">';
  941. print $table;
  942. $sql='ALTER TABLE '.$table.' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci';
  943. print '<!-- '.$sql.' -->';
  944. if ($force_utf8_on_tables == 'confirmed')
  945. {
  946. $resql = $db->query($sql);
  947. print ' - Done ('.($resql?'OK':'KO').')';
  948. }
  949. else print ' - Disabled';
  950. print '</td></tr>';
  951. }
  952. // Enable foreign key checking
  953. if ($force_utf8_on_tables == 'confirmed')
  954. {
  955. $sql='SET FOREIGN_KEY_CHECKS=1';
  956. print '<!-- '.$sql.' -->';
  957. $resql = $db->query($sql);
  958. }
  959. }
  960. else
  961. {
  962. print '<tr><td colspan="2">Not available with database type '.$db->type.'</td></tr>';
  963. }
  964. }
  965. print '</table>';
  966. if (empty($actiondone))
  967. {
  968. print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
  969. }
  970. if ($oneoptionset)
  971. {
  972. print '<div class="center" style="padding-top: 10px"><a href="../index.php?mainmenu=home&leftmenu=home'.(isset($_POST["login"])?'&username='.urlencode($_POST["login"]):'').'">';
  973. print $langs->trans("GoToDolibarr");
  974. print '</a></div>';
  975. }
  976. else
  977. {
  978. print '<div class="center warning" style="padding-top: 10px">';
  979. print $langs->trans("SetAtLeastOneOptionAsUrlParameter");
  980. print '</div>';
  981. }
  982. dolibarr_install_syslog("--- repair: end");
  983. pFooter(1,$setuplang);
  984. if ($db->connected) $db->close();
  985. // Return code if ran from command line
  986. if (! $ok && isset($argv[1])) exit(1);