2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
41 ********************************************************************************/
50 class Role extends SugarBean {
58 var $modified_user_id;
63 var $disable_row_level_security = true;
65 var $table_name = 'roles';
66 var $rel_module_table = 'roles_modules';
67 var $object_name = 'Role';
68 var $module_dir = 'Roles';
69 var $new_schema = true;
76 function get_summary_text()
81 function create_export_query($order_by, $where)
83 return $this->create_new_list_query($order_by, $where);
86 function query_modules($allow = 1)
88 $query = "SELECT module_id FROM roles_modules WHERE ";
89 $query .= "role_id = '$this->id' AND allow = '$allow' AND deleted=0";
90 $result = $this->db->query($query);
92 $return_array = array();
94 while($row = $this->db->fetchByAssoc($result))
96 array_push($return_array, $row['module_id']);
101 function set_module_relationship($role_id, &$mod_ids, $allow)
103 foreach($mod_ids as $mod_id)
106 $this->set_relationship('roles_modules', array( 'module_id'=>$mod_id, 'role_id'=>$role_id, 'allow'=>$allow ));
110 function clear_module_relationship($role_id)
112 $query = "DELETE FROM roles_modules WHERE role_id='$role_id'";
113 $this->db->query($query);
116 function set_user_relationship($role_id, &$user_ids)
118 foreach($user_ids as $user_id)
121 $this->set_relationship('roles_users', array( 'user_id'=>$user_id, 'role_id'=>$role_id ));
125 function clear_user_relationship($role_id, $user_id)
127 $query = "DELETE FROM roles_users WHERE role_id='$role_id' AND user_id='$user_id'";
128 $this->db->query($query);
131 function query_user_allowed_modules($user_id)
133 $userArray = array();
134 global $app_list_strings;
138 $sql = "SELECT role_id FROM roles_users WHERE user_id='$user_id'";
140 $result = $this->db->query($sql);
142 while($row = $this->db->fetchByAssoc($result))
144 $role_id = $row["role_id"];
145 $sql = "SELECT module_id FROM roles_modules WHERE role_id='$role_id' AND allow='1'";
146 $res = $this->db->query($sql);
148 while($col = $this->db->fetchByAssoc($res))
150 $key = $col['module_id'];
151 if(!(array_key_exists($key, $userArray)))
153 $userArray[$key] = $app_list_strings['moduleList'][$key];
161 function query_user_disallowed_modules($user_id, &$allowed)
165 $returnArray = array();
167 foreach($moduleList as $key=>$val)
169 if(array_key_exists($val, $allowed))
171 $returnArray[$val] = $val;
180 // First, get the list of IDs.
184 $query = "SELECT user_id as id FROM roles_users WHERE role_id='$this->id' AND deleted=0";
186 return $this->build_related_list($query, new User());
189 function check_user_role_count($user_id)
191 $query = "SELECT count(*) AS num FROM roles_users WHERE ";
192 $query .= "user_id='$user_id' AND deleted=0";
193 $result = $this->db->query($query);
195 $row = $this->db->fetchByAssoc($result);