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 $name = notags(trim($_POST['groupname']));
25 $r = group_add(local_user(),$name);
27 info( t('Group created.') . EOL );
28 $r = group_byname(local_user(),$name);
30 goaway($a->get_baseurl() . '/group/' . $r);
33 notice( t('Could not create group.') . EOL );
34 goaway($a->get_baseurl() . '/group');
37 if(($a->argc == 2) && (intval($a->argv[1]))) {
38 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
43 notice( t('Group not found.') . EOL );
44 goaway($a->get_baseurl() . '/contacts');
48 $groupname = notags(trim($_POST['groupname']));
49 if((strlen($groupname)) && ($groupname != $group['name'])) {
50 $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
56 info( t('Group name changed.') . EOL );
59 $a->page['aside'] = group_side();
64 function group_content(&$a) {
67 notice( t('Permission denied') . EOL);
71 // Switch to text mode interface if we have more than 'n' contacts or group members
73 $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
74 if($switchtotext === false)
75 $switchtotext = get_config('system','groupedit_image_limit');
76 if($switchtotext === false)
79 $tpl = get_markup_template('group_edit.tpl');
80 $context = array('$submit' => t('Submit'));
82 if(($a->argc == 2) && ($a->argv[1] === 'new')) {
84 return replace_macros($tpl, $context + array(
85 '$title' => t('Create a group of contacts/friends.'),
86 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
93 if(($a->argc == 3) && ($a->argv[1] === 'drop')) {
94 if(intval($a->argv[2])) {
95 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
100 $result = group_rmv(local_user(),$r[0]['name']);
102 info( t('Group removed.') . EOL);
104 notice( t('Unable to remove group.') . EOL);
106 goaway($a->get_baseurl() . '/group');
110 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
111 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
116 $change = intval($a->argv[2]);
119 if(($a->argc > 1) && (intval($a->argv[1]))) {
121 require_once('include/acl_selectors.php');
122 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
127 notice( t('Group not found.') . EOL );
128 goaway($a->get_baseurl() . '/contacts');
131 $members = group_get_members($group['id']);
132 $preselected = array();
133 if(count($members)) {
134 foreach($members as $member)
135 $preselected[] = $member['id'];
139 if(in_array($change,$preselected)) {
140 group_rmv_member(local_user(),$group['name'],$change);
143 group_add_member(local_user(),$group['name'],$change);
146 $members = group_get_members($group['id']);
147 $preselected = array();
148 if(count($members)) {
149 foreach($members as $member)
150 $preselected[] = $member['id'];
155 $drop_tpl = get_markup_template('group_drop.tpl');
156 $drop_txt = replace_macros($drop_tpl, array(
157 '$id' => $group['id'],
158 '$delete' => t('Delete')
161 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
164 $context = $context + array(
165 '$title' => t('Group Editor'),
166 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
167 '$gid' => $group['id'],
168 '$drop' => $drop_txt,
176 $groupeditor = array(
177 'label_members' => t('Members'),
178 'members' => array(),
179 'label_contacts' => t('All Contacts'),
180 'contacts' => arraY(),
184 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
185 foreach($members as $member) {
187 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
188 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
191 group_rmv_member(local_user(),$group['name'],$member['id']);
194 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
199 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
200 foreach($r as $member) {
201 if(! in_array($member['id'],$preselected)) {
202 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
203 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
208 $context['$groupeditor'] = $groupeditor;
209 $context['$desc'] = t('Click on a contact to add or remove.');
212 $tpl = get_markup_template('groupeditor.tpl');
213 echo replace_macros($tpl, $context);
217 return replace_macros($tpl, $context);