<?php

class Admins extends Controller {
  function Admins(){
    parent::Controller();
    session_start();
    
	if ($_SESSION['userid'] < 1){
    	redirect('login','refresh');
    }
  }
  
  function index(){
	$data['liID']=$this->uri->segment(2);
	$data['title'] = "Διαχείριση Χρηστών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/admins_home';
	$data['admins'] = $this->MAdmins->getAllUsers();
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  

  
  function create(){
  	$data['liID']=$this->uri->segment(2);
	$this->load->library('encrypt');
   	if ($this->input->post('username')){
  		$this->MAdmins->addUser();
  		$this->session->set_flashdata('message','User created');
  		redirect('admin/admins/index','refresh');
  	}else{
		$data['title'] = "Δημιουργία νέου χρήστη / διαχειρηστή";
		$data['hideColumn']="hideboth";
		$data['main'] = 'admin/admins_create';
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');    
	} 
  }
  
  function edit($id=0){
  	$data['liID']=$this->uri->segment(2);
	$this->load->library('encrypt');
  	if ($this->input->post('username')){
  		$this->MAdmins->updateUser();
  		$this->session->set_flashdata('message','User updated');
  		redirect('admin/admins/index','refresh');
  	}else{
		//$id = $this->uri->segment(4);
		$data['title'] = "Μεταβολή στοιχείων χρήστών";
		$data['hideColumn']="hideboth";
		$data['main'] = 'admin/admins_edit';
		$data['admin'] = $this->MAdmins->getUser($id);
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');    
	}
  }
  
  function delete($id){
	$this->MAdmins->deleteUser($id);
	$this->session->set_flashdata('message','User deleted');
	redirect('admin/admins','refresh');
  }
  
}


?>