CMS  Version 3.9
survey_question_form.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4 Copyright (c) 2007,2008 Sonjara, Inc
5 
6 Permission is hereby granted, free of charge, to any person
7 obtaining a copy of this software and associated documentation
8 files (the "Software"), to deal in the Software without
9 restriction, including without limitation the rights to use,
10 copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following
13 conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 Except as contained in this notice, the name(s) of the above
19 copyright holders shall not be used in advertising or otherwise
20 to promote the sale, use or other dealings in this Software
21 without prior written authorization.
22 
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 /*
35  * Description: Form to add/update/delete a survey question.
36  * Can be used for either defining standard questions for
37  * question sets or to create a custom question within a survey.
38  *
39  * author: Janice Gallant for Sonjara, Inc.
40  *
41  * date: 10/17/2010
42  *
43  */
44 
45 Fakoli::using("survey", "questionnaire");
46 Fakoli::usingFeature("auto_form");
47 
48 $survey_question_id = checkNumeric($_GET["survey_question_id"]);
49 $survey_id = checkNumeric($_GET["survey_id"]);
50 
52 
53 if(!$survey_id)
54 {
55  redirect("survey_dashboard");
56 }
57 
59 
61 {
63 }
64 else
65 {
66  $question->setDefaultValues();
67 
68 }
69 
70 $page->page_title .= " for {$survey->title}";
71 
72 // check if question has been answered
73 $editable = $question->isEditable();
74 
75 $redirect = "survey_questions?survey_id=$survey_id";
76 
77 $form = new AutoForm($question);
78 $form->required("question");
79 $form->annotate("options", "<br><span class='annotate'>List each option on a separate line.</span>");
80 $form->getRenderer("question")->height = "100px";
81 
83 QuestionFormHelper::questionTypeSetup($form, $editable);
84 
86 {
87  $form->button("Remove", "questionnaireMgr.removeQuestionFromForm($survey_question_id)", "Are you sure you want to remove this question?", true);
88 }
89 $form->button("Cancel", $redirect);
90 $form->hide("question_name");
91 $form->data->set("survey_id", $survey_id);
92 
93 if(!$editable)
94 {
95  $infoText = "<i>Note:&nbsp;</i>This question has been answered. You may edit the question but be careful not to change its meaning.";
96 }
97 
99 {
100  $form->onSaveComplete = saveSurveyQuestionXref;
101 }
102 
104 $tabs->page = "survey_questions";
105 $tabs->active = "Questions";
106 
107 if ($method == "POST")
108 {
109  if ($form->save())
110  {
111  redirect($redirect);
112  }
113 }
114 
115 
116 $script .= $form->writeScript();
117 $script .= $mgr->writeScript();
118 $script .= QuestionFormHelper::writeScript($form);
119 
121 {
122  $tabs->writeHTML();
123 
124  ?>
125 <div id="survey_tab_border"><?
126 }
127 
128 echo "<b>{$infoText}</b>";
129 
130 $form->drawForm();
131 
133 {
134  $mgr = new SurveyCreateManager(new Survey($form->data->get("survey_id")));
135  $mgr->saveQuestionXref($form->data);
136 }
137 ?></div>
$page
Definition: help.inc:39
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static surveyTabs($key="")
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$survey_question_id
if(! $survey_id) $survey
if(! $editable) if(! $survey_question_id) $tabs
saveSurveyQuestionXref($form)
if($method=="POST") $script