Add Active Link Class - javascript

I have a dynamic navigation bar that stores the pages/URLs in a database. The nav.php is the script that handles displaying and running through the SQL queries to display the links. I'm having a difficult time adding a script that adds an active class to the links.
My page URLs are as follows:
/page/2/full-service-fleet
/rate-request
/employment
/page/5/links
/page/6/contact
PHP:
<nav>
<?php
while ($row = $result->fetch_assoc())
{
$navid = $row['id'];
$navname = $row['nav'];
$navslug = $row['slug'];
$navurl = $row['url'];
$navnum = $row['num'];
if ($navurl != ''){
$navlink = $navurl;
}
else{
$navlink = "page.php?id=".$navid."&title=".$navslug;
}
if (substr($navlink,0,4) != "http"){
if ($server_name <> "") {
$navlink = "http://".$server_name."/".$navlink;
}
}
if ($navurl == '#'){
$navlink = $navurl;
}
if ($navnum ==0){
?>
<?php echo $navname; ?>
<?php
}else{
?>
<!-- the rest isn't necessary -->
......
</nav>
Browser Rendered Output
The actual links that are being displayed is this line:
<?php echo $navname; ?>
JS Script:
jQuery(document).ready(function($){
// Get current path and find target link
var path = window.location.pathname.split("/").pop();
// Account for home page with empty path
if ( path == '' ) {
path = 'index.php';
}
var target = $('nav a[href="'+path+'"]');
// Add active class to target link
target.addClass('active');
});

You can use this code as it is or you can grab some idea from this one
:
<div class="w3-top" style="z-index: 999;">
<div class="navcontainer">
<div class="w3-hide-small">
<img src="/images/-logo.png" alt="U.S. Transportation" title="" style="">
<div class="abovenav w3-right">
<button class="w3-button w3-round-large" onclick="">Customer Login</button>
<button class="w3-button w3-round-large" onclick="">Carrier Login</button>
</div>
</div>
<div class="w3-bar nav w3-card-2 w3-left-align w3-large" style="text-overflow: auto;" id="nav">
<div class="w3-hide-large w3-hide-medium">
<a class="w3-hide-medium w3-hide-large w3-right w3-margin-right w3-text-white buttons" href="javascript:void(0);" onclick="myFunction()" title="Toggle Navigation Menu"><span class="fa fa-bars"></span></a>
<a href="<?php
if ($server_name <> "") {
echo "http://" . $server_name . "/";
}
?>/index.php" title="Home" class="w3-left w3-margin-left w3-text-white buttons"><span class="fa fa-home w3-xlarge"></span></a>
</div>
<div style="margin-right: 10%;">
<nav>
<?php
include 'yortal\db.php';
$sql = "SELECT *,(select count(*) from pages where parent = p.id) as num from pages p where parent = 0 and status = 'ON' order by sort DESC";
$result = $mysqli->query($sql);
while ($row = $result->fetch_assoc()) {
$navid = $row['id'];
$navname = $row['nav'];
$navslug = $row['slug'];
$navurl = $row['url'];
$navnum = $row['num'];
if ($navurl != '') {
$navlink = $navurl;
} else {
$navlink = "page.php?id=" . $navid . "&title=" . $navslug;
}
if (substr($navlink, 0, 4) != "http") {
if ($server_name <> "") {
$navlink = "http://" . $server_name . "/" . $navlink;
}
}
if ($navurl == '#') {
$navlink = $navurl;
}
if ($navnum == 0) {
$current_link = $_SERVER[REQUEST_URI];
$active_class = ($navlink==$current_link)?'active':'';
?>
<?php echo $navname; ?>
<?php
} else {
?>
<div class="w3-dropdown-hover w3-hide-small w3-right" onclick="javascript:window.location.href = '<?php echo $navlink; ?>'">
<button class="w3-button"><?php echo $navname; ?></button>
<div class="w3-dropdown-content w3-white w3-card-4">
<?php
//Subpages
$sql2 = "SELECT *,(select count(*) from pages where parent = p.id) as num from pages p where parent = " . $navid . " and status = 'ON' order by sort";
$result2 = $mysqli->query($sql2);
while ($row2 = $result2->fetch_assoc()) {
$dropid = $row2['id'];
$dropname = $row2['nav'];
$dropurl = $row2['url'];
$dropslug = $row2['slug'];
$dropnum = $row2['num'];
if ($dropurl != '') {
$droplink = $dropurl;
} else {
$droplink = "page.php?id=" . $dropid . "&title=" . $dropslug;
}
if (substr($droplink, 0, 4) != "http") {
if ($server_name <> "") {
$droplink = "http://" . $server_name . "/" . $droplink;
}
}
if ($dropurl == '#') {
$droplink = $dropurl;
}
?>
<?php
$actual_link = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
$active_class = ($actual_link==$droplink || $_SERVER[REQUEST_URI] == $droplink)?'active':'';
?>
<?php echo $dropname; ?>
<?php
}
?>
</div>
</div><?php
}
}
?>
</nav>
</div>
</div>
</div>

First of all I'm pretty sure that you may have got wrong path. I suggest the following implementation which will depend on each():
$(document).ready(function(){
loc = window.location.pathname;
$("nav a").each(function(){
if ($(this).attr("href") == loc){
$(this).addClass("active");
$(this).attr("href") = "#"; // to prevent link to the same page
return true;
}
});
});

Related

Add a button to download all images from a website

I made a button but I can't get the function to work as I want, does anyone know what code I could use here?
I was thinking of downloading all the images with ZIP and it can be compressed by creating a folder on my server.
I think that a button is better to download them all or individually
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Image Parser</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<header class="header-image">
<div class="container">
<h1><strong>Image Parser</strong></h1>
<h3>Enter any URL and get all the images on the page</h3>
<button type="button" class="action-buttons" data-toggle="modal" data-target="#aboutmodal">About</button>
<button class="action-buttons">Get API</button>
</div>
</header>
<hr>
<div class="container">
<div class="row">
<div class="col-md-12">
<form id="form-extractor" class="form-horizontal form-main" method="GET">
<input type="text" class="form-control" name="url" placeholder="Enter the URL from where images are to be extracted" required autofocus>
<br>
<button type="button" id="submit" class="btn btn-lg btn-success">Extract</button>
</form>
</div>
</div>
</div>
<div class="spinner" style="display:none;">
<div class="rect1"></div> <div class="rect2"></div> <div class="rect3"></div> <div class="rect4"></div> <div class="rect5"></div>
</div>
<div id="stats" class="container" style="display:none;">
<div class="row">
<div class="col-xs-12 text-center" id="download-file" >
<a class="btn btn-lg btn-info" target="_blank" href="#">Download zip file</a>
</div>
</div>
</div>
<div id="result" class="other-text">Welcome :)</div>
</div>
<div class="modal fade" id="aboutmodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Image-Parser</h4>
</div>
<div class="modal-body text-justify">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="assets/js/script.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
script.js
$(document).ready(function() {
var spinner = toggleSpinner(),
submit_button = $("#submit");
submit_button.click(function(e) {
e.preventDefault();
spinner();
$.ajax({
url: 'api/image-parser.php?url=' + $('input[name="url"]').val(),
dataType: 'json',
beforeSend: function() {
submit_button.text("Extracting...");
submit_button.prop('disabled', true);
},
success: function(result) {
spinner();
if (result.success) {
renderStats(result);
renderImages(result);
} else {
$('#result').html('Invalid URL!');
}
},
error: function(xhr, resp, text) {
spinner();
$('#result').html('Could not connect to server, please try again later');
},
complete: function() {
submit_button.text("Extract");
submit_button.prop('disabled', false);
}
})
});
});
function renderStats(result) {
var stats =
'<strong>URL Searched</strong> : ' + $('input[name="url"]').val() + '<br>' +
'<strong>Parent Domain</strong> : ' + result.parent_url + '<br>';
$('#stats .other-text').empty().append(stats);
}
function renderImages(result) {
var images;
if (0 == result.images.length) {
images = '<b>No Image Found at your Given Location</b>';
} else {
images = result.images.map(function(image) {
return '<img src="' + image + '" width="250" style="margin:20px">';
});
}
$('#result').empty().append(images);
}
function toggleSpinner() {
var isHidden = true;
return function() {
if (isHidden) {
$('#stats').hide();
$('#result').empty();
$('.spinner').show();
} else {
$('#stats').show();
$('.spinner').hide();
}
isHidden = !isHidden;
}
}
image-parser.php
<?php
/**
* error reporting disabled, if you want to enable it
* change it to "error_reporting(E_ALL)"
* ref : http://php.net/manual/en/function.error-reporting.php
*/
error_reporting(0);
$final_response = get_extracted_images();
echo json_encode($final_response);
/**
* function to extract images from URL in GET Parameter
* #return response object
*/
function get_extracted_images() {
$final_response = array();
$images = array();
if (isset($_GET['url'])) {
$url = $_GET['url'];
$parts = explode('/', trim($url));
/**
* this flag is to check whether user has entered the http or https in the beginning of URL or not
* #var boolean
*/
$flag = ($parts[0] == 'http:' || $parts[0] == 'https:') ? true : false;
if (!$flag)
$url = 'http://' . $url;
/**
* check whether URL entered by user is correct or not
*/
if (!isValidURL($url)) {
return array(
'url_searched' => $url,
'valid_url' => false,
'success' => false
);
} else {
$final_response['valid_url'] = true;
/**
* check if there is a trailing slash (/) or not, if there is one, remove it
*/
if (substr($url, strlen($url) - 1) == '/')
$url = rtrim($url, "/");
$parts = explode('/', $url);
/**
* parent domain name called, if there is a subdomain, it would also be included here
* #var string
*/
$Root = $parts[0] . '//' . $parts[2];
$html = curl_URL_call($url);
if (empty($html)) {
return array(
'url_searched' => $url,
'valid_url' => false,
'success' => false,
'message' => 'We are unable to access the given URL: ' . $url
);
}
$dom = new DOMDocument;
$dom->loadHTML($html);
$final_response['url_searched'] = $url;
$final_response['parent_url'] = $Root;
/**
* check if there is any image in HTML source code or not
*/
if (preg_match_all('/<img[^>]+>/i', $html, $result)) {
$final_response['success'] = true;
foreach ($result[0] as $key) {
preg_match('/src="([^"]+)/i', $key, $src_key);
for ($i = 0; $i < count($src_key); $i += 2) {
$src = $src_key[1];
if (!preg_match("/http:/", $src) && !preg_match("/https:/", $src)) {
/**
* check whether the URL in the src is absolute or relative
* if it is relative, make it absolute
*/
if ($src[0] == '/' && $src[1] == '/') {
$src = 'http:' . $src;
} else if ($src[0] == '/') {
$src = $Root . $src;
} else {
$src = $Root . '/' . $src;
}
}
array_push($images, $src);
}
}
} else {
/**
* No images were found in the HTML
* source code, hence success if false
*/
$final_response['success'] = false;
}
/**
* Getting urls for stylesheets in the webpage
*/
foreach ($dom->getElementsByTagName('link') as $node) {
if ($node->getAttribute("rel") == "stylesheet") {
$css_route = $node->getAttribute("href");
/**
* check whether the URL in the $css_route is absolute or relative
* if it is relative, make it absolute
*/
if ($css_route[0] == '/' && $css_route[1] == '/') {
$css_route = 'http:' . $css_route;
} else if ($css_route[0] == '/') {
$css_route = $Root . $css_route;
} else if ($css_route[0] != 'h') {
$css_route = $Root . '/' . $css_route;
}
$parts = explode('/', $css_route);
$parts_length = sizeof($parts);
$css_root = $parts[0] . '//' . $parts[2];
$css_active_dir = $css_root;
$css_parent_dir = $css_root;
for ($i = 3; $i < $parts_length - 1; ++$i) {
if ($i < $parts_length - 2) {
$css_active_dir = $css_active_dir . '/' . $parts[$i];
$css_parent_dir = $css_parent_dir . '/' . $parts[$i];
} else {
$css_active_dir = $css_active_dir . '/' . $parts[$i];
}
}
$css = curl_URL_call($css_route);
$matches = array();
/**
* Getting image urls using image extension matches in stylesheet extracted
*/
preg_match_all('/url\(\s*[\'"]?(\S*\.(?:jpe?g|gif|png))[\'"]?\s*\)[^;}]*?/i', $css, $matches);
foreach ($matches[1] as $image_link) {
/**
* check whether the URL in the $image_link is absolute or relative
* if it is relative, make it absolute
*/
if ($image_link[0] == '.' && $image_link[1] == '.') {
$image_link = $css_parent_dir . substr($image_link, 2);
} else if ($image_link[0] == '.') {
$image_link = $css_active_dir . substr($image_link, 1);
} else if ($image_link[0] == '/') {
$image_link = $css_active_dir . $image_link;
} else {
$image_link = $css_active_dir . '/' . $image_link;
}
array_push($images, $image_link);
}
}
}
}
/**
* All the images are added to the images array in
* final response
*/
$final_response['images'] = $images;
return $final_response;
} else {
$message = "Please enter a URL to extract information as a 'url' parameter in GET request";
return array(
'url_searched' => null,
'valid_url' => false,
'success' => false,
'message' => $message,
);
}
}
/**
* function to check if the URL entered by the user is correct or not
* #param string $url URL to be passed which is to be checked
* #return boolean returns if URL passed is valid or not
*/
function isValidURL($url){
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
/**
* function to make a CURL call in order to fetch the complete HTML source code of URL entered
* #param string $url URL of the page
* #return string HTML source code of the URL entered
*/
function curl_URL_call($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

why ajax duplicate content

Hello I am new here and working on a project that requires this option of "Viewing content in DIV .posts_area, from database using AJAX",
I had a problem that the content I get in .posts_area sometimes duplicate itself.
Can anyone help me with the solution and I would also be happy for more detailed explanation about the subject.
// AJAX in
<script type="text/javascript">
$(document).ready(function() {
var flag = 0;
$.ajax({
type: 'GET',
url: 'getData.php',
data: {
'offset': 0,
'limit': 6
},
async: true,
success: function(data) {
$('.posts_area').append(data);
flag += 3;
}
});
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
$.ajax({
type: 'GET',
url: 'getData.php',
data: {
'offset': flag,
'limit': 5
},
success: function(data) {
$('.posts_area').append(data);
flag += 3;
}
});
}
});
});
</script>
//getData.php
<?php
include ('config/config.php');
include 'includes/classes/user.php';
include 'includes/classes/post.php';
if(isset($_GET['offset']) && isset($_GET['limit'])){
$limit = $_GET['limit'];
$offset = $_GET['offset'];
$data = mysqli_query($con,"SELECT * FROM posts WHERE deleted='no' ORDER by id DESC LIMIT {$limit} OFFSET {$offset} ");
if(mysqli_num_rows($data ) > 0) {
while($row = mysqli_fetch_array($data) ){
$id = $row['id'];
$comments_check = mysqli_query($con, "SELECT * FROM comments WHERE post_id='$id'");
$comments_check_num = mysqli_num_rows($comments_check);
?>
<script>
function myFunction<?php echo $id; ?>() {
var x = document.getElementById("toggleComment<?php echo $id; ?>");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
</script>
<?php
$added_by_user = $row['added_by_user'];
$post_profile_pic = $row['post_profile_pic'];
$added_by = $row['added_by'];
$body = $row['body'];
$date_time = $row['date_added'];
$user_session = $_SESSION['user'];
if($user_session == $added_by_user)
$delete_button = "<form action = 'delete_post.php?id=$id' method='POST' id = 'delete_post_id_form'>
<input type ='submit' class = 'delete_post_class_input' id = 'delete_post_id_input' value = 'Delete'></input>
</form>";
else
$delete_button = "";
// if($user_session == $added_by_user)
// $update_button = "<form action = 'update_post.php?post_id=$id' method='POST'>
// <input type ='submit' class = 'update_post_class' id = 'update_post_id' value = 'Update'></input>
// </form>";
// else
// $update_button = "";
$str .= "<div class='status_post' >
<div class='on_post_profile_pic_class' id = 'on_post_profile_pic_id'>
<a href='$added_by_user' class='posted_by_on_img'><img src='$post_profile_pic' width='50' id = 'on_post_profile_img_id'></img></a>
</div>
<div class='posted_by1' id='added_by_on_post' style='color:#ACACAC;'>
<a href='$added_by_user' class='posted_by'> $added_by </a>
</div>
<img src='assets/images/icons/more_info_button_black_down.png' onClick='show_hide()'alt='more_info_on_post_button_black_down_button_alt' class='more_info_on_post_button_black_down_btn' id ='more_info_on_post_button_black_down_btn_id' name ='more_info_name'></img>
<img src='assets/images/icons/more_info_button_black_up.png' alt='more_info_on_post_button_black_up_button_alt' class='more_info_on_post_button_black_up_btn' id ='more_info_on_post_button_black_up_btn_id'></img>
<div class = 'date_added_on_post_class' id = 'date_added_on_post_id'>$date_time</div>
<div class = 'update_post_class' id = 'update_post_id'>$update_button</div>
<div class = 'delete_post_class_div' id = 'delete_post_id'>$delete_button</div>
<div id='post_body' dir=auto>
$body
</div>
</div>
</div>
<div class='span_class' id='span_id' onclick='myFunction$id()' >Comments($comments_check_num) </div>
<hr>
<div class='post_comment' id='toggleComment$id' >
<iframe src='comment_frame.php?post_id=$id' class = 'comment_iframe_class' id='comment_iframe' frameborder='0'></iframe>
</div>
<hr class ='hr'>";
}
echo $str;
}
}
?>
$('.posts_area').html(data);
Use this instead of append()

How to implementing EasyPay Pakistan Payment gateway in WordPress?

Hi Everyone I am trying to implement the EasyPay Pakistan payment gateway for my website but i am getting this error Parameter Authentication failed my code is below which is in plugin they provided:
<?php
require '../../../wp-config.php';
$storeId = get_option('storeId');
$daysToExpire = get_option('daysToExpire');
$live = get_option('live');
$liveVal = $live['menu'];
$easypayIndexPage = '';
if ($liveVal == 'no') {
$easypayIndexPage = 'https://easypaystg.easypaisa.com.pk/easypay/Index.jsf';
} else {
$easypayIndexPage = 'https://easypay.easypaisa.com.pk/easypay/Index.jsf';
}
$merchantConfirmPage = home_url().'/wp-content/plugins/Easypay/confirmEasypay.php';
$options = get_option('autoRedirect');
//$autoRedirect = checked( isset( $options['autoRedirectCb'] ) );
$autoRedirect = checked( isset( $options['autoRedirectCb'] ),1,false );
if($autoRedirect) {
$autoRedirect = 1;
} else {
$autoRedirect = 0;
}
$orderId = $_GET['orderId'];
if (strpos($_GET['amount'], '.') !== false) {
$amount = $_GET['amount'];
} else {
$amount = sprintf("%0.1f",$_GET['amount']);
}
$custEmail = $_GET['custEmail'];
$custCell = $_GET['custCell'];
$hashKey = get_option('hashKey');
date_default_timezone_set('Asia/Karachi');
$expiryDate = '';
$currentDate = new DateTime();
if($daysToExpire != null) {
$currentDate->modify('+'.$daysToExpire.'day');
$expiryDate = $currentDate->format('Ymd His');
}
$paymentMethods = get_option('paymentMethod');
$paymentMethodVal = $paymentMethods['methods'];
$hashRequest = '';
if(strlen($hashKey) > 0 && (strlen($hashKey) == 16 || strlen($hashKey) == 24 || strlen($hashKey) == 32 )) {
// Create Parameter map
$paramMap = array();
$paramMap['amount'] = $amount ;
$paramMap['autoRedirect'] = $autoRedirect ;
if($custEmail != null && $custEmail != '') {
$paramMap['emailAddr'] = $custEmail ;
}
if($expiryDate != null && $expiryDate != '') {
$paramMap['expiryDate'] = $expiryDate;
}
if($custCell != null && $custCell != '') {
$paramMap['mobileNum'] = $custCell;
}
$paramMap['orderRefNum'] = $orderId ;
if($paymentMethodVal != null && $paymentMethodVal != '') {
$paramMap['paymentMethod'] = $paymentMethodVal ;
}
$paramMap['postBackURL'] = $merchantConfirmPage;
$paramMap['storeId'] = $storeId ;
//Creating string to be encoded
$mapString = '';
foreach ($paramMap as $key => $val) {
$mapString .= $key.'='.$val.'&';
}
$mapString = substr($mapString , 0, -1);
// Encrypting mapString
$ivlen = openssl_cipher_iv_length($cipher="AES-128-ECB");
$iv = openssl_random_pseudo_bytes($ivlen);
$crypttext = openssl_encrypt($mapString, $cipher, $hashKey,OPENSSL_RAW_DATA, $iv);
$hashRequest = base64_encode($crypttext);
}
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
die('Could not connect: ' . mysqli_errno());
}
mysqli_select_db($con, DB_NAME);
global $wpdb;
$table_name = $wpdb->prefix . 'easypay_order';
// mysql inserting an order with pending status
$query = "INSERT INTO ".$table_name."( easypay_order_id, easypay_order_info, easypay_order_status, ipn_attr ) VALUES ('$orderId' ,'null', 'pending', 'null')";
try {
mysqli_query($con, $query);
} catch (Exception $ex) {
error_log($ex->getMessage());
}
// echo $easypayIndexPage;
//echo "\r\n".$storeId;
// echo $amount;
//echo $merchantConfirmPage;
//echo $orderId;
// echo $hashRequest;
//<?php header("Location: $easypayIndexPage") ?>
<form name="easypayform" method="post" action="<?php echo $easypayIndexPage; ?>">
<input name="storeId" value="<?php echo $storeId ?>" hidden = "true" readOnly="true" />
<input name="amount" value="<?php echo $amount ?>" hidden = "true"/>
<input name="postBackURL" value="<?php echo $merchantConfirmPage ?>" hidden = "true" readOnly="true" />
<input name="orderRefNum" value="<?php echo $orderId ?>" hidden = "true" readOnly="true" />
<?php if ($expiryDate != '' && $expiryDate != null) { ?>
<input name="expiryDate" value="<?php echo $expiryDate ?>" hidden = "false"/>
<?php } ?>
<input name="autoRedirect" value="<?php echo $autoRedirect ?>" hidden = "true"/>
<input name="emailAddr" value="<?php echo $custEmail ?>" hidden = "true"/>
<input name="mobileNum" value="<?php echo $custCell ?>" hidden = "true"/>
<input name="merchantHashedReq" value="<?php echo $hashRequest ?>" hidden = "true"/>
<input name="paymentMethod" value="<?php echo $paymentMethodVal ?>" hidden = "true"/>
</form>
<script data-cfasync="false" type="text/javascript">
document.easypayform.submit();
</script>
When I click on Proceed to easypay nothing appears on the page and just white black page appears, so after research I came to know that this below written code is not working:
<script data-cfasync="false" type="text/javascript">
document.easypayform.submit();
</script>
Therefore I added this line of code into my form so that I can manually click the button so redirect to EasyPay page.
<input type = "submit" value="Submit">
Now, when clicking on the submit button it is redirecting to EasyPay page but this error occurs saying Parameter Authentication failed.
So, is there anyone who can help me out in this implementation because there support team is not helpful.
I will be very thankful for your help.
This EasyPay plugin can't accept payment values greater than 2 decimals, so, by going in Woo-Commerce plugin in the currency's setting and changing number of decimals to 1 the EasyPay plugin issue will be resolve.

