dolibarr  13.0.2
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->projet->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) $socid = $user->socid;
44 $result = restrictedArea($user, 'loan', $id, '', '');
45 
46 // Get parameters
47 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST("sortfield", 'alpha');
49 $sortorder = GETPOST("sortorder", 'alpha');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1) {
52  $page = 0;
53 }
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) $sortorder = "ASC";
58 if (!$sortfield) $sortfield = "name";
59 
60 $object = new Loan($db);
61 if ($id > 0) $object->fetch($id);
62 
63 $upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
64 $modulepart = 'loan';
65 
66 
67 /*
68  * Actions
69  */
70 
71 include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
72 
73 
74 /*
75  * View
76  */
77 
78 $form = new Form($db);
79 
80 $title = $langs->trans("Loan").' - '.$langs->trans("Documents");
81 $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
82 llxHeader("", $title, $help_url);
83 
84 if ($object->id)
85 {
86  $totalpaid = $object->getSumPayment();
87 
88  $head = loan_prepare_head($object);
89 
90  print dol_get_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
91 
92  $morehtmlref = '<div class="refidno">';
93  // Ref loan
94  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
95  $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
96  // Project
97  if (!empty($conf->projet->enabled)) {
98  $langs->load("projects");
99  $morehtmlref .= '<br>'.$langs->trans('Project').' : ';
100  if ($user->rights->loan->write) {
101  //if ($action != 'classify')
102  // $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
103  if ($action == 'classify') {
104  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
105  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
106  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
107  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
108  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
109  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
110  $morehtmlref .= '</form>';
111  } else {
112  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
113  }
114  } else {
115  if (!empty($object->fk_project)) {
116  $proj = new Project($db);
117  $proj->fetch($object->fk_project);
118  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
119  $morehtmlref .= $proj->ref;
120  $morehtmlref .= '</a>';
121  } else {
122  $morehtmlref .= '';
123  }
124  }
125  }
126  $morehtmlref .= '</div>';
127 
128  $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
129 
130  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
131 
132  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
133 
134  print '<div class="fichecenter">';
135  print '<div class="underbanner clearboth"></div>';
136 
137 
138  // Build file list
139  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
140  $totalsize = 0;
141  foreach ($filearray as $key => $file)
142  {
143  $totalsize += $file['size'];
144  }
145 
146 
147  print '<table class="border tableforfield centpercent">';
148  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
149  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
150  print "</table>\n";
151 
152  print "</div>\n";
153 
155 
156  $modulepart = 'loan';
157  $permission = $user->rights->loan->write;
158  $permtoedit = $user->rights->loan->write;
159  $param = '&id='.$object->id;
160  include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
161 } else {
162  print $langs->trans("ErrorUnknown");
163 }
164 
165 // End of page
166 llxFooter();
167 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Loan.
Definition: loan.class.php:30
loan_prepare_head($object)
Prepare array with list of tabs.
Definition: loan.lib.php:33
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59