index.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. require '../../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.pdf.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("agenda", "commercial"));
  33. $action = GETPOST('action', 'aZ09');
  34. $month = GETPOST('month', 'int');
  35. $year = GETPOST('year', 'int');
  36. $optioncss = GETPOST('optioncss', 'alpha');
  37. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  38. $sortfield = GETPOST('sortfield', 'aZ09comma');
  39. $sortorder = GETPOST('sortorder', 'aZ09comma');
  40. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  41. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  42. // If $page is not defined, or '' or -1 or if we click on clear filters
  43. $page = 0;
  44. }
  45. $offset = $limit * $page;
  46. if (!$sortorder) {
  47. $sortorder = "DESC";
  48. }
  49. if (!$sortfield) {
  50. $sortfield = "a.datep";
  51. }
  52. // Security check
  53. $socid = GETPOST('socid', 'int');
  54. if ($user->socid) {
  55. $socid = $user->socid;
  56. }
  57. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  58. if ($user->socid && $socid) {
  59. $result = restrictedArea($user, 'societe', $socid);
  60. }
  61. /*
  62. * Actions
  63. */
  64. if ($action == 'builddoc') {
  65. $cat = new CommActionRapport($db, $month, $year);
  66. $result = $cat->write_file(GETPOST('id', 'int'));
  67. if ($result < 0) {
  68. setEventMessages($cat->error, $cat->errors, 'errors');
  69. }
  70. }
  71. /*
  72. * View
  73. */
  74. $formfile = new FormFile($db);
  75. llxHeader();
  76. $sql = "SELECT count(*) as cc,";
  77. $sql .= " date_format(a.datep, '%m/%Y') as df,";
  78. $sql .= " date_format(a.datep, '%m') as month,";
  79. $sql .= " date_format(a.datep, '%Y') as year";
  80. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a,";
  81. $sql .= " ".MAIN_DB_PREFIX."user as u";
  82. $sql .= " WHERE a.fk_user_author = u.rowid";
  83. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  84. //$sql.= " AND percent = 100";
  85. $sql .= " GROUP BY year, month, df";
  86. $sql .= " ORDER BY year DESC, month DESC, df DESC";
  87. $nbtotalofrecords = '';
  88. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  89. $result = $db->query($sql);
  90. $nbtotalofrecords = $db->num_rows($result);
  91. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  92. $page = 0;
  93. $offset = 0;
  94. }
  95. }
  96. $sql .= $db->plimit($limit + 1, $offset);
  97. //print $sql;
  98. dol_syslog("select", LOG_DEBUG);
  99. $resql = $db->query($sql);
  100. if ($resql) {
  101. $num = $db->num_rows($resql);
  102. $param = '';
  103. if ($limit > 0 && $limit != $conf->liste_limit) {
  104. $param .= '&limit='.$limit;
  105. }
  106. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  107. if ($optioncss != '') {
  108. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  109. }
  110. print '<input type="hidden" name="token" value="'.newToken().'">';
  111. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  112. print '<input type="hidden" name="action" value="list">';
  113. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  114. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  115. print_barre_liste($langs->trans("EventReports"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit, 0, 0, 1);
  116. $moreforfilter = '';
  117. $i = 0;
  118. print '<div class="div-table-responsive">';
  119. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  120. print '<tr class="liste_titre">';
  121. print '<td>'.$langs->trans("Period").'</td>';
  122. print '<td class="center">'.$langs->trans("EventsNb").'</td>';
  123. print '<td class="center">'.$langs->trans("Action").'</td>';
  124. print '<td>'.$langs->trans("PDF").'</td>';
  125. print '<td class="center">'.$langs->trans("Date").'</td>';
  126. print '<td class="center">'.$langs->trans("Size").'</td>';
  127. print "</tr>\n";
  128. while ($i < min($num, $limit)) {
  129. $obj = $db->fetch_object($resql);
  130. if ($obj) {
  131. print '<tr class="oddeven">';
  132. // Date
  133. print "<td>".$obj->df."</td>\n";
  134. // Nb of events
  135. print '<td class="center">'.$obj->cc.'</td>';
  136. // Button to build doc
  137. print '<td class="center">';
  138. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=builddoc&page='.((int) $page).'&month='.((int) $obj->month).'&year='.((int) $obj->year).'">'.img_picto($langs->trans('BuildDoc'), 'filenew').'</a>';
  139. print '</td>';
  140. $name = "actions-".$obj->month."-".$obj->year.".pdf";
  141. $relativepath = $name;
  142. $file = $conf->agenda->dir_temp."/".$name;
  143. $modulepart = 'actionsreport';
  144. $documenturl = DOL_URL_ROOT.'/document.php';
  145. if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
  146. $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
  147. }
  148. if (file_exists($file)) {
  149. print '<td class="tdoverflowmax300">';
  150. //print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?page='.$page.'&amp;file='.urlencode($relativepath).'&amp;modulepart=actionsreport">'.img_pdf().'</a>';
  151. $filearray = array('name'=>basename($file), 'fullname'=>$file, 'type'=>'file');
  152. $out = '';
  153. // Show file name with link to download
  154. $out .= '<a href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
  155. $mime = dol_mimetype($relativepath, '', 0);
  156. $out .= ' target="_blank" rel="noopener noreferrer">';
  157. $out .= img_mime($filearray["name"], $langs->trans("File").': '.$filearray["name"]);
  158. $out .= $filearray["name"];
  159. $out .= '</a>'."\n";
  160. $out .= $formfile->showPreview($filearray, $modulepart, $relativepath, 0, $param);
  161. print $out;
  162. print '</td>';
  163. print '<td class="center">'.dol_print_date(dol_filemtime($file), 'dayhour').'</td>';
  164. print '<td class="center">'.dol_print_size(dol_filesize($file)).'</td>';
  165. } else {
  166. print '<td>&nbsp;</td>';
  167. print '<td>&nbsp;</td>';
  168. print '<td>&nbsp;</td>';
  169. }
  170. print "</tr>\n";
  171. }
  172. $i++;
  173. }
  174. print "</table>";
  175. print '</div>';
  176. print '</form>';
  177. $db->free($resql);
  178. } else {
  179. dol_print_error($db);
  180. }
  181. // End of page
  182. llxFooter();
  183. $db->close();