Cleanup a bunch of files
jdarwood007

jdarwood007 commited on 2019-02-16 15:24:21
Showing 30 changed files, with 416 additions and 329 deletions.


Signed-off-by: jdarwood007 <unmonitored+github@sleepycode.com>
... ...
@@ -8,11 +8,12 @@ php:
8 8
   - 7.1
9 9
   - 7.2
10 10
   - 7.3
11
+  - 7.4
11 12
 
12 13
 matrix:
13 14
   include:
14 15
     - php: hhvm
15
-      dist: trusty
16
+      dist: xenial
16 17
 
17 18
 script:
18 19
   - sudo add-apt-repository ppa:git-core/ppa -y
... ...
@@ -466,10 +466,18 @@ dl.settings dt.shd_cust_fields_largetext, .shd_cust_fields_largetext textarea {
466 466
 
467 467
 /* Urgency stuff */
468 468
 .generic_icons.urgency_increase::before {
469
-	background-position: -161px -5px;
469
+	width: 16px;
470
+	height: 16px;
471
+	display: inline-block;
472
+	content: '';
473
+	background: url(../images/simpledesk/move_up.png) no-repeat;
470 474
 }
471 475
 .generic_icons.urgency_decrease::before {
472
-	background-position: -213px -5px;
476
+	width: 16px;
477
+	height: 16px;
478
+	display: inline-block;
479
+	content: '';
480
+	background: url(../images/simpledesk/move_down.png) no-repeat;
473 481
 }
474 482
 
475 483
 /* We need some adjustments */
... ...
@@ -116,13 +116,15 @@ function shd_admin_canned_list()
116 116
 		}
117 117
 		$context['canned_replies'][$cat_id]['move_up'] &= $context['move_between_cats'];
118 118
 		$context['canned_replies'][$cat_id]['move_down'] &= $context['move_between_cats'];
119
+
120
+		$last_cat_id = $cat_id;
119 121
 	}
120 122
 
121
-	if (!isset($cat_id))
123
+	if (!isset($last_cat_id))
122 124
 		return;
123 125
 
124 126
 	$context['canned_replies'][key($context['canned_replies'])]['move_up'] = false;
125
-	$context['canned_replies'][$cat_id]['move_down'] = false;
127
+	$context['canned_replies'][$last_cat_id]['move_down'] = false;
126 128
 }
127 129
 
128 130
 /**
... ...
@@ -148,7 +150,7 @@ function shd_admin_canned_movecat()
148 150
 	if ($smcFunc['db_num_rows']($query) == 0 || empty($_REQUEST['direction']))
149 151
 	{
150 152
 		$smcFunc['db_free_result']($query);
151
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat', false);
153
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat', false);
152 154
 	}
153 155
 
154 156
 	$cats = array();
... ...
@@ -158,13 +160,13 @@ function shd_admin_canned_movecat()
158 160
 
159 161
 	$cats_map = array_flip($cats);
160 162
 	if (empty($cats_map[$context['canned_category']]))
161
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat', false);
163
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat', false);
162 164
 
163 165
 	$current_pos = $cats_map[$context['canned_category']];
164 166
 	$destination = $current_pos + ($_REQUEST['direction'] == 'up' ? -1 : 1);
165 167
 
166 168
 	if (empty($cats[$destination]))
167
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat_' . $_REQUEST['direction'], false);
169
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_cat_' . $_REQUEST['direction'], false);
168 170
 
169 171
 	$other_cat = $cats[$destination];
170 172
 
... ...
@@ -214,7 +216,7 @@ function shd_admin_canned_movereply()
214 216
 	if ($smcFunc['db_num_rows']($query) == 0 || empty($_REQUEST['direction']))
215 217
 	{
216 218
 		$smcFunc['db_free_result']($query);
217
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply', false);
219
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply', false);
218 220
 	}
219 221
 
220 222
 	$replies = array();
... ...
@@ -224,13 +226,13 @@ function shd_admin_canned_movereply()
224 226
 
225 227
 	$replies_map = array_flip($replies);
226 228
 	if (empty($replies_map[$context['canned_reply_id']]))
227
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply', false);
229
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply', false);
228 230
 
229 231
 	$current_pos = $replies_map[$context['canned_reply_id']];
230 232
 	$destination = $current_pos + ($_REQUEST['direction'] == 'up' ? -1 : 1);
231 233
 
232 234
 	if (empty($replies[$destination]))
233
-		return fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply_' . $_REQUEST['direction'], false);
235
+		shd_fatal_lang_error('shd_admin_cannedreplies_cannot_move_reply_' . $_REQUEST['direction'], false);
234 236
 
235 237
 	$other_reply = $replies[$destination];
236 238
 
... ...
@@ -293,7 +295,7 @@ function shd_admin_canned_editcat()
293 295
 	if ($smcFunc['db_num_rows']($query) == 0)
294 296
 	{
295 297
 		$smcFunc['db_free_result']($query);
296
-		return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
298
+		shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
297 299
 	}
298 300
 
299 301
 	list($context['category_name']) = $smcFunc['db_fetch_row']($query);
... ...
@@ -392,9 +394,9 @@ function shd_admin_canned_savecat()
392 394
 
393 395
 	// There are two things we could be doing here. $_POST['cat'] should be set, and it should be set to 'new' for new categories, or a number of an existing category otherwise.
394 396
 	if (empty($_POST['cat']))
395
-		return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
397
+		shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
396 398
 	elseif (empty($_POST['catname']))
397
-		return fatal_lang_error('shd_admin_cannedreplies_nocatname', false);
399
+		shd_fatal_lang_error('shd_admin_cannedreplies_nocatname', false);
398 400
 
399 401
 	checkSubmitOnce('check');
400 402
 
... ...
@@ -436,7 +438,7 @@ function shd_admin_canned_savecat()
436 438
 		);
437 439
 
438 440
 		if ($smcFunc['db_affected_rows']() == 0)
439
-			return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
441
+			shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
440 442
 
441 443
 		// Log this action.
442 444
 		shd_admin_log('admin_canned', array(
... ...
@@ -473,7 +475,7 @@ function shd_admin_canned_createreply()
473 475
 	if ($smcFunc['db_num_rows']($query) == 0)
474 476
 	{
475 477
 		$smcFunc['db_free_result']($query);
476
-		return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
478
+		shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
477 479
 	}
478 480
 	$smcFunc['db_free_result']($query);
479 481
 
... ...
@@ -538,7 +540,7 @@ function shd_admin_canned_editreply()
538 540
 	if ($smcFunc['db_num_rows']($query) == 0)
539 541
 	{
540 542
 		$smcFunc['db_free_result']($query);
541
-		return fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
543
+		shd_fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
542 544
 	}
543 545
 
544 546
 	$row = $smcFunc['db_fetch_assoc']($query);
... ...
@@ -658,11 +660,11 @@ function shd_admin_canned_savereply()
658 660
 	}
659 661
 
660 662
 	if (empty($context['canned_reply_id']))
661
-		return fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
663
+		shd_fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
662 664
 
663 665
 	$_POST['title'] = isset($_POST['title']) ? strtr($smcFunc['htmlspecialchars']($_POST['title']), array("\r" => '', "\n" => '', "\t" => '')) : '';
664 666
 	if (empty($_POST['title']))
665
-		return fatal_lang_error('shd_admin_cannedreplies_notitle', false);
667
+		shd_fatal_lang_error('shd_admin_cannedreplies_notitle', false);
666 668
 
667 669
 	$_REQUEST['shd_canned_reply'] = isset($_POST['shd_canned_reply']) ? $_POST['shd_canned_reply'] : '';
668 670
 
... ...
@@ -674,7 +676,7 @@ function shd_admin_canned_savereply()
674 676
 	}
675 677
 
676 678
 	if ($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['shd_canned_reply']), ENT_QUOTES) === '')
677
-		return fatal_lang_error('shd_admin_cannedreplies_nobody', false);
679
+		shd_fatal_lang_error('shd_admin_cannedreplies_nobody', false);
678 680
 
679 681
 	$_POST['shd_canned_reply'] = $smcFunc['htmlspecialchars']($_POST['shd_canned_reply'], ENT_QUOTES);
680 682
 	preparsecode($_POST['shd_canned_reply']);
... ...
@@ -686,7 +688,7 @@ function shd_admin_canned_savereply()
686 688
 
687 689
 	// Verify the destination category exists.
688 690
 	if (!isset($_POST['cat']))
689
-		return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
691
+		shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
690 692
 
691 693
 	$query = $smcFunc['db_query']('', '
692 694
 		SELECT cat_name
... ...
@@ -699,7 +701,7 @@ function shd_admin_canned_savereply()
699 701
 	if ($smcFunc['db_num_rows']($query) == 0)
700 702
 	{
701 703
 		$smcFunc['db_free_result']($query);
702
-		return fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
704
+		shd_fatal_lang_error('shd_admin_cannedreplies_thecatisalie', false);
703 705
 	}
704 706
 	$smcFunc['db_free_result']($query);
705 707
 
... ...
@@ -742,7 +744,7 @@ function shd_admin_canned_savereply()
742 744
 
743 745
 		// 3. Insert the departments.
744 746
 		if (empty($reply_id))
745
-			return fatal_lang_error('shd_admin_cannedreplies_notcreated', false);
747
+			shd_fatal_lang_error('shd_admin_cannedreplies_notcreated', false);
746 748
 
747 749
 		$inserts = array();
748 750
 		foreach ($depts_insert as $dept)
... ...
@@ -772,7 +774,7 @@ function shd_admin_canned_savereply()
772 774
 			)
773 775
 		);
774 776
 		if ($smcFunc['db_num_rows']($query) == 0)
775
-			return fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
777
+			shd_fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
776 778
 		$smcFunc['db_free_result']($query);
777 779
 
778 780
 		// We're updating, apparently.
... ...
@@ -830,7 +832,7 @@ function shd_admin_canned_movereplycat()
830 832
 	// Before we go any further, establish that the user specified a reply to move and that there is at least one category not including the one the reply is in.
831 833
 	$context['canned_reply_id'] = isset($_REQUEST['reply']) ? (int) $_REQUEST['reply'] : 0;
832 834
 	if (empty($context['canned_reply_id']) || $context['canned_reply_id'] < 0)
833
-		return fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
835
+		shd_fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
834 836
 
835 837
 	$query = $smcFunc['db_query']('', '
836 838
 		SELECT id_cat, reply_order
... ...
@@ -841,7 +843,7 @@ function shd_admin_canned_movereplycat()
841 843
 		)
842 844
 	);
843 845
 	if ($smcFunc['db_num_rows']($query) == 0)
844
-		return fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
846
+		shd_fatal_lang_error('shd_admin_cannedreplies_thereplyisalie', false);
845 847
 
846 848
 	list($current_cat, $current_reply_pos) = $smcFunc['db_fetch_row']($query);
847 849
 	$smcFunc['db_free_result']($query);
... ...
@@ -858,7 +860,7 @@ function shd_admin_canned_movereplycat()
858 860
 		)
859 861
 	);
860 862
 	if ($smcFunc['db_num_rows']($query) == 0)
861
-		return fatal_lang_error('shd_admin_cannedreplies_onlyonecat', false);
863
+		shd_fatal_lang_error('shd_admin_cannedreplies_onlyonecat', false);
862 864
 	while ($row = $smcFunc['db_fetch_assoc']($query))
863 865
 		$context['cannedreply_cats'][$row['id_cat']] = $row['cat_name'];
864 866
 	$smcFunc['db_free_result']($query);
... ...
@@ -877,7 +879,7 @@ function shd_admin_canned_movereplycat()
877 879
 		// 1. Is the new department valid?
878 880
 		$_REQUEST['newcat'] = isset($_REQUEST['newcat']) ? (int) $_REQUEST['newcat'] : 0;
879 881
 		if (!isset($context['cannedreply_cats'][$_REQUEST['newcat']]))
880
-			return fatal_lang_error('shd_admin_cannedreplies_destnoexist', false);
882
+			shd_fatal_lang_error('shd_admin_cannedreplies_destnoexist', false);
881 883
 
882 884
 		// 1a. Everything is valid, just double check it's not a random double submission.
883 885
 		checkSubmitOnce('check');
... ...
@@ -235,7 +235,7 @@ function shd_admin_custom_edit()
235 235
 	else
236 236
 	{
237 237
 		$smcFunc['db_free_result']($query);
238
-		return fatal_lang_error('shd_admin_cannot_edit_custom_field', false);
238
+		shd_fatal_lang_error('shd_admin_cannot_edit_custom_field', false);
239 239
 	}
240 240
 
241 241
 	loadLanguage('ManageSettings');
... ...
@@ -326,7 +326,7 @@ function shd_admin_custom_save()
326 326
 
327 327
 	// Fix all the input
328 328
 	if (trim($_POST['field_name']) == '')
329
-		return fatal_lang_error('shd_admin_no_fieldname', false);
329
+		shd_fatal_lang_error('shd_admin_no_fieldname', false);
330 330
 	$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
331 331
 	$_POST['description'] = $smcFunc['htmlspecialchars'](isset($_POST['description']) ? $_POST['description'] : '');
332 332
 	preparsecode($_POST['description']);
... ...
@@ -437,7 +437,7 @@ function shd_admin_custom_save()
437 437
 	{
438 438
 		$types = shd_admin_cf_change_types(false);
439 439
 		if (!in_array($_POST['field_type'], $types))
440
-			return fatal_lang_error('shd_admin_custom_field_invalid', false);
440
+			shd_fatal_lang_error('shd_admin_custom_field_invalid', false);
441 441
 
442 442
 		// Order??
443 443
 		$count_query = shd_db_query('', '
... ...
@@ -469,7 +469,7 @@ function shd_admin_custom_save()
469 469
 		);
470 470
 
471 471
 		if (empty($new_field))
472
-			return fatal_lang_error('shd_admin_could_not_create_field', false);
472
+			shd_fatal_lang_error('shd_admin_could_not_create_field', false);
473 473
 
474 474
 		// Also update fields
475 475
 		$smcFunc['db_query']('', '
... ...
@@ -519,12 +519,12 @@ function shd_admin_custom_save()
519 519
 			$smcFunc['db_free_result']($query);
520 520
 			$types = shd_admin_cf_change_types($row['field_type']);
521 521
 			if (!in_array($_POST['field_type'], $types))
522
-				return fatal_lang_error('shd_admin_custom_field_reselect_invalid', false);
522
+				shd_fatal_lang_error('shd_admin_custom_field_reselect_invalid', false);
523 523
 		}
524 524
 		else
525 525
 		{
526 526
 			$smcFunc['db_free_result']($query);
527
-			return fatal_lang_error('shd_admin_cannot_edit_custom_field', false);
527
+			shd_fatal_lang_error('shd_admin_cannot_edit_custom_field', false);
528 528
 		}
529 529
 
530 530
 		// Depending on the field type, we may need to be funky about overlaying things, hence grabbing the old options.
... ...
@@ -637,7 +637,7 @@ function shd_admin_custom_move()
637 637
 	if ($smcFunc['db_num_rows']($query) == 0 || empty($_REQUEST['direction']))
638 638
 	{
639 639
 		$smcFunc['db_free_result']($query);
640
-		return fatal_lang_error('shd_admin_cannot_move_custom_field', false);
640
+		shd_fatal_lang_error('shd_admin_cannot_move_custom_field', false);
641 641
 	}
642 642
 
643 643
 	$fields = array();
... ...
@@ -651,13 +651,13 @@ function shd_admin_custom_move()
651 651
 	ksort($fields);
652 652
 
653 653
 	if (!isset($fields_map[$_REQUEST['field']]))
654
-		return fatal_lang_error('shd_admin_cannot_move_custom_field', false);
654
+		shd_fatal_lang_error('shd_admin_cannot_move_custom_field', false);
655 655
 
656 656
 	$current_pos = $fields_map[$_REQUEST['field']];
657 657
 	$destination = $current_pos + ($_REQUEST['direction'] == 'up' ? -1 : 1);
658 658
 
659 659
 	if (empty($fields[$destination]))
660
-		return fatal_lang_error('shd_admin_cannot_move_custom_field_' . $_REQUEST['direction'], false);
660
+		shd_fatal_lang_error('shd_admin_cannot_move_custom_field_' . $_REQUEST['direction'], false);
661 661
 
662 662
 	$other_field = $fields[$destination];
663 663
 
... ...
@@ -110,7 +110,7 @@ function shd_admin_dept_move()
110 110
 	if ($smcFunc['db_num_rows']($query) == 0 || empty($_REQUEST['direction']))
111 111
 	{
112 112
 		$smcFunc['db_free_result']($query);
113
-		return fatal_lang_error('shd_admin_cannot_move_dept', false);
113
+		shd_fatal_lang_error('shd_admin_cannot_move_dept', false);
114 114
 	}
115 115
 
116 116
 	$depts = array();
... ...
@@ -120,13 +120,13 @@ function shd_admin_dept_move()
120 120
 
121 121
 	$depts_map = array_flip($depts);
122 122
 	if (empty($depts_map[$_REQUEST['dept']]))
123
-		return fatal_lang_error('shd_admin_cannot_move_dept', false);
123
+		shd_fatal_lang_error('shd_admin_cannot_move_dept', false);
124 124
 
125 125
 	$current_pos = $depts_map[$_REQUEST['dept']];
126 126
 	$destination = $current_pos + ($_REQUEST['direction'] == 'up' ? -1 : 1);
127 127
 
128 128
 	if (empty($depts[$destination]))
129
-		return fatal_lang_error('shd_admin_cannot_move_dept_' . $_REQUEST['direction'], false);
129
+		shd_fatal_lang_error('shd_admin_cannot_move_dept_' . $_REQUEST['direction'], false);
130 130
 
131 131
 	$other_dept = $depts[$destination];
132 132
 
... ...
@@ -180,13 +180,13 @@ function shd_admin_create_dept()
180 180
 
181 181
 		// Boring stuff like session checks done. Were you a naughty admin and didn't set it properly?
182 182
 		if (!isset($_POST['dept_name']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['dept_name'])) === '')
183
-			return fatal_lang_error('shd_no_dept_name', false);
183
+			shd_fatal_lang_error('shd_no_dept_name', false);
184 184
 		else
185 185
 			$_POST['dept_name'] = strtr($smcFunc['htmlspecialchars']($_POST['dept_name']), array("\r" => '', "\n" => '', "\t" => ''));
186 186
 
187 187
 		// Now to check the category.
188 188
 		if (!isset($_POST['dept_cat']) || !isset($context['shd_cat_list'][$_POST['dept_cat']]))
189
-			return fatal_lang_error('shd_invalid_category', false);
189
+			shd_fatal_lang_error('shd_invalid_category', false);
190 190
 
191 191
 		$_POST['dept_cat'] = (int) $_POST['dept_cat'];
192 192
 		$_POST['dept_beforeafter'] = empty($_POST['dept_beforeafter']) || empty($_POST['dept_cat']) ? 0 : 1;
... ...
@@ -210,7 +210,7 @@ function shd_admin_create_dept()
210 210
 		);
211 211
 
212 212
 		if (empty($newdept))
213
-			return fatal_lang_error('shd_could_not_create_dept', false);
213
+			shd_fatal_lang_error('shd_could_not_create_dept', false);
214 214
 
215 215
 		// Log this.
216 216
 		shd_admin_log('admin_dept', array(
... ...
@@ -243,7 +243,7 @@ function shd_admin_edit_dept()
243 243
 	if ($smcFunc['db_num_rows']($query) == 0)
244 244
 	{
245 245
 		$smcFunc['db_free_result']($query);
246
-		return fatal_lang_error('shd_unknown_dept', false);
246
+		shd_fatal_lang_error('shd_unknown_dept', false);
247 247
 	}
248 248
 	$context['shd_dept'] = $smcFunc['db_fetch_assoc']($query);
249 249
 	$context['shd_dept']['description'] = htmlspecialchars($context['shd_dept']['description']);
... ...
@@ -309,7 +309,7 @@ function shd_admin_save_dept()
309 309
 	if ($smcFunc['db_num_rows']($query) == 0)
310 310
 	{
311 311
 		$smcFunc['db_free_result']($query);
312
-		return fatal_lang_error('shd_unknown_dept', false);
312
+		shd_fatal_lang_error('shd_unknown_dept', false);
313 313
 	}
314 314
 	$context['shd_dept'] = $smcFunc['db_fetch_assoc']($query);
315 315
 	$smcFunc['db_free_result']($query);
... ...
@@ -323,7 +323,7 @@ function shd_admin_save_dept()
323 323
 			FROM {db_prefix}helpdesk_depts');
324 324
 		list($count) = $smcFunc['db_fetch_row']($query);
325 325
 		if ($count == 1)
326
-			return fatal_lang_error('shd_must_have_dept', false);
326
+			shd_fatal_lang_error('shd_must_have_dept', false);
327 327
 
328 328
 		// What about it having tickets in it?
329 329
 		$query = $smcFunc['db_query']('', '
... ...
@@ -337,7 +337,7 @@ function shd_admin_save_dept()
337 337
 		list($count) = $smcFunc['db_fetch_row']($query);
338 338
 		$smcFunc['db_free_result']($query);
339 339
 		if (!empty($count))
340
-			return fatal_lang_error('shd_dept_not_empty', false);
340
+			shd_fatal_lang_error('shd_dept_not_empty', false);
341 341
 
342 342
 		// Before we kill it, get its order position.
343 343
 		$query = $smcFunc['db_query']('', '
... ...
@@ -351,7 +351,7 @@ function shd_admin_save_dept()
351 351
 		if ($smcFunc['db_num_rows']($query) == 0)
352 352
 		{
353 353
 			$smcFunc['db_free_result']($query);
354
-			return fatal_lang_error(shd_unknown_dept, false);
354
+			shd_fatal_lang_error(shd_unknown_dept, false);
355 355
 		}
356 356
 		list($dept_order) = $smcFunc['db_fetch_row']($query);
357 357
 		$smcFunc['db_free_result']($query);
... ...
@@ -408,10 +408,10 @@ function shd_admin_save_dept()
408 408
 	// 5. Get the stuff in the form.
409 409
 	// 5a. That there's something in the dept. name
410 410
 	if (!isset($_POST['dept_name']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['dept_name'])) === '')
411
-		return fatal_lang_error('shd_no_dept_name', false);
411
+		shd_fatal_lang_error('shd_no_dept_name', false);
412 412
 	// 5b. Now to check the category exists and where we're putting it in the category.
413 413
 	elseif (!isset($_POST['dept_cat']) || !isset($context['shd_cat_list'][$_POST['dept_cat']]))
414
-		return fatal_lang_error('shd_invalid_category', false);
414
+		shd_fatal_lang_error('shd_invalid_category', false);
415 415
 
416 416
 	$_POST['dept_name'] = strtr($smcFunc['htmlspecialchars']($_POST['dept_name']), array("\r" => '', "\n" => '', "\t" => ''));
417 417
 	$_POST['dept_cat'] = (int) $_POST['dept_cat'];
... ...
@@ -138,7 +138,7 @@ function shd_admin_maint_reattribute()
138 138
 	$members = findMembers($_POST['to']);
139 139
 
140 140
 	if (empty($members))
141
-		return fatal_lang_error('shd_reattribute_cannot_find_member');
141
+		shd_fatal_lang_error('shd_reattribute_cannot_find_member');
142 142
 
143 143
 	$memID = array_shift($members);
144 144
 	$memID = $memID['id'];
... ...
@@ -146,25 +146,25 @@ function shd_admin_maint_reattribute()
146 146
 	if ($_POST['type'] == 'email')
147 147
 	{
148 148
 		if (empty($_POST['from_email']))
149
-			return fatal_lang_error('shd_reattribute_no_email');
149
+			shd_fatal_lang_error('shd_reattribute_no_email');
150 150
 		$clause = 'poster_email = {string:attribute}';
151 151
 		$attribute = $_POST['from_email'];
152 152
 	}
153 153
 	elseif ($_POST['type'] == 'name')
154 154
 	{
155 155
 		if (empty($_POST['from_name']))
156
-			return fatal_lang_error('shd_reattribute_no_user');
156
+			shd_fatal_lang_error('shd_reattribute_no_user');
157 157
 		$clause = 'poster_name = {string:attribute}';
158 158
 		$attribute = $_POST['from_name'];
159 159
 	}
160 160
 	elseif ($_POST['type'] == 'starter')
161 161
 	{
162 162
 		if (empty($_POST['from_starter']))
163
-			return fatal_lang_error('shd_reattribute_no_user');
163
+			shd_fatal_lang_error('shd_reattribute_no_user');
164 164
 		$from = findMembers($_POST['from_starter']);
165 165
 
166 166
 		if (empty($from))
167
-			return fatal_lang_error('shd_reattribute_cannot_find_member_from');
167
+			shd_fatal_lang_error('shd_reattribute_cannot_find_member_from');
168 168
 
169 169
 		$fromID = array_shift($from);
170 170
 		$attribute = $fromID['id'];
... ...
@@ -175,7 +175,7 @@ function shd_admin_maint_reattribute()
175 175
 			WHERE id_member_started = {int:attribute})';
176 176
 	}
177 177
 	else
178
-		return fatal_lang_error('shd_reattribute_no_user');
178
+		shd_fatal_lang_error('shd_reattribute_no_user');
179 179
 
180 180
 	// Now, we don't delete the user id from posts on account deletion, never have.
181 181
 	// So, get all the user ids attached to this user/email, make sure they're not in use, and then reattribute them.
... ...
@@ -194,7 +194,7 @@ function shd_admin_maint_reattribute()
194 194
 
195 195
 	// Did we find any members? If not, bail.
196 196
 	if (empty($members))
197
-		return fatal_lang_error('shd_reattribute_no_messages', false);
197
+		shd_fatal_lang_error('shd_reattribute_no_messages', false);
198 198
 
199 199
 	// Topic starters are a bit easier.
200 200
 	if ($_POST['type'] == 'starter')
... ...
@@ -221,7 +221,7 @@ function shd_admin_maint_reattribute()
221 221
 		$members = array_diff($members, $temp_members);
222 222
 
223 223
 		if (empty($members))
224
-			return fatal_lang_error('shd_reattribute_in_use', false);
224
+			shd_fatal_lang_error('shd_reattribute_in_use', false);
225 225
 
226 226
 		// OK, let's go!
227 227
 		$smcFunc['db_query']('', '
... ...
@@ -255,9 +255,9 @@ function shd_admin_maint_massdeptmove()
255 255
 	$_POST['id_dept_from'] = isset($_POST['id_dept_from']) ? (int) $_POST['id_dept_from'] : 0;
256 256
 	$_POST['id_dept_to'] = isset($_POST['id_dept_to']) ? (int) $_POST['id_dept_to'] : 0;
257 257
 	if ($_POST['id_dept_from'] == 0 || $_POST['id_dept_to'] == 0 || !in_array($_POST['id_dept_from'], $depts) || !in_array($_POST['id_dept_to'], $depts))
258
-		return fatal_lang_error('shd_unknown_dept', false);
258
+		shd_fatal_lang_error('shd_unknown_dept', false);
259 259
 	elseif ($_POST['id_dept_from'] == $_POST['id_dept_to'])
260
-		return fatal_lang_error('shd_admin_maint_massdeptmove_samedept', false);
260
+		shd_fatal_lang_error('shd_admin_maint_massdeptmove_samedept', false);
261 261
 
262 262
 	$clauses = array();
263 263
 	if (empty($_POST['moveopen']))
... ...
@@ -88,7 +88,7 @@ function shd_admin_create_role()
88 88
 
89 89
 	$context['role_template_id'] = isset($_REQUEST['template']) ? (int) $_REQUEST['template'] : 0;
90 90
 	if (empty($context['shd_permissions']['roles'][$context['role_template_id']]))
91
-		return fatal_lang_error('shd_unknown_template', false);
91
+		shd_fatal_lang_error('shd_unknown_template', false);
92 92
 
93 93
 	if (empty($_REQUEST['part']))
94 94
 	{
... ...
@@ -103,7 +103,7 @@ function shd_admin_create_role()
103 103
 
104 104
 		// Boring stuff like session checks done. Were you a naughty admin and didn't set it properly?
105 105
 		if (!isset($_POST['rolename']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['rolename'])) === '')
106
-			return fatal_lang_error('shd_no_role_name', false);
106
+			shd_fatal_lang_error('shd_no_role_name', false);
107 107
 
108 108
 		$_POST['rolename'] = strtr($smcFunc['htmlspecialchars']($_POST['rolename']), array("\r" => '', "\n" => '', "\t" => ''));
109 109
 
... ...
@@ -117,7 +117,7 @@ function shd_admin_create_role()
117 117
 		);
118 118
 
119 119
 		if (empty($newrole))
120
-			return fatal_lang_error('shd_could_not_create_role', false);
120
+			shd_fatal_lang_error('shd_could_not_create_role', false);
121 121
 
122 122
 		// Always need logs.
123 123
 		shd_admin_log('admin_permissions', array(
... ...
@@ -138,7 +138,7 @@ function shd_admin_edit_role()
138 138
 	shd_load_role($context['shd_role_id']);
139 139
 
140 140
 	if (empty($context['shd_permissions']['user_defined_roles'][$context['shd_role_id']]))
141
-		return fatal_lang_error('shd_unknown_role', false);
141
+		shd_fatal_lang_error('shd_unknown_role', false);
142 142
 
143 143
 	// OK, figure out what groups are possible groups (including regular members), and what groups this role has.
144 144
 	// We're not interested in admin (group 1), board mod (group 3) or post count groups (min_posts != -1)
... ...
@@ -218,7 +218,7 @@ function shd_admin_save_role()
218 218
 
219 219
 	// Hah, no, you're just an extra, bye.
220 220
 	if (empty($context['shd_permissions']['user_defined_roles'][$context['shd_role_id']]))
221
-		return fatal_lang_error('shd_unknown_role', false);
221
+		shd_fatal_lang_error('shd_unknown_role', false);
222 222
 
223 223
 	// 2b. Oh, we have actually heard of you. That's fine, we'll just refer to you by codename because we're lazy.
224 224
 	$role = &$context['shd_permissions']['user_defined_roles'][$context['shd_role_id']];
... ...
@@ -270,7 +270,7 @@ function shd_admin_save_role()
270 270
 
271 271
 	// 4. The unknown actor in a role?
272 272
 	if (!isset($_POST['rolename']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['rolename'])) === '')
273
-		return fatal_lang_error('shd_no_role_name', false);
273
+		shd_fatal_lang_error('shd_no_role_name', false);
274 274
 
275 275
 	$_POST['rolename'] = strtr($smcFunc['htmlspecialchars']($_POST['rolename']), array("\r" => '', "\n" => '', "\t" => ''));
276 276
 
... ...
@@ -487,7 +487,7 @@ function shd_admin_copy_role()
487 487
 
488 488
 	// Hah, no, you're just an extra, bye.
489 489
 	if (empty($context['shd_permissions']['user_defined_roles'][$context['shd_role_id']]))
490
-		return fatal_lang_error('shd_unknown_role', false);
490
+		shd_fatal_lang_error('shd_unknown_role', false);
491 491
 
492 492
 	if (empty($_REQUEST['part']))
493 493
 	{
... ...
@@ -502,7 +502,7 @@ function shd_admin_copy_role()
502 502
 
503 503
 		// Boring stuff like session checks done. Were you a naughty admin and didn't set it properly?
504 504
 		if (!isset($_POST['rolename']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['rolename'])) === '')
505
-			return fatal_lang_error('shd_no_role_name', false);
505
+			shd_fatal_lang_error('shd_no_role_name', false);
506 506
 
507 507
 		$_POST['rolename'] = strtr($smcFunc['htmlspecialchars']($_POST['rolename']), array("\r" => '', "\n" => '', "\t" => ''));
508 508
 
... ...
@@ -516,7 +516,7 @@ function shd_admin_copy_role()
516 516
 		);
517 517
 
518 518
 		if (empty($newrole))
519
-			return fatal_lang_error('shd_could_not_create_role', false);
519
+			shd_fatal_lang_error('shd_could_not_create_role', false);
520 520
 
521 521
 		// OK, so we made the role. Now add the permissions from the existing role, first grab 'em
522 522
 		$new_perms = array();
... ...
@@ -142,10 +142,13 @@ function shd_ajax_privacy()
142 142
 		)
143 143
 	);
144 144
 
145
-	if ($row = $smcFunc['db_fetch_assoc']($query))
146
-	{
145
+	$row = $smcFunc['db_fetch_assoc']($query);
147 146
 	$smcFunc['db_free_result']($query);
148 147
 
148
+	// No ticket, no luck.
149
+	if (empty($row))
150
+		return array('success' => false, 'error' => $txt['shd_no_ticket']);
151
+		
149 152
 	if (in_array($row['status'], array(TICKET_STATUS_CLOSED, TICKET_STATUS_DELETED)) || !shd_allowed_to('shd_alter_privacy_any', $row['id_dept']) && (!shd_allowed_to('shd_alter_privacy_own', $row['id_dept']) || $row['id_member_started'] != $user_info['id']))
150 153
 		return array('success' => false, 'error' => $txt['shd_cannot_change_privacy']);
151 154
 
... ...
@@ -172,8 +175,6 @@ function shd_ajax_privacy()
172 175
 
173 176
 	return array('success' => true, 'message' => $new ? $txt['shd_ticket_private'] : $txt['shd_ticket_notprivate']);
174 177
 }
175
-	return array('success' => false, 'error' => $txt['shd_no_ticket']);
176
-}
177 178
 
178 179
 /**
179 180
  *	Handles AJAX updates to ticket urgency.
... ...
@@ -215,10 +216,13 @@ function shd_ajax_urgency()
215 216
 		)
216 217
 	);
217 218
 
218
-	if ($row = $smcFunc['db_fetch_assoc']($query))
219
-	{
219
+	$row = $smcFunc['db_fetch_assoc']($query);
220 220
 	$smcFunc['db_free_result']($query);
221 221
 
222
+	// No ticket, no luck.
223
+	if (empty($row))
224
+		return array('error' => $txt['shd_no_ticket']);
225
+
222 226
 	$can_urgency = shd_can_alter_urgency($row['urgency'], $row['id_member_started'], ($row['status'] == TICKET_STATUS_CLOSED), ($row['status'] == TICKET_STATUS_DELETED), $row['id_dept']);
223 227
 
224 228
 	if (empty($_GET['change']) || empty($can_urgency[$_GET['change']]))
... ...
@@ -261,8 +265,6 @@ function shd_ajax_urgency()
261 265
 
262 266
 	return $context['ajax_return'];
263 267
 }
264
-	return array('error' => $txt['shd_no_ticket']);
265
-}
266 268
 
267 269
 /**
268 270
  *	Collects ticket post data for quoting posts through AJAX (i.e. inserting a quote live into the postbox)
... ...
@@ -291,8 +293,11 @@ function shd_ajax_quote()
291 293
 
292 294
 	$_REQUEST['quote'] = !empty($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : 0;
293 295
 	$message = '';
294
-	if (!empty($_REQUEST['quote']))
295
-	{
296
+
297
+	// Nothing to quote, blank message.
298
+	if (empty($_REQUEST['quote']))
299
+		return array('success' => true, 'message' => $message);
300
+
296 301
 	$query = shd_db_query('', '
297 302
 		SELECT hdtr.body, COALESCE(mem.real_name, hdtr.poster_name) AS poster_name, hdtr.poster_time, hdt.id_ticket, hdt.id_first_msg
298 303
 		FROM {db_prefix}helpdesk_ticket_replies AS hdtr
... ...
@@ -305,10 +310,13 @@ function shd_ajax_quote()
305 310
 		)
306 311
 	);
307 312
 
308
-		if ($row = $smcFunc['db_fetch_assoc']($query))
309
-		{
313
+	$row = $smcFunc['db_fetch_assoc']($query);
310 314
 	$smcFunc['db_free_result']($query);
311 315
 
316
+	// Can't find this, no quote.
317
+	if (empty($row))
318
+		return array('success' => true, 'message' => $message);
319
+		
312 320
 	// Censor the message!
313 321
 	$row['body'] = un_preparsecode($row['body']);
314 322
 	censorText($row['body']);
... ...
@@ -317,25 +325,13 @@ function shd_ajax_quote()
317 325
 	if (strpos($row['poster_name'], '[') !== false || strpos($row['poster_name'], ']') !== false)
318 326
 		$row['poster_name'] = '"' . $row['poster_name'] . '"';
319 327
 
320
-			// Make the body HTML if need be.
321
-			if (!empty($_REQUEST['mode']))
322
-			{
323
-				require_once($sourcedir . '/Subs-Editor.php');
324
-				$row['body'] = strtr($row['body'], array('&lt;' => '#smlt#', '&gt;' => '#smgt#', '&amp;' => '#smamp#'));
325
-				$row['body'] = bbc_to_html($row['body']);
326
-				$lb = "\n";
327
-			}
328
-			else
329
-				$lb = "\n";
330
-
331 328
 	$message = '[quote author=' . $row['poster_name'] . ' link=action=helpdesk;sa=ticket;ticket=' . $row['id_ticket'];
332
-			if ($row['id_first_msg'] != $_REQUEST['quote']) // don't add the msg if we're quoting the ticket itself
333
-				$message .= '.msg' . $_REQUEST['quote'] . '#msg' . $_REQUEST['quote'];
334 329
 
335
-			$message .= ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]';
336
-		}
337
-	}
330
+	// don't add the msg if we're quoting the ticket itself
331
+	if ($row['id_first_msg'] != $_REQUEST['quote'])
332
+		$message .= '.msg' . $_REQUEST['quote'] . '#msg' . $_REQUEST['quote'];
338 333
 
334
+	$message .= ' date=' . $row['poster_time'] . ']' . "\n" . $row['body'] . "\n" . '[/quote]';
339 335
 	return array('success' => true, 'message' => $message);
340 336
 }
341 337
 
... ...
@@ -365,8 +361,9 @@ function shd_ajax_canned()
365 361
 
366 362
 	$_REQUEST['reply'] = !empty($_REQUEST['reply']) ? (int) $_REQUEST['reply'] : 0;
367 363
 	$message = '';
368
-	if (!empty($_REQUEST['reply']) && !empty($context['ticket_id']))
369
-	{
364
+	if (empty($_REQUEST['reply']) || empty($context['ticket_id']))
365
+		return array('success' => true, 'message' => $message);
366
+
370 367
 	$query = shd_db_query('', '
371 368
 		SELECT hdt.id_member_started, hdt.id_dept, hdcr.body, hdcr.vis_user, hdcr.vis_staff
372 369
 		FROM {db_prefix}helpdesk_tickets AS hdt
... ...
@@ -381,7 +378,8 @@ function shd_ajax_canned()
381 378
 			'reply' => $_REQUEST['reply'],
382 379
 		)
383 380
 	);
384
-		if ($smcFunc['db_num_rows']($query) == 0)
381
+
382
+	if (empty($smcFunc['db_num_rows']($query)))
385 383
 	{
386 384
 		$smcFunc['db_free_result']($query);
387 385
 		return array('success' => true, 'message' => $message);
... ...
@@ -410,15 +408,6 @@ function shd_ajax_canned()
410 408
 	censorText($message);
411 409
 	$message = preg_replace('~<br ?/?' . '>~i', "\n", $row['body']);
412 410
 
413
-		// Make the body HTML if need be.
414
-		if (!empty($_REQUEST['mode']))
415
-		{
416
-			require_once($sourcedir . '/Subs-Editor.php');
417
-			$message = strtr($message, array('&lt;' => '#smlt#', '&gt;' => '#smgt#', '&amp;' => '#smamp#'));
418
-			$message = bbc_to_html($message);
419
-		}
420
-	}
421
-
422 411
 	$message = strtr($message, array('&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;'));
423 412
 	return array('success' => true, 'message' => $message);
424 413
 }
... ...
@@ -446,7 +435,7 @@ function shd_ajax_assign()
446 435
 		return array('success' => false, 'error' => $txt['shd_no_ticket']);
447 436
 
448 437
 	$query = shd_db_query('', '
449
-		SELECT hdt.private, hdt.id_member_started, id_member_assigned, id_dept, hdt.status, 1 AS valid
438
+		SELECT hdt.private, hdt.id_member_started, id_member_assigned, id_dept, hdt.status
450 439
 		FROM {db_prefix}helpdesk_tickets AS hdt
451 440
 		WHERE {query_see_ticket}
452 441
 			AND hdt.id_ticket = {int:ticket}',
... ...
@@ -454,13 +443,12 @@ function shd_ajax_assign()
454 443
 			'ticket' => $context['ticket_id'],
455 444
 		)
456 445
 	);
457
-	if ($smcFunc['db_num_rows']($query) != 0)
458
-		list($private, $ticket_starter, $ticket_assigned, $dept, $status, $valid) = $smcFunc['db_fetch_row']($query);
459
-	$smcFunc['db_free_result']($query);
460
-
461
-	if (empty($valid))
446
+	if (empty($smcFunc['db_num_rows']($query)))
462 447
 		return array('success' => false, 'error' => $txt['shd_no_ticket']);
463 448
 
449
+	list($private, $ticket_starter, $ticket_assigned, $dept, $status) = $smcFunc['db_fetch_row']($query);
450
+	$smcFunc['db_free_result']($query);
451
+
464 452
 	require_once($sourcedir . '/sd_source/SimpleDesk-Assign.php');
465 453
 	$assignees = shd_get_possible_assignees($private, $ticket_starter, $dept);
466 454
 	array_unshift($assignees, 0); // add the unassigned option in at the start
... ...
@@ -512,7 +500,7 @@ function shd_ajax_assign2()
512 500
 		return array('error' => $txt['shd_no_ticket']);
513 501
 
514 502
 	$query = shd_db_query('', '
515
-		SELECT hdt.private, hdt.id_member_started, id_member_assigned, subject, id_dept, hdt.status, 1 AS valid
503
+		SELECT hdt.private, hdt.id_member_started, id_member_assigned, subject, id_dept, hdt.status
516 504
 		FROM {db_prefix}helpdesk_tickets AS hdt
517 505
 		WHERE {query_see_ticket}
518 506
 			AND hdt.id_ticket = {int:ticket}',
... ...
@@ -520,13 +508,12 @@ function shd_ajax_assign2()
520 508
 			'ticket' => $context['ticket_id'],
521 509
 		)
522 510
 	);
523
-	if ($smcFunc['db_num_rows']($query) != 0)
524
-		list($private, $ticket_starter, $ticket_assigned, $subject, $dept, $status, $valid) = $smcFunc['db_fetch_row']($query);
525
-	$smcFunc['db_free_result']($query);
526
-
527
-	if (empty($valid))
511
+	if (empty($smcFunc['db_num_rows']($query)))
528 512
 		return array('error' => $txt['shd_no_ticket']);
529 513
 
514
+	list($private, $ticket_starter, $ticket_assigned, $subject, $dept, $status) = $smcFunc['db_fetch_row']($query);
515
+	$smcFunc['db_free_result']($query);
516
+
530 517
 	if (!isset($_GET['to_user']) || !is_numeric($_GET['to_user']))
531 518
 		return array('success' => false, 'error' => $txt['shd_assigned_not_permitted']);
532 519
 
... ...
@@ -54,7 +54,7 @@ function shd_assign()
54 54
 	checkSession('get');
55 55
 
56 56
 	if (empty($context['ticket_id']))
57
-		return fatal_lang_error('shd_no_ticket');
57
+		shd_fatal_lang_error('shd_no_ticket');
58 58
 
59 59
 	$context['shd_return_to'] = isset($_REQUEST['home']) ? 'home' : 'ticket';
60 60
 
... ...
@@ -80,11 +80,11 @@ function shd_assign()
80 80
 	else
81 81
 	{
82 82
 		$smcFunc['db_free_result']($query);
83
-		return fatal_lang_error('shd_no_ticket');
83
+		shd_fatal_lang_error('shd_no_ticket');
84 84
 	}
85 85
 
86 86
 	if ($status == TICKET_STATUS_CLOSED || $status == TICKET_STATUS_DELETED)
87
-		return fatal_lang_error('shd_cannot_assign', false);
87
+		shd_fatal_lang_error('shd_cannot_assign', false);
88 88
 
89 89
 	if (shd_allowed_to('shd_assign_ticket_any', $dept)) // can regularly assign? If so, load up potential candidates and throw it at the template.
90 90
 	{
... ...
@@ -112,7 +112,7 @@ function shd_assign()
112 112
 		}
113 113
 
114 114
 		if (empty($members))
115
-			return fatal_lang_error('shd_no_staff_assign');
115
+			shd_fatal_lang_error('shd_no_staff_assign');
116 116
 
117 117
 		if ($context['shd_multi_dept'])
118 118
 			$context['linktree'][] = array(
... ...
@@ -153,10 +153,10 @@ function shd_assign()
153 153
 			shd_commit_assignment($context['ticket_id'], 0);
154 154
 		}
155 155
 		else // oops, assigned to somebody else
156
-			return fatal_lang_error('shd_cannot_assign_other', false);
156
+			shd_fatal_lang_error('shd_cannot_assign_other', false);
157 157
 	}
158 158
 	else
159
-		return fatal_lang_error('shd_cannot_assign', false);
159
+		shd_fatal_lang_error('shd_cannot_assign', false);
160 160
 }
161 161
 
162 162
 /**
... ...
@@ -177,7 +177,7 @@ function shd_assign2()
177 177
 	checkSubmitOnce('check');
178 178
 
179 179
 	if (empty($context['ticket_id']))
180
-		return fatal_lang_error('shd_no_ticket');
180
+		shd_fatal_lang_error('shd_no_ticket');
181 181
 
182 182
 	$context['shd_return_to'] = isset($_REQUEST['home']) ? 'home' : 'ticket';
183 183
 
... ...
@@ -206,7 +206,7 @@ function shd_assign2()
206 206
 	else
207 207
 	{
208 208
 		$smcFunc['db_free_result']($query);
209
-		return fatal_lang_error('shd_no_ticket');
209
+		shd_fatal_lang_error('shd_no_ticket');
210 210
 	}
211 211
 
212 212
 	// Just in case, are they cancelling?
... ...
@@ -214,7 +214,7 @@ function shd_assign2()
214 214
 		return redirectexit('action=helpdesk;sa=ticket;ticket=' . $context['ticket_id']);
215 215
 
216 216
 	if ($status == TICKET_STATUS_CLOSED || $status == TICKET_STATUS_DELETED)
217
-		return fatal_lang_error('shd_cannot_assign', false);
217
+		shd_fatal_lang_error('shd_cannot_assign', false);
218 218
 
219 219
 	if (shd_allowed_to('shd_assign_ticket_any', $dept)) // can regularly assign? If so, see if our requested member is staff and can see the ticket
220 220
 	{
... ...
@@ -239,7 +239,7 @@ function shd_assign2()
239 239
 				shd_commit_assignment($context['ticket_id'], $assignee);
240 240
 			}
241 241
 			else
242
-				return fatal_lang_error('shd_assigned_not_permitted', false);
242
+				shd_fatal_lang_error('shd_assigned_not_permitted', false);
243 243
 		}
244 244
 	}
245 245
 	elseif (shd_allowed_to('shd_assign_ticket_own', $dept) && shd_allowed_to('shd_staff', $dept)) // can't just randomly assign (and must be staff), so look at if it's already assigned or not.
... ...
@@ -259,10 +259,10 @@ function shd_assign2()
259 259
 			shd_commit_assignment($context['ticket_id'], 0);
260 260
 		}
261 261
 		else // oops, assigned to somebody else
262
-			return fatal_lang_error('shd_cannot_assign_other', false);
262
+			shd_fatal_lang_error('shd_cannot_assign_other', false);
263 263
 	}
264 264
 	else
265
-		return fatal_lang_error('shd_cannot_assign', false);
265
+		shd_fatal_lang_error('shd_cannot_assign', false);
266 266
 }
267 267
 
268 268
 /**
... ...
@@ -52,7 +52,7 @@ function shd_ticket_delete()
52 52
 	checkSession('get');
53 53
 
54 54
 	if (empty($context['ticket_id']))
55
-		return fatal_lang_error('shd_no_ticket', false);
55
+		shd_fatal_lang_error('shd_no_ticket', false);
56 56
 
57 57
 	// Check we can actually see the ticket we're deleting, and if we can only delete our own, we are the owner
58 58
 	$query_ticket = shd_db_query('', '
... ...
@@ -69,12 +69,12 @@ function shd_ticket_delete()
69 69
 	{
70 70
 		$smcFunc['db_free_result']($query_ticket);
71 71
 		if (!shd_allowed_to('shd_delete_ticket_any', $row['id_dept']) && (!shd_allowed_to('shd_delete_ticket_own', $row['id_dept']) || $user_info['id'] != $row['id_member_started']))
72
-			return fatal_lang_error('shd_cannot_delete_ticket', false);
72
+			shd_fatal_lang_error('shd_cannot_delete_ticket', false);
73 73
 	}
74 74
 	else
75 75
 	{
76 76
 		$smcFunc['db_free_result']($query_ticket);
77
-		return fatal_lang_error('shd_no_ticket', false);
77
+		shd_fatal_lang_error('shd_no_ticket', false);
78 78
 	}
79 79
 
80 80
 	$subject = $row['subject'];
... ...
@@ -116,7 +116,7 @@ function shd_reply_delete()
116 116
 	$_REQUEST['reply'] = !empty($_REQUEST['reply']) ? (int) $_REQUEST['reply'] : 0;
117 117
 
118 118
 	if (empty($_REQUEST['reply']) || empty($context['ticket_id']))
119
-		return fatal_lang_error('shd_no_ticket');
119
+		shd_fatal_lang_error('shd_no_ticket');
120 120
 
121 121
 	// Check we can actually see the ticket we're deleting, that this reply is in this ticket and that we can delete this reply
122 122
 	$query_ticket = shd_db_query('', '
... ...
@@ -138,12 +138,12 @@ function shd_reply_delete()
138 138
 	{
139 139
 		$smcFunc['db_free_result']($query_ticket);
140 140
 		if (($row['status'] == TICKET_STATUS_CLOSED || $row['status'] == TICKET_STATUS_DELETED) || (!shd_allowed_to('shd_delete_reply_any', $row['id_dept']) && (!shd_allowed_to('shd_delete_reply_own', $row['id_dept']) || $user_info['id'] != $row['id_member'])))
141
-			return fatal_lang_error('shd_cannot_delete_reply', false);
141
+			shd_fatal_lang_error('shd_cannot_delete_reply', false);
142 142
 	}
143 143
 	else
144 144
 	{
145 145
 		$smcFunc['db_free_result']($query_ticket);
146
-		return fatal_lang_error('shd_no_ticket', false);
146
+		shd_fatal_lang_error('shd_no_ticket', false);
147 147
 	}
148 148
 
149 149
 	$subject = $row['subject'];
... ...
@@ -203,7 +203,7 @@ function shd_perma_delete()
203 203
 
204 204
 	// We have to have either a ticket or a reply to know what to delete (Or do you want me to drop your whole database? >:D)
205 205
 	if (empty($context['ticket_id']) && empty($_REQUEST['reply']))
206
-		return fatal_lang_error('shd_no_ticket', false);
206
+		shd_fatal_lang_error('shd_no_ticket', false);
207 207
 
208 208
 	// If we're deleting a whole ticket...
209 209
 	if (!empty($context['ticket_id']) && empty($_REQUEST['reply']))
... ...
@@ -222,7 +222,7 @@ function shd_perma_delete()
222 222
 		if ($smcFunc['db_num_rows']($query_ticket) == 0)
223 223
 		{
224 224
 			$smcFunc['db_free_result']($query_ticket);
225
-			return fatal_lang_error('shd_no_ticket', false);
225
+			shd_fatal_lang_error('shd_no_ticket', false);
226 226
 		}
227 227
 		else
228 228
 		{
... ...
@@ -232,7 +232,7 @@ function shd_perma_delete()
232 232
 		}
233 233
 
234 234
 		if ($row['status'] != TICKET_STATUS_DELETED)
235
-			return fatal_lang_error('shd_cannot_delete_ticket', false);
235
+			shd_fatal_lang_error('shd_cannot_delete_ticket', false);
236 236
 
237 237
 		$subject = $row['subject'];
238 238
 		// Expire the cache of count(active tickets)
... ...
@@ -368,7 +368,7 @@ function shd_perma_delete()
368 368
 		if ($smcFunc['db_num_rows']($query_ticket) == 0)
369 369
 		{
370 370
 			$smcFunc['db_free_result']($query_ticket);
371
-			return fatal_lang_error('shd_no_ticket', false);
371
+			shd_fatal_lang_error('shd_no_ticket', false);
372 372
 		}
373 373
 		else
374 374
 		{
... ...
@@ -378,7 +378,7 @@ function shd_perma_delete()
378 378
 		}
379 379
 
380 380
 		if ($row['status'] == TICKET_STATUS_DELETED || $row['message_status'] != MSG_STATUS_DELETED)
381
-			return fatal_lang_error('shd_cannot_delete_reply', false);
381
+			shd_fatal_lang_error('shd_cannot_delete_reply', false);
382 382
 
383 383
 		$subject = $row['subject'];
384 384
 		// Expire the cache of count(active tickets)
... ...
@@ -463,7 +463,7 @@ function shd_perma_delete()
463 463
 		redirectexit('action=helpdesk;sa=ticket;ticket=' . $context['ticket_id']);
464 464
 	}
465 465
 	else
466
-		return fatal_lang_error('shd_no_ticket');
466
+		shd_fatal_lang_error('shd_no_ticket');
467 467
 }
468 468
 
469 469
 // Delete a given attachment from the one-click interface.
... ...
@@ -472,7 +472,7 @@ function shd_attach_delete()
472 472
 	global $smcFunc, $user_info, $context, $sourcedir;
473 473
 
474 474
 	if (empty($context['ticket_id']) || empty($_GET['attach']) || (int) $_GET['attach'] == 0)
475
-		return fatal_lang_error('no_access', false);
475
+		shd_fatal_lang_error('no_access', false);
476 476
 
477 477
 	$_GET['attach'] = (int) $_GET['attach'];
478 478
 
... ...
@@ -494,7 +494,7 @@ function shd_attach_delete()
494 494
 	if ($smcFunc['db_num_rows']($query) == 0)
495 495
 	{
496 496
 		$smcFunc['db_free_result']($query);
497
-		return fatal_lang_error('no_access');
497
+		shd_fatal_lang_error('no_access');
498 498
 	}
499 499
 
500 500
 	list($dept, $filename, $id_msg, $subject) = $smcFunc['db_fetch_row']($query);
... ...
@@ -531,7 +531,7 @@ function shd_ticket_restore()
531 531
 	checkSession('get');
532 532
 
533 533
 	if (empty($context['ticket_id']))
534
-		return fatal_lang_error('shd_no_ticket', false);
534
+		shd_fatal_lang_error('shd_no_ticket', false);
535 535
 
536 536
 	// Does the ticket we're trying to restore exist and can we see it?
537 537
 	$query_ticket = shd_db_query('', '
... ...
@@ -548,7 +548,7 @@ function shd_ticket_restore()
548 548
 	{
549 549
 		$smcFunc['db_free_result']($query_ticket);
550 550
 		if ($row['status'] != TICKET_STATUS_DELETED || (!shd_allowed_to('shd_restore_ticket_any', $row['id_dept']) && (!shd_allowed_to('shd_restore_ticket_own', $row['id_dept']) || $user_info['id'] != $row['id_member_started'])))
551
-			return fatal_lang_error('shd_cannot_restore_ticket', false);
551
+			shd_fatal_lang_error('shd_cannot_restore_ticket', false);
552 552
 
553 553
 		$subject = $row['subject'];
554 554
 		$starter = $row['id_member_started'];
... ...
@@ -558,7 +558,7 @@ function shd_ticket_restore()
558 558
 	else
559 559
 	{
560 560
 		$smcFunc['db_free_result']($query_ticket);
561
-		return fatal_lang_error('shd_no_ticket', false);
561
+		shd_fatal_lang_error('shd_no_ticket', false);
562 562
 	}
563 563
 
564 564
 	// The ticket's id is in $context['ticket_id'].
... ...
@@ -599,7 +599,7 @@ function shd_reply_restore()
599 599
 	$_REQUEST['reply'] = empty($_REQUEST['reply']) ? 0 : (int) $_REQUEST['reply'];
600 600
 
601 601
 	if (empty($_REQUEST['reply']))
602
-		return fatal_lang_error('shd_no_ticket', false);
602
+		shd_fatal_lang_error('shd_no_ticket', false);
603 603
 
604 604
 	// Check we can actually see the ticket we're restoring from, and that we can restore this reply
605 605
 	$query_ticket = shd_db_query('', '
... ...
@@ -619,7 +619,7 @@ function shd_reply_restore()
619 619
 	{
620 620
 		$smcFunc['db_free_result']($query_ticket);
621 621
 		if (($row['status'] == TICKET_STATUS_DELETED || $row['status'] == TICKET_STATUS_CLOSED || $row['message_status'] != MSG_STATUS_DELETED) || (!shd_allowed_to('shd_restore_reply_any', $row['id_dept']) && (!shd_allowed_to('shd_restore_reply_own', $row['id_dept']) || $user_info['id'] != $row['id_member'])))
622
-			return fatal_lang_error('shd_cannot_restore_reply', false);
622
+			shd_fatal_lang_error('shd_cannot_restore_reply', false);
623 623
 
624 624
 		$context['ticket_id'] = (int) $row['id_ticket'];
625 625
 		$subject = $row['subject'];
... ...
@@ -630,7 +630,7 @@ function shd_reply_restore()
630 630
 	else
631 631
 	{
632 632
 		$smcFunc['db_free_result']($query_ticket);
633
-		return fatal_lang_error('shd_no_ticket', false);
633
+		shd_fatal_lang_error('shd_no_ticket', false);
634 634
 	}
635 635
 
636 636
 	// The ticket's id is in $context['ticket_id'], the reply id in $_REQUEST['reply'].
... ...
@@ -81,7 +81,7 @@ function shd_ticket_resolve()
81 81
 
82 82
 	// First, figure out the state of the ticket - is it resolved or not? Can we even see it?
83 83
 	if (empty($context['ticket_id']))
84
-		return fatal_lang_error('shd_no_ticket', false);
84
+		shd_fatal_lang_error('shd_no_ticket', false);
85 85
 
86 86
 	$context['shd_return_to'] = isset($_REQUEST['home']) ? 'home' : 'ticket';
87 87
 
... ...
@@ -97,7 +97,7 @@ function shd_ticket_resolve()
97 97
 	if ($smcFunc['db_num_rows']($query) == 0)
98 98
 	{
99 99
 		$smcFunc['db_free_result']($query);
100
-		return fatal_lang_error('shd_no_ticket', false);
100
+		shd_fatal_lang_error('shd_no_ticket', false);
101 101
 	}			
102 102
 	$row = $smcFunc['db_fetch_assoc']($query);
103 103
 	$smcFunc['db_free_result']($query);
... ...
@@ -106,7 +106,7 @@ function shd_ticket_resolve()
106 106
 	call_integration_hook('shd_hook_mark' . $action);
107 107
 
108 108
 	if (!shd_allowed_to('shd_' . $action . '_ticket_any', $row['id_dept']) && (!shd_allowed_to('shd_' . $action . '_ticket_own', $row['id_dept']) || $row['id_member_started'] != $user_info['id']))
109
-		return fatal_lang_error('shd_cannot_' . $action, false);
109
+		shd_fatal_lang_error('shd_cannot_' . $action, false);
110 110
 
111 111
 	// OK, so what about any children related tickets that are still open? Eeek, could be awkward.
112 112
 	if (empty($modSettings['shd_disable_relationships']))
... ...
@@ -127,7 +127,7 @@ function shd_ticket_resolve()
127 127
 		list($count_children) = $smcFunc['db_fetch_row']($query);
128 128
 		$smcFunc['db_free_result']($query);
129 129
 		if (!empty($count_children))
130
-			return fatal_lang_error('error_shd_cannot_resolve_children', false);
130
+			shd_fatal_lang_error('error_shd_cannot_resolve_children', false);
131 131
 	}
132 132
 
133 133
 	$new = shd_determine_status($action, $row['id_member_started'], $row['id_member_updated'], $row['num_replies'], $row['id_dept']);
... ...
@@ -172,7 +172,7 @@ function shd_privacy_change_noajax()
172 172
 
173 173
 	// First, figure out the state of the ticket - is it private or not? Can we even see it?
174 174
 	if (empty($context['ticket_id']))
175
-		return fatal_lang_error('shd_no_ticket', false);
175
+		shd_fatal_lang_error('shd_no_ticket', false);
176 176
 
177 177
 	$query = shd_db_query('', '
178 178
 		SELECT id_member_started, subject, private, status, id_dept
... ...
@@ -186,13 +186,13 @@ function shd_privacy_change_noajax()
186 186
 	if ($smcFunc['db_num_rows']($query) == 0)
187 187
 	{
188 188
 		$smcFunc['db_free_result']($query);
189
-		return fatal_lang_error('shd_no_ticket', false);
189
+		shd_fatal_lang_error('shd_no_ticket', false);
190 190
 	}			
191 191
 	$row = $smcFunc['db_fetch_assoc']($query);
192 192
 	$smcFunc['db_free_result']($query);
193 193
 
194 194
 	if (in_array($row['status'], array(TICKET_STATUS_CLOSED, TICKET_STATUS_DELETED)) || !shd_allowed_to('shd_alter_privacy_any', $row['id_dept']) && (!shd_allowed_to('shd_alter_privacy_own', $row['id_dept']) || $row['id_member_started'] != $user_info['id']))
195
-		return fatal_lang_error('shd_cannot_change_privacy', false);
195
+		shd_fatal_lang_error('shd_cannot_change_privacy', false);
196 196
 
197 197
 	$smcFunc['db_free_result']($query);
198 198
 
... ...
@@ -236,7 +236,7 @@ function shd_urgency_change_noajax()
236 236
 
237 237
 	// First, figure out the state of the ticket - is it private or not? Can we even see it? Current urgency?
238 238
 	if (empty($context['ticket_id']))
239
-		return fatal_lang_error('shd_no_ticket', false);
239
+		shd_fatal_lang_error('shd_no_ticket', false);
240 240
 
241 241
 	$query = shd_db_query('', '
242 242
 		SELECT id_member_started, subject, urgency, status, id_dept
... ...
@@ -250,7 +250,7 @@ function shd_urgency_change_noajax()
250 250
 	if ($smcFunc['db_num_rows']($query) == 0)
251 251
 	{
252 252
 		$smcFunc['db_free_result']($query);
253
-		return fatal_lang_error('shd_no_ticket', false);
253
+		shd_fatal_lang_error('shd_no_ticket', false);
254 254
 	}			
255 255
 	$row = $smcFunc['db_fetch_assoc']($query);
256 256
 	$smcFunc['db_free_result']($query);
... ...
@@ -258,7 +258,7 @@ function shd_urgency_change_noajax()
258 258
 	$can_urgency = shd_can_alter_urgency($row['urgency'], $row['id_member_started'], ($row['status'] == TICKET_STATUS_CLOSED), ($row['status'] == TICKET_STATUS_DELETED), $row['id_dept']);
259 259
 
260 260
 	if (empty($_GET['change']) || empty($can_urgency[$_GET['change']]))
261
-		return fatal_lang_error('shd_cannot_change_urgency');
261
+		shd_fatal_lang_error('shd_cannot_change_urgency');
262 262
 
263 263
 	$new_urgency = $row['urgency'] + ($_GET['change'] == 'increase' ? 1 : -1);
264 264
 	$action = 'urgency_' . $_GET['change'];
... ...
@@ -298,14 +298,14 @@ function shd_ticket_relation()
298 298
 	checkSession('request');
299 299
 
300 300
 	if (!empty($modSettings['shd_disable_relationships']))
301
-		return fatal_lang_error('shd_relationships_are_disabled', false);
301
+		shd_fatal_lang_error('shd_relationships_are_disabled', false);
302 302
 
303 303
 	$otherticket = isset($_REQUEST['otherticket']) ? (int) $_REQUEST['otherticket'] : 0;
304 304
 
305 305
 	if (empty($context['ticket_id']) || empty($otherticket))
306
-		return fatal_lang_error('shd_no_ticket', false);
306
+		shd_fatal_lang_error('shd_no_ticket', false);
307 307
 	elseif ($context['ticket_id'] == $otherticket)
308
-		return fatal_lang_error('shd_cannot_relate_self', false);
308
+		shd_fatal_lang_error('shd_cannot_relate_self', false);
309 309
 
310 310
 	$actions = array(
311 311
 		'linked',
... ...
@@ -317,7 +317,7 @@ function shd_ticket_relation()
317 317
 
318 318
 	$rel_action = isset($_REQUEST['relation']) && in_array($_REQUEST['relation'], $actions) ? $_REQUEST['relation'] : '';
319 319
 	if (empty($rel_action))
320
-		return fatal_lang_error('shd_invalid_relation', false);
320
+		shd_fatal_lang_error('shd_invalid_relation', false);
321 321
 
322 322
 	// Quick/consistent way to ensure permissions are adhered to and that the ticket exists. Might as well get the subject while here too.
323 323
 	$ticketinfo = shd_load_ticket($context['ticket_id']);
... ...
@@ -345,7 +345,7 @@ function shd_ticket_relation()
345 345
 	$smcFunc['db_free_result']($query);
346 346
 
347 347
 	if ($rel_action == 'delete' && $new_relationship)
348
-		return fatal_lang_error('shd_no_relation_delete', false);
348
+		shd_fatal_lang_error('shd_no_relation_delete', false);
349 349
 
350 350
 	$log_prefix = 'rel_' . ($new_relationship || $rel_action == 'delete' ? '' : 're_');
351 351
 	$log_map = array(
... ...
@@ -41,9 +41,9 @@ function shd_movedept()
41 41
 	checkSession('get');
42 42
 
43 43
 	if (empty($context['ticket_id']))
44
-		return fatal_lang_error('shd_no_ticket', false);
44
+		shd_fatal_lang_error('shd_no_ticket', false);
45 45
 	elseif (empty($context['shd_multi_dept']))
46
-		return fatal_lang_error('shd_cannot_move_dept', false);
46
+		shd_fatal_lang_error('shd_cannot_move_dept', false);
47 47
 
48 48
 	$context['shd_return_to'] = isset($_REQUEST['home']) ? 'home' : 'ticket';
49 49
 	$context['can_pm'] = empty($modSettings['shd_helpdesk_only']) || empty($modSettings['shd_disable_pm']);
... ...
@@ -64,12 +64,12 @@ function shd_movedept()
64 64
 	else
65 65
 	{
66 66
 		$smcFunc['db_free_result']($query);
67
-		return fatal_lang_error('shd_no_ticket');
67
+		shd_fatal_lang_error('shd_no_ticket');
68 68
 	}
69 69
 	$smcFunc['db_free_result']($query);
70 70
 
71 71
 	if (!shd_allowed_to('shd_move_dept_any', $context['current_dept']) && !(shd_allowed_to('shd_move_dept_own', $context['current_dept']) && $ticket_starter == $user_info['id']))
72
-		return fatal_lang_error('shd_no_perm_move_dept', false);
72
+		shd_fatal_lang_error('shd_no_perm_move_dept', false);
73 73
 		
74 74
 	$visible_depts = shd_allowed_to('access_helpdesk', false);
75 75
 	$context['dept_list'] = array();
... ...
@@ -190,21 +190,21 @@ function shd_movedept2()
190 190
 	checkSubmitOnce('check');
191 191
 
192 192
 	if (empty($context['ticket_id']))
193
-		return fatal_lang_error('shd_no_ticket', false);
193
+		shd_fatal_lang_error('shd_no_ticket', false);
194 194
 
195 195
 	if ((isset($_POST['send_pm']) && (!isset($_POST['pm_content']) || trim($_POST['pm_content']) == '')) && (empty($modSettings['shd_helpdesk_only']) || empty($modSettings['shd_disable_pm'])))
196
-		return fatal_lang_error('shd_move_no_pm', false);
196
+		shd_fatal_lang_error('shd_move_no_pm', false);
197 197
 
198 198
 	// Just in case, are they cancelling?
199 199
 	if (isset($_REQUEST['cancel']))
200 200
 		redirectexit('action=helpdesk;sa=ticket;ticket=' . $context['ticket_id']);
201 201
 
202 202
 	if (empty($context['shd_multi_dept']))
203
-		return fatal_lang_error('shd_cannot_move_dept', false);
203
+		shd_fatal_lang_error('shd_cannot_move_dept', false);
204 204
 
205 205
 	$dest = isset($_REQUEST['to_dept']) ? (int) $_REQUEST['to_dept'] : 0;
206 206
 	if (empty($dest) || !shd_allowed_to('access_helpdesk', $dest))
207
-		return fatal_lang_error('shd_cannot_move_dept', false);
207
+		shd_fatal_lang_error('shd_cannot_move_dept', false);
208 208
 
209 209
 	$context['shd_return_to'] = isset($_REQUEST['home']) ? 'home' : 'ticket';
210 210
 
... ...
@@ -224,15 +224,15 @@ function shd_movedept2()
224 224
 	else
225 225
 	{
226 226
 		$smcFunc['db_free_result']($query);
227
-		return fatal_lang_error('shd_no_ticket');
227
+		shd_fatal_lang_error('shd_no_ticket');
228 228
 	}
229 229
 
230 230
 	$smcFunc['db_free_result']($query);
231 231
 
232 232
 	if ($context['current_dept'] == $dest)
233
-		return fatal_lang_error('shd_cannot_move_dept', false);
233
+		shd_fatal_lang_error('shd_cannot_move_dept', false);
234 234
 	elseif (!shd_allowed_to('shd_move_dept_any', $context['current_dept']) && !(shd_allowed_to('shd_move_dept_own', $context['current_dept']) && $ticket_starter == $user_info['id']))
235
-		return fatal_lang_error('shd_no_perm_move_dept', false);
235
+		shd_fatal_lang_error('shd_no_perm_move_dept', false);
236 236
 
237 237
 	// Find the new department. We've already established the user can see it, but we need its name.
238 238
 	$query = $smcFunc['db_query']('', '
... ...
@@ -495,7 +495,7 @@ function shd_notify_popup()
495 495
 	$email_type = isset($_GET['template']) ? preg_replace('~[^a-z_]~', '', $_GET['template']) : '';
496 496
 
497 497
 	if (empty($modSettings['shd_display_ticket_logs']) || empty($_GET['log']) || empty($email_type))
498
-		return fatal_lang_error('no_access', false);
498
+		shd_fatal_lang_error('no_access', false);
499 499
 
500 500
 	$query = $smcFunc['db_query']('', '
501 501
 		SELECT hdla.id_member, hdla.id_ticket, hdla.id_msg, hdla.extra, COALESCE(hdtr.body, {string:empty}) AS body, COALESCE(mem.real_name, hdtr.poster_name) AS poster_name
... ...
@@ -513,7 +513,7 @@ function shd_notify_popup()
513 513
 	if ($smcFunc['db_num_rows']($query) == 0)
514 514
 	{
515 515
 		$smcFunc['db_free_result']($query);
516
-		return fatal_lang_error('no_access');
516
+		shd_fatal_lang_error('no_access');
517 517
 	}
518 518
 	$row = $smcFunc['db_fetch_assoc']($query);
519 519
 	$smcFunc['db_free_result']($query);
... ...
@@ -522,13 +522,13 @@ function shd_notify_popup()
522 522
 
523 523
 	// Just check we did actually log an email of that type.
524 524
 	if (empty($row['extra']['emails'][$_GET['template']]))
525
-		return fatal_lang_error('no_access', false);
525
+		shd_fatal_lang_error('no_access', false);
526 526
 
527 527
 	$ticketinfo = shd_load_ticket($row['id_ticket']);
528 528
 
529 529
 	// OK, if we're here, we can see the ticket. Can we actually see the email log at this point?
530 530
 	if (!shd_allowed_to('shd_view_ticket_logs_any', $ticketinfo['dept']) && (!shd_allowed_to('shd_view_ticket_logs_own', $ticketinfo['dept']) || !$ticketinfo['is_own']))
531
-		return fatal_lang_error('no_access', false);
531
+		shd_fatal_lang_error('no_access', false);
532 532
 
533 533
 	// We're reusing the Help template, need its language file.
534 534
 	loadLanguage('Help');
... ...
@@ -649,7 +649,7 @@ function shd_notify_ticket_options()
649 649
 	{
650 650
 		case 'monitor_on';
651 651
 			if (!shd_allowed_to('shd_monitor_ticket_any', $ticketinfo['dept']) && (!$ticket_starter || !shd_allowed_to('shd_monitor_ticket_own', $ticketinfo['dept'])))
652
-				return fatal_lang_error('cannot_monitor_ticket', false);
652
+				shd_fatal_lang_error('cannot_monitor_ticket', false);
653 653
 
654 654
 			// Unlike turning it off, we might be turning it on from either just off, or ignored, so log that fact.
655 655
 			if ($old_state == NOTIFY_ALWAYS)
... ...
@@ -682,7 +682,7 @@ function shd_notify_ticket_options()
682 682
 			break;
683 683
 		case 'monitor_off';
684 684
 			if (!shd_allowed_to('shd_monitor_ticket_any', $ticketinfo['dept']) && (!$ticket_starter || !shd_allowed_to('shd_monitor_ticket_own', $ticketinfo['dept'])))
685
-				return fatal_lang_error('cannot_unmonitor_ticket', false);
685
+				shd_fatal_lang_error('cannot_unmonitor_ticket', false);
686 686
 			// Just delete the old status.
687 687
 			$smcFunc['db_query']('', '
688 688
 				DELETE FROM {db_prefix}helpdesk_notify_override
... ...
@@ -702,7 +702,7 @@ function shd_notify_ticket_options()
702 702
 			break;
703 703
 		case 'ignore_on';
704 704
 			if (!shd_allowed_to('shd_ignore_ticket_any', $ticketinfo['dept']) && (!$ticket_starter || !shd_allowed_to('shd_ignore_ticket_own', $ticketinfo['dept'])))
705
-				return fatal_lang_error('cannot_monitor_ticket', false);
705
+				shd_fatal_lang_error('cannot_monitor_ticket', false);
706 706
 
707 707
 			// Unlike turning it off, we might be turning it on from either just off, or ignored, so log that fact.
708 708
 			if ($old_state == NOTIFY_NEVER)
... ...
@@ -735,7 +735,7 @@ function shd_notify_ticket_options()
735 735
 			break;
736 736
 		case 'ignore_off';
737 737
 			if (!shd_allowed_to('shd_ignore_ticket_any', $ticketinfo['dept']) && (!$ticket_starter || !shd_allowed_to('shd_ignore_ticket_own', $ticketinfo['dept'])))
738
-				return fatal_lang_error('cannot_unmonitor_ticket', false);
738
+				shd_fatal_lang_error('cannot_unmonitor_ticket', false);
739 739
 
740 740
 			$smcFunc['db_query']('', '
741 741
 				DELETE FROM {db_prefix}helpdesk_notify_override
... ...
@@ -43,58 +43,92 @@ function shd_post_ticket()
43 43
 	if ($new_ticket)
44 44
 	{
45 45
 		// Need to have a department to post in. If not, goodbye.
46
-		$_REQUEST['dept'] = isset($_REQUEST['dept']) ? (int) $_REQUEST['dept'] : 0;
46
+		$dept = isset($_REQUEST['dept']) ? (int) $_REQUEST['dept'] : 0;
47
+
48
+		shd_is_allowed_to('shd_new_ticket', $dept); // If we don't have a department, we will verify the ability in any department, and figure it out later.
49
+
50
+		$context['ticket_form'] = array( // yes, everything goes in here.
51
+			'dept' => $dept,
52
+			'selecting_dept' => $context['shd_multi_dept'] && empty($dept),
53
+			'form_title' => $txt['shd_create_ticket'],
54
+			'form_action' => $scripturl . '?action=helpdesk;sa=saveticket',
55
+			'first_msg' => 0,
56
+			'message' =>  '',
57
+			'subject' => '',
58
+			'ticket' => 0 ,
59
+			'link' => '',
60
+			'msg' => 0,
61
+			'display_id' => '',
62
+			'status' => TICKET_STATUS_NEW,
63
+			'urgency' => array(
64
+				'setting' => TICKET_URGENCY_LOW,
65
+			),
66
+			'private' => array(
67
+				'setting' => false,
68
+				'can_change' => shd_allowed_to('shd_alter_privacy_any', $dept) || (shd_allowed_to('shd_alter_privacy_own', $dept)),
69
+				'options' => array(
70
+					0 => 'shd_ticket_notprivate',
71
+					1 => 'shd_ticket_private',
72
+				),
73
+			),
74
+			'errors' => array(),
75
+			'num_replies' => 0,
76
+			'do_attach' => shd_allowed_to('shd_post_attachment', $dept),
77
+			'num_allowed_attachments' => empty($modSettings['attachmentNumPerPostLimit']) || $modSettings['shd_attachments_mode'] == 'ticket' ? -1 : $modSettings['attachmentNumPerPostLimit'],
78
+			'return_to_ticket' => isset($_REQUEST['goback']),
79
+			'disable_smileys' => !empty($_REQUEST['no_smileys']),
80
+		);
47 81
 
48
-		shd_is_allowed_to('shd_new_ticket', $_REQUEST['dept']); // If we don't have a department, we will verify the ability in any department, and figure it out later.
49 82
 	}
50 83
 	else
51 84
 	{
52 85
 		checkSession('get');
53 86
 		$ticketinfo = shd_load_ticket();
87
+		$dept = $ticketinfo['dept'];
54 88
 		if (!shd_allowed_to('shd_edit_ticket_any', $ticketinfo['dept']) && (!shd_allowed_to('shd_edit_ticket_own', $ticketinfo['dept']) || !$ticketinfo['is_own']))
55
-			return fatal_lang_error('cannot_shd_edit_ticket');
56
-	}
57
-
58
-	// Things we need
59
-	loadTemplate('sd_template/SimpleDesk-Post');
60
-	require_once($sourcedir . '/sd_source/Subs-SimpleDeskPost.php');
61
-	require_once($sourcedir . '/Subs-Post.php');
62
-	require_once($sourcedir . '/Subs-Editor.php');
63
-
64
-	$context['template_layers'][] = 'shd_post_nojs';
65
-	$dept = $new_ticket ? $_REQUEST['dept'] : $ticketinfo['dept'];
89
+			shd_fatal_lang_error('cannot_shd_edit_ticket');
66 90
 
67 91
 		$context['ticket_form'] = array( // yes, everything goes in here.
68 92
 			'dept' => $dept,
69 93
 			'selecting_dept' => $context['shd_multi_dept'] && empty($dept),
70
-		'form_title' => $new_ticket ? $txt['shd_create_ticket'] : $txt['shd_edit_ticket'],
94
+			'form_title' => $txt['shd_edit_ticket'],
71 95
 			'form_action' => $scripturl . '?action=helpdesk;sa=saveticket',
72
-		'first_msg' => $new_ticket ? 0 : $ticketinfo['id_first_msg'],
73
-		'message' => $new_ticket ? '' : $ticketinfo['body'],
74
-		'subject' => $new_ticket ? '' : $ticketinfo['subject'],
75
-		'ticket' => $new_ticket ? 0 : $context['ticket_id'],
76
-		'link' => $new_ticket ? '' : '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>',
77
-		'msg' => $new_ticket ? 0 : $ticketinfo['id_first_msg'],
78
-		'display_id' => $new_ticket ? '' : str_pad($context['ticket_id'], $modSettings['shd_zerofill'], '0', STR_PAD_LEFT),
79
-		'status' => $new_ticket ? TICKET_STATUS_NEW : $ticketinfo['status'],
96
+			'first_msg' => $ticketinfo['id_first_msg'],
97
+			'message' => $ticketinfo['body'],
98
+			'subject' => $ticketinfo['subject'],
99
+			'ticket' => $context['ticket_id'],
100
+			'link' => '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>',
101
+			'msg' => $ticketinfo['id_first_msg'],
102
+			'display_id' => str_pad($context['ticket_id'], $modSettings['shd_zerofill'], '0', STR_PAD_LEFT),
103
+			'status' => $ticketinfo['status'],
80 104
 			'urgency' => array(
81
-			'setting' => $new_ticket ? TICKET_URGENCY_LOW : $ticketinfo['urgency'],
105
+				'setting' => $ticketinfo['urgency'],
82 106
 			),
83 107
 			'private' => array(
84
-			'setting' => $new_ticket ? false : ($ticketinfo['private'] == 1),
85
-			'can_change' => shd_allowed_to('shd_alter_privacy_any', $dept) || (shd_allowed_to('shd_alter_privacy_own', $dept) && ($new_ticket || !empty($ticketinfo['is_own']))),
108
+				'setting' => $ticketinfo['private'] == 1,
109
+				'can_change' => shd_allowed_to('shd_alter_privacy_any', $dept) || (shd_allowed_to('shd_alter_privacy_own', $dept) && !empty($ticketinfo['is_own'])),
86 110
 				'options' => array(
87 111
 					0 => 'shd_ticket_notprivate',
88 112
 					1 => 'shd_ticket_private',
89 113
 				),
90 114
 			),
91 115
 			'errors' => array(),
92
-		'num_replies' => $new_ticket ? 0 : $ticketinfo['num_replies'],
116
+			'num_replies' => $ticketinfo['num_replies'],
93 117
 			'do_attach' => shd_allowed_to('shd_post_attachment', $dept),
94 118
 			'num_allowed_attachments' => empty($modSettings['attachmentNumPerPostLimit']) || $modSettings['shd_attachments_mode'] == 'ticket' ? -1 : $modSettings['attachmentNumPerPostLimit'],
95 119
 			'return_to_ticket' => isset($_REQUEST['goback']),
96
-		'disable_smileys' => $new_ticket ? !empty($_REQUEST['no_smileys']) : ($ticketinfo['smileys_enabled'] == 0),
120
+			'disable_smileys' => $ticketinfo['smileys_enabled'] == 0,
97 121
 		);
122
+	}
123
+
124
+	// Things we need
125
+	loadTemplate('sd_template/SimpleDesk-Post');
126
+	require_once($sourcedir . '/sd_source/Subs-SimpleDeskPost.php');
127
+	require_once($sourcedir . '/Subs-Post.php');
128
+	require_once($sourcedir . '/Subs-Editor.php');
129
+
130
+	$context['template_layers'][] = 'shd_post_nojs';
131
+
98 132
 	$context['can_solve'] = !$new_ticket && (shd_allowed_to('shd_resolve_ticket_any', $dept) || (shd_allowed_to('shd_resolve_ticket_own', $dept) && $ticketinfo['starter_id'] == $user_info['id']));
99 133
 	$context['can_post_proxy'] = $new_ticket && isset($_REQUEST['proxy']) && shd_allowed_to('shd_post_proxy', $dept);
100 134
 	if ($context['can_post_proxy'] && !empty($_REQUEST['proxy']))
... ...
@@ -116,9 +150,9 @@ function shd_post_ticket()
116 150
 
117 151
 	// A few basic checks
118 152
 	if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED)
119
-		return fatal_lang_error('shd_cannot_edit_closed', false);
153
+		shd_fatal_lang_error('shd_cannot_edit_closed', false);
120 154
 	elseif ($context['ticket_form']['status'] == TICKET_STATUS_DELETED)
121
-		return fatal_lang_error('shd_cannon_edit_deleted', false);
155
+		shd_fatal_lang_error('shd_cannon_edit_deleted', false);
122 156
 
123 157
 	shd_load_custom_fields(true, $context['ticket_form']['ticket'], $context['ticket_form']['dept']);
124 158
 
... ...
@@ -246,7 +280,7 @@ function shd_save_post()
246 280
 	{
247 281
 		// Pfft.
248 282
 		if (isset($_POST['shd_message']) && strtolower($_POST['shd_message']) == 'this is simpledesk!')
249
-			fatal_error('You are not King Leonidas...', false);
283
+			shd_fatal_error('You are not King Leonidas...', false);
250 284
 		$_POST['shd_message'] = $smcFunc['htmlspecialchars']($_POST['shd_message'], ENT_QUOTES);
251 285
 		preparsecode($_POST['shd_message']);
252 286
 
... ...
@@ -329,7 +363,7 @@ function shd_save_ticket()
329 363
 
330 364
 		// S'pose we'd better check the permissions here
331 365
 		if (!shd_allowed_to('shd_edit_ticket_any', $dept) && (!shd_allowed_to('shd_edit_ticket_own', $dept) || !$ticketinfo['is_own']))
332
-			return fatal_lang_error('cannot_shd_edit_ticket', false);
366
+			shd_fatal_lang_error('cannot_shd_edit_ticket', false);
333 367
 
334 368
 		$msg = $ticketinfo['id_first_msg'];
335 369
 		$is_own = $ticketinfo['is_own'];
... ...
@@ -346,13 +380,13 @@ function shd_save_ticket()
346 380
 
347 381
 	$context['ticket_form'] = array(
348 382
 		'dept' => isset($newdept) ? $newdept : $dept,
349
-		'form_title' => $new_ticket ? $txt['shd_create_ticket'] : $txt['shd_edit_ticket'],
383
+		'form_title' => !$new_ticket ? $txt['shd_edit_ticket'] : $txt['shd_create_ticket'],
350 384
 		'form_action' => $scripturl . '?action=helpdesk;sa=saveticket',
351
-		'first_msg' => $new_ticket ? 0 : $ticketinfo['id_first_msg'],
385
+		'first_msg' => !$new_ticket ? $ticketinfo['id_first_msg'] : 0,
352 386
 		'message' => $_POST['shd_message'],
353 387
 		'subject' => $_POST['subject'],
354 388
 		'ticket' => $context['ticket_id'],
355
-		'link' => $new_ticket ? '' : '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>',
389
+		'link' => !$new_ticket ? '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>' : '',
356 390
 		'msg' => $msg,
357 391
 		'display_id' => empty($context['ticket_id']) ? '' : str_pad($context['ticket_id'], $modSettings['shd_zerofill'], '0', STR_PAD_LEFT),
358 392
 		'status' => $new_status,
... ...
@@ -485,9 +519,9 @@ function shd_save_ticket()
485 519
 
486 520
 	// A few basic checks
487 521
 	if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED)
488
-		return fatal_lang_error('shd_cannot_edit_closed', false);
522
+		shd_fatal_lang_error('shd_cannot_edit_closed', false);
489 523
 	elseif ($context['ticket_form']['status'] == TICKET_STATUS_DELETED)
490
-		return fatal_lang_error('shd_cannon_edit_deleted', false);
524
+		shd_fatal_lang_error('shd_cannon_edit_deleted', false);
491 525
 
492 526
 	// OK, does the user want to close this ticket? Are there any problems with that?
493 527
 	if (!empty($context['can_solve']) && !empty($_POST['resolve_ticket']))
... ...
@@ -698,10 +732,10 @@ function shd_post_reply()
698 732
 			if (shd_allowed_to('shd_reply_ticket_own', $ticketinfo['dept']))
699 733
 			{
700 734
 				if (!$ticketinfo['is_own'])
701
-					return fatal_lang_error('shd_cannot_reply_any_but_own', false);
735
+					shd_fatal_lang_error('shd_cannot_reply_any_but_own', false);
702 736
 			}
703 737
 			else
704
-				return fatal_lang_error('shd_cannot_reply_any', false); // can't do nuthin'
738
+				shd_fatal_lang_error('shd_cannot_reply_any', false); // can't do nuthin'
705 739
 		}
706 740
 	}
707 741
 	else
... ...
@@ -721,7 +755,7 @@ function shd_post_reply()
721 755
 		if ($smcFunc['db_num_rows']($query) == 0)
722 756
 		{
723 757
 			$smcFunc['db_free_result']($query);
724
-			return fatal_lang_error('shd_no_ticket', false);
758
+			shd_fatal_lang_error('shd_no_ticket', false);
725 759
 		}
726 760
 
727 761
 		$reply = $smcFunc['db_fetch_assoc']($query);
... ...
@@ -731,10 +765,10 @@ function shd_post_reply()
731 765
 			if (shd_allowed_to('shd_edit_reply_own', $ticketinfo['dept']))
732 766
 			{
733 767
 				if ($reply['id_member'] != $user_info['id'])
734
-					return fatal_lang_error('shd_cannot_edit_reply_any_but_own', false);
768
+					shd_fatal_lang_error('shd_cannot_edit_reply_any_but_own', false);
735 769
 			}
736 770
 			else
737
-				return fatal_lang_error('shd_cannot_edit_reply_any', false);
771
+				shd_fatal_lang_error('shd_cannot_edit_reply_any', false);
738 772
 		}
739 773
 
740 774
 		// Fix the body up for later
... ...
@@ -820,9 +854,9 @@ function shd_post_reply()
820 854
 
821 855
 	// A few basic checks
822 856
 	if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED)
823
-		return fatal_lang_error('shd_cannot_reply_closed', false);
857
+		shd_fatal_lang_error('shd_cannot_reply_closed', false);
824 858
 	elseif ($context['ticket_form']['status'] == TICKET_STATUS_DELETED)
825
-		return fatal_lang_error('shd_cannon_reply_deleted', false);
859
+		shd_fatal_lang_error('shd_cannon_reply_deleted', false);
826 860
 
827 861
 	shd_load_custom_fields(false, $context['ticket_form']['msg'], $context['ticket_form']['dept']);
828 862
 	shd_load_attachments();
... ...
@@ -936,10 +970,10 @@ function shd_save_reply()
936 970
 			if (shd_allowed_to('shd_reply_ticket_own', $ticketinfo['dept']))
937 971
 			{
938 972
 				if (!$ticketinfo['is_own'])
939
-					return fatal_lang_error('shd_cannot_reply_any_but_own', false);
973
+					shd_fatal_lang_error('shd_cannot_reply_any_but_own', false);
940 974
 			}
941 975
 			else
942
-				return fatal_lang_error('shd_cannot_reply_any', false); // can't do nuthin'
976
+				shd_fatal_lang_error('shd_cannot_reply_any', false); // can't do nuthin'
943 977
 		}
944 978
 	}
945 979
 	else
... ...
@@ -958,7 +992,7 @@ function shd_save_reply()
958 992
 		if ($smcFunc['db_num_rows']($query) == 0)
959 993
 		{
960 994
 			$smcFunc['db_free_result']($query);
961
-			return fatal_lang_error('shd_no_ticket', false);
995
+			shd_fatal_lang_error('shd_no_ticket', false);
962 996
 		}
963 997
 
964 998
 		$reply = $smcFunc['db_fetch_assoc']($query);
... ...
@@ -968,10 +1002,10 @@ function shd_save_reply()
968 1002
 			if (shd_allowed_to('shd_edit_reply_own', $ticketinfo['dept']))
969 1003
 			{
970 1004
 				if ($reply['id_member'] != $user_info['id'])
971
-					return fatal_lang_error('shd_cannot_edit_reply_any_but_own', false);
1005
+					shd_fatal_lang_error('shd_cannot_edit_reply_any_but_own', false);
972 1006
 			}
973 1007
 			else
974
-				return fatal_lang_error('shd_cannot_edit_reply_any', false);
1008
+				shd_fatal_lang_error('shd_cannot_edit_reply_any', false);
975 1009
 		}
976 1010
 	}
977 1011
 
... ...
@@ -1057,9 +1091,9 @@ function shd_save_reply()
1057 1091
 
1058 1092
 	// A few basic checks
1059 1093
 	if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED)
1060
-		return fatal_lang_error('shd_cannot_edit_closed', false);
1094
+		shd_fatal_lang_error('shd_cannot_edit_closed', false);
1061 1095
 	elseif ($context['ticket_form']['status'] == TICKET_STATUS_DELETED)
1062
-		return fatal_lang_error('shd_cannon_edit_deleted', false);
1096
+		shd_fatal_lang_error('shd_cannon_edit_deleted', false);
1063 1097
 
1064 1098
 	// Have there been any new replies that we missed?
1065 1099
 	if (empty($options['no_new_reply_warning']) && isset($_REQUEST['num_replies']))
... ...
@@ -1507,7 +1541,7 @@ function shd_prepare_reply_context()
1507 1541
 		$memberContext[$message['id_member']]['group'] = $txt['guest_title'];
1508 1542
 		$memberContext[$message['id_member']]['link'] = $message['poster_name'];
1509 1543
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1510
-		$memberContext[$message['id_member']]['show_email'] = showEmailAddress(true, 0);
1544
+		$memberContext[$message['id_member']]['show_email'] = false;
1511 1545
 		$memberContext[$message['id_member']]['is_guest'] = true;
1512 1546
 		$memberContext[$message['id_member']]['group_icons'] = '';
1513 1547
 	}
... ...
@@ -1689,27 +1723,27 @@ function shd_check_attachments()
1689 1723
 				if (!is_uploaded_file($uplfile['tmp_name']) || (@ini_get('open_basedir') == '' && !file_exists($uplfile['tmp_name'])))
1690 1724
 				{
1691 1725
 					checkSubmitOnce('free');
1692
-					return fatal_lang_error('attach_timeout', 'critical');
1726
+					shd_fatal_lang_error('attach_timeout', 'critical');
1693 1727
 				}
1694 1728
 
1695 1729
 				if (!empty($modSettings['attachmentSizeLimit']) && $uplfile['size'] > $modSettings['attachmentSizeLimit'] * 1024)
1696 1730
 				{
1697 1731
 					checkSubmitOnce('free');
1698
-					return fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
1732
+					shd_fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
1699 1733
 				}
1700 1734
 
1701 1735
 				$quantity++;
1702 1736
 				if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit'] && $modSettings['shd_attachments_mode'] != 'ticket')
1703 1737
 				{
1704 1738
 					checkSubmitOnce('free');
1705
-					return fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
1739
+					shd_fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
1706 1740
 				}
1707 1741
 
1708 1742
 				$total_size += $uplfile['size'];
1709 1743
 				if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024)
1710 1744
 				{
1711 1745
 					checkSubmitOnce('free');
1712
-					return fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
1746
+					shd_fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
1713 1747
 				}
1714 1748
 
1715 1749
 				if (!empty($modSettings['attachmentCheckExtensions']))
... ...
@@ -1727,7 +1761,7 @@ function shd_check_attachments()
1727 1761
 					$dirSize = 0;
1728 1762
 
1729 1763
 					if (!is_dir($current_attach_dir))
1730
-						return fatal_lang_error('cant_access_upload_path', 'critical');
1764
+						shd_fatal_lang_error('cant_access_upload_path', 'critical');
1731 1765
 
1732 1766
 					$dir = opendir($current_attach_dir);
1733 1767
 					if (!is_resource($dir))
... ...
@@ -1753,11 +1787,11 @@ function shd_check_attachments()
1753 1787
 
1754 1788
 					// Too big!  Maybe you could zip it or something...
1755 1789
 					if ($uplfile['size'] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024)
1756
-						return fatal_lang_error('ran_out_of_space');
1790
+						shd_fatal_lang_error('ran_out_of_space');
1757 1791
 				}
1758 1792
 
1759 1793
 				if (!is_writable($current_attach_dir))
1760
-					return fatal_lang_error('attachments_no_write', 'critical');
1794
+					shd_fatal_lang_error('attachments_no_write', 'critical');
1761 1795
 
1762 1796
 				$attachID = 'post_tmp_' . $user_info['id'] . '_' . $temp_start++;
1763 1797
 				$_SESSION['temp_attachments'][$attachID] = basename($uplfile['name']);
... ...
@@ -1770,7 +1804,7 @@ function shd_check_attachments()
1770 1804
 				$destName = $current_attach_dir . '/' . $attachID;
1771 1805
 
1772 1806
 				if (!move_uploaded_file($uplfile['tmp_name'], $destName))
1773
-					return fatal_lang_error('attach_timeout', 'critical');
1807
+					shd_fatal_lang_error('attach_timeout', 'critical');
1774 1808
 
1775 1809
 				if (file_exists($destName) && is_writable($destName))
1776 1810
 					chmod($destName, 0644);
... ...
@@ -1940,7 +1974,7 @@ function shd_handle_attachments()
1940 1974
 			if ($quantity > $file_limit)
1941 1975
 			{
1942 1976
 				checkSubmitOnce('free');
1943
-				return fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
1977
+				shd_fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
1944 1978
 			}
1945 1979
 
1946 1980
 			// Check the total upload size for this post...
... ...
@@ -1950,7 +1984,7 @@ function shd_handle_attachments()
1950 1984
 			if ($total_size > $size_limit)
1951 1985
 			{
1952 1986
 				checkSubmitOnce('free');
1953
-				return fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
1987
+				shd_fatal_lang_error('file_too_big', false, array($modSettings['attachmentPostLimit']));
1954 1988
 			}
1955 1989
 
1956 1990
 			$attachmentOptions = array(
... ...
@@ -1975,12 +2009,12 @@ function shd_handle_attachments()
1975 2009
 				if (in_array('could_not_upload', $attachmentOptions['errors']))
1976 2010
 				{
1977 2011
 					checkSubmitOnce('free');
1978
-					return fatal_lang_error('attach_timeout', 'critical');
2012
+					shd_fatal_lang_error('attach_timeout', 'critical');
1979 2013
 				}
1980 2014
 				if (in_array('too_large', $attachmentOptions['errors']))
1981 2015
 				{
1982 2016
 					checkSubmitOnce('free');
1983
-					return fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
2017
+					shd_fatal_lang_error('file_too_big', false, array($modSettings['attachmentSizeLimit']));
1984 2018
 				}
1985 2019
 				if (in_array('bad_extension', $attachmentOptions['errors']))
1986 2020
 				{
... ...
@@ -1990,7 +2024,7 @@ function shd_handle_attachments()
1990 2024
 				if (in_array('directory_full', $attachmentOptions['errors']))
1991 2025
 				{
1992 2026
 					checkSubmitOnce('free');
1993
-					return fatal_lang_error('ran_out_of_space', 'critical');
2027
+					shd_fatal_lang_error('ran_out_of_space', 'critical');
1994 2028
 				}
1995 2029
 				if (in_array('bad_filename', $attachmentOptions['errors']))
1996 2030
 				{
... ...
@@ -2000,7 +2034,7 @@ function shd_handle_attachments()
2000 2034
 				if (in_array('taken_filename', $attachmentOptions['errors']))
2001 2035
 				{
2002 2036
 					checkSubmitOnce('free');
2003
-					return fatal_lang_error('filename_exists');
2037
+					shd_fatal_lang_error('filename_exists');
2004 2038
 				}
2005 2039
 			}
2006 2040
 		}
... ...
@@ -131,7 +131,7 @@ function shd_profile_frontpage($memID)
131 131
 
132 132
 	// Attempt to load the member's profile data.
133 133
 	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
134
-		return fatal_lang_error('not_a_user', false);
134
+		shd_fatal_lang_error('not_a_user', false);
135 135
 
136 136
 	$context['page_title'] = $txt['shd_profile_area'] . ' - ' . $txt['shd_profile_main'];
137 137
 	$context['sub_template'] = 'shd_profile_main';
... ...
@@ -589,7 +589,7 @@ function shd_profile_permissions($memID)
589 589
 	// 2. Do we have a department?
590 590
 	$_REQUEST['permdept'] = isset($_REQUEST['permdept']) ? (int) $_REQUEST['permdept'] : 0;
591 591
 	$depts = shd_allowed_to('access_helpdesk', false);
592
-	if (!in_array($_REQUEST['permdept'], $depts))
592
+	if (!is_array($depts) || !in_array($_REQUEST['permdept'], $depts))
593 593
 		$_REQUEST['permdept'] = 0; // this way we know that 0 = show list only, non-0 means to show a listing.
594 594
 
595 595
 	// 2b. We still need to get the list of departments.
... ...
@@ -39,7 +39,7 @@ function shd_search()
39 39
 	loadJavascriptFile('suggest.js', array('defer' => false, 'minimize' => false), 'suggest');
40 40
 
41 41
 	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
42
-		return fatal_lang_error('loadavg_search_disabled', false);
42
+		shd_fatal_lang_error('loadavg_search_disabled', false);
43 43
 
44 44
 	loadTemplate('sd_template/SimpleDesk-Search');
45 45
 
... ...
@@ -78,7 +78,7 @@ function shd_search2()
78 78
 	shd_is_allowed_to('shd_search', 0);
79 79
 
80 80
 	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
81
-		return fatal_lang_error('loadavg_search_disabled', false);
81
+		shd_fatal_lang_error('loadavg_search_disabled', false);
82 82
 
83 83
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
84 84
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
... ...
@@ -281,7 +281,7 @@ function shd_search2()
281 281
 	$context['search_params']['start'] = ($context['pagenum'] - 1) * $number_per_page;
282 282
 	$context['search_params']['limit'] = $number_per_page;
283 283
 
284
-	if (empty($context['search_terms']))
284
+	if (empty($context['search_terms']) || empty($tokens) || empty($count_tokens))
285 285
 	{
286 286
 		// This is where it starts to get expensive, *sob*. We first have to query to get the number of applicable rows.
287 287
 		$query = shd_db_query('', '
... ...
@@ -44,7 +44,7 @@ function shd_tickettotopic()
44 44
 	checkSession('get');
45 45
 
46 46
 	if (empty($context['ticket_id']))
47
-		return fatal_lang_error('shd_no_ticket');
47
+		shd_fatal_lang_error('shd_no_ticket');
48 48
 
49 49
 	// Get ticket details - and kick it out if they shouldn't be able to see it.
50 50
 	$query = shd_db_query('', '
... ...
@@ -65,11 +65,11 @@ function shd_tickettotopic()
65 65
 	else
66 66
 	{
67 67
 		$smcFunc['db_free_result']($query);
68
-		return fatal_lang_error('shd_no_ticket');
68
+		shd_fatal_lang_error('shd_no_ticket');
69 69
 	}
70 70
 
71 71
 	if (!shd_allowed_to('shd_ticket_to_topic', $dept) || !empty($modSettings['shd_helpdesk_only']) || !empty($modSettings['shd_disable_tickettotopic']))
72
-		return fatal_lang_error('shd_cannot_move_ticket', false);
72
+		shd_fatal_lang_error('shd_cannot_move_ticket', false);
73 73
 
74 74
 	// Hang on... are there any deleted replies?
75 75
 	if ($deleted_replies > 0)
... ...
@@ -77,7 +77,7 @@ function shd_tickettotopic()
77 77
 		if (shd_allowed_to('shd_access_recyclebin', $dept))
78 78
 			$context['deleted_prompt'] = true;
79 79
 		else
80
-			return fatal_lang_error('shd_cannot_move_ticket_with_deleted');
80
+			shd_fatal_lang_error('shd_cannot_move_ticket_with_deleted');
81 81
 	}
82 82
 
83 83
 	// In a department, for the linktree?
... ...
@@ -135,7 +135,7 @@ function shd_tickettotopic()
135 135
 	$smcFunc['db_free_result']($request);
136 136
 
137 137
 	if (empty($context['categories']))
138
-		return fatal_lang_error('shd_moveticket_noboards', false);
138
+		shd_fatal_lang_error('shd_moveticket_noboards', false);
139 139
 
140 140
 	// OK, now we got to check for custom fields. In any case, we need to fetch the list of fields that might be applicable to this ticket.
141 141
 	shd_load_language('sd_language/SimpleDeskAdmin');
... ...
@@ -237,7 +237,7 @@ function shd_tickettotopic()
237 237
 		{
238 238
 			// So they're staff. But the field might not be visible to them; they can't deal with it.
239 239
 			if (!$field['visible']['staff'])
240
-				return fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
240
+				shd_fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
241 241
 			elseif (!$field['visible']['user'])
242 242
 			{
243 243
 				// Normal mortals can't see it even if this person can, so warn them.
... ...
@@ -248,7 +248,7 @@ function shd_tickettotopic()
248 248
 		else
249 249
 			// Non staff aren't special. They should not be able to make this decision. If someone can't see it, they don't get to make the choice.
250 250
 			if (!$field['visible']['user'] || !$field['visible']['staff'])
251
-				return fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
251
+				shd_fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
252 252
 	}
253 253
 
254 254
 	// Store the ticket subject for the template
... ...
@@ -290,11 +290,11 @@ function shd_tickettotopic2()
290 290
 	checkSubmitOnce('check');
291 291
 
292 292
 	if (empty($context['ticket_id']))
293
-		return fatal_lang_error('shd_no_ticket');
293
+		shd_fatal_lang_error('shd_no_ticket');
294 294
 	elseif (isset($_POST['send_pm']) && (!isset($_POST['pm_content']) || trim($_POST['pm_content']) == ''))
295 295
 	{
296 296
 		checkSubmitOnce('free');
297
-		return fatal_lang_error('shd_move_no_pm', false);
297
+		shd_fatal_lang_error('shd_move_no_pm', false);
298 298
 	}
299 299
 
300 300
 	// Just in case, are they cancelling?
... ...
@@ -331,13 +331,13 @@ function shd_tickettotopic2()
331 331
 		)
332 332
 	);
333 333
 	if ($smcFunc['db_num_rows']($request) == 0)
334
-		return fatal_lang_error('no_board');
334
+		shd_fatal_lang_error('no_board');
335 335
 
336 336
 	list ($pcounter, $board_name, $subject, $owner, $body, $firstmsg, $smileys_enabled, $modified_time, $modified_name, $time, $shd_id_msg, $deleted_replies, $dept) = $smcFunc['db_fetch_row']($request);
337 337
 	$smcFunc['db_free_result']($request);
338 338
 
339 339
 	if (!shd_allowed_to('shd_ticket_to_topic', $dept) || !empty($modSettings['shd_helpdesk_only']) || !empty($modSettings['shd_disable_tickettotopic']))
340
-		return fatal_lang_error('shd_cannot_move_ticket', false);
340
+		shd_fatal_lang_error('shd_cannot_move_ticket', false);
341 341
 
342 342
 	// Are we changing the subject?
343 343
 	$old_subject = $subject;
... ...
@@ -354,7 +354,7 @@ function shd_tickettotopic2()
354 354
 			$context['deleted_prompt'] = isset($_REQUEST['deleted_replies']) && in_array($_REQUEST['deleted_replies'], $dr_opts) ? $_REQUEST['deleted_replies'] : 'abort';
355 355
 		}
356 356
 		else
357
-			return fatal_lang_error('shd_cannot_move_ticket_with_deleted');
357
+			shd_fatal_lang_error('shd_cannot_move_ticket_with_deleted');
358 358
 	}
359 359
 
360 360
 	if (!empty($context['deleted_prompt']) && $context['deleted_prompt'] == 'abort')
... ...
@@ -445,14 +445,14 @@ function shd_tickettotopic2()
445 445
 		{
446 446
 			// So they're staff. But the field might not be visible to them; they can't deal with it whatever.
447 447
 			if (!$field['visible']['staff'])
448
-				return fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
448
+				shd_fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
449 449
 			elseif (!$field['visible']['user'])
450 450
 				$context['custom_fields_warning'] = true;
451 451
 		}
452 452
 		else
453 453
 			// Non staff aren't special. They should not be able to make this decision. If someone can't see it, they don't get to make the choice.
454 454
 			if (!$field['visible']['user'] || !$field['visible']['staff'])
455
-				return fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
455
+				shd_fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false);
456 456
 
457 457
 		// Are we ignoring this field? If so, we can now safely get rid of it at this very point.
458 458
 		if (isset($_POST['field' . $field_id]) && $_POST['field' . $field_id] == 'lose')
... ...
@@ -463,7 +463,7 @@ function shd_tickettotopic2()
463 463
 	if (!empty($context['custom_fields_warning']) && empty($_POST['accept_move']))
464 464
 	{
465 465
 		checkSubmitOnce('free');
466
-		return fatal_lang_error('shd_ticket_move_reqd_nonselected', false);
466
+		shd_fatal_lang_error('shd_ticket_move_reqd_nonselected', false);
467 467
 	}
468 468
 
469 469
 	// Just before we do this, make sure we call any hooks. $context has lots of interesting things, as does $_POST.
... ...
@@ -741,7 +741,7 @@ function shd_tickettotopic2()
741 741
 		);
742 742
 	}
743 743
 	else
744
-		return fatal_lang_error('shd_move_topic_not_created', false);
744
+		shd_fatal_lang_error('shd_move_topic_not_created', false);
745 745
 
746 746
 	// Clear our cache
747 747
 	shd_clear_active_tickets($dept);
... ...
@@ -830,9 +830,9 @@ function shd_topictoticket()
830 830
 	checkSession('get');
831 831
 
832 832
 	if (!shd_allowed_to('shd_topic_to_ticket', 0) || !empty($modSettings['shd_helpdesk_only']) || !empty($modSettings['shd_disable_tickettotopic']))
833
-		return fatal_lang_error('shd_cannot_move_topic', false);
833
+		shd_fatal_lang_error('shd_cannot_move_topic', false);
834 834
 	elseif (empty($_REQUEST['topic']))
835
-		return fatal_lang_error('shd_no_topic');
835
+		shd_fatal_lang_error('shd_no_topic');
836 836
 
837 837
 	$context['topic_id'] = (int) $_REQUEST['topic'];
838 838
 
... ...
@@ -856,7 +856,7 @@ function shd_topictoticket()
856 856
 	else
857 857
 	{
858 858
 		$smcFunc['db_free_result']($query);
859
-		return fatal_lang_error('shd_no_topic');
859
+		shd_fatal_lang_error('shd_no_topic');
860 860
 	}
861 861
 
862 862
 	// Get the department list
... ...
@@ -995,9 +995,9 @@ function shd_topictoticket2()
995 995
 		$_REQUEST['dept'] = -1; // which is never a valid department!
996 996
 
997 997
 	if (!shd_allowed_to('shd_topic_to_ticket', $_REQUEST['dept']) || !empty($modSettings['shd_helpdesk_only']) || !empty($modSettings['shd_disable_tickettotopic']))
998
-		return fatal_lang_error('shd_cannot_move_topic', false);
998
+		shd_fatal_lang_error('shd_cannot_move_topic', false);
999 999
 	elseif (empty($_REQUEST['topic']))
1000
-		return fatal_lang_error('shd_no_topic');
1000
+		shd_fatal_lang_error('shd_no_topic');
1001 1001
 
1002 1002
 	$context['topic_id'] = (int) $_REQUEST['topic'];
1003 1003
 
... ...
@@ -1005,7 +1005,7 @@ function shd_topictoticket2()
1005 1005
 	if (isset($_REQUEST['cancel']))
1006 1006
 		return redirectexit('topic=' . $context['topic_id']);
1007 1007
 	elseif (isset($_POST['send_pm']) && (!isset($_POST['pm_content']) || trim($_POST['pm_content']) == ''))
1008
-		return fatal_lang_error('shd_move_no_pm_topic', false);
1008
+		shd_fatal_lang_error('shd_move_no_pm_topic', false);
1009 1009
 
1010 1010
 	require_once($sourcedir . '/sd_source/Subs-SimpleDeskPost.php');
1011 1011
 
... ...
@@ -1023,7 +1023,7 @@ function shd_topictoticket2()
1023 1023
 		)
1024 1024
 	);
1025 1025
 	if ($smcFunc['db_num_rows']($request) == 0)
1026
-		return fatal_lang_error('shd_move_ticket_not_created');
1026
+		shd_fatal_lang_error('shd_move_ticket_not_created');
1027 1027
 
1028 1028
 	list ($subject, $board, $owner, $body, $firstmsg, $smileys_enabled, $memberupdated, $numreplies, $postername, $posteremail, $posterip, $postertime, $modified_time, $modified_name, $smf_id_msg) = $smcFunc['db_fetch_row']($request);
1029 1029
 	$smcFunc['db_free_result']($request);
... ...
@@ -1070,7 +1070,7 @@ function shd_topictoticket2()
1070 1070
 
1071 1071
 	// Ticket created, let's dig out the replies and post them in the ticket, if there are any.
1072 1072
 	if (!isset($ticketOptions['id']))
1073
-		return fatal_lang_error('shd_move_ticket_not_created', false);
1073
+		shd_fatal_lang_error('shd_move_ticket_not_created', false);
1074 1074
 
1075 1075
 	$request = shd_db_query('', '
1076 1076
 		SELECT body, id_member, poster_time, poster_name, poster_email, poster_ip, smileys_enabled, id_msg
... ...
@@ -47,12 +47,14 @@ function shd_main()
47 47
 
48 48
 	// Basic sanity stuff
49 49
 	if (!$modSettings['helpdesk_active'])
50
-		return fatal_lang_error('shd_inactive', false);
50
+		shd_fatal_lang_error('shd_inactive', false);
51 51
 
52 52
 	// Let's be sneaky. Can they only access one department? If they can only access one department, put them there and make a note of it for later.
53 53
 	$depts = shd_allowed_to('access_helpdesk', false);
54 54
 	$context['shd_multi_dept'] = true;
55
-	if (count($depts) == 1)
55
+	if (is_bool($dept))
56
+		shd_fatal_error('Bug hunters unite...', false);
57
+	elseif (count($depts) == 1)
56 58
 	{
57 59
 		$_REQUEST['dept'] = $depts[0];
58 60
 		$context['shd_multi_dept'] = false;
... ...
@@ -626,7 +628,7 @@ function shd_closed_tickets()
626 628
 	global $context, $txt, $smcFunc, $user_profile, $scripturl, $settings, $user_info;
627 629
 
628 630
 	if (!shd_allowed_to('shd_view_closed_own', $context['shd_department']) && !shd_allowed_to('shd_view_closed_any', $context['shd_department']))
629
-		return fatal_lang_error('shd_cannot_view_resolved', false);
631
+		shd_fatal_lang_error('shd_cannot_view_resolved', false);
630 632
 
631 633
 	// Stuff we need to add to $context, the permission we want to use, page title etc etc
632 634
 	$context += array(
... ...
@@ -179,8 +179,11 @@ function shd_init()
179 179
 			// First figure out what department they're in.
180 180
 			$this_dept = 0;
181 181
 			$depts = shd_allowed_to('access_helpdesk', false);
182
+
182 183
 			// Do they only have one dept? If so, that's the one.
183
-			if (count($depts) == 1)
184
+			if (is_bool($dept))
185
+				shd_fatal_error('No Bools here', false);
186
+			elseif (count($depts) == 1)
184 187
 				$this_dept = $depts[0];
185 188
 			// They might explicitly say it on the request.
186 189
 			elseif (isset($_REQUEST['dept']))
... ...
@@ -730,7 +733,7 @@ function shd_load_ticket($ticket = 0)
730 733
 
731 734
 	// Make sure they set a ticket ID.
732 735
 	if ($ticket == 0 && empty($context['ticket_id']))
733
-		return fatal_lang_error('shd_no_ticket', false);
736
+		shd_fatal_lang_error('shd_no_ticket', false);
734 737
 
735 738
 	// Get the ticket data. Note this implicitly checks perms too.
736 739
 	$query = shd_db_query('', '
... ...
@@ -755,7 +758,7 @@ function shd_load_ticket($ticket = 0)
755 758
 	if ($smcFunc['db_num_rows']($query) == 0)
756 759
 	{
757 760
 		$smcFunc['db_free_result']($query);
758
-		return fatal_lang_error('shd_no_ticket', false);
761
+		shd_fatal_lang_error('shd_no_ticket', false);
759 762
 	}
760 763
 
761 764
 	$ticketinfo = $smcFunc['db_fetch_assoc']($query);
... ...
@@ -1067,12 +1070,12 @@ function shd_no_expand_pageindex($base_url, &$start, $max_value, $num_per_page,
1067 1070
 function shd_load_language($langfile, $override_lang = '')
1068 1071
 {
1069 1072
 	global $modSettings, $user_info, $language;
1070
-	if (empty($modSettings['disable_language_fallback']))
1071
-	{
1073
+
1072 1074
 	$cur_language = isset($user_info['language']) ? $user_info['language'] : ($override_lang == '' ? $language : $override_lang);
1073
-		if ($cur_language !== 'english')
1075
+
1076
+	if (empty($modSettings['disable_language_fallback']) && $cur_language !== 'english')
1074 1077
 		loadLanguage($langfile, 'english', false);
1075
-	}
1078
+
1076 1079
 	loadLanguage($langfile, $cur_language, false);
1077 1080
 }
1078 1081
 
... ...
@@ -2048,3 +2051,39 @@ function shd_bbc_codes(&$codes, &$no_autolink_tags)
2048 2051
 		'block_level' => true,
2049 2052
 	);
2050 2053
 }
2054
+
2055
+/**
2056
+ *	SimpleDesk Fatal Language Error handler.
2057
+ *  Works the same way as SMF, but allows customizing and overriding.
2058
+ *
2059
+ *	@since 2.1
2060
+ *  @param string $error The error message
2061
+ *  @param string|false $log The type of error, or false to not log it
2062
+ *  @param array $sprintf An array of data to be sprintf()'d into the specified message
2063
+ *  @param int $status = false The HTTP status code associated with this error
2064
+ *  @return mixed User error page should occur, failing that we trigger a fatal generic user error page.
2065
+ */
2066
+function shd_fatal_lang_error($error, $log = 'simpledesk', $sprintf = array(), $status = 403)
2067
+{
2068
+	fatal_lang_error($error, $log, $sprintf, $status);
2069
+
2070
+	trigger_error('Hacking attempt...', E_USER_ERROR);
2071
+	return false;
2072
+}
2073
+
2074
+/**
2075
+ *	SimpleDesk Fatal Error handler.
2076
+ *  Works the same way as SMF, but allows customizing and overriding.
2077
+ *
2078
+ * @param string $error The error message
2079
+ * @param string $log = 'general' What type of error to log this as (false to not log it))
2080
+ * @param int $status The HTTP status code associated with this error
2081
+ */
2082
+function shd_fatal_error($error, $log = 'general', $status = 500)
2083
+{
2084
+	fatal_error($error, $log, $status);
2085
+
2086
+	trigger_error('Hacking attempt...', E_USER_ERROR);
2087
+	return false;
2088
+
2089
+}
... ...
@@ -362,7 +362,7 @@ function shd_action_log_exclusions()
362 362
 
363 363
 		// Can they see multiple departments? If not, exclude dept move notices too.
364 364
 		$dept = shd_allowed_to('access_helpdesk', false);
365
-		if (count($dept) == 1)
365
+		if (!is_bool($dept) && count($dept) == 1)
366 366
 			$exclude[] = 'move_dept';
367 367
 	}
368 368
 
... ...
@@ -44,7 +44,7 @@ function shd_add_to_boardindex($boardIndexOptions, &$categories)
44 44
 
45 45
 	// OK, so what helpdesks are we displaying?
46 46
 	$depts = shd_allowed_to('access_helpdesk', false);
47
-	if (empty($depts))
47
+	if (is_bool($depts) || empty($depts))
48 48
 		return;
49 49
 
50 50
 	$cat_list = array();
... ...
@@ -72,8 +72,11 @@ function shd_repair_attachments_nomsg(&$ignore_ids, $min_substep, $max_substep)
72 72
 */
73 73
 function shd_attachment_remove(&$filesRemoved, $attachments)
74 74
 {
75
+	$idsRemoved = array();
76
+
75 77
 	if (in_array($_REQUEST['type'], array('shd_attach', 'shd_thumb')) && !empty($attachments))
76 78
 		$idsRemoved = removeAttachments(array('id_attach' => $attachments), '', true);
79
+
77 80
 	$filesRemoved = array_merge($filesRemoved, $idsRemoved);
78 81
 }
