gradebook_add_link.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 '../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=' . (empty($_GET['course_code'])?'':Security::remove_XSS($_GET['course_code']));
  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. /*
  47. if ($category[0]->get_course_code() == '' && !empty($_GET['course_code'])) {
  48. $link->set_course_code($_GET['course_code']);
  49. } else {
  50. $link->set_course_code($category[0]->get_course_code());
  51. }*/
  52. $link->set_course_code(api_get_course_id());
  53. $link->set_category_id($addvalues['select_gradebook']);
  54. if ($link->needs_name_and_description()) {
  55. $link->set_name($addvalues['name']);
  56. } else {
  57. $link->set_ref_id($addvalues['select_link']);
  58. }
  59. $parent_cat = Category :: load($addvalues['select_gradebook']);
  60. $global_weight = $category[0]->get_weight();
  61. //$addvalues['weight'] = $addvalues['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
  62. $link->set_weight($addvalues['weight_mask']);
  63. if ($link->needs_max()) {
  64. $link->set_max($addvalues['max']);
  65. }
  66. if ($link->needs_name_and_description()) {
  67. $link->set_description($addvalues['description']);
  68. }
  69. $link->set_visible(empty ($addvalues['visible']) ? 0 : 1);
  70. //update view_properties
  71. if (isset($_GET['typeselected']) && 5 == $_GET['typeselected'] && (isset($addvalues['select_link']) && $addvalues['select_link']<>"")) {
  72. $sql1 = 'SELECT thread_title from '.$tbl_forum_thread.'
  73. WHERE c_id = '.$course_info['real_id'].' AND thread_id='.$addvalues['select_link'];
  74. $res1 = Database::query($sql1);
  75. $rowtit = Database::fetch_row($res1);
  76. $course_id = api_get_course_id();
  77. $sql_l='SELECT count(*) FROM '.$tbl_link.' WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
  78. $res_l=Database::query($sql_l);
  79. $row=Database::fetch_row($res_l);
  80. if ( $row[0]==0 ) {
  81. $link->add();
  82. $sql = 'UPDATE '.$tbl_forum_thread.' SET thread_qualify_max='.$addvalues['weight'].',thread_weight='.$addvalues['weight'].',thread_title_qualify="'.$rowtit[0].'"
  83. WHERE thread_id='.$addvalues['select_link'].' AND c_id = '.$course_info['real_id'].' ';
  84. Database::query($sql);
  85. }
  86. }
  87. $link->add();
  88. $addvalue_result=!empty($addvalues['addresult'])?$addvalues['addresult']:array();
  89. if ($addvalue_result == 1) {
  90. header('Location: gradebook_add_result.php?selecteval=' . $link->get_ref_id());
  91. exit;
  92. } else {
  93. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?linkadded=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  94. exit;
  95. }
  96. }
  97. }
  98. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' .Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
  99. $this_section = SECTION_COURSES;
  100. $htmlHeadXtra[] = '<script type="text/javascript">
  101. $(document).ready( function() {
  102. $("#hide_category_id").change(function() {
  103. $("#hide_category_id option:selected").each(function () {
  104. var cat_id = $(this).val();
  105. $.ajax({
  106. url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  107. data: "cat_id="+cat_id,
  108. success: function(return_value) {
  109. if (return_value != 0 ) {
  110. $("#max_weight").html(return_value);
  111. }
  112. },
  113. });
  114. });
  115. });
  116. });
  117. </script>';
  118. Display :: display_header(get_lang('MakeLink'));
  119. if (isset ($typeform)) {
  120. $typeform->display();
  121. }
  122. if (isset ($addform)) {
  123. $addform->display();
  124. }
  125. Display :: display_footer();