Issues (2811)

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

Labels
Severity
1
<?php
2
3
/* Copyright (C) 2004-2009  Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2017       Ferran Marcet       	    <[email protected]>
5
 * Copyright (C) 2024       Rafael San José             <[email protected]>
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
21
use Dolibarr\Code\Contrat\Classes\Contrat;
22
use Dolibarr\Code\Core\Classes\Form;
23
use Dolibarr\Code\Core\Classes\FormFile;
24
use Dolibarr\Code\Core\Classes\FormProjets;
25
use Dolibarr\Code\Projet\Classes\Project;
26
use Dolibarr\Lib\ViewMain;
27
28
/**
29
 *      \file       htdocs/contrat/agenda.php
30
 *      \ingroup    contrat
31
 *      \brief      Page of contract events
32
 */
33
34
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
35
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
36
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php';
37
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/contract.lib.php';
38
39
// Load translation files required by the page
40
$langs->loadLangs(array("companies", "contracts"));
41
42
$action = GETPOST('action', 'alpha');
43
$confirm = GETPOST('confirm', 'alpha');
44
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contratagenda';
45
46
if (GETPOST('actioncode', 'array')) {
47
    $actioncode = GETPOST('actioncode', 'array', 3);
48
    if (!count($actioncode)) {
49
        $actioncode = '0';
50
    }
51
} else {
52
    $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
53
}
54
55
$search_rowid = GETPOST('search_rowid');
56
$search_agenda_label = GETPOST('search_agenda_label');
57
58
$id = GETPOSTINT('id');
59
$ref = GETPOST('ref', 'alpha');
60
61
// Security check
62
if ($user->socid) {
63
    $socid = $user->socid;
64
}
65
66
// Security check
67
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
68
$fieldtype = (!empty($id) ? 'rowid' : 'ref');
69
$result = restrictedArea($user, 'contrat', $fieldvalue, '', '', '', $fieldtype);
70
71
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
72
$sortfield = GETPOST('sortfield', 'aZ09comma');
73
$sortorder = GETPOST('sortorder', 'aZ09comma');
74
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
75
if (empty($page) || $page == -1) {
76
    $page = 0;
77
}     // If $page is not defined, or '' or -1
78
$offset = $limit * $page;
79
$pageprev = $page - 1;
80
$pagenext = $page + 1;
81
if (!$sortfield) {
82
    $sortfield = 'a.datep,a.id';
83
}
84
if (!$sortorder) {
85
    $sortorder = 'DESC,DESC';
86
}
87
88
$object = new Contrat($db);
89
if ($id > 0 || !empty($ref)) {
90
    $result = $object->fetch($id, $ref);
91
}
92
93
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
94
$hookmanager->initHooks(array('agendacontract', 'globalcard'));
95
96
$permissiontoadd = $user->hasRight('contrat', 'creer');     //  Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
97
98
$result = restrictedArea($user, 'contrat', $object->id);
99
100
/*
101
 * Actions
102
 */
103
104
$parameters = array('id' => $id, 'ref' => $ref);
105
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106
if ($reshook < 0) {
107
    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108
}
109
110
if (empty($reshook)) {
111
    // Cancel
112
    if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
113
        header("Location: " . $backtopage);
114
        exit;
115
    }
116
117
    // Purge search criteria
118
    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
119
        $actioncode = '';
120
        $search_agenda_label = '';
121
    }
122
}
123
124
/*
125
 * View
126
 */
127
128
$form = new Form($db);
129
$formfile = new FormFile($db);
130
if (isModEnabled('project')) {
131
    $formproject = new FormProjets($db);
132
}
133
134
if ($object->id > 0) {
135
    // Load object modContract
136
    $module = (getDolGlobalString('CONTRACT_ADDON') ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
137
    if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
138
        $module = substr($module, 0, dol_strlen($module) - 4);
139
    }
140
    $result = dol_include_once('/core/modules/contract/' . $module . '.php');
141
    if ($result > 0) {
142
        $modCodeContract = new $module();
143
    }
144
145
    require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
146
147
    $object->fetch_thirdparty();
148
149
    $title = $langs->trans("Agenda");
150
    if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contractrefonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->ref) {
151
        $title = $object->ref . " - " . $title;
152
    }
