survey_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author unknown
  19. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  20. * @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
  21. *
  22. * @todo The ansTarget column is not done
  23. * @todo try to understand the white, blue, ... template stuff.
  24. * @todo use quickforms for the forms
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'survey';
  28. // including the global dokeos file
  29. require ('../inc/global.inc.php');
  30. // including additional libraries
  31. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  32. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  33. /** @todo replace this with the correct code */
  34. /*
  35. $status = surveymanager::get_status();
  36. api_protect_course_script();
  37. if($status==5)
  38. {
  39. api_protect_admin_script();
  40. }
  41. */
  42. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  43. if (!api_is_allowed_to_edit())
  44. {
  45. Display :: display_header();
  46. Display :: display_error_message(get_lang('NotAllowedHere'));
  47. Display :: display_footer();
  48. exit;
  49. }
  50. // Database table definitions
  51. /** @todo use database constants for the survey tables */
  52. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  53. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  54. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  55. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  56. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  57. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  58. // language variables
  59. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  60. {
  61. $tool_name = get_lang('SearchASurvey');
  62. }
  63. else
  64. {
  65. $tool_name = get_lang('Survey');
  66. }
  67. // Header
  68. Display :: display_header($tool_name);
  69. //api_display_tool_title($tool_name);
  70. // Action handling: searching
  71. if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
  72. {
  73. display_survey_search_form();
  74. }
  75. // Action handling: deleting a survey
  76. if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
  77. {
  78. $return = SurveyManager::delete_survey($_GET['survey_id']);
  79. if ($return)
  80. {
  81. Display :: display_confirmation_message(get_lang('SurveyDeleted'));
  82. }
  83. else
  84. {
  85. Display :: display_error_message(get_lang('ErrorOccurred'));
  86. }
  87. }
  88. // Action handling: performing the same action on multiple surveys
  89. if ($_POST['action'])
  90. {
  91. if (is_array($_POST['id']))
  92. {
  93. foreach ($_POST['id'] as $key=>$value)
  94. {
  95. SurveyManager::delete_survey($value);
  96. }
  97. Display :: display_confirmation_message(get_lang('SurveyDeleted'));
  98. }
  99. else
  100. {
  101. Display :: display_error_message(get_lang('NoSurveysSelected'));
  102. }
  103. }
  104. // Action links
  105. echo '<a href="create_new_survey.php?action=add">'.get_lang('CreateNewSurvey').'</a> | ';
  106. echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> | ';
  107. echo '<a href="'.$_SERVER['PHP_SELF'].'?search=advanced">'.get_lang('Search').'</a>';
  108. // Main content
  109. display_survey_list();
  110. // Footer
  111. Display :: display_footer();
  112. /**
  113. * This function displays the form for searching a survey
  114. *
  115. * @return html code
  116. *
  117. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  118. * @version January 2007
  119. *
  120. * @todo use quickforms
  121. * @todo consider moving this to surveymanager.inc.lib.php
  122. */
  123. function display_survey_search_form()
  124. {
  125. echo '<form method="get" action="survey_list.php?search=advanced">';
  126. echo '<table>
  127. <tr>
  128. <td>'.get_lang('Title').'</td>
  129. <td><input type="text" name="keyword_title"/></td>
  130. </tr>
  131. <tr>
  132. <td>'.get_lang('Code').'</td>
  133. <td><input type="text" name="keyword_code"/></td>
  134. </tr>
  135. <tr>
  136. <td>'.get_lang('Language').'</td>
  137. <td>
  138. <select name="keyword_language"><option value="%">'.get_lang('All').'</option>';
  139. $languages = api_get_languages();
  140. foreach ($languages['name'] as $index => $name)
  141. {
  142. echo '<option value="'.$languages['folder'][$index].'">'.$name.'</option>';
  143. }
  144. echo ' </select>
  145. </td>
  146. </tr>
  147. <tr>
  148. <td>&nbsp;</td>
  149. <td><input type="submit" name="do_search" value="'.get_lang('Ok').'"/></td>
  150. </tr>
  151. </table>
  152. </form>';
  153. }
  154. /**
  155. * This function displays the sortable table with all the surveys
  156. *
  157. * @return html code
  158. *
  159. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  160. * @version January 2007
  161. */
  162. function display_survey_list()
  163. {
  164. if ($_GET['do_search'])
  165. {
  166. $message = get_lang('DisplaySearchResults').'<br />';
  167. $message .= '<a href="'.$_SERVER['PHP_SELF'].'">'.get_lang('DisplayAll').'</a>';
  168. Display::display_normal_message($message);
  169. }
  170. // Create a sortable table with survey-data
  171. $table = new SortableTable('surveys', 'get_number_of_surveys', 'get_survey_data',2);
  172. $table->set_additional_parameters($parameters);
  173. $table->set_header(0, '', false);
  174. $table->set_header(1, get_lang('SurveyName'));
  175. $table->set_header(2, get_lang('SurveyCode'));
  176. $table->set_header(3, get_lang('Author'));
  177. $table->set_header(4, get_lang('Language'));
  178. $table->set_header(5, get_lang('AvailableFrom'));
  179. $table->set_header(6, get_lang('AvailableUntill'));
  180. $table->set_header(7, get_lang('AnsTarget'));
  181. $table->set_header(8, get_lang('Modify'), false);
  182. $table->set_column_filter(8, 'modify_filter');
  183. $table->set_form_actions(array ('delete' => get_lang('DeleteSurvey')));
  184. $table->display();
  185. }
  186. /**
  187. * This function calculates the total number of surveys
  188. *
  189. * @return integer
  190. *
  191. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  192. * @version January 2007
  193. */
  194. function get_number_of_surveys()
  195. {
  196. global $table_survey;
  197. $search_restriction = survey_search_restriction();
  198. if ($search_restriction)
  199. {
  200. $search_restriction = 'WHERE '.$search_restriction;
  201. }
  202. $sql = "SELECT count(survey_id) AS total_number_of_items FROM ".$table_survey.' '.$search_restriction;
  203. $res = api_sql_query($sql, __FILE__, __LINE__);
  204. $obj = mysql_fetch_object($res);
  205. return $obj->total_number_of_items;
  206. }
  207. /**
  208. * This function gets all the survey data that is to be displayed in the sortable table
  209. *
  210. * @param unknown_type $from
  211. * @param unknown_type $number_of_items
  212. * @param unknown_type $column
  213. * @param unknown_type $direction
  214. * @return unknown
  215. *
  216. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  217. * @version January 2007
  218. */
  219. function get_survey_data($from, $number_of_items, $column, $direction)
  220. {
  221. global $table_survey;
  222. global $table_user;
  223. // searching
  224. $search_restriction = survey_search_restriction();
  225. if ($search_restriction)
  226. {
  227. $search_restriction = ' AND '.$search_restriction;
  228. }
  229. $sql = "SELECT
  230. survey.survey_id AS col0,
  231. survey.title AS col1,
  232. survey.code AS col2,
  233. CONCAT(user.firstname, ' ', user.lastname) AS col3,
  234. survey.lang AS col4,
  235. survey.avail_from AS col5,
  236. survey.avail_till AS col6,
  237. '' AS col7,
  238. survey.survey_id AS col8
  239. FROM $table_survey survey, $table_user user
  240. WHERE survey.author = user.user_id
  241. $search_restriction
  242. ";
  243. $sql .= " ORDER BY col$column $direction ";
  244. $sql .= " LIMIT $from,$number_of_items";
  245. $res = api_sql_query($sql, __FILE__, __LINE__);
  246. $surveys = array ();
  247. while ($survey = mysql_fetch_row($res))
  248. {
  249. $surveys[] = $survey;
  250. }
  251. return $surveys;
  252. }
  253. /**
  254. * This function changes the modify column of the sortable table
  255. *
  256. * @param integer $survey_id the id of the survey
  257. * @return html code that are the actions that can be performed on any survey
  258. *
  259. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  260. * @version January 2007
  261. */
  262. function modify_filter($survey_id)
  263. {
  264. $return = '<a href="create_new_survey.php?action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif').'</a>';
  265. $return .= '<a href="survey_question.php?action=add&amp;survey_id='.$survey_id.'">'.Display::return_icon('add.gif').'</a>';
  266. $return .= '<a href="survey_list.php?action=delete&amp;survey_id='.$survey_id.'">'.Display::return_icon('delete.gif').'</a>';
  267. $return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif').'</a>';
  268. $return .= '<a href="survey_white.php?survey_id='.$survey_id.'">'.Display::return_icon('preview.gif').'</a>';
  269. $return .= '<a href="../announcements/announcements.php?action=add&amp;publish_survey='.$survey_id.'">'.Display::return_icon('survey_publish.gif').'</a>';
  270. $return .= '<a href="reporting.php?action=reporting&amp;surveyid='.$survey_id.'">'.Display::return_icon('surveyreporting.gif').'</a>';
  271. return $return;
  272. }
  273. /**
  274. * this function handles the search restriction for the SQL statements
  275. *
  276. * @return false or a part of a SQL statement
  277. *
  278. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  279. * @version January 2007
  280. */
  281. function survey_search_restriction()
  282. {
  283. if ($_GET['do_search'])
  284. {
  285. if ($_GET['keyword_title']<>'')
  286. {
  287. $search_term[] = 'title =\''.mysql_real_escape_string($_GET['keyword_title']).'\'';
  288. }
  289. if ($_GET['keyword_code']<>'')
  290. {
  291. $search_term[] = 'code =\''.mysql_real_escape_string($_GET['keyword_code']).'\'';
  292. }
  293. if ($_GET['keyword_language']<>'%')
  294. {
  295. $search_term[] = 'lang =\''.mysql_real_escape_string($_GET['keyword_language']).'\'';
  296. }
  297. $search_restriction = implode(' AND ', $search_term);
  298. return $search_restriction;
  299. }
  300. else
  301. {
  302. return false;
  303. }
  304. }
  305. /* if(isset($published))
  306. {
  307. $sname = surveymanager::pick_surveyname($surveyid);
  308. $error_message = get_lang('YourSurveyHasBeenPublished');
  309. Display::display_error_message("Survey "."'".$sname."'"." ".$error_message);
  310. }
  311. $res = api_sql_query($sql,__FILE__,__LINE__);
  312. if (mysql_num_rows($res) > 0)
  313. {
  314. $courses = array ();
  315. while ($obj = mysql_fetch_object($res))
  316. {
  317. $template=$obj->template;
  318. $surveyid = $obj->survey_id;
  319. if($template=='template1'){$view='white';}
  320. elseif($template=='template2'){$view='blue';}
  321. elseif($template=='template3'){$view='brown';}
  322. elseif($template=='template4'){$view='gray';}
  323. else{$view=='blank';}
  324. $sql_sent=" SELECT DISTINCT user_info.*
  325. FROM $user_info as user_info
  326. INNER JOIN $table_survey as survey
  327. ON user_info.sid = survey.survey_id
  328. AND survey.code = '".$obj->code."'";
  329. $res_sent=api_sql_query($sql_sent);
  330. $sent=mysql_num_rows($res_sent);
  331. $attempted=0;
  332. $sqlAttempt = ' SELECT DISTINCT *
  333. FROM '.Database::get_main_table(TABLE_MAIN_SURVEY_USER).'
  334. WHERE survey_id='.$obj->survey_id.' AND db_name="'.$db_name.'"';
  335. $res_attempt=api_sql_query($sqlAttempt);
  336. $attempted=mysql_num_rows($res_attempt);
  337. if($sent=='0')
  338. {$ratio=$attempted."/".$sent." "."(Not Published)";}
  339. else
  340. $ratio=$attempted."/".$sent;
  341. $survey = array ();
  342. $survey[] = '<input type="checkbox" name="survey_delete[]" value="'.$obj->survey_id.'">';
  343. $survey[] = $obj->title;
  344. $survey[] = $obj->code;
  345. $idd=surveymanager::get_author($db_name,$surveyid);
  346. $author=surveymanager::get_survey_author($idd);
  347. $survey[] = $author;
  348. $survey[] = $obj->lang;
  349. $survey[] = $obj->avail_from ;
  350. $survey[] = $obj->avail_till ;
  351. $survey[] = $ratio;
  352. //$NoOfQuestion=surveymanager::no_of_question($gid);
  353. //$language=surveymanager::no_of_question($sid);
  354. $survey[] = '<a href="survey_edit.php?surveyid='.$obj->survey_id.'"><img src="../img/edit.gif" border="0" align="absmiddle" alt="'.get_lang('Edit').'"/></a>'.'<a href="survey_list.php?&action=delete_surveys&survey_delete[]='.$obj->survey_id.'&delete_survey='.$obj->survey_id.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;"><img src="../img/delete.gif" border="0" align="absmiddle" alt="'.get_lang('Delete').'"/></a>'.'<a href="create_survey_in_another_language.php?id_survey='.$obj->survey_id.'"><img width="28" src="../img/copy.gif" border="0" align="absmiddle" alt="'.get_lang('CreateInAnotherLanguage').'" title="'.get_lang('CreateInAnotherLanguage').'" /></a>'.'<a href="survey_white.php?surveyid='.$surveyid.'&temp='.$template.'">&nbsp;<img src="../img/visible.gif" border="0" align="absmiddle" alt="'.get_lang('ViewSurvey').'"></a>'.'<a href="../announcements/announcements.php?action=add&publish_survey='.$obj->survey_id.'">&nbsp;<img src="../img/survey_publish.gif" border="0" align="absmiddle" alt="'.get_lang('Publish').'"></a>'.'<a href="reporting.php?action=reporting&surveyid='.$obj->survey_id.'">&nbsp;<img src="../img/surveyreporting.gif" border="0" align="absmiddle" alt="'.get_lang('Reporting').'"></a>';
  355. $surveys[] = $survey;
  356. }
  357. $table_header[] = array (' ', false);
  358. $table_header[] = array (get_lang('SurveyName'), true);
  359. $table_header[] = array (get_lang('SurveyCode'), true);
  360. $table_header[] = array (get_lang('Author'), true);
  361. $table_header[] = array (get_lang('Language'), true);
  362. $table_header[] = array (get_lang('AvailableFrom'), true);
  363. $table_header[] = array (get_lang('AvailableTill'), true);
  364. $table_header[] = array (get_lang('AnsTarget'), true);
  365. $table_header[] = array (' ', false);
  366. echo '<form method="get" action="survey_list.php" name="frm">';
  367. Display :: display_sortable_table($table_header, $surveys, array (), array (), $parameters);
  368. echo '<select name="action">';
  369. echo '<option value="delete_surveys">'.get_lang('DeleteSurvey').'</option>';
  370. echo '</select>';
  371. echo '&nbsp;&nbsp;<input type="submit" value="'.get_lang('Ok').'" onclick="return validate(\'frm\');"/>';
  372. echo '</form>';
  373. }
  374. else
  375. {
  376. if((isset ($_GET['keyword'])) || (isset ($_GET['keyword_title']))){
  377. echo get_lang('NoSearchResults') ;
  378. }
  379. else{
  380. $nosurvey=get_lang('NoSurveyAvailable');
  381. api_display_tool_title($nosurvey);
  382. }
  383. }
  384. }
  385. */
  386. ?>