PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / functions-html.php

functions-html.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/functions-html.php

302 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Prints help text
9 *
10 * @param string the description
11 *
12 * @return void
13 */
14 function erp_html_form_help( $value = '' ) {
15 if ( ! empty( $value ) ) {
16 echo '<span class="description">' . wp_kses_post( $value ) . '</span>';
17 }
18 }
19
20 /**
21 * Prints a label attribute
22 *
23 * @param string label vlaue
24 * @param string id field for label
25 *
26 * @return void
27 */
28 function erp_html_form_label( $label, $field_id = '', $required = false ) {
29 $req = $required ? ' <span class="required">*</span>' : '';
30 echo '<label for="' . esc_attr( $field_id ) . '">' . wp_kses_post( $label ) . $req . '</label>';
31 }
32
33 /**
34 * Handles an elements custom attribute
35 *
36 * @param array attributes as key/value pair
37 *
38 * @return array
39 */
40 function erp_html_form_custom_attr( $attr = array(), $other_attr = array() ) {
41 $custom_attributes = array();
42
43 if ( ! empty( $attr ) && is_array( $attr ) ) {
44 foreach ( $attr as $attribute => $value ) {
45 if ( $value != '' ) {
46 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
47 }
48 }
49 }
50
51 if ( ! empty( $other_attr ) && is_array( $other_attr ) ) {
52 foreach ( $attr as $attribute => $value ) {
53 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
54 }
55 }
56
57 return $custom_attributes;
58 }
59
60 /**
61 * Prints a HTML input field
62 *
63 * @param array the args
64 *
65 * @return void
66 */
67 function erp_html_form_input( $args = array() ) {
68 $defaults = array(
69 'placeholder' => '',
70 'required' => false,
71 'type' => 'text',
72 'class' => '',
73 'tag' => '',
74 'wrapper_class' => '',
75 'label' => '',
76 'name' => '',
77 'id' => '',
78 'value' => '',
79 'help' => '',
80 'addon' => '',
81 'addon_pos' => 'before',
82 'custom_attr' => array(),
83 'options' => array(),
84 );
85
86 $field = wp_parse_args( $args, $defaults );
87 $field_id = empty( $field['id'] ) ? $field['name'] : $field['id'];
88
89 $field_attributes = array_merge( array(
90 'name' => $field['name'],
91 'id' => $field_id,
92 'class' => $field['class'],
93 'placeholder' => $field['placeholder'],
94 ), $field['custom_attr'] );
95
96 if ( $field['required'] ) {
97 $field_attributes['required'] = 'required';
98 }
99
100 $custom_attributes = erp_html_form_custom_attr( $field_attributes );
101
102 // open tag
103 if ( ! empty( $field['tag'] ) ) {
104 echo '<' . $field['tag'] . ' class="erp-form-field ' . esc_attr( $field['name'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">';
105 }
106
107 if ( ! empty( $field['label'] ) ) {
108 erp_html_form_label( $field['label'], $field_id, $field['required'] );
109 }
110
111 if ( ! empty( $field['addon'] ) ) {
112 echo '<div class="input-group">';
113
114 if ( $field['addon_pos'] == 'before' ) {
115 echo '<span class="input-group-addon">' . $field['addon'] . '</span>';
116 }
117 }
118
119 switch ( $field['type'] ) {
120 case 'text':
121 case 'email':
122 case 'number':
123 case 'hidden':
124 case 'url':
125 echo '<input type="' . $field['type'] . '" value="' . esc_attr( $field['value'] ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
126 break;
127
128 case 'select':
129 if ( $field['options'] ) {
130 echo '<select ' . implode( ' ', $custom_attributes ) . '>';
131 foreach ($field['options'] as $key => $value) {
132 printf( "<option value='%s'%s>%s</option>\n", $key, selected( $field['value'], $key, false ), $value );
133 }
134 echo '</select>';
135 }
136 break;
137
138 case 'textarea':
139 echo '<textarea ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea>';
140 break;
141
142 case 'wysiwyg':
143 $editor_args = [
144 'editor_class' => $field['class'],
145 'textarea_rows' => isset( $field['custom_attr']['rows'] ) ? $field['custom_attr']['rows'] : 10,
146 'media_buttons' => isset( $field['custom_attr']['media'] ) ? $field['custom_attr']['media'] : false,
147 'teeny' => isset( $field['custom_attr']['teeny'] ) ? $field['custom_attr']['teeny'] : true,
148
149 ];
150
151 wp_editor( $field['value'], $field['name'], $editor_args );
152 break;
153
154 case 'checkbox':
155 //echo '<input type="hidden" value="off" name="' . $field['name'] . '" />';
156 echo '<span class="checkbox">';
157 echo '<label for="' . esc_attr( $field_attributes['id'] ) . '">';
158 echo '<input type="checkbox" '.checked( $field['value'], 'on', false ).' value="on" ' . implode( ' ', $custom_attributes ) . ' />';
159 echo wp_kses_post( $field['help'] );
160 echo '</label>';
161 echo '</span>';
162 break;
163
164 case 'multicheckbox':
165
166 echo '<span class="checkbox">';
167 unset( $custom_attributes['id'] );
168
169 foreach ( $field['options'] as $key => $value ) {
170 echo '<label for="' . esc_attr( $field_attributes['id'] ) . '-' . $key .'">';
171 if ( ! empty( $field['value'] ) ) {
172 if ( is_array( $field['value'] ) ) {
173 $checked = in_array( $key, $field['value'] ) ? 'checked' : '';
174 } else if ( is_string( $field['value'] ) ) {
175 $checked = in_array( $key, explode(',', $field['value'] ) ) ? 'checked' : '';
176 } else {
177 $checked = '';
178 }
179 } else {
180 $checked = '';
181 }
182
183 echo '<input type="checkbox" '. $checked .' id="' . esc_attr( $field_attributes['id'] ) . '-' . $key . '" value="'.$key.'" ' . implode( ' ', $custom_attributes ) . ' />';
184 echo '<span class="checkbox-value">' . wp_kses_post( $value ) . '</span>';
185 echo '</label>';
186 }
187 echo '</span>';
188 break;
189
190 case 'radio':
191 if ( $field['options'] ) {
192 foreach ( $field['options'] as $key => $value) {
193 echo '<input type="radio" '.checked( $field['value'], $key, false ).' value="'.$key.'" ' . implode( ' ', $custom_attributes ) . ' />'. $value . '&nbsp;';
194 }
195 }
196 break;
197
198 case 'file':
199 //need to enqueue wp_enqueue_script( 'plupload-handlers' ); wp_enqueue_script( 'erp-file-upload' );
200 $id = $field['id'];
201 $pick_files = $id . '-upload-pickfiles';
202 $drop = $id . '-drop-files';
203 $action = isset( $field['action'] ) ? $field['action'] : 'erp_file_upload';
204 $call_back = isset( $field['callback'] ) ? json_encode( $field['callback'] ) : json_encode([]);
205 $values = is_array( $field['value'] ) ? $field['value'] : [];
206 ?>
207
208 <div id="<?php echo $id; ?>" class="erp-attachment-area">
209
210 <div id="<?php echo $drop; ?>" class="erp-drop-jon">
211 <div class="erp-attachment-upload-filelist" data-type="file">
212 <ul class="erp-attachment-list">
213 <?php
214 $uploader = new \WeDevs\ERP\Uploader();
215 foreach ( $values as $key => $attach_id ) {
216 echo $uploader->attach_html( $attach_id, $custom_attributes );
217 }
218 ?>
219
220 </ul>
221 <div class="erp-clear"></div>
222
223 <div class="erp-attc-link-text"><?php _e( 'To attach, ', 'erp' ); ?> <a id="<?php echo $pick_files; ?>" href="#"><?php _e( 'select files', 'erp' ); ?></a><?php _e( ' from your computer.', 'erp' ); ?></div>
224 </div>
225 </div>
226 </div>
227
228
229 <script type="text/javascript">
230 jQuery(function($) {
231 var pick_files = '<?php echo $pick_files; ?>',
232 id = '<?php echo $id; ?>',
233 drop_jone = '<?php echo $drop; ?>',
234 action = '<?php echo $action; ?>',
235 callback = <?php echo $call_back; ?>;
236
237 new ERP_Uploader( action, pick_files, id, drop_jone, 'file_upload', 'doc,docx,xls,xlsx,jpg,jpeg,gif,png,pdf,bmp,zip,rar', 1024, callback );
238 });
239 </script>
240 <?php
241 break;
242
243 default:
244 # code...
245 break;
246 }
247
248 if ( ! empty( $field['addon'] ) ) {
249
250 if ( $field['addon_pos'] == 'after' ) {
251 echo '<span class="input-group-addon">' . $field['addon'] . '</span>';
252 }
253
254 echo '</div>';
255 }
256
257 if ( $field['type'] != 'checkbox' ) {
258 erp_html_form_help( $field['help'] );
259 }
260
261 // closing tag
262 if ( ! empty( $field['tag'] ) ) {
263 echo '</' . $field['tag'] . '>';
264 }
265 }
266
267 /**
268 * Generate an HTML dropdown option by provided values
269 *
270 * @param array $values
271 * @param string $selected
272 *
273 * @return string
274 */
275 function erp_html_generate_dropdown( $values = array(), $selected = null ) {
276 $dropdown = '';
277
278 if ( $values ) {
279 foreach ($values as $key => $label) {
280 $dropdown .= sprintf( "<option value='%s'%s>%s</option>\n", $key, selected( $selected, $key, false ), $label );
281 }
282 }
283
284 return $dropdown;
285 }
286
287 /**
288 * Print notices for WordPress
289 *
290 * @param string $text
291 * @param string $type
292 *
293 * @return void
294 */
295 function erp_html_show_notice( $text, $type = 'updated' ) {
296 ?>
297 <div class="<?php echo esc_attr( $type ); ?>">
298 <p><strong><?php echo $text; ?></strong></p>
299 </div>
300 <?php
301 }
302