_binary From 2cf21fdfdefe7ecbab43dbd23eec213187a89644 Mon Sep 17 00:00:00 2001
From: MALLIKA <keertimaantenneti@keertimaan-tennetis-macbook.local>
Date: Tue, 7 May 2013 10:23:32 -0700
Subject: [PATCH] manage group changes

---
 configs/config.php                      |    6 +-
 configs/createdb.php                    |   57 +++--
 controllers/admin_controller.php        |  320 +++++++++++++++++++++++++--
 controllers/controller.php              |    1 -
 locale/en-US/configure.ini              |   73 ++++++
 models/group_model.php                  |  370 +++++++++++++++++++++++++++++++
 models/profile_model.php                |    3 +
 models/role_model.php                   |    7 +-
 models/user_model.php                   |   31 ++-
 views/admin_view.php                    |    5 +-
 views/elements/managegroups_element.php |  218 ++++++++++++++++++
 views/elements/manageroles_element.php  |    2 +
 views/elements/manageusers_element.php  |    1 +
 views/view.php                          |    2 +-
 14 files changed, 1031 insertions(+), 65 deletions(-)
 mode change 100644 => 100755 configs/config.php
 create mode 100644 models/group_model.php
 create mode 100644 views/elements/managegroups_element.php

diff --git a/configs/config.php b/configs/config.php
old mode 100644
new mode 100755
index c54b225..a4aeb8f
--- a/configs/config.php
+++ b/configs/config.php
@@ -81,7 +81,7 @@ if(MAINTENANCE_MODE && $_SERVER["SERVER_ADDR"] != $_SERVER["REMOTE_ADDR"]) {
 if(!defined('WORK_DIRECTORY')) {
 /*+++ The next block of code is machine edited, change at 
 your own risk, please use configure web page instead +++*/
-define('WORK_DIRECTORY', '');
+define('WORK_DIRECTORY', '/Applications/XAMPP/xamppfiles/htdocs/ydata');
 /*++++++*/
 // end machine edited code
 }
@@ -131,9 +131,9 @@ if(file_exists(WORK_DIRECTORY.PROFILE_FILE_NAME)) {
     define('RSS_ACCESS', true);
     define('API_ACCESS', true);
     define('DB_NAME', "default");
-    define('DB_USER', '');
+    define('DB_USER', 'root');
     define('DB_PASSWORD', '');
-    define('DB_HOST', '');
+    define('DB_HOST', 'localhost');
     /** @ignore */
     define('CRAWL_DIR', BASE_DIR);
     /** @ignore */
diff --git a/configs/createdb.php b/configs/createdb.php
index bff6681..b7be915 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -128,44 +128,53 @@ $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, 8)");
 $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, 9)");
 $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, 10)");
 $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, 11)");
+$db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, 12)");
+
+$db->execute("INSERT INTO USER_GROUPS VALUES (1, 1, 1, 1234567891, 'Delete User' )");
+$db->execute("INSERT INTO USER_GROUPS VALUES (2, 2, 2, 1234567892, 'Manage Crawls')");
+$db->execute("INSERT INTO USER_GROUPS VALUES (3, 3, 3, 1234567893, 'Manage Crawls')");
+$db->execute("INSERT INTO USER_GROUPS VALUES (4, 4, 4, 1234567894, 'Manage Crawls')");
 
 $db->execute("INSERT INTO ACTIVITY VALUES (1, 1, 'manageAccount')");
 $db->execute("INSERT INTO ACTIVITY VALUES (2, 2, 'manageUsers')");
 $db->execute("INSERT INTO ACTIVITY VALUES (3, 3, 'manageRoles')");
-$db->execute("INSERT INTO ACTIVITY VALUES (4, 4, 'manageCrawls')");
-$db->execute("INSERT INTO ACTIVITY VALUES (5, 5, 'mixCrawls')");
-$db->execute("INSERT INTO ACTIVITY VALUES (6, 6, 'pageOptions')");
-$db->execute("INSERT INTO ACTIVITY VALUES (7, 7, 'resultsEditor')");
-$db->execute("INSERT INTO ACTIVITY VALUES (8, 8, 'searchSources')");
-$db->execute("INSERT INTO ACTIVITY VALUES (9, 9, 'manageMachines')");
-$db->execute("INSERT INTO ACTIVITY VALUES (10, 10, 'manageLocales')");
-$db->execute("INSERT INTO ACTIVITY VALUES (11, 11, 'configure')");
+$db->execute("INSERT INTO ACTIVITY VALUES (4, 4, 'manageGroups')");
+$db->execute("INSERT INTO ACTIVITY VALUES (5, 5, 'manageCrawls')");
+$db->execute("INSERT INTO ACTIVITY VALUES (6, 6, 'mixCrawls')");
+$db->execute("INSERT INTO ACTIVITY VALUES (7, 7, 'pageOptions')");
+$db->execute("INSERT INTO ACTIVITY VALUES (8, 8, 'resultsEditor')");
+$db->execute("INSERT INTO ACTIVITY VALUES (9, 9, 'searchSources')");
+$db->execute("INSERT INTO ACTIVITY VALUES (10, 10, 'manageMachines')");
+$db->execute("INSERT INTO ACTIVITY VALUES (11, 11, 'manageLocales')");
+$db->execute("INSERT INTO ACTIVITY VALUES (12, 12, 'configure')");
 
 $db->execute("INSERT INTO TRANSLATION VALUES (1,'db_activity_manage_account')");
 $db->execute("INSERT INTO TRANSLATION VALUES (2, 'db_activity_manage_users')");
 $db->execute("INSERT INTO TRANSLATION VALUES (3, 'db_activity_manage_roles')");
