[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/course/ -> request_form.php (source)

   1  <?php  // $Id: request_form.php,v 1.11.2.1 2007/11/23 22:12:35 skodak Exp $
   2  
   3  require_once($CFG->libdir.'/formslib.php');
   4  
   5  class course_request_form extends moodleform {
   6      function definition() {
   7          $mform =& $this->_form;
   8  
   9          $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
  10          $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
  11          $mform->setType('fullname', PARAM_TEXT);
  12  
  13          $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="100" size="20"');
  14          $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
  15          $mform->setType('shortname', PARAM_TEXT);
  16  
  17          $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
  18          $mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
  19          $mform->setType('summary', PARAM_RAW);
  20          $mform->setHelpButton('summary', array('text', get_string('helptext')));
  21  
  22  
  23          $mform->addElement('textarea', 'reason', get_string('courserequestreason'), array('rows'=>'15', 'cols'=>'50'));
  24          $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
  25          $mform->setType('reason', PARAM_TEXT);
  26  
  27          $mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
  28          $mform->setType('password', PARAM_RAW);
  29  
  30  
  31          $this->add_action_buttons();
  32      }
  33  
  34      function validation($data, $files) {
  35          $errors = parent::validation($data, $files);
  36          $foundcourses = null;
  37          $foundreqcourses = null;
  38  
  39          if (!empty($data['shortname'])) {
  40              $foundcourses = get_records('course', 'shortname', $data['shortname']);
  41              $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
  42          }
  43          if (!empty($foundreqcourses)) {
  44              if (!empty($foundcourses)) {
  45                  $foundcourses = array_merge($foundcourses, $foundreqcourses);
  46              } else {
  47                  $foundcourses = $foundreqcourses;
  48              }
  49          }
  50  
  51          if (!empty($foundcourses)) {
  52  
  53              if (!empty($foundcourses)) {
  54                  foreach ($foundcourses as $foundcourse) {
  55                      if (isset($foundcourse->requester) && $foundcourse->requester) {
  56                          $pending = 1;
  57                          $foundcoursenames[] = $foundcourse->fullname.' [*]';
  58                      } else {
  59                          $foundcoursenames[] = $foundcourse->fullname;
  60                      }
  61                  }
  62                  $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
  63  
  64                  $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
  65                  if (!empty($pending)) {
  66                      $errors['shortname'] .= get_string('starpending');
  67                  }
  68              }
  69          }
  70  
  71          return $errors;
  72      }
  73  
  74  }
  75  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7