153
    $help_url = 'EN:Module_Contracts|FR:Module_Contrat';
154
155
    ViewMain::llxHeader('', $title, $help_url);
156
157
    if (isModEnabled('notification')) {
158
        $langs->load("mails");
159
    }
160
    $head = contract_prepare_head($object);
161
162
    print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
163
164
    $linkback = '<a href="' . constant('BASE_URL') . '/contrat/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
165
166
    $morehtmlref = '';
167
    if (!empty($modCodeContract->code_auto)) {
168
        $morehtmlref .= $object->ref;
169
    } else {
170
        $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 3);
171
        $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 2);
172
    }
173
174
    $permtoedit = 0;
175
176
    $morehtmlref .= '<div class="refidno">';
177
    // Ref customer
178
    $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
179
    $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
180
    // Ref supplier
181
    $morehtmlref .= '<br>';
182
    $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
183
    $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
184
    // Thirdparty
185
    $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

185
    $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...
186
    if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
187
        $morehtmlref .= ' (<a href="' . constant('BASE_URL') . '/contrat/list.php?socid=' . $object->thirdparty->id . '&search_name=' . urlencode($object->thirdparty->name) . '">' . $langs->trans("OtherContracts") . '</a>)';
188
    }
189
    // Project
190
    if (isModEnabled('project')) {
191
        $langs->load("projects");
192
        $morehtmlref .= '<br>';
193
        if (0) {
194
            $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
195
            if ($action != 'classify') {
196
                $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
197
            }
198
            $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
199
        } else {
200
            if (!empty($object->fk_project)) {
201
                $proj = new Project($db);
202
                $proj->fetch($object->fk_project);
203
                $morehtmlref .= $proj->getNomUrl(1);
204
                if ($proj->title) {
205
                    $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
206
                }
207
            }
208
        }
209
    }
210
    $morehtmlref .= '</div>';
211
212
    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
213
214
    print '<div class="fichecenter">';
215
216
    print '<div class="underbanner clearboth"></div>';
217
218
    $object->info($object->id);
219
    dol_print_object_info($object, 1);
220
221
    print '</div>';
222
223
    print dol_get_fiche_end();
224
225
226
    // Actions buttons
227
228
    /*$objthirdparty=$object;
229
    $objcon=new stdClass();
230
231
    $out='';
232
    $permok=$user->rights->agenda->myactions->create;
233
    if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
234
    {
235
        //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
236
        if (get_only_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
237
        $out.=(!empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1';
238
        //$out.=$langs->trans("AddAnAction").' ';
239
        //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
240
        //$out.="</a>";
241
    }*/
242
243
244
    //print '<div class="tabsAction">';
245
    //print '</div>';
246
247
248
    $newcardbutton = '';
249
    if (isModEnabled('agenda')) {
250
        if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
251
            $backtopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
252
            $out = '&origin=' . $object->element . '&originid=' . $object->id . '&backtopage=' . urlencode($backtopage);
253
            $messagingUrl = constant('BASE_URL') . '/contrat/messaging.php?id=' . $object->id;
254
            $newcardbutton .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
255
            $messagingUrl = constant('BASE_URL') . '/contrat/agenda.php?id=' . $object->id;
256
            $newcardbutton .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
257
            $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', constant('BASE_URL') . '/comm/action/card.php?action=create' . $out);
258
        }
259
    }
260
261
    if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
262
        print '<br>';
263
264
        $param = '&id=' . $object->id;
265
        if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
266
            $param .= '&contextpage=' . $contextpage;
267
        }
268
        if ($limit > 0 && $limit != $conf->liste_limit) {
269
            $param .= '&limit=' . $limit;
270
        }
271
272
        // Try to know count of actioncomm from cache
273
        require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/memory.lib.php';
274
        $cachekey = 'count_events_thirdparty_' . $object->id;
275
        $nbEvent = dol_getcache($cachekey);
276
277
        print_barre_liste($langs->trans("ActionsOnContract"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 0);
278
279
        // List of all actions
280
        $filters = array();
281
        $filters['search_agenda_label'] = $search_agenda_label;
282
        $filters['search_rowid'] = $search_rowid;
283
284
        // TODO Replace this with same code than into list.php
285
        show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
286
    }
287
}
288
289
ViewMain::llxFooter();
290
$db->close();
291