PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/branch/2.0.2/system/application/controllers/surveyBuilder.php

http://records-authority.googlecode.com/
PHP | 315 lines | 154 code | 34 blank | 127 comment | 25 complexity | f6363d9acaba6edd9851a5741c5c3590 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Copyright 2011 University of Denver--Penrose Library--University Records Management Program
  4. * Author evan.blount@du.edu and fernando.reyes@du.edu
  5. *
  6. * This file is part of Records Authority.
  7. *
  8. * Records Authority is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Records Authority is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Records Authority. If not, see <http://www.gnu.org/licenses/>.
  20. **/
  21. class SurveyBuilder extends CI_Controller {
  22. public function __construct() {
  23. parent::__construct();
  24. }
  25. /**
  26. * adds survey name to database
  27. *
  28. * @access public
  29. * @param $_POST
  30. * @return void
  31. */
  32. public function addSurveyName() {
  33. // remove smart quotes
  34. $this->load->library('convertsmartquotes');
  35. $_POST = $this->convertsmartquotes->convert($_POST);
  36. $surveyName = array('surveyName'=>$_POST['surveyName'],
  37. 'surveyDescription'=>$_POST['surveyDescription']
  38. );
  39. $surveyID['surveyID'] = $this->SurveyBuilderModel->addSurveyName($surveyName);
  40. $id = $surveyID['surveyID'];
  41. //redirect
  42. $url = site_url();
  43. $data['refresh'] = header("Refresh: 0; url=$url/dashboard/addSurveyQuestions/$id");
  44. $data['message'] = "<p><strong>Creating Survey...</strong></p>";
  45. $this->load->view('includes/redirect', $data);
  46. }
  47. /**
  48. * adds survey Question to database
  49. *
  50. * @access public
  51. * @param $_POST
  52. * @return $id / echo's questionID for use by jQuery
  53. */
  54. public function addSurveyQuestion() {
  55. $surveyQuestion = array('surveyID'=>$this->input->post('surveyID'),
  56. 'question'=>$this->input->post('question'),
  57. 'fieldTypeID'=>$this->input->post('fieldTypeID'),
  58. 'subQuestion'=>$this->input->post('subQuestion'),
  59. 'required'=>$this->input->post('required'),
  60. 'questionType'=>$this->input->post('questionType')
  61. );
  62. $questionID['questionID'] = $this->SurveyBuilderModel->addSurveyQuestion($surveyQuestion);
  63. $id = $questionID['questionID'];
  64. echo $id;
  65. }
  66. /**
  67. * adds survey Sub Question to database
  68. *
  69. * @access public
  70. * @param $_POST
  71. * @return void
  72. */
  73. public function addSurveySubQuestion() {
  74. $surveySubQuestion = array('questionID'=>$this->input->post('questionID'),
  75. 'fieldTypeID'=>$this->input->post('fieldTypeID'),
  76. 'subQuestion'=>$this->input->post('subQuestion'),
  77. 'subChoiceQuestionCheck'=>$this->input->post('subChoiceQuestionCheck'),
  78. 'toggle'=>$this->input->post('toggle')
  79. );
  80. $surveySubChoiceQuesiton = array('subChoiceQuestion'=>$this->input->post('subChoiceQuestion'),
  81. 'fieldTypeID'=>$this->input->post('subFieldTypeID'),
  82. 'toggle'=>$this->input->post('toggle')
  83. );
  84. $this->SurveyBuilderModel->addSurveySubQuestion($surveySubQuestion, $surveySubChoiceQuesiton);
  85. }
  86. /**
  87. * saves survey Sub Question to database
  88. *
  89. * @access public
  90. * @param $_POST
  91. * @return void
  92. */
  93. public function addSurveyContactQuestion() {
  94. $surveyContactQuestion = array('surveyID'=>$this->input->post('surveyID'),
  95. 'contactQuestion'=>$this->input->post('contactQuestion'),
  96. 'questionType'=>$this->input->post('questionType'),
  97. );
  98. $contactQuestionID['contactQuestionID'] = $this->SurveyBuilderModel->addSurveyContactQuestion($surveyContactQuestion);
  99. $id = $contactQuestionID['contactQuestionID'];
  100. echo $id; // results pulled into view via jQuery AJAX
  101. }
  102. /**
  103. * saves survey contact field to database
  104. *
  105. * @access public
  106. * @param $_POST
  107. * @return void
  108. */
  109. public function addSurveyContactField() {
  110. $surveyContactField = array('contactQuestionID'=>$this->input->post('contactQuestionID'),
  111. 'contactField'=>$this->input->post('contactField'),
  112. 'fieldTypeID'=>$this->input->post('fieldTypeID'),
  113. 'required'=>$this->input->post('required')
  114. );
  115. $this->SurveyBuilderModel->addSurveyContactField($surveyContactField);
  116. }
  117. /**
  118. * gets survey questions
  119. *
  120. * @access public
  121. * @param $surveyID
  122. * @return void
  123. */
  124. public function getSurveyQuestions() {
  125. $surveyID = $this->uri->segment(3, 0);
  126. if ($surveyID == 0) {
  127. echo 'An error occured. Unable to generate survey questions.';
  128. } else {
  129. $this->SurveyBuilderModel->getSurveyQuestions($surveyID);
  130. }
  131. }
  132. /**
  133. * re-orders survey question **NOT USED**
  134. *
  135. * @access public
  136. * @param $surveyID
  137. * @return void
  138. */
  139. public function reorderSurveyQuestions() {
  140. $surveyID = $this->uri->segment(3, 0);
  141. if ($surveyID == 0) {
  142. echo 'An error occured. Unable to generate survey questions.';
  143. } else {
  144. print_r($_POST);
  145. echo "<br /><br /><br /><br />";
  146. foreach ($_POST as &$field) {
  147. echo $field . "<br />";
  148. }
  149. }
  150. }
  151. /**
  152. * generates survey
  153. *
  154. * @access public
  155. * @param $surveyID
  156. * @param $action / could be publish or preview
  157. * @return void
  158. */
  159. public function generateSurvey() {
  160. $surveyID = $this->uri->segment(3, 0);
  161. // action = preview / publish
  162. $action = $this->uri->segment(4, 0);
  163. if ($surveyID == 0) {
  164. echo 'An error occured. Unable to generate survey.';
  165. } elseif ($action == "publish") {
  166. // check session exists
  167. $siteUrl = site_url();
  168. $this->load->library('session');
  169. $loginUrl = $siteUrl;
  170. $isLoggedIn = $this->session->userdata('isLoggedIn');
  171. //if session does not exist...send user to login form
  172. if (!isset($isLoggedIn) || $isLoggedIn != TRUE){
  173. header("Location: $loginUrl");
  174. exit();
  175. }
  176. }
  177. $surveyHtml = $this->SurveyBuilderModel->generateSurvey($surveyID);
  178. if ($action == "publish") {
  179. $data['surveyHtml'] = $surveyHtml;
  180. $this->load->view('public/forms/surveyForm', $data);
  181. } elseif ($action == "preview") {
  182. echo $surveyHtml; // results pulled into view via jQuery AJAX
  183. }
  184. }
  185. /**
  186. * edits survey questions
  187. *
  188. * @access public
  189. * @return $formHtml
  190. */
  191. public function editSurveyQuestions() {
  192. $this->load->model('JsModel');
  193. $popUpParams = $this->JsModel->popUp();
  194. $surveyID = $this->uri->segment(3, 0);
  195. $formHtml = $this->SurveyBuilderModel->editSurveyQuestions($surveyID, $popUpParams);
  196. echo $formHtml; // results pulled into view via jQuery AJAX
  197. }
  198. /**
  199. * edits survey sub questions
  200. *
  201. * @access public
  202. * @return $formHtml
  203. */
  204. public function editSurveySubQuestions() {
  205. $questionID = $this->uri->segment(3, 0);
  206. $formHtml = $this->SurveyBuilderModel->editSurveySubQuestions($questionID);
  207. echo $formHtml; // results pulled into view via jQuery AJAX
  208. }
  209. /**
  210. * edits sub choice questions
  211. *
  212. * @access public
  213. * @return $formHtml
  214. */
  215. public function editSurveySubChoiceQuestions() {
  216. $subQuestionID = $this->uri->segment(3, 0);
  217. $formHtml = $this->SurveyBuilderModel->editSurveySubChoiceQuestions($subQuestionID);
  218. echo $formHtml; // results pulled into view via jQuery AJAX
  219. }
  220. /**
  221. * updates survey
  222. *
  223. * @access public
  224. * @return void
  225. */
  226. public function updateSurvey() {
  227. // updates survey description
  228. if (isset($_POST['surveyID']) && isset($_POST['descriptionID'])) {
  229. $this->SurveyBuilderModel->updateSurveyDescription($_POST);
  230. }
  231. // updates survey question
  232. if (isset($_POST['questionID']) && !isset($_POST['subQuestionID'])) {
  233. $this->SurveyBuilderModel->updateSurveyQuestion($_POST);
  234. }
  235. // updates survey sub question
  236. if (isset($_POST['subQuestionID']) && isset($_POST['questionID'])) {
  237. $this->SurveyBuilderModel->updateSurveySubQuestion($_POST);
  238. }
  239. // updates survey sub choice question
  240. if (isset($_POST['subChoiceQuestionID'])) {
  241. $this->SurveyBuilderModel->updateSurveySubChoiceQuestion($_POST);
  242. }
  243. }
  244. /**
  245. * deletes survey question
  246. *
  247. * @access public
  248. * @return void
  249. */
  250. public function deleteSurveyQuestion() {
  251. if ($_POST['questionID']) {
  252. $questionID = trim($_POST['questionID']);
  253. $this->SurveyBuilderModel->deleteSurveyQuestion($questionID);
  254. }
  255. }
  256. /**
  257. * deletes survey sub question
  258. *
  259. * @access public
  260. * @return void
  261. */
  262. public function deleteSurveySubQuestion() {
  263. if ($_POST['subQuestionID']) {
  264. $subQuestionID = trim($_POST['subQuestionID']);
  265. $this->SurveyBuilderModel->deleteSurveySubQuestion($subQuestionID);
  266. }
  267. }
  268. /**
  269. * deletes survey sub choice question
  270. *
  271. * @access public
  272. * @return void
  273. */
  274. public function deleteSurveySubChoiceQuestion() {
  275. if ($_POST['subChoiceQuestionID']) {
  276. $subChoiceQuestionID = trim($_POST['subChoiceQuestionID']);
  277. $this->SurveyBuilderModel->deleteSurveySubChoiceQuestion($subChoiceQuestionID);
  278. }
  279. }
  280. }
  281. ?>