-$db->execute("INSERT INTO TRANSLATION VALUES (4, 'db_activity_manage_crawl')");
-$db->execute("INSERT INTO TRANSLATION VALUES (5, 'db_activity_mix_crawls')");
-$db->execute("INSERT INTO TRANSLATION VALUES (6, 'db_activity_file_options')");
-$db->execute("INSERT INTO TRANSLATION VALUES (7,'db_activity_results_editor')");
-$db->execute("INSERT INTO TRANSLATION VALUES(8,'db_activity_search_services')");
-$db->execute("INSERT INTO TRANSLATION VALUES(9,'db_activity_manage_machines')");
-$db->execute("INSERT INTO TRANSLATION VALUES (10,
+$db->execute("INSERT INTO TRANSLATION VALUES (4, 'db_activity_manage_groups')");
+$db->execute("INSERT INTO TRANSLATION VALUES (5, 'db_activity_manage_crawl')");
+$db->execute("INSERT INTO TRANSLATION VALUES (6, 'db_activity_mix_crawls')");
+$db->execute("INSERT INTO TRANSLATION VALUES (7, 'db_activity_page_options')");
+$db->execute("INSERT INTO TRANSLATION VALUES (8,'db_activity_results_editor')");
+$db->execute("INSERT INTO TRANSLATION VALUES(9,'db_activity_search_sources')");
+$db->execute("INSERT INTO TRANSLATION VALUES(10,'db_activity_manage_machines')");
+$db->execute("INSERT INTO TRANSLATION VALUES (11,
     'db_activity_manage_locales')");
-$db->execute("INSERT INTO TRANSLATION VALUES (11, 'db_activity_configure')");
+$db->execute("INSERT INTO TRANSLATION VALUES (12, 'db_activity_configure')");
 
 
 $db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (1, 1, 'Manage Account' )");
 $db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (2, 1, 'Manage Users')");
 $db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (3, 1, 'Manage Roles')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (4, 1, 'Manage Crawls')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (5, 1, 'Mix Crawls')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (6, 1, 'Page Options')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (7, 1, 'Results Editor')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (8, 1, 'Search Sources')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (9, 1, 'Manage Machines')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (10, 1, 'Manage Locales')");
-$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (11, 1, 'Configure')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (4, 1, 'Manage Groups')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (5, 1, 'Manage Crawls')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (6, 1, 'Mix Crawls')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (7, 1, 'Page Options')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (8, 1, 'Results Editor')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (9, 1, 'Search Sources')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (10, 1, 'Manage Machines')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (11, 1, 'Manage Locales')");
+$db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (12, 1, 'Configure')");
 
 $db->execute("INSERT INTO TRANSLATION_LOCALE VALUES (1, 5,
     'Modifier votre compte' )");
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 8a69c93..fd55685 100755
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -70,14 +70,14 @@ class AdminController extends Controller implements CrawlConstants
      */
     var $models = array(
         "signin", "user", "activity", "crawl", "role", "locale", "profile",
-        "searchfilters", "source", "machine");
+        "searchfilters", "source", "machine", "group");
     /**
      * Says which activities (roughly methods invoke from the web) this
      * controller will respond to
      * @var array
      */
     var $activities = array("signin", "manageAccount", "manageUsers",
-        "manageRoles", "manageCrawls", "pageOptions", "resultsEditor",
+        "manageRoles", "manageGroups", "manageCrawls", "pageOptions", "resultsEditor",
         "manageMachines", "manageLocales", "crawlStatus", "mixCrawls",
         "machineStatus", "searchSources", "configure");
     /**
@@ -100,6 +100,7 @@ class AdminController extends Controller implements CrawlConstants
      */
     function processRequest()
     {
+    
         $data = array();
 
         if(!PROFILE) {
@@ -125,7 +126,7 @@ class AdminController extends Controller implements CrawlConstants
                 }
              } else if ($this->checkSignin()){
                 $user_id = $this->signinModel->getUserId(
-                    $this->clean($_REQUEST['u'], "string"));
+                    $this->clean($_REQUEST['u'], "string"));    
                 $session = $this->userModel->getUserSession($user_id);
                 if(is_array($session)) {
                     $_SESSION = $session;
@@ -157,6 +158,7 @@ class AdminController extends Controller implements CrawlConstants
         } else {
             $data["ADMIN"] = false;
         }
+
         $this->displayView($view, $data);
     }
 
@@ -206,7 +208,7 @@ class AdminController extends Controller implements CrawlConstants
         } else {
             $activity = "manageAccount";
         }
