Browse Source

Configuration basics and users manager added.

master
Rogier Neeleman 9 years ago
parent
commit
1f590a8aec
  1. 122
      application/controllers/config.php
  2. 47
      application/migrations/20160311233300_add_config.php
  3. 50
      application/models/Config_model.php
  4. 2
      application/views/config_common.php
  5. 25
      application/views/config_tabbar.php
  6. 51
      application/views/config_users.php
  7. 45
      application/views/config_users_add.php
  8. 2
      application/views/header.php

122
application/controllers/config.php

@ -0,0 +1,122 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Info Class
*/
class Config extends CI_Controller
{
public function __construct()
{
parent::__construct();
if(! $this->session->userdata('validated')){
redirect(base_url('/login'));
}
if (! ($this->session->admin == '1' OR $this->session->superadmin == '1')) {
redirect(base_url('/dashboard'));
}
}
public function index()
{
$data['page'] = 'config';
$data['tab'] = 'common';
// Header
$this->load->view('header', $data);
// Tab bar
$this->load->view('config_tabbar', $data);
// config page
$this->load->view('config_common', $data);
// Footer
$this->load->view('footer');
}
public function users($action = NULL, $id = NULL)
{
$data['page'] = 'config';
$data['tab'] = 'users';
// Load data
$this->load->model('Config_model');
// Check for post
if ($this->input->post('save')) {
$users = $this->Config_model->get_user_list();
foreach ($users as $user) {
if ($this->input->post('admin'.$user['id']) == 1) {
$update[$user['id']]['admin'] = 1;
} else {
$update[$user['id']]['admin'] = 0;
}
if ($this->input->post('superadmin'.$user['id']) == 1) {
$update[$user['id']]['superadmin'] = 1;
} else {
$update[$user['id']]['superadmin'] = 0;
}
}
// Update user
$this->Config_model->update_user_rights($update);
$data['updatemsg'] = 'Rechten aangepast.';
} elseif ($this->input->post('saveuser')) {
if ($this->input->post('username')) {
$update['username'] = $this->input->post('username');
}
if ($this->input->post('password')) {
$update['password'] = sha1($this->input->post('password'));
}
if ($this->input->post('admin') == 1) {
$update['admin'] = 1;
} else {
$update['admin'] = 0;
}
if ($this->input->post('superadmin') == 1) {
$update['superadmin'] = 1;
} else {
$update['superadmin'] = 0;
}
$update['regioid'] = $this->session->regio;
$this->Config_model->add_user($update);
$data['updatemsg'] = 'Gebruiker aangemaakt.';
}
// Get data
$data['users'] = $this->Config_model->get_user_list();
// Header
$this->load->view('header', $data);
// Tab bar
$this->load->view('config_tabbar', $data);
// If add user
if (isset($action)) {
if ($action == 'add') {
$this->load->view('config_users_add', $data);
} elseif ($action == 'remove') {
if (isset($id)) {
$this->Config_model->remove_user($id);
$data['users'] = $this->Config_model->get_user_list();
$this->load->view('config_users', $data);
}
} else {
$this->load->view('config_users', $data);
}
} else {
// config page
$this->load->view('config_users', $data);
}
//echo "<pre>";
//print_r($update);
//echo "</pre>";
// Footer
$this->load->view('footer');
}
}

47
application/migrations/20160311233300_add_config.php

@ -0,0 +1,47 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Add regio table
*/
class Migration_Add_config extends CI_Migration
{
public function up()
{
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => '5',
'unsigned' => TRUE,
'auto_increment' => TRUE,
),
'regioid' => array(
'type' => 'INT',
'constraint' => '3',
'unsigned' => TRUE,
),
'jaar' => array(
'type' => 'INT',
'constraint' => '4',
'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '80',
),
'value' => array(
'type' => 'VARCHAR',
'constraint' => '80',
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('config');
}
public function down()
{
$this->dbforge->drop_table('config');
}
}

50
application/models/Config_model.php

