How can I print this div with drag and drop objects? - php

I can print it but the output is wrong. This is my script for print:
<script type="text/javascript">
function printDiv(divName)
{
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
And this is for the view:
<div class="accordion-body collapse in body" id="printableArea">
<div class="col-lg-12">
<span class="text-left"><h4><b>Course Code-Section: </b><?php echo $class;?></h4></span>
<span class="text-left"><h4><b>Course Description: </b><?php echo $description;?></h4></span>
<span class="text-left"><h4><b>School Year-Semester: </b><?php echo $schoolyearsemester;?></h4></span>
<span class="text-left"><h4><b>Day-Time: </b><?php echo $daytime;?></h4></span>
<span class="text-left"><h4><b>Room: </b><?php echo $room;?></h4></span>
<br>
</div>
<ul class="draglist" style="width:{{config.width * config.col}}px;" ng-cloak>
<li ng-repeat="obj in chairs" ng-drop="false" ng-drop-success="onDropComplete($index, $data,$event)" ng-cloak>
<div ng-drag="false" ng-drag-data="obj" ng-class="obj" ng-cloak>
<span class="student-name">{{obj.length > 3 ? obj: ''}}</span>
</div>
</li>
</ul>
<div class="form-actions">
<h3 class="text-center">Professor's Table</h3>
</div>
</div>
<input type="button" onclick="printDiv('printableArea')" value="Print Seatplan" />
And this is the image or output that displaying:
And this is the one that I am printing, a drag and drop seatplan:

Related

Bootstrap Cards Filter PHP/AJAX Problems

I have a page of a website which has bootstrap cards on. The cards are generated dynamically, but I wanted to add a filter section. I am trying to use AJAX to acheive this, I have got to a point where when you select a checkbox it triggers the loader gif but then that loader gif doesn't disapear. Through my hours of debugging I can see that its the page that the AJAX call is calling that is the problem, but I just can't see what the issue is and I am not getting errors or anything in the console.
If anyone has any ideas I would really appreciate it, I have pasted my code below, also I am aware my sql queries are currently open to injection, just want to get it to work first.
<body>
<?php include("PHP/header.php"); ?>
<div class="container-fluid">
<div class="container" style="margin-top: 2%; text-align: center;">
<h1>Title goes here</h1>
Some tetx
<br/>
<br/>
<br/>
Filter Reviews:
<ul class="list-group">
<?php
$search = $conn->prepare("SELECT DISTINCT reviewcat FROM review_db ORDER BY reviewcat");
$search->execute();
while ($row = $search->fetch(PDO::FETCH_ASSOC)) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" value="<?=$row['reviewcat'];?>" id="reviewcat"> <?=$row['reviewcat']; ?>
</label>
</div>
</li>
<?php } ?>
</ul>
</div>
<br/><br/>
<div class="row-fluid ">
<h5 class="text-center" id="textChange"> All Products </h5>
<hr>
<div class="text-center">
<img src="Images/loader.gif" id="loader" width="100" style="display: none">
</div>
<div id="result" class="card-deck card_group_style pt-4" >
<?php
$res_data = $conn->prepare("SELECT * FROM review_db");
$res_data->execute();
?>
<?php while ($row = $res_data->fetch(PDO::FETCH_ASSOC)) {// Important line !!! Check summary get row on array .. ?>
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/<?php echo $row['reviewimage1'];?>" alt="<?php echo $row['reviewtitle'];?>" >
<div class="card-body">
<h5 class="card-title"><?php echo $row['reviewtitle'];?></h5>
<p class="card-text"><?php echo $row['reviewsynop'];?></p>
<a href="Reviews/review-content.php?id=<?php echo $row['id'];?>&reviewtitle=<?php echo $row['reviewtitle'];?>" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: <?php
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;?></small>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include("PHP/footer.php"); ?>
</div>
</body>
<?php include("PHP/js.php"); ?>
<script>
$(document).ready(function(){
$('#link-review,#link-footer-review').addClass('active');
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function get_filter_text(text_id){
var filterData = [];
$('#'+text_id+':checked').each(function(){
filterData.push($(this).val());
});
return filterData;
}
$(".product_check").click(function(){
$("#loader").show();
var action = 'data';
var reviewcat = get_filter_text('reviewcat');
$.ajax({
method:'POST',
url:'reviewaction.php',
data:{action:action,reviewcat:reviewcat},
success:function(response){
$("#result").html(response);
$("#loader").hide();
$("#textChange").text("Filtered Reviews");
}
});
});
});
</script>
</html>
reviewaction.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT'] . '/Private/db.php';
// $stmt = $conn->prepare("SELECT * FROM blogdata ORDER BY blogsub DESC");
// $stmt->execute();
?>
<?php
if(isset($_POST['action'])){
$sql = "SELECT * FROM review_db WHERE reviewcat !=''";
$revsearch = $conn->prepare($sql);
$revsearch->execute();
$output='';
if($revsearch->num_rows>0){
while ($row = $revsearch->fetch(PDO::FETCH_ASSOC)) {
$output .= '
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/'. echo $row['reviewimage1'];.'" alt="'. echo $row['reviewtitle'];.'" >
<div class="card-body">
<h5 class="card-title">'. echo $row['reviewtitle'];.'</h5>
<p class="card-text">'. echo $row['reviewsynop'];.'</p>
<a href="Reviews/review-content.php?id='. echo $row['id'];.'&reviewtitle='. echo $row['reviewtitle'];.'" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: '.
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;.'</small>
</div>
</div>
</div>
</div>
';
}
else{
$output = "<h3>No Reviews Found!</h3>";
}
echo $output;
}
?>
I have actually found something in the server error log, I was stupidly only use dev tools on firefox, but have found that in the reviewaction.php script I had left semicolons in and had also missed a closing bracket. There are still some other problems, which I can fix, just couldn't work out why it wasn't firing.

Fetch data from mysql by checking radio button

i have few models of products and when i click on each model to show me his variants, like on image from below
Here is what i made in html :
<div class="owl-carousel owl-theme no-pb slide-arrow-2" data-
dots="false" data-nav="true" data-items="4" data-lg-items="3"
data-md-items="2" data-sm-items="2" data-margin="30" data-
autoplay="false">
<?php
$qua = "SELECT * FROM produse WHERE categorie = '$id' ORDER BY pozitie";
$qla = mysqli_query($conn, $qua);
while($rova = mysqli_fetch_assoc($qla)){?>
<?php
$id_paletar = $rova['id'];
$sql2=mysqli_query($conn,"SELECT * FROM pret_produse WHERE produs_id='$id_paletar'");
$pret2=mysqli_fetch_array($sql2);
?>
<div class="item">
<div class="product-item">
<div class="product-img">
<img class="img-fluid" src="cms/produse/<?=$rova['poza'];?>" alt="">
<div class="product-overlay">
<ul class="list-unstyled">
</ul>
</div>
</div>
<div class="product-btn ifix">
<div class="btn btn-theme btn-block btn-new" ><span style="font-size: 15px;"><?=$rova['titlu'];?></span>
<div>
<label class="containere">
<input type="radio" name="produse" id="paletar_pret" class="palt" value="<?=$rova['id'];?>">
<p class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
</div>
<?php }?>
</div>
Here is my jquery:
$(document).ready(function(){
$('.palt').change(function() {
if(this.checked) {
var check= $(this).val();
alert(check);
$.ajax({
url: 'cere_cotatie.php',
type: 'POST',
data: {check:check},
success: function(data){
$('.fetch').append(data);
}
});
}
});
And here is my php file which i use on ajax to call:
<?php
if($_POST)
{
include('config.php');
echo $check = $_POST['check'];
$s = "SELECT * FROM variante WHERE id_var='$check'";
$q = mysqli_query($conn, $s);
while ($r = mysqli_fetch_assoc($q)) {?>
<div class="item" style="width:220px;">
<div class="product-item">
<div class="product-img">
<img class="img-fluid" src="cms/variante/<?=$r['poza'];?>" alt="">
<div class="product-overlay">
<ul class="list-unstyled">
</ul>
</div>
</div>
<div class="product-btn ifix">
<div class="btn btn-theme btn-block btn-new" ><span style="font-size: 15px;"> <?=$r['denumire'];?></span>
<div>
<label class="containere">
<input type="checkbox">
<p class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
</div>
<?php }?>
<?php }
?>
My problem is like this if i check first box to display me variants of what i checked but my code is doing this way, if i check first box is loading data and after that if i check another box results from first box need to dissapear and to be only what i check.
EDIT: in that print screen you can see the problem.
I think you should add below code
$('.palt').change(function(e) {
e.preventDefault();
});
and remove alert(check);
Hope it work for you.

How to display hidden data of one div to another div?

I am working on a project where I came across where when I click plus sign the data will hide and the appear in the div next to it.
here is the code:
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" href onclick="return addSrvToCart('itemservices<?php echo $id ?>')" >
<strong>&#8377 <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding" id="cart">
<div class="col-md-12" >
</div>
</div>
<div class="col-sm-12 no-right-padding" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
<label class="pull-right">/*what should i write here to show the sum */: ₨ </label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
And This the Jquery code:
<script>
function addSrvToCart(elem){
alert($('#' + elem).html());
$('#' + elem).hide();
//return false;
//what should i write here the show that hidden div
document.getElementById('summery);
return false;
}
</script>
This is the picture and I want to display the data in the Cart div and show the amount
You need to change in both HTML and Script to achieve the result
Try like this
HTML
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" onclick=" addSrvToCart('itemservices<?php echo $id ?>')" >
&#8377<strong> <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding">
<div class="col-md-12" id="cart" >
</div>
</div>
<div class="col-sm-12 no-right-padding pull-right" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
Total: ₨ <label class="" id="sumAmount">0</label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
Script:
function addSrvToCart(elem){
var div=$('#' + elem);
div.hide();
$('#cart').append(div.html());
var total = parseInt(div.find('strong').html()) + parseInt($('#sumAmount').html());
$('#sumAmount').html(total);
}
It will produce output as
I think it will help you.

What is wrong with my onClick syntax?

http://phpcodechecker.com/ says that 'Notification' is a (T_STRING) in my code. What should I replace ' to?
<?php
$Query = $this->DBase('Query', array( 0 => "SELECT * FROM `factions`" ));
while ($FACTIONS = $Query->fetch_object()) {
$this->FACTION->FACTIONSLIST .=
'<tr class="even pointer">
<td width="1%" class="a-center "><input type="checkbox" class="flat" name="table_records"></td>
<td width="10%">{$FACTIONS->id}</td>
<td>{$FACTIONS->Name} </td>
<td width="5%" class="last">
<a href="{SITE_CMS_ROOT}?factions&edit={$FACTIONS->id}">
<i class="fa fa-pencil"></i>
</a>
<a href="#" onclick="new TabbedNotification([
title: 'Notification',
text: 'Faction 123 successfully deleted!, page will be updated shortly.',
type: 'Error',
sound: false
]);">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>';
}
?>
Here is the HTML with the onClick script.
The {SITE_FACTIONS} is the php script with the onClick function.
<body class="nav-md">
<div class="container body">
<div class="main_container">
{SITE_SIDEBAR}
{SITE_NAVIGATION}
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h3> </h3>
</div>
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<div class="clearfix"></div>
{SITE_FACTIONS}
</div>
</div>
</div>
{SITE_FOOTER}
</div>
</div>
<div id="custom_notifications" class="custom-notifications dsp_none">
<ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group">
</ul>
<div class="clearfix"></div>
<div id="notif-group" class="tabbed_notifications"></div>
</div>
<!-- jQuery -->
<script src="{SITE_CMS_ROOT}vendors/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="{SITE_CMS_ROOT}vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="{SITE_CMS_ROOT}vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="{SITE_CMS_ROOT}vendors/nprogress/nprogress.js"></script>
<!-- bootstrap-progressbar -->
<script src="{SITE_CMS_ROOT}vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
<!-- iCheck -->
<script src="{SITE_CMS_ROOT}vendors/iCheck/icheck.min.js"></script>
<!-- PNotify -->
<script src="{SITE_CMS_ROOT}vendors/pnotify/dist/pnotify.js"></script>
<script src="{SITE_CMS_ROOT}vendors/pnotify/dist/pnotify.buttons.js"></script>
<script src="{SITE_CMS_ROOT}vendors/pnotify/dist/pnotify.nonblock.js"></script>
<!-- Custom Theme Scripts -->
<script src="{SITE_CMS_ROOT}build/js/custom.min.js"></script>
<!-- Custom Notification -->
<script>
$(document).ready(function() {
var cnt = 10;
TabbedNotification = function(options) {
var message = "<div id='ntf" + cnt + "' class='text alert-" + options.type + "' style='display:none'><h2><i class='fa fa-bell'></i> " + options.title +
"</h2><div class='close'><a href='javascript:;' class='notification_close'><i class='fa fa-close'></i></a></div><p>" + options.text + "</p></div>";
if (!document.getElementById('custom_notifications')) {
alert('doesnt exists');
} else {
$('#custom_notifications ul.notifications').append("<li><a id='ntlink" + cnt + "' class='alert-" + options.type + "' href='#ntf" + cnt + "'><i class='fa fa-bell animated shake'></i></a></li>");
$('#custom_notifications #notif-group').append(message);
cnt++;
CustomTabs(options);
}
};
CustomTabs = function(options) {
$('.tabbed_notifications > div').hide();
$('.tabbed_notifications > div:first-of-type').show();
$('#custom_notifications').removeClass('dsp_none');
$('.notifications a').click(function(e) {
e.preventDefault();
var $this = $(this),
tabbed_notifications = '#' + $this.parents('.notifications').data('tabbed_notifications'),
others = $this.closest('li').siblings().children('a'),
target = $this.attr('href');
others.removeClass('active');
$this.addClass('active');
$(tabbed_notifications).children('div').hide();
$(target).show();
});
};
CustomTabs();
var tabid = idname = '';
$(document).on('click', '.notification_close', function(e) {
idname = $(this).parent().parent().attr("id");
tabid = idname.substr(-2);
$('#ntf' + tabid).remove();
$('#ntlink' + tabid).parent().remove();
$('.notifications a').first().addClass('active');
$('#notif-group div').first().css('display', 'block');
});
});
</script>
<!-- /Custom Notification -->
chnage this:
title: 'Notification',
text: 'Faction 123 successfully deleted!, page will be updated shortly.',
type: 'Error',
to:
title: "Notification",
text: "Faction 123 successfully deleted!, page will be updated shortly.",
type: "Error",
When you are using ' (single quote) between two ' (single quote), you must escape the single quote. Try like this:
title: \'Notification\',
text: \'Faction 123 successfully deleted!, page will be updated shortly.\',
type: \'Error\',

jquery just works for the latest button not all button

My PHP HTML code is this :
<?php
foreach($questions as $question){
echo"
<div id='postShare'>
<div class='col-md-10 col-md-offset-1' id='listPost'>
<div class='list-group'>
<li class='list-group-item text-center '>
<span class='pull-left' id='question_author'>".$question->author."</span>
<span class='pull-right' id='question_time'><p>".time_ago($question->time)."</p></span>
<hr>
<span class='pull-right' style='color:red;font-size:11px;'>سوال</span>
<br>
<center><h4 id='question_title'>" .$question->title. "</h4></center>
<hr>
<span class='pull-right' style='color:blue;font-size:11px;'>توضیحات</span>
<br>
<h5 id='question_desc'>".$question->description."</h5>
<hr>
<span class='pull-right' style='color:GoldenRod;font-size:11px;'>کد برنامه</span>
<br>
<pre id='question_code'>".$question->code."</pre>
<hr>
<button class='btn btn-primary' id='send_answer'>پاسخگویی به این سوال</button>
</li>
</div>
</div>
</div>";
}
?>
and my Jquery file is this :
$(function(){
$("#send_answer").click(function(e){
alert("cliked");
e.preventDefault();
});
});
This PHP code just fetch and show the database data with a button.
I want to when I click at that button it shows an alert. its work for the latest data that fetch and do not work for all.
You need to create button with the same class. Creating with a same id will result in only one to be operated on.
PHP
<?php
foreach($questions as $question) {
echo "
<div id='postShare'>
<div class='col-md-10 col-md-offset-1' id='listPost'>
<div class='list-group'>
<li class='list-group-item text-center '>
<span class='pull-left' id='question_author'>".$question->author."</span>
<span class='pull-right' id='question_time'><p>".time_ago($question->time)."</p></span><hr>
<span class='pull-right' style='color:red;font-size:11px;'>سوال</span><br><center><h4 id='question_title'>" .$question->title. "</h4></center><hr>
<span class='pull-right' style='color:blue;font-size:11px;'>توضیحات</span><br><h5 id='question_desc'>".$question->description."</h5><hr>
<span class='pull-right' style='color:GoldenRod;font-size:11px;'>کد برنامه</span><br><pre id='question_code'>".$question->code."</pre><hr>
<button class='btn btn-primary send_answer'>پاسخگویی به این سوال</button>
</li>
</div>
</div>
</div>";
}
?>
jQuery
$(function() {
$(".send_answer").click(function(e) {
alert("cliked");
e.preventDefault();
});
});

Categories