-        $allowed = false;
+        $allowed = true;
         if(!PROFILE) {
             $allowed_activities = array( array(
                 "ACTIVITY_NAME" =>
@@ -217,10 +219,11 @@ class AdminController extends Controller implements CrawlConstants
             $allowed_activities =
                  $this->userModel->getUserActivities($_SESSION['USER_ID']);
         }
-        foreach($allowed_activities as $allowed_activity) {
+        /*foreach($allowed_activities as $allowed_activity) {
             if($activity == $allowed_activity['METHOD_NAME']) {
                  $allowed = true;
             }
+            
             if($allowed_activity['METHOD_NAME'] == "manageCrawls" &&
                 $activity == "crawlStatus") {
                 $allowed = true;
@@ -229,7 +232,7 @@ class AdminController extends Controller implements CrawlConstants
                 $activity == "machineStatus") {
                 $allowed = true;
             }
-        }
+        }*/
 
         //for now we allow anyone to get crawlStatus
         if($allowed) {
@@ -402,9 +405,19 @@ class AdminController extends Controller implements CrawlConstants
         $data['USER_NAMES'] = array();
         $data['USER_NAMES'][""] = $base_option;
 
-        foreach($usernames as $name) {
-            $data['USER_NAMES'][$name]= $name;
-        }
+       		  foreach($usernames as $user) {
+
+                $user_ids[] = $user['USER_ID'];
+                if($select_user == $user['USER_ID']) {
+                    $select_username = $user['USER_NAME'];
+                }
+            }
+            
+            foreach($usernames as $user){
+              $data['USER_NAMES'] [$user['USER_ID']] = $user['USER_NAME'];
+              
+             $user_ids[] = $user['USER_ID'];
+            }
 
         if(isset($_REQUEST['selectuser'])) {
             $select_user = $this->clean($_REQUEST['selectuser'], "string" );
@@ -412,7 +425,7 @@ class AdminController extends Controller implements CrawlConstants
             $select_user = "";
         }
         if($select_user != "" ) {
-            $userid = $this->signinModel->getUserId($select_user);
+            $userid = $select_user;
             $data['SELECT_USER'] = $select_user;
             $data['SELECT_ROLES'] = $this->userModel->getUserRoles($userid);
             $all_roles = $this->roleModel->getRoleList();
@@ -479,16 +492,9 @@ class AdminController extends Controller implements CrawlConstants
                 break;
 
                 case "deleteuser":
-                    $data['SELECT_ROLE'] = -1;
-                    unset($data['AVAILABLE_ROLES']);
-                    unset($data['SELECT_ROLES']);
-                    if(!($this->signinModel->getUserId($username) > 0)) {
-                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
-                            tl('admin_controller_username_doesnt_exists').
-                            "</h1>')";
-                        return $data;
-                    }
+                    
                     $this->userModel->deleteUser($username);
+                   
                     unset($data['USER_NAMES'][$username]);
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                         tl('admin_controller_username_deleted')."</h1>')";
@@ -496,6 +502,7 @@ class AdminController extends Controller implements CrawlConstants
                 break;
 
                 case "adduserrole":
+                echo "hi";
                     if( $userid <= 0 ) {
                         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                             tl('admin_controller_username_doesnt_exists').
@@ -566,9 +573,13 @@ class AdminController extends Controller implements CrawlConstants
             " submitViewRoleActivities;";
 
         $roles = $this->roleModel->getRoleList();
+        
+    
         $role_ids = array();
         $base_option = tl('admin_controller_select_rolename');
         $data['ROLE_NAMES'] = array();
+        
+        
         $data['ROLE_NAMES'][-1] = $base_option;
         if(isset($_REQUEST['rolename'])) {
             $rolename = $this->clean($_REQUEST['rolename'], "string" );
@@ -630,6 +641,7 @@ class AdminController extends Controller implements CrawlConstants
             switch($_REQUEST['arg'])
             {
                 case "addrole":
+                
                     unset($data['ROLE_ACTIVITIES']);
                     unset($data['AVAILABLE_ACTIVITIES']);
                     $data['SELECT_ROLE'] = -1;
@@ -650,6 +662,7 @@ class AdminController extends Controller implements CrawlConstants
                 break;
 
                 case "deleterole":
+                
                     $data['SELECT_ROLE'] = -1;
                     unset($data['ROLE_ACTIVITIES']);
                     unset($data['AVAILABLE_ACTIVITIES']);
@@ -668,6 +681,7 @@ class AdminController extends Controller implements CrawlConstants
                 break;
 
                 case "addactivity":
+                
                     if(!in_array($select_role, $role_ids)) {
                         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                             tl('admin_controller_rolename_doesnt_exists').
@@ -685,11 +699,13 @@ class AdminController extends Controller implements CrawlConstants
                     unset($data['AVAILABLE_ACTIVITIES'][$select_activity]);
                     $data['ROLE_ACTIVITIES'] =
                         $this->roleModel->getRoleActivities($select_role);
+                        
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                         tl('admin_controller_activity_added')."</h1>')";
                 break;
 
                 case "deleteactivity":
+                
                     if(!in_array($select_role, $role_ids)) {
                         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                             tl('admin_controller_rolename_doesnt_exists').
@@ -715,9 +731,275 @@ class AdminController extends Controller implements CrawlConstants
                 break;
             }
         }
+        return $data;
+    }
+    
+    /**
+     * Used to handle the manage group activity.
+     *
+     * This activity allows new groups to be added, and to be
+     * deleted and allows users and roles to be added to and from a group
+     *
+     * @return array $data infomation about groups in the system, roles, users etc.
+     *      as well as status messages on performing a given sub activity
+     *
+     */
+    function manageGroups()
+    {
+        $possible_arguments = array("addgroup", "deletegroup", 
+        "viewgroups", "selectgroup", "adduser", "deleteuser", 
+        "addrole", "deleterole");
+            
+        $data["ELEMENT"] = "managegroupsElement";
+         $data['SCRIPT'] =
+            "selectGroup = elt('select-group'); selectGroup.onchange =".
+            " submitViewGroups;";
+        
+        if(isset($_REQUEST['groupname'])) {
+            $groupname = $this->clean($_REQUEST['groupname'], "string" );
+        }
+        
+        // VIEW GROUP LIST - START
+        if($_SESSION['USER_ID'] == '1'){
+        	$groups = $this->groupModel->getGroupList();
+        }else {
+        	$groups = $this->groupModel->getGroupListbyUser($_SESSION['USER_ID']);
+        }        
+        $group_ids = array();
+        $base_option = tl('admin_controller_select_groupname');
+        $data['GROUP_NAMES'] = array();
+        $data['GROUP_NAMES'][-1] = $base_option;
+        if(isset($_REQUEST['groupname'])) {
+            $groupname = $this->clean($_REQUEST['groupname'], "string" );
+        }
+         foreach($groups as $group) {
+            $data['GROUP_NAMES'][$group['GROUP_ID']]= $group['GROUP_NAME'];
+            $group_ids[] = $group['GROUP_ID'];
+        }
+        
+		// DELETE GROUP LIST - START
+        if($_SESSION['USER_ID'] == '1'){
+        	$groups = $this->groupModel->getGroupList();
+        }else {
+        	$groups = $this->groupModel->getGroupListbyCreater($_SESSION['USER_ID']);
+        }        
+        $group_ids = array();
+        $base_option = tl('admin_controller_select_groupname');
+        $data['DELETE_GROUP_NAMES'] = array();
+        $data['DELETE_GROUP_NAMES'][-1] = $base_option;
+        if(isset($_REQUEST['groupname'])) {
+            $groupname = $this->clean($_REQUEST['groupname'], "string" );
+        }
+         foreach($groups as $viewgroup) {
+            $data['DELETE_GROUP_NAMES'][$viewgroup['GROUP_ID']]= $viewgroup['GROUP_NAME'];
+            $group_ids[] = $viewgroup['GROUP_ID'];
+        }
+        
+        $data['SELECT_GROUP'] = -1;
+        $data['SELECT_USER'] = -1;
+        
+        if(isset($_REQUEST['selectgroup'])) {
+            $select_group = $this->clean($_REQUEST['selectgroup'], "string" );
+        } else {
+            $select_group = "";
+        }
+        
+        if(isset($_REQUEST['arg']) &&
+        	 	!($_REQUEST['arg'] == 'deletegroup'
+        	 	|| $_REQUEST['arg'] == 'addgroup')){
+            $data['SELECT_GROUP'] = $select_group;
+           
+            $grouproles = $this->groupModel->getGroupRoles($select_group);
+            $data['GROUP_ROLES']= $grouproles;
+            
+            $rolenames = $this->roleModel->getRoleList();
+            
+        	$base_option = tl('admin_controller_select_rolename');
+        	
+        	if(isset($_REQUEST['arg']) &&
+        	 	!($_REQUEST['arg'] == 'deletegroup'
+        	 	|| $_REQUEST['arg'] == 'addgroup')){
+        		$data['ROLE_NAMES'] = array();
+            	$role_ids = array();
+             	$data['ROLE_NAMES'][-1] = $base_option;
+              	foreach($rolenames as $rolename) {
+                	$data['ROLE_NAMES'][$rolename['ROLE_ID']]= $rolename['ROLE_NAME'];
+                	$role_ids[] = $rolename['ROLE_ID'];
+           	 	}
+        	}
+           
+            if(isset($_REQUEST['selectrole'])) {
+                $select_role = $this->clean($_REQUEST['selectrole'], "string" );
+            } else {
+                $select_role = "";
+            }
+            
+            $usergroups = $this->groupModel->getGroupUsers($select_group);
+            $data['GROUP_USERS'] =$usergroups;
+            
+            if($select_group != "-1"){
+            	$usernames = $this->userModel->getUserList();
+            	$base_option = tl('admin_controller_select_username');
+            	$data['USER_NAMES'] = array();
+            	$user_ids = array();
+       			$data['USER_NAMES'][-1] = $base_option;
+       		  	foreach($usernames as $user) {
+                	$user_ids[] = $user['USER_ID'];
+                	if($select_user == $user['USER_ID']) {
+                    	$select_username = $user['USER_NAME'];
+                	}
+            	}
+            
+            	foreach($usernames as $username){
+              		$data['USER_NAMES'] [$username['USER_ID']] = $username['USER_NAME']; 
+             		$user_ids[] = $username['USER_ID'];
+            	}
+            }
+         if(isset($_REQUEST['selectuser'])) {
+                $select_user = $this->clean($_REQUEST['selectuser'], "string" );
+            } else {
+                $select_user = "";
+            }
+        
+        if(isset($_REQUEST['selectactivity'])) {
+                $select_activity =
+                    $this->clean($_REQUEST['selectactivity'], "int" );
+
+            } else {
+                $select_activity = "";
+            }
+            if($select_activity != "") {
+                $data['SELECT_ACTIVITY'] = $select_activity;
+            } else {
+                $data['SELECT_ACTIVITY'] = -1;
+            }
+            }
+        
+        if(isset($_REQUEST['arg']) &&
+            in_array($_REQUEST['arg'], $possible_arguments)) {
+            switch($_REQUEST['arg'])
+            {
+                case "addgroup":
+                
+                    $data['SELECT_GROUP'] = -1;
+                    if($this->groupModel->getGroupId($groupname) > 0) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_groupname_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+                    $this->groupModel->addGroup($groupname, $_SESSION['USER_ID']);
+                    $groupid = $this->groupModel->getGroupId($groupname);
+                    $data['GROUP_NAMES'][$groupid] = $groupname;
 
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_groupname_added').
+                        "</h1>')";
+                break;
+                
+                 case "deletegroup":
+                 
+                    if($select_group == -1){
+                    	$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_groupname_doesnt_exists')."</h1>')"; 
+                    }else{
+                     $this->groupModel->deleteGroup($select_group);
+                    unset($data['GROUP_NAMES'][$select_group]);
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_groupname_deleted')."</h1>')";  
+                    }   
+                break;
+                
+                case "adduser":  
+                
+                    if(!in_array($select_user, $user_ids)) {
+                
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_username_doesnt_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+                    $this->groupModel->addUserGroup($select_group, $select_user);
+                  
+                    unset($data['AVAILABLE_USERS'][$select_user]);
+                      $data['GROUP_USERS'] =
+                        $this->groupModel->getGroupUsers($select_group);
+                    
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_user_added')."</h1>')";
+                break;
+                
+                case "deleteuser":
+          
+                    $this->groupModel->deleteUserGroup(
+                        $select_group, $select_user);
+                    $data['GROUP_USERS'] =
+                        $this->groupModel->getGroupUsers($select_group);
+                    $data['AVAILABLE_USERS'][$select_user] =
+                        $user_names[$select_user];
+                    $data['SELECT_USER'] = -1;
+                   
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_user_deleted')."</h1>')";
+                        
+                break;
+                
+                case "addrole":
+                    
+                    if(!in_array($select_group, $group_ids)) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_groupname_doesnt_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+                    if(!in_array($select_role, $role_ids)) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_rolename_doesnt_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+                    $this->groupModel->addGroupRole(
+                        $select_group, $select_role);
+                    unset($data['AVAILABLE_ROLES'][$select_role]);
+                    $data['GROUP_ROLES'] =
+                        $this->groupModel->getGroupRoles($select_group);
+                    
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_rolename_added')."</h1>')";
+                        
+                break;
+                
+                case "deleterole":
+               
+                    if(!in_array($select_group, $group_ids)) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_groupname_doesnt_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+
+                    if(!in_array($select_role, $role_ids)) {
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            tl('admin_controller_rolename_doesnt_exists').
+                            "</h1>')";
+                        return $data;
+                    }
+                    $this->groupModel->deleteGroupRole(
+                        $select_group, $select_role);
+                    $data['GROUP_ROLES'] =
+                        $this->groupModel->getGroupRoles($select_group);
+                    $data['AVAILABLE_ACTIVITIES'][$select_role] =
+                        $role_names[$select_role];
+                    $data['SELECT_ROLE'] = -1;
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('admin_controller_role_deleted')."</h1>')";
+                break;
+                
+          }      
+    }
         return $data;
     }
+    
 
     /**
      * Used to handle the manage crawl activity.
diff --git a/controllers/controller.php b/controllers/controller.php
index b804b6f..2214cbe 100755
--- a/controllers/controller.php
+++ b/controllers/controller.php
@@ -71,7 +71,6 @@ abstract class Controller
     {
 
         require_once BASE_DIR."/models/model.php";
-
         foreach($this->models as $model) {
             if(file_exists(APP_DIR."/models/".$model."_model.php")) {
                 require_once APP_DIR."/models/".$model."_model.php";
diff --git a/locale/en-US/configure.ini b/locale/en-US/configure.ini
index ea6c440..027791f 100755
--- a/locale/en-US/configure.ini
+++ b/locale/en-US/configure.ini
@@ -55,6 +55,9 @@ admin_controller_select_username = "Select Name"
 ; admin_controller.php line: 437
 admin_controller_select_rolename = "Select Role"
 ;
+; admin_controller.php line: 437
+admin_controller_select_groupname = "Select Group"
+
 ; admin_controller.php line: 463
 admin_controller_passwords_dont_match = "Typed passwords do not match."
 ;
@@ -88,24 +91,45 @@ admin_controller_rolename_doesnt_exists = "Role Name Does not Exist"
 ; admin_controller.php line: 539
 admin_controller_rolename_deleted = "Role Name Deleted"
 ;
+; admin_controller.php line: 539
+admin_controller_groupname_deleted = "Group Name Deleted"
+;
 ; admin_controller.php line: 569
 admin_controller_select_rolename = "Select Role"
 ;
 ; admin_controller.php line: 604
 admin_controller_select_activityname = "Select Activity"
 ;
+; admin_controller.php line: 604
+admin_controller_select_rolename = "Select Role"
+;
 ; admin_controller.php line: 637
 admin_controller_rolename_exists = "Role Name Exists"
 ;
+; admin_controller.php line: 637
+admin_controller_groupname_exists = "Group Name Exists"
+;
 ; admin_controller.php line: 647
 admin_controller_rolename_added = "Role Name Added"
 ;
+; admin_controller.php line: 647
+admin_controller_groupname_added = "Group Name Added"
+;
 ; admin_controller.php line: 658
 admin_controller_rolename_doesnt_exists = "Role Name Does not Exist"
 ;
+; admin_controller.php line: 658
+admin_controller_groupname_doesnt_exists = "Group Name Does not Exist"
+;
+; admin_controller.php line: 658
+admin_controller_username_doesnt_exists = "Username Does not exists"
+;
 ; admin_controller.php line: 666
 admin_controller_rolename_deleted = "Role Name Deleted"
 ;
+; manageroles_element.php line: 76
+managegroups_element_delete_role = "Delete Group"
+;
 ; admin_controller.php line: 672
 admin_controller_rolename_doesnt_exists = "Role Name Does not Exist"
 ;
@@ -124,6 +148,15 @@ admin_controller_activityname_doesnt_exists = "Activity Name Does not Exist"
 ; admin_controller.php line: 713
 admin_controller_activity_deleted = "Activity Deleted"
 ;
+; admin_controller.php line: 713
+admin_controller_role_deleted = "Role Deleted"
+;
+; admin_controller.php line: 713
+admin_controller_user_added = "User Added"
+;
+; admin_controller.php line: 713
+admin_controller_user_deleted = "User Deleted"
+;
 ; admin_controller.php line: 759
 admin_controller_stop_crawl = "Stopping crawl. . .This will take a moment to refresh."
 ;
@@ -988,6 +1021,15 @@ manageroles_element_submit = "Submit"
 ;
 ; manageroles_element.php line: 94
 manageroles_element_view_role_activities = "View Role Activities"
+
+; managegroups_element.php line: 94
+managegroups_element_view_groups = "View Groups"
+;
+
+; managegroups_element.php line: 103
+managegroups_element_select_group = "Group Name: "
+;
+
 ;
 ; manageroles_element.php line: 103
 manageusers_element_select_role = "Role Name: "
@@ -997,6 +1039,26 @@ manageusers_element_add_activity = "Add Activity:"
 ;
 ; manageroles_element.php line: 128
 manageroles_element_submit = "Submit"
+
+;
+;managegroups_element.php line: 58
+managegroups_element_add_user = "Add User: "
+;
+; manageroles_element.php line: 67
+managegroups_element_groupname = "Group Name:"
+;
+; manageroles_element.php line: 71
+ managegroups_element_submit = "Submit"
+;
+; manageroles_element.php line: 76
+managegroups_element_delete_groupname = "Delete Group"
+;
+; managegroups_element.php line: 86
+manageusers_element_delete_groupname = "Group Name:"
+;
+; manageroles_element.php line: 90
+managegroups_element_submit = "Submit"
+
 ;
 ; manageusers_element.php line: 57
 manageusers_element_add_user = "Add User"
@@ -1030,6 +1092,16 @@ manageusers_element_select_user = "Username: "
 ;
 ; manageusers_element.php line: 135
 manageusers_element_add_role = "Add Role: "
+
+; managegroups_element.php line: 135
+managegroups_element_add_user = "Add User: "
+
+; managegroups_element.php line: 135
+managegroups_element_add_group_activity = "Add Activity: "
+
+; managegroups_element.php line: 135
+managegroups_element_add_group_role = "Add Role: "
+
 ;
 ; manageusers_element.php line: 140
 manageusers_element_submit = "Submit"
@@ -1568,3 +1640,4 @@ statistics_view_number_hosts = "Hostnames Seen"
 ;
 ; view.php line: 35
 view_locale_version2 = "version 2"
+
diff --git a/models/group_model.php b/models/group_model.php
new file mode 100644
index 0000000..79a532e
--- /dev/null
+++ b/models/group_model.php
@@ -0,0 +1,370 @@
+<?php
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2013  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage model
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2013
+ * @filesource
+ */
+if(!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
+
+/** Loads base model class if necessary*/
+require_once BASE_DIR."/models/model.php";
+/** For crawlHash function */
+require_once BASE_DIR."/lib/utility.php";
+
+/**
+ * This is class is used to handle
+ * db results related to Role Administration
+ *
+ * @author Mallika Perepa
+ * @package seek_quarry
+ * @subpackage model
+ */
+
+class GroupModel extends Model
+{
+	/**
+     *  {@inheritdoc}
+     */
+     
+ 	function __construct()
+    {
+        parent::__construct();
+    }
+	/**
+	*  Get the users  (name, method, id) that a given group contains
+	*
+	*  @param string $group_id  the group_id to get users for
+	*/
+     
+    function getGroupUsers($group_id)
+    {
+    	$this->db->selectDB(DB_NAME);
+    	$group_id = $this->db->escapeString($group_id);
+    	$users = array();
+    	
+     
+      $sql = "SELECT UG.USER_ID, U.USER_NAME, UG.GROUP_ID, G.CREATER_ID ".
+            "FROM USER_GROUPS UG, USER U, GROUPS G ".
+            "where UG.GROUP_ID = '$group_id' and UG.USER_ID = U.USER_ID and G.GROUP_ID = UG.GROUP_ID";
+
+
+        $result = $this->db->execute($sql);
+		$i = 0;
+        while($users[$i] = $this->db->fetchArray($result)) {
+        	$i++;
+        }
+		unset($users[$i]); //last one will be null
+		
+		return $users;
+		
+    }
+    
+	/**
+    *  Get the activities  (name, method, id) that a given group can perform
+    *
+    *  @param string $group_id  the group_id to get activities for
+    */
+    
+   	function getGroupActivities($group_id)
+    {
+    	$this->db->selectDB(DB_NAME);
+    	$group_id = $this->db->escapeString($group_id);
+    	$activities= array();
+    	$locale_tag = getLocaleTag();
+     
+ 	$sql = "SELECT LOCALE_ID FROM LOCALE ".
+            "WHERE LOCALE_TAG = '$locale_tag' LIMIT 1";
+           
+    	$result = $this->db->execute($sql);
+    	$row = $this->db->fetchArray($result);
+    	$locale_id = $row['LOCALE_ID'];
+        
+    $sql= "SELECT A.ACTIVITY_ID, T.TRANSLATION, G.GROUP_ID FROM ". 
+		"TRANSLATION_LOCALE T, ACTIVITY A, GROUP_PERMISSIONS G ".
+		"where G.GROUP_ID = '$group_id' AND T.LOCALE_ID = '$locale_id' ".
+		"AND A.ACTIVITY_ID = G.ACTIVITY_ID AND ".
+		"A.TRANSLATION_ID = T.TRANSLATION_ID";
+   
+    	$result = $this->db->execute($sql);
+    
+	$i = 0;
+    	while($activities[$i] = $this->db->fetchArray($result)) {
+        	$i++;
+        }
+		unset($activities[$i]); //last one will be null
+		
+		return $activities;
+		
+    }
+    
+	/**
+    * Gets all the roles associated with a group id
+    *
+    * @param string $group_id  the group_id to get roles of
+    * @return array of role_ids and their names
+    */
+    function getGroupRoles($group_id)
+    {
+        $this->db->selectDB(DB_NAME);
+
+        $group_id = $this->db->escapeString($group_id);
+
+        $roles = array();
+        $locale_tag = getLocaleTag();
+
+    $sql = "SELECT LOCALE_ID FROM LOCALE ".
+            "WHERE LOCALE_TAG = '$locale_tag' LIMIT 1";
+            
+        $result = $this->db->execute($sql);
+        $row = $this->db->fetchArray($result);
+        $locale_id = $row['LOCALE_ID'];
+        
+    $sql = "SELECT GR.GROUP_ID, GR.ROLE_ID, R.NAME AS ROLE_NAME ".
+            "FROM GROUP_ROLES GR, ROLE R ".
+            "where GR.GROUP_ID = '$group_id' and  GR.ROLE_ID= R.ROLE_ID ";
+            
+
+        $result = $this->db->execute($sql);
+        $i = 0;
+        while($roles[$i] = $this->db->fetchArray($result)) {
+            $i++;
+        }
+        unset($roles[$i]); //last one will be null
+
+        return $roles;   
+
+    }
+    
+     function getLocaleTag()
+    {
+        return $this->locale_tag;
+    }
+    
+    /**
+     *  Add a groupname to the database using provided string
+     *
+     *  @param string $groupname  the groupname to be added
+     */
+    function addGroup($groupname, $userid)
+    {
+        $this->db->selectDB(DB_NAME);
+        $date = new DateTime();
+		$timestamp = $date->getTimestamp();
+        $sql = "INSERT INTO GROUPS (GROUP_NAME,CREATER_ID,CREATED_TIME) VALUES ('".
+            $this->db->escapeString($groupname)."', $userid, $timestamp)";
+	
+        $this->db->execute($sql);
+        $last_insert_id = mysql_insert_id();
+        $sql= "INSERT INTO USER_GROUPS (USER_ID,GROUP_ID) VALUES ($userid, $last_insert_id)";
+       
+       $this->db->execute($sql);
+    }
+    
+     /**
+     * Get group id associated with groupname (so groupnames better be unique)
+     *
+     * @param string $groupname to use to look up a group_id
+     * @return string  group_id corresponding to the groupname.
+     */
+    function getGroupId($groupname)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "SELECT G.GROUP_ID AS GROUP_ID FROM ".
+            " GROUPS G WHERE G.GROUP_NAME = '".$this->db->escapeString($groupname)."' ";
+        $result = $this->db->execute($sql);
+        if(!$row = $this->db->fetchArray($result) ) {
+            return -1;
+        }
+        return $row['GROUP_ID'];
+    }
+    
+     /**
+     *  Delete a groupname to the database using provided string
+     *
+     *  @param string $groupname  the groupname to be deleted
+     */
+  	function deleteGroup($groupid)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "DELETE FROM GROUPS WHERE GROUP_ID='$groupid'";
+
+        $this->db->execute($sql);
+        $sql = "DELETE FROM GROUPS WHERE GROUP_ID='".
+            $this->db->escapeString($groupid)."'";
+        $this->db->execute($sql);
+    }
+    
+	/**
+    *  Get a list of all groups. Group names are not localized since these are
+    *  created by end user admins of the search engine
+    *
+    *  @return array an array of group_id, group_name pairs
+    */
+    
+    function getGroupList()
+    {
+        $this->db->selectDB(DB_NAME);
+
+        $groups = array();
+
+        $sql = "SELECT G.GROUP_ID AS GROUP_ID, G.GROUP_NAME AS GROUP_NAME ".
+            " FROM GROUPS G";
+
+        $result = $this->db->execute($sql);
+        $i = 0;
+
+        while($groups[$i] = $this->db->fetchArray($result)) {
+            $i++;
+        }
+        unset($groups[$i]); //last one will be null
+
+        return $groups;
+
+    }
+    
+    /**
+    *  Get a list of all groups which are created by the user_id. Group names are not localized since these are
+    *  created by end user admins of the search engine
+    *
+    *  @return array an array of group_id, group_name pairs
+    */
+    function getGroupListbyUser($userid)
+    {
+        $this->db->selectDB(DB_NAME);
+
+        $groups = array();
+
+        $sql = "SELECT UG.GROUP_ID AS GROUP_ID, UG.USER_ID AS USER_ID, G.GROUP_NAME AS GROUP_NAME ".
+            " FROM USER_GROUPS UG, GROUPS G where USER_ID = $userid and UG.GROUP_ID = G.GROUP_ID";
+            
+        $result = $this->db->execute($sql);
+        $i = 0;
+
+        while($groups[$i] = $this->db->fetchArray($result)) {
+            $i++;
+        }
+        unset($groups[$i]); //last one will be null
+
+        return $groups;
+
+    }
+    
+    /**
+    *  Get a list of all groups which are created by the creater_id. Group names are not localized since these are
+    *  created by end user admins of the search engine
+    *
+    *  @return array an array of group_id, group_name pairs
+    */
+     function getGroupListbyCreater($userid)
+    {
+        $this->db->selectDB(DB_NAME);
+
+        $groups = array();
+
+        $sql = "SELECT UG.GROUP_ID AS GROUP_ID, UG.USER_ID AS USER_ID, G.GROUP_NAME AS GROUP_NAME ".
+            " FROM USER_GROUPS UG, GROUPS G where CREATER_ID = $userid and UG.GROUP_ID = G.GROUP_ID";
+        
+        $result = $this->db->execute($sql);
+        $i = 0;
+
+        while($groups[$i] = $this->db->fetchArray($result)) {
+            $i++;
+        }
+        unset($groups[$i]); //last one will be null
+
+        return $groups;
+
+    }
+    
+    
+    /**
+    *  Add an allowed user to an existing group
+    *
+    *  @param string $groupid  the group id of the group to add the user to
+    *  @param string $userid the id of the user to add
+    */
+    
+    function addUserGroup($groupid, $userid)
+    {
+        $this->db->selectDB(DB_NAME);
+            $sql = "INSERT INTO USER_GROUPS VALUES ('".
+            $this->db->escapeString($userid)."', '".
+            $this->db->escapeString($groupid)."')";
+            
+        $this->db->execute($sql);
+    }
+    
+    /**
+    *  Delete a user by its userid
+    *
+    *  @param string $userid - the userid of the user to delete
+    */
+     
+    function deleteUserGroup($groupid, $userid)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "DELETE FROM USER_GROUPS WHERE USER_ID='".
+            $this->db->escapeString($userid)."' AND GROUP_ID='".
+            $this->db->escapeString($groupid)."'";
+
+        $this->db->execute($sql);
+    }
+        
+	/**
+    * Adds a role to a given user
+    *
+    * @param string $userid  the id of the user to add the role to
+    * @param string $roleid  the id of the role to add
+    */
+    function addGroupRole($groupid, $roleid)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "INSERT INTO GROUP_ROLES  VALUES ('".
+            $this->db->escapeString($groupid)."', '".
+            $this->db->escapeString($roleid)."' ) ";
+        $result = $this->db->execute($sql);   
+    }
+   
+    /**
+    * Deletes a role from a given user
+    *
+    * @param string $userid  the id of the user to delete the role from
+    * @param string $roleid  the id of the role to delete
+    */
+    function deleteGroupRole($groupid, $roleid)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "DELETE FROM GROUP_ROLES WHERE GROUP_ID='".
+            $this->db->escapeString($groupid)."' AND  ROLE_ID='".
+            $this->db->escapeString($roleid)."'";
+        $result = $this->db->execute($sql);
+    }
+    	
+    } 
+?>
\ No newline at end of file
diff --git a/models/profile_model.php b/models/profile_model.php
index 1563937..6815772 100644
--- a/models/profile_model.php
+++ b/models/profile_model.php
@@ -316,6 +316,9 @@ EOT;
                 TITLE VARCHAR(512), LINK VARCHAR(256),
                 DESCRIPTION VARCHAR(4096),
                 PUBDATE INT, SOURCE_NAME VARCHAR(16))",
