Issues (2811)

public/htdocs/fichinter/agenda.php (1 issue)

Labels
Severity
1
<?php
2
3
/* Copyright (C) 2017       Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2024       Rafael San José             <[email protected]>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
use Dolibarr\Code\Core\Classes\ExtraFields;
21
use Dolibarr\Code\Core\Classes\Form;
22
use Dolibarr\Code\FichInter\Classes\Fichinter;
23
use Dolibarr\Code\Projet\Classes\Project;
24
use Dolibarr\Lib\ViewMain;
25
26
/**
27
 *  \file       htdocs/fichinter/agenda.php
28
 *  \ingroup    fichinter
29
 *  \brief      Tab of events on Interventions
30
 */
31
32
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
33
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
34
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/fichinter.lib.php';
35
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php';
36
37
// Load translation files required by the page
38
$langs->loadLangs(array("fichinter", "other"));
39
40
// Get parameters
41
$id = GETPOSTINT('id');
42
$ref = GETPOST('ref', 'alpha');
43
$action = GETPOST('action', 'aZ09');
44
$cancel = GETPOST('cancel', 'aZ09');
45
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search
46
$backtopage = GETPOST('backtopage', 'alpha');
47
48
if (GETPOST('actioncode', 'array')) {
49
    $actioncode = GETPOST('actioncode', 'array', 3);
50
    if (!count($actioncode)) {
51
        $actioncode = '0';
52
    }
53
} else {
54
    $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
55
}
56
$search_rowid = GETPOST('search_rowid');
57
$search_agenda_label = GETPOST('search_agenda_label');
58
59
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60
$sortfield = GETPOST('sortfield', 'aZ09comma');
61
$sortorder = GETPOST('sortorder', 'aZ09comma');
62
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63
if (empty($page) || $page == -1) {
64
    $page = 0;
65
}     // If $page is not defined, or '' or -1
66
$offset = $limit * $page;
67
$pageprev = $page - 1;
68
$pagenext = $page + 1;
69
if (!$sortfield) {
70
    $sortfield = 'a.datep,a.id';
71
}
72
if (!$sortorder) {
73
    $sortorder = 'DESC,DESC';
74
}
75
76
// Initialize technical objects
77
$object = new Fichinter($db);
78
$extrafields = new ExtraFields($db);
79
80
$hookmanager->initHooks(array('myobjectagenda', 'globalcard')); // Note that conf->hooks_modules contains array
81
// Fetch optionals attributes and labels
82
$extrafields->fetch_name_optionals_label($object->table_element);
83
84
// Load object
85
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once  // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
86
87
$permissiontoread = $user->hasRight("fichinter", "lire");
88
$permissiontoadd = $user->hasRight("fichinter", "creer");
89
90
// Security check
91
if (!empty($user->socid)) {
92
    $socid = $user->socid;
93
}
94
$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
95
restrictedArea($user, 'ficheinter', $object->id, 'fichinter', '', 'fk_soc', 'rowid', $isdraft);
96
97
98
99
/*
100
 *  Actions
101
 */
102
103
$parameters = array('id' => $id);
104
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105
if ($reshook < 0) {
106
    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107
}
108
109
if (empty($reshook)) {
110
    // Cancel
111
    if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
112
        header("Location: " . $backtopage);
113
        exit;
114
    }
115
116
    // Purge search criteria
117
    if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
118
        $actioncode = '';
119
        $search_agenda_label = '';
120
    }
121
}
122
123
/*
124
 *	View
125
 */
