Refreshing parent main window from child small window

Posted on February 11, 2010
Filed Under JavaScript | Leave a Comment

Hello Friends,

If you want to know how to refreshing parent widow from child small window. so first you create JavaScript function in child window page and in function for example :-

<script language="javascript">
function par_refresh()
{
window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
}
}
</script>

then use this function on child close button for example:-

<input onclick="par_refresh()" type="button" value="Close" />

And if you want go another url in parent main window from child small window so here is code below..

<script language="javascript">
var randomnumber=Math.floor(Math.random()*11);
parent.opener.location.href='another page url?sid='+randomnumber;
parent.close();
</script>

So here you can easily refresh and redirect your parent window through this code..

Enjoy and keep in touch :)

Hyper Text Markup Language – HTML

Posted on December 28, 2009
Filed Under HTML | 3 Comments

Hello Friends,

Welcome in Codehunter.in for html tutorial. here you will learn how to use html for creaing your own website.

HTML, which stands for HyperText Markup Language, is a markup language used to create web pages. The web developer uses “HTML tags” to format different parts of the document. For example, you use HTML tags to specify headings, paragraphs, lists, tables, images and much more.

HTML is a subset of Standard Generalized Markup Language (SGML) and is specified by the World Wide Web Consortium (W3C).

What do I need to create HTML?
You have everything to create html page.

1. Computer
2. Text-editor or html editor
3. Web browser

HTML Tags

HTML markup tags are usually called HTML tags

HTML Documents = Web Pages

So here you can start with first example

<html>
<body>

<h1>First Heading</h1>

<p>first paragraph.</p>

</body>
</html>

Keep visiting for more and keep in touch :)

Code Hunter Dynamic Slide Show

Posted on December 23, 2009
Filed Under PHP | 2 Comments

Hello Friends,

Here I give you code hunter dynamic slide show with image lightbox with the help of highslide. so here you can easily to download this script.
Download :- Click Here. and Demo here

Here the index.php code below…

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

 <title>Code Hunter Slide Dynamic Slide Show</title>
 <link rel="stylesheet" href="css/image-slideshow.css" type="text/css">
 <script type="text/javascript" src="js/image-slideshow.js">
 </script>

 <head>

<script type="text/javascript" src="highslide/highslide.js"></script>
<script type="text/javascript">    

// remove the registerOverlay call to disable the close button

hs.registerOverlay({

 overlayId: 'closebutton',

 position: 'top right',

 fade: 2 // fading the semi-transparent overlay looks bad in IE

});

hs.graphicsDir = 'highslide/graphics/';

</script>

<!-- 

 3) These CSS-styles are necessary for the script to work. You may also put

 them in an external CSS-file. See the webpage for documentation.

-->

<style type="text/css">

/** {

 font-family: Verdana, Helvetica;

 font-size: 10pt;

}*/

.highslide {

 cursor: url(highslide/graphics/zoomin.cur), pointer;

 outline: none;

}

.highslide-active-anchor img {

 visibility: hidden;

}

.highslide img {

 border: 0px;

}

.highslide:hover img {

 border: 2px solid silver;

}

.highslide-wrapper {

 background: white;

}

.highslide-image {

 border-bottom: 1px solid white;

}

.highslide-image-blur {

}

.highslide-caption {

 display: none;

 border-bottom: 1px solid white;

 padding: 5px;

 background-color: silver;

}

.highslide-loading {

 display: block;

 color: black;

 text-decoration: none;

 padding: 2px;

 border: 1px solid black;

 background-color: white;

 padding-left: 22px;

 background-image: url(highslide/graphics/loader.white.gif);

 background-repeat: no-repeat;

 background-position: 3px 1px;

}

a.highslide-credits,

a.highslide-credits i {

 padding: 2px;

 color: silver;

 text-decoration: none;

}

a.highslide-credits:hover,

a.highslide-credits:hover i {

 color: white;

 background-color: gray;

}

a.highslide-full-expand {

 background: url(highslide/graphics/fullexpand.gif) no-repeat;

 display: block;

 margin: 0 10px 10px 0;

 width: 34px;

 height: 34px;

}

.highslide-overlay {

 display: none;

}

/* Mac-style close button */

.closebutton {

 position: relative;

 top: -15px;

 left: 15px;

 width: 30px;

 height: 30px;

 cursor: hand; /* ie */

 cursor: pointer; /* w3c */

 background: url(highslide/graphics/close.png);

 /* For IE6, remove background and add filter */

 _background: none;

 _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='highslide/graphics/close.png', sizingMethod='scale');

}

/* These must always be last */

.highslide-display-block {

 display: block;

}

.highslide-display-none {

 display: none;

}

</style>

</head>
</head>
<body>
<center>
<h1>Code Hunter Dynamic Slide Show</h1>
<div id="dhtmlgoodies_slideshow">

 <div id="galleryContainer">
 <div id="arrow_left"><img src="images/arrow_left.gif"></div>
 <div id="arrow_right"><img src="images/arrow_right.gif"></div>
 <div id="theImages">
 <?php
 $con=mysql_connect("localhost","wwwcode_demo","demo123");
 mysql_select_db("wwwcode_demo",$con);
 $result=mysql_query("select * from user_gallery_photo where type='wearlook'");
 while($row=mysql_fetch_array($result))
 {

 ?>
 <a href="wearimage/<?php echo $row['image_path'];?>" onclick="return hs.expand(this)"><img src="wearimage/<?php echo $row['image_path'];?>" width="100" height="100"></a>

 <?php
 }

 ?>

 <!-- Thumbnails -->

 <!-- End thumbnails -->

 <div id="slideEnd"></div>
 </div>
 </div>
