From 542a72c684c989137788efba087edc8698e61bbb Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sat, 10 Jun 2017 23:50:02 +0200
Subject: [PATCH] NEW custom dir is enabled dy default on first install. Fix
 modulebuilder when custom dir not defined.

---
 htdocs/admin/modules.php       |  70 +++++++-------
 htdocs/install/step1.php       |  10 +-
 htdocs/langs/en_US/admin.lang  |   2 +-
 htdocs/modulebuilder/README.md |  16 +---
 htdocs/modulebuilder/index.php | 168 ++++++++++++++++++++-------------
 5 files changed, 150 insertions(+), 116 deletions(-)

diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php
index fe735cb2499..57ed97c9b20 100644
--- a/htdocs/admin/modules.php
+++ b/htdocs/admin/modules.php
@@ -278,7 +278,7 @@ foreach ($modulesdir as $dir)
 
 		            try
 		            {
-		                $res=include_once $dir.$file;     // A class already exists in a different file will send a non catchable fatal error. 
+		                $res=include_once $dir.$file;     // A class already exists in a different file will send a non catchable fatal error.
 		                if (class_exists($modName))
 						{
 							try {
@@ -352,7 +352,7 @@ foreach ($modulesdir as $dir)
 		    			            {
 		    			                $arrayofwarningsext[$modName]=$objMod->warnings_activation_ext;
 		    			            }
-		    			             
+
 		    			            $orders[$i]  = $familyinfo[$familykey]['position']."_".$familykey."_".$moduleposition."_".$j;   // Sort by family, then by module position then number
 		    						$dirmod[$i]  = $dir;
 		    						//print $i.'-'.$dirmod[$i].'<br>';
@@ -436,7 +436,7 @@ if ($mode == 'common')
     print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
     print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
     print '<input type="hidden" name="page" value="'.$page.'">';
-    
+
     dol_fiche_head($head, $mode, '', -1);
 
     $moreforfilter = '';
@@ -473,12 +473,12 @@ if ($mode == 'common')
         $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
         print $hookmanager->resPrint;
     }
-    
-    
+
+
     print '<div class="clearboth"></div><br>';
 
     $moreforfilter='';
-    
+
     // Show list of modules
 
     $oldfamily='';
@@ -564,13 +564,13 @@ if ($mode == 'common')
         if ($familykey!=$oldfamily)
         {
         	if ($oldfamily) print '</table></div><br>';
-        	
+
             $familytext=empty($familyinfo[$familykey]['label'])?$familykey:$familyinfo[$familykey]['label'];
             print_fiche_titre($familytext, '', '');
-    		
+
             print '<div class="div-table-responsive">';
         	print '<table class="tagtable liste" summary="list_of_modules">'."\n";
-            
+
         	$atleastoneforfamily=0;
         }
 
@@ -582,9 +582,9 @@ if ($mode == 'common')
         	$oldfamily=$familykey;
         }
 
-        
 
-        
+
+
         // Version (with picto warning or not)
         $version=$objMod->getVersion(0);
         $versiontrans='';
@@ -592,14 +592,14 @@ if ($mode == 'common')
         if (preg_match('/experimental/i', $version)) $versiontrans.=img_warning($langs->trans("Experimental"), 'style="float: left"');
         if (preg_match('/deprecated/i', $version))   $versiontrans.=img_warning($langs->trans("Deprecated"), 'style="float: left"');
         $versiontrans.=$objMod->getVersion(1);
-        
+
         // Define imginfo
         $imginfo="info";
         if ($objMod->isCoreOrExternalModule() == 'external')
         {
             $imginfo="info_black";
         }
-        
+
         print '<tr>'."\n";
 
         // Picto + Name of module
@@ -756,32 +756,32 @@ if ($mode == 'common')
 	        	print "</a>\n";
         	}
         	print "</td>\n";
-        	
+
         	// Link config
         	print '<td class="tdsetuppicto right valignmiddle" width="60px">'.img_picto($langs->trans("NothingToSetup"),"setup",'class="opacitytransp" style="padding-right: 6px"').'</td>';
         }
 
         print "</tr>\n";
     }
