To redirect the url - php

in the below code i am searching a data before searching my url will be in coursemaster_site and when i search it will be in coursemaster_site/index1 and when i close the search results the url will be in coursemaster_site /coursemaster_site but i want url to be in coursemaster_site after closing the search results.
controller:coursemaster_site
function index1()
{
$data = array();
$keyword = $this->input->post('keyword');
if($keyword!=""){
$data['results'] = $this->coursemaster_model->search($keyword);
}
$this->load->view('coursemaster_view', $data);
}
view:coursemaster_view
<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search" onClick="hide1('hiddendiv')" class="btn-success btn" /></center>
</form>
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal" >
<table class="display2 table table-bordered table-striped" id='results'>
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo"<div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
}
echo"no results";
echo'</div>';
echo '</div>'; }
// If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function hide1(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>

Change to:
<div id='hideme'>CLOSE
<a href='/coursemaster_site' class='close_notification' title='Click to Close'>
...
on both places. The leading slash makes the href start from root.

Do the following changes and check if it works or not:
<div id='hideme'>
CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";

Related

datatables with ajax in php

I am working on event management site where i've to send emails and show the read, unread, bounced back...etc status email address in modal box. Showing the email addresses in modal box is working fine. I want to add datatables to it. When i Load the modal box first time it is showing the pagination but when i click on second time there is datatables error. Can Anyone help me in this please? Below is my code:-
$("body").on("click", ".textcontent", function(){
var option = $(this).attr("option");
var campaign_id = $("#campaign").val();
$.ajax({
type: "POST",
url: "get_emaillist.php",
data: { option : option, campaign_id : campaign_id },
success: function (resp){
$("#emailslist").html(resp);
$("#myModal").modal("show");
}
});
});
Below is the response from ajax
<?php
$option = $_REQUEST["option"];
$campaign_id = $_REQUEST["campaign_id"];
$emaillist = $gnrl->emaillist($campaign_id,$option);
$totalemail = count($emaillist);
?>
<div class="container">
<div class="row">
<div class="agent-profile">
<div class="col-lg-10 col-sm-10">
<div class="modal fade modelbx" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content" style="padding: 20px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo $option." Users List"; ?></h4>
<?php if($totalemail){ ?>
Export Users
<?php } ?>
</div>
<div class="modal-body">
<?php if(isset($campaign_id) && $campaign_id != "" && $campaign_id != "0"){ ?>
<div class="form-group">
<label class="control-label" for="selectbasic">Event Name</label><hr>
<div><span class="emaillist"><?php echo $campaigntitle = $dclass->select("tbl_campaign","campaignsubject","id = :id",array("id" => $campaign_id)); ?></span></div>
</div>
<?php } if($option == "Nominated" && $totalemail > 0){ ?>
<div class="form-group">
<table border="1" id="statstable">
<thead>
<tr>
<th>Nominated By User</th>
<th>Nominated User Name</th>
<th>Email</th>
<th>Company</th>
<th>Contact Number</th>
<th>Mobile Number</th>
</tr>
</thead>
<tbody>
<?php
if(isset($campaign_id) && $campaign_id != "0"){
$nominateduid = $dclass->select("tbl_nominateusers n left join tbl_user u on n.user_id = u.id","n.id,n.user_id,u.emailaddress"," AND n.campaign_id = '$campaign_id'");
}else{
$nominateduid = $dclass->select("tbl_nominateusers n left join tbl_user u on n.user_id = u.id","n.id,n.user_id,u.emailaddress");
}
foreach($nominateduid as $value){
$nominid = $value["id"];
if(isset($campaign_id) && $campaign_id != "0"){
$selcond = " AND campaign_id = '$campaign_id' AND id = '$nominid'";
}else{
$selcond = " AND user_id = '{$value["user_id"]}' AND id = '$nominid'";
}
$emaildet = $dclass->select("tbl_nominateusers","*",$selcond);
?>
<tr>
<td>
<?php
if($value["user_id"] == 0){
if(isset($campaign_id) && $campaign_id != "0"){
$nominatedemailaddress = $dclass->select("tbl_emailusers","useremail","campaign_id = :campaign_id AND user_id = :user_id",array("campaign_id" => $campaign_id, "user_id" => 0));
}else{
$nominatedemailaddress = $dclass->select("tbl_emailusers","useremail","user_id = :user_id",array("user_id" => 0));
}
}else{
$nominatedemailaddress = $value["emailaddress"];
}
echo $nominatedemailaddress;
?>
</td>
<td>
<?php
if(isset($emaildet[0]["nominatename"]) && $emaildet[0]["nominatename"] != ""){
echo $emaildet[0]["nominatename"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if($totalemail > 0){
echo $emaildet[0]["useremails"];
}else{
echo "There is No $option Email";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["companyname"]) && $emaildet[0]["companyname"] != ""){
echo $emaildet[0]["companyname"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["contactnumber"]) && $emaildet[0]["contactnumber"] != ""){
echo $emaildet[0]["contactnumber"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["mobilenumber"]) && $emaildet[0]["mobilenumber"] != ""){
echo $emaildet[0]["mobilenumber"];
}else{
echo "---";
}
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php }else{ ?>
<div class="form-group">
<table border="1" id="statstable">
<thead><tr><th>Email Address</th></tr></thead>
<tbody>
<?php
if($totalemail > 0){
foreach($emaillist as $emails){
?>
<tr><td><?php echo $emails; ?></td></tr>
<?php } }else{ ?>
<tr><td><?php echo "There is No $option Email"; ?></td></tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<style>
.modal.fade.in{ top: 10%!important; }
img{ max-width: 125%!important; }
.modal-dialog{ width: 900px!important; }
.modal .modal-body{ max-height: 420px; overflow-y: auto; }
.modal{ width: auto!important; }
.carttable, .carttable td{ padding: 5px; }
.modelbx{ background: rgba(0, 0, 0, 0) url("../images/login-main-bg.png") repeat scroll 0 0; bottom: 0; display: none; left: 0; position: fixed; right: 0; top: 0; z-index: 999999 !important; }
.sbbtn{ background-color: green; border: 0!important; border-radius: 10px; color: #fff; height: 35px; width: 90px; }
.alert-success{ color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; }
.alert{ padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; }
.textcontent{ float: left; width:100%; color: #5C9BD5; }
.emaillist{ color: #5698D4; line-height: 30px; margin: 10px; }
td, th{ padding: 10px!important; }
#statstable{ margin-bottom: 20px!important; }
</style>
<script type="text/javascript">
$(document).ready(function (){
$("#statstable").dataTable({
"aaSorting": [[0,"desc"]]
});
});
</script>
When you charge new elements with ajax, the javascript code doesn´t know those new elements. Maybe you can try recalling the data-tables init in the success section of the ajax call.

table page break in CSS

I am implementing the printing of pages in HTML.
My aim is if a table will not be accommodated in the same page, the whole table will be transferred to the next page. How do i do this. i have this code.. please help me.
here is my CSS part.
<style type="text/css">
.printOnly {
margin-top: 100px;
display: none;
}
.textSummaryTable { page-break-inside:auto }
.textSummaryTable tr { page-break-inside:avoid; page-break-after:auto }
#media print {
.summaryTable tr:nth-child(odd){ background-color:#E1E4E5;}
.summaryTable tr:nth-child(even) { background-color:#ffffff; }
.printOnly { display: block; }
.panel {
border: 1px solid transparent;
padding: 2px;
margin: 0;
}
.textSummaryTable{ border:1px solid gray; }
.textSummaryTable td{ border:1px solid gray; }
#main {
overflow: hidden;
position: absolute;
padding: 0px;
height: auto;
width: 100%;
}
#title { display: none; }
#line-break { display: block; }
.textSummaryTable { width: 100%; }
}
#media screen {
#line-break { display: none; }
}
</style>
and My tables are here.
<?php
$this->pageTitle = Yii::app()->name . ' - View Evaluation';
$user = LoginForm::getUser();
?>
<?php $participants = $modelE->evaluationDetails; ?>
<style type="text/css">
#media print {
body {
overflow: hidden;
}
}
</style>
<div class=" non-printable">
<div class='pull-right non-printable'>
<button id="btnPrint" type="button" class="btn btn-default pull-right" onclick="window.print();">
<span class="glyphicon glyphicon-print"></span> Print
</button>
</div>
<?php
$startDate = date("M j, Y", strtotime($modelE->start_date));
$endDate = date("M j, Y", strtotime($modelE->end_date));
?>
</div>
<div id='line-break'>
<br>
<br>
<br>
</div>
<div class="container-fluid">
<div class="printable">
<h4><?php echo htmlentities($modelE->evaluationForm->name); ?></h4>
<h5><?php echo $startDate; ?> - <?php echo $endDate; ?></h5>
<h5>Candidate: <?php echo htmlentities($modelE->evaluatee); ?></h5>
<h5>Overall Evaluation: <?php echo htmlentities($modelE->getResult()); ?></h5>
<h5>Participants: <?php echo htmlentities(count($participants)); ?></h5>
<div class="panel panel-default">
<div class="panel-body">
<h5><strong>Instructions: </strong> <?php echo htmlentities($modelE->evaluationForm->description); ?></h5>
<!-- <h4>Results Summary</h4> -->
<?php
$radioFlag = false;
foreach ($modelE->evaluationForm->evaluationFormDetails as $question) {
$criteria = new CDbCriteria;
$criteria->with = 'evalResult';
$criteria->addInCondition('eval_form_question_id', array($question->id));
$criteria->addInCondition('evalResult.eval_id', array($modelE->id));
$resultSet = EvaluationResultsDetails::model()->findAll($criteria);
if ( strtolower($question->field_type) != "radioheader" && $question->field_type != "slider" ) {
if($radioFlag){
echo "</table>";
$radioFlag = false;
}
if( $question->field_type == "text" ) {
echo "<h4>" . $question->field_name . "</h4>";
}
else {
echo "<table class='textSummaryTable'><tr><td style='width: 100%'><label>" . $question->field_name . "</label></td></tr>";
foreach ($resultSet as $answer) {
echo "<tr><td>" . $answer->eval_answer . "</td></tr>";
}
echo "</table>";
}
} else {
if(!$radioFlag){
echo '<table border-size = 0px width=100% class="summaryTable">';
$radioFlag = true;
}
echo "<tr><td style='width: 90%'>" . $question->field_name . "";
echo "</td><td style='width: 10%'>";
$sum = 0;
$count = 0;
foreach ($resultSet as $answer) {
$count++;
$sum += $answer->eval_answer;
}
echo $count == 0 ? "-" : number_format($sum / $count, 2);
echo "</td></tr>";
/*** end here ***/
}
}
if($radioFlag){
echo "</table>";
}
?>
<table class="printOnly">
<tr>
<td colspan="2">
<p> I hereby certify that all information declared in this document are accurate and true. Each item have been discussed with my Immediate Superior and mutually agreed upon.</p>
</td>
</tr>
<tr>
<td>
<p>Prepared by
<?= $modelE->project->manager->family_name . ", " . $modelE->project->manager->first_name ?>
</p>
Date <?= date("Y-m-d"); ?>
</td>
<td>
<p>Conformed by <?= $modelE->evaluatee ?></p>
Date
</td>
</tr>
<tr>
<td colspan="2">
<p>Noted by HR Division</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>

else statement is displaying

In this below code when i execuete it it shows no results.But i place no results in if-else condition .Actual result: textbox ,submit button and no results..My expected result is a textbox and button should be displayed and not no results.Without searching a data it displays no reults.So any one help me.
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<?php
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
?>
</table></div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
You are checking if $results variable is set or not.
Instead you need to check for if $results is empty or not.
Replace
if($results){
With
if(!empty($results)){
and also make sure that $results contains the array. I mean your variable must have value.
As far as I can tell from your code, $results is not set. Therefore if ($results) evaluates as false and else is displayed.
check the request is a post request or a default page load
use
else if($_SERVER['REQUEST_METHOD'] === 'POST')
{
echo "no results";
}
instead of
else
{
echo "no results";
}

Javascript drag and drop div styling

So I'm trying to make a "Simple" php + javascript drag and drop, here's my code:
<title>Web Editor</title>
<?php
mysql_connect("$host","$user","$pass");
mysql_select_db("$db");
if(isset($_POST['submit'])){
$name=$_FILES['file']['name'];
$temp=$_FILES['file']['tmp_name'];
move_uploaded_file($temp,"uploaded/".$name);
$url="http://www.bluejayke.com/edit/uploaded/$name";
}
?>
<?php
if(isset($_POST['submit'])){
mysql_query("INSERT INTO uploadedvideos(id,name,url) VALUES('','$name','$url')");
echo "</br>" . $name . " uploaded";
}
$query="SELECT * FROM uploadedvideos";
$result = mysql_query($query);
?>
<div class='wrapper' id='wrapper'>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td style="width:400px; height:50px;"><form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">
</form></td>
</tr>
<tr>
<td style="width:400px; height:500px;">
<div style="width:100%; height:100%; overflow:auto; ">
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1");
</script>
<?php
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$name=$row['name'];
$url=$row['url'];
echo "<div style='position:absolute;cursor:pointer;' id='".$id."'><a href='javascript: click(\"$url\")'>$name</br><embed id='$id' src='$url' width='120' height='120' draggable='true' ondragstart='drag(event)'></embed></a><input type='button' id='delete' value='X' onclick='return Deleteqry($id)' /></div><br> ";
?>
<script type="text/javascript">
var dragging = false
$(function () {
var target<?php echo $id ?> = $('#<?php echo $id; ?>')
target<?php echo $id ?>.mousedown(function() { dragging<?php echo $id; ?> = true })
$(document).mouseup(function() { dragging<?php echo $id; ?> = false })
$(document).mousemove(function(e) {
if(dragging<?php echo $id; ?>){
target<?php echo $id ?>.css('left', e.pageX)
target<?php echo $id ?>.css('top', e.pageY)
}
})
})
</script>
<?php
}
?>
</div>
</table>
</div>
<div class='wactch' id='watching' height='480' width='720'>Loading..</div>
<script>
/*document.onmousemove=mouseMove;
function mouseMove(ev)
{
ev = ev || window.event;
var mousePos=mouseCords(ev);
}
function mouseCords(ev)
{
if(ev.pageX || ev.pageY)
{
return{x:ev.pageX,y:ev.pageY);
}
return
{
x:ev.clientX+document.body.scrollLeft-document.body.clientLeft, y:ev.clientY.document.body.scrollTop-document.body.clientTop
};
}
}*/
function Deleteqry(id)
{
if(confirm("Are you sure you want to delete this picture?")==true)
window.location="index.php?del="+id;
return false;
}
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
window.onload=function()
{
click("http://www.bluejayke.com/edit/uploaded/dpnewslogo.png");
}
function click(url)
{
document.getElementById("watching").innerHTML='<embed src="'+url+'" width=720 height=480></embed>';
}
</script>
<?php
if($_GET['del']){
$delete_id=$_GET['del'];
mysql_query("DELETE FROM `uploadedvideos` WHERE `uploadedvideos`.`id` = $delete_id");
header("location: index.php");
}
?>
<style type="text/css">
.wrapper
{
width:500px;
overflow: hidden;
float: left;
}
#watching {
float: right;
}
.div1 {width:750px;height:120px;padding:10px;border:1px solid #aaaaaa; oveflow: hidden;}
</style>
The important part is in the while loop. The result of this code is all the divs I made in the while loop are piled up on top of each other, when I want them in a vertical line-like structure. Anyone have any insight on this? It's something with the div's styling I think, but I'm not sure how to resolve it while still keeping the drag and drop function.
Your divs are being positioned absolute. You simply need to change them to position:relative;
http://www.w3schools.com/css/css_positioning.asp

i want to replace that html code with javascript code?

i want to replace all between <p> tags with a simple word NotFound
<p id='2'>
<?php
foreach ($d as $key=>$value)
{
extract($value);
if($key%4==0)
{
echo "</tr>";
echo"<tr>";
}
include('item.php');
}
echo"</table>";
echo"</div>";
?>
</p>
how can i do that using javaScript??
update:
i used that code in the javascript area:
<script type="text/javascript">
window.onload=msg;
function msg(){
document.getElementById('1').onclick=clickhandlee;
//
}
function clickhandlee(){
var ps = document.getElementsByTagName('p');
for(var i=0, max=ps.length; i<max; i++){
ps[i].innerHTML = "NotFound";
}
}
</script>
and the same previous code in the <body> tags
<p id='2'>
<?php
foreach ($d as $key=>$value)
{
extract($value);
if($key%4==0)
{
echo "</tr>";
echo"<tr>";
}
include('item.php');
}
echo"</table>";
echo"</div>";
?>
</p>
this is the included php template item.php
<td style='border: 0px none ; margin: 0px; padding: 0px; width: 240px;' align='right' valign='top'>
<div style='margin-bottom: 10px;'>
<table class='topic' border='0' cellpadding='0' cellspacing='0' align='right'>
<tbody>
<tr>
<td style='background: url('style/$style/images/top_background.jpg') no-repeat left center; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous' align='center' height='35'>
<div style='overflow: hidden; width: 230px;'>
<a class='link' href='t<?=$id;?>-<?=$name;?>.html'>
<?=$name;?> </a>
</div>
</td>
</tr>
<tr>
<td align='center' style="height: 197px">
<a href='count-<?=$id;?>;.html'>
<img src='<?=$photo;?>' class='image' border='0' width='220' height='170'/></a>
<div dir='rtl' class='shortdes'><?=$shortdes;?></div>
</td>
</tr>
<tr valign='top'>
<td style='background: url('style/$style/images/footer_background.jpg') no-repeat left center; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; height: 29px;' align='center' height='35'>
<a class='dlink' href='count-<?=$id;?>.html'>
<div class='download' style="height: 17px">
التحميل : <?=$visits;?>
</div></a>
</td>
</tr>
</tbody>
</table>
</div>
</td>
var paragraphs = document.getElementsByTagName('p'),
i = paragraphs.length;
while (i--)
{
paragraphs[i].innerHTML = 'NotFound';
}
Using Javascript:
var ps = document.getElementsByTagName('p');
for(var i=0, max=ps.length; i<max; i++)
ps[i].innerHTML = "NotFound";
Using Javascript
Note comment by user DA - IDs cannot start with a number before HTML 5, so assume that the ID is spelled out (two) instead of the numeral (2) if not using HTML 5.
If it is only for the <p> tag with id=two:
document.getElementById("two").innerHTML = "NotFound";
If it is for all <p> tags:
var paragraphs = document.getElementsByTagName("p");
for(var i = 0; i < paragraphs.length; i++) {
paragraphs[i].innerHTML = "NotFound";
}
The key is the innerHTML tag of the DOM elements.
If you're using jquery: $('p').html('NotFound');

Categories