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);
36 notice( t('Could not create group.') . EOL );
38 goaway(App::get_baseurl() . '/group');
42 if (($a->argc == 2) && (intval($a->argv[1]))) {
43 check_form_security_token_redirectOnErr('/group', 'group_edit');
45 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
49 if (! dbm::is_result($r)) {
50 notice( t('Group not found.') . EOL );
51 goaway(App::get_baseurl() . '/contacts');
55 $groupname = notags(trim($_POST['groupname']));
56 if ((strlen($groupname)) && ($groupname != $group['name'])) {
57 $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d",
64 info( t('Group name changed.') . EOL );
68 $a->page['aside'] = group_side();
73 function group_content(App &$a) {
77 notice( t('Permission denied') . EOL);
81 // Switch to text mode interface if we have more than 'n' contacts or group members
83 $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
84 if($switchtotext === false)
85 $switchtotext = get_config('system','groupedit_image_limit');
86 if($switchtotext === false)
89 $tpl = get_markup_template('group_edit.tpl');
92 '$submit' => t('Save Group'),
95 if(($a->argc == 2) && ($a->argv[1] === 'new')) {
97 return replace_macros($tpl, $context + array(
98 '$title' => t('Create a group of contacts/friends.'),
99 '$gname' => array('groupname',t('Group Name: '), '', ''),
101 '$form_security_token' => get_form_security_token("group_edit"),
107 if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
108 check_form_security_token_redirectOnErr('/group', 'group_drop', 't');
110 if (intval($a->argv[2])) {
111 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
118 if (dbm::is_result($r)) {
119 $result = group_rmv(local_user(),$r[0]['name']);
123 info( t('Group removed.') . EOL);
125 notice( t('Unable to remove group.') . EOL);
128 goaway(App::get_baseurl() . '/group');
132 if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
133 check_form_security_token_ForbiddenOnErr('group_member_change', 't');
135 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
139 if (dbm::is_result($r))
140 $change = intval($a->argv[2]);
143 if (($a->argc > 1) && (intval($a->argv[1]))) {
145 require_once('include/acl_selectors.php');
146 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
150 if (! dbm::is_result($r)) {
151 notice( t('Group not found.') . EOL );
152 goaway(App::get_baseurl() . '/contacts');
155 $members = group_get_members($group['id']);
156 $preselected = array();
157 if(count($members)) {
158 foreach($members as $member)
159 $preselected[] = $member['id'];
163 if(in_array($change,$preselected)) {
164 group_rmv_member(local_user(),$group['name'],$change);
167 group_add_member(local_user(),$group['name'],$change);
170 $members = group_get_members($group['id']);
171 $preselected = array();
172 if(count($members)) {
173 foreach($members as $member)
174 $preselected[] = $member['id'];
179 $drop_tpl = get_markup_template('group_drop.tpl');
180 $drop_txt = replace_macros($drop_tpl, array(
181 '$id' => $group['id'],
182 '$delete' => t('Delete'),
183 '$form_security_token' => get_form_security_token("group_drop"),
187 $context = $context + array(
188 '$title' => t('Group Editor'),
189 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
190 '$gid' => $group['id'],
191 '$drop' => $drop_txt,
192 '$form_security_token' => get_form_security_token('group_edit'),
200 $groupeditor = array(
201 'label_members' => t('Members'),
202 'members' => array(),
203 'label_contacts' => t('All Contacts'),
204 'group_is_empty' => t('Group is empty'),
205 'contacts' => array(),
208 $sec_token = addslashes(get_form_security_token('group_member_change'));
209 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
210 foreach($members as $member) {
212 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
213 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
216 group_rmv_member(local_user(),$group['name'],$member['id']);
219 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC",
223 if (dbm::is_result($r)) {
224 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
225 foreach($r as $member) {
226 if(! in_array($member['id'],$preselected)) {
227 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
228 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
233 $context['$groupeditor'] = $groupeditor;
234 $context['$desc'] = t('Click on a contact to add or remove.');
237 $tpl = get_markup_template('groupeditor.tpl');
238 echo replace_macros($tpl, $context);
242 return replace_macros($tpl, $context);