From cc9a1d3a71ac2952666a3ab58b337de99ae7fccc Mon Sep 17 00:00:00 2001 From: mattpiwik <matthieu.aubry@gmail.com> Date: Thu, 1 Apr 2010 21:08:24 +0000 Subject: [PATCH] * Added General settings page to: enable browser archiving, define today's archive time to live (fixes #1149) * added User settings page, that all logged in users can access to edit: Alias, email, default report to load, default date. Implemented settings in the _option table (rather than adding new fields to the table). Fixes #401 refs #526 * the super user can edit settings for the anonymous user and force the anonymous to the login screen or a specific website * added order feature in admin menu + colored current menu + hiding menu entries that are not visible to the logged in user anyway * improved styles of admin forms git-svn-id: http://dev.piwik.org/svn/trunk@2036 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- config/global.ini.php | 51 +++--- core/ArchiveProcessing.php | 62 +++++-- core/Common.php | 18 +- core/Controller.php | 58 ++++-- core/Piwik.php | 14 +- core/PluginsFunctions/AdminMenu.php | 50 ++++-- core/Tracker/Visit.php | 2 +- core/View.php | 2 +- lang/en.php | 31 +++- plugins/CoreAdminHome/Controller.php | 49 ++--- plugins/CoreAdminHome/CoreAdminHome.php | 9 + .../templates/generalSettings.js | 30 ++++ .../templates/generalSettings.tpl | 48 +++++ plugins/CoreAdminHome/templates/index.tpl | 16 -- plugins/CoreAdminHome/templates/menu.css | 2 +- plugins/CoreAdminHome/templates/menu.tpl | 16 +- plugins/CoreAdminHome/templates/styles.css | 43 ++++- plugins/CoreHome/Controller.php | 19 +- plugins/CoreHome/templates/menu.css | 5 +- plugins/CoreHome/templates/top_bar.tpl | 2 +- plugins/CorePluginsAdmin/CorePluginsAdmin.php | 5 +- plugins/DBStats/Controller.php | 1 + plugins/DBStats/DBStats.php | 5 +- plugins/Installation/templates/structure.tpl | 6 +- plugins/LanguagesManager/LanguagesManager.php | 2 +- plugins/Login/Form.php | 2 +- plugins/Login/ResetPasswordForm.php | 2 +- plugins/Login/templates/login.css | 2 - plugins/Login/templates/login.tpl | 2 +- plugins/MultiSites/templates/index.tpl | 5 +- plugins/SecurityInfo/SecurityInfo.php | 8 +- plugins/SitesManager/SitesManager.php | 5 +- .../SitesManager/templates/SitesManager.tpl | 15 +- plugins/UsersManager/API.php | 37 +++- plugins/UsersManager/Controller.php | 169 ++++++++++++++++++ plugins/UsersManager/UsersManager.php | 9 +- .../UsersManager/templates/UsersManager.tpl | 2 +- .../UsersManager/templates/userSettings.js | 56 ++++++ .../UsersManager/templates/userSettings.tpl | 117 ++++++++++++ tests/core/ArchiveProcessing.test.php | 8 +- themes/default/common.css | 4 + themes/default/simple_structure.css | 2 - 42 files changed, 799 insertions(+), 192 deletions(-) create mode 100644 plugins/CoreAdminHome/templates/generalSettings.js create mode 100644 plugins/CoreAdminHome/templates/generalSettings.tpl delete mode 100644 plugins/CoreAdminHome/templates/index.tpl create mode 100644 plugins/UsersManager/templates/userSettings.js create mode 100644 plugins/UsersManager/templates/userSettings.tpl diff --git a/config/global.ini.php b/config/global.ini.php index 8f3ba91f8f..06801cf81a 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -2,10 +2,10 @@ ; If you want to change some of these default values, the best practise is to override ; them in your configuration file in config/config.ini.php. If you directly edit this file, ; you risk losing your changes when you upgrade Piwik. -; For example if you want to override enable_browser_archiving_triggering, +; For example if you want to override action_title_category_delimiter, ; edit config/config.ini.php and add the following: ; [General] -; enable_browser_archiving_triggering = 0 +; action_title_category_delimiter = "-" [superuser] login = root @@ -48,29 +48,6 @@ enable_sql_profiler = 0 track_visits_inside_piwik_ui = 0 [General] -; Time in seconds after which an archive will be computed again. -; This setting is used only for today's statistics. -; Defaults to 10 seconds so that by default, Piwik provides real time reporting. -time_before_today_archive_considered_outdated = 10 - -; When loading piwik interface, we redirect the user to 'yesterday' statistics by default -; Possible values: yesterday, today, or any YYYY-MM-DD -default_day = yesterday -; Possible values: day, week, month, year -default_period = day - -; When loading piwik interface, Piwik will load by default the CoreHome module -; You can override the setting to force the user to login. -; This is useful when you have some websites view "anonymous" access but you want to -; force users to login instead of viewing the first anonymous website available -default_module_login = 0 - -; When loading the piwik interface in the browser (as opposed to from the PHP-CLI client) -; should we launch the archiving process if the archives have not yet been processed? -; You want to set it to 0 when triggering the archiving is done through a crontab, -; so that your users do not trigger archiving in their browser when this is not expected -enable_browser_archiving_triggering = 1 - ; character used to automatically create categories in the Actions > Pages, Outlinks and Downloads reports ; for example a URL like "example.com/blog/development/first-post" will create ; the page first-post in the subcategory development which belongs to the blog category @@ -87,10 +64,6 @@ action_default_name = index action_default_name_when_not_defined = "page title not defined" action_default_url_when_not_defined = "page url not defined" -; currency used by default when reporting money in Piwik -; the trailing space is required for php 5.2.x vs 5.3 compatibility -default_currency = "$ " - ; if you want all your users to use Piwik in only one language, disable the LanguagesManager ; plugin, and set this default_language (users won't see the language drop down) default_language = en @@ -106,6 +79,21 @@ API_datatable_default_limit = 50 ; as it slows down the loading of the Piwik UI by setting this value to 0 show_website_selector_in_user_interface = 1 +; This setting is overriden in the UI, under "User Settings". +; The date and period loaded by Piwik uses the defaults below. Possible values: yesterday, today. +default_day = yesterday +; Possible values: day, week, month, year. +default_period = day + +; This setting is overriden in the UI, under "General Settings". This is the default value used if the setting hasn't been overriden via the UI. +; Time in seconds after which an archive will be computed again. This setting is used only for today's statistics. +; Defaults to 10 seconds so that by default, Piwik provides real time reporting. +time_before_today_archive_considered_outdated = 10 + +; This setting is overriden in the UI, under "General Settings". The default value is to allow browsers +; to trigger the Piwik archiving process. +enable_browser_archiving_triggering = 1 + ; PHP minimum required version (minimum requirement known to date = ->newInstanceArgs) minimum_php_version = 5.1.3 @@ -213,9 +201,12 @@ campaign_keyword_var_name = piwik_kwd ; maximum length of a Page Title or a Page URL recorded in the log_action.name table page_maximum_length = 1024; -; number of octets in IP address to mask, in order to anonymize a visitor's IP address; if the AnonymizeIP plugin is deactivated, this value is ignored; for IPv4 addresses, valid values are 0..4 +; number of octets in IP address to mask, in order to anonymize a visitor's IP address +; if the AnonymizeIP plugin is deactivated, this value is ignored +; for IPv4 addresses, valid values are 0..4 ip_address_mask_length = 1 + [log] ;possible values for log: screen, database, file ; normal messages diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php index d236fafd83..949affe791 100644 --- a/core/ArchiveProcessing.php +++ b/core/ArchiveProcessing.php @@ -221,6 +221,48 @@ abstract class Piwik_ArchiveProcessing return $process; } + const OPTION_TODAY_ARCHIVE_TTL = 'todayArchiveTimeToLive'; + const OPTION_BROWSER_TRIGGER_ARCHIVING = 'enableBrowserTriggerArchiving'; + + static public function setTodayArchiveTimeToLive($timeToLiveSeconds) + { + $timeToLiveSeconds = (int)$timeToLiveSeconds; + if($timeToLiveSeconds <= 0) + { + throw new Exception('Today archive time to live must be a number of seconds greater than zero'); + } + Piwik_SetOption(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoload = true); + } + + static public function getTodayArchiveTimeToLive() + { + $timeToLive = Piwik_GetOption(self::OPTION_TODAY_ARCHIVE_TTL); + if($timeToLive !== false) + { + return $timeToLive; + } + return Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated; + } + + static public function setBrowserTriggerArchiving($enabled) + { + if(!is_bool($enabled)) + { + throw new Exception('Browser trigger archiving must be set to true or false.'); + } + Piwik_SetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int)$enabled, $autoload = true); + + } + static public function isBrowserTriggerArchivingEnabled() + { + $browserArchivingEnabled = Piwik_GetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING); + if($browserArchivingEnabled !== false) + { + return (bool)$browserArchivingEnabled; + } + return (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering; + } + public function getIdArchive() { return $this->idArchive; @@ -280,8 +322,8 @@ abstract class Piwik_ArchiveProcessing && $this->startTimestampUTC <= time() && $this->endTimestampUTC > time() ) { - $minDatetimeArchiveProcessedUTC = time() - Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated; - $browserArchivingEnabled = Zend_Registry::get('config')->General->enable_browser_archiving_triggering; + $minDatetimeArchiveProcessedUTC = time() - self::getTodayArchiveTimeToLive(); + $browserArchivingEnabled = self::isBrowserTriggerArchivingEnabled(); // see #1150; if new archives are not triggered from the browser, // we still want to try and return the latest archive available for today (rather than return nothing) if(!$browserArchivingEnabled) @@ -636,19 +678,11 @@ abstract class Piwik_ArchiveProcessing */ protected function isArchivingDisabled() { - static $archivingIsDisabled = null; - if(is_null($archivingIsDisabled)) + if(!self::isBrowserTriggerArchivingEnabled() + && !Piwik_Common::isPhpCliMode()) { - $archivingIsDisabled = false; - $enableBrowserArchivingTriggering = (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering; - if($enableBrowserArchivingTriggering == false) - { - if( !Piwik_Common::isPhpCliMode()) - { - $archivingIsDisabled = true; - } - } + return true; } - return $archivingIsDisabled; + return false; } } diff --git a/core/Common.php b/core/Common.php index 1ee6e8844b..e6c50f31f5 100644 --- a/core/Common.php +++ b/core/Common.php @@ -105,23 +105,17 @@ class Piwik_Common } catch (Exception $e) { Piwik::createDatabaseObject(); } - $isSuperUser = Piwik::isUserIsSuperUser(); - Piwik::setUserIsSuperUser(); - $pluginsManager = Piwik_PluginsManager::getInstance(); - $pluginsManager->setPluginsToLoad( Zend_Registry::get('config')->Plugins->Plugins->toArray() ); + $pluginsManager = Piwik_PluginsManager::getInstance(); + $pluginsManager->setPluginsToLoad( Zend_Registry::get('config')->Plugins->Plugins->toArray() ); } + $isSuperUser = Piwik::isUserIsSuperUser(); + Piwik::setUserIsSuperUser(); $content = array(); Piwik_PostEvent('Common.fetchWebsiteAttributes', $content, $idSite); - if(!empty($GLOBALS['PIWIK_TRACKER_MODE'])) - { - // we remove the temporary Super user privilege - if(!$isSuperUser) - { - Piwik::setUserIsSuperUser($isSuperUser); - } - } + // we remove the temporary Super user privilege + Piwik::setUserIsSuperUser($isSuperUser); // if nothing is returned from the plugins, we don't save the content // this is not expected: all websites are expected to have at least one URL diff --git a/core/Controller.php b/core/Controller.php index f0a73eeaac..fda80afbf8 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -256,6 +256,7 @@ abstract class Piwik_Controller $view->maxDateMonth = $maxDate->toString('m'); $view->maxDateDay = $maxDate->toString('d'); + $view->currentAdminMenuName = Piwik_GetCurrentAdminMenuName(); $view->debugTrackVisitsInsidePiwikUI = Zend_Registry::get('config')->Debug->track_visits_inside_piwik_ui; $view->isSuperUser = Zend_Registry::get('access')->isSuperUser(); @@ -293,12 +294,21 @@ abstract class Piwik_Controller $view->periodsNames = $periodNames; } - function redirectToIndex($moduleToRedirect, $actionToRedirect) + function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null) { - $websiteId = $this->getDefaultWebsiteId(); - $defaultDate = $this->getDefaultDate(); - $defaultPeriod = $this->getDefaultPeriod(); - + if(is_null($websiteId)) + { + $websiteId = $this->getDefaultWebsiteId(); + } + if(is_null($defaultDate)) + { + $defaultDate = $this->getDefaultDate(); + } + if(is_null($defaultPeriod)) + { + $defaultPeriod = $this->getDefaultPeriod(); + } + if($websiteId) { header("Location:index.php?module=".$moduleToRedirect ."&action=".$actionToRedirect @@ -323,7 +333,7 @@ abstract class Piwik_Controller Piwik_ExitWithMessage($errorMessage, false, true); } - Piwik_FrontController::dispatch('Login', false); + Piwik_FrontController::dispatch(Piwik::getLoginPluginName(), false); exit; } @@ -335,6 +345,14 @@ abstract class Piwik_Controller protected function getDefaultWebsiteId() { $defaultWebsiteId = false; + + // User preference: default website ID to load + $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + if(is_numeric($defaultReport)) + { + $defaultWebsiteId = $defaultReport; + } + Piwik_PostEvent( 'Controller.getDefaultWebsiteId', $defaultWebsiteId ); if($defaultWebsiteId) @@ -349,23 +367,41 @@ abstract class Piwik_Controller } return false; } - + /** * Returns default date for Piwik reports * @return string today, 2010-01-01, etc. */ protected function getDefaultDate() { - return Zend_Registry::get('config')->General->default_day; + $userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE); + if($userSettingsDate === false) + { + return Zend_Registry::get('config')->General->default_day; + } + if($userSettingsDate == 'yesterday') + { + return $userSettingsDate; + } + return 'today'; } /** - * Returns default period for Piwik reports - * @return string day, week, etc. + * Returns default date for Piwik reports + * @return string today, 2010-01-01, etc. */ protected function getDefaultPeriod() { - return Zend_Registry::get('config')->General->default_period; + $userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE); + if($userSettingsDate === false) + { + return Zend_Registry::get('config')->General->default_period; + } + if(in_array($userSettingsDate, array('today','yesterday'))) + { + return 'day'; + } + return $userSettingsDate; } /** diff --git a/core/Piwik.php b/core/Piwik.php index 8fc6ce1f7e..b9411b348d 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -930,6 +930,18 @@ class Piwik } } + /** + * Returns the name of the Login plugin currently being used. + * Must be used since it is not allowed to hardcode 'Login' in URLs + * in case another Login plugin is being used. + * + * @return string + */ + static public function getLoginPluginName() + { + return Zend_Registry::get('auth')->getName(); + } + /** * Helper method user to set the current as Super User. * This should be used with great care as this gives the user all permissions. @@ -1036,7 +1048,7 @@ class Piwik static public function isUserHasSomeViewAccess() { try{ - self::checkUserHasViewAccess( $idSites ); + self::checkUserHasSomeViewAccess(); return true; } catch( Exception $e){ return false; diff --git a/core/PluginsFunctions/AdminMenu.php b/core/PluginsFunctions/AdminMenu.php index e926c77d7f..44142e9841 100644 --- a/core/PluginsFunctions/AdminMenu.php +++ b/core/PluginsFunctions/AdminMenu.php @@ -16,6 +16,7 @@ class Piwik_AdminMenu { private $adminMenu = null; + private $adminMenuOrdered = null; static private $instance = null; /** @@ -36,31 +37,37 @@ class Piwik_AdminMenu */ public function get() { - if(!is_null($this->adminMenu)) + if(!is_null($this->adminMenuOrdered)) { - return; + return $this->adminMenuOrdered; } Piwik_PostEvent('AdminMenu.add'); - - foreach($this->adminMenu as $key => &$element) + + $this->adminMenuOrdered = array(); + ksort($this->adminMenu); + foreach($this->adminMenu as $order => $menu) { - if(is_null($element)) - { - unset($this->adminMenu[$key]); - } + foreach($menu as $key => &$element) + { + if(!is_null($element)) + { + $this->adminMenuOrdered[$key] = $element; + } + } } - return $this->adminMenu; + return $this->adminMenuOrdered; } /* * */ - public function add($adminMenuName, $url) + public function add($adminMenuName, $url, $displayedForCurrentUser, $order) { - if(!isset($this->adminMenu[$adminMenuName])) + if($displayedForCurrentUser + && !isset($this->adminMenu[$adminMenuName])) { - $this->adminMenu[$adminMenuName] = $url; + $this->adminMenu[$order][$adminMenuName] = $url; } } @@ -74,15 +81,30 @@ class Piwik_AdminMenu $this->adminMenu[$adminMenuRenamed] = $save; } } +function Piwik_GetCurrentAdminMenuName() +{ + $menu = Piwik_GetAdminMenu(); + $currentModule = Piwik::getModule(); + $currentAction = Piwik::getAction(); + foreach($menu as $name => $parameters) + { + if($parameters['module'] == $currentModule + && $parameters['action'] == $currentAction) + { + return $name; + } + } + return false; +} function Piwik_GetAdminMenu() { return Piwik_AdminMenu::getInstance()->get(); } -function Piwik_AddAdminMenu( $adminMenuName, $url ) +function Piwik_AddAdminMenu( $adminMenuName, $url, $displayedForCurrentUser = true, $order = 10 ) { - return Piwik_AdminMenu::getInstance()->add($adminMenuName, $url); + return Piwik_AdminMenu::getInstance()->add($adminMenuName, $url, $displayedForCurrentUser, $order); } function Piwik_RenameAdminMenuEntry($adminMenuOriginal, $adminMenuRenamed) diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 4c10b24677..18b088ff60 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -476,7 +476,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface } } - /* custom filters can override the built-in filter above */ + /* custom filters can override the built-in filters above */ Piwik_PostEvent('Tracker.Visit.isExcluded', $excluded); /* diff --git a/core/View.php b/core/View.php index 37fbc00ca7..2ddd7671e2 100644 --- a/core/View.php +++ b/core/View.php @@ -126,7 +126,7 @@ class Piwik_View implements Piwik_iView $this->piwik_version = Piwik_Version::VERSION; $this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable(); - $this->loginModule = Zend_Registry::get('auth')->getName(); + $this->loginModule = Piwik::getLoginPluginName(); } catch(Exception $e) { // can fail, for example at installation (no plugin loaded yet) } diff --git a/lang/en.php b/lang/en.php index 1ed12a74f9..5b59c1cc10 100644 --- a/lang/en.php +++ b/lang/en.php @@ -8,7 +8,9 @@ $translations = array( 'General_HelloUser' => 'Hello, %s!', 'General_OpenSourceWebAnalytics' => 'Open Source Web Analytics', 'General_Dashboard' => 'Dashboard', + 'General_DashboardForASpecificWebsite' => 'Dashboard for a specific website', 'General_MultiSitesSummary' => 'All Websites', + 'General_AllWebsitesDashboard' => 'All Websites dashboard', 'General_API' => 'API', 'General_Widgets' => 'Widgets', 'General_Settings' => 'Settings', @@ -25,6 +27,7 @@ $translations = array( 'General_Ok' => 'Ok', 'General_Close' => 'Close', 'General_Logout' => 'Sign out', + 'General_Username' => 'Username', 'General_Done' => 'Done', 'General_Details' => 'Details', 'General_LoadingData' => 'Loading data...', @@ -42,6 +45,11 @@ $translations = array( 'General_ExportAsImage_js' => 'Export as Image', 'General_SaveImageOnYourComputer_js' => 'To save the image on your computer, right click on the image and select "Save Image As..."', 'General_Refresh' => 'Refresh the page', + 'General_Today' => 'Today', + 'General_Yesterday' => 'Yesterday', + 'General_CurrentWeek' => 'Current Week', + 'General_CurrentMonth' => 'Current Month', + 'General_CurrentYear' => 'Current Year', 'General_Visitors' => 'Visitors', 'General_ColumnNbUniqVisitors' => 'Unique visitors', 'General_ColumnNbVisits' => 'Visits', @@ -59,6 +67,14 @@ $translations = array( 'General_Save' => 'Save', 'General_ForExampleShort' => 'eg.', 'General_Website' => 'Website', + 'General_GeneralSettings' => 'General Settings', + 'General_AllowPiwikArchivingToTriggerBrowser' => 'Allow Piwik archiving to trigger when reports are viewed from the browser', + 'General_ArchivingInlineHelp' => 'For medium to high traffic websites, it is recommended to disable Piwik archiving to trigger from the browser. Instead, we recommend that you setup a cron job to process Piwik reports every hour.', + 'General_SeeTheOfficialDocumentationForMoreInformation' => 'See the %sofficial documentation%s for more information.', + 'General_ReportsForTodayWillBeProcessedAtMostEvery' => 'Reports for today will be processed at most every', + 'General_NSeconds' => '%s seconds', + 'General_SmallTrafficYouCanLeaveDefault' => 'For small traffic websites, you can leave the default %s seconds, and access all reports in real time.', + 'General_MediumToHighTrafficItIsRecommendedTo' => 'For medium to high traffic websites, we recommend to process reports for today at most every half hour (%s seconds) or every hour (%s seconds).', 'General_RequiresFlash' => 'Displaying Graphs in Piwik requires Flash', 'General_GraphHelp' => 'More information about displaying graphs in Piwik.', 'General_NoDataForGraph' => 'No data for this graph.', @@ -137,6 +153,7 @@ $translations = array( 'API_QuickDocumentation' => '<h2>API quick documentation</h2><p>If you don\'t have data for today you can first <a href=\'misc/generateVisits.php\' target=_blank>generate some data</a> using the Visits Generator script.</p><p>You can try the different formats available for every method. It is very easy to extract any data you want from Piwik!</p><p><b>For more information have a look at the <a href=\'http://dev.piwik.org/trac/wiki/API\'>official API Documentation</a> or the <a href=\'http://dev.piwik.org/trac/wiki/API/Reference\'>API Reference</a>.</b></P><h2>User authentication</h2><p>If you want to <b>request the data in your scripts, in a crontab, etc. </b> you need to add the parameter <code><u>&token_auth=%s</u></code> to the API calls URLs that require authentication.</p><p>This token_auth is as secret as your login and password, <b>do not share it!</p>', 'API_LoadedAPIs' => 'Loaded successfully %s APIs', 'CoreAdminHome_PluginDescription' => 'Administration area of Piwik.', + 'CoreAdminHome_MenuGeneralSettings' => 'General settings', 'CoreHome_PluginDescription' => 'Web Analytics Reports Structure.', 'CoreHome_NoPrivileges' => 'You are logged in as \'%s\' but it seems you don\'t have any permission set in Piwik.<br />Ask your Piwik administrator to give you \'view\' access to a website.', 'CoreHome_JavascriptDisabled' => 'JavaScript must be enabled in order for you to use Piwik in standard view.<br />However, it seems JavaScript is either disabled or not supported by your browser.<br />To use standard view, enable JavaScript by changing your browser options, then %1$stry again%2$s.<br />', @@ -462,11 +479,10 @@ $translations = array( 'Live_Referrer_URL' => 'Referrer URL', 'Login_PluginDescription' => 'Login Authentication plugin, reading the credentials from the config/config.inc.php file for the Super User, and from the Database for the other users. Can be easily replaced to introduce a new Authentication mechanism (OpenID, htaccess, custom Auth, etc.).', 'Login_LoginPasswordNotCorrect' => 'Username & Password not correct', - 'Login_Login' => 'Username', 'Login_Password' => 'Password', 'Login_PasswordRepeat' => 'Password (repeat)', 'Login_ChangePassword' => 'Change password', - 'Login_LoginOrEmail' => 'Login or E-mail', + 'Login_LoginOrEmail' => 'Username or E-mail', 'Login_LogIn' => 'Sign in', 'Login_Logout' => 'Sign out', 'Login_LostYourPassword' => 'Lost your password?', @@ -896,14 +912,23 @@ $translations = array( 'UsersManager_PrivView' => 'View', 'UsersManager_PrivAdmin' => 'Admin', 'UsersManager_ChangeAllConfirm' => 'Are you sure you want to change \'%s\' permissions on all the websites?', - 'UsersManager_Login' => 'Login', 'UsersManager_Password' => 'Password', 'UsersManager_Email' => 'Email', 'UsersManager_Alias' => 'Alias', + 'UsersManager_TheSuperUserAliasCannotBeChanged' => 'The Super User alias cannot be changed.', + 'UsersManager_ReportToLoadByDefault' => 'Report to load by default', + 'UsersManager_ReportDateToLoadByDefault' => 'Report date to load by default', + 'UsersManager_ForAnonymousUsersReportDateToLoadByDefault' => 'For anonymous users, report date to load by default', 'UsersManager_Edit' => 'Edit', 'UsersManager_AddUser' => 'Add a new user', 'UsersManager_MenuUsers' => 'Users', + 'UsersManager_MenuUserSettings' => 'User settings', + 'UsersManager_MenuAnonymousUserSettings' => 'Anonymous user settings', + 'UsersManager_NoteNoAnonymousUserAccessSettingsWontBeUsed' => 'Note: You do not have any website that the anonymous user can access, the following settings won\'t be used.', + 'UsersManager_WhenUsersAreNotLoggedInAndVisitPiwikTheyShouldAccess' => 'When users are not logged in and visit Piwik, they should access', + 'UsersManager_TheLoginScreen' => 'The login screen', 'UsersManager_DeleteConfirm_js' => 'Are you sure you want to delete the user %s?', + 'UsersManager_YourUsernameCannotBeChanged' => 'Your username cannot be changed.', 'UsersManager_ExceptionLoginExists' => 'Login \'%s\' already exists.', 'UsersManager_ExceptionEmailExists' => 'User with email \'%s\' already exists.', 'UsersManager_ExceptionInvalidLoginFormat' => 'The login must be between %1$s and %2$s characters long and contain only letters, numbers, or the characters \'_\' or \'-\' or \'.\'', diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php index 767d6ce8ca..2c63abbc7c 100644 --- a/plugins/CoreAdminHome/Controller.php +++ b/plugins/CoreAdminHome/Controller.php @@ -16,37 +16,38 @@ */ class Piwik_CoreAdminHome_Controller extends Piwik_Controller { - function getDefaultAction() + public function index() { - return 'redirectToIndex'; - } - - function redirectToIndex() - { - if(Piwik::isUserIsSuperUser()) - { - $module = 'CorePluginsAdmin'; - } - else - { - $module = 'SitesManager'; - } - header("Location:index.php?module=" . $module); + return $this->redirectToIndex('UsersManager', 'userSettings'); } - public function index() + public function generalSettings() { - Piwik::checkUserIsSuperUser(); - $view = $this->getDefaultIndexView(); + $view = Piwik_View::factory('generalSettings'); + $view->enableBrowserTriggerArchiving = Piwik_ArchiveProcessing::isBrowserTriggerArchivingEnabled(); + $view->todayArchiveTimeToLive = Piwik_ArchiveProcessing::getTodayArchiveTimeToLive(); + + $this->setGeneralVariablesView($view); + $view->menu = Piwik_GetAdminMenu(); echo $view->render(); } - protected function getDefaultIndexView() + public function setGeneralSettings() { - $view = Piwik_View::factory('index'); - $view->content = ''; - $this->setGeneralVariablesView($view); - $view->menu = Piwik_GetAdminMenu(); - return $view; + $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format')); + try { + Piwik::checkUserIsSuperUser(); + $this->checkTokenInUrl(); + $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving'); + $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive'); + + Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool)$enableBrowserTriggerArchiving); + Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive); + $toReturn = $response->getResponse(); + } catch(Exception $e ) { + $toReturn = $response->getResponseException( $e ); + } + echo $toReturn; } + } diff --git a/plugins/CoreAdminHome/CoreAdminHome.php b/plugins/CoreAdminHome/CoreAdminHome.php index 673a9c5449..1a6259ddc0 100644 --- a/plugins/CoreAdminHome/CoreAdminHome.php +++ b/plugins/CoreAdminHome/CoreAdminHome.php @@ -31,6 +31,7 @@ class Piwik_CoreAdminHome extends Piwik_Plugin { return array( 'template_css_import' => 'css', + 'AdminMenu.add' => 'addMenu' ); } @@ -38,4 +39,12 @@ class Piwik_CoreAdminHome extends Piwik_Plugin { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"plugins/CoreAdminHome/templates/menu.css\" />\n"; } + + function addMenu() + { + Piwik_AddAdminMenu('CoreAdminHome_MenuGeneralSettings', + array('module' => 'CoreAdminHome', 'action' => 'generalSettings'), + Piwik::isUserIsSuperUser(), + $order = 6); + } } diff --git a/plugins/CoreAdminHome/templates/generalSettings.js b/plugins/CoreAdminHome/templates/generalSettings.js new file mode 100644 index 0000000000..2501baa210 --- /dev/null +++ b/plugins/CoreAdminHome/templates/generalSettings.js @@ -0,0 +1,30 @@ +function getGeneralSettingsAJAX() +{ + var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoading', 'ajaxError'); + var enableBrowserTriggerArchiving = $('#enableBrowserTriggerArchiving').val(); + var todayArchiveTimeToLive = $('#todayArchiveTimeToLive').val(); + var request = ''; + request += 'module=CoreAdminHome'; + request += '&action=setGeneralSettings'; + request += '&format=json'; + request += '&enableBrowserTriggerArchiving='+enableBrowserTriggerArchiving; + request += '&todayArchiveTimeToLive='+todayArchiveTimeToLive; + request += '&token_auth=' + piwik.token_auth; + ajaxRequest.data = request; + return ajaxRequest; +} + +$(document).ready( function() { + $('#generalSettingsSubmit').click( function() { + $.ajax( getGeneralSettingsAJAX() ); + }); + + $('input').keypress( function(e) { + var key=e.keyCode || e.which; + if (key==13) { + $('#generalSettingsSubmit').click(); + } + } + ) +}); + diff --git a/plugins/CoreAdminHome/templates/generalSettings.tpl b/plugins/CoreAdminHome/templates/generalSettings.tpl new file mode 100644 index 0000000000..47eaefd4e7 --- /dev/null +++ b/plugins/CoreAdminHome/templates/generalSettings.tpl @@ -0,0 +1,48 @@ +{assign var=showSitesSelection value=false} +{assign var=showPeriodSelection value=false} +{include file="CoreAdminHome/templates/header.tpl"} +{loadJavascriptTranslations plugins='UsersManager'} +{include file="CoreAdminHome/templates/menu.tpl"} +<script type="text/javascript" src="plugins/CoreAdminHome/templates/generalSettings.js"></script> + +<h2>{'General_GeneralSettings'|translate}</h2> + +{ajaxErrorDiv id=ajaxError} +{ajaxLoadingDiv id=ajaxLoading} +<table class="adminTable adminTableNoBorder" style='width:900px'> +<tr> + <td style='width:400px'>{'General_AllowPiwikArchivingToTriggerBrowser'|translate}</td> + <td style='width:150px'> + <fieldset> + <label><input type="radio" value="0" name="enableBrowserTriggerArchiving" {if $enableBrowserTriggerArchiving==0}checked="checked"{/if}> {'General_Yes'|translate}</label><br> + <label><input type="radio" value="1" name="enableBrowserTriggerArchiving" {if $enableBrowserTriggerArchiving!=0}checked="checked"{/if}> {'General_No'|translate}</label> + </fieldset> + <td> + {capture assign=browserArchivingHelp} + {'General_ArchivingInlineHelp'|translate}<br/> + {'General_SeeTheOfficialDocumentationForMoreInformation'|translate:"<a href='misc/redirectToUrl.php?url=http://piwik.org/docs/setup-auto-archiving/' target='_blank'>":"</a>"} + {/capture} + {$browserArchivingHelp|inlineHelp} </td> + </td> +</tr> + +<tr> + <td><label for="todayArchiveTTL">{'General_ReportsForTodayWillBeProcessedAtMostEvery'|translate}</label></td> + <td> + {'General_NSeconds'|translate:"<input size='3' value='$todayArchiveTimeToLive' id='todayArchiveTimeToLive'>"} + </td> + <td width='450px'> + {capture assign=archiveTodayTTLHelp} + {'General_SmallTrafficYouCanLeaveDefault'|translate:10}<br/> + {'General_MediumToHighTrafficItIsRecommendedTo'|translate:1800:3600} + {/capture} + {$archiveTodayTTLHelp|inlineHelp} </td> + </td> +</tr> + +</table> +<input type="submit" value="{'General_Save'|translate}" id="generalSettingsSubmit" class="submit"> +<br/><br/> + + +{include file="CoreAdminHome/templates/footer.tpl"} \ No newline at end of file diff --git a/plugins/CoreAdminHome/templates/index.tpl b/plugins/CoreAdminHome/templates/index.tpl deleted file mode 100644 index fdc6e74c52..0000000000 --- a/plugins/CoreAdminHome/templates/index.tpl +++ /dev/null @@ -1,16 +0,0 @@ -{assign var=showSitesSelection value=false} -{assign var=showPeriodSelection value=false} -{include file="CoreAdminHome/templates/header.tpl"} -{include file="CoreAdminHome/templates/menu.tpl"} - -<div style="clear:both;"></div> - -<div id="content"> -{if $content}{$content}{/if} -</div> - -<div id="footer" style="border-top:1px solid gray; margin-top:20px;padding-top:10px;"> -<a href="index.php?module=CoreHome">{'General_BackToHomepage'|translate}</a> -</div> - -{include file="CoreAdminHome/templates/footer.tpl"} diff --git a/plugins/CoreAdminHome/templates/menu.css b/plugins/CoreAdminHome/templates/menu.css index 1c5b5ef3d6..8ecc659a4c 100644 --- a/plugins/CoreAdminHome/templates/menu.css +++ b/plugins/CoreAdminHome/templates/menu.css @@ -29,7 +29,7 @@ -webkit-border-radius:4px 4px 0 0; } -#tablist li a:hover { +#tablist li a:hover, #tablist li a.active { color: black; background: #defdbb; border-color: black; diff --git a/plugins/CoreAdminHome/templates/menu.tpl b/plugins/CoreAdminHome/templates/menu.tpl index 3dc4469aa5..9200e8160c 100644 --- a/plugins/CoreAdminHome/templates/menu.tpl +++ b/plugins/CoreAdminHome/templates/menu.tpl @@ -1,7 +1,9 @@ -<div id="menu"> -<ul id="tablist"> -{foreach from=$menu key=name item=url name=menu} - <li><a href='index.php{$url|@urlRewriteWithParameters}'>{$name|translate}</a></li> -{/foreach} -</ul> -</div> +{if count($menu) > 1} + <div id="menu"> + <ul id="tablist"> + {foreach from=$menu key=name item=url name=menu} + <li> <a href='index.php{$url|@urlRewriteWithParameters}' {if isset($currentAdminMenuName) && $name==$currentAdminMenuName}class='active'{/if}>{$name|translate}</a></li> + {/foreach} + </ul> + </div> +{/if} \ No newline at end of file diff --git a/plugins/CoreAdminHome/templates/styles.css b/plugins/CoreAdminHome/templates/styles.css index b2236fe076..3c2bbdda7b 100644 --- a/plugins/CoreAdminHome/templates/styles.css +++ b/plugins/CoreAdminHome/templates/styles.css @@ -1,15 +1,9 @@ -body { - font-family: Georgia, Trebuchet MS, arial, sans-serif; -} - img { vertical-align: baseline; } - textarea { font-size: 1em; } - a { color: black; } @@ -114,7 +108,19 @@ p { margin:0pt 15px; padding:0pt; } - +textarea, input, select { + background-color:#FFFFFF; + border-color:#939EA5; + -moz-border-radius:4px; + -webkit-border-radius:4px; + border-style:solid; + border-width:1px; + margin:1px; + padding:3px; +} +input[disabled] { + background-color:#F7F7F7; +} .adminTable { border-width: 1px; border-style: solid; @@ -133,8 +139,9 @@ p { border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ccc; - font-size: 11px; + font-size: 13px; vertical-align: text-top; + vertical-align:top; } .adminTable td { padding: 7px 15px 9px 10px; @@ -182,3 +189,23 @@ p { .adminTable .active { background-color: #ECF9DD; } + +.adminTable .ui-inline-help { + margin-top:0; + width:100%; +} +/* admin table, without borders */ +.adminTableNoBorder { + border:0; +} +.adminTableNoBorder td, .adminTableNoBorder th { + border:0; +} + +/* other styles */ + +.form-description { + color:#666666; + font-style:italic; + margin-left:10px; +} \ No newline at end of file diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php index 0ad3be6a33..0abc5f919c 100644 --- a/plugins/CoreHome/Controller.php +++ b/plugins/CoreHome/Controller.php @@ -23,13 +23,22 @@ class Piwik_CoreHome_Controller extends Piwik_Controller function redirectToCoreHomeIndex() { - // redirect to Login only for anonymous user - if((bool)Zend_Registry::get('config')->General->default_module_login == true - && Piwik::getCurrentUserLogin() == 'anonymous') + $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + $module = 'CoreHome'; + $action = 'index'; + + // User preference: default report to load is the All Websites dashboard + if($defaultReport == 'MultiSites' + && Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')) { - return Piwik_FrontController::dispatch('Login', false); + $module = 'MultiSites'; } - parent::redirectToIndex('CoreHome', 'index'); + if($defaultReport == Piwik::getLoginPluginName()) + { + $module = Piwik::getLoginPluginName(); + } + + parent::redirectToIndex($module, $action); } public function showInContext() diff --git a/plugins/CoreHome/templates/menu.css b/plugins/CoreHome/templates/menu.css index c8c19eef83..a4d9df5ed5 100644 --- a/plugins/CoreHome/templates/menu.css +++ b/plugins/CoreHome/templates/menu.css @@ -61,14 +61,15 @@ } .nav li, .nav li:hover,.nav li.sfHover,.nav li.current,.nav a:focus,.nav a:hover,.nav a:active{ --moz-border-radius:5px 5px 0 0; --webkit-border-radius:5px 5px 0 0; + -moz-border-radius:5px 5px 0 0; + -webkit-border-radius:5px 5px 0 0; } /* LEVEL1 HOVER */ .nav li:hover,.nav li.sfHover,.nav li.current,.nav a:focus,.nav a:hover,.nav a:active { background: #C9D5FF; -moz-border-radius:5px 5px 0 0; + -webkit-border-radius:5px 5px 0 0; } .nav li { diff --git a/plugins/CoreHome/templates/top_bar.tpl b/plugins/CoreHome/templates/top_bar.tpl index c347f83fcb..53957f4110 100644 --- a/plugins/CoreHome/templates/top_bar.tpl +++ b/plugins/CoreHome/templates/top_bar.tpl @@ -13,7 +13,7 @@ <nobr> <small> {'General_HelloUser'|translate:"<strong>$userLogin</strong>"} -{if isset($userHasSomeAdminAccess) && $userHasSomeAdminAccess}| <a href='index.php?module=CoreAdminHome'>{'General_Settings'|translate}</a>{/if} +{if $userLogin != 'anonymous'}| <a href='index.php?module=CoreAdminHome'>{'General_Settings'|translate}</a>{/if} {if $showSitesSelection && $showWebsiteSelectorInUserInterface}| {include file=CoreHome/templates/sites_selection.tpl}{/if} | {if $userLogin == 'anonymous'}<a href='index.php?module={$loginModule}'>{'Login_LogIn'|translate}</a>{else}<a href='index.php?module={$loginModule}&action=logout'>{'Login_Logout'|translate}</a>{/if} </small> diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php index 9e6b12a6b9..f2a009461e 100644 --- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php +++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php @@ -34,6 +34,9 @@ class Piwik_CorePluginsAdmin extends Piwik_Plugin function addMenu() { - Piwik_AddAdminMenu('CorePluginsAdmin_MenuPlugins', array('module' => 'CorePluginsAdmin', 'action' => 'index')); + Piwik_AddAdminMenu('CorePluginsAdmin_MenuPlugins', + array('module' => 'CorePluginsAdmin', 'action' => 'index'), + Piwik::isUserIsSuperUser(), + $order = 7); } } diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php index a10151789a..dca55f0fe1 100644 --- a/plugins/DBStats/Controller.php +++ b/plugins/DBStats/Controller.php @@ -18,6 +18,7 @@ class Piwik_DBStats_Controller extends Piwik_Controller { function index() { + Piwik::checkUserIsSuperUser(); $view = Piwik_View::factory('DBStats'); $view->tablesStatus = Piwik_DBStats_API::getInstance()->getAllTablesStatus(); $this->setGeneralVariablesView($view); diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 65ef3d40f1..acbd6ccf9f 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -34,6 +34,9 @@ class Piwik_DBStats extends Piwik_Plugin function addMenu() { - Piwik_AddAdminMenu('DBStats_DatabaseUsage', array('module' => 'DBStats', 'action' => 'index')); + Piwik_AddAdminMenu('DBStats_DatabaseUsage', + array('module' => 'DBStats', 'action' => 'index'), + Piwik::isUserIsSuperUser(), + $order = 9); } } diff --git a/plugins/Installation/templates/structure.tpl b/plugins/Installation/templates/structure.tpl index 3c850d84a3..4a02e3c044 100644 --- a/plugins/Installation/templates/structure.tpl +++ b/plugins/Installation/templates/structure.tpl @@ -127,10 +127,8 @@ h3 { margin: auto; background: #FFFFFF; padding: 0.2em 2em 2em 2em; - - -moz-border-radius: 8px; - -khtml-border-radius: 8px; - -webkit-border-radius: 8px; + -moz-border-radius: 8px; + -webkit-border-radius: 8px; } /* form errors */ #adminErrors { diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index bd7bf1149b..0343877b5c 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -54,7 +54,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin $view->languages = Piwik_LanguagesManager_API::getInstance()->getAvailableLanguageNames(); $view->currentLanguageCode = self::getLanguageCodeForCurrentUser(); $view->currentLanguageName = self::getLanguageNameForCurrentUser(); - echo $view ->render(); + echo $view->render(); } function getLanguageToLoad($notification) diff --git a/plugins/Login/Form.php b/plugins/Login/Form.php index 156dd907ca..88483c1fe6 100644 --- a/plugins/Login/Form.php +++ b/plugins/Login/Form.php @@ -33,7 +33,7 @@ class Piwik_Login_Form extends Piwik_Form $this->addElements( $formElements ); $formRules = array( - array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Login')), 'required'), + array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('General_Username')), 'required'), array('form_password', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Password')), 'required'), ); $this->addRules( $formRules ); diff --git a/plugins/Login/ResetPasswordForm.php b/plugins/Login/ResetPasswordForm.php index 1f623cd8aa..87470f6e18 100644 --- a/plugins/Login/ResetPasswordForm.php +++ b/plugins/Login/ResetPasswordForm.php @@ -41,7 +41,7 @@ class Piwik_Login_ResetPasswordForm extends Piwik_Form $this->setDefaults($defaults); $formRules = array( - array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Login')), 'required'), + array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('General_Username')), 'required'), array('form_password', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Password')), 'required'), array('form_password_bis', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_PasswordRepeat')), 'required'), array('form_token', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_PasswordResetToken')), 'required'), diff --git a/plugins/Login/templates/login.css b/plugins/Login/templates/login.css index e80d7c4a19..af9a89aee7 100644 --- a/plugins/Login/templates/login.css +++ b/plugins/Login/templates/login.css @@ -14,7 +14,6 @@ form { padding: 16px 16px 40px 16px; font-weight: bold; -moz-border-radius: 5px; - -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } @@ -34,7 +33,6 @@ form .forgetmenot { border-width: 1px; border-style: solid; -moz-border-radius: 3px; - -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; cursor: default; diff --git a/plugins/Login/templates/login.tpl b/plugins/Login/templates/login.tpl index c95a715f20..e95725a90f 100644 --- a/plugins/Login/templates/login.tpl +++ b/plugins/Login/templates/login.tpl @@ -16,7 +16,7 @@ <form {$form_data.attributes}> <p> - <label>{'Login_Login'|translate}:<br /> + <label>{'General_Username'|translate}:<br /> <input type="text" name="form_login" id="form_login" class="input" value="" size="20" tabindex="10" /> <input type="hidden" name="form_nonce" id="form_nonce" value="{$nonce}" /></label> </p> diff --git a/plugins/MultiSites/templates/index.tpl b/plugins/MultiSites/templates/index.tpl index 59ed8d0cd9..550b2df1f3 100644 --- a/plugins/MultiSites/templates/index.tpl +++ b/plugins/MultiSites/templates/index.tpl @@ -35,7 +35,8 @@ </script> {postEvent name="template_headerMultiSites"} -<table id="mt" class="dataTable" cellspacing="0" style="width:850px;margin: auto"> +<div align="center"> +<table id="mt" class="dataTable" cellspacing="0" style="width:850px;"> <thead> <th id="names" class="label" style="text-align:center"> <span style="cursor:pointer;" onClick="params = setOrderBy(this,allSites, params, 'names');">{'General_Website'|translate}</span> @@ -80,7 +81,7 @@ </tr> </tfoot> </table> - +</div> <script type="text/javascript"> prepareRows(allSites, params, '{$orderBy}'); diff --git a/plugins/SecurityInfo/SecurityInfo.php b/plugins/SecurityInfo/SecurityInfo.php index 6811aae328..d62916909d 100644 --- a/plugins/SecurityInfo/SecurityInfo.php +++ b/plugins/SecurityInfo/SecurityInfo.php @@ -37,9 +37,9 @@ class Piwik_SecurityInfo extends Piwik_Plugin function addMenu() { - if (Piwik::isUserIsSuperUser()) - { - Piwik_AddAdminMenu('SecurityInfo_Security', array('module' => 'SecurityInfo', 'action' => 'index')); - } + Piwik_AddAdminMenu('SecurityInfo_Security', + array('module' => 'SecurityInfo', 'action' => 'index'), + Piwik::isUserIsSuperUser(), + $order = 10); } } diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index c9b6751183..ebd2838131 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -39,7 +39,10 @@ class Piwik_SitesManager extends Piwik_Plugin function addMenu() { - Piwik_AddAdminMenu('SitesManager_MenuSites', array('module' => 'SitesManager', 'action' => 'index')); + Piwik_AddAdminMenu('SitesManager_MenuSites', + array('module' => 'SitesManager', 'action' => 'index'), + Piwik::isUserHasSomeAdminAccess(), + $order = 5); } function css() diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index 81e942a0b8..858f634a1d 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -67,15 +67,6 @@ option, select { textarea { font-size:9pt; } -.globalSettings td { -vertical-align:top; -} -.globalSettings .ui-inline-help { - margin-top:0; - margin-bottom:30px; - width:100%; - margin-left:40px; -} .admin thead th { vertical-align:middle; } @@ -102,7 +93,7 @@ vertical-align:middle; <th>{'SitesManager_Name'|translate}</th> <th>{'SitesManager_Urls'|translate}</th> <th>{'SitesManager_ExcludedIps'|translate}</th> - <th>{'SitesManager_ExcludedParameters'|replace:" ":"<br/>"}</th> + <th>{'SitesManager_ExcludedParameters'|translate|replace:" ":"<br/>"}</th> <th>{'SitesManager_Timezone'|translate}</th> <th>{'SitesManager_Currency'|translate}</th> <th> </th> @@ -139,7 +130,7 @@ vertical-align:middle; <br/> {ajaxErrorDiv id=ajaxErrorGlobalSettings} {ajaxLoadingDiv id=ajaxLoadingGlobalSettings} - <table width='600px' class='globalSettings'> + <table style='width:600px' class="adminTable adminTableNoBorder" > <tr><td colspan="2"> <b>{'SitesManager_GlobalListExcludedIps'|translate}</b> @@ -183,7 +174,7 @@ vertical-align:middle; {$currencyHelpPlain} </td></tr> </table> - <p><input type="submit" class="submit" id='globalSettingsSubmit' value="{'General_Save'|translate}" /></p> + <span style='margin-left:20px'><input type="submit" class="submit" id='globalSettingsSubmit' value="{'General_Save'|translate}" /></span> {/if} <br /><br /><br /><br /> diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 94ed2d98c4..4e99a36639 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -31,6 +31,40 @@ class Piwik_UsersManager_API return self::$instance; } + const PREFERENCE_DEFAULT_REPORT = 'defaultReport'; + const PREFERENCE_DEFAULT_REPORT_DATE = 'defaultReportDate'; + + /** + * Sets a user preference + * @param $userLogin + * @param $preferenceName + * @param $preferenceValue + * @return void + */ + public function setUserPreference($userLogin, $preferenceName, $preferenceValue) + { + Piwik::checkUserIsSuperUserOrTheUser($userLogin); + Piwik_SetOption($this->getPreferenceId($userLogin, $preferenceName), $preferenceValue); + } + + /** + * Gets a user preference + * @param $userLogin + * @param $preferenceName + * @param $preferenceValue + * @return void + */ + public function getUserPreference($userLogin, $preferenceName) + { + Piwik::checkUserIsSuperUserOrTheUser($userLogin); + return Piwik_GetOption($this->getPreferenceId($userLogin, $preferenceName)); + } + + private function getPreferenceId($login, $preference) + { + return $login . '_' . $preference; + } + /** * Returns the list of all the users * @@ -176,7 +210,7 @@ class Piwik_UsersManager_API */ public function getUser( $userLogin ) { - Piwik::checkUserIsSuperUser(); + Piwik::checkUserIsSuperUserOrTheUser($userLogin); $this->checkUserExists($userLogin); $this->checkUserIsNotSuperUser($userLogin); @@ -395,7 +429,6 @@ class Piwik_UsersManager_API */ public function userExists( $userLogin ) { - Piwik::checkUserHasSomeAdminAccess(); $count = Piwik_FetchOne("SELECT count(*) FROM ".Piwik::prefixTable("user"). " WHERE login = ?", $userLogin); diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index 9b4f552ca1..0607cbecc1 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -17,6 +17,9 @@ */ class Piwik_UsersManager_Controller extends Piwik_Controller { + /** + * The "Manage Users and Permissions" Admin UI screen + */ function index() { $view = Piwik_View::factory('UsersManager'); @@ -70,4 +73,170 @@ class Piwik_UsersManager_Controller extends Piwik_Controller $view->menu = Piwik_GetAdminMenu(); echo $view->render(); } + + const DEFAULT_DATE = 'today'; + + /** + * The "User Settings" admin UI screen view + */ + public function userSettings() + { + $view = Piwik_View::factory('userSettings'); + + $userLogin = Piwik::getCurrentUserLogin(); + if(Piwik::isUserIsSuperUser()) + { + $view->userAlias = $userLogin; + $view->userEmail = Zend_Registry::get('config')->superuser->email; + } + else + { + $user = Piwik_UsersManager_API::getInstance()->getUser($userLogin); + $view->userAlias = $user['alias']; + $view->userEmail = $user['email']; + } + + $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + if($defaultReport === false) + { + $defaultReport = $this->getDefaultWebsiteId(); + } + $view->defaultReport = $defaultReport; + + $defaultDate = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE); + if($defaultDate === false) + { + $defaultDate = self::DEFAULT_DATE; + } + $view->defaultDate = $defaultDate; + $view->availableDefaultDates = array( + 'today' => Piwik_Translate('General_Today'), + 'yesterday' => Piwik_Translate('General_Yesterday'), + 'week' => Piwik_Translate('General_CurrentWeek'), + 'month' => Piwik_Translate('General_CurrentMonth'), + 'year' => Piwik_Translate('General_CurrentYear'), + ); + + $this->initViewAnonymousUserSettings($view); + + $this->setGeneralVariablesView($view); + $view->menu = Piwik_GetAdminMenu(); + echo $view->render(); + } + + /** + * The Super User can modify Anonymous user settings + * @param $view + */ + protected function initViewAnonymousUserSettings($view) + { + if(!Piwik::isUserIsSuperUser()) + { + return; + } + $userLogin = 'anonymous'; + + // Which websites are available to the anonymous users? + $anonymousSitesAccess = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser($userLogin); + $anonymousSites = array(); + foreach($anonymousSitesAccess as $info) + { + $idSite = $info['site']; + $anonymousSites[$idSite] = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + } + $view->anonymousSites = $anonymousSites; + + // Which report is displayed by default to the anonymous user? + $anonymousDefaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + if($anonymousDefaultReport === false) + { + if(empty($anonymousSites)) + { + $anonymousDefaultReport = Piwik::getLoginPluginName(); + } + else + { + // we manually imitate what would happen, in case the anonymous user logs in + // and is redirected to the first website available to him in the list + // @see getDefaultWebsiteId() + reset($anonymousSites); + $anonymousDefaultReport = key($anonymousSites); + } + } + $view->anonymousDefaultReport = $anonymousDefaultReport; + + $anonymousDefaultDate = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE); + if($anonymousDefaultDate === false) + { + $anonymousDefaultDate = self::DEFAULT_DATE; + } + $view->anonymousDefaultDate = $anonymousDefaultDate; + } + + /** + * Records settings for the anonymous users (default report, default date) + */ + public function recordAnonymousUserSettings() + { + $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format')); + try { + Piwik::checkUserIsSuperUser(); + $this->checkTokenInUrl(); + $anonymousDefaultReport = Piwik_Common::getRequestVar('anonymousDefaultReport'); + $anonymousDefaultDate = Piwik_Common::getRequestVar('anonymousDefaultDate'); + $userLogin = 'anonymous'; + Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, + Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, + $anonymousDefaultReport); + Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, + Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE, + $anonymousDefaultDate); + $toReturn = $response->getResponse(); + } catch(Exception $e ) { + $toReturn = $response->getResponseException( $e ); + } + echo $toReturn; + } + + /** + * Records settings from the "User Settings" page + */ + public function recordUserSettings() + { + $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format')); + try { + $this->checkTokenInUrl(); + $alias = Piwik_Common::getRequestVar('alias'); + $email = Piwik_Common::getRequestVar('email'); + $defaultReport = Piwik_Common::getRequestVar('defaultReport'); + $defaultDate = Piwik_Common::getRequestVar('defaultDate'); + + $userLogin = Piwik::getCurrentUserLogin(); + if(Piwik::isUserIsSuperUser()) + { + $superUser = Zend_Registry::get('config')->superuser; + if($email != $superUser->email) + { + $superUser->email = $email; + Zend_Registry::get('config')->superuser = $superUser->toArray(); + } + } + else + { + Piwik_UsersManager_API::getInstance()->updateUser($userLogin, false, $email, $alias); + } + Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, + Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, + $defaultReport); + Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, + Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE, + $defaultDate); + + $toReturn = $response->getResponse(); + } catch(Exception $e ) { + $toReturn = $response->getResponseException( $e ); + } + echo $toReturn; + } + } diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index 63a2d4bfef..17623368b1 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -36,7 +36,14 @@ class Piwik_UsersManager extends Piwik_Plugin function addMenu() { - Piwik_AddAdminMenu('UsersManager_MenuUsers', array('module' => 'UsersManager', 'action' => 'index')); + Piwik_AddAdminMenu('UsersManager_MenuUsers', + array('module' => 'UsersManager', 'action' => 'index'), + Piwik::isUserHasSomeAdminAccess(), + $order = 3); + Piwik_AddAdminMenu('UsersManager_MenuUserSettings', + array('module' => 'UsersManager', 'action' => 'userSettings'), + Piwik::isUserHasSomeViewAccess(), + $order = 1); } } diff --git a/plugins/UsersManager/templates/UsersManager.tpl b/plugins/UsersManager/templates/UsersManager.tpl index 211de590cb..b07d07e9a8 100644 --- a/plugins/UsersManager/templates/UsersManager.tpl +++ b/plugins/UsersManager/templates/UsersManager.tpl @@ -113,7 +113,7 @@ <table class="admin" id="users"> <thead> <tr> - <th>{'UsersManager_Login'|translate}</th> + <th>{'General_Username'|translate}</th> <th>{'UsersManager_Password'|translate}</th> <th>{'UsersManager_Email'|translate}</th> <th>{'UsersManager_Alias'|translate}</th> diff --git a/plugins/UsersManager/templates/userSettings.js b/plugins/UsersManager/templates/userSettings.js new file mode 100644 index 0000000000..93922aa099 --- /dev/null +++ b/plugins/UsersManager/templates/userSettings.js @@ -0,0 +1,56 @@ +function getUserSettingsAJAX() +{ + var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingUserSettings', 'ajaxErrorUserSettings'); + var alias = $('#alias').val(); + var email = $('#email').val(); + var defaultReport = $('input[name=defaultReport]:checked').val(); + if(defaultReport == 1) { + defaultReport = $('#defaultReportWebsite option:selected').val(); + } + var defaultDate = $('input[name=defaultDate]:checked').val(); + var request = ''; + request += 'module=UsersManager'; + request += '&action=recordUserSettings'; + request += '&format=json'; + request += '&alias='+alias; + request += '&email='+email; + request += '&defaultReport='+defaultReport; + request += '&defaultDate='+defaultDate; + request += '&token_auth=' + piwik.token_auth; + ajaxRequest.data = request; + return ajaxRequest; +} +function getAnonymousUserSettingsAJAX() +{ + var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingAnonymousUserSettings', 'ajaxErrorAnonymousUserSettings'); + var anonymousDefaultReport = $('input[name=anonymousDefaultReport]:checked').val(); + if(anonymousDefaultReport == 1) { + anonymousDefaultReport = $('#anonymousDefaultReportWebsite option:selected').val(); + } + var anonymousDefaultDate = $('input[name=anonymousDefaultDate]:checked').val(); + var request = ''; + request += 'module=UsersManager'; + request += '&action=recordAnonymousUserSettings'; + request += '&format=json'; + request += '&anonymousDefaultReport='+anonymousDefaultReport; + request += '&anonymousDefaultDate='+anonymousDefaultDate; + request += '&token_auth=' + piwik.token_auth; + ajaxRequest.data = request; + return ajaxRequest; +} + +$(document).ready( function() { + $('#userSettingsSubmit').click( function() { + $.ajax( getUserSettingsAJAX() ); + }); + $('#userSettingsTable input').keypress( function(e) { + var key=e.keyCode || e.which; + if (key==13) { + $('#userSettingsSubmit').click(); + }}); + + $('#anonymousUserSettingsSubmit').click( function() { + $.ajax( getAnonymousUserSettingsAJAX() ); + }); +}); + diff --git a/plugins/UsersManager/templates/userSettings.tpl b/plugins/UsersManager/templates/userSettings.tpl new file mode 100644 index 0000000000..ee5207b8f7 --- /dev/null +++ b/plugins/UsersManager/templates/userSettings.tpl @@ -0,0 +1,117 @@ +{assign var=showSitesSelection value=false} +{assign var=showPeriodSelection value=false} +{include file="CoreAdminHome/templates/header.tpl"} +{loadJavascriptTranslations plugins='UsersManager'} +{include file="CoreAdminHome/templates/menu.tpl"} +<script type="text/javascript" src="plugins/UsersManager/templates/userSettings.js"></script> +<h2>{'UsersManager_MenuUserSettings'|translate}</h2> + +{ajaxErrorDiv id=ajaxErrorUserSettings} +{ajaxLoadingDiv id=ajaxLoadingUserSettings} +<br/> +<table id='userSettingsTable' class="adminTable adminTableNoBorder" style='width:700px'> +<tr> + <td><label for="username">{'General_Username'|translate} </label></td> + <td> + <input size="25" value="{$userLogin}" id="username" disabled="disabled"> + <span class='form-description'>{'UsersManager_YourUsernameCannotBeChanged'|translate}</span> + </td> +</tr> + +<tr> + <td><label for="alias">{'UsersManager_Alias'|translate} </label></td> + <td><input size="25" value="{$userAlias}" id="alias" {if $isSuperUser}disabled="disabled"{/if}> + {if $isSuperUser} + <span class='form-description'> + {'UsersManager_TheSuperUserAliasCannotBeChanged'|translate} + </span> + {/if} + </td> +</td> +</tr> +<tr> + <td><label for="email">{'UsersManager_Email'|translate} </label></td> + <td><input size="25" value="{$userEmail}" id="email"></td> +</tr> +<tr> + <td>{'UsersManager_ReportToLoadByDefault'|translate}</td> + <td> + <fieldset> + <label><input type="radio" value="MultiSites" name="defaultReport" {if $defaultReport=='MultiSites'}checked="checked"{/if}> {'General_AllWebsitesDashboard'|translate}</label><br> + <label><input type="radio" value="1" name="defaultReport" {if $defaultReport!='MultiSites'}checked="checked"{/if}> {'General_DashboardForASpecificWebsite'|translate}</label> + <select id="defaultReportWebsite"> + {if isset($sites)}{foreach from=$sites item=info} + <option value="{$info.idsite}" {if $defaultReport==$info.idsite} selected="selected"{/if}>{$info.name}</option> + {/foreach}{/if} + </select> + </fieldset> + </td> +</tr> +<tr> + <td>{'UsersManager_ReportDateToLoadByDefault'|translate}</td> + <td> + <fieldset> + {foreach from=$availableDefaultDates key=value item=description} + <label><input type="radio" {if $defaultDate==$value}checked="checked"{/if} value="{$value}" name="defaultDate"> {$description}</label><br/> + {/foreach} + </fieldset> + </td> +</tr> + +</table> + +<input type="submit" value="{'General_Save'|translate}" id="userSettingsSubmit" class="submit"> + + +{if $isSuperUser} + <h2>{'UsersManager_MenuAnonymousUserSettings'|translate}</h2> + {if count($anonymousSites) == 0} + <br/><span class='form-description'><b>{'UsersManager_NoteNoAnonymousUserAccessSettingsWontBeUsed'|translate}</b></span><br/> + {/if} + <br/> + + {ajaxErrorDiv id=ajaxErrorAnonymousUserSettings} + {ajaxLoadingDiv id=ajaxLoadingAnonymousUserSettings} + + <table id='anonymousUserSettingsTable' class="adminTable adminTableNoBorder" style='width:800px'> + <tr> + <td style='width:400px'>{'UsersManager_WhenUsersAreNotLoggedInAndVisitPiwikTheyShouldAccess'|translate}</td> + <td> + <fieldset> + <label><input type="radio" value="Login" name="anonymousDefaultReport" {if $anonymousDefaultReport==$loginModule}checked="checked"{/if}> {'UsersManager_TheLoginScreen'|translate}</label><br> + <label><input {if empty($anonymousSites)}disabled="disabled"{/if} type="radio" value="MultiSites" name="anonymousDefaultReport" {if $anonymousDefaultReport=='MultiSites'} checked="checked"{/if}> {'General_AllWebsitesDashboard'|translate}</label><br> + + <label><input {if empty($anonymousSites)}disabled="disabled"{/if} type="radio" value="1" name="anonymousDefaultReport" {if $anonymousDefaultReport>0}checked="checked"{/if}> {'General_DashboardForASpecificWebsite'|translate}</label> + {if !empty($anonymousSites)} + <select id="anonymousDefaultReportWebsite"> + {foreach from=$anonymousSites item=info} + <option value="{$info.idsite}" {if $anonymousDefaultReport==$info.idsite} selected="selected"{/if}>{$info.name}</option> + {/foreach} + </select> + {/if} + </fieldset> + </td> + </tr> + <tr> + <td>{'UsersManager_ForAnonymousUsersReportDateToLoadByDefault'|translate}</td> + <td> + <fieldset> + {foreach from=$availableDefaultDates key=value item=description} + <label><input type="radio" {if $anonymousDefaultDate==$value}checked="checked"{/if} value="{$value}" name="anonymousDefaultDate"> {$description}</label><br/> + {/foreach} + </fieldset> + </td> + </tr> + + </table> + +<input type="submit" value="{'General_Save'|translate}" id="anonymousUserSettingsSubmit" class="submit"> + +{/if} +{* +<h2>Exclude visits using a cookie</h2> +<i>Your visits are currently tracked by Piwik</i> +<br/> +Click here to set a cookie in your browser to not be tracked by Piwik +*} +{include file="CoreAdminHome/templates/footer.tpl"} \ No newline at end of file diff --git a/tests/core/ArchiveProcessing.test.php b/tests/core/ArchiveProcessing.test.php index 35ff22e48d..e7fded57a8 100644 --- a/tests/core/ArchiveProcessing.test.php +++ b/tests/core/ArchiveProcessing.test.php @@ -89,17 +89,17 @@ class Test_Piwik_ArchiveProcessing extends Test_Database // test of validity of an archive, for today's archive public function test_init_today() { - Zend_Registry::get('config')->General->enable_browser_archiving_triggering = true; + Piwik_ArchiveProcessing::setBrowserTriggerArchiving(true); $archiveProcessing = $this->createArchiveProcessing('day', 'today', 'UTC-1'); - // we look at anything processed in the last time_before_today_archive_considered_outdated seconds - $dateMinArchived = time() - Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated; + // we look at anything processed within the time to live range + $dateMinArchived = time() - Piwik_ArchiveProcessing::getTodayArchiveTimeToLive(); $this->assertEqual($archiveProcessing->getMinTimeArchivedProcessed(), $dateMinArchived); // when browsers don't trigger archives, we force ArchiveProcessing // to fetch any of the most recent archive - Zend_Registry::get('config')->General->enable_browser_archiving_triggering = false; + Piwik_ArchiveProcessing::setBrowserTriggerArchiving(false); $dateMinArchived = 0; $this->assertEqual($archiveProcessing->getMinTimeArchivedProcessed(), $dateMinArchived); diff --git a/themes/default/common.css b/themes/default/common.css index a4b99eab05..29e88351fc 100644 --- a/themes/default/common.css +++ b/themes/default/common.css @@ -22,6 +22,9 @@ ol,ul { blockquote,q { quotes: none; } +label { + cursor:pointer; +} /* remember to define focus styles! */ :focus { outline: 0; @@ -180,6 +183,7 @@ input.submit { border-width:3px; color:#333; padding:0.15em; + align:center; } .ajaxError { color: red; diff --git a/themes/default/simple_structure.css b/themes/default/simple_structure.css index f6e679508f..e02a93f8e7 100644 --- a/themes/default/simple_structure.css +++ b/themes/default/simple_structure.css @@ -8,7 +8,6 @@ html { background: #eee; } margin:auto; margin-top: 30px; -moz-border-radius: 12px; - -khtml-border-radius: 12px; -webkit-border-radius: 12px; } #h1 { @@ -37,7 +36,6 @@ a { color: #006; } padding: 5px 7px 7px; border: 1px solid #a3a3a3; -moz-border-radius: 3px; - -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; color: #246; -- GitLab