3 function delegate_content(&$a) {
6 notice( t('Permission denied.') . EOL);
10 if($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) {
12 // delegated admins can view but not change delegation permissions
14 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
15 goaway($a->get_baseurl() . '/delegate');
20 $r = q("select `nickname` from user where uid = %d limit 1",
24 $r = q("select id from contact where uid = %d and nurl = '%s' limit 1",
26 dbesc(normalise_link($a->get_baseurl() . '/profile/' . $r[0]['nickname']))
29 q("insert into manage ( uid, mid ) values ( %d , %d ) ",
35 goaway($a->get_baseurl() . '/delegate');
38 if($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) {
40 // delegated admins can view but not change delegation permissions
42 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
43 goaway($a->get_baseurl() . '/delegate');
45 q("delete from manage where uid = %d and mid = %d limit 1",
49 goaway($a->get_baseurl() . '/delegate');
53 $full_managers = array();
55 // These people can manage this account/page with full privilege
57 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
59 dbesc($a->user['email']),
60 dbesc($a->user['password'])
67 // find everybody that currently has delegated management to this account/page
69 $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ",
78 if(count($full_managers))
79 foreach($full_managers as $rr)
83 foreach($delegates as $rr)
86 // find every contact who might be a candidate for delegation
88 $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s'
89 and contact.uid = %d and contact.self = 0 and network = '%s' ",
90 dbesc($a->get_baseurl()),
96 notice( t('No potential page delegates located.') . EOL);
100 $nicknames = array();
104 $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
108 $potentials = array();
110 $nicks = implode(',',$nicknames);
112 // get user records for all potential page delegates who are not already delegates or managers
114 $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )");
118 if(! in_array($rr['uid'],$uids))
121 $o = replace_macros(get_markup_template('delegate.tpl'),array(
122 '$header' => t('Delegate Page Management'),
123 '$base' => $a->get_baseurl(),
124 '$desc' => t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
125 '$head_managers' => t('Existing Page Managers'),
126 '$managers' => $full_managers,
127 '$head_delegates' => t('Existing Page Delegates'),
128 '$delegates' => $delegates,
129 '$head_potentials' => t('Potential Delegates'),
130 '$potentials' => $potentials,
131 '$remove' => t('Remove'),
133 '$none' => t('No entries.')