aaaaaa123456789 icon

Prize awarder for bls

aaaaaa123456789 | PRO | 12/25/13 05:58:27 PM UTC | 0 ⭐ | 410 👁️ | Never ⏰ | []
PHP |

5 KB

|

None

|

0 👍

/

0 👎

<?php
 
require_once 'ptempl.php';
 
function ob_kill () {
  $ob = ob_get_contents();
  ob_end_clean();
  return $ob;
}
 
ob_start();
// initial page follows
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Prize awarder login</title>
  </head>
  <body>
    <center>
    <h4>Please enter the following cookie information:</h4>
    <!-- ##form: location -->
    <form action="$$location" method="post">
      <input type="hidden" name="mode" value="awstart" />
      bb_userid: <input type="text" name="cookie_bb_userid" value="" maxlength="5" size="6" /><br />
      bb_password: <input type="text" name="cookie_bb_password" value="" maxlength="32" size="44" /><br />
      <input type="submit" value="Log in" />
      <input type="reset" value="Reset fields" />
    </form>
    <!-- ### -->
  </body>
</html>
<?php
$initial_page = ob_kill();
 
ob_start();
// output page follows
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Prize awarder</title>
  </head>
  <body>
    <center>
      <!-- ##form: location -->
      <form action="$$location" method="post">
        <!-- ##parameter: name, value -->
        <input type="hidden" name="$$name" value="$$value" />
        <!-- #### -->
        <input type="text" name="username" value="" /><br />
        <input type="submit" value="Award!" />
        <input type="reset" value="Reset" />
      </form>
      <!-- ### -->
      <br /><hr /><br />
      <!-- ##list -->
      <h2>Awarded prizes:</h2>
      <select multiple="multiple" style="width: 90%;">
        <!-- ##awarded: info -->
        <option>$$info</option>
        <!-- #### -->
      </select>
      <!-- ### -->
    </center>
  </body>
</html>
<?php
$output_page = ob_kill();
 
function show_initial_page () {
  global $initial_page;
  echo parse_template($initial_page, array('form' => function () {return array(1 => $_SERVER['PHP_SELF']);}));
}
 
function award_prize ($username, $cookie_info) {
  $curl_session = curl_init();
  curl_setopt($curl_session, CURLOPT_URL, 'http://jiggmin.com/contests/award-prize.php?' . http_build_query(array(
    'contest' => 'Epic Santa',
    'action' => 'give',
    'jvname' => '',
    'pr2name' => $username)));
  $cookiestring = '';
  foreach ($cookie_info as $cookie => $value) {
    if ($cookiestring != '') $cookiestring .= '; ';
    $cookiestring .= "$cookie=$value";
  }
  curl_setopt($curl_session, CURLOPT_COOKIE, $cookiestring);
  curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($curl_session);
  curl_close($curl_session);
  $result = strpos($result, 'It seems there was an error:');
  return $result === false;
}
 
function show_awards_page ($award_info, $cookie_info) {
  global $output_page;
  echo parse_template($output_page, array(
      'form' => function () {
        return array(1 => $_SERVER['PHP_SELF']);
      },
      'parameter' => function ($awards, $cookies) {
        $params = array();
        $count = 0;
        foreach ($cookies as $name => $value)
          $params[++ $count] = array(1 => htmlspecialchars('cookie_' . $name), 2 => htmlspecialchars($value));
        foreach ($awards as $id => $value)
          $params[++ $count] = array(1 => 'award' . $id, 2 => htmlspecialchars($value));
        $params[++ $count] = array(1 => 'total_awards', 2 => count($awards));
        $params[++ $count] = array(1 => 'mode', 2 => 'award');
        $params[0] = $count;
        return $params;
      },
      'list' => function ($awards) {
        return (bool) (count($awards));
      },
      'awarded' => function ($awards) {
        $result = array();
        $result[0] = count($awards);
        for ($i = 0; $i < count($awards); $i ++)
          $result[count($awards) - $i] = array(1 => $awards[$i]);
        return $result;
      }
    ), $award_info, $cookie_info);
}
 
function get_cookie_info () {
  $cookieinfo = array();
  foreach ($_POST as $name => $value)
    if (substr($name, 0, 7) == 'cookie_')
      $cookieinfo[substr($name, 7)] = $value;
  return $cookieinfo;
}
 
function get_award_info () {
  if (@$_POST['mode'] != 'award') return array();
  $count = (int) $_POST['total_awards'];
  $result = array();
  for ($i = 0; $i < $count; $i ++)
    $result[$i] = $_POST['award' . $i];
  return $result;
}
 
if (!isset($_POST['mode']))
  show_initial_page();
else
  switch ($_POST['mode']) {
    case 'awstart':
      $cookies = get_cookie_info();
      show_awards_page(array(), $cookies);
      break;
    case 'award':
      $cookies = get_cookie_info();
      $user = $_POST['username'];
      $awards = get_award_info();
      $status = award_prize($user, $cookies);
      $awards[] = $status ? $user : "$user [NOT AWARDED]";
      show_awards_page($awards, $cookies);
      break;
    default:
      show_initial_page();
  }
?>

Comments