79 82
 
... ...
@@ -386,7 +386,10 @@ function shd_load_user_perms()
386 386
 
387 387
 	$tickets_any_dept = shd_allowed_to('shd_view_ticket_any', false);
388 388
 	$tickets_own_dept = shd_allowed_to('shd_view_ticket_own', false);
389
-	if (!empty($tickets_any_dept) && !empty($tickets_own_dept))
389
+
390
+	if (is_bool($tickets_own_dept) || is_bool($tickets_any_dept))
391
+		shd_fatal_error('Silly Human, bools belong elsewhere', false);
392
+	elseif (!empty($tickets_any_dept) && !empty($tickets_own_dept))
390 393
 		$tickets_own_dept = array_diff($tickets_any_dept, $tickets_own_dept);
391 394
 
392 395
 	if ($user_info['is_admin'])
... ...
@@ -431,20 +434,20 @@ function shd_load_user_perms()
431 434
 		$depts_closed_own = array_diff($depts_closed_own, $depts_closed_any);
432 435
 
433 436
 		if (empty($depts_closed_any) && empty($depts_closed_own)) // No access at all. Disable all access to closed tickets.
434
-			$clauses[] = 'hdt.status != 3';
437
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_CLOSED;
435 438
 		elseif (!empty($depts_closed_any) && empty($depts_closed_own)) // Only where we can access 'all closed' but not 'any of our own closed', e.g. admins
436
-			$clauses[] = 'hdt.status != 3 OR (hdt.status = 3 AND hdt.id_dept IN (' . implode(',', $depts_closed_any) . '))';
439
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_CLOSED . ' OR (hdt.status = ' . TICKET_STATUS_CLOSED . ' AND hdt.id_dept IN (' . implode(',', $depts_closed_any) . '))';
437 440
 		elseif (!empty($depts_closed_any) && !empty($depts_closed_own)) // So we have a mixture
438
-			$clauses[] = 'hdt.status != 3 OR (hdt.status = 3 AND (hdt.id_dept IN (' . implode(',', $depts_closed_any) . ') OR (hdt.id_member_started = {int:user_info_id} AND hdt.id_dept IN (' . implode(',', $depts_closed_own) . '))))';
441
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_CLOSED . ' OR (hdt.status = ' . TICKET_STATUS_CLOSED . ' AND (hdt.id_dept IN (' . implode(',', $depts_closed_any) . ') OR (hdt.id_member_started = {int:user_info_id} AND hdt.id_dept IN (' . implode(',', $depts_closed_own) . '))))';
439 442
 		elseif (empty($depts_closed_any) && !empty($depts_closed_own)) // We can't ever see 'any', but we can see our own
440
-			$clauses[] = 'hdt.status != 3 OR (hdt.status = 3 AND hdt.id_dept IN (' . implode(',', $depts_closed_own) . ') AND hdt.id_member_started = {int:user_info_id})';
443
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_CLOSED . ' OR (hdt.status = ' . TICKET_STATUS_CLOSED . ' AND hdt.id_dept IN (' . implode(',', $depts_closed_own) . ') AND hdt.id_member_started = {int:user_info_id})';
441 444
 
