<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Administrator extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('date');
$this->load->model('location_model', 'location');
$this->load->model('state_model', 'state');
$this->load->model('province_model', 'province');
$this->load->model('member_model', 'member');
$this->load->model('administrator_model', 'admin');
$this->load->model('shout_model', 'shout');
$this->load->model('message_model', 'message');
$this->load->model('event_model', 'event');
$this->load->model('image_model', 'image');
$this->load->model('diary_model', 'diary');
$this->load->model('advertisement_model', 'ad');
$this->load->model('visit_model', 'visit');
$this->load->model('friend_model', 'friend');
$this->load->helper('language');
$this->lang->load('useful_words', 'swedish');
}
public function _remap($function, $params)
{
if ($this->session->userdata('admin') == false) {
$this->index();
}
$member = $this->session->userdata('member');
// user profile
if (intval($function) > 0) {
$id = $function;
if (isset($params[1])) {
$this->$params[1]($id);
} else {
$this->index($id);
}
if ($member !== false) {
if ($id != ($member->id) {
$this->visit->add($id, ($member->id);
}
}
//REMEMBER if blocked (members_modell) then not show
// own profile
} elseif ($member != false) {
$this->$function($member->id);
} elseif ($function == 'login') {
$this->login();
} else {
redirect('home');
}
}
private function login() {
$username = $this->input->post('username');
$password = $this->input->post('password');
$admin = $this->admin->login($username, $password);
if (is_object($admin)) {
$admin_data = array(
'id' => $admin->account_id,
'user' => $admin->username,
'pass' => $admin->password
);
$this->session->set_userdata('admin', $admin_data);
$this->session->unset_userdata('failed_admin_login');
} else {
$this->session->unset_userdata('admin');
$this->session->set_userdata('failed_admin_login', true);
}
redirect('administrator');
}
private function logout() {
$this->session->unset_userdata('admin');
redirect('home');
}
private function load_header()
{
$header['leftside'] = true;
$header['rightside'] = true;
$header['shouts'] = $this->shout->get_list();
$member = $this->session->userdata('member');
if($member != false){
$header['messages'] = $this->message->getUnread($member->id);
}
$this->load->view('header', $header);
}
private function load_footer()
{
$footer['rightside'] = true;
$footer['shouts'] = $this->shout->get_list();
$this->load->view('footer', $footer);
}
public function index($id = 0)
{
$data = array();
/*design*/
$this->load_header();
$this->load->view('administrator/menu');
$this->load->view('administrator/home', $data);
$this->load_footer();
}
private function places($id)
{
$data['countries'] = $this->admin->get_countries();
$data['states'] = $this->admin->get_states();
$data['provinces'] = $this->admin->get_provinces();
/*design*/
$this->load_header();
$this->load->view('administrator/menu');
$this->load->view('administrator/places', $data);
$this->load_footer();
}
public function members($id)
{
$letter = $this->uri->segment(3);
$data['members'] = $this->admin->get_members($letter);
/*design*/
$this->load_header();
$this->load->view('administrator/menu');
$this->load->view('administrator/members', $data);
$this->load_footer();
}
public function reports($id)
{
$data['reports'] = $this->admin->get_reports();
$data['users'] = $this->member->get_list();
/*design*/
$this->load_header();
$this->load->view('administrator/menu');
$this->load->view('administrator/reports', $data);
$this->load_footer();
//its read now
$read = array(
'read' => 1
);
$this->admin->read_report($read);
}
public function text($id)
{
$data['text'] = $this->admin->get_text('1');
$data['text_no'] = $this->admin->get_text('2');
/*design*/
$this->load_header();
$this->load->view('administrator/menu');
$this->load->view('administrator/text', $data);
$this->load_footer();
}
public function save_text($id)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$text=array("content" => $this->input->post('text_swe'));
$this->admin->edit_text(1, $text);
$text=array("content" => $this->input->post('text_no'));
$this->admin->edit_text(2, $text);
}
redirect('administrator/text');
}
public function add_country($id)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['country']) && !empty($_POST['country'])) {
$country = array(
'country_name' => $_POST['country']
);
$this->admin->add_country($country);
}
}
}
public function add_state($id)
{
$state_id = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['country']) && !empty($_POST['country'])) {
$state = array(
'state_name' => $_POST['state'],
'country_id' => $_POST['country']
);
$state_id = $this->admin->add_state($state);
}
}
echo $state_id;
}
public function update_state($id)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$state = array(
'state_name' => $_POST['state'],
'country_id' => $_POST['country']
);
$this->admin->update_state($state, $_POST['stateid']);
}
echo 0;
}
public function add_province($id)
{
$province_id = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['province']) && !empty($_POST['province'])) {
$province = array(
'province_name' => $_POST['province'],
'state_id' => $_POST['state']
);
$province_id = $this->admin->add_province($province);
}
}
echo $province_id;
}
public function update_province($id)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$province = array(
'province_name' => $_POST['province'],
'state_id' => $_POST['state']
);
$this->admin->update_province($province, $_POST['provinceid']);
}
echo 0;
}
public function delete_member($id){
/*REMEMBER
* ARE YOU SURE?
*/
$delete_id = (int) $this->uri->segment(3);
$this->member->delete($delete_id);
redirect('administrator/members');
}
public function update_member($id){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$update_id = $_POST['update_id'];
$member= array(
'membership_id' => $_POST['membership']
);
$this->member->update($update_id, $member);
//var_export($update_id.$_POST['membership']);
}
}
}
/* End of file home.php */
/* Location: ./application/controllers/home.php */