/**
  * Server side validation.
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $columns =& $this->_customdata;
     $optype = $data['uutype'];
     // Detect if password column needed in file.
     if (!in_array('password', $columns)) {
         switch ($optype) {
             case UU_UPDATE:
                 if (!empty($data['uupasswordold'])) {
                     $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_ADD_UPDATE:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 if (!empty($data['uupasswordold'])) {
                     $errors['uupasswordold'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_ADDNEW:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
             case UU_ADDINC:
                 if (empty($data['uupasswordnew'])) {
                     $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password');
                 }
                 break;
         }
     }
     // Look for other required data.
     if ($optype != UU_UPDATE) {
         if (!in_array('firstname', $columns)) {
             $errors['uutype'] = get_string('missingfield', 'error', 'firstname');
         }
         if (!in_array('lastname', $columns)) {
             if (isset($errors['uutype'])) {
                 $errors['uutype'] = '';
             } else {
                 $errors['uutype'] = ' ';
             }
             $errors['uutype'] .= get_string('missingfield', 'error', 'lastname');
         }
         if (!in_array('email', $columns) and empty($data['email'])) {
             $errors['email'] = get_string('requiredtemplate', 'tool_uploaduser');
         }
     }
     return $errors;
 }
 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 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;
 }