Working with multiple dialog boxes, logics error - jquery-ui

I am using the following code to View Complete Messages from Users, on my web page.
u can see my web page here : http://team-kh.hireexpertprogrammers.com/~maiarn/Admin.php
But the only prob is some logic Error here, When i randomly click on the View Complete link, the dialog Box, shows me the title and content of the first message. How can i avoid this error:
Such that, which View Complete Link is clicked, the dialog box shall show the title and content of that row , message.
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"FullName");
$Name = $ f1;
$f2=mysql_result($result,$i,"EmailAddr");
$string=mysql_result($result,$i,"Message");
$limit=10;
$string1 = myTruncate($string,$limit);
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $string1; ?></font>
<a id="button1"href="#">View Complete</a>
<div id="dialog1"title="<?php echo $Name; ?>" style="display: none;">
<?php echo $string; ?></div>
</td>
</tr>
<?php
$i++;
}
?>
The script is
<script type="text/javascript" src="jquery/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery-ui-1.8.18.custom.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$("a#button1").click(function(e) {
e.preventDefault();
$("#dialog1").dialog({height: 300, width: 500, modal: true});
});
});
</script>

You either need to assign dynamic ID's to your dialogs based on a number or some other distinguishing string or load the information from the row into a single dialog before you display it (which would be preferable).

Related

Kendo Panelbar MVC - Trying to Open Popup by clicking on a menu item

In my program we have Kendo Panel bar which shows menu, i want to open a dialog box/ popup window when user clicks on any menu child item.
<div>
#(Html.Kendo().PanelBar()
.Name("panelbar")
.ExpandMode(PanelBarExpandMode.Single)
.Events(events => events
.Select(#<text> ReportController.onSelect </text>))
.Items(panelbar =>
{
panelbar.Add().Text("Test1")
.Expanded(true)
.Items(Test1=>
{
workers.Add().Text("Sample1");
workers.Add().Text("Sample2");
workers.Add().Text("Sample3");
});
panelbar.Add().Text("Test2")
.Items(Test2 =>
{
clients.Add().Text("Book1")
.Items(costings =>
{
costings.Add().Text("Page1");
costings.Add().Text("Page2");
costings.Add().Text("Page3");
});
clients.Add().Text("Book2");
});
panelbar.Add().Text("New Page").Enabled(false);
})
)
</div>
<script type="text/javascript">
$(document)
.ready(function() {
ReportController.init("#panelBar");
});
</script>
If user clicks on Sample1 here it should open a popup window. i am new with kendo controls, how can i achieve this?
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/panelbar/events">
<style>
html {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.default.mobile.min.css" />
<script src="//kendo.cdn.telerik.com/2016.2.714/js/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.714/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="../content/shared/styles/examples-offline.css">
<script src="../content/shared/js/console.js"></script>
</head>
<body>
<div id="example">
<div class="demo-section k-content">
<ul id="panelbar">
<li class="k-state-active">
Metallica - Master of Puppets 1986
<ul>
<li>Battery</li>
<li>Master of Puppets</li>
<li>The Thing That Should Not Be</li>
<li>Welcome Home (Sanitarium)</li>
<li>Disposable Heroes</li>
<li>Leper Messiah</li>
<li>Orion (Instrumental)</li>
<li>Damage, Inc.</li>
</ul>
</li>
<li>
Iron Maiden - Brave New World 2000
<ul>
<li>The Wicker Man</li>
<li>Ghost Of The Navigator</li>
<li>Brave New World</li>
<li>Blood Brothers</li>
<li>The Mercenary</li>
<li>Dream Of Mirrors</li>
<li>The Fallen Angel</li>
<li>The Nomad</li>
<li>Out Of The Silent Planet</li>
<li>The Thin Line Between Love And Hate</li>
</ul>
</li>
<li>
Empty Item
</li>
<li>
Ajax Item
<div></div>
</li>
<li>
Error Item
<div></div>
</li>
</ul>
</div>
<div id="console" class="box" style="display:none">
<h4>Console log</h4>
<div class="console"></div>
</div>
</div>
<script>
$(function () {
$("#console").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
});
function onSelect(e) {
var theDialog = $("#console").dialog("open");
theDialog.dialog("open");
kendoConsole.log("Select: " + $(e.item).find("> .k-link").text());
}
function onExpand(e) {
kendoConsole.log("Expand: " + $(e.item).find("> .k-link").text());
}
function onCollapse(e) {
kendoConsole.log("Collapse: " + $(e.item).find("> .k-link").text());
}
function onActivate(e) {
kendoConsole.log("Activate: " + $(e.item).find("> .k-link").text());
}
function onContentLoad(e) {
kendoConsole.log("Content loaded in <b>" + $(e.item).find("> .k-link").text() +
"</b> and starts with <b>" + $(e.contentElement).text().substr(0, 20) + "...</b>");
}
function onError(e) {
kendoConsole.error("Loading failed with " + e.xhr.statusText + " " + e.xhr.status);
}
$("#panelbar").kendoPanelBar({
expandMode: "single",
select: onSelect,
expand: onExpand,
collapse: onCollapse,
activate: onActivate,
contentLoad: onContentLoad,
error: onError,
contentUrls: [, , , "../content/web/panelbar/ajax/ajaxContent1.html", "error.html"]
});
</script>
</body>
</html>
In above example, you can observe that in OnSelect Event , i have opened a Div as an Dialog(Model), for which i have intialised that in its above function.
Hope it helps.. !!

Flexslider not syncing with dynamic items

I have flexslider activated with a ACF for each loop using this code:
$(window).load(function() {
// The slider being synced must be initialized first
$('#gallerycarousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
directionNav: true,
itemWidth: 300,
itemMargin: 10,
animationLoop: true,
asNavFor: '#galleryslider'
});
$('#galleryslider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
directionNav: true,
sync: "#gallerycarousel"
});
});
<div class="flexslider" id="galleryslider">
<ul class="slides">
<?php
$gallery = get_field('fullgallery');
foreach( $gallery as $galleryImage ):
$image = $galleryImage['url']; ?>
<li style="background-image: url('<?php echo $image; ?>')"></li>
<?php endforeach; ?>
</ul>
</div>
<div class="flexslider" id="gallerycarousel">
<ul class="slides">
<?php
foreach( $gallery as $galleryImage ):
$image = $galleryImage['url'];
?>
<li style="background-image: url('<?php echo $image; ?>'); background-size: cover;">
<div class="viewImg">
<a class="fancybox" rel="gallery1" href="<?php echo $image; ?>" title="<?php echo $galleryImage['caption']; ?>"><i class="fa fa-search"></i></a>
</div>
</li>
<meta property="og:image" content="<?php echo $galleryImage['url']; ?>" />
<?php endforeach; ?>
</ul>
</div>
My issue is that on click of a thumbnail, it takes me to the wrong large image, I have tried re-downloading flexslider but no luck, I have also tried replacing the for each loop with just static items and, that seems to fix it.
I am unsure on how to get it to work with the foreach loop, does anyone have a solution for this?
It seems removing this: <meta property="og:image" content="<?php echo $galleryImage['url']; ?>" /> fixed the issue.

