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