30 require
'../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/categories.lib.php';
37 $langs->loadlangs(array(
'categories',
'bills'));
41 $label =
GETPOST(
'label',
'alpha');
42 $action =
GETPOST(
'action',
'aZ09');
45 if ($id ==
'' && $label ==
'') {
54 $result = $object->fetch($id, $label);
59 $type = $object->type;
60 if (is_numeric($type)) {
61 $type = Categorie::$MAP_ID_TO_CODE[$type];
64 $upload_dir = $conf->categorie->multidir_output[$object->entity];
70 if (isset($_FILES[
'userfile']) && $_FILES[
'userfile'][
'size'] > 0 &&
GETPOST(
"sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) {
72 $file = $_FILES[
'userfile'];
73 if (is_array($file[
'name']) && count($file[
'name']) > 0) {
74 foreach ($file[
'name'] as $i => $name) {
75 if (empty($file[
'tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file[
'tmp_name'][$i])) {
76 setEventMessage($file[
'name'][$i].
' : '.$langs->trans(empty($file[
'tmp_name'][$i]) ?
'ErrorFailedToSaveFile' :
'MaxSizeForUploadedFiles'));
77 unset($file[
'name'][$i], $file[
'type'][$i], $file[
'tmp_name'][$i], $file[
'error'][$i], $file[
'size'][$i]);
82 if (!empty($file[
'tmp_name'])) {
83 $object->add_photo($upload_dir, $file);
88 if ($action ==
'confirm_delete' && $_GET[
"file"] && $confirm ==
'yes' && $user->rights->categorie->creer) {
89 $object->delete_photo($upload_dir.
"/".$_GET[
"file"]);
92 if ($action ==
'addthumb' && $_GET[
"file"]) {
93 $object->addThumbs($upload_dir.
"/".$_GET[
"file"]);
101 llxHeader(
"",
"", $langs->trans(
"Categories"));
107 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
112 $backtolist = (
GETPOST(
'backtolist') ?
GETPOST(
'backtolist') : DOL_URL_ROOT.
'/categories/index.php?leftmenu=cat&type='.urlencode($type));
113 $linkback =
'<a href="'.dol_sanitizeUrl($backtolist).
'">'.$langs->trans(
"BackToList").
'</a>';
114 $object->next_prev_filter =
' type = '.$object->type;
115 $object->ref = $object->label;
116 $morehtmlref =
'<br><div class="refidno"><a href="'.DOL_URL_ROOT.
'/categories/index.php?leftmenu=cat&type='.$type.
'">'.$langs->trans(
"Root").
'</a> >> ';
117 $ways = $object->print_all_ways(
" >> ",
'', 1);
118 foreach ($ways as $way) {
119 $morehtmlref .= $way.
"<br>\n";
121 $morehtmlref .=
'</div>';
123 dol_banner_tab($object,
'label', $linkback, ($user->socid ? 0 : 1),
'label',
'label', $morehtmlref,
'&type='.$type, 0,
'',
'', 1);
128 if ($action ==
'delete') {
129 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&type='.$type.
'&file='.$_GET[
"file"], $langs->trans(
'DeletePicture'), $langs->trans(
'ConfirmDeletePicture'),
'confirm_delete',
'', 0, 1);
134 print
'<div class="fichecenter">';
135 print
'<div class="underbanner clearboth"></div>';
136 print
'<table class="border centpercent tableforfield">';
139 print
'<tr><td class="titlefield notopnoleft">';
140 print $langs->trans(
"Description").
'</td><td>';
145 print
'<tr><td class="notopnoleft">';
146 print $langs->trans(
"Color").
'</td><td>';
147 print $formother->showColor($object->color);
160 print
'<div class="tabsAction">'.
"\n";
162 if ($action !=
'ajout_photo' && $user->rights->categorie->creer) {
163 if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
164 print
'<a class="butAction hideonsmartphone" href="'.$_SERVER[
'PHP_SELF'].
'?action=ajout_photo&id='.$object->id.
'&type='.$type.
'">';
165 print $langs->trans(
"AddPhoto").
'</a>';
167 print
'<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
168 print $langs->trans(
"AddPhoto").
'</a>';
177 if ($action ==
'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC)) {
180 $formfile->form_attach_new_file($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&type='.$type, $langs->trans(
"AddPhoto"), 1,
'', $user->rights->categorie->creer, 50, $object,
'',
false,
'', 0);
184 if ($action !=
'ajout_photo') {
191 $pdir =
get_exdir($object->id, 2, 0, 0, $object,
'category').$object->id.
"/photos/";
192 $dir = $upload_dir.
'/'.$pdir;
194 $listofphoto = $object->liste_photos($dir);
196 if (is_array($listofphoto) && count($listofphoto)) {
198 print
'<table width="100%" valign="top" class="center centpercent">';
200 foreach ($listofphoto as $key => $obj) {
203 if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
204 print
'<tr class"center valignmiddle" border="1">';
207 print
'<td width="'.ceil(100 / $nbbyrow).
'%" class="photo">';
210 print
'<a href="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=category&entity='.$object->entity.
'&file='.urlencode($pdir.$obj[
'photo']).
'" alt="Original size" target="_blank" rel="noopener noreferrer">';
213 if ($obj[
'photo_vignette']) {
214 $filename = $obj[
'photo_vignette'];
216 $filename = $obj[
'photo'];
220 $viewfilename = $obj[
'photo'];
223 $object->get_image_size($dir.$filename);
224 $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
225 $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
227 print
'<img border="0" width="'.$imgWidth.
'" height="'.$imgHeight.
'" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=category&entity='.$object->entity.
'&file='.urlencode($pdir.$filename).
'">';
230 print
'<br>'.$viewfilename;
234 if (!$obj[
'photo_vignette'] && preg_match(
'/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj[
'photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
235 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&token='.
newToken().
'&action=addthumb&type='.$type.
'&file='.urlencode($pdir.$viewfilename).
'">'.
img_picto($langs->trans(
'GenerateThumb'),
'refresh').
' </a>';
237 if ($user->rights->categorie->creer) {
238 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'&type='.$type.
'&file='.urlencode($pdir.$viewfilename).
'">';
244 if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
250 while ($nbphoto % $nbbyrow) {
251 print
'<td width="'.ceil(100 / $nbbyrow).
'%"> </td>';
259 print
'<div class="opacitymedium">'.$langs->trans(
"NoPhotoYet").
"</div>";
263 print $langs->trans(
"ErrorUnknown");