Esempio n. 1
0
function get_costcenter() { 
   
    global $DB,$CFG,$PAGE;
     require_once($CFG->dirroot . '/local/costcenter/lib.php');
     $PAGE->requires->js('/local/batches/js/batches.js');
    $costcenter = new costcenter();
//$designation_list = $DB->get_records_sql('select distinct(designation) as designation from {local_userdata} where designation!=""');
if (is_siteadmin() || is_odmanager()) {
    $costcenters = $DB->get_records('local_costcenter', array('visible' => 1));
} 
else {
    $costcenters = $costcenter->get_assignedcostcenters();
}
  echo "
      <select name='costcenter[]' id=\"assign_selects\"  multiple onchange=\"activate_submit(\'assign_user' . $id . '\',\'assign-user-select' . $id . '\')\" class=\"assign-user-select' . $id . '\">
        <option value='null'>--Select Department--</option>
          <option value='-1'>All</option>";
  
  foreach($costcenters as $costcenter) {
      echo "<option value='$costcenter->id'>$costcenter->fullname</option>";
   }
  echo "</select>"  ;
    
}
     }
 }
 if ($c != 0) {
     echo '<h6 style="color:red;">User name "' . $user->loginid . '" entered at line no. "' . $linenum . '" of uploaded excelsheet is already exists.</h6>';
     goto loop;
 }
 // check  costcenters
 $fac = trim($user->zonecode);
 $costcenter = $DB->get_record('local_costcenter', array('shortname' => $fac));
 if (empty($costcenter)) {
     echo '<h6 style="color:red;">Invalid zonecode name "' . $user->zonecode . '" entered at line no. "' . $linenum . '" of uploaded excelsheet.</h6>';
     goto loop;
 }
 $scid = $costcenter->id;
 $ccenter = new costcenter();
 $costcenters = $ccenter->get_assignedcostcenters();
 if (is_siteadmin()) {
     $costcenters = $ccenter->get_costcenter_items();
 }
 $c = 0;
 foreach ($costcenters as $scl) {
     if ($scid == $scl->id) {
         ++$c;
         break;
     }
 }
 if ($c == 0) {
     echo '<h6 style="color:red;">Sorry you are not assigned to this zonecode "' . $user->zonecode . '" entered at line no. "' . $linenum . '" of uploaded excelsheet.</h6>';
     goto loop;
 }
 // check dob
Esempio n. 3
0
    /**
     * Candidate users
     * @param string $search
     * @return array
     */
    public function find_users($search) {
        global $DB;
        if(!is_siteadmin()){
        $costcenter = new costcenter();
        $costcenterlist = $costcenter->get_assignedcostcenters();
        $costcenterlist = $costcenter->get_costcenter_parent($costcenterlist, $selected = array(), $inctop = false, $all = false);
        $costcenteridin = implode(',', array_keys($costcenterlist));
        $userdata_sql = "select userid from {local_userdata} where costcenterid in($costcenteridin)";
        //if(!empty($this->skillset)&&$this->skillset!=null)
        //$userdata_sql .=" AND skillset='$this->skillset'";
        //if(!empty($this->position)&&$this->position!=null)
        //$userdata_sql .=" AND position='$this->position'";

        $users_list = $DB->get_fieldset_sql($userdata_sql);

        $users_list = implode(',',$users_list);
        }elseif(is_siteadmin()){
        $userdata_sql = "select userid from {local_userdata} where id>0";
        //if(!empty($this->skillset))
        //$userdata_sql .=" AND skillset='$this->skillset'";
        //if(!empty($this->position))
        //$userdata_sql .=" AND position='$this->position'";
        // $userdata_sql;
        $users_list = $DB->get_fieldset_sql($userdata_sql);
         $users_list = implode(',',$users_list);  
        }
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';
       
        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE  $wherecondition";
        if(!empty($users_list) && !is_siteadmin())
        $sql .=" AND u.id in($users_list)";
        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
        $order = ' ORDER BY ' . $sort;
        if (!$this->is_validating()) {
            $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
            if ($potentialmemberscount > $this->maxusersperpage) {
                return $this->too_many_results($search, $potentialmemberscount);
            }
        }
        if(empty($users_list) && !is_siteadmin())  
        $availableusers = array();
        else
         $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));
        
        if (empty($availableusers)) {
            return array();
        }


        if ($search) {
            $groupname = get_string('enrolledusersmatching', 'enrol', $search);
        } else {
            $groupname = get_string('enrolledusers', 'enrol');
        }
 
        return array($groupname => $availableusers);
    }
