* Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/admin/tools/update.php * \brief Page to make a Dolibarr online upgrade */ require '../../main.inc.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/geturl.lib.php'; $langs->load("admin"); $langs->load("other"); $action=GETPOST('action','alpha'); if (! $user->admin) accessforbidden(); if (GETPOST('msg','alpha')) { setEventMessage(GETPOST('msg','alpha'), 'errors'); } $urldolibarr='http://www.dolibarr.org/downloads/'; $urldolibarrmodules='http://www.dolistore.com/'; $urldolibarrthemes='http://www.dolistore.com/'; $dolibarrroot=preg_replace('/([\\/]+)$/i','',DOL_DOCUMENT_ROOT); $dolibarrroot=preg_replace('/([^\\/]+)$/i','',$dolibarrroot); $dolibarrdataroot=preg_replace('/([\\/]+)$/i','',DOL_DATA_ROOT); $dirins=DOL_DOCUMENT_ROOT.'/custom'; /* * Actions */ if ($action=='install') { $error=0; // $original_file should match format module_modulename-x.y[.z].zip $original_file=basename($_FILES["fileinstall"]["name"]); $newfile=$conf->admin->dir_temp.'/'.$original_file.'/'.$original_file; if (! $original_file) { $langs->load("Error"); setEventMessage($langs->trans("ErrorFileRequired"), 'warnings'); $error++; } else { if (! preg_match('/\.zip/i',$original_file)) { $langs->load("errors"); setEventMessage($langs->trans("ErrorFileMustBeADolibarrPackage",$original_file), 'errors'); $error++; } } if (! $error) { if ($original_file) { @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$original_file); dol_mkdir($conf->admin->dir_temp.'/'.$original_file); } $tmpdir=preg_replace('/\.zip$/','',$original_file).'.dir'; if ($tmpdir) { @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$tmpdir); dol_mkdir($conf->admin->dir_temp.'/'.$tmpdir); } $result=dol_move_uploaded_file($_FILES['fileinstall']['tmp_name'],$newfile,1,0,$_FILES['fileinstall']['error']); if ($result > 0) { $result=dol_uncompress($newfile,$conf->admin->dir_temp.'/'.$tmpdir); if (! empty($result['error'])) { $langs->load("errors"); setEventMessage($langs->trans($result['error'],$original_file), 'errors'); $error++; } else { // Now we move the dir of the module $modulename=preg_replace('/module_/', '', $original_file); $modulename=preg_replace('/\-[\d]+\.[\d]+.*$/', '', $modulename); // Search dir $modulename $modulenamedir=$conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulename; //var_dump($modulenamedir); if (! dol_is_dir($modulenamedir)) { $modulenamedir=$conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulename; //var_dump($modulenamedir); if (! dol_is_dir($modulenamedir)) { setEventMessage($langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat"), 'errors'); $error++; } } if (! $error) { //var_dump($dirins); @dol_delete_dir_recursive($dirins.'/'.$modulename); $result=dolCopyDir($modulenamedir, $dirins.'/'.$modulename, '0444', 1); if ($result <= 0) { setEventMessage($langs->trans("ErrorFailedToCopy"), 'errors'); $error++; } } } } else { $error++; } } if (! $error) { setEventMessage($langs->trans("SetupIsReadyForUse")); } } /* * View */ // Set dir where external modules are installed if (! dol_is_dir($dirins)) { dol_mkdir($dirins); } $dirins_ok=(dol_is_dir($dirins)); $wikihelp='EN:Installation_-_Upgrade|FR:Installation_-_Mise_à_jour|ES:Instalación_-_Actualización'; llxHeader('',$langs->trans("Upgrade"),$wikihelp); print_fiche_titre($langs->trans("Upgrade"),'','title_setup'); print $langs->trans("CurrentVersion").' : '.DOL_VERSION.'
'; $result = getURLContent('http://sourceforge.net/projects/dolibarr/rss'); //var_dump($result['content']); $sfurl = simplexml_load_string($result['content']); if ($sfurl) { $title=$sfurl->channel[0]->item[0]->title; function word_limiter($text, $limit = 30, $chars = '0123456789.') { if (strlen( $text ) > $limit) { $words = str_word_count($text, 2, $chars); $words = array_reverse($words, TRUE); foreach($words as $length => $word) { if ($length + strlen( $word ) >= $limit) { array_shift($words); } else { break; } } $words = array_reverse($words); $text = implode(" ", $words) . ''; } return $text; } $str = $title; print $langs->trans("LastStableVersion").' : '. word_limiter( $str ).'
'; } else { print $langs->trans("LastStableVersion").' : ' .$langs->trans("UpdateServerOffline").'
'; } print '
'; // Upgrade print $langs->trans("Upgrade").'
'; print '
'; print $langs->trans("ThisIsProcessToFollow").'
'; print ''.$langs->trans("StepNb",1).': '; $fullurl=''.$urldolibarr.''; print $langs->trans("DownloadPackageFromWebSite",$fullurl).'
'; print ''.$langs->trans("StepNb",2).': '; print $langs->trans("UnpackPackageInDolibarrRoot",$dolibarrroot).'
'; print ''.$langs->trans("StepNb",3).': '; print $langs->trans("RemoveLock",$dolibarrdataroot.'/install.lock').'
'; print ''.$langs->trans("StepNb",4).': '; $fullurl=''.DOL_URL_ROOT.'/install/'; print $langs->trans("CallUpdatePage",$fullurl).'
'; print ''.$langs->trans("StepNb",5).': '; print $langs->trans("RestoreLock",$dolibarrdataroot.'/install.lock').'
'; print '
'; print '
'; // Install external module $allowonlineinstall=true; $allowfromweb=1; if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) $allowonlineinstall=false; $fullurl=''.$urldolibarrmodules.''; $message=''; if (! empty($allowonlineinstall)) { if (! in_array('/custom',explode(',',$dolibarr_main_url_root_alt))) { $message=info_admin($langs->trans("ConfFileMuseContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT)); $allowfromweb=-1; } else { if ($dirins_ok) { if (! is_writable(dol_osencode($dirins))) { $langs->load("errors"); $message=info_admin($langs->trans("ErrorFailedToWriteInDir",$dirins)); $allowfromweb=0; } } else { $message=info_admin($langs->trans("NotExistsDirect",$dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample")); $allowfromweb=0; } } } else { $message=info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile",$dolibarrdataroot.'/installmodules.lock')); $allowfromweb=0; } print $langs->trans("AddExtensionThemeModuleOrOther").'
'; print '
'; if ($allowfromweb < 1) { print $langs->trans("SomethingMakeInstallFromWebNotPossible"); print $message; //print $langs->trans("SomethingMakeInstallFromWebNotPossible2"); print '
'; } if ($allowfromweb >= 0) { if ($allowfromweb == 1) print $langs->trans("ThisIsProcessToFollow").'
'; else print $langs->trans("ThisIsAlternativeProcessToFollow").'
'; print ''.$langs->trans("StepNb",1).': '; print $langs->trans("FindPackageFromWebSite",$fullurl).'
'; print ''.$langs->trans("StepNb",2).': '; print $langs->trans("DownloadPackageFromWebSite",$fullurl).'
'; print ''.$langs->trans("StepNb",3).': '; if ($allowfromweb == 1) { print $langs->trans("UnpackPackageInDolibarrRoot",$dirins).'
'; print '
'; print ''; print $langs->trans("YouCanSubmitFile").' '; print ''; print '
'; } else { print $langs->trans("UnpackPackageInDolibarrRoot",$dirins).'
'; print ''.$langs->trans("StepNb",4).': '; print $langs->trans("SetupIsReadyForUse").'
'; } } if (! empty($result['return'])) { print '
'; foreach($result['return'] as $value) { echo $value.'
'; } } llxFooter(); $db->close();