</div>
<b><a href="http://www.codehunter.in">Back to Codehunter</a></b>
</center>
</body>
</html>

Manage database connection according to your database info and import the user_gallery_photo table in give Zip file so Enjoy this slide show If you have any problem in this script so please feel free to ask me, I will solve it.

Keep in touch :)

Ajax Image Upload & Change Image Dimension Script

Posted on December 7, 2009
Filed Under Ajax | 3 Comments

Hello Friends,

In this script you can easily upload and change image dimension through Ajax according to your given dimension.
you can easily to manage this script in your site, here the code below…..

Here your index.php code….

<html>
<head>
<title>Ajax Image Upload & Change Image Dimension Script</title>
<style>
iframe {border-width: 0px;height: 200px;width: 400px;}
iframe.hidden {visibility: hidden;width:0px;height:0px;}
#main1 {overflow: hidden;margin: auto;width: 90%;height: 460px;border-style: solid;border-width: 1px;background-color: white;}
#images1 {margin: 20px;}
#images1 div {margin: 10px;border-style: solid;border-width: 2px;border-color: #DEDFDE;float: left;overflow: hidden;}
#images1 div:hover {border-color: #D8F18C;}
#images1 img.load { margin-top:20px;}
.blacklink:link, .blacklink:alink, .blacklink:vlink, .blacklink:hover{color:#000000}
a.redlink{color: #96001C; text-decoration: none}
a:hover.redlink{color: #96001C; text-decoration: underline}
</style>
</head>
<body>
<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
 <Tr><td align="center"><h1>Code Hunter</h1></td></Tr>
 <Tr>
 <td align="center" valign="middle">
 <div id="main1">
 <div id="iframe">
 <iframe src="upload.php" frameborder="0"></iframe>
 </div>
 <div id="images1">
 </div>
 </div>
 <div id="myDivLink"></div>
 </td>
 </Tr>
 <tr>
 <Td align="center">
 Power by <a href="http://www.Codehunter.in">Code Hunter</a>
 </Td>
 </tr>
</table>    
</body>
</html>

Here your upload.php code

<?php sleep(2);
 $ftmp = $_FILES['image']['tmp_name'];
 $oname = $_FILES['image']['name'];
 $target_path = "upload/";
 $extenssion = strstr($oname, ".");
 $fname = 'upload/'.$_FILES['image']['name'];
 $width=$_POST['width'];
 $height=$_POST['height'];
 if(move_uploaded_file($ftmp, $fname)){
 $target_path = $target_path . basename( $_FILES['image']['name']);  
 $str_images=explode('.',$_FILES['image']['name']);
include("thum.php");
copy($target_path,'thumbnails/'.$_FILES['image']['name']);
resize_picture($width, $height, 'thumbnails/'.$_FILES['image']['name'], $str_images[1]);
 ?>
 <html><head><script>
 var par = window.parent.document;
 var images = par.getElementById('images1');
 var imgdiv = images.getElementsByTagName('div')[<?php echo (int)$_POST['imgnum'];?>];
 var image = imgdiv.getElementsByTagName('img')[0];
 imgdiv.removeChild(image); 

 var image_new = par.createElement('img');
 image_new.src = 'resize.php?pic=<?php echo $oname;?>';
 image_new.className = 'loaded'; 

 imgdiv.appendChild(image_new); 

 var bre    =    par.createElement('br');
 imgdiv.appendChild(bre); 

 var oNewP = par.createElement('span');
 var oText = par.createTextNode("  ");
 oNewP.appendChild(oText);
 imgdiv.appendChild(oNewP); 

 </script>
 <?php
 exit();
 }    
?>
<script language="javascript">
function upload(){
 // hide old iframe
 var par = window.parent.document;
 var num = par.getElementsByTagName('iframe').length - 1;
 var iframe = par.getElementsByTagName('iframe')[num];
 iframe.className = 'hidden'; 

 // create new iframe
 var new_iframe = par.createElement('iframe');
 new_iframe.src = 'upload.php';
 new_iframe.frameBorder = '0';
 par.getElementById('iframe').appendChild(new_iframe); 

 // add image progress
 var images = par.getElementById('images1');
 var new_div = par.createElement('div');
 var new_img = par.createElement('img');
 new_img.src = 'thumbnails/'+document.iform.image.value;
 new_img.className = 'load';
 new_div.appendChild(new_img); 

 images.appendChild(new_div); 

 var imgnum = images.getElementsByTagName('div').length - 1;
 document.iform.imgnum.value = imgnum;
 setTimeout(document.iform.submit(),5000);
}
</script>
<style>
#file {
 width: 350px;
}
</style>
</head><body><center>
<form name="iform" action="" method="post" enctype="multipart/form-data">
<table>
<tr><td>
Width :</td><td><input type"text" name="width"> </td><tr><td>Height :</td><td><input type="text" name="height"></td></tr>
<tr><td colspan="2">
<input id="file" type="file" name="image" onChange="upload()" /></td></tr>
<input type="hidden" name="imgnum" />
</table>
</form>
</center></html>

Here your thum.php code…

<?php
function resize_picture($w, $h, $picture, $format)
 {
 $format = str_replace(".", "", $format);
 switch(strtolower($format))
 {
 case "jpg":
 //$th_size = new_picture_size($w, $h, $picture);
 $oldpic = imagecreatefromjpeg($picture);
 $newpic = imagecreatetruecolor($w, $h);
 $size = min(imageSX($oldpic), imageSY($oldpic));
 $offsetX = (imageSX($oldpic) - $size) / 2;
 imagecopyresampled($newpic, $oldpic, 0, 0, $offsetX, 0, $w, $h, $size, $size); 

 imagejpeg($newpic, $picture, 100);
 imagedestroy($oldpic);
 imagedestroy($newpic);
 break;
 case "jpeg":
 $oldpic = imagecreatefromjpeg($picture);
 $newpic = imagecreatetruecolor($w, $h);
 $size = min(imageSX($oldpic), imageSY($oldpic));
 $offsetX = (imageSX($oldpic) - $size) / 2;
 imagecopyresampled($newpic, $oldpic, 0, 0, $offsetX, 0, $w, $h, $size, $size);
 imagejpeg($newpic, $picture, 100);
 imagedestroy($oldpic);
 imagedestroy($newpic);
 break;
 case "png":
 $oldpic = imagecreatefrompng($picture);
 $newpic = imagecreatetruecolor($w, $h);
 $size = min(imageSX($oldpic), imageSY($oldpic));
 $offsetX = (imageSX($oldpic) - $size) / 2;
 //$offsetY = (imageSX($oldpic) - $size) / 2;
 imagecopyresampled($newpic, $oldpic, 0, 0, $offsetX, 0, $w, $h, $size, $size);
 imagepng($newpic, $picture, 100);
 imagedestroy($oldpic);
 imagedestroy($newpic);
 break;
 case "gif";
 $oldpic = imagecreatefromgif($picture);
 $newpic = imagecreate($w, $h);
 $size = min(imageSX($oldpic), imageSY($oldpic));
 $offsetX = (imageSX($oldpic) - $size) / 2;
 //$offsetY = (imageSX($oldpic) - $size) / 2;
 imagecopyresampled($newpic, $oldpic, 0, 0, $offsetX, 0, $w, $h, $size, $size);
 imagegif($newpic, $picture, 100);
 imagedestroy($oldpic);
 imagedestroy($newpic);
 break;
 }
 }
?>

And here your last page resize.php code…

<?php
if($_GET['pic']){
 $img = new img('upload/'.$_GET['pic']);
 $width    =    $_GET["width"];
 $height    =    $_GET["height"];
 $img->resize();
 $img->show();
} 

class img { 

 var $image = '';
 var $temp = ''; 

 function img($sourceFile){
 if(file_exists($sourceFile)){
 $this->image = ImageCreateFromJPEG($sourceFile);
 } else {
 $this->errorHandler();
 }
 return;
 } 

 function resize($width = 100, $height = 100, $aspectradio = true){
 $o_wd = imagesx($this->image);
 $o_ht = imagesy($this->image);
 if(isset($aspectradio)&&$aspectradio) {
 $w = round($o_wd * $height / $o_ht);
 $h = round($o_ht * $width / $o_wd);
 if(($height-$h)<($width-$w)){
 $width =& $w;
 } else {
 $height =& $h;
 }
 }
 $this->temp = imageCreateTrueColor($width,$height);
 imageCopyResampled($this->temp, $this->image,
 0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
 $this->sync();
 return;
 } 

 function sync(){
 $this->image =& $this->temp;
 unset($this->temp);
 $this->temp = '';
 return;
 } 

 function show(){
 $this->_sendHeader();
 ImageJPEG($this->image);
 return;
 } 

 function _sendHeader(){
 header('Content-Type: image/jpeg');
 } 

 function errorHandler(){
 echo "error";
 exit();
 } 

 function store($file){
 ImageJPEG($this->image,$file);
 return;
 } 

 function watermark($pngImage, $left = 0, $top = 0){
 ImageAlphaBlending($this->image, true);
 $layer = ImageCreateFromPNG($pngImage);  
 $logoW = ImageSX($layer);  
 $logoH = ImageSY($layer);  
 ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);  
 }
}
?>

Manage this all pages and create two folder :-

1. thumbnails

2. upload

In thumbnails folder you got your resized image according to your given dimension and in upload folder here your original  image..

So enjoy the Ajax Image Upload & Change Image Dimension Script.

Keep in touch :)

Simple Dynamic Ajax Agent Paging

Posted on November 30, 2009
Filed Under Ajax | 5 Comments

Hello Friends,

Here I give you simple dynamic paging using ajax agent…

First you create config.php like this…

<?php
$host="localhost"; // Replace with your host name
$username="root"; // Replace with your username
$password="";    // Replace with your Password
$con=mysql_connect($host,$username,$password);
mysql_select_db("paging",$con);
?>

Create Database name paging like this :-

CREATE TABLE `user` (
  `id` int(11) NOT NULL auto_increment,
  `fname` varchar(255) NOT NULL,
  `lname` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

INSERT INTO `user` (`id`, `fname`, `lname`) VALUES
(1, 'balraj', 'parmar'),
(2, 'amit', 'paliwal'),
(3, 'rahul', 'khanna'),
(4, 'raj', 'parmar'),
(5, 'raju', 'parmar'),
(6, 'ritesh', 'parmar');

Here your index.php page..


<?php
//database connection file config.php....
include("config.php");
// Ajax Agent use for paging
include_once("ajax/agent.php");
?>
<!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=iso-8859-1" />
<title>Ajax Paging</title>
<script language="javascript">

function paging(var1,var2)
{
agent.call("function.php","paging","paging_data",var1,var2);
}
function paging_data(str)
{
document.getElementById("paging").innerHTML=str;

}
</script>
<?php
 $agent->init();?>
</head>
<body>
<script language="javascript">paging('0','2');</script>
<center><strong>Ajax Paging</strong></center>
<div id="paging" style="margin-top:100px">
</div>
</body>
</html>

Here Your function.php code….

<?php
include("config.php");
function paging($x,$y)
{

if(!isset($start1)) {
$start1 = 0;
}

$eu1 =($start1-0);
$limit1 =2;
$eu1=$x;

$this1 =$x+$y;
$back1 =$x-$y;
$next1 =$x+$y;
$var='';

$query22="select * from user";

$result22=mysql_query($query22);

$nume1=mysql_num_rows($result22);
if($nume1>0)
{

$select_databse_home=mysql_query("select * from user limit $x,$y");

$num_rpw=mysql_num_rows($select_databse_home);
$num_rpw=$num_rpw+$x;

$var.='<table width="25%" align="center" border="1">

<tr style="background-color:#33CCFF">';

$var.='<th><strong>First Name</span></strong></th>';

$var.='<th><strong>Last Name</strong></th>
</tr>';

$color="#0099FF";
$battu=1;

while($row_data_home=mysql_fetch_array($select_databse_home))
{
if($color=='#0099FF')
{
$color="#ffffff";
}
else
{
$color="#0099FF";
}
$var.='
<tr style="background-color:'.$color.'">
<td style="vertical-align:top;text-align:center">'.$row_data_home['fname'].'</td><td style="vertical-align:top;text-align:center">'.$row_data_home['lname'].'</td>
</tr>';

$battu++;

}

$var.='</table><br>';

$var.='<center><span >';
if($nume1 > $y ){
if($back1 >=0) {
$var.='<a href="javascript:void(0)" onclick="paging('.$back1.','.$limit1.' )"><font face="Verdana" size="2">&nbsp;PREV&nbsp;</font></a>';
}
$i=0;
$l=1;
for($i=0;$i<$nume1;$i=$i+$y)
{
if($i <> $x){
$var.='<a href="javascript:void(0)" onclick="paging('.$i.','.$limit1.' )"><font face="Verdana" size="2">'.$l.'</font></a>';

}
else { $var.='<font face="Verdana" size="2" color=red>'.$l.'</font>';}
$l=$l+1;
}
if($this1 < $nume1) {
$var.='<a href="javascript:void(0)" onclick="paging('.$next1.','.$limit1.' )"><font face="Verdana" size="2">&nbsp;NEXT</font></a>';} }
$var.='</span></center>';
return $var;
}
else
{
return " Sorry No Record!";
}

return $var;
}
include_once("ajax/agent.php");
?>

And here agent.php code…

<?php
/*
--------------------------------------------------------------------
Ajax Agent for PHP v.0.3. Copyright (c) 2006 ajaxagent.org.
@author: Steve Hemmady, Anuta Udyawar <contact at ajaxagent dot org>
This program is free software; you can redistribute it under the
terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version. This program is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more info
at http://www.gnu.org/licenses/gpl.txt
--------------------------------------------------------------------
*/

// produce the client-side script (json.js & agent.js)
if(isset($_GET['ajaxagent']) && $_GET['ajaxagent']=='js') {
?>
<!--
/*
Copyright (c) 2005 JSON.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The Software shall be used for Good, not Evil.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/*
The global object JSON contains two methods.

JSON.stringify(value) takes a JavaScript value and produces a JSON text.
The value must not be cyclical.

JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
throw a 'JSONError' exception if there is an error.
*/
var JSON = {
copyright: '(c)2005 JSON.org',
license: 'http://www.crockford.com/JSON/license.html',
/*
Stringify a JavaScript value, producing a JSON text.
*/
stringify: function (v) {
var a = [];

/*
Emit a string.
*/
function e(s) {
a[a.length] = s;
}

/*
Convert a value.
*/
function g(x) {
var c, i, l, v;

switch (typeof x) {
case 'object':
if (x) {
if (x instanceof Array) {
e('[');
l = a.length;
for (i = 0; i < x.length; i += 1) {
v = x[i];
if (typeof v != 'undefined' &&
typeof v != 'function') {
if (l < a.length) {
e(',');
}
g(v);
}
}
e(']');
return;
} else if (typeof x.toString != 'undefined') {
e('{');
l = a.length;
for (i in x) {
v = x[i];
if (x.hasOwnProperty(i) &&
typeof v != 'undefined' &&
typeof v != 'function') {
if (l < a.length) {
e(',');
}
g(i);
e(':');
g(v);
}
}
return e('}');
}
}
e('null');
return;
case 'number':
e(isFinite(x) ? +x : 'null');
return;
case 'string':
l = x.length;
e('"');
for (i = 0; i < l; i += 1) {
c = x.charAt(i);
if (c >= ' ') {
if (c == '\\' || c == '"') {
e('\\');
}
e(c);
} else {
switch (c) {
case '\b':
e('\\b');
break;
case '\f':
e('\\f');
break;
case '\n':
e('\\n');
break;
case '\r':
e('\\r');
break;
case '\t':
e('\\t');
break;
default:
c = c.charCodeAt();
e('\\u00' + Math.floor(c / 16).toString(16) +
(c % 16).toString(16));
}
}
}
e('"');
return;
case 'boolean':
e(String(x));
return;
default:
e('null');
return;
}
}
g(v);
return a.join('');
},
/*
Parse a JSON text, producing a JavaScript value.
*/
parse: function (text) {
return (/^(\s+|[,:{}\[\]]|"(\\["\\\/bfnrtu]|[^\x00-\x1f"\\]+)*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)+$/.test(text)) &&
eval('(' + text + ')');
}
};

// client-side agent implementation
this_url = "<?php echo $_GET['this_url'] ?>";
function Agent() {
this.debug = false; // default
this.call = function () {
var aa_sfunc = "";
var aa_cfunc = "";
var result = "";
var xmlHttpObject;
if(arguments.length<3) {
alert("Incorrect number of parameters. Please check your function call");
return;
}
aa_url=arguments[0];
aa_sfunc=arguments[1];
aa_cfunc=arguments[2];

if((aa_url==null)||(aa_url=="")) aa_url = this_url;
var aa_poststr = "aa_afunc=call&aa_sfunc=" + encodeURI(aa_sfunc) +
"&aa_cfunc=" + encodeURI(aa_cfunc);
for(var i=3; i<arguments.length; i++) {
if(typeof(arguments[i])=='object') {
aa_poststr += "&aa_sfunc_args[]="+encodeURI(JSON.stringify(arguments[i]));
} else {
aa_poststr += "&aa_sfunc_args[]="+encodeURI(arguments[i]);
}
}
xmlHttpObject = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlHttpObject = new XMLHttpRequest();
if (xmlHttpObject.overrideMimeType) {
xmlHttpObject.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttpObject) {
alert('Agent unable to establish communication  :(  ');
return false;
}

if((aa_sfunc==null)||(aa_sfunc=="")) {
if(arguments[3]) aa_poststr=arguments[3];
}

if((aa_cfunc==null)||(aa_cfunc=="")) {
xmlHttpObject.open('POST', aa_url, false);
xmlHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpObject.setRequestHeader("Content-length", arguments.length+1);
//xmlHttpObject.setRequestHeader("Connection", "close"); // not needed
xmlHttpObject.send(aa_poststr);
return xmlHttpObject.responseText;
} else {
xmlHttpObject.onreadystatechange = function () {
if (xmlHttpObject.readyState == 4) {
if (xmlHttpObject.status == 200) {
result = xmlHttpObject.responseText;
result = result.replace(/\\\"/g,'"');
if(document.getElementById(aa_cfunc)) {
try {
document.getElementById(aa_cfunc).innerHTML=result;
}
catch (e) {
document.getElementById(aa_cfunc).value=result;
}
} else {
if (JSON.parse(result))
eval(aa_cfunc+"(JSON.parse(result));");
else
eval(aa_cfunc+"(result);");
}
} else {
if(xmlHttpObject.status!=0) {
alert('There was a problem with the request.');
}
}
}
}
xmlHttpObject.open('POST', aa_url, true);
xmlHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpObject.setRequestHeader("Content-length", arguments.length+1);
//xmlHttpObject.setRequestHeader("Connection", "close"); // not needed
xmlHttpObject.send(aa_poststr);
return xmlHttpObject;
}
}
this.listen = function (aa_event, aa_cfunc) {
// listener function will come here
}
}
var agent = new Agent();

//-->
<?php
exit();
}

/**********************************************************************/
/****         FOLLOWING BLOCK BORROWED FROM JSON.PHP               ****/
/**********************************************************************/

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* Converts to and from JSON format.
*
* JSON (JavaScript Object Notation) is a lightweight data-interchange
* format. It is easy for humans to read and write. It is easy for machines
* to parse and generate. It is based on a subset of the JavaScript
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
* This feature can also be found in  Python. JSON is a text format that is
* completely language independent but uses conventions that are familiar
* to programmers of the C-family of languages, including C, C++, C#, Java,
* JavaScript, Perl, TCL, and many others. These properties make JSON an
* ideal data-interchange language.
*
* This package provides a simple encoder and decoder for JSON notation. It
* is intended for use with client-side Javascript applications that make
* use of HTTPRequest to perform server communication functions - data can
* be encoded into JSON notation for use in a client-side javascript, or
* decoded from incoming Javascript requests. JSON format is native to
* Javascript, and can be directly eval()'ed with no further parsing
* overhead
*
* All strings should be in ASCII or UTF-8 format!
*
* LICENSE: Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met: Redistributions of source code must retain the
* above copyright notice, this list of conditions and the following
* disclaimer. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* @category
* @package     Services_JSON
* @author      Michal Migurski <mike-json@teczno.com>
* @author      Matt Knapp <mdknapp[at]gmail[dot]com>
* @author      Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
* @copyright   2005 Michal Migurski
* @version     CVS: $Id: JSON.php,v 1.30 2006/03/08 16:10:20 migurski Exp $
* @license     http://www.opensource.org/licenses/bsd-license.php
* @link        http://pear.php.net/pepr/pepr-proposal-show.php?id=198
*/

/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_SLICE',   1);

/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_STR',  2);

/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_ARR',  3);

/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_OBJ',  4);

/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_CMT', 5);

/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_LOOSE_TYPE', 16);

/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);

/**
* Converts to and from JSON format.
*
* Brief example of use:
*
* <code>
* // create a new instance of Services_JSON
* $json = new Services_JSON();
*
* // convert a complexe value to JSON notation, and send it to the browser
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
* $output = $json->encode($value);
*
* print($output);
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
*
* // accept incoming POST data, assumed to be in JSON notation
* $input = file_get_contents('php://input', 1000000);
* $value = $json->decode($input);
* </code>
*/
class Services_JSON
{
/**
* constructs a new JSON instance
*
* @param    int     $use    object behavior flags; combine with boolean-OR
*
*                           possible values:
*                           - SERVICES_JSON_LOOSE_TYPE:  loose typing.
*                                   "{...}" syntax creates associative arrays
*                                   instead of objects in decode().
*                           - SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
*                                   Values which can't be encoded (e.g. resources)
*                                   appear as NULL instead of throwing errors.
*                                   By default, a deeply-nested resource will
*                                   bubble up with an error, so all return values
*                                   from encode() should be checked with isError()
*/
function Services_JSON($use = 0)
{
$this->use = $use;
}

/**
* convert a string from one UTF-16 char to one UTF-8 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param    string  $utf16  UTF-16 character
* @return   string  UTF-8 character
* @access   private
*/
function utf162utf8($utf16)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}

$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});

switch(true) {
case ((0x7F & $bytes) == $bytes):
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x7F & $bytes);

case (0x07FF & $bytes) == $bytes:
// return a 2-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xC0 | (($bytes >> 6) & 0x1F))
. chr(0x80 | ($bytes & 0x3F));

case (0xFFFF & $bytes) == $bytes:
// return a 3-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xE0 | (($bytes >> 12) & 0x0F))
. chr(0x80 | (($bytes >> 6) & 0x3F))
. chr(0x80 | ($bytes & 0x3F));
}

// ignoring UTF-32 for now, sorry
return '';
}

