dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

Source for file linkaddeditform.class.php

Documentation is available at linkaddeditform.class.php

  1. <?php
  2. include_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  3. include_once (dirname(__FILE__).'/../be.inc.php');
  4. include_once (dirname(__FILE__).'/../gradebook_functions.inc.php');
  5. include_once (api_get_path(LIBRARY_PATH'groupmanager.lib.php');
  6. require_once (api_get_path(LIBRARY_PATH'formvalidator/FormValidator.class.php');
  7.  
  8. /**
  9.  * Form used to add or edit links
  10.  * @author Stijn Konings
  11.  * @author Bert Stepp�
  12.  */
  13. {
  14.  
  15.     const TYPE_ADD = 1;
  16.     const TYPE_EDIT = 2;
  17.  
  18.     /**
  19.      * Constructor
  20.      * To add link, define category_object and link_type
  21.      * To edit link, define link_object
  22.      */
  23.     function LinkAddEditForm($form_type$category_object$link_type$link_object$form_name$action null)
  24.     {
  25.         parent :: __construct($form_name'post'$action);
  26.  
  27.         // set or create link object
  28.         if (isset ($link_object))
  29.             $link $link_object;
  30.         elseif (isset ($link_type&& isset ($category_object))
  31.         {
  32.             $link LinkFactory :: create ($link_type);
  33.             $cc $category_object->get_course_code();
  34.             if(empty($cc&& !empty($_GET['course_code']))
  35.             {
  36.                 $link->set_course_code(Database::escape_string($_GET['course_code']));
  37.             }
  38.             else
  39.             {
  40.                 $link->set_course_code($category_object->get_course_code());
  41.             }
  42.         }
  43.         else
  44.             die ('LinkAddEditForm error: define link_type/category_object or link_object');
  45.  
  46.         $defaults array();
  47.         $this->addElement('hidden''zero'0);
  48.  
  49.         // ELEMENT: name
  50.         if ($form_type == self :: TYPE_ADD || $link->is_allowed_to_change_name())
  51.         {
  52.             if ($link->needs_name_and_description())
  53.             {
  54.                 $this->add_textfield('name',
  55.                                       get_lang('Name'),
  56.                                       true,
  57.                                       array('size'=>'40',
  58.                                             'maxlength'=>'40'));
  59.             }
  60.             else
  61.             {
  62.                 $select $this->addElement('select',
  63.                                             'select_link',
  64.                                             get_lang('ChooseExercise'));
  65.                 foreach ($link->get_all_links(as $newlink)
  66.                     $select->addoption($newlink[1],$newlink[0]);
  67.             }
  68.         }
  69.         else
  70.             $this->addElement('static',
  71.                                 'label',
  72.                                 get_lang('Name'),
  73.                                 $link->get_name().' ['.$link->get_type_name().']');
  74.  
  75.  
  76.         // ELEMENT: weight
  77.         $this->add_textfield('weight'get_lang('Weight'),true,array('size'=>'4','maxlength'=>'4'));
  78.         $this->addRule('weight',get_lang('OnlyNumbers'),'numeric');
  79.         $this->addRule(array ('weight''zero')get_lang('NegativeValue')'compare''>=');
  80.         if ($form_type == self :: TYPE_EDIT)
  81.             $defaults['weight'$link->get_weight();
  82.  
  83.         // ELEMENT: max
  84.         if ($link->needs_max())
  85.         {
  86.             if ($form_type == self :: TYPE_EDIT && $link->has_results())
  87.                 $this->add_textfield('max'get_lang('Max')falsearray ('size' => '4','maxlength' => '4''disabled' => 'disabled'));
  88.             else
  89.             {
  90.                 $this->add_textfield('max'get_lang('Max')truearray ('size' => '4','maxlength' => '4'));
  91.                 $this->addRule('max'get_lang('OnlyNumbers')'numeric');
  92.                 $this->addRule(array ('max''zero')get_lang('NegativeValue')'compare''>=');
  93.             }
  94.             if ($form_type == self :: TYPE_EDIT)
  95.                 $defaults['max'$link->get_max();
  96.         }
  97.         
  98.         // ELEMENT: date
  99.         $this->add_datepicker('date',get_lang('Date'));
  100.         $defaults['date'($form_type == self :: TYPE_EDIT $link->get_date(time());
  101.         
  102.         
  103.         // ELEMENT: description
  104.         if ($link->needs_name_and_description())
  105.         {
  106.             $this->addElement('textarea''description'get_lang('Description')array ('rows' => '3','cols' => '34'));
  107.             if ($form_type == self :: TYPE_EDIT)
  108.                 $defaults['description'$link->get_description();
  109.         }
  110.  
  111.         // ELEMENT: visible
  112.         $visible ($form_type == self :: TYPE_EDIT && $link->is_visible()) '1' '0';
  113.         $this->addElement('checkbox''visible',get_lang('Visible'),null,$visible);
  114.         if ($form_type == self :: TYPE_EDIT)
  115.             $defaults['visible'$link->is_visible();
  116.  
  117.         // ELEMENT: add results
  118.         if ($form_type == self :: TYPE_ADD && $link->needs_results())
  119.             $this->addElement('checkbox''addresult'get_lang('AddResult'));
  120.  
  121.  
  122.         // submit button
  123.         if ($form_type == self :: TYPE_ADD)
  124.             $this->addElement('submit'nullget_lang('Add'));
  125.         else
  126.             $this->addElement('submit'nullget_lang('Edit'));
  127.         
  128.         
  129.         // set default values
  130.         $this->setDefaults($defaults);
  131.  
  132.     }
  133.     
  134.     
  135. }
  136. ?>

Documentation generated on Thu, 12 Jun 2008 13:59:40 -0500 by phpDocumentor 1.4.1