/**
  * Form tweaks that depend on current data.
  */
 public function definition_after_data()
 {
     global $USER, $SESSION;
     $mform =& $this->_form;
     $columns =& $this->_customdata;
     foreach ($columns as $column) {
         if ($mform->elementExists($column)) {
             $mform->removeElement($column);
         }
     }
     // Set the companyid to bypass the company select form if possible.
     if (!empty($SESSION->currenteditingcompany)) {
         $companyid = $SESSION->currenteditingcompany;
     } else {
         $companyid = company_user::companyid();
     }
     // Get the department list.
     $parentlevel = company::get_company_parentnode($companyid);
     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->departmentid = $userhierarchylevel;
     $subhierarchieslist = company::get_all_subdepartments($userhierarchylevel);
     //  Department drop down.
     $mform->insertElementBefore($mform->createElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $subhierarchieslist, $userhierarchylevel), 'uutypelabel');
     $this->courseselector = $this->add_course_selector();
     $this->add_action_buttons(true, get_string('uploadusers', 'tool_uploaduser'));
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function definition()
 {
     global $USER, $SESSION, $DB;
     $mform =& $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('trainingeventname', 'trainingevent'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->add_intro_editor(true, get_string('trainingeventintro', 'trainingevent'));
     $mform->addElement('date_time_selector', 'startdatetime', get_string('startdatetime', 'trainingevent'));
     $mform->addRule('startdatetime', get_string('missingstartdatetime', 'trainingevent'), 'required', null, 'client');
     $mform->addElement('date_time_selector', 'enddatetime', get_string('enddatetime', 'trainingevent'));
     $mform->addRule('enddatetime', get_string('missingenddatetime', 'trainingevent'), 'required', null, 'client');
     // Set the companyid to bypass the company select form if possible.
     $params = array();
     if (!empty($SESSION->currenteditingcompany)) {
         $params['companyid'] = $SESSION->currenteditingcompany;
     } else {
         if (!empty($USER->company)) {
             $params['companyid'] = company_user::companyid();
         }
     }
     $choices = array();
     if ($rooms = $DB->get_recordset('classroom', $params, 'name', '*')) {
         foreach ($rooms as $room) {
             $choices[$room->id] = $room->name;
         }
         $rooms->close();
     }
     $choices = array('' => get_string('selectaroom', 'trainingevent') . '...') + $choices;
     $mform->addElement('select', 'classroomid', get_string('selectaroom', 'trainingevent'), $choices);
     $mform->addRule('classroomid', get_string('required'), 'required', null, 'client');
     $choices = array(get_string('none', 'trainingevent'), get_string('manager', 'trainingevent'), get_string('companymanager', 'trainingevent'), get_string('both', 'trainingevent'), get_string('enrolonly', 'trainingevent'));
     $mform->addElement('select', 'approvaltype', get_string('approvaltype', 'trainingevent'), $choices);
     $this->standard_grading_coursemodule_elements();
     $this->standard_coursemodule_elements();
     // Add the buttons.
     $this->add_action_buttons(true, false, null);
 }
iomad::require_capability('block/iomad_company_admin:user_upload', $context);
// Correct the navbar.
// Set the name for the page.
$linktext = get_string('users_download', 'block_iomad_company_admin');
// Set the url.
$linkurl = new moodle_url('/blocks/iomad_company_admin/user_bulk_download.php');
// Build the nav bar.
company_admin_fix_breadcrumb($PAGE, $linktext, $linkurl);
$blockpage = new blockpage($PAGE, $OUTPUT, 'iomad_company_admin', 'block', 'user_bulk_download_title');
$blockpage->setup();
// Set the companyid
$companyid = iomad::get_my_companyid($context);
$return = $CFG->wwwroot . '/' . $CFG->admin . '/user/user_bulk.php';
// If company user override the companyid parameter - they can only download their own.
if (company_user::is_company_user()) {
    $companyid = company_user::companyid();
}
// Deal with the departments.
$parentlevel = company::get_company_parentnode($companyid);
$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;
}
if ($format) {
    $fields = array('id' => 'id', 'username' => 'username', 'email' => 'email', 'firstname' => 'firstname', 'lastname' => 'lastname', 'idnumber' => 'idnumber', 'institution' => 'institution', 'department' => 'department', 'phone1' => 'phone1', 'phone2' => 'phone2', 'city' => 'city', 'url' => 'url', 'icq' => 'icq', 'skype' => 'skype', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn', 'country' => 'country');
    // Get company category.
    if ($category = $DB->get_record_sql('SELECT uic.id, uic.name
                                         FROM {user_info_category} uic, {company} c
        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;
    }
}
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$companyid = optional_param('companyid', company_user::companyid(), PARAM_INTEGER);
$departmentid = optional_param('departmentid', 0, PARAM_INTEGER);
$createdok = optional_param('createdok', 0, PARAM_INTEGER);
$userlocation = optional_param('userlocation', 0, PARAM_INTEGER);
// GWL : Get User Location
$createcourses = optional_param_array('currentcourses', null, PARAM_INT);
$context = context_system::instance();
require_login();
iomad::require_capability('block/iomad_company_admin:user_create', $context);
$PAGE->set_context($context);
// GWL : Add Js to add condition of displaying field as per role select
$PAGE->requires->jquery();
$PAGE->requires->js('/blocks/iomad_company_admin/js/company_region_location_management.js');
$PAGE->requires->js_init_call('obj.company_region_location_init', array($CFG->wwwroot));
// End -  GWL : Add Js to add condition of displaying field as per role select
$urlparams = array('companyid' => $companyid);
Esempio n. 6
0
/**
 * Gets the list of outstanding approvals for the current user.
 *
 * returns array
 *
 **/
function approve_enroll_get_my_users()
{
    global $CFG, $DB, $USER, $SESSION;
    require_once $CFG->dirroot . '/local/iomad/lib/company.php';
    require_once $CFG->dirroot . '/local/iomad/lib/user.php';
    // Set the companyid to bypass the company select form if possible.
    if (!empty($SESSION->currenteditingcompany)) {
        $companyid = $SESSION->currenteditingcompany;
    } else {
        if (!empty($USER->company)) {
            $companyid = company_user::companyid();
        } else {
            return false;
        }
    }
    // Check if we can have users of my type.
    if (is_siteadmin($USER->id)) {
        $approvaltype = 'both';
    } else {
        // What type of manager am I?
        if ($manageruser = $DB->get_record('company_users', array('userid' => $USER->id))) {
            if ($manageruser->managertype == 2) {
                $approvaltype = 'manager';
            } else {
                if ($manageruser->managertype == 1) {
                    $approvaltype = 'company';
                } else {
                    return false;
                }
            }
        }
    }
    // Get the list of users I am responsible for.
    $myuserids = company::get_my_users_list($companyid);
    if (!empty($myuserids)) {
        if ($approvaltype == 'manager') {
            //  Need to deal with departments here.
            if ($userarray = $DB->get_records_sql("SELECT beae.* FROM {block_iomad_approve_access} beae\n                                               RIGHT JOIN {trainingevent} cc ON cc.id=beae.activityid\n                                               AND cc.approvaltype in (1,3)\n                                               WHERE beae.companyid=:companyid AND beae.manager_ok = 0\n                                               AND beae.userid != :myuserid\n                                               AND beae.userid\n                                               IN ({$myuserids})", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
        if ($approvaltype == 'company') {
            if ($userarray = $DB->get_records_sql("SELECT beae.* FROM {block_iomad_approve_access} beae\n                                               RIGHT JOIN {trainingevent} cc ON cc.id=beae.activityid\n                                               WHERE beae.companyid=:companyid\n                                               AND beae.userid != :myuserid\n                                               AND beae.userid IN ({$myuserids})\n                                               AND (\n                                                cc.approvaltype in (2,3)\n                                                AND beae.tm_ok = 0 )\n                                               OR (\n                                                cc.approvaltype = 1\n                                                AND beae.manager_ok = 0)", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
        if ($approvaltype == 'both') {
            if ($userarray = $DB->get_records_sql("SELECT * FROM {block_iomad_approve_access}\n                                                   WHERE companyid=:companyid\n                                                   AND (tm_ok = 0 OR manager_ok = 0)\n                                                   AND userid != :myuserid\n                                                   AND userid IN ({$myuserids})", array('companyid' => $companyid, 'myuserid' => $USER->id))) {
                return $userarray;
            }
        }
    }
    return array();
}