Skip to content

Commit

Permalink
Merge pull request benedmunds#332 from adityamenon/2
Browse files Browse the repository at this point in the history
Another partial update to benedmunds#248
  • Loading branch information
benedmunds committed Oct 20, 2012
2 parents 5ce8304 + a5d1476 commit 0449148
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
65 changes: 64 additions & 1 deletion controllers/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ function create_group()
$new_group_id = $this->ion_auth->create_group($this->input->post('group_name'), $this->input->post('description'));
if($new_group_id)
{
// check to see if we are creating the user
// check to see if we are creating the group
// redirect them back to the admin page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth", 'refresh');
Expand Down Expand Up @@ -646,6 +646,69 @@ function create_group()
}
}

//edit a group
function edit_group($id)
{
// bail if no group id given
if(!$id || empty($id))
{
redirect('auth', 'refresh');
}

$this->data['title'] = "Edit Group";

if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
{
redirect('auth', 'refresh');
}

$group = $this->ion_auth->group($id)->row();

//validate form input
$this->form_validation->set_rules('group_name', 'Group name', 'required|alpha_dash|xss_clean');
$this->form_validation->set_rules('group_description', 'Group Description', 'xss_clean');

if (isset($_POST) && !empty($_POST))
{
if ($this->form_validation->run() === TRUE)
{
$group_update = $this->ion_auth->update_group($id, $_POST['group_name'], $_POST['description']);

if($group_update)
{
$this->session->set_flashdata('message', "Group Saved");
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
}
redirect("auth", 'refresh');
}
}

//set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

//pass the user to the view
$this->data['group'] = $group;

$this->data['group_name'] = array(
'name' => 'group_name',
'id' => 'group_name',
'type' => 'text',
'value' => $this->form_validation->set_value('group_name', $group->name),
);
$this->data['description'] = array(
'name' => 'description',
'id' => 'description',
'type' => 'text',
'value' => $this->form_validation->set_value('description', $group->description),
);

$this->load->view('auth/edit_group', $this->data);
}


function _get_csrf_nonce()
{
$this->load->helper('string');
Expand Down
1 change: 1 addition & 0 deletions language/english/ion_auth_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
// Groups
$lang['group_creation_successful'] = 'Group created Successfully';
$lang['group_already_exists'] = 'Group name already taken';
$lang['group_update_successful'] = 'Group details updated';

// Email Subjects
$lang['email_forgotten_password_subject'] = 'Forgotten Password Verification';
Expand Down
38 changes: 38 additions & 0 deletions models/ion_auth_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,44 @@ public function create_group($group_name = FALSE, $group_description = NULL)
return $group_id;
}

/**
* update_group
*
* @return bool
* @author aditya menon
**/
public function update_group($group_id = FALSE, $group_name = FALSE, $group_description = NULL)
{
$mandatory = array($group_id, $group_name);

// bail if no group id or name given
foreach ($mandatory as $mandatory_param) {
if(!$mandatory_param || empty($mandatory_param))
{
return FALSE;
}
}

// bail if the group name already exists
$existing_group = $this->db->get_where('groups', array('name' => $group_name))->row();
if(isset($existing_group->id) && $existing_group->id != $group_id)
{
$this->set_error('group_already_exists');
return FALSE;
}

$query_data = array(
'name' => $group_name,
'description' => $group_description,
);

$this->db->update($this->tables['groups'], $query_data, array('id' => $group_id));

$this->set_message('group_update_successful');

return TRUE;
}

public function set_hook($event, $name, $class, $method, $arguments)
{
$this->_ion_hooks->{$event}[$name] = new stdClass;
Expand Down
20 changes: 20 additions & 0 deletions views/auth/edit_group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>Edit Group</h1>
<p>Please enter the group information below.</p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open(current_url());?>

<p>
Group Name: <br />
<?php echo form_input($group_name);?>
</p>

<p>
Group Description: <br />
<?php echo form_input($group_description);?>
</p>

<p><?php echo form_submit('submit', 'Save Group');?></p>

<?php echo form_close();?>

0 comments on commit 0449148

Please sign in to comment.