Carousel need to start from middle slide on page load

I have using Multi Carousel to display complete months dates in a slider. Each date some data be hide on click. When I browse to Multi Carousel clicked date is today,s date, Means active class for slides is current date.
But as slider have 30 days. so slider always start from day 1. I always need to slide it to current date by clicking next arrow.
Like today is sep-26. If you check following page you find a date slider there which is on sep-1 now. so to get sep-26 you need to slide next. http://prosport.guru/ps/game.php
I want that when page load slider should moves to current date auto. I have add auto class to current date slide but it did not work.
Following is my code for Multi Carousel.
<?php
$page2 = $_SERVER["PHP_SELF"];
$page2 = explode("/", $page2);
$page2 = $page2[count($page2) - 1];
$id_sport2 = $_GET["id_sport"];
$m = date("m");
$day = date("d");
$year = date("Y");
$dates = array();
$dates2 = array();
$tmp = array();
for ($i = 1; $i < 32; $i++) {
if ($i < 10) {
$ii = "0$i";
} else {
$ii = $i;
}
$date = "$year-$m-$ii";
//$date = date("Y-m-d", strtotime($date));
if ($i % 3 != 0) {
array_push($tmp, $date);
if ($i == 60) {
if (count($tmp != 0)) {
array_push($dates2, $tmp);
}
}
} else {
array_push($tmp, $date);
array_push($dates2, $tmp);
$tmp = array();
}
array_push($dates, $date);
}
///print_r($dates2);
?>
<div class="row" style="border:1px solid silver; background: #a0a0a0; color: white; ">
<div class="MultiCarousel" data-items="1,3,5,6" data-slide="3" id="MultiCarousel2" data-interval="1000" >
<div class="MultiCarousel-inner">
<?php
$cpt = 0;
for ($i = 0; $i < count($dates2); $i++) {
$line = $dates2[$i];
$today = date("Y-m-d");
if (empty($_GET["date"])) {
$goto = $today;
if (in_array($today, $line)) {
$active = "active";
} else {
$active = "";
}
} else {
$dt = $_GET["date"];
$goto = $dt;
if (in_array($dt, $line)) {
$active = "active";
} else {
$active = "";
}
}
for ($x = 0; $x < count($line); $x++) {
$el = $line[$x];
if (!empty($_GET["date"])) {
$dt = $_GET["date"];
if ($el == $dt) {
$color = "red";
} else {
$color = "white";
}
} else {
if ($el == $today) {
$color = "red";
} else {
$color = "white";
}
}
$href = "$page2?id_sport=$id_sport2&date=$el";
if ($x == 0) {
//echo "<div class='col-lg-1 col-xs-1'> </div>";
//echo "<div class='col-lg-10 col-xs-10'>";
}
/* echo ' <div class="col-md-4 col-xs-4 col-lg-4 ">
'.$el.'</div>';
*/
if ($x == 2) {
//echo "</div>";
}
?>
<div class="item " style="text-align:center">
<a href="<?php echo $href; ?>" >
<p class=" sportName mydate p-date" real="<?php echo $el; ?>" style="color:white; font-size: 12px; text-align: center;" >
<?php
$date = $el;
$month_name = ucfirst(strftime("%b", strtotime($date)));
$day_number = ucfirst(strftime("%d", strtotime($date)));
echo $month_name . ' ' . $day_number;
?>
</p>
</a>
</div>
<?php
}
}
echo "<input type='hidden' value='$goto' id='cd'>";
?>
</div>
<button class="btn btn-primary btn-sm leftLst" style="border-radius: 0px; top: calc(64% - 20px);"><</button>
<button class="btn btn-primary btn-sm rightLst fw" style="border-radius: 0px; top: calc(64% - 20px);">></button>
</div></div>
<script>
$(document).ready(function () {
var cd = $("#cd").val();
$(".mydate").each(function () {
var cd_tmp = $(this).attr("real");
if (cd_tmp != cd) {
//alert(cd_tmp+" is different from "+cd);
//$(".fw").click();
} else {
$(this).addClass("tag tag-danger active");
//break;
}
})
})
</script>
This jquery script will move it to the current date on page load.
$(function() {
// Get month and day, ex. "Sep 21"
var monthAndDay = new Date().toLocaleString("en-us", { month: "short" }) + ' ' + new Date().getDate();
// Locate the carousel item using month and day string
var $list = $('#MultiCarousel2 > div .item');
var $carouselToday = $('#MultiCarousel2 > div .item a p:contains('+monthAndDay+')');
var $parent = $carouselToday.closest('.item');
var index = $list.index( $parent );
var itemWidth = $list.eq(0).width();
var position = (index * itemWidth) * -1;
$('#MultiCarousel2 > div').css({"transition": "0s", "transform": "translate("+ position +"px)"});
$('#MultiCarousel2 > div').one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() {
$(this).css({"transition": "1s ease all"})
});
});