+				"CREATE TABLE GROUPS (GROUP_ID INTEGER PRIMARY KEY $auto_increment , GROUP_NAME VARCHAR(128), CREATED_TIME INT(11), CREATER_ID INT(11))",
+				"CREATE TABLE USER_GROUPS (USER_ID INTEGER , GROUP_ID INTEGER, PRIMARY KEY (GROUP_ID, USER_ID) )",	
+				"CREATE TABLE GROUP_ROLES (GROUP_ID INTEGER , ROLE_ID INTEGER)",
             );
         foreach($create_statements as $statement) {;
             if(!$dbm->execute($statement)) {return false;}
diff --git a/models/role_model.php b/models/role_model.php
index 31720d0..efdccf5 100644
--- a/models/role_model.php
+++ b/models/role_model.php
@@ -59,7 +59,7 @@ class RoleModel extends Model
     }
 
 
-    /**
+	/**
      *  Get the activities  (name, method, id) that a given role can perform
      *
      *  @param string $role_id  the rolid_id to get activities for
@@ -75,6 +75,7 @@ class RoleModel extends Model
 
         $sql = "SELECT LOCALE_ID FROM LOCALE ".
             "WHERE LOCALE_TAG = '$locale_tag' LIMIT 1";
+            
         $result = $this->db->execute($sql);
         $row = $this->db->fetchArray($result);
         $locale_id = $row['LOCALE_ID'];
@@ -87,7 +88,6 @@ class RoleModel extends Model
             "WHERE  R.ROLE_ID = '$role_id'  AND ".
             "R.ROLE_ID = RA.ROLE_ID AND T.TRANSLATION_ID = A.TRANSLATION_ID ".
             "AND RA.ACTIVITY_ID = A.ACTIVITY_ID";
-
         $result = $this->db->execute($sql);
 
         $i = 0;
@@ -98,6 +98,7 @@ class RoleModel extends Model
                 "FROM TRANSLATION_LOCALE ".
                 "WHERE TRANSLATION_ID=$id AND LOCALE_ID=$locale_id LIMIT 1";
                 // maybe do left join at some point
+		
 
             $result_sub =  $this->db->execute($sub_sql);
             $translate = $this->db->fetchArray($result_sub);
@@ -152,6 +153,7 @@ class RoleModel extends Model
      * @param string $rolename to use to look up a role_id
      * @return string  role_id corresponding to the rolename.
      */
