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(get_uid(),$name);
27 notice( t('Group created.') . EOL );
28 $r = group_byname(get_uid(),$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 );
58 $members = $_POST['group_members_select'];
59 array_walk($members,'validate_members');
60 $r = q("DELETE FROM `group_member` WHERE `gid` = %d AND `uid` = %d",
66 foreach($members as $member) {
67 $r = q("INSERT INTO `group_member` ( `uid`, `gid`, `contact-id`)
68 VALUES ( %d, %d, %d )",
78 notice( t('Membership list updated.') . EOL);
79 $a->page['aside'] = group_side();
84 function group_content(&$a) {
87 notice( t('Permission denied') . EOL);
91 if(($a->argc == 2) && ($a->argv[1] == 'new')) {
92 $tpl = load_view_file('view/group_new.tpl');
93 $o .= replace_macros($tpl,array());
97 if(($a->argc == 3) && ($a->argv[1] == 'drop')) {
98 if(intval($a->argv[2])) {
99 $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
104 $result = group_rmv(get_uid(),$r[0]['name']);
106 notice( t('Group removed.') . EOL);
108 notice( t('Unable to remove group.') . EOL);
110 goaway($a->get_baseurl() . '/group');
111 return; // NOTREACHED
115 if(($a->argc == 2) && (intval($a->argv[1]))) {
116 require_once('view/acl_selectors.php');
117 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
122 notice( t('Group not found.') . EOL );
123 goaway($a->get_baseurl() . '/contacts');
126 $ret = group_get_members($group['id']);
127 $preselected = array();
130 $preselected[] = $p['id'];
133 $drop_tpl = load_view_file('view/group_drop.tpl');
134 $drop_txt = replace_macros($drop_tpl, array(
135 '$id' => $group['id'],
136 '$delete' => t('Delete')
139 $tpl = load_view_file('view/group_edit.tpl');
140 $o .= replace_macros($tpl, array(
141 '$gid' => $group['id'],
142 '$name' => $group['name'],
143 '$drop' => $drop_txt,
144 '$selector' => contact_select('group_members_select','group_members_select',$preselected,25)