gradebook_add_link.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. $language_file = array('gradebook', 'exercice');
  8. require_once '../inc/global.inc.php';
  9. require_once 'lib/be.inc.php';
  10. require_once 'lib/gradebook_functions.inc.php';
  11. require_once 'lib/fe/linkform.class.php';
  12. require_once 'lib/fe/linkaddeditform.class.php';
  13. require_once '../forum/forumfunction.inc.php';
  14. $current_course_tool = TOOL_GRADEBOOK;
  15. api_protect_course_script();
  16. api_block_anonymous_users();
  17. block_students();
  18. $courseCode = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : null;
  19. $course_info = api_get_course_info($courseCode);
  20. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  21. $tbl_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  22. $session_id = api_get_session_id();
  23. $typeSelected = isset($_GET['typeselected']) ? intval($_GET['typeselected']) : null;
  24. if ($session_id == 0) {
  25. $all_categories = Category::load(null, null, api_get_course_id(), null, null, $session_id);
  26. } else {
  27. $all_categories = Category::load_session_categories(null, $session_id);
  28. }
  29. $category = Category :: load($_GET['selectcat']);
  30. $url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&newtypeselected='.$typeSelected.'&course_code='.api_get_course_id().'&'.api_get_cidreq();
  31. $typeform = new LinkForm(
  32. LinkForm :: TYPE_CREATE,
  33. $category[0],
  34. null,
  35. 'create_link',
  36. null,
  37. $url,
  38. $typeSelected
  39. );
  40. // if user selected a link type
  41. if ($typeform->validate() && isset($_GET['newtypeselected'])) {
  42. // reload page, this time with a parameter indicating the selected type
  43. header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat'])
  44. .'&typeselected='.$typeform->exportValue('select_link')
  45. .'&course_code='.Security::remove_XSS($_GET['course_code']).'&'.api_get_cidreq()
  46. );
  47. exit;
  48. }
  49. // link type selected, show 2nd form to retrieve the link data
  50. if (isset($typeSelected) && $typeSelected != '0') {
  51. $url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&typeselected='.$typeSelected.'&course_code='.$courseCode.'&'.api_get_cidreq();
  52. $addform = new LinkAddEditForm(
  53. LinkAddEditForm :: TYPE_ADD,
  54. $all_categories,
  55. $typeSelected,
  56. null,
  57. 'add_link',
  58. $url
  59. );
  60. if ($addform->validate()) {
  61. $addvalues = $addform->exportValues();
  62. $link = LinkFactory :: create($typeSelected);
  63. $link->set_user_id(api_get_user_id());
  64. $link->set_course_code(api_get_course_id());
  65. $link->set_category_id($addvalues['select_gradebook']);
  66. if ($link->needs_name_and_description()) {
  67. $link->set_name($addvalues['name']);
  68. } else {
  69. $link->set_ref_id($addvalues['select_link']);
  70. }
  71. $parent_cat = Category::load($addvalues['select_gradebook']);
  72. $global_weight = $category[0]->get_weight();
  73. $link->set_weight($addvalues['weight_mask']);
  74. if ($link->needs_max()) {
  75. $link->set_max($addvalues['max']);
  76. }
  77. if ($link->needs_name_and_description()) {
  78. $link->set_description($addvalues['description']);
  79. }
  80. $link->set_visible(empty($addvalues['visible']) ? 0 : 1);
  81. // Update view_properties
  82. if (isset($typeSelected) &&
  83. 5 == $typeSelected &&
  84. (isset($addvalues['select_link']) && $addvalues['select_link'] <> "")
  85. ) {
  86. $sql1 = 'SELECT thread_title from '.$tbl_forum_thread.'
  87. WHERE c_id = '.$course_info['real_id'].' AND thread_id='.$addvalues['select_link'];
  88. $res1 = Database::query($sql1);
  89. $rowtit = Database::fetch_row($res1);
  90. $course_id = api_get_course_id();
  91. $sql_l = 'SELECT count(*) FROM '.$tbl_link.'
  92. WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
  93. $res_l = Database::query($sql_l);
  94. $row = Database::fetch_row($res_l);
  95. if ($row[0] == 0) {
  96. $link->add();
  97. $sql = 'UPDATE '.$tbl_forum_thread.' SET
  98. thread_qualify_max='.$addvalues['weight'].',
  99. thread_weight='.$addvalues['weight'].',
  100. thread_title_qualify="'.$rowtit[0].'"
  101. WHERE thread_id='.$addvalues['select_link'].' AND c_id = '.$course_info['real_id'].' ';
  102. Database::query($sql);
  103. }
  104. }
  105. $link->add();
  106. $addvalue_result = !empty($addvalues['addresult']) ? $addvalues['addresult'] : array();
  107. if ($addvalue_result == 1) {
  108. header('Location: gradebook_add_result.php?selecteval='.$link->get_ref_id().'&'.api_get_cidreq());
  109. exit;
  110. } else {
  111. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?linkadded=&selectcat='.Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq());
  112. exit;
  113. }
  114. }
  115. }
  116. $interbreadcrumb[] = array(
  117. 'url' => $_SESSION['gradebook_dest'].'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq(),
  118. 'name' => get_lang('Gradebook')
  119. );
  120. $this_section = SECTION_COURSES;
  121. $htmlHeadXtra[] = '<script>
  122. $(document).ready( function() {
  123. $("#hide_category_id").change(function() {
  124. $("#hide_category_id option:selected").each(function () {
  125. var cat_id = $(this).val();
  126. $.ajax({
  127. url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  128. data: "cat_id="+cat_id,
  129. success: function(return_value) {
  130. if (return_value != 0 ) {
  131. $("#max_weight").html(return_value);
  132. }
  133. }
  134. });
  135. });
  136. });
  137. });
  138. </script>';
  139. Display::display_header(get_lang('MakeLink'));
  140. if (isset($typeform)) {
  141. echo Display::return_message(get_lang('LearningPathGradebookWarning'), 'warning');
  142. $typeform->display();
  143. }
  144. if (isset($addform)) {
  145. $addform->display();
  146. }
  147. Display::display_footer();