442 445
 		// And finally, deleted tickets.
443 446
 		$depts_deleted = shd_allowed_to('shd_access_recyclebin', false);
444
-		if (empty($depts_deleted))
445
-			$clauses[] = 'hdt.status != 6';
447
+		if (is_bool($depts_deleted) || empty($depts_deleted))
448
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_DELETED;
446 449
 		else
447
-			$clauses[] = 'hdt.status != 6 OR (hdt.status = 6 AND hdt.id_dept IN (' . implode(',', $depts_deleted) . '))';
450
+			$clauses[] = 'hdt.status != ' . TICKET_STATUS_DELETED . ' OR (hdt.status = ' . TICKET_STATUS_DELETED .' AND hdt.id_dept IN (' . implode(',', $depts_deleted) . '))';
448 451
 
449 452
 		// Finally, assemble into $user_info.
450 453
 		if (empty($clauses))
... ...
@@ -879,7 +879,6 @@ function shd_validate_custom_fields($scope, $dept)
879 879
 		// Otherwise, for each field, check it was sent in the form.
880 880
 		elseif (isset($_POST['field-' . $field_id]))
881 881
 		{
882
-			if ($field['type'] != CFIELD_TYPE_MULTI)
883 882
 			$value = trim($_POST['field-' . $field_id]);
884 883
 
885 884
 			// Now to sanitise the individual value.
... ...
@@ -177,10 +177,11 @@ function template_shd_edit_canned_reply()
177 177
 					<dd><input type="text" value="', $context['canned_reply']['title'], '" name="title" size="80"></dd>
178 178
 				</dl>
179 179
 				<p><strong>', $txt['shd_admin_cannedreplies_content'], '</strong></p>
180
-				<div class="block">
181
-					<div id="bbcbox"></div>
182
-					<div id="smileybox"></div>',
183
-					template_control_richedit($context['post_box_name'], 'smileybox', 'bbcbox'), '
180
+				<div class="block">';
181
+
182
+	template_control_richedit($context['post_box_name'], true, true);
183
+
184
+	echo '
184 185
 				</div>
185 186
 				<dl class="settings">
186 187
 					<dt><strong>', $txt['shd_admin_cannedreplies_active'], '</strong></dt>
... ...
@@ -43,15 +43,20 @@ function template_shd_permissions_home()
43 43
 			</tr>';
44 44
 
45 45
 	foreach ($context['shd_permissions']['roles'] as $role_id => $role_details)
46
+	{
46 47
 		echo '
47 48
 			<tr class="windowbg">
48 49
 				<td>', !empty($role_details['icon']) ? ('<img src="' . $settings['default_images_url'] . '/simpledesk/' . $role_details['icon'] . '" alt="">') : '', '</td>
49 50
 				<td>
50 51
 					', $txt[$role_details['description']], '
51 52
 					<div class="smalltext">[<a href="', $scripturl, '?action=admin;area=helpdesk_permissions;sa=createrole;template=', $role_id, '">', $txt['shd_create_role'], '</a>]</div>
52
-				</td>
53
-				', template_shd_display_permission_list($role_details['permissions']), '
53
+				</td>';
54
+
55
+		template_shd_display_permission_list($role_details['permissions']);
56
+
57
+		echo '
54 58
 			</tr>';
59
+	}
55 60
 
56 61
 	echo '
57 62
 		</table>
... ...
@@ -91,7 +96,9 @@ function template_shd_permissions_home()
91 96
 						[<a href="', $scripturl, '?action=admin;area=helpdesk_permissions;sa=copyrole;role=', $role, '">', $txt['shd_copy_role'], '</a>]
92 97
 					</div>
93 98
 				</td>
94
-				', template_shd_display_permission_list($role_details['permissions']);
99
+				';
100
+
101
+			template_shd_display_permission_list($role_details['permissions']);
95 102
 
96 103
 			if (empty($role_details['groups']))
97 104
 				echo '
... ...
@@ -314,13 +321,10 @@ function template_shd_edit_role()
314 321
 					else
315 322
 						list($perm_class, $perm_value) = array('shd_no', 'disallow');
316 323
 				}