/**
* convert a string from one UTF-8 char to one UTF-16 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param    string  $utf8   UTF-8 character
* @return   string  UTF-16 character
* @access   private
*/
function utf82utf16($utf8)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
}

switch(strlen($utf8)) {
case 1:
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return $utf8;

case 2:
// return a UTF-16 character from a 2-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x07 & (ord($utf8{0}) >> 2))
. chr((0xC0 & (ord($utf8{0}) << 6))
| (0x3F & ord($utf8{1})));

case 3:
// return a UTF-16 character from a 3-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr((0xF0 & (ord($utf8{0}) << 4))
| (0x0F & (ord($utf8{1}) >> 2)))
. chr((0xC0 & (ord($utf8{1}) << 6))
| (0x7F & ord($utf8{2})));
}

// ignoring UTF-32 for now, sorry
return '';
}

/**
* encodes an arbitrary variable into JSON format
*
* @param    mixed   $var    any number, boolean, string, array, or object to be encoded.
*                           see argument 1 to Services_JSON() above for array-parsing behavior.
*                           if var is a strng, note that encode() always expects it
*                           to be in ASCII or UTF-8 format!
*
* @return   mixed   JSON string representation of input var or an error if a problem occurs
* @access   public
*/
function encode($var)
{
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';

case 'NULL':
return 'null';

case 'integer':
return (int) $var;

case 'double':
case 'float':
return (float) $var;

case 'string':
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
$ascii = '';
$strlen_var = strlen($var);

/*
* Iterate over every character in the string,
* escaping with a slash or encoding to UTF-8 where necessary
*/
for ($c = 0; $c < $strlen_var; ++$c) {

$ord_var_c = ord($var{$c});

switch (true) {
case $ord_var_c == 0x08:
$ascii .= '\b';
break;
case $ord_var_c == 0x09:
$ascii .= '\t';
break;
case $ord_var_c == 0x0A:
$ascii .= '\n';
break;
case $ord_var_c == 0x0C:
$ascii .= '\f';
break;
case $ord_var_c == 0x0D:
$ascii .= '\r';
break;

case $ord_var_c == 0x22:
case $ord_var_c == 0x2F:
case $ord_var_c == 0x5C:
// double quote, slash, slosh
$ascii .= '\\'.$var{$c};
break;

case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
// characters U-00000000 - U-0000007F (same as ASCII)
$ascii .= $var{$c};
break;

case (($ord_var_c & 0xE0) == 0xC0):
// characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
$c += 1;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;

case (($ord_var_c & 0xF0) == 0xE0):
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}));
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;

