* Copyright (C) 2003 Eric Seigne * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/comm/action/rapport/index.php * \ingroup commercial * \brief Page with reports of actions */ // Load Dolibarr environment require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.class.php'; // Load translation files required by the page $langs->loadLangs(array("agenda", "commercial")); $action = GETPOST('action', 'aZ09'); $month = GETPOST('month', 'int'); $year = GETPOST('year', 'int'); $optioncss = GETPOST('optioncss', 'alpha'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // If $page is not defined, or '' or -1 or if we click on clear filters $page = 0; } $offset = $limit * $page; if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "a.datep"; } // Security check $socid = GETPOST('socid', 'int'); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'agenda', 0, '', 'myactions'); if ($user->socid && $socid) { $result = restrictedArea($user, 'societe', $socid); } /* * Actions */ if ($action == 'builddoc') { $cat = new CommActionRapport($db, $month, $year); $result = $cat->write_file(GETPOST('id', 'int')); if ($result < 0) { setEventMessages($cat->error, $cat->errors, 'errors'); } } /* * View */ $formfile = new FormFile($db); llxHeader(); $sql = "SELECT count(*) as cc,"; $sql .= " date_format(a.datep, '%m/%Y') as df,"; $sql .= " date_format(a.datep, '%m') as month,"; $sql .= " date_format(a.datep, '%Y') as year"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a,"; $sql .= " ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE a.fk_user_author = u.rowid"; $sql .= ' AND a.entity IN ('.getEntity('agenda').')'; //$sql.= " AND percent = 100"; $sql .= " GROUP BY year, month, df"; $sql .= " ORDER BY year DESC, month DESC, df DESC"; $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } } $sql .= $db->plimit($limit + 1, $offset); //print $sql; dol_syslog("select", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $param = ''; if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.$limit; } print '
'; if ($optioncss != '') { print ''; } print ''; print ''; print ''; print ''; print ''; print_barre_liste($langs->trans("EventReports"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit, 0, 0, 1); $moreforfilter = ''; $i = 0; print '
'; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); if ($obj) { print ''; // Date print "\n"; // Nb of events print ''; // Button to build doc print ''; $name = "actions-".$obj->month."-".$obj->year.".pdf"; $relativepath = $name; $file = $conf->agenda->dir_temp."/".$name; $modulepart = 'actionsreport'; $documenturl = DOL_URL_ROOT.'/document.php'; if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) { $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper } if (file_exists($file)) { print ''; print ''; print ''; } else { print ''; print ''; print ''; } print "\n"; } $i++; } print "
'.$langs->trans("Period").''.$langs->trans("EventsNb").''.$langs->trans("Action").''.$langs->trans("PDF").''.$langs->trans("Date").''.$langs->trans("Size").'
".$obj->df."'.$obj->cc.''; print ''.img_picto($langs->trans('BuildDoc'), 'filenew').''; print ''; //print ''.img_pdf().''; $filearray = array('name'=>basename($file), 'fullname'=>$file, 'type'=>'file'); $out = ''; // Show file name with link to download $out .= 'trans("File").': '.$filearray["name"]); $out .= $filearray["name"]; $out .= ''."\n"; $out .= $formfile->showPreview($filearray, $modulepart, $relativepath, 0, $param); print $out; print ''.dol_print_date(dol_filemtime($file), 'dayhour').''.dol_print_size(dol_filesize($file)).'   
"; print '
'; print '
'; $db->free($resql); } else { dol_print_error($db); } // End of page llxFooter(); $db->close();