Skip to content
Snippets Groups Projects
Commit 452636b0 authored by Maxime Kohlhaas's avatar Maxime Kohlhaas
Browse files

New : Add option to allow extrafield to be modified regardless of the document status

parent 815c7927
No related branches found
No related tags found
No related merge requests found
......@@ -2032,9 +2032,16 @@ if ($action == 'create')
}
else
{
print '<tr><td';
print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td';
if (! empty($extrafields->attribute_required [$key])) print ' class="fieldrequired"';
print '>' . $label . '</td><td colspan="5">';
print '>' . $label . '</td>';
if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key))
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_edit().'</a></td>';
print '</tr></table>';
print '<td colspan="5">';
// Convert date into timestamp format
if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
$value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
......@@ -2057,8 +2064,6 @@ if ($action == 'create')
else
{
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->propal->creer)
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . '</a>';
}
print '</td></tr>' . "\n";
}
......
......@@ -141,7 +141,7 @@ if ($action == 'add')
}
}
$result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params);
$result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params,(GETPOST('alwayseditable')?1:0));
if ($result > 0)
{
setEventMessage($langs->trans('SetupSaved'));
......@@ -278,7 +278,7 @@ if ($action == 'update')
$params['options'][$key] = $value;
}
}
$result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params);
$result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params,(GETPOST('alwayseditable')?1:0));
if ($result > 0)
{
setEventMessage($langs->trans('SetupSaved'));
......
......@@ -50,6 +50,8 @@ class ExtraFields
var $attribute_param;
// Int to store position of attribute
var $attribute_pos;
// Int to store if attribute is editable regardless of the document status
var $attribute_alwayseditable;
var $error;
var $errno;
......@@ -105,7 +107,7 @@ class ExtraFields
* @param array $param Params for field
* @return int <=0 if KO, >0 if OK
*/
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0,$default_value='', $param=0)
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0)
{
if (empty($attrname)) return -1;
if (empty($label)) return -1;
......@@ -119,7 +121,7 @@ class ExtraFields
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{
// Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param);
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable);
$err2=$this->errno;
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
{
......@@ -219,7 +221,7 @@ class ExtraFields
* @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int <=0 if KO, >0 if OK
*/
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='')
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0)
{
global $conf;
......@@ -241,7 +243,7 @@ class ExtraFields
$params='';
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable)";
$sql.= " VALUES('".$attrname."',";
$sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$type."',";
......@@ -251,7 +253,8 @@ class ExtraFields
$sql.= " '".$elementtype."',";
$sql.= " '".$unique."',";
$sql.= " '".$required."',";
$sql.= " '".$params."'";
$sql.= " '".$params."',";
$sql.= " '".$alwayseditable."'";
$sql.=')';
dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
......@@ -349,7 +352,7 @@ class ExtraFields
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int >0 if OK, <=0 if KO
*/
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='')
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0)
{
$table=$elementtype.'_extrafields';
......@@ -384,7 +387,7 @@ class ExtraFields
{
if ($label)
{
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param);
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable);
}
if ($result > 0)
{
......@@ -434,7 +437,7 @@ class ExtraFields
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @return int <=0 if KO, >0 if OK
*/
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='')
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0)
{
global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required);
......@@ -465,6 +468,7 @@ class ExtraFields
$sql.= " fieldunique,";
$sql.= " fieldrequired,";
$sql.= " pos,";
$sql.= " alwayseditable,";
$sql.= " param";
$sql.= ") VALUES (";
$sql.= "'".$attrname."',";
......@@ -476,6 +480,7 @@ class ExtraFields
$sql.= " '".$unique."',";
$sql.= " '".$required."',";
$sql.= " '".$pos."',";
$sql.= " '".$alwayseditable."',";
$sql.= " '".$param."'";
$sql.= ")";
dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
......@@ -529,7 +534,7 @@ class ExtraFields
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
return $array_name_label;
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos";
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
......@@ -557,6 +562,7 @@ class ExtraFields
$this->attribute_required[$tab->name]=$tab->fieldrequired;
$this->attribute_param[$tab->name]=unserialize($tab->param);
$this->attribute_pos[$tab->name]=$tab->pos;
$this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
}
}
......
......@@ -101,6 +101,8 @@
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique" <?php echo (GETPOST('unique')?' checked="true"':''); ?>></td></tr>
<!-- Required -->
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required" <?php echo (GETPOST('required')?' checked="true"':''); ?>></td></tr>
<!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable" <?php echo (GETPOST('alwayseditable')?' checked="true"':''); ?>></td></tr>
</table>
<div align="center"><br><input type="submit" name="button" class="button" value="<?php echo $langs->trans("Save"); ?>"> &nbsp;
......
......@@ -54,6 +54,7 @@ $size=$extrafields->attribute_size[$attrname];
$unique=$extrafields->attribute_unique[$attrname];
$required=$extrafields->attribute_required[$attrname];
$pos=$extrafields->attribute_pos[$attrname];
$alwayseditable=$extrafields->attribute_alwayseditable[$attrname];
$param=$extrafields->attribute_param[$attrname];
if((($type == 'select') || ($type == 'checkbox') ||(($type == 'radio'))) && is_array($param))
......@@ -110,6 +111,8 @@ if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') ||(($typ
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique" <?php echo ($unique?' checked="true"':''); ?>></td></tr>
<!-- Required -->
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required" <?php echo ($required?' checked="true"':''); ?>></td></tr>
<!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable" <?php echo ($alwayseditable?' checked="true"':''); ?>></td></tr>
</table>
......
......@@ -1096,3 +1096,5 @@ DELETE FROM llx_const WHERE name = 'MAIN_MODULE_BOUTIQUE';
DELETE FROM llx_const WHERE name = 'OSC_DB_HOST';
DELETE FROM llx_menu WHERE module = 'boutique';
-- Add option always editable on extrafield
ALTER TABLE llx_extrafields ADD alwayseditable INT(11) NOT NULL AFTER pos;
\ No newline at end of file
......@@ -30,5 +30,6 @@ create table llx_extrafields
fieldunique integer DEFAULT 0,
fieldrequired integer DEFAULT 0,
pos integer DEFAULT 0,
alwayseditable integer DEFAULT 0,
param text
)ENGINE=innodb;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment