Created
January 20, 2011 18:33
-
-
Save storborg/788341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Queue: | |
| * Manages the flow to the web servers on high traffic event sales | |
| * by placing customers into a line and then redirecting them to the | |
| * web app serves as space is opened for trans processing | |
| * | |
| * @author Marc Urbaitel <urb@inticketing.com> | |
| * @copyright In Ticketing | |
| */ | |
| //echo "img2 "; | |
| $time_refresh = "60"; | |
| $queue_home = "http://tickets.burningman.com:8080"; | |
| $events_home = "http://tickets2.burningman.com"; | |
| $eventid = htmlentities($_GET[eventid],ENT_QUOTES); | |
| $key_queue = htmlentities($_GET[key_queue],ENT_QUOTES); | |
| //echo $key_queue; | |
| /** | |
| * Load initialization files | |
| */ | |
| require_once("/export/data/engine/db.inc"); | |
| require_once("/www/engine-ssl/live/includes/inDB.php"); | |
| require_once("/www/engine-ssl/live/includes/inQueue.php"); | |
| /** | |
| * ADD TO QUEUE | |
| * If no key queue is passed in | |
| * and no cookie exists | |
| */ | |
| if (!$key_queue && !$_COOKIE["inQueue$eventid"]) { | |
| /** | |
| * Add record to queue | |
| */ | |
| $key_queue = add_queue($eventid); | |
| display_info_queue($queue_home,$time_refresh,$eventid,$key_queue); | |
| exit; | |
| } | |
| /** | |
| * COOKIE IS SET | |
| * if no key exists but cookie is set | |
| * due to page reload manually | |
| */ | |
| if (!$key_queue && $_COOKIE["inQueue$eventid"]) { | |
| $key_queue = $_COOKIE["inQueue$eventid"]; | |
| } | |
| /** | |
| * Sets a cookie to handle the queue | |
| */ | |
| setcookie ("inQueue$eventid",$key_queue,time()+86400); | |
| /** | |
| * Open read database connection | |
| */ | |
| $db_read = open_read_queue(); | |
| /** | |
| * If databse read fails | |
| * then go ahead and display the info queue | |
| */ | |
| if (!$db_read) { | |
| display_info_queue($queue_home,$time_refresh,$eventid,$key_queue); | |
| exit; | |
| } | |
| /** | |
| * Start read class initialization | |
| */ | |
| $oQueueRead = new inQueue(&$db_read,$eventid,$key_queue,QUEUE_MAX); | |
| /** | |
| * If key is not valid | |
| */ | |
| if (!$oQueueRead->check_queue_key($key_queue)) { | |
| /** | |
| * Add new record to queue | |
| */ | |
| $key_queue = add_queue($eventid); | |
| display_info_queue($queue_home,$time_refresh,$eventid,$key_queue); | |
| exit; | |
| } | |
| /** | |
| * Check if go is set | |
| */ | |
| if ($oQueueRead->aQueue[go]) { | |
| /** | |
| * Initialize write db handle | |
| * and queue write object | |
| */ | |
| $db_write = new inDB(DSN_QUEUE); | |
| $oQueueWrite = new inQueue(&$db_write,$eventid,$key_queue); | |
| /** | |
| * Flag queue as inprogress | |
| */ | |
| $oQueueWrite->set_inprogress_queue(); | |
| /** | |
| * Close write db handle | |
| */ | |
| $db_write->close(); | |
| $db_read->close(); | |
| /** | |
| * Delete the cookie for queue | |
| */ | |
| setcookie("inQueue$eventid", '', time()-42000, '/'); | |
| /** | |
| * Send over to the event page | |
| */ | |
| if ($_GET[queuetest]) { | |
| header("Location: $events_home/qlink.php?eventid=$eventid&queue=$key_queue"); | |
| } else { | |
| ?> | |
| <script language="javascript"> | |
| top.location.href = "<?=$events_home?>/qlink.php?eventid=<?=$eventid?>&queue=<?=$key_queue?>&go=1"; | |
| </script> | |
| <noscript> | |
| <META HTTP-EQUIV="Refresh" CONTENT="1;URL=<?=$events_home?>/qlink.php?eventid=<?=$_GET[eventid]?>&queue=<?=$key_queue?>"> | |
| </noscript> | |
| <? | |
| } | |
| exit; | |
| } | |
| /** | |
| * calculate # in queue | |
| */ | |
| $num_queue = get_number_queue($eventid,$oQueueRead->aQueue[id_queue],$_COOKIE["inQueue$eventid-num_queue"]); | |
| /** | |
| * Display queue info | |
| */ | |
| display_info_queue($queue_home,$time_refresh,$eventid,$key_queue,$oQueueRead->aQueue,$num_queue); | |
| /** | |
| * Closs database handle | |
| */ | |
| $db_read->close(); | |
| exit; | |
| /** | |
| * Open read connection to queue | |
| * | |
| * @return handle | |
| */ | |
| function open_read_queue() { | |
| /** | |
| * Initialize objects | |
| */ | |
| $db_read = new inDB(DSN_QUEUE_SELECT); | |
| /** | |
| * If cannot connect to database | |
| * show info and refresh | |
| */ | |
| if (!$db_read) return false; | |
| return $db_read; | |
| } | |
| /** | |
| * Add record to the queue | |
| * | |
| * @param integer $eventid | |
| * @return char | |
| */ | |
| function add_queue($eventid) { | |
| /** | |
| * Initialize write db handle | |
| * and queue write object | |
| */ | |
| $db_write = new inDB(DSN_QUEUE); | |
| $oQueueWrite = new inQueue(&$db_write,$eventid); | |
| /** | |
| * Add record into the queue | |
| * returns the id number | |
| */ | |
| $key_queue = $oQueueWrite->add_queue($eventid); | |
| /** | |
| * Set the key queue in the read object | |
| */ | |
| $oQueueWrite->set_key_queue($key_queue); | |
| /** | |
| * Sets a cookie to handle the queue | |
| */ | |
| setcookie ("inQueue$eventid",$key_queue,time()+86400); | |
| /** | |
| * Close write db handle | |
| */ | |
| $db_write->close(); | |
| return $key_queue; | |
| } | |
| /** | |
| * Get number in queue | |
| * | |
| * @param integer $eventid | |
| * @param integer $id_queue | |
| * @param integer $cookie_queue | |
| * @return integer | |
| */ | |
| function get_number_queue($eventid,$id_queue,$cookie_queue) { | |
| /** | |
| * Calculate the number in the queue | |
| */ | |
| $filename = "/export/data/queue_next_$eventid.txt"; | |
| if ($handle = fopen($filename, "r")) { | |
| $next_to_go = fread($handle, filesize($filename)); | |
| fclose($handle); | |
| if ($next_to_go) { | |
| if ($next_to_go < $id_queue) { | |
| $raw_num = $id_queue - $next_to_go; | |
| } else { | |
| $raw_num = 0; | |
| } | |
| /** | |
| * Sets a cookie for line number | |
| */ | |
| setcookie ("inQueue$eventid-num_queue",$raw_num,time()+86400); | |
| $num_queue = number_format($raw_num); | |
| } | |
| } else { | |
| if ($cookie_queue) { | |
| $num_queue = number_format($cookie_queue); | |
| } | |
| } | |
| return $num_queue; | |
| } | |
| /** | |
| * Display the info about the queue, #, etc. | |
| * | |
| * @param unknown_type $oQueue | |
| */ | |
| function display_info_queue($queue_home,$time_refresh,$eventid,$key_queue,$aQueue="",$num_queue="") { | |
| ?> | |
| <html><head> | |
| <style type=text/css> | |
| <!-- | |
| body { | |
| margin:0px; | |
| } | |
| p,input { | |
| font-family: Arial, Helvetica, sans-serif; | |
| font-size: 12px; | |
| color: #6E574B; | |
| font-weight: normal; | |
| } | |
| input { | |
| width: 24px; | |
| font-weight: bold; | |
| border:none; | |
| } | |
| --> | |
| </style> | |
| <META HTTP-EQUIV="Refresh" CONTENT="<?=$time_refresh?>;URL=<?=$queue_home?>/queue.php?eventid=<?=$eventid?>&key_queue=<?=$key_queue?>&go=0"> | |
| </head> | |
| <body><center> | |
| <form name=redirect> | |
| <p> | |
| <? | |
| if ($num_queue) { | |
| echo "There are approximately <b>$num_queue</b> orders ahead of you.<br>"; | |
| } | |
| ?> | |
| Your status will be updated in <input type="text" name="redirect2">seconds.*</form> | |
| <?php | |
| if ($message = getMessage($eventid)) | |
| { | |
| echo $message."<br>"; | |
| } | |
| ?> | |
| <script> | |
| <!-- | |
| var targetURL="<?=$queue_home?>/queue.php?eventid=<?=$eventid?>&key_queue=<?=$key_queue?>&go=0" | |
| var countdownfrom=<?=$time_refresh?> | |
| var currentsecond=document.redirect.redirect2.value=countdownfrom+1 | |
| function countredirect(){ | |
| if (currentsecond!=1){ | |
| currentsecond-=1 | |
| document.redirect.redirect2.value=currentsecond | |
| } | |
| else{ | |
| window.location=targetURL | |
| return | |
| } | |
| setTimeout("countredirect()",1000) | |
| } | |
| countredirect() | |
| //--> | |
| </script> | |
| </center> | |
| </body> | |
| </html> | |
| <? | |
| } | |
| function getMessage($eventid) { | |
| /** | |
| * Calculate the number in the queue | |
| */ | |
| $filename = "/export/data/queue_msg_$eventid.txt"; | |
| if ($handle = fopen($filename, "r")) { | |
| $message = fread($handle, filesize($filename)); | |
| fclose($handle); | |
| return $message; | |
| } else { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment