27 function menu_get_assets($id_name, $majorids, $ignore_permissions = FALSE)
32 if (!isset($GLOBALS[
'MENU_DATA'][$id_name])) {
33 $GLOBALS[
'MENU_DATA'][$id_name] = Array();
35 $storage =& $GLOBALS[
'MENU_DATA'][$id_name];
38 foreach ($majorids as $id) {
39 if (empty($storage[$id])) {
40 $majorids_str .=
'\''.(string)$id.
'\',
';
42 foreach ($storage[$id] as $row) {
43 $assetids[] = (int) $row['assetid
'];
48 if (empty($majorids_str)) return $assetids;
50 // Watch out for this static var, once it has been set, it won't go into the
if is_null. However the bind vars will need to be there because
this static var contain the query that uses bind vars.
51 static $USERIDS_COND = NULL;
52 static $USERIDS_BIND_VARS = NULL;
55 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
56 if (is_null($USERIDS_COND)) {
58 if ($GLOBALS[
'SQ_SYSTEM']->userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin() || $ignore_permissions) {
61 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
62 $userids = $user->getUserGroups();
63 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
64 $userids[] = $public_userid;
65 $userids[] = $GLOBALS[
'SQ_SYSTEM']->user->id;
66 $userids_bind_vars = Array();
67 $userids_vars_p = Array();
68 $userids_vars_r = Array();
69 for (reset($userids); NULL !== ($i = key($userids)); next($userids)) {
70 $userids_vars_p[] =
':mga_userids_p_'.$i;
71 $userids_bind_vars[
'mga_userids_p_'.$i] = (string) $userids[$i];
72 $userids_vars_r[] =
':mga_userids_r_'.$i;
73 $userids_bind_vars[
'mga_userids_r_'.$i] = (string) $userids[$i];
75 $USERIDS_BIND_VARS = serialize($userids_bind_vars);
76 $userids_p_str = implode(
', ', $userids_vars_p);
77 $userids_r_str = implode(
', ', $userids_vars_r);
78 $USERIDS_COND =
'AND (p.userid IN ('.$userids_p_str.
') ';
79 $USERIDS_COND .=
'OR r.userid IN ('.$userids_r_str.
')) ';
80 $USERIDS_COND .=
' AND (
81 (p.permission = :p_permission AND (
83 OR r.userid <> :r_userid
84 OR (p.userid = :p_userid_1 AND p.granted = \'1\')
85 OR (r.userid = :r_userid_1 AND p.granted = \'1\')
89 p.permission > :p_permission_1 AND p.granted = \'1\'
93 GROUP BY a.assetid, l.majorid, a.type_code, a.status, a.name, a.short_name, pt.path, l.sort_order, p.assetid
94 HAVING MIN(p.granted) <> \'0\'';
101 if ($USERIDS_COND !==
'') {
102 $bind_vars[
'p_permission'] = SQ_PERMISSION_READ;
103 $bind_vars[
'p_permission_1'] = SQ_PERMISSION_READ;
104 $bind_vars[
'p_userid'] = $public_userid;
105 $bind_vars[
'p_userid_1'] = $public_userid;
106 $bind_vars[
'r_userid'] = $public_userid;
107 $bind_vars[
'r_userid_1'] = $public_userid;
111 if (!is_null($USERIDS_BIND_VARS)) {
112 $userids_bind_vars_values = @unserialize($USERIDS_BIND_VARS);
113 foreach ($userids_bind_vars_values as $bind_id => $bind_value) {
114 $bind_vars[$bind_id] = $bind_value;
118 $sql =
'SELECT DISTINCT a.assetid, l.majorid, a.type_code, a.status, a.name, a.short_name, pt.path, l.sort_order
119 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast a
120 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk l ON a.assetid = l.minorid
121 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_path pt ON a.assetid = pt.assetid ';
122 if (!empty($USERIDS_COND)) {
124 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_perm p ON a.assetid = p.assetid ';
126 LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_role r ON p.userid = r.roleid AND p.assetid = r.assetid ';
128 $where =
'l.majorid IN ('.substr($majorids_str, 0, -1).
')
130 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'a');
131 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
132 if (!empty($USERIDS_COND)) {
133 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'p');
135 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'pt');
136 $where .=
' '.$USERIDS_COND.
'
137 ORDER BY l.majorid, l.sort_order';
141 foreach ($bind_vars as $bind_var => $bind_value) {
145 }
catch (Exception $e) {
146 throw new Exception(
'Unable to get valid menu entries due to database error: '.$e->getMessage());
151 foreach ($result as $row) {
152 if (!($row[
'status'] & (SQ_STATUS_LIVE | SQ_STATUS_LIVE_APPROVAL))) {
153 $menu_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($row[
'assetid']);
154 $read_access = $menu_asset->readAccess();
156 $row[
'name'] = $menu_asset->name;
157 $row[
'short_name'] = $menu_asset->short_name;
159 if ($row[
'status'] & SQ_SC_STATUS_NOT_LIVE) {
161 $row[
'name'] =
'(( '.$row[
'name'].
' ))';
162 $row[
'short_name'] =
'(( '.$row[
'short_name'].
' ))';
165 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($menu_asset);
167 if (!$read_access)
continue;
169 $assetids[] = $row[
'assetid'];
170 if (!isset($storage[$row[
'majorid']])) {
171 $storage[$row[
'majorid']] = Array();
173 $storage[$row[
'majorid']][$row[
'assetid']] = $row;