gradebook_add_link.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006-2008 Dokeos SPRL
  6. Copyright (c) 2006 Ghent University (UGent)
  7. Copyright (c) various contributors
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. $language_file = 'gradebook';
  20. //$cidReset = true;
  21. require_once ('../inc/global.inc.php');
  22. require_once ('lib/be.inc.php');
  23. require_once ('lib/gradebook_functions.inc.php');
  24. require_once ('lib/fe/linkform.class.php');
  25. require_once ('lib/fe/linkaddeditform.class.php');
  26. require_once ('../forum/forumfunction.inc.php');
  27. api_block_anonymous_users();
  28. block_students();
  29. $course_info =isset($_GET['course_code'])? api_get_course_info($_GET['course_code']) : '';
  30. $my_db_course=isset($_GET['course_code'])?$course_info['dbName']:'';
  31. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD,$my_db_course);
  32. $tbl_link=Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  33. $category = Category :: load($_GET['selectcat']);
  34. $typeform = new LinkForm(LinkForm :: TYPE_CREATE,
  35. $category[0],
  36. null,
  37. 'create_link',
  38. null,
  39. api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  40. . '&newtypeselected=' . (isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '')
  41. . '&course_code=' . (empty($_GET['course_code'])?'':Security::remove_XSS($_GET['course_code'])))
  42. ;
  43. // if user selected a link type
  44. if ($typeform->validate() && isset($_GET['newtypeselected'])) {
  45. // reload page, this time with a parameter indicating the selected type
  46. header('Location: '.api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  47. . '&typeselected='.$typeform->exportValue('select_link')
  48. . '&course_code=' . Security::remove_XSS($_GET['course_code']));
  49. exit;
  50. }
  51. // link type selected, show 2nd form to retrieve the link data
  52. if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0') {
  53. $addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD,
  54. $category[0],
  55. intval($_GET['typeselected']),
  56. null,
  57. 'add_link',
  58. api_get_self() . '?selectcat=' . $_GET['selectcat']
  59. . '&typeselected=' . $_GET['typeselected'] . '&course_code=' . $_GET['course_code']);
  60. if ($addform->validate()) {
  61. $addvalues = $addform->exportValues();
  62. $link= LinkFactory :: create($_GET['typeselected']);
  63. $link->set_user_id(api_get_user_id());
  64. if($category[0]->get_course_code() == '' && !empty($_GET['course_code'])) {
  65. $link->set_course_code(Database::escape_string($_GET['course_code']));
  66. } else {
  67. $link->set_course_code($category[0]->get_course_code());
  68. }
  69. $link->set_category_id($category[0]->get_id());
  70. if ($link->needs_name_and_description()) {
  71. $link->set_name($addvalues['name']);
  72. } else {
  73. $link->set_ref_id($addvalues['select_link']);
  74. }
  75. $link->set_weight($addvalues['weight']);
  76. if ($link->needs_max()) {
  77. $link->set_max($addvalues['max']);
  78. }
  79. $link->set_date(strtotime($addvalues['date']));
  80. if ($link->needs_name_and_description()) {
  81. $link->set_description($addvalues['description']);
  82. }
  83. $link->set_visible(empty ($addvalues['visible']) ? 0 : 1);
  84. //update view_properties
  85. $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  86. if ( isset($_GET['typeselected']) && 5==$_GET['typeselected'] && (isset($addvalues['select_link']) && $addvalues['select_link']<>"")) {
  87. $sql1='SELECT thread_title from '.$tbl_forum_thread.' where thread_id='.$addvalues['select_link'].';';
  88. $res1=Database::query($sql1);
  89. $rowtit=Database::fetch_row($res1);
  90. $course_id=api_get_course_id();
  91. $sql_l='SELECT count(*) FROM '.$tbl_link.' WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
  92. $res_l=Database::query($sql_l);
  93. $row=Database::fetch_row($res_l);
  94. if ( $row[0]==0 ) {
  95. $link->add();
  96. $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'].';';
  97. Database::query($sql);
  98. //$sql_l='UPDATE '.$tbl_link.' SET weight='.$addvalues['weight'].' WHERE ref_id='.$addvalues['select_link'].' AND type=5;';
  99. //Database::query($sql_l);
  100. }
  101. }
  102. $link->add();
  103. $addvalue_result=!empty($addvalues['addresult'])?$addvalues['addresult']:array();
  104. if ($addvalue_result == 1) {
  105. header('Location: gradebook_add_result.php?selecteval=' . $link->get_ref_id());
  106. exit;
  107. } else {
  108. header('Location: '.$_SESSION['gradebook_dest'].'?linkadded=&selectcat=' . $_GET['selectcat']);
  109. exit;
  110. }
  111. }
  112. }
  113. $interbreadcrumb[]= array (
  114. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . $_GET['selectcat'],
  115. 'name' => get_lang('Gradebook'
  116. ));
  117. Display :: display_header(get_lang('MakeLink'));
  118. if (isset ($typeform)) {
  119. $typeform->display();
  120. }
  121. if (isset ($addform)) {
  122. $addform->display();
  123. }
  124. Display :: display_footer();