diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php
index 0949fa1a334..17fae31ef7d 100644
--- a/htdocs/bom/bom_card.php
+++ b/htdocs/bom/bom_card.php
@@ -79,6 +79,7 @@ $permissionnote=$user->rights->bom->write; // Used by the include of actions_set
$permissiondellink=$user->rights->bom->write; // Used by the include of actions_dellink.inc.php
$permissionedit=$user->rights->bom->write; // Used by the include of actions_lineupdown.inc.php
$permissiontoadd=$user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php
+$permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && $object->status == 0);
/*
@@ -93,11 +94,11 @@ if (empty($reshook))
{
$error=0;
- $permissiontoadd = $user->rights->bom->write;
- $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && $object->status == 0);
$backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php';
- if (empty($backtopage)) {
- if (empty($id) && $action != 'add' && $action != 'create') $backtopage = $backurlforlist;
+
+ if (empty($backtopage) || ($cancel && empty($id))) {
+ //var_dump($backurlforlist);exit;
+ if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist;
else $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__');
}
$triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record
@@ -218,7 +219,7 @@ if ($action == 'create')
dol_fiche_head(array(), '');
- print '
'."\n";
+ print ''."\n";
// Common attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
@@ -252,7 +253,9 @@ if (($id || $ref) && $action == 'edit')
dol_fiche_head();
- print ''."\n";
+ //$object->fields['keyfield']['disabled'] = 1;
+
+ print ''."\n";
// Common attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php
index 07ae81e2994..02e39149364 100644
--- a/htdocs/bom/class/bom.class.php
+++ b/htdocs/bom/class/bom.class.php
@@ -91,7 +91,7 @@ class BOM extends CommonObject
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>1, 'searchall'=>1, 'showoncombobox'=>'1',),
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,),
- 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'),
+ 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'),
'qty' => array('type'=>'real', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>55, 'notnull'=>1, 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
'efficiency' => array('type'=>'real', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>-1, 'default'=>1, 'position'=>100, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'),
'duration' => array('type'=>'real', 'label'=>'EstimatedDuration', 'enabled'=>1, 'visible'=>-1, 'position'=>101, 'notnull'=>-1, 'css'=>'maxwidth50imp', 'help'=>'EstimatedDurationDesc'),
diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index e87333e4c01..d618a0702c8 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -32,6 +32,8 @@
if ($cancel)
{
+ /*var_dump($cancel);
+ var_dump($backtopage);exit;*/
if (! empty($backtopage))
{
header("Location: ".$backtopage);
@@ -80,7 +82,8 @@ if ($action == 'add' && ! empty($permissiontoadd))
if ($result > 0)
{
// Creation OK
- $urltogo=$backtopage?str_replace('__ID__', $result, $backtopage):$backurlforlist;
+ $urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
+ $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: ".$urltogo);
exit;
}
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index cc8ae3238c0..95fa2c2fc59 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -5556,16 +5556,20 @@ abstract class CommonObject
$type='';
$param = array();
$param['options']=array();
- $size =$this->fields[$key]['size'];
+ $reg=array();
+ $size = $this->fields[$key]['size'];
// Because we work on extrafields
- if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
- $param['options']=array($reg[1].':'.$reg[2]=>'N');
- $type ='link';
- } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
- $param['options']=array($reg[1].':'.$reg[2]=>'N');
+ if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)){
+ $param['options']=array($reg[2].':'.$reg[3].':'.$reg[4].':'.$reg[5] => 'N');
+ $type ='link';
+ } elseif (preg_match('/^(integer|link):(.*):(.*):(.*)/i', $val['type'], $reg)){
+ $param['options']=array($reg[2].':'.$reg[3].':'.$reg[4] => 'N');
+ $type ='link';
+ } elseif (preg_match('/^(integer|link):(.*):(.*)/i', $val['type'], $reg)){
+ $param['options']=array($reg[2].':'.$reg[3] => 'N');
$type ='link';
} elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
- $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N');
+ $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4] => 'N');
$type ='sellist';
} elseif(preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) {
$param['options']=array();
@@ -6078,16 +6082,26 @@ abstract class CommonObject
}
elseif ($type == 'link')
{
- $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
+ $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter]]'
+ $param_list_array = explode(':', $param_list[0]);
$showempty=(($required && $default != '')?0:1);
- $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty);
- if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
+
+ $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty, '', '', '', '', 0, empty($val['disabled'])?0:1);
+
+ if (! empty($param_list_array[2])) // If we set to add a create button
{
- list($class,$classfile)=explode(':', $param_list[0]);
- if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php', 1);
- else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php', 1);
- $out.='';
- // TODO Add Javascript code to add input fields contents to new elements urls
+ if (! GETPOSTISSET('backtopage') && empty($val['disabled'])) // To avoid to open several infinitely the 'Create Object' button and to avoid to have button if field is protected by a "disabled".
+ {
+ list($class,$classfile)=explode(':', $param_list[0]);
+ if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php', 1);
+ else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.strtolower($class).'_card.php', 1);
+ $paramforthenewlink = '';
+ $paramforthenewlink .= (GETPOSTISSET('action')?'&action='.GETPOST('action','aZ09'):'');
+ $paramforthenewlink .= (GETPOSTISSET('id')?'&id='.GETPOST('id','int'):'');
+ $paramforthenewlink .= '&fk_'.strtolower($class).'=--IDFORBACKTOPAGE--';
+ // TODO Add Javascript code to add input fields already filled into $paramforthenewlink so we won't loose them when going back to main page
+ $out.='';
+ }
}
}
elseif ($type == 'password')
@@ -6167,6 +6181,7 @@ abstract class CommonObject
$label = $val['label'];
$type = $val['type'];
$size = $val['css'];
+ $reg = array();
// Convert var to be able to share same code than showOutputField of extrafields
if (preg_match('/varchar\((\d+)\)/', $type, $reg))
@@ -6182,7 +6197,9 @@ abstract class CommonObject
$computed=$val['computed'];
$unique=$val['unique'];
$required=$val['required'];
- $param=$val['param'];
+ $param=array();
+ $param['options']=array();
+
if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval'];
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
{
diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php
index 1837f82a2a4..07cd778d3a0 100644
--- a/htdocs/core/class/cunits.class.php
+++ b/htdocs/core/class/cunits.class.php
@@ -234,8 +234,6 @@ class CUnits // extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
- $records=array();
-
$sql = 'SELECT';
$sql.= " t.rowid,";
$sql.= " t.code,";
@@ -273,6 +271,7 @@ class CUnits // extends CommonObject
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
}
+
$resql = $this->db->query($sql);
if ($resql) {
$this->records=array();
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 6d26e585435..66646ee4c4f 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -5824,10 +5824,11 @@ class Form
* @param string $morecss More CSS
* @param string $moreparams More params provided to ajax call
* @param int $forcecombo Force to load all values and output a standard combobox (with no beautification)
+ * @param int $disabled 1=Html component is disabled
* @return string Return HTML string
* @see selectForFormsList() select_thirdparty
*/
- public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0)
+ public function selectForForms($objectdesc, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $disabled = 0)
{
global $conf, $user;
@@ -5868,12 +5869,12 @@ class Form
$out.= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array());
$out.= '';
if ($placeholder) $placeholder=' placeholder="'.$placeholder.'"';
- $out.= '';
+ $out.= '';
}
else
{
// Immediate load of all database
- $out.=$this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo);
+ $out.=$this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo, 0, $disabled);
}
return $out;
@@ -5893,10 +5894,11 @@ class Form
* @param string $moreparams More params provided to ajax call
* @param int $forcecombo Force to load all values and output a standard combobox (with no beautification)
* @param int $outputmode 0=HTML select string, 1=Array
+ * @param int $disabled 1=Html component is disabled
* @return string Return HTML string
* @see selectForForms()
*/
- public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0)
+ public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0)
{
global $conf, $langs, $user;
@@ -5948,7 +5950,7 @@ class Form
}
// Construct $out and $outarray
- $out.= '