gradebook_add_link.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // $Id: gradebook_add_link.php 338 2007-04-06 14:02:05Z stijn $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2006 Dokeos S.A.
  7. Copyright (c) 2007 Stijn Konings, Bert Stepp� (Hogeschool Gent)
  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, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. $language_file = 'gradebook';
  20. $cidReset = true;
  21. include_once ('../inc/global.inc.php');
  22. include_once ('lib/be.inc.php');
  23. include_once ('lib/gradebook_functions.inc.php');
  24. include_once ('lib/fe/linkform.class.php');
  25. include_once ('lib/fe/linkaddeditform.class.php');
  26. api_block_anonymous_users();
  27. block_students();
  28. $category = Category :: load($_GET['selectcat']);
  29. $typeform = new LinkForm(LinkForm :: TYPE_CREATE,
  30. $category[0],
  31. null,
  32. 'create_link',
  33. null,
  34. api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  35. . '&newtypeselected=' . (isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '')
  36. . '&course_code=' . (empty($_GET['course_code'])?'':Security::remove_XSS($_GET['course_code'])))
  37. ;
  38. // if user selected a link type
  39. if ($typeform->validate() && isset($_GET['newtypeselected']))
  40. {
  41. // reload page, this time with a parameter indicating the selected type
  42. header('Location: '.api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  43. . '&typeselected='.$typeform->exportValue('select_link')
  44. . '&course_code=' . Security::remove_XSS($_GET['course_code']));
  45. exit;
  46. }
  47. // link type selected, show 2nd form to retrieve the link data
  48. if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0')
  49. {
  50. $addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD,
  51. $category[0],
  52. intval($_GET['typeselected']),
  53. null,
  54. 'add_link',
  55. api_get_self() . '?selectcat=' . $_GET['selectcat']
  56. . '&typeselected=' . $_GET['typeselected'] . '&course_code=' . $_GET['course_code']);
  57. if ($addform->validate())
  58. {
  59. $addvalues = $addform->exportValues();
  60. $link= LinkFactory :: create($_GET['typeselected']);
  61. $link->set_user_id(api_get_user_id());
  62. if($category[0]->get_course_code() == '' && !empty($_GET['course_code']))
  63. {
  64. $link->set_course_code(Database::escape_string($_GET['course_code']));
  65. }
  66. else
  67. {
  68. $link->set_course_code($category[0]->get_course_code());
  69. }
  70. $link->set_category_id($category[0]->get_id());
  71. if ($link->needs_name_and_description())
  72. $link->set_name($addvalues['name']);
  73. else
  74. $link->set_ref_id($addvalues['select_link']);
  75. $link->set_weight($addvalues['weight']);
  76. if ($link->needs_max())
  77. $link->set_max($addvalues['max']);
  78. $link->set_date(strtotime($addvalues['date']));
  79. if ($link->needs_name_and_description())
  80. $link->set_description($addvalues['description']);
  81. $link->set_visible(empty ($addvalues['visible']) ? 0 : 1);
  82. $link->add();
  83. if ($addvalues['addresult'] == 1)
  84. {
  85. header('Location: gradebook_add_result.php?selecteval=' . $link->get_ref_id());
  86. exit;
  87. }
  88. else
  89. {
  90. header('Location: gradebook.php?linkadded=&selectcat=' . $_GET['selectcat']);
  91. exit;
  92. }
  93. }
  94. }
  95. $interbreadcrumb[]= array (
  96. 'url' => 'gradebook.php?selectcat=' . $_GET['selectcat'],
  97. 'name' => get_lang('Gradebook'
  98. ));
  99. Display :: display_header(get_lang('MakeLink'));
  100. if (isset ($typeform))
  101. $typeform->display();
  102. if (isset ($addform))
  103. $addform->display();
  104. Display :: display_footer();
  105. ?>