324
+				elseif (!empty($role['permissions'][$permission]) && $role['permissions'][$permission] == ROLEPERM_ALLOW)
325
+					list($perm_class, $perm_value) = array('shd_yes', 'allow');
317 326
 				else
318
-				{
319
-					if (empty($role['permissions'][$permission]))
320 327
 					list($perm_class, $perm_value) = array('shd_no', 'disallow');
321
-					elseif ($role['permissions'][$permission] == ROLEPERM_ALLOW)
322
-						list($perm_class, $perm_value) = array('shd_yes', 'allow');
323
-				}
324 328
 
325 329
 				echo '
326 330
 						<dt', (empty($txt['permissionhelp_' . $permission]) ? '' : ' title="' . $txt['permissionhelp_' . $permission] . '"') . '><img src="', shd_image_url($icon), '" alt="*">', $txt['permissionname_' . $permission], '</dt>
... ...
@@ -39,18 +39,11 @@ function template_viewticket()
39 39
 				<span class="floatright smalltext shd_ticketlinks" id="ticket">';
40 40
 
41 41
 	// SimpleDesk style Icons go here.
42
-	if ($modSettings['shd_ticketnav_style'] == 'sd')
43
-		foreach ($context['ticket_navigation'] as $button)
44
-			if (!empty($button['display']))
42
+	if ($modSettings['shd_ticketnav_style'] == 'sd' || $modSettings['shd_ticketnav_style'] == 'sdcompact')
43
+		foreach ($context['ticket_navigation'] as $act)
44
+			if (!empty($act['display']))
45 45
 				echo '
