gradebook_add_link.php 5.8 KB

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