dolibarr 18.0.6
document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32if (isModEnabled('project')) {
33 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34}
35
36// Load translation files required by the page
37$langs->loadLangs(array("other", "companies", "compta", "bills", "loan"));
38
39$id = GETPOST('id', 'int');
40$action = GETPOST('action', 'aZ09');
41$confirm = GETPOST('confirm', 'alpha');
42
43// Security check
44if ($user->socid) {
45 $socid = $user->socid;
46}
47$result = restrictedArea($user, 'loan', $id, '', '');
48
49// Get parameters
50$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
51$sortfield = GETPOST('sortfield', 'aZ09comma');
52$sortorder = GETPOST('sortorder', 'aZ09comma');
53$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54if (empty($page) || $page == -1) {
55 $page = 0;
56}
57$offset = $limit * $page;
58$pageprev = $page - 1;
59$pagenext = $page + 1;
60if (!$sortorder) {
61 $sortorder = "ASC";
62}
63if (!$sortfield) {
64 $sortfield = "name";
65}
66
67$object = new Loan($db);
68if ($id > 0) {
69 $object->fetch($id);
70}
71
72$upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
73$modulepart = 'loan';
74
75$permissiontoadd = $user->rights->loan->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
76
77
78/*
79 * Actions
80 */
81
82include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
83
84
85/*
86 * View
87 */
88
89$form = new Form($db);
90
91$title = $langs->trans("Loan").' - '.$langs->trans("Documents");
92$help_url = 'EN:Module_Loan|FR:Module_Emprunt';
93llxHeader("", $title, $help_url);
94
95if ($object->id) {
96 $totalpaid = $object->getSumPayment();
97
98 $head = loan_prepare_head($object);
99
100 print dol_get_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
101
102 $morehtmlref = '<div class="refidno">';
103 // Ref loan
104 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
105 $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
106 // Project
107 if (isModEnabled('project')) {
108 $langs->load("projects");
109 $morehtmlref .= '<br>'.$langs->trans('Project').' : ';
110 if ($user->rights->loan->write) {
111 //if ($action != 'classify')
112 // $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
113 if ($action == 'classify') {
114 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
115 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
116 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
117 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
118 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
119 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
120 $morehtmlref .= '</form>';
121 } else {
122 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
123 }
124 } else {
125 if (!empty($object->fk_project)) {
126 $proj = new Project($db);
127 $proj->fetch($object->fk_project);
128 $morehtmlref .= ' : '.$proj->getNomUrl(1);
129 if ($proj->title) {
130 $morehtmlref .= ' - '.$proj->title;
131 }
132 } else {
133 $morehtmlref .= '';
134 }
135 }
136 }
137 $morehtmlref .= '</div>';
138
139 $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
140
141 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
142
143 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
144
145 print '<div class="fichecenter">';
146 print '<div class="underbanner clearboth"></div>';
147
148
149 // Build file list
150 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
151 $totalsize = 0;
152 foreach ($filearray as $key => $file) {
153 $totalsize += $file['size'];
154 }
155
156
157 print '<table class="border tableforfield centpercent">';
158 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
159 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
160 print "</table>\n";
161
162 print "</div>\n";
163
164 print dol_get_fiche_end();
165
166 $modulepart = 'loan';
167 $permissiontoadd = $user->rights->loan->write;
168 $permtoedit = $user->rights->loan->write;
169 $param = '&id='.$object->id;
170 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
171} else {
172 print $langs->trans("ErrorUnknown");
173}
174
175// End of page
176llxFooter();
177$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
Loan.
Class to manage projects.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
loan_prepare_head($object)
Prepare array with list of tabs.
Definition loan.lib.php:33
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.