linkform.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  4. require_once (dirname(__FILE__).'/../be.inc.php');
  5. require_once (dirname(__FILE__).'/../gradebook_functions.inc.php');
  6. require_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php');
  7. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  8. /**
  9. * Forms related to links
  10. * @author Stijn Konings
  11. * @author Bert Stepp� (made more generic)
  12. * @package dokeos.gradebook
  13. */
  14. class LinkForm extends FormValidator
  15. {
  16. const TYPE_CREATE = 1;
  17. const TYPE_MOVE = 2;
  18. private $category_object;
  19. private $link_object;
  20. private $extra;
  21. /**
  22. * Builds a form containing form items based on a given parameter
  23. * @param int form_type 1=choose link
  24. * @param obj cat_obj the category object
  25. * @param string form name
  26. * @param method
  27. * @param action
  28. */
  29. function LinkForm($form_type, $category_object,$link_object, $form_name, $method = 'post', $action = null, $extra = null) {
  30. parent :: __construct($form_name, $method, $action);
  31. if (isset ($category_object)) {
  32. $this->category_object = $category_object;
  33. } if (isset ($link_object)) {
  34. $this->link_object = $link_object;
  35. }
  36. if (isset ($extra)) {
  37. $this->extra = $extra;
  38. }
  39. if ($form_type == self :: TYPE_CREATE) {
  40. $this->build_create();
  41. } elseif ($form_type == self :: TYPE_MOVE) {
  42. $this->build_move();
  43. }
  44. //$this->setDefaults();
  45. }
  46. protected function build_move() {
  47. $renderer =& $this->defaultRenderer();
  48. $renderer->setElementTemplate('<span>{element}</span> ');
  49. $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
  50. $this->addElement('static',null,null,get_lang('MoveTo').' : ');
  51. $select = $this->addElement('select','move_cat',null,null);
  52. foreach ($this->link_object->get_target_categories() as $cat) {
  53. for ($i=0;$i<$cat[2];$i++) {
  54. $line .= '&mdash;';
  55. }
  56. $select->addoption($line.' '.$cat[1],$cat[0]);
  57. $line = '';
  58. }
  59. $this->addElement('submit', null, get_lang('Ok'));
  60. }
  61. protected function build_create() {
  62. $this->addElement('header', '', get_lang('MakeLink'));
  63. $select = $this->addElement('select',
  64. 'select_link',
  65. get_lang('ChooseLink'),
  66. null,
  67. array('onchange' => 'document.create_link.submit()'));
  68. $linktypes = LinkFactory :: get_all_types();
  69. $select->addoption('['.get_lang('ChooseLink').']', 0);
  70. $cc = $this->category_object->get_course_code();
  71. foreach ($linktypes as $linktype) {
  72. $link = LinkFactory :: create ($linktype);
  73. if(!empty($cc)) {
  74. $link->set_course_code($cc);
  75. } elseif(!empty($_GET['course_code'])) {
  76. $link->set_course_code(Database::escape_string($_GET['course_code']));
  77. }
  78. // disable this element if the link works with a dropdownlist
  79. // and if there are no links left
  80. if (!$link->needs_name_and_description()
  81. && count($link->get_all_links()) == '0') {
  82. $select->addoption($link->get_type_name(), $linktype, 'disabled');
  83. } else {
  84. $select->addoption($link->get_type_name(), $linktype);
  85. }
  86. }
  87. if (isset($this->extra)) {
  88. $this->setDefaults(array('select_link' => $this->extra));
  89. }
  90. }
  91. }