Esempio n. 4
0
    function definition() {
        global $USER, $CFG, $DB, $PAGE;
        global  $myuser;
        $costcenter = new costcenter();
        $mform = $this->_form;
        $positions=new positions();
        $id = $this->_customdata['id'];
        $editoroptions = $this->_customdata['editoroptions'];
        $filemanageroptions = $this->_customdata['filemanageroptions'];
        $admin = $this->_customdata['admin'];
        $mform->addElement('header', 'moodle', get_string('generaldetails', 'local_users'));

        if (!$admin) {
            $mform->addElement('date_selector', 'dateofapplication', get_string('joiningdate', 'local_users'));
        }

        if (is_siteadmin($USER->id)) {
            $costcenters = $DB->get_records('local_costcenter', array('visible' => 1));
            $Position =$DB->get_records('local_positions',array('visible'=>1));
        } else {
            $costcenters = $costcenter->get_assignedcostcenters();
        }

        $parents = $costcenter->get_costcenter_parent($costcenters, '', $top = true, $all = false);
        $position =$positions->get_positions_parent($Position,'', $top=true, $all = false);
        $count = count($costcenters);
        $mform->addElement('hidden', 'count', $count);
        $mform->setType('count', PARAM_INT);
        if ($id > 0) {
            $mform->addElement('static', 'costcenter_name', get_string('costcenterid', 'local_costcenter'));
            //$mform->addElement('static', 'role_name', get_string('role', 'local_users'));
        } else {
            if ($count == 1) {
                //registrar is assigned to only one costcenter, display as static
                foreach ($costcenters as $scl) {
                    $key = $scl->id;
                    $value = $scl->fullname;
                }
                $mform->addElement('static', 'costcenters', get_string('costcenterid', 'local_costcenter'), $value);
                $mform->addElement('hidden', 'costcenterid', $key);
                $mform->setType('costcenterid', PARAM_INT);
            } else {
                $costcenters = $mform->addElement('select', 'costcenterid', get_string('select', 'local_costcenter'), $parents);
                $mform->addHelpButton('costcenterid', 'assigncostcenter', 'local_costcenter');
                $mform->addRule('costcenterid', get_string('required'), 'required', null, 'client');
            }

          //  $systemroles = $myuser->systemroles_custom();
         //   $mform->addElement('select', 'roleid', get_string('selectrole', 'local_users'), $systemroles);
       //     $mform->addHelpButton('roleid', 'assignrole', 'local_users');
        //    $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
        }

        $mform->addElement('text', 'username', get_string('username', 'local_users'));
        $mform->addRule('username', get_string('required'), 'required', null, 'client');
        $mform->setType('username', PARAM_RAW);

        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);
        if ($id < 0)
            $mform->addRule('newpassword', get_string('required'), 'required', null, 'client');

        $mform->addElement('header', 'moodle', get_string('personaldetails', 'local_users'));
        $mform->addElement('text', 'firstname', get_string('firstname', 'local_users'));
        $mform->addRule('firstname', get_string('required'), 'required', null, 'client');
        $mform->setType('firstname', PARAM_RAW);

        $mform->addElement('text', 'middlename', get_string('middlename', 'local_users'));
        $mform->setType('middlename', PARAM_RAW);

        $mform->addElement('text', 'lastname', get_string('lastname', 'local_users'));
        $mform->addRule('lastname', get_string('required'), 'required', null, 'client');
        $mform->setType('lastname', PARAM_RAW);
        
        //$costcenters = $mform->addElement('select', 'position', get_string('select', 'local_positions'), $position);
        //$mform->addHelpButton('position', 'assignpositions', 'local_positions');
        //$mform->addRule('position', get_string('required'), 'required', null, 'client');

        $radioarray = array();
        $radioarray[] = & $mform->createElement('radio', 'gender', '', get_string('male', 'local_users'), 'M');
        $radioarray[] = & $mform->createElement('radio', 'gender', '', get_string('female', 'local_users'), 'F');
        $mform->addGroup($radioarray, 'gender', 'Gender', array(' '), false);
        $mform->setDefault('gender', 'Male');

        //if (!$admin) {
        //    $mform->addElement('date_selector', 'dob', get_string('dob', 'local_users'));
        //    $mform->addHelpButton('dob', 'dateofbirth', 'local_users');
        //}
        /************************************code by sreekanth**********************************************/
		 $mform->addElement('header', 'otherdetails', get_string('otherdetails', 'local_users'));
		$mform->addElement('text', 'designation', get_string('designation', 'local_users'));
        $mform->setType('designation', PARAM_RAW);
		
		$mform->addElement('text', 'level', get_string('level', 'local_users'));
        $mform->setType('level', PARAM_RAW);
		
		$mform->addElement('date_selector', 'doj', get_string('dateofjoin', 'local_users'));
        
		$mform->addElement('date_selector', 'dob', get_string('dateofbirth', 'local_users'));
		
		$mform->addElement('text', 'eligibility', get_string('eligibility', 'local_users'));
        $mform->setType('eligibility', PARAM_RAW);
		
		$mform->addElement('text', 'vertical', get_string('vertical', 'local_users'));
        $mform->setType('vertical', PARAM_RAW);
		
		$mform->addElement('text', 'state', get_string('state', 'local_users'));
        $mform->setType('state', PARAM_RAW);
		
		$mform->addElement('text', 'branch', get_string('branch', 'local_users'));
		$mform->setType('branch', PARAM_RAW);
		
		$mform->addElement('text', 'jobfunction', get_string('jobfunction', 'local_users'));
        $mform->setType('jobfunction', PARAM_RAW);
		
		$mform->addElement('text', 'grade', get_string('grade', 'local_users'));
        $mform->setType('grade', PARAM_RAW);
		
		 $mform->addElement('text', 'experience', get_string('experience', 'local_users'));
         $mform->setType('experience', PARAM_INT);
		
        $mform->addElement('text', 'qualification', 'Qualification');
        $mform->setType('qualification', PARAM_RAW);
        
		$mform->addElement('text', 'category', get_string('category', 'local_users'));
        $mform->setType('category', PARAM_RAW);
		
		$mform->addElement('text', 'department', get_string('department', 'local_users'));
        $mform->setType('department', PARAM_RAW);
        /*end of code by sreekanth*/
        $mform->addElement('header', 'moodle', get_string('contactdetails', 'local_users'));
        $mform->addElement('text', 'phone1', get_string('phone', 'local_users'));
        $mform->addRule('phone1', get_string('required'), 'required', null, 'client');
        $mform->addRule('phone1', get_string('numeric','local_users'), 'numeric', null, 'client');
        $mform->addRule('phone1', get_string('phoneminimum', 'local_users'), 'minlength', 10, 'client');
        $mform->addRule('phone1', get_string('phonemaximum', 'local_users'), 'maxlength', 15, 'client');
        $mform->setType('phone1', PARAM_RAW);

        $mform->addElement('text', 'email', get_string('email', 'local_users'));
        $mform->addRule('email', get_string('required'), 'required', null, 'client');
        $mform->addRule('email', get_string('emailerror', 'local_users'), 'email', null, 'client');
        $mform->setType('email', PARAM_RAW);

        $mform->addElement('text', 'city', get_string('city'));
        $mform->addRule('city', get_string('required'), 'required', null, 'client');
        $mform->setType('city', PARAM_RAW);

        $country = get_string_manager()->get_list_of_countries();
        $default_country[''] = get_string('selectacountry');
        $country = array_merge($default_country, $country);
        $mform->addElement('select', 'country', get_string('country'), $country);
        $mform->addRule('country', get_string('country_error','local_users'), 'required', null, 'client');
        
       $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
       $mform->setDefault('lang', $CFG->lang);

        $mform->addElement('textarea', 'address', get_string('address', 'local_users'));
        $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
        $mform->setType('description_editor', PARAM_CLEANHTML);
        $mform->addHelpButton('description_editor', 'userdescription');

        $mform->addElement('header', 'moodle', get_string('userpicture', 'local_users'));

        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
        $mform->setDefault('deletepicture', 0);
        $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions);
        $mform->addHelpButton('imagefile', 'newpicture');

        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $submitlable = ($id > 0) ? get_string('updateuser', 'local_users') : get_string('createuser', 'local_users');
        $this->add_action_buttons(true, 'Submit');
    }
