3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2010, Franck Villaume - Capgemini
5 * Copyright 2012-2013, Franck Villaume - TrivialDev
6 * Copyright 2013, French Ministry of National Education
8 * This file is a part of Fusionforge.
10 * Fusionforge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Fusionforge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
24 require_once 'Widget.class.php';
27 * Widget_ProjectLatestDocuments
30 class Widget_ProjectLatestDocuments extends Widget {
32 function __construct() {
33 $this->Widget('projectlatestdocuments');
34 $request =& HTTPRequest::instance();
35 $pm = ProjectManager::instance();
36 $project = $pm->getProject($request->get('group_id'));
37 if ($project && $this->canBeUsedByProject($project) && forge_check_perm('docman', $project->getID(), 'read')) {
38 $this->content['title'] = _('5 Latest Published Documents');
43 return $this->content['title'];
46 function getContent() {
48 $request =& HTTPRequest::instance();
49 $group_id = $request->get('group_id');
51 $qpa = db_construct_qpa();
52 $qpa = db_construct_qpa($qpa, 'SELECT filename, title, updatedate, createdate, realname, user_name, state_name, filetype, docid
57 if (session_loggedin() && (user_ismember($group_id) ||
58 forge_check_global_perm('forge_admin'))) {
59 $qpa = db_construct_qpa($qpa, ' AND stateid IN ($1, $2, $3, $4)', array('1','3','4','5'));
61 $qpa = db_construct_qpa($qpa, ' AND stateid=$1', array('1'));
64 $qpa = db_construct_qpa($qpa, ' ORDER BY updatedate,createdate DESC LIMIT 5',array());
65 $res_files = db_query_qpa($qpa);
67 $rows_files = db_numrows($res_files);
68 if (!$res_files || $rows_files < 1) {
71 echo '<div class="warning">'._('This Project Has Not Published Any Documents').'</div>';
73 $tabletop = array(_('Date'), _('Filename'), _('Title'), _('Author'));
74 if (session_loggedin() && (user_ismember($group_id) ||
75 forge_check_global_perm('forge_admin'))) {
76 $tabletop[] = _('Status');
78 echo $HTML->listTableTop($tabletop, false, 'sortable_widget_docman_listfile', 'sortable');
79 for ($f=0; $f<$rows_files; $f++) {
80 $updatedate = db_result($res_files, $f, 'updatedate');
81 $createdate = db_result($res_files, $f, 'createdate');
82 $realdate = ($updatedate >= $createdate) ? $updatedate : $createdate;
83 $filename = db_result($res_files,$f,'filename');
84 $title = db_result($res_files,$f,'title');
85 $realname = db_result($res_files,$f,'realname');
86 $user_name = db_result($res_files,$f,'user_name');
87 $statename = db_result($res_files,$f,'state_name');
88 $filetype = db_result($res_files,$f,'filetype');
89 $docid = db_result($res_files,$f,'docid');
96 $docurl = util_make_url('/docman/view.php/'.$group_id.'/'.$docid.'/'.urlencode($filename));
100 <tr '. $HTML->boxGetAltRowStyle($f+1) .'>
102 . date(_('Y-m-d'),$realdate) .
105 <a href="'.$docurl.'" ><strong>' . $filename . '</strong></a>
111 . make_user_link($user_name, $realname) .
113 if (session_loggedin() && (user_ismember($group_id) ||
114 forge_check_global_perm('forge_admin'))) {
121 echo $HTML->listTableBottom();
123 echo '<div class="underline-link">' . util_make_link('/docman/?group_id='.$group_id, _('Browse Documents Manager')) . '</div>';
126 function isAvailable() {
127 return isset($this->content['title']);
130 function canBeUsedByProject(&$project) {
131 return $project->usesDocman();
134 function getCategory() {
135 return 'Documents-Manager';
138 function getDescription() {
139 return _(' List the 5 most recent documents published by team project.');