3 function validate_members(&$item) {
7 function group_init(&$a) {
9 require_once('include/group.php');
10 $a->page['aside'] = group_side('contacts','group',false,(($a->argc > 1) ? intval($a->argv[1]) : 0));
16 function group_post(&$a) {
19 notice( t('Permission denied.') . EOL);
23 if(($a->argc == 2) && ($a->argv[1] === 'new')) {
24 check_form_security_token_redirectOnErr('/group/new', 'group_edit');
26 $name = notags(trim($_POST['groupname']));
27 $r = group_add(local_user(),$name);
29 info( t('Group created.') . EOL );
30 $r = group_byname(local_user(),$name);
32 goaway($a->get_baseurl() . '/group/' . $r);
35 notice( t('Could not create group.') . EOL );
36 goaway($a->get_baseurl() . '/group');
39 if(($a->argc == 2) && (intval($a->argv[1]))) {
40 check_form_security_token_redirectOnErr('/group', 'group_edit');
42 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
47 notice( t('Group not found.') . EOL );
48 goaway($a->get_baseurl() . '/contacts');
52 $groupname = notags(trim($_POST['groupname']));
53 if((strlen($groupname)) && ($groupname != $group['name'])) {
54 $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
60 info( t('Group name changed.') . EOL );
63 $a->page['aside'] = group_side();
68 function group_content(&$a) {
72 notice( t('Permission denied') . EOL);
76 // Switch to text mode interface if we have more than 'n' contacts or group members
78 $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
79 if($switchtotext === false)
80 $switchtotext = get_config('system','groupedit_image_limit');
81 if($switchtotext === false)
84 $tpl = get_markup_template('group_edit.tpl');
85 $context = array('$submit' => t('Submit'));
87 if(($a->argc == 2) && ($a->argv[1] === 'new')) {
89 return replace_macros($tpl, $context + array(
90 '$title' => t('Create a group of contacts/friends.'),
91 '$gname' => array('groupname',t('Group Name: '), '', ''),
93 '$form_security_token' => get_form_security_token("group_edit"),
99 if(($a->argc == 3) && ($a->argv[1] === 'drop')) {
100 check_form_security_token_redirectOnErr('/group', 'group_drop', 't');
102 if(intval($a->argv[2])) {
103 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
108 $result = group_rmv(local_user(),$r[0]['name']);
110 info( t('Group removed.') . EOL);
112 notice( t('Unable to remove group.') . EOL);
114 goaway($a->get_baseurl() . '/group');
118 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
119 check_form_security_token_ForbiddenOnErr('group_member_change', 't');
121 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
126 $change = intval($a->argv[2]);
129 if(($a->argc > 1) && (intval($a->argv[1]))) {
131 require_once('include/acl_selectors.php');
132 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
137 notice( t('Group not found.') . EOL );
138 goaway($a->get_baseurl() . '/contacts');
141 $members = group_get_members($group['id']);
142 $preselected = array();
143 if(count($members)) {
144 foreach($members as $member)
145 $preselected[] = $member['id'];
149 if(in_array($change,$preselected)) {
150 group_rmv_member(local_user(),$group['name'],$change);
153 group_add_member(local_user(),$group['name'],$change);
156 $members = group_get_members($group['id']);
157 $preselected = array();
158 if(count($members)) {
159 foreach($members as $member)
160 $preselected[] = $member['id'];
165 $drop_tpl = get_markup_template('group_drop.tpl');
166 $drop_txt = replace_macros($drop_tpl, array(
167 '$id' => $group['id'],
168 '$delete' => t('Delete'),
169 '$form_security_token' => get_form_security_token("group_drop"),
172 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
175 $context = $context + array(
176 '$title' => t('Group Editor'),
177 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
178 '$gid' => $group['id'],
179 '$drop' => $drop_txt,
180 '$form_security_token' => get_form_security_token('group_edit'),
188 $groupeditor = array(
189 'label_members' => t('Members'),
190 'members' => array(),
191 'label_contacts' => t('All Contacts'),
192 'contacts' => array(),
195 $sec_token = addslashes(get_form_security_token('group_member_change'));
196 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
197 foreach($members as $member) {
199 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
200 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
203 group_rmv_member(local_user(),$group['name'],$member['id']);
206 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
211 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
212 foreach($r as $member) {
213 if(! in_array($member['id'],$preselected)) {
214 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
215 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
220 $context['$groupeditor'] = $groupeditor;
221 $context['$desc'] = t('Click on a contact to add or remove.');
224 $tpl = get_markup_template('groupeditor.tpl');
225 echo replace_macros($tpl, $context);
229 return replace_macros($tpl, $context);