! Fixed placement of custom fields + Added new classes for custom fields ! Fixed bugs with custom fields where textareas and radio buttons didn't work properly ! Still need to fix actual posting of custom field data
jblaze

jblaze commited on 2011-02-07 03:06:07
Showing 3 changed files, with 106 additions and 86 deletions.

... ...
@@ -111,6 +111,13 @@ h3.ticketheader img
111 111
 	width: 20%;
112 112
 	float: left;
113 113
 }
114
+.shd_customfields
115
+{
116
+	width: 66%;
117
+	margin-bottom: 0;
118
+	float: left;
119
+	margin-top: 5px;
120
+}
114 121
 .shd_additional_details
115 122
 {
116 123
 	overflow: auto;
... ...
@@ -126,7 +133,7 @@ h3.ticketheader img
126 133
 /* The ticket container */
127 134
 .shd_ticket
128 135
 {
129
-	min-height: 340px;
136
+	min-height: 640px;
130 137
 }
131 138
 .shd_ticket_description
132 139
 {
... ...
@@ -347,18 +354,18 @@ h3.ticketheader img
347 354
 ***********************************/
348 355
 .shd_reply_attachments
349 356
 {
350
-	width: 68%;
357
+	width: 66%;
351 358
 	margin-bottom: 0;
352 359
 	float: left;
353 360
 	margin-top: 5px;
354 361
 }
355
-.shd_replyattachments ul, .shd_replyattachments li
362
+.shd_reply_attachments ul, .shd_reply_attachments li
356 363
 {
357 364
 	display: block;
358 365
 	list-style-type: none;
359 366
 }
360 367
 
361
-.shd_replyattachments li
368
+.shd_reply_attachments li
362 369
 {
363 370
 	float: left;
364 371
 	width: 30%;
... ...
@@ -562,8 +562,8 @@ function shd_load_custom_fields($use_roles = false)
562 562
 
563 563
 	// Load up our custom fields from the database
564 564
 	$custom_fields = shd_db_query('', '
565
-		SELECT cf.id_field, cf.active, cf.field_order, cf.field_name, cf.field_loc, cf.icon,
566
-			cf.field_type, cf.default_value, cf.bbc, cf.can_see, cf.can_edit, cf.field_length,
565
+		SELECT cf.id_field, cf.active, cf.field_order, cf.field_name, cf.field_desc, cf.field_loc, cf.icon,
566
+			cf.field_type, cf.field_options, cf.default_value, cf.bbc, cf.can_see, cf.can_edit, cf.field_length,
567 567
 			cf.display_empty, cf.required, cf.placement
568 568
 		FROM {db_prefix}helpdesk_custom_fields AS cf
569 569
 		WHERE cf.active = 1
... ...
@@ -580,22 +580,21 @@ function shd_load_custom_fields($use_roles = false)
580 580
 		if (empty($row['id_field']))
581 581
 			return false;
582 582
 
583
-		$row['can_see'] = explode(',', $row['can_see']);
584
-		$row['can_edit'] = explode(',', $row['can_edit']);
585
-
586
-		$context['ticket_form']['custom_fields'][$row['id_field']] = array(
583
+		$context['ticket_form']['custom_fields'][$row['placement']][$row['id_field']] = array(
587 584
 			'id' => $row['id_field'],
588 585
 			'order' => $row['field_order'],
589 586
 			'location' => $row['field_loc'],
590 587
 			'name' => $row['field_name'],
591 588
 			'desc' => $row['field_desc'],
592 589
 			'icon' => $row['icon'],
590
+			'options' => explode(',', $row['field_options']),
593 591
 			'type' => $row['field_type'],
594
-			'options' => $row['field_options'],
595
-			'default_value' => $row['default_value'],
592
+			'default_value' => explode(',', $row['default_value']),
596 593
 			'display_empty' => $row['required'] == 1 ? 1 : $row['display_empty'], // Required and "selection" fields will always be displayed.
597 594
 			'bbc' => $row['bbc'] == 1,
598
-			'is_required' => $row['required'] == 1
595
+			'is_required' => $row['required'] == 1,
596
+			'can_see' => explode(',', $row['can_see']),
597
+			'can_edit' => explode(',', $row['can_edit'])
599 598
 		);
600 599
 	}
601 600
 
... ...
@@ -88,7 +88,6 @@ function template_ticket_info()
88 88
 
89 89
 	echo '
90 90
 			<form action="', $context['ticket_form']['form_action'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" onsubmit="', 'submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\'], \'options\');" enctype="multipart/form-data" style="margin: 0;">
91
-			<div class="tborder">
92 91
 			<div class="cat_bar grid_header">
93 92
 				<h3 class="catbg">
94 93
 					<img src="', $settings['default_images_url'], '/simpledesk/ticket.png" alt="x" /> ', $context['ticket_form']['form_title'], '
... ...
@@ -141,10 +140,94 @@ function template_ticket_info()
141 140
 							', shd_profile_link($context['ticket_form']['member']['avatar']['image'], $context['ticket_form']['member']['id']), '
142 141
 						</div>';
143 142
 
143
+	// Custom fields
144
+	template_ticket_custom_fields(1);
145
+
144 146
 	echo '
145 147
 					</div>';
146 148
 }
147 149
 
150
+function template_ticket_custom_fields($placement = 2)
151
+{
152
+	global $context, $settings;
153
+
154
+	// Custom fields maybe?
155
+	if ($context['ticket_form']['custom_fields'] != 0)
156
+	{
157
+		echo '
158
+					<div class="information shd_customfields">
159
+						<ul class="reset">';
160
+
161
+			foreach ($context['ticket_form']['custom_fields'][$placement] as $field)
162
+			{
163
+				echo '
164
+							<li id="field-' . $field['id'] . '">
165
+								', !empty($field['icon']) ? '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" />' : '', '
166
+								<strong>' . $field['name'] . '</strong><br />
167
+								<span class="smalltext">' . $field['desc'] . '</span>
168
+								<br />';
169
+
170
+				// Text
171
+				if ($field['type'] == 1)
172
+					echo '
173
+								<input type="text" name="field-' . $field['id'] . '" value="' . $field['default_value'] . '" size="50" />';
174
+				// Textarea
175
+				elseif ($field['type'] == 2)
176
+					echo '
177
+								<textarea name="field-' . $field['id'] . '"', !empty($field['default_value']) ? ' rows="' . $field['default_value'][0] . '" cols="' . $field['default_value'][1] . '" ' : '', '> </textarea>';
178
+				// Integers only
179
+				elseif ($field['type'] == 3)
180
+					echo '
181
+								<input name="field-' . $field['id'] . '" value="' . $field['default_value'] . ' size="10 />';
182
+				// Floating numbers
183
+				elseif ($field['type'] == 4)
184
+					echo '
185
+								<input name="field-' . $field['id'] . '" value="' . $field['default_value'] . ' size="10 />';
186
+				// Select boxes
187
+				elseif ($field['type'] == 5)
188
+				{
189
+					echo '
190
+								<select name="field-' . $field['id'] . '">';
191
+
192
+					foreach ($field['options'] as $option)
193
+					{
194
+						echo '
195
+									<option value="' . $option . '">' . $option . '&nbsp;</option>';
196
+					}
197
+
198
+					echo '
199
+								</select>';
200
+				}
201
+				// Checkboxes!
202
+				elseif ($field['type'] == 6)
203
+					echo '
204
+								<input name="field-' . $field['id'] . '" type="checkbox" ' . $field['default_value'] == 1 ? 'checked="checked"' : '' . '/>';
205
+				// Last one, radio buttons
206
+				elseif ($field['type'] == 7)
207
+				{
208
+					foreach ($field['options'] as $option)
209
+					{
210
+						echo '
211
+								<label for="field-' . $field['id'] . '">' . $option . '</label>
212
+								<input name="field-' . $field['id'] . '" type="radio" value="' . $option . '" />';
213
+					}
214
+				}
215
+				// Default to a text input field
216
+				else
217
+					echo '
218
+								<input type="text" name="field-' . $field['id'] . '" value="' . $field['default_value'] . '" size="50" />';
219
+
220
+				echo '
221
+							</li>
222
+							', $placement == 1 ? '' : '<hr />', '<br />';
223
+			}
224
+
225
+		echo '
226
+						</ul>
227
+					</div>';
228
+	}
229
+}
230
+
148 231
 function template_ticket_posterrors()
149 232
 {
150 233
 	global $context, $txt;
... ...
@@ -301,6 +384,9 @@ function template_ticket_postbox()
301 384
 
302 385
 	echo template_control_richedit($context['post_box_name'], 'shd_smileybox', 'shd_bbcbox');
303 386
 
387
+	// Custom fields
388
+	template_ticket_custom_fields(2);
389
+
304 390
 	// Additional ticket options (attachments, smileys, etc)
305 391
 	template_ticket_additional_options();
306 392
 
... ...
@@ -450,78 +536,6 @@ function template_ticket_additional_options()
450 536
 	});
451 537
 						// ]]></script>';
452 538
 	}
453
-
454
-	// Custom fields maybe?
455
-	if ($context['ticket_form']['custom_fields'] != 0)
456
-	{
457
-		echo '
458
-						<dl id="postAttachment">';
459
-
460
-			foreach ($context['ticket_form']['custom_fields'] as $field)
461
-			{
462
-				echo '
463
-							<dt id="field-' . $field['id'] . '">
464
-								' . $field['name'] . '<br />
465
-								<span class="smalltext">' . $field['desc'] . '</span>
466
-							</dt>
467
-							<dd>';
468
-
469
-				// Text
470
-				if ($field['type'] == 1)
471
-					echo '
472
-								<input type="text" name="field_' . $field['id'] . '" value="' . $field['default_value'] . '" size="50" />';
473
-				// Textarea
474
-				elseif ($field['type'] == 2)
475
-					echo '
476
-								<textarea name="field_' . $field['id'] . '" rows="4" cols="50">' . $field['default_value'] . '</textarea>';
477
-				// Integers only
478
-				elseif ($field['type'] == 3)
479
-					echo '
480
-								<input name="field_' . $field['id'] . '" value="' . $field['default_value'] . ' size="10 />';
481
-				// Floating numbers
482
-				elseif ($field['type'] == 4)
483
-					echo '
484
-								<input name="field_' . $field['id'] . '" value="' . $field['default_value'] . ' size="10 />';
485
-				// Select boxes
486
-				elseif ($field['id'] == 5)
487
-				{
488
-					echo '
489
-								<select name="field_' . $field['id'] . '">';
490
-
491
-					foreach ($field['options'] as $option)
492
-					{
493
-						echo '
494
-									<option value="' . $option . '">' . $option . '</option>';
495
-					}
496
-
497
-					echo '
498
-								</select>';
499
-				}
500
-				// Checkboxes!
501
-				elseif ($field['type'] == 6)
502
-					echo '<input name="field_' . $field['id'] . '" type="checkbox" ' . $field['default_value'] == 1 ? 'checked="checked"' : '' . '/>';
503
-				// Last one, radio buttons
504
-				elseif ($field['type'] == 7)
505
-				{
506
-					foreach ($field['options'] as $option)
507
-					{
508
-						echo '
509
-								<label for="field_' . $field['id'] . '">' . $option['name'] . '</label>
510
-								<input name="field_' . $field['id'] . '" type="radio" value="' . $option . '" />';
511
-					}
512
-				}
513
-				// Default to a text input field
514
-				else
515
-					echo '
516
-								<input type="text" name="field_' . $field['id'] . '" value="' . $field['default_value'] . '" size="50" />';
517
-
518
-				echo '
519
-							</dd>';
520
-			}
521
-
522
-		echo '
523
-						</dl>';
524
-	}
525 539
 }
526 540
 
527 541
 function template_ticket_begin_replies()
528 542