agendaplus.class.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. class AgendaPlus
  3. {
  4. public $db;
  5. public $addedFilters = ['eventdetails', 'eventproduct', 'eventlocation'];
  6. public function __construct()
  7. {
  8. global $db;
  9. $this->db = $db;
  10. }
  11. /**
  12. * Show filter form in agenda view
  13. *
  14. * @param Form $form Form object
  15. * @param int $canedit Can edit filter fields
  16. * @param int $status Status
  17. * @param int $year Year
  18. * @param int $month Month
  19. * @param int $day Day
  20. * @param int $showbirthday Show birthday
  21. * @param string $filtera Filter on create by user
  22. * @param string $filtert Filter on assigned to user
  23. * @param string $eventdetails Filter on eventdetails
  24. * @param string $eventproduct Filter on eventproduct
  25. * @param string $eventlocation Filter on eventlocation
  26. * @param string $filterd Filter of done by user
  27. * @param int $pid Product id
  28. * @param int $socid Third party id
  29. * @param string $action Action string
  30. * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend
  31. * @param string|array $actioncode Preselected value(s) of actioncode for filter on event type
  32. * @param int $usergroupid Id of group to filter on users
  33. * @param string $excludetype A type to exclude ('systemauto', 'system', '')
  34. * @param int $resourceid Preselected value of resource for filter on resource
  35. * @return void
  36. */
  37. function new_print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $eventdetails, $eventproduct, $eventlocation, $filterd, $pid, $socid, $action, $showextcals = array(), $actioncode = '', $usergroupid = '', $excludetype = '', $resourceid = 0)
  38. {
  39. global $conf, $user, $langs, $db, $hookmanager;
  40. global $begin_h, $end_h, $begin_d, $end_d;
  41. global $massaction;
  42. $langs->load("companies");
  43. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  44. $formactions = new FormActions($db);
  45. // Filters
  46. //print '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="get">';
  47. print '<input type="hidden" name="token" value="' . newToken() . '">';
  48. print '<input type="hidden" name="year" value="' . ((int) $year) . '">';
  49. print '<input type="hidden" name="month" value="' . ((int) $month) . '">';
  50. print '<input type="hidden" name="day" value="' . ((int) $day) . '">';
  51. if ($massaction != 'predelete' && $massaction != 'preaffecttag') { // When $massaction == 'predelete', action may be already output to 'delete' by the mass action system.
  52. print '<input type="hidden" name="action" value="' . $action . '">';
  53. }
  54. print '<input type="hidden" name="search_showbirthday" value="' . ((int) $showbirthday) . '">';
  55. if ($canedit) {
  56. // Assigned to user
  57. print '<div class="divsearchfield">';
  58. print img_picto($langs->trans("ActionsToDoBy"), 'user', 'class="pictofixedwidth inline-block"');
  59. print $form->select_dolusers($filtert, 'search_filtert', 1, '', !$canedit, '', '', 0, 0, 0, '', 0, '', 'minwidth150 maxwidth500 widthcentpercentminusxx');
  60. print '</div>';
  61. }
  62. if ($canedit && !preg_match('/list/', $_SERVER["PHP_SELF"])) {
  63. // Status
  64. print '<div class="divsearchfield">';
  65. print img_picto($langs->trans("Status"), 'setup', 'class="pictofixedwidth inline-block"');
  66. $formactions->form_select_status_action('formaction', $status, 1, 'search_status', 1, 2, 'minwidth100');
  67. print '</div>';
  68. }
  69. //print $form->select_dolusers($eventdetails, 'search_eventdetails', 1, '', !$canedit, '', '', 0, 0, 0, '', 0, '', 'minwidth150 maxwidth500 widthcentpercentminusxx');
  70. // new filters (event_details, event products, event location from)
  71. print '<div class="divsearchfield">';
  72. print img_picto($langs->trans("ActionsToDoBy"), 'fa-cogs', 'class="pictofixedwidth inline-block"');
  73. print $this->eventselector($eventdetails, 'eventdetails', 1);
  74. print '</div>';
  75. print '<div class="divsearchfield">';
  76. print img_picto($langs->trans("ActionsToDoBy"), 'fa-product-hunt', 'class="pictofixedwidth inline-block"');
  77. print $this->eventselector($eventproduct, 'eventproduct', 1);
  78. print '</div>';
  79. print '<div class="divsearchfield">';
  80. print img_picto($langs->trans("ActionsToDoBy"), 'fa-location-arrow', 'class="pictofixedwidth inline-block"');
  81. print $this->eventselector($eventlocation, 'eventlocation', 1);
  82. print '</div>';
  83. // Hooks
  84. $parameters = array('canedit' => $canedit, 'pid' => $pid, 'socid' => $socid);
  85. $object = null;
  86. $reshook = $hookmanager->executeHooks('searchAgendaFrom', $parameters, $object, $action); // Note that $action and $object may have been
  87. print '<div style="clear:both"></div>';
  88. }
  89. private function eventselector($selected, $htmlname, $show_empty = 0, $multiple = false, $disabled = 0)
  90. {
  91. global $db, $langs;
  92. $i = 0;
  93. $out = '';
  94. $morecss = '';
  95. $textforempty = '&nbsp;';
  96. $sql = "SELECT rowid, label FROM llx_eventwizard_{$htmlname} ORDER BY label ASC";
  97. $result = $this->db->query($sql);
  98. $num = $this->db->num_rows($result);
  99. if ($selected === '') {
  100. $selected = array();
  101. } elseif (!is_array($selected)) {
  102. $selected = array($selected);
  103. }
  104. if ($num) {
  105. $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : ' minwidth200') . '" id="search_' . $htmlname . '" name="search_' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . ($disabled ? ' disabled' : '') . '>';
  106. $out .= '<option class="optiongrey" value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n";
  107. while ($i < $num) {
  108. while ($obj = $this->db->fetch_object($result)) {
  109. $out .= '<option value="' . $obj->rowid . '"';
  110. if (in_array($obj->rowid, $selected)) {
  111. $out .= ' selected';
  112. }
  113. $out .= '>';
  114. $out .= $obj->label;
  115. $out .= '</option>';
  116. $i++;
  117. }
  118. }
  119. } else {
  120. $out .= '<select class="flat" id="search_' . $htmlname . '" name="search_' . $htmlname . '" disabled>';
  121. $out .= '<option value="">' . $langs->trans("None") . '</option>';
  122. }
  123. $out .= '</select>';
  124. return $out;
  125. }
  126. function getSearchedElement($element)
  127. {
  128. return GETPOST("search_" . $element, "int", 3) ? GETPOST("search_" . $element, "int", 3) : GETPOST($element, "int", 3);
  129. }
  130. function completeParametersArray($parameters, $eventdetails, $eventproduct, $eventlocation)
  131. {
  132. foreach ($this->addedFilters as $filter) {
  133. $parameters[$filter] = $$filter;
  134. }
  135. return $parameters;
  136. }
  137. function completeParamString($eventdetails, $eventproduct, $eventlocation)
  138. {
  139. $param = '';
  140. if ($eventdetails) {
  141. $param .= "&search_eventdetails=" . urlencode($eventdetails);
  142. }
  143. if ($eventproduct) {
  144. $param .= "&search_eventproduct=" . urlencode($eventproduct);
  145. }
  146. if ($eventlocation) {
  147. $param .= "&search_eventlocation=" . urlencode($eventlocation);
  148. }
  149. return $param;
  150. }
  151. function completeSqlSelectString($eventdetails, $eventproduct, $eventlocation)
  152. {
  153. $sql = '';
  154. if ($eventdetails != '' && $eventdetails != -1)
  155. $sql .= ' edt.rowid as ed_rowid,';
  156. if ($eventproduct != '' && $eventproduct != -1)
  157. $sql .= ' epr.rowid as epr_rowid,';
  158. if ($eventlocation != '' && $eventlocation != -1)
  159. $sql .= ' eln.rowid as loc_rowid,';
  160. return $sql;
  161. }
  162. function completeSqlFromString($eventlocation)
  163. {
  164. $sql = "";
  165. //if($eventdetails != '' && $eventdetails != -1)
  166. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "eventwizard_eventdetails as edt ON edt.rowid = a.fk_element";
  167. //if($eventproduct != '' && $eventproduct != -1)
  168. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "eventwizard_eventproduct as epr ON epr.fk_eventdetails = edt.rowid";
  169. if ($eventlocation != '' && $eventlocation != -1)
  170. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "eventwizard_eventlocation as eln ON eln.rowid = edt.fk_elventlocation_departure";
  171. return $sql;
  172. }
  173. function completeSqlWhereString($eventdetails, $eventproduct, $eventlocation)
  174. {
  175. $sql = "";
  176. if ($eventdetails != '' && $eventdetails != -1)
  177. $sql .= " AND edt.rowid = {$eventdetails}";
  178. if ($eventproduct != '' && $eventproduct != -1)
  179. $sql .= " AND epr.rowid = {$eventproduct}";
  180. if ($eventlocation != '' && $eventlocation != -1)
  181. $sql .= " AND eln.rowid = {$eventlocation}";
  182. return $sql;
  183. }
  184. }