case (($ord_var_c & 0xF8) == 0xF0):
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}));
$c += 3;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;

case (($ord_var_c & 0xFC) == 0xF8):
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}));
$c += 4;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;

case (($ord_var_c & 0xFE) == 0xFC):
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}),
ord($var{$c + 5}));
$c += 5;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
}
}

return '"'.$ascii.'"';

case 'array':
/*
* As per JSON spec if any array key is not an integer
* we must treat the the whole array as an object. We
* also try to catch a sparsely populated associative
* array with numeric keys here because some JS engines
* will create an array with empty indexes up to
* max_index which can cause memory issues and because
* the keys, which may be relevant, will be remapped
* otherwise.
*
* As per the ECMA and JSON specification an object may
* have any string as a property. Unfortunately due to
* a hole in the ECMA specification if the key is a
* ECMA reserved word or starts with a digit the
* parameter is only accessible using ECMAScript's
* bracket notation.
*/

// treat as a JSON object
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
$properties = array_map(array($this, 'name_value'),
array_keys($var),
array_values($var));

foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}

return '{' . join(',', $properties) . '}';
}

// treat it like a regular array
$elements = array_map(array($this, 'encode'), $var);

foreach($elements as $element) {
if(Services_JSON::isError($element)) {
return $element;
}
}

