linkform.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. require_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  21. require_once (dirname(__FILE__).'/../be.inc.php');
  22. require_once (dirname(__FILE__).'/../gradebook_functions.inc.php');
  23. require_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php');
  24. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  25. /**
  26. * Forms related to links
  27. * @author Stijn Konings
  28. * @author Bert Stepp� (made more generic)
  29. * @package dokeos.gradebook
  30. */
  31. class LinkForm extends FormValidator
  32. {
  33. const TYPE_CREATE = 1;
  34. const TYPE_MOVE = 2;
  35. private $category_object;
  36. private $link_object;
  37. private $extra;
  38. /**
  39. * Builds a form containing form items based on a given parameter
  40. * @param int form_type 1=choose link
  41. * @param obj cat_obj the category object
  42. * @param string form name
  43. * @param method
  44. * @param action
  45. */
  46. function LinkForm($form_type, $category_object,$link_object, $form_name, $method = 'post', $action = null, $extra = null) {
  47. parent :: __construct($form_name, $method, $action);
  48. if (isset ($category_object)) {
  49. $this->category_object = $category_object;
  50. } if (isset ($link_object)) {
  51. $this->link_object = $link_object;
  52. }
  53. if (isset ($extra)) {
  54. $this->extra = $extra;
  55. }
  56. if ($form_type == self :: TYPE_CREATE) {
  57. $this->build_create();
  58. } elseif ($form_type == self :: TYPE_MOVE) {
  59. $this->build_move();
  60. }
  61. //$this->setDefaults();
  62. }
  63. protected function build_move() {
  64. $renderer =& $this->defaultRenderer();
  65. $renderer->setElementTemplate('<span>{element}</span> ');
  66. $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
  67. $this->addElement('static',null,null,get_lang('MoveTo').' : ');
  68. $select = $this->addElement('select','move_cat',null,null);
  69. foreach ($this->link_object->get_target_categories() as $cat) {
  70. for ($i=0;$i<$cat[2];$i++) {
  71. $line .= '&mdash;';
  72. }
  73. $select->addoption($line.' '.$cat[1],$cat[0]);
  74. $line = '';
  75. }
  76. $this->addElement('submit', null, get_lang('Ok'));
  77. }
  78. protected function build_create() {
  79. $select = $this->addElement('select',
  80. 'select_link',
  81. get_lang('ChooseLink'),
  82. null,
  83. array('onchange' => 'document.create_link.submit()'));
  84. $linktypes = LinkFactory :: get_all_types();
  85. $select->addoption('['.get_lang('ChooseLink').']', 0);
  86. $cc = $this->category_object->get_course_code();
  87. foreach ($linktypes as $linktype) {
  88. $link = LinkFactory :: create ($linktype);
  89. if(!empty($cc)) {
  90. $link->set_course_code($cc);
  91. } elseif(!empty($_GET['course_code'])) {
  92. $link->set_course_code(Database::escape_string($_GET['course_code']));
  93. }
  94. // disable this element if the link works with a dropdownlist
  95. // and if there are no links left
  96. if (!$link->needs_name_and_description()
  97. && count($link->get_all_links()) == '0') {
  98. $select->addoption($link->get_type_name(), $linktype, 'disabled');
  99. } else {
  100. $select->addoption($link->get_type_name(), $linktype);
  101. }
  102. }
  103. if (isset($this->extra)) {
  104. $this->setDefaults(array('select_link' => $this->extra));
  105. }
  106. }
  107. }