aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-31 15:22:48 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-31 15:22:48 +0000
commitab7d70b9d870d69a5b79c3fbb005565302112efc (patch)
tree3e1b7ed7925885fe4780c249a4008f9bd3f5cea9
parent2ba7cd11ba933888f137f875006766122fa6e0b0 (diff)
downloadelgg-ab7d70b9d870d69a5b79c3fbb005565302112efc.tar.gz
elgg-ab7d70b9d870d69a5b79c3fbb005565302112efc.tar.bz2
Picker saves correctly!
git-svn-id: https://code.elgg.org/elgg/trunk@1635 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--actions/friends/editcollection.php37
-rw-r--r--engine/lib/access.php31
-rw-r--r--friends/pickercallback.php9
-rw-r--r--languages/en.php1
-rw-r--r--views/default/friends/collection.php6
-rw-r--r--views/default/friends/collectiontabs.php19
-rw-r--r--views/default/friends/forms/collectionfields.php23
-rw-r--r--views/default/friends/forms/edit.php7
-rw-r--r--views/default/friends/picker.php69
9 files changed, 134 insertions, 68 deletions
diff --git a/actions/friends/editcollection.php b/actions/friends/editcollection.php
index f8458da46..fd1944c51 100644
--- a/actions/friends/editcollection.php
+++ b/actions/friends/editcollection.php
@@ -11,42 +11,11 @@
* @link http://elgg.org/
*/
- //must be logged in
- gatekeeper();
-
$collection_id = get_input('collection_id');
$collection_name = get_input('collection_name');
+ $friends = get_input('friend');
- //$friends = get_input('friends_collection');
-
- //chech the colelction exists and the current user owners it
- if($full_collection = get_access_collection($collection_id)){
-
- //first check to make sure that a collection name has been set and create the new colection
- if($collection_name){
-
- //create the collection
- $create_collection = create_access_collection($collection_name, $_SESSION['user']->getGUID());
-
-
- // Success message
- system_message(elgg_echo("friends:collectionadded"));
- // Forward to the collections page
- forward("pg/collections/" . $_SESSION['user']->username);
-
- } else {
-
- register_error(elgg_echo("friends:nocollectionname"));
-
- }
-
- } else {
-
- register_error(elgg_echo("friends:nocollectionname"));
-
- }
-
- // Forward to the add collection page
- forward("pg/collections/add");
+ //chech the collection exists and the current user owners it
+ update_access_collection($collection_id, $friends);
?> \ No newline at end of file
diff --git a/engine/lib/access.php b/engine/lib/access.php
index 2c9a886e6..a1741f8bf 100644
--- a/engine/lib/access.php
+++ b/engine/lib/access.php
@@ -202,6 +202,33 @@
}
/**
+ * Updates the membership in an access collection.
+ *
+ * @param int $collection_id The ID of the collection.
+ * @param array $members Array of member GUIDs
+ * @return true|false Depending on success
+ */
+ function update_access_collection($collection_id, $members) {
+
+ global $CONFIG;
+ $collection_id = (int) $collection_id;
+
+ if ($collection = get_access_collection($collection_id)) {
+ delete_data("delete from {$CONFIG->dbprefix}access_collection_membership where access_collection_id = {$collection_id}");
+ }
+
+ if (is_array($members) && sizeof($members) > 0) {
+ foreach($members as $member) {
+ $member = (int) $member;
+ add_user_to_access_collection($member, $collection_id);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Deletes a specified access collection
*
* @param int $collection_id The collection ID
@@ -232,7 +259,7 @@
$collection_id = (int) $collection_id;
global $CONFIG;
- $get_collection = get_data("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}");
+ $get_collection = get_data_row("SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}");
return $get_collection;
@@ -252,7 +279,7 @@
$collections = get_write_access_array();
if (array_key_exists($collection_id, $collections) && $user = get_user($user_guid)) {
-
+
global $CONFIG;
insert_data("insert into {$CONFIG->dbprefix}access_collection_membership set access_collection_id = {$collection_id}, user_guid = {$user_guid}");
return true;
diff --git a/friends/pickercallback.php b/friends/pickercallback.php
index 2a6a55439..478549d3d 100644
--- a/friends/pickercallback.php
+++ b/friends/pickercallback.php
@@ -13,17 +13,20 @@
// Load Elgg engine
require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
+ global $CONFIG;
// Get callback type (list or picker)
$type = get_input('type','picker');
// Get list of members if applicable
- $members = get_input('members','');
+ /*$members = get_input('members','');
if (!empty($members)) {
$members = explode(',',$members);
} else {
$members = array();
- }
+ }*/
+ $collection = (int) get_input('collection',0);
+ $members = get_members_of_access_collection($collection, true);
$friendspicker = (int) get_input('friendspicker',0);
@@ -43,6 +46,8 @@
'value' => $members,
'callback' => true,
'friendspicker' => $friendspicker,
+ 'formcontents' => elgg_view('friends/forms/collectionfields',array('collection' => get_access_collection($collection))),
+ 'formtarget' => $CONFIG->wwwroot . 'action/friends/editcollection',
));
break;
diff --git a/languages/en.php b/languages/en.php
index b323b6a89..8d6e80fd5 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -397,6 +397,7 @@
*/
'save' => "Save",
+ 'cancel' => "Cancel",
'saving' => "Saving ...",
'update' => "Update",
'edit' => "Edit",
diff --git a/views/default/friends/collection.php b/views/default/friends/collection.php
index 8d8afd7d1..438d82e8c 100644
--- a/views/default/friends/collection.php
+++ b/views/default/friends/collection.php
@@ -36,16 +36,14 @@
// individual collection panels
if($friends = $vars['collection']->entities){
- $members = $vars['collection']->members;
- $implodedmemberslist = implode(',',$members);
- $content = elgg_view('friends/collectiontabs', array('members' => $members, 'friends' => $friends, 'collection' => $vars['collection'], 'friendspicker' => $vars['friendspicker']));
+ $content = elgg_view('friends/collectiontabs', array('owner' => $_SESSION['user'], 'collection' => $vars['collection'], 'friendspicker' => $vars['friendspicker']));
echo elgg_view('friends/picker',array('entities' => $friends, 'value' => $members, 'content' => $content, 'replacement' => '', 'friendspicker' => $vars['friendspicker']));
?>
<script type="text/javascript">
$(document).ready(function () {
- $('#friends_picker_placeholder<?php echo $vars['friendspicker']; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=list&members=<?php echo $implodedmemberslist; ?>');
+ $('#friends_picker_placeholder<?php echo $vars['friendspicker']; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=list&collection=<?php echo $vars['collection']->id; ?>');
});
</script>
diff --git a/views/default/friends/collectiontabs.php b/views/default/friends/collectiontabs.php
index 1e40dd584..cdeb6b798 100644
--- a/views/default/friends/collectiontabs.php
+++ b/views/default/friends/collectiontabs.php
@@ -2,19 +2,8 @@
$friendspicker = $vars['friendspicker'];
- if (isset($vars['members'])) {
- $members = implode(',',$vars['members']);
- } else {
- $members = "";
- }
-
- $friends = "";
- if (isset($vars['friends'])) {
- foreach($vars['friends'] as $friend) {
- if (!empty($friends)) $friends .= ",";
- $friends .= $friend->getGUID();
- }
- }
+ $collectionid = $vars['collection']->id;
+ $ownerid = $vars['owner']->getGUID();
?>
@@ -32,7 +21,7 @@ $(document).ready(function () {
$('a.collectionmembers<?php echo $friendspicker; ?>').click(function () {
// load collection members pane
- $('#friends_picker_placeholder<?php echo $friendspicker; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=list&members=<?php echo $members; ?>');
+ $('#friends_picker_placeholder<?php echo $friendspicker; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=list&collection=<?php echo $collectionid; ?>');
// remove selected state from previous tab
$(this).parent().parent().find("li.selected").removeClass("selected");
@@ -44,7 +33,7 @@ $(document).ready(function () {
$('a.editmembers<?php echo $friendspicker; ?>').click(function () {
// load friends picker pane
- $('#friends_picker_placeholder<?php echo $friendspicker; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=picker&members=<?php echo $members; ?>&friends=<?php echo $friends; ?>&friendspicker=<?php echo $friendspicker; ?>');
+ $('#friends_picker_placeholder<?php echo $friendspicker; ?>').load('<?php echo $vars['url']; ?>friends/pickercallback.php?username=<?php echo $_SESSION['user']->username; ?>&type=picker&collection=<?php echo $collectionid; ?>&friendspicker=<?php echo $friendspicker; ?>');
// remove selected state from previous tab
$(this).parent().parent().find("li.selected").removeClass("selected");
diff --git a/views/default/friends/forms/collectionfields.php b/views/default/friends/forms/collectionfields.php
new file mode 100644
index 000000000..ef3c367e3
--- /dev/null
+++ b/views/default/friends/forms/collectionfields.php
@@ -0,0 +1,23 @@
+<?php
+
+ /**
+ * Elgg friend collections required hidden fields for js friends picker form
+ *
+ * @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/
+ */
+
+ if (isset($vars['collection'])) {
+?>
+
+ <input type="hidden" name="collection_id" value="<?php echo $vars['collection']->id; ?>" />
+
+<?php
+
+ }
+
+?> \ No newline at end of file
diff --git a/views/default/friends/forms/edit.php b/views/default/friends/forms/edit.php
index 6ed58d5bf..7c8a3f455 100644
--- a/views/default/friends/forms/edit.php
+++ b/views/default/friends/forms/edit.php
@@ -3,11 +3,12 @@
/**
* Elgg friend collections add/edit
*
- * @package ElggFriends
+ * @package Elgg
+ * @subpackage Core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Dave Tosh <dave@elgg.com>
+ * @author Curverider Ltd
* @copyright Curverider Ltd 2008
- * @link http://elgg.com/
+ * @link http://elgg.org/
*
* @uses $vars['object'] Optionally, the collection edit
*/
diff --git a/views/default/friends/picker.php b/views/default/friends/picker.php
index 94211f49b..d813e6fe7 100644
--- a/views/default/friends/picker.php
+++ b/views/default/friends/picker.php
@@ -49,6 +49,14 @@
$users = array();
$activeletters = array();
+
+ // Are we displaying form tags and submit buttons?
+ // (If we've been given a target, then yes! Otherwise, no.)
+ if (isset($vars['formtarget'])) {
+ $formtarget = $vars['formtarget'];
+ } else {
+ $formtarget = false;
+ }
// Sort users by letter
if (is_array($vars['entities']) && sizeof($vars['entities']))
@@ -85,10 +93,40 @@
}
if (!isset($vars['replacement'])) {
-
+
+ if ($formtarget) {
?>
+
+ <script language="text/javascript">
+ $(function() { // onload...do
+ $('#collectionMembersForm<?php echo $friendspicker; ?>').submit(function() {
+ var inputs = [];
+ $(':input', this).each(function() {
+ inputs.push(this.name + '=' + escape(this.value));
+ });
+ jQuery.ajax({
+ type: "POST",
+ data: inputs.join('&'),
+ url: this.action,
+ success: function(){
+ $('a.collectionmembers<?php echo $friendspicker; ?>').click();
+ }
+
+ });
+ return false;
+ })
+ })
+
+ </script>
-
+ <!-- Collection members form -->
+ <form id="collectionMembersForm<?php echo $friendspicker; ?>" action="<?php echo $formtarget; ?>" method="post"> <!-- action="" method=""> -->
+
+<?php
+
+ }
+
+?>
<div class="friendsPicker_wrapper">
<div id="friendsPicker<?php echo $friendspicker; ?>">
@@ -171,12 +209,27 @@
}
?>
- </div>
- <!-- Collection members form -->
- <form id="collectionMembersForm"> <!-- action="" method=""> -->
- <input type="submit" class="submit_button" value="Save changes" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();"/>
- <input type="button" class="cancel_button" value="Cancel" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" />
- </form>
+ </div>
+
+<?php
+
+ if ($formtarget) {
+
+ if (isset($vars['formcontents']))
+ echo $vars['formcontents'];
+
+?>
+ <input type="submit" class="submit_button" value="<?php echo elgg_echo('save'); ?>" />
+ <!-- onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" -->
+ <input type="button" class="cancel_button" value="<?php echo elgg_echo('cancel'); ?>" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" />
+ </form>
+
+<?php
+
+ }
+
+?>
+
</div>
</div>