-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathactions_digiquali.class.php
417 lines (374 loc) · 15.8 KB
/
actions_digiquali.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?php
/* Copyright (C) 2022 EVARISK <[email protected]>
*
* 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 <https://www.gnu.org/licenses/>.
*/
/**
* \file class/actions_digiquali.class.php
* \ingroup digiquali
* \brief DigiQuali hook overload.
*/
/**
* Class ActionsDigiquali
*/
class ActionsDigiquali
{
/**
* @var DoliDB Database handler.
*/
public $db;
/**
* @var string Error code (or message)
*/
public $error = '';
/**
* @var array Errors
*/
public $errors = array();
/**
* @var array Hook results. Propagated to $hookmanager->resArray for later reuse
*/
public $results = array();
/**
* @var string String displayed by executeHook() immediately after return
*/
public $resprints;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Overloading the constructCategory function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function constructCategory($parameters, &$object)
{
$error = 0; // Error counter
if (strpos($parameters['context'], 'category') !== false) {
$tags = [
'question' => [
'id' => 436301001,
'code' => 'question',
'obj_class' => 'Question',
'obj_table' => 'digiquali_question',
],
'sheet' => [
'id' => 436301002,
'code' => 'sheet',
'obj_class' => 'Sheet',
'obj_table' => 'digiquali_sheet',
],
'control' => [
'id' => 436301003,
'code' => 'control',
'obj_class' => 'Control',
'obj_table' => 'digiquali_control',
],
'survey' => [
'id' => 436301004,
'code' => 'survey',
'obj_class' => 'Survey',
'obj_table' => 'digiquali_survey',
]
];
}
if (!$error) {
$this->results = $tags;
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the doActions function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadata (context, etc...)
* @param object $object The object to process
* @param string $action Current action (if set). Generally create or edit or null
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function doActions(array $parameters, $object, string $action): int
{
global $langs, $user;
$error = 0; // Error counter
if (strpos($parameters['context'], 'categorycard') !== false) {
require_once __DIR__ . '/../class/question.class.php';
require_once __DIR__ . '/../class/sheet.class.php';
require_once __DIR__ . '/../class/control.class.php';
require_once __DIR__ . '/../class/survey.class.php';
}
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the addHtmlHeader function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadata (context, etc...)
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function addHtmlHeader(array $parameters): int
{
if (strpos($_SERVER['PHP_SELF'], 'digiquali') !== false) {
?>
<script>
$('link[rel="manifest"]').remove();
</script>
<?php
$this->resprints = '<link rel="manifest" href="' . DOL_URL_ROOT . '/custom/digiquali/manifest.json.php' . '" />';
}
return 0; // or return 1 to replace standard code-->
}
/**
* Overloading the printCommonFooter function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
public function printCommonFooter($parameters)
{
global $conf, $form, $langs, $object, $user;
$error = 0; // Error counter
if (strpos($parameters['context'], 'categoryindex') !== false) { // do something only for the context 'somecontext1' or 'somecontext2'
print '<script src="../custom/digiquali/js/digiquali.js"></script>';
} elseif (strpos($parameters['context'], 'productlotcard') !== false) {
$productLot = new ProductLot($this->db);
$productLot->fetch(GETPOST('id'));
$objectB64 = $productLot->array_options['options_control_history_link'];
$publicControlInterfaceUrl = dol_buildpath('custom/digiquali/public/control/public_control_history.php?track_id=' . $objectB64 . '&entity=' . $conf->entity, 3);
$out = showValueWithClipboardCPButton($publicControlInterfaceUrl, 0, ' ');
$out .= '<a target="_blank" href="'. $publicControlInterfaceUrl .'"><div class="butAction">';
$out .= '<i class="fa fa-external-link"></i>';
$out .= '</div></a>'; ?>
<script>
$('[class*=extras_control_history_link]').html(<?php echo json_encode($out) ?>);
</script>
<?php
}
require_once __DIR__ . '/../lib/digiquali_sheet.lib.php';
$linkableElements = get_sheet_linkable_objects();
if (!empty($linkableElements)) {
foreach($linkableElements as $linkableElement) {
if ($linkableElement['link_name'] == $object->element) {
if (strpos($parameters['context'], $linkableElement['hook_name_card']) !== false) {
$picto = img_picto('', 'fontawesome_fa-clipboard-check_fas_#d35968', 'class="pictofixedwidth"');
$extrafieldsNames = ['qc_frequency', 'control_history_link'];
foreach ($extrafieldsNames as $extrafieldsName) {
$jQueryElement = 'td.' . $object->element . '_extras_' . $extrafieldsName; ?>
<script>
var objectElement = <?php echo "'" . $jQueryElement . "'"; ?>;
jQuery(objectElement).prepend(<?php echo json_encode($picto); ?>);
</script>
<?php
}
} elseif (preg_match('/' . $linkableElement['hook_name_list'] . '|projecttaskscard/', $parameters['context'])) {
$picto = img_picto('', 'fontawesome_fa-clipboard-check_fas_#d35968', 'class="pictofixedwidth"');
$extrafieldsNames = ['qc_frequency', 'control_history_link'];
foreach ($extrafieldsNames as $extrafieldsName) { ?>
<script>
var objectElement = <?php echo "'" . $extrafieldsName . "'"; ?>;
var outJS = <?php echo json_encode($picto); ?>;
var cell = $('.liste > tbody > tr.liste_titre').find('th[data-titlekey="' + objectElement + '"]');
cell.prepend(outJS);
</script>
<?php
}
}
}
}
}
if (!$error) {
$this->results = array('myreturn' => 999);
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the formObjectOptions function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @param object|null $object Current object
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function formObjectOptions(array $parameters, ?object $object): int
{
if (strpos($parameters['context'], 'productlotcard') !== false) {
$objectData = ['type' => $object->element, 'id' => $object->id];
$objectDataJson = json_encode($objectData);
$objectDataB64 = base64_encode($objectDataJson);
if (dol_strlen($object->array_options['options_control_history_link'] == 0 )) {
$object->array_options['options_control_history_link'] = $objectDataB64;
$object->updateExtrafield('control_history_link');
}
}
return 0; // or return 1 to replace standard code
}
/**
* Overloading the redirectAfterConnection function : replacing the parent's function with the one below
*
* @param $parameters
* @return int
*/
public function redirectAfterConnection($parameters)
{
global $conf;
if (strpos($parameters['context'], 'mainloginpage') !== false) {
if ($conf->global->DIGIQUALI_REDIRECT_AFTER_CONNECTION) {
$value = dol_buildpath('/custom/digiquali/digiqualiindex.php?mainmenu=digiquali', 1);
} else {
$value = '';
}
}
if (true) {
$this->resprints = $value;
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the saturneBannerTab function : replacing the parent's function with the one below.
*
* @param array $parameters Hook metadatas (context, etc...).
* @param CommonObject $object Current object.
* @return int 0 < on error, 0 on success, 1 to replace standard code.
*/
public function saturneBannerTab(array $parameters, CommonObject $object): int
{
global $conf, $langs;
// Do something only for the current context.
if (preg_match('/controlcard|surveycard/', $parameters['context'])) {
if ($conf->browser->layout == 'phone') {
$morehtmlref = '<br><div>' . img_picto('', 'fontawesome_fa-caret-square-down_far_#966EA2F2_fa-2em', 'class="toggle-object-infos pictofixedwidth valignmiddle" style="width: 35px;"') . $langs->trans('DisplayMoreInfo') . '</div>';
} else {
$morehtmlref = '';
}
$this->resprints = $morehtmlref;
}
return 0; // or return 1 to replace standard code.
}
/**
* Overloading the saturneAdminDocumentData function : replacing the parent's function with the one below.
*
* @param array $parameters Hook metadatas (context, etc...).
* @return int 0 < on error, 0 on success, 1 to replace standard code.
*/
public function saturneAdminDocumentData(array $parameters): int
{
// Do something only for the current context.
if (strpos($parameters['context'], 'digiqualiadmindocuments') !== false) {
$types = [
'ControlDocument' => [
'documentType' => 'controldocument',
'picto' => 'fontawesome_fa-tasks_fas_#d35968'
],
'SurveyDocument' => [
'documentType' => 'surveydocument',
'picto' => 'fontawesome_fa-marker_fas_#d35968'
]
];
$this->results = $types;
}
return 0; // or return 1 to replace standard code.
}
/**
* Overloading the saturneAdminObjectConst function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function saturneAdminObjectConst(array $parameters): int
{
if (strpos($parameters['context'], 'surveyadmin') !== false) {
$constArray['digiquali'] = [
'DisplayMedias' => [
'name' => 'DisplayMediasSample',
'description' => 'DisplaySurveyMediasSampleDescription',
'code' => 'DIGIQUALI_SURVEY_DISPLAY_MEDIAS',
],
'UseLargeSizeMedia' => [
'name' => 'UseLargeSizeMedia',
'description' => 'UseLargeSizeMediaDescription',
'code' => 'DIGIQUALI_SURVEY_USE_LARGE_MEDIA_IN_GALLERY',
],
'AutoSaveActionQuestionAnswer' => [
'name' => 'AutoSaveActionQuestionAnswer',
'description' => 'AutoSaveActionQuestionAnswerDescription',
'code' => 'DIGIQUALI_SURVEYDET_AUTO_SAVE_ACTION',
]
];
$this->results = $constArray;
return 1;
}
if (strpos($parameters['context'], 'controladmin') !== false) {
$constArray['digiquali'] = [
'DisplayMedias' => [
'name' => 'DisplayMediasSample',
'description' => 'DisplayMediasSampleDescription',
'code' => 'DIGIQUALI_CONTROL_DISPLAY_MEDIAS',
],
'UseLargeSizeMedia' => [
'name' => 'UseLargeSizeMedia',
'description' => 'UseLargeSizeMediaDescription',
'code' => 'DIGIQUALI_CONTROL_USE_LARGE_MEDIA_IN_GALLERY',
],
'LockControlOutdatedEquipment' => [
'name' => 'LockControlOutdatedEquipment',
'description' => 'LockControlOutdatedEquipmentDescription',
'code' => 'DIGIQUALI_LOCK_CONTROL_OUTDATED_EQUIPMENT',
],
'AutoSaveActionQuestionAnswer' => [
'name' => 'AutoSaveActionQuestionAnswer',
'description' => 'AutoSaveActionQuestionAnswerDescription',
'code' => 'DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION',
],
'EnablePublicControlHistory' => [
'name' => 'EnablePublicControlHistory',
'description' => 'EnablePublicControlHistoryDescription',
'code' => 'DIGIQUALI_ENABLE_PUBLIC_CONTROL_HISTORY',
],
'ShowQcFrequencyPublicInterface' => [
'name' => 'ShowQcFrequencyPublicInterface',
'description' => 'ShowQcFrequencyPublicInterfaceDescription',
'code' => 'DIGIQUALI_SHOW_QC_FREQUENCY_PUBLIC_INTERFACE',
],
'ShowLastControlFirstOnPublicHistory' => [
'name' => 'ShowLastControlFirstOnPublicHistory',
'description' => 'ShowLastControlFirstOnPublicHistoryDescription',
'code' => 'DIGIQUALI_SHOW_LAST_CONTROL_FIRST_ON_PUBLIC_HISTORY',
]
];
$this->results = $constArray;
return 1;
}
return 0; // or return 1 to replace standard code.
}
}