View difference between Paste ID: 2WtS7vpC and ycBUvhhm
SHOW: | | - or go back to the newest paste.
1-
1+
2
	if (!defined('SMF'))
3
	die('Hacking attempt...');
4-
		die('Hacking attempt...');
4+
	@session_start();
5-
5+
6-
//	This function shows the custom forms and submits them.
6+
	//	This function shows the custom forms and submits them.
7-
function CustomForm()
7+
	function CustomForm()
8-
{
8+
9-
	global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $modSettings;
9+
		global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $modSettings;
10
		
11-
global $txt, $context, $sourcedir, $modSettings;
11+
		global $txt, $context, $sourcedir, $modSettings;
12-
   
12+
13-
   
13+
		global $_SESSION;
14-
   // Generate a visual verification code to make sure the user is no bot.
14+
15-
      $context['require_verification'] = $user_info['is_guest'] || !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha']);
15+
		// Generate a visual verification code to make sure the user is no bot.
16-
      if ($context['require_verification'])
16+
		$context['require_verification'] = $user_info['is_guest'] || !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha']);
17-
      {
17+
		if ($context['require_verification'])
18-
         require_once($sourcedir . '/Subs-Editor.php');
18+
19-
         $verificationOptions = array(
19+
20
			$verificationOptions = array(
21-
         );
21+
22-
         $context['visual_verification'] = create_control_verification($verificationOptions);
22+
23-
         $context['visual_verification_id'] = $verificationOptions['id'];
23+
			$context['visual_verification'] = create_control_verification($verificationOptions);
24-
      }
24+
			$context['visual_verification_id'] = $verificationOptions['id'];
25-
      // Otherwise we have nothing to show.
25+
26-
      else
26+
		// Otherwise we have nothing to show.
27-
         $context['visual_verification'] = false;
27+
		else
28-
28+
		$context['visual_verification'] = false;
29
		
30
		//	Are we looking for the thank you page.
31-
{
31+
32-
		$context['sub_template'] = 'ThankYou';
32+
33-
		loadTemplate('CustomForm');
33+
			$context['sub_template'] = 'ThankYou';
34-
}
34+
			loadTemplate('CustomForm');
35-
else
35+
36-
	//	Do we have a valid form id?
36+
		else
37-
	if(isset($_REQUEST['n'])
37+
		//	Do we have a valid form id?
38-
	&& intval($_REQUEST['n']))
38+
		if(isset($_REQUEST['n'])
39
		&& intval($_REQUEST['n']))
40-
		$form_id = intval($_REQUEST['n']);
40+
41
			$form_id = intval($_REQUEST['n']);
42-
		//	Wait a second... Are you even allowed to use this form?
42+
43-
		if(!allowedTo('custom_forms_'.$form_id))
43+
			//	Wait a second... Are you even allowed to use this form?
44
			if(!allowedTo('custom_forms_'.$form_id))
45
			redirectExit("action=form");
46-
		//	Get the data about the current form.
46+
47-
		$request = $smcFunc['db_query']('','
47+
			//	Get the data about the current form.
48
			$request = $smcFunc['db_query']('','
49
			SELECT title, output, subject, id_board, icon, form_exit, template_function
50
			FROM {db_prefix}cf_forms
51
			WHERE id_form = {int:id}',
52-
				'id' => $form_id,
52+
53
			'id' => $form_id,
54-
		);
54+
55-
55+
56-
		//	Did we get some form data? If not then redirect the user to the form view page.
56+
57-
		if(!($form_data = $smcFunc['db_fetch_assoc']($request)))
57+
			//	Did we get some form data? If not then redirect the user to the form view page.
58
			if(!($form_data = $smcFunc['db_fetch_assoc']($request)))
59
			redirectExit("action=form;");
60-
		$output = $form_data['output'];
60+
61-
		$exit = $form_data['form_exit'];
61+
			$output = $form_data['output'];
62-
		$subject = $form_data['subject'];
62+
			$exit = $form_data['form_exit'];
63-
		$icon = $form_data['icon'];
63+
			$subject = $form_data['subject'];
64-
		$board = $form_data['id_board'];
64+
			$icon = $form_data['icon'];
65-
		$form_title = $form_data['title'];
65+
			$board = $form_data['id_board'];
66
			$form_title = $form_data['title'];
67-
		//	Free the db request.
67+
68-
		$smcFunc['db_free_result']($request);		
68+
			//	Free the db request.
69-
69+
			$smcFunc['db_free_result']($request);		
70-
		//	Get a list of the current fields attached to this form.
70+
71-
		$request = $smcFunc['db_query']('','
71+
			//	Get a list of the current fields attached to this form.
72
			$request = $smcFunc['db_query']('','
73
			SELECT title, text, type, type_vars
74
			FROM {db_prefix}cf_fields
75
			WHERE id_form = {int:id}
76
			AND title != \'\'
77
			AND text != \'\'
78
			AND type != \'\'
79
			ORDER BY ID_FIELD',
80-
				'id' => $form_id,
80+
81
			'id' => $form_id,
82-
		);
82+
83
			);
84-
		$data = array();
84+
85-
		//	Get all of data from the db query.
85+
			$data = array();
86-
		while($row = $smcFunc['db_fetch_assoc']($request))
86+
			//	Get all of data from the db query.
87
			while($row = $smcFunc['db_fetch_assoc']($request))
88
			$data[] = $row;
89-
		//	Free the db request.
89+
90-
		$smcFunc['db_free_result']($request);
90+
			//	Free the db request.
91
			$smcFunc['db_free_result']($request);
92-
		//	Do we have fields attached to this form? If not then redirect the user to the form view page.
92+
93-
		if(empty($data))
93+
			//	Do we have fields attached to this form? If not then redirect the user to the form view page.
94
			if(empty($data))
95
			redirectExit("action=form;");
96-
		$fail_submit = false;
96+
97
			$fail_submit = false;
98-
		//	Do we need to submit this form?
98+
99-
		if(isset($_GET['submit']))
99+
			//	Do we need to submit this form?
100
			if(isset($_GET['submit']))
101-
			$vars = array();
101+
102-
			$replace = array();
102+
				$vars = array();
103-
			$i = -1;
103+
				$replace = array();
104
				$i = -1;
105-
			//	Check for valid post data from the forms fields.
105+
106
				//	Check for valid post data from the forms fields.
107
				foreach($data as $field)
108-
				$i++;
108+
109-
				$value = '';
109+
					$i++;
110-
				$size = '';
110+
					$value = '';
111-
				$default = '';
111+
					$size = '';
112
					$default = '';
113-
				$temp = ($field['type_vars'] != '') ? explode(',', $field['type_vars']) : array();
113+
					
114-
				$type_vars = array();
114+
					$temp = ($field['type_vars'] != '') ? explode(',', $field['type_vars']) : array();
115
					$type_vars = array();
116-
				//	Remove whitespace from temp, to avoid unwanted issues.
116+
					
117-
				for($p=0; $p < count($temp); $p++)
117+
					//	Remove whitespace from temp, to avoid unwanted issues.
118
					for($p=0; $p < count($temp); $p++)
119
					$temp[$p] = trim($temp[$p]);
120
					
121-
				if(!empty($temp))
121+
					//	Go through all of the type_vars to format them correctly.
122
					if(!empty($temp))
123
					foreach($temp as $var)
124
					{
125
						//	Check for a size value.
126-
							$size = intval(substr($var, 5));
126+
127-
							
127+
						$size = intval(substr($var, 5));
128
						
129
						//	Check for a default value
130-
							$default = substr($var, 8);
130+
131
						$default = substr($var, 8);
132
						
133
						//	Add them to the vars list.
134-
							$type_vars[] = $var;
134+
135
						$type_vars[] = $var;
136
					}
137-
				$required = in_array('required', $temp);
137+
					
138
					$required = in_array('required', $temp);
139-
				//	Go through each of the possible types of fields.
139+
					
140-
				switch ($field['type'])
140+
					//	Go through each of the possible types of fields.
141
					switch ($field['type'])
142-
					case 'checkbox':
142+
143
						case 'checkbox':
144
						$value = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : false;
145
						//	Replace the normal true/false values if we have special type_var values.
146-
							$value = $type_vars[0];
146+
147
						$value = $type_vars[0];
148-
							$value = $type_vars[1];
148+
149
						$value = $type_vars[1];
150-
							$value = $txt['yes'];
150+
151
						$value = $txt['yes'];
152-
							$value = $txt['no'];
152+
153-
					break;
153+
						$value = $txt['no'];
154-
					case 'selectbox':
154+
						break;
155
						case 'selectbox':
156
						//	Skip this field, if there are no select values.
157-
							continue 2;
157+
158
						continue 2;
159
						$value = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : '';
160
						//	Make sure that the selectbox value is in the array, otherwise stop those dodgy users from passing weird values. ;)
161-
							$value = '';
161+
162-
					break;
162+
						$value = '';
163-
					case 'int':
163+
						break;
164
						case 'int':
165
						$value = isset($_REQUEST[$field['title']]) ? intval($_REQUEST[$field['title']]) : '';
166
						//	If value is empty then set it to the default.
167
						if(($value == '')
168-
							$value = $default;
168+
169
						$value = $default;
170
						//	Restrict the length of value if necessary.
171
						if(($size != ''))
172-
					break;
172+
						$value = substr($value, 0, $size);
173-
					case 'float':
173+
						break;
174
						case 'float':
175
						$value = isset($_REQUEST[$field['title']]) ? floatval($_REQUEST[$field['title']]) : '';
176
						//	If value is empty then set it to the default.
177
						if(($value == '')
178-
							$value = $default;
178+
179
						$value = $default;
180
						//	Restrict the length of the float value if necessary.
181-
							$value = rtrim(substr($value, 0, $size), '.');
181+
182-
					break;
182+
						$value = rtrim(substr($value, 0, $size), '.');
183-
					case 'radiobox':
183+
						break;
184
						case 'radiobox':
185
						//	Skip this field, if there are no radio select values.
186-
							continue 2;
186+
187
						continue 2;
188
						$value = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : '';
189
						//	Make sure that the radiobox value is in the array, otherwise stop those dodgy users from passing weird values. ;)
190-
							$value = '';
190+
191-
					break;
191+
						$value = '';
192-
					//	Do the formating for both large and normal textboxes. 
192+
						break;
193-
					default:
193+
						//	Do the formating for both large and normal textboxes. 
194
						default:
195
						$value = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : '';
196
						//	If value is empty then set it to the default.
197
						if(($value == '')
198-
							$value = $default;
198+
199
						$value = $default;
200
						//	Only bother with further formating if there is now some text. - This avoids huge errors with the parse_bbc() function returning all bbc. 
201
						if(!($value == ''))
202
						{
203
							//	Remove all bbc code if we don't need to parse it.
204-
								$value = strip_tags(parse_bbc($value, false), '<br>');
204+
205
							$value = strip_tags(parse_bbc($value, false), '<br>');
206
							//	Restrict the length of value if necessary, can stuff up html, but hey...
207-
								$value = substr($value, 0, $size);
207+
208
							$value = substr($value, 0, $size);
209
						}
210-
210+
211-
				//	Do we have an invalid value? Is this field required?
211+
					
212-
				if(($required
212+
					//	Do we have an invalid value? Is this field required?
213-
				&& (($value == '') || ($value == '0'))
213+
					if(($required
214-
				&& ($field['type'] != 'checkbox'))
214+
					&& (($value == '') || ($value == '0'))
215-
				//	Failing for selectboxes is far more simple, If there is no valid value, it fails.
215+
					&& ($field['type'] != 'checkbox'))
216-
				|| (($field['type'] == 'selectbox') && ($value == '')))
216+
					//	Failing for selectboxes is far more simple, If there is no valid value, it fails.
217
					|| (($field['type'] == 'selectbox') && ($value == '')))
218-
					//	Do the 'fail form/field' stuff.
218+
219-
					$data[$i]['failed'] = true;
219+
						//	Do the 'fail form/field' stuff.
220-
					$fail_submit = true;
220+
						$data[$i]['failed'] = true;
221-
					continue;
221+
						$fail_submit = true;
222
						continue;
223
					}
224-
				//	Add this fields value to the list of variables for the output post.
224+
					
225-
				$vars[] = '/\{'.$field['title'].'\}/';
225+
					//	Add this fields value to the list of variables for the output post.
226-
				$replace[] = str_replace('$','\$',$value);
226+
					$vars[] = '/\{'.$field['title'].'\}/';
227-
227+
					$replace[] = str_replace('$','\$',$value);
228-
                //    {{ }} Syntax: Setup REGEX for removing entire {{ }} string or just stripping the outermost { }, depending upon the replacement value being blank or not
228+
					
229-
                if($value == '')
229+
					//    {{ }} Syntax: Setup REGEX for removing entire {{ }} string or just stripping the outermost { }, depending upon the replacement value being blank or not
230-
                {
230+
					if($value == '')
231-
                    $vars_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/'; 
231+
232-
                    $vars_non_blank[] = '//';
232+
						$vars_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/'; 
233-
                }
233+
						$vars_non_blank[] = '//';
234-
                else
234+
235-
                {
235+
					else
236-
                    $vars_blank[] = '//';
236+
237-
                    $vars_non_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/';
237+
						$vars_blank[] = '//';
238-
                }				
238+
						$vars_non_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/';
239-
239+
					}				
240-
				//	Also add this data back into the data array, just in case we can't actually submit the form.
240+
					
241-
				$data[$i]['value'] = $value;
241+
					//	Also add this data back into the data array, just in case we can't actually submit the form.
242
					$data[$i]['value'] = $value;
243-
				//	Do a small fix for the last line, if this is a checkbox.
243+
					
244-
				if($field['type'] == 'checkbox')
244+
					//	Do a small fix for the last line, if this is a checkbox.
245
					if($field['type'] == 'checkbox')
246-
246+
247
					
248
                    if (($required) && (!$data[$i]['value']))
249
                    {
250
                        //   Do the 'fail form/field' stuff.
251
                        $data[$i]['failed'] = true;
252
                        $fail_submit = true;
253-
                    }
253+
254-
254+
255-
				//	Do a small fix for the last line, if this is a largetextbox.
255+
					
256-
				if(($field['type'] == 'largetextbox'))
256+
					//	Do a small fix for the last line, if this is a largetextbox.
257
					if(($field['type'] == 'largetextbox'))
258
					$data[$i]['value'] = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : '';
259-
259+
260-
   // Check whether the visual verification code was entered correctly.
260+
261-
      $context['require_verification'] = $user_info['is_guest'] || !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha']);
261+
				// Check whether the visual verification code was entered correctly.
262-
      if ($context['require_verification'])
262+
				$context['require_verification'] = $user_info['is_guest'] || !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha']);
263
				if ($context['require_verification'])
264
				{
265
					require_once($sourcedir . '/Subs-Editor.php');
266-
				'id' => 'register',
266+
					$verificationOptions = array(
267
					'id' => 'register',
268-
			$context['visual_verification'] = create_control_verification($verificationOptions, true);
268+
					);
269-
269+
					$context['visual_verification'] = create_control_verification($verificationOptions, true);
270-
			if (is_array($context['visual_verification']))
270+
					
271
					if (is_array($context['visual_verification']))
272-
				loadLanguage('Errors');
272+
273-
				foreach ($context['visual_verification'] as $error)
273+
						loadLanguage('Errors');
274-
					fatal_error($txt['error_' . $error], false);
274+
						foreach ($context['visual_verification'] as $error)
275
						fatal_error($txt['error_' . $error], false);
276
					}
277-
277+
278-
			//	Do we have completly valid field data?
278+
279-
			if(!$fail_submit)
279+
				//	Do we have completly valid field data?
280
				if(!$fail_submit)
281-
				require_once($sourcedir.'/Subs-Post.php');
281+
282-
282+
					require_once($sourcedir.'/Subs-Post.php');
283-
                //    {{ }} Syntax: Strip out everything in {{ }} if value is blank
283+
					
284-
                $output = preg_replace($vars_blank, '', $output);
284+
					//    {{ }} Syntax: Strip out everything in {{ }} if value is blank
285-
                $subject = preg_replace($vars_blank, '', $subject);
285+
					$output = preg_replace($vars_blank, '', $output);
286-
286+
					$subject = preg_replace($vars_blank, '', $subject);
287-
                //    {{ }} Syntax: Remove outside brackets if value is not blank
287+
					
288-
                $output = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $output);
288+
					//    {{ }} Syntax: Remove outside brackets if value is not blank
289-
                $subject = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $subject);
289+
					$output = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $output);
290-
290+
					$subject = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $subject);
