forked from riprap/Survey-Ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_survey.php
107 lines (78 loc) · 3.09 KB
/
edit_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
<?php
/*
File Name: edit_survey.php
Authors Name: Scott Montgomery and Nolan Knill
Web Site Name: Survey Site
File Description: The page that allows a user to edit an instance of a survey.
*/
$page_name = "Edit Survey";
include "functions/functions.php";
//Including this partial will set the value of the $survey_number, $survey, $survey_type and $questions
include 'partials/get_survey.php';
$survey_name = $survey['name'];
if ($logged_in_profile['id'] != $survey['creator_id']) {
set_message("error", "You do not have permission to edit this survey.");
header('Location: index.php');
die;
}
list($start_day, $start_month, $start_year) = get_date_params($survey['start_date']);
list($end_day, $end_month, $end_year) = get_date_params($survey['end_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";
//If there are no validation errors attempt to create the survey
if (empty($errors)) :
update_survey($survey['id'], $survey_name, $start_date, $end_date);
set_message("success", "Survey has been updated.");
header('Location: index.php');
die;
endif;
endif; //End the if statement to deal with form processing
?>
<?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>
<br/>
<?php echo create_hidden_survey_id_field($survey['id']); ?>
<input type="submit" value="Update" class="button">
</form>
</div>
<?php include 'partials/sidebar.php' ?>
</div>
<?php include 'partials/footer.php'; ?>
</body>
</html>