Esempio n. 5
0
    public function assign_users($id) {
        global $CFG, $OUTPUT, $DB, $PAGE, $USER;
        $is_manager = $DB->record_exists_sql("select cp.* from {local_costcenter_permissions} as cp 
                             JOIN {role_assignments} as ra ON ra.userid=cp.userid and cp.userid=$USER->id
                             JOIN {role} as r ON r.id=ra.roleid
                             where r.archetype='manager'");
        $urlparams = array('id' => $id);
		$costcenterid = $DB->get_field('learning_learningplan','costcenter',array('id'=>$id));
        $lp_users = $DB->get_fieldset_sql("select u_id from {learning_user_learningplan} where lp_id=$id");
        $lp_users = implode(',', $lp_users);
        if (is_siteadmin()) {
            $managers = $DB->get_records_sql_menu("SELECT u.id,u.username FROM {user} as u RIGHT JOIN {local_costcenter_permissions} as cp ON cp.userid=u.id group by u.id");
            $sql = 'SELECT distinct(u.id), CONCAT(u.firstname," ", u.lastname) FROM {user} as u JOIN {local_userdata} as ud ON u.id=ud.userid and ud.costcenterid='.$costcenterid.'';
        } else if ($is_manager) {
            $costcenter = new costcenter();
            $costcenterlist = $costcenter->get_assignedcostcenters();
            $costcenterlist = $costcenter->get_costcenter_parent($costcenterlist, $selected = array(), $inctop = false, $all = false);
            $costcenteridin = implode(',', array_keys($costcenterlist));
            //$sql = 'SELECT distinct(u.id), CONCAT(u.firstname," ", u.lastname) FROM {user} as u JOIN {local_userdata} as ud ON u.id=ud.userid  where ud.costcenterid in(' . $costcenteridin . ')'; // code commented by sreenivas
            $sql = 'SELECT distinct(u.id), CONCAT(u.firstname," ", u.lastname) FROM {user} as u JOIN {local_userdata} as ud ON u.id=ud.userid  where ud.costcenterid ='.$costcenterid.''; // code added by sreenivas
        }
        if (!empty($lp_users))
            $sql .= ' AND u.id not in(' . $lp_users . ')';
        $users = $DB->get_records_sql_menu($sql, array($params = null), $limitfrom = 0, $limitnum = 0);
        $output = '';
        if (!$users) {
            $output .= $OUTPUT->heading(get_string("nousersyet", 'block_learning_plan'), 5);
        } else {
            if (is_siteadmin()) {
                $users = $users ;
            }
            $output .= '<form autocomplete="off"  id="assign_user' . $id . '" action="view.php" method="post" accept-charset="utf-8" class="mform">';
            $output .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
            $output .= '<input type="hidden" name="viewpage" value="3" />';
            $count = 0;
            $abletomoveusers = false;
            $baseurl = new moodle_url('/blocks/learning_plan/view.php', $urlparams + array('sesskey' => sesskey()));
            $output .= '<fieldset class="hidden"><div><div id="fitem_id_t_id[]" class="fitem fitem_fselect "><div class="fitemtitle"><label for="id_u_id[]">Select users</label></div><div class="felement ftext"><select name="u_id[]" id="assign_selects" size="10" multiple onchange="activate_submit(\'assign_user' . $id . '\',\'assign-user-select' . $id . '\')" class="assign-user-select' . $id . '">';
            foreach ($users as $key => $value) {
                $output .= '<option value=' . $key . '>' . $value . '</option>';
            }
            $output .= "</select></div></div></div></fieldset>";
            $output .= '<input type="hidden" name="l_id" value=' . $id . ' />';
            $output .= '<fieldset class="hidden"><div><div id="fitem_id_submitbutton" class="fitem fitem_actionbuttons fitem_fsubmit"><div class="felement fsubmit"><input type="submit" id="movetoid' . $id . '" class="form-submit" disabled value="Assign users" /></div></div>';
            $output .= '</div></fieldset></form>';
        }
        $output .= html_writer::link(new moodle_url('/blocks/learning_plan/enrolluser.php', array('lpid' => $id)), 'Enroll multiple users');
        return $output;
    }