126
127
$form = new Form($db);
128
129
if ($object->id > 0) {
130
    $title = $langs->trans("Agenda");
131
    $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
132
    ViewMain::llxHeader('', $title, $help_url);
133
134
    if (isModEnabled('notification')) {
135
        $langs->load("mails");
136
    }
137
    $head = fichinter_prepare_head($object);
138
139
140
    print dol_get_fiche_head($head, 'agenda', $langs->trans("Intervention"), -1, $object->picto);
141
142
    // Object card
143
    // ------------------------------------------------------------
144
    $linkback = '<a href="' . constant('BASE_URL') . '/fichinter/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
145
146
    $morehtmlref = '<div class="refidno">';
147
    // Ref customer
148
    $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
149
    $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
150
    // Thirdparty
151
    $morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
0 ignored issues
show
The method getNomUrl() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

151
    $morehtmlref .= '<br>' . $object->thirdparty->/** @scrutinizer ignore-call */ getNomUrl(1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
    // Project
153
    if (isModEnabled('project')) {
154
        $langs->load("projects");
155
        $morehtmlref .= '<br>';
156
        if (0) {
157
            $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
158
            if ($action != 'classify') {
159
                $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
160
            }
161
            $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
162
        } else {
163
            if (!empty($object->fk_project)) {
164
                $proj = new Project($db);
165
                $proj->fetch($object->fk_project);
166
                $morehtmlref .= $proj->getNomUrl(1);
167
                if ($proj->title) {
168
                    $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
169
                }
170
            }
171
        }
172
    }
173
    $morehtmlref .= '</div>';
174
175
176
    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
177
178
    print '<div class="fichecenter">';
179
    print '<div class="underbanner clearboth"></div>';
180
181
    $object->info($object->id);
182
    dol_print_object_info($object, 1);
183
184
    print '</div>';
185
186
    print dol_get_fiche_end();
187
188
189
190
    // Actions buttons
191
192
    $objthirdparty = $object;
193
    $objcon = new stdClass();
194
195
    $out = '&origin=' . urlencode((string) ($object->element . (property_exists($object, 'module') ? '@' . $object->module : ''))) . '&originid=' . urlencode((string) ($object->id));
196
    $urlbacktopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
197
    $out .= '&backtopage=' . urlencode($urlbacktopage);
198
    $permok = $user->hasRight('agenda', 'myactions', 'create');
199
    if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
200
        //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
201
        if (get_only_class($objthirdparty) == 'Societe') {
202
            $out .= '&socid=' . urlencode((string) ($objthirdparty->id));
203
        }
204
        $out .= (!empty($objcon->id) ? '&contactid=' . urlencode($objcon->id) : '');
205
        //$out.=$langs->trans("AddAnAction").' ';
206
        //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
207
        //$out.="</a>";
208
    }
209
210
    $morehtmlright = '';
211
212
    //$messagingUrl = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
213
    //$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
214
    //$messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
215
    //$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
216
217
    if (isModEnabled('agenda')) {
218
        if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
219
            $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', constant('BASE_URL') . '/fichinter/card.php?action=create' . $out);
220
        } else {
221
            $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', constant('BASE_URL') . '/fichinter/card.php?action=create' . $out, '', 0);
222
        }
223
    }
224
225
226
    if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
227
        print '<br>';
228
229
        $param = '&id=' . $object->id . (!empty($socid) ? '&socid=' . $socid : '');
230
        if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
231
            $param .= '&contextpage=' . urlencode($contextpage);
232
        }
233
        if ($limit > 0 && $limit != $conf->liste_limit) {
234
            $param .= '&limit=' . ((int) $limit);
235
        }
236
237
        // Try to know count of actioncomm from cache
238
        require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/memory.lib.php';
239
        $cachekey = 'count_events_fichinter_' . $object->id;
240
        $nbEvent = dol_getcache($cachekey);
241
242
        print_barre_liste($langs->trans("ActionsOnFicheInter") . (is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">(' . $nbEvent . ')</span>' : ''), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
243
        //print_barre_liste($langs->trans("ActionsOnPropal"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
244
245
        // List of all actions
246
        $filters = array();
247
        $filters['search_agenda_label'] = $search_agenda_label;
248
        $filters['search_rowid'] = $search_rowid;
249
250
        // TODO Replace this with same code than into list.php
251
        show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, property_exists($object, 'module') ? $object->module : '');
252
    }
253
}
254
255
// End of page
256
ViewMain::llxFooter();
257
$db->close();
258