3 function validate_members(&$item) {
7 function group_init(App $a) {
9 require_once('include/group.php');
10 $a->page['aside'] = group_side('contacts','group','extended',(($a->argc > 1) ? intval($a->argv[1]) : 0));
16 function group_post(App $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(App::get_baseurl() . '/group/' . $r);
35 notice( t('Could not create group.') . EOL );
37 goaway(App::get_baseurl() . '/group');
41 if (($a->argc == 2) && (intval($a->argv[1]))) {
42 check_form_security_token_redirectOnErr('/group', 'group_edit');
44 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
48 if (! dbm::is_result($r)) {
49 notice( t('Group not found.') . EOL );
50 goaway(App::get_baseurl() . '/contacts');
54 $groupname = notags(trim($_POST['groupname']));
55 if ((strlen($groupname)) && ($groupname != $group['name'])) {
56 $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d",
63 info( t('Group name changed.') . EOL );
67 $a->page['aside'] = group_side();
72 function group_content(App $a) {
76 notice( t('Permission denied') . EOL);
80 // Switch to text mode interface if we have more than 'n' contacts or group members
82 $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
83 if($switchtotext === false)
84 $switchtotext = get_config('system','groupedit_image_limit');
85 if($switchtotext === false)
88 $tpl = get_markup_template('group_edit.tpl');
91 '$submit' => t('Save Group'),
94 if (($a->argc == 2) && ($a->argv[1] === 'new')) {
96 return replace_macros($tpl, $context + array(
97 '$title' => t('Create a group of contacts/friends.'),
98 '$gname' => array('groupname',t('Group Name: '), '', ''),
100 '$form_security_token' => get_form_security_token("group_edit"),
106 if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
107 check_form_security_token_redirectOnErr('/group', 'group_drop', 't');
109 if (intval($a->argv[2])) {
110 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
117 if (dbm::is_result($r)) {
118 $result = group_rmv(local_user(),$r[0]['name']);
122 info( t('Group removed.') . EOL);
124 notice( t('Unable to remove group.') . EOL);
127 goaway(App::get_baseurl() . '/group');
131 if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
132 check_form_security_token_ForbiddenOnErr('group_member_change', 't');
134 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
138 if (dbm::is_result($r))
139 $change = intval($a->argv[2]);
142 if (($a->argc > 1) && (intval($a->argv[1]))) {
144 require_once('include/acl_selectors.php');
145 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
149 if (! dbm::is_result($r)) {
150 notice( t('Group not found.') . EOL );
151 goaway(App::get_baseurl() . '/contacts');
154 $members = group_get_members($group['id']);
155 $preselected = array();
156 if(count($members)) {
157 foreach($members as $member)
158 $preselected[] = $member['id'];
162 if(in_array($change,$preselected)) {
163 group_rmv_member(local_user(),$group['name'],$change);
166 group_add_member(local_user(),$group['name'],$change);
169 $members = group_get_members($group['id']);
170 $preselected = array();
171 if(count($members)) {
172 foreach($members as $member)
173 $preselected[] = $member['id'];
178 $drop_tpl = get_markup_template('group_drop.tpl');
179 $drop_txt = replace_macros($drop_tpl, array(
180 '$id' => $group['id'],
181 '$delete' => t('Delete'),
182 '$form_security_token' => get_form_security_token("group_drop"),
186 $context = $context + array(
187 '$title' => t('Group Editor'),
188 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
189 '$gid' => $group['id'],
190 '$drop' => $drop_txt,
191 '$form_security_token' => get_form_security_token('group_edit'),
199 $groupeditor = array(
200 'label_members' => t('Members'),
201 'members' => array(),
202 'label_contacts' => t('All Contacts'),
203 'group_is_empty' => t('Group is empty'),
204 'contacts' => array(),
207 $sec_token = addslashes(get_form_security_token('group_member_change'));
208 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
209 foreach($members as $member) {
211 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
212 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
215 group_rmv_member(local_user(),$group['name'],$member['id']);
218 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC",
222 if (dbm::is_result($r)) {
223 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
224 foreach($r as $member) {
225 if(! in_array($member['id'],$preselected)) {
226 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
227 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
232 $context['$groupeditor'] = $groupeditor;
233 $context['$desc'] = t('Click on a contact to add or remove.');
236 $tpl = get_markup_template('groupeditor.tpl');
237 echo replace_macros($tpl, $context);
241 return replace_macros($tpl, $context);