dolibarr  16.0.1
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('ecm'));
36 
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $socid = GETPOST('socid', 'int');
40 $action = GETPOST('action', 'aZ09');
41 
42 // Get parameters
43 $socid = GETPOST("socid", "int");
44 // Security check
45 if ($user->socid > 0) {
46  $action = '';
47  $socid = $user->socid;
48 }
49 
50 $backtopage = GETPOST('backtopage', 'alpha');
51 
52 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
53 $sortfield = GETPOST('sortfield', 'aZ09comma');
54 $sortorder = GETPOST('sortorder', 'aZ09comma');
55 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
56 if (empty($page) || $page == -1) {
57  $page = 0;
58 } // If $page is not defined, or '' or -1
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 if (!$sortorder) {
63  $sortorder = "ASC";
64 }
65 if (!$sortfield) {
66  $sortfield = "label";
67 }
68 
69 $section = GETPOST("section", 'alpha');
70 if (!$section) {
71  dol_print_error('', 'Error, section parameter missing');
72  exit;
73 }
74 $urlfile = (string) dol_sanitizePathName(GETPOST("urlfile"));
75 if (!$urlfile) {
76  dol_print_error('', "ErrorParamNotDefined");
77  exit;
78 }
79 
80 // Load ecm object
81 $ecmdir = new EcmDirectory($db);
82 $result = $ecmdir->fetch(GETPOST("section", 'alpha'));
83 if (!($result > 0)) {
84  dol_print_error($db, $ecmdir->error);
85  exit;
86 }
87 $relativepath = $ecmdir->getRelativePath();
88 $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
89 
90 $fullpath = $conf->ecm->dir_output.'/'.$relativepath.$urlfile;
91 
92 $relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document
93 $filepath = $relativepath.$urlfile;
94 $filepathtodocument = $relativetodocument.$urlfile;
95 
96 // Try to load object from index
97 $object = new ECMFiles($db);
98 $extrafields = new ExtraFields($db);
99 // fetch optionals attributes and labels
100 $extrafields->fetch_name_optionals_label($object->table_element);
101 
102 $result = $object->fetch(0, '', $filepathtodocument);
103 if ($result < 0) {
104  dol_print_error($db, $object->error, $object->errors);
105  exit;
106 }
107 
108 $permissionnote = $user->rights->ecm->setup; // Used by the include of actions_setnotes.inc.php
109 
110 $permtoread = $user->rights->ecm->read;
111 
112 if (!$permtoread) {
113  accessforbidden();
114 }
115 
116 
117 /*
118  * Actions
119  */
120 
121 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
122 
123 
124 /*
125  * View
126  */
127 
128 llxHeader('', $langs->trans('EcmFiles'));
129 
130 $form = new Form($db);
131 
132 $object->section_id = $ecmdir->id;
133 $object->label = $urlfile;
134 $head = ecm_file_prepare_head($object);
135 
136 print dol_get_fiche_head($head, 'note', $langs->trans("File"), -1, 'generic');
137 
138 $s = '';
139 $tmpecmdir = new EcmDirectory($db); // Need to create a new one
140 $tmpecmdir->fetch($ecmdir->id);
141 $result = 1;
142 $i = 0;
143 while ($tmpecmdir && $result > 0) {
144  $tmpecmdir->ref = $tmpecmdir->label;
145  $s = $tmpecmdir->getNomUrl(1).$s;
146  if ($tmpecmdir->fk_parent) {
147  $s = ' -> '.$s;
148  $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
149  } else {
150  $tmpecmdir = 0;
151  }
152  $i++;
153 }
154 
155 $urlfiletoshow = preg_replace('/\.noexe$/', '', $urlfile);
156 
157 $s = img_picto('', 'object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> '.$s.' -> ';
158 if ($action == 'edit') {
159  $s .= '<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfiletoshow.'">';
160 } else {
161  $s .= $urlfiletoshow;
162 }
163 
164 $linkback = '';
165 if ($backtopage) {
166  $linkback = '<a href="'.$backtopage.'">'.$langs->trans("BackToTree").'</a>';
167 }
168 
169 $object->ref = ''; // Force to hide ref
170 dol_banner_tab($object, '', $linkback, 0, '', '', $s);
171 
172 
173 
174 print '<div class="fichecenter">';
175 print '<div class="underbanner clearboth"></div>';
176 
177 
178 $cssclass = "titlefield";
179 $moreparam = '&amp;section='.$section.'&amp;urlfile='.$urlfile;
180 include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
181 
182 print '</div>';
183 
184 print dol_get_fiche_end();
185 
186 
187 // End of page
188 llxFooter();
189 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizePathName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a path name.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Class to manage standard extra fields.
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 from a POST of a form...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
ecm_file_prepare_head($object)
Prepare array with list of tabs.
Definition: ecm.lib.php:101
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
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.
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:73
Class to manage ECM directories.