index.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/action/rapport/index.php
  22. * \ingroup commercial
  23. * \brief Page with reports of actions
  24. */
  25. // Load Dolibarr environment
  26. require '../../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("agenda", "commercial"));
  34. $action = GETPOST('action', 'aZ09');
  35. $month = GETPOST('month', 'int');
  36. $year = GETPOST('year', 'int');
  37. $optioncss = GETPOST('optioncss', 'alpha');
  38. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  39. $sortfield = GETPOST('sortfield', 'aZ09comma');
  40. $sortorder = GETPOST('sortorder', 'aZ09comma');
  41. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  42. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  43. // If $page is not defined, or '' or -1 or if we click on clear filters
  44. $page = 0;
  45. }
  46. $offset = $limit * $page;
  47. if (!$sortorder) {
  48. $sortorder = "DESC";
  49. }
  50. if (!$sortfield) {
  51. $sortfield = "a.datep";
  52. }
  53. // Security check
  54. //$result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  55. if (!$user->hasRight("agenda", "allactions", "read")) {
  56. accessForbidden();
  57. }
  58. /*
  59. * Actions
  60. */
  61. if ($action == 'builddoc') {
  62. $cat = new CommActionRapport($db, $month, $year);
  63. $result = $cat->write_file(GETPOST('id', 'int'));
  64. if ($result < 0) {
  65. setEventMessages($cat->error, $cat->errors, 'errors');
  66. }
  67. }
  68. /*
  69. * View
  70. */
  71. $formfile = new FormFile($db);
  72. llxHeader();
  73. $sql = "SELECT count(*) as cc,";
  74. $sql .= " date_format(a.datep, '%m/%Y') as df,";
  75. $sql .= " date_format(a.datep, '%m') as month,";
  76. $sql .= " date_format(a.datep, '%Y') as year";
  77. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a,";
  78. $sql .= " ".MAIN_DB_PREFIX."user as u";
  79. $sql .= " WHERE a.fk_user_author = u.rowid";
  80. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  81. //$sql.= " AND percent = 100";
  82. $sql .= " GROUP BY year, month, df";
  83. $sql .= " ORDER BY year DESC, month DESC, df DESC";
  84. $nbtotalofrecords = '';
  85. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  86. $result = $db->query($sql);
  87. $nbtotalofrecords = $db->num_rows($result);
  88. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  89. $page = 0;
  90. $offset = 0;
  91. }
  92. }
  93. $sql .= $db->plimit($limit + 1, $offset);
  94. //print $sql;
  95. dol_syslog("select", LOG_DEBUG);
  96. $resql = $db->query($sql);
  97. if ($resql) {
  98. $num = $db->num_rows($resql);
  99. $param = '';
  100. if ($limit > 0 && $limit != $conf->liste_limit) {
  101. $param .= '&limit='.$limit;
  102. }
  103. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  104. if ($optioncss != '') {
  105. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  106. }
  107. print '<input type="hidden" name="token" value="'.newToken().'">';
  108. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  109. print '<input type="hidden" name="action" value="list">';
  110. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  111. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  112. print_barre_liste($langs->trans("EventReports"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit, 0, 0, 1);
  113. $moreforfilter = '';
  114. $i = 0;
  115. print '<div class="div-table-responsive">';
  116. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  117. print '<tr class="liste_titre">';
  118. print '<td>'.$langs->trans("Period").'</td>';
  119. print '<td class="center">'.$langs->trans("EventsNb").'</td>';
  120. print '<td class="center">'.$langs->trans("Action").'</td>';
  121. print '<td>'.$langs->trans("PDF").'</td>';
  122. print '<td class="center">'.$langs->trans("Date").'</td>';
  123. print '<td class="center">'.$langs->trans("Size").'</td>';
  124. print "</tr>\n";
  125. while ($i < min($num, $limit)) {
  126. $obj = $db->fetch_object($resql);
  127. if ($obj) {
  128. print '<tr class="oddeven">';
  129. // Date
  130. print "<td>".$obj->df."</td>\n";
  131. // Nb of events
  132. print '<td class="center">'.$obj->cc.'</td>';
  133. // Button to build doc
  134. print '<td class="center">';
  135. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=builddoc&token='.newToken().'&page='.((int) $page).'&month='.((int) $obj->month).'&year='.((int) $obj->year).'">'.img_picto($langs->trans('BuildDoc'), 'filenew').'</a>';
  136. print '</td>';
  137. $name = "actions-".$obj->month."-".$obj->year.".pdf";
  138. $relativepath = $name;
  139. $file = $conf->agenda->dir_temp."/".$name;
  140. $modulepart = 'actionsreport';
  141. $documenturl = DOL_URL_ROOT.'/document.php';
  142. if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
  143. $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
  144. }
  145. if (file_exists($file)) {
  146. print '<td class="tdoverflowmax300">';
  147. //print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?page='.$page.'&amp;file='.urlencode($relativepath).'&amp;modulepart=actionsreport">'.img_pdf().'</a>';
  148. $filearray = array('name'=>basename($file), 'fullname'=>$file, 'type'=>'file');
  149. $out = '';
  150. // Show file name with link to download
  151. $out .= '<a href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
  152. $mime = dol_mimetype($relativepath, '', 0);
  153. $out .= ' target="_blank" rel="noopener noreferrer">';
  154. $out .= img_mime($filearray["name"], $langs->trans("File").': '.$filearray["name"]);
  155. $out .= $filearray["name"];
  156. $out .= '</a>'."\n";
  157. $out .= $formfile->showPreview($filearray, $modulepart, $relativepath, 0, $param);
  158. print $out;
  159. print '</td>';
  160. print '<td class="center">'.dol_print_date(dol_filemtime($file), 'dayhour').'</td>';
  161. print '<td class="center">'.dol_print_size(dol_filesize($file)).'</td>';
  162. } else {
  163. print '<td>&nbsp;</td>';
  164. print '<td>&nbsp;</td>';
  165. print '<td>&nbsp;</td>';
  166. }
  167. print "</tr>\n";
  168. }
  169. $i++;
  170. }
  171. print "</table>";
  172. print '</div>';
  173. print '</form>';
  174. $db->free($resql);
  175. } else {
  176. dol_print_error($db);
  177. }
  178. // End of page
  179. llxFooter();
  180. $db->close();