gradebook_add_link.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = 'gradebook';
  4. //$cidReset = true;
  5. require_once '../inc/global.inc.php';
  6. require_once 'lib/be.inc.php';
  7. require_once 'lib/gradebook_functions.inc.php';
  8. require_once 'lib/fe/linkform.class.php';
  9. require_once 'lib/fe/linkaddeditform.class.php';
  10. require_once '../forum/forumfunction.inc.php';
  11. api_block_anonymous_users();
  12. block_students();
  13. $course_info =isset($_GET['course_code'])? api_get_course_info($_GET['course_code']) : '';
  14. $my_db_course=isset($_GET['course_code'])?$course_info['dbName']:'';
  15. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD,$my_db_course);
  16. $tbl_link=Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  17. $category = Category :: load($_GET['selectcat']);
  18. $typeform = new LinkForm(LinkForm :: TYPE_CREATE,
  19. $category[0],
  20. null,
  21. 'create_link',
  22. null,
  23. api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  24. . '&newtypeselected=' . (isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '')
  25. . '&course_code=' . (empty($_GET['course_code'])?'':Security::remove_XSS($_GET['course_code'])),
  26. $_GET['typeselected'])
  27. ;
  28. // if user selected a link type
  29. if ($typeform->validate() && isset($_GET['newtypeselected'])) {
  30. // reload page, this time with a parameter indicating the selected type
  31. header('Location: '.api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  32. . '&typeselected='.$typeform->exportValue('select_link')
  33. . '&course_code=' . Security::remove_XSS($_GET['course_code']));
  34. exit;
  35. }
  36. // link type selected, show 2nd form to retrieve the link data
  37. if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0') {
  38. $addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD,
  39. $category[0],
  40. intval($_GET['typeselected']),
  41. null,
  42. 'add_link',
  43. api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  44. . '&typeselected=' . Security::remove_XSS($_GET['typeselected']) . '&course_code=' . Security::remove_XSS($_GET['course_code']));
  45. if ($addform->validate()) {
  46. $addvalues = $addform->exportValues();
  47. $link= LinkFactory :: create($_GET['typeselected']);
  48. $link->set_user_id(api_get_user_id());
  49. if($category[0]->get_course_code() == '' && !empty($_GET['course_code'])) {
  50. $link->set_course_code($_GET['course_code']);
  51. } else {
  52. $link->set_course_code($category[0]->get_course_code());
  53. }
  54. $link->set_category_id($category[0]->get_id());
  55. if ($link->needs_name_and_description()) {
  56. $link->set_name($addvalues['name']);
  57. } else {
  58. $link->set_ref_id($addvalues['select_link']);
  59. }
  60. $link->set_weight($addvalues['weight']);
  61. if ($link->needs_max()) {
  62. $link->set_max($addvalues['max']);
  63. }
  64. if ($link->needs_name_and_description()) {
  65. $link->set_description($addvalues['description']);
  66. }
  67. $link->set_visible(empty ($addvalues['visible']) ? 0 : 1);
  68. //update view_properties
  69. $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  70. if ( isset($_GET['typeselected']) && 5==$_GET['typeselected'] && (isset($addvalues['select_link']) && $addvalues['select_link']<>"")) {
  71. $sql1='SELECT thread_title from '.$tbl_forum_thread.' where thread_id='.$addvalues['select_link'].';';
  72. $res1=Database::query($sql1);
  73. $rowtit=Database::fetch_row($res1);
  74. $course_id=api_get_course_id();
  75. $sql_l='SELECT count(*) FROM '.$tbl_link.' WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
  76. $res_l=Database::query($sql_l);
  77. $row=Database::fetch_row($res_l);
  78. if ( $row[0]==0 ) {
  79. $link->add();
  80. $sql='UPDATE '.$tbl_forum_thread.' set thread_qualify_max='.$addvalues['weight'].',thread_weight='.$addvalues['weight'].',thread_title_qualify="'.$rowtit[0].'" WHERE thread_id='.$addvalues['select_link'].';';
  81. Database::query($sql);
  82. //$sql_l='UPDATE '.$tbl_link.' SET weight='.$addvalues['weight'].' WHERE ref_id='.$addvalues['select_link'].' AND type=5;';
  83. //Database::query($sql_l);
  84. }
  85. }
  86. $link->add();
  87. $addvalue_result=!empty($addvalues['addresult'])?$addvalues['addresult']:array();
  88. if ($addvalue_result == 1) {
  89. header('Location: gradebook_add_result.php?selecteval=' . $link->get_ref_id());
  90. exit;
  91. } else {
  92. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?linkadded=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  93. exit;
  94. }
  95. }
  96. }
  97. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' .Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
  98. $this_section = SECTION_COURSES;
  99. Display :: display_header(get_lang('MakeLink'));
  100. if (isset ($typeform)) {
  101. $typeform->display();
  102. }
  103. if (isset ($addform)) {
  104. $addform->display();
  105. }
  106. Display :: display_footer();