1<?php
2/* Copyright (C) 2005-2016 Laurent Destailleur  <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@inodbox.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19/**
20 *      \file       htdocs/projet/info.php
21 *      \ingroup    project
22 *		\brief      Page with events on project
23 */
24
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30
31// Load translation files required by the page
32$langs->load("projects");
33
34$id     = GETPOST('id', 'int');
35$ref    = GETPOST('ref', 'alpha');
36$socid  = GETPOST('socid', 'int');
37$action = GETPOST('action', 'aZ09');
38
39$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
40$sortfield = GETPOST("sortfield", "aZ09comma");
41$sortorder = GETPOST("sortorder", 'aZ09comma');
42$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
43$page = is_numeric($page) ? $page : 0;
44$page = $page == -1 ? 0 : $page;
45if (!$sortfield) {
46	$sortfield = "a.datep,a.id";
47}
48if (!$sortorder) {
49	$sortorder = "DESC";
50}
51$offset = $limit * $page;
52$pageprev = $page - 1;
53$pagenext = $page + 1;
54
55if (GETPOST('actioncode', 'array')) {
56	$actioncode = GETPOST('actioncode', 'array', 3);
57	if (!count($actioncode)) {
58		$actioncode = '0';
59	}
60} else {
61	$actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
62}
63$search_agenda_label = GETPOST('search_agenda_label');
64
65// Security check
66$id = GETPOST("id", 'int');
67$socid = 0;
68//if ($user->socid > 0) $socid = $user->socid;    // For external user, no check is done on company because readability is managed by public status of project and assignement.
69$result = restrictedArea($user, 'projet', $id, 'projet&project');
70
71if (!$user->rights->projet->lire) {
72	accessforbidden();
73}
74
75
76
77/*
78 * Actions
79 */
80
81$parameters = array('id'=>$socid);
82$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
83if ($reshook < 0) {
84	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
85}
86
87// Purge search criteria
88if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
89	$actioncode = '';
90	$search_agenda_label = '';
91}
92
93
94
95/*
96 * View
97 */
98
99$form = new Form($db);
100$object = new Project($db);
101
102if ($id > 0 || !empty($ref)) {
103	$object->fetch($id, $ref);
104	$object->fetch_thirdparty();
105	if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
106		$object->fetchComments();
107	}
108	$object->info($object->id);
109}
110
111$title = $langs->trans("Project").' - '.$object->ref.' '.$object->name;
112if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
113	$title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
114}
115$help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
116llxHeader("", $title, $help_url);
117
118$head = project_prepare_head($object);
119
120print dol_get_fiche_head($head, 'agenda', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
121
122
123// Project card
124
125$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
126
127$morehtmlref = '<div class="refidno">';
128// Title
129$morehtmlref .= $object->title;
130// Thirdparty
131if ($object->thirdparty->id > 0) {
132	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
133}
134$morehtmlref .= '</div>';
135
136// Define a complementary filter for search of next/prev ref.
137if (!$user->rights->projet->all->lire) {
138	$objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
139	$object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
140}
141
142dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
143
144
145print '<div class="fichecenter">';
146print '<div class="underbanner clearboth"></div>';
147
148dol_print_object_info($object, 1);
149
150print '</div>';
151
152print '<div class="clearboth"></div>';
153
154print dol_get_fiche_end();
155
156
157// Actions buttons
158
159$out = '';
160$permok = $user->rights->agenda->myactions->create;
161if ($permok) {
162	$out .= '&projectid='.$object->id;
163}
164
165
166//print '<div class="tabsAction">';
167$morehtmlcenter = '';
168if (!empty($conf->agenda->enabled)) {
169	$addActionBtnRight = !empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create);
170	$morehtmlcenter .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&socid='.$object->socid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $addActionBtnRight);
171}
172
173//print '</div>';
174
175if (!empty($object->id)) {
176	print '<br>';
177
178	$param = '&id='.$object->id;
179	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
180		$param .= '&contextpage='.$contextpage;
181	}
182	if ($limit > 0 && $limit != $conf->liste_limit) {
183		$param .= '&limit='.$limit;
184	}
185
186	print_barre_liste($langs->trans("ActionsOnProject"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlcenter, '', 0, 1, 1);
187
188	// List of all actions
189	$filters = array();
190	$filters['search_agenda_label'] = $search_agenda_label;
191	show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
192}
193
194// End of page
195llxFooter();
196$db->close();
197