linkform.class.php 3.0 KB

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