How I add a class css to php? - html

function autoDate()
{
for ($i = 1; $i <= date("t"); $i++) {
echo "<li>" . $i . "</li>";
if ($i == date("j")) {
???
}
}
}
I need to put class "active" when date of today is true...

If you are intending to add the active class to the list, then you should do that before you echo your list:
function autoDate() {
for ($i = 1; $i <= date("t"); $i++) {
echo "<li" . ($i == date("j") ? ' class="active"' : '') . ">" . $i . "</li>";
}
}

I think you should code here:
function autoDate() {
$data = "";
for ($i = 1; $i <= date("t"); $i++) {
$data .= "<li>" . $i . "</li>";
if ($i == date("j")) {
$data .= "<li class='abc' >" . $i . "</li>";
}
}
echo $data;
}

function autoDate()
{
for ($i = 1; $i <= date("t"); $i++) {
$class = '';
if($i == date("j")){
$class = 'active';
}
echo "<li class='".$class."'>" . $i . "</li>";
}
}
Try this one.
by default $class is empty and if date matched then $class = 'active'

Related

PHP Mysql - adding an empty row can't figure it out

Here is the table code - when this is printed out the has one empty row at the bottom. I am not sure why the last row is added? Is it perhaps the if else statement?
<?php
$row = mysql_fetch_array($result);
if ($row['Price'] == '0.00') {
echo "<TABLE width='100%'>\n";
echo "<TR><TD id=tblrowsHead2>Item</TD><TD id=tblrowsHead2>Size</TD><TD
id=tblrowsHead2>Contact</TD></TR>\n";
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD id=Size>" . $row['Item'] . "</TD><TD id=Size>" . $row['Size']
. "</TD>
<TD id=Price>Contact Us</TD>\n";
}
} else {
echo "<TABLE width='100%'>\n";
echo "<TR><TD id=tblrowsHead2>Item</TD><TD id=tblrowsHead2>Size</TD><TD
id=tblrowsHead2>Price</TD></TR>\n";
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD id=Size>" . $row['Item'] . "</TD><TD id=Size>" . $row['Size']
. "</TD>
<TD id=Price>$" . $row['Price'] . "</TD>\n";
}
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
Try this code instead:
<?php
$row = mysql_fetch_array($result);
$i = 0;
if ($row['Price'] == '0.00') {
echo "<TABLE width='100%'>\n";
echo "<TR><TD id=tblrowsHead2>Item</TD><TD id=tblrowsHead2>Size</TD><TD id=tblrowsHead2>Contact</TD></TR>\n";
do {
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo '<TD id=Size>'.$row['Item'].'</TD><TD id=Size>'.$row['Size'].'</TD>';
echo "<TD id=Price>Contact Us</TD></TR>\n";
$i++;
} while ($row = mysql_fetch_array($result)); //get a row from our result set
} else {
do {
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo '<TD id=Size>'.$row['Item'].'</TD><TD id=Size>'.$row['Size'].'</TD>';
echo "<TD id=Price>$" . $row['Price'] . "</TD></TR>\n";
$i++;
} while ($row = mysql_fetch_array($result)); //get a row from our result set
}
//now let's close the table and be done with it
echo "</TABLE>\n";
When you using the mysql_fetch_array at the first line of for-loop, you will lost the first record of your data-table, so you will have an empty line at the end

Sage Pay v3.00 Integration

