I just can't get this to work, basically Im displaying the files on a ftp server, which works fine, but some of the folder names have german characters like ä ö ü or french characters. I placed the line below into the php code to see if it helps but it only gets rid of the french characters, however the german characters still have the � icon instead of the actual character...
header('Content-Type: text/html; charset=utf-8');
I would appreciate any help. Below is the whole file:
import.php
<html>
<head>
<title>Import</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/import.css"/>
<style type="text/css">
.folder_hilighted table tr td div.name_tag_name{
background: #75B323;
color: #ffffff;
border-radius: 20px;
text-shadow: 0px -1px 0px #5D855A;
}
</style>
</head>
<body><br>
<table width="100%" cellspacing="0" cellpadding="0"><tr><td>
<ul class="folders">
<?php
ini_set("max_execution_time",100000);
$folder = $_GET['folder'];
// set up basic connection
$ftp_server = "xxx.xxx.xx.xx";
$ftp_user_name = "admin";
$ftp_user_pass = "password";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// get the file list for /
if($folder==""){
$buff = ftp_nlist($conn_id, '/array1/MediaBox/iTunes/');
}
else{
$buff = ftp_nlist($conn_id, '/array1/MediaBox/iTunes/'.$folder.'/');
}
// close the connection
ftp_close($conn_id);
// output the buffer
for($i=0;$i<=sizeof($buff)-1;$i++){
if(is_dir('ftp://'.$ftp_user_name.':'.$ftp_user_pass.'#'.$ftp_server.$buff[$i]) && $buff[$i]!="/array1/MediaBox/iTunes/Mobile Applications" && $buff[$i]!="/array1/MediaBox/iTunes/Automatically Add to iTunes.localized" && $buff[$i]!="/array1/MediaBox/iTunes/Books" && $buff[$i]!="/array1/MediaBox/iTunes/Tones"){
if($folder==""){
$folder_name = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
$folder_name = mb_convert_encoding($folder_name, 'UTF-8', mb_detect_encoding($folder_name));
$folder_name = htmlspecialchars($folder_name, ENT_QUOTES, 'UTF-8');
}
else{
$folder_name = str_replace(array("/array1/MediaBox/iTunes/".$folder."/"), array(""), $buff[$i]);
$folder_name = mb_convert_encoding($folder_name, 'UTF-8', mb_detect_encoding($folder_name));
$folder_name = htmlspecialchars($folder_name, ENT_QUOTES, 'UTF-8');
$last_folder = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
$last_folders = explode("/", $last_folder);
for($k=0;$k<=count($last_folders);$k++){
if($k==count($last_folders)){
$prev_folder = $last_folders[$k-3];
}
}
}
?>
<li align="center" title="<?php echo $folder_name ?>" id="<?php echo md5($folder_name); ?>" onClick="hilight_folder('<?php echo md5($folder_name); ?>');" ondblclick="change_folder('<?php echo $folder_name; ?>')" style="cursor: pointer; height: 90px;">
<table cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<img height="75" style="padding-left: 5px; padding-right: 5px; padding-top: 5px;" src="img/folder.png">
<div class="prev_folder" style="display: none;"><?php echo $prev_folder ?></div>
</td>
</tr>
<tr>
<td align="center" class="name_tag">
<div class="name_tag_name" style="margin-top: 2px; width: auto;">
<?php
$short_folder = substr($folder_name, 0, 12);
if($folder_name == $short_folder){
}
else{
$short_folder = $short_folder."...";
}
echo $short_folder;
?>
</td>
</div>
</tr>
</table>
</li>
<?php
}
else if($buff[$i]!="/array1/MediaBox/iTunes/Mobile Applications" && $buff[$i]!="/array1/MediaBox/iTunes/Automatically Add to iTunes.localized" && $buff[$i]!="/array1/MediaBox/iTunes/Books" && $buff[$i]!="/array1/MediaBox/iTunes/Tones" && $buff[$i]!="/array1/MediaBox/iTunes/" && $buff[$i]!="/array1/MediaBox/iTunes/Icon"){
if($folder==""){
$folder_name = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
}
else{
$folder_name = str_replace(array("/array1/MediaBox/iTunes/".$folder."/"), array(""), $buff[$i]);
$last_folder = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
$last_folders = explode("/", $last_folder);
for($k=0;$k<=count($last_folders);$k++){
if($k==count($last_folders)){
$prev_folder = $last_folders[$k-3];
}
}
}
?>
<li align="center" title="<?php echo $folder_name ?>" id="<?php echo md5($folder_name); ?>" onClick="hilight_folder('<?php echo md5($folder_name); ?>');" ondblclick="change_folder('<?php echo str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]); ?>')" style="cursor: pointer; height: 90px;">
<table cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<img height="75" style="padding-left: 5px; padding-right: 5px; padding-top: 5px;" src="img/music_file.png">
<div class="prev_folder" style="display: none;"><?php echo $prev_folder ?></div>
</td>
</tr>
<tr>
<td align="center" class="name_tag">
<div class="name_tag_name" style="margin-top: 2px; width: auto;">
<?php
$short_folder = substr($folder_name, 0, 12);
if($folder_name == $short_folder){
}
else{
$short_folder = $short_folder."...";
}
echo $short_folder;
?>
</td>
</div>
</tr>
</table>
</li>
<?php
}
}
ftp_close($conn_id);
?>
</ul>
</td></tr>
<tr><td>
<div style="height: 60px;"> </div>
</td></tr></table>
</body>
</html>
If it's possible (if it is supported on FTP server) try to call:
ftp_raw($conn_id, "OPTS UTF8 ON");
This command enable UTF-8 encoding for directory listing (ftp_nlist).
Okay, I've worked out a work around which may be useful for other people to know:
str_replace(array('%82','%94','+'),array('é','ö',' '),urlencode($folder_name));
It's not the best way, but it works for me, if you url encode a string it changes the awkward characters into e.g. %82... You can then replace these with the HTML codes.
Related
I am trying to delete files inside folder, using delete_file.php, which is action file offcourse. It can recieve data as $_POST['filename1'] only, but for every foreach() iteration , this value is getting over-written. Any suggestions, what else can SOLVE this subject? Thanks in Advance.
Problem:
delete_file.php is catching filename1 as $_POST['filename1']
But with each foreach iteration, filename1 is getting over-written.
And delete_file.php, is deleting LAST ENTRY ONLY, EVERY TIME.
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!--[if lte IE 8]>
<script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css"/>
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ie8.css"/><![endif]-->
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ie9.css"/><![endif]-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.leanModal.min.js"></script>
</head>
<body class="no-sidebar">
<table border="1px solid" style="text-align:center; margin-left:auto; margin-right:auto; width:900px">
<tr>
<th><strong>S.No</strong></th>
<th><strong>Image-Name</strong></th>
<th><strong>Image/Logo</strong></th>
<th><strong>Image Size</strong></th>
<th><strong>Action</strong></th>
</tr>
<?php
$dirname = "../assets/img/logos/";
$images = glob($dirname . "*.{jpg,png,gif,tiff,jpeg,JPG}", GLOB_BRACE);
$sn = 1;
foreach ($images as $image) {
$imageName = str_replace("../assets/img/logos/", "", $image);
$variable_id = str_replace(".", "_", $imageName);
?>
<!---///////////////////// IMAGE-<?= $sn++ ?> STARTS //////////////////////----------->
<tr>
<td><?= $sn++ ?></td>
<td><?php echo $imageName; ?></td>
<td><img src="<?php echo $image; ?>" width="150px" height="100px"/></td>
<td><?php echo filesize($image) / 1000 . " KB"; ?></td>
<!-------
<td>
<a id="delete" href="delete_plogos.php?filename=<?//=$imageName ?>" style="color:#D00A0D"><strong>Delete</strong></a>
</td>
-------->
<td>
<p style="text-align: center; font-size: 10px; margin-top: 5px;">
<a id="modaltrigger_<?= $variable_id ?>" href="#<?= $variable_id ?>" class="btn"
style="border: none !important;">Delete</a>
</p>
</td>
</tr>
<!----------------------popup for delete----------------------->
<div id="<?= $variable_id ?>" class="popupContainer" style="display:none;">
<header class="popupHeader" style="background: #F4F4F2;
position: relative;
padding: 10px 20px;
border-bottom: 1px solid #DDD;
font-weight: bold; height: 55px;">
<span class="header_title">Delete</span>
<span class="modal_close"><i class="fa fa-times"></i></span>
</header>
<section class="popupBody">
<!-- Register Form -->
<div class="deleteplogo_<?= $variable_id ?>">
<form id="newpageform_<?= $variable_id ?>" name="newpageform_<?= $variable_id ?>" method="post">
<input name="filename_<?= $variable_id ?>" id="filename_<?= $variable_id ?>" type="text" style="display:none"
value="<?= $imageName ?>"/>
<p><strong><?= $imageName ?> - Image will be deleted Permanently. <br/>Proceed
?</strong></p>
<br/>
<div class="action_btns">
<div class="one_half" style="float:none;">
<a id="ajax-submit_<?= $variable_id ?>" class="btn btn_red" style="cursor: pointer"
>Yes! I
Agree
.Delete</a></div>
</div>
</form>
</div><!--------delete_plogo----------->
</section>
</div> <!----------------------#modal ENDS----------------------->
<!---------------- delete image : pop up ------------------------------>
<script type="text/javascript">
var magica = "<?php echo $variable_id; ?>";
$('#modaltrigger_' + magica).leanModal({top: 200, overlay: 0.6, closeButton: ".modal_close"});
$(function () {
$('#modaltrigger_' + magica).click(function () {
$('.deleteplogo_' + magica).show();
return false;
});
})
/////// 3.) AJAX-FORM SUBMIT - + then reload
$("#ajax-submit_"+magica).click(function () {
var filename = $("#filename_"+magica).val();
if (filename == '') {
alert("File doesn't EXIST....!!");
} else {
$.post("delete_plogos_action.php", {filename1: filename}, function (data) {
$("span.modal_close > i").trigger("click"); // to auto-close leanModal window
alert(data).fadeOut("slow");
window.location=trustedpartners_listviewdel_logos.php;
//close_modal("modal");
});
}
});
</script>
<!---///////////////////// IMAGE-ENDS //////////////////////----------->
<?php
}
?>
</table>
</body>
</html>
You can try something like removing the php loop:
<script type = "text/javascript" >
$(function() {
$('div[id^="modaltrigger_"]').leanModal({
top: 200,
overlay: 0.6,
closeButton: ".modal_close"
});
$('div[id^="modaltrigger_"]').click(function() {
magica = $(this).attr('id').split('_')[1];
$('.deleteplogo_' + magica).show();
return false;
});
})
$('div[id^="ajax-submit_"]').click(function() {
magica = $(this).attr('id').split('_')[1];
var filename = $("#filename_" + magica).val();
if (filename == '') {
alert("File doesn't EXIST....!!");
} else {
$.post("delete_file.php", {
filename1: filename
}, function(data) {
$("span.modal_close > i").trigger("click");
//alert(data).fadeOut("slow"); damn you can't fade out a alert box :))
window.location = mypage.php;
} // else ends here
});
}); < /script>
A better solution will be to replace the ids with a class and append a data-attribute to the elements iwth the value of magica
Deleted all AJAX-JQUERY code & used :
file1.php
<td>
<p style="text-align: center; font-size: 10px; margin-top: 5px;">
<a id="modaltrigger_<?= $variable_id ?>" href="delete.php?id=<?php echo $imageName; ?>" class="btn"
style="border: none !important;">Delete</a>
</p>
</td>
delete.php
<?php
$filePath = "D:/folder/".$_GET['id'];
if(is_file($filePath)){
#unlink($filePath);
echo ('<strong>SUCCESS! Deleted: <span style="color:red">'. $_GET['id']. '</span>, file from Directory</strong>');
}
else if(!unlink($filePath)){
echo ("Error deleting file : ". $_GET['id']. " Already deleted OR doesn't EXIST");
}
?>
Worked like Charm ! Thanks !
I have view file on my app there is code array I want to get first object of that array without going in loop.
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
$result is array of object I'm getting from a form. In below you can clearly see I'm chunking it to 3 more array and looping though individual objects and getting their details to html for example.
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
I want to get the first object details let's say want get $product->product_name of first object of result array without going in loop how to achieve that.
here is complete view file code.
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 0px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<div class="footer">
Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?>, $ Rate : Rs. <?php echo $usd; ?> </div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
<?php $GLOBALS['a']= $product->product_id; ?>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
ok man as i said u need to change your way of writing codes but about your specific question use this:
$result = array('a', 'b', 'c', 'd', 'e');
reset($array);
$first = current($array);
you can check this:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.current.php
But still about your way of coding. u should soon go to MVC or such ways of programming so u should separate your view and coding logics
like u may have a page like view_profile.php which is going to show user's information. in regular coding u have this:
view_profile.php:
<?php session_start();
// you check sessions to see if the user is logged in and has the right to view this page.
// like:
if ($_SESSIONS['is_user_logged_in']){
$username=$_SESSIONS['username'];
$name=$_SESSIONS['name'];
// ....
}else{
header('location: ./login.php');// if user is not authenticated u redirect to login page
exit();// prevents the rest of codes to be shown and executed
}
?>
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
But in a better way u can do it like this:
you have files like
'view_profile.htm' // holds the HTML
'view_profile.php // holds the PHP logic
'inc.php' // holds some useful functions that help you in writing PHP logic
view_profile.htm
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
inc.php
<?php
function ses_start(){
if(!session_id()){
session_start();
}
}
function ses_get($key){
ses_start();
if(!empty($_SESSION[$key])){
return $_SESSION[$key];
}
return NULL;
}
function ses_set($key,$val){
$_SESSION[$key]=$val;
}
function is_user_loggedin(){
ses_start();
if(!empty(ses_get('is_user_loggedin')){
return true;
}
return false;
}
function go($to){
header('location: '.$to);
exit();
}
//and lots of useful functions that help u connect and work with data base.
view_profile.php
<?php
include('inc.php');
if(is_user_loggedin(){
$username=ses_get('username');
$name=ses_get('name');
//...
}else{
go('login.php);
}
include('view_profile.html); // and u call the .htm file that holds the HTML the view file)
?>
this was a simple sample of separating codes logic(php codes) from views(html tags)
and also u may search about MVC Model-View-Controller and try working with simple MVC frameworks.
I hav run into a problem - I am not that familiar with cakephp - but I have taken over a project (A webshop project) - and now I have a bit of a problem - I have a field (tracking id for the package) which writes to DB - that works great - but here is the trouble - when I click the button and save the tracking number to the DB - I wan't the system to send an email to the customer with the tracking id.
I can get the system to send a mail - but there is no tracking number on so I guess the email is send before the DB i updated.
Hope someone can point me in the right direction
public function send($order_id = null, $is_resolved = true)
{
if($this->request->is('post'))
{
$this->Order->id = $this->request->data['Order']['id'];
$this->Order->saveField('state', 'resolved');
$this->Order->saveField('date_resolved', date('Y-m-d H:i:s'));
$this->Order->saveField('delivery_label', $this->request->data['Order']['delivery_label']);
$this->Session->setFlash('Ordren er nu sat til "Sendt".'.$this->Session->read('Message.success.message'), null, array(), 'success');
$this->redirect(array('controller' => 'orders', 'action' => 'index'));
}
$order = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id, 'Order.state' => 'packed'), 'recursive' => 4));
// Does the item exist?
if(empty($order))
{
// Tell the user this item did not exist
$this->Session->setFlash('Ordren findes ikke.'.$this->Session->read('Message.warning.message'), null, array(), 'warning');
return $this->redirect($this->referer());
}
if($is_resolved) {
// Send the email receipt
$Email = new CakeEmail('receipt');
$Email->to($order['Customer']['email_address']);
$Email->template('receipt_send')->viewVars( array('order' => $order));
$Email->send();
}
$this->set('order', $order);
}
Here is the receipt_send code
<table style="width:100%; margin-bottom:30px; border-collapse: collapse; color:#777;">
<tr style="vertical-align:middle; border-bottom:1px solid #777;">
<td colspan="3" style="width:45%; padding:10px 0;"><?php echo $this->Html->image('logo.png', array('style' => 'height:50px; margin-top:-15px; vertical-align:middle;', 'fullBase' => true)); ?></td>
</tr>
<tr style="font-size:1em; border-bottom:1px solid #777;">
<td style="padding: 5px 0;"><strong>Kvittering</strong> fra Bundgaards Garn</td>
<td style="padding: 5px 0;">Ordre nr. <strong><?php echo $order['Order']['id']; ?></strong></td>
</tr>
<p style="width:50%; float:right;">Din ordre er afsendt og har fået trackingnummer: <strong><?php echo $order['Order']['delivery_label']; ?></strong></p>
<table style="text-align: left; width:100%; border-collapse: collapse;">
<tr style="border-bottom:2px solid #dddddd;">
<th style="width:35%; padding: 10px 0;">Vare</th>
<th style="width:25%; padding: 10px 0;">Antal</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Pris</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Total</th>
</tr>
<?php foreach ($order['OrderItem'] as $key => $order_item): ?>
<tr style="border-bottom:1px solid #dddddd;">
<!-- PRODCUT LINK -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $order_item['YarnBatch']['YarnVariant']['Yarn']['name'] . ' - ' . $order_item['YarnBatch']['YarnVariant']['color_code'] . '-' . $order_item['YarnBatch']['batch_code']; ?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $order_item['NeedleVariant']['Needle']['name'] . ' - ' . $order_item['NeedleVariant']['product_code']; ?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
Print af <?php echo $order_item['Recipe']['name']; ?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
Farveprøve af <?php echo $order_item['ColorSample']['name']; ?>
<?php endif; ?>
</td>
<!-- PRODCUT LINK COLLAPSE -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php echo $order_item['amount']; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['YarnBatch']['price'], 'DKK');?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['NeedleVariant']['price'], 'DKK');?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['Recipe']['price'], 'DKK');?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['ColorSample']['price'], 'DKK');?>
<?php endif; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;" >
<?php echo $this->Number->currency($order_item['price'], 'DKK');?>
<?php if($order_item['saving'] > 0) : ?>
<br/>
<span style="color:#5cb85c;"><?php echo $this->Number->currency($order_item['saving'], 'DKK');?>´</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<p>Levering</p>
<?php if($order['Order']['saving'] > 0) : ?>
<p>Rabat</p>
<?php endif; ?>
<p><strong>Subtotal</strong></p>
<p><strong>Moms</strong></p>
</td>
<td style="text-align:right;">
<p><?php echo $this->Number->currency($order['Order']['shipping_price'], 'DKK');?></p>
<?php if($order['Order']['saving'] > 0) : ?>
<p style="color:#5cb85c;"><strong><?php echo $this->Number->currency($order['Order']['saving'], 'DKK');?></strong></p>
<?php endif; ?>
<p><strong><?php echo $this->Number->currency($order['Order']['sub_total'], 'DKK');?></strong></p>
<p><strong><?php echo $this->Number->currency($order['Order']['tax'], 'DKK');?></strong></p>
</td>
</tr>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<h4>Total:</h4>
</td>
<td style="text-align:right; color:#900000;">
<h4><strong><?php echo $this->Number->currency($order['Order']['price'], 'DKK');?></strong></h4>
</td>
</tr>
</table>
<div style="width:50%; float:left;">
<h4>Ordren sendes til:</h4>
<p>
<strong><?php echo $order['Customer']['first_name'] . ' ' . $order['Customer']['last_name']; ?></strong><br>
<?php echo $order['Customer']['ShippingAddress']['street'] . ' ' .
$order['Customer']['ShippingAddress']['zip_code'] . ' ' .
$order['Customer']['ShippingAddress']['city_name']?><br>
<?php echo $order['Customer']['email_address']; ?><br>
<?php echo $order['Customer']['phone_number']; ?><br>
</p>
</div>
<div style="width:50%; float:left;">
<?php if(!empty($order['Order']['customer_note'])) : ?>
<h4>Note til forhandleren:</h4>
<p>
<?php echo $order['Order']['customer_note']; ?>
</p>
<?php endif; ?>
</div>
<hr style="width:100%; border: 0; border-bottom: 1px solid #ddd;">
<p style="color:#999; font-size:0.8em;">
<strong>Bundggards Garn</strong> <br/>
<a style="color:#777;" href="https://bundgaardsgarn.dk">bundgaardsgarn.dk</a> <br/>
kontakt#bundgaardsgarn.dk <br/>
Saltumvej 46 9700 Brønderslev <br/>
30369522 <br/>
<i>CVR:</i> 34526826 <br/>
</p>
Got it to work by creating a controller and make a button to the information.... Works like a charm.
I have this script.
<?php
$self=$_SERVER['PHP_SELF'];
$ipresurse='resurse.fibula.ro';
$PartnerID="travelplaza";
$SelectedAirport="ANTALYA";
function checkXmlCache($xmlQuery) {
$fibulabasexml="http://resurse.fibula.ro/parteneri/"; $cachedir="http://ydashopimpex.com/tmp"; $ageInSeconds = 3600;
$xmlQuery=str_replace(array("'",'"'),"",$xmlQuery); $xmlQuery2=$xmlQuery;
$long=array("stars=","TURKEY","bestprice=","country=", "location=","hotelcode=","prices=yes","tara=","simple=yes","rand()","sort=","limit=","price ","hotelname"," desc","desc");
$short=array("ST-","TR","B-","C-", "L-", "H-", "PY-", "T-", "-S-", "-R-", "S-", "LT-", "PP-","HN","-D","-D");
$xmlQuery2=str_replace($long,$short,$xmlQuery2);
$xmlQuery2=str_replace(array("xmlhotels.php","xmllocations.php"),array("XH-","XL-"),$xmlQuery2);
$xmlQuery2=str_replace(array("&","?"),array(""),$xmlQuery2);
$xmlQuery2.="_.XML";
$xmlQuery2=strip_tags($xmlQuery2);
if(!file_exists($cachedir.$xmlQuery2) || (filemtime($cachedir.$xmlQuery2) + $ageInSeconds < (time() )) ) {
$contents = file_get_contents($fibulabasexml.str_replace(" ","%20",$xmlQuery));
if(strlen($contents)>200 ) { file_put_contents($cachedir.$xmlQuery2, $contents); }
}
return($cachedir.$xmlQuery2);
}
function moneda($moneda) { $numemoneda=array("EURO","USD"); $simbol=array("€","$"); return str_replace($numemoneda,$simbol,$moneda); }
$feedbpl = checkXmlCache('xmlhotels.php?airport='.$SelectedAirport.'&myid=travelplaza'.$PartnerID.'&simple=yes&sort=nume asc');
$bpl = simplexml_load_file($feedbpl); $sh="0"; if(isset($_GET['code'])) { $codes=explode(",",$_GET['code']); $sh=strip_tags($codes[2]); }
?>
<div style="padding:2px; text-align:center">
<form name="fastsearch" method="get" action="<?php print $self; ?>">
<strong>CAUTARE RAPIDA HOTEL</strong> <select name="code" onchange="submit()" style="padding:2px 1px;"><option value="">---selecteaza hotel---</option><?php
foreach ($bpl->hotel as $h)
{
?><option <?php if($h['hotelcode']==$sh) { ?> selected="selected" <?php }?> value="<?php print $h['hotelname'].",".$h['location'].",".$h['hotelcode'];?>" title="<?php print $h['hotelname']." ".$h['stars'];?>"><?php print substr($h['hotelname'],0,30)." ".$h['stars'];?></option><?php
}
?>
</select></form>
</div>
<?php
if(!isset($_GET['code']))
{
/*
?>
<iframe style="padding:0px; margin:0px;" src='http://<?php print $ipresurse?>/WL/?myid=travelplaza<?php print $PartnerID; ?>&small=1' frameborder='0' width='100%' height='380' scrolling='auto'></iframe>
<?php
*/
}
if(isset($_GET['code']))
{
$feedurl =checkXmlCache("xmlhotels.php?hotelcode=".$sh."&prices=yes&myid=travelplaza".$PartnerID); $xml = simplexml_load_file($feedurl);
?>
<h1><?php print $xml->hotel['hotelname']; ?> <?php print $xml->hotel['stars']; ?></h1>
<div class="localizare"><?php print $xml->hotel['location']; ?> / <?php print $xml->hotel['country']; ?>
<div style="float:right; background-color:#C9F; color:white; -moz-border-radius: 10px; border-radius: 10px; font-weight:bold; padding:5px; text-align:center">REZERVA ACUM<br />de la <?php print floatval($xml->hotel['bestprice']). " " .moneda($xml->hotel['currency']); ?></div>
</div>
<div class="gallery" style="display:inline-table; width:100%;">
<img style="float:left" src="http://resurse.fibula.ro/hotel_images/<?php print $xml->hotel['hotelcode']."___".$xml->hotel['defaultimage'].".jpg"; ?>" alt="" width="350" />
<?php
foreach($xml->hotel->images->image as $img)
{
?>
<p style="float:left; margin:0px; padding:0px;"><a title="<?php print $xml->hotel['hotelname']; ?>" href="<?php print $img['url'];?>" rel="gallery">
<img style="float:left" src="<?php print str_replace(".jpg","___small.jpg",$img['url']);?>" alt="<?php print $xml->hotel['hotelname']; ?>" title="<?php print $xml->hotel['hotelname']; ?>" width="50" height="38"/></a>
</p>
<?php
}
?>
</div>
<?php print html_entity_decode($xml->hotel->description); ?>
<div style="display:inline-table; width:100%;" id="rezervare123">
<h4 >Rezerva acum ! Oferta de la <?php print floatval($xml->hotel['bestprice']). " " .moneda($xml->hotel['currency']); ?> </h4>
<?php /* ?>
<iframe style="padding:0px; margin:0px;" src='http://<?php print $ipresurse?>/WL/?myid=travelplaza<?php print $PartnerID; ?>&small=1&hotelcode=<?php print $xml->hotel['hotelcode']?>&hotel=<?php print $xml->hotel['hotelname']?>' frameborder='0' width='100%' height='380' scrolling='auto'></iframe>
<?php */ ?>
</div>
<?php
/*
foreach($xml->hotel->prices->bestPrice as $prices)
{
$capete[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['night'])]=trim($prices['night']);
$tarife[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['checkin'])][trim($prices['night'])]=number_format(floatval($prices['price']),0);
}
*/
//new tarife
$DefaultDiscount=0;
foreach($xml->hotel->prices->bestPrice as $prices) { $customprice=floatval($prices['price'])-$DefaultDiscount; $capete[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['night'])]=trim($prices['night']); $tarife[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['checkin'])][trim($prices['night'])]=$customprice; }
?>
<!-- prices start -->
<?php
foreach($capete as $key=>$value){ asort($value);
?>
<div id="<?php print $key; ?>" style="padding:0px;" class="content">
<p></p>
<table width="100%"><thead>
<tr><td width="10%">Data plecare</td>
<?php foreach($value as $n) { ?><td><?php print $n;?></td><?php }?>
</tr>
<thead><tbody>
<tr><td colspan="<?php print count($value)+1; ?>" align="center"><span style="color: #ff6600; font-weight:bold;">
Tarife de persoana in camera standard. (* tarifele nu includ taxele de aeroport 95€/pers)
</span>
</td></tr>
<?php foreach($tarife[$key] as $checkin=>$nn) { $chk=new DateTime($checkin); ?>
<tr><td><?php print $chk->format('d.m.Y');?></td><?php
foreach($value as $n) { ?><td align="right"> <?php if(array_key_exists($n,$nn)) { print $nn[$n];} ?></td><?php } ?>
</tr><?php
}
?>
</tbody>
</table>
</div>
<?php
}
?>
<?php
/*
foreach ($tarife as $rute=>$plecari)
{ sort($capete[$rute]); $ut=0; $i=0;
foreach($plecari as $plecare=>$tarif)
{ $sd=explode("-",$plecare); if($ut!=$tarif[$capete[$rute][0]]) {$i++; }
${str_replace("-","_",$rute)}[$tarif[$capete[$rute][0]]."|".$i][]=$sd[2].".".$sd[1];
$ut=$tarif[$capete[$rute][0]];
}
}
foreach($capete as $rute=>$value)
{
?>
<h4>Oferta <?php print $rute. " ".$value[0]." nopti"; ?></h4>
<table style="font-size:10px; border-collapse:collapse; " border="1" width="100%"><tr><?php
foreach(${str_replace("-","_",$rute)} as $key=>$value)
{ ?><td valign="bottom" align="center" style=" border-collapse:collapse; "><?php foreach($value as $dep) { print $dep."<br>";}?></td><?php }
?></tr><tr><?php
foreach(${str_replace("-","_",$rute)} as $key=>$value)
{ $t=explode("|",$key); ?><td style=" background-color:lightblue; border-collapse:collapse; text-align:center;"><?php print $t[0];?></td><?php }
?>
</tr></table>
<?php unset(${str_replace("-","_",$rute)});
}
*/
?>
<!-- end of prices -->
<?php
}
else
{
$feedurl =checkXmlCache('xmllocations.php?country=TURKEY&myid=travelplaza'.$PartnerID); $locations = simplexml_load_file($feedurl);
foreach($locations->country->location as $x) { $airs[trim($x['airport'])][]=$x; }
$xxx=0; $HotelsPerPage=15; $pagini=ceil($bpl['offers']/$HotelsPerPage); $pc=1; $maxi=$HotelsPerPage; $mini=1;
if(isset($_GET['pagina'])) {$pc=intval($_GET['pagina']); $maxi=$pc*$HotelsPerPage; $mini=$maxi-$HotelsPerPage+1; }
foreach ($bpl->hotel as $hbpl)
{
$xxx++;
if( ($xxx<=$maxi) and ($xxx>=$mini) )
{
$locatie=$hbpl['location'];
$imageurl="http://".$ipresurse."/hotel_images/".$hbpl['hotelcode']."___".$hbpl['defaultimage']."___medium.jpg";
$l=0; $locationLink=$self."?";
foreach($_GET as $k=>$v)
{ $l++; $si="&"; if($l==1) { $si=""; }
if( ($k!='location') and ($k!='nopti') and ($k!='hotel') and ($k!='hotelcode') and ($k!='ruta') ) { $locationLink.=$si.$k."=".$v; }
}
if($hbpl['airport']=='ANTALYA') {$linkruta="OTP_AYT";} else {$linkruta="OTP_BJV";}
$hotelLink=$self."?code=".urlencode($hbpl['hotelname']).",".$hbpl['location'].",".$hbpl['hotelcode'];
?>
<div class="box">
<div class="thumb"><img width="330" height="220" src="<?php print $imageurl; ?>" class="attachment-post-thumbnail wp-post-image" alt="<?php print $hbpl['hotelname'] ?>" title="<?php print $hbpl['hotelname'] ?>" /></div>
<a class="box-title" href="<?php print $hotelLink; ?>"><?php print $hbpl['hotelname'] ?> <?php print $hbpl['stars']; ?> <?php print number_format(floatval($hbpl['bestprice']))." ".moneda($hbpl['currency']); ?></a>
<a class="button" href="<?php print $hotelLink; ?>">Afla mai multe</a>
</div>
<?php
}
}
?>
<div style=" display: inline-block; width:100%;"> </div>
<div style="border-top:solid 1px #ccc; display:inline-table; width:100%;" align="center">
<?php
if($pc>1) { ?>
<span style=" float:left; padding:1px; margin:1px; background-color:#ccc;"><a style="text-decoration:none" href="<?php print $self."?pagina=".($pc-1); ?>">« Inapoi</a></span><?php }
for($i=1; $i<=$pagini; $i++)
{
?><span style=" float:left; padding:0px; margin:1px; border:solid 1px #ccc; <?php if($i==$pc) { ?> background-color:#ccc; <?php }?>" >
<a style="text-decoration:none; padding:0px 2px; margin:0px; line-height:10px;" href="<?php if($i==$pc) { print "#"; } else { print $self."?pagina=".$i;} ?>"><?php print $i;?></a>
</span><?php
}
if($pc<$pagini) { ?><span style=" float:left; padding:1px; margin:1px; background-color:#ccc;"><a style="text-decoration:none" href="<?php print $self."?pagina=".($pc+1); ?>">Inainte » </a></span><?php }
?>
</div>
<?php
}
?>
On my localhost it works.
But when I upload it to the servers it reads only the html.
Picture attached. Any idea of what it can be wrong? Maybe a php function on the server that might be disabled? What should I check? I have spoken with my webhost and he told me that I must know which function I need.
You can use ini_set and error_reporting to set the PHP Error Reporting to ALL and other error related ini settings.
i.e:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
Also, as mentioned in the comments, create a php file holding the phpinfo() command to see weather or not php is running on your server at all.
testphp.php
<?php
phpinfo();
If you open yourwebsitesdomain.com/testphp.php and you do not see information on php running, contact your webhoster and tell him php is not working on the server.
I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html(' ');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>