<?php

require_once '../../FbStats.php';
include_once '../config.php';
include_once 'helper.php';
if (!session_id()) {
    session_start();
}
// Create Facebook Instance
$fb = new FbStats($config);
if (isset($_POST['publish'])) {
    try {
        $wall_post = $fb->wallPost($_POST['group'], $_POST['message']);
        if ($wall_post) {
            echo '<div class="success">Published</div>';
        } else {
            echo '<div class="alert-message error">Error in publishing result. Please try again.</div>';
        }
    } catch (Exception $e) {
        echo '<div class="alert-message error">' . $e->getMessage() . '</div>';
    }
} else {
    // Get submitted data
    $since = !empty($_POST['from']) ? time_ago(time() - strtotime(urldecode($_POST['from']))) : 'yesterday';
    $until = !empty($_POST['to']) ? time_ago(time() - strtotime(urldecode($_POST['to']))) : 'now';
    $stat = $_POST['stat'];
    $usersCount = !empty($_POST['usersCount']) ? $_POST['usersCount'] : 10;
    $selfComments = isset($_POST['selfComments']) ? $_POST['selfComments'] : 0;
    $ignoreLinks = isset($_POST['ignoreLinks']) ? $_POST['ignoreLinks'] : 0;
    $ignorePhotos = isset($_POST['ignorePhotos']) ? $_POST['ignorePhotos'] : 0;
    $minLines = isset($_POST['minLines']) && !empty($_POST['minLines']) ? $_POST['minLines'] : 0;