Merge branch 'atm-maxime-mkoevols' into develop

This commit is contained in:
Laurent Destailleur 2014-10-18 15:39:02 +02:00
commit 720cf0782f
16 changed files with 188 additions and 334 deletions

View File

@ -66,6 +66,7 @@ For users:
- New: Add feature to order to invoice on supplier part - New: Add feature to order to invoice on supplier part
- Upgrade phpexcel lib to 1.7.8 - Upgrade phpexcel lib to 1.7.8
- New : Use of MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR to use disk cache for big excel export - New : Use of MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR to use disk cache for big excel export
- New : Option on extrafields to have them always editable regardless of the document status
- Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action - Fix: [ bug #1487 ] PAYMENT_DELETE trigger does not intercept trigger action
- Fix: [ bug #1470, #1472, #1473] User trigger problem - Fix: [ bug #1470, #1472, #1473] User trigger problem
- Fix: [ bug #1489, #1491 ] Intervention trigger problem - Fix: [ bug #1489, #1491 ] Intervention trigger problem

View File

@ -2008,62 +2008,9 @@ if ($action == 'create')
print '</tr>'; print '</tr>';
} }
// Other attributes (TODO Move this into an include) // Other attributes
$res = $object->fetch_optionals($object->id, $extralabels); $cols = 3;
$parameters = array('colspan' => ' colspan="3"'); include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified
// by
// hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach ($extrafields->attribute_label as $key => $label)
{
if ($action == 'edit_extras')
{
$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
}
else
{
$value = $object->array_options ["options_" . $key];
}
if ($extrafields->attribute_type [$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required [$key])) print ' class="fieldrequired"';
print '>' . $label . '</td><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]);
}
if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key)
{
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
}
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";
}
}
}
// Amount HT // Amount HT
print '<tr><td height="10" width="25%">' . $langs->trans('AmountHT') . '</td>'; print '<tr><td height="10" width="25%">' . $langs->trans('AmountHT') . '</td>';

View File

@ -2130,60 +2130,9 @@ if ($action == 'create' && $user->rights->commande->creer) {
print '</tr>'; print '</tr>';
} }
// Other attributes (TODO Move this into an include) // Other attributes
$parameters = array('colspan' => ' colspan="3"'); $cols = 3;
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach ($extrafields->attribute_label as $key => $label)
{
if ($action == 'edit_extras')
{
$value = (isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
}
else
{
$value = $object->array_options["options_" . $key];
}
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required [$key])) print ' class="fieldrequired"';
print '>' . $label . '</td><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]);
}
if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
{
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
}
else
{
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->commande->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";
}
}
}
$rowspan = 4; $rowspan = 4;
if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0)

View File

@ -3324,52 +3324,9 @@ if ($action == 'create')
print '</tr>'; print '</tr>';
} }
// Other attributes (TODO Move this into an include) // Other attributes
$res = $object->fetch_optionals($object->id, $extralabels); $cols = 5;
$parameters = array('colspan' => ' colspan="5"', "cols" => 5); include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
// hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach ($extrafields->attribute_label as $key => $label)
{
if ($action == 'edit_extras') {
$value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
$value = $object->array_options ["options_" . $key];
}
if ($extrafields->attribute_type [$key] == 'separate') {
print $extrafields->showSeparator($key);
} else {
print '<tr><td';
if (! empty($extrafields->attribute_required [$key]))
print ' class="fieldrequired"';
print '>' . $label . '</td><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]);
}
if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) {
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
} else {
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->facture->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";
}
}
}
print '</table><br>'; print '</table><br>';

View File

@ -1189,52 +1189,8 @@ else
} }
// Other attributes // Other attributes
$parameters=array('colspan' => ' colspan="3"'); $cols = 3;
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
$res = $object->fetch_optionals($object->id, $extralabels);
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
foreach ($extrafields->attribute_label as $key => $label) {
if ($action == 'edit_extras') {
$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
$value = $object->array_options ["options_" . $key];
}
if ($extrafields->attribute_type [$key] == 'separate') {
print $extrafields->showSeparator($key);
} else {
print '<tr><td';
if (! empty($extrafields->attribute_required [$key]))
print ' class="fieldrequired"';
print '>' . $label . '</td><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]);
}
if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formcontract">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
} else {
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->commande->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";
}
}
}
print "</table>"; print "</table>";

View File

