diff options
-rw-r--r-- | engine/lib/access.php | 41 | ||||
-rw-r--r-- | views/default/input/access.php | 45 |
2 files changed, 85 insertions, 1 deletions
diff --git a/engine/lib/access.php b/engine/lib/access.php index e81bd2da0..46e8b2e77 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -60,7 +60,7 @@ if (!isset($access_array))
$access_array = array();
- if ($user_id == 0) $user_id = $_SESSION['id'];
+ if ($user_id == 0) $user_id = $_SESSION['guid'];
if (($site_id == 0) && (isset($CONFIG->site_id))) $site_id = $CONFIG->site_id;
$user_id = (int) $user_id;
$site_id = (int) $site_id;
@@ -87,6 +87,45 @@ return $access_array[$user_id];
}
+
+ /**
+ * Returns an array of access permissions that the specified user is allowed to save objects with.
+ * Permissions are of the form ('id' => 'Description')
+ *
+ * @param int $user_id The user's GUID.
+ * @param int $site_id The current site.
+ * @param true|false $flush If this is set to true, this will shun any cached version
+ * @return array List of access permissions=
+ */
+ function get_write_access_array($user_id = 0, $site_id = 0, $flush = false) {
+
+ global $CONFIG;
+ static $access_array;
+
+ if ($user_id == 0) $user_id = $_SESSION['guid'];
+ if (($site_id == 0) && (isset($CONFIG->site_id))) $site_id = $CONFIG->site_id;
+ $user_id = (int) $user_id;
+ $site_id = (int) $site_id;
+
+ if (empty($access_array[$user_id]) || $flush == true) {
+
+ $query = "select ag.* from {$CONFIG->dbprefix}access_groups ag ";
+ $query .= " where (ag.site_guid = {$site_id} or ag.site_guid = 0)";
+ $query .= " and (ag.owner_guid = {$user_id} or ag.owner_guid = 0)";
+
+ $tmp_access_array = array();
+ if ($groups = get_data($query)) {
+ foreach($groups as $group)
+ $tmp_access_array[$group->id] = elgg_echo($group->name);
+ }
+
+ $access_array[$user_id] = $tmp_access_array;
+
+ }
+
+ return $access_array[$user_id];
+
+ }
/**
* Some useful constant definitions
diff --git a/views/default/input/access.php b/views/default/input/access.php new file mode 100644 index 000000000..4c767d0d0 --- /dev/null +++ b/views/default/input/access.php @@ -0,0 +1,45 @@ +<?php
+
+ /**
+ * Elgg access level input
+ * Displays a pulldown input field
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ * @uses $vars['value'] The current value, if any
+ * @uses $vars['js'] Any Javascript to enter into the input tag
+ * @uses $vars['internalname'] The name of the input field
+ *
+ */
+
+ $vars['options'] = array();
+ $vars['options'] = get_write_access_array();
+
+ if (is_array($vars['options']) && sizeof($vars['options']) > 0) {
+
+?>
+
+<select name="<?php echo $vars['internalname']; ?>" <?php echo $vars['js']; ?>>
+<?php
+
+ foreach($vars['options'] as $option) {
+ if ($option != $vars['value']) {
+ echo "<option>{$option}</option>";
+ } else {
+ echo "<option selected=\"selected\">{$option}</option>";
+ }
+ }
+
+?>
+</select>
+
+<?php
+
+ }
+
+?>
\ No newline at end of file |