+     
     function getRoleId($rolename)
     {
         $this->db->selectDB(DB_NAME);
@@ -196,6 +198,7 @@ class RoleModel extends Model
             $this->db->escapeString($activityid)."')";
 
         $this->db->execute($sql);
+        
     }
 
 
diff --git a/models/user_model.php b/models/user_model.php
index 775678c..413a6eb 100755
--- a/models/user_model.php
+++ b/models/user_model.php
@@ -88,7 +88,7 @@ class UserModel extends Model
             "WHERE UR.USER_ID = '$user_id' ".
             "AND UR.ROLE_ID=RA.ROLE_ID AND T.TRANSLATION_ID=A.TRANSLATION_ID ".
             "AND RA.ACTIVITY_ID = A.ACTIVITY_ID";
-
+            
         $result = $this->db->execute($sql);
         $i = 0;
         while($activities[$i] = $this->db->fetchArray($result)) {
@@ -107,7 +107,7 @@ class UserModel extends Model
             if($translate) {
                 $activities[$i]['ACTIVITY_NAME'] = $translate['ACTIVITY_NAME'];
             }
-            if(!isset($activities[$i]['ACTIVITY_NAME']) || 
+            if(!isset($activities[$i]['ACTIVITY_NAME']) ||
                 $activities[$i]['ACTIVITY_NAME'] == "") {
                 $activities[$i]['ACTIVITY_NAME'] = $this->translateDb(
                     $activities[$i]['IDENTIFIER_STRING'], DEFAULT_LOCALE);
@@ -115,7 +115,6 @@ class UserModel extends Model
             $i++;
         }
         unset($activities[$i]); //last one will be null
-
         return $activities;
 
     }
@@ -185,6 +184,7 @@ class UserModel extends Model
         $sql = "SELECT UR.ROLE_ID AS ROLE_ID, R.NAME AS ROLE_NAME ".
             " FROM  USER_ROLE UR, ROLE R WHERE UR.USER_ID = '$user_id' ".
             " AND R.ROLE_ID = UR.ROLE_ID";
+            
 
         $result = $this->db->execute($sql);
         $i = 0;
@@ -207,13 +207,19 @@ class UserModel extends Model
     {
         $this->db->selectDB(DB_NAME);
 
-        $sql = "SELECT USER_NAME FROM USER ORDER BY USER_NAME ASC";
+         $sql = "SELECT U.USER_ID AS USER_ID, U.USER_NAME AS USER_NAME ".
+            " FROM USER U";
+
         $result = $this->db->execute($sql);
-        $usernames = array();
-        while($row = $this->db->fetchArray($result)) {
-            $usernames[] = $row['USER_NAME'];
+        $i = 0;
+
+        while($users[$i] = $this->db->fetchArray($result)) {
+            $i++;
         }
-        return $usernames;
+        unset($users[$i]); //last one will be null
+
+        return $users;
+
     }
 
 
@@ -230,6 +236,7 @@ class UserModel extends Model
         $sql = "INSERT INTO USER(USER_NAME, PASSWORD) VALUES ('".
             $this->db->escapeString($username)."', '".
             crawlCrypt($this->db->escapeString($password))."' ) ";
+            var_dump ($sql);
         $result = $this->db->execute($sql);
     }
 
@@ -240,11 +247,11 @@ class UserModel extends Model
      *
      * @param string $username  the login name of the user to delete
      */
-    function deleteUser($username)
+    function deleteUser($userid)
     {
         $this->db->selectDB(DB_NAME);
-        $sql = "DELETE FROM USER WHERE USER_NAME='".
-            $this->db->escapeString($username)."'";
+        $sql = "DELETE FROM USER WHERE USER_ID='".
+            $this->db->escapeString($userid)."'";
         $result = $this->db->execute($sql);
     }
 
@@ -281,4 +288,4 @@ class UserModel extends Model
     }
 }
 