return '[' . join(',', $elements) . ']';

case 'object':
$vars = get_object_vars($var);

$properties = array_map(array($this, 'name_value'),
array_keys($vars),
array_values($vars));

foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}

return '{' . join(',', $properties) . '}';

default:
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
? 'null'
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
}
}

/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param    string  $name   name of key to use
* @param    mixed   $value  reference to an array element to be encoded
*
* @return   string  JSON-formatted name-value pair, like '"name":value'
* @access   private
*/
function name_value($name, $value)
{
$encoded_value = $this->encode($value);

if(Services_JSON::isError($encoded_value)) {
return $encoded_value;
}

return $this->encode(strval($name)) . ':' . $encoded_value;
}

/**
* reduce a string by removing leading and trailing comments and whitespace
*
* @param    $str    string      string value to strip of comments and whitespace
*
* @return   string  string value stripped of comments and whitespace
* @access   private
*/
function reduce_string($str)
{
$str = preg_replace(array(

// eliminate single line comments in '// ...' form
'#^\s*//(.+)$#m',

// eliminate multi-line comments in '/* ... */' form, at start of string
'#^\s*/\*(.+)\*/#Us',

// eliminate multi-line comments in '/* ... */' form, at end of string
'#/\*(.+)\*/\s*$#Us'

), '', $str);

// eliminate extraneous space
return trim($str);
}

