html.formactions.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 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. var $db;
  30. var $error;
  31. /**
  32. * Constructor
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. function __construct($db)
  37. {
  38. $this->db = $db;
  39. return 1;
  40. }
  41. /**
  42. * Show list of action status
  43. *
  44. * @param string $formname Name of form where select is included
  45. * @param string $selected Preselected value (-1..100)
  46. * @param int $canedit 1=can edit, 0=read only
  47. * @param string $htmlname Name of html prefix for html fields (selectX and valX)
  48. * @param integer $showempty Show an empty line if select is used
  49. * @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)
  50. * @param string $morecss More css on select field
  51. * @return void
  52. */
  53. function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
  54. {
  55. global $langs,$conf;
  56. $listofstatus = array(
  57. '-1' => $langs->trans("ActionNotApplicable"),
  58. '0' => $langs->trans("ActionsToDoShort"),
  59. '50' => $langs->trans("ActionRunningShort"),
  60. '100' => $langs->trans("ActionDoneShort")
  61. );
  62. // +ActionUncomplete
  63. if (! empty($conf->use_javascript_ajax))
  64. {
  65. print "\n";
  66. print "<script type=\"text/javascript\">
  67. var htmlname = '".$htmlname."';
  68. $(document).ready(function () {
  69. select_status();
  70. $('#select' + htmlname).change(function() {
  71. select_status();
  72. });
  73. // FIXME use another method for update combobox
  74. //$('#val' + htmlname).change(function() {
  75. //select_status();
  76. //});
  77. });
  78. function select_status() {
  79. var defaultvalue = $('#select' + htmlname).val();
  80. var percentage = $('input[name=percentage]');
  81. var selected = '".(isset($selected)?$selected:'')."';
  82. var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
  83. percentage.val(value);
  84. if (defaultvalue == -1) {
  85. percentage.prop('disabled', true);
  86. $('.hideifna').hide();
  87. }
  88. else if (defaultvalue == 0) {
  89. percentage.val(0);
  90. percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
  91. $('.hideifna').show();
  92. }
  93. else if (defaultvalue == 100) {
  94. percentage.val(100);
  95. percentage.prop('disabled', true);
  96. $('.hideifna').show();
  97. }
  98. else {
  99. if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
  100. percentage.removeAttr('disabled');
  101. $('.hideifna').show();
  102. }
  103. }
  104. </script>\n";
  105. }
  106. if (! empty($conf->use_javascript_ajax) || $onlyselect)
  107. {
  108. //var_dump($selected);
  109. if ($selected == 'done') $selected='100';
  110. print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
  111. if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
  112. foreach($listofstatus as $key => $val)
  113. {
  114. print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
  115. if ($key == '50' && $onlyselect == 2)
  116. {
  117. print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
  118. }
  119. }
  120. print '</select>';
  121. if ($selected == 0 || $selected == 100) $canedit=0;
  122. if (empty($onlyselect))
  123. {
  124. print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
  125. print '<span class="hideonsmartphone hideifna">%</span>';
  126. }
  127. }
  128. else
  129. {
  130. print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
  131. }
  132. }
  133. /**
  134. * Show list of actions for element
  135. *
  136. * @param Object $object Object
  137. * @param string $typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
  138. * @param int $socid socid of user
  139. * @param int $forceshowtitle Show title even if there is no actions to show
  140. * @param string $morecss More css on table
  141. * @return int <0 if KO, >=0 if OK
  142. */
  143. function showactions($object,$typeelement,$socid=0,$forceshowtitle=0,$morecss='listactions')
  144. {
  145. global $langs,$conf,$user;
  146. global $bc;
  147. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  148. $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement);
  149. if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
  150. $num = count($listofactions);
  151. if ($num || $forceshowtitle)
  152. {
  153. if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
  154. elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
  155. elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
  156. elseif ($typeelement == 'supplier_payment') $title=$langs->trans('ActionsOnSupplierPayment');
  157. elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
  158. elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
  159. elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
  160. elseif ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
  161. elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
  162. elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
  163. else $title=$langs->trans("Actions");
  164. $buttontoaddnewevent = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.'&socid='.$object->socid.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">';
  165. $buttontoaddnewevent.= $langs->trans("AddEvent");
  166. $buttontoaddnewevent.= '</a>';
  167. print load_fiche_titre($title, $buttontoaddnewevent, '');
  168. $page=0; $param=''; $sortfield='a.datep';
  169. $total = 0;
  170. print '<div class="div-table-responsive">';
  171. print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
  172. print '<tr class="liste_titre">';
  173. print_liste_field_titre($langs->trans('Ref'), $_SERVER["PHP_SELF"], '', $page, $param, '');
  174. print_liste_field_titre($langs->trans('Action'), $_SERVER["PHP_SELF"], '', $page, $param, '');
  175. print_liste_field_titre($langs->trans('Type'), $_SERVER["PHP_SELF"], '', $page, $param, '');
  176. print_liste_field_titre($langs->trans('Date'), $_SERVER["PHP_SELF"], '', $page, $param, '');
  177. print_liste_field_titre($langs->trans('By'), $_SERVER["PHP_SELF"], '', $page, $param, '');
  178. print_liste_field_titre('', $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"');
  179. print '</tr>';
  180. print "\n";
  181. $userstatic = new User($this->db);
  182. foreach($listofactions as $action)
  183. {
  184. $ref=$action->getNomUrl(1,-1);
  185. $label=$action->getNomUrl(0,38);
  186. print '<tr class="oddeven">';
  187. print '<td>'.$ref.'</td>';
  188. print '<td>'.$label.'</td>';
  189. print '<td>'.$action->type.'</td>';
  190. print '<td>'.dol_print_date($action->datep,'dayhour');
  191. if ($action->datef)
  192. {
  193. $tmpa=dol_getdate($action->datep);
  194. $tmpb=dol_getdate($action->datef);
  195. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
  196. {
  197. if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef,'hour');
  198. }
  199. else print '-'.dol_print_date($action->datef,'dayhour');
  200. }
  201. print '</td>';
  202. print '<td>';
  203. if (! empty($action->author->id))
  204. {
  205. $userstatic->id = $action->author->id;
  206. $userstatic->firstname = $action->author->firstname;
  207. $userstatic->lastname = $action->author->lastname;
  208. print $userstatic->getNomUrl(1);
  209. }
  210. print '</td>';
  211. print '<td align="right">';
  212. if (! empty($action->author->id))
  213. {
  214. print $action->getLibStatut(3);
  215. }
  216. print '</td>';
  217. print '</tr>';
  218. }
  219. print '</table>';
  220. print '</div>';
  221. }
  222. return $num;
  223. }
  224. /**
  225. * Output html select list of type of event
  226. *
  227. * @param array|string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
  228. * @param string $htmlname Name of select field
  229. * @param string $excludetype A type to exclude ('systemauto', 'system', '')
  230. * @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"
  231. * @param int $hideinfohelp 1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
  232. * @param int $multiselect 1=Allow multiselect of action type
  233. * @param int $nooutput 1=No output
  234. * @return string
  235. */
  236. function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
  237. {
  238. global $langs,$user,$form,$conf;
  239. if (! is_object($form)) $form=new Form($db);
  240. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  241. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  242. $caction=new CActionComm($this->db);
  243. // Suggest a list with manual events or all auto events
  244. $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
  245. array_unshift($arraylist,'&nbsp;'); // Add empty line at start
  246. //asort($arraylist);
  247. if ($selected == 'manual') $selected='AC_OTH';
  248. if ($selected == 'auto') $selected='AC_OTH_AUTO';
  249. if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
  250. $out='';
  251. if (! empty($multiselect))
  252. {
  253. if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
  254. $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
  255. }
  256. else
  257. {
  258. $out.=$form->selectarray($htmlname, $arraylist, $selected);
  259. }
  260. if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
  261. {
  262. $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
  263. }
  264. if ($nooutput) return $out;
  265. else print $out;
  266. return '';
  267. }
  268. }