function check_user_progress($pano_id)
{
    // Check the user's progress before allowing
    // the user to see the pano
    $allowed = true;
    $flag_not_set = true;
    $accumulated_points = 0;
    $bonus_points = 0;
    $total_points = 0;
    $user_id = get_current_user_id();
    // Check if the pano has a prereq
    $prereqs = get_pano_prereq($pano_id);
    // if it does make sure the user has completed
    // enough skills and missions
    if (count($prereqs) > 0) {
        if (is_null(v) || $prereqs->prereq_domain_id == 0) {
            // Get the accumulated points
            $accumulated_points = get_user_accumulated_points($user_id);
            // Get the bonus points
            $bonus_points = get_user_accumulated_bonus_pts($user_id);
        } else {
            // Get the accumulated points based on the prereq domain
            $accumulated_points = get_user_accumulated_points_for_prereq($user_id, $prereqs->prereq_domain_id);
            // Get the bonus points
            $bonus_points = get_user_accumulated_bonus_pts_for_prereq($user_id, $prereqs->prereq_domain_id);
        }
        $items = get_prereq_items($prereqs->id);
        $user_items_count = 0;
        $prereq_items_count = sizeof($items);
        foreach ($items as $item) {
            if (check_if_user_has_item(get_current_user_id(), $item->item_id)) {
                $user_items_count++;
            }
        }
        // Ensures the values are not null
        $accumulated_points = $accumulated_points ? $accumulated_points : 0;
        $bonus_points = $bonus_points ? $bonus_points : 0;
        // Add up the points
        $total_points = $accumulated_points->points + $bonus_points->bonus_points;
        // check if they are enough for the prereq
        if ($total_points > $prereqs->prereq_pts && $user_items_count == $prereq_items_count) {
            $allowed = true;
            $flag_not_set = true;
        } else {
            if ($flag_not_set) {
                $allowed = false;
                $flag_not_set = false;
            }
        }
    }
    // If they have, return the pano else return default id
    if ($allowed) {
        return true;
    } else {
        return false;
    }
}
Пример #2
0
function prereq_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $new_prereq_url = admin_url() . "admin.php?page=prereq_new_setting";
    $edit_prereq_url = admin_url() . "admin.php?page=prereq_edit_setting";
    $pano_id = null;
    if (isset($_GET['pano_id']) && is_numeric($_GET['pano_id'])) {
        $pano_id = $_GET['pano_id'];
    }
    $prereqs = get_pano_prereq($pano_id);
    ?>
    <link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
    <h2>Create a new prereq!</h2>
    <hr>
    <?php 
    if (isset($_GET['settings-saved'])) {
        ?>
        <div class="updated"><p>Settings updated successfully.</p></div>
    <?php 
    }
    ?>
    <table class="ui table segment">
      <tr>
        <th>Prereq Points</th>
        <th>Prereq Domain</th>
        <th>Prereq Info</th>
        <th>Prereq Item Qty</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>
      <?php 
    foreach ($prereqs as $prereq) {
        ?>

            <?php 
        $domain = get_domain($prereq->prereq_domain_id);
        ?>

            <tr>
                <td><?php 
        echo $prereq->prereq_pts;
        ?>
</td>
                <td><?php 
        echo $domain->name;
        ?>
</td>
                <td><?php 
        echo $prereq->prereq_desc;
        ?>
</td>
                <td><?php 
        echo count(get_prereq_items($prereq->id));
        ?>
</td>
                <td><a class="ui blue icon button" href="<?php 
        echo $edit_prereq_url;
        ?>
&id=<?php 
        echo $prereq->id;
        ?>
" style="padding: 7px">Edit</a></td>
                <td>
                    <form method="post" action="admin-post.php" id="delete_prereq_form<?php 
        echo $prereq->id;
        ?>
">
                        <!-- pano processing hook -->
                        <input type="hidden" name="action" value="delete_prereq" />
                        <input type="hidden" name="pano_id" value="<?php 
        echo $pano_id;
        ?>
" />
                        <input type="hidden" name="prereq_id" value="<?php 
        echo $prereq->id;
        ?>
" />

                        <input type="submit" class="ui blue icon button" value="Delete" style="padding: 7px" >
                    </form>
                </td>
            </tr>

        <?php 
    }
    ?>
    </table>
    <a class="ui blue icon button" href="<?php 
    echo $new_prereq_url;
    ?>
&pano_id=<?php 
    echo $pano_id;
    ?>
" style="padding: 7px">New Prereq</a>
    </div>

    <script>
        jQuery(document).ready(function(){
        });
    </script>

