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",
115 if (dbm::is_result($r))
116 $result = group_rmv(local_user(),$r[0]['name']);
118 info( t('Group removed.') . EOL);
120 notice( t('Unable to remove group.') . EOL);
122 goaway(App::get_baseurl() . '/group');
126 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
127 check_form_security_token_ForbiddenOnErr('group_member_change', 't');
129 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
133 if (dbm::is_result($r))
134 $change = intval($a->argv[2]);
137 if(($a->argc > 1) && (intval($a->argv[1]))) {
139 require_once('include/acl_selectors.php');
140 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
144 if (! dbm::is_result($r)) {
145 notice( t('Group not found.') . EOL );
146 goaway(App::get_baseurl() . '/contacts');
149 $members = group_get_members($group['id']);
150 $preselected = array();
151 if(count($members)) {
152 foreach($members as $member)
153 $preselected[] = $member['id'];
157 if(in_array($change,$preselected)) {
158 group_rmv_member(local_user(),$group['name'],$change);
161 group_add_member(local_user(),$group['name'],$change);
164 $members = group_get_members($group['id']);
165 $preselected = array();
166 if(count($members)) {
167 foreach($members as $member)
168 $preselected[] = $member['id'];
173 $drop_tpl = get_markup_template('group_drop.tpl');
174 $drop_txt = replace_macros($drop_tpl, array(
175 '$id' => $group['id'],
176 '$delete' => t('Delete'),
177 '$form_security_token' => get_form_security_token("group_drop"),
181 $context = $context + array(
182 '$title' => t('Group Editor'),
183 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
184 '$gid' => $group['id'],
185 '$drop' => $drop_txt,
186 '$form_security_token' => get_form_security_token('group_edit'),
194 $groupeditor = array(
195 'label_members' => t('Members'),
196 'members' => array(),
197 'label_contacts' => t('All Contacts'),
198 'group_is_empty' => t('Group is empty'),
199 'contacts' => array(),
202 $sec_token = addslashes(get_form_security_token('group_member_change'));
203 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
204 foreach($members as $member) {
206 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
207 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
210 group_rmv_member(local_user(),$group['name'],$member['id']);
213 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC",
217 if (dbm::is_result($r)) {
218 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
219 foreach($r as $member) {
220 if(! in_array($member['id'],$preselected)) {
221 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
222 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
227 $context['$groupeditor'] = $groupeditor;
228 $context['$desc'] = t('Click on a contact to add or remove.');
231 $tpl = get_markup_template('groupeditor.tpl');
232 echo replace_macros($tpl, $context);
236 return replace_macros($tpl, $context);