gradebook_add_link.php 5.6 KB

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