+ Added custom fields to new ticket screen (buggy) ! Fixed template layout ! Tidied up Post template + Fixed license.txt formatting
jblaze

jblaze commited on 2011-02-06 12:36:41
Showing 4 changed files, with 133 additions and 20 deletions.

... ...
@@ -108,7 +108,8 @@ h3.ticketheader img
108 108
 {
109 109
 	min-height: 280px;
110 110
 	overflow: auto;
111
-	width: 100%;
111
+	width: 20%;
112
+	float: left;
112 113
 }
113 114
 .shd_additional_details
114 115
 {
... ...
@@ -101,6 +101,9 @@ function shd_post_ticket()
101 101
 
102 102
 	shd_posting_additional_options();
103 103
 
104
+	if (!shd_load_custom_fields())
105
+		$context['ticket_form']['custom_fields'] == 0;
106
+
104 107
 	// A few basic checks
105 108
 	if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED)
106 109
 		fatal_lang_error('shd_cannot_edit_closed', false);
... ...
@@ -556,4 +556,50 @@ function shd_get_urgency_options($self_ticket = false)
556 556
 		$context['ticket_form']['urgency']['can_change'] = false;
557 557
 }
558 558
 
559
+function shd_load_custom_fields($use_roles = false)
560
+{
561
+	global $context, $smcFunc;
562
+
563
+	// Load up our custom fields from the database
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,
567
+			cf.display_empty, cf.required, cf.placement
568
+		FROM {db_prefix}helpdesk_custom_fields AS cf
569
+		WHERE cf.active = 1
570
+		ORDER BY cf.field_order',
571
+		array()
572
+	);
573
+
574
+	$context['ticket_form']['custom_fields'] = array();
575
+
576
+	// Loop through all fields and figure out where they should be.
577
+	while($row = $smcFunc['db_fetch_assoc']($custom_fields))
578
+	{
579
+		// No custom fields? Bah...
580
+		if (empty($row['id_field']))
581
+			return false;
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(
587
+			'id' => $row['id_field'],
588
+			'order' => $row['field_order'],
589
+			'location' => $row['field_loc'],
590
+			'name' => $row['field_name'],
591
+			'desc' => $row['field_desc'],
592
+			'icon' => $row['icon'],
593
+			'type' => $row['field_type'],
594
+			'options' => $row['field_options'],
595
+			'default_value' => $row['default_value'],
596
+			'display_empty' => $row['required'] == 1 ? 1 : $row['display_empty'], // Required and "selection" fields will always be displayed.
597
+			'bbc' => $row['bbc'] == 1,
598
+			'is_required' => $row['required'] == 1
599
+		);
600
+	}
601
+
602
+	return $context['ticket_form']['custom_fields'];
603
+}
604
+
559 605
 ?>
560 606
\ No newline at end of file
... ...
@@ -102,7 +102,7 @@ function template_ticket_info()
102 102
 					<div class="information shd_ticketdetails">
103 103
 						<strong><img src="', $settings['default_images_url'], '/simpledesk/details.png" alt="" class="shd_smallicon" /> ', $txt['shd_ticket_details'], '</strong>
104 104
 						<hr />
105
-						<ul>';
105
+						<ul class="reset">';
106 106
 
107 107
 	if (!empty($context['ticket_form']['display_id']))
108 108
 		echo '
... ...
@@ -301,7 +301,8 @@ function template_ticket_postbox()
301 301
 
302 302
 	echo template_control_richedit($context['post_box_name'], 'shd_smileybox', 'shd_bbcbox');
303 303
 
304
-	template_ticket_attachments();
304
+	// Additional ticket options (attachments, smileys, etc)
305
+	template_ticket_additional_options();
305 306
 
306 307
 	echo '
307 308
 						<br class="clear" />
... ...
@@ -309,7 +310,6 @@ function template_ticket_postbox()
309 310
 						<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" tabindex="', $context['tabindex']++, '" accesskey="s" class="button_submit" />
310 311
 						<input class="button_submit" type="submit" name="preview" value="', $txt['preview'], '" accesskey="p" tabindex="', $context['tabindex']++, '" />';
311 312
 
312
-	template_ticket_additional_options();
313 313
 }
314 314
 
315 315
 function template_ticket_footer()
... ...
@@ -358,14 +358,27 @@ function template_preview()
358 358
 	}
359 359
 }
360 360
 
361
-function template_ticket_attachments()
361
+function template_ticket_additional_options()
362 362
 {
363
-	global $context, $modSettings, $txt;
364
-	if (empty($context['current_attachments']) && empty($context['ticket_form']['do_attach']))
365
-		return;
363
+	global $context, $options, $txt, $modSettings;
364
+
365
+	echo '
366
+					<div class="information shd_reply_attachments" id="shd_attach_container"', !empty($context['shd_display']) ? ' style="display:none;"' : '', '>
367
+						<ul class="post_options">';
368
+
369
+	foreach ($context['ticket_form']['additional_opts'] as $key => $details)
370
+	{
371
+		if (!empty($details['show']))
372
+			echo '
373
+							<li><label for="', $key, '"><input type="checkbox" name="', $key, '" id="', $key, '"', (!empty($details['checked']) ? ' checked="checked"' : ''), ' value="1" class="input_check" /> ', $details['text'], '</label></li>';
374
+	}
366 375
 
367 376
 	echo '
368
-					<div class="information shd_reply_attachments" id="shd_attach_container"', !empty($context['shd_display']) ? ' style="display:none;"' : '', '>';
377
+						</ul>
378
+						<hr />';
379
+
380
+	if (empty($context['current_attachments']) && empty($context['ticket_form']['do_attach']))
381
+		return;
369 382
 
370 383
 	if (!empty($context['current_attachments']))
371 384
 	{
... ...
@@ -438,27 +451,77 @@ function template_ticket_attachments()
438 451
 						// ]]></script>';
439 452
 	}
440 453
 
454
+	// Custom fields maybe?
455
+	if ($context['ticket_form']['custom_fields'] != 0)
456
+	{
441 457
 		echo '
442
-					</div>';
443
-}
458
+						<dl id="postAttachment">';
444 459
 
445
-function template_ticket_additional_options()
460
+			foreach ($context['ticket_form']['custom_fields'] as $field)
446 461
 			{
447
-	global $context, $options, $txt, $modSettings;
448 462
 				echo '
449
-					<div id="postMoreOptions" class="smalltext">
450
-						<ul class="post_options">';
463
+							<dt id="field-' . $field['id'] . '">
464
+								' . $field['name'] . '<br />
465
+								<span class="smalltext">' . $field['desc'] . '</span>
466
+							</dt>
467
+							<dd>';
451 468
 
452
-	foreach ($context['ticket_form']['additional_opts'] as $key => $details)
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)
453 487
 				{
454
-		if (!empty($details['show']))
455 488
 					echo '
456
-							<li><label for="', $key, '"><input type="checkbox" name="', $key, '" id="', $key, '"', (!empty($details['checked']) ? ' checked="checked"' : ''), ' value="1" class="input_check" /> ', $details['text'], '</label></li>';
489
+								<select name="field_' . $field['id'] . '">';
490
+
491
+					foreach ($field['options'] as $option)
492
+					{
493
+						echo '
494
+									<option value="' . $option . '">' . $option . '</option>';
457 495
 					}
458 496
 
459 497
 					echo '
460
-						</ul>
461
-					</div>';
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
+	}
462 525
 }
463 526
 
464 527
 function template_ticket_begin_replies()
465 528