Print All Users - Joomla 2.5 - joomla

I am new to Joomla. I have created website using Joomla 2.5. I have login page which is default Joomla user management system.
What I want is display all user data in a tabular format. How could I do the same?
Edit 1
I can see the users with below steps.
Go to administrator page as www.site.com/administrator.
Login as admin
Click Users >> User Manager menu and then I can see the list of users.
I want to print same list, however on the website and not on administrator site at backend.

you can do this run the query on your page where you want to show user list. you can fetch all users table field with $row object.
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__users" ;
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
echo $row->id.'|'.$row->username.'|'.$row->email;
}
Edit 1
Below is what I used.
Installed extension Flexi Custom Code.
Create module using this, add above code in it and appear that menu on the menu where you want to display.

You'll need some sort of component for this. This user profile component for example (N.B. Using this as my example as a work colleague once used it - not as customizable as I would have liked - but probably OK for what your after. I'm sure there are more as there's an entire member list category.)
Just install one of them and choose what you want to show. Add it to a menu like any other component and off you go!

Two possible solutions
Use the User Profile Component available in JED
Enable "User - Contact Creator" plugin to create a Contact profile for each new user and then use the Joomla built-in Menu Item to list all contacts

// my example with opt-groups, preselected user and better user-ids
function getUserList ($user_id) {
$db = JFactory::getDBO ();
$db->setQuery ("SELECT id, username, usertype FROM ' . $db->quoteName ('#__users') . ' ORDER BY usertype,username ASC");
$rows = $db->loadAssocList ();
static $opt_tag;
$list = '<option value="0">' . JText::_ ('SELECTION') . '</option>';
foreach ($rows as $row) {
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '<optgroup label="' . $row['usertype'] . '">';
$opt_tag = $row['usertype'];
}
if ($row['id'] < 10) {
$id = '000' . $row['id'];
}
elseif ($row['id'] < 100) {
$id = '00' . $row['id'];
}
elseif ($row['id'] < 1000) {
$id = '0' . $row['id'];
}
$list .= '<option value="' . $row['id'] . '"' . (((int) $user_id == $row['id']) ? ' selected="SELECTED"' : '') . '>' . $id . ' - ' . $row['username'] . '</option>';
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '</optgroup>';
}
}
return $list;
}

Related

How to bypass or reset a filter manually?

I want to show filter of category on submenu, my code works!!
My problem is that if page are already filtered, my code does not return the options
I believe it has to do something in the code that bypasses the filter page and again bring the options in the submenu even if already have the filter on page
HTML of submenu:
{{block type="core/template" category="3" template="page/html/icons_submenu.phtml"}}
Content of page icons_submenu.phtml:
<?php
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel('catalog/category')->load($this->getCategory());
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Example:
I would really suggest you to actually move all that logic into a proper module, a proper block and a proper model and not in a template like you are doing right now.
If you actually want further help for that, feel free to ask, making something according to the coding guide lines of Magento would make you even happier of your job, I can assure you.
This being said, what you actually want is a current filter model based on the current category and a specify attribute.
You don't need to go by the block catalog/layer_filter_attribute in a way to do this, you can directly go by the model based on the layer you already load.
So, this way of doing it should work, although it should not be in a template or view, once again :
<?php
$category = Mage::getModel('catalog/category')
->load($this->getCategory());
$layer = Mage::getModel('catalog/layer')
->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
// $filterBlockName = 'catalog/layer_filter_attribute';
/** This is actually your only problem in your code **/
// $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
/** But would work with this line **/
$result = Mage::getModel('catalog/layer_filter_attribute')
->setLayer($layer)
->setAttributeModel($attribute);
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Then you can see it still works based on only the colours I have in the current category
But also when the category is already filtered on a specific colour

Auto redirect to another page In Joomla

I am making payment through paypal. After payment completion it redirect to my website(complete.php) page. I have code in complete.php that will update the credit in database. when i refresh the same page then it automatically update credits in database. I want to update credit only when payment is done. The code i am using in complete.php is:
$db = JFactory::getDBO();
$result = null;
$user = JFactory::getUser();
if ($user->guest) {
return false;
}
$query = 'SELECT credit' .
' FROM #__vodes_credits' .
' WHERE userid = ' . (int) $user->id
;
$db->setQuery($query);
$result = $db->loadResult();
$result_final=$result+20;
$query = 'update #__vodes_credits SET credit='.$result_final.
' WHERE userid = ' . (int) $user->id
;
//echo $query;
//echo $query;
$db->setQuery($query);
$result = $db->loadResult();
if ($db->getErrorNum()) {
JError::raiseWarning( 500, $db->stderr());
}
return $result;
?>
Please help me to sought it out.
I recommend you to create a COOKIE before the payment and then destroy that COOKIE after the first time the user has visited the complete.php, that will work.
Regards.
In case you want to redirect, I am not sure where are you writing your code but try the below code
$app=JFactory::getApplication();
$app->setRedirect('url','msg');

How Do I Output Delivery Instructions for Magento?

