public function __construct($actionurl, $companyid, $userid, $regionid = 0, $locationid = 0, $returnurl = '')
 {
     global $CFG, $USER;
     $this->selectedcompany = $companyid;
     $this->regionid = $regionid;
     $this->locationid = $locationid;
     $this->userid = $userid;
     $this->returnurl = $this->returnurl;
     //$company = new company($this->selectedcompany);
     // $parentlevel = company::get_company_parentnode($company->id);
     //$this->companydepartment = $parentlevel->id;
     /*
               if (iomad::has_capability('block/iomad_company_admin:edit_all_departments', context_system::instance())) {
               $userhierarchylevel = $parentlevel->id;
               } else {
               $userlevel = company::get_userlevel($USER);
               $userhierarchylevel = $userlevel->id;
               }
     
               $this->subhierarchieslist = company::get_all_subdepartments($userhierarchylevel);
               if ($this->departmentid == 0) {
               $departmentid = $userhierarchylevel;
               } else {
               $departmentid = $this->departmentid;
               }
               $this->userdepartment = $userhierarchylevel; */
     /*
      $options = array('context' => $this->context,
      'multiselect' => true,
      'companyid' => $this->selectedcompany,
      'departmentid' => $departmentid,
      'subdepartments' => $this->subhierarchieslist,
      'parentdepartmentid' => $parentlevel,
      'showopenshared' => true,
      'license' => false);
      $this->currentcourses = new potential_subdepartment_course_selector('currentcourses', $options);
      $this->currentcourses->set_rows(20);
      $this->context = context_coursecat::instance($CFG->defaultrequestcategory);
     */
     parent::moodleform($actionurl);
 }
 public function validation($data, $files)
 {
     global $DB, $CFG;
     $errors = parent::validation($data, $files);
     if ($foundcompanies = $DB->get_records('company', array('name' => $data['name']))) {
         if (!empty($this->companyid)) {
             unset($foundcompanies[$this->companyid]);
         }
         if (!empty($foundcompanies)) {
             foreach ($foundcompanies as $foundcompany) {
                 $foundcompanynames[] = $foundcompany->name;
             }
             $foundcompanynamestring = implode(',', $foundcompanynames);
             $errors['name'] = get_string('companynametaken', 'block_iomad_company_admin', $foundcompanynamestring);
         }
     }
     if ($foundcompanies = $DB->get_records('company', array('shortname' => $data['shortname']))) {
         if (!empty($this->companyid)) {
             unset($foundcompanies[$this->companyid]);
         }
         if (!empty($foundcompanies)) {
             foreach ($foundcompanies as $foundcompany) {
                 $foundcompanyshortnames[] = $foundcompany->shortname;
             }
             $foundcompanynamestring = implode(',', $foundcompanyshortnames);
             $errors['shortname'] = get_string('companyshortnametaken', 'block_iomad_company_admin', $foundcompanynamestring);
         }
     }
     return $errors;
 }
 public function set_data($data)
 {
     parent::set_data($data);
     if ($data['companyid'] > 0) {
         $this->selectedcompany = $data['companyid'];
     }
 }
 public function get_data()
 {
     $data = parent::get_data();
     return $data;
 }
示例#5
0
 public function __construct($actionurl, $companyid, $submitlabelstring)
 {
     $this->selectedcompany = $companyid;
     $this->submitlabel = get_string($submitlabelstring, 'block_iomad_company_admin');
     parent::moodleform($actionurl);
 }
 public function validation($usernew, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($usernew, $files);
     $usernew = (object) $usernew;
     // Validate email.
     if ($DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
         $errors['email'] = get_string('emailexists');
     }
     //GWL : Validate Phone No.
     if ($DB->record_exists('user', array('username' => $usernew->phone, 'mnethostid' => $CFG->mnet_localhost_id))) {
         $errors['phone'] = get_string('phonenumexists');
     }
     /* GWL : Phone no. validation For Company User Reg page */
     if (!preg_match("/^[0-9]{10}\$/", $usernew->phone)) {
         $errors['phone'] = get_string('errorphonenum');
     }
     /* GWL : Phone no. validation For Company User Reg page */
     if (!empty($usernew->newpassword)) {
         $errmsg = '';
         // Prevent eclipse warning.
         if (!check_password_policy($usernew->newpassword, $errmsg)) {
             $errors['newpassword'] = $errmsg;
         }
     }
     // GWL : Code added For Title & Department
     if ($usernew->managertype != 1 && $usernew->managertype != 3) {
         //GWL : Add Instructor
         if (empty($usernew->userregion)) {
             $errors['userregion'] = get_string('selectregion', 'block_iomad_company_admin');
         }
     }
     // End of code
     // It is insecure to send passwords by email without forcing them to be changed on first login.
     if (!$usernew->preference_auth_forcepasswordchange && $usernew->sendnewpasswordemails) {
         $errors['preference_auth_forcepasswordchange'] = get_string('sendemailsforcepasswordchange', 'block_iomad_company_admin', array('forcechange' => get_string('forcepasswordchange'), 'sendemail' => get_string('sendnewpasswordemails', 'block_iomad_company_admin')));
     }
     return $errors;
 }
 public function get_data()
 {
     $data = parent::get_data();
     if ($data !== null && $this->currentcourses) {
         $data->selectedcourses = $this->currentcourses->get_selected_courses();
     }
     return $data;
 }