|
Eric
Ivan SoukenkaWeb Developer & Computer Specialist
Na Panenske 1800/6
Roztoky U Prahy
252 63 Czech Republic
contact form
Translate to Czech
Code Snippets
Here are some examples that show a small window into my coding abilities.
This section is meant for the interviewer that knows a little bit of coding. Once again
thank you for looking over my online resume.
Feel free to grab this sites source code there is A lot of coding I believe may be useful for you to review. source
All of my database functions are set in a file
I call clsDatabase in my /inc folder. I use a class
to power almost every database function. The reason I do
my database code like this is for organization and so I can
pass variables easily between functions. Here is what my
default clsDatabase looks like before any modifications. Even
the server information is put here. Notice I have not converted
this to PHP 5 yet however it works in PHP 5 fine.
Snippets available in PDF format: php_ajax_with_sql php_database_mysql_2 php_mysql_class Partial source code: Click here to open in a popover window for easier viewing
class database
{
var $table;
var $columnTotal;
var $columnName;
var $fetchedArray;
var $select;
var $conn;
var $selectCaseAllColorTables;
var $activeColorTable;
function database($table)
{
$this->columnTotal = '';
$this->columnName = '';
$this->fetchedArray = '';
$this->select = '';
$this->conn = '';
$this->selectCaseAllColorTables = '';
$this->activeColorTable = '';
DEFINE('MYSQL_SERVER','localhost');
DEFINE('MYSQL_DBNAME','myname');
DEFINE('MYSQL_LOGIN','myname');
DEFINE('MYSQL_PASS','mypass');
$conn=mysql_connect(MYSQL_SERVER,MYSQL_LOGIN,MYSQL_PASS);
mysql_select_db(MYSQL_DBNAME);
$this->conn=$conn;
database::selectTable($table);
}
function selectTable($table)
{
$this->table=$table;
}
function query($query)
{
$this->select = mysql_query($query) or die('<center><p style="color:red;">server down or invalid page request</p><br>'.$query.'</center>');
}
function amountTableColumns()
{
$result=mysql_query("show columns from $this->table");
$this->columnTotal=mysql_num_rows($result);
}
function nameTableColumns()
{
$result=mysql_query("show columns from $this->table");
$intCounter=0;
while ($arrRows = mysql_fetch_array($result))
{
$this->columnName[$intCounter]=$arrRows[0];
$intCounter++;
}
}
function fetchArray()
{
database::amountTableColumns();
$rowCounter=0;
while ($arrRows = mysql_fetch_array($this->select))
{
$intCounter=0;
while ($this->columnTotal >= $intCounter)
{
$this->fetchedArray[$rowCounter][$intCounter]=$arrRows[$intCounter];
$intCounter++;
}
$rowCounter++;
}
}
}
Now with this class loaded anytime in my script I need to do an
SQL query I can just do this for example:
This allows a user to immediately add files to there web server. I used this code on thebloggalaxy so user can
upload an image and afterwards can click it to insert into there blog post. After file is uploaded you will notice I use
imagick to resize the image based on the users preference they selected. To see this code in action visit thebloggalaxy
and scroll to bottom login using public/public and select option to create a blog entry.
upload_with_php_plus_image_resize pdf Click here to open in a popover window for easier viewing
<\php
session_start();
$username=$_SESSION['username'];
/*******************************************
* I will branch this off into its own media product.
* will include filebrowser and possibily video not sure dependant upon space on
* webserver
*******************************************/
\?>
<html>
<head>
<title>File Uploader</title>
<script type="text/javascript" src="jquery126.js"></script>
<script type="text/javascript">
$(document).ready(function() { //do this when dom is finished loading
bindGlobal();
});
function insertImage(image) {
imageInfo='<img src="'+image+'" /></img>';
//imageInfo=image;
//window.parent.tinyMCE.insertImage(imageInfo,'alt',0,0,150,150,'left','title');window.parent.tinyMCE.triggerNodeChange();
window.parent.tinyMCE.execCommand('mceInsertContent', false, imageInfo);
return false;
}
function bindGlobal() {
$('#mediaLocalPictureButton').click(function() {
$('#localPicture').show();
$('#help').hide();
$('#webPicture').hide();
});
$('#mediaWebPictureButton').click(function() {
$('#webPicture').show();
$('#help').hide();
$('#localPicture').hide();
});
$('#submit, #submit').click(function() {
$('#wiperAll').hide();
$('#help').hide();
$('#hidden').show();
});
}
</script>
\<\php
function parseURL($url) {
$parser = explode('/',$url);
$int=0;
$parsedOutPic='none';
while ($int < count($parser)) {
$parsedOutPic=$parser[$int];
$int++;
}
return $parsedOutPic;
}
/* just some macros */
function uploadComplete($imageName,$imagePath,$output) {
$strContent ='<div id="startOver"><a target="_self" href="upload.php">Add Another Image.</a></div>';
$strContent .='<div id="success">Transfer & Conversion Complete!<br/>';
$strContent .='<img width="80px" height="80px;" onclick="insertImage('.$imagePath.$output.'');" src="'.$imagePath.'/'.$output.'"/>';
$strContent .='<div id="tip">tip: Just click the image above with your mouse and picture will be placed at the cursor location below! After inserting your image you can move it around inside of your entry with the mouse or right click for more options.</div>';
$strContent .='</div>';
return $strContent;
}
function resizeImage($imageSize,$imagePath,$input,$output) {
exec("convert -geometry $imageSize $imagePath/$input $imagePath/$output");
exec("rm $imagePath/$input");
}
function error($details) {
$strContent = '<div id="error">An error occured here is any debug information we have gathered:'.$details.'</div>';
return $strContent;
}
?>
<link href="../css/cssIndex.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="mediaManager">
<?php
if(isset($_POST['url'])) {
$url=$_POST['url'];
$imageSize=$_POST['size'].'x'.$_POST['size'];
$imageName=parseURL($url);
$file_extension = explode('.',$imageName);
$file_extension = $file_extension[1];
$imageSize= $_POST['size'].'x'.$_POST['size'];
$imagePath = "../../userfiles/$username/";
if ($file_extension === 'jpg' or $file_extension === 'gif' or $file_extension === 'png' or $file_extension === 'epg' or $file_extension === 'JPG' or $file_extension === 'GIF' or $file_extension === 'PNG' or $file_extension === 'EPG' or $file_extension === 'Jpg' or $file_extension === 'Gif' or $file_extension === 'Png' or $file_extension === 'Epg') {
exec("wget -P $imagePath $url");
$input = $imageName;
$output= '_'.$imageName;
resizeImage($imageSize,$imagePath,$input,$output);
echo uploadComplete($imageName,$imagePath,$output);
exit;
} else {echo error('not a valid picture url');}
}
if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != "") {
$imageSize=$_POST['size'].'x'.$_POST['size'];
$local_file = $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded
$file_extension = $_FILES['txt_file']['name'];
$file_extension = explode('.',$file_extension);
$file_extension = $file_extension[1];
$imagePath = "../../userfiles/$username/";
$imageName = $_FILES['txt_file']['name'];
$imageName= $_FILES['txt_file']['name']; //used below to display image
if ($file_extension === 'jpg' or $file_extension === 'gif' or $file_extension === 'png' or $file_extension === 'epg' or $file_extension === 'JPG' or $file_extension === 'GIF' or $file_extension === 'PNG' or $file_extension === 'EPG' or $file_extension === 'Jpg' or $file_extension === 'Gif' or $file_extension === 'Png' or $file_extension === 'Epg') {
$destination_file = "public_html/userfiles/$username/".basename($_FILES['txt_file']['name']); // Path for File Upload (relative to your login dir)
// Global Connection Settings
switch($_SERVER['SERVER_PORT']) {
default:
case 80:
$url = 'http';
break;
case 443:
$url = 'https';
break;
}
$url .= '://'.$_SERVER['SERVER_NAME'].(!in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? ':'.$_SERVER['SERVER_PORT'] : null).$_SERVER['REQUEST_URI'];
$parts = explode('/', $url);
$int=0;
while ($int < count($parts)) {
$location=$parts[$int];
if( $location==='www.ourlittlejourneycalledlife.com') $location='ourlittlejourneycalledlife.com';
if( $location==='www.thebloggalaxy.com') $location='thebloggalaxy.com';
if( $location==='bloggalaxy_repos' || $location==='thebloggalaxy.com' || $location==='oljcl_home' || $location==='ourlittlejourneycalledlife.com' ) {break;}
$int++;
}
if($location==='ourlittlejourneycalledlife.com') {
$ftp_server = "ourlittlejourneycalledlife.com";
$ftp_user_name = "ourlittl";
$ftp_user_pass = "asdp2002";
}
elseif($location==='thebloggalaxy.com') {
$ftp_server = "thebloggalaxy.com";
$ftp_user_name = "theblogg";
$ftp_user_pass = "asdp2002";
}
else {echo 'you must setup connection settings';exit;}
// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Verify Log In Status
if ((!$conn_id) || (!$login_result)) {
echo error('FTP connection has failed!');
exit;
}
$upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY);
// Verify Upload Status
if (!$upload) {
echo error('upload failed');
exit;
} else {
$input = $imageName;
$output= '_'.$imageName;
resizeImage($imageSize,$imagePath,$input,$output);
echo uploadComplete($imageName, $imagePath, $output);
}
ftp_close($conn_id);
exit;
}
else {echo error('Invalid filetype allowed extension include jpg, jpeg, gif, png');}
}
\?>
<div id="wiperAll">
<div id="mainPage">
<a style="font-size:8px;" target="_self" href="upload.php">Refresh</a>
<div id="mediaLocalPictureButton">Upload Local Picture</div>
<div id="mediaWebPictureButton">Download Web Picture</div>
<div style="clear:both;height:1px;"></div>
<div id="help">
This is your photo manager. Just select from one of the options above if you wish to use a picture in your post. We recommend
you start this first as while the picture is being handles you can still continue typing your blog entry. Please respect all
copyrights.
</div>
</div>
<form id="localPicture" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<label>Resize this image to:</label>
<label>200x200</label><input name="size" value="200" type="radio" checked="checked"/>
<label>400x400</label><input name="size" value="400" type="radio"/><br/>
<input name="txt_file" type="file" size="20" />
<input type="submit" name="start_upload" id="submit" value="Upload File"/><br/>
</form>
<form id="webPicture" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<label>Resize this image to:</label>
<label>200x200<label><input name="size" value="200" type="radio" checked="checked"/>
<label>400x400</label><input name="size" value="400" type="radio"/><br/>
<input name="url" value="paste url to image here" type="text"/>
<input type="submit" id="submit" value="Download File"/><br/><!-- this is not onsubmit for a reason -->
</form>
</div>
<div id="hidden">
<img id="progress" src="../images/ajax-loader.gif" />
<p id="progText">
Upload Started!
<br>
tip: Feel free to continue with your blog post while upload is in progress
</p>
</div>
</div>
</body>
<html>
This powerful script allows a user to upload an image and includes a file browser. What is interesting to point out is the popup
window does communicate with the parent window so the user can minimize this and continue with there and be notified when it is
complete. The picture puts itself automatically into the parent window with just a click.
php_file_uploader_plus_browser.pdf Click here to open in a popover window for easier viewing
<html>
<head>
<title>File Uploader</title>
<script type="text/javascript">
function callParentWindowFunction(image,mode)
{
window.opener.CallAlert(image,mode);
return false;
}
window.onload = function() {
document.getElementById("progress").style.visibility = "hidden";
document.getElementById("prog_text").style.visibility = "hidden";
}
function dispProgress() {
document.getElementById("progress").style.visibility = "visible";
document.getElementById("prog_text").style.visibility = "visible";
}
</script>
</head>
<body style="background-color:#000033;">
<div style="margin-top:20px;color:#fff;text-align:center;">
<php
if(isset($_POST[start_upload]) && $_FILES[txt_file][name] != "")
{
$displayFileName = $_FILES[txt_file][name];
$local_file = $_FILES[txt_file][tmp_name]; // Defines Name of Local File to be Uploaded
$file_extension = $_FILES[txt_file][name];
$file_extension = explode(.,$file_extension);
$file_extension = $file_extension[1];
$image = $_SERVER[HTTP_HOST];
$image .= /userfiles;
$image .= /;
$image .= $_FILES[txt_file][name];
if ($file_extension === jpg or $file_extension === gif or $file_extension === png or $file_extension === epg)
{
$destination_file = "/traversecitytoolbar.com/userfiles/".basename($_FILES[txt_file][name]); // Path for File Upload (relative to your login dir)
// Global Connection Settings
$ftp_server = "98.130.93.5"; // FTP Server Address (exlucde ftp://)
$ftp_user_name = "easoukenka"; // FTP Server Username
$ftp_user_pass = ""; // Password
// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Verify Log In Status
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed! <br />";
//echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name <br />";
}
$upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY); // Upload the File
// Verify Upload Status
if (!$upload)
{
echo "Upload Failed! <br> most likely due to filesize larger then 2MB <br />Please close this window and try again<br />";
exit;
}
else { echo "<h2>Upload Complete!<br /></h2><br /><br />"; }
ftp_close($conn_id); // Close the FTP Connection
echo you may close this window now;
echo <script type="text/javascript">callParentWindowFunction(\.$displayFileName.\, \upload\);window.close();</script>;
exit;
}
else { echo <h2>Invalid Filetype allowed extension jpg, jpeg, gif, png close this window and try again</h2>Close Window Now;exit; }
}
>
<form action="<php echo $_SERVER[PHP_SELF];>" method="POST" enctype="multipart/form-data">
Please choose a file: <br><br> <input name="txt_file" type="file" size="25" />
<br><br>
Then click here to upload: <br><br> <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
</form>
<img id="progress" src="../images/ajax-loader.gif" />
<p id="prog_text" style="font-size:11px;display:inline;">
Upload Started!
</p>
</div>
</body>
</html>
>
This is a down-loadable file you may look at with some random PHP functions. I do not wish to post them all on the web
but if you wish to see more I would be more then glad to email them upon request.
PHP Functions
When I was teaching myself how to use classes for fun I took one of my typical form I use for customers to contact me
and turned it into a class. It is actually more convenient this way
but was mainly done for learning purposes. You can
see a live example of this on my contact page.
Click here to open in a popover window for easier viewing
/* Depends on email.php. Also if you want to use the database
function requires database.php. */
//include('clsDatabase.php');
include('email.php');
$form = new form($_REQUEST['mode']);
$mode = $form->mode;
switch ($mode)
{
case '':
$form->checkform();
$form->style();
$form->buildForm('Setup Interview','General Inquiry','Business Relations','More Information','Other');
break;
case 'save':
$form->success('../index.php');
$form->grabResults();
//$form->save_to_database();
$form->formatResults();
email('easoukenka@gmail.com','soukenka.info contact form submitted', $form->formattedResults);
break;
}
echo $form->strContent;
/* usage instructions
-only things you should have to change are located right above.
-buildForm('1','2','3','4','5'); those are what will show up in the
select pull down box.
-email(lots to enter here) just start writing in there it will tell
you what your entering.
do not edit $this->formattedResults
-it is possible with database you will have to adjust settings here
and in database.php.
-you may create a table using the following sql query if you wish:
CREATE TABLE `log`
(
`code` int(8) NOT NULL auto_increment,
`topic` varchar(32) NOT NULL default '',
`name` varchar(32) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
`comment` text NOT NULL,
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
*/
class form
{
var $mode;
var $strContent;
var $formattedResults;
var $topic;
var $name;
var $email;
var $comment;
function form($mode)
{
$this->mode = $mode;
//$this->$strContent = '';
}
function checkform()
{
$this->strContent .= '<script type="text/javascript">
function checkform()
{
var msg = '';
if ( document.form1.topic.value == 'none' ) {
msg += 'Please select a topic.\n';
}
if ( document.form1.name.value.length < 1 ) {
msg += 'Please enter your name.\n';
}
if ( document.form1.email.value.length < 1 ) {
msg += 'Please enter your email address.\n';
}
if ( document.form1.comment.value.length < 1 ) {
msg += 'Please enter a comment.\n';
}
if ( msg.length > 0 ) {
alert(msg);
return false;
} else {
return true;
}
}
</script>';
}
function style()
{
$this->strContent .= '<style type="text/css">
body {
/*font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
width: 900px;
margin: 0px auto 0px auto;
padding: 0px;
color: #000;*/
}
h2 {
color: #660066;
font-size: 1.4em;
}
input {
margin: 2px 0px 3px 0px;
}
textarea {
margin: 2px 0px 3px 0px;
}
label {
width: 100px;
float: left;
}
</style>';
}
function buildForm($topic1,$topic2,$topic3,$topic4,$topic5)
{
$this->strContent .= '<h2>Please fill out the form below.</h2>' .
'<form action="inc/clsFormMail.php?mode=save" method="post" name="form1" onsubmit="return checkform();">'. "\n" .
'<label>Topic</label>' . "\n" .
'<select name="topic">' . "\n" .
'<option value="none">Please select from below.</option>' . "\n" .
'<option value="'.$topic1.'">'.$topic1.'</option>' . "\n" .
'<option value="'.$topic2.'">'.$topic2.'</option>' . "\n" .
'<option value="'.$topic3.'">'.$topic3.'</option>' . "\n" .
'<option value="'.$topic4.'">'.$topic4.'</option>' . "\n" .
'<option value="'.$topic5.'">'.$topic5.'</option>' . "\n" .
'</select><br />' . "\n" .
'<label>Name:</label>' . "\n" .
'<input type="text" size="25" name="name" /><br />' .
'<label>E-mail:</label>' . "\n" .
'<input type="text" size="25" name="email" /><br />' .
'<label>Comment:</label>' . "\n" .
'<textarea rows="5" cols="25" name="comment"></textarea><br />' . "\n" .
'<label> </label>' . "\n" .
'<input type="submit" name="submitButton" value="Send" />' . "\n" .
'</form>';
}
function success($forwardURL)
{
$this->strContent .= '<br>Thank you your form has been successfully sent.<br/>' .
'<br /><a href="'.$forwardURL.'">Continue</a>';
}
function grabResults()
{
$this->topic = $_REQUEST['topic'];
$this->name = $_REQUEST['name'];
$this->email = $_REQUEST['email'];
$this->comment = $_REQUEST['comment'];
}
function formatResults()
{
$this->formattedResults .= 'Topic: ' . $this->topic . '<br>';
$this->formattedResults .= 'Name: ' . $this->name . '<br>';
$this->formattedResults .= 'Email: ' . $this->email . '<br>';
$this->formattedResults .= 'Comment: ' . $this->comment . '<br>';
}
function save_to_database()
{
$sql = new database('training');
$sql->query("insert into $sql->table
values('','$this->topic','$this->name','$this->email','$this->comment')");
$sql->closeDatabase();
}
}
You may download this file by right clicking here. This example has been altered including indents and the ' just to output correctly in the browser.
For my blog I created a script that allows people to sign up for something. This will email them a confirmation link to click on
and once done will activate the account. Written so it is easy to implement in different projects. This script will also email
me just to let me know someone has activated an account.
Click here to open in a popover window for easier viewing
<html>
<head>
<title>Your Subscription</title>
</head>
<body style="width:500px;margin-left:auto;margin-right:auto;background-color:teal;text-align:center;margin-top:20px;">
<?php
if (isset($_REQUEST['mode']))
{
DEFINE('MYSQL_SERVER','mysql17.opentransfer.com');
DEFINE('MYSQL_DBNAME','easouke_blog');
DEFINE('MYSQL_LOGIN','easouke_eric');
DEFINE('MYSQL_PASS','');
DEFINE('MYSQL_TABLE1','subscribe');
$conn=mysql_connect(MYSQL_SERVER,MYSQL_LOGIN,MYSQL_PASS);
mysql_select_db(MYSQL_DBNAME);
}
switch ($_REQUEST['mode'])
{
case 'add':
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subscriptionId = createRandomSubscriptionId();
mysql_query("INSERT INTO ".MYSQL_TABLE1." (name , email, subscription_id) VALUES ('$name' , '$email' , '$subscriptionId')");
echo 'Thank you we have added you to our database ';
echo '<a href="index.php">Home Page</a>';
break;
case 'confirmdelete':
$subscriptionId = $_REQUEST['subscriptionid'];
echo
'
We are sorry to hear that you wish to cancel your subscription to us. We hope it is
only because you enjoy visiting our site so much you don't need it. Just enter
your email address in the box below and you will be removed from our list automatically.
<form action="subscribe.php" method="get">
<input type="hidden" name="mode" value="checkanddelete"/>
<input type="hidden" name="subscriptionid" value="'.$subscriptionId.'">
<br><br>
<input type="text" name="email" value="enter email here"/>
<input type="submit" value="submit"/>
</form>
';
mysql_query("");
//DELETE FROM `subscribe` WHERE email = 'easoukenka@gmail.com'
break;
case 'checkanddelete':
$subscriptionId = $_REQUEST['subscriptionid'];
$email = $_REQUEST['email'];
$select = mysql_query("Select * from ".MYSQL_TABLE1." where subscription_id='$subscriptionId' ");
$result=mysql_fetch_array($select);
if ($result['email'] === $email)
{
mysql_query("delete from ".MYSQL_TABLE1." where email='$email'");
echo 'We have deleted all your information from our database. Thank You.';
}
else
{
echo 'you have entered the wrong email address for your subscription id please <a href="formmail.php">contact us</a> if you have any questions.';
}
break;
case '':
echo
'
Thank you for your interest in subscribing to our blog. By being a subscriber you will recieve an
email notification each time we make a post. This is great so you don't have to keep coming back
to see if we added something every 5 minutes like I know you were. :)
<br>
We gaurantee your email address will never be handed out to anyone else or used for any type of spam
whatsoever. On top of that you may unsubscribe anytime you wish.
<br><br>
<form action="subscribe.php" method="POST" style="text-align:left;">
<input type="hidden" name="mode" value="add"></input>
<table cellspacing="5" style="color:white;">
<tr>
<td>
Please Enter Your Name:
</td>
<td>
<input type="text" name="name"/>
</td>
</tr>
<tr></div>
<td>
Your email address:
</td>
<td>
<input type="text" name="email"/>
<input type="submit" value="submit"/>
</td>
</tr>
</table>
</form>
';
break;
}
if(isset($_REQUEST['mode'])) mysql_close($conn);
//---------------------------------------- PHP FUNCTIONS ----------------------------------------------------------//
function createRandomSubscriptionId()
{
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7)
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
?>
</body>
</html>
You may download this file by right clicking here. This example has been altered including indents and the ' just to output correctly in the browser.
AJAX is an advanced utility of Javascript. It allows a website to have full functionality without a single page reload. This can
be used to turn a website into a web application, increase user experience, be used wisely to assist with page loading, or just for fun.
These examples were all written by me and recommended reading.
ajax_with_jquery.pdf ajax_php.pdf Code Snippet different from above files which are updated
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
session_start();
$strContent = '';
$_elm = $_REQUEST['_elm'];
$body = restoreItem($_REQUEST['body']);
//$body = $_REQUEST['body']; //not sure why i did above but it messed up later coding
$mode = $_REQUEST['mode'];
$page_name = $_REQUEST['page_name'];
$access = $_REQUEST['access'];
$code = $_REQUEST['code'];
include('../clsDatabase.php');
switch ($_REQUEST['mode'])
{
case 'newpost':
$thisDatabase = $_SESSION['username'];
$thisDatabase .= '_';
$thisDatabase .= $page_name;
$sql = new database($thisDatabase);
echo $sql->newPostExtras();
$sql->closeDatabase();
break;
case 'save':
$thisDatabase = '';
$thisDatabase = $_SESSION['username'];
$thisDatabase .= '_';
$thisDatabase .= $page_name;
$sql = new database($thisDatabase);
if ($_elm === 'newpost')
{
$form_name = restoreItem($_REQUEST['form_name']);
if ($_REQUEST['form_newcategory']) $form_category = restoreItem($_REQUEST['form_category']);
else $form_category = restoreItem($_REQUEST['form_newcategory']);
$form_title = restoreItem($_REQUEST['form_title']);
$sql->query("INSERT INTO $sql->table (name, category, title, body, DTstamp) VALUES ('$form_name','$form_category','$form_title','$body', now())");
}
else
{
$sql = new database($thisDatabase);
if ($code === '' or $code === 'undefined')
{
$sql->query("select body from $sql->table where elm='$_elm'");
$sql->fetchArray();
if ($sql->fetchedArray[0][0] != $body and isset($sql->fetchedArray[0][0]))
{
$sql->query("UPDATE $sql->table SET body = '$body' WHERE elm = '$_elm'");
$sql->query("select comments from $sql->table where elm='$_elm'");
$sql->fetchArray();
if ($sql->fetchedArray[0][0] === 'rss7337' and $access != 'rss7337') $sql->query("UPDATE $sql->table SET comments = '' WHERE elm = '$_elm'");
if ($access === 'rss7337') $sql->query("UPDATE $sql->table SET comments = 'rss7337' WHERE elm = '$_elm'");
}
if (!isset($sql->fetchedArray[0][0]))
{
$sql->query("INSERT INTO $sql->table (body) VALUES ('$body')");
}
}
else
{
$sql->query("UPDATE $sql->table SET body = '$body' WHERE code = '$code'");
}
}
$sql->closeDatabase();
$form_sendemail = $_REQUEST['form_sendemail'];
<a href="examples/ajax_with_jquery.pdf">ajax_with_jquery.pdf</a>
if ($form_sendemail === 'yes')
{
$sql = new database('subscribe');
$sql->fetchArray();
$intCounter = 0;
$sql->amountTableRows();
while ($intCounter <= $sql->rowTotal)
{
$subject = 'Hello ' . $sql->fetchedArray[$intCounter][1] . '!';
$body = 'We made a post titled '.$form_title.' and you have subscribed to recieve an email each time we make a new post. Please visit <a href="http://ourlittlejourneycalledlife.com">our blog</a> Thank you for subscribing and feel free to leave a comment on our blog. You can be removed from our mailing list by clicking <a href="http://ourlittlejourneycalledlife.com/subscribe.php?mode=confirmdelete&subscriptionid='.$sql->fetchedArray[0][5].'">unsubscribe</a>';
$to = $sql->fetchedArray[$intCounter][2];
email($to,$subject,$body);
$intCounter++;
}
$sql->closeDatabase();
}
break;
case 'retrieve':
$thisDatabase = '';
$thisDatabase .= $_SESSION['username'];
$thisDatabase .= '_';
$thisDatabase .= $page_name;
$sql = new database($thisDatabase);
if ($code === '' or $code === 'undefined') $sql->query("select body from $sql->table where elm='$_elm'");
else $sql->query("select body from $sql->table where code='$code'");
$sql->fetchArray();
$strContent .= restoreItem($sql->fetchedArray[0][0]);
echo $strContent;
$sql->closeDatabase();
break;
case 'pageMenu':
$thisDatabase = $_SESSION['username'];
$thisDatabase .= '_';
$thisDatabase .= $page_name;
$sql = new database($thisDatabase);
$sql->query("SELECT * FROM $sql->table where elm != ''");
echo $sql->buildElmLinks($page_name);
$sql->closeDatabase();
break;
case 'access':
$sql = new database($_SESSION['pageIndex']);
$sql->query("UPDATE $sql->table set access='$access' where page_name='$page_name'");
$sql->closeDatabase();
break;
function ajaxFunction(mode,_elm,body,page_name,access,code)
{
body=cleanItem(body);
window.mode=mode;
window._elm=_elm;
window.elm = _elm.replace( '_' , '');
window.body=body;
window.page_name=page_name;
window.access=access;
window.code=code;
//send to ajax
if (window.newpost != undefined && window.newpost != '[object HTMLInputElement]' && window.newpost!='') queryString = 'mode=' + mode + '&form_name=' + window.form_name + '&form_sendemail=' + window.form_sendemail + '&form_category=' + cleanItem(window.form_category) + '&form_newcategory=' + cleanItem(window.form_newcategory) + '&form_title=' + cleanItem(window.form_title) + '&page_name=' + page_name + '&body=' + body + '&_elm=' + _elm;
else queryString = 'mode=' + mode + '&_elm=' + _elm + '&body=' + body + '&page_name=' + page_name + '&access=' + access + '&code=' + code;
http.open("GET", 'inc/ajax/ajax.php' + '?' + queryString, true);
switch (mode)
{
case 'save': http.onreadystatechange = ajaxSave;break;
case 'retrieve': http.onreadystatechange = ajaxRetrieve;break;
case 'preview': http.onreadystatechange = ajaxPreview;break;
case 'pageMenu': http.onreadystatechange = ajaxPageMenu;break;
case 'access': http.onreadystatechange = ajaxAccess;break;
case 'createnewpage': http.onreadystatechange = ajaxCreateNewPage;break;
case 'deletepage': http.onreadystatechange = ajaxDeletePage;break;
case 'deleteblog': http.onreadystatechange = ajaxDeleteBlog;break;
case 'newpost': http.onreadystatechange = ajaxNewPost;break;
case 'createnewcategory': http.onreadystatechange = ajaxCreateNewCategory;break;
case 'blogbrowser': http.onreadystatechange = ajaxBlogBrowser;break;
}
http.send(null);
}
function ajaxSave()
{
document.getElementById('status').innerHTML = 'Status: Saving';
setPositionByLeftTop('loadingImage');
show('loading');
if (http.status==200 && http.readyState==4)
{
if (window.form_sendemail == 'yes') alert('email sent to your subscribers successfully');
document.getElementById('status').innerHTML = 'Status: Saved';
//document.getElementById('pageSelector').innerHTML = http.responseText; //delete this unrem top*******
//alert('your post has been saved');
hide('loading');hide('editor');hide('pageMenu');show('welcome');hide('info');
}
}
function ajaxRetrieve()
{
setPositionByLeftTop('loadingImage');
if (window.elm == 'widgets')
{
hide('editor');
show('rawEditor');
}
else
{
show('editor');
hide('rawEditor');
}
show('info');
show('loading');
hide('welcome');
hide('blogBrowser');
hide('newPostExtras');
document.getElementById('status').innerHTML = 'Status: Loading';
if (http.status==200 && http.readyState==4)
{
if (_elm == 'pictures') show('enterrss');
else hide('enterrss');
//tinyMCE.activeEditor.setContent(http.responseText); used for version 3
if (window.elm != 'widgets') tinyMCE.setContent(http.responseText);
else document.rawHTMLForm.rawHTML.value = http.responseText;
hide('loading');
document.getElementById('status').innerHTML = 'Status: Loaded';
document.getElementById('elm').innerHTML = elm;
document.getElementById('page_name').innerHTML = window.page_name;
if (window.newpost) window.newpost = '';
}
}
See the full code in action at here login with username public and password public credentials. This is probably boring for everyone but me.
© 2008 Cyclon Solutions All Rights Reserved.
|