-    
+
     if ($oldfamily)
     {
         print "</table>\n";
         print '</div>';
     }
-    
+
     dol_fiche_end();
-    
+
     // Show warning about external users
     print info_admin(showModulesExludedForExternal($modules))."\n";
-    
+
     print '</form>';
 }
 
 if ($mode == 'marketplace')
 {
     dol_fiche_head($head, $mode, '', -1);
-    
+
     // Marketplace
     print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
     print "<tr class=\"liste_titre\">\n";
@@ -790,7 +790,7 @@ if ($mode == 'marketplace')
     print '<td>'.$langs->trans("URL").'</td>';
     print '</tr>';
 
-    
+
     print "<tr class=\"oddeven\">\n";
     $url='https://www.dolistore.com';
     print '<td align="left"><a href="'.$url.'" target="_blank" rel="external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolistore_logo.png"></a></td>';
@@ -798,7 +798,7 @@ if ($mode == 'marketplace')
     print '<td><a href="'.$url.'" target="_blank" rel="external">'.$url.'</a></td>';
     print '</tr>';
 
-    
+
     print "<tr class=\"oddeven\">\n";
     $url='https://partners.dolibarr.org';
     print '<td align="left"><a href="'.$url.'" target="_blank" rel="external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolibarr_preferred_partner_int.png"></a></td>';
@@ -813,23 +813,23 @@ if ($mode == 'marketplace')
 
 
 // Install external module
-   
+
 if ($mode == 'deploy')
 {
     dol_fiche_head($head, $mode, '', -1);
 
-    
+
     $allowonlineinstall=true;
     $allowfromweb=1;
     if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) $allowonlineinstall=false;
-    
+
     $fullurl='<a href="'.$urldolibarrmodules.'" target="_blank">'.$urldolibarrmodules.'</a>';
     $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));
+            $message=info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
             $allowfromweb=-1;
         }
         else
