Joomla 2.5 module permissions - joomla

I simply want to make a module visible dependent on whether a user belongs to a custom set of groups - including NOT visible if (s)he belongs to a particular group(s). For example, adverts show for public and registered but not a custom "premium" group. A shoutbox should appear for registered and premium but not "not logged in". Thus, the "guest" and "special" groups are pretty useless as far as I can tell. Am I missing something really simple?
If I have to use a 3rd party component/module to achieve this then a free or cheap one would be most beneficial.
Thanks.

One way to achieve this is to edit and create new access levels. To cover up the examples you gave in the question, the following could work:
You need to get the guests out of the root parent group called Public. You can do this by the following three steps:
Using the User Manager, create a new group called "Guest" with Public as parent.
Open up the User Manager Options.
Change Guest User Group to your new group Guest.
The guests on your site will from now on be put into the Guest group. Now you could create a access level for the advert. So create a new access level, name it something like "Non premium users" and add Guest and Registered. Now apply this access level to the module and it should work. Note that the premium group cannot have Registered as a parent.
Next is the access level for the shoutbox. I see two options for this access level. One of them is to create a new access level and add Registered and Premium to it. A simpler approach though is to add the Premium group to the already existing access level called Registered.
Helpful ACL Links:
Allowing Guest-Only Access to Menu Items and Modules
Joomla ACL: Access Levels

None of the ACL levels work 100% of the time for me, I had to hack the template I was using and add in some code...
<?php
// make sure user is an accepted user group
jimport( 'joomla.user.helper' );
$user =& JFactory::getUser();
$userId = $user->get( 'id' );
$groups = JUserHelper::getUserGroups($userId);
// print_r($groups);
/*
3 Author
4 Editor
5 Publisher
6 Manager
7 Administrator
8 Super Users
*/
$menu = '' ;
if (in_array("3", $groups)) {
// echo "<!-- Author Group Found! -->";
// echo '<!-- USER ID: ' . $userId . ' -->';
$menu .= "
<a href='http://yourdomain.com/authors-area'>Authors Area</a>
" ;
} elseif(in_array("4", $groups)) {
$menu .= "
<a href='http://yourdomain.com/editors-area'>Editors Area</a>
" ;
} elseif(in_array("5", $groups)) {
$menu .= "
<a href='http://yourdomain.com/publishers-area'>Publishers Area</a>
" ;
} elseif(in_array("6", $groups)) {
$menu .= "
<a href='http://yourdomain.com/managers-area'>Managers Area</a>
" ;
} elseif(in_array("7", $groups)) {
$menu .= "
<a href='http://yourdomain.com/administrators-area'>Administrators Area</a>
" ;
} elseif(in_array("8", $groups)) {
$menu .= "
<a href='http://yourdomain.com/superusers-area'>Super Users Area</a>
" ;
} else {
$null = '' ; ;
}
?>

Related

How to pass an array to a view as Contextual Filter

I am new in Drupal. I am currently developing an e-commerce site using drupal 7. I want to know how can i pass an array of nid to views_embed_view('view_name','display_name',contextual filter) contextual filters. Here is my sample code-
foreach($result as $record)
{
$querystring .= "+";
$querystring .= $record->nid;
}
$querystring = ltrim($querystring, '+');
views_embed_view('tours_listings', 'page_2',$querystring);
You can add accomplish this by:
Checking the
Allow multiple values on the view contextual settings page.
If selected, users can enter multiple values in the form of 1+2+3. Due
to the number of JOINs it would require, AND will be treated as OR
with this filter.
Then instead of code above:
$recordIds = array();
foreach($result as $record)
{
$recordIds[] = $record->nid;
}
$querystring = implode('+', $recordIds);
//Do not forget to print this out.
print views_embed_view('tours_listings', 'page_2', $querystring);

How to disable TFA (Two factor authentication)