Can anyone help me incorporate the Sagepay v3.00 AES/CBC/PKCS#5 algorithm (encryption) into the following file. I'm really struggling to understand how to include so that customer data is encrypted to the new standard and then decrypted on the way back. Using Sagepay Form with a very old version of cs-cart, though have successfully managed to upgrade from version 2.22 to 2.23, but Sagepay are pulling all support from July.
Not sure how much of this script is relevant to the encryption:
<?php
if ( !defined('IN_CSCART') ) { die('Access denied'); }
if (defined('PAYMENT_NOTIFICATION')) {
// Get the password
$payment_id=db_get_field("SELECT $db_tables[payments].payment_id FROM $db_tables[payments] LEFT JOIN $db_tables[payment_processors] ON $db_tables[payment_processors].processor_id = $db_tables[payments].processor_id WHERE $db_tables[payment_processors].processor_script='protx_form.php'");
$processor_data = fn_get_payment_method_data($payment_id);
$result = "&".simpleXor(base64Decode($_REQUEST['crypt']), $processor_data["params"]["password"])."&";
preg_match("/Status=(.+)&/U", $result, $a);
if(trim($a[1]) == "OK") {
$pp_response['order_status'] = ($processor_data["params"]["transaction_type"] == 'PAYMENT') ? 'P' : 'O';
preg_match("/TxAuthNo=(.+)&/U", $result, $authno);
$pp_response["reason_text"] = "AuthNo: ".$authno[1];
preg_match("/VPSTxID={(.+)}/U", $result, $transaction_id);
$pp_response["transaction_id"] = #$transaction_id[1];
} else {
$pp_response['order_status'] = 'F';
preg_match("/StatusDetail=(.+)&/U", $result, $stat);
$pp_response["reason_text"] = "Status: ".trim($stat[1])." (".trim($a[1]).") ";
}
preg_match("/AVSCV2=(.*)&/U", $result, $avs);
if(!empty($avs[1])) {
$pp_response['descr_avs'] = $avs[1];
}
include $payment_files_dir.'payment_cc_complete.php';
fn_order_placement_routines($order_id);
}
else
{
global $http_location, $b_order, $_total_back;
$post_address = ($processor_data['params']['testmode'] != "N") ? "https://test.sagepay.com/gateway/service/vspform-register.vsp" : "https://live.sagepay.com/gateway/service/vspform-register.vsp";
$post["VPSProtocol"] = "2.23";
$post["TxType"] = $processor_data["params"]["transaction_type"];
$post["Vendor"] = htmlspecialchars($processor_data["params"]["vendor"]);
// Form Cart products
$strings = 0;
if (is_array($cart['products'])) {
$strings += count($cart['products']);
}
if (!empty($cart['products'])) {
foreach ($cart['products'] as $v) {
$_product = db_get_field("SELECT product FROM $db_tables[product_descriptions] WHERE product_id='$v[product_id]' AND lang_code='$cart_language'");
$products_string .= ":".str_replace(":", " ", $_product).":".$v['amount'].":".fn_format_price($v['subtotal']/$v['amount']).":::".fn_format_price($v['subtotal']);
}
}
if (!empty($cart['payment_surcharge'])) {
$products_string .= ":Payment surcharge:---:---:---:---:".fn_format_price($cart['payment_surcharge']);
$strings ++;
}
if (!empty($cart['shipping_cost'])) {
$products_string .= ":Shipping cost:---:---:---:---:".fn_format_price($cart['shipping_cost']);
$strings ++;
}
$post_encrypted .= "Basket=".$strings.$products_string;
$post["Crypt"] = base64_encode(simpleXor($post_encrypted, $processor_data["params"]["password"]));
$post["Crypt"] = htmlspecialchars($post["Crypt"]);
$msg = fn_get_lang_var('text_cc_processor_connection');
$msg = str_replace('[processor]', 'Protx Server', $msg);
echo <<<EOT
<html>
<body onLoad="document.process.submit();">
<form action="{$post_address}" method="POST" name="process">
<INPUT type=hidden name="VPSProtocol" value="{$post['VPSProtocol']}">
<INPUT type=hidden name="Vendor" value="{$post['Vendor']}">
<INPUT type=hidden name="TxType" value="{$post['TxType']}">
<INPUT type=hidden name="Crypt" value="{$post['Crypt']}">
<p>
<div align=center>{$msg}</div>
</p>
</body>
</html>
EOT;
}
exit;
//
// ---------------- Additional functions ------------
//
function simpleXor($InString, $Key) {
$KeyList = array();
$output = "";
for($i = 0; $i < strlen($Key); $i++){
$KeyList[$i] = ord(substr($Key, $i, 1));
}
for($i = 0; $i < strlen($InString); $i++) {
$output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
}
return $output;
}
function base64Decode($scrambled) {
// Initialise output variable
$output = "";
// Fix plus to space conversion issue
$scrambled = str_replace(" ","+",$scrambled);
// Do encoding
$output = base64_decode($scrambled);
// Return the result
return $output;
}
?>
You could try dropping the following functions into the script, then swapping out simpleXor for encryptAes. Make sure that you also add an '#' symbol as the first character of the crypt string (and strip it off when decoding the response from Sage Pay).
function addPKCS5Padding($input)
{
$blockSize = 16;
$padd = "";
$length = $blockSize - (strlen($input) % $blockSize);
for ($i = 1; $i <= $length; $i++)
{
$padd .= chr($length);
}
return $input . $padd;
}
function removePKCS5Padding($input)
{
$blockSize = 16;
$padChar = ord($input[strlen($input) - 1]);
$unpadded = substr($input, 0, (-1) * $padChar);
return $unpadded;
}
function encryptAes($string, $key)
{
$string = addPKCS5Padding($string);
$crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $key);
return strtoupper(bin2hex($crypt));
}
function decryptAes($strIn, $password)
{
$strInitVector = $password;
$strIn = pack('H*', $hex);
$string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, $strIn, MCRYPT_MODE_CBC,$strInitVector);
return removePKCS5Padding($string);
}
You could try this. I can't test it, so let me know how you get on.
<?php
if ( !defined('IN_CSCART') ) { die('Access denied'); }
if (defined('PAYMENT_NOTIFICATION')) {
// Get the password
$payment_id=db_get_field("SELECT $db_tables[payments].payment_id FROM $db_tables[payments] LEFT JOIN $db_tables[payment_processors] ON $db_tables
[payment_processors].processor_id = $db_tables[payments].processor_id WHERE $db_tables[payment_processors].processor_script='protx_form.php'");
$processor_data = fn_get_payment_method_data($payment_id);
#Rik added:
$result = "&".decryptAes($_REQUEST['crypt'], $processor_data["params"]["password"])."&";
#$result = "&".simpleXor(base64Decode($_REQUEST['crypt']), $processor_data["params"]["password"])."&";
preg_match("/Status=(.+)&/U", $result, $a);
if(trim($a[1]) == "OK") {
$pp_response['order_status'] = ($processor_data["params"]["transaction_type"] == 'PAYMENT') ? 'P' : 'O';
preg_match("/TxAuthNo=(.+)&/U", $result, $authno);
$pp_response["reason_text"] = "AuthNo: ".$authno[1];
preg_match("/VPSTxID={(.+)}/U", $result, $transaction_id);
$pp_response["transaction_id"] = #$transaction_id[1];
} else {
$pp_response['order_status'] = 'F';
preg_match("/StatusDetail=(.+)&/U", $result, $stat);
$pp_response["reason_text"] = "Status: ".trim($stat[1])." (".trim($a[1]).") ";
}
preg_match("/AVSCV2=(.*)&/U", $result, $avs);
if(!empty($avs[1])) {
$pp_response['descr_avs'] = $avs[1];
}
include $payment_files_dir.'payment_cc_complete.php';
fn_order_placement_routines($order_id);
}
else
{
global $http_location, $b_order, $_total_back;
$post_address = ($processor_data['params']['testmode'] != "N") ? "https://test.sagepay.com/gateway/service/vspform-register.vsp" :
"https://live.sagepay.com/gateway/service/vspform-register.vsp";
$post["VPSProtocol"] = "2.23";
$post["TxType"] = $processor_data["params"]["transaction_type"];
$post["Vendor"] = htmlspecialchars($processor_data["params"]["vendor"]);
// Form Cart products
$strings = 0;
if (is_array($cart['products'])) {
$strings += count($cart['products']);
}
if (!empty($cart['products'])) {
foreach ($cart['products'] as $v) {
$_product = db_get_field("SELECT product FROM $db_tables[product_descriptions] WHERE product_id='$v[product_id]' AND lang_code='$cart_language'");
$products_string .= ":".str_replace(":", " ", $_product).":".$v['amount'].":".fn_format_price($v['subtotal']/$v['amount']).":::".fn_format_price($v
['subtotal']);
}
}
if (!empty($cart['payment_surcharge'])) {
$products_string .= ":Payment surcharge:---:---:---:---:".fn_format_price($cart['payment_surcharge']);
$strings ++;
}
if (!empty($cart['shipping_cost'])) {
$products_string .= ":Shipping cost:---:---:---:---:".fn_format_price($cart['shipping_cost']);
$strings ++;
}
$post_encrypted .= "Basket=".$strings.$products_string;
#Rik added:
$post["Crypt"] = "#".encryptAes($post_encrypted, $processor_data["params"]["password"]);
# $post["Crypt"] = base64_encode(simpleXor($post_encrypted, $processor_data["params"]["password"]));
# $post["Crypt"] = htmlspecialchars($post["Crypt"]);
$msg = fn_get_lang_var('text_cc_processor_connection');
$msg = str_replace('[processor]', 'Protx Server', $msg);
echo <<<EOT
<html>
<body onLoad="document.process.submit();">
<form action="{$post_address}" method="POST" name="process">
<INPUT type=hidden name="VPSProtocol" value="{$post['VPSProtocol']}">
<INPUT type=hidden name="Vendor" value="{$post['Vendor']}">
<INPUT type=hidden name="TxType" value="{$post['TxType']}">
<INPUT type=hidden name="Crypt" value="{$post['Crypt']}">
<p>
<div align=center>{$msg}</div>
</p>
</body>
</html>
EOT;
}
exit;
//
// ---------------- Additional functions ------------
//
function simpleXor($InString, $Key) {
$KeyList = array();
$output = "";
for($i = 0; $i < strlen($Key); $i++){
$KeyList[$i] = ord(substr($Key, $i, 1));
}
for($i = 0; $i < strlen($InString); $i++) {
$output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
}
return $output;
}
function base64Decode($scrambled) {
// Initialise output variable
$output = "";
// Fix plus to space conversion issue
$scrambled = str_replace(" ","+",$scrambled);
// Do encoding
$output = base64_decode($scrambled);
// Return the result
return $output;
}
#added by Rik
function addPKCS5Padding($input)
{
$blockSize = 16;
$padd = "";
$length = $blockSize - (strlen($input) % $blockSize);
for ($i = 1; $i <= $length; $i++)
{
$padd .= chr($length);
}
return $input . $padd;
}
function removePKCS5Padding($input)
{
$blockSize = 16;
$padChar = ord($input[strlen($input) - 1]);
$unpadded = substr($input, 0, (-1) * $padChar);
return $unpadded;
}
function encryptAes($string, $key)
{
$string = addPKCS5Padding($string);
$crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $key);
return strtoupper(bin2hex($crypt));
}
function decryptAes($strIn, $password)
{
#Sagepay specific - remove the '#'
$strIn = substr($strIn,1)
$strInitVector = $password;
$strIn = pack('H*', $hex);
$string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, $strIn, MCRYPT_MODE_CBC,$strInitVector);
return removePKCS5Padding($string);
}
?>
/*First build your data. */
$data = 'variableA='.$this->variableA;
$data .= '&variableB='.$this->variableB;
...
$data .= '&variableZ='.$this->variableZ;
/** Encript data */
$dataEncrip = $this->encData($data);
/** function to Encrypt *//
public function encData($data){
$data = $this->pkcs5_pad( $data, 16);
$dataEnc = "#".bin2hex( mcrypt_encrypt( MCRYPT_RIJNDAEL_128,
$this->passwordToEncript,
$data,
MCRYPT_MODE_CBC,
$this->getPasswordToEncrypt()));
return $dataEnc;
}
/** Pkcs5_pad */
public function pkcs5_pad( $data, $blocksize ){
$pad = $blocksize - (strlen( $data ) % $blocksize);
return $data . str_repeat( chr( $pad ), $pad );
}

