how change user account inactive as default (codeigniter)? - php

I have code CodeIgniter
I want help with the problem ,
"I want to set the account as inactive by default " it's active when a user creates new account.
<?php // status ?>
<div class="form-group col-sm-3<?php echo form_error('status') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('users input status'), '', array('class'=>'control-label')); ?>
<span class="required">*</span>
<div>
<label style="font-weight:500">
<?php echo form_radio(array('class'=>'radio', 'type'=>'radio', 'name'=>'status', 'id'=>'radio-status-1', 'value'=>'1', 'checked'=>(( ! isset($user['status']) OR (isset($user['status']) && (int)$user['status'] == 1) OR $user['id'] == 1) ? 'checked' : FALSE))); ?>
<span><?php echo lang('admin input active'); ?></span>
</label>
</div>
<?php if ( ! $user['id'] OR $user['id'] > 1) : ?>
<div>
<label style="font-weight:500">
<?php echo form_radio(array('class'=>'radio', 'type'=>'radio', 'name'=>'status', 'id'=>'radio-status-2', 'value'=>'0', 'checked'=>((isset($user['status']) && (int)$user['status'] == 0) ? 'checked' : FALSE))); ?>
<span><?php echo lang('admin input inactive'); ?></span>
</label>
</div>
<?php endif; ?>
</div>

Let me give you some explanation on this:
If I understand you correctly you want to have every visitor as inactive, and (new) registered users as active? Which will become active when $user is set?
Am I correct, by reading your code, <?php if ( ! $user['id'] OR $user['id'] > 1) : ?> this part should show a line of code if it's a user? Currently you are saying two things:
The line of code needs to be shown if:
There is NO $user['id'] known
OR if $user['id'] is higher than value 1.
So, lets say:
Your code is showing to ALL users currently (both inactive and active).
You could fix it with something like this:
<?php if ( $user['id'] > 1) : ?>
<div>
<label style="font-weight:500">
<?php echo form_radio(array('class'=>'radio', 'type'=>'radio', 'name'=>'status', 'id'=>'radio-status-2', 'value'=>'0', 'checked'=>((isset($user['status']) && (int)$user['status'] == 0) ? 'checked' : FALSE))); ?>
<span><?php echo lang('admin input inactive'); ?></span>
</label>
</div>
<?php endif; ?>
By deleting your OR statement it will now ONLY show to active users. If you wish to show a line of code to inactive users you could simply do this:
<?php if ( $user['id'] > 1) : ?>
<div>
<label style="font-weight:500">
<?php echo form_radio(array('class'=>'radio', 'type'=>'radio', 'name'=>'status', 'id'=>'radio-status-2', 'value'=>'0', 'checked'=>((isset($user['status']) && (int)$user['status'] == 0) ? 'checked' : FALSE))); ?>
<span><?php echo lang('admin input inactive'); ?></span>
</label>
</div>
<?php else :?>
// Code which is showing when there is NO $user['id'] known or lower than 2.
<?php endif; ?>
I hope this helped you.

Related

Load a conditional .phtml file in a block of layout xml file (ex. based on product SKU)

Extreme newbie to Magento and php.
I want to set a different phtml based on the product in a block of my catalog.xml layout.
Basically, for normal products i want to load the usual text.phtml file in a block of my category.xml layout
(catalog/product/view/options/type/text.phtml, the one that shows custom text options)
But a particular product, I want the same block to load, say,different_text.phtml (catalog/product/view/options/type/different_text.phtml)
Is there a way to load a different phtml fle in a block on the basis of the SKU of the product?
The easiest way would be to keep one template and separate the content to display inside the template, small example here that uses a sample product id 10:
<?php $_option = $this->getOption(); ?>
<?php $p = $this->getProduct(); ?>
<?php if($p->getId != 10): ?>
<dt><label<?php if ($_option->getIsRequire()) echo ' class="required"' ?>><?php if ($_option->getIsRequire()) echo '<em>*</em>' ?><?php echo $this->escapeHtml($_option->getTitle()) ?></label>
<?php echo $this->getFormatedPrice() ?></dt>
<dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<?php if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD): ?>
<input type="text" onchange="opConfig.reloadPrice()" id="options_<?php echo $_option->getId() ?>_text" class="input-text<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?> <?php echo $_option->getMaxCharacters() ? ' validate-length maximum-length-'.$_option->getMaxCharacters() : '' ?> product-custom-option" name="options[<?php echo $_option->getId() ?>]" value="<?php echo $this->escapeHtml($this->getDefaultValue()) ?>" />
<?php elseif ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA): ?>
<textarea id="options_<?php echo $_option->getId() ?>_text" onchange="opConfig.reloadPrice()" class="<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?> <?php echo $_option->getMaxCharacters() ? ' validate-length maximum-length-'.$_option->getMaxCharacters() : '' ?> product-custom-option" name="options[<?php echo $_option->getId() ?>]" rows="5" cols="25"><?php echo $this->escapeHtml($this->getDefaultValue()) ?></textarea>
<?php endif; ?>
<?php if ($_option->getMaxCharacters()): ?>
<p class="note"><?php echo Mage::helper('catalog')->__('Maximum number of characters:')?> <strong><?php echo $_option->getMaxCharacters() ?></strong></p>
<?php endif; ?>
</div>
</dd>
<?php else: ?>
display something else
<?php endif; ?>
That would be the quick n' dirty way :-)
The longer, more complex but professional way is to write your own extension with a block class that extends the current block class Mage_Catalog_Block_Product_View_Options_Type_Text and decide inside your new block class which template you want to load based on product id or sth. else.