I am trying to create a script that I can access via URL so that it outputs delivery details, specifically the fields I need to display are: orderID, status, gift_message and a custom customer address attribute that is called "delivery_instructions". So far I have the following, but I am stuck with trying to get the delivery instructions, any help would be much appreciated.
<?php
require_once 'app/Mage.php';
Mage::app('default');
$myOrder=Mage::getModel('sales/order');
$orders=Mage::getModel('sales/mysql4_order_collection');
$message = Mage::getModel('giftmessage/message');
$customer = Mage::getModel('customer/customer');
$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0
//$orders->addFieldToFilter('gift_message_id',Array('gt'=>0));
$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
$myOrder->reset()->load($thisId);
$shippingAddress = $myOrder->getShippingAddress();
$customerDetails = $myOrder->getCustomer();
//echo $myOrder->shippingaddress->getData('delivery_instructions');
$customer_id = $myOrder->getCustomerId() . "',";
echo $customer_id . "',";
echo "'" . $myOrder->getStatus() . "',";
echo "'" . $myOrder->getIncrementID() . "',";
$gift_message_id = $myOrder->getGiftMessageId();
if(!is_null($gift_message_id)) {
$message->load($gift_message_id);
echo $gift_message = $message->getData('message') . "',";
};
$customer = Mage::getModel('customer/customer')->load( $customer_id);
echo $customer = $customer->getData('incrementId');
echo "\r\n";
echo "<br/ >";
}
?>
You are close with this:
//echo $myOrder->shippingaddress->getData('delivery_instructions');
In order to get the shipping address object you need to use:
$myOrder->getShippingAddress()
and to get the delivery_instruction from the shipping address object:
$myOrder->getShippingAddress()->getDeliveryInstructions()
You can create custom address attributes and custom customer attributes.
Customer attributes can be accessed like this:
// A customer is not mandatory for an order.
if($myOrder->getCustomerId()){
$customer = Mage::getModel(’customer/customer’)->load($myOrder->getCustomerId());
$customer->getDeliveryInstructions();
}
Address attributes can be accessed like this:
$myOrder->getShippingAddress()->getDeliveryInstructions();

How to Get User Group Names in Joomla 2.5

I'm writing a Joomla 2.5 component that I had been developing in Joomla 1.7. I have been using code like this:
$user = JFactory::getUser();
$groups = $user->get('groups');
The $groups array would contain a list of ids with the group name as the index. Joomla 2.5 seems to have scrapped this functionality. I have been unable to find out how to get the group names without directly querying the database. Is there any method for getting a list of the groups a user is a member of without having to resort to querying the database?
The code I generated below gets the names of all the groups the user is a part of and stores them in the variable $groupNames separated by line breaks:
foreach ($user->groups as $groupId => $value){
$db = JFactory::getDbo();
$db->setQuery(
'SELECT `title`' .
' FROM `#__usergroups`' .
' WHERE `id` = '. (int) $groupId
);
$groupNames .= $db->loadResult();
$groupNames .= '<br/>';
}
print $groupNames;
It technically queries the database but is done via the Joomla API. This is working well for me on Joomla 2.5.
Yes, this changed.
But what you should be using instead is:
JFactory::getUser()->getAuthorisedGroups();
or just getUserGroups
Real snippet:
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery($db->getQuery(true)
->select('*')
->from("#__usergroups")
);
$groups=$db->loadRowList();
$userGroups = $user->groups;
$return=array();
foreach ($groups as $key=>$g){
if (array_key_exists($g[0],$userGroups)) array_push($return,$g[4]);
}
$groups=$return;
/////printing groupnames for current user/////////////
print_r($groups);
Here it is:
<?php
$user =& JFactory::getUser();
foreach ($user->groups as $key => $value){
echo $key.'<br>';
}
?>
This will print all the user group names to the screen. The user group names are the "keys" of the array $user->groups.

In Magento, How does one modify the admin store select list at the search filter stage and not the select stage?

Magento Admin has a store select drop down list of all the stores.
I have added an addititional "SELECT ALL STORES" value to allow me to know when a user wishes to carry out a task on all stores.
I based this customisation on enterprise magento version 1.9 although I think the version is quite irrelevant since my question is quite generic to magento I think.
How do I stop my "SELECT ALL STORES" from being selected by default in the search ?
/index.php/admin/admin/urlrewrite/index
The store list select form is built here:
app\code\core\Adminhtml\Block\Widget\Grid\Column\Filter\Store.php
Once I found that, I could override it to the local code pool and make the modifications I needed.
public function getHtml()
{
$storeModel = Mage::getSingleton('adminhtml/system_store');
/* #var $storeModel Mage_Adminhtml_Model_System_Store */
$websiteCollection = $storeModel->getWebsiteCollection();
$groupCollection = $storeModel->getGroupCollection();
$storeCollection = $storeModel->getStoreCollection();
$allShow = $this->getColumn()->getStoreAll();
$html = '<select name="' . $this->_getHtmlName() . '" ' . $this->getColumn()->getValidateClass() . '>';
$value = $this->getColumn()->getValue();
//if ($allShow) {
$html .= '<option value=""' . (**$value == 0** ? ' selected="selected"' : '') . '>' . Mage::helper('adminhtml')->__('All Store Views') . '</option>';
//} else {
// $html .= '<option value=""' . (!$value ? ' selected="selected"' : '') . '></option>';
//}

Resources