/**
* decodes a JSON string into appropriate variable
*
* @param    string  $str    JSON-formatted string
*
* @return   mixed   number, boolean, string, array, or object
*                   corresponding to given JSON input string.
*                   See argument 1 to Services_JSON() above for object-output behavior.
*                   Note that decode() always returns strings
*                   in ASCII or UTF-8 format!
* @access   public
*/
function decode($str)
{
$str = $this->reduce_string($str);

switch (strtolower($str)) {
case 'true':
return true;

case 'false':
return false;

case 'null':
return null;

default:
$m = array();

if (is_numeric($str)) {
// Lookie-loo, it's a number

// This would work on its own, but I'm trying to be
// good about returning integers where appropriate:
// return (float)$str;

// Return float or int, as appropriate
return ((float)$str == (integer)$str)
? (integer)$str
: (float)$str;

} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
// STRINGS RETURNED IN UTF-8 FORMAT
$delim = substr($str, 0, 1);
$chrs = substr($str, 1, -1);
$utf8 = '';
$strlen_chrs = strlen($chrs);

for ($c = 0; $c < $strlen_chrs; ++$c) {

$substr_chrs_c_2 = substr($chrs, $c, 2);
$ord_chrs_c = ord($chrs{$c});

switch (true) {
case $substr_chrs_c_2 == '\b':
$utf8 .= chr(0x08);
++$c;
break;
case $substr_chrs_c_2 == '\t':
$utf8 .= chr(0x09);
++$c;
break;
case $substr_chrs_c_2 == '\n':
$utf8 .= chr(0x0A);
++$c;
break;
case $substr_chrs_c_2 == '\f':
$utf8 .= chr(0x0C);
++$c;
break;
case $substr_chrs_c_2 == '\r':
$utf8 .= chr(0x0D);
++$c;
break;

case $substr_chrs_c_2 == '\\"':
case $substr_chrs_c_2 == '\\\'':
case $substr_chrs_c_2 == '\\\\':
case $substr_chrs_c_2 == '\\/':
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
$utf8 .= $chrs{++$c};
}
break;

case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
// single, escaped unicode character
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
. chr(hexdec(substr($chrs, ($c + 4), 2)));
$utf8 .= $this->utf162utf8($utf16);
$c += 5;
break;

case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
$utf8 .= $chrs{$c};
break;

case ($ord_chrs_c & 0xE0) == 0xC0:
// characters U-00000080 - U-000007FF, mask 110XXXXX
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 2);
++$c;
break;

case ($ord_chrs_c & 0xF0) == 0xE0:
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 3);
$c += 2;
break;

case ($ord_chrs_c & 0xF8) == 0xF0:
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 4);
$c += 3;
break;