291-
				//	Replace all vars with their correct value, for both the message and the subject.
291+
					
292-
				$output = preg_replace($vars, $replace, $output);
292+
					//	Replace all vars with their correct value, for both the message and the subject.
293-
				$subject = preg_replace($vars, $replace, $subject);
293+
					$output = preg_replace($vars, $replace, $output);
294-
294+
					$subject = preg_replace($vars, $replace, $subject);
295-
				// Collect all necessary parameters for the creation of the post.
295+
					
296-
				$msgOptions = array(
296+
					// Collect all necessary parameters for the creation of the post.
297
					$msgOptions = array(
298
					'id' =>  0,
299
					'subject' => $subject,
300
					'icon' => $icon,
301
					'body' => $output,
302
					'smileys_enabled' => true,
303-
				$topicId = 0;
303+
					);
304-
                                If (isset($_GET['topic']))
304+
					
305-
                                {
305+
					//Get topicId from GET
306-
                                   $topicId = $_GET['topic'];
306+
					$topicId = 0;
307-
                                }
307+
					If (isset($_SESSION['topic']))
308-
308+
309-
				$topicOptions = array(
309+
						$topicId = $_SESSION['topic'];
310
					}
311
					
312
					$topicOptions = array(
313
					'id' => $topicId,
314
					'board' => $board,
315-
				$posterOptions = array(
315+
316
					);
317
					
318
					$posterOptions = array(
319-
				//	Finally create the post!!! :D
319+
320-
				$newTopicId = createPost($msgOptions, $topicOptions, $posterOptions);
320+
					);
321-
				print_r($newTopicId);die;
321+
					
322-
322+
					//	Finally create the post!!! :D
323-
				//	Redirect this user as well.
323+
					$newTopicId = createPost($msgOptions, $topicOptions, $posterOptions);
324-
				if ($exit == 'board' || $exit == '')
324+
					print_r($newTopicId);die;
325-
				  redirectexit('board=' . $board . '.0');
325+
					
326-
				elseif ($exit == 'forum')
326+
					//	Redirect this user as well.
327-
				  redirectExit();
327+
					if ($exit == 'board' || $exit == '')
328-
				elseif ($exit == 'form')
328+
					redirectexit('board=' . $board . '.0');
329-
				  redirectExit("action=form;");
329+
					elseif ($exit == 'forum')
330-
				elseif ($exit == 'thanks')
330+
					redirectExit();
331-
				  redirectExit("action=form;thankyou");
331+
					elseif ($exit == 'form')
332-
				else
332+
					redirectExit("action=form;");
333-
				  redirectexit("$exit");
333+
					elseif ($exit == 'thanks')
334
					redirectExit("action=form;thankyou");
335
					else
336
					redirectexit("$exit");
337-
		//	Otherwise we shall show the submit form page.
337+
338-
		$context['fields'] = array();
338+
339
			
340-
		//	Okay, lets format the field data.
340+
			//	Otherwise we shall show the submit form page.
341-
		foreach($data as $field)
341+
			$context['fields'] = array();
342
			
343
			//	Okay, lets format the field data.
344-
			$size = false;
344+
345-
			$type_vars = ($field['type_vars'] != '') ? explode(',', $field['type_vars']) : array();
345+
346-
			$vars = array();
346+
347-
			$required = false;
347+
				$size = false;
348
				$type_vars = ($field['type_vars'] != '') ? explode(',', $field['type_vars']) : array();
349-
			//	Go through all of the type_vars to format them correctly.
349+
				$vars = array();
350-
			if(!empty($type_vars))
350+
				$required = false;
351
				
352
				//	Go through all of the type_vars to format them correctly.
353
				if(!empty($type_vars))
354
				foreach($type_vars as $var)
355
				{
356
					//	Remove whitespace from vars, to avoid unwanted issues.
357-
						$vars[] = $var;
357+
358
					//	Add them to the vars list, in the correct format for the template.
359
					if($var != '')
360-
						$required = true;
360+
					$vars[] = $var;
361
					//	Check to see if this field is required.
362
					if($var == 'required')
363-
			//	Make sure that we have valid options, if this is a selectbox.
363+
					$required = true;
364-
			if(($field['type'] == 'selectbox')
364+
365-
			&& empty($vars))
365+
366
				//	Make sure that we have valid options, if this is a selectbox.
367-
367+
				if(($field['type'] == 'selectbox')
368-
			//	Make sure that we have valid options, if this is a radiobox.
368+
				&& empty($vars))
369-
			if(($field['type'] == 'radiobox')
369+
370-
			&& empty($vars))
370+
371
				//	Make sure that we have valid options, if this is a radiobox.
372-
372+
				if(($field['type'] == 'radiobox')
373-
			//	Store any previous values for the template to look after.
373+
				&& empty($vars))
374-
			if(isset($field['value']))
374+
375
				
376
				//	Store any previous values for the template to look after.
377-
			//	Finally put the data for this field into the $context['field'] array for the 'submit form' template functions.
377+
				if(isset($field['value']))
378-
			$context['fields'][$field['title']] = array(
378+
379
				
380
				//	Finally put the data for this field into the $context['field'] array for the 'submit form' template functions.
381
				$context['fields'][$field['title']] = array(
382
				'text' => $field['text'],
383
				'type' => $field['type'],
384
				'data' => $vars,
385
				'value' => isset($field['value']) ? $field['value'] : '',
386
				'required' => $required,
387
				'failed' => isset($field['failed']),
388-
		//	Do we have fields data? If not then redirect the user to the form view page.
388+
389-
		if(empty($context['fields']))
389+
390
			
391
			//	Do we have fields data? If not then redirect the user to the form view page.
392-
		//	Load the language files.
392+
			if(empty($context['fields']))
393-
		loadLanguage('Modifications');
393+
394
			
395-
		//	Setup and load the necessary template related stuff.
395+
			//	Load the language files.
396-
		$context['settings_title'] = '<a href="'.$scripturl.'?action=form;">'.((isset($modSettings['CustomForm_view_title']) && ($modSettings['CustomForm_view_title'] != '')) ? $modSettings['CustomForm_view_title'] : $txt['CustomForm_tabheader']) . '</a> : ' . $form_title;
396+
			loadLanguage('Modifications');
397-
		$context['failed_form_submit'] = $fail_submit;
397+
398-
		$context['template_function'] = $form_data['template_function'];
398+
			//	Setup and load the necessary template related stuff.
399-
		$context['post_url'] = $scripturl.'?action=form;n='.$form_id.';submit;';
399+
			$context['settings_title'] = '<a href="'.$scripturl.'?action=form;">'.((isset($modSettings['CustomForm_view_title']) && ($modSettings['CustomForm_view_title'] != '')) ? $modSettings['CustomForm_view_title'] : $txt['CustomForm_tabheader']) . '</a> : ' . $form_title;
400-
		$context['sub_template'] = 'submit_form';
400+
			$context['failed_form_submit'] = $fail_submit;
401-
		loadTemplate('CustomForm');
401+
			$context['template_function'] = $form_data['template_function'];
402
			$context['post_url'] = $scripturl.'?action=form;n='.$form_id.';submit;';
403-
	//	If not then fall to the default view form page, with the list of forms.
403+
			$context['sub_template'] = 'submit_form';
404-
	else
404+
			loadTemplate('CustomForm');
405
		}
406-
		//	Wait a second... Are you even allowed to view the form list?
406+
		//	If not then fall to the default view form page, with the list of forms.
407-
		if(!allowedTo('CustomForm_view_perms'))
407+
		else
408
		{
409
			//	Wait a second... Are you even allowed to view the form list?
410-
		//	Declare the array of data which we need to pass to the template.
410+
			if(!allowedTo('CustomForm_view_perms'))
411-
		$context['custom_forms_list'] = array();
411+
412
			
413-
		//	Firstly get a list of all the fields from the cf_fields table.
413+
			//	Declare the array of data which we need to pass to the template.
414-
		$request = $smcFunc['db_query']('','
414+
			$context['custom_forms_list'] = array();
415
			
416
			//	Firstly get a list of all the fields from the cf_fields table.
417
			$request = $smcFunc['db_query']('','
418
			SELECT id_form
419
			FROM {db_prefix}cf_fields
420-
		);
420+
421
			AND text != \'\'
422-
		$forms = array();
422+
423
			);
424-
		while($row = $smcFunc['db_fetch_assoc']($request))
424+
425
			$forms = array();
426-
		$smcFunc['db_free_result']($request);
426+
427
			while($row = $smcFunc['db_fetch_assoc']($request))
428-
		//	Get the data from the cf_forms table.
428+
429-
		$request = $smcFunc['db_query']('','
429+
			$smcFunc['db_free_result']($request);
430
			
431
			//	Get the data from the cf_forms table.
432
			$request = $smcFunc['db_query']('','
433
			SELECT f.id_form, f.title, b.name, b.id_board
434-
		);
434+
435-
435+
436-
		//	Go through all of the forms and add them to the list.
436+
437-
		while($row = $smcFunc['db_fetch_assoc']($request))
437+
438
			
439-
			//	Wait. Are you allowed to view/use this form?
439+
			//	Go through all of the forms and add them to the list.
440-
			if(!allowedTo('custom_forms_'.$row['id_form']))
440+
			while($row = $smcFunc['db_fetch_assoc']($request))
441
			{
442
				//	Wait. Are you allowed to view/use this form?
443-
			//	Did we get some fields from this form?
443+
				if(!allowedTo('custom_forms_'.$row['id_form']))
444-
			if(!in_array($row['id_form'], $forms))
444+
445
				
446
				//	Did we get some fields from this form?
447-
			//	Add this forms data, for the template to show.
447+
				if(!in_array($row['id_form'], $forms))
448-
			$context['custom_forms_list'][] = array(
448+
449
				
450
				//	Add this forms data, for the template to show.
451
				$context['custom_forms_list'][] = array(
452
				'id' => $row['id_form'],
453
				'title' => $row['title'],
454
				'id_board' => $row['id_board'],
455
				'board' => $row['name'],
456-
		//	Free the db request.
456+
457-
		$smcFunc['db_free_result']($request);
457+
458-
458+
459-
		//	Finally load the necessary template for this action.	
459+
			//	Free the db request.
460-
		$context['sub_template'] = 'FormList';
460+
			$smcFunc['db_free_result']($request);
461-
		loadTemplate('CustomForm');
461+
462-
462+
			//	Finally load the necessary template for this action.	
463
			$context['sub_template'] = 'FormList';
464-
464+
			loadTemplate('CustomForm');
465-
	//	Set the page title, just for lolz! :D
465+
466-
	$context['page_title'] = (isset($modSettings['CustomForm_view_title']) && ($modSettings['CustomForm_view_title'] != '')) ? $modSettings['CustomForm_view_title'] : $txt['CustomForm_tabheader'];
466+
467-
}
467+
468
		//	Set the page title, just for lolz! :D
469
		$context['page_title'] = (isset($modSettings['CustomForm_view_title']) && ($modSettings['CustomForm_view_title'] != '')) ? $modSettings['CustomForm_view_title'] : $txt['CustomForm_tabheader'];
470
	}
471
?>