2 require_once('mod/settings.php');
4 function delegate_init(&$a) {
5 return settings_init($a);
9 function delegate_content(&$a) {
12 notice( t('Permission denied.') . EOL);
16 if($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) {
18 // delegated admins can view but not change delegation permissions
20 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
21 goaway($a->get_baseurl() . '/delegate');
26 $r = q("select `nickname` from user where uid = %d limit 1",
30 $r = q("select id from contact where uid = %d and nurl = '%s' limit 1",
32 dbesc(normalise_link($a->get_baseurl() . '/profile/' . $r[0]['nickname']))
35 q("insert into manage ( uid, mid ) values ( %d , %d ) ",
41 goaway($a->get_baseurl() . '/delegate');
44 if($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) {
46 // delegated admins can view but not change delegation permissions
48 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
49 goaway($a->get_baseurl() . '/delegate');
51 q("delete from manage where uid = %d and mid = %d limit 1",
55 goaway($a->get_baseurl() . '/delegate');
59 $full_managers = array();
61 // These people can manage this account/page with full privilege
63 $r = q("SELECT * FROM `user` WHERE `email` = '%s' AND `password` = '%s' ",
64 dbesc($a->user['email']),
65 dbesc($a->user['password'])
72 // find everybody that currently has delegated management to this account/page
74 $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ",
83 if(count($full_managers))
84 foreach($full_managers as $rr)
88 foreach($delegates as $rr)
91 // find every contact who might be a candidate for delegation
93 $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s'
94 and contact.uid = %d and contact.self = 0 and network = '%s' ",
95 dbesc(normalise_link($a->get_baseurl())),
101 notice( t('No potential page delegates located.') . EOL);
105 $nicknames = array();
109 $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
113 $potentials = array();
115 $nicks = implode(',',$nicknames);
117 // get user records for all potential page delegates who are not already delegates or managers
119 $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )");
123 if(! in_array($rr['uid'],$uids))
126 require_once("mod/settings.php");
129 $o = replace_macros(get_markup_template('delegate.tpl'),array(
130 '$header' => t('Delegate Page Management'),
131 '$base' => $a->get_baseurl(),
132 '$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.'),
133 '$head_managers' => t('Existing Page Managers'),
134 '$managers' => $full_managers,
135 '$head_delegates' => t('Existing Page Delegates'),
136 '$delegates' => $delegates,
137 '$head_potentials' => t('Potential Delegates'),
138 '$potentials' => $potentials,
139 '$remove' => t('Remove'),
141 '$none' => t('No entries.')