3 function validate_members(&$item) {
7 function group_init(&$a) {
9 require_once('include/group.php');
10 $a->page['aside'] = group_side();
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 notice( 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 notice( t('Group name changed.') . EOL );
59 $a->page['aside'] = group_side();
64 function group_content(&$a) {
67 notice( t('Permission denied') . EOL);
71 if(($a->argc == 2) && ($a->argv[1] === 'new')) {
72 $tpl = get_markup_template('group_new.tpl');
73 $o .= replace_macros($tpl,array(
74 '$desc' => t('Create a group of contacts/friends.'),
75 '$name' => t('Group Name: '),
76 '$submit' => t('Submit')
81 if(($a->argc == 3) && ($a->argv[1] === 'drop')) {
82 if(intval($a->argv[2])) {
83 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
88 $result = group_rmv(local_user(),$r[0]['name']);
90 notice( t('Group removed.') . EOL);
92 notice( t('Unable to remove group.') . EOL);
94 goaway($a->get_baseurl() . '/group');
98 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
99 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
104 $change = intval($a->argv[2]);
107 if(($a->argc > 1) && (intval($a->argv[1]))) {
109 require_once('include/acl_selectors.php');
110 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
115 notice( t('Group not found.') . EOL );
116 goaway($a->get_baseurl() . '/contacts');
119 $members = group_get_members($group['id']);
120 $preselected = array();
121 if(count($members)) {
122 foreach($members as $member)
123 $preselected[] = $member['id'];
127 if(in_array($change,$preselected)) {
128 group_rmv_member(local_user(),$group['name'],$change);
131 group_add_member(local_user(),$group['name'],$change);
134 $members = group_get_members($group['id']);
135 $preselected = array();
136 if(count($members)) {
137 foreach($members as $member)
138 $preselected[] = $member['id'];
143 $drop_tpl = get_markup_template('group_drop.tpl');
144 $drop_txt = replace_macros($drop_tpl, array(
145 '$id' => $group['id'],
146 '$delete' => t('Delete')
149 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
151 $tpl = get_markup_template('group_edit.tpl');
152 $o .= replace_macros($tpl, array(
153 '$gid' => $group['id'],
154 '$name' => $group['name'],
155 '$drop' => $drop_txt,
156 '$desc' => t('Click on a contact to add or remove.'),
157 '$title' => t('Group Editor'),
158 '$gname' => t('Group Name: '),
159 '$submit' => t('Submit')
167 $o .= '<div id="group-update-wrapper">';
171 $o .= '<div id="group-members">';
172 $o .= '<h3>' . t('Members') . '</h3>';
173 foreach($members as $member) {
175 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
176 $o .= micropro($member,true,'mpgroup');
179 group_rmv_member(local_user(),$group['name'],$member['id']);
182 $o .= '</div><div id="group-members-end"></div>';
183 $o .= '<hr id="group-separator" />';
184 $o .= '<div id="group-all-contacts">';
186 $o .= '<h3>' . t('All Contacts') . '</h3>';
187 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
192 foreach($r as $member) {
193 if(! in_array($member['id'],$preselected)) {
194 $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
195 $o .= micropro($member,true,'mpall');
200 $o .= '</div><div id="group-all-contacts-end"></div>';