1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Tdmdownloads; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* TDMDownload |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting source code |
12
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
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. |
16
|
|
|
* |
17
|
|
|
* @copyright Gregory Mage (Aka Mage) |
18
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
19
|
|
|
* @author Gregory Mage (Aka Mage) |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Field |
24
|
|
|
* @package XoopsModules\Tdmdownloads |
25
|
|
|
*/ |
26
|
|
|
class Field extends \XoopsObject |
27
|
|
|
{ |
28
|
|
|
// constructor |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
$this->initVar('fid', \XOBJ_DTYPE_INT, null, false, 11); |
32
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); |
33
|
|
|
$this->initVar('img', \XOBJ_DTYPE_TXTBOX, null, false); |
34
|
|
|
$this->initVar('weight', \XOBJ_DTYPE_INT, null, false, 11); |
35
|
|
|
$this->initVar('status', \XOBJ_DTYPE_INT, null, false, 5); |
36
|
|
|
$this->initVar('search', \XOBJ_DTYPE_INT, null, false, 5); |
37
|
|
|
$this->initVar('status_def', \XOBJ_DTYPE_INT, null, false, 5); |
38
|
|
|
//pour les jointures |
39
|
|
|
$this->initVar('data', \XOBJ_DTYPE_TXTAREA, null, false); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param null $db |
44
|
|
|
* @return int|string |
45
|
|
|
*/ |
46
|
|
|
public function getNewEnreg($db = null) |
47
|
|
|
{ |
48
|
|
|
$newEnreg = 0; |
49
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
50
|
|
|
if (null !== $db) { |
51
|
|
|
$newEnreg = $db->getInsertId(); |
52
|
|
|
} |
53
|
|
|
return $newEnreg; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param bool $action |
58
|
|
|
* |
59
|
|
|
* @return \XoopsThemeForm |
60
|
|
|
*/ |
61
|
|
|
public function getForm($action = false) |
62
|
|
|
{ |
63
|
|
|
$helper = Helper::getInstance(); |
64
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
65
|
|
|
if (!$action) { |
66
|
|
|
$action = $_SERVER['REQUEST_URI']; |
67
|
|
|
} |
68
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
69
|
|
|
//nom du formulaire selon l'action (editer ou ajouter): |
70
|
|
|
$title = $this->isNew() ? \sprintf(_AM_TDMDOWNLOADS_FORMADD) : \sprintf(_AM_TDMDOWNLOADS_FORMEDIT); |
71
|
|
|
//création du formulaire |
72
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
73
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
74
|
|
|
//titre |
75
|
|
|
if (1 == $this->getVar('status_def')) { |
76
|
|
|
$form->addElement(new \XoopsFormLabel(_AM_TDMDOWNLOADS_FORMTITLE, $this->getVar('title'))); |
77
|
|
|
$form->addElement(new \XoopsFormHidden('title', $this->getVar('title'))); |
|
|
|
|
78
|
|
|
} else { |
79
|
|
|
$form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMTITLE, 'title', 50, 255, $this->getVar('title')), true); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
//image |
82
|
|
|
$downloadsfield_img = $this->getVar('img') ?: 'blank.gif'; |
83
|
|
|
$uploadirectory = '/uploads/' . $moduleDirName . '/images/field'; |
84
|
|
|
$imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMAGE, '<br>'); |
85
|
|
|
$imgpath = \sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory); |
86
|
|
|
$imageselect = new \XoopsFormSelect($imgpath, 'downloadsfield_img', $downloadsfield_img); |
87
|
|
|
$topics_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadirectory); |
88
|
|
|
foreach ($topics_array as $image) { |
89
|
|
|
$imageselect->addOption($image, $image); |
90
|
|
|
} |
91
|
|
|
$imageselect->setExtra("onchange='showImgSelected(\"image3\", \"downloadsfield_img\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'"); |
92
|
|
|
$imgtray->addElement($imageselect, false); |
93
|
|
|
$imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $downloadsfield_img . "' name='image3' id='image3' alt=''><br>")); |
94
|
|
|
$fileseltray = new \XoopsFormElementTray('', '<br>'); |
95
|
|
|
$fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxuploadsize')), false); |
96
|
|
|
$fileseltray->addElement(new \XoopsFormLabel(''), false); |
97
|
|
|
$imgtray->addElement($fileseltray); |
98
|
|
|
$form->addElement($imgtray); |
99
|
|
|
//poids du champ |
100
|
|
|
$form->addElement(new \XoopsFormText(_AM_TDMDOWNLOADS_FORMWEIGHT, 'weight', 5, 5, $this->getVar('weight', 'e')), false); |
101
|
|
|
// affiché? |
102
|
|
|
$status = $this->getVar('status') ?: 0; |
103
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHE, 'status', $status)); |
104
|
|
|
// affiché dans le champ de recherche? |
105
|
|
|
$search = $this->getVar('search') ?: 0; |
106
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_TDMDOWNLOADS_FORMAFFICHESEARCH, 'search', $search)); |
107
|
|
|
// pour passer "fid" si on modifie le champ |
108
|
|
|
if (!$this->isNew()) { |
109
|
|
|
$form->addElement(new \XoopsFormHidden('fid', $this->getVar('fid'))); |
110
|
|
|
$form->addElement(new \XoopsFormHidden('status_def', $this->getVar('status_def'))); |
111
|
|
|
} else { |
112
|
|
|
$form->addElement(new \XoopsFormHidden('status_def', 0)); |
113
|
|
|
} |
114
|
|
|
//pour enregistrer le formulaire |
115
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save_field')); |
116
|
|
|
//boutton d'envoi du formulaire |
117
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', 'submit', false)); |
118
|
|
|
return $form; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|