html.formactions.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2010-2018 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/class/html.formactions.class.php
  21. * \ingroup core
  22. * \brief Fichier de la classe des fonctions predefinie de composants html actions
  23. */
  24. /**
  25. * Class to manage building of HTML components
  26. */
  27. class FormActions
  28. {
  29. /**
  30. * @var DoliDB Database handler.
  31. */
  32. public $db;
  33. /**
  34. * @var string Error code (or message)
  35. */
  36. public $error='';
  37. /**
  38. * Constructor
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db)
  43. {
  44. $this->db = $db;
  45. }
  46. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  47. /**
  48. * Show list of action status
  49. *
  50. * @param string $formname Name of form where select is included
  51. * @param string $selected Preselected value (-1..100)
  52. * @param int $canedit 1=can edit, 0=read only
  53. * @param string $htmlname Name of html prefix for html fields (selectX and valX)
  54. * @param integer $showempty Show an empty line if select is used
  55. * @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)
  56. * @param string $morecss More css on select field
  57. * @return void
  58. */
  59. function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
  60. {
  61. // phpcs:enable
  62. global $langs,$conf;
  63. $listofstatus = array(
  64. '-1' => $langs->trans("ActionNotApplicable"),
  65. '0' => $langs->trans("ActionsToDoShort"),
  66. '50' => $langs->trans("ActionRunningShort"),
  67. '100' => $langs->trans("ActionDoneShort")
  68. );
  69. // +ActionUncomplete
  70. if (! empty($conf->use_javascript_ajax))
  71. {
  72. print "\n";
  73. print "<script type=\"text/javascript\">
  74. var htmlname = '".$htmlname."';
  75. $(document).ready(function () {
  76. select_status();
  77. $('#select' + htmlname).change(function() {
  78. select_status();
  79. });
  80. // FIXME use another method for update combobox
  81. //$('#val' + htmlname).change(function() {
  82. //select_status();
  83. //});
  84. });
  85. function select_status() {
  86. var defaultvalue = $('#select' + htmlname).val();
  87. var percentage = $('input[name=percentage]');
  88. var selected = '".(isset($selected)?$selected:'')."';
  89. var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
  90. percentage.val(value);
  91. if (defaultvalue == -1) {
  92. percentage.prop('disabled', true);
  93. $('.hideifna').hide();
  94. }
  95. else if (defaultvalue == 0) {
  96. percentage.val(0);
  97. percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
  98. $('.hideifna').show();
  99. }
  100. else if (defaultvalue == 100) {
  101. percentage.val(100);
  102. percentage.prop('disabled', true);
  103. $('.hideifna').show();
  104. }
  105. else {
  106. if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
  107. percentage.removeAttr('disabled');
  108. $('.hideifna').show();
  109. }
  110. }
  111. </script>\n";
  112. }
  113. if (! empty($conf->use_javascript_ajax) || $onlyselect)
  114. {
  115. //var_dump($selected);
  116. if ($selected == 'done') $selected='100';
  117. print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
  118. if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
  119. foreach($listofstatus as $key => $val)
  120. {
  121. print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
  122. if ($key == '50' && $onlyselect == 2)
  123. {
  124. print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
  125. }
  126. }
  127. print '</select>';
  128. if ($selected == 0 || $selected == 100) $canedit=0;
  129. if (empty($onlyselect))
  130. {
  131. print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
  132. print '<span class="hideonsmartphone hideifna">%</span>';
  133. }
  134. }
  135. else
  136. {
  137. print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
  138. }
  139. }
  140. /**
  141. * Show list of actions for element
  142. *
  143. * @param Object $object Object
  144. * @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
  145. * @param int $socid Socid of user
  146. * @param int $forceshowtitle Show title even if there is no actions to show
  147. * @param string $morecss More css on table
  148. * @param int $max Max number of record
  149. * @param string $moreparambacktopage More param for the backtopage
  150. * @param string $morehtmlright More html text on right of title line
  151. * @return int <0 if KO, >=0 if OK
  152. */
  153. function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
  154. {
  155. global $langs,$conf,$user;
  156. global $bc;
  157. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  158. $sortfield='a.datep,a.id';
  159. $sortorder='DESC,DESC';
  160. $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
  161. if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
  162. $num = count($listofactions);
  163. if ($num || $forceshowtitle)
  164. {
  165. if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
  166. elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
  167. elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
  168. elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
  169. elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
  170. elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
  171. elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
  172. elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
  173. elseif ($typeelement == 'project') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
  174. elseif ($typeelement == 'task') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
  175. elseif ($typeelement == 'member') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
  176. else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
  177. $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
  178. $projectid = $object->fk_project;
  179. if ($typeelement == 'project') $projectid = $object->id;
  180. $newcardbutton='';
  181. if (! empty($conf->agenda->enabled))
  182. {
  183. $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>';
  184. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  185. $newcardbutton.= '</a>';
  186. }
  187. print '<!-- formactions->showactions -->'."\n";
  188. print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
  189. $page=0; $param='';
  190. $total = 0;
  191. print '<div class="div-table-responsive-no-min">';
  192. print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
  193. print '<tr class="liste_titre">';
  194. print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
  195. print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
  196. print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
  197. print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
  198. print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
  199. print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
  200. print '</tr>';
  201. print "\n";
  202. $userstatic = new User($this->db);
  203. if (count($listofactions))
  204. {
  205. $cursorevent = 0;
  206. foreach($listofactions as $action)
  207. {
  208. if ($max && $cursorevent >= $max) break;
  209. $ref=$action->getNomUrl(1,-1);
  210. $label=$action->getNomUrl(0,38);
  211. print '<tr class="oddeven">';
  212. // Ref
  213. print '<td>'.$ref.'</td>';
  214. // Onwer
  215. print '<td>';
  216. if (! empty($action->userownerid))
  217. {
  218. $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
  219. print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
  220. }
  221. print '</td>';
  222. // Type
  223. print '<td>';
  224. $imgpicto='';
  225. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
  226. {
  227. if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
  228. else {
  229. if ($action->type_code == 'AC_RDV') $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
  230. elseif ($action->type_code == 'AC_TEL') $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
  231. elseif ($action->type_code == 'AC_FAX') $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
  232. elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
  233. elseif ($action->type_code == 'AC_INT') $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
  234. elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
  235. }
  236. }
  237. print $imgpicto;
  238. print $action->type_short ? $action->type_short : $action->type;
  239. print '</td>';
  240. // Label
  241. print '<td>'.$label.'</td>';
  242. // Date
  243. print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
  244. if ($action->datef)
  245. {
  246. $tmpa=dol_getdate($action->datep);
  247. $tmpb=dol_getdate($action->datef);
  248. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
  249. {
  250. if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
  251. }
  252. else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
  253. }
  254. print '</td>';
  255. print '<td align="right">';
  256. if (! empty($action->author->id))
  257. {
  258. print $action->getLibStatut(3);
  259. }
  260. print '</td>';
  261. print '</tr>';
  262. $cursorevent++;
  263. }
  264. }
  265. else
  266. {
  267. print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  268. }
  269. if ($max && $num > $max)
  270. {
  271. print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
  272. }
  273. print '</table>';
  274. print '</div>';
  275. }
  276. return $num;
  277. }
  278. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  279. /**
  280. * Output html select list of type of event
  281. *
  282. * @param array|string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
  283. * @param string $htmlname Name of select field
  284. * @param string $excludetype A type to exclude ('systemauto', 'system', '')
  285. * @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"
  286. * @param int $hideinfohelp 1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
  287. * @param int $multiselect 1=Allow multiselect of action type
  288. * @param int $nooutput 1=No output
  289. * @return string
  290. */
  291. function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
  292. {
  293. // phpcs:enable
  294. global $langs,$user,$form,$conf;
  295. if (! is_object($form)) $form=new Form($db);
  296. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  297. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  298. $caction=new CActionComm($this->db);
  299. // Suggest a list with manual events or all auto events
  300. $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
  301. array_unshift($arraylist,'&nbsp;'); // Add empty line at start
  302. //asort($arraylist);
  303. if ($selected == 'manual') $selected='AC_OTH';
  304. if ($selected == 'auto') $selected='AC_OTH_AUTO';
  305. if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
  306. $out='';
  307. if (! empty($multiselect))
  308. {
  309. if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
  310. $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
  311. }
  312. else
  313. {
  314. $out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  315. }
  316. if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
  317. {
  318. $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
  319. }
  320. if ($nooutput) return $out;
  321. else print $out;
  322. return '';
  323. }
  324. }