gradebook_add_link.php 5.4 KB

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