index.php 7.3 KB

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