PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / layouts / form / fields.php
vikappointments / admin / layouts / form Last commit date
control 2 days ago fields 2 days ago fields.php 2 days ago index.html 2 days ago
fields.php
148 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 $fields = !empty($displayData['fields']) ? $displayData['fields'] : array();
15 $params = !empty($displayData['params']) ? $displayData['params'] : array();
16 $prefix = !empty($displayData['prefix']) ? $displayData['prefix'] : '';
17
18 if (JFactory::getApplication()->isClient('administrator'))
19 {
20 $base = null;
21 }
22 else
23 {
24 // site client, take layouts from admin folder
25 $base = VAPADMIN . DIRECTORY_SEPARATOR . 'layouts';
26 }
27
28 // create control layouts
29 $openControl = new JLayoutFile('form.control.open', $base);
30 $closeControl = new JLayoutFile('form.control.close', $base);
31
32 if (count($fields))
33 {
34 foreach ($fields as $key => $f)
35 {
36 if (is_string($f))
37 {
38 /**
39 * String provided, directly echo the HTML.
40 *
41 * @since 1.7.4
42 */
43 echo $f;
44 continue;
45 }
46
47 if (isset($params[$key]))
48 {
49 // always overwrite value with the given one
50 $f['value'] = $params[$key];
51 }
52
53 if (!isset($f['value']) || (is_string($f['value']) && strlen($f['value']) === 0 && $f['type'] !== 'checkbox'))
54 {
55 if (!empty($f['default']))
56 {
57 // use default value
58 $f['value'] = $f['default'];
59 }
60 }
61
62 if (!empty($f['help']))
63 {
64 // register help within description
65 $f['description'] = $f['help'];
66 }
67
68 if (!empty($f['label']) && strpos($f['label'], '//') !== false)
69 {
70 // extract help string from label
71 $_label_arr = explode('//', $f['label']);
72 // trim trailing colon
73 $f['label'] = str_replace(':', '', $_label_arr[0]);
74 // overwrite field description
75 $f['description'] = $_label_arr[1];
76 }
77
78 if (empty($f['name']))
79 {
80 $f['name'] = $key;
81 }
82
83 if (empty($f['id']))
84 {
85 // build ID from name
86 $f['id'] = preg_replace("/[^a-zA-Z0-9_\-]+/", '-', $f['name']);
87 }
88
89 if ($prefix)
90 {
91 // add prefix before name
92 $f['name'] = $prefix . $f['name'];
93 // add prefix before ID
94 $f['id'] = $prefix . $f['id'];
95 }
96
97 if ($f['type'] == 'custom')
98 {
99 $f['type'] = 'html';
100 }
101 else if ($f['type'] == 'checkbox' && !empty($f['value']))
102 {
103 $f['checked'] = true;
104 }
105
106 // check if we have a required field
107 if (!empty($f['required']))
108 {
109 // add "required" class
110 $f['class'] = empty($f['class']) ? 'required' : $f['class'] . ' required';
111 }
112
113 if (!empty($f['multiple']) && !preg_match("/\[\]$/", $f['name']))
114 {
115 // append array notation in case the field accepts multiples values
116 $f['name'] .= '[]';
117 }
118
119 if ($f['type'] == 'password' && $base && !isset($f['toggle']))
120 {
121 // disable password/text toggle button if we are in the front-end
122 $f['toggle'] = false;
123 }
124
125 // do not display control and label in case of hidden field
126 if ($f['type'] != 'hidden' && empty($f['hidden']))
127 {
128 // open control
129 echo $openControl->render($f);
130 }
131
132 // render field
133 echo $this->sublayout($f['type'], $f);
134
135 // do not display control in case of hidden field
136 if ($f['type'] != 'hidden' && empty($f['hidden']))
137 {
138 // close control
139 echo $closeControl->render();
140 }
141 }
142 }
143 else
144 {
145 // no parameters found
146 echo VAPApplication::getInstance()->alert(JText::translate('VAPMANAGEPAYMENT9'));
147 }
148