public function login_submit() { $user = new Users(); $password = $this->input->post('password'); $username = $this->input->post('username'); $returned_user = $user->login($username, $password); //If user successfully logs in, proceed here if ($returned_user) { //Create basic data to be saved in the session $reply = Users::login($username, $password); $user_data = $reply->toArray(); $access_typeid = $user_data['usertype_id']; $fname = $user_data['fname']; $user_id = $user_data['id']; $lname = $user_data['lname']; $district_id = $user_data['district']; $facility_id = $user_data['facility']; $phone = $user_data['telephone']; $user_email = $user_data['email']; $county_id = $user_data['county_id']; $partner_id = $user_data['partner']; $fullname = $fname . ' ' . $lname; $banner_name = ''; $access_level = Access_level::get_access_level_name($access_typeid); $user_indicator = $access_level['user_indicator']; if ($user_indicator == 'district') { //get subcounty name $district_name = districts::get_district_name_($district_id); $county_name = Counties::get_county_name($county_id); $banner_name = $county_name['county'] . " County" . ", " . $district_name['district'] . " Sub-county "; $facility_no = Facilities::get_district_facilities_using_hcmp($district_id); $facility_count = "Total Facilities Using HCMP in " . $district_name['district'] . " Subcounty: " . count($facility_no); } elseif ($user_indicator == 'county') { //get county name $county_name = Counties::get_county_name($county_id); $banner_name = $county_name['county'] . " County"; $facility_no = Counties::get_facilities_in_county($county_id); $facility_count = "Total Facilities Using HCMP in " . $county_name['county'] . " County: " . count($facility_no); } elseif ($user_indicator == 'facility' || $user_indicator == 'facility_admin' || $user_indicator == 'recovery') { //get facility name $facility_name = Facilities::get_facility_name2($facility_id); $district_name = districts::get_district_name_($district_id); $county_name = Counties::get_county_name($county_id); $banner_name = $county_name['county'] . " County, " . $district_name['district'] . " Sub-county, " . $facility_name['facility_name']; $facility_count = NULL; } $session_data = array('county_id' => $county_id, 'partner_id' => $partner_id, 'phone_no' => $phone, 'user_email' => $user_email, 'user_id' => $user_id, 'user_indicator' => $user_indicator, 'fname' => $fname, 'lname' => $lname, 'facility_id' => $facility_id, 'district_id' => $district_id, 'user_type_id' => $access_typeid, 'full_name' => $fullname, 'banner_name' => $banner_name, 'facility_count' => $facility_count); $this->session->set_userdata($session_data); //get menu items $menu_items = Menu::getByUsertype($access_typeid); //Create array that will hold all the accessible menus in the session $menus = array(); $menuids = array(); $counter = 0; foreach ($menu_items as $menu_item) { $menus[$counter] = array("menu_text" => $menu_item->menu_text, "menu_url" => $menu_item->menu_url, "menu_id" => $menu_item->id, "parent_status" => $menu_item->parent_status); $counter++; $menuids[] = $menu_item->id; } $sub_menus = array(); foreach ($menuids as $parentid) { $sub_items = Sub_menu::getByparent((int) $parentid); foreach ($sub_items as $item) { $sub_menus[] = array("submenu_text" => $item->subm_text, "submenu_url" => $item->subm_url, "menu_id" => $item->parent_id); } } //Save this menus array in the session $this->session->set_userdata("menus", $menus); //Save this sub menus array in the session $_SESSION["submenus"] = $sub_menus; //creating a new log value Log::update_log_out_action($this->session->userdata('user_id')); $facility_code = $this->session->userdata('facility_id'); $u1 = new Log(); $action = 'Logged In'; $u1->user_id = $this->session->userdata('user_id'); $u1->action = $action; $u1->facility_code = $facility_code == 0 ? null : $facility_code; $u1->save(); redirect('home'); } else { $data['popup'] = "errorpopup"; $data['title'] = "Login"; $this->load->view("shared_files/login_pages/login_v", $data); } }
public function tester() { $id = $this->session->userdata('county_id'); $sth = Counties::get_facilities_in_county($id); echo "<pre>"; print_r($sth); echo "</pre>"; exit; }