Php mysql fetch result

I've made a script for movies but i have an issue.
The home of script is contain code like this :
<div class="box">
<div id="movie"></div><div id="movie"></div><div id="movie"></div>
</div>
I've do a mysql query but i don't know how to echo just 3 record per div .
Im using this code for mysql query :
$query=mysql_query("select * from movies where id=$id");
while($row=mysql_fetch_assoc($query))
{
echo $row['name'];
}
You will need something like this I think
$query = mysql_query("select * from movies");
$result = array();
while($r = mysql_fetch_assoc($query)) {
$result[$r['id']] = array($r['name'],$r['thumb']);
}
$i = 0;
foreach($result as $id => $data){
if($i == 0)
{
echo "<div class=\"box\">";
echo "<div id=\"movie\">";
echo "ID: $id";
echo "Name: $data[0]";
echo "Thumb: $data[1]";
echo "</div>";
$i = $i + 1;
}
elseif($i == 1)
{
echo "<div id=\"movie\">";
echo "ID: $id";
echo "Name: $data[0]";
echo "Thumb: $data[1]";
echo "</div>";
$i = $i + 1;
}
elseif($i == 2)
{
echo "<div id=\"movie\">";
echo "ID: $id";
echo "Name: $data[0]";
echo "Thumb: $data[1]";
echo "</div>";
echo "</div>";
$i = 0;
}
}
Multiple elements with the same id? Not a good idea.
You didn't say what you want to happen if you're query returns less then 3 rows.
You might try:
...
$x=0;
while($row=mysql_fetch_assoc($query) && ++$x<=3) {
echo $row['name'];
}

