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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
<?php
function feedback_menu() {
$items = array();
$items["feedback"] = array(
"title" => "Oscad workshop feedback form.",
"page callback" => "feedback_all",
"access arguments" => array("access feedback"),
"type" => MENU_CALLBACK
);
$items["feedback/thank-you"] = array(
"title" => "Thank you",
"page callback" => "feedback_thank_you_all",
"access arguments" => array("access feedback"),
"type" => MENU_CALLBACK
);
return $items;
}
function feedback_perm() {
return array(
"access feedback",
);
}
function feedback_form($form_state) {
$form = array();
$form["wrapper"] = array(
'#type' => "fieldset",
"#title" => t("
(Feedback form for the Oscad workshop conducted on
10th May 2014 at PESIT, Bangalore.)
"),
"#prefix" => "<div class='feedback-form'>",
"#suffix" => "</div>",
);
$form["wrapper"]["first_name"] = array(
"#type" => "textfield",
"#title" => t("First name"),
"#required" => TRUE
);
$form["wrapper"]["last_name"] = array(
"#type" => "textfield",
"#title" => t("Last name"),
"#required" => TRUE
);
$form["wrapper"]["email"] = array(
"#type" => "textfield",
"#title" => t("Email"),
"#required" => FALSE
);
$form["wrapper"]["phone"] = array(
"#type" => "textfield",
"#title" => t("Phone"),
"#required" => FALSE
);
$form["wrapper"]["institution"] = array(
"#type" => "textfield",
"#title" => t("Institution/College"),
"#required" => TRUE
);
$form["wrapper"]["activities"] = array(
"#type" => "checkboxes",
"#title" => t("
1. Which of the following activities are you interested to
contribute to (Tick all that are applicable.)?
"),
"#options" => get_activities(),
"#required" => TRUE
);
$form["wrapper"]["rating"] = array(
"#type" => "radios",
"#title" => t("
2. How would you rate this workshop on a scale of 5?
"),
"#options" => array_combine(range(1, 5), range(1, 5)),
"#required" => TRUE
);
$form["wrapper"]["liked"] = array(
"#type" => "textarea",
"#title" => t("3. Things that you liked in Oscad workshop"),
"#required" => TRUE
);
$form["wrapper"]["disliked"] = array(
"#type" => "textarea",
"#title" => t("4. Things that you disliked in Oscad workshop"),
"#required" => TRUE
);
$form["wrapper"]["difficulties"] = array(
"#type" => "textarea",
"#title" => t("
5. Did you face any difficulties while using Oscad?
"),
"#required" => TRUE
);
$form["wrapper"]["platform"] = array(
"#type" => "radios",
"#title" => t("6. On which platform do you use Oscad?"),
"#options" => array(
t("GNU/Linux"),
t("Windows"),
t("Both")
),
"#required" => TRUE
);
$form["wrapper"]["missing"] = array(
"#type" => "textarea",
"#title" => t("7. Any feature you find missing in Oscad?"),
"#required" => TRUE
);
$form["wrapper"]["workshop"] = array(
"#type" => "radios",
"#title" => t("
8. Would you like to have a workshop
on advanced features of Oscad?
"),
"#options" => array(
t("Yes"), t("No")
),
"#required" => TRUE
);
$form["wrapper"]["future"] = array(
"#type" => "radios",
"#title" => t("
9. Can we contact you in the future to
know your experience with Oscad?
"),
"#options" => array(
t("Yes"), t("No")
),
"#required" => TRUE
);
$form["wrapper"]["contact"] = array(
"#type" => "textarea",
"#title" => t("
10. Please provide your contact details if you
selected 'Yes' in question 8 or 9.
"),
"#required" => FALSE
);
$form["wrapper"]["magazines"] = array(
"#type" => "textarea",
"#title" => t("
11. In order to inform the college teachers and students
about Oscad, we plan to place advertisements.
Which technical magazines do you read?
"),
"#required" => FALSE
);
$form["wrapper"]["suggestion"] = array(
"#type" => "textarea",
"#title" => t("
12. Any other Suggestions / Feedback / Appreciation
"),
"#required" => FALSE
);
$form["wrapper"]["submit"] = array(
"#type" => "submit",
"#value" => "Submit"
);
return $form;
}
function feedback_form_validate($form, &$form_state) {
/* making contact field required if 'Yes' in workshop/future field */
$v = $form_state["values"];
if(($v["workshop"] == 0 || $v["future"] == 0) && $v["contact"] == "") {
form_set_error("contact", "
10. Please provide your contact details if you selected 'Yes'
in question 8 or 9. This field is required since you selected
'Yes' in question 8 or 9.
");
}
if($v["email"] && !valid_email_address($v["email"])) {
form_set_error("email", "Please enter a valid email id.");
}
if($v["phone"] && !is_numeric($v["phone"])) {
form_set_error("phone", "Please enter a valid phone number. (Only digits allowed)");
}
}
function feedback_form_submit($form, &$form_state) {
/* escaping special characters */
foreach($form_state["values"] as $key => $value) {
if(gettype($value) == "string") {
$form_state["values"][$key] = db_escape_string($value);
}
}
$v = $form_state["values"];
$v["activities"] = implode(",", array_filter($v["activities"]));
$query = "
INSERT INTO feedback (
first_name, last_name, email, phone, institution, activities,
rating, liked, disliked, difficulties, platform, missing,
workshop, future, contact, magazines, suggestion
) VALUES (
'{$v["first_name"]}', '{$v["last_name"]}', '{$v["email"]}',
'{$v["phone"]}', '{$v["institution"]}', '{$v["activities"]}',
{$v["rating"]}, '{$v["liked"]}', '{$v["disliked"]}',
'{$v["difficulties"]}', {$v["platform"]}, '{$v["missing"]}',
{$v["workshop"]}, {$v["future"]}, '{$v["contact"]}',
'{$v["magazines"]}', '{$v["suggestion"]}'
)
";
$result = db_query($query);
drupal_goto("feedback/thank-you");
}
function feedback_all() {
$page_content = "";
$page_content .= "
<div style='color: red;'>
<sup>*</sup> Required
</div>
";
$page_content .= drupal_get_form("feedback_form");
return $page_content;
}
function feedback_thank_you_all() {
$page_content = "";
$page_content .= "<br>";
$page_content .= l("Click here", "feedback");
$page_content .= " to submit another feedback.";
drupal_set_message("Feedback recorded successfully.");
return $page_content;
}
function feedback_init() {
drupal_add_css(drupal_get_path("module", "feedback") . "/css/feedback.css");
}
/* helper functions */
function get_activities() {
return array(
1 => t("Creating a textbook companion (TBC)"),
2 => t("Migrating your lab to Oscad (LM)"),
3 => t("Adding to component library (CL)"),
4 => t("Doing projects (BE, M.Sc, ME, Ph.D) with Oscad"),
5 => t("Review of the above (TBC, LM, CL, projects)"),
6 => t("Building hardware using Oscad and testing"),
7 => t("Enhancing the capabilities of Oscad - need IT expertise"),
8 => t("Creation of Spoken Tutorials on Oscad"),
9 => t("Promoting Oscad"),
);
}
?>
|