2014-09-21 17:42:38 +02:00
|
|
|
<?php
|
2019-01-28 21:39:22 +01:00
|
|
|
/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
2018-05-19 08:06:52 +02:00
|
|
|
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
|
2014-09-21 17:42:38 +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
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-09-21 17:42:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-22 20:19:22 +01:00
|
|
|
* \file htdocs/loan/document.php
|
2014-09-22 08:25:39 +02:00
|
|
|
* \ingroup loan
|
|
|
|
|
* \brief Page with attached files on loan
|
2014-09-21 17:42:38 +02:00
|
|
|
*/
|
|
|
|
|
|
2015-03-22 20:19:22 +01:00
|
|
|
require '../main.inc.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
|
2014-09-21 17:42:38 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
2014-09-22 08:25:39 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
|
2014-09-21 17:42:38 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
2020-04-10 10:59:32 +02:00
|
|
|
if (!empty($conf->projet->enabled)) {
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
2017-12-26 12:13:35 +01:00
|
|
|
}
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2018-05-26 21:11:25 +02:00
|
|
|
// Load translation files required by the page
|
2020-04-10 10:59:32 +02:00
|
|
|
$langs->loadLangs(array("other", "companies", "compta", "bills", "loan"));
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
$id = GETPOST('id', 'int');
|
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
2014-09-21 17:42:38 +02:00
|
|
|
$confirm = GETPOST('confirm', 'alpha');
|
|
|
|
|
|
|
|
|
|
// Security check
|
2021-02-26 18:20:21 +01:00
|
|
|
if ($user->socid) {
|
|
|
|
|
$socid = $user->socid;
|
|
|
|
|
}
|
2019-01-27 11:55:16 +01:00
|
|
|
$result = restrictedArea($user, 'loan', $id, '', '');
|
2014-09-21 17:42:38 +02:00
|
|
|
|
|
|
|
|
// Get parameters
|
2020-04-20 15:06:27 +02:00
|
|
|
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
|
2019-01-27 11:55:16 +01:00
|
|
|
$sortfield = GETPOST("sortfield", 'alpha');
|
|
|
|
|
$sortorder = GETPOST("sortorder", 'alpha');
|
2020-03-13 13:07:11 +01:00
|
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
|
2019-05-31 15:53:23 +02:00
|
|
|
if (empty($page) || $page == -1) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$page = 0;
|
2014-09-21 17:42:38 +02:00
|
|
|
}
|
2020-04-20 15:06:27 +02:00
|
|
|
$offset = $limit * $page;
|
2014-09-21 17:42:38 +02:00
|
|
|
$pageprev = $page - 1;
|
|
|
|
|
$pagenext = $page + 1;
|
2021-02-26 18:20:21 +01:00
|
|
|
if (!$sortorder) {
|
|
|
|
|
$sortorder = "ASC";
|
|
|
|
|
}
|
|
|
|
|
if (!$sortfield) {
|
|
|
|
|
$sortfield = "name";
|
|
|
|
|
}
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2014-09-22 08:25:39 +02:00
|
|
|
$object = new Loan($db);
|
2021-02-26 18:20:21 +01:00
|
|
|
if ($id > 0) {
|
|
|
|
|
$object->fetch($id);
|
|
|
|
|
}
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2014-09-22 08:25:39 +02:00
|
|
|
$upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
|
2019-11-13 19:35:39 +01:00
|
|
|
$modulepart = 'loan';
|
2014-09-21 17:42:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-19 16:10:19 +01:00
|
|
|
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
2014-09-21 17:42:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$form = new Form($db);
|
|
|
|
|
|
2019-11-13 19:35:39 +01:00
|
|
|
$title = $langs->trans("Loan").' - '.$langs->trans("Documents");
|
2016-12-20 07:29:49 +01:00
|
|
|
$help_url = 'EN:Module_Loan|FR:Module_Emprunt';
|
2019-01-27 11:55:16 +01:00
|
|
|
llxHeader("", $title, $help_url);
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2021-02-26 18:20:21 +01:00
|
|
|
if ($object->id) {
|
2019-11-13 19:35:39 +01:00
|
|
|
$totalpaid = $object->getSumPayment();
|
2015-04-07 03:00:11 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$head = loan_prepare_head($object);
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print dol_get_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref = '<div class="refidno">';
|
2016-12-20 07:29:49 +01:00
|
|
|
// Ref loan
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
|
|
|
|
|
$morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
|
2017-07-29 00:28:41 +02:00
|
|
|
// Project
|
2019-11-13 19:35:39 +01:00
|
|
|
if (!empty($conf->projet->enabled)) {
|
2017-07-29 00:28:41 +02:00
|
|
|
$langs->load("projects");
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= '<br>'.$langs->trans('Project').' : ';
|
2017-07-29 00:28:41 +02:00
|
|
|
if ($user->rights->loan->write) {
|
|
|
|
|
//if ($action != 'classify')
|
2019-10-06 15:34:22 +02:00
|
|
|
// $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
|
2017-07-29 00:28:41 +02:00
|
|
|
if ($action == 'classify') {
|
|
|
|
|
// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
|
2017-07-29 00:28:41 +02:00
|
|
|
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
|
2019-12-18 23:12:31 +01:00
|
|
|
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
|
2017-07-29 00:28:41 +02:00
|
|
|
$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
2017-07-29 00:28:41 +02:00
|
|
|
$morehtmlref .= '</form>';
|
|
|
|
|
} else {
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
|
2017-07-29 00:28:41 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-11-13 19:35:39 +01:00
|
|
|
if (!empty($object->fk_project)) {
|
2017-07-29 00:28:41 +02:00
|
|
|
$proj = new Project($db);
|
|
|
|
|
$proj->fetch($object->fk_project);
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
|
2017-07-29 00:28:41 +02:00
|
|
|
$morehtmlref .= $proj->ref;
|
|
|
|
|
$morehtmlref .= '</a>';
|
|
|
|
|
} else {
|
|
|
|
|
$morehtmlref .= '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-13 19:35:39 +01:00
|
|
|
$morehtmlref .= '</div>';
|
2016-12-20 07:29:49 +01:00
|
|
|
|
2019-12-14 14:53:49 +01:00
|
|
|
$linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
2016-12-20 07:29:49 +01:00
|
|
|
|
2019-11-13 19:35:39 +01:00
|
|
|
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
|
2016-12-20 07:29:49 +01:00
|
|
|
|
|
|
|
|
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
|
|
|
|
|
|
|
|
|
|
print '<div class="fichecenter">';
|
|
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
|
|
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
// Build file list
|
|
|
|
|
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
|
|
|
|
|
$totalsize = 0;
|
2021-02-26 18:20:21 +01:00
|
|
|
foreach ($filearray as $key => $file) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$totalsize += $file['size'];
|
|
|
|
|
}
|
2014-09-21 17:42:38 +02:00
|
|
|
|
|
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<table class="border tableforfield centpercent">';
|
|
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
|
|
|
|
|
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
|
|
|
|
|
print "</table>\n";
|
2016-12-20 07:29:49 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print "</div>\n";
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print dol_get_fiche_end();
|
2014-09-21 17:42:38 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$modulepart = 'loan';
|
2021-06-08 16:19:21 +02:00
|
|
|
$permissiontoadd = $user->rights->loan->write;
|
2020-10-31 14:32:18 +01:00
|
|
|
$permtoedit = $user->rights->loan->write;
|
|
|
|
|
$param = '&id='.$object->id;
|
2021-04-12 21:25:58 +02:00
|
|
|
include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-10-31 14:32:18 +01:00
|
|
|
print $langs->trans("ErrorUnknown");
|
2014-09-21 17:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-13 11:25:48 +02:00
|
|
|
// End of page
|
2014-09-21 17:42:38 +02:00
|
|
|
llxFooter();
|
|
|
|
|
$db->close();
|