public function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('companyuser', 'block_iomad_company_admin'));
     $mform->addElement('hidden', 'companyid', $this->selectedcompany);
     $mform->setType('companyid', PARAM_INT);
     // Code added by sumit
     $mform->addElement('hidden', 'returnurl', $this->returnurl);
     $mform->setType('returnurl', PARAM_LOCALURL);
     // end of code
     /* copied from /user/editlib.php */
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'id', $this->userid);
     $mform->setType('id', PARAM_INT);
     // Deal with the name order sorting and required fields.
     $necessarynames = useredit_get_required_name_fields();
     foreach ($necessarynames as $necessaryname) {
         $mform->addElement('text', $necessaryname, get_string($necessaryname), 'maxlength="100" size="30"');
         $mform->addRule($necessaryname, $strrequired, 'required', null, 'client');
         $mform->setType($necessaryname, PARAM_NOTAGS);
     }
     // Do not show email field if change confirmation is pending.
     if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
         $notice = get_string('auth_emailchangepending', 'auth_email', $user);
         $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('auth_emailchangecancel', 'auth_email') . '</a>';
         $mform->addElement('static', 'emailpending', get_string('email'), $notice);
     } else {
         $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
         $mform->addRule('email', $strrequired, 'required', null, 'client');
         $mform->setType('email', PARAM_EMAIL);
     }
     /* GWL : Add Field for Username while edit the user */
     $mform->addElement('text', 'username', get_string('phone'), 'size="20"');
     // GWL : Change get_string('username') to 'phone'
     $mform->addRule('username', $strrequired, 'required', null, 'client');
     $mform->setType('username', PARAM_RAW);
     /* GWL : Add Field for Username while edit the user  */
     /* /copied from /user/editlib.php */
     $mform->addElement('static', 'blankline', '', '');
     if (!empty($CFG->passwordpolicy)) {
         $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
     }
     $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
     $mform->addHelpButton('newpassword', 'newpassword');
     $mform->setType('newpassword', PARAM_RAW);
     $mform->addElement('static', 'generatepassword', '', get_string('leavepasswordemptytogenerate', 'block_iomad_company_admin'));
     $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
     $mform->addHelpButton('preference_auth_forcepasswordchange', 'forcepasswordchange');
     // $mform->setDefault('preference_auth_forcepasswordchange', 1);
     $mform->addElement('selectyesno', 'sendnewpasswordemails', get_string('sendnewpasswordemails', 'block_iomad_company_admin'));
     $mform->setDefault('sendnewpasswordemails', 1);
     $mform->disabledIf('sendnewpasswordemails', 'newpassword', 'eq', '');
     // Deal with company optional fields.
     $mform->addElement('header', 'category_id', format_string(get_string('companyprofilefields', 'block_iomad_company_admin')));
     // Department drop down.
     // $mform->addElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $this->subhierarchieslist, $this->userdepartment);
     // Add in company/department manager checkboxes.
     $departmentlist = company_department::get_department_list($this->selectedcompany);
     $titlelist = company_title::get_title_list($this->selectedcompany);
     if ($departmentlist) {
         $mform->addElement('select', 'userdepartment', get_string('department', 'block_iomad_company_admin'), $departmentlist);
     }
     if ($titlelist) {
         $mform->addElement('select', 'usertitle', get_string('title', 'local_manage_company_dept_title'), $titlelist);
     }
     $managerarray = array();
     if (iomad::has_capability('block/iomad_company_admin:assign_department_manager', context_system::instance())) {
         $managerarray['0'] = get_string('user', 'block_iomad_company_admin');
         $managerarray['2'] = get_string('regionlocationmanager', 'block_iomad_company_admin');
     }
     if (iomad::has_capability('block/iomad_company_admin:assign_company_manager', context_system::instance())) {
         if (empty($managearray)) {
             $managerarray['0'] = get_string('user', 'block_iomad_company_admin');
         }
         $managerarray['1'] = get_string('companymanager', 'block_iomad_company_admin');
         $managerarray['3'] = get_string('companyinstructor', 'block_iomad_company_admin');
         //GWL : Add Instructor
     }
     if (!empty($managerarray)) {
         $mform->addElement('select', 'managertype', get_string('managertype', 'block_iomad_company_admin'), $managerarray, 0);
         $mform->addHelpButton('managertype', 'managertype', 'block_iomad_company_admin');
     } else {
         $mform->addElement('hidden', 'managertype', 0);
     }
     // get region list
     $regionslistobj = company::get_all_regions($this->selectedcompany);
     $regionlist = array('' => get_string('regionnotselect', 'block_iomad_company_admin'));
     foreach ($regionslistobj as $region) {
         $regionlist[$region->id] = $region->name;
     }
     // Code added by sumit display region and location drop downs list
     $locationlist = array('' => get_string('choose'));
     if (!empty($this->regionid)) {
         $locationlistarr = company::get_all_locations($this->regionid);
         foreach ($locationlistarr as $location) {
             $locationlist[$location->id] = $location->name;
         }
     }
     $mform->addElement('select', 'userregion', get_string('region', 'block_iomad_company_admin'), $regionlist, array('class' => 'companyregion'));
     $mform->addElement('select', 'userlocation', get_string('location', 'block_iomad_company_admin'), $locationlist, array('id' => 'id_locationid'));
     $mform->disabledIf('userregion', 'managertype', 'eq', 1);
     $mform->disabledIf('userlocation', 'managertype', 'eq', 1);
     $mform->disabledIf('userregion', 'managertype', 'eq', 3);
     //GWL : Add Instructor
     $mform->disabledIf('userlocation', 'managertype', 'eq', 3);
     //GWL : Add Instructor
     // End of Code
     // Get global fields.
     // Get company category.
     if ($companyinfo = $DB->get_record('company', array('id' => $this->selectedcompany))) {
         // Get fields from company category.
         if ($fields = $DB->get_records('user_info_field', array('categoryid' => $companyinfo->profileid))) {
             // Display the header and the fields.
             foreach ($fields as $field) {
                 require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
                 $newfield = 'profile_field_' . $field->datatype;
                 $formfield = new $newfield($field->id);
                 $formfield->edit_field($mform);
                 $mform->setDefault($formfield->inputname, $formfield->field->defaultdata);
             }
         }
     }
     /*
      $mform->addElement('header', 'courses', get_string('courses', 'block_iomad_company_admin'));
      $mform->addElement('html', "<div class='fitem'><div class='fitemtitle'>" .
      get_string('selectenrolmentcourse', 'block_iomad_company_admin') .
      "</div><div class='felement'>");
      $mform->addElement('html', $this->currentcourses->display(true));
      $mform->addElement('html', "</div></div>");
     */
     // add action buttons
     $buttonarray = array();
     //$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('createuseragain', 'block_iomad_company_admin'));
     $buttonarray[] =& $mform->createElement('submit', 'submitandback', get_string('createuserandback', 'block_iomad_company_admin'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
 public function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $company = new company($this->selectedcompany);
     //$departmentslist = company::get_all_departments($company->id);
     $departmentlist = array();
     if ($this->deptid) {
         $departmentlist = array();
         if ($this->locationid) {
             $department = company::get_departmentbyid($this->locationid);
             $departmenttree = company::get_subdepartments($department);
             $parentlist[$department->id] = array($department->id => '/' . $department->name);
             $departmentlist = company::array_flatten($parentlist + company::get_subdepartments_list($departmenttree));
         }
     }
     // Then show the fields about where this block appears.
     if ($this->action == 0) {
         $mform->addElement('header', 'header', get_string('createdepartment', 'block_iomad_company_admin'));
     } else {
         $mform->addElement('header', 'header', get_string('editdepartments', 'block_iomad_company_admin'));
     }
     $regionlist = company::get_all_regions($company->id);
     $regionlistarr = array('' => get_string('choose'));
     foreach ($regionlist as $region) {
         $regionlistarr[$region->id] = $region->name;
     }
     $parentnode = company::get_company_parentnode($this->selectedcompany);
     $context = context_system::instance();
     if (iomad::has_capability('block/iomad_company_admin:edit_all_departments', $context)) {
         $userhierarchylevel = $parentnode->id;
     } else {
         $userlevel = company::get_userlevel($USER);
         $userhierarchylevel = $userlevel->id;
     }
     $showregion = 1;
     $showlocation = 1;
     if ($parentnode->id != $userhierarchylevel) {
         $myregion = company::get_my_region($userhierarchylevel);
         if (!$myregion) {
             $showregion = 0;
         }
         $mylocation = company::get_my_location($userhierarchylevel);
         if (!$mylocation) {
             $showlocation = 0;
         }
     }
     $locationlist = array();
     if ($this->locationid) {
         $locationdetail = company::get_departmentbyid($this->locationid);
         $locationlist[$locationdetail->id] = $locationdetail->name;
     }
     $mform->addElement('hidden', 'departmentid', $this->deptid);
     $mform->setType('departmentid', PARAM_INT);
     $mform->addElement('hidden', 'deptlocation', $this->locationid);
     $mform->setType('deptlocation', PARAM_INT);
     $mform->addElement('hidden', 'action', $this->action);
     $mform->setType('action', PARAM_INT);
     if ($showregion) {
         $mform->addElement('select', 'regionid', get_string('region', 'block_iomad_company_admin'), $regionlistarr);
         $mform->disabledIf('regionid', 'action', 'eq', 1);
     }
     if ($showlocation) {
         $mform->addElement('select', 'locationid', get_string('location', 'block_iomad_company_admin'), $locationlist);
         $mform->disabledIf('locationid', 'action', 'eq', 1);
     }
     if ($departmentlist) {
         $attr = array('class' => 'dept_container');
         if ($this->disabledeptlist) {
             $attr['disabled'] = 'disabled';
         }
         $mform->addElement('select', 'deptid', get_string('department', 'block_iomad_company_admin'), $departmentlist, $attr);
     }
     $mform->addElement('text', 'fullname', get_string('fullnamedepartment', 'block_iomad_company_admin'), 'maxlength = "254" size = "50"');
     $mform->addHelpButton('fullname', 'fullnamedepartment', 'block_iomad_company_admin');
     $mform->addRule('fullname', get_string('missingfullnamedepartment', 'block_iomad_company_admin'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_MULTILANG);
     $mform->addElement('text', 'shortname', get_string('shortnamedepartment', 'block_iomad_company_admin'), 'maxlength = "100" size = "20"');
     $mform->addHelpButton('shortname', 'shortnamedepartment', 'block_iomad_company_admin');
     $mform->addRule('shortname', get_string('missingshortnamedepartment', 'block_iomad_company_admin'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_MULTILANG);
     $mform->addElement('hidden', 'chosenid', $this->chosenid);
     $mform->setType('chosenid', PARAM_INT);
     $this->add_action_buttons();
 }
 public function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $company = new company($this->selectedcompany);
     //$regionlist = company::get_all_regions($company->id);
     $regionlistarr = array();
     $parentnode = company::get_company_parentnode($company->id);
     if ($this->regionid != $parentnode->id) {
         $regionlist = company::get_my_region($this->regionid);
         if ($regionlist) {
             $regionlistarr[$regionlist->id] = '/' . $regionlist->name;
         }
     } else {
         $regionlist = company::get_all_regions($company->id);
         foreach ($regionlist as $region) {
             $regionlistarr[$region->id] = '/' . $region->name;
         }
     }
     $department = company::get_departmentbyid($this->departmentid);
     // Then show the fields about where this block appears.
     if ($this->action == 0) {
         $mform->addElement('header', 'header', get_string('createlocation', 'block_iomad_company_admin'));
     } else {
         $mform->addElement('header', 'header', get_string('editlocations', 'block_iomad_company_admin'));
     }
     $mform->addElement('hidden', 'departmentid', $this->departmentid);
     $mform->setType('departmentid', PARAM_INT);
     $mform->addElement('hidden', 'action', $this->action);
     $mform->setType('action', PARAM_INT);
     if ($regionlist) {
         $select = $mform->addElement('select', 'deptid', get_string('region', 'block_iomad_company_admin'), $regionlistarr);
         //$mform->disabledIf('deptid', 'action', 'eq', 1);
     }
     $mform->addElement('text', 'fullname', get_string('fullnamelocation', 'block_iomad_company_admin'), 'maxlength = "254" size = "50"');
     $mform->addHelpButton('fullname', 'fullnamelocation', 'block_iomad_company_admin');
     $mform->addRule('fullname', get_string('missingfullnamelocation', 'block_iomad_company_admin'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_MULTILANG);
     $mform->addElement('text', 'shortname', get_string('shortnamelocation', 'block_iomad_company_admin'), 'maxlength = "100" size = "20"');
     $mform->addHelpButton('shortname', 'shortnamelocation', 'block_iomad_company_admin');
     $mform->addRule('shortname', get_string('missingshortnamelocation', 'block_iomad_company_admin'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_MULTILANG);
     if (!$this->departmentid) {
         $mform->addElement('hidden', 'chosenid', $this->chosenid);
     } else {
         $mform->addElement('hidden', 'chosenid', $this->departmentid);
     }
     $mform->setType('chosenid', PARAM_INT);
     $this->add_action_buttons();
 }
 public function definition()
 {
     global $CFG, $OUTPUT;
     $mform =& $this->_form;
     $company = new company($this->selectedcompany);
     if (!($parentnode = company::get_company_parentnode($company->id))) {
         // Company has not been set up, possibly from before an upgrade.
         company::initialise_departments($company->id);
     }
     $notcompanymanager = 0;
     if ($this->departmentid != $parentnode->id) {
         $regionlist = company::get_my_region($this->departmentid);
         $notcompanymanager = 1;
     } else {
         $regionlist = company::get_all_regions($company->id);
     }
     //print_object($regionlist);
     //die;
     $companieslist = company::get_companies_select();
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('companyregion', 'block_iomad_company_admin'));
     //GWL : Remove Company Name
     //$mform->addElement('select', 'deptid', get_string('company', 'block_iomad_company_admin'), $companieslist);
     // $mform->addElement('html', $subdepartmenthtml);
     $regionlisthtml = '';
     if (!empty($regionlist)) {
         $regionlisthtml = "<p>" . get_string('regions', 'block_iomad_company_admin') . "</p>";
         $regioncount = 0;
         if (!$notcompanymanager) {
             $regionlisthtml = "<div class='locationlist_container checkboxcontainer'>";
             foreach ($regionlist as $region) {
                 $regioncount++;
                 $regionlisthtml .= '<input type = "checkbox" name = "regionids[]" value="' . $region->id . '" /> ' . $region->name . '</br>';
             }
         } else {
             $regionlisthtml .= '<input type = "checkbox" name = "regionids[]" value="' . $regionlist->id . '" /> ' . $regionlist->name . '</br>';
         }
         $regionlisthtml .= '</div>';
         if ($this->departmentid == $parentnode->id && $regioncount > 1) {
             $regionlisthtml .= '<p><br/><input type="checkbox" id="selectallcheckbox" />Select all / Deselect All</p>';
         }
     } else {
         if (!company::can_manage_department($parentnode->id)) {
             echo $OUTPUT->header();
             echo $OUTPUT->notification(get_string('notaccessregion', 'block_iomad_company_admin'));
             echo $OUTPUT->footer();
             die;
         }
     }
     $mform->addElement('html', $regionlisthtml);
     $buttonarray = array();
     if ($this->departmentid == $parentnode->id) {
         $buttonarray[] = $mform->createElement('submit', 'create', get_string('createregion', 'block_iomad_company_admin'));
     }
     if (!empty($regionlist)) {
         $buttonarray[] = $mform->createElement('submit', 'edit', get_string('editregions', 'block_iomad_company_admin'), array('class' => 'editdepart'));
         if ($this->departmentid == $parentnode->id) {
             $buttonarray[] = $mform->createElement('submit', 'delete', get_string('deleteregion', 'block_iomad_company_admin'));
         }
     }
     $mform->addGroup($buttonarray, '', array(' '), ' ', false);
 }