array ("post", "string", FALSE), "site_id" => array ("post", "integer", -1), "right" => array ("post", "string", FALSE), ); getFields($fields); if ($user_name === FALSE) { $msg->raise("ERROR", "piwik", _('No piwik user specified')); } else { // Add a user to a piwik website if ($site_id != -1 && $right !== FALSE) { $db->query("SELECT COUNT(*) AS ok FROM piwik_sites WHERE uid=? AND piwik_id=?;",array($cuid,$site_id)); $db->next_record(); if ($db->f('ok')!=1) { $msg->raise("ERROR", "piwik", _("You don't own this piwik website")); } else { $db->query("SELECT COUNT(*) AS ok FROM piwik_users WHERE uid=? AND login=?",array($cuid,$user_name)); $db->next_record(); if ($db->f('ok')!=1) { $msg->raise("ERROR", "piwik", _("You don't own this piwik user")); } else { $piwik_rights = array("noaccess", "view", "admin"); if (in_array($right, $piwik_rights)) { $api_data = $piwik->site_set_user_right($site_id, $user_name, $right); if ($api_data === FALSE) $msg->raise("ERROR", "piwik", $api_data->message); $msg->raise("ERROR", "piwik", $api_data->message); else $msg->raise("INFO", "piwik", _('success')); } else { $msg->raise("ERROR", "piwik", _("This right does not exist")); } } } } $user_piwik_sites = array(); $db->query("SELECT piwik_id FROM piwik_sites WHERE uid=?",array($cuid)); while ($db->next_record()) array_push($user_piwik_sites, $db->f('piwik_id')); // Weird behaviour of php: array_push products an array such as: // array_push(array(1,2,3) , 4) produces // array(0 => 1, 1 => 2, 2 => 3, 3 => 4) // So for further comparison, we need to exchange keys and values $user_piwik_sites = array_flip($user_piwik_sites); $user_piwik_users = array(); $db->query("SELECT login FROM piwik_users WHERE uid=?",arary($cuid)); while ($db->next_record()) array_push ($user_piwik_users, $db->f('login')); // Swap keys and values, see user_piwik_sites $user_piwik_users = array_flip($user_piwik_users); } ?>
msg_html_all(); $raw_sites = $piwik->get_site_list(); $piwik_sites = array(); foreach ($raw_sites AS $site) { $piwik_sites[ $site->idsite ] = array('name' => $site->name, 'url' => $site->main_url); } $raw_access = $piwik->get_site_access($user_name); $piwik_user_sites = array_intersect_ukey($piwik_sites, $user_piwik_sites, "strcmp"); $available_user_sites = $piwik_user_sites; echo '