/
create_survey.php
121 lines (94 loc) · 3.53 KB
/
create_survey.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
File Name: create_survey.php
Authors Name: Scott Montgomery and Nolan Knill
Web Site Name: Survey Site
File Description: The page that allows a user to create a new instance of a survey.
*/
$page_name = "Create Survey";
include "functions/functions.php";
$survey_name = '';
//Get the values for the current date
list($start_day, $start_month, $start_year) = get_current_date();
list($end_day, $end_month, $end_year) = get_tomorrow_date();
// if the user submitted the form (with method="post")
if (!empty($_POST)) :
if (empty($_POST['name'])) :
$errors[] = "Please enter the survey name.";
$field_errors[] = 'name';
endif;
//Including this partial will validate the date fields for start_date and end_date. It will set the values of $start_date and $end_date
include "partials/date_validation.php";
$question_count = $_POST['question_count'];
$survey_type = $_POST['survey_type'];
$survey_name = $_POST['name'];
//If there are no validation errors attempt to create the survey
if (empty($errors)) :
//Create survey and get the id
$survey_id = add_survey($survey_name, $survey_type, $logged_in_profile['id'], $start_date, $end_date, $question_count);
set_message("success", "Survey has been created");
header('Location: add_questions.php?survey='.$survey_id);
endif;
endif;
?>
<?php include 'partials/html_header.php'; ?>
<body>
<?php include 'partials/header.php'; ?>
<div class="row">
<div class="large-9 columns" role="content">
<h3>
<?php echo $page_name;?>
</h3>
<?php include 'partials/messages.php'; ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label>Survey Name:</label>
<input type="text" name="name" <?php echo check_field_errors('name', $field_errors); ?> value="<?php echo $survey_name; ?>">
<label>Start Date:</label>
<select name="start_month">
<?php echo create_month_dropdown($start_month);?>
</select>
<select name="start_day">
<?php echo create_day_dropdown($start_day); ?>
</select>
<select name="start_year" id="year">
<?php echo create_year_dropdown($start_year); ?>
</select>
<label>End Date:</label>
<select name="end_month">
<?php echo create_month_dropdown($end_month); ?>
</select>
<select name="end_day">
<?php echo create_day_dropdown($end_day); ?>
</select>
<select name="end_year" id="year">
<?php echo create_year_dropdown($end_year); ?>
</select>
<label>Survey type:</label>
<select name="survey_type">
<?php
if (isset($survey_type)) {
echo create_survey_type_dropdown($survey_type);
}
else {
echo create_survey_type_dropdown();
}
?>
</select>
<label>Number of Questions:</label>
<select name="question_count">
<?php
if (isset($question_count)) {
echo create_day_dropdown($question_count);
} else {
echo create_day_dropdown();
}
?>
</select><br/>
<input type="submit" value="Create Survey" class="button">
</form>
</div>
<?php include 'partials/sidebar.php' ?>
</div>
<?php include 'partials/footer.php'; ?>
</body>
</html>