예제 #1
0
 public function onPlatformInitialized()
 {
     $lastSeenTimeLogger = new LastSeenTimeLogger();
     $lastSeenTimeLogger->logCurrentUserLastSeenTime();
 }
예제 #2
0
 /**
  * The "Manage Users and Permissions" Admin UI screen
  */
 function index()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = new View('@UsersManager/index');
     $IdSitesAdmin = APISitesManager::getInstance()->getSitesIdWithAdminAccess();
     $idSiteSelected = 1;
     if (count($IdSitesAdmin) > 0) {
         $defaultWebsiteId = $IdSitesAdmin[0];
         $idSiteSelected = Common::getRequestVar('idSite', $defaultWebsiteId);
     }
     if ($idSiteSelected === 'all') {
         $usersAccessByWebsite = array();
         $defaultReportSiteName = $this->translator->translate('UsersManager_ApplyToAllWebsites');
     } else {
         $defaultReportSiteName = Site::getNameFor($idSiteSelected);
         try {
             $usersAccessByWebsite = APIUsersManager::getInstance()->getUsersAccessFromSite($idSiteSelected);
         } catch (NoAccessException $e) {
             return $this->noAdminAccessToWebsite($idSiteSelected, $defaultReportSiteName, $e->getMessage());
         }
     }
     // we dont want to display the user currently logged so that the user can't change his settings from admin to view...
     $currentlyLogged = Piwik::getCurrentUserLogin();
     $usersLogin = APIUsersManager::getInstance()->getUsersLogin();
     foreach ($usersLogin as $login) {
         if (!isset($usersAccessByWebsite[$login])) {
             $usersAccessByWebsite[$login] = 'noaccess';
         }
     }
     unset($usersAccessByWebsite[$currentlyLogged]);
     // $usersAccessByWebsite is not supposed to contain unexistant logins, but it does when upgrading from some old Piwik version
     foreach ($usersAccessByWebsite as $login => $access) {
         if (!in_array($login, $usersLogin)) {
             unset($usersAccessByWebsite[$login]);
             continue;
         }
     }
     ksort($usersAccessByWebsite);
     $users = array();
     $superUsers = array();
     $usersAliasByLogin = array();
     $formatter = new Formatter();
     if (Piwik::isUserHasSomeAdminAccess()) {
         $view->showLastSeen = true;
         $users = APIUsersManager::getInstance()->getUsers();
         foreach ($users as $index => $user) {
             $usersAliasByLogin[$user['login']] = $user['alias'];
             $lastSeen = LastSeenTimeLogger::getLastSeenTimeForUser($user['login']);
             $users[$index]['last_seen'] = $lastSeen == 0 ? false : $formatter->getPrettyTimeFromSeconds(time() - $lastSeen);
         }
         if (Piwik::hasUserSuperUserAccess()) {
             foreach ($users as $user) {
                 if ($user['superuser_access']) {
                     $superUsers[] = $user['login'];
                 }
             }
         }
     }
     $view->anonymousHasViewAccess = $this->hasAnonymousUserViewAccess($usersAccessByWebsite);
     $view->idSiteSelected = $idSiteSelected;
     $view->defaultReportSiteName = $defaultReportSiteName;
     $view->users = $users;
     $view->superUserLogins = $superUsers;
     $view->usersAliasByLogin = $usersAliasByLogin;
     $view->usersCount = count($users) - 1;
     $view->usersAccessByWebsite = $usersAccessByWebsite;
     $websites = APISitesManager::getInstance()->getSitesWithAdminAccess();
     uasort($websites, array('Piwik\\Plugins\\UsersManager\\Controller', 'orderByName'));
     $view->websites = $websites;
     $this->setBasicVariablesView($view);
     return $view->render();
 }