array ("request", "integer", -1), // alternc ID of the piwik site
"right" => array ("request", "array", FALSE), // array of rights associated foreach user of $site_id
);
getFields($fields);
/* Get once alternc users and sites */
$piwik_alternc_users = $piwik->get_alternc_users();
$piwik_alternc_sites = $piwik->get_alternc_sites();
/* Does current user still has quota ? */
if ($quota->cancreate("piwik")) {
$quotapiwik=$quota->getquota('piwik');
/* If quota are still available, display form to let user add a new site */
if ($quotapiwik['t']>0) {
?>
msg_html_all(true, true);
?>
0
} else {
$msg->raise("INFO", "piwik", _("You cannot add any new Piwik sites, your quota is over."));
} // cancreate piwik
/* In that part, we'll manage the rights associated to a selected piwik site. */
/* The output is the following: */
/* [ site [v]] */
/* - user1 no access () view () admin () */
/* - user2 no access () view () admin () */
/* [ submit ] */
?>
site_list();
$infos_urls = $piwik->get_users_url_infos();
/* Form was submitted, need to deal with work to do. */
if ($right !== FALSE) {
// Should this stay here, or in the API?
if (!in_array($site_id, $piwik_alternc_sites))
$msg->raise("ERROR", "piwik", _("You don't own this piwik site!"));
else {
foreach ($sitelist as $site) {
if ($site->id == $site_id)
$domain = $site->name;
}
/* Foreach row of right, extract user, and selected credential */
foreach ($right AS $user => $cred) {
/* Ensures that the user is legitimate for that user */
/* If not, we just break the loop, and set error message */
if (!in_array($user, $piwik_alternc_users)) {
$msg->raise("ERROR", "piwik", _('You dont own user'), $user);
break;
}
foreach ($infos_urls[$site_id] as $v) {
if ($v['login'] == $user && $v['cred'] != $cred) {
/* Ok, current user has right to manage this piwik user. Update rights. */
if (!$piwik->site_set_user_right($site_id, $user, $cred)) {
break;
} else {
$msg->raise("INFO", "piwik", _("Account '%s' has been given '%s' rights on '%s'"), array($user, $cred, $domain));
}
}
}
}
$infos_urls = $piwik->get_users_url_infos();
}
}
echo $msg->msg_html_all();
/* If user didn't add a website, just do nothing but display there's no site */
if (empty($sitelist)){
__("No existing Piwik websites");
} else {
/* Otherwize, display the html form, [ sitename, url, javascript code ] */
?>
Javascript Code
Interface
id."' id='list_users_".$site->id."' onChange='change_url(".$site->id.", this);'>";
foreach ($infos_urls[$site->id] as $v) {
if ($v['cred'] != 'noaccess') {
$list_users .= "";
if ($no_user)
$first_url = $piwik->url()."?module=Login&action=logme&login=".$v['login']."&idSite=".$site->id."&password=".$v['password'];
$no_user=false;
}
}
$list_users .= "";
?>