openstamanager/modules/checklists/modutil.php

197 lines
7.8 KiB
PHP
Raw Normal View History

2019-07-30 16:50:10 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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/>.
*/
2019-07-30 16:50:10 +02:00
function renderChecklist($check, $level = 1, $parent = 0) {
global $structure;
2019-07-30 16:50:10 +02:00
$user = auth()->getUser();
$enabled = $check->assignedUsers ? ($check->assignedUsers->pluck('id')->search($user->id) !== false || ($user->idgruppo) == 1): true;
2019-07-30 16:50:10 +02:00
$margin = ($level*20);
2019-07-30 16:50:10 +02:00
$result = '
<tr id="check_'.$check->id.'" data-id="'.$check->id.'" class="sortablerow sonof_'.$parent.'" >
<td style="padding-top:0px;padding-bottom:0px;border-top:0px;">
<table class="table" style="margin-bottom:0px;">
<tr>';
$result .= '
<td style="width:40px;text-align:center;border-top:0px;border-left:3px solid #eaeaea;">
2023-05-26 15:41:55 +02:00
<input type="checkbox" class="checkbox unblockable" data-id="'.$check->id.'" value="'.(!empty($check->checked_at) ? '1' : '0').'" '.(!empty($check->checked_at) ? 'checked' : '').' '.(!$enabled ? 'disabled' : '').'>
</td>';
2019-07-30 16:50:10 +02:00
$result .= '
<td style="border-top:0px;">
2023-05-26 15:41:55 +02:00
<span class="text unblockable" style="'.(!empty($check->checked_at)?'text-decoration:line-through;':'').'">'.$check->content.' </span>
2023-05-19 17:15:30 +02:00
</td>';
$result .= '
<td style="width:500px;border-top:0px;">
2023-05-26 15:41:55 +02:00
{[ "type": "textarea", "class": "unblockable", "name": "note_checklist", "placeholder": "'.tr('Note').'...", "id": "'.$check->id.'", "value": "'.$check->note.'" ]}
2023-05-19 17:15:30 +02:00
</td>';
$result .= '
<td style="width:250px;border-top:0px;">';
2019-07-30 16:50:10 +02:00
2023-02-20 19:01:24 +01:00
if (intval($check->assignedUsers->pluck('id')->toArray())>0){
$result .= ' <span class="label label-info pull-right" style="padding:6px 8px;" data-toggle="tooltip" title="Assegnato a '. implode(', ', $check->assignedUsers->pluck('username')->toArray()).'"><i class="fa fa-user"></i></span>';
2023-02-20 19:01:24 +01:00
}else{
$result .= ' <span class="label label-danger pull-right" style="padding:6px 8px;">'. tr('Nessun utente assegnato').'</span>';
2023-02-20 19:01:24 +01:00
}
if(!empty($check->checked_at)){
$result .= '
<span class="label label-default pull-right" style="margin-right:5px;padding:6px 8px;">'.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [
'_NAME_' => $check->checkUser->username,
'_DATE_' => timestampFormat($check->checked_at),
]) : '').'
</span>';
2019-07-30 17:44:15 +02:00
}
$result .= '
</td>';
2019-07-30 17:44:15 +02:00
2020-12-02 11:31:52 +01:00
$result .= '
2023-05-19 17:15:30 +02:00
<td style="width:10px;text-align:center;border-top:0px;">
<div class="input-group-btn">
<button class="btn btn-warning btn-xs '.(!$enabled ? 'disabled' : '').'" onclick="edit_check(\''.$check->id.'\')"><i class="fa fa-edit"></i></button>
<button class="btn btn-danger btn-xs '.(!$enabled ? 'disabled' : '').'" onclick="delete_check(\''.$check->id.'\')"><i class="fa fa-trash"></i></button>
2023-05-19 17:15:30 +02:00
<button class="btn btn-xs btn-default handle" title="Modifica ordine delle righe" draggable="true"><i class="fa fa-sort"></i></button>
</div>
</td>';
2020-12-04 15:40:47 +01:00
2019-07-30 17:44:15 +02:00
$result .= '
</tr>';
2019-07-30 16:50:10 +02:00
if(sizeof($check->children)>0){
$result .= '
<tr>
2023-05-19 17:15:30 +02:00
<td colspan="5" style="padding-left:'.$margin.'px;padding-right:10px;padding-top:0px;padding-bottom:0px;border-top:0px;">
<table class="table" style="margin-bottom:0px;">
<tbody class="sort" data-sonof="'.$check->id.'">';
$children = $structure->checks()->where('id_parent', $check->id)->orderBy('order')->get();
foreach ($children as $child) {
$result .= renderChecklist($child, $level + 1, $check->id);
}
$result .= '
</tbody>
</table>
</td>
</tr>';
2019-07-30 16:50:10 +02:00
}
$result .= '
</table>
</td>
</tr>';
return $result;
}
function renderChecklistInserimento($check, $level = 1, $parent = 0)
{
global $record;
$margin = ($level*20);
$result = '
<tr id="check_'.$check->id.'" data-id="'.$check->id.'" class="sortablerow sonof_'.$parent.'" >
<td style="padding-top:0px;padding-bottom:0px;border-top:0px;">
<table class="table" style="margin-bottom:0px;">
<tr>';
$result .= '
<td style="width:40px;border-top:0px;border-left:3px solid #eaeaea;">';
$result .= '
<span class="text">'.$check->content.'</span>';
$result .= '
</td>';
$result .= '
<td style="width:40px;text-align:right;border-top:0px;">
<div class="input-group-btn">
<button class="btn btn-warning btn-xs" onclick="edit_check(\''.$check->id.'\')"><i class="fa fa-edit"></i></button>
<button class="btn btn-danger btn-xs" onclick="delete_check(\''.$check->id.'\')"><i class="fa fa-trash"></i></button>
</div>
</td>';
$result .= '
</tr>';
if(sizeof($check->children)>0){
$result .= '
<tr>
<td colspan="4" style="padding-left:'.$margin.'px;padding-right:0px;padding-top:0px;padding-bottom:0px;border-top:0px;">
<table class="table" style="margin-bottom:0px;">
<tbody class="sort" data-sonof="'.$check->id.'">';
$children = $record->checks()->where('id_parent', $check->id)->orderBy('order')->get();
foreach ($children as $child) {
$result .= renderChecklistInserimento($child, $level + 1, $check->id);
}
$result .= '
</tbody>
</table>
</td>
</tr>';
}
$result .= '
</table>
</td>
<td style="width:40px;text-align:center;border-top:0px;">
<button class="btn btn-xs btn-default handle" title="Modifica ordine delle righe" draggable="true">
<i class="fa fa-sort"></i>
</button>
</td>
</tr>';
2019-07-30 16:50:10 +02:00
return $result;
}
function renderChecklistHtml($check, $level = 0)
{
$user = auth()->getUser();
$enabled = $check->assignedUsers ? $check->assignedUsers->pluck('id')->search($user->id) !== false : true;
$width = 10+20*$level;
$result = '
<tr>
<td class="text-center" style="width:30px;">
2023-03-17 14:58:09 +01:00
'.(!empty($check->checked_at)?'<img src="'.ROOTDIR.'/templates/interventi/check.png" style="width:10px;">':'').'
</td>
<td style="padding-left:'.$width.'px;">
<span class="text"><b>'.$check->content.'</b>'.(!empty($check->value)?': '.$check->value:'').'</span>
</td>
</tr>';
$children = $check->children;
foreach ($children as $child) {
$result .= renderChecklistHtml($child, $level + 1);
}
return $result;
}