What can i do to find a Broken Link?

I am working on a website and the owner of the website found three broken links (through a software/tool of IBM) in the given page. I removed two broken links but there is one broken link left. I searched the whole web page but I am unable to find it.
What can I do to find that link?
Here is the code of the page:
<?php
session_start();
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Legal Aid Service Monitoring System</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery3.js"></script>
<script type="text/javascript" src="js/jquery4.js"></script>
<script type="text/javascript" src="js/jquery5.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#login-form").validate({
debug: false,
rules: {
email: {
required: true,
email: true
}
},
messages: {
email: "Please enter a valid email.",
},
});
});
</script>
<style type="text/css">
label.error { width: 250px; color: red;}
</style>
</head>
<body>
<?php
if($_POST['login'])
{
require_once("config.php");
if($_POST['user_type']=='admin')
{
$user=mysql_real_escape_string($_POST['uname']);
$password=md5($_POST['pwd']);
$sql=mysql_query("select id from admin where username='$user' and password='$password'");
$count=mysql_num_rows($sql);
if($count>0)
{
$row=mysql_fetch_array($sql);
$_SESSION['admin']=$row['id'];
$date=date('d-m-y');
$time_now=mktime(date('h')+0,date('i')+00,date('s'));
$time=date('h:i:s',$time_now);
$login=mysql_query("insert into user_login (user_id, login_date, login_time) values ('$_SESSION[admin]', '$date', '$time')");
header('location: administrator');
}
else
{
?>
<script type="text/javascript"> alert('Incorrect Username and Password.');</script>
<?php
}
}
else if($_POST['user_type']=='advo')
{
$user=mysql_real_escape_string($_POST['uname']);
$password=md5($_POST['pwd']);
$sql=mysql_query("select id, status from advocates where email='$user' and password='$password'");
$count=mysql_num_rows($sql);
$row=mysql_fetch_array($sql);
if($count>0 and $row['status']=='1')
{
$_SESSION['advocate']=$row['id'];
$date=date('d-m-y');
$time_now=mktime(date('h')+0,date('i')+00,date('s'));
$time=date('h:i:s',$time_now);
$login=mysql_query("insert into advo_login (advo_id, login_date, login_time) values ('$_SESSION[advocate]', '$date', '$time')");
header('location: advocate');
}
else
{
if($row['status']=='0')
{
?>
<script type="text/javascript">alert('Your account has been blocked by admin.');</script>
<?php
}
else
{
?>
<script type="text/javascript">alert('Incorrect Username and Password.');</script>
<?php
}
}
}
}
?>
<div class="main" id="main">
<div id="headerbg">
<div id="header"></div>
</div>
<div id="center">
<div class="style1" id="centerright">
<div id="centerup">
<table width="514" border="0" align="center">
<tr>
<td><h3>Welcome to Legal Aid Service Monitoring System</h3></td>
</tr>
</table>
</div>
<div id="centerdown">
<div id="loginbg">
<form id="login-form" name="login-form" method="post" action="">
<table width="500" border="0" >
<tr><td></td>
<td height="30">
<input type="radio" name="user_type" value="advo" checked="checked" />Advocate
<input type="radio" name="user_type" value="admin" />Administrator
</td>
</tr>
<tr>
<td width="50"><span class="style5">Username:</span></td>
<td width="236"><label>
<input type="text" name="uname" class="required input" size="30" />
</label></td>
</tr>
<tr>
<td><span class="style5">Password:</span></td>
<td><label>
<input type="password" name="pwd" id="pwd" class="required input" size="30"/>
</label></td>
</tr>
<tr>
<td></td>
<td><label>
<input type="submit" class="style1loginbg" name="login" id="button" value="Login" />
</label></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If you have Firebug or somekind of similar console access you could run this snippet of code on a page by page basis:
jQuery(function(){
var getHost = function(url){
url = String(url);
if ( (url.substr(0,5) == 'http:') || (url.substr(0,6) == 'https:') ) {
return url.split('/').slice(0,3).join('/');
}
else {
return null;
}
}
var host = getHost(window.location);
jQuery('a').each(function(){
var link = $(this), href = link.attr('href'), hst = getHost(href);
if ( hst === host || hst === null ){
jQuery.ajax({
url: href,
error: function(){
link.css('border', '5px solid red');
}
});
}
else {
link.css('border', '5px solid purple');
window.open( link,'_blank');
}
});
});
It should highlight with a red border any internal links that fail to load via ajax, and highlight any external links with purple (at which point it'll try and open the external link in a new tab for you to visually check). Obviously this might go a bit mad if your page has many external links...
It would be far better to actually get some link checking software - search Google - and run that... as that should act in a way that's know as 'Spidering a site'. Basically it would step through each of your pages and return a report of all the broken links found (you'd have to make sure the software supported cookies seeing as the site you've given requires authorisation).
One further thing to be aware of is that it isn't just links that can cause software to fire a 'broken link' error. You may find that some of your page resources trigger a 404... i.e. you should check all your images, css and js to make sure they load.
This suggestion doesn't solve the question, but I believe it's worth mentioning that the WebDev toolbar (http://chrispederick.com/work/web-developer/ (a firefox add-on) can at least help here.
It can display all links in a webpage and highlight and show all anchors. This can help the developer to 'scan' a website for out-of-place links. )
When installed, choose INFORMATION ยป and either
Display anchors
Display page information
Display link information
You can use a tool like phantomjs or protractor for this. One working tool can be found on https://github.com/ashittheone/broken-links-log.
this repository can be used to log all broken links upto 5 depth of anywebsite.
Although in a later version the depth is expected to be coming customizable

Insertion into google fusion table

I want to insert data into my fusion table which is public . I looked out at https://developers.google.com/fusiontables/docs/sample_code for help specifically http://code.google.com/p/fusion-tables-client-php/source/browse/trunk/samples/form_example.php . I downloaded the necessary files for this script to run i.e. downloaded clienlogin.php , file.php , sql.php and constants.php. The script is running but rows are not getting inserted and I am not able to find the reason . I have pasted my code ( its a small code .. please have a look at it and let me know the error I am commiting). Essentially I want to insert data into my fusion table after collecting user info through user forms . I don't want to use google forms. Any kind of help / pointers in this direction would be helpful.
<html>
<?php
include('D:\xampp\htdocs\itpold\clientlogin.php');
include('D:\xampp\htdocs\itpold\sql.php');
include('D:\xampp\htdocs\itpold\file.php');
// Table id
$tableid = 3544282;
//Enter your username and password
$username = "ABCD#gmail.com";
$password = "XYZ";
$token = ClientLogin::getAuthToken($username, $password);
$ftclient = new FTClientLogin($token);
// If the request is a post, insert the data into the table
if($_SERVER['REQUEST_METHOD'] == 'POST') {
// Insert form data into table
$insertresults = $ftclient->query(SQLBuilder::insert($tableid,
array('Name'=> $_POST['Name'],
'Location' => $_POST['Location'])));
$insertresults = explode("\n", $insertresults);
$rowid1 = $insertresults[1];
echo $rowid1 ;
}
?>
<head>
<title>Simple Form Example</title>
<style>
body { font-family: Arial, sans-serif; }
</style>
<script type="text/javascript">
// Simple form checking.
function check_form() {
if(document.getElementById('Name').value == '' ||
document.getElementById('Location').value == '') {
alert('Name and location required.');
return false;
}
return true;
}
</script>
</head>
<body >
<h1>Simple Form Example</h1>
<h2>Insert data</h2>
<form method="post" action="forms.php" onsubmit="return check_form();">
Name: <input type="text" name="Name" id="Name" /><br />
Result: <input type="text" name="Location" id="Location" /><br />
<input type="submit" value="Submit" />
</form>
<h2>Table data</h2>
<p>
<?php
// Show the data from table
$table_data = $ftclient->query(SQLBuilder::select($tableid));
$table_data = explode("\n", $table_data);
for($i = 0; $i < count($table_data); $i++) {
echo $table_data[$i] . '<br />';
}
?>
</p>
</body>
</html>
Often, the server is not able to send requests to secure URLs. See the following StackOverflow post for some ideas on how to fix the problem:
Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?
I suspect that this is a permissions problem with your table. Have you made sure that the account your are logging in with is set up as an editor for this table? The easiest way to check this is to go into Fusion Tables as the owner for the table, and click the share link in the upper right hand corner.

jQuery UI datepicker causes screen to scroll to the top after selecting a date

I have a couple of jQuery datepickers inside a jQuery dialog. Whenever users select a date from the datepicker the screen scrolls to the top. This only happens in IE8 not the Firefox 3.6 or Chrome 5. Since the majority of users will user IE this is going to be very annoying. Can anyone give me a clue as to why this is happening?
Here is a snippet of the HTML for the dialog:
<div id="AppointmentDialog" style="display: none; font-size: 12px;">
<table>
<tr class="lesson notAvailable allDay">
<td>
Start
</td>
<td>
<input id="txtStartDate" type="text" readonly="readonly" style="width: 90px" class="lesson notAvailable allDay" />
<input id="txtStartTime" type="text" style="width: 50px" class="lesson notAvailable" />
<input id="hidStartTime" type="hidden" value="" />
</td>
</tr>
<tr class="notAvailable allDay">
<td>
End
</td>
<td>
<input id="txtEndDate" type="text" readonly="readonly" style="width: 90px" class="notAvailable allDay" />
<input id="txtEndTime" type="text" style="width: 50px" class="notAvailable" />
<input id="hidEndTime" type="hidden" value="" />
</td>
</tr>
</table>
</div>
Snippet of Javascript to initialise the dialog and datepickers:
$(document).ready(function() {
initDialogs();
});
function initDialogs() {
// Configure the New Appointment dialog
$("#AppointmentDialog").dialog({
autoOpen: false,
resizable: false,
width: 320,
modal: true,
title: 'Appointment',
buttons: {
"Close": function() { $(this).dialog("close"); },
"Save": function() {
// Function call
}
}
});
$.mask.definitions['h'] = '[012]';
$.mask.definitions['m'] = '[012345]';
$("#txtStartTime").mask("h9:m9");
$("#txtEndTime").mask("h9:m9");
// Init date pickers
$("#txtStartDate").datepicker({ dateFormat: 'dd-mm-yy' });
$("#txtEndDate").datepicker({ dateFormat: 'dd-mm-yy' });
};
EDIT
I'm using jQuery 1.4.2 and UI 1.8.2
I've looked into it again. The bug has been reported with a workaround.
I'm using a minified version of jQuery UI so the code looks like this:
(B?" ui-priority-secondary":"")+'" href="#">'+q.getDate()+"</a>")+"</td>"
(B?" ui-priority-secondary":"")+'" href="javascript:;">'+q.getDate()+"</a>")+"</td>"
I had this exact problem, but the real issue turned out to be duplicate ids on the page. Once I removed the duplicate id the problem went away completely.
I wasn't allowed to touch js libraries, I added this line under onSelect handler.
$('#ui-datepicker-div table td a').attr('href', 'javascript:;');
so my code looked like
$('#txtDate').datepicker({
// other properties
onSelect: function (selectedDate) {
$('#ui-datepicker-div table td a').attr('href', 'javascript:;');
// other code
}
});
You need to override the "$" placeholder with "jQuery" if the text contain "#"

Resources