case ($ord_chrs_c & 0xFC) == 0xF8:
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 5);
$c += 4;
break;

case ($ord_chrs_c & 0xFE) == 0xFC:
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 6);
$c += 5;
break;

}

}

return $utf8;

} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
// array, or object notation

if ($str{0} == '[') {
$stk = array(SERVICES_JSON_IN_ARR);
$arr = array();
} else {
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = array();
} else {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = new stdClass();
}
}

array_push($stk, array('what'  => SERVICES_JSON_SLICE,
'where' => 0,
'delim' => false));

$chrs = substr($str, 1, -1);
$chrs = $this->reduce_string($chrs);

if ($chrs == '') {
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;

} else {
return $obj;

}
}

//print("\nparsing {$chrs}\n");

$strlen_chrs = strlen($chrs);

for ($c = 0; $c <= $strlen_chrs; ++$c) {

$top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2);

if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

if (reset($stk) == SERVICES_JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
array_push($arr, $this->decode($slice));

} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
// we are in an object, so figure
// out the property name and set an
// element in an associative array,
// for now
$parts = array();

if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// "name":value pair
$key = $this->decode($parts[1]);
$val = $this->decode($parts[2]);

if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// name:value pair, where name is unquoted
$key = $parts[1];
$val = $this->decode($parts[2]);

