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'], ''),
92 if(($a->argc == 3) && ($a->argv[1] === 'drop')) {
93 if(intval($a->argv[2])) {
94 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
99 $result = group_rmv(local_user(),$r[0]['name']);
101 info( t('Group removed.') . EOL);
103 notice( t('Unable to remove group.') . EOL);
105 goaway($a->get_baseurl() . '/group');
109 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
110 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
115 $change = intval($a->argv[2]);
118 if(($a->argc > 1) && (intval($a->argv[1]))) {
120 require_once('include/acl_selectors.php');
121 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
126 notice( t('Group not found.') . EOL );
127 goaway($a->get_baseurl() . '/contacts');
130 $members = group_get_members($group['id']);
131 $preselected = array();
132 if(count($members)) {
133 foreach($members as $member)
134 $preselected[] = $member['id'];
138 if(in_array($change,$preselected)) {
139 group_rmv_member(local_user(),$group['name'],$change);
142 group_add_member(local_user(),$group['name'],$change);
145 $members = group_get_members($group['id']);
146 $preselected = array();
147 if(count($members)) {
148 foreach($members as $member)
149 $preselected[] = $member['id'];
154 $drop_tpl = get_markup_template('group_drop.tpl');
155 $drop_txt = replace_macros($drop_tpl, array(
156 '$id' => $group['id'],
157 '$delete' => t('Delete')
160 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
163 $context = $context + array(
164 '$title' => t('Group Editor'),
165 '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
166 '$gid' => $group['id'],
167 '$drop' => $drop_txt,
175 $groupeditor = array(
176 'label_members' => t('Members'),
177 'members' => array(),
178 'label_contacts' => t('All Contacts'),
179 'contacts' => arraY(),
183 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
184 foreach($members as $member) {
186 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
187 $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
190 group_rmv_member(local_user(),$group['name'],$member['id']);
193 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
198 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
199 foreach($r as $member) {
200 if(! in_array($member['id'],$preselected)) {
201 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
202 $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
207 $context['$groupeditor'] = $groupeditor;
208 $context['$desc'] = t('Click on a contact to add or remove.');
211 $tpl = get_markup_template('groupeditor.tpl');
212 echo replace_macros($tpl, $context);
216 return replace_macros($tpl, $context);