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