make button disabled based on if row column - php

I have some working PHP code and I have recently added a button that allows the user to download the image form the root directory, in the database we put the file name e.g. example.png / example.jpeg and when the user clicks download it opens the image in a new tab
what we need is: if the [proof] is= NULL , the download button disables, otherwise it will be enabled and they can click the button
<?php
// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {
?>
<div class="card mb-4 box-shadow"><div class="card-header">
<h4 class="my-0 font-weight-normal">Job Reference: <?php echo $row["jobRef"]; ?></h4>
</div>
<div class="card-body">
<p><b>Company Name:</b><br> <?php echo $row["companyName"]; ?> </p>
<p><b>Requested:</b><br> <?php echo $row["dateReq"]; ?> </p>
<p><b>Request By:</b><br> <?php echo $row["yourName"]; ?> </p>
<p><b>Graphic Type:</b><br> <?php echo $row["graphicType"]; ?> </p>
<p><b>Double Sided:</b><br> <?php echo $row["doubleS"]; ?> </p>
<p><b>Design Info:</b><br> <?php echo $row["info"]; ?> </p>
<p><b>Purpose:</b><br> <?php echo $row["purpose"]; ?> </p>
<p><b>Proof:</b><br> <?php echo $row["approved"]; ?> </p>
<p><b>Proof Date:</b><br> <?php echo $row["appDate"]; ?> </p>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">Download</a>
</div>
</div>
<?php
}
?>

To my knowledge the link tag does not have a "disabled" attribute. But you can "disable" the link by removing the href attribute.
Something like this: It checks if $row['proof'] has some value (by negating the empty), then it prints out the href if result is true.
<a class="btn btn-success" target="_blank" <?php if(!empty($row['proof'])): ?> href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php endif; ?> >Download</a>
Or maybe better: Check if variable is empty and give the user a hint that it's not available. I think this is the better solution, because then your users will know what's going on.
<?php if(empty($row['proof'])): ?>
<span>No proof available</span>
<?php else: ?>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
<?php endif; ?>

<a
class="btn btn-success"
target="_blank"
<?php if(empty($row['proof'])) echo "disabled"; ?>
href="<?php if(!empty($row['proof'])) echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
try above code. and add disabled class using this condition

<?php
$state = (empty($row['proof'])) ? "disabled='disabled'" : "";
$class = (empty($row['proof'])) ? "disabled" : "";
?>
<a class="btn btn-success <?php echo $class; ?>" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php echo $state; ?>>Download</a>
To disabled the button, you need to use disabled HTML attribute. The code above checks $row['proof'] == NULL. If this statement is true it prints disabled = "disabled" in the button element and it isn't true, it prints nothing.
Assuming that you are using bootstrap, .disabled will grayed out the button.

Related

Detail Page using CodeIgniter

I want to create a detail page, but when I click button examp_title, I can't move to Tryout/soal.
Thank You
Controller (Tryout.php)
public function deskripsi($tryout_id)
{
$data['tryout'] = $this->M_tryout->deskripsi_to($tryout_id)->row();
$data['exam_tpa'] = $this->M_tryout->get_exam_tpa($tryout_id)->result();
$data['exam_tps'] = $this->M_tryout->get_exam_tps($tryout_id)->result();
$this->load->view('tryout/deskripsi', $data);
}
public function soal($exam_code)
{
$data['soal'] = $this->M_tryout->get_soal_tryout($exam_code)->result;
$this->load->view('tryout/soal', $data);
}
View (deskripsi.php)
<?php foreach ($exam_tps as $key => $value) { ?>
<h5 class="fw-bold" class="sub_to">
<a href="<?php base_url('tryout/soal/') ?>
<?php echo $exam->exam_code?>">
<?php echo $value->exam_title;?>
</a>
</h5>
<p>
<?php echo $value->exam_duration;?> Menit,
<?php echo $value->exam_count_question;?> soal <br> Pembahasan
</p>
<?php } ?>
It looks like your <a> tag is not outputting the link you want due to a missing echo.
I have simplified the href below...
<h5 class="fw-bold" class="sub_to">
<a href="<?php echo base_url('tryout/soal/') . $exam->exam_code ?>">
<?php echo $value->exam_title; ?>
</a>
</h5>