I enabled TFA in Joomla 3.2 and it worked fine, but my smartphone is unaccessible.
Then I cannot go in backend and I tried to disable the plugin plg_twofactorauth_totp in database but it stay enabled.
Disabling by rename the folder hide Secret Key input, but I wasn't able to login.
Go to your MySQL database for joomla, go to the users table. Clear the value of otpKey. you should be able to login without a key now.
https://gist.github.com/medigeek/28a047be0d0d527a95769130a6faf559
This code will disable two-factor auth plugins and clear keys for Joomla! Super Users.
This script disables Joomla!'s two factor authentication plugin and clears the otpKey and otep values for Super Users. It allows you to login when you aren't able to use Google authenticator for any reason.
Usage:
Place it in the Joomla! 3.x root dir (where configuration.php and index.php are) and run it. Then login and leave the security key field empty.
Warning: Use with caution. Backup before use!
Snapshot of the code
<?php
/* This script disables Joomla!'s two factor authentication
* plugin and clears the otpKey and otep values for Super
* Users. It allows you to login when you aren't able to
* use Google authenticator for any reason.
* Usage:
* Place it in the Joomla! 3.x root dir (where configuration.php
* and index.php are) and run it. Then login and leave the
* security key field empty.
* Warning: Use with caution. Backup before use.
*/
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(JPATH_BASE . '/defines.php')) { require_once JPATH_BASE . '/defines.php'; }
if (!defined('_JDEFINES')) { require_once JPATH_BASE . '/includes/defines.php'; }
require_once JPATH_LIBRARIES . '/import.legacy.php'; // Get the framework.
require_once JPATH_LIBRARIES . '/cms.php'; // Bootstrap the CMS libraries.
class Reset2FA extends JApplicationCli
{
public function execute()
{
$this->out('Initialising');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query2 = $db->getQuery(true);
//get users by group: (array of integers)
$sadminids = JAccess::getUsersByGroup(8); // 8 = Super Users
$strsadminids = implode(',', $sadminids);
$this->out(sprintf('Super User IDs: %s', $strsadminids));
$this->out('Disabling twofactorauth plugin (totp and yubikey)');
// Fields to update.
$fields = array(sprintf('%s = 0', $db->quoteName('enabled')));
// Conditions for which records should be updated.
// plg_twofactorauth_totp
// plg_twofactorauth_yubikey
$conditions = array(sprintf('%s LIKE %s', $db->quoteName('name'), $db->quote('plg_twofactorauth_%')));
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
$this->out('Disabling/clearing otpKey and otep for all Super Users');
// UPDATE 2
$fields2 = array(
$db->quoteName('otpKey') . " = ''",
$db->quoteName('otep') . " = ''",
);
// Conditions for which records should be updated.
// otpKey
// otep
$conditions2 = array(
$db->quoteName('otpKey') . " != ''",
$db->quoteName('otep') . " != ''",
sprintf('%s IN (%s)', $db->quoteName('id'), $strsadminids)
);
$query2->update($db->quoteName('#__users'))->set($fields2)->where($conditions2);
$db->setQuery($query2);
$result2 = $db->execute();
$this->out('Done');
}
}
JApplicationCli::getInstance('Reset2FA')->execute();
?>

Magento Admin Create Order not showing Custom Options

I have simple products with custom options in my store. They work perfectly from the front end, but if I try to add an order from the admin section, The custom options do not show up.
I only have this problem if the type of custom option is a dropdown, multi select, radio buttons, or check boxes. If it is a text field, date or anything else, it works fine.
I am assumming i need to make some changes to something in the /www/app/design/adminhtml/default/default/template/sales/order/create area, but no clue what i should try.
Looking a bit further, I found this /www/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/grid.php
/**
* Get Custom Options of item
*
* #param Mage_Sales_Model_Quote_Item $item
* #return array
*/
public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
{
$optionStr = '';
$this->_moveToCustomerStorage = true;
if ($optionIds = $item->getOptionByCode('option_ids')) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $item->getProduct()->getOptionById($optionId)) {
$optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
$optionStr .= $option->getTitle() . ':';
$quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
$group = $option->groupFactory($option->getType())
->setOption($option)
->setQuoteItemOption($quoteItemOption);
$optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
$optionStr .= "\n";
}
}
}
return $optionStr;
}
The best way to find the correct template path is to turn on admin template hints.
By default magento does not provide a way to accomplish from the admin, but you can easily accomplish this using one of these methods Enable template path hint in admin pages - Magento

Magento multiple websites share shopping cart