php code to display icon on active button

I am working on cakephp 1.3..
i have button and value displaying inside button coming from database.
I want to show arrow icon on my active button only..
now the active arrow icon is displaying in all button...inside forloop.
plz help me to do this..
below is my code
<?php
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo);
?>
<li class="active">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
</li>
<?php } ?>
You should add a condition in your for loop
Like this
<?php
// you need to send button unique name to controller
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo); ?>
<li class="<?php echo ($mo == $selectedUniqueButtonID) ? 'active' : '' ?>">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<?php if($mo == $selectedUniqueButtonID){ ?>
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
<?php } ?>
</li>
<?php
} ?>
Controller code
$selectedUniqueButtonID = $this->data['Customer']['mode'];
$this->set('selectedUniqueButtonID',$selectedUniqueButtonID);

Joomla 3 , change php else if for site link to something global

i have a php elseif code that looks like that,
<?php if ($item->getPrimaryImage()) :?>
<img src="<?php echo $item->getPrimaryImage()->getSource(); ?>" class="sprocket-lists-image" alt="" />
<?php endif; ?>
<?php echo $item->getText(); ?>
<?php if ($item->getPrimaryLink()) : ?></br>
<?php if ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3200") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=1508") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=1840") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=2541") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/topmenu-1478/3350-2015-03-10-09-52-10") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3426") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3420") : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php else : ?></br>
<span><?php rc_e('READ_MORE'); ?></span>
<?php endif; ?>
<?php endif; ?>
the code is quite simple , that is
all the elseif have a link starting like == "index.php... etc,,, meaning that the readon button will open inside the website like _parent link WITHOUT the MODAL..
the last (case) else open all the rest links INSIDE THE MODAL
Question
You will notice that all the links on the elseif cases starting like "index.php/..,,,
Is there is any way of coding to avoid all the elseif and having something global, meaning that will recognize the starting link "index.php/.. ?
You will notice that the action followed for the elseif
<span><?php rc_e('READ_MORE'); ?></span>
on all the cases is the same.
I need a piece of code that will understand-recognize the link starting "index.php/..
is this possible ?
Target
My target is that i do not want to use so many elseif every time a new link have to be added, and the code will take care it,, cause right now every time when i have to add a new image-banner that will link to an article inside the joomla site i have to hardcoded and add a new elseif like the above,,, otherwise it will open it inside the modal..
I hope its clear enough, please some help cause i m trying for ages to solve this..
Thank you in advance for reading this..
A general if clause to check if a string starts with a specific word is:
<?php if(substr($item->getPrimaryLink()->getUrl(), 0, 10) == "index.php/") : ?>
...
<?php endif; ?>
Reference: substr
Using an URL library like http://url.thephpleague.com/3.0/ should do the work exploding the URL between :
index.php/component/content/article
and the GET argument id.
Then you can simplify your code.

If / Else Statements

