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 `email` = '%s' AND `password` = '%s' ",
58 dbesc($a->user['email']),
59 dbesc($a->user['password'])
66 // find everybody that currently has delegated management to this account/page
68 $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ",
77 if(count($full_managers))
78 foreach($full_managers as $rr)
82 foreach($delegates as $rr)
85 // find every contact who might be a candidate for delegation
87 $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s'
88 and contact.uid = %d and contact.self = 0 and network = '%s' ",
89 dbesc(normalise_link($a->get_baseurl())),
95 notice( t('No potential page delegates located.') . EOL);
103 $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
107 $potentials = array();
109 $nicks = implode(',',$nicknames);
111 // get user records for all potential page delegates who are not already delegates or managers
113 $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )");
117 if(! in_array($rr['uid'],$uids))
120 $o = replace_macros(get_markup_template('delegate.tpl'),array(
121 '$header' => t('Delegate Page Management'),
122 '$base' => $a->get_baseurl(),
123 '$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.'),
124 '$head_managers' => t('Existing Page Managers'),
125 '$managers' => $full_managers,
126 '$head_delegates' => t('Existing Page Delegates'),
127 '$delegates' => $delegates,
128 '$head_potentials' => t('Potential Delegates'),
129 '$potentials' => $potentials,
130 '$remove' => t('Remove'),
132 '$none' => t('No entries.')