/**
  * Creates a PermissionsEditor
  *
  * @param SiteSettings $settings
  * @param DataEditControl $controlling_editor
  * @param string $s_id
  * @param string $s_title
  */
 public function __construct(SiteSettings $settings, DataEditControl $controlling_editor, $s_id, $s_title)
 {
     $this->SetDataObjectClass('IdValue');
     $this->SetDataObjectMethods('GetId', '', '');
     parent::__construct($settings, $controlling_editor, $s_id, $s_title, array("Permission", "Resource URI"));
     # initialise arrays
     $this->permissions = array(new IdValue(PermissionType::ViewPage(), ucfirst(PermissionType::Text(PermissionType::ViewPage()))), new IdValue(PermissionType::ForumAddMessage(), ucfirst(PermissionType::Text(PermissionType::ForumAddMessage()))), new IdValue(PermissionType::EditPersonalInfo(), ucfirst(PermissionType::Text(PermissionType::EditPersonalInfo()))), new IdValue(PermissionType::MANAGE_CATEGORIES, ucfirst(PermissionType::Text(PermissionType::MANAGE_CATEGORIES))), new IdValue(PermissionType::MANAGE_USERS_AND_PERMISSIONS, ucfirst(PermissionType::Text(PermissionType::MANAGE_USERS_AND_PERMISSIONS))), new IdValue(PermissionType::PageSubscribe(), ucfirst(PermissionType::Text(PermissionType::PageSubscribe()))), new IdValue(PermissionType::MANAGE_URLS, ucfirst(PermissionType::Text(PermissionType::MANAGE_URLS))), new IdValue(PermissionType::MANAGE_SEARCH, ucfirst(PermissionType::Text(PermissionType::MANAGE_SEARCH))), new IdValue(PermissionType::VIEW_ADMINISTRATION_PAGE, ucfirst(PermissionType::Text(PermissionType::VIEW_ADMINISTRATION_PAGE))), new IdValue(PermissionType::VIEW_WORDPRESS_LOGIN, ucfirst(PermissionType::Text(PermissionType::VIEW_WORDPRESS_LOGIN))), new IdValue(PermissionType::EXCLUDE_FROM_ANALYTICS, ucfirst(PermissionType::Text(PermissionType::EXCLUDE_FROM_ANALYTICS))), new IdValue(PermissionType::MANAGE_TEAMS, ucfirst(PermissionType::Text(PermissionType::MANAGE_TEAMS))), new IdValue(PermissionType::MANAGE_COMPETITIONS, ucfirst(PermissionType::Text(PermissionType::MANAGE_COMPETITIONS))), new IdValue(PermissionType::MANAGE_GROUNDS, ucfirst(PermissionType::Text(PermissionType::MANAGE_GROUNDS))), new IdValue(PermissionType::ADD_MATCH, ucfirst(PermissionType::Text(PermissionType::ADD_MATCH))), new IdValue(PermissionType::EDIT_MATCH, ucfirst(PermissionType::Text(PermissionType::EDIT_MATCH))), new IdValue(PermissionType::DELETE_MATCH, ucfirst(PermissionType::Text(PermissionType::DELETE_MATCH))), new IdValue(PermissionType::MANAGE_MATCHES, ucfirst(PermissionType::Text(PermissionType::MANAGE_MATCHES))), new IdValue(PermissionType::MANAGE_PLAYERS, ucfirst(PermissionType::Text(PermissionType::MANAGE_PLAYERS))), new IdValue(PermissionType::MANAGE_STATISTICS, ucfirst(PermissionType::Text(PermissionType::MANAGE_STATISTICS))));
 }
 function OnPreRender()
 {
     /* @var $o_top_level Category */
     $review_item = $this->o_topic->GetReviewItem();
     $s_suggested_title = urlencode(StringFormatter::PlainText(trim($review_item->GetTitle())));
     $s_page = urlencode($_SERVER['REQUEST_URI']);
     $s_subscribe_link = '/play/subscribe.php?type=' . $review_item->GetType() . '&item=' . $review_item->GetId() . '&title=' . $s_suggested_title . '&page=' . $s_page;
     $s_subscribe_title = 'Get an email alert every time there are new comments on this page';
     $this->AddControl('<div class="forumSubscribe"><a href="' . $s_subscribe_link . '" title="' . $s_subscribe_title . '">Subscribe to comments</a></div>');
     if (!$this->authentication_manager->GetUser()->Permissions()->HasPermission(PermissionType::ForumAddMessage())) {
         $add = $this->o_topic->GetCount() ? 'Add your comments' : 'Be the first to add your comments!';
         $this->AddControl('<div class="forumPost"><a href="' . Html::Encode($this->authentication_manager->GetPermissionUrl()) . urlencode('#forumMessageForm') . '">' . $add . '</a></div>');
     }
 }
 /**
  * Gets a description of a permission
  * @param int $type
  * @return string
  */
 public static function Text($type)
 {
     switch ($type) {
         case PermissionType::ViewPage():
             return 'view a page';
         case PermissionType::ForumAddMessage():
             return "post a forum message";
         case PermissionType::EditPersonalInfo():
             return "edit own profile";
         case PermissionType::MANAGE_CATEGORIES:
             return "manage categories";
         case PermissionType::MANAGE_USERS_AND_PERMISSIONS:
             return "manage users and permissions";
         case PermissionType::PageSubscribe():
             return "subscribe to alerts for comments on pages";
         case PermissionType::MANAGE_URLS:
             return "manage URLs";
         case PermissionType::MANAGE_SEARCH:
             return "manage search";
         case PermissionType::VIEW_ADMINISTRATION_PAGE:
             return "view the admin menu";
         case PermissionType::VIEW_WORDPRESS_LOGIN:
             return "view the WordPress login link";
         case PermissionType::EXCLUDE_FROM_ANALYTICS:
             return "opt out of Google Analytics";
         case PermissionType::MANAGE_TEAMS:
             return "manage teams and clubs";
         case PermissionType::MANAGE_COMPETITIONS:
             return "manage competitions and seasons";
         case PermissionType::MANAGE_GROUNDS:
             return "manage grounds";
         case PermissionType::ADD_MATCH:
             return 'add matches';
         case PermissionType::EDIT_MATCH:
             return "edit own matches, and results of any match";
         case PermissionType::DELETE_MATCH:
             return "delete own matches";
         case PermissionType::MANAGE_MATCHES:
             return "manage matches";
         case PermissionType::MANAGE_PLAYERS:
             return "manage players";
         case PermissionType::MANAGE_STATISTICS:
             return "manage match statistics";
     }
 }
            echo "<p>There aren't any statistics for " . htmlentities($this->match->GetTitle(), ENT_QUOTES, "UTF-8", false) . ' yet.</p>
            <p>To find out how to add them, see <a href="/play/manage/website/matches-and-results-why-you-should-add-yours/">Matches and results - why you should add yours</a>.</p>';
        } else {
            ?>
            <div class="statsColumns">
                <div class="statsColumn">
            <div class="chart-js-template" id="worm-chart"></div>
            </div>
                <div class="statsColumn">
            <div class="chart-js-template" id="run-rate-chart"></div>
            </div>
            </div>
            <div class="statsColumns manhattan">
            <h2>Scores in each over</h2>
                <div class="statsColumn">
                    <div class="chart-js-template" id="manhattan-chart-first-innings"></div>
                </div>
                <div class="statsColumn">
                    <div class="chart-js-template" id="manhattan-chart-second-innings"></div>
                </div>
            </div>
            <?php 
        }
        ?>
        </div>
        </div>
        <?php 
    }
}
new CurrentPage(new StoolballSettings(), PermissionType::ViewPage(), false);
<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../classes/');
require_once 'page/stoolball-page.class.php';
class EditProfilePage extends StoolballPage
{
    function OnPrePageLoad()
    {
        $this->SetPageTitle('Edit profile for ' . AuthenticationManager::GetUser()->GetName());
    }
    function OnPageLoad()
    {
        echo '<h1>' . htmlentities($this->GetPageTitle(), ENT_QUOTES, "UTF-8", false) . '</h1>';
        echo '<div class="nav">' . '<h2><a href="' . $this->GetSettings()->GetUrl('AccountEssential') . '">Essential information</a></h2>' . '<p>Change your name, email address or password.</p>' . '<h2><a href="personal.php">More about you</a></h2>' . "<p>Tell others where you're from, who you are and what you like.</p>" . '<h2><a href="' . $this->GetSettings()->GetUrl('EmailAlerts') . '">Email alerts</a></h2>' . "<p>Change the email alerts you get when someone adds a comment.</p>" . "</div>";
    }
}
new EditProfilePage(new StoolballSettings(), PermissionType::EditPersonalInfo(), false);
 /**
  * @return bool
  * @desc Gets whether the person is currently signed in to the site
  */
 function IsSignedIn()
 {
     return $this->Permissions()->HasPermission(PermissionType::EditPersonalInfo());
 }
                $o_message->AddControl(new XhtmlElement('p', $s_message));
            } else {
                echo '<h1>Check your email to confirm your registration</h1>';
                $o_message->AddControl(new XhtmlElement('p', 'Thanks for registering with ' . Html::Encode($this->GetSettings()->GetSiteName()) . '.'));
                $s_message = "We've sent you an email. Please check your inbox now, and click on the link in the email to confirm your registration.";
                $o_message->AddControl(new XhtmlElement('p', $s_message));
            }
            echo $o_message;
        } else {
            if ($this->b_success) {
                ?>
                <h1>Confirmation successful</h1>
                <p>Welcome to <?php 
                echo Html::Encode($this->GetSettings()->GetSiteName());
                ?>
!</p>
                <p>We've activated your account, and sent you an email confirming your sign in details.</p>
          
                <p><strong>Please <a href="/you">sign in</a> using your email address and your new password.</strong></p>
           
                <?php 
            } else {
                echo new XhtmlElement('h1', 'Confirmation failed');
                echo new XhtmlElement('p', 'Sorry, your registration for ' . Html::Encode($this->GetSettings()->GetSiteName()) . ' could not be confirmed.');
                echo new XhtmlElement('p', 'Please check that you used the exact address in the email you received, or try to <a href="' . Html::Encode($this->GetSettings()->GetUrl('AccountCreate')) . '">register again</a>.');
            }
        }
    }
}
new ActivationPage(new StoolballSettings(), PermissionType::ViewPage(), false);
require_once 'forums/subscription-manager.class.php';
require_once 'forums/subscription-grid.class.php';
class SubscriptionManagerPage extends StoolballPage
{
    private $a_subs;
    function OnLoadPageData()
    {
        $sub_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection());
        # process delete request
        if (isset($_GET['delete']) and is_numeric($_GET['delete']) and (isset($_GET['type']) and is_numeric($_GET['type']))) {
            $sub_manager->DeleteSubscription($_GET['delete'], $_GET['type'], AuthenticationManager::GetUser()->GetId());
        }
        # get subscription data
        $sub_manager->ReadSubscriptionsForUser(AuthenticationManager::GetUser()->GetId());
        $this->a_subs = $sub_manager->GetItems();
    }
    function OnPrePageLoad()
    {
        $this->SetPageTitle('Email alerts for ' . AuthenticationManager::GetUser()->GetName());
    }
    function OnPageLoad()
    {
        echo new XhtmlElement('h1', Html::Encode($this->GetPageTitle()));
        echo '<p>You can subscribe to emails for ' . Html::Encode($this->GetSettings()->GetSiteName()) . '\'s match comments. ' . 'Once you have subscribed, as soon as anyone else adds their comments,  you\'ll get an email.</p>';
        # display tables of subscriptions
        echo new SubscriptionGrid($this->GetSettings(), $this->a_subs);
        echo '<form method="get" action="' . Html::Encode($this->GetSettings()->GetUrl('AccountEdit')) . '"><div>' . '<input type="submit" class="submit" value="Done" title="Return to your edit profile options page" />' . '</div></form>';
    }
}
new SubscriptionManagerPage(new StoolballSettings(), PermissionType::PageSubscribe(), false);
                    $s_email_status = $email_success ? '' : '&email=no';
                    $this->Redirect($this->GetSettings()->GetUrl('AccountActivate') . '?action=request' . $s_email_status);
                }
            } else {
                # email not in db, so sign up a new user
                $new_user = $authentication_manager->RegisterUser($new_user);
                # add activation request
                $s_hash = $authentication_manager->SaveRequest($new_user->GetId());
                # send email requesting activation - validates email address
                $email_success = $authentication_manager->SendActivationEmail($new_user, $s_hash);
                # redirect to sign-in page
                $s_email_status = $email_success ? '' : '&email=no';
                $this->Redirect($this->GetSettings()->GetUrl('AccountActivate') . '?action=request' . $s_email_status);
            }
        }
    }
    function OnPrePageLoad()
    {
        $this->SetPageTitle('Register with ' . $this->GetSettings()->GetSiteName());
        $this->SetContentConstraint(StoolballPage::ConstrainText());
    }
    function OnPageLoad()
    {
        echo '<h1>' . Html::Encode($this->GetPageTitle()) . '</h1>';
        $new_user = is_object($this->new_user) ? $this->new_user : new User();
        $this->form->SetDataObject($new_user);
        echo $this->form;
    }
}
new SignUpPage(new StoolballSettings(), PermissionType::ViewPage(), false);
 private function DisplayComments()
 {
     # Display review topic listing
     require_once 'forums/forum-topic-listing.class.php';
     require_once 'forums/forum-comments-topic-navbar.class.php';
     if (!isset($this->topic)) {
         $this->topic = new ForumTopic($this->GetSettings());
     }
     $this->topic->SetReviewItem($this->review_item);
     $signed_in = AuthenticationManager::GetUser()->IsSignedIn();
     echo '<div id="comments-topic"';
     if ($signed_in) {
         echo ' class="signed-in"';
     }
     echo '>';
     if ($this->topic->GetCount() or !$signed_in) {
         echo '<h2>Comments</h2>';
     }
     $navbar = new ForumCommentsTopicNavbar($this->topic, $this->GetAuthenticationManager());
     echo $navbar;
     $o_review_topic = new ForumTopicListing($this->GetSettings(), AuthenticationManager::GetUser(), $this->topic);
     echo $o_review_topic;
     if ($this->topic->GetCount() and !$signed_in) {
         echo $navbar;
     }
     # Add comment
     if (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::ForumAddMessage())) {
         # create form
         $this->LoadClientScript("/scripts/tiny_mce/jquery.tinymce.js");
         $this->LoadClientScript("/scripts/tinymce.js");
         require_once 'forums/forum-message-form.class.php';
         $o_form = new ForumMessageForm();
         echo $o_form->GetForm();
     }
     echo '</div>';
 }
 /**
  * Ensures there is a user object available with view permissions even if no user is signed in
  *
  * @return void
  */
 public static function EnsureUser()
 {
     if (!isset($_SESSION['user'])) {
         $_SESSION['user'] = new User();
     }
     $_SESSION['user']->Permissions()->AddPermission(PermissionType::ViewPage());
 }
            }
            # success - redirect to edit profile home
            $this->Redirect($this->GetSettings()->GetUrl('AccountEdit'));
        }
    }
    function OnPrePageLoad()
    {
        $this->SetPageTitle('Essential information for ' . AuthenticationManager::GetUser()->GetName());
        $this->SetContentConstraint($this->ConstrainText());
    }
    function OnPageLoad()
    {
        if ($this->show_changed_email_message) {
            ?>
<h1>Just one more thing&#8230;</h1>
<p>There's one more step before we update your email address.</p>
<p>Please check your email inbox, and within the next few minutes you should see something from us asking you to confirm your email address. 
    Click on the link in the email, and we'll update your account.</p>
			<?php 
            echo '<p><a href="' . Html::Encode($this->GetSettings()->GetUrl('AccountEdit')) . '">Back to your profile</a></p>';
        } else {
            echo new XhtmlElement('h1', Html::Encode($this->GetPageTitle()));
            if (!is_null($this->error)) {
                echo $this->error;
            }
            echo $this->form;
        }
    }
}
new CurrentPage(new StoolballSettings(), PermissionType::EditPersonalInfo(), false);