I am having a problem placing the IF / ELSE statement without breaking the rest of the page.
I have a following banner on my page :
<div class="awesome-banner">
<div class="image-wrap<?php echo $banner ? '' : ' awesome-hide'; ?>">
<?php $banner_url = $banner ? wp_get_attachment_url($banner) : ''; ?>
<input type="hidden" class="awesome-file-field" value="<?php echo $banner; ?>" name="awesome_banner">
<img class="awesome-banner-img" src="<?php echo esc_url($banner_url); ?>">
<a class="close awesome-remove-banner-image">×</a>
</div>
<div class="button-area<?php echo $banner ? ' awesome-hide' : ''; ?>">
<i class="fa fa-cloud-upload"></i>
<?php _e('Upload banner', 'awesome'); ?>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div>
</div> <!-- .awesome-banner -->
<?php do_action('awesome_settings_after_banner', $current_user, $profile_info); ?>
I need to place in the following statement inside this banner ( PLEASE CORRECT IF WRONG ):
<?
if ((current_user_can('manager')) )
{ ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
Upgrade Account
</div>
</div>
<?
return;
} else{
return false;
}
?>
So basically it should state the following inside this banner :
If the current user is user role "manager" then instead of the <div class="button-area"> it should display <div class="access-restricted">
Otherwise just go on as normally.
I am trying to place the statement directly inside like this :
<div class="awesome-banner">
<div class="image-wrap<?php echo $banner ? '' : ' awesome-hide'; ?>">
<?php $banner_url = $banner ? wp_get_attachment_url($banner) : ''; ?>
<input type="hidden" class="awesome-file-field" value="<?php echo $banner; ?>" name="awesome_banner">
<img class="awesome-banner-img" src="<?php echo esc_url($banner_url); ?>">
<a class="close awesome-remove-banner-image">×</a>
</div>
// Here I am placing my statement like this
<?
if ((current_user_can('manager')) )
{ ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
Upgrade Account
</div>
</div>
<?
return;
} else{
return false;
}
?>
// End of my statement
<div class="button-area<?php echo $banner ? ' awesome-hide' : ''; ?>">
<i class="fa fa-cloud-upload"></i>
<?php _e('Upload banner', 'awesome'); ?>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div>
</div> <!-- .awesome-banner -->
<?php do_action('awesome_settings_after_banner', $current_user, $profile_info); ?>
It displays the content correctly for the role, but it breaks the rest of the content on the page behind the awesome banner div.
Am I closing my statement and everything else correctly ?? Thanks
Further to my (and #maiorano84's comments), the return will stop your code if either condition is met (true or false):
if(current_user_can('manager')) { ?>
<div class="access-restricted">
<h5>Sign In Or Sign Up</h5>
<p class="non-manager-notice">You need to be a manager to upload a banner</p>
<div class="upgrade-button">
Upgrade Account
</div>
</div><?
// If you need to record a true or false here, assign to a variable.
// Don't return or your code will stop here.
$manager = true;
}
else { ?>
<div class="button-area<?php if($banner) echo ' awesome-hide'; ?>">
<i class="fa fa-cloud-upload"></i>
<?php _e('Upload banner', 'awesome'); ?>
<p class="help-block"><?php _e('(Upload a banner for your profile. Banner size is (825x300) pixel. )', 'awesome'); ?></p>
</div><?php
// If you need true/false, assign here
$manager = false;
} ?>

How can I better this code?

I have this code :
<div class="boxContentScroll">
<?
while($row=mysql_fetch_array($query, MYSQL_NUM)) {
?>
<div class="boxAddCategory<? if($row[1]==1) echo "Yes"; else echo "No"; ?>">
<div class="boxAddCategory1">
<? echo $row[0]."<br />"; ?>
</div>
<div class="boxAddCategory2">
<?
if((isset($_SESSION['admin'])) && ($_SESSION['admin']==1)) {
?>
<input type="checkbox" <? if($row[1]==1) echo "checked='checked'" ?> value="categories[]" />
<?
} else echo " "
?>
</div>
</div>
<?
}
?>
</div>
but is not so good read it (just watch the number of ?> or <?). What can you suggest to improve it? Thanks
If you want this code to run on all environments, don't use short_tags (<?). But if you're running this on your own server, you can disregard it.
Use PHP's alternative syntax for control structures. This will make it much more readable.
Don't mix your business logic with your view logic. Either setup your own MVC stack or use a templating engine if you want.
Well I would start with replacing if with short version:
<?php echo ($row[1]==1) ? "Yes" : "No"; ?>
You could write this:
<? if($row[1]==1) echo "Yes"; else echo "No"; ?>
like this:
<?= $row[1] == 1 ? 'Yes' : 'No' ?>
And you could replace this:
if((isset($_SESSION['admin'])) && ($_SESSION['admin']==1)) {
with this:
if ( $admin ) {
and put this before the while loop:
$admin = isset($_SESSION['admin']) && $_SESSION['admin'] == 1;
Any time you're in a loop and have a static condition to check like this:
if((isset($_SESSION['admin'])) && ($_SESSION['admin']==1))
Define it in a variable it outside the loop. If it won't change within the loop, you don't have to check each time, only once. This becomes relevant when doing resource intensive checks and function calls that won't produce a different result outside the loop.
<div class="boxContentScroll">
<?php while($row=mysql_fetch_array($query, MYSQL_NUM)) : ?>
<div class="boxAddCategory <?=($row[1] == 1 ? 'Yes' : 'No')?>">
<div class="boxAddCategory1">
<?=$row[0].'<br />'?>
</div>
<div class="boxAddCategory2">
<?php if((isset($_SESSION['admin'])) && ($_SESSION['admin']==1)) : ?>
<input type="checkbox" <?=($row[1]==1 ? 'checked="checked"' : '')?> value="categories[]" />
<?php endif; ?>
</div>
</div>
<?php endwhile; ?>
</div>
Using a HEREDOC:
<div class="boxContentScroll">
<?php
while ($row=mysql_fetch_array($query, MYSQL_NUM)) {
$class = ($row[1]==1) ? 'Yes' : 'No';
$checked = ($class) ? 'checked="checked"' : '';
$data = $row[0];
$admin = (isset($_SESSION['admin']) && $_SESSION['admin']==1) ? 1 : 0;
echo <<< HTML
<div class="boxAddCategory{$class}">
<div class="boxAddCategory1">
{$data}
</div>
HTML;
if ($admin) {
echo <<< HTML
<div class="boxAddCategory2">
<input type="checkbox" value="categories[]" {$checked} />
</div>
HTML;
}
echo <<< HTML
</div>
HTML;
}
?>
</div>

Categories