public function process()
 {
     global $DB;
     if ($this->selectedcompany) {
         $company = new company($this->selectedcompany);
         $companyshortname = $company->get_shortname();
         $companydefaultdepartment = company::get_company_parentnode($company->id);
         // Process incoming assignments.
         if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
             $userstoassign = $this->potentialusers->get_selected_users();
             if (!empty($userstoassign)) {
                 foreach ($userstoassign as $adduser) {
                     $allow = true;
                     if ($allow) {
                         $user = $DB->get_record('user', array('id' => $adduser->id));
                         // Add user to default company department.
                         $company->assign_user_to_company($adduser->id);
                     }
                 }
                 $this->potentialusers->invalidate_selected_users();
                 $this->currentusers->invalidate_selected_users();
             }
         }
         // Process incoming unassignments.
         if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
             $userstounassign = $this->currentusers->get_selected_users();
             if (!empty($userstounassign)) {
                 foreach ($userstounassign as $removeuser) {
                     // Check if the user was a company manager.
                     if ($DB->get_records('company_users', array('userid' => $removeuser->id, 'managertype' => 1))) {
                         $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
                         role_unassign($companymanagerrole->id, $removeuser->id, $this->context->id);
                     }
                     if ($DB->get_records('company_users', array('userid' => $removeuser->id, 'managertype' => 2))) {
                         $departmentmanagerrole = $DB->get_record('role', array('shortname' => 'departmentmanager'));
                         role_unassign($departmentmanagerrole->id, $removeuser->id, $this->context->id);
                     }
                     $DB->delete_records('company_users', array('userid' => $removeuser->id));
                     // Deal with the company theme.
                     $DB->set_field('user', 'theme', '', array('id' => $removeuser->id));
                 }
                 $this->potentialusers->invalidate_selected_users();
                 $this->currentusers->invalidate_selected_users();
             }
         }
     }
 }
iomad::require_capability('block/iomad_company_admin:user_upload', context_system::instance());
// Correct the navbar .
// Set the name for the page.
$linktext = get_string('user_upload_title', 'block_iomad_company_admin');
// Set the url.
$linkurl = new moodle_url('/blocks/iomad_company_admin/uploaduser.php');
// Build the nav bar.
company_admin_fix_breadcrumb($PAGE, $linktext, $linkurl);
$blockpage = new blockpage($PAGE, $OUTPUT, 'iomad_company_admin', 'block', 'user_upload_title');
$blockpage->setup();
// Set the companyid
$companyid = iomad::get_my_companyid($context);
$companyshortname = '';
if ($companyid) {
    $company = new company($companyid);
    $companyshortname = $company->get_shortname();
}
require_login(null, false);
// Adds to $PAGE, creates $OUTPUT.
$systemcontext = context_system::instance();
$struserrenamed = get_string('userrenamed', 'tool_uploaduser');
$strusernotrenamedexists = get_string('usernotrenamedexists', 'error');
$strusernotrenamedmissing = get_string('usernotrenamedmissing', 'error');
$strusernotrenamedoff = get_string('usernotrenamedoff', 'error');
$strusernotrenamedadmin = get_string('usernotrenamedadmin', 'error');
$struserupdated = get_string('useraccountupdated', 'tool_uploaduser');
$strusernotupdated = get_string('usernotupdatederror', 'error');
$strusernotupdatednotexists = get_string('usernotupdatednotexists', 'error');
$strusernotupdatedadmin = get_string('usernotupdatedadmin', 'error');
$struseradded = get_string('newuser');
$strusernotadded = get_string('usernotaddedregistered', 'error');