gradebook_add_link.php 5.4 KB

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