@ -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) if ($result > 0)
{ {
setEventMessage($langs->trans('SetupSaved')); setEventMessage($langs->trans('SetupSaved'));
@ -278,7 +278,7 @@ if ($action == 'update')
$params['options'][$key] = $value; $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) if ($result > 0)
{ {
setEventMessage($langs->trans('SetupSaved')); setEventMessage($langs->trans('SetupSaved'));

View File

@ -50,6 +50,8 @@ class ExtraFields
var $attribute_param; var $attribute_param;
// Int to store position of attribute // Int to store position of attribute
var $attribute_pos; var $attribute_pos;
// Int to store if attribute is editable regardless of the document status
var $attribute_alwayseditable;
var $error; var $error;
var $errno; var $errno;
@ -103,9 +105,10 @@ class ExtraFields
* @param int $required Is field required or not * @param int $required Is field required or not
* @param string $default_value Defaulted value * @param string $default_value Defaulted value
* @param array $param Params for field * @param array $param Params for field
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @return int <=0 if KO, >0 if OK * @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($attrname)) return -1;
if (empty($label)) return -1; if (empty($label)) return -1;
@ -119,7 +122,7 @@ class ExtraFields
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{ {
// Add declaration of field into table // 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; $err2=$this->errno;
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
{ {
@ -217,9 +220,10 @@ class ExtraFields
* @param int $unique Is field unique or not * @param int $unique Is field unique or not
* @param int $required Is field required or not * @param int $required Is field required or not
* @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @return int <=0 if KO, >0 if OK * @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; global $conf;
@ -241,7 +245,7 @@ class ExtraFields
$params=''; $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.= " VALUES('".$attrname."',";
$sql.= " '".$this->db->escape($label)."',"; $sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$type."',"; $sql.= " '".$type."',";
@ -251,7 +255,8 @@ class ExtraFields
$sql.= " '".$elementtype."',"; $sql.= " '".$elementtype."',";
$sql.= " '".$unique."',"; $sql.= " '".$unique."',";
$sql.= " '".$required."',"; $sql.= " '".$required."',";
$sql.= " '".$params."'"; $sql.= " '".$params."',";
$sql.= " '".$alwayseditable."'";
$sql.=')'; $sql.=')';
dol_syslog(get_class($this)."::create_label", LOG_DEBUG); dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
@ -347,9 +352,10 @@ class ExtraFields
* @param int $required Is field required or not * @param int $required Is field required or not
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @return int >0 if OK, <=0 if KO * @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'; $table=$elementtype.'_extrafields';
@ -384,7 +390,7 @@ class ExtraFields
{ {
if ($label) 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) if ($result > 0)
{ {
@ -432,9 +438,10 @@ class ExtraFields
* @param int $required Is field required or not * @param int $required Is field required or not
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @return int <=0 if KO, >0 if OK * @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; global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required); dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required);
@ -465,6 +472,7 @@ class ExtraFields
$sql.= " fieldunique,"; $sql.= " fieldunique,";
$sql.= " fieldrequired,"; $sql.= " fieldrequired,";
$sql.= " pos,"; $sql.= " pos,";
$sql.= " alwayseditable,";
$sql.= " param"; $sql.= " param";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'".$attrname."',"; $sql.= "'".$attrname."',";
@ -476,6 +484,7 @@ class ExtraFields
$sql.= " '".$unique."',"; $sql.= " '".$unique."',";
$sql.= " '".$required."',"; $sql.= " '".$required."',";
$sql.= " '".$pos."',"; $sql.= " '".$pos."',";
$sql.= " '".$alwayseditable."',";
$sql.= " '".$param."'"; $sql.= " '".$param."'";
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::update_label", LOG_DEBUG); dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
@ -529,7 +538,7 @@ class ExtraFields
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
return $array_name_label; 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.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")"; $sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
@ -557,6 +566,7 @@ class ExtraFields
$this->attribute_required[$tab->name]=$tab->fieldrequired; $this->attribute_required[$tab->name]=$tab->fieldrequired;
$this->attribute_param[$tab->name]=unserialize($tab->param); $this->attribute_param[$tab->name]=unserialize($tab->param);
$this->attribute_pos[$tab->name]=$tab->pos; $this->attribute_pos[$tab->name]=$tab->pos;
$this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
} }
} }

View File

@ -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> <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 --> <!-- 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> <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> </table>
<div align="center"><br><input type="submit" name="button" class="button" value="<?php echo $langs->trans("Save"); ?>"> &nbsp; <div align="center"><br><input type="submit" name="button" class="button" value="<?php echo $langs->trans("Save"); ?>"> &nbsp;

View File

@ -54,6 +54,7 @@ $size=$extrafields->attribute_size[$attrname];
$unique=$extrafields->attribute_unique[$attrname]; $unique=$extrafields->attribute_unique[$attrname];
$required=$extrafields->attribute_required[$attrname]; $required=$extrafields->attribute_required[$attrname];
$pos=$extrafields->attribute_pos[$attrname]; $pos=$extrafields->attribute_pos[$attrname];
$alwayseditable=$extrafields->attribute_alwayseditable[$attrname];
$param=$extrafields->attribute_param[$attrname]; $param=$extrafields->attribute_param[$attrname];
if((($type == 'select') || ($type == 'checkbox') ||(($type == 'radio'))) && is_array($param)) 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> <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 --> <!-- 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> <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> </table>

View File

@ -0,0 +1,83 @@
<?php
/* Copyright (C) 2014 Maxime Kohlhaas <support@atm-consulting.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*
* Need to have following variables defined:
* $object (invoice, order, ...)
* $conf
* $langs
*
* $cols
*/
//$res = $object->fetch_optionals($object->id, $extralabels);
$parameters = array('colspan' => ' colspan="'.$cols.'"', 'cols' => $cols, 'socid' => $object->fk_soc);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach ($extrafields->attribute_label as $key => $label)
{
if ($action == 'edit_extras')
{
$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
}
else
{
$value = $object->array_options ["options_" . $key];
}
if ($extrafields->attribute_type [$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td';
if (! empty($extrafields->attribute_required [$key])) print ' class="fieldrequired"';
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]);
}
if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key)
{
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
}
else
{
print $extrafields->showOutputField($key, $value);
}
print '</td></tr>' . "\n";
}
}
}