I have a bit of a dilemma with a Magento website I am building. I have two websites with a store each set up in order to enable multiple currencies checkout for each site. So the only difference between the two sites (on two different domains) that are managed via one common magento installation is the currency display and checkout currency. This is all working fine so far.
However I am trying to share the checkout session between the sites so the shopping cart stays the same when switching between the sites. I manage to get the correct session id added to the switching url so each site knows what session we are looking for. However the method that actually displays the shopping cart does not seem to work website independent - for example in
Mage_Checkout_Model_Session
_getQuoteIdKey() -> uses the current website id to check for the quote id in the session.
And I can not figure out what/how to overwrite this functionality so that each website shares exactly the same shopping cart data!
my $_SESSION['checkout'] variable shows the same on each site but with this website id included the data is no use for the shopping cart:
'quote_id_4' => string '13' (length=2)
Any ideas whether this is possible at all?
After I searched for an answer to this and stumbled across the same question being asked since 2009 without a definite solution, I finally had to look into the deep end of the code myself - and voila, I have a working solution. Here a detailed guide for anyone who wants to set up Magento with
multiple currencies that don't just get displayed but actually charged in the selected currency
share the shopping cart throughout websites and not just stores
The main problem with this combination is that with the default Magento structure you can only ever do one or the other, not the two combined.
So lets set Magento up for multiple currencies first.
Create a website for each currency with a corresponding store and store view (not just store views, complete websites)
Set System - Configuration - Currency Setup per website to the respective currency. All three entries Base Currecny, Default Display Currency and Allowed currencies should be set to just one and the same currency.
Go back to the default overall config scope and set System - Configuration - Catalog - - - Price the Catalog Price Scope to “Website”
You can also define you currency rates in System - Manage Currency Rates
For each website scope set the appropriate System - Configuration - Web - Secure and Unsecure base url.
In your .htaccess file add this at the top (replace the appropriate website domains and code you entered when setting up the websites (here http://website-us.local with base_us and http://website-uk.local with code base_uk)
SetEnvIf Host website-us.local MAGE_RUN_CODE=base_us
SetEnvIf Host website-us.local MAGE_RUN_TYPE=website
SetEnvIf Host ^website-us.local MAGE_RUN_CODE=base_us
SetEnvIf Host ^website-us.local MAGE_RUN_TYPE=website
SetEnvIf Host website-uk.local MAGE_RUN_CODE=base_uk
SetEnvIf Host website-uk.local MAGE_RUN_TYPE=website
SetEnvIf Host ^website-uk.local MAGE_RUN_CODE=base_uk
SetEnvIf Host ^website-uk.local MAGE_RUN_TYPE=website
Overwrite the method convertPrice in Mage/Core/Model/Store and change the method convertPrice - this will ensure that the prices are always displayed in the correct conversion AND the correct currency sign.
/**
* Convert price from default currency to current currency
*
* #param double $price
* #param boolean $format Format price to currency format
* #param boolean $includeContainer Enclose into <span class="price"><span>
* #return double
*/
public function convertPrice($price, $format = false, $includeContainer = true)
{
$categories = Mage::getModel('catalog/category')->getCollection();
$categ_ids=$categories->getAllIds();
$baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode,array_values($allowedCurrencies));
if ($this->getCurrentCurrency() && $this->getBaseCurrency()) {
$value = $this->getBaseCurrency()->convert($price, $this->getCurrentCurrency());
} else {
$value = $price;
}
if($this->getCurrentCurrencyCode() != $baseCurrencyCode)
{
$value = $price * $currencyRates[$this->getCurrentCurrencyCode()];
}
if ($this->getCurrentCurrency() && $format) {
$value = $this->formatPrice($value, $includeContainer);
}
return $value;
}
}
But of course we also want to share the users data, cart and login throughout the websites we just set up.
While in default config scope set System - Configuration - Customer Configuration - Account Sharing Options - Share Customer Accounts to Global
Overwrite magento/app/code/core/Mage/Checkout/Model/Session.php and replace this method:
protected function _getQuoteIdKey()
{
return 'quote_id';
//return 'quote_id_' . $websites[1];
}
Overwrite magento/app/code/core/Mage/Sales/Model/Quote.php and change the method getSharedStoreIds to:
public function getSharedStoreIds()
{
$ids = $this->_getData('shared_store_ids');
if (is_null($ids) || !is_array($ids)) {
$arrStoreIds = array();
foreach(Mage::getModel('core/website')->getCollection() as $website)
{
$arrStoreIds = array_merge($arrStoreIds,$website->getStoreIds());
}
return $arrStoreIds;
/*if ($website = $this->getWebsite()) {
return $website->getStoreIds();
}
var_dump($this->getStore()->getWebsite()->getStoreIds());exit();
return $this->getStore()->getWebsite()->getStoreIds();
*/
}
return $ids;
}
Overwrite magento/app/code/core/Mage/Customers/Model/Customer.php and change again the method getSharedWebsiteIds() to:
public function getSharedWebsiteIds() {
$ids = $this->_getData('shared_website_ids');
if ($ids === null) {
$ids = array();
if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
$ids[] = $this->getWebsiteId();
} else {
foreach (Mage::app()->getWebsites() as $website) {
$ids[] = $website->getId();
}
}
$this->setData('shared_website_ids', $ids);
}
return $ids;
}
If you use the wishlist option you should do the same for the method in magento/app/code/core/Mage/Wishlist/Model/Wishlist.php and change getSharedWebsiteIds so it not only loads the store ids from the current website but from all of them
Now we also have to implement a currency (website) switch on the frontend stores and pass the correct session ids inbetween so magento knows what stores to look for. I imitated the currency switch here and added the following dropdown to
magento/app/design/frontend/default/yourtheme/template/directory/currency.phtml
This loads all websites and applies the current Session Id as a query string so magento knows on any domain which session to use.
<?php
/**
* Currency switcher
*
* #see Mage_Directory_Block_Currency
*/
?>
<div class="top-currency">
<?php
$websites = Mage::getModel('core/website')->getCollection();
$this_session_id = Mage::getSingleton('core/session', array('name' => 'frontend'))->getSessionId();
?>
<select id="website-changer" onChange="document.location=this.options[selectedIndex].value">
<?php
foreach($websites as $website):
$default_store = $website->getDefaultStore();
$website_currency = $default_store->getBaseCurrency()->getCurrencyCode();
$url_obj = new Mage_Core_Model_Url();
$default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
$default_store_path .= Mage::getSingleton('core/url')->escape(ltrim(Mage::app()->getRequest()->getRequestString(), '/'));
$default_store_path = explode('?', $default_store_path);
$default_store_path = $default_store_path[0] . '?SID=' . $this_session_id;
?>
<option <? if(strstr($default_store_path,Mage::getBaseUrl())):?>selected="selected"<?endif; ?> value="<?=$default_store_path ?>">
<?=$website_currency?>
</option>
<?endforeach;?>
</select>
</div>
This query string will only be applied the first time you switch but magento will remember the session id after that stored in a cookie.
In order for this to work properly, overwrite
magento/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
and
replace this
// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId();
with
// potential custom logic for session id (ex. switching between hosts)
/* Amend to ensure shopping carts are shared between websites */
if (isset($_COOKIE['lastsid']))
{
session_decode(file_get_contents(Mage::getBaseDir('session').'/sess_'.$_COOKIE['lastsid']));
setcookie ('lastsid', '', time() - 3600);
}
if (isset($_GET['SID']))
{
$this->setSessionId($_GET['SID']);
session_decode(file_get_contents(Mage::getBaseDir('session') . '/sess_' . $_GET['SID']));
setcookie('lastsid', $_GET['SID']);
$_COOKIE['lastsid'] = $_GET['SID'];
}
else
{
$this->setSessionId();
}
/* Amend end */
This should now display multiple currencies, charge in multiple currencies across mutliple websites and on top of this share logins and shopping carts. This solution is a collection of knowledge I found on the interwebs combined with a few bits and pieces I figured out myself, so thanks for anyone who gave advice!

Phpbb3 forum integration with existing site

I am trying to integrate the phpbb forum with my existing site. I have already looked at these links, and it doesn't seem to work. I have copied this code
define('IN_PHPBB', true);
define('ROOT_PATH', "/path/to/forums");
if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
exit();
}
$phpEx = "php";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
into a loginforum.php file, which I include in every page I want the sessions to be kept. I have done the three steps indicated in the sessions integration section, but when I try to check whether the user is authenticated, it doesn't seem so. Using the same code here:
<?php
if ($user->data['user_id'] == ANONYMOUS){
echo 'Please login!';
}
else{
echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>
I only get the "Please login" phrase, even when I login.
I've been over this for hours, I don't understand where the problem is. Shouldn't it work after the three miraculous steps?
Try this:
if ($user->data['username'] == 'Anonymous')
{
echo 'Please login!';
}
This is the first (and guest) user in the PHPBB database:
SELECT `user_id`,
`username`,
`username_clean`
FROM
`phpbb_users` WHERE user_id = 1
Result:
"user_id" "username" "username_clean"
"1" "Anonymous" "anonymous"

Resources