PHPEXCEL mysql php insert empty rows

I am trying to use phpexcel to let users upload a spreadsheet and insert into mysql. I have it working except if the user has blank rows in the spreadsheet it puts several unnecessary rows in the database. I have read and mysql doesnt support check constraints and most of that would need to be done at the application level which is what I am trying to do. How in PHP could have it check if a specific column is empty and skip that row. Any help would be appreciated or if there is a better solution I am up for all options. I was trying for a while to get it that is the bldg column was empty than just skip that row but wasnt having any luck..
<?php require '../Classes/PHPExcel.php';
require_once '../Classes/PHPExcel/IOFactory.php';
$path = "../upload/uploads/$Filename";
$objPHPExcel = PHPExcel_IOFactory::load($path);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow();
$highestColumn = 'L'; // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
$objReader = PHPExcel_IOFactory::createReaderForFile($path);
$objReader->setReadDataOnly(true);
echo '<br>Data: <table width="100%" cellpadding="3" cellspacing="0"><tr>';
for ($row = 16; $row <= $highestRow; ++ $row) {
echo '<tr>';
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
if($row === 1)
echo '<td style="background:#000; color:#fff;">' . $val . '</td>';
else
echo '<td>' . $val . '</td>';
}
echo '</tr>';
}
echo '</table>';
for ($row = 16; $row <= $highestRow; ++ $row) {
$val=array();
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val[] = $cell->getValue();
}
$sql="insert into excess1(date_excessed, bldg, floor, jack, equipment_owner, contact_name, contact_phone, qty, type_of_excess, asset_tag, service_tag, comments)
values('".$val[0] . "','" . $val[1] . "','" . $val[2]. "','" . $val[3]. "','" . $val[4]. "','" . $val[5]. "','".$val[6] . "','".$val[7] . "','".$val[8] . "','".$val[9] . "','".$val[10] . "','".$val[11] . "')";
$result = mysql_query($sql) or die(mysql_error());
print "$result";
}
}
unlink("../upload/uploads/$Filename");
?>
</article>
$inputFileType = PHPExcel_IOFactory::identify($filename);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
$i=0;
foreach ($allDataInSheet as $value) {
if ($value === null){
continue;
} //this is skipping empty rows
$data[$i] = $value['A'];
$data[$i] = $value['B'];
$i++;
}

How can I paginate within a while loop?

I basically need to have take some videos information out of a database with a while loop and put them into a div. The only issue is that I need to put only 6 at a time in between a and tag and have it go to the next 6 and so forth. Here's my code:
$count = 0;
$sql = "SELECT * FROM videos ORDER BY id DESC";
$result_set = $database->query($sql);
while($videos = $database->fetch_array($result_set)) {
$count++;
// i know this is horribly wrong...
if($count == 0 || (($count % 6)+1 == 1)) {
echo '<div>';
}
// i need 6 videos to go in between the <div> and </div> tags then go on to another 6
echo "{$videos['title']}";
if($count == 0 || (($count % 6)+1 == 1)) {
echo '<div>';
}
}
This is an efficent way to do what you want:
$resultPerPage = 6;
$count = 0;
$sql = "SELECT * FROM videos ORDER BY id DESC";
$result_set = $database->query($sql);
$noPage = 1;
echo '<div id="page_1" class="pages">';
while($videos = $database->fetch_array($result_set)) {
$count++;
echo "{$videos['title']}";
if($count == $resultPerPage) {
echo '</div><div id="page_' . $noPage++ . '" class="pages">';
$count=0;
}
}
echo '</div>';