@@ -845,7 +845,7 @@ if ($mode == 'deploy')
             }
             else
             {
-    
+
                 $message=info_admin($langs->trans("NotExistsDirect",$dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
                 $allowfromweb=0;
             }
@@ -856,7 +856,7 @@ if ($mode == 'deploy')
         $message=info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile",$dolibarrdataroot.'/installmodules.lock'));
         $allowfromweb=0;
     }
-    
+
     if ($allowfromweb < 1)
     {
     	print $langs->trans("SomethingMakeInstallFromWebNotPossible");
@@ -864,15 +864,15 @@ if ($mode == 'deploy')
     	//print $langs->trans("SomethingMakeInstallFromWebNotPossible2");
     	print '<br>';
     }
-    
-    
+
+
     if ($allowfromweb >= 0)
     {
-    	if ($allowfromweb == 1) 
+    	if ($allowfromweb == 1)
     	{
     	    //print $langs->trans("ThisIsProcessToFollow").'<br>';
     	}
-    	else 
+    	else
     	{
     	    print $langs->trans("ThisIsAlternativeProcessToFollow").'<br>';
         	print '<b>'.$langs->trans("StepNb",1).'</b>: ';
@@ -881,7 +881,7 @@ if ($mode == 'deploy')
         	print $langs->trans("DownloadPackageFromWebSite",$fullurl).'<br>';
         	print '<b>'.$langs->trans("StepNb",3).'</b>: ';
     	}
-    
+
     	if ($allowfromweb == 1)
     	{
     		print $langs->trans("UnpackPackageInModulesRoot",$dirins).'<br>';
@@ -899,12 +899,12 @@ if ($mode == 'deploy')
     		print $langs->trans("SetupIsReadyForUse").'<br>';
     	}
     }
-    
-    
+
+
     if (! empty($result['return']))
     {
     	print '<br>';
-    
+
     	foreach($result['return'] as $value)
     	{
     		echo $value.'<br>';
diff --git a/htdocs/install/step1.php b/htdocs/install/step1.php
index a57ffd0c674..631ac79752f 100644
--- a/htdocs/install/step1.php
+++ b/htdocs/install/step1.php
@@ -57,14 +57,14 @@ $db_user=GETPOST('db_user','alpha');
 $db_pass=GETPOST('db_pass');
 $db_port=GETPOST('db_port','int');
 $db_prefix=GETPOST('db_prefix','alpha');
-$db_create_database = GETPOST('db_create_database');
-$db_create_user = GETPOST('db_create_user');
+$db_create_database = GETPOST('db_create_database','none');
+$db_create_user = GETPOST('db_create_user','none');
 // Force https
-$main_force_https = ((GETPOST("main_force_https") && (GETPOST("main_force_https") == "on" || GETPOST("main_force_https") == 1)) ? '1' : '0');
+$main_force_https = ((GETPOST("main_force_https",'alpha') && (GETPOST("main_force_https",'alpha') == "on" || GETPOST("main_force_https",'alpha') == 1)) ? '1' : '0');
 // Use alternative directory
-$main_use_alt_dir = ((GETPOST("main_use_alt_dir") && (GETPOST("main_use_alt_dir") == "on" || GETPOST("main_use_alt_dir") == 1)) ? '' : '//');
+$main_use_alt_dir = ((GETPOST("main_use_alt_dir",'alpha') == '' || (GETPOST("main_use_alt_dir",'alpha') == "on" || GETPOST("main_use_alt_dir",'alpha') == 1)) ? '' : '//');
 // Alternative root directory name
-$main_alt_dir_name = ((GETPOST("main_alt_dir_name") && GETPOST("main_alt_dir_name") != '') ? GETPOST("main_alt_dir_name") : 'custom');
+$main_alt_dir_name = ((GETPOST("main_alt_dir_name",'alpha') && GETPOST("main_alt_dir_name",'alpha') != '') ? GETPOST("main_alt_dir_name",'alpha') : 'custom');
 
 session_start();    // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters)
 
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 421b3fae132..695373e22b5 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1619,7 +1619,7 @@ BackupDumpWizard=Wizard to build database backup dump file
 SomethingMakeInstallFromWebNotPossible=Installation of external module is not possible from the web interface for the following reason:
 SomethingMakeInstallFromWebNotPossible2=For this reason, process to upgrade described here is only manual steps a privileged user can do. 
 InstallModuleFromWebHasBeenDisabledByFile=Install of external module from application has been disabled by your administrator. You must ask him to remove the file <strong>%s</strong> to allow this feature.
-ConfFileMuseContainCustom=Installing an external module from application need to save the module files into directory <strong>%s</strong>. To have this directory processed by Dolibarr, you must setup your <strong>conf/conf.php</strong> to add the 2 directive lines:<br><strong>$dolibarr_main_url_root_alt='/custom';</strong><br><strong>$dolibarr_main_document_root_alt='%s/custom';</strong> 
+ConfFileMustContainCustom=Installing or building an external module from application need to save the module files into directory <strong>%s</strong>. To have this directory processed by Dolibarr, you must setup your <strong>conf/conf.php</strong> to add the 2 directive lines:<br><strong>$dolibarr_main_url_root_alt='/custom';</strong><br><strong>$dolibarr_main_document_root_alt='%s/custom';</strong> 
 HighlightLinesOnMouseHover=Highlight table lines when mouse move passes over
 HighlightLinesColor=Highlight color of the line when the mouse passes over (keep empty for no highlight)
 TextTitleColor=Color of page title
diff --git a/htdocs/modulebuilder/README.md b/htdocs/modulebuilder/README.md
index 5e2af06a430..548e87b7912 100644
--- a/htdocs/modulebuilder/README.md
+++ b/htdocs/modulebuilder/README.md
@@ -9,26 +9,26 @@ If you're not a module developer you have no use for this.
 Documentation
 -------------
 
-[Module tutorial](http://wiki.dolibarr.org/index.php/Module_development)
+[Module tutorial](https://wiki.dolibarr.org/index.php/Module_development)
 
-[Dolibarr development](http://wiki.dolibarr.org/index.php/Developer_documentation)
+[Dolibarr development](https://wiki.dolibarr.org/index.php/Developer_documentation)
 
 ### Translations
 
-Dolibarr uses [Transifex](http://transifex.com) to manage it's translations.
+Dolibarr uses [Transifex](https://transifex.com) to manage it's translations.
 
 This template also contains a sample configuration for Transifex managed translations under the hidden [.tx](.tx) directory.
 
 For more informations, see the [translator's documentation](http://wiki.dolibarr.org/index.php/Translator_documentation).
 
-There is a [Transifex project](http://transifex.com/projects/p/dolibarr-module-template) for this module.
+There is a [Transifex project](https://transifex.com/projects/p/dolibarr-module-template) for this module.
 
 Install
 -------
 
 ### Manually
 
-- Make sure Dolibarr (>= 3.3.x) is already installed and configured on your workstation or development server.
+- Make sure Dolibarr is already installed and configured on your workstation or development server.
 
 - In your Dolibarr installation directory, edit the ```htdocs/conf/conf.php``` file
 
@@ -60,8 +60,6 @@ Install
 
     For more information about the ```conf.php``` file take a look at the conf.php.example file.
 
-*Note that for Dolibarr versions before 3.5, the ```$dolibarr_main_url_root_alt``` has to be an absolute path*
-
 - Clone the repository in ```$dolibarr_main_document_root_alt/mymodule```
 
 *(You may have to create the ```htdocs/custom``` directory first if it doesn't exist yet.)*
@@ -187,10 +185,6 @@ The de-facto standard for publishing and marketing modules for Dolibarr is the [
 Templates for required images and texts are [provided](dev/dolistore).  
 Check the dedicated [README](dev/dolistore/README.md) for more informations.
 
-Contributions
--------------
-
-Feel free to contribute and report defects on our [issue tracker](http://github.com/Dolibarr/dolibarr-module-template/issues).
 
 Licenses
 --------
diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php
index b3b2c8dac77..17599e922aa 100644
--- a/htdocs/modulebuilder/index.php
+++ b/htdocs/modulebuilder/index.php
@@ -45,7 +45,7 @@ if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessfor
 
 // Dir for custom dirs
 $tmp=explode(',', $dolibarr_main_document_root_alt);
-$dircustom = $tmp[0];
+$dirins = $tmp[0];
 
 $FILEFLAG='modulebuilder.txt';
 
@@ -54,16 +54,16 @@ $FILEFLAG='modulebuilder.txt';
  * Actions
  */
 
-if ($dircustom && $action == 'initmodule' && $modulename)
+if ($dirins && $action == 'initmodule' && $modulename)
 {
     $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
-    $destdir = $dircustom.'/'.strtolower($modulename);
+    $destdir = $dirins.'/'.strtolower($modulename);
 
     $arrayreplacement=array(
         'mymodule'=>strtolower($modulename),
      	'MyModule'=>$modulename
     );
-    
+
     $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
     //dol_mkdir($destfile);
     if ($result <= 0)
@@ -94,17 +94,17 @@ if ($dircustom && $action == 'initmodule' && $modulename)
 	        	'My module'=>$modulename,
 	        	'htdocs/modulebuilder/template/'=>'',
 	        );
-	        
-	        
+
+
 	        $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
 	        //var_dump($result);
 	        if ($result < 0)
 	        {
 	        	setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
 	        }
-	    }    
+	    }
     }
-        
+
     if (! $error)
     {
         setEventMessages('ModuleInitialized', null);
@@ -113,15 +113,15 @@ if ($dircustom && $action == 'initmodule' && $modulename)
     }
 }
 
-if ($dircustom && $action == 'generatepackage')
+if ($dirins && $action == 'generatepackage')
 {
     $modulelowercase=strtolower($module);
-	
+
     // Dir for module
-    $dir = $dircustom.'/'.$modulelowercase;
+    $dir = $dirins.'/'.$modulelowercase;
     // Zip file to build
     $FILENAMEZIP='';
-    
+
     // Load module
     dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
     $class='mod'.$module;
@@ -144,13 +144,13 @@ if ($dircustom && $action == 'generatepackage')
         dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
         exit;
     }
-    
+
     $arrayversion=explode('.',$moduleobj->version,3);
     if (count($arrayversion))
     {
         $FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
         $outputfile = $conf->admin->dir_temp.'/'.$FILENAMEZIP;
-    
+
         $result = dol_compress_dir($dir, $outputfile, 'zip');
         if ($result > 0)
         {
@@ -176,6 +176,14 @@ if ($dircustom && $action == 'generatepackage')
  * View
  */
 
+// Set dir where external modules are installed
+if (! dol_is_dir($dirins))
+{
+    dol_mkdir($dirins);
+}
+$dirins_ok=(dol_is_dir($dirins));
+
+
 llxHeader("",$langs->trans("ModuleBuilder"),"");
 
 
@@ -193,8 +201,8 @@ if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder')	// En
     {
         foreach ($dolibarr_main_document_root_alt as $diralt)
         {*/
-            $dirsincustom=dol_dir_list($dircustom, 'directories');
-            
+            $dirsincustom=dol_dir_list($dirins, 'directories');
+
             if (is_array($dirsincustom) && count($dirsincustom) > 0)
             {
                 foreach ($dirsincustom as $dircustomcursor)
@@ -224,8 +232,40 @@ if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder')	// En
 
 
 // Show description of content
+$newdircustom=$dirins;
+if (empty($newdircustom)) $newdircustom=img_warning();
 print $langs->trans("ModuleBuilderDesc").'<br>';
-print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $dircustom).'<br>';
+print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'<br>';
+
+$message='';
+if (! $dirins)
+{
+    $message=info_admin($langs->trans("ConfFileMustContainCustom", 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;
+    }
+}
+if ($message)
+{
+    print $message;
+}
+
 print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
 //print '<br>';
 
@@ -237,7 +277,7 @@ $moduleobj = null;
 if (! empty($module) && $module != 'initmodule')
 {
 	$modulelowercase=strtolower($module);
-	
+
     // Load module
     dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
     $class='mod'.$module;
@@ -261,7 +301,7 @@ if (! empty($module) && $module != 'initmodule')
     }
 }
 
-print '<br>';            
+print '<br>';
 
 
 // Tabs for all modules
@@ -272,7 +312,7 @@ $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
 $head[$h][1] = $langs->trans("NewModule");
 $head[$h][2] = 'initmodule';
 $h++;
-    
+
 foreach($listofmodules as $tmpmodule => $tmpmodulewithcase)
 {
     $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulewithcase;
@@ -292,11 +332,11 @@ if ($module == 'initmodule')
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
     print '<input type="hidden" name="action" value="initmodule">';
     print '<input type="hidden" name="module" value="initmodule">';
-    
+
     print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
-    
+
     print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
-    print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
+    print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins?'':' disabled="disabled"').'>';
     print '</form>';
 }
 elseif (! empty($module))
@@ -310,53 +350,53 @@ elseif (! empty($module))
        	$modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive");
         if (! empty($conf->$module->enabled))
         {
-        	$modulestatusinfo=img_warning().' '.$langs->trans("ModuleIsLive");	
+        	$modulestatusinfo=img_warning().' '.$langs->trans("ModuleIsLive");
         }
-        
+
         foreach($listofmodules as $tmpmodule => $tmpmodulewithcase)
         {
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("Description");
             $head2[$h][2] = 'description';
             $h++;
-            
+
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("Objects");
             $head2[$h][2] = 'objects';
-            $h++;        
-        
+            $h++;
+
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("Menus");
             $head2[$h][2] = 'menus';
             $h++;
-            
+
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("Permissions");
             $head2[$h][2] = 'permissions';
-            $h++;        
-    
+            $h++;
+
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("Triggers");
             $head2[$h][2] = 'triggers';
-            $h++;        
+            $h++;
 
             $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$tmpmodulewithcase;
             $head2[$h][1] = $langs->trans("BuildPackage");
             $head2[$h][2] = 'buildpackage';
-            $h++;        
+            $h++;
         }
 
         print $modulestatusinfo.'<br><br>';
-       
+
         dol_fiche_head($head2, $tab, '', -1, '');
 
         print $langs->trans("ModuleBuilderDesc".$tab).'<br><br>';
-        
+
         if ($tab == 'description')
         {
         	print '<div class="underbanner clearboth"></div>';
         	print '<div class="fichecenter">';
-        	
+
         	print '<table class="border centpercent">';
         	print '<tr class="liste_titre"><td class="titlefield">';
         	print $langs->trans("Parameter");
@@ -369,90 +409,90 @@ elseif (! empty($module))
         	print '</td><td>';
         	print $moduleobj->numero;
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("Name");
         	print '</td><td>';
         	print $moduleobj->getName();
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("Version");
         	print '</td><td>';
         	print $moduleobj->getVersion();
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("Family");
         	print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
         	print '</td><td>';
         	print $moduleobj->family;
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("EditorName");
         	print '</td><td>';
         	print $moduleobj->editor_name;
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("EditorUrl");
         	print '</td><td>';
         	print $moduleobj->editor_url;
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("Description");
         	print '</td><td>';
         	print $moduleobj->getDesc();
         	print '</td></tr>';
-        	
+
         	print '<tr><td>';
         	print $langs->trans("LongDescription");
         	print '</td><td>';
         	print $moduleobj->getDescLong();
         	print '</td></tr>';
-        	
+
         	print '</table>';
-    		
+
         	print '</div>';
-    		
+
         	print '<br><br>';
         	print '<form name="delete">';
         	print '<input type="hidden" name="action" value="confirm_delete">';
         	print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
         	print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
-        	print '<input type="submit" class="buttonDelete" value="'.$langs->trans("Delete").'">';		
+        	print '<input type="submit" class="buttonDelete" value="'.$langs->trans("Delete").'"'.($dirins?'':' disabled="disabled"').'>';
         	print '</form>';
         }
-        
+
         if ($tab == 'objects')
         {
     		print $langs->trans("FeatureNotYetAvailable");
-        	
-        
+
+
         }
-        
+
         if ($tab == 'menus')
         {
     		print $langs->trans("FeatureNotYetAvailable");
-        	
-        
+
+
         }
-        
+
         if ($tab == 'permissions')
         {
     		print $langs->trans("FeatureNotYetAvailable");
-        
+
         }
-        
+
         if ($tab == 'triggers')
         {
         	require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
-        	
+
 			$interfaces = new Interfaces($db);
 			$triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
-			
+
 			print '<div class="div-table-responsive-no-min">';
 			print '<table class="noborder">
 			<tr class="liste_titre">
@@ -461,11 +501,11 @@ elseif (! empty($module))
 			<td align="center">&nbsp;</td>
 			</tr>
 			';
-			
+
 			$var=True;
 			foreach ($triggers as $trigger)
 			{
-				
+
 				print '<tr class="oddeven">';
 				print '<td valign="top" width="14" align="center">'.$trigger['picto'].'</td>';
 				print '<td class="tdtop">'.$trigger['file'].'</td>';
@@ -478,7 +518,7 @@ elseif (! empty($module))
 				print '</td>';
 				print '</tr>';
 			}
-			
+
 			print '</table>';
 			print '</div>';
         }
@@ -490,15 +530,15 @@ elseif (! empty($module))
                 print img_warning().' '.$langs->trans("ErrNoZipEngine");
                 print '<br>';
             }
-            
+
         	print '<form name="generatepackage">';
         	print '<input type="hidden" name="action" value="generatepackage">';
         	print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
         	print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
-        	print '<input type="submit" class="button" value="'.$langs->trans("Generate").'">';		
+        	print '<input type="submit" class="button" value="'.$langs->trans("Generate").'">';
         	print '</form>';
         }
-        
+
         dol_fiche_end();
     }
 }
-- 
GitLab