gradebook_add_link.php 5.9 KB

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