PHP post variable is not being rendered

I have a PHP program that takes in a image name and loads the image and displays the name and the image on the page.
The variable in javascrip is written as
var latest_image_name = '<?=$post_img_name?>';
The PHP code is
<?php
foreach($files_assoc_array_keys as $file_name){
if($file_name==$post_img_name){
?>
<label class="lbl_image_name active"><?=$file_name?></label>
<?php
}else{
?>
<label class="lbl_image_name"><?=$file_name?></label>
<?php
}
}
?>
the html output, is being rendered as
<div id="image_list_wrapper">
<label class="lbl_image_name"><?=$file_name?></label>
</div>
And as you can see it seems that PHP has not replaced the tag with the posted image name.
The code works on the original server that it was developed on, it does not work when i migrated it to another server, i have tried two other servers both Centos 6.4 with apache and PHP installed. I am not sure what the setup was for the original server that it as does work on.
the full code is seen below
<?php
header('Refresh: 5; URL=display.php');
print_r($_POST['post_img_name']);
$target_directory = "uploaded_images";
if(!file_exists($target_directory)){
mkdir($target_directory);
}
if(isset($_POST['del_image'])) {
$del_image_name = $_POST['del_img_name'];
if(file_exists($target_directory."/".$del_image_name.".jpg")){
unlink($target_directory."/".$del_image_name.".jpg");
}
if(is_dir_empty($target_directory)){
die("Last image delete. No images exist now.");
}
$post_img_name = basename(get_latest_file_name($target_directory), '.jpg');
}else if(isset($_POST['post_img_name'])){
$post_img_name=$_POST['post_img_name'];
$post_img_temp_name = $_FILES['post_img_file']['tmp_name'];
}else{
$post_img_name = basename(get_latest_file_name($target_directory), '.jpg');
}
$files_array = new DirectoryIterator($target_directory);
$total_number_of_files = iterator_count($files_array) - 2;
$files_assoc_array = array();
$already_exists = "false";
if($total_number_of_files != 0){
foreach ($files_array as $file_info){
$info = pathinfo( $file_info->getFilename() );
$filename = $info['filename'];
if ($filename==$post_img_name) {
$already_exists = "true";
}
}
}
if(!isset($_POST['del_image']) && isset($_POST['post_img_name'])){
$target_file = "$target_directory"."/".$post_img_name.".jpg";
$source_file = $post_img_temp_name;
if($already_exists == "true"){
unlink($target_file);
}
move_uploaded_file($source_file, $target_file);
}
foreach ($files_array as $file_info){
$info = pathinfo( $file_info->getFilename() );
$filename = $info['filename'];
if(!$file_info->isDot()){
$files_assoc_array[$filename] = $target_directory."/".$file_info->getFilename();
}
}
$files_assoc_array_keys = array_keys($files_assoc_array);
function get_latest_file_name($target_directory){
$files_array = new DirectoryIterator($target_directory);
$total_number_of_files = iterator_count($files_array) - 2;
$timestamps_array = array();
if($total_number_of_files!=0){
foreach($files_array as $file){
if(!$file->isDot()){
$timestamps_array[filemtime($target_directory."/".$file)] = $file->getFilename();
}
}
}
$max_timestamp = max(array_keys($timestamps_array));
return $timestamps_array[$max_timestamp];
}
function is_dir_empty($dir) {
if (!is_readable($dir))
return NULL;
$handle = opendir($dir);
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
return FALSE;
}
}
return TRUE;
}
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="css/style.css"/>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
var files_array_text = '<?php echo implode(", ", $files_assoc_array)?>';
var files_array_keys_text = '<?php echo implode(", ", $files_assoc_array_keys)?>';
var files_array = files_array_text.split(", ");
var files_array_keys = files_array_keys_text.split(", ");
var files_assoc_array = createAssociativeArray(files_array_keys, files_array);
var latest_image_name = '<?=$post_img_name?>';
display_image(latest_image_name);
$('.lbl_image_name').click(function(){
$('#img_loading').show();
$('#img_display').hide();
var image_name = $(this).text();
$('.active').removeClass('active');
$(this).addClass('active');
display_image(image_name);
});
function createAssociativeArray(arr1, arr2) {
var arr = {};
for(var i = 0, ii = arr1.length; i<ii; i++) {
arr[arr1[i]] = arr2[i];
}
return arr;
}
function display_image(image_name){
var image_path = files_assoc_array[image_name];
$('#img_display').attr('src', image_path);
$('#img_display').load(image_path, function(){
$('#img_loading').hide();
$('#img_display').show();
})
}
});
</script>
</head>
<body>
<div id="container">
<div id="image_list_wrapper">
<?php
foreach($files_assoc_array_keys as $file_name){
if($file_name==$post_img_name){
?>
<label class="lbl_image_name active"><?=$file_name?></label>
<?php
}else{
?>
<label class="lbl_image_name"><?=$file_name?></label>
<?php
}
}
?>
</div>
<div class="separator"></div>
<div id="image_display_wrapper">
<div id="img_loading_wrapper">
<img src="images/loading.gif" id="img_loading"/>
</div>
<img src="" id="img_display"/>
</div>
<div style="clear: both">
</div>
</div>
Go Back
</body>
</html>
As arbitter has pointed out my server did not support <?= ... ?> it worked after i changed to <?php print $variable_name ?>

Categories

Resources