gradebook_add_link.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ;
  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. $addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD,
  38. $category[0],
  39. intval($_GET['typeselected']),
  40. null,
  41. 'add_link',
  42. api_get_self() . '?selectcat=' . $_GET['selectcat']
  43. . '&typeselected=' . $_GET['typeselected'] . '&course_code=' . $_GET['course_code']);
  44. if ($addform->validate()) {
  45. $addvalues = $addform->exportValues();
  46. $link= LinkFactory :: create($_GET['typeselected']);
  47. $link->set_user_id(api_get_user_id());
  48. if($category[0]->get_course_code() == '' && !empty($_GET['course_code'])) {
  49. $link->set_course_code(Database::escape_string($_GET['course_code']));
  50. } else {
  51. $link->set_course_code($category[0]->get_course_code());
  52. }
  53. $link->set_category_id($category[0]->get_id());
  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. $link->set_weight($addvalues['weight']);
  60. if ($link->needs_max()) {
  61. $link->set_max($addvalues['max']);
  62. }
  63. $link->set_date(strtotime($addvalues['date']));
  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: '.$_SESSION['gradebook_dest'].'?linkadded=&selectcat=' . $_GET['selectcat']);
  93. exit;
  94. }
  95. }
  96. }
  97. $interbreadcrumb[]= array (
  98. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . $_GET['selectcat'],
  99. 'name' => get_lang('Gradebook'
  100. ));
  101. Display :: display_header(get_lang('MakeLink'));
  102. if (isset ($typeform)) {
  103. $typeform->display();
  104. }
  105. if (isset ($addform)) {
  106. $addform->display();
  107. }
  108. Display :: display_footer();