PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/asterix14/dolibarr
PHP | 183 lines | 106 code | 25 blank | 52 comment | 22 complexity | 2ee99e1deaad34b2e4dd0d807444295a MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (c) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
  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 2 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 FormActions
  26. * \brief Class to manage building of HTML components
  27. */
  28. class FormActions
  29. {
  30. var $db;
  31. var $error;
  32. /**
  33. * Constructor
  34. *
  35. * @param DoliDB $DB Database handler
  36. */
  37. function FormActions($DB)
  38. {
  39. $this->db = $DB;
  40. return 1;
  41. }
  42. /**
  43. * Show list of action status
  44. *
  45. * @param formname Name of form where select in included
  46. * @param selected Preselected value
  47. * @param canedit 1=can edit, 0=read only
  48. * @param htmlname Name of html prefix for html fields (selectX and valX)
  49. */
  50. function form_select_status_action($formname,$selected,$canedit=1,$htmlname='complete')
  51. {
  52. global $langs,$conf;
  53. $listofstatus=array('-1'=>$langs->trans("ActionNotApplicable"),
  54. '0'=>$langs->trans("ActionRunningNotStarted"),
  55. '50'=>$langs->trans("ActionRunningShort"),
  56. '100'=>$langs->trans("ActionDoneShort"));
  57. if ($conf->use_javascript_ajax)
  58. {
  59. print "\n";
  60. print '<script type="text/javascript">'."\n";
  61. print 'jQuery(document).ready(function () {'."\n";
  62. print 'jQuery("#select'.$htmlname.'").change(function() { select_status(document.'.$formname.'.status.value); });'."\n";
  63. print 'jQuery("#val'.$htmlname.'").change(function() { select_status(document.'.$formname.'.status.value); });'."\n";
  64. print 'select_status(document.'.$formname.'.status.value);'."\n";
  65. print '});'."\n";
  66. print 'function select_status(mypercentage) {'."\n";
  67. print 'document.'.$formname.'.percentageshown.value=(mypercentage>=0?mypercentage:\'\');'."\n";
  68. print 'document.'.$formname.'.percentage.value=mypercentage;'."\n";
  69. print 'if (mypercentage == -1) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").hide(); }'."\n";
  70. print 'else if (mypercentage == 0) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n";
  71. print 'else if (mypercentage == 100) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n";
  72. print 'else { document.'.$formname.'.percentageshown.disabled=false; }'."\n";
  73. print '}'."\n";
  74. print '</script>'."\n";
  75. print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">';
  76. foreach($listofstatus as $key => $val)
  77. {
  78. print '<option value="'.$key.'"'.($selected == $key?' selected="selected"':'').'>'.$val.'</option>';
  79. }
  80. print '</select>';
  81. if ($selected == 0 || $selected == 100) $canedit=0;
  82. print ' <input type="text" id="val'.$htmlname.'" name="percentageshown" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled="disabled"').'>';
  83. print '<span class="hideifna">%</span>';
  84. print ' <input type="hidden" name="percentage" value="'.$selected.'">';
  85. }
  86. else
  87. {
  88. print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled="disabled"').'>%';
  89. }
  90. }
  91. /**
  92. * Show list of actions for element
  93. * @param object Object
  94. * @param typeelement 'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
  95. * @param socid socid of user
  96. * @return int <0 if KO, >=0 if OK
  97. */
  98. function showactions($object,$typeelement,$socid=0)
  99. {
  100. global $langs,$conf,$user;
  101. global $bc;
  102. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  103. $actioncomm = new ActionComm($this->db);
  104. $actioncomm->getActions($socid, $object->id, $typeelement);
  105. $num = count($actioncomm->actions);
  106. if ($num)
  107. {
  108. if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
  109. elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
  110. elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
  111. elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
  112. elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
  113. elseif ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
  114. elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
  115. elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
  116. else $title=$langs->trans("Actions");
  117. print_titre($title);
  118. $total = 0; $var=true;
  119. print '<table class="border" width="100%">';
  120. 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>';
  121. print "\n";
  122. foreach($actioncomm->actions as $action)
  123. {
  124. $var=!$var;
  125. print '<tr '.$bc[$var].'>';
  126. print '<td>'.$action->getNomUrl(1).'</td>';
  127. print '<td>'.dol_print_date($action->datep,'day').'</td>';
  128. print '<td title="'.dol_escape_htmltag($action->label).'">'.dol_trunc($action->label,32).'</td>';
  129. $userstatic = new User($this->db);
  130. $userstatic->id = $action->author->id;
  131. $userstatic->prenom = $action->author->firstname;
  132. $userstatic->nom = $action->author->lastname;
  133. print '<td>'.$userstatic->getNomUrl(1).'</td>';
  134. print '</tr>';
  135. }
  136. print '</table>';
  137. }
  138. return $num;
  139. }
  140. /**
  141. * Output list of type of event
  142. * @param selected Type pre-selectionne
  143. * @param htmlname Nom champ formulaire
  144. */
  145. function select_type_actions($selected='',$htmlname='actioncode')
  146. {
  147. global $langs,$user;
  148. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
  149. require_once(DOL_DOCUMENT_ROOT."/core/class/html.form.class.php");
  150. $caction=new CActionComm($this->db);
  151. $form=new Form($this->db);
  152. $arraylist=$caction->liste_array(1,'code');
  153. array_unshift($arraylist,'&nbsp;'); // Add empty line at start
  154. //asort($arraylist);
  155. print $form->selectarray($htmlname, $arraylist, $selected);
  156. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  157. }
  158. }