' . "\n";
- $output .= '
' . t('Here you can assign group roles to members. This will give that member permission of that role. It will apply to all posts of this group type.') . "
\n";
+ $output .= '
'. t('Here you can assign group roles to members. This will give that member permission of that role. It will apply to all posts of this group type.') ."
\n";
// $header[] = array('data' => t('Users'));
$header[] = array('data' => t('Roles'), 'colspan' => 2);
$rows = array();
@@ -492,7 +492,7 @@
* TRUE if this group type allows roles to be assigned, otherwise FALSE
*/
function og_user_roles_is_allowed($nid) {
- $node = node_load(array('nid'=>$nid));
+ $node = node_load(array('nid' => $nid));
if (in_array($node->type, variable_get('og_node_types', array('og'))) && variable_get("og_user_roles_roles_$node->type", NULL)) {
return TRUE;
}
@@ -500,68 +500,68 @@
return FALSE;
}
}
-
-//
-// Modification
-// Added the following two functions to add and remove roles.
-//
+
+//
+// Modification
+// Added the following two functions to add and remove roles.
+//
/**
* Add role to og_users_roles table.
*/
-function og_user_roles_role_join($uid, $rid, $gid) {
- db_query("INSERT INTO {og_users_roles} (rid, uid, gid) VALUES ('%d','%d','%d')", $rid, $uid, $gid);
-}
+function og_user_roles_role_join($uid, $rid, $gid) {
+ db_query("INSERT INTO {og_users_roles} (rid, uid, gid) VALUES ('%d','%d','%d')", $rid, $uid, $gid);
+}
/**
* Remove all roles for a user in a group table.
*/
-function og_user_roles_role_leave($uid, $gid) {
- db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d", $uid, $gid);
-}
-//
-// Modification
-// Added the following functions from this snippet: http://drupal.org/node/41936
-// Creates multiple checkbox columns
-//
-function expand_checkbox_columns($element) {
- $value = is_array($element['#value']) ? $element['#value'] : array();
- $element['#type'] = 'checkboxes';
- $element['#tree'] = TRUE;
- if (count($element['#options']) > 0) {
- if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
- $element['#default_value'] = array();
- }
- foreach ($element['#options'] as $key => $choice) {
- $class = ($column % $element['#columns']) && $column ? 'checkbox-columns' : 'checkbox-columns-clear';
- if (!isset($element[$key])) {
- $element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#default_value' => in_array($key, $value), '#attributes' => $element['#attributes'], '#prefix' => '
', '#suffix' => '
', '#return_value' => $choice);
- }
- $column++;
- }
- }
- return $element;
-}
-//
-// Modification
-// Added the following functions from this snippet: http://drupal.org/node/41936
-// To let Drupal know about the new "expand_checkbox_columns".
-//
-function og_user_roles_elements() {
- $type['checkbox_columns'] = array('#input' => TRUE, '#process' => array('expand_checkbox_columns' => array()), '#tree' => TRUE);
- return $type;
-}
-
+function og_user_roles_role_leave($uid, $gid) {
+ db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d", $uid, $gid);
+}
+//
+// Modification
+// Added the following functions from this snippet: http://drupal.org/node/41936
+// Creates multiple checkbox columns
+//
+function expand_checkbox_columns($element) {
+ $value = is_array($element['#value']) ? $element['#value'] : array();
+ $element['#type'] = 'checkboxes';
+ $element['#tree'] = TRUE;
+ if (count($element['#options']) > 0) {
+ if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
+ $element['#default_value'] = array();
+ }
+ foreach ($element['#options'] as $key => $choice) {
+ $class = ($column % $element['#columns']) && $column ? 'checkbox-columns' : 'checkbox-columns-clear';
+ if (!isset($element[$key])) {
+ $element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#default_value' => in_array($key, $value), '#attributes' => $element['#attributes'], '#prefix' => '
', '#suffix' => '
', '#return_value' => $choice);
+ }
+ $column++;
+ }
+ }
+ return $element;
+}
+//
+// Modification
+// Added the following functions from this snippet: http://drupal.org/node/41936
+// To let Drupal know about the new "expand_checkbox_columns".
+//
+function og_user_roles_elements() {
+ $type['checkbox_columns'] = array('#input' => TRUE, '#process' => array('expand_checkbox_columns' => array()), '#tree' => TRUE);
+ return $type;
+}
+
/**
* @ingroup views
*/
/**
* Implementation of hook_views_tables():
- * Present fields and filters for user data.
+ * Present fields and filters for user data.
* Requires that usernode be installed.
*/
-
+
function og_user_roles_views_tables() {
-
+
$tables['og_users_roles'] = array(
'name' => 'og_users_roles',
'provider' => 'internal', // won't show up in external list.
@@ -592,7 +592,7 @@
),
),
);
-
+
$tables['og_users_uid'] = array(
'name' => 'og_uid',
'provider' => 'internal', // won't show up in external list.
@@ -616,7 +616,7 @@
),
),
);
-
+
$tables['og_non_group_roles'] = array(
'name' => 'users_roles',
'provider' => 'internal', // won't show up in external list.
@@ -642,314 +642,306 @@
return $tables;
}
-
-
+
+
/*
* Create a list of group names and IDs.
*/
-function views_handler_filter_group() {
- $list = array();
- $list = variable_get('og_node_types', array('og'));
- $groupTypes = implode(",", $list);
+function views_handler_filter_group() {
+ $list = array();
+ $list = variable_get('og_node_types', array('og'));
+ $group_types = implode(",", $list);
$vids = array();
- $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('". $groupTypes ."') ORDER BY n.title");
+ $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('". $group_types ."') ORDER BY n.title");
while ($obj = db_fetch_object($result)) {
$vids[$obj->nid] = $obj->title;
}
return $vids;
}
-
+
/*
- * Implementation of hook_init.
- *
- * Got the idea of re-directing if this is a add group node request
- * from here: http://drupal.org/project/globalredirect
+ * Implementation of hook_init.
+ *
+ * Got the idea of re-directing if this is a add group node request
+ * from here: http://drupal.org/project/globalredirect
*
*/
-
-function og_user_roles_init ()
-{
- global $user;
-
- // Looking for this format: http://www.scbbs.com/node/add/link?gids[]=29
-
- // We only need to process this if the user is logged in
- if ($user->uid > 0) {
-
- // Bootstrap if arg() doesn't exist
- if (!function_exists('arg') && $user->uid > 0){
- drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
- }
-
- // If this is a group node/add, re-direct to ognodeadd
- if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
- $gids = $_GET['gids'];
- $gid = intval(current($_REQUEST['gids']));
-
- $type = arg(2);
-
- $path = 'node/ognodeadd';
- if ($type == 'og_user_roles_subgroup') $type = variable_get("og_user_roles_create_subgroup_value", ''); // change OG Subgroups type to 'group'
-
- $query = 'type=' . $type . '&gids[]=' . $gid;
-
- // Modification as per: http://drupal.org/node/156568
-
- if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum' && is_numeric(arg(3))) {
- $query = 'type=' . $type . '&gids[]=' . $gid . '&tid=' . intval(arg(3));
- }
-
- drupal_goto($path, $query);
- }
-
- // Modification as per: http://drupal.org/node/156568
- // If this is a group node/add/forum with no gids, re-direct to ognodeadd and include gids
- if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum' && is_numeric(arg(3)) && (!isset($_REQUEST['gids'])) ) {
- $type = arg(2);
- $tid = intval(arg(3));
-
- $gid = og_user_roles_gid_from_tid($tid);
-
- // Hijack only if there is a gid value;
- if (!empty($gid)){
- $path = 'node/ognodeadd';
- $query = 'type=' . $type . '&gids[]=' . $gid . '&tid=' . $tid;
- drupal_goto($path, $query);
- }
- }
-
- }
-}
-
+
+function og_user_roles_init() {
+ global $user;
+
+ // Looking for this format: http://www.scbbs.com/node/add/link?gids[]=29
+
+ // We only need to process this if the user is logged in
+ if ($user->uid > 0) {
+
+ // Bootstrap if arg() doesn't exist
+ if (!function_exists('arg') && $user->uid > 0) {
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
+ }
+
+ // If this is a group node/add, re-direct to ognodeadd
+ if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
+ $gids = $_GET['gids'];
+ $gid = intval(current($_REQUEST['gids']));
+
+ $type = arg(2);
+
+ $path = 'node/ognodeadd';
+ if ($type == 'og_user_roles_subgroup') $type = variable_get("og_user_roles_create_subgroup_value", ''); // change OG Subgroups type to 'group'
+
+ $query = 'type='. $type .'&gids[]='. $gid;
+
+ // Modification as per: http://drupal.org/node/156568
+
+ if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum' && is_numeric(arg(3))) {
+ $query = 'type='. $type .'&gids[]='. $gid .'&tid='. intval(arg(3));
+ }
+
+ drupal_goto($path, $query);
+ }
+
+ // Modification as per: http://drupal.org/node/156568
+ // If this is a group node/add/forum with no gids, re-direct to ognodeadd and include gids
+ if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum' && is_numeric(arg(3)) && (!isset($_REQUEST['gids'])) ) {
+ $type = arg(2);
+ $tid = intval(arg(3));
+
+ $gid = og_user_roles_gid_from_tid($tid);
+
+ // Hijack only if there is a gid value;
+ if (!empty($gid)) {
+ $path = 'node/ognodeadd';
+ $query = 'type='. $type .'&gids[]='. $gid .'&tid='. $tid;
+ drupal_goto($path, $query);
+ }
+ }
+ }
+}
+
/*
- * Implementation of hook_user.
- * Put new users in default role if applicable.
- *
- * Got this code from here: http://drupal.org/node/28379#comment-132430
+ * Implementation of hook_user.
+ * Put new users in default role if applicable.
+ *
+ * Got this code from here: http://drupal.org/node/28379#comment-132430
*
*/
-
-function og_user_roles_user ($op, &$edit, &$user, $category=null)
-{
- // If the user opted to create a default role
-
- if (variable_get("og_user_roles_assign_default", 0) == 1) {
-
- $rid = variable_get("og_user_roles_default_value", 0);
-
- // special case for new users
- if ($op == "insert")
- {
-/*
- * Modification as per: http://drupal.org/node/149483
- */
- // Check to see if this user doesn't already have this role;
- // If not, then assign it.
-
- $sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
- $result = db_query($sql, $user->uid, $rid);
- $output = (db_result($result));
- if ($output == 0) db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
- }
-
- } // end if
-
- // Add the group roles to $user->roles if this is a group
- // This should only be effective until the next global $user call
-
- if ($op == "load") {
- $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
- $user->roles = $roles;
- } // end $op load
-
- // Remove user info from og_users_roles table
-
- if ($op == "delete") {
+
+function og_user_roles_user($op, &$edit, &$user, $category=null) {
+ // If the user opted to create a default role
+ if (variable_get("og_user_roles_assign_default", 0) == 1) {
+ $rid = variable_get("og_user_roles_default_value", 0);
+ // special case for new users
+ if ($op == "insert") {
+ /*
+ * Modification as per: http://drupal.org/node/149483
+ */
+ // Check to see if this user doesn't already have this role;
+ // If not, then assign it.
+
+ $sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
+ $result = db_query($sql, $user->uid, $rid);
+ $output = (db_result($result));
+ if ($output == 0) db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
+ }
+
+ } // end if
+
+ // Add the group roles to $user->roles if this is a group
+ // This should only be effective until the next global $user call
+
+ if ($op == "load") {
+ $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
+ $user->roles = $roles;
+ } // end $op load
+
+ // Remove user info from og_users_roles table
+
+ if ($op == "delete") {
db_query("DELETE FROM {og_users_roles} WHERE uid = %d", $user->uid); // delete all records for this user
- } // end $op delete
-
-}
-
-/**
- * implementation of hook_og();
- *
- * @param $op string, 'user insert', 'user update', 'user delete'
- * @param $nid node ID of the group
- * @param $uid the user ID
- * @param $args associative array containing details about the subscription
- */
-function og_user_roles_og($op, $nid, $uid, $args = array()) {
- switch ($op) {
- case 'user insert':
-
- // --- Modification - 2007-06-18 - as per: http://drupal.org/node/152442
- // Adding every user to a basic group restricted role, that all users in the group should have.
- // I don't know a better way, so I'll do it like this. This is based on the creating of a founder role,
- // just that every user in the group should automagically get this role.
- // -Bibo
- if (variable_get("og_user_roles_assign_basicgrouprole", 0) == 1) {
- $rid = variable_get("og_user_roles_basicgrouprole_value", 0);
- og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
- }
- //--- end of modification
-
- global $base_url;
- $user = user_load(array('uid' => $uid));
- $username = $user->name;
- $node = node_load($nid);
-
- // Send notification of new og subscription to administrators of group;
-
- if (variable_get("og_user_roles_notify_default", 0) == 1) {
- $group = $node->title;
- $sender = variable_get('site_mail', '');
- $subject = 'User ' . $username . ' added to group: ' . $group;
- $message = "User
" . $username . " added to group:
" . $group . "";
-
- // Get the group admin(s)
-
-// $result = db_query("SELECT uid FROM og_uid WHERE is_admin = 1 AND nid = " . $nid);
- $result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $nid); // FIXED TABLE PREFIX
- while ($obj = db_fetch_object($result)) {
- $recipient_uid = $obj->uid;
- $recipient_user = user_load(array('uid' => $recipient_uid));
- $recipient = $recipient_user->mail;
- mimemail($sender, $recipient, $subject, $message);
- } // end while
- } // end if
-
- break;
-
- case 'user delete':
-
- // Remove all roles for this user in this group if he is being unsubscribed;
-
- og_user_roles_role_leave($uid, $nid);
-
- break;
-
- } // end switch
-}
-
-/**
- * Implementation of hook_node_info().
- */
-function og_user_roles_node_info() {
-
- // If og_subgroups is installed AND og_user_roles_create_subgroup checkbox is checked;
-
- if (module_exists('og_subgroups') && variable_get("og_user_roles_create_subgroup", 0) == 1) {
- return array(
- 'og_user_roles_subgroup' => array(
- 'name' => t('Subgroup'),
- 'module' => 'og_user_roles',
- 'description' => t('Create a basic subgroup.'),
- 'help' => t('Create a basic subgroup.'),
- 'body_label' => t('Description'),
- ),
- );
- } // end if
-}
-
+ } // end $op delete
+}
+
+/**
+ * implementation of hook_og();
+ *
+ * @param $op string, 'user insert', 'user update', 'user delete'
+ * @param $nid node ID of the group
+ * @param $uid the user ID
+ * @param $args associative array containing details about the subscription
+ */
+function og_user_roles_og($op, $nid, $uid, $args = array()) {
+ switch ($op) {
+ case 'user insert':
+
+ // --- Modification - 2007-06-18 - as per: http://drupal.org/node/152442
+ // Adding every user to a basic group restricted role, that all users in the group should have.
+ // I don't know a better way, so I'll do it like this. This is based on the creating of a founder role,
+ // just that every user in the group should automagically get this role.
+ // -Bibo
+ if (variable_get("og_user_roles_assign_basicgrouprole", 0) == 1) {
+ $rid = variable_get("og_user_roles_basicgrouprole_value", 0);
+ og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
+ }
+ //--- end of modification
+
+ global $base_url;
+ $user = user_load(array('uid' => $uid));
+ $username = $user->name;
+ $node = node_load($nid);
+
+ // Send notification of new og subscription to administrators of group;
+
+ if (variable_get("og_user_roles_notify_default", 0) == 1) {
+ $group = $node->title;
+ $sender = variable_get('site_mail', '');
+ $subject = 'User '. $username .' added to group: '. $group;
+ $message = "User
". $username ." added to group:
". $group ."";
+
+ // Get the group admin(s)
+
+// $result = db_query("SELECT uid FROM og_uid WHERE is_admin = 1 AND nid = " . $nid);
+ $result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $nid); // FIXED TABLE PREFIX
+ while ($obj = db_fetch_object($result)) {
+ $recipient_uid = $obj->uid;
+ $recipient_user = user_load(array('uid' => $recipient_uid));
+ $recipient = $recipient_user->mail;
+ mimemail($sender, $recipient, $subject, $message);
+ } // end while
+ } // end if
+
+ break;
+
+ case 'user delete':
+
+ // Remove all roles for this user in this group if he is being unsubscribed;
+
+ og_user_roles_role_leave($uid, $nid);
+
+ break;
+
+ } // end switch
+}
+
+/**
+ * Implementation of hook_node_info().
+ */
+function og_user_roles_node_info() {
+
+ // If og_subgroups is installed AND og_user_roles_create_subgroup checkbox is checked;
+
+ if (module_exists('og_subgroups') && variable_get("og_user_roles_create_subgroup", 0) == 1) {
+ return array(
+ 'og_user_roles_subgroup' => array(
+ 'name' => t('Subgroup'),
+ 'module' => 'og_user_roles',
+ 'description' => t('Create a basic subgroup.'),
+ 'help' => t('Create a basic subgroup.'),
+ 'body_label' => t('Description'),
+ ),
+ );
+ } // end if
+}
+
/**
* Implementation of hook_load().
- *
+ *
* Doesn't seem to work.
*/
-//function og_user_roles_load($node) {
- // watchdog test
-// watchdog("hook_load", "og_user_roles : type = " . $node->type);
-
-// return $node;
-//}
-
+//function og_user_roles_load($node) {
+ // watchdog test
+// watchdog("hook_load", "og_user_roles : type = " . $node->type);
+
+// return $node;
+//}
+
/**
* Implementation of hook_nodeapi().
*
*/
function og_user_roles_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
-
- case 'access':
-//
-// This access check is used for TAC and OG permissions integration;
-//
- if (variable_get("og_user_roles_tac_og_value", 0) == 1) {
-
- $access = FALSE;
- $og_access = og_user_roles_og_access_check($teaser, $node);
- $tac_access = og_user_roles_taxonomy_access_check($teaser, $node);
-
- if ($og_access === TRUE && $tac_access == FALSE) $access = FALSE;
- if ($og_access === FALSE) $access = FALSE;
- if ($og_access === TRUE && $tac_access == TRUE) $access = TRUE;
-
- return $access;
- }
-
- break;
-
+
+ case 'access':
+//
+// This access check is used for TAC and OG permissions integration;
+//
+ if (variable_get("og_user_roles_tac_og_value", 0) == 1) {
+
+ $access = FALSE;
+ $og_access = og_user_roles_og_access_check($teaser, $node);
+ $tac_access = og_user_roles_taxonomy_access_check($teaser, $node);
+
+ if ($og_access === TRUE && $tac_access == FALSE) $access = FALSE;
+ if ($og_access === FALSE) $access = FALSE;
+ if ($og_access === TRUE && $tac_access == TRUE) $access = TRUE;
+
+ return $access;
+ }
+
+ break;
+
case 'submit':
- //
- // Put appropriate nodes into all groups upon node submission;
- //
- // Get list of nodes to put into all groups;
-
- $nodelist = variable_get('og_user_roles_all_groups_nodes', '');
- if (!empty($nodelist)) {
- $nodelistArray = explode(",", $nodelist);
- foreach ($nodelistArray as $nodelistItem) {
- if ($node->nid == $nodelistItem) {
- if ($grps = og_user_roles_get_groups($node)) {
- $node->og_groups = array_keys($grps);
- $node->og_groups_names = array_values($grps);
+ //
+ // Put appropriate nodes into all groups upon node submission;
+ //
+ // Get list of nodes to put into all groups;
+
+ $nodelist = variable_get('og_user_roles_all_groups_nodes', '');
+ if (!empty($nodelist)) {
+ $nodelist_array = explode(",", $nodelist);
+ foreach ($nodelist_array as $nodelist_item) {
+ if ($node->nid == $nodelist_item) {
+ if ($grps = og_user_roles_get_groups($node)) {
+ $node->og_groups = array_keys($grps);
+ $node->og_groups_names = array_values($grps);
- $public = db_result(db_query_range("SELECT is_public FROM {og_ancestry} WHERE nid = %d", $node->nid, 0, 1));
- $node->og_public = $public ? TRUE : FALSE;
- } // end $grps if
- } // end $node->nid if
- } // end foreach
- } // end $nodelist if
-
-
+ $public = db_result(db_query_range("SELECT is_public FROM {og_ancestry} WHERE nid = %d", $node->nid, 0, 1));
+ $node->og_public = $public ? TRUE : FALSE;
+ } // end $grps if
+ } // end $node->nid if
+ } // end foreach
+ } // end $nodelist if
+
+
break;
-
+
case 'insert':
-
- // If this is a group node, put the group creator into a group role upon creation;
-
- if (variable_get("og_user_roles_assign_founder", 0) == 1) {
-
- $rid = variable_get("og_user_roles_founder_value", 0);
-
- // If this is a group node
- if (og_is_group_type($node->type)) {
- // Get the requisite data
- $uid = $node->uid; // user ID
- $gid = $node->nid; // group ID
- og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
- }
- }
-
- // Create a subgroup record for this group
-
- // 'ognodeadd' is my node add callback, so I know if this node is a group and
- // here, then we need to process it node as a subgroup
-
- if ($node->type == variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') {
-
- $gids = $_GET['gids'];
- $gid = $gids[0];
- $subgroup = $node->nid;
- $sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
- db_query($sql, $subgroup, $gid);
- }
-
+
+ // If this is a group node, put the group creator into a group role upon creation;
+
+ if (variable_get("og_user_roles_assign_founder", 0) == 1) {
+
+ $rid = variable_get("og_user_roles_founder_value", 0);
+
+ // If this is a group node
+ if (og_is_group_type($node->type)) {
+ // Get the requisite data
+ $uid = $node->uid; // user ID
+ $gid = $node->nid; // group ID
+ og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
+ }
+ }
+
+ // Create a subgroup record for this group
+
+ // 'ognodeadd' is my node add callback, so I know if this node is a group and
+ // here, then we need to process it node as a subgroup
+
+ if ($node->type == variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') {
+
+ $gids = $_GET['gids'];
+ $gid = $gids[0];
+ $subgroup = $node->nid;
+ $sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
+ db_query($sql, $subgroup, $gid);
+ }
+
break;
-
+
} // end switch
} // end og_user_roles_nodeapi function
-
+
// returns all groups so long as this is not a group itself
function og_user_roles_get_groups($node) {
$groups = array();
@@ -967,379 +959,380 @@
$sql = "SELECT oga.group_nid, n.title FROM {og_ancestry} oga INNER JOIN {node} n ON oga.group_nid = n.nid";
// we use rewrite_sql() in order to avoid disclosing completely private groups (once we support those properly)
// return db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), $nid);
- return db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), '');
+ return db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), '');
+}
+
+//
+// My OG Roles Modifications
+//
+//
+// Modification - Added this function
+//
+// This function returns an array of role keys and names, like $user->roles
+// However, it returns site roles as well as group roles
+//
+function og_user_roles_all_roles_array($user) {
+
+ $roles = og_user_roles_all_roles($user);
+
+ return $roles;
}
-
-//
-// My OG Roles Modifications
-//
-//
-// Modification - Added this function
-//
-// This function returns an array of role keys and names, like $user->roles
-// However, it returns site roles as well as group roles
-//
-function og_user_roles_all_roles_array($user) {
-
- $roles = og_user_roles_all_roles($user);
-
- return $roles;
-}
-
-// This function takes the global $user (or $account) value and returns a list
-// of group and non-group roles for this user
-
-function og_user_roles_all_roles($user) {
-
- // This will be the process to get BOTH the group and non-group roles for a user
-
- $uid = $user->uid;
- $gid = 0;
- $gids = array();
- $nodeID = 0;
- $location = 0;
-
- $uri_request_id = $_SERVER['REQUEST_URI'];
- $arg = explode("/", $uri_request_id);
-
- $ogroles = array();
- $x1 = 0;
- //
- // This will by default add the anonymous user role (no need since we merge user->roles)
- //
- // We get the groupID
- //
- $group_node = og_get_group_context();
- $gid02 = $group_node->nid;
- $gid = $gid02;
- if ($gid02 === null) $gid = 0;
- //
- // If the above doesn't get the groupID, then we start trying stuff
- //
- if ($gid == 0) {
-
- // http://doadance.scbbs.com/drupal03/node/79
-
- if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
- $location = 1;
- $nodeID = (int)arg(1);
- $gid = getgid($nodeID, $uid);
- }
-
- // http://doadance.scbbs.com/node/79/edit
- // http://doadance.scbbs.com/node/79/outline
- // http://doadance.scbbs.com/node/79/track
-
- if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' ) ) {
- $location = 2;
- $nodeID = (int)arg(1);
- $gid = getgid($nodeID, $uid);
- }
- // 0 1 2
- // http://www.mysite.com/comment/edit/14
- //
- if (arg(0) == 'comment' && is_numeric(arg(2)) && arg(1) == 'edit' ) {
- $location = 3;
- $comment = _comment_load(arg(2));
- $nodeID = $comment->nid;
- $gid = getgid($nodeID, $uid);
- }
- // 0 1 2
- // http://www.mysite.com/comment/reply/128#comment_form
- //
- if (arg(0) == 'comment' && arg(1) == 'reply' ) {
- $location = 4;
- $subsections = explode("#", arg(2));
- $nodeID = (int)$subsections[0];
- $gid = getgid($nodeID, $uid);
- }
-
- // og_term access
- // 0 1 2 3
- // http://www.mysite.com/node/add/forum/121
- //
- if (arg(0) == 'node' && is_numeric(arg(3)) && arg(1) == 'add' ) {
- $location = 5;
- $nodeID = (int)arg(3);
- $gid = getgid($nodeID, $uid);
- }
-
- // Here we get the gid directly
- //
- // http://doadance.scbbs.com/node/79/view/tree
- // http://doadance.scbbs.com/node/79/view/members
- // http://doadance.scbbs.com/node/79/view
-
- if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'view' ) {
- $location = 2;
- $gid = (int)arg(1);
- }
-
- // Here we get the gid directly
- //
- // http://doadance.scbbs.com/og/users/72
- // http://doadance.scbbs.com/og/manage/72
-
- if (arg(0) == 'og' && is_numeric(arg(2)) && is_null(arg(3))) {
- $location = 6;
- $gid = (int)arg(2);
- }
-
- // og_user_roles
- //
- // http://doadance.scbbs.com/og/users/72/roles
- // http://doadance.scbbs.com/og/users/72/add
-
- if (arg(0) == 'og' && arg(1) == 'users' && is_numeric(arg(2)) && is_null(arg(4))) {
- $location = 6;
- $gid = (int)arg(2);
- }
-
- // og unsubscribe
- // og_user_roles
- //
- // This is sort of a catch all for "og" and gid in this order
- // og/
/
- //
- // http://doadance.scbbs.com/og/unsubscribe/72
- // http://doadance.scbbs.com/og/users/72/add
-
- if (arg(0) == 'og' && is_numeric(arg(2))) {
- $location = 6;
- $gid = (int)arg(2);
- }
-
- // og_forum
- //
- // http://doadance.scbbs.com/og_forum/manage/72
-
- if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(2)) && is_null(arg(3))) {
- $location = 6;
- $gid = (int)arg(2);
- }
-
- // http://doadance.scbbs.com/og_forum/manage/edit/72
- // http://doadance.scbbs.com/og_forum/manage/add/72
-
- if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(3))) {
- $location = 6;
- $gid = (int)arg(3);
- }
-
- // og_calendar
- //
- // http://doadance.scbbs.com/og_calendar/72
-
- // Modification - og_calendar was modified and now may look like this:
- // http://www.centralavedance.com/og_calendar/2973/2007/07/01
-
-// if (arg(0) == 'og_calendar' && is_numeric(arg(1)) && is_null(arg(2))) {
- if (arg(0) == 'og_calendar' && is_numeric(arg(1)) ) {
- $location = 7;
- $gid = (int)arg(1);
- }
-
- // og_forum
- // 0 1 2 3
- // http://www.mysite.com/og_forum/39/72?edit[og_groups][]=72
- // http://www.mysite.com/og_forum/37/71?sort=asc&order=Replies&edit[og_groups][0]=71
-
-// if ($arg[1] == 'og_forum' && strpos($arg[3], 'og_groups') !== false && (!is_null($arg[3])) ) {
-// $location = 8;
-// $subsections = explode("=", $arg[3]);
-// foreach ($subsections as $subsection) {
-// if (is_numeric($subsection)) {
-// $gid = (int)$subsection;
-// }
-// }
-// }
-
- // Modification as per: http://drupal.org/node/155882 - replaced $uri_request_id
- // with arg() values.
-
- if (arg(0) == 'og_forum' && is_numeric(arg(2)) && isset($_REQUEST['edit']) ) {
- $location = 8;
- $edit = $_GET['edit'];
- if ($edit[og_groups][0] > 0) {
- // $gid = $edit[og_groups][0];
- $gid = arg(2);
- }
- }
-
- // og_forum
- // http://www.mysite.com/forum/39
- //
- // Modification - 2007-07-04. In the case where this is a forum
-
- if (arg(0) == 'forum' && is_numeric(arg(1)) && is_null(arg(2)) ) {
- $location = 8;
- $tid = (int)arg(1);
- $gid = og_user_roles_gid_from_tid($tid);
-
- // If no gid returned, then set $gid = 0
-
- if (empty($gid)) {
- $gid = 0;
- }
- }
-
- // og create nodes (version 5.1)
- // 0 1 2 3
- // http://sbn.scbbs.com/node/add/forum?gids[]=72
- // http://sbn.scbbs.com/node/add/simplenews?gids[]=72
- // http://sbn.scbbs.com/node/add/webform?gids[]=72
- // http://sbn.scbbs.com/node/add/video?gids[]=72
- // http://sbn.scbbs.com/node/add/page?gids[]=72
- // http://sbn.scbbs.com/node/add/blog?gids[]=72
- // http://sbn.scbbs.com/node/add/event?gids[]=72
- // http://sbn.scbbs.com/node/add/poll?gids[]=72
- // http://sbn.scbbs.com/node/add/flexinode-3?gids[]=72
-
-// if ($arg[1] == 'node' && strpos($arg[3], 'gids') !== false && (!is_null($arg[3])) ) {
-// $location = 10 . "(" . arg(0) . "|" . arg(1) . "|" . arg(2) . ")";
-// $subsections = explode("=", $arg[3]);
-// $gid = (int)$subsections[1];
-// }
-
- // Modification as per: http://drupal.org/node/155882 - replaced $uri_request_id
- // with arg() values.
-
- if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids']) ) {
- $location = 10 . "(" . arg(0) . "|" . arg(1) . "|" . arg(2) . ")";
- $gids = $_GET['gids'];
- $gid = intval(current($_REQUEST['gids']));
- }
-
- // og create nodes (custom node/20 aliased to node/ognodeadd)
- // 0 1 2 3
- // http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
- //
-// if ($arg[1] == 'node') {
-// if (strpos($arg[2], 'ognodeadd') !== false ) {
-// if (strpos($arg[2], 'gids') !== false ) {
-// $location = 13;
-// $subsections = explode("=", $arg[2]);
-// $gid = (int)$subsections[2];
-// }
- //
- // Modification as per: http://drupal.org/node/155882
- // We use arg() instead of $arg[] ($uri_request_id)
- //
- if (arg(0) == 'node') {
- if (arg(1) == 'ognodeadd') {
- //
- // Modification -- Get the gid from the variable instead of trying to calculate it.
- // -- In case we need to add "tid=" to url as per:
- // -- http://drupal.org/node/156568
- //
- if (isset($_REQUEST['gids'])) {
- $location = 13;
- $gids = $_GET['gids'];
- $gid = intval(current($_REQUEST['gids']));
- }
- }
- }
-
- } // end $gid if
- //
- // Now, using $uid and $gid we find out what roles this user has in this group;
- //
- if (empty($gid)) $gid = 0; // This prevents us from getting error on non-group node/add
-// $query = 'SELECT role.rid, role.name FROM role INNER JOIN og_users_roles ON role.rid = og_users_roles.rid WHERE og_users_roles.uid = ' . $uid . ' AND og_users_roles.gid = ' . $gid;
-// $results = db_query($query);
- $query = 'SELECT {role}.rid, {role}.name FROM {role} INNER JOIN {og_users_roles} ON {role}.rid = {og_users_roles}.rid WHERE {og_users_roles}.uid = %d AND {og_users_roles}.gid = %d'; // FIXED TABLE PREFIX
- $results = db_query($query, $uid, $gid);
- //
- // Create an array of these roles;
- //
- while ( $row = db_fetch_array($results) ) {
- $x1 = $row["rid"];
- $ogroles[$x1] = $row["name"];
- }
- //
- // First, we need to create an array of $user->roles
- //
- $c = $user->roles;
- //
- // Next, we add the $user->roles array to the $ogroles array, if there is an ogroles array;
- //
- if ($x1 > 0) {
- $d = array();
- $d = $c + $ogroles;
- $d = array_unique($d);
- } else {
- $d = $c;
- }
-
- // Write the test data
-
- og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query);
-//
-// $d is either the merged results, or just $user->roles;
-//
- return $d;
-
-} // end og_user_roles_all_roles()
-
-function getgid($nodeID, $uid) {
-
- // This will return a $gid based upon the $nodeID and $uid supplied
-
- $gid = 0;
-
-// $result = db_query("select node_access.gid from node_access INNER JOIN og_uid ON node_access.gid = og_uid.nid WHERE node_access.realm = 'og_subscriber' AND og_uid.uid = $uid AND (node_access.nid = $nodeID OR node_access.gid = $nodeID)"); // modified to check for either the node or group ID in node_access
- $result = db_query("select {node_access}.gid from {node_access} INNER JOIN {og_uid} ON {node_access}.gid = {og_uid}.nid WHERE {node_access}.realm = 'og_subscriber' AND {og_uid}.uid = %d AND ({node_access}.nid = %d OR {node_access}.gid = %d)", $uid, $nodeID, $nodeID); // FIXED TABLE PREFIX - modified to check for either the node or group ID in node_access
- while($t = db_fetch_object($result)) {
- $gid = $t->gid;
- }
-
- // If $gid still equals 0 then try searching og_term table (if it exists)
- // og forums will typically be listed here
-
- if ($gid == 0) {
- if (user_table_exists('{og_term}')) {
-// $result = db_query("select og_term.nid from og_term INNER JOIN og_uid ON og_term.nid = og_uid.nid WHERE og_term.tid = $nodeID AND og_uid.uid = $uid");
- $result = db_query("select {og_term}.nid from {og_term} INNER JOIN {og_uid} ON {og_term}.nid = {og_uid}.nid WHERE {og_term}.tid = %d AND {og_uid}.uid = %d", $nodeID, $uid); // FIXED TABLE PREFIX
- while($t = db_fetch_object($result)) {
- $gid = $t->nid;
- }
- }
- }
-
- return $gid;
-
-} // end getgid()
-//
-// Modification - Added this function
-//
-function user_table_exists($table) {
- return db_num_rows(db_query("SHOW TABLES LIKE '{" . db_escape_table($table) . "}'"));
-}
-
-function og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query) {
-//
-// See what is found in user_all_roles
-//
- $testStatus = "";
- $testDate = format_date(time(), 'custom', 'Y-m-d h:i:s a');
- $testUser = $user->uid;
- $testFunction = "og_user_roles_all_roles";
- $testSubFunction = $location;
- $testString = "group context: " . $gid02;
- $testUserName = $user->name;
- $testGroup = $gid;
- $testURI = $uri_request_id;
- $testAArg0 = arg(0);
- $testAArg1 = arg(1);
- $testAArg2 = arg(2);
- $testAArg3 = arg(3);
- $testPerm = "Roles Returned: (" . implode(",", $d) . ")
dbQuery = " . $query;
- if (user_table_exists('{user_test}')) {
- $testQuery = "insert into user_test (testStatus, testDate, testUser, testUserName, testGroup, testFunction, testSubFunction, testString, testURI, testAArg0, testAArg1, testAArg2, testAArg3, testPerm) values ('" . $testStatus . "','" . $testDate . "','" . $testUser . "','" . $testUserName . "','" . $testGroup . "','" . $testFunction . "','" . $testSubFunction . "','" . $testString . "','" . $testURI . "','" . $testAArg0 . "','" . $testAArg1 . "','" . $testAArg2 . "','" . $testAArg3 . "','" . $testPerm . "')";
- db_query($testQuery);
- }
-}
-
+
+// This function takes the global $user (or $account) value and returns a list
+// of group and non-group roles for this user
+
+function og_user_roles_all_roles($user) {
+
+ // This will be the process to get BOTH the group and non-group roles for a user
+
+ $uid = $user->uid;
+ $gid = 0;
+ $gids = array();
+ $nid = 0;
+ $location = 0;
+
+ $uri_request_id = request_uri();
+ $arg = explode("/", $uri_request_id);
+
+ $ogroles = array();
+ $x1 = 0;
+ //
+ // This will by default add the anonymous user role (no need since we merge user->roles)
+ //
+ // We get the groupID
+ //
+ $group_node = og_get_group_context();
+ $gid02 = $group_node->nid;
+ $gid = $gid02;
+ if ($gid02 === null) $gid = 0;
+ //
+ // If the above doesn't get the groupID, then we start trying stuff
+ //
+ if ($gid == 0) {
+
+ // http://doadance.scbbs.com/drupal03/node/79
+
+ if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
+ $location = 1;
+ $nid = (int)arg(1);
+ $gid = getgid($nid, $uid);
+ }
+
+ // http://doadance.scbbs.com/node/79/edit
+ // http://doadance.scbbs.com/node/79/outline
+ // http://doadance.scbbs.com/node/79/track
+
+ if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' ) ) {
+ $location = 2;
+ $nid = (int)arg(1);
+ $gid = getgid($nid, $uid);
+ }
+ // 0 1 2
+ // http://www.mysite.com/comment/edit/14
+ //
+ if (arg(0) == 'comment' && is_numeric(arg(2)) && arg(1) == 'edit' ) {
+ $location = 3;
+ $comment = _comment_load(arg(2));
+ $nid = $comment->nid;
+ $gid = getgid($nid, $uid);
+ }
+ // 0 1 2
+ // http://www.mysite.com/comment/reply/128#comment_form
+ //
+ if (arg(0) == 'comment' && arg(1) == 'reply' ) {
+ $location = 4;
+ $subsections = explode("#", arg(2));
+ $nid = (int)$subsections[0];
+ $gid = getgid($nid, $uid);
+ }
+
+ // og_term access
+ // 0 1 2 3
+ // http://www.mysite.com/node/add/forum/121
+ //
+ if (arg(0) == 'node' && is_numeric(arg(3)) && arg(1) == 'add' ) {
+ $location = 5;
+ $nid = (int)arg(3);
+ $gid = getgid($nid, $uid);
+ }
+
+ // Here we get the gid directly
+ //
+ // http://doadance.scbbs.com/node/79/view/tree
+ // http://doadance.scbbs.com/node/79/view/members
+ // http://doadance.scbbs.com/node/79/view
+
+ if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'view' ) {
+ $location = 2;
+ $gid = (int)arg(1);
+ }
+
+ // Here we get the gid directly
+ //
+ // http://doadance.scbbs.com/og/users/72
+ // http://doadance.scbbs.com/og/manage/72
+
+ if (arg(0) == 'og' && is_numeric(arg(2)) && is_null(arg(3))) {
+ $location = 6;
+ $gid = (int)arg(2);
+ }
+
+ // og_user_roles
+ //
+ // http://doadance.scbbs.com/og/users/72/roles
+ // http://doadance.scbbs.com/og/users/72/add
+
+ if (arg(0) == 'og' && arg(1) == 'users' && is_numeric(arg(2)) && is_null(arg(4))) {
+ $location = 6;
+ $gid = (int)arg(2);
+ }
+
+ // og unsubscribe
+ // og_user_roles
+ //
+ // This is sort of a catch all for "og" and gid in this order
+ // og//
+ //
+ // http://doadance.scbbs.com/og/unsubscribe/72
+ // http://doadance.scbbs.com/og/users/72/add
+
+ if (arg(0) == 'og' && is_numeric(arg(2))) {
+ $location = 6;
+ $gid = (int)arg(2);
+ }
+
+ // og_forum
+ //
+ // http://doadance.scbbs.com/og_forum/manage/72
+
+ if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(2)) && is_null(arg(3))) {
+ $location = 6;
+ $gid = (int)arg(2);
+ }
+
+ // http://doadance.scbbs.com/og_forum/manage/edit/72
+ // http://doadance.scbbs.com/og_forum/manage/add/72
+
+ if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(3))) {
+ $location = 6;
+ $gid = (int)arg(3);
+ }
+
+ // og_calendar
+ //
+ // http://doadance.scbbs.com/og_calendar/72
+
+ // Modification - og_calendar was modified and now may look like this:
+ // http://www.centralavedance.com/og_calendar/2973/2007/07/01
+
+// if (arg(0) == 'og_calendar' && is_numeric(arg(1)) && is_null(arg(2))) {
+ if (arg(0) == 'og_calendar' && is_numeric(arg(1)) ) {
+ $location = 7;
+ $gid = (int)arg(1);
+ }
+
+ // og_forum
+ // 0 1 2 3
+ // http://www.mysite.com/og_forum/39/72?edit[og_groups][]=72
+ // http://www.mysite.com/og_forum/37/71?sort=asc&order=Replies&edit[og_groups][0]=71
+
+// if ($arg[1] == 'og_forum' && strpos($arg[3], 'og_groups') !== false && (!is_null($arg[3])) ) {
+// $location = 8;
+// $subsections = explode("=", $arg[3]);
+// foreach ($subsections as $subsection) {
+// if (is_numeric($subsection)) {
+// $gid = (int)$subsection;
+// }
+// }
+// }
+
+ // Modification as per: http://drupal.org/node/155882 - replaced $uri_request_id
+ // with arg() values.
+
+ if (arg(0) == 'og_forum' && is_numeric(arg(2)) && isset($_REQUEST['edit']) ) {
+ $location = 8;
+ $edit = $_GET['edit'];
+ if ($edit[og_groups][0] > 0) {
+ // $gid = $edit[og_groups][0];
+ $gid = arg(2);
+ }
+ }
+
+ // og_forum
+ // http://www.mysite.com/forum/39
+ //
+ // Modification - 2007-07-04. In the case where this is a forum
+
+ if (arg(0) == 'forum' && is_numeric(arg(1)) && is_null(arg(2)) ) {
+ $location = 8;
+ $tid = (int)arg(1);
+ $gid = og_user_roles_gid_from_tid($tid);
+
+ // If no gid returned, then set $gid = 0
+
+ if (empty($gid)) {
+ $gid = 0;
+ }
+ }
+
+ // og create nodes (version 5.1)
+ // 0 1 2 3
+ // http://sbn.scbbs.com/node/add/forum?gids[]=72
+ // http://sbn.scbbs.com/node/add/simplenews?gids[]=72
+ // http://sbn.scbbs.com/node/add/webform?gids[]=72
+ // http://sbn.scbbs.com/node/add/video?gids[]=72
+ // http://sbn.scbbs.com/node/add/page?gids[]=72
+ // http://sbn.scbbs.com/node/add/blog?gids[]=72
+ // http://sbn.scbbs.com/node/add/event?gids[]=72
+ // http://sbn.scbbs.com/node/add/poll?gids[]=72
+ // http://sbn.scbbs.com/node/add/flexinode-3?gids[]=72
+
+// if ($arg[1] == 'node' && strpos($arg[3], 'gids') !== false && (!is_null($arg[3])) ) {
+// $location = 10 . "(" . arg(0) . "|" . arg(1) . "|" . arg(2) . ")";
+// $subsections = explode("=", $arg[3]);
+// $gid = (int)$subsections[1];
+// }
+
+ // Modification as per: http://drupal.org/node/155882 - replaced $uri_request_id
+ // with arg() values.
+
+ if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids']) ) {
+ $location = 10 ."(". arg(0) ."|". arg(1) ."|". arg(2) .")";
+ $gids = $_GET['gids'];
+ $gid = intval(current($_REQUEST['gids']));
+ }
+
+ // og create nodes (custom node/20 aliased to node/ognodeadd)
+ // 0 1 2 3
+ // http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
+ //
+// if ($arg[1] == 'node') {
+// if (strpos($arg[2], 'ognodeadd') !== false ) {
+// if (strpos($arg[2], 'gids') !== false ) {
+// $location = 13;
+// $subsections = explode("=", $arg[2]);
+// $gid = (int)$subsections[2];
+// }
+ //
+ // Modification as per: http://drupal.org/node/155882
+ // We use arg() instead of $arg[] ($uri_request_id)
+ //
+ if (arg(0) == 'node') {
+ if (arg(1) == 'ognodeadd') {
+ //
+ // Modification -- Get the gid from the variable instead of trying to calculate it.
+ // -- In case we need to add "tid=" to url as per:
+ // -- http://drupal.org/node/156568
+ //
+ if (isset($_REQUEST['gids'])) {
+ $location = 13;
+ $gids = $_GET['gids'];
+ $gid = intval(current($_REQUEST['gids']));
+ }
+ }
+ }
+
+ } // end $gid if
+ //
+ // Now, using $uid and $gid we find out what roles this user has in this group;
+ //
+ if (empty($gid)) $gid = 0; // This prevents us from getting error on non-group node/add
+// $query = 'SELECT role.rid, role.name FROM role INNER JOIN og_users_roles ON role.rid = og_users_roles.rid WHERE og_users_roles.uid = ' . $uid . ' AND og_users_roles.gid = ' . $gid;
+// $results = db_query($query);
+ $query = 'SELECT {role}.rid, {role}.name FROM {role} INNER JOIN {og_users_roles} ON {role}.rid = {og_users_roles}.rid WHERE {og_users_roles}.uid = %d AND {og_users_roles}.gid = %d'; // FIXED TABLE PREFIX
+ $results = db_query($query, $uid, $gid);
+ //
+ // Create an array of these roles;
+ //
+ while ( $row = db_fetch_array($results) ) {
+ $x1 = $row["rid"];
+ $ogroles[$x1] = $row["name"];
+ }
+ //
+ // First, we need to create an array of $user->roles
+ //
+ $c = $user->roles;
+ //
+ // Next, we add the $user->roles array to the $ogroles array, if there is an ogroles array;
+ //
+ if ($x1 > 0) {
+ $d = array();
+ $d = $c + $ogroles;
+ $d = array_unique($d);
+ }
+ else {
+ $d = $c;
+ }
+
+ // Write the test data
+
+ og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query);
+//
+// $d is either the merged results, or just $user->roles;
+//
+ return $d;
+
+} // end og_user_roles_all_roles()
+
+function getgid($nid, $uid) {
+
+ // This will return a $gid based upon the $nid and $uid supplied
+
+ $gid = 0;
+
+// $result = db_query("select node_access.gid from node_access INNER JOIN og_uid ON node_access.gid = og_uid.nid WHERE node_access.realm = 'og_subscriber' AND og_uid.uid = $uid AND (node_access.nid = $nid OR node_access.gid = $nid)"); // modified to check for either the node or group ID in node_access
+ $result = db_query("select {node_access}.gid from {node_access} INNER JOIN {og_uid} ON {node_access}.gid = {og_uid}.nid WHERE {node_access}.realm = 'og_subscriber' AND {og_uid}.uid = %d AND ({node_access}.nid = %d OR {node_access}.gid = %d)", $uid, $nid, $nid); // FIXED TABLE PREFIX - modified to check for either the node or group ID in node_access
+ while ($t = db_fetch_object($result)) {
+ $gid = $t->gid;
+ }
+
+ // If $gid still equals 0 then try searching og_term table (if it exists)
+ // og forums will typically be listed here
+
+ if ($gid == 0) {
+ if (user_table_exists('{og_term}')) {
+// $result = db_query("select og_term.nid from og_term INNER JOIN og_uid ON og_term.nid = og_uid.nid WHERE og_term.tid = $nid AND og_uid.uid = $uid");
+ $result = db_query("select {og_term}.nid from {og_term} INNER JOIN {og_uid} ON {og_term}.nid = {og_uid}.nid WHERE {og_term}.tid = %d AND {og_uid}.uid = %d", $nid, $uid); // FIXED TABLE PREFIX
+ while ($t = db_fetch_object($result)) {
+ $gid = $t->nid;
+ }
+ }
+ }
+
+ return $gid;
+
+} // end getgid()
+//
+// Modification - Added this function
+//
+function user_table_exists($table) {
+ return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
+}
+
+function og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query) {
+//
+// See what is found in user_all_roles
+//
+ $test_status = "";
+ $test_date = format_date(time(), 'custom', 'Y-m-d h:i:s a');
+ $test_user = $user->uid;
+ $test_function = "og_user_roles_all_roles";
+ $test_sub_function = $location;
+ $test_string = "group context: " . $gid02;
+ $test_user_name = $user->name;
+ $test_group = $gid;
+ $test_uri = $uri_request_id;
+ $test_arg0 = arg(0);
+ $test_arg1 = arg(1);
+ $test_arg2 = arg(2);
+ $test_arg3 = arg(3);
+ $test_perm = "Roles Returned: (". implode(",", $d) .")
dbQuery = ". $query;
+ if (user_table_exists('{user_test}')) {
+ $test_query = "INSERT into {user_test} (testStatus, testDate, testUser, testUserName, testGroup, testFunction, testSubFunction, testString, testURI, testAArg0, testAArg1, testAArg2, testAArg3, testPerm) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')";
+ db_query($test_query, $test_status, $test_date, $test_user, $test_user_name, $test_group, $test_function, $test_sub_function, $test_string, $test_uri, $test_arg0, $test_arg1, $test_arg2, $test_arg3, $test_perm);
+ }
+}
+
/**
* Called by og_user_roles_nodeapi('access')
* To check og access permissions
@@ -1347,141 +1340,142 @@
*/
function og_user_roles_og_access_check($op, $node = NULL) {
global $user;
- $uid = $user->uid;
-
- if ($op != 'create' && $node->nid && $node->status) {
-
+ $uid = $user->uid;
+
+ if ($op != 'create' && $node->nid && $node->status) {
+
if (isset($user) && is_array($user->og_groups)) {
- $gids = array_keys($user->og_groups);
+ $gids = array_keys($user->og_groups);
}
else {
$gids[] = 0;
}
-
-
+
+
if (isset($user) && is_array($user->roles)) {
$rids = array_keys($user->roles);
}
else {
$rids[] = 1;
}
-
- //
- // if this node has groups or is a group, then use group sql, else use non-group sql
- //
-
- $groups = $node->og_groups;
-
- if ($groups || $node->type == 'group') {
-
- $sql = "
- SELECT COUNT(*) FROM {node_access} na
- LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid
- LEFT OUTER JOIN {og} ogm on ogm.nid = na.nid
- WHERE (na.nid = 0 OR na.nid = %d)
- AND ((na.realm = 'og_public' and na.gid = 0)
- OR (na.realm = 'og_subscriber' AND na.gid in ('".implode("','",$gids)."'))
- OR (ogm.nid > 0 and (na.nid in ('".implode("','",$gids)."')) or ogm.directory = 1 )
- OR (na.realm = 'term_access' AND na.nid in ('".implode("','",$gids)."')) )
- AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ".$uid.") )
- ";
- } else {
- $sql = "
- SELECT COUNT(*) FROM {node_access} na
- WHERE (na.nid = 0 OR na.nid = %d)
- AND (na.realm = 'term_access' AND na.gid in ('".implode("','",$rids)."'))
- AND na.grant_$op >= 1
- ";
- }
-
- $result = db_query($sql, $node->nid);
- $output = (db_result($result));
- if ($output == 0) return FALSE;
- if ($output > 0) return TRUE;
- }
-}
-
+
+ //
+ // if this node has groups or is a group, then use group sql, else use non-group sql
+ //
+
+ $groups = $node->og_groups;
+
+ if ($groups || $node->type == 'group') {
+
+ $sql = "
+ SELECT COUNT(*) FROM {node_access} na
+ LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid
+ LEFT OUTER JOIN {og} ogm on ogm.nid = na.nid
+ WHERE (na.nid = 0 OR na.nid = %d)
+ AND ((na.realm = 'og_public' and na.gid = 0)
+ OR (na.realm = 'og_subscriber' AND na.gid in ('". implode("','", $gids) ."'))
+ OR (ogm.nid > 0 and (na.nid in ('". implode("','", $gids) ."')) or ogm.directory = 1 )
+ OR (na.realm = 'term_access' AND na.nid in ('". implode("','", $gids) ."')) )
+ AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ". $uid .") )
+ ";
+ }
+ else {
+ $sql = "
+ SELECT COUNT(*) FROM {node_access} na
+ WHERE (na.nid = 0 OR na.nid = %d)
+ AND (na.realm = 'term_access' AND na.gid in ('". implode("','", $rids) ."'))
+ AND na.grant_$op >= 1
+ ";
+ }
+ $result = db_query($sql, $node->nid);
+ $output = (db_result($result));
+ if ($output == 0) return FALSE;
+ if ($output > 0) return TRUE;
+ }
+}
+
/**
- * Called by og_user_roles_nodeapi('access')
+ * Called by og_user_roles_nodeapi('access')
* To check taxonomy_access access permissions
*
*/
-function og_user_roles_taxonomy_access_check($op, $node = NULL) {
- global $user;
- $uid = $user->uid;
-
- if ($op != 'create' && $node->nid && $node->status) {
- // Discovered that I needed to continue using user->roles to get non-group roles.
- // will get group roles using og_users_roles and og_ancestry
- //
+function og_user_roles_taxonomy_access_check($op, $node = NULL) {
+ global $user;
+ $uid = $user->uid;
+
+ if ($op != 'create' && $node->nid && $node->status) {
+ // Discovered that I needed to continue using user->roles to get non-group roles.
+ // will get group roles using og_users_roles and og_ancestry
+ //
if (isset($user) && is_array($user->roles)) {
$rids = array_keys($user->roles);
}
else {
$rids[] = 1;
}
-
- $sql = "SELECT COUNT(*) FROM {node_access} na";
- $sql .= " LEFT OUTER JOIN {og_users_roles} ogr ON ogr.rid = na.gid";
- $sql .= " LEFT OUTER JOIN {og_ancestry} oga ON oga.nid = na.nid";
- $sql .= " LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid";
- $sql .= " WHERE (na.nid = 0 OR na.nid = %d) AND ((na.realm = 'term_access' AND na.gid in ('".implode("','",$rids)."')) OR (ogr.uid = " . $uid . " AND na.realm = 'term_access' AND oga.group_nid = ogr.gid) )";
- $sql .= " AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ".$uid.") )";
- $result = db_query($sql, $node->nid);
- $output = (db_result($result));
- if ($output == 0) return FALSE;
- if ($output > 0) return TRUE;
- }
-}
-
+
+ $sql = "SELECT COUNT(*) FROM {node_access} na";
+ $sql .= " LEFT OUTER JOIN {og_users_roles} ogr ON ogr.rid = na.gid";
+ $sql .= " LEFT OUTER JOIN {og_ancestry} oga ON oga.nid = na.nid";
+ $sql .= " LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid";
+ $sql .= " WHERE (na.nid = 0 OR na.nid = %d) AND ((na.realm = 'term_access' AND na.gid in ('". implode("','", $rids) ."')) OR (ogr.uid = ". $uid ." AND na.realm = 'term_access' AND oga.group_nid = ogr.gid) )";
+ $sql .= " AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ". $uid .") )";
+ $result = db_query($sql, $node->nid);
+ $output = (db_result($result));
+ if ($output == 0) return FALSE;
+ if ($output > 0) return TRUE;
+ }
+}
+
/**
- * Create content
+ * Create content
*
- * Format: http://www.scbbs.com/node/ognodeadd?type=link&gids[]=29
+ * Format: http://www.scbbs.com/node/ognodeadd?type=link&gids[]=29
*
*/
-function og_user_roles_ognodeadd() {
- global $user;
- $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
- $user->roles = $roles;
-
- $gids = $_GET['gids'];
-
- $typeFound = 'no';
-
- if ($gids) {
- $group_node = node_load($gids[0]);
- og_set_group_context($group_node);
- }
-
- $type = $_GET['type'];
-
- if ($type) {
- //
- // Got this from node.module (node_access)
- // No matter the type, this should return us the create permission.
- //
- $module = node_get_types('module', $type);
- if ($module == 'node') {
- $module = 'node_content'; // Avoid function name collisions.
- }
- $access = module_invoke($module, 'access', 'create', $type);
- if ($access === TRUE) {
- $output = node_add($type);
- } else {
- $output = "Access denied.";
- watchdog("access denied", "node/ognodeadd?type=" . $type . "&gids[]=" . $gids[0], WATCHDOG_WARNING);
- }
- }
- return $output;
-}
-/**
- * using the tid, get the group id
- * stolen from og_forum (had to in the case where og_user_roles user doesn't have latest
- * version of og_forum module which includes this)
- */
-function og_user_roles_gid_from_tid($tid=0) {
- $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
- $gid = db_result(db_query($sql, $tid));
- return $gid;
-}
+function og_user_roles_ognodeadd() {
+ global $user;
+ $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
+ $user->roles = $roles;
+
+ $gids = $_GET['gids'];
+
+ $type_found = 'no';
+
+ if ($gids) {
+ $group_node = node_load($gids[0]);
+ og_set_group_context($group_node);
+ }
+
+ $type = $_GET['type'];
+
+ if ($type) {
+ //
+ // Got this from node.module (node_access)
+ // No matter the type, this should return us the create permission.
+ //
+ $module = node_get_types('module', $type);
+ if ($module == 'node') {
+ $module = 'node_content'; // Avoid function name collisions.
+ }
+ $access = module_invoke($module, 'access', 'create', $type);
+ if ($access === TRUE) {
+ $output = node_add($type);
+ }
+ else {
+ $output = "Access denied.";
+ watchdog("access denied", "node/ognodeadd?type=". $type ."&gids[]=". $gids[0], WATCHDOG_WARNING);
+ }
+ }
+ return $output;
+}
+/**
+ * using the tid, get the group id
+ * stolen from og_forum (had to in the case where og_user_roles user doesn't have latest
+ * version of og_forum module which includes this)
+ */
+function og_user_roles_gid_from_tid($tid=0) {
+ $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
+ $gid = db_result(db_query($sql, $tid));
+ return $gid;
+}