Jump to content

happypete

Members
  • Posts

    124
  • Joined

  • Last visited

  • Days Won

    1

happypete last won the day on September 29 2012

happypete had the most liked content!

Profile Information

  • Gender
    Male

happypete's Achievements

Member

Member (2/5)

16

Reputation

  1. Try this. Create an index.php, ageCheck.php & verified.php page and use the code below. Navigate to the verified.php page in the browser first (to check its working) you should automatically be redirected to the index.php page. Now if you select "i'm 21" then you will be redirected to the verified page. index.php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form method="POST" action="ageCheck.php"> <input type="submit" name="valid_age" value="I'm 21" /> <input type="submit" name="invalid_age" value="Nope. I sit at the kid's table" /> </form> </body> </html> When they select either of the button the details will be sent to the ageCheck.php page: ageCheck.php <?php //Start session session_start(); /* * First, we want to make sure they came to this ageCheck.php via a form. * Then we can check to see if $_POST['valid_age'] is set, since it will only * be set if they pressed the "I'm 21" button. */ if(isset($_POST)){ if(isset($_POST['valid_age'])){ /* * Since they got here, it means they are of the right age. * Now we set the session value. */ $_SESSION['age_verified'] = true; header("Location: verified.php"); exit; }else{ /* * To young! Just re-direct them to Google. */ header("Location: http://www.google.com"); exit; } }else{ die("Trying to sneak in are we?"); } ?> This page will send them to google.com if they have selected "Nope. I sit at the kid's table", or send them to verified.php if they selected "I'm 21" verified.php <?php //Start the session session_start(); /* * If they haven't passed the age test * then the age_verified session will not * be set, since it is only set if they * say they are 21 years of age. */ if(!isset($_SESSION['age_verified'])){ header("Location: index.php"); exit; } else { $verified = "your age has been verified!"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php echo $verified; ?> </body> </html> On the verified page it will again check if they are verified (and send them to index.php if not) of will echo "your age has been verified!" Any other page that you want them to visit and check they have been verified their age, add this code at the top. If they are not verified it will send then back to the index.php page <?php //Start the session session_start(); /* * If they haven't passed the age test * then the age_verified session will not * be set, since it is only set if they * say they are 21 years of age. */ if(!isset($_SESSION['age_verified'])){ header("Location: index.php"); exit; } else { $verified = "your age has been verified!"; } ?>
  2. Awesome, thanks, that worked: window.addEventListener("change", function(e) { e.preventDefault(); e.stopPropagation(); upcontrol.start(e.target.files);
  3. I have an image upload script which works file on desktop but not on mobile so I am trying to change the drag drop file input to select multiple files. original: <!-- DROP ZONE --> <div id="uploader"> <div class="drop">Drop Files Here</div> </div> /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); // callback text done! done.innerHTML = "Uploads Complete"; document.getElementById('done').appendChild(done); } }; xhr.send(data); } }; window.addEventListener("load", function () { // IF DRAG-DROP UPLOAD SUPPORTED if (window.File && window.FileReader && window.FileList && window.Blob) { /* [THE ELEMENTS] */ var uploader = document.getElementById('uploader'); /* [UPLOAD MECHANICS] */ // STOP THE DEFAULT BROWSER ACTION FROM OPENING THE FILE uploader.addEventListener("dragover", function (e) { e.preventDefault(); e.stopPropagation(); }); uploader.addEventListener("drop", function (e) { e.preventDefault(); e.stopPropagation(); uploader.classList.remove('highlight'); upcontrol.start(e.dataTransfer.files); }); New <input type="file" id="uploader" name="files[]" accept="image/jpeg, image/jpg, image/gif, image/png" multiple/> This bit the same as before /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); // callback text done! done.innerHTML = "Uploads Complete"; document.getElementById('done').appendChild(done); } }; xhr.send(data); } }; And this is where I am stuck. I'm trying to convert the drop to a select multiple files so need to change the "dataTransfer.files;" window.addEventListener("change", function(e) { e.preventDefault(); e.stopPropagation(); ///I believe this bit below is what needs changing???? upcontrol.start(e.dataTransfer.files); I get this far, and the console give the following error: "Uncaught TypeError: Cannot read property 'files' of undefined"
  4. Awesome thanks, that's just want I needed to know.
  5. Hi, I have an drag and drop image upload script that will process multiple image uploads with PHP, the JS gives a notification of each file uploaded. I want to be able to give an "all files uploaded" notification at the end ... index.php <script src="upload.js"></script> </head> <body> <h2>Upload a new image.</h2> <!-- DROP ZONE --> <div id="uploader"> <div class="drop">Drop Files Here</div> </div> upload.js /* !! UPDATE : AJAX IS ASYNCHRONOUS !! */ /* We do not want users to dump 100 files & upload all at the same time */ /* This will create sort of a queue system & upload one at a time */ var upcontrol = { queue : null, // upload queue now : 0, // current file being uploaded start : function (files) { // upcontrol.start() : start upload queue // WILL ONLY START IF NO EXISTING UPLOAD QUEUE if (upcontrol.queue==null) { // VISUAL - DISABLE UPLOAD UNTIL DONE upcontrol.queue = files; document.getElementById('uploader').classList.add('disabled'); // PROCESS UPLOAD - ONE BY ONE upcontrol.run(); } }, run : function () { // upcontrol.run() : proceed upload file var xhr = new XMLHttpRequest(), data = new FormData(); data.append('file-upload', upcontrol.queue[upcontrol.now]); xhr.open('POST', 'process.php', true); xhr.onload = function (e) { // SHOW UPLOAD STATUS var fstat = document.createElement('div'), txt = upcontrol.queue[upcontrol.now].name + " - "; if (xhr.readyState === 4) { if (xhr.status === 200) { // SERVER RESPONSE txt += xhr.responseText; } else { // ERROR txt += xhr.statusText; } } fstat.innerHTML = txt; document.getElementById('upstat').appendChild(fstat); // UPLOAD NEXT FILE upcontrol.now++; if (upcontrol.now < upcontrol.queue.length) { upcontrol.run(); } // ALL DONE // // // I WANT TO ADD SOME CODE HERE TO CREATE A MESSAGE ON THE INDEX.PHP TO SAY ALL IMAGES UPLOADED // // // else { upcontrol.now = 0; upcontrol.queue = null; document.getElementById('uploader').classList.remove('disabled'); } }; xhr.send(data); } };
  6. I'm getting the following errors: Notice: Undefined index: field Notice: Undefined index:content I'm getting a Status 200 and the content is passed: content zbzbfff<br> field text1 so I cant work out why it says there are undefined index??? ------------------------------------------------------ error message: <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: field in C:\wamp\www\archive\SmallProjects\cke-backup\save.php on line <i>9</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>369704</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\archive\SmallProjects\cke-backup\save.php' bgcolor='#eeeeec'>..\save.php<b>:</b>0</td></tr> </table></font> <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: content in C:\wamp\www\archive\SmallProjects\cke-backup\save.php on line <i>13</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>369704</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\archive\SmallProjects\cke-backup\save.php' bgcolor='#eeeeec'>..\save.php<b>:</b>0</td></tr> </table></font> OK <?php ini_set('display_errors',1); error_reporting(E_ALL); include('inc/db.php'); // Extract details from database $stmt = $db->prepare("SELECT * FROM data WHERE id=1"); $stmt->execute(); $e = $stmt->fetch(); $edit = "yes"; ?> <!DOCTYPE html> <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]--> <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]--> <head> <meta charset="utf-8"> <title></title> <meta name="keywords" content=""/> <meta name="description" content=""/> <meta name="author" content=""> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link rel="stylesheet" href="stylesheets/base.css"> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!-- Favicons ================================================== --> <link rel="shortcut icon" href="images/favicon.ico"> <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png"> <link href='http://fonts.googleapis.com/css?family=Coming+Soon' rel='stylesheet' type='text/css'> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-#######-##']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script></head> <body onLoad="initialize()"> <!--[if lte IE 9]><script src="js/respond.js"></script><![endif]--> <!-- ================================================== --> <div class="container"> <div class="sixteen columns"> <div id="message"></div> <p><a id="vacationrentalbariloche"></a></p> <p> </p> <h1 <?php if ($edit == "yes") { echo 'contenteditable="true" rel="text1"';} ?>> <?php echo html_entity_decode(stripslashes($e['text1'])) ?></h1> <h5 <?php if ($edit == "yes") { echo 'contenteditable="true" rel="text2"';} ?>> <?php echo html_entity_decode(stripslashes($e['text2'])) ?></h5> </div><!-- container --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <!--<script src="jquery 1.9.0.js"></script>--> <script src="ckeditor/ckeditor.js"></script> <script src="ckeditor/customize-toolbar.js"></script> <script src="saving.js"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script src="js/pikadate.js"></script> <script src="js/all.js"></script> </body> </html> saving.js: // JavaScript Document /* This bit of code saves the editable area every 60 seconds when it is being edited, but I also want it so be saved when the user deselects the text area & it need to save multiple editable areas - only save the editable area that is being edited or was selected, DON'T save all editbale areas at once just the one being edited at the time. */ /* provide feedback to use that content saved when deselected 'content saved message' and every 60 seconds 'autosave message' */ /* instance will be created for every element, and for every element we will set listeners for focus and blur events */ /* when element is in focus, interval is set, to save data every 60 sec. Beside that, we will keep interval ID to destroy him once element is blured */ CKEDITOR.on( "instanceReady", function(event) { var element=event.editor.element.$; $(element).on("focus", function(){ var intervalID=setInterval(function(){ saveData($(this), true); }, 30000); // 30000 = 30 seconds autosave $(this).data("intervalID", intervalID); }); $(element).on("blur", function(){ var intervalID=parseInt($(this).data("intervalID"), 10); clearInterval(intervalID); saveData($(this), false); }); } ); //function saves data from CKEditor into the database, element is jQuery element that contain data that needs to be saved //auto is just a flag that tells us what message to display after save - "autosave" or "update" function saveData(element, auto) { $.ajax({ method:"post", url:"save.php", data:{"field":element.attr("rel"), "content":element.html()}, success: function(status){ if(status==="OK") { var message; if(auto===true) { message="Autosave completed"; } else { message="Saved"; } $('#message').html(message).stop().hide().fadeIn(200).fadeOut(2500); } else { alert(status); //alert("Error: System cannot save your changes"); } } }); } and the PHP - save.php <?php include('inc/db.php'); // Update data $sql = "UPDATE data SET ".$_POST['field']."=:content WHERE id=1"; $stmt = $db->prepare($sql); $content=$_POST['content']; $stmt->bindParam(":content", $content); $stmt->execute(); $stmt->closeCursor(); echo "OK"; return; ?>
  7. OK sorted it based on this: http://code.google.com/p/ics-parser/ to create an array of the booked dates
  8. Hi, I'm trying to combine an array (if that's the right way to describe it..??) I have this Array ( [0] => Array ( [0] => 2013-07-14 [1] => 2013-07-15 [2] => 2013-07-16 [3] => 2013-07-17 ) [1] => Array ( [0] => 2013-08-02 [1] => 2013-08-03 [2] => 2013-08-04 [3] => 2013-08-05 [4] => 2013-08-06 ) [2] => Array ( [0] => 2013-10-06 [1] => 2013-10-07 [2] => 2013-10-08 [3] => 2013-10-09 ) ) and i want this: Array ( [0] => 2013-07-14 [1] => 2013-07-15 [2] => 2013-07-16 [3] => 2013-07-17 [4] => 2013-08-02 [5] => 2013-08-03 [6] => 2013-08-04 [7] => 2013-08-05 [8] => 2013-08-06 [9] => 2013-10-06 [10] => 2013-10-07 [11] => 2013-10-08 [12] => 2013-10-09 )
  9. I'm using the http://code.google.com/p/ics-parser/ to extract the start and end date from my ical file: $array =($ical1->events()); $newArray = array(); foreach ($array as $k => $v) { $newArray[$k]['startRange'] = date("Y-m-d", strtotime($v['DTSTART'])); $newArray[$k]['endRange'] = date("Y-m-d", strtotime($v['DTEND'])); } print_r(newArray) which returns this: Array ( [0] => Array ( [startRange] => 2013-07-14 [endRange] => 2013-07-26 ) [1] => Array ( [startRange] => 2013-08-02 [endRange] => 2013-09-12 ) [2] => Array ( [startRange] => 2013-10-06 [endRange] => 2013-10-10 ) [3] => Array ( [startRange] => 2013-10-17 [endRange] => 2013-10-28 ) [4] => Array ( [startRange] => 2013-11-05 [endRange] => 2013-11-13 ) [5] => Array ( [startRange] => 2013-11-14 [endRange] => 2013-11-23 ) [6] => Array ( [startRange] => 2013-12-18 [endRange] => 2014-01-05 ) ) OK, so I found this to print out all dates between a start and end date: $begin = new DateTime('2013-02-01'); $end = new DateTime('2013-02-07'); $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end); foreach($daterange as $date){ echo $date->format("Y-m-d") . "<br>"; } This prints out: 2013-02-01 2013-02-02 2013-02-03 2013-02-04 2013-02-05 2013-02-06 The question: How do I do the same with the ical file to print out the start date, all the dates in between and the end date for each event and put it in an array like this: Array ( [0] => 2014-03-12 [1] => 2014-03-13 [2] => 2014-03-14 [3] => 2014-11-21 [4] => 2014-11-22 [5] => 2014-11-23 [6] => 2014-11-24 [7] => 2014-11-25 [8] => 2014-11-26 )
  10. If you are new to PHP you probably wont have the skills to code you own secure login. You your try one like this: http://www.php-login.net/ or at least look at the code to see how it is done.
  11. You will need to resize the images and validate them as well. Here is something I was working on a while back: http://forums.phpfreaks.com/topic/268852-image-upload-validation-not-working/page-2?do=findComment&comment=1381699
  12. Surely you will design the interface yourself since you are proficient in HTML/CSS, Look at some examples for inspiration or purchase a pre-designed admin template:https://www.google.com/#q=admin+templates The rest will just be some CRUD; personally I prefer PDO over MySQLi: https://www.google.com/search?q=php+pdo+crud
  13. Can someone set me off in the right direction please. I'm trying to create an availability calendar by importing dates from an ical file. Basically I'm trying to export booked dates from an airbnb listing and show them on a custom calendar on a personal website. Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.