Fix: edit of percentage

Conflicts:
	htdocs/comm/action/fiche.php
This commit is contained in:
Laurent Destailleur 2012-09-02 14:27:00 +02:00
parent d12700aeab
commit a7d6289d4b
2 changed files with 183 additions and 155 deletions

View File

@ -85,13 +85,14 @@ if ($action == 'add_action')
} }
$fulldayevent=$_POST["fullday"]; $fulldayevent=$_POST["fullday"];
$percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):GETPOST("percentage"); // If status is -1 or 100, percentage is not defined and we must use status
// Clean parameters // Clean parameters
$datep=dol_mktime($fulldayevent?'00':$_POST["aphour"], $fulldayevent?'00':$_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datep=dol_mktime($fulldayevent?'00':$_POST["aphour"], $fulldayevent?'00':$_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]);
$datef=dol_mktime($fulldayevent?'23':$_POST["p2hour"], $fulldayevent?'59':$_POST["p2min"], $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); $datef=dol_mktime($fulldayevent?'23':$_POST["p2hour"], $fulldayevent?'59':$_POST["p2min"], $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]);
// Check parameters // Check parameters
if (! $datef && $_POST["percentage"] == 100) if (! $datef && $percentage == 100)
{ {
$error++; $error++;
$action = 'create'; $action = 'create';
@ -135,7 +136,7 @@ if ($action == 'add_action')
$actioncomm->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0; $actioncomm->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0;
$actioncomm->datep = $datep; $actioncomm->datep = $datep;
$actioncomm->datef = $datef; $actioncomm->datef = $datef;
$actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0; $actioncomm->percentage = $percentage;
$actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60; $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60;
$usertodo=new User($db); $usertodo=new User($db);
@ -257,21 +258,20 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
} }
/* /*
* Action mise a jour de l'action * Action update event
*/ */
if ($action == 'update') if ($action == 'update')
{ {
if (! $_POST["cancel"]) if (! $_POST["cancel"])
{ {
$fulldayevent=$_POST["fullday"]; $fulldayevent=$_POST["fullday"];
$percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):GETPOST("percentage"); // If status is -1 or 100, percentage is not defined and we must use status
// Clean parameters // Clean parameters
if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["aphour"] == -1) $_POST["aphour"]='0';
if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0';
if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0'; if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0';
if ($_POST["p2min"] == -1) $_POST["p2min"]='0'; if ($_POST["p2min"] == -1) $_POST["p2min"]='0';
//if ($_POST["adhour"] == -1) $_POST["adhour"]='0';
//if ($_POST["admin"] == -1) $_POST["admin"]='0';
$actioncomm = new Actioncomm($db); $actioncomm = new Actioncomm($db);
$actioncomm->fetch($id); $actioncomm->fetch($id);
@ -282,9 +282,7 @@ if ($action == 'update')
$actioncomm->label = $_POST["label"]; $actioncomm->label = $_POST["label"];
$actioncomm->datep = $datep; $actioncomm->datep = $datep;
$actioncomm->datef = $datef; $actioncomm->datef = $datef;
//$actioncomm->date = $datea; $actioncomm->percentage = $percentage;
//$actioncomm->dateend = $datea2;
$actioncomm->percentage = $_POST["percentage"];
$actioncomm->priority = $_POST["priority"]; $actioncomm->priority = $_POST["priority"];
$actioncomm->fulldayevent= $_POST["fullday"]?1:0; $actioncomm->fulldayevent= $_POST["fullday"]?1:0;
$actioncomm->location = isset($_POST["location"])?$_POST["location"]:''; $actioncomm->location = isset($_POST["location"])?$_POST["location"]:'';
@ -294,7 +292,7 @@ if ($action == 'update')
$actioncomm->note = $_POST["note"]; $actioncomm->note = $_POST["note"];
$actioncomm->pnote = $_POST["note"]; $actioncomm->pnote = $_POST["note"];
if (! $datef && $_POST["percentage"] == 100) if (! $datef && $percentage == 100)
{ {
$error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd")); $error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd"));
$action = 'edit'; $action = 'edit';

View File

@ -1,185 +1,215 @@
<?php <?php
/* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file htdocs/core/class/html.formactions.class.php * \file htdocs/core/class/html.formactions.class.php
* \ingroup core * \ingroup core
* \brief Fichier de la classe des fonctions predefinie de composants html actions * \brief Fichier de la classe des fonctions predefinie de composants html actions
*/ */
/** /**
* Class to manage building of HTML components * Class to manage building of HTML components
*/ */
class FormActions class FormActions
{ {
var $db; var $db;
var $error; var $error;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
*/ */
function FormActions($db) function FormActions($db)
{ {
$this->db = $db; $this->db = $db;
return 1; return 1;
} }
/** /**
* Show list of action status * Show list of action status
* *
* @param string $formname Name of form where select in included * @param string $formname Name of form where select in included
* @param string $selected Preselected value * @param string $selected Preselected value (-1..100)
* @param int $canedit 1=can edit, 0=read only * @param int $canedit 1=can edit, 0=read only
* @param string $htmlname Name of html prefix for html fields (selectX and valX) * @param string $htmlname Name of html prefix for html fields (selectX and valX)
* @return void * @return void
*/ */
function form_select_status_action($formname,$selected,$canedit=1,$htmlname='complete') function form_select_status_action($formname,$selected,$canedit=1,$htmlname='complete')
{ {
global $langs,$conf; global $langs,$conf;
$listofstatus=array('-1'=>$langs->trans("ActionNotApplicable"), $listofstatus = array(
'0'=>$langs->trans("ActionRunningNotStarted"), '-1' => $langs->trans("ActionNotApplicable"),
'50'=>$langs->trans("ActionRunningShort"), '0' => $langs->trans("ActionRunningNotStarted"),
'100'=>$langs->trans("ActionDoneShort")); '50' => $langs->trans("ActionRunningShort"),
'100' => $langs->trans("ActionDoneShort")
);
if ($conf->use_javascript_ajax) if (! empty($conf->use_javascript_ajax))
{ {
print "\n"; print "\n";
print '<script type="text/javascript">'."\n"; print "<script type=\"text/javascript\">
print 'jQuery(document).ready(function () {'."\n"; var htmlname = '".$htmlname."';
print 'jQuery("#select'.$htmlname.'").change(function() { select_status(document.'.$formname.'.status.value); });'."\n";
print 'jQuery("#val'.$htmlname.'").change(function() { select_status(jQuery("#val'.$htmlname.'").val()); });'."\n"; $(document).ready(function () {
print 'select_status(document.'.$formname.'.status.value);'."\n"; select_status();
print '});'."\n";
print 'function select_status(mypercentage) {'."\n"; $('#select' + htmlname).change(function() {
print 'document.'.$formname.'.percentageshown.value=(mypercentage>=0?mypercentage:\'\');'."\n"; select_status();
print 'document.'.$formname.'.percentage.value=mypercentage;'."\n"; });
print 'if (mypercentage == -1) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").hide(); }'."\n"; // FIXME use another method for update combobox
print 'else if (mypercentage == 0) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n"; //$('#val' + htmlname).change(function() {
print 'else if (mypercentage == 100) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n"; //select_status();
print 'else { document.'.$formname.'.percentageshown.disabled=false; jQuery(".hideifna").show();}'."\n"; //});
print '}'."\n"; });
print '</script>'."\n";
print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">'; function select_status() {
foreach($listofstatus as $key => $val) var defaultvalue = $('#select' + htmlname).val();
{ var percentage = $('input[name=percentage]');
print '<option value="'.$key.'"'.($selected == $key?' selected="selected"':'').'>'.$val.'</option>'; var selected = '".(isset($selected)?$selected:'')."';
} var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
print '</select>';
if ($selected == 0 || $selected == 100) $canedit=0; percentage.val(value);
print ' <input type="text" id="val'.$htmlname.'" name="percentageshown" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled="disabled"').'>';
print '<span class="hideifna">%</span>'; if (defaultvalue == -1) {
print ' <input type="hidden" name="percentage" value="'.$selected.'">'; percentage.attr('disabled', 'disabled');
} $('.hideifna').hide();
else }
{ else if (defaultvalue == 0) {
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled="disabled"').'>%'; percentage.val(0);
} percentage.attr('disabled', 'disabled');
} $('.hideifna').show();
}
else if (defaultvalue == 100) {
percentage.val(100);
percentage.attr('disabled', 'disabled');
$('.hideifna').show();
}
else {
if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
percentage.removeAttr('disabled');
$('.hideifna').show();
}
}
</script>\n";
print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">';
foreach($listofstatus as $key => $val)
{
print '<option value="'.$key.'"'.(($selected == $key) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected="selected"' : '').'>'.$val.'</option>';
}
print '</select>';
if ($selected == 0 || $selected == 100) $canedit=0;
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled="disabled"').'>';
print '<span class="hideifna">%</span>';
}
else
{
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled="disabled"').'>%';
}
}
/** /**
* Show list of actions for element * Show list of actions for element
* *
* @param Object $object Object * @param Object $object Object
* @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter' * @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
* @param int $socid socid of user * @param int $socid socid of user
* @return int <0 if KO, >=0 if OK * @return int <0 if KO, >=0 if OK
*/ */
function showactions($object,$typeelement,$socid=0) function showactions($object,$typeelement,$socid=0)
{ {
global $langs,$conf,$user; global $langs,$conf,$user;
global $bc; global $bc;
require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
$actioncomm = new ActionComm($this->db); $actioncomm = new ActionComm($this->db);
$actioncomm->getActions($socid, $object->id, $typeelement); $actioncomm->getActions($socid, $object->id, $typeelement);
$num = count($actioncomm->actions); $num = count($actioncomm->actions);
if ($num) if ($num)
{ {
if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill'); if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill'); elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal'); elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder'); elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder'); elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
elseif ($typeelement == 'project') $title=$langs->trans('ActionsOnProject'); elseif ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping'); elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter'); elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
else $title=$langs->trans("Actions"); else $title=$langs->trans("Actions");
print_titre($title); print_titre($title);
$total = 0; $var=true; $total = 0; $var=true;
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans('Ref').'</th><th class="liste_titre">'.$langs->trans('Date').'</th><th class="liste_titre">'.$langs->trans('Action').'</th><th class="liste_titre">'.$langs->trans('By').'</th></tr>'; print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans('Ref').'</th><th class="liste_titre">'.$langs->trans('Date').'</th><th class="liste_titre">'.$langs->trans('Action').'</th><th class="liste_titre">'.$langs->trans('By').'</th></tr>';
print "\n"; print "\n";
foreach($actioncomm->actions as $action) foreach($actioncomm->actions as $action)
{ {
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'.$action->getNomUrl(1).'</td>'; print '<td>'.$action->getNomUrl(1).'</td>';
print '<td>'.dol_print_date($action->datep,'day').'</td>'; print '<td>'.dol_print_date($action->datep,'day').'</td>';
print '<td title="'.dol_escape_htmltag($action->label).'">'.dol_trunc($action->label,32).'</td>'; print '<td title="'.dol_escape_htmltag($action->label).'">'.dol_trunc($action->label,32).'</td>';
$userstatic = new User($this->db); $userstatic = new User($this->db);
$userstatic->id = $action->author->id; $userstatic->id = $action->author->id;
$userstatic->firstname = $action->author->firstname; $userstatic->firstname = $action->author->firstname;
$userstatic->lastname = $action->author->lastname; $userstatic->lastname = $action->author->lastname;
print '<td>'.$userstatic->getNomUrl(1).'</td>'; print '<td>'.$userstatic->getNomUrl(1).'</td>';
print '</tr>'; print '</tr>';
} }
print '</table>'; print '</table>';
} }
return $num; return $num;
} }
/** /**
* Output list of type of event * Output list of type of event
* *
* @param string $selected Type pre-selectionne * @param string $selected Type pre-selectionne
* @param string $htmlname Nom champ formulaire * @param string $htmlname Nom champ formulaire
* @return void * @return void
*/ */
function select_type_actions($selected='',$htmlname='actioncode') function select_type_actions($selected='',$htmlname='actioncode')
{ {
global $langs,$user; global $langs,$user;
require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.form.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.form.class.php");
$caction=new CActionComm($this->db); $caction=new CActionComm($this->db);
$form=new Form($this->db); $form=new Form($this->db);
$arraylist=$caction->liste_array(1,'code'); $arraylist=$caction->liste_array(1,'code');
array_unshift($arraylist,'&nbsp;'); // Add empty line at start array_unshift($arraylist,'&nbsp;'); // Add empty line at start
//asort($arraylist); //asort($arraylist);
print $form->selectarray($htmlname, $arraylist, $selected); print $form->selectarray($htmlname, $arraylist, $selected);
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
} }
} }