dolibarr  16.0.5
index.php
Go to the documentation of this file.
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 
27 require '../../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.pdf.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("agenda", "commercial"));
36 
37 $action = GETPOST('action', 'aZ09');
38 $month = GETPOST('month', 'int');
39 $year = GETPOST('year', 'int');
40 
41 $optioncss = GETPOST('optioncss', 'alpha');
42 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
43 $sortfield = GETPOST('sortfield', 'aZ09comma');
44 $sortorder = GETPOST('sortorder', 'aZ09comma');
45 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
46 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
47  // If $page is not defined, or '' or -1 or if we click on clear filters
48  $page = 0;
49 }
50 $offset = $limit * $page;
51 if (!$sortorder) {
52  $sortorder = "DESC";
53 }
54 if (!$sortfield) {
55  $sortfield = "a.datep";
56 }
57 
58 // Security check
59 $socid = GETPOST('socid', 'int');
60 if ($user->socid) {
61  $socid = $user->socid;
62 }
63 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
64 if ($user->socid && $socid) {
65  $result = restrictedArea($user, 'societe', $socid);
66 }
67 
68 
69 /*
70  * Actions
71  */
72 
73 if ($action == 'builddoc') {
74  $cat = new CommActionRapport($db, $month, $year);
75  $result = $cat->write_file(GETPOST('id', 'int'));
76  if ($result < 0) {
77  setEventMessages($cat->error, $cat->errors, 'errors');
78  }
79 }
80 
81 
82 /*
83  * View
84  */
85 
86 $formfile = new FormFile($db);
87 
88 llxHeader();
89 
90 $sql = "SELECT count(*) as cc,";
91 $sql .= " date_format(a.datep, '%m/%Y') as df,";
92 $sql .= " date_format(a.datep, '%m') as month,";
93 $sql .= " date_format(a.datep, '%Y') as year";
94 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a,";
95 $sql .= " ".MAIN_DB_PREFIX."user as u";
96 $sql .= " WHERE a.fk_user_author = u.rowid";
97 $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
98 //$sql.= " AND percent = 100";
99 $sql .= " GROUP BY year, month, df";
100 $sql .= " ORDER BY year DESC, month DESC, df DESC";
101 
102 $nbtotalofrecords = '';
103 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
104  $result = $db->query($sql);
105  $nbtotalofrecords = $db->num_rows($result);
106  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
107  $page = 0;
108  $offset = 0;
109  }
110 }
111 
112 $sql .= $db->plimit($limit + 1, $offset);
113 
114 //print $sql;
115 dol_syslog("select", LOG_DEBUG);
116 $resql = $db->query($sql);
117 if ($resql) {
118  $num = $db->num_rows($resql);
119 
120  $param = '';
121  if ($limit > 0 && $limit != $conf->liste_limit) {
122  $param .= '&limit='.$limit;
123  }
124 
125  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
126  if ($optioncss != '') {
127  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
128  }
129  print '<input type="hidden" name="token" value="'.newToken().'">';
130  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
131  print '<input type="hidden" name="action" value="list">';
132  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
133  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
134 
135  print_barre_liste($langs->trans("EventReports"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit, 0, 0, 1);
136 
137  $moreforfilter = '';
138 
139  $i = 0;
140  print '<div class="div-table-responsive">';
141  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
142 
143  print '<tr class="liste_titre">';
144  print '<td>'.$langs->trans("Period").'</td>';
145  print '<td class="center">'.$langs->trans("EventsNb").'</td>';
146  print '<td class="center">'.$langs->trans("Action").'</td>';
147  print '<td>'.$langs->trans("PDF").'</td>';
148  print '<td class="center">'.$langs->trans("Date").'</td>';
149  print '<td class="center">'.$langs->trans("Size").'</td>';
150  print "</tr>\n";
151 
152  while ($i < min($num, $limit)) {
153  $obj = $db->fetch_object($resql);
154 
155  if ($obj) {
156  print '<tr class="oddeven">';
157 
158  // Date
159  print "<td>".$obj->df."</td>\n";
160 
161  // Nb of events
162  print '<td class="center">'.$obj->cc.'</td>';
163 
164  // Button to build doc
165  print '<td class="center">';
166  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>';
167  print '</td>';
168 
169  $name = "actions-".$obj->month."-".$obj->year.".pdf";
170  $relativepath = $name;
171  $file = $conf->agenda->dir_temp."/".$name;
172  $modulepart = 'actionsreport';
173  $documenturl = DOL_URL_ROOT.'/document.php';
174  if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
175  $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
176  }
177 
178  if (file_exists($file)) {
179  print '<td class="tdoverflowmax300">';
180  //print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?page='.$page.'&amp;file='.urlencode($relativepath).'&amp;modulepart=actionsreport">'.img_pdf().'</a>';
181 
182  $filearray = array('name'=>basename($file), 'fullname'=>$file, 'type'=>'file');
183  $out = '';
184 
185  // Show file name with link to download
186  $out .= '<a href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
187  $mime = dol_mimetype($relativepath, '', 0);
188  $out .= ' target="_blank" rel="noopener noreferrer">';
189  $out .= img_mime($filearray["name"], $langs->trans("File").': '.$filearray["name"]);
190  $out .= $filearray["name"];
191  $out .= '</a>'."\n";
192  $out .= $formfile->showPreview($filearray, $modulepart, $relativepath, 0, $param);
193  print $out;
194 
195  print '</td>';
196  print '<td class="center">'.dol_print_date(dol_filemtime($file), 'dayhour').'</td>';
197  print '<td class="center">'.dol_print_size(dol_filesize($file)).'</td>';
198  } else {
199  print '<td>&nbsp;</td>';
200  print '<td>&nbsp;</td>';
201  print '<td>&nbsp;</td>';
202  }
203 
204  print "</tr>\n";
205  }
206  $i++;
207  }
208  print "</table>";
209  print '</div>';
210  print '</form>';
211 
212  $db->free($resql);
213 } else {
214  dol_print_error($db);
215 }
216 
217 // End of page
218 llxFooter();
219 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
dol_filemtime
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:593
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_mimetype
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
Definition: functions.lib.php:9741
CommActionRapport
Class to generate event report.
Definition: rapport.pdf.php:36
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
dol_filesize
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:581
img_mime
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
Definition: functions.lib.php:4726
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137