@ -0,0 +1,50 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Regio model
*/
class Config_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_user_list()
{
$this->db->select('id, username, admin, superadmin');
$this->db->from('user');
$this->db->where('regioid', $this->session->regio);
$this->db->order_by('username', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
public function update_user_rights($users)
{
foreach ($users as $id=>$user)
{
$this->db->where('id', $id);
$this->db->where('regioid', $this->session->regio);
$this->db->update('user', $user);
}
}
public function add_user($user)
{
$this->db->insert('user', $user);
}
public function remove_user($id)
{
$this->db->where('id', $id);
if ($this->session->superadmin != '1') {
$this->db->where('superadmin !=', '1');
}
$this->db->delete('user');
}
}

2
application/views/config_common.php

@ -0,0 +1,2 @@
</div>

25
application/views/config_tabbar.php

@ -0,0 +1,25 @@
<div class="container">
<hr>
<ul class="nav nav-tabs">
<li role="presentation"
<?php if ($tab == "common"){ ?>
class="active"
<?php }; ?>
><a href="<?php echo base_url('config/'); ?>">Algemeen</a></li>
<li role="presentation"
<?php if ($tab == "users"){ ?>
class="active"
<?php }; ?>
><a href="<?php echo base_url('config/users'); ?>">Gebruikers</a></li>
<?php if ($this->session->superadmin == '1') { ?>
<li role="presentation"><a href="<?php echo base_url('config/regios/'); ?>">Regios</a></li>
<?php }; ?>
<li role="presentation"><a href="<?php echo base_url('config/groepen/'); ?>">Groepen</a></li>
<li role="presentation"><a href="<?php echo base_url('config/subgroepen/'); ?>">Subgroepen</a></li>
<li role="presentation"><a href="<?php echo base_url('config/onderdelen/'); ?>">Onderdelen</a></li>
<li role="presentation"><a href="<?php echo base_url('config/spelgebieden/'); ?>">Spelgebieden</a></li>
<li role="presentation"><a href="<?php echo base_url('config/lijsten/'); ?>">Lijsten</a></li>
<li role="presentation"><a href="<?php echo base_url('config/vragen/'); ?>">Vragen</a></li>
</ul>

51
application/views/config_users.php

@ -0,0 +1,51 @@
<br>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?php echo form_open(base_url('config/users/')); ?>
<table class="table table-hover">
<thead>
<tr>
<th>Naam</th>
<th class="text-center">Admin</th>
<?php if ($this->session->superadmin == '1') { ?>
<th class="text-center">Superadmin</th>
<?php }; ?>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user) { ?>
<tr>
<td><?php echo $user['username']; ?></td>
<td class="text-center"><?php echo form_checkbox('admin'.$user['id'], '1', $user['admin']); ?></td>
<?php if ($this->session->superadmin == '1') { ?>
<td class="text-center"><?php echo form_checkbox('superadmin'.$user['id'], '1', $user['superadmin']); ?></td>
<?php }; ?>
<td>
<!-- ><span class="glyphicon glyphicon-cog"></span> -->
<?php if ($this->session->superadmin != '1') { ?>
<?php if ($user['superadmin'] == '1') { ?>
<span class="glyphicon glyphicon-trash"></span>
<?php } else { ?>
<a href="<?php echo base_url('config/users/remove/'.$user['id'])?>"><span class="glyphicon glyphicon-trash text-danger"></span></a>
<?php }; ?>
<?php } else { ?>
<a href="<?php echo base_url('config/users/remove/'.$user['id'])?>"><span class="glyphicon glyphicon-trash text-danger"></span></a>
<?php }; ?>
</td>
</tr>
<?php }; ?>
</tbody>
</table>
<div class="text-right">
<a class="btn btn-default" href="<?php echo base_url('config/users/add/')?>" role="button"><span class="glyphicon glyphicon-plus"></span></a>
<button type="submit" class="btn btn-default" name="save" value="yes"><span class="glyphicon glyphicon-floppy-disk"></span></button>
<br><br>
<?php if (isset($updatemsg)) {?>
<div class="alert alert-success" role="alert"><?php echo $updatemsg?></div>
<?php }; ?>
</div>
</form>
</div>
</div>
</div>

45
application/views/config_users_add.php

@ -0,0 +1,45 @@
<br>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?php echo form_open(base_url('config/users/'), 'class="form-horizontal"'); ?>
<div class='form-group'>
<label for="inputUsername" class="col-sm-4 control-label">Inlognaam</label>
<div class='col-sm-8'>
<?php echo form_input('username', '', 'class="form-control"'); ?>
</div>
</div>
<div class='form-group'>
<label for="inputPassword" class="col-sm-4 control-label">Wachtwoord</label>
<div class='col-sm-8'>
<?php echo form_password('password', '', 'class="form-control"'); ?>
</div>
</div>
<div class='form-group'>
<label for="inputAdmin" class="col-sm-4 control-label">Admin</label>
<div class='col-sm-8'>
<div class="checkbox"><?php echo form_checkbox('admin', '1', '0'); ?></div>
</div>
</div>
<?php if ($this->session->superadmin == '1') { ?>
<div class='form-group'>
<label for="inputSuperAdmin" class="col-sm-4 control-label">Superadmin</label>
<div class='col-sm-8'>
<div class="checkbox"><?php echo form_checkbox('superadmin', '1', '0'); ?></div>
</div>
</div>
<?php }; ?>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8 text-right">
<a class="btn btn-default" href="<?php echo base_url('config/users/')?>" role="button"><span class="glyphicon glyphicon-remove"></span></a>
<button type="submit" class="btn btn-default" name="saveuser" value="yes"><span class="glyphicon glyphicon-floppy-disk"></span></button>
</div>
</div>
</form>
</div>
</div>
</div>

2
application/views/header.php

@ -28,7 +28,7 @@
<li role="presentation" <?php if ($page == 'home') {?> class="active" <?php } ?> ><a href="<?php echo base_url('/');?>">Home</a></li> <li role="presentation" <?php if ($page == 'home') {?> class="active" <?php } ?> ><a href="<?php echo base_url('/');?>">Home</a></li>
<li role="presentation" <?php if ($page == 'beoordelen') {?> class="active" <?php } ?> ><a href="<?php echo base_url('beoordelen/');?>">Beoordelen</a></li> <li role="presentation" <?php if ($page == 'beoordelen') {?> class="active" <?php } ?> ><a href="<?php echo base_url('beoordelen/');?>">Beoordelen</a></li>
<?php if ($this->session->admin == '1' OR $this->session->superadmin == '1') { ?> <?php if ($this->session->admin == '1' OR $this->session->superadmin == '1') { ?>
<li role="presentation" <?php if ($page == 'configuratie') {?> class="active" <?php } ?> ><a href="<?php echo base_url('admin/config/');?>">Configuratie</a></li> <li role="presentation" <?php if ($page == 'config') {?> class="active" <?php } ?> ><a href="<?php echo base_url('config/');?>">Configuratie</a></li>
<?php }; ?> <?php }; ?>
<li role="presentation" <?php if ($page == 'info') {?> class="active" <?php } ?> ><a href="<?php echo base_url('info/');?>">Informatie</a></li> <li role="presentation" <?php if ($page == 'info') {?> class="active" <?php } ?> ><a href="<?php echo base_url('info/');?>">Informatie</a></li>
<?php if ($this->session->superadmin == '1') { ?> <?php if ($this->session->superadmin == '1') { ?>

Loading…
Cancel
Save