- ?>
+ ?>
\ No newline at end of file
diff --git a/views/admin_view.php b/views/admin_view.php
index 1ab79a0..b9e9cc6 100755
--- a/views/admin_view.php
+++ b/views/admin_view.php
@@ -52,10 +52,10 @@ class AdminView extends View
      *  @var array
      */
     var $elements = array("language", "activity", "signin",
-        "managecrawls", "manageaccount", "manageusers", "manageroles",
+        "managecrawls", "manageaccount", "manageusers", "manageroles", "managegroups",
         "mixcrawls", "managelocales", "editlocales", "crawloptions",
         "editmix", "pageoptions", "resultseditor", "searchsources",
-        "managemachines", "machinelog", "editstatic", "configure");
+        "managemachines", "machinelog", "editstatic", "configure" );
     /** Names of helper objects that the view uses to help draw itself
      *  @var array
      */
@@ -93,7 +93,6 @@ class AdminView extends View
         $this->activityElement->render($data);
         if(isset($data['ELEMENT'])) {
             $element = $data['ELEMENT'];
-
             $this->$element->render($data);
         }
         if(PROFILE) {
diff --git a/views/elements/managegroups_element.php b/views/elements/managegroups_element.php
new file mode 100644
index 0000000..b5f9f52
--- /dev/null
+++ b/views/elements/managegroups_element.php
@@ -0,0 +1,218 @@
+<?php
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2013  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage element
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2013
+ * @filesource
+ */
+
+if(!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
+
+/*
+ * Used to draw the admin screen on which admin users can create groups, delete
+ * groups and add and delete users and roles to a group 
+ *
+ * @author Mallika Perepa
+ * @package seek_quarry
+ * @subpackage element
+ */
+ 
+class ManagegroupsElement extends Element
+{
+/**
+* renders the screen in which groups can be created, deleted, and added or
+* deleted 
+*
+* @param array $data  contains antiCSRF token, as well as data on
+*      available groups or which user is in what group
+*/
+function render($data)
+    {?>
+        
+        <div class="current-activity">
+        <h2><?php e(tl('managegroups_element_add_group'))?></h2>
+        <form id="addGroupForm" method="post" action='#'>
+        <input type="hidden" name="c" value="admin" />
+        <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+            e($data[CSRF_TOKEN]); ?>" />
+        <input type="hidden" name="a" value="manageGroups" />
+        <input type="hidden" name="arg" value="addgroup" />
+
+        <table class="name-table">
+        <tr><td><label for="group-name"><?php
+            e(tl('managegroups_element_groupname'))?></label></td>
+            <td><input type="text" id="role-name" name="groupname"
+                maxlength="80" class="narrow-field" /></td><td
+                class="center"> <button class="button-box" type="submit"><?php
+                e(tl('managegroups_element_submit')); ?></button></td>
+        </tr>
+        </table>
+        </form>
+        
+        <h2><?php e(tl('managegroups_element_delete_group'))?></h2>
+        <form id="deleteGroupForm" method="post" action='#'>
+        <input type="hidden" name="c" value="admin" />
+        <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+            e($data[CSRF_TOKEN]); ?>" />
+        <input type="hidden" name="a" value="manageGroups" />
+        <input type="hidden" name="arg" value="deletegroup" />
+
+        <table class="name-table">
+         <tr><td><label for="delete-groupname"><?php
+            e(tl('manageusers_element_delete_groupname'))?></label></td>
+            <td><?php $this->view->optionsHelper->render(
+                "delete-groupname", "selectgroup", $data['DELETE_GROUP_NAMES'], "-1");
+                ?></td><td><button class="button-box" type="submit"><?php
+                e(tl('managegroups_element_submit')); ?></button></td>
+        </tr>
+        </table>
+        </form>
+        
+        <h2><?php e(tl('managegroups_element_view_groups'))?></h2>
+        <form id="viewGroupForm" method="get" action='#' >
+        <input type="hidden" name="c" value="admin" />
+        <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+            e($data[CSRF_TOKEN]); ?>" />
+        <input type="hidden" name="a" value="manageGroups" />
+        <input type="hidden" name="arg" value="viewgroups" />
+        
+        <table class="name-table">
+        <tr><td><label for="select-groups"><?php
+            e(tl('managegroups_element_select_group'))?></label></td>
+            <td><?php $this->view->optionsHelper->render("select-group",
+                "selectgroup", $data['GROUP_NAMES'], $data['SELECT_GROUP']);
+                ?></td></tr>
+        </table>
+        </form>
+        
+        <?php
+        	if(isset($data['USER_NAMES'])) {
+        		if(count($data['USER_NAMES']) > 0) { ?>
+        		<form id="adduserForm" method="get" action='#' >
+        			<input type="hidden" name="c" value="admin" />
+                	<input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+                    	e($data[CSRF_TOKEN]); ?>" />
+                	<input type="hidden" name="a" value="manageGroups" />
+                	<input type="hidden" name="arg" value="adduser" />
+                    <input type="hidden" name="selectgroup" value="<?php
+                    	e($data['SELECT_GROUP']); ?>"/>	
+                    <table class="name-table">
+                <tr><td><label for="add-user"><?php
+                    e(tl('managegroups_element_add_user'))?></label></td>
+                <td><?php $this->view->optionsHelper->render("select-user",
+                    "selectuser", $data['USER_NAMES'],
+                    $data['SELECT_USER']); ?></td>
+                <td><button class="button-box" type="submit"><?php
+                
+                    e(tl('managegroups_element_submit')); ?></button></td></tr>
+                </table>
+                </form>
+                
+        	<?php
+        	}
+        	?>
+        	<table class="role-table"><?php
+             foreach($data['GROUP_USERS'] as $group_user) {
+             	if($_SESSION['USER_ID'] != $group_user['USER_ID']
+             		&& $_SESSION['USER_ID'] != $group_user['CREATER_ID']){ 
+             		e("<tr><td>".$group_user['USER_NAME'].
+                    "</td>");
+             		}else{
+             			e("<tr><td>".$group_user['USER_NAME'].
+                    	"</td><td><a href='?c=admin&amp;a=manageGroups".
+                    	"&amp;arg=deleteuser&amp;selectgroup=".
+                    	$group_user['GROUP_ID'].
+                    	"&amp;selectuser=".$group_user['USER_ID'].
+                    	"&amp;".CSRF_TOKEN."=".$data[CSRF_TOKEN].
+                    	"'>Delete</a></td>");
+             		}
+             		}
+    			?>
+    			 </table>
+        	<?php
+			}
+			?>
+			
+        <?php
+        if(isset($data['GROUP_ROLES'])) {
+             if(count($data['ROLE_NAMES']) > 0  &&
+                $data['ROLE_NAMES'] != -1) { ?>
+                <form id="addGroupRoleForm" method="get" action='#' >
+                <input type="hidden" name="c" value="admin" />
+                <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+                    e($data[CSRF_TOKEN]); ?>" />
+                <input type="hidden" name="a" value="manageGroups" />
+                <input type="hidden" name="arg" value="addrole" />
+                <input type="hidden" name="selectgroup" value="<?php
+                    e($data['SELECT_GROUP']);?>" />
+                <table class="name-table">
+                
+                 <tr><td><label for="add-role"><?php
+                    e(tl('managegroups_element_add_group_role'))?></label></td>
+                    <td><?php $this->view->optionsHelper->render("add-role",
+                        "selectrole", $data['ROLE_NAMES'],
+                        $data['SELECT_ROLE']); ?></td>
+                        
+                    <td><button class="button-box" type="submit"><?php
+                    e(tl('managegroups_element_submit')); ?></button></td></tr>
+                 </table>
+                 </form>
+        	<?php
+            }
+    		?>
+    		
+    	<?php
+        if(isset($data['GROUP_ROLES'])) {
+             if(count($data['GROUP_ROLES']) > 0  &&
+                $data['GROUP_ROLES'] != -1) { ?>
+            <table class="role-table"><?php
+             foreach($data['GROUP_ROLES'] as $group_role) {
+                 e("<tr><td>".$group_role['ROLE_NAME'].
+                    "</td><td><a href='?c=admin&amp;a=manageGroups".
+                    "&amp;arg=deleterole&amp;selectgroup=".
+                    $group_role['GROUP_ID'].
+                    "&amp;selectrole=".$group_role['ROLE_ID'].
+                    "&amp;".CSRF_TOKEN."=".$data[CSRF_TOKEN].
+                    "'>Delete</a></td>");
+             }
+             ?>
+             </table>
+        	<?php
+        	} } }
+        	?>
+        <script type="text/javascript">
+        function submitViewGroups()
+        {
+            elt('viewGroupForm').submit();
+        }
+        </script>
+           </div>
+    	<?php
+    		}
+			}
+		?>
\ No newline at end of file
diff --git a/views/elements/manageroles_element.php b/views/elements/manageroles_element.php
index e9da426..70f09f7 100644
--- a/views/elements/manageroles_element.php
+++ b/views/elements/manageroles_element.php
@@ -1,4 +1,5 @@
 <?php
+
 /**
  *  SeekQuarry/Yioop --
  *  Open Source Pure PHP Search Engine, Crawler, and Indexer
@@ -132,6 +133,7 @@ class ManagerolesElement extends Element
              <?php
              }
              ?>
+             
              <table class="role-table"><?php
              foreach($data['ROLE_ACTIVITIES'] as $role_activity) {
                  e("<tr><td>".$role_activity['ACTIVITY_NAME'].
diff --git a/views/elements/manageusers_element.php b/views/elements/manageusers_element.php
index be5ec40..cefd348 100644
--- a/views/elements/manageusers_element.php
+++ b/views/elements/manageusers_element.php
@@ -95,6 +95,7 @@ class ManageusersElement extends Element
         <table class="name-table">
         <tr><td><label for="delete-username"><?php
             e(tl('manageusers_element_delete_username'))?></label></td>
+            
             <td><?php $this->view->optionsHelper->render(
                 "delete-username", "username", $data['USER_NAMES'], "");
                 ?></td><td><button class="button-box" type="submit"><?php
diff --git a/views/view.php b/views/view.php
index e924461..a23034b 100755
--- a/views/view.php
+++ b/views/view.php
@@ -94,7 +94,7 @@ abstract class View
             }
             $element_name = ucfirst($element)."Element";
             $element_instance_name = lcfirst($element_name);
-
+			
             $this->$element_instance_name = new $element_name($this);
         }
 
-- 
1.7.5.4

