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

364 lines
16 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>
* Copyright (C) 2010-2018 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
*
2014-06-26 20:24:00 +02:00
* @param string $formname Name of form where select is included
* @param string $selected Preselected value (-1..100)
* @param int $canedit 1=can edit, 0=read only
* @param string $htmlname Name of html prefix for html fields (selectX and valX)
* @param integer $showempty Show an empty line if select is used
* @param integer $onlyselect 0=Standard, 1=Hide percent of completion and force usage of a select list, 2=Same than 1 and add "Incomplete (Todo+Running)
2017-05-05 20:41:44 +02:00
* @param string $morecss More css on select field
2012-01-27 15:17:36 +01:00
* @return void
2010-11-22 10:18:53 +01:00
*/
2017-05-05 20:41:44 +02:00
function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
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"),
2016-10-30 12:39:51 +01:00
'0' => $langs->trans("ActionsToDoShort"),
2012-08-20 02:42:56 +02:00
'50' => $langs->trans("ActionRunningShort"),
'100' => $langs->trans("ActionDoneShort")
);
2014-06-26 20:24:00 +02:00
// +ActionUncomplete
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) {
percentage.prop('disabled', true);
2012-08-20 09:40:59 +02:00
$('.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);
2016-10-30 12:39:51 +01:00
percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
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);
percentage.prop('disabled', true);
2012-08-20 09:40:59 +02:00
$('.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";
2014-06-26 20:24:00 +02:00
}
if (! empty($conf->use_javascript_ajax) || $onlyselect)
{
//var_dump($selected);
if ($selected == 'done') $selected='100';
2017-05-05 20:41:44 +02:00
print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
2010-11-22 10:18:53 +01:00
foreach($listofstatus as $key => $val)
{
print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
2014-06-26 20:24:00 +02:00
if ($key == '50' && $onlyselect == 2)
{
2016-12-20 12:06:26 +01:00
print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
2014-06-26 20:24:00 +02:00
}
2010-11-22 10:18:53 +01:00
}
print '</select>';
if ($selected == 0 || $selected == 100) $canedit=0;
2014-06-26 20:24:00 +02:00
if (empty($onlyselect))
{
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
print '<span class="hideonsmartphone hideifna">%</span>';
2014-06-26 20:24:00 +02:00
}
2010-11-22 10:18:53 +01:00
}
else
2014-06-26 20:24:00 +02:00
{
print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' 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
*
* @param Object $object Object
* @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
* @param int $socid Socid of user
* @param int $forceshowtitle Show title even if there is no actions to show
* @param string $morecss More css on table
* @param int $max Max number of record
* @param string $moreparambacktopage More param for the backtopage
2017-10-04 12:58:13 +02:00
* @param string $morehtmlright More html text on right of title line
* @return int <0 if KO, >=0 if OK
2010-11-22 10:18:53 +01:00
*/
2017-10-04 12:58:13 +02:00
function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
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';
2017-11-25 16:05:45 +01:00
$sortfield='a.datep,a.id';
2017-11-25 16:21:44 +01:00
$sortorder='DESC,DESC';
$listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
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
{
if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
2011-07-07 23:56:20 +02:00
elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
2011-07-07 23:56:20 +02:00
elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
elseif ($typeelement == 'project') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
elseif ($typeelement == 'task') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
elseif ($typeelement == 'member') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
2017-09-23 12:59:49 +02:00
else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
2011-07-07 23:56:20 +02:00
$urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
$projectid = $object->fk_project;
if ($typeelement == 'project') $projectid = $object->id;
2018-04-18 02:10:23 +02:00
$newcardbutton='';
if (! empty($conf->agenda->enabled))
{
$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid>0?'&socid='.$object->socid:($socid>0?'&socid='.$socid:'')).($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
$newcardbutton.= '</a>';
}
2017-09-23 12:59:49 +02:00
print '<!-- formactions->showactions -->'."\n";
2018-04-18 02:10:23 +02:00
print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
2011-07-07 23:56:20 +02:00
$page=0; $param='';
2017-06-10 13:54:43 +02:00
$total = 0;
2017-09-23 12:59:49 +02:00
print '<div class="div-table-responsive-no-min">';
2016-04-07 13:06:22 +02:00
print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
print '<tr class="liste_titre">';
2017-11-14 01:57:50 +01:00
print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
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);
2017-09-23 12:59:49 +02:00
if (count($listofactions))
2011-06-19 17:10:32 +02:00
{
2017-09-23 12:59:49 +02:00
$cursorevent = 0;
foreach($listofactions as $action)
{
if ($max && $cursorevent >= $max) break;
$ref=$action->getNomUrl(1,-1);
$label=$action->getNomUrl(0,38);
print '<tr class="oddeven">';
2017-11-25 16:21:44 +01:00
// Ref
2017-09-23 12:59:49 +02:00
print '<td>'.$ref.'</td>';
2017-11-25 16:21:44 +01:00
// Onwer
2017-09-23 12:59:49 +02:00
print '<td>';
2017-10-04 12:58:13 +02:00
if (! empty($action->userownerid))
{
$userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
}
print '</td>';
2017-11-25 16:21:44 +01:00
// Type
print '<td>';
$imgpicto='';
if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
{
if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
else {
if ($action->type_code == 'AC_RDV') $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
elseif ($action->type_code == 'AC_TEL') $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
elseif ($action->type_code == 'AC_FAX') $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
elseif ($action->type_code == 'AC_INT') $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
}
}
print $imgpicto;
print $action->type_short ? $action->type_short : $action->type;
2017-09-23 12:59:49 +02:00
print '</td>';
2017-11-25 16:21:44 +01:00
// Label
2017-10-04 12:58:13 +02:00
print '<td>'.$label.'</td>';
2017-11-25 16:21:44 +01:00
// Date
2017-10-29 17:50:50 +01:00
print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
2017-09-23 12:59:49 +02:00
if ($action->datef)
{
$tmpa=dol_getdate($action->datep);
$tmpb=dol_getdate($action->datef);
if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
{
2017-10-29 17:50:50 +01:00
if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
2017-09-23 12:59:49 +02:00
}
2017-10-29 17:49:24 +01:00
else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
2017-09-23 12:59:49 +02:00
}
print '</td>';
print '<td align="right">';
if (! empty($action->author->id))
{
print $action->getLibStatut(3);
}
print '</td>';
print '</tr>';
$cursorevent++;
}
}
else
{
print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2011-06-19 17:10:32 +02:00
}
if ($max && $num > $max)
{
2017-09-23 12:59:49 +02:00
print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
}
2011-06-19 17:10:32 +02:00
print '</table>';
print '</div>';
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
}
/**
2015-11-22 12:23:10 +01:00
* Output html select list of type of event
2012-01-29 23:24:47 +01:00
*
2016-10-17 17:52:58 +02:00
* @param array|string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
* @param string $htmlname Name of select field
* @param string $excludetype A type to exclude ('systemauto', 'system', '')
* @param integer $onlyautoornot 1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type, -1=Keep details and add a combined line "All manual"
2016-10-17 17:52:58 +02:00
* @param int $hideinfohelp 1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
* @param int $multiselect 1=Allow multiselect of action type
* @param int $nooutput 1=No output
* @return string
2010-11-22 10:18:53 +01:00
*/
function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
2010-11-22 10:18:53 +01:00
{
global $langs,$user,$form,$conf;
2010-11-22 10:18:53 +01:00
if (! is_object($form)) $form=new Form($this->db);
2014-06-26 20:24:00 +02:00
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);
// 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';
2014-10-20 12:29:35 +02:00
if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
2016-10-17 17:52:58 +02:00
$out='';
2017-06-10 13:54:43 +02:00
if (! empty($multiselect))
2015-11-22 12:23:10 +01:00
{
2016-10-17 17:52:58 +02:00
if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
}
2017-06-10 13:54:43 +02:00
else
2015-12-04 20:51:34 +01:00
{
$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
}
2017-06-10 13:54:43 +02:00
if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
{
2016-10-17 17:52:58 +02:00
$out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
}
2017-06-10 13:54:43 +02:00
2016-10-17 17:52:58 +02:00
if ($nooutput) return $out;
else print $out;
return '';
2010-11-22 10:18:53 +01:00
}
2010-05-03 10:22:35 +02:00
}