Permalink
Browse files

groups cms

  • Loading branch information...
Mubashar Iqbal
Mubashar Iqbal committed Dec 14, 2011
1 parent cd69b3e commit ef0b4941d4b3baad86118c0428e01ac5a6c0b0f1
View
@@ -18,7 +18,7 @@ RewriteRule ^logout$ index.php/$0 [PT,L]
RewriteRule ^-cms$ index.php/cms/home/index [QSA,PT,L]
RewriteRule ^-cms/(.*)$ index.php/cms/$1/index [QSA,PT,L]
RewriteRule ^-cms/(.*)/(.*)$ index.php/cms/$1/$2 [QSA,PT,L]
-RewriteRule ^directory/(.*)$ RewriteCondex.php/filebrowser/access?path=$1 [QSA,PT,L]
+RewriteRule ^directory/(.*)$ index.php/filebrowser/access?path=$1 [QSA,PT,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@@ -0,0 +1,21 @@
+<form action="<?php print SubfolioTheme::get_site_root(); ?>-cms/groups/create" method="post">
+
+ <?php if (isset($errors)) { ?>
+ <span class='big_exclam'>!</span>
+ <ul>
+ <?php foreach ($errors as $error) { ?>
+ <li><?php print $error ?></li>
+ <?php } ?>
+ </ul>
+ <?php } ?>
+
+ <div>
+ <label for="name">Group name:</label>
+ <input type="text" name="name" id="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : '' ?>" tabindex="1" />
+ </div>
+
+ <div>
+ <input type="submit" value="Submit" />
+ </div>
+</form>
+
@@ -0,0 +1,22 @@
+<div class="standard_paragraph">
+ <h2>Groups List</h4>
+ <table width="100%;">
+ <thead>
+ <th>Name</th>
+ <th>Action</th>
+ </thead>
+ <?php
+ foreach ($groups as $name => $group) { ?>
+ <tr>
+ <td>
+ <a href="<?php print SubfolioTheme::get_site_root(); ?>-cms/groups/view/<?php print $name; ?>"><?php print $name; ?></a>
+ </td>
+ <td>
+ <a onclick="javascript:return confirm('Are you sure?');" href="<?php print SubfolioTheme::get_site_root(); ?>-cms/groups/delete/<?php print $name; ?>">delete</a>
+ </td>
+ </li>
+ <?php }
+ ?>
+ </table>
+</div>
+<p><a href="<?php print SubfolioTheme::get_site_root(); ?>-cms/groups/add">Add new group</a></p>
@@ -0,0 +1,20 @@
+<div class="standard_paragraph">
+ <h2>Groups Members: <?php echo $groupname; ?></h4>
+
+ <ul>
+ <?php
+ $count = 0;
+ foreach ($group as $user) {
+ if ($user <> '') {
+ $count ++;
+ ?>
+ <li><?php print $user; ?></li>
+ <?php
+ }
+ }
+
+ if ($count == 0) { ?>
+ <li>No users have been added to this group.</li>
+ <?php } ?>
+ </ul>
+</div>
@@ -1 +1,7 @@
-HOME INDEX
+<div class="standard_paragraph">
+
+ <h2>Subfolio CMS</h2>
+
+ <p>Here you can manage, your <a href="<?php print SubfolioTheme::get_site_root(); ?>-cms/users/">users</a> and <a href="<?php print SubfolioTheme::get_site_root(); ?>-cms/groups/">groups</a>, more coming soon!</p>
+
+</div>
@@ -1,5 +1,5 @@
<div class="standard_paragraph">
- <h4>User List</h4>
+ <h2>Users List</h2>
<table width="100%;">
<thead>
<th>Name</th>
@@ -18,6 +18,7 @@
</td>
<td>
<?php if ($user['admin']) print "Yes" ?>
+ </td>
<td>
<a href="<?php print SubfolioTheme::get_site_root(); ?>-cms/users/edit/<?php print $name; ?>">edit</a> &bull;
<a onclick="javascript:return confirm('Are you sure?');" href="<?php print SubfolioTheme::get_site_root(); ?>-cms/users/delete/<?php print $name; ?>">delete</a>
@@ -0,0 +1,102 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+class Groups_Controller extends Cms_Controller {
+
+ public function __construct() {
+ parent::__construct();
+ $this->check_access();
+ $this->template->content = $this->load_nav();
+ }
+
+ public function index() {
+ $content = View::factory('cms/groups/index');
+ $content->groups = $this->auth->groups();
+ $this->template->content .= $content;
+ }
+
+ public function view($groupname) {
+ $errors = array();
+ $groupArray = $this->auth->get_group_by_name($groupname);
+ if (!$groupArray) {
+ $this->session->set_flash('flash', 'Group not found');
+ url::redirect(SubfolioTheme::get_site_root()."-cms/groups");
+ exit();
+ }
+
+ $content = View::factory('cms/groups/view');
+ $content->groupname = $groupname;
+ $content->group = $groupArray;
+ $this->template->content .= $content;
+ }
+
+ public function add() {
+ $content = View::factory('cms/groups/add');
+ $this->template->content .= $content;
+ }
+
+ public function create() {
+ $errors = array();
+ if ($_POST) {
+ $errors = $this->_validate_group($_POST);
+ if (sizeof($errors) == 0) {
+ // check to see if this user exists already
+ if (!$this->auth->is_group($_POST['name'])) {
+ $group = array('-');
+
+ $this->auth->add_group($_POST['name'], $group);
+ $this->auth->save_groups();
+ $this->session->set_flash('flash', 'Group created');
+ url::redirect(SubfolioTheme::get_site_root()."-cms/groups/view/".$_POST['name']);
+ exit();
+ } else {
+ $errors['name'] = "Group already exists";
+ }
+ }
+ } else {
+ url::redirect(SubfolioTheme::get_site_root()."-cms/groups/add");
+ exit();
+ }
+
+ $content = View::factory('cms/groups/add');
+ $content->errors = $errors;
+ $this->template->content .= $content;
+ }
+
+
+ public function delete($groupname) {
+ $errors = array();
+ $groupArray = $this->auth->get_group_by_name($groupname);
+ if (!$groupArray) {
+ $this->session->set_flash('flash', 'Group not found');
+ url::redirect(SubfolioTheme::get_site_root()."-cms/groups");
+ exit();
+ }
+
+ // delete the user
+ $this->auth->delete_group($groupname);
+ $this->auth->save_groups();
+
+ $this->session->set_flash('flash', 'Group deleted');
+ url::redirect(SubfolioTheme::get_site_root()."-cms/groups");
+ exit();
+ }
+
+
+ // ------------------------------------------------------
+ // PRIVATE
+ // ------------------------------------------------------
+
+ private function _validate_group($data) {
+ $errors = array();
+
+ // name
+ if (!isset($data['name']) || $data['name'] == '') {
+ $errors['name'] = 'Name is required';
+ } else if (strlen($data['name']) > 32) {
+ $errors['name'] = 'Name must be less than 32 characters';
+ } else if (!preg_match('/^[a-z0-9]+$/i', $data['name'])) {
+ $errors['name'] = 'Name must contain only alpha numeric characters';
+ }
+
+ return $errors;
+ }
+}
@@ -83,11 +83,27 @@ public function get_user_by_name($username) {
return NULL;
}
+ public function get_group_by_name($groupname) {
+ if (isset($this->groups[$groupname])) {
+ return $this->groups[$groupname];
+ }
+ return NULL;
+ }
+
public function is_user($username) {
if (isset($this->users[$username])) {
return TRUE;
}
+ return FALSE;
+ }
+
+
+ public function is_group($groupname) {
+ if (isset($this->groups[$groupname])) {
+ return TRUE;
+ }
+
return FALSE;
}

0 comments on commit ef0b494

Please sign in to comment.