3 function validate_members(&$item) {
7 function group_init(&$a) {
8 require_once('include/group.php');
9 $a->page['aside'] = group_side();
15 function group_post(&$a) {
18 notice( t('Permission denied.') . EOL);
22 if(($a->argc == 2) && ($a->argv[1] == 'new')) {
23 $name = notags(trim($_POST['groupname']));
24 $r = group_add($_SESSION['uid'],$name);
26 notice( t('Group created.') . EOL );
27 $r = group_byname($_SESSION['uid'],$name);
29 goaway($a->get_baseurl() . '/group/' . $r);
32 notice( t('Could not create group.') . EOL );
33 goaway($a->get_baseurl() . '/group');
36 if(($a->argc == 2) && (intval($a->argv[1]))) {
37 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
39 intval($_SESSION['uid'])
42 notice( t('Group not found.') . EOL );
43 goaway($a->get_baseurl() . '/contacts');
46 $groupname = notags(trim($_POST['groupname']));
47 if((strlen($groupname)) && ($groupname != $group['name'])) {
48 $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
50 intval($_SESSION['uid']),
54 notice( t('Group name changed.') . EOL );
56 $members = $_POST['group_members_select'];
57 array_walk($members,'validate_members');
58 $r = q("DELETE FROM `group_member` WHERE `gid` = %d AND `uid` = %d",
60 intval($_SESSION['uid'])
64 foreach($members as $member) {
65 $r = q("INSERT INTO `group_member` ( `uid`, `gid`, `contact-id`)
66 VALUES ( %d, %d, %d )",
67 intval($_SESSION['uid']),
76 notice( t('Membership list updated.') . EOL);
77 $a->page['aside'] = group_side();
82 function group_content(&$a) {
85 notice( t('Permission denied') . EOL);
89 if(($a->argc == 2) && ($a->argv[1] == 'new')) {
90 $tpl = file_get_contents('view/group_new.tpl');
91 $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",
101 intval($_SESSION['uid'])
104 $result = group_rmv($_SESSION['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",
119 intval($_SESSION['uid'])
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 = file_get_contents('view/group_drop.tpl');
134 $drop_txt = replace_macros($drop_tpl, array(
135 '$id' => $group['id'],
136 '$delete' => t('Delete')
139 $tpl = file_get_contents('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)