Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // By Kaeru~
- require('lib/common.php');
- /*if($_GET['lol']=='yes')
- {
- $sql->query('TRUNCATE TABLE g_opts');
- $sql->query('TRUNCATE TABLE g_stages');
- $sql->query('TRUNCATE TABLE g_rep');
- $sql->query('INSERT INTO g_stages SET text = "Oops you fell out of the internet into real life. Now what?"');
- $sql->query('INSERT INTO g_opts SET stage = 1, text = "Go back to sleep"');
- $sql->query('INSERT INTO g_opts SET stage = 1, text = "Eat something"');
- $sql->query('INSERT INTO g_opts SET stage = 1, text = "Go outside"');
- print 'queries done';
- }*/
- function branch($stage)
- {
- global $sql;
- $tree = array();
- $opts = $sql->query('SELECT * FROM g_opts WHERE stage = '.$stage);
- $stage = $sql->fetchq('SELECT * FROM g_stages WHERE id = '.$stage);
- $tree['text'] = $stage['text'];
- $tree['opts'] = array();
- while($opt = $sql->fetch($opts))
- {
- $tree['opts'][$opt['id']] = array('opt' => $opt['text'], 'branch' => branch($opt['to']));
- }
- return $tree;
- }
- function loosends($stage, &$num)
- {
- global $sql;
- $out = '';
- $opts = $sql->query('SELECT * FROM g_opts WHERE stage = '.$stage);
- while($opt = $sql->fetch($opts))
- {
- if(!$opt['to'])
- {
- $num++;
- $out .= '<li><a href="game.php?option='.$opt['id'].'">'.$opt['text'].'</a></li>';
- }
- else
- $out .= loosends($opt['to'], $num);
- }
- return $out;
- }
- function branchp($arr)
- {
- $out = '<div class="tree" style="display: none;">';
- $out .= '<p>'.($arr['text']?nl2br(htmlval($arr['text'])):'This part of the story isn\'t done yet!').'</p>';
- foreach($arr['opts'] as $k => $v)
- {
- if(is_array($v))
- {
- $out .= '<div class="tog" onclick="$(this).next().slideToggle();">'.$v['opt'].'</div>';
- $out .= branchp($v['branch']);
- }
- }
- $out .= '</div>';
- return $out;
- }
- $links = '<a href="game.php?loose">Loose ends</a> | <a href="game.php">Beginning</a>';
- $option = isset($_GET['option'])?intval($_GET['option']):0;
- $action = isset($_POST['action'])?$_POST['action']:'';
- $rep = isset($_GET['report'])?intval($_GET['report']):0;
- $msg = $link = $title = '';
- if($rep&&$log)
- {
- if($sql->resultq('SELECT COUNT(*) FROM g_stages WHERE id = "'.$rep.'"')>0)
- {
- $option = $sql->resultq('SELECT id FROM g_opts WHERE `to` = "'.$rep.'"');
- if($sql->resultq('SELECT COUNT(*) FROM g_rep WHERE stage = "'.$rep.'" AND user = "'.$loguser['id'].'"')>0)
- {
- $msg = 'You already reported this setting!';
- }
- else
- {
- $sql->query('REPLACE INTO g_rep SET stage = "'.$rep.'", user = "'.$loguser['id'].'"');
- $msg = 'This setting has been reported!';
- }
- $msg .= '<br /><a href="game.php?option='.$option.'">Go back</a>';
- }
- else
- $msg = 'This setting doesn\'t even exist!<br /><a href="game.php">Go back</a>';
- }
- elseif($option!=0)
- {
- $option = $sql->fetchq('SELECT * FROM g_opts WHERE id = "'.$option.'"');
- $link = '<a href="game.php">Go back to start</a>';
- }
- else
- $option = array('id' => 0, 'to' => 1, 'stage' => 0, 'text' => 'The Beginning');
- if(isset($_GET['branch']))
- {
- $title = 'Branch';
- $tree = branch(1);
- $msg = '<div class="tog" onclick="$(this).next().slideDown();">Start!</div>'.branchp($tree);
- }
- elseif(isset($_GET['loose']))
- {
- $num = 0;
- $msg = '<ol>'.loosends(1, $num).'</ol>';
- $title = 'Loose ends ('.$num.')';
- }
- elseif($action)
- {
- if($log)
- {
- switch($action)
- {
- case 'newsetting':
- $num = isset($_POST['numopts'])?intval($_POST['numopts']):2;
- $optid = isset($_POST['optid'])?intval($_POST['optid']):0;
- if($num>=4) $num = 4;
- if($num<1) $num = 1;
- if($optid)
- {
- $opt = $sql->fetchq('SELECT * FROM g_opts WHERE id = "'.$_POST['optid'].'"');
- $msg = '
- <form method="post" action="game.php"><input type="hidden" name="optid" value="'.$_POST['optid'].'"><input type="hidden" name="numopts" value="'.$num.'"><input type="hidden" name="action" value="submitsetting"><table>
- <tr><th colspan="2">Setting for "'.$opt['text'].'" option</th></tr>
- <tr><td width="150px"><label for="setting">Setting:</label></td><td><textarea id="setting" name="setting" cols="80" rows="5"></textarea></td></tr>';
- for($i=1;$i<=$num;$i++)
- $msg.= '<tr><td><label for="opt'.$i.'">Option '.$i.':</label></td><td><input type="text" id="opt'.$i.'" name="opt'.$i.'"></td></tr>
- ';
- $msg .= '<tr><td> </td><td><input type="submit" value="Submit"></td></tr>
- </table></form>';
- }
- else
- $msg = 'No option ID was specified.';
- break;
- case 'submitsetting':
- $num = isset($_POST['numopts'])?intval($_POST['numopts']):2;
- if($num>=4) $num = 4;
- if($num<1) $num = 1;
- $text = isset($_POST['setting'])?trim($_POST['setting']):'';
- $optid = isset($_POST['optid'])?intval($_POST['optid']):0;
- $err = array();
- if(!$text)
- {
- $err[] = 'You didn\'t fill the "setting" field.';
- }
- if(!$optid)
- {
- $err[] = 'No option ID was specified.';
- }
- else
- {
- $opt = $sql->fetchq('SELECT * FROM g_opts WHERE id = "'.$_POST['optid'].'"');
- if($opt['to']!=0)
- $err[] = 'Someone submitted the option before you did!';
- }
- for($i=1;$i<=$num;$i++)
- {
- if(!trim($_POST['opt'.$i]))
- {
- $err[] = 'You didn\'t fill all the options.';
- break;
- }
- }
- if(!$err[0])
- {
- $sql->query('INSERT INTO g_stages SET text = "'.$text.'", user = "'.$loguser['id'].'"');
- $stageid = mysql_insert_id();
- $sql->query('UPDATE g_opts SET `to` = "'.$stageid.'" WHERE id = "'.$optid.'"');
- for($i=1;$i<=$num;$i++)
- $sql->query('INSERT INTO g_opts SET stage = '.$stageid.', text = "'.$_POST['opt'.$i].'"');
- sendirc('New option submitted by '.$loguser['name'].'! {boardurl}game.php?option='.$optid);
- $msg = 'Option submitted succesfully!<br /><a href="game.php?option='.$optid.'">Go back where you ended!</a>';
- }
- else
- {
- $msg = 'The following error'.(sizeof($err)==1?'':'s').' occured:<ul><li>'.implode('</li><li>', $err).'</li></ul>';
- }
- break;
- case 'ending':
- $text = isset($_POST['ending'])?trim($_POST['ending']):'';
- $optid = isset($_POST['optid'])?intval($_POST['optid']):0;
- if(!$text)
- {
- $err[] = 'You didn\'t fill the "ending" field.';
- }
- if(!$optid)
- {
- $err[] = 'No option ID was specified.';
- }
- if(!$err[0])
- {
- $sql->query('INSERT INTO g_stages SET text = "'.$text.'", user = "'.$loguser['id'].'"');
- $stageid = mysql_insert_id();
- $sql->query('UPDATE g_opts SET `to` = "'.$stageid.'" WHERE id = "'.$optid.'"');
- sendirc('An ending was submitted by '.$loguser['name'].'! {boardurl}game.php?option='.$optid);
- $msg = 'Setting submitted succesfully!<br /><a href="game.php?option='.$optid.'">Go back where you ended!</a>';
- }
- else
- {
- $msg = 'The following error'.(sizeof($err)==1?'':'s').' occured:<ul><li>'.implode('</li><li>', $err).'</li></ul>';
- }
- break;
- }
- }
- else
- $msg = 'You need to be logged in to add to the game!<br /><a href="login.php">Log in.</a>';
- }
- elseif(!$msg)
- {
- if(!$option)
- {
- $msg = 'This option doesn\'t even exist!';
- }
- elseif(!$option['to'])
- {
- $title = $option['text'];
- $msg = '<h3>This part of the story isn\'t done yet. You can either continue the story, or end it here.</h3>
- <div><a href="#" onclick="$(\'#end\').slideUp(); $(\'#continue\').slideDown(); return false;">Continue</a> | <a href="#" onclick="$(\'#continue\').slideUp(); $(\'#end\').slideDown(); return false;">End</a></div>
- <div id="continue" style="display: none;"><form method="post" action="game.php"><input type="hidden" name="optid" value="'.$option['id'].'"><input type="hidden" name="action" value="newsetting"><table>
- <tr><th colspan="2">Continue the story</th></tr>
- <tr><td width="150px"><label for="numopts">Number of options (max: 4):</label></td><td><input type="text" id="numopts" name="numopts" size="2" maxlength="1"></td></tr>
- <tr><td> </td><td><input type="submit" value="Submit"></td></tr>
- </table></form></div>
- <div id="end" style="display: none;"><form method="post" action="game.php"><input type="hidden" name="optid" value="'.$option['id'].'"><input type="hidden" name="action" value="ending"><table>
- <tr><th colspan="2">End it here</th></tr>
- <tr><td width="150px"><label for="ending">Ending text:</label></td><td><textarea id="ending" name="ending" cols="80" rows="5"></textarea></td></tr>
- <tr><td> </td><td><input type="submit" value="Submit"></td></tr>
- </table></form></div>';
- }
- else
- {
- $setting = $sql->fetchq('SELECT * FROM g_stages WHERE id = "'.$option['to'].'"');
- $opts = $sql->query('SELECT * FROM g_opts WHERE stage = "'.$option['to'].'"');
- $title = $option['text'];
- $l = array();
- while($opt = $sql->fetch($opts))
- {
- $msg .= '<li><a href="game.php?option='.$opt['id'].'">'.htmlentities($opt['text']).'</a></li>';
- }
- if(!$msg) $msg = '<h2>THE END</h2><a href="game.php">Go back to the beginning</a>.';
- else $msg = '<ul>'.$msg.'</ul>';
- }
- $msg = '<div id="setting">'.nl2br(htmlval($setting['text'])).'</div><div id="opts">'.$msg.'</div>';
- if($option['stage'])
- {
- $option = $sql->resultq('SELECT id FROM g_opts WHERE `to` = "'.$option['stage'].'"');
- $l[] = '<a href="game.php'.($option?'?option='.$option:'').'">Go back to previous setting</a>';
- }
- if($setting['user'])
- {
- $user = $sql->fetchq('SELECT name,sex,power,color,id FROM users WHERE id = '.$setting['user']);
- $l[] = 'Setting by '.userlink($user).'~';
- }
- if($log)
- $l[] = '<a href="game.php?report='.$setting['id'].'">Report</a>';
- if($l[0])
- $links .= ' | '.implode(' | ', $l);
- }
- $title = ($title?$title.' | ':'').'Choose your own adventure: Neritic';
- ?>
- <!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>
- <title><?=$title?></title>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <meta name="Author" content="Kaeru" />
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
- <style type="text/css">
- body{font-size: 12px; font-family: tahoma; color: #000; background: #fafafa; padding: 8px;}
- div#main{background: #eee; border: #000 1px solid; padding: 10px;}
- div.t {background: #444; border: #666 1px solid; padding: 10px; color: #eee;}
- div.t > div {padding: 10px;}
- p.sm{border: 0; border-top: #999 1px dotted; font-size: .8em}
- div.tree{padding: 4px; border: #aaa 1px solid; background: url('theme/fragment/tdbg3.png')}
- div.tog{font-weight: bold; cursor: pointer; margin: 4px;}
- input[type=submit]{background: #e6e6e6; border: #ccc 1px outset; color: #111;}
- input[type=submit]:hover{background: #eee; border: #ccc 1px inset; color: #111;}
- textarea, input[type=text]{background: #c6c6c6; border: #eee 1px outset; color: #111;}
- a:link{color:#333; font-weight: bold; text-decoration: none;}
- a:visited{color:#333; font-weight: bold; text-decoration: none;}
- a:active{color:#222; text-decoration: none;}
- a:hover{color:#111;text-decoration: underline;}
- div a:link, div a:visited{color:#ccc; font-weight: bold; text-decoration: none;}
- div a:active{color:#fff; text-decoration: none;}
- div a:hover{color:#fff;text-decoration: underline;}
- form{display: inline;}
- table{border: #e6e6e6 1px outset; width: 100%; margin: 4px;}
- </style>
- </head>
- <body>
- <h1><?=$title?></h1>
- <p class="sm"><?=$links?></p>
- <div id="main">
- <div class="t"><?=$msg?></div>
- </div>
- <div><small>By Kaeru~<br /><?=pagestats();?></small></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement