gradebook_add_link.php 5.7 KB

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