Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2012-11-27 09:34:34 +01:00
commit 6c9d6eda56
7 changed files with 100 additions and 56 deletions

View File

@ -115,7 +115,8 @@ class HookManager
* @param Object &$object Object to use hooks on * @param Object &$object Object to use hooks on
* @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* @return mixed For doActions,formObjectOptions: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO. * @return mixed For doActions,formObjectOptions: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO.
* For printSearchForm,printLeftBlock,printTopRightMenu,...: Return HTML string. * For printSearchForm,printLeftBlock,printTopRightMenu,formAddObjectLine,...: Return HTML string. TODO Must always return an int and things to print into ->resprints.
* Can also return some values into an array ->results.
* $this->error or this->errors are also defined by class called by this function if error. * $this->error or this->errors are also defined by class called by this function if error.
*/ */
function executeHooks($method, $parameters=false, &$object='', &$action='') function executeHooks($method, $parameters=false, &$object='', &$action='')
@ -127,45 +128,58 @@ class HookManager
// Loop on each hook to qualify modules that declared context // Loop on each hook to qualify modules that declared context
$modulealreadyexecuted=array(); $modulealreadyexecuted=array();
$resaction=0; $resprint=''; $resaction=0; $error=0;
$this->resPrint=''; $this->resArray=array();
foreach($this->hooks as $modules) // this->hooks is an array with context as key and value is an array of modules that handle this context foreach($this->hooks as $modules) // this->hooks is an array with context as key and value is an array of modules that handle this context
{ {
if (! empty($modules)) if (! empty($modules))
{ {
foreach($modules as $module => $actionclassinstance) foreach($modules as $module => $actionclassinstance)
{ {
// test to avoid to run twice a hook, when a module implements several active contexts // jump to next class if method does not exists
if (! method_exists($actionclassinstance,$method)) continue;
// test to avoid to run twice a hook, when a module implements several active contexts
if (in_array($module,$modulealreadyexecuted)) continue; if (in_array($module,$modulealreadyexecuted)) continue;
$modulealreadyexecuted[$module]=$module; $modulealreadyexecuted[$module]=$module;
// Hooks that return int // Hooks that return int
if (($method == 'doActions' || $method == 'formObjectOptions') && method_exists($actionclassinstance,$method)) if (($method == 'doActions' || $method == 'formObjectOptions'))
{ {
$resaction+=$actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) $resaction+=$actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0)) if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
{ {
$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors); $error++;
if ($method == 'doActions') $this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
{ // TODO remove this. Change must be inside the method if required
if ($action=='add') $action='create'; // TODO this change must be inside the doActions if ($method == 'doActions')
if ($action=='update') $action='edit'; // TODO this change must be inside the doActions {
} if ($action=='add') $action='create';
} if ($action=='update') $action='edit';
}
}
} }
// Generic hooks that return a string (printSearchForm, printLeftBlock, formBuilddocOptions, ...) // Generic hooks that return a string (printSearchForm, printLeftBlock, printTopRightMenu, formAddObjectLine, formBuilddocOptions, ...)
else if (method_exists($actionclassinstance,$method)) else
{ {
if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue; // TODO. this should be done into the method by returning nothing
if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
$result = $actionclassinstance->$method($parameters, $object, $action, $this); $result = $actionclassinstance->$method($parameters, $object, $action, $this);
if (is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
// TODO. remove this. array result must be set into $actionclassinstance->results
if (is_array($result)) $this->resArray = array_merge($this->resArray, $result); if (is_array($result)) $this->resArray = array_merge($this->resArray, $result);
else $resprint.=$result; // TODO. remove this. result must not be a string. we must use $actionclassinstance->resprint to return a string
if (! is_array($result) && ! is_numeric($result)) $this->resPrint.=$result;
} }
} }
} }
} }
if ($method == 'doActions' || $method == 'formObjectOptions') return $resaction; if ($method != 'doActions' && $method != 'formObjectOptions') return $this->resPrint; // TODO remove this. When there is something to print, ->resPrint is filled.
return $resprint; return ($error?-1:$resaction);
} }
} }

View File

@ -1447,7 +1447,8 @@ class Form
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$outselect.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; //$outselect.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax
$outselect.='<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
if (! $selected) $outselect.='<option value="0" selected="selected">&nbsp;</option>'; if (! $selected) $outselect.='<option value="0" selected="selected">&nbsp;</option>';
else $outselect.='<option value="0">&nbsp;</option>'; else $outselect.='<option value="0">&nbsp;</option>';

View File

