dolibarr/htdocs/core/class/html.formactions.class.php

240 lines
9.3 KiB
PHP
Raw Normal View History

2010-05-03 10:22:35 +02:00
<?php
2012-01-27 15:17:36 +01:00
/* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
2011-07-07 11:18:27 +02:00
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
2010-05-03 10:22:35 +02:00
*
* 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
2010-05-03 10:22:35 +02:00
* (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
2011-08-01 01:45:11 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-05-03 10:22:35 +02:00
*/
/**
2010-11-22 10:18:53 +01:00
* \file htdocs/core/class/html.formactions.class.php
* \ingroup core
* \brief Fichier de la classe des fonctions predefinie de composants html actions
*/
2010-05-03 10:22:35 +02:00
/**
2012-01-27 15:17:36 +01:00
* Class to manage building of HTML components
2010-11-22 10:18:53 +01:00
*/
2010-05-03 10:22:35 +02:00
class FormActions
{
2010-11-22 10:18:53 +01:00
var $db;
var $error;
/**
2011-09-11 20:35:38 +02:00
* Constructor
*
2012-01-27 15:17:36 +01:00
* @param DoliDB $db Database handler
2010-11-22 10:18:53 +01:00
*/
function __construct($db)
2010-11-22 10:18:53 +01:00
{
2012-01-27 15:17:36 +01:00
$this->db = $db;
2010-11-22 10:18:53 +01:00
return 1;
}
/**
2012-01-27 15:17:36 +01:00
* Show list of action status
2011-09-11 20:35:38 +02:00
*
2012-01-27 15:17:36 +01:00
* @param string $formname Name of form where select in included
2012-09-02 14:11:07 +02:00
* @param string $selected Preselected value (-1..100)
2012-01-27 15:17:36 +01:00
* @param int $canedit 1=can edit, 0=read only
* @param string $htmlname Name of html prefix for html fields (selectX and valX)
* @return void
2010-11-22 10:18:53 +01:00
*/
function form_select_status_action($formname,$selected,$canedit=1,$htmlname='complete')
2010-11-22 10:18:53 +01:00
{
global $langs,$conf;
2012-08-20 02:42:56 +02:00
$listofstatus = array(
'-1' => $langs->trans("ActionNotApplicable"),
'0' => $langs->trans("ActionRunningNotStarted"),
'50' => $langs->trans("ActionRunningShort"),
'100' => $langs->trans("ActionDoneShort")
);
2010-11-22 10:18:53 +01:00
2012-08-20 09:40:59 +02:00
if (! empty($conf->use_javascript_ajax))
2010-11-22 10:18:53 +01:00
{
print "\n";
2012-08-20 02:42:56 +02:00
print "<script type=\"text/javascript\">
var htmlname = '".$htmlname."';
2012-08-20 09:40:59 +02:00
$(document).ready(function () {
select_status();
$('#select' + htmlname).change(function() {
2012-08-20 02:42:56 +02:00
select_status();
});
2012-08-20 09:40:59 +02:00
// FIXME use another method for update combobox
//$('#val' + htmlname).change(function() {
//select_status();
//});
2012-08-20 02:42:56 +02:00
});
function select_status() {
var defaultvalue = $('#select' + htmlname).val();
2012-08-20 09:40:59 +02:00
var percentage = $('input[name=percentage]');
var selected = '".(isset($selected)?$selected:'')."';
var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
percentage.val(value);
if (defaultvalue == -1) {
2012-08-20 09:40:59 +02:00
percentage.attr('disabled', 'disabled');
$('.hideifna').hide();
2012-08-20 02:42:56 +02:00
}
else if (defaultvalue == 0) {
2012-09-02 14:11:07 +02:00
percentage.val(0);
percentage.attr('disabled', 'disabled');
2012-08-20 09:40:59 +02:00
$('.hideifna').show();
2012-08-20 02:42:56 +02:00
}
else if (defaultvalue == 100) {
2012-09-02 14:11:07 +02:00
percentage.val(100);
2012-08-20 09:40:59 +02:00
percentage.attr('disabled', 'disabled');
$('.hideifna').show();
2012-08-20 02:42:56 +02:00
}
else {
2012-09-02 14:11:07 +02:00
if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
percentage.removeAttr('disabled');
2012-08-20 09:40:59 +02:00
$('.hideifna').show();
2012-08-20 02:42:56 +02:00
}
}
</script>\n";
2011-08-31 17:12:09 +02:00
print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">';
2010-11-22 10:18:53 +01:00
foreach($listofstatus as $key => $val)
{
print '<option value="'.$key.'"'.(($selected == $key) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected="selected"' : '').'>'.$val.'</option>';
2010-11-22 10:18:53 +01:00
}
print '</select>';
if ($selected == 0 || $selected == 100) $canedit=0;
2012-08-20 09:40:59 +02:00
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>';
2010-11-22 10:18:53 +01:00
}
else
{
2011-08-31 17:12:09 +02:00
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled="disabled"').'>%';
2010-11-22 10:18:53 +01:00
}
}
/**
2012-01-27 15:17:36 +01:00
* Show list of actions for element
2012-01-29 23:24:47 +01:00
*
2012-01-27 15:17:36 +01:00
* @param Object $object Object
* @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
* @param int $socid socid of user
2013-02-11 20:26:01 +01:00
* @param int $forceshowtitle Show title even if there is no actions to show
2012-01-27 15:17:36 +01:00
* @return int <0 if KO, >=0 if OK
2010-11-22 10:18:53 +01:00
*/
2013-02-11 20:26:01 +01:00
function showactions($object,$typeelement,$socid=0,$forceshowtitle=0)
2010-11-22 10:18:53 +01:00
{
global $langs,$conf,$user;
global $bc;
2011-07-07 23:56:20 +02:00
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
$listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement);
2013-01-07 23:20:00 +01:00
if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
2011-07-07 23:56:20 +02:00
$num = count($listofactions);
2013-02-11 20:26:01 +01:00
if ($num || $forceshowtitle)
2010-11-22 10:18:53 +01:00
{
2011-07-07 23:56:20 +02:00
if ($typeelement == '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 == '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 == 'shipping') $title=$langs->trans('ActionsOnShipping');
elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
else $title=$langs->trans("Actions");
2011-06-19 17:10:32 +02:00
print_titre($title);
2011-07-07 23:56:20 +02:00
2011-06-19 17:10:32 +02:00
$total = 0; $var=true;
2012-01-31 12:18:43 +01:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th class="liste_titre">'.$langs->trans('Ref').'</th>';
print '<th class="liste_titre">'.$langs->trans('Action').'</th>';
print '<th class="liste_titre">'.$langs->trans('Date').'</th>';
print '<th class="liste_titre">'.$langs->trans('By').'</th>';
print '</tr>';
2011-06-19 17:10:32 +02:00
print "\n";
2011-06-20 12:40:25 +02:00
$userstatic = new User($this->db);
foreach($listofactions as $action)
2011-06-19 17:10:32 +02:00
{
$savlabel=$action->label;
$action->label=$action->ref;
$ref=$action->getNomUrl(1);
$action->label=$savlabel;
$label=$action->getNomUrl(0,38);
2011-06-19 17:10:32 +02:00
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$ref.'</td>';
print '<td>'.$label.'</td>';
2011-06-19 17:10:32 +02:00
print '<td>'.dol_print_date($action->datep,'day').'</td>';
2013-03-13 17:34:54 +01:00
print '<td>';
if (! empty($action->author->id))
{
$userstatic->id = $action->author->id;
$userstatic->firstname = $action->author->firstname;
$userstatic->lastname = $action->author->lastname;
print $userstatic->getNomUrl(1);
}
print '</td>';
2011-06-19 17:10:32 +02:00
print '</tr>';
}
print '</table>';
2010-11-22 10:18:53 +01:00
}
2011-07-07 23:56:20 +02:00
2011-06-19 17:10:32 +02:00
return $num;
2010-11-22 10:18:53 +01:00
}
/**
2012-01-27 15:17:36 +01:00
* Output list of type of event
2012-01-29 23:24:47 +01:00
*
* @param string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'
2012-09-20 00:42:51 +02:00
* @param string $htmlname Nom champ formulaire
* @param string $excludetype Type to exclude
* @param string $onlyautoornot Group list by auto events or not: We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
2012-01-27 15:17:36 +01:00
* @return void
2010-11-22 10:18:53 +01:00
*/
function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0)
2010-11-22 10:18:53 +01:00
{
global $langs,$user;
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
2010-11-22 10:18:53 +01:00
$caction=new CActionComm($this->db);
$form=new Form($this->db);
// Suggest a list with manual events or all auto events
$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
array_unshift($arraylist,'&nbsp;'); // Add empty line at start
//asort($arraylist);
2010-11-22 10:18:53 +01:00
if ($selected == 'manual') $selected='AC_OTH';
2013-06-05 16:24:32 +02:00
if ($selected == 'auto') $selected='AC_OTH_AUTO';
2010-11-22 10:18:53 +01:00
print $form->selectarray($htmlname, $arraylist, $selected);
if ($user->admin && empty($onlyautoornot)) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
2010-11-22 10:18:53 +01:00
}
2010-05-03 10:22:35 +02:00
}