Hope you guys are fine. I am in a little problem. I am not expert in Codeigniter.
I have 5 user groups like super_admin, admin, reseller, agent and general. while super_admin will create a user he can give all access to the new user. but an admin can give reseller, agent and general. Reseller can agent and general and finally agent cant only general access. Now want to hide those user group name from a drop-down menu which has not permission of a user.
My code is below. I wrote the code in a create_user.php page. Please help me.
<?php
foreach ($groups as $group):
$a=$this->ion_auth->get_users_groups()->row()->name;
if(!in_array($group->name, $a)){
?>
<option value="<?php echo $group['id']; ?>"><?php echo htmlspecialchars($group['description'], ENT_QUOTES, 'UTF-8'); ?></option>
<?php } endforeach ?>
</select>
</div>
?php endif ?>
Here is an example that you can test.
Few assumptions are taken that should be readily apparent like consecutive ids and that super_admin is id 5.
The relevant ion_auth functions are commented out.
<?php
$groups = array(
array(
'id' => 1,
'name' => 'general'
),
array(
'id' => 2,
'name' => 'agent'
),
array(
'id' => 3,
'name' => 'reseller'
),
array(
'id' => 4,
'name' => 'admin'
),
array(
'id' => 5,
'name' => 'super_admin'
),
);
//$groups = $this->ion_auth->groups()->result_array();
array_pop($groups); // remove super_admin (last element) from array
$curr_user_group = 4;
//$curr_user_group = $this->ion_auth->get_users_groups()->row()->id;
$user_create_groups = $curr_user_group - 1;
$groups = array_slice($groups, 0, $user_create_groups);
echo '<pre>';
foreach ($groups as $group) {
print_r($group);
}
As general can't create a group lower the $groups array will be blank for it. Hopefully you have thought of this and have some system in place so a user with that group can't create users. Also note that you need to institute a similar validation function on the backend to make sure users don't elevate themselves or others to super_admin by changing the select box in their browser.
Related
I have created a custom module in Magento2 where currently I'm selecting a customer and entered multiple order numbers, it will saved into a custom table in the database.
Currently I have to entered order numbers in a textarea but now I want to display all orders after choosing the customer which are not in Complete status.
From this section admin choose orders by clicking on the right side checkbox and Saved it.
Can anyone help me to solve this problem?
Existing Module’s Layout
Want to modify the above layout to the following one: In this desired system when admin change the customer name order numbers associated with that customer will be listed.
New invoice
Code I have used to create the customer dropdown field:
$fieldset->addField('customer_id', 'select', array(
'label' => __('Customer'),
'name' => 'customer_id',
'title' => __('Customer'),
'values' => $this->getCustomerOptionArray()
));
protected function getCustomerOptionArray()
{
$options = array();
$options[] = array(
'value' => 0,
'label' => __('Select Customer'),
);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')->getCollection();
foreach ($customerObj as $customerObjdata ){
$options[] = array(
'value' => $customerObjdata->getId(),
'label' => $customerObjdata->getName(),
);
}
return $options;
}
I am using some custom options as additional options on site
I am using below code to show additional options to cart page using checkout_cart_product_add_after event. it is working fine
$additionalOptions[] = array(
'code' => 'Personalize '.$j,
'label' => 'Personalize '.$j,
'value' => $personalizeData
);
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions)
));
//Here $personalizeData is my custom options array.
Now I want to show these options also on user's wishlist when user adds product to wishlist.
Please suggest me.
Try this,
In app/design/frontend/<your_package>/<your_theme>/template/wishlist/item/list.phtml file
<?php foreach ($this->getItems() as $item): ?>
<?php $options = $this->helper('catalog/product_configuration')->getOptions($item); print_r($options); ?>
<?php endforeach; ?>
I have a number of social networking links (about 5) in the footer of my site and I need to generate data for each of the anchor link’s TITLE and URL - and ICON (image).
It’s not really worth creating a new table for only 5 rows, so I’m thinking a helper might be a the answer - some sort of associative array.
However, I’m a bit unsure how to construct the helper’s array - and completely clueless as to how to loop the results in the view file.
Any help, or any links to useful examples, is greatly appreciated!
In your helper:
function footer_link_data()
{
return array(
array(
'title' => 'Facebook',
'url' => 'http://facebook.com',
'icon' => 'http://placehold.it/64x64'
),
array(
'title' => 'Twitter',
'url' => 'http://twitter.com',
'icon' => 'http://placehold.it/64x64'
),
array(
'title' => 'Pinterest',
'url' => 'http://pinterest.com',
'icon' => 'http://placehold.it/64x64'
),
);
}
In your view:
<?php
$links = footer_link_data();
foreach($links as $link): ?>
<?php echo $link['icon'] ?>
<?php
endforeach; ?>
Alternatively, you can just create the HTML statically. For 5 links having it generated dynamically is kind of pointless.
Is it possible that when user register in Magento, that time he also saves his Addresses (Billing & Shipping)
Create a module with a controller that extends the Mage_Customer_AccountController, containing createPostAction(). I duplicated the bit that handles the billing address, find this if-block:
if ($this->getRequest()->getPost('create_address')) {
And add this to the end of it:
if ($this->getRequest()->getPost('create_shipping_address')) {
$shippingAddress = Mage::getModel('customer/address');
$shippingAddressForm = Mage::getModel('customer/form');
$shippingAddressForm->setFormCode('customer_register_address')
->setEntity($shippingAddress);
$shippingAddressData = array(
'firstname' => $addressData['firstname'],
'lastname' => $addressData['lastname'],
'company' => $this->getRequest()->getPost('shipping_company'),
'street' => $this->getRequest()->getPost('shipping_street'),
'city' => $this->getRequest()->getPost('shipping_city'),
'country_id' => $this->getRequest()->getPost('shipping_country_id'),
'region' => $this->getRequest()->getPost('shipping_region'),
'region_id' => $this->getRequest()->getPost('shipping_region_id'),
'postcode' => $this->getRequest()->getPost('shipping_postcode'),
'telephone' => $this->getRequest()->getPost('shipping_telephone'),
'fax' => $this->getRequest()->getPost('shipping_fax')
);
$shippingAddressErrors = $addressForm->validateData($shippingAddressData);
if ($shippingAddressErrors === true) {
$shippingAddress->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('shipping_default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('shipping_default_shipping', false));
$shippingAddressForm->compactData($shippingAddressData);
$customer->addAddress($shippingAddress);
$shippingAddressErrors = $shippingAddress->validate();
if (is_array($shippingAddressErrors)) {
$errors = array_merge($errors, $shippingAddressErrors);
}
} else {
$errors = array_merge($errors, $shippingAddressErrors);
}}
Of course you also need to duplicate the form in your themes template/customer/form/register.html, specifically the code inside this if-block:
if($this->getShowAddressFields()): ?>
Prefix all the field names IDs and in the copied code with shipping_. In the JavaScript at the bottom you need to duplicate the RegionUpdater line, like so:
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
new RegionUpdater('country', 'shipping_region', 'shipping_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
(almost) complete code can be found here:
AccountController.php:
http://pastebin.com/9h9HqYAa
register.html:
http://pastebin.com/Q7EawU7L
It works perfectly
There is a way you can have one address input while registration.
Go to : template/customer/form/register.phtml and if($this->getShowAddressFields())
Just forcefully alter this condition and you will get address fields there.
To add to Massi and Steve's answer, in Magento 1.9.0.1, I am just learning but I was able to get this to work by adding that code to the end of _getErrorsOnCustomerAddress function in an extension of Mage_Customer_AccountController.
Not in the default magento version. you must search for an extension for this or write your own "observer" to add an address on the same time of the registration.
Like butcher said,adding that code to the end of _getErrorsOnCustomerAddress. I just tried it, and it works fine for me.
And I also set the value for "1" instead of "0" in the code
<input type="hidden" name="create_shipping_address" value="0" />
(look the link that Steve and Massi have given register.html: http://pastebin.com/Q7EawU7L)
Im on Magento 1.9.0.1
Normally, the CakePHP's validation messages from models like:
class User extends AppModel {
public $name = 'User';
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
),
'regexp' => array(
'rule' => '/^[a-z0-9]{3,10}$/i',
'message' => 'Only letters and integers, min 3, max. 10 characters'
)
)
)
}
Are printed below the inputs, I mean that messages: 'message' => 'A username is required'
So it looks like:
|INPUT|
[Message]
How do I can change that so the messages gonna be added to the array:
$errors[] = 'Message';
And then, I would like to use foreach to print them in one place.
Is that possible?
CakePHP has all of the validation errors available to the view in $this->validationErrors. So I loop through them thusly:
<?php if ( !empty($this->validationErrors['Model']) ) { ?>
<div id="errorlist">
<h3>You have errors in your submission. <?php echo $warnimage; ?></h3>
<div>
<ul>
<?php foreach( $this->validationErrors['Model'] as $val ){ ?>
<li><?php echo $val; ?></li>
<?php } ?>
</ul>
</div>
</div>
<?php } ?>
EDIT
Where to place this code?
Place the code in the view where you would like it displayed.
How to disable displaying those errors below inputs?
I don't disable that display but suppose if you wished you could just unset $this->validationErrors['Model']. (untested)
Another solution is to use elements as shown in this article by Miles Johnson.