dolibarr  19.0.0-dev
file_note.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('ecm'));
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $socid = GETPOST('socid', 'int');
41 $action = GETPOST('action', 'aZ09');
42 
43 // Get parameters
44 $socid = GETPOST("socid", "int");
45 // Security check
46 if ($user->socid > 0) {
47  $action = '';
48  $socid = $user->socid;
49 }
50 
51 $backtopage = GETPOST('backtopage', 'alpha');
52 
53 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
54 $sortfield = GETPOST('sortfield', 'aZ09comma');
55 $sortorder = GETPOST('sortorder', 'aZ09comma');
56 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
57 if (empty($page) || $page == -1) {
58  $page = 0;
59 } // If $page is not defined, or '' or -1
60 $offset = $limit * $page;
61 $pageprev = $page - 1;
62 $pagenext = $page + 1;
63 if (!$sortorder) {
64  $sortorder = "ASC";
65 }
66 if (!$sortfield) {
67  $sortfield = "label";
68 }
69 
70 $section = GETPOST("section", 'alpha');
71 if (!$section) {
72  dol_print_error('', 'Error, section parameter missing');
73  exit;
74 }
75 $urlfile = (string) dol_sanitizePathName(GETPOST("urlfile"));
76 if (!$urlfile) {
77  dol_print_error('', "ErrorParamNotDefined");
78  exit;
79 }
80 
81 // Load ecm object
82 $ecmdir = new EcmDirectory($db);
83 $result = $ecmdir->fetch(GETPOST("section", 'alpha'));
84 if (!($result > 0)) {
85  dol_print_error($db, $ecmdir->error);
86  exit;
87 }
88 $relativepath = $ecmdir->getRelativePath();
89 $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
90 
91 $fullpath = $conf->ecm->dir_output.'/'.$relativepath.$urlfile;
92 
93 $relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document
94 $filepath = $relativepath.$urlfile;
95 $filepathtodocument = $relativetodocument.$urlfile;
96 
97 // Try to load object from index
98 $object = new EcmFiles($db);
99 $extrafields = new ExtraFields($db);
100 // fetch optionals attributes and labels
101 $extrafields->fetch_name_optionals_label($object->table_element);
102 
103 $result = $object->fetch(0, '', $filepathtodocument);
104 if ($result < 0) {
105  dol_print_error($db, $object->error, $object->errors);
106  exit;
107 }
108 
109 $permissionnote = $user->rights->ecm->setup; // Used by the include of actions_setnotes.inc.php
110 
111 $permissiontoread = $user->rights->ecm->read;
112 
113 if (!$permissiontoread) {
114  accessforbidden();
115 }
116 
117 
118 /*
119  * Actions
120  */
121 
122 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
123 
124 
125 /*
126  * View
127  */
128 
129 llxHeader('', $langs->trans('EcmFiles'));
130 
131 $form = new Form($db);
132 
133 $object->section_id = $ecmdir->id;
134 $object->label = $urlfile;
135 $head = ecm_file_prepare_head($object);
136 
137 print dol_get_fiche_head($head, 'note', $langs->trans("File"), -1, 'generic');
138 
139 $s = '';
140 $tmpecmdir = new EcmDirectory($db); // Need to create a new one
141 $tmpecmdir->fetch($ecmdir->id);
142 $result = 1;
143 $i = 0;
144 while ($tmpecmdir && $result > 0) {
145  $tmpecmdir->ref = $tmpecmdir->label;
146  $s = $tmpecmdir->getNomUrl(1).$s;
147  if ($tmpecmdir->fk_parent) {
148  $s = ' -> '.$s;
149  $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
150  } else {
151  $tmpecmdir = 0;
152  }
153  $i++;
154 }
155 
156 $urlfiletoshow = preg_replace('/\.noexe$/', '', $urlfile);
157 
158 $s = img_picto('', 'object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> '.$s.' -> ';
159 if ($action == 'edit') {
160  $s .= '<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfiletoshow.'">';
161 } else {
162  $s .= $urlfiletoshow;
163 }
164 
165 $linkback = '';
166 if ($backtopage) {
167  $linkback = '<a href="'.$backtopage.'">'.$langs->trans("BackToTree").'</a>';
168 }
169 
170 $object->ref = ''; // Force to hide ref
171 dol_banner_tab($object, '', $linkback, 0, '', '', $s);
172 
173 
174 
175 print '<div class="fichecenter">';
176 print '<div class="underbanner clearboth"></div>';
177 
178 
179 $cssclass = "titlefield";
180 $moreparam = '&amp;section='.$section.'&amp;urlfile='.$urlfile;
181 include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
182 
183 print '</div>';
184 
185 print dol_get_fiche_end();
186 
187 
188 // End of page
189 llxFooter();
190 $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 ECM directories.
Class to manage ECM files.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
ecm_file_prepare_head($object)
Prepare array with list of tabs.
Definition: ecm.lib.php:118
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.