<?php 
}
function prereq_edit_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $domains = get_domains();
    $items = get_items();
    $item_types = get_item_types();
    $prereq = null;
    $prereq_id = null;
    if (isset($_GET['pano_id']) && is_numeric($_GET['pano_id'])) {
        $prereq = get_pano_prereq($_GET['pano_id']);
        $prereq_id = $prereq->id;
    }
    $prereq_items = get_prereq_items($prereq_id);
    $selected_items = array();
    foreach ($prereq_items as $selected_item) {
        array_push($selected_items, $selected_item->item_id);
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit your Prereqs!</h2>
<hr>

<form id="form" method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
  <!-- pano processing hook -->
  <input type="hidden" name="action" value="edit_prereq" />
  <input type="hidden" name="id" value="<?php 
    echo $prereq->id;
    ?>
" />
  <input type="hidden" name="pano_id" value="<?php 
    echo $prereq->pano_id;
    ?>
" />
  <div class="ui form segment new_prereq_form">
    <div class="ui form">
      <div class="field">
        <label for="prereq_pts">Prereq Points</label>
        <input type="number" name="prereq_pts" id="prereq_pts" placeholder="100" value="<?php 
    echo $prereq->prereq_pts;
    ?>
"required />
      </div>
    </div>
    <input type="hidden" name="prereq_domain_id" value="NA" />
    <div class="ui form">
      <div class="field">
        <label for="prereq_desc">Prereq Info</label>
        <textarea name="prereq_desc" id="prereq_desc" required ><?php 
    echo $prereq->prereq_desc;
    ?>
</textarea>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label for="item_type">Filter by Item Type</label>
        <select name="item_type" id="item_type" class="ui dropdown">
          <option value="NA">All items</option>
          <?php 
    foreach ($item_types as $item_type) {
        ?>
          <option value="<?php 
        echo $item_type->id;
        ?>
"><?php 
        echo $item_type->name;
        ?>
</option>
          <?php 
    }
    ?>
        </select>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label>Items<span id="item_limit"> - maximum of 5 items</span></label>
        <ul>
          <?php 
    foreach ($items as $item) {
        ?>
            <?php 
        if (in_array($item->id, $selected_items)) {
            ?>
            <li class="games_form item <?php 
            echo $item->type_id;
            ?>
">
              <input type="checkbox" id="<?php 
            echo $item->id;
            ?>
" name="items[]" value="<?php 
            echo $item->id;
            ?>
" checked>
              <label for="<?php 
            echo $item->id;
            ?>
"><?php 
            echo $item->name;
            ?>
</label>
            </li>
            <?php 
        } else {
            ?>
            <li class="games_form item <?php 
            echo $item->type_id;
            ?>
">
              <input type="checkbox" id="<?php 
            echo $item->id;
            ?>
" name="items[]" value="<?php 
            echo $item->id;
            ?>
">
              <label for="<?php 
            echo $item->id;
            ?>
"><?php 
            echo $item->name;
            ?>
</label>
            </li>
            <?php 
        }
        ?>
          <?php 
    }
    ?>
        </ul>
      </div>
    </div>
    <?php 
    submit_button();
    ?>
  </div>
</form>
<script type="text/javascript">
  // Hiding error message
  jQuery('#item_limit').hide();

  // Event listener
  jQuery('#item_type').change(function(){
    filterTypes();
  });
  jQuery(':checkbox').change(function(){
    restrictItems();
  });
  jQuery('#form').submit(function(e){
    if(!restrictItems()){
      e.preventDefault();
    }
  });

  // Filters items based on user selection of item type.
  function filterTypes(){
    if(jQuery('#item_type').val() == 'NA'){
      jQuery('.item').each(function(){
        jQuery(this).show();
      });
    } else {
      var typeId = jQuery('#item_type').val();
      jQuery('.item').each(function(){
        jQuery(this).hide();
      });
      jQuery('.item').each(function(){
        jQuery('.' + typeId).each(function(){
          jQuery(this).show();
        });
      });
    }
  }

  // Displays a message if user picks more than [qty] items.
  // Prevents form submission if user picks more than [qty] items.
  function restrictItems(){
    var qty = 5;
    var allowSend = false;
    if(jQuery(':checkbox:checked').length > qty){
      jQuery('#item_limit').show();
      jQuery('#item_limit').css({'color': 'red', 'font-weight': 'bold'});
      allowSend = false;
    } else {
      jQuery('#item_limit').hide();
      allowSend = true;
    }
    return allowSend;
  }
</script>
<?php 
}
<?php

require_once '../../../../wp-config.php';
require_once '../../../../wp-includes/wp-db.php';
require_once '../../../../wp-includes/pluggable.php';
$semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
$pano_id = $_GET['pano_id'];
$prereq = get_pano_prereq($pano_id);
$currency = get_points_symbol();
$items = get_prereq_items($prereq->id);
$user_id = get_current_user_id();
$items_size = sizeof($items);
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php 
echo $semantic;
?>
"/>
</head>
<body>
<h1>Pano Requirements</h1>
<p><?php 
echo "To access this pano you need:";
?>
</p>