@ -49,8 +49,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
// Remove product id before select another product // Remove product id before select another product
// use keyup instead change to avoid loosing the product id // use keyup instead change to avoid loosing the product id
$("input#search_'.$htmlname.'").keyup(function() { $("input#search_'.$htmlname.'").keydown(function() {
$("#'.$htmlname.'").val("").trigger("change"); //console.log(\'purge_id_after_keydown\');
$("#'.$htmlname.'").val("");
});
$("input#search_'.$htmlname.'").change(function() {
//console.log(\'keyup\');
$("#'.$htmlname.'").trigger("change");
}); });
// Check when keyup // Check when keyup
$("input#search_'.$htmlname.'").onDelayedKeyup({ handler: function() { $("input#search_'.$htmlname.'").onDelayedKeyup({ handler: function() {
@ -116,6 +121,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
dataType: "json", dataType: "json",
minLength: '.$minLength.', minLength: '.$minLength.',
select: function( event, ui ) { select: function( event, ui ) {
//console.log(\'set value of id with \'+ui.item.id);
$("#'.$htmlname.'").val(ui.item.id).trigger("change"); $("#'.$htmlname.'").val(ui.item.id).trigger("change");
// Disable an element // Disable an element
if (options.option_disabled) { if (options.option_disabled) {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -42,14 +42,13 @@
<td align="right"><?php echo $langs->trans('ReductionShort'); ?></td> <td align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
<?php <?php
$colspan = 4; $colspan = 4;
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled))
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
?> ?>
<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td> <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
<?php <?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
$colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES))
$colspan++;
} }
?> ?>
<td colspan="<?php echo $colspan; ?>">&nbsp;</td> <td colspan="<?php echo $colspan; ?>">&nbsp;</td>
@ -63,7 +62,7 @@ if (! empty($conf->margin->enabled)) {
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
jQuery('#idprod').change(function() { jQuery('#idprod').change(function() {
jQuery('#np_desc').focus(); if (jQuery('#idprod').val() > 0) jQuery('#np_desc').focus();
}); });
}); });
</script> </script>
@ -97,17 +96,16 @@ jQuery(document).ready(function() {
<td align="right" nowrap><input type="text" size="1" name="remise_percent" value="<?php echo $buyer->remise_client; ?>">%</td> <td align="right" nowrap><input type="text" size="1" name="remise_percent" value="<?php echo $buyer->remise_client; ?>">%</td>
<?php <?php
$colspan = 4; $colspan = 4;
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled))
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
?> ?>
<td align="right"> <td align="right">
<select id="fournprice" name="fournprice" style="display: none;"></select> <select id="fournprice" name="fournprice" style="display: none;"></select>
<input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>"> <input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td> </td>
<?php <?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
$colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES))
$colspan++;
} }
?> ?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"> <td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
@ -115,18 +113,17 @@ if (! empty($conf->margin->enabled)) {
</td> </td>
</tr> </tr>
<?php if (! empty($conf->service->enabled) && $dateSelector) { <?php
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) if (! empty($conf->service->enabled) && $dateSelector)
$colspan = 10; {
else if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10;
$colspan = 9; else $colspan = 9;
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled))
$colspan++; // For the buying price {
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; // For the buying price
$colspan++; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
$colspan++; }
}
?> ?>
<tr <?php echo $bcnd[$var]; ?>> <tr <?php echo $bcnd[$var]; ?>>
<td colspan="<?php echo $colspan; ?>"> <td colspan="<?php echo $colspan; ?>">
@ -138,11 +135,15 @@ if (! empty($conf->margin->enabled)) {
?> ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php
}
?>
</form> </form>
<?php <?php
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled))
{
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$("#idprod").change(function() { $("#idprod").change(function() {
@ -177,5 +178,7 @@ $("#idprod").change(function() {
'json'); 'json');
}); });
</script> </script>
<?php } ?> <?php
}
?>
<!-- END PHP TEMPLATE predefinedproductline_create.tpl.php --> <!-- END PHP TEMPLATE predefinedproductline_create.tpl.php -->

View File

@ -1461,12 +1461,22 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';
// TODO Use the predefinedproductline_create.tpl.php file
// Add free products/services form // Add free products/services form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">'; print '<input type="hidden" name="action" value="addline">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
$var=true; $var=true;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';

View File

@ -1814,10 +1814,20 @@ else
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';
// TODO Use the predefinedproductline_create.tpl.php file
print '<form name="addline_predef" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">'; print '<form name="addline_predef" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="'. $object->socid .'">'; print '<input type="hidden" name="socid" value="'. $object->socid .'">';
print '<input type="hidden" name="facid" value="'.$object->id.'">'; print '<input type="hidden" name="facid" value="'.$object->id.'">';
print '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#idprodfournprice\').change(function() {
if (jQuery(\'#idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</script>';
$var=! $var; $var=! $var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="4">'; print '<td colspan="4">';

View File

@ -1121,7 +1121,7 @@ else
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Name // Name
print '<tr><td><span class="fieldrequired">'.$langs->trans('ThirdPartyName').'</span></td><td colspan="3"><input type="text" size="40" maxlength="60" name="nom" value="'.$object->name.'"></td></tr>'; print '<tr><td><span class="fieldrequired">'.$langs->trans('ThirdPartyName').'</span></td><td colspan="3"><input type="text" size="40" maxlength="60" name="nom" value="'.dol_escape_htmltag($object->name).'"></td></tr>';
// Prefix // Prefix
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
@ -1130,12 +1130,12 @@ else
// It does not change the prefix mode using the auto numbering prefix // It does not change the prefix mode using the auto numbering prefix
if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
{ {
print '<input type="hidden" name="prefix_comm" value="'.$object->prefix_comm.'">'; print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
print $object->prefix_comm; print $object->prefix_comm;
} }
else else
{ {
print '<input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'">'; print '<input type="text" size="5" maxlength="5" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
} }
print '</td>'; print '</td>';
} }