create_new_group.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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
  19. * @version $Id: create_new_group.php 10705 2007-01-12 22:40:01Z pcool $
  20. */
  21. /*
  22. ==============================================================================
  23. INIT SECTION
  24. ==============================================================================
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'survey';
  28. // including the global dokeos file
  29. require_once ('../inc/global.inc.php');
  30. // including additional libraries
  31. /** @todo check if these are all needed */
  32. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  33. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  34. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  35. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  36. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  37. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  38. /** @todo replace this with the correct code */
  39. /*
  40. $status = surveymanager::get_status();
  41. api_protect_course_script();
  42. if($status==5)
  43. {
  44. api_protect_admin_script();
  45. }
  46. */
  47. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  48. if (!api_is_allowed_to_edit())
  49. {
  50. Display :: display_header();
  51. Display :: display_error_message(get_lang('NotAllowedHere'));
  52. Display :: display_footer();
  53. exit;
  54. }
  55. // Database table definitions
  56. /** @todo use database constants for the survey tables */
  57. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  58. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  59. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  60. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  61. $table_survey_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  62. $table_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  63. $tool_name1 = get_lang('CreateNewGroup');
  64. $tool_name = get_lang('CreateNewGroup');
  65. $header1 = get_lang('GroupList');
  66. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  67. $surveyid = $_GET['surveyid'];
  68. $surveyname = SurveyManager::pick_surveyname($surveyid);
  69. if(isset($_GET['direction'])){
  70. $sql = 'SELECT *
  71. FROM '.$table_group.'
  72. WHERE group_id='.intval($_GET['id_group']);
  73. $rs = api_sql_query($sql, __FILE__, __LINE__);
  74. $group = mysql_fetch_object($rs);
  75. if(is_object($group)){
  76. $_GET['direction'] == 'up' ? $operateur = '-' : $operateur = '+';
  77. $sql = 'UPDATE '.$table_group.' SET
  78. sortby='.$group->sortby.'
  79. WHERE sortby='.$group->sortby.$operateur.'1' ;
  80. $rs = api_sql_query($sql,__FILE__,__LINE__);
  81. $sql = 'UPDATE '.$table_group.' SET
  82. sortby='.$group->sortby.$operateur.'1'.'
  83. WHERE group_id='.intval($_GET['id_group']);
  84. $rs = api_sql_query($sql,__FILE__,__LINE__);
  85. }
  86. }
  87. if(isset($_REQUEST['delete']))
  88. {
  89. $group_id = $_REQUEST['group_delete'];
  90. $surveyid = $_REQUEST['surveyid'];
  91. SurveyManager::delete_group($group_id);
  92. header("Location:create_new_group.php?surveyid=$surveyid");
  93. exit;
  94. }
  95. if ($_POST['action'] == 'new_group')
  96. {
  97. $surveyid = $_POST['surveyid'];
  98. $groupname = $_POST['groupname'];
  99. $surveyintroduction = $_POST['content'];
  100. if(isset($_POST['back']))
  101. {
  102. header("location:select_question_group.php?surveyid=$surveyid");
  103. exit;
  104. }
  105. $groupname=trim($groupname);
  106. if(empty ($groupname))
  107. {
  108. $error_message = get_lang('PleaseEnterGroupName');
  109. }
  110. else
  111. {
  112. $groupid = SurveyManager::create_group($surveyid,$groupname,$surveyintroduction,$table_group);
  113. if(isset($_POST['next']) && $groupid)
  114. {
  115. header("location:addanother.php?surveyid=$surveyid&newgroupid=$groupid");
  116. exit;
  117. }elseif(isset($_POST['saveandexit']) && $groupid){
  118. header("location:survey_list.php");
  119. exit;
  120. }
  121. else
  122. {
  123. $error_message = "This Group Already Exists !";
  124. }
  125. }
  126. }
  127. Display::display_header($tool_name1);
  128. ?>
  129. <tr>
  130. <td><?php api_display_tool_title($header1); ?></td>
  131. </tr>
  132. <?php
  133. if( isset($error_message) )
  134. {
  135. Display::display_error_message($error_message);
  136. }
  137. $sql = "SELECT * FROM $table_survey_group WHERE survey_id='$surveyid' ORDER BY sortby ASC";
  138. $parameters = array ();
  139. $parameters['surveyid']=$surveyid;
  140. $parameters['groupid']=$groupid;
  141. $res = api_sql_query($sql,__FILE__,__LINE__);
  142. $countGroups = mysql_num_rows($res);
  143. if ($countGroups > 0)
  144. {
  145. $i=0;
  146. //$surveys = array ();
  147. while ($obj = mysql_fetch_object($res))
  148. {
  149. $gid=$obj->group_id;
  150. $gname = $obj->groupname;
  151. $survey = array ();
  152. $survey[] = $obj->groupname;
  153. $gid=$obj->group_id;
  154. $idd=surveymanager::pick_author($surveyid);
  155. $author=surveymanager::get_survey_author($idd);
  156. $surveyname=surveymanager::pick_surveyname($surveyid);
  157. $survey[] = $surveyname;
  158. $survey[] = $author;
  159. $directions = '<table cellpadding="0" cellspacing="0" border="0" style="border:0px"><tr>';
  160. if($i < $countGroups-1){
  161. $directions .= '<td><a href="'.$_SERVER['PHP_SELF'].'?surveyid='.$surveyid.'&&direction=down&id_group='.$gid.'"><img src="../img/down.gif" border="0" title="lang_move_down"></a></td>';
  162. }
  163. else {
  164. $directions .= '<td width="20"></td>';
  165. }
  166. if($i > 0){
  167. $directions .= '<td><a href="'.$_SERVER['PHP_SELF'].'?surveyid='.$surveyid.'&direction=up&id_group='.$gid.'"><img src="../img/up.gif" border="0" title="lang_move_up"></a></td>';
  168. }
  169. else {
  170. $directions .= '<td></td>';
  171. }
  172. $directions .= '</tr></table>';
  173. $survey[] = $directions;
  174. $survey[] = '<a href="group_edit.php?groupid='.$obj->group_id.'&surveyid='.$surveyid.'"><img src="../img/edit.gif" border="0" align="absmiddle" alt="'.get_lang('Edit').'"/></a>'
  175. .'<a href="create_new_group.php?delete=1&group_delete='.$gid.'&surveyid='.$surveyid.'" 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>'
  176. ;
  177. $surveys[] = $survey;
  178. $i++;
  179. }
  180. $table_header[] = array (get_lang('QuesGroup'), true);
  181. $table_header[] = array (get_lang('SurveyName'), true);
  182. $table_header[] = array (get_lang('Author'), true);
  183. $table_header[] = array (get_lang('OrderBy'), true);
  184. $table_header[] = array (' ', false);
  185. Display :: display_sortable_table($table_header, $surveys, array ('column'=>get_lang('OrderBy')), array (), $parameters);
  186. }
  187. else
  188. {
  189. echo get_lang('NoSearchResults');
  190. }
  191. echo '<a href="select_question_group.php?surveyid='.$surveyid.'">'.get_lang('BackToQuestions').'</a><br><br>';
  192. api_display_tool_title($tool_name);
  193. ?>
  194. <script src=tbl_change.js type="text/javascript" language="javascript"></script>
  195. <form name="new_calendar_item" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  196. <input type="hidden" name="action" value="new_group">
  197. <input type="hidden" name="surveyid" value="<?php echo $surveyid; ?>">
  198. <input type="hidden" name="groupid" value="<?php echo $groupid; ?>">
  199. <!--<input type="hidden" name="cidReq" value="<?php echo $_REQUEST['cidReq']; ?>">-->
  200. <table>
  201. <tr>
  202. <td><?php echo get_lang('GroupName'); ?></td>
  203. <td><input type="text" name="groupname" size="40" maxlength="39" value="<?php echo $code ?>"></td>
  204. </tr>
  205. <tr><td valign="top"><?php echo get_lang('GroupIntroduction'); ?>&nbsp;</td>
  206. <td>
  207. <?php
  208. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  209. $oFCKeditor = new FCKeditor('content') ;
  210. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  211. $oFCKeditor->Height = '300';
  212. $oFCKeditor->Width = '600';
  213. $oFCKeditor->Value = $content;
  214. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  215. $oFCKeditor->ToolbarSet = "Survey";
  216. $sql="SELECT isocode FROM ".$table_languages." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  217. $result_sql=api_sql_query($sql);
  218. $isocode_language=mysql_result($result_sql,0,0);
  219. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  220. $return = $oFCKeditor->CreateHtml();
  221. echo $return;
  222. ?>
  223. <br>
  224. </td>
  225. </tr>
  226. </table>
  227. <tr>
  228. <td>&nbsp;</td>
  229. <td><input type="submit" name="back" value="<?php echo get_lang('Back'); ?>"></td>
  230. <td><input type="submit" name="saveandexit" value="<?php echo get_lang('SaveAndExit'); ?>"></td>
  231. <td><input type="submit" name="next" value="<?php echo get_lang('Next'); ?>"></td>
  232. </tr>
  233. </form>
  234. <?php
  235. /*
  236. ==============================================================================
  237. FOOTER
  238. ==============================================================================
  239. */
  240. Display :: display_footer();
  241. ?>