dolibarr  16.0.5
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 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 if (!empty($conf->project->enabled)) {
32  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33 }
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("other", "companies", "compta", "bills", "loan"));
37 
38 $id = GETPOST('id', 'int');
39 $action = GETPOST('action', 'aZ09');
40 $confirm = GETPOST('confirm', 'alpha');
41 
42 // Security check
43 if ($user->socid) {
44  $socid = $user->socid;
45 }
46 $result = restrictedArea($user, 'loan', $id, '', '');
47 
48 // Get parameters
49 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
50 $sortfield = GETPOST('sortfield', 'aZ09comma');
51 $sortorder = GETPOST('sortorder', 'aZ09comma');
52 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53 if (empty($page) || $page == -1) {
54  $page = 0;
55 }
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 if (!$sortorder) {
60  $sortorder = "ASC";
61 }
62 if (!$sortfield) {
63  $sortfield = "name";
64 }
65 
66 $object = new Loan($db);
67 if ($id > 0) {
68  $object->fetch($id);
69 }
70 
71 $upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
72 $modulepart = 'loan';
73 
74 $permissiontoadd = $user->rights->loan->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
75 
76 
77 /*
78  * Actions
79  */
80 
81 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
82 
83 
84 /*
85  * View
86  */
87 
88 $form = new Form($db);
89 
90 $title = $langs->trans("Loan").' - '.$langs->trans("Documents");
91 $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
92 llxHeader("", $title, $help_url);
93 
94 if ($object->id) {
95  $totalpaid = $object->getSumPayment();
96 
97  $head = loan_prepare_head($object);
98 
99  print dol_get_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
100 
101  $morehtmlref = '<div class="refidno">';
102  // Ref loan
103  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
104  $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
105  // Project
106  if (!empty($conf->project->enabled)) {
107  $langs->load("projects");
108  $morehtmlref .= '<br>'.$langs->trans('Project').' : ';
109  if ($user->rights->loan->write) {
110  //if ($action != 'classify')
111  // $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
112  if ($action == 'classify') {
113  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
114  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
115  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
116  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
117  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
118  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
119  $morehtmlref .= '</form>';
120  } else {
121  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
122  }
123  } else {
124  if (!empty($object->fk_project)) {
125  $proj = new Project($db);
126  $proj->fetch($object->fk_project);
127  $morehtmlref .= ' : '.$proj->getNomUrl(1);
128  if ($proj->title) {
129  $morehtmlref .= ' - '.$proj->title;
130  }
131  } else {
132  $morehtmlref .= '';
133  }
134  }
135  }
136  $morehtmlref .= '</div>';
137 
138  $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
139 
140  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
141 
142  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
143 
144  print '<div class="fichecenter">';
145  print '<div class="underbanner clearboth"></div>';
146 
147 
148  // Build file list
149  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
150  $totalsize = 0;
151  foreach ($filearray as $key => $file) {
152  $totalsize += $file['size'];
153  }
154 
155 
156  print '<table class="border tableforfield centpercent">';
157  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
158  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
159  print "</table>\n";
160 
161  print "</div>\n";
162 
163  print dol_get_fiche_end();
164 
165  $modulepart = 'loan';
166  $permissiontoadd = $user->rights->loan->write;
167  $permtoedit = $user->rights->loan->write;
168  $param = '&id='.$object->id;
169  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
170 } else {
171  print $langs->trans("ErrorUnknown");
172 }
173 
174 // End of page
175 llxFooter();
176 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Loan
Loan.
Definition: loan.class.php:30
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
loan_prepare_head
loan_prepare_head($object)
Prepare array with list of tabs.
Definition: loan.lib.php:33
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52