46
-					<a href="', $button['url'], '"', (!empty($button['is_last']) ? ' id="last"' : ''), '', (!empty($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : ''), '><img src="', $settings['default_images_url'], '/simpledesk/', $button['icon'], '.png" alt="', $button['alt'], '" title="', $txt[$button['text']], '"> ', $txt[$button['text']], '</a>';
47
-	elseif ($modSettings['shd_ticketnav_style'] == 'sdcompact')
48
-		foreach ($context['ticket_navigation'] as $button)
49
-		{
50
-			if (!empty($button['display']))
51
-				echo '
52
-					<a href="', $button['url'], '"', (!empty($button['is_last']) ? ' id="last"' : ''), '', (!empty($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : ''), '><img src="', $settings['default_images_url'], '/simpledesk/', $button['icon'], '.png" alt="', $button['alt'], '" title="', $txt[$button['text']], '"></a>';
53
-		}
46
+					<a href="', $act['url'], '"', (!empty($act['is_last']) ? ' id="last"' : ''), '', (!empty($act['onclick']) ? ' onclick="' . $act['onclick'] . '"' : ''), '><img src="', $settings['default_images_url'], '/simpledesk/', $act['icon'], '.png" alt="', $act['alt'], '" title="', $txt[$act['text']], '"> ', $modSettings['shd_ticketnav_style'] == 'sd' ? $txt[$act['text']] : '', '</a>';
54 47
 
55 48
 	echo '
56 49
 				</span>
... ...
@@ -24,8 +24,7 @@ function template_movedept()
24 24
 		$context['shd_return_to'] = 'ticket';
25 25
 
26 26
 	// Back to the helpdesk.
27
-	echo '
28
-		', template_button_strip(array($context['navigation']['back']), 'bottom'), '';
27
+	template_button_strip(array($context['navigation']['back']), 'bottom');
29 28
 
30 29
 	echo '
31 30
 	<div class="cat_bar">
... ...
@@ -74,6 +74,8 @@ function template_ticket_option($option)
74 74
 	}
75 75
 	else
76 76
 		echo $txt[$context['ticket_form'][$option]['options'][$context['ticket_form'][$option]['setting']]];
77
+
78
+	return '';
77 79
 }
78 80
 
79 81
 function template_ticket_info()
... ...
@@ -481,11 +483,16 @@ function template_ticket_postbox()
481 483
 	{
482 484
 		$width = round(((int) $editor_context['width']) / 0.988, 1);
483 485
 		echo '
484
-						<div style="width: ', $width, '%;">', template_control_richedit($context['post_box_name'], 'shd_smileybox', 'shd_bbcbox'), '</div>';
486
+						<div style="width: ', $width, '%;">';
487
+
488
+		template_control_richedit($context['post_box_name'], true, true)
489
+
490
+		echo '
491
+						</div>';
485 492
 	}
486 493
 	// Editor width isn't proportional, presumably we don't care.
487 494
 	else
488
-		echo template_control_richedit($context['post_box_name'], 'shd_smileybox', 'shd_bbcbox');
495
+		template_control_richedit($context['post_box_name'], true, true);
489 496
 
490 497
 	// Custom fields
491 498
 	template_ticket_custom_fields();
... ...
@@ -587,6 +587,11 @@ function template_shd_profile_permissions()
587 587
 					$roles = $context['member_permissions']['allowed'][$permission . '_own'];
588 588
 					echo $txt['permissionname_' . $permission . '_own'];
589 589
 				}
590
+				else
591
+				{
592
+					$roles = 'no';
593
+					echo $txt['permissionname_' . $permission . '_no'];
594
+				}
590 595
 
591 596
 				echo '</td>';
592 597
 			}
593 598