예제 #1
0
 public function add_company_selector($required = true)
 {
     $mform =& $this->_form;
     if (company_user::is_company_user()) {
         $mform->addElement('hidden', 'companyid', company_user::companyid());
     } else {
         $companies = company::get_companies_rs();
         $companyoptions = array('' => get_string('selectacompany', 'block_iomad_company_admin'));
         foreach ($companies as $company) {
             if (company_user::can_see_company($company->shortname)) {
                 $companyoptions[$company->id] = $company->name;
             }
         }
         $companies->close();
         if (count($companyoptions) == 1) {
             $mform->addElement('html', get_string('nocompanies', 'block_iomad_company_admin'));
             return false;
         } else {
             $mform->addElement('select', 'companyid', get_string('company', 'block_iomad_company_admin'), $companyoptions);
             if ($required) {
                 $mform->addRule('companyid', get_string('missingcompany', 'block_iomad_company_admin'), 'required', null, 'client');
             }
             $defaultvalues['companyid'] = array($this->selectedcompany);
             $mform->setDefaults($defaultvalues);
         }
     }
     return true;
 }
예제 #2
0
if ($companies = company::get_companies_rs($page, $perpage)) {
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $strusers = $blockpage->get_string('company_users');
    $strnewuser = $blockpage->get_string('newuser');
    $strmanagers = $blockpage->get_string('company_managers');
    $strcourses = $blockpage->get_string('company_courses');
    $strcreatecourse = $blockpage->get_string('newcourse');
    $strcourseusers = $blockpage->get_string('courseusers');
    $strusersdownload = $blockpage->get_string('users_download');
    $table = new html_table();
    $table->head = array("Name", "Short name", "City", "", "", "", "", "", "", "", "", "");
    $table->align = array("left", "left", "left", "center", "center", "center", "center", "center", "center", "center", "center", "center");
    $table->width = "95%";
    foreach ($companies as $company) {
        if (company_user::can_see_company($company)) {
            if (iomad::has_capability('block/iomad_company_admin:company_delete', $context)) {
                $deletebutton = "<a href=\"company_list.php?delete={$company->id}&amp;sesskey=" . sesskey() . "\">{$strdelete}</a>";
            } else {
                $deletebutton = "";
            }
            if (iomad::has_capability('block/iomad_company_admin:company_edit', $context)) {
                $editbutton = "<a href='" . new moodle_url('company_edit_form.php', array("companyid" => $company->id)) . "'>{$stredit}</a>";
            } else {
                $editbutton = "";
            }
            if (iomad::has_capability('block/iomad_company_admin:company_user', $context)) {
                $usersbutton = "<a href='" . new moodle_url('company_users_form.php', array("companyid" => $company->id)) . "'>{$strusers}</a>";
            } else {
                $usersbutton = "";
            }
예제 #3
0
 /**
  * Sets up the page
  *
  * Paramters -
  *             $urlparams = array().
  *
  **/
 public function setup($urlparams = null)
 {
     global $USER;
     // All iomad_company_admin pages require login.
     require_login(null, false);
     // Adds to $PAGE, creates $OUTPUT.
     // Make sure a company user can not retrieve pages for other companies.
     $companyid = optional_param('companyid', 0, PARAM_INTEGER);
     if ($companyid && !company_user::can_see_company($companyid)) {
         throw new Exception(self::get_string('notallowedtoaccessothercompaniesdata'));
     }
     $this->page->set_url($this->get_relative_url($urlparams));
     $this->page->set_context(context_system::instance());
     $this->page->set_pagelayout('mydashboard');
     $blocktitle = self::get_string('blocktitle');
     /**
      * *Think* this bit is deprecated
     $entryurl = optional_param('entryurl', '', PARAM_LOCALURL);
     $entrytitle = optional_param('entrytitle', '', PARAM_TEXT);
     
     if ( $entryurl || $entrytitle ) {
         if ( !isset($USER->iomad) ) {
             $USER->iomad = new stdClass();
         }
     
         if ( $entryurl == (new moodle_url('/')) ) {
             unset($USER->iomad->entrypoint);
             unset($USER->iomad->entrytitle);
         } else {
             $USER->iomad->entrypoint = $entryurl;
             $USER->iomad->entrytitle = $entrytitle;
         }
     }
     */
     $this->page->set_title($this->pagetitle);
     $this->page->set_heading($blocktitle);
 }
예제 #4
0
// Print the form.
echo $OUTPUT->heading(get_string('uploaduserspreview', 'tool_uploaduser'));
$cir->init();
$availableauths = get_plugin_list('auth');
$availableauths = array_keys($availableauths);
$contents = array();
while ($fields = $cir->next()) {
    $errormsg = array();
    $rowcols = array();
    foreach ($fields as $key => $field) {
        $rowcols[$columns[$key]] = $field;
    }
    if ((!isset($rowcols['profile_field_company']) || empty($rowcols['profile_field_company'])) && !company_user::is_company_user() && $companyid == 0) {
        $errormsg['profile_field_company'] = get_string('profile_field_company_not_set', 'block_iomad_company_admin');
    }
    if (isset($rowcols['profile_field_company']) && !company_user::can_see_company($rowcols['profile_field_company'])) {
        $errormsg['profile_field_company'] = get_string('invalid_company', 'block_iomad_company_admin');
    }
    if ($companyid > 0 && isset($rowcols['profile_field_company']) && !empty($rowcols['profile_field_company']) && $rowcols['profile_field_company'] != $companyshortname) {
        $errormsg['profile_field_company'] = get_string('profile_field_company_not_empty_does_not_match_selected', 'block_iomad_company_admin');
    }
    if ((!isset($rowcols['username']) || empty($rowcols['username'])) && isset($rowcols['email']) && !empty($rowcols['email'])) {
        // No username given, try to find an existing user via the email address.
        if ($perfexistinguser = $DB->get_record('user', array('email' => $rowcols['email']))) {
            $rowcols['username'] = $perfexistinguser->username;
        } else {
            // No existing user matches, generate a new username.
            $rowcols['username'] = company_user::generate_username($rowcols['email']);
        }
    }
    $usernameexist = $DB->record_exists('user', array('username' => $rowcols['username']));