2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2010 */
\r
6 /* Inclusive Design Institute */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
13 define('TR_INCLUDE_PATH', '../include/');
\r
15 include(TR_INCLUDE_PATH.'vitals.inc.php');
\r
16 include_once(TR_INCLUDE_PATH.'classes/DAO/UserGroupsDAO.class.php');
\r
17 include_once(TR_INCLUDE_PATH.'classes/DAO/UserGroupPrivilegeDAO.class.php');
\r
18 include_once(TR_INCLUDE_PATH.'classes/DAO/PrivilegesDAO.class.php');
\r
20 unset($id); // clean up the temporary id values set by vitals.inc.php
\r
22 if (isset($_GET["id"])) $id = intval($_GET["id"]);
\r
24 $userGroupsDAO = new UserGroupsDAO();
\r
27 if (isset($_POST['cancel']))
\r
29 $msg->addFeedback('CANCELLED');
\r
30 header('Location: user_group.php');
\r
33 else if (isset($_POST['save']))
\r
35 $title = $addslashes(trim($_POST['title']));
\r
39 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
\r
42 if (!$msg->containsErrors())
\r
44 if (isset($id)) // edit existing user group
\r
46 $userGroupsDAO->update($id,
\r
48 $addslashes(trim($_POST['description'])));
\r
50 else // create a new user group
\r
52 $id = $userGroupsDAO->Create($title,
\r
53 $addslashes(trim($_POST['description'])));
\r
56 if (!$msg->containsErrors())
\r
58 $userGroupPrivilegeDAO = new UserGroupPrivilegeDAO();
\r
60 if (is_array($_POST['add_privileges_id']))
\r
62 foreach ($_POST['add_privileges_id'] as $add_priv_id)
\r
63 $userGroupPrivilegeDAO->Create($id, $add_priv_id);
\r
66 if (is_array($_POST['user_requirement']))
\r
68 foreach ($_POST['user_requirement'] as $priv_id => $user_requirement)
\r
70 $user_group_priv_row = $userGroupPrivilegeDAO->Get($id, $priv_id);
\r
71 if ($user_group_priv_row && $user_group_priv_row['user_requirement'] <> $user_requirement)
\r
72 $userGroupPrivilegeDAO->UpdateField($id, $priv_id, 'user_requirement', $user_requirement);
\r
76 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
77 header('Location: user_group.php');
\r
82 else if (isset($_POST['remove']))
\r
84 $userGroupPrivilegeDAO = new UserGroupPrivilegeDAO();
\r
86 if (is_array($_POST['del_privileges_id']))
\r
88 foreach ($_POST['del_privileges_id'] as $del_priv_id)
\r
89 $userGroupPrivilegeDAO->Delete($id, $del_priv_id);
\r
93 // interface display
\r
96 // create user group
\r
97 $privilegesDAO = new PrivilegesDAO();
\r
99 $savant->assign('privs_to_add_rows', $privilegesDAO->getAll());
\r
103 // edit existing user group
\r
104 $privilegesDAO = new PrivilegesDAO();
\r
105 $privs_rows = $privilegesDAO->getUserGroupPrivileges($id);
\r
107 // get privs that are not in user group
\r
108 unset($str_existing_privs);
\r
109 if (is_array($privs_rows))
\r
111 foreach($privs_rows as $priv_row)
\r
112 $str_existing_privs .= $priv_row['privilege_id'] .',';
\r
113 $str_existing_privs = substr($str_existing_privs, 0, -1);
\r
116 $savant->assign('user_group_row', $userGroupsDAO->getUserGroupByID($id));
\r
117 $savant->assign('privs_rows', $privs_rows);
\r
118 $savant->assign('privs_to_add_rows', $privilegesDAO->getAllPrivsExceptListed($str_existing_privs));
\r
121 $savant->display('user/user_group_create_edit.tmpl.php');
\r