Skip to content

Commit

Permalink
Fix: change 'editfieldkey' and 'editfieldval' for compatibility with
Browse files Browse the repository at this point in the history
external module and hook system.
Fix: uniform code
  • Loading branch information
hregis committed Nov 8, 2011
1 parent da27a55 commit cbec43e
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 498 deletions.
230 changes: 116 additions & 114 deletions htdocs/comm/fiche.php

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions htdocs/comm/mailing/fiche.php
Expand Up @@ -722,18 +722,18 @@
print '</td></tr>';

// Description
print '<tr><td>'.$form->editfieldkey("MailTitle",'desc',$mil->titre,'id',$mil->id,$user->rights->mailing->creer).'</td><td colspan="3">';
print $form->editfieldval("MailTitle",'desc',$mil->titre,'id',$mil->id,$user->rights->mailing->creer);
print '<tr><td>'.$form->editfieldkey("MailTitle",'desc',$mil->titre,$mil,$user->rights->mailing->creer).'</td><td colspan="3">';
print $form->editfieldval("MailTitle",'desc',$mil->titre,$mil,$user->rights->mailing->creer);
print '</td></tr>';

// From
print '<tr><td>'.$form->editfieldkey("MailFrom",'from',$mil->email_from,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
print $form->editfieldval("MailFrom",'from',$mil->email_from,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email');
print '<tr><td>'.$form->editfieldkey("MailFrom",'from',$mil->email_from,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
print $form->editfieldval("MailFrom",'from',$mil->email_from,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email');
print '</td></tr>';

// Errors to
print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'errorsto',$mil->email_errorsto,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
print $form->editfieldval("MailErrorsTo",'errorsto',$mil->email_errorsto,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email');
print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'errorsto',$mil->email_errorsto,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
print $form->editfieldval("MailErrorsTo",'errorsto',$mil->email_errorsto,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email');
print '</td></tr>';

// Status
Expand Down
20 changes: 10 additions & 10 deletions htdocs/compta/deplacement/fiche.php
Expand Up @@ -381,9 +381,9 @@

// Type
print '<tr><td>';
print $form->editfieldkey("Type",'type',$langs->trans($object->type),'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
print '</td><td>';
print $form->editfieldval("Type",'type',$langs->trans($object->type),'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
print $form->editfieldval("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
print '</td></tr>';

// Who
Expand All @@ -395,16 +395,16 @@

// Date
print '<tr><td>';
print $form->editfieldkey("Date",'dated',$object->date,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
print '</td><td>';
print $form->editfieldval("Date",'dated',$object->date,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
print '</td></tr>';

// Km/Price
print '<tr><td valign="top">';
print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
print '</td><td>';
print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
print "</td></tr>";

// Where
Expand Down Expand Up @@ -448,18 +448,18 @@

// Public note
print '<tr><td valign="top">';
print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print '</td><td>';
print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print "</td></tr>";

// Private note
if (! $user->societe_id)
{
print '<tr><td valign="top">';
print $form->editfieldkey("NotePrivate",'note',$object->note_private,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print $form->editfieldkey("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print '</td><td>';
print $form->editfieldval("NotePrivate",'note',$object->note_private,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print $form->editfieldval("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
print "</td></tr>";
}

Expand Down
12 changes: 6 additions & 6 deletions htdocs/compta/paiement/fiche.php
Expand Up @@ -219,25 +219,25 @@
print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';

// Date payment
print '<tr><td valign="top">'.$form->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
print $form->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement,'day');
print '<tr><td valign="top">'.$form->editfieldkey("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
print $form->editfieldval("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement,'day');
print '</td></tr>';

// Payment type (VIR, LIQ, ...)
$labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle;
print '<tr><td valign="top">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';

// Payment numero
print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
print $form->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
print $form->editfieldval("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
print '</td></tr>';

// Amount
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';

// Note
print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
print $form->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement,'text');
print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
print $form->editfieldval("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement,'text');
print '</td></tr>';

// Bank account
Expand Down
14 changes: 12 additions & 2 deletions htdocs/core/ajax/loadinplace.php
Expand Up @@ -66,8 +66,18 @@
$cachename = 'cache_'.GETPOST('method');

$form = new Form($db);
$ret = $form->$methodname();
if ($ret > 0) echo json_encode($form->$cachename);
if (method_exists($form, $methodname))
{
$ret = $form->$methodname();
if ($ret > 0) echo json_encode($form->$cachename);
}
else
{
dol_include_once('/'.$element.'/class/'.$element.'.class.php');
$classname = ucfirst($element);
$object = new $classname($db);
print_r($object);
}
}
else
{
Expand Down
50 changes: 26 additions & 24 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -68,16 +68,15 @@ function Form($DB)
/**
* Output key field for an editable field
*
* @param string $text Text of label or key to translate
* @param string $htmlname Name of select field
* @param string $preselected Value to show/edit
* @param string $paramkey Key of parameter for Url (unique if there is several parameter to show). In most cases "id".
* @param string $paramvalue Value of parameter for Url
* @param boolean $perm Permission to allow button to edit parameter
* @param string $text Text of label or key to translate
* @param string $htmlname Name of select field
* @param string $preselected Name of Value to show/edit (not used in this function)
* @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
* @return string HTML edit field
* @return string HTML edit field
*/
function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
function editfieldkey($text,$htmlname,$preselected,$object,$perm,$typeofdata='string')
{
global $conf,$langs;

Expand All @@ -102,7 +101,7 @@ function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
}

Expand All @@ -115,21 +114,21 @@ function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$
* @param string $text Text of label (not used in this function)
* @param string $htmlname Name of select field
* @param string $value Value to show/edit
* @param string $paramkey Key of parameter (unique if there is several parameter to show). In most cases "id".
* @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
* @param string $editvalue When in edit mode, use this value as $value instead of value
* @return string HTML edit field
* @return string HTML edit field
*/
function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='')
{
global $conf,$langs,$db;
$ret='';

// When option to edit inline is activated
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
{
$ret.=$this->editInPlace($value, $htmlname, $perm, $typeofdata);
$ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata);
}
else
{
Expand All @@ -139,7 +138,7 @@ function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeof
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
$ret.='<input type="hidden" name="id" value="'.$object->id.'">';
$ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$ret.='<tr><td>';
if (preg_match('/^(string|email|numeric)/',$typeofdata))
Expand All @@ -153,7 +152,7 @@ function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeof
}
else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
{
$ret.=$this->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$value,$htmlname);
$ret.=$this->form_date($_SERVER['PHP_SELF'].($objectkey?'?id='.$object->id:''),$value,$htmlname);
}
else if (preg_match('/^ckeditor/',$typeofdata))
{
Expand Down Expand Up @@ -189,13 +188,14 @@ function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeof
/**
* Output edit in place form
*
* @param object $object Object
* @param string $value Value to show/edit
* @param string $htmlname DIV ID (field name)
* @param int $condition Condition to edit
* @param string $inputType Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx')
* @return string HTML edit in place
*/
private function editInPlace($value, $htmlname, $condition, $inputType='textarea')
private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea')
{
global $conf;

Expand All @@ -206,7 +206,7 @@ private function editInPlace($value, $htmlname, $condition, $inputType='textarea
else if (preg_match('/^numeric/',$inputType)) $value = price($value);
else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day');

if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && $condition)
if ($condition)
{
if (preg_match('/^(string|email|numeric)/',$inputType))
{
Expand All @@ -215,31 +215,33 @@ private function editInPlace($value, $htmlname, $condition, $inputType='textarea
}
if ($inputType == 'datepicker')
{
$out.= '<input id="timeStamp" type="hidden"/>'; // Use for timestamp format
$out.= '<input id="timestamp_'.$htmlname.'" type="hidden"/>'."\n"; // Use for timestamp format
}
else if (preg_match('/^select/',$inputType))
{
$tmp=explode(':',$inputType);
$inputType=$tmp[0]; $inputOption=$tmp[1];
$out.= '<input id="loadmethod" value="'.$inputOption.'" type="hidden"/>';
$out.= '<input id="loadmethod_'.$htmlname.'" value="'.$inputOption.'" type="hidden"/>'."\n";
}
else if (preg_match('/^ckeditor/',$inputType))
{
$tmp=explode(':',$inputType);
$inputType=$tmp[0]; $inputOption=$tmp[1];
if (! empty($conf->fckeditor->enabled))
{
$out.= '<input id="toolbar" value="'.$inputOption.'" type="hidden"/>';
$out.= '<input id="ckeditor_toolbar" value="'.$inputOption.'" type="hidden"/>'."\n";
}
else
{
$inputType = 'textarea';
}
}

$out.= '<div class="editval_'.$inputType.'" id="val_'.$htmlname.'">';
$out.= $value;
$out.= '</div>'."\n";

$out.= '<input id="element_'.$htmlname.'" value="'.$object->element.'" type="hidden">'."\n";
$out.= '<input id="table_element_'.$htmlname.'" value="'.$object->table_element.'" type="hidden">'."\n";
$out.= '<input id="fk_element_'.$htmlname.'" value="'.$object->id.'" type="hidden">'."\n";

$out.= '<div id="val_'.$htmlname.'" class="editval_'.$inputType.'">'.$value.'</div>'."\n";
}
else
{
Expand Down

0 comments on commit cbec43e

Please sign in to comment.