PHP foreach - Creating multple searchs in the same page

Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>

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;
} ?>

Multilingual slideshow

I have this code for a slideshow in my Drupal 7, Nexus 7.x-1.3 theme.
My website is multilingual and I need to use a different image for every language, eg. I would like to change slide-image-1.jpg (en language) with other image-name for (gr language).
My code:
<?php if ($is_front): ?>
<?php if (theme_get_setting('slideshow_display','nexus')): ?>
<?php
$slide1_head = check_plain(theme_get_setting('slide1_head','nexus')); $slide1_desc = check_markup(theme_get_setting('slide1_desc','nexus'), 'full_html'); $slide1_url = check_plain(theme_get_setting('slide1_url','nexus'));
$slide2_head = check_plain(theme_get_setting('slide2_head','nexus')); $slide2_desc = check_markup(theme_get_setting('slide2_desc','nexus'), 'full_html'); $slide2_url = check_plain(theme_get_setting('slide2_url','nexus'));
$slide3_head = check_plain(theme_get_setting('slide3_head','nexus')); $slide3_desc = check_markup(theme_get_setting('slide3_desc','nexus'), 'full_html'); $slide3_url = check_plain(theme_get_setting('slide3_url','nexus'));
?>
<div id="slidebox" class="flexslider">
<ul class="slides">
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-1.jpg'; ?>"/>
<?php if($slide1_head || $slide1_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide1_head; ?></h2><?php print $slide1_desc; ?>
<a class="frmore" href="<?php print url($slide1_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-2.jpg'; ?>"/>
<?php if($slide2_head || $slide2_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide2_head; ?></h2><?php print $slide2_desc; ?>
<a class="frmore" href="<?php print url($slide2_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-3.jpg'; ?>"/>
<?php if($slide3_head || $slide3_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide3_head; ?></h2><?php print $slide3_desc; ?>
<a class="frmore" href="<?php print url($slide3_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
</ul><!-- /slides -->
<div class="doverlay"></div>
</div>
<?php endif; ?>
<?php endif; ?>
Is there any solution for that? Thank you.
There is a Drupal connector from Smartling that may be of help. Here is a video showing how the connector works.
Many sites running on Smartling do language/country-specific image replacement, which is explained here.
Hope this helps,
Nataly
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<SCRIPT>
function english(){
$(#image).attr('src','http://link.to.your/english/image.png')
}
function greek(){
$(#image).attr('src','http://link.to.your/greek/image.png')
}
</SCRIPT>
<IMG id="image" src="http://link.to.your/greek/image.png">
Change to English<BR>
Change to Greek
Finally I fixed it in page.tpl with php code. One if/else on your page language to set you picture path.
Regards, HashKey

How to change a button's name

this code out put is here....(look at the footer subscribe section )
<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
$formatedPrice = sprintf('%1.02f',$level->price);
$dotpos = strpos($formatedPrice, '.');
$price_integer = substr($formatedPrice,0,$dotpos);
$price_fractional = substr($formatedPrice,$dotpos+1);
?>
<div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
<p class="level-title">
<span class="level-price">
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
<span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
</span>
<span class="level-title-text">
<a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
<?php echo $this->escape($level->title)?>
</a>
</span>
</p>
<div class="level-inner">
<div class="level-description">
<div class="level-description-inner">
<?php if(!empty($level->image)):?>
<img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
<?php endif;?>
<?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
</div>
</div>
<div class="level-clear"></div>
<div >
<button onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
<?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
this is the language file contain that name
COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"
I want to name those three sections butons as 6month,12month,24month
How will change the code ?
If you are unable to get the value using PHP, try changing the value of the button's name on page load
Here is the JQUERY
$(document).ready(function){
$('div.akeebasubs-awesome-description').each(function(
substription = $(this).children('H4').html()
button = $(this).parent().next().children('button')
$(button).attr(name,substription.split(' ')[0]+'month')
})
})
and the JAVASCRIPT
divs = document.getElementsByClassName('akeebasubs-awesome-description');
for (var i in divs){
divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
}
This will take the text of the H4 and make that the corresponding button's name

Categories