if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
}

}

} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
// found a quote, and we are not inside a string
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
//print("Found start of string at {$c}\n");

} elseif (($chrs{$c} == $top['delim']) &&
($top['what'] == SERVICES_JSON_IN_STR) &&
(($chrs{$c - 1} != '\\') ||
($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
// found a quote, we're in a string, and it's not escaped
array_pop($stk);
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");

} elseif (($chrs{$c} == '[') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
//print("Found start of array at {$c}\n");

} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
// found a right-bracket, and we're in an array
array_pop($stk);
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

} elseif (($chrs{$c} == '{') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
//print("Found start of object at {$c}\n");

} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
// found a right-brace, and we're in an object
array_pop($stk);
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

} elseif (($substr_chrs_c_2 == '/*') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
$c++;
//print("Found start of comment at {$c}\n");

} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
// found a comment end, and we're in one now
array_pop($stk);
$c++;

for ($i = $top['where']; $i <= $c; ++$i)
$chrs = substr_replace($chrs, ' ', $i, 1);

//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

}

}

if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;

} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
return $obj;

}

}
}
}

/**
* @todo Ultimately, this should just call PEAR::isError()
*/
function isError($data, $code = null)
{
if (class_exists('pear')) {
return PEAR::isError($data, $code);
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
is_subclass_of($data, 'services_json_error'))) {
return true;
}

return false;
}
}

if (class_exists('PEAR_Error')) {

class Services_JSON_Error extends PEAR_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
}

} else {

/**
* @todo Ultimately, this class shall be descended from PEAR_Error
*/
class Services_JSON_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{

}
}

}

// Server side Ajax Agent implimentation follows
$agent = new Agent;
if (isset($_POST['aa_afunc'])) $aa_afunc = $_POST['aa_afunc']; else $aa_afunc="";
if (isset($_POST['aa_sfunc'])) $aa_sfunc = $_POST['aa_sfunc']; else $aa_sfunc="";
if (isset($_POST['aa_event'])) $aa_event = $_POST['aa_event']; else $aa_event="";
if (isset($_POST['aa_cfunc'])) $aa_cfunc = $_POST['aa_cfunc']; else $aa_cfunc="";
if (isset($_POST['aa_sfunc_args'])) $aa_sfunc_args = $_POST['aa_sfunc_args'];
else $aa_sfunc_args="";

if($_SERVER['REQUEST_URI']==null||$_SERVER['REQUEST_URI']=="") {
$aa_url = $_SERVER['PHP_SELF'];
} else {
$aa_url = $_SERVER['REQUEST_URI'];
}

if($aa_afunc=="call") {
$agent->call($aa_sfunc, $aa_cfunc, $aa_sfunc_args);
}

if($aa_afunc=="listen") {
$agent->listen($aa_event, $aa_cfunc, $aa_sfunc_args);
}

class Agent {
function call ($aa_sfunc, $aa_cfunc, $aa_sfunc_args) {
$json = new Services_JSON();
$aa_sfunc_args_dc=array();
if($aa_sfunc_args && sizeof($aa_sfunc_args)>=1) {
foreach ($aa_sfunc_args as $aa_arg) {
if ((strpos($aa_arg, "[")!==false) || (strpos($aa_arg, "{")!==false)) {
if ((strpos($aa_arg, "[")===0) || (strpos($aa_arg, "{")===0)) {
$aa_arg = str_replace('\"', '"', $aa_arg);
$aa_arg_dc = $json->decode($aa_arg);
array_push($aa_sfunc_args_dc,$aa_arg_dc);
} else {
array_push($aa_sfunc_args_dc,$aa_arg);
}
} else {
array_push($aa_sfunc_args_dc,$aa_arg);
}
}
}

// sfix # sf001
$arr = get_defined_functions();
if (!in_array(strtolower($aa_sfunc), $arr["user"]) && !in_array($aa_sfunc, $arr["user"])) exit();

$ret = call_user_func_array($aa_sfunc, $aa_sfunc_args_dc);
if(is_array($ret) || is_object($ret)) {
$ret = $json->encode($ret);
$ret = str_replace('\"', '"', $ret);
echo $ret;
} else {
echo $ret;
}
exit();
}

function listen ($aa_event, $aa_cfunc, $aa_sfunc_args) {
// to be implemented
exit();
}

function init () {
global $aa_url;
?>
<script type="text/javascript" src="?ajaxagent=js&this_url=<?php echo urlencode($aa_url); ?>">
<!--
/*
--------------------------------------------------------------------
Ajax Agent for PHP v.0.3. Copyright (c) 2006 ajaxagent.org.
@author: Steve Hemmady, Anuta Udyawar <contact at ajaxagent dot org>
This program is free software; you can redistribute it under the
terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version. This program is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more info
at http://www.gnu.org/licenses/gpl.txt
--------------------------------------------------------------------
*/
//-->
</script>
<?php
}
}
?>

Manage this all pages and enjoy your ajax agent paging without page refresh…

Keep in touch :)

Code Hunter Introduction

Posted on November 6, 2009
Filed Under My Stuff | 2 Comments

Hello Friends,

This is  Balraj Parmar, a web developer. Basically my area of expertise are PHP , ajax, javascript, css and html. If you need any help regarding web development, php programming, Ajax programming, JavaScript, jQuery, Mootools then then i will definitely help you if I’ve a solution.