View File

@ -1330,49 +1330,9 @@ else if ($id > 0 || ! empty($ref))
// Statut // Statut
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
// Other attributes (TODO Move this into an include) // Other attributes
$parameters=array('colspan' => ' colspan="3"'); $cols = 3;
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key=>$label)
{
if ($action == 'edit_extras') {
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
} else {
$value=$object->array_options["options_".$key];
}
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
// 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]);
}
if ($action == 'edit_extras' && $user->rights->ficheinter->creer && GETPOST('attribute') == $key)
{
print '<input type="hidden" name="attribute" value="'.$key.'">';
print $extrafields->showInputField($key,$value);
print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
}
else
{
print $extrafields->showOutputField($key,$value);
if (($object->statut == 0 || $object->statut == 1) && $user->rights->ficheinter->creer) print ' &nbsp; <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras&attribute='.$key.'">'.img_picto('','edit').' '.$langs->trans('Modify').'</a>';
}
print '</td></tr>'."\n";
}
}
}
print "</table>"; print "</table>";

View File

@ -414,6 +414,15 @@ class FactureFournisseur extends CommonInvoice
$this->socid = $obj->socid; $this->socid = $obj->socid;
$this->socnom = $obj->socnom; $this->socnom = $obj->socnom;
// Retreive all extrafield
// fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
if ($this->statut == 0) $this->brouillon = 1;
$result=$this->fetch_lines(); $result=$this->fetch_lines();
if ($result < 0) if ($result < 0)
{ {

View File

@ -1484,78 +1484,9 @@ elseif (! empty($object->id))
print '</tr>'; print '</tr>';
} }
// Other attributes (TODO Move this into an include) // Other attributes
$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $cols = 3;
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key=>$label)
{
if ($action == 'edit_extras')
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
}
else
{
$value=$object->array_options["options_".$key];
}
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><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]);
}
if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
{
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print $extrafields->showInputField($key, $value);
print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
}
else
{
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->commande->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";
}
}
if(count($extrafields->attribute_label) > 0)
{
if ($action == 'edit_extras' && $user->rights->fournisseur->commande->creer)
{
print '<tr><td></td><td colspan="5">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else
{
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
}
// Ligne de 3 colonnes // Ligne de 3 colonnes
print '<tr><td>'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';

View File

@ -72,6 +72,10 @@ $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$hookmanager->initHooks(array('invoicesuppliercard','globalcard')); $hookmanager->initHooks(array('invoicesuppliercard','globalcard'));
$object=new FactureFournisseur($db); $object=new FactureFournisseur($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Load object // Load object
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
@ -1054,6 +1058,45 @@ elseif ($action == 'remove_file')
} }
} }
elseif ($action == 'update_extras')
{
// Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if($ret < 0) $error++;
if (!$error)
{
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('supplierorderdao'));
$parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$object->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
}
else
{
$action = 'edit_extras';
}
}
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
@ -1884,9 +1927,9 @@ else
print '</tr>'; print '</tr>';
} }
// Other options // Other attributes
$parameters=array('colspan' => ' colspan="4"'); $cols = 4;
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>'; print '</table>';

View File

@ -1097,3 +1097,5 @@ DELETE FROM llx_const WHERE name = 'MAIN_MODULE_BOUTIQUE';
DELETE FROM llx_const WHERE name = 'OSC_DB_HOST'; DELETE FROM llx_const WHERE name = 'OSC_DB_HOST';
DELETE FROM llx_menu WHERE module = 'boutique'; 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;

View File

@ -22,7 +22,7 @@ create table llx_extrafields
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
name varchar(64) NOT NULL, -- nom de l'attribut name varchar(64) NOT NULL, -- nom de l'attribut
entity integer DEFAULT 1 NOT NULL, -- multi company id entity integer DEFAULT 1 NOT NULL, -- multi company id
elementtype varchar(64) NOT NULL DEFAULT 'member', elementtype varchar(64) NOT NULL DEFAULT 'member',
tms timestamp, tms timestamp,
label varchar(255) NOT NULL, -- label correspondant a l'attribut label varchar(255) NOT NULL, -- label correspondant a l'attribut
type varchar(8), type varchar(8),
@ -30,5 +30,6 @@ create table llx_extrafields
fieldunique integer DEFAULT 0, fieldunique integer DEFAULT 0,
fieldrequired integer DEFAULT 0, fieldrequired integer DEFAULT 0,
pos integer DEFAULT 0, pos integer DEFAULT 0,
alwayseditable integer DEFAULT 0,
param text param text
)ENGINE=innodb; )ENGINE=innodb;