Ejemplo n.º 1
0
function jg_front_end_eventlist($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('detail' => 0, 'display' => true, 'submit' => 'page', 'template' => '', 'pagesize' => 25), $atts));
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    $url = $_SERVER['REQUEST_URI'];
    if (trim($template) == '') {
        $template = 'list-event.html';
    }
    $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jgevents;");
    $events = array();
    $mainEvent = $client->Event->Retrieve($wpjg_generalSettings['Event']);
    $events[] = array('eventname' => $mainEvent->name, 'eventdescr' => $mainEvent->description, 'jgeventid' => $mainEvent->id, 'eventcomplete' => date('d-m-Y H:i', strtotime($mainEvent->completionDate)), 'eventexpiry' => date('d-m-Y H:i', strtotime($mainEvent->expiryDate)), 'eventstart' => date('d-m-Y H:i', strtotime($mainEvent->startDate)), 'eventtype' => $mainEvent->eventType, 'location' => $mainEvent->location);
    foreach ($results as $result) {
        $events[] = (array) $result;
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $formurl = jg_curpageurl();
    $smarty->assign('nonce', wp_nonce_field('verify_true_eventadd', 'eventadd_nonce_field', true, false));
    $smarty->assign('detailpage', get_permalink($detail));
    $smarty->assign('events', $events);
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 2
0
function jg_front_end_eventdetail($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('list' => 0, 'detail' => 0, 'display' => true, 'submit' => 'page', 'template' => '', 'pagesize' => 25), $atts));
    if (trim($_SESSION['userEnc']) == '' || !isset($_GET['evid'])) {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    $url = $_SERVER['REQUEST_URI'];
    if (trim($template) == '') {
        $template = 'create-event.html';
    }
    $events = array();
    $eventPages = $client->Event->RetrievePages($_GET['evid'], $_GET['page'], $pagesize);
    $eventPages = (array) $eventPages->fundraisingPages;
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $formurl = jg_curpageurl();
    $smarty->assign('nonce', wp_nonce_field('verify_true_eventadd', 'eventadd_nonce_field', true, false));
    $smarty->assign('pages', $eventPages);
    $smarty->assign('detailpage', get_permalink($detail));
    // pageShortName is needed to call the detail
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 3
0
function jgcallback($buffer)
{
    $wpjg_generalSettings = get_option('jg_general_settings');
    if ((int) $wpjg_generalSettings['lolagrove'] == 1) {
        $urlparms = parse_url(jg_curpageurl());
        parse_str($urlparms['query'], $get_array);
        if (isset($get_array['from']) && $get_array['from'] == 'lolagrove') {
            if (session_id() == '' || !isset($_SESSION)) {
                // session isn't started
                session_start();
            }
            $_SESSION['lolagrove'] = json_encode($get_array);
        }
        //error_log(obsafe_print_r($_SESSION,true));
    }
    return str_replace('replacing', 'width', $buffer);
}
Ejemplo n.º 4
0
function jg_front_end_sagepay($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('redirectPaid' => 0, 'display' => true, 'template' => ''), $atts));
    /*
       if ( trim($_SESSION['userEnc']) == '' ){
           $redirectLink = trim(home_url());
           if (intval($redirectLink) != 0)
               $redirectLink = get_permalink($redirectLink);
           else{
               if (!jg_check_missing_http($redirectLink)) $redirectLink = 'http://'. $redirectLink;
           }
           wp_redirect( $redirectLink ); exit;
       }
    */
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 && $result['paidaccess'] == 1) {
        $redirectLink = trim($redirectPaid);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    if (trim($template) == '') {
        $template = 'sagepay.html';
    }
    $crypt = '';
    if (isset($_REQUEST["action"])) {
        require_once JG_PLUGIN_DIR . "/sagepay/sagepay.php";
        $p = new SagePay();
        // paypal class
        $action = $_REQUEST["action"];
        switch ($action) {
            case "process":
                // case process insert the form data in DB and process to the paypal
                $wpdb->update($wpdb->prefix . "jgusers", array('paytoken' => $_POST["invoice"]), array('userEnc' => trim($_SESSION['userEnc'])));
                $this_script = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $p->setSuccessURL($this_script . '?action=success');
                // return URL after the transaction got over
                $p->setFailureURL($this_script . '?action=cancel');
                // cancel URL if the trasaction was cancelled during half of the transaction
                $p->setCurrency($_POST["currency_code"]);
                $p->setDescription($_POST["product_name"]);
                $p->setAmount($wpjg_generalSettings['payamount']);
                $p->setBillingFirstnames($_POST["payer_fname"]);
                $p->setBillingSurname($_POST["payer_lname"]);
                $p->setBillingAddress1($_POST["payer_address"]);
                $p->setBillingCity($_POST["payer_city"]);
                $p->setBillingState($_POST["payer_state"]);
                $p->setBillingCountry($_POST["payer_country"]);
                $p->setBillingPostCode($_POST["payer_zip"]);
                $p->setVendorTxCode($_POST["invoice"]);
                $p->setDeliverySameAsBilling();
                $xml = new DOMDocument();
                $basketNode = $xml->createElement("basket");
                $itemNode = $xml->createElement("item");
                $descriptionNode = $xml->createElement('description');
                $descriptionNode->nodeValue = 'Entry fee';
                $itemNode->appendChild($descriptionNode);
                $quantityNode = $xml->createElement('quantity');
                $quantityNode->nodeValue = $_POST["product_quantity"];
                $itemNode->appendChild($quantityNode);
                $unitNetAmountNode = $xml->createElement('unitNetAmount');
                $unitNetAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($unitNetAmountNode);
                $unitTaxAmountNode = $xml->createElement('unitTaxAmount');
                $unitTaxAmountNode->nodeValue = '0';
                $itemNode->appendChild($unitTaxAmountNode);
                $unitGrossAmountNode = $xml->createElement('unitGrossAmount');
                $unitGrossAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($unitGrossAmountNode);
                $totalGrossAmountNode = $xml->createElement('totalGrossAmount');
                $totalGrossAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($totalGrossAmountNode);
                $basketNode->appendChild($itemNode);
                $xml->appendChild($basketNode);
                $p->setBasketXML($xml->saveHTML());
                $crypt = $sagePay->getCrypt();
                break;
            case "success":
                if ($_REQUEST['crypt']) {
                    $responseArray = $sagePay->decode($_REQUEST['crypt']);
                    //Check status of response
                    if ($responseArray["Status"] === "OK") {
                        $wpdb->update($wpdb->prefix . "jgusers", array('paidaccess' => 1, 'txn_id' => $responseArray["VPSTxId"]), array('paytoken' => trim($_POST["VendorTxCode"])));
                    } elseif ($responseArray["Status"] === "ABORT") {
                        // Payment Cancelled
                    } else {
                        // Payment Failed
                        throw new \Exception($responseArray["StatusDetail"]);
                    }
                    print '<pre>';
                    print_r($responseArray);
                    print '</pre>';
                    exit;
                }
                break;
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    $smarty->assign('Settings', $wpjg_generalSettings);
    $invoice = array('productid' => rand(1111, 99999), 'invoiceid' => date("His") . rand(1234, 9632));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('User', $_SESSION);
    $smarty->assign('Invoice', $invoice);
    $smarty->assign('crypt', $crypt);
    $smarty->assign('vendor', $wpjg_generalSettings['paypal_femail']);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 5
0
function jg_front_end_eventdate($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('list' => 0, 'display' => true, 'submit' => 'page', 'template' => '', 'pagesize' => 25), $atts));
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        echo $redirectLink;
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        //echo $redirectLink; exit;
        wp_redirect($redirectLink);
        exit;
    }
    if (trim($template) == '') {
        $template = 'event-date.html';
    }
    $errors = array();
    if ('POST' == $_SERVER['REQUEST_METHOD'] && wp_verify_nonce($_POST['editdatepage_nonce_field'], 'verify_true_editdate')) {
        include_once JG_PLUGIN_DIR . '/lib/functions.php';
        $results = array('eventstart' => '', 'eventend' => '');
        $rules = array('eventstart' => 'notEmpty', 'eventend' => 'notEmpty');
        $messages = array('eventstart' => 'Please choose your start date', 'eventend' => 'Please enter your end date');
        foreach ($results as $key => $value) {
            $results[$key] = $_POST[$key];
        }
        $errors = validateJGInputs($results, $rules, $messages);
        if (count($errors) != 0) {
            $foundError = true;
        }
        if (!$founderror) {
            $wpdb->update($wpdb->prefix . "jgusers", array('eventstart' => isset($_POST['eventstart']) ? strtotime($_POST['eventstart']) : '', 'eventend' => isset($_POST['eventend']) ? strtotime($_POST['eventend']) : ''), array('userEnc' => trim($_SESSION['userEnc'])));
            $template = 'event-date-thanks.html';
        }
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    $url = $_SERVER['REQUEST_URI'];
    $events = array();
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "'", ARRAY_A);
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $formurl = jg_curpageurl();
    $smarty->assign('nonce', wp_nonce_field('verify_true_eventadd', 'eventadd_nonce_field', true, false));
    $smarty->assign('page', $pageDetails);
    $smarty->assign('donations', $donations);
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('nonce', wp_nonce_field('verify_true_editdate', 'editdatepage_nonce_field', true, false));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 6
0
function jg_front_end_register($atts)
{
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    /* Check if users can register. */
    $registration = get_option('users_can_register');
    extract(shortcode_atts(array('forgot' => 0, 'display' => true, 'redirect' => '', 'submit' => 'page', 'create' => '', 'thanks' => '', 'login' => '', 'template' => ''), $atts));
    $ordate = '';
    $errors = array();
    if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'adduser' && wp_verify_nonce($_POST['register_nonce_field'], 'verify_true_registration') && $_POST['formName'] == 'register') {
        $default_role = get_option('default_role');
        $user_pass = '';
        if (isset($_POST['password'])) {
            $user_pass = esc_attr($_POST['password']);
        }
        $email = '';
        if (isset($_POST['email'])) {
            $email = trim($_POST['email']);
            $_SESSION['email'] = $email;
        }
        $_SESSION['optin'] = isset($_POST['optin']) ? $_POST['optin'] : 0;
        $_SESSION['country'] = isset($_POST['country']) ? $_POST['country'] : '';
        $user_name = jg_generate_random_username($email);
        $first_name = '';
        if (isset($_POST['firstname'])) {
            $first_name = trim($_POST['firstname']);
        }
        $last_name = '';
        if (isset($_POST['lastname'])) {
            $last_name = trim($_POST['lastname']);
        }
        $userdata = array('user_pass' => $user_pass, 'user_login' => esc_attr($user_name), 'first_name' => esc_attr($first_name), 'last_name' => esc_attr($last_name), 'user_email' => esc_attr($email), 'role' => $default_role);
        /*
                if ($_POST['haveaccount'] == 0 &&
             $_POST['createpage'] == 1 &&
             (trim($userdata['user_pass']) == '' ||
              trim($userdata['user_pass']) != trim($_POST['cpassword']))){
        
         $foundError = true;
                }
        */
        include_once JG_PLUGIN_DIR . '/lib/functions.php';
        $results = array('title' => '', 'firstname' => '', 'lastname' => '', 'email' => '', 'address' => '', 'address2' => '', 'town' => '', 'county' => '', 'postcode' => '', 'packpost' => '', 'createpage' => '', 'haveaccount' => '', 'optin' => 0, 'country' => '', 'heardabout' => '', 'password' => '', 'cpassword' => '', 'tsandcs' => '');
        $rules = array('title' => 'notEmpty', 'title_alt' => 'other_title', 'firstname' => 'notEmpty', 'lastname' => 'notEmpty', 'email' => 'email', 'address' => 'notEmpty', 'town' => 'notEmpty', 'postcode' => $_POST['country'] == 'Ireland' ? '' : 'postCode', 'createpage' => 'notEmpty', 'country' => 'ukonly', 'password' => 'length6', 'tsandcs' => 'notEmpty');
        $messages = array('title' => 'Please choose your title', 'firstname' => 'Please enter your first name', 'lastname' => 'Please enter your surname', 'email' => "Hmm. There's something wrong with this address. Please check.", 'address' => 'Please enter your address', 'address2' => 'Please enter your address', 'town' => 'Please enter your town', 'postcode' => 'Please enter your postcode', 'packpost' => 'Would you like a fundraising pack', 'createpage' => 'Would you like to create a fundraising page', 'country' => 'ukonly', 'password' => 'Please enter a password', 'tsandcs' => 'You must accept the terms and conditions');
        foreach ($results as $key => $value) {
            $results[$key] = $_POST[$key];
        }
        $errors = validateJGInputs($results, $rules, $messages);
        if (count($errors) != 0) {
            $foundError = true;
        }
        if ($_POST['country'] != 'United Kingdom' && $_POST['country'] != 'Ireland' && $_POST['createpage'] == 1) {
            $foundError = true;
            $errors['country']['message'] = "We're sorry - you can't create a JustGiving page from this country";
        }
        include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
        $wpjg_generalSettings = get_option('jg_general_settings');
        $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
        //print_R($errors);
        $hasJGAccount = $client->Account->IsEmailRegistered(trim($results['email']));
        if ($hasJGAccount) {
            $errors['email']['message'] = 'A JustGiving account exists for that email address';
            $foundError = true;
        }
        //print_R($errors);
        //print_R($hasJGAccount);
        if (!$foundError) {
            if ((int) $wpjg_generalSettings['lolagrove'] == 1 && isset($_SESSION['lolagrove'])) {
                //from=lolagrove&id=1234.567&sub_id=subid1&callback_id=callbackid1
                $lolagrove = json_decode($_SESSION['lolagrove']);
                $dumpdata = array('id' => $lolagrove->id, 'email' => $results['email'], 'title' => $results['title'] == 'Other' && trim($_POST['other_title']) !== '' ? $_POST['other_title'] : $results['title'], 'firstname' => $results['firstname'], 'lastname' => $results['lastname'], 'address1' => isset($results['address']) ? $results['address'] : '', 'address2' => isset($results['address2']) ? $results['address2'] : '', 'towncity' => isset($results['town']) ? $results['town'] : '', 'postcode' => isset($results['postcode']) ? $results['postcode'] : '', 'timestamp' => date('YmdHis', time()), 'terms' => 'y', 'sub_id' => $lolagrove->sub_id, 'ipaddress' => get_jgip(), 'callback_id' => $lolagrove->callback_id, 'supplier_lead_id' => '', 'securekey' => '1c7c35d9-d962-4f6a-be83-d826d9d8f72f');
                $lurl = 'https://v3.lolagrove.com/data.ashx?';
                $qstring = http_build_query($dumpdata);
                $res = wp_remote_get($lurl . $qstring);
                //error_log('lola = '.$lurl.$qstring);
                //error_log('localret = '.print_R($res, true));
            }
            /*
            	       	https://v3.lolagrove.com/data.ashx?id=12432.2724&email=demo@lolagrove.com&title=Mr&firstname=Robin&lastname=Caller&address1=7 Brayfield Terrace&address2=Barnsbury&towncity=London&postcode=N1 1HZ&timestamp=20101231235959&terms=y&sub_id=abc123&ipaddress=127.0.0.1&callback_id=abc123&supplier_lead_id=xxx&securekey=1c7c35d9-d962-4f6a-be83-d826d9d8f72f
            */
            //print_R($_POST);
            //print_R($userdata);
            //$new_user = wp_insert_user( $userdata );
            unset($_POST['password']);
            unset($_POST['cpassword']);
            unset($_POST['firstname']);
            unset($_POST['lastname']);
            unset($_POST['action']);
            unset($_POST['register_nonce_field']);
            unset($_POST['formName']);
            unset($_POST['submit']);
            unset($_POST['_wp_http_referer']);
            if ($results['country'] == 'Ireland') {
                $results['postcode'] = 'n/a';
            }
            $wpdb->insert($wpdb->prefix . "jgusers", array('title' => $results['title'] == 'Other' && trim($_POST['other_title']) !== '' ? $_POST['other_title'] : $results['title'], 'firstname' => $results['firstname'], 'lastname' => $results['lastname'], 'dob' => $results['dob'], 'email' => $results['email'], 'address' => isset($results['address']) ? $results['address'] : '', 'address2' => isset($results['address2']) ? $results['address2'] : '', 'towncity' => isset($results['town']) ? $results['town'] : '', 'county' => isset($results['county']) ? $results['county'] : '', 'postcode' => isset($results['postcode']) ? $results['postcode'] : '', 'packbypost' => isset($results['packpost']) ? $results['packpost'] : '', 'cpage' => isset($results['createpage']) ? $results['createpage'] : '', 'hasaccount' => isset($results['haveaccount']) ? $results['haveaccount'] : '', 'userEnc' => base64_encode($results['email'] . ':' . trim($userdata['user_pass'])), 'pageurl' => '', 'signupdate' => time(), 'eventstart' => isset($_POST['eventstart']) ? strtotime($_POST['eventstart']) : '', 'eventend' => isset($_POST['eventend']) ? strtotime($_POST['eventend']) : '', 'optin' => isset($results['optin']) ? $results['optin'] : 0, 'country' => isset($results['country']) ? $results['country'] : '', 'heardabout' => isset($results['heardabout']) ? $results['heardabout'] : '', 'tsandcs' => $_POST['tandcs']));
            if ($hasJGAccount) {
                /* if login JG change password */
                if ($_POST['createpage'] == 1) {
                    //create a page
                    $_SESSION['email'] = trim($results['email']);
                    $_SESSION['userEnc'] = base64_encode($results['email'] . ':' . trim($userdata['user_pass']));
                    $redirectLink = trim($login);
                    if (intval($redirectLink) != 0) {
                        $redirectLink = get_permalink($redirectLink);
                    } else {
                        if (!jg_check_missing_http($redirectLink)) {
                            $redirectLink = 'http://' . $redirectLink;
                        }
                    }
                    wp_redirect($redirectLink);
                    exit;
                } elseif (intval(trim($redirect)) != 0) {
                    $redirectLink = get_permalink($redirect);
                    wp_redirect($redirectLink);
                    exit;
                } else {
                    // -> send stright to thanks - send email
                    $redirectLink = trim($thanks);
                    if (intval($redirectLink) != 0) {
                        $redirectLink = get_permalink($redirectLink);
                    } else {
                        if (!jg_check_missing_http($redirectLink)) {
                            $redirectLink = 'http://' . $redirectLink;
                        }
                    }
                    wp_redirect($redirectLink);
                    $vars = array('firstname' => $results['firstname']);
                    sendthanks($results['email'], $results['firstname'] . ' ' . $results['lastname'], $vars, 0);
                    exit;
                }
            } else {
                error_log('register 293 ' . print_R($_POST, true));
                error_log('register 293 ' . print_R($userdata, true));
                if ($_POST['haveaccount'] == 0 && trim($userdata['user_pass']) != '') {
                    //include_once(JG_PLUGIN_DIR.'/lib/ApiClients/Model/CreateAccountRequest.php');
                    $request = array();
                    $request['email'] = trim($results['email']);
                    $request['firstName'] = $results['firstname'];
                    $request['lastName'] = $results['lastname'];
                    $request['password'] = trim($userdata['user_pass']);
                    $request['title'] = $results['title'] == 'Other' && trim($_POST['other_title']) !== '' ? $_POST['other_title'] : $results['title'];
                    $request['address']['line1'] = trim($results['address']);
                    $request['address']['line2'] = trim($results['address2']);
                    $request['address']['countyOrState'] = trim($results['county']);
                    $request['address']['townOrCity'] = trim($results['town']);
                    $request['address']['postcodeOrZipcode'] = trim($results['postcode']);
                    $request['address']['country'] = trim($results['country']);
                    $request['acceptTermsAndConditions'] = true;
                    //error_log(print_R($request, true));
                    $response = $client->Account->Create($request);
                    //$current = print_R($_POST, true);
                    //file_put_contents('curldata.txt', $current, FILE_APPEND);
                    $ret = $client->Account->GetUser(base64_encode($request['email'] . ':' . $request['password']));
                    error_log('getuser register 315 ' . print_R($ret, true));
                    if ($ret) {
                        $wpdb->update($wpdb->prefix . "jgusers", array('userid' => intval($ret->accountId)), array('email' => $request['email']));
                    }
                    if ($_POST['createpage'] == 1) {
                        $_SESSION['email'] = trim($results['email']);
                        $_SESSION['userEnc'] = base64_encode($results['email'] . ':' . trim($userdata['user_pass']));
                        //create a page
                        $redirectLink = trim($create);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        //echo 'goto' .$redirectLink;
                        //$current = print_R('goto a' .$redirectLink, true);
                        //file_put_contents('curldata.txt', $current, FILE_APPEND);
                        wp_redirect($redirectLink);
                        exit;
                    } else {
                        //echo $thanks;
                        // -> send stright to thanks - send email
                        $redirectLink = trim($thanks);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        //$current = print_R('goto b' .$redirectLink, true);
                        //file_put_contents('curldata.txt', $current, FILE_APPEND);
                        $vars = array('firstname' => $results['firstname']);
                        sendthanks($results['email'], $results['firstname'] . ' ' . $results['lastname'], $vars, 0);
                        wp_redirect($redirectLink);
                        exit;
                    }
                } else {
                    if ($_POST['createpage'] == 1) {
                        $_SESSION['email'] = trim($results['email']);
                        //login with the account you said you had
                        // even though you don't have an account on this email
                        // cos we'd have found it by now
                        $redirectLink = trim($login);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        //$current = print_R('goto c' .$redirectLink, true);
                        //file_put_contents('curldata.txt', $current, FILE_APPEND);
                        wp_redirect($redirectLink);
                        exit;
                    } else {
                        //echo 'meh';
                        //echo $thanks;
                        /* what to do if login is incorrect but wanted to create a page ?*/
                        // -> send stright to thanks
                        //echo $thanks;
                        $redirectLink = trim($thanks);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        //echo $redirectLink;
                        $vars = array('firstname' => $results['firstname']);
                        sendthanks($results['email'], $results['firstname'] . ' ' . $results['lastname'], $vars, 0);
                        //$current = print_R('goto d' .$redirectLink, true);
                        //file_put_contents('curldata.txt', $current, FILE_APPEND);
                        wp_redirect($redirectLink);
                        exit;
                    }
                }
            }
            $redirectLink = trim($redirect);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
            wp_redirect($redirectLink);
            exit;
        }
    }
    // if ( $registration || current_user_can( 'create_users' ) ) :
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword']);
    $countries = get_transient('justgiving_countries');
    if (DEBUG) {
        $countries = NULL;
    }
    if (!$countries) {
        $countries = $client->Country->GetCountries();
    }
    //print_r($countries);
    if (!DEBUG) {
        set_transient('justgiving_countries', $countries, 60 * 60 * 12);
        // 1/2 day storage
    }
    include_once JG_PLUGIN_DIR . '/lib/functions.php';
    if (!isset($_POST['country']) || $_POST['country'] == '') {
        $_POST['country'] = "United Kingdom";
    }
    $smarty->assign('countries', $countries);
    $smarty->assign('maxdate', date('Y-m-d'));
    if (isset($_POST['dob'])) {
        $_POST['dob'] = $ordate;
    }
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('nonce', wp_nonce_field('verify_true_registration', 'register_nonce_field', true, false));
    $smarty->assign('home', get_home_url());
    $smarty->assign('settings', $wpjg_generalSettings);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('register.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 7
0
function jg_front_end_login($atts)
{
    $loginFilterArray = array();
    ob_start();
    global $wpjg_login;
    $wpjg_generalSettings = get_option('jg_general_settings');
    extract(shortcode_atts(array('forgot' => 0, 'display' => true, 'redirect' => '', 'register' => 0, 'create' => 0, 'choose' => 0, 'submit' => 'page', 'template' => ''), $atts));
    $passworderror = '';
    $usernameerror = '';
    //echo $permaLnk2;
    if (isset($_SESSION['userEnc'])) {
        // Successful login
        $permaLnk2 = jg_curpageurl();
        if (trim($redirect) != '') {
            $permaLnk2 = trim($redirect);
            if (intval($permaLnk2) != 0) {
                $permaLnk2 = get_permalink($permaLnk2);
            } else {
                if (!jg_check_missing_http($permaLnk2)) {
                    $permaLnk2 = 'http://' . $permaLnk2;
                }
            }
        } elseif (trim($create) != '') {
            $permaLnk2 = trim($create);
            if (intval($permaLnk2) != 0) {
                $permaLnk2 = get_permalink($permaLnk2);
            } else {
                if (!jg_check_missing_http($permaLnk2)) {
                    $permaLnk2 = 'http://' . $permaLnk2;
                }
            }
        }
        wp_redirect($permaLnk2);
        exit;
    } else {
        // Not logged in
        if (!empty($_POST['action']) && isset($_POST['formName'])) {
            if ($_POST['formName'] == 'login') {
                if (trim($_POST['user-name']) == '') {
                    if (isset($wpjg_generalSettings['loginWith']) && $wpjg_generalSettings['loginWith'] == 'email') {
                        $loginFilterArray['emptyUsernameError'] = __('The email field is empty', 'justgiving') . '.';
                        $loginFilterArray['emptyUsernameError'] = apply_filters('wpjg_login_empty_email_as_username_error_message', $loginFilterArray['emptyUsernameError']);
                    } else {
                        $loginFilterArray['emptyUsernameError'] = __('The username field is empty', 'justgiving') . '.';
                        $loginFilterArray['emptyUsernameError'] = apply_filters('wpjg_login_empty_username_error_message', $loginFilterArray['emptyUsernameError']);
                    }
                    $usernameerror = $loginFilterArray['emptyUsernameError'];
                } elseif (trim($_POST['password']) == '') {
                    $loginFilterArray['emptyPasswordError'] = __('The password field is empty', 'justgiving') . '.';
                    $loginFilterArray['emptyPasswordError'] = apply_filters('wpjg_login_empty_password_error_message', $loginFilterArray['emptyPasswordError']);
                    $passworderror = $loginFilterArray['emptyPasswordError'];
                }
                if (is_wp_error($wpjg_login)) {
                    $loginFilterArray['wpError'] = 'Incorrect password';
                    $loginFilterArray['wpError'] = apply_filters('wpjg_login_wp_error_message', $loginFilterArray['wpError'], $wpjg_login);
                    $passworderror = $loginFilterArray['wpError'];
                }
            }
        }
        /* use this action hook to add extra content before the login form. */
        do_action('wppb_before_login');
        global $vars;
        $vars = array();
        $forgotURL = '';
        if (trim($forgot) != '' && intval($forgot) > 0) {
            $forgoturi = true;
            $forgotURL = get_permalink($forgot);
        }
        $chooseURL = '';
        if (trim($choose) != '' && intval($choose) > 0) {
            $chooseuri = true;
            $chooseURL = get_permalink($choose);
        }
        require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
        $smarty = new Smarty();
        $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
        $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
        $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
        $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
        //print_R($_POST);
        if (isset($_POST['user-name'])) {
            $smarty->assign('userName', esc_html($_POST['user-name']));
        } else {
            $smarty->assign('userName', '');
        }
        $formurl = jg_curpageurl();
        $smarty->assign('pageshortname', isset($_POST['pageshortname']) ? stripslashes($_POST['pageshortname']) : '');
        $smarty->assign('passworderror', $passworderror);
        $smarty->assign('usernameerror', $usernameerror);
        $smarty->assign('submit', 'page');
        $smarty->assign('pagetitle', isset($_POST['pagetitle']) ? stripslashes($_POST['pagetitle']) : '');
        $smarty->assign('errorpagetitle', isset($errors['pagetitle']) ? $errors['pagetitle']['message'] : '');
        $smarty->assign('nonce', wp_nonce_field('verify_true_login', 'login_nonce_field', true, false));
        $smarty->assign('jgoptinyes', isset($_POST['jgoptin']) && $_POST['jgoptin'] == '1' || !isset($_REQUEST['jgoptin']) ? 'checked="checked"' : '');
        $smarty->assign('jgoptinno', isset($_POST['jgoptin']) && $_POST['jgoptin'] == '0' ? 'checked="checked"' : '');
        $smarty->assign('choptinyes', isset($_POST['charityoptin']) && $_POST['charityoptin'] == '1' || isset($_SESSION['optin']) && $_SESSION['optin'] == 1 && $_POST['charityoptin'] != 0 || !isset($_REQUEST['charityoptin']) && (!isset($_SESSION['optin']) || $_SESSION['optin'] != 0) ? 'checked="checked"' : '');
        $smarty->assign('choptinno', isset($_POST['charityoptin']) && $_POST['charityoptin'] == '0' ? 'checked="checked"' : '');
        $smarty->assign('formurl', $formurl);
        $smarty->assign('forgotURL', $forgotURL);
        $smarty->assign('chooseURL', $chooseURL);
        $smarty->assign('settings', $wpjg_generalSettings);
        if ($template != '') {
            $smarty->display($template);
        } else {
            $smarty->display('login-page.html');
        }
    }
    /* use this action hook to add extra content after the login form. */
    do_action('wppb_after_login');
    $output = ob_get_contents();
    ob_end_clean();
    $loginFilterArray = apply_filters('wpjg_login', $loginFilterArray);
    return $output;
}
Ejemplo n.º 8
0
function jg_front_end_view_user($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('forgot' => 0, 'display' => true, 'redirect' => '', 'teampage' => '', 'submit' => 'page', 'create' => '', 'thanks' => '', 'template' => ''), $atts));
    if (!isset($_SESSION['userEnc']) || trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        //echo $redirectLink ;
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    $user = $client->Account->GetUser(trim($_SESSION['userEnc']));
    $pages = '';
    $teams = '';
    $events = '';
    if ($user) {
        //print_R($user);
        $userRows = $wpdb->get_row(" SELECT * FROM {$wpdb->prefix}jgusers WHERE `email`='{$user->email}';", ARRAY_A);
        //print_R($userRows);
        $pages = $client->Page->ListAll(trim($_SESSION['userEnc']));
        $teams = $client->Team->Search();
        $pagecount = 0;
        foreach ($pages as $page) {
            //print_R($page);
            if ($page->charityId == $wpjg_generalSettings['Charity']) {
                if (strlen(trim($wpjg_generalSettings['Event'])) > 0 && $page->eventId == $wpjg_generalSettings['Event']) {
                    $pagecount++;
                    if (!$teams) {
                        $uniqueId = uniqid();
                        $request = array();
                        $request['teamShortName'] = "team" . $uniqueId;
                        $request['name'] = "team" . $uniqueId;
                        $request['story'] = "story" . $uniqueId;
                        $request['targetType'] = "Aggregate";
                        $request['teamType'] = "ByInvitationOnly";
                        $request['teamMembers'] = array(array('pageShortName' => $page->pageShortName));
                        $response = $client->Team->Create($request, trim($_SESSION['userEnc']));
                        if ($response == 1) {
                            $teams = $client->Team->Get($request['teamShortName']);
                        }
                    }
                }
            }
        }
        $eventRows = $wpdb->get_results(" SELECT * FROM {$wpdb->prefix}jgevents WHERE `owner`='{$userRows['id']}';", ARRAY_A);
        foreach ($eventRows as $eventRow) {
            $events[] = $client->Event->Retrieve($eventRows['jgeventid']);
        }
        require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
        $smarty = new Smarty();
        $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
        $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
        $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
        $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
        $formurl = jg_curpageurl();
        $smarty->assign('settings', $wpjg_generalSettings);
        $smarty->assign('formurl', $formurl);
        $smarty->assign('user', $user);
        $smarty->assign('pages', $pages);
        $smarty->assign('teams', $teams);
        $smarty->assign('events', $events);
        if ($template != '') {
            $smarty->display($template);
        } else {
            $smarty->display('viewuser.html');
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 9
0
function jg_front_end_paypal($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('redirectPaid' => 0, 'display' => true, 'template' => ''), $atts));
    /*
       if ( trim($_SESSION['userEnc']) == '' ){
           $redirectLink = trim(home_url());
           if (intval($redirectLink) != 0)
               $redirectLink = get_permalink($redirectLink);
           else{
               if (!jg_check_missing_http($redirectLink)) $redirectLink = 'http://'. $redirectLink;
           }
           wp_redirect( $redirectLink ); exit;
       }
    */
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 && $result['paidaccess'] == 1) {
        $redirectLink = trim($redirectPaid);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    if (isset($_REQUEST["action"])) {
        require_once JG_PLUGIN_DIR . "/paypal/paypal_class.php";
        $p = new paypal_class();
        // paypal class
        $p->admin_mail = $wpjg_generalSettings['paypal_email'];
        // set notification email
        $action = $_REQUEST["action"];
        switch ($action) {
            case "process":
                // case process insert the form data in DB and process to the paypal
                $wpdb->update($wpdb->prefix . "jgusers", array('paytoken' => $_POST["invoice"]), array('userEnc' => trim($_SESSION['userEnc'])));
                $this_script = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $p->add_field('business', $wpjg_generalSettings['paypal_femail']);
                // Call the facilitator eaccount
                $p->add_field('cmd', $_POST["cmd"]);
                // cmd should be _cart for cart checkout
                $p->add_field('upload', '1');
                $p->add_field('return', $this_script . '?action=success');
                // return URL after the transaction got over
                $p->add_field('cancel_return', $this_script . '?action=cancel');
                // cancel URL if the trasaction was cancelled during half of the transaction
                $p->add_field('notify_url', $this_script . '?action=ipn');
                // Notify URL which received IPN (Instant Payment Notification)
                $p->add_field('currency_code', $_POST["currency_code"]);
                $p->add_field('invoice', $_POST["invoice"]);
                $p->add_field('item_name_1', $_POST["product_name"]);
                $p->add_field('item_number_1', $_POST["product_id"]);
                $p->add_field('quantity_1', $_POST["product_quantity"]);
                $p->add_field('amount_1', $wpjg_generalSettings['payamount']);
                $p->add_field('first_name', $_POST["payer_fname"]);
                $p->add_field('last_name', $_POST["payer_lname"]);
                $p->add_field('address1', $_POST["payer_address"]);
                $p->add_field('city', $_POST["payer_city"]);
                $p->add_field('state', $_POST["payer_state"]);
                $p->add_field('country', $_POST["payer_country"]);
                $p->add_field('zip', $_POST["payer_zip"]);
                $p->add_field('email', $_POST["payer_email"]);
                $p->submit_paypal_post();
                // POST it to paypal
                break;
            case "success":
                $redirectLink = trim($redirectPaid);
                if (intval($redirectLink) != 0) {
                    $redirectLink = get_permalink($redirectLink);
                } else {
                    if (!jg_check_missing_http($redirectLink)) {
                        $redirectLink = 'http://' . $redirectLink;
                    }
                }
                wp_redirect($redirectLink);
                exit;
                break;
            case "ipn":
                if ($p->validate_ipn()) {
                    $wpdb->update($wpdb->prefix . "jgusers", array('paidaccess' => 1, 'txn_id' => $_POST["txn_id"]), array('paytoken' => trim($_POST["invoice"])));
                }
                break;
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    $smarty->assign('Settings', $wpjg_generalSettings);
    $invoice = array('productid' => rand(1111, 99999), 'invoiceid' => date("His") . rand(1234, 9632));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('User', $_SESSION);
    $smarty->assign('Invoice', $invoice);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('paypal.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 10
0
function jg_front_end_stripe($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('redirectpaid' => 0, 'display' => true, 'template' => ''), $atts));
    /*
       if ( trim($_SESSION['userEnc']) == '' ){
           $redirectLink = trim(home_url());
           if (intval($redirectLink) != 0)
               $redirectLink = get_permalink($redirectLink);
           else{
               if (!jg_check_missing_http($redirectLink))
                   $redirectLink = 'http://'. $redirectLink;
           }
           wp_redirect( $redirectLink ); exit;
       }
    */
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 && intval($result['paidaccess']) == 1 && intval($redirectpaid) != 0) {
        $redirectLink = trim($redirectpaid);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    $success = '';
    if (isset($_REQUEST["currency_code"])) {
        require_once JG_PLUGIN_DIR . "/stripe/init.php";
        \Stripe\Stripe::setApiKey($wpjg_generalSettings['stripe_key']);
        try {
            if (!isset($_POST['stripeToken'])) {
                throw new Exception("The Stripe Token was not generated correctly");
            }
            // Create a Customer
            $customer = \Stripe\Customer::create(array("source" => $_POST["stripeToken"], "email" => strip_tags(trim($result['email'])), "description" => $result['firstname'] . ' ' . $result['lastname']));
            $charge = \Stripe\Charge::create(array("amount" => $wpjg_generalSettings['payamount'] * 100, "currency" => $_POST["currency_code"], "description" => "Entry fee", "customer" => $customer->id));
            //error_log(print_R($charge->__toJSON(), true));
            $ch_data = json_decode($charge->__toJSON());
            //error_log(print_R($ch_data, true));
            $wpdb->update($wpdb->prefix . "jgusers", array('paidaccess' => 1, 'txn_id' => $ch_data->balance_transaction), array('userEnc' => trim($_SESSION['userEnc'])));
            $success = 'Your payment was successful.';
            if (trim($redirectpaid) != '' && intval($redirectpaid) != 0) {
                $redirectLink = trim($redirectpaid);
                if (intval($redirectLink) != 0) {
                    $redirectLink = get_permalink($redirectLink);
                } else {
                    if (!jg_check_missing_http($redirectLink)) {
                        $redirectLink = 'http://' . $redirectLink;
                    }
                }
                wp_redirect($redirectLink);
                exit;
            }
        } catch (Exception $e) {
            $errors = $e->getMessage();
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    $smarty->assign('Settings', $wpjg_generalSettings);
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('User', $_SESSION);
    $smarty->assign('UserD', $result);
    $smarty->assign('success', $success);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('stripe.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 11
0
function jg_front_end_pagecomplete($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('list' => 0, 'display' => true, 'submit' => 'page', 'template' => '', 'pagesize' => 25), $atts));
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        echo $redirectLink;
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        //echo $redirectLink; exit;
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    $url = $_SERVER['REQUEST_URI'];
    if (trim($template) == '') {
        $template = 'page-complete.html';
    }
    $events = array();
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "'", ARRAY_A);
    $bits = parse_url($result['pageurl']);
    $pageDetails = $client->Page->Retrieve(ltrim($bits['path'], '/'));
    $donations = $client->Page->RetrieveDonationsForPage(ltrim($bits['path'], '/'), $pagesize, $_GET['page']);
    $totalDonations = floatval($donations['totalRaisedOffline']) + floatval($donations['totalRaisedOnline']) + floatval($donations['totalRaisedSms']);
    $donations['total'] = $totalDonations;
    //print_r($donations);exit;
    if ($totalDonations < floatval($wpjg_generalSettings['targetAmount'])) {
        $template = 'page-notcomplete.html';
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $formurl = jg_curpageurl();
    $smarty->assign('nonce', wp_nonce_field('verify_true_eventadd', 'eventadd_nonce_field', true, false));
    $smarty->assign('page', $pageDetails);
    $smarty->assign('donations', $donations);
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 12
0
function jg_front_end_eventadd($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    wp_enqueue_script('modernizr', '//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js', 'jquery', false);
    wp_enqueue_script('yepnope', 'https://cdnjs.cloudflare.com/ajax/libs/yepnope/1.5.4/yepnope.min.js', 'jquery', true);
    wp_register_script('justgiving-gaddress', 'https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places', false, null, true);
    wp_enqueue_script('justgiving-gaddress');
    wp_enqueue_script('justgiving-gplacej', JG_PLUGIN_URL . '/js/geocode.js', array('jquery', 'justgiving-gaddress'), '1', true);
    wp_enqueue_script('justgiving-gplace', JG_PLUGIN_URL . '/js/googleaddress.js', array('jquery', 'justgiving-gplacej'), '1', true);
    extract(shortcode_atts(array('paid' => 0, 'display' => true, 'redirect' => '', 'thanks' => 0, 'submit' => 'page', 'template' => ''), $atts));
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (!isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 || $result['paidaccess'] == 0 && $wpjg_generalSettings['paidaccess'] == 1) {
        $redirectLink = trim($paid);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword'], true);
    if (trim($template) == '') {
        $template = 'create-event.html';
    }
    //error_log(print_R($_POST, true));
    if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'eventadd' && wp_verify_nonce($_POST['eventadd_nonce_field'], 'verify_true_eventadd') && $_POST['formName'] == 'eventadd') {
        include_once JG_PLUGIN_DIR . '/lib/functions.php';
        $results = array('eventname' => '', 'description' => '', 'eventend' => '', 'eventstart' => '', 'eventtype' => '', 'eventlocn' => '');
        $rules = array('eventname' => 'notEmpty', 'description' => 'notEmpty', 'eventend' => 'notEmpty', 'eventstart' => 'notEmpty', 'eventtype' => 'notEmpty');
        date_default_timezone_set("UTC");
        $_POST['eventend'] = strtotime($_POST['eventend-date'] . ' ' . $_POST['eventend-time']);
        $_POST['eventstart'] = strtotime($_POST['eventstart-date'] . ' ' . $_POST['eventstart-time']);
        //error_log(print_R($_POST, true));
        $messages = array('eventname' => 'Please enter your event name', 'description' => 'Please enter your event description', 'eventend' => 'Please choose your event end date', 'eventstart' => 'Please choose your event start date', 'eventtype' => 'Please choose your event type');
        foreach ($results as $key => $value) {
            $results[$key] = $_POST[$key];
        }
        //error_log(print_R($errors, true));
        $foundError = false;
        $errors = validateJGInputs($results, $rules, $messages);
        if (count($errors) != 0) {
            $foundError = true;
        }
        if (!$founderror) {
            //error_log('here');
            $newEvent = array("name" => $results['eventname'], "description" => $results['eventdescr'], "completionDate" => gmdate("Y-m-d\\TH:i:s", $results['eventend'] + date("Z", $results['eventend'])), "expiryDate" => gmdate("Y-m-d\\TH:i:s", strtotime("+1 day", $results['eventend'])), "startDate" => gmdate("Y-m-d\\TH:i:s", $results['eventstart'] + date("Z", $results['eventstart'])), "eventType" => $results['eventtype'], "location" => $results['eventlocn']);
            $user = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "'  ORDER BY id DESC LIMIT 1");
            //error_log(print_R($user, true));
            $uid = 0;
            if (count($user) > 0) {
                $event = $client->Event->Create($newEvent);
                //error_log(print_R($event, true));
                if (!$event) {
                    $errors['eventname']['message'] = 'Could not create event at JustGiving';
                } else {
                    $wpdb->insert($wpdb->prefix . "jgevents", array('owner' => $user->id, 'jgeventid' => $event->id, 'eventname' => $results['eventname'], 'eventdescr' => $results['eventdescr'], 'eventcomplete' => date('d-m-Y H:i', $results['eventend']), 'eventexpiry' => date('d-m-Y H:i', strtotime("+1 day", $results['eventend'])), 'eventstart' => date('d-m-Y H:i', $results['eventstart']), 'eventtype' => $results['eventtype'], 'location' => $results['eventlocn'], 'street_number' => $_POST['street_number'], 'street_name' => $_POST['street_name'], 'city' => $_POST['city'], 'state' => $_POST['administrative_area_level_1'], 'postcode' => $_POST['postcode'], 'country' => $_POST['country'], 'lat' => $_POST['lat'], 'lng' => $_POST['lng'], 'submittedtime' => date('Y-m-d G:i:s'), 'lastmodified' => date('Y-m-d G:i:s')));
                    //$cntent  = print_R($wpdb->queries , true);
                    //file_put_contents( '/var/www/html/doe/doe_error.log' , $cntent, FILE_APPEND );
                    $uid = $result['id'];
                    if (trim($redirect) !== '') {
                        $redirectLink = trim($redirect);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    } else {
                        $redirectLink = trim($thanks);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    }
                }
            }
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $formurl = jg_curpageurl();
    $eventtypes = array();
    $row = $wpdb->get_row("SHOW COLUMNS FROM {$wpdb->prefix}jgevents WHERE field='eventtype'");
    //print_R($row);
    preg_match_all("/'(.*?)'/", $row->Type, $categories);
    //print_R($categories);
    foreach ($categories[1] as $k) {
        preg_match_all('/((?:^|[A-Z])[a-z]+)/', $k, $matches);
        $eventtypes[$k] = implode(' ', $matches[1]);
    }
    $smarty->assign('nonce', wp_nonce_field('verify_true_eventadd', 'eventadd_nonce_field', true, false));
    $smarty->assign('eventtypes', $eventtypes);
    $smarty->assign('formurl', $formurl);
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('suggestions', $suggestions);
    $data = array();
    for ($i = date('Y') - 18; $i >= date('Y') - 98; $i--) {
        $data[] = $i;
    }
    $smarty->assign('years', $data);
    $smarty->assign('maxdate', date('Y'));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    //print_R($_SESSION);
    //print_R($eventtypes);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 13
0
function jg_front_end_choose($atts)
{
    $loginFilterArray = array();
    ob_start();
    global $wpjg_login;
    $wpjg_generalSettings = get_option('jg_general_settings');
    extract(shortcode_atts(array('login' => 0, 'register' => 0, 'submit' => 'page', 'template' => ''), $atts));
    // Not logged in
    if (!empty($_POST['action']) && isset($_POST['formName'])) {
        switch ($_POST['choose']) {
            case 'login':
                $redirectLink = trim($login);
                if (intval($redirectLink) != 0) {
                    $redirectLink = get_permalink($redirectLink);
                } else {
                    if (!jg_check_missing_http($redirectLink)) {
                        $redirectLink = 'http://' . $redirectLink;
                    }
                }
                wp_redirect($redirectLink);
                exit;
                break;
            case 'register':
                $redirectLink = trim($register);
                if (intval($redirectLink) != 0) {
                    $redirectLink = get_permalink($redirectLink);
                } else {
                    if (!jg_check_missing_http($redirectLink)) {
                        $redirectLink = 'http://' . $redirectLink;
                    }
                }
                wp_redirect($redirectLink);
                exit;
                break;
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    //print_R($_POST);
    if (isset($_POST['user-name'])) {
        $smarty->assign('userName', esc_html($_POST['user-name']));
    } else {
        $smarty->assign('userName', '');
    }
    $formurl = jg_curpageurl();
    $smarty->assign('pageshortname', isset($_POST['pageshortname']) ? stripslashes($_POST['pageshortname']) : '');
    $smarty->assign('submit', 'page');
    $smarty->assign('pagetitle', isset($_POST['pagetitle']) ? stripslashes($_POST['pagetitle']) : '');
    $smarty->assign('errorpagetitle', isset($errors['pagetitle']) ? $errors['pagetitle']['message'] : '');
    $smarty->assign('nonce', wp_nonce_field('verify_true_login', 'login_nonce_field', true, false));
    $smarty->assign('formurl', $formurl);
    $smarty->assign('forgotURL', $forgotURL);
    $smarty->assign('settings', $wpjg_generalSettings);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('account-choose.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 14
0
function jg_front_end_justgiving($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('redirectpaid' => 0, 'display' => true, 'template' => '', 'loggedin' => true, 'pageurl' => ''), $atts));
    if ($loggedin && trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim(home_url());
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = array();
    if ($loggedin) {
        $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
        if (isset($result['paidaccess']) && $result['paidaccess'] == 1) {
            $redirectLink = trim($redirectpaid);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
            //echo $redirectLink;
            wp_redirect($redirectLink);
            exit;
        }
        if (!isset($result['pageurl']) || $result['pageurl'] == 0) {
            $redirectLink = trim($redirectpaid);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
            //echo $redirectLink;
            wp_redirect($redirectLink);
            exit;
        }
    } else {
        $result['pageurl'] = $pageurl;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword']);
    //http://v3-sandbox.justgiving.com/test2964
    //echo $pageShortName ;
    //exit;
    //print_r($_REQUEST);
    if (isset($_REQUEST["action"])) {
        $action = $_REQUEST["action"];
        switch ($action) {
            case "process":
                // case process insert the form data in DB and process to the paypal
                $pageShortName = trim(parse_url($result['pageurl'], PHP_URL_PATH), "/");
                if ($client->Page->IsShortNameRegistered($pageShortName) != 200) {
                    //no page or page is rubbish
                    $redirectLink = trim(home_url());
                    if (intval($redirectLink) != 0) {
                        $redirectLink = get_permalink($redirectLink);
                    } else {
                        if (!jg_check_missing_http($redirectLink)) {
                            $redirectLink = 'http://' . $redirectLink;
                        }
                    }
                    wp_redirect($redirectLink);
                    exit;
                }
                if ($loggedin) {
                    $wpdb->update($wpdb->prefix . "jgusers", array('paytoken' => $_POST["invoice"]), array('userEnc' => trim($_SESSION['userEnc'])));
                }
                $this_script = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $this_scriptq = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $extref = 'urteam-' . rand(1234, 9632) . '-' . time();
                if ($loggedin) {
                    $wpdb->insert($wpdb->prefix . "jgjustgiving", array('owner' => $result['id'], 'reference' => $_POST["invoice"], 'extref' => $extref, 'amount' => $_POST["product_amount"], 'submittedtime' => date('Y-m-d H:i:s')));
                }
                if (get_option('permalink_structure') != '') {
                    $jgurl = $result['pageurl'] . "/4w350m3/donate/?amount=" . $_POST["product_amount"] . "&reference=" . $_POST["invoice"] . "&exitUrl=" . urlencode($this_script . '?action=ipn&shrtref=' . $extref . '&donationId=JUSTGIVING-DONATION-ID');
                } else {
                    $jgurl = $result['pageurl'] . "/4w350m3/donate/?amount=" . $_POST["product_amount"] . "&reference=" . $_POST["invoice"] . "&exitUrl=" . urlencode($this_scriptq . '&action=ipn&shrtref=' . $extref . '&donationId=JUSTGIVING-DONATION-ID');
                }
                wp_redirect($jgurl);
                exit;
                break;
            case "ipn":
                $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgjustgiving WHERE `extref`='" . trim($_REQUEST['shrtref']) . "';", ARRAY_A);
                if (isset($result['id'])) {
                    $donation = $client->Donation->RetrieveStatus($_REQUEST['donationId']);
                    //$donation = $client->Donation->Retrieve($_REQUEST['donationId'], trim($_SESSION['userEnc']) );
                    if ($donation && $donation->donationId !== Null) {
                        // money in here
                        if (trim($donation->status) == 'Accepted' || trim($donation->status) == 'Pending') {
                            if ($donation->ref !== null) {
                                $wpdb->update($wpdb->prefix . "jgjustgiving", array('paid' => 1, 'txn_id' => $donation->donationId), array('id' => $result['id'], 'reference' => $donation->ref));
                            } else {
                                $wpdb->update($wpdb->prefix . "jgjustgiving", array('paid' => 1, 'txn_id' => $donation->donationId), array('id' => $result['id']));
                            }
                            $wpdb->update($wpdb->prefix . "jgusers", array('paidaccess' => 1), array('userEnc' => trim($_SESSION['userEnc'])));
                            $redirectLink = trim($redirectPaid);
                            if (intval($redirectLink) != 0) {
                                $redirectLink = get_permalink($redirectLink);
                            } else {
                                if (!jg_check_missing_http($redirectLink)) {
                                    $redirectLink = 'http://' . $redirectLink;
                                }
                            }
                            wp_redirect($redirectLink);
                            exit;
                        }
                    } else {
                        //redirect to failure page ?
                    }
                } elseif (!$loggedin) {
                    $donation = $client->Donation->RetrieveStatus($_REQUEST['donationId']);
                    if ($donation && $donation->donationId !== Null) {
                        $redirectLink = trim($redirectPaid);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        wp_redirect($redirectLink);
                        exit;
                    }
                }
                break;
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    $smarty->assign('Settings', $wpjg_generalSettings);
    $invoice = array('invoiceid' => date("His") . rand(1234, 9632) . '-' . time());
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('User', $_SESSION);
    $smarty->assign('Invoice', $invoice);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('justgiving.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Ejemplo n.º 15
0
function jg_front_end_create_page($atts)
{
    wp_enqueue_script('jg_pagesearch', JG_PLUGIN_URL . '/js/jgacsearch.js', array('jquery', 'jquery-ui-autocomplete'), '1', true);
    wp_localize_script('jg_pagesearch', 'JGSearch', array('url' => admin_url('admin-ajax.php')));
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('paid' => 0, 'forgot' => 0, 'logout' => 0, 'display' => true, 'redirect' => '', 'teampage' => '', 'submit' => 'page', 'create' => '', 'thanks' => '', 'advocate' => '', 'template' => ''), $atts));
    $user = '';
    $pass = '';
    $errors = array();
    //print_r($_SESSION);
    if (trim($_SESSION['userEnc']) == '') {
        $redirectLink = trim($forgot);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (trim($result['pageurl']) != '' && intval(trim($result['pageurl'])) != 0) {
        if (!isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 || $result['paidaccess'] == 0 && $wpjg_generalSettings['paidaccess'] == 1) {
            $redirectLink = trim($paid);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
        } elseif (trim($teampage) !== '') {
            $redirectLink = trim($teampage);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
            $redirectLink = parse_url($redirectLink, PHP_URL_QUERY) ? $redirectLink . '&team=' . $_POST['jointeam'] : rtrim($redirectLink, '?') . '?team=' . $_POST['jointeam'];
        } elseif (trim($redirect) !== '') {
            $redirectLink = trim($redirect);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
        } elseif (trim($advocate) !== '' && $_POST['advocate'] == 1) {
            $redirectLink = trim($advocate);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
        } else {
            $redirectLink = trim($thanks);
            if (intval($redirectLink) != 0) {
                $redirectLink = get_permalink($redirectLink);
            } else {
                if (!jg_check_missing_http($redirectLink)) {
                    $redirectLink = 'http://' . $redirectLink;
                }
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    include_once JG_PLUGIN_DIR . '/lib/JustGivingClient.php';
    $client = new JustGivingClient($wpjg_generalSettings['ApiLocation'], $wpjg_generalSettings['ApiKey'], $wpjg_generalSettings['ApiVersion'], $wpjg_generalSettings['TestUsername'], $wpjg_generalSettings['TestValidPassword']);
    $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "'");
    //if (intval($wpjg_generalSettings['Event']) == $wpjg_generalSettings['Event']) echo 'a';
    $suggestions = array();
    if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'createpage' && wp_verify_nonce($_POST['createpage_nonce_field'], 'verify_true_create') && $_POST['formName'] == 'createpage') {
        include_once JG_PLUGIN_DIR . '/lib/functions.php';
        $results = array('jointeam' => '', 'pagetitle' => '', 'tsandcs' => '', 'pageshortname' => '', 'packbypost' => '', 'heardabout' => '', 'work' => '', 'advocate' => '', 'dob' => '');
        $rules = array('pagetitle' => 'notEmpty', 'tsandcs' => 'notEmpty', 'pageshortname' => 'url');
        $messages = array('jointeam' => 'Please choose your team', 'pagetitle' => 'Please enter your page title', 'tsandcs' => 'You must accept the terms and conditions', 'pageshortname' => 'What is the address of your JustGiving fundraising page');
        foreach ($results as $key => $value) {
            $results[$key] = $_POST[$key];
        }
        $errors = validateJGInputs($results, $rules, $messages);
        if (count($errors) != 0) {
            $foundError = true;
        }
        if (!$founderror) {
            $pageExists = $client->Page->IsShortNameRegistered($_POST['pageshortname']);
            //file_put_contents('/var/www/html/test6/PHP_errors.log', (int)$pageExists , FILE_APPEND);
            /*create page*/
            if (!$pageExists) {
                //file_put_contents('/var/www/html/test6/PHP_errors.log', 'in - no page' , FILE_APPEND);
                $targetAmount = $wpjg_generalSettings['targetAmount'];
                if (trim($_POST['targetch']) == 'var' && isset($_POST['target']) && is_numeric($_POST['target'])) {
                    $targetAmount = $_POST['target'];
                } elseif (is_numeric($_POST['targetch'])) {
                    $targetAmount = $_POST['targetch'];
                }
                /*
                $ordate = $_POST['dob'];
                $pos = strpos($_POST['dob'], '-');
                if (MyCheckDate($_POST['dob'])){
                    //american or off a date field
                    list( $year , $month , $day ) = explode('-',$_POST['dob']);
                    $_POST['dob'] = date('d-m-Y', mktime(0, 0, 0, $month, $day, $year));
                }
                
                $cc5 = array(
                    $_POST['dob'],$_POST['heardabout'],$_POST['work'],($_POST['advocate'] == 1)? 'y':'n','y'
                );
                
                $dto = array(
                    'currency' => ($_SESSION['country'] == 'Ireland') ? 'EUR' : 'GBP',
                    'pageShortName' => $_POST['pageshortname'],
                    'charityId' =>  $wpjg_generalSettings['Charity'],
                    'eventId' => $wpjg_generalSettings['Event'],
                    'justGivingOptIn' => ((bool) $_POST['jgoptin']),
                    'charityOptIn' => ((bool) $_POST['charityoptin']),
                    'pageTitle' => stripslashes($_POST['pagetitle']),
                    'targetAmount' => $targetAmount  ,
                    'charityFunded' => false,
                    "customCodes" => array( 
                        "customCode5" => implode('|', $cc5),
                        "customCode6" => (strpos($wpjg_generalSettings['cc6'],'(data)')  !== false) ? stripslashes($_POST[str_replace('(data)','',$wpjg_generalSettings['cc6'] )]) : stripslashes($wpjg_generalSettings['cc6'])
                    )
                ); 
                */
                $dto = array('currency' => $_SESSION['country'] == 'Ireland' ? 'EUR' : 'GBP', 'pageShortName' => $_POST['pageshortname'], 'charityId' => $wpjg_generalSettings['Charity'], 'justGivingOptIn' => (bool) $_POST['jgoptin'], 'charityOptIn' => (bool) $_POST['charityoptin'], 'pageTitle' => stripslashes($_POST['pagetitle']), 'targetAmount' => $targetAmount, 'charityFunded' => false, "customCodes" => array("customCode1" => strpos($wpjg_generalSettings['cc1'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc1'])]) : stripslashes($wpjg_generalSettings['cc1']), "customCode2" => strpos($wpjg_generalSettings['cc2'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc2'])]) : stripslashes($wpjg_generalSettings['cc2']), "customCode3" => strpos($wpjg_generalSettings['cc3'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc3'])]) : stripslashes($wpjg_generalSettings['cc3']), "customCode4" => strpos($wpjg_generalSettings['cc4'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc4'])]) : stripslashes($wpjg_generalSettings['cc4']), "customCode5" => strpos($wpjg_generalSettings['cc5'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc5'])]) : stripslashes($wpjg_generalSettings['cc5']), "customCode6" => strpos($wpjg_generalSettings['cc6'], '(data)') !== false ? stripslashes($_POST[str_replace('(data)', '', $wpjg_generalSettings['cc6'])]) : stripslashes($wpjg_generalSettings['cc6'])));
                if (trim($wpjg_generalSettings['Event']) != '' && intval($wpjg_generalSettings['Event']) == $wpjg_generalSettings['Event']) {
                    $dto['eventId'] = $wpjg_generalSettings['Event'];
                } elseif (trim($wpjg_generalSettings['Event']) != '') {
                    //Birthday Wedding OtherCelebration InMemory
                    $dto['activityType'] = $wpjg_generalSettings['Event'];
                    date_default_timezone_set("UTC");
                    $_POST['eventDate'] = strtotime($_POST['eventDate-date'] . ' ' . $_POST['eventDate-time']);
                    $dto['eventDate'] = "\\/Date(" . $_POST['eventDate'] . "\\/";
                    $dto['eventName'] = $_POST['eventName'];
                } else {
                    $dto['activityType'] = $_POST['eventType'];
                    date_default_timezone_set("UTC");
                    $_POST['eventDate'] = strtotime($_POST['eventDate-date'] . ' ' . $_POST['eventDate-time']);
                    $dto['eventDate'] = "\\/Date(" . $_POST['eventDate'] . "\\/";
                    $dto['eventName'] = $_POST['eventName'];
                }
                if (strlen($wpjg_generalSettings['imageurl']) > 0) {
                    $url = !jg_check_missing_http($wpjg_generalSettings['imageurl']) ? home_url() . $wpjg_generalSettings['imageurl'] : $wpjg_generalSettings['imageurl'];
                    $dto['images'] = array(array("caption" => get_bloginfo('name'), "isDefault" => true, "url" => $url));
                }
                if (strlen($wpjg_generalSettings['pageStory']) > 0) {
                    $dto['pageStory'] = $wpjg_generalSettings['pageStory'];
                }
                if (strlen($wpjg_generalSettings['pageSummaryWhat']) > 0) {
                    $dto['pageSummaryWhat'] = $wpjg_generalSettings['pageSummaryWhat'];
                }
                if (strlen($wpjg_generalSettings['pageSummaryWhy']) > 0) {
                    $dto['pageSummaryWhy'] = $wpjg_generalSettings['pageSummaryWhy'];
                }
                //$cntent  = print_R($_SESSION, true);
                //file_put_contents( '/var/www/html/test6/PHP_errors.log' , $cntent, FILE_APPEND );
                //$cntent  = print_R($dto, true);
                //file_put_contents('/var/www/html/test6/PHP_errors.log', $cntent , FILE_APPEND);
                $page = $client->Page->Create(trim($_SESSION['userEnc']), $dto);
                /*update user with url*/
                if (!$page) {
                    $errors['shortname']['message'] = 'Could not create page at JustGiving';
                }
                //$cntent  = print_R($page, true);
                //file_put_contents( '/var/www/html/test6/PHP_errors.log' , $cntent, FILE_APPEND );
                //$cntent  = print_R($_SESSION, true);
                //file_put_contents( '/var/www/html/test6/PHP_errors.log' , $cntent, FILE_APPEND );
                $uid = 0;
                if ($page) {
                    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "'", ARRAY_A);
                    if (count($result) > 0) {
                        //file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' , 'update', FILE_APPEND );
                        $wpdb->update($wpdb->prefix . "jgusers", array('pageurl' => $page->next->uri, 'pageid' => $page->pageId, 'optin' => $_POST['charityoptin'], 'tsandcs' => $_POST['tandcs'], 'packbypost' => $_POST['packbypost'], 'heardabout' => $_POST['heardabout'], 'eventstart' => $_POST['eventstart'], 'eventend' => $_POST['eventend'], 'work' => $_POST['work'], 'worktown' => $_POST['worktown'], 'workcountry' => $_POST['workcountry'], 'workpostcode' => $_POST['workpostcode'], 'workwhere' => $_POST['workwhere'], 'dofereln' => $_POST['dofereln'], 'dofegold' => $_POST['dofegold'], 'dofeevent' => $_POST['dofeevent'], 'tshirt' => $_POST['tshirt'], 'discountcode' => $_POST['discountcode'], 'region' => $_POST['region'], 'signoff' => $_POST['signoff'], 'dob' => $_POST['dob']), array('userEnc' => trim($_SESSION['userEnc'])));
                        //$cntent  = print_R($wpdb->queries , true);
                        //file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' , $cntent, FILE_APPEND );
                        $uid = $result['id'];
                    } else {
                        //file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' , 'insert', FILE_APPEND );
                        $wpdb->insert($wpdb->prefix . "jgusers", array('email' => trim($_SESSION['email']), 'userEnc' => trim($_SESSION['userEnc']), 'pageurl' => $page->next->uri, 'pageid' => $page->pageId, 'signupdate' => time(), 'optin' => $_POST['charityoptin'], 'tsandcs' => $_POST['tandcs'], 'packbypost' => $_POST['packbypost'], 'eventstart' => $_POST['eventstart'], 'eventend' => $_POST['eventend'], 'work' => $_POST['work'], 'worktown' => $_POST['worktown'], 'workcountry' => $_POST['workcountry'], 'workpostcode' => $_POST['workpostcode'], 'workwhere' => $_POST['workwhere'], 'dofereln' => $_POST['dofereln'], 'dofegold' => $_POST['dofegold'], 'dofeevent' => $_POST['dofeevent'], 'tshirt' => $_POST['tshirt'], 'discountcode' => $_POST['discountcode'], 'region' => $_POST['region'], 'signoff' => $_POST['signoff'], 'heardabout' => $_POST['heardabout'], 'advocate' => $_POST['advocate'], 'dob' => $_POST['dob']));
                        $uid = $wpdb->insert_id;
                    }
                    //$sql = "INSERT INTO {$wpdb->prefix}jgpages (pageid,userid,next_rel,next_uri,next_type,short,signOnUrl) VALUES (%s,%s,%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE userid = %s, next_rel = %s, next_uri = %s, next_type = %s, short = %s, signOnUrl = %s";
                    //var_dump($sql); // debug
                    //$sql = $wpdb->prepare($sql,$page->pageId,$result['id'],$page->next->rel,$page->next->uri,$page->next->type,$short,$page->signOnUrl,$result['id'],$page->next->rel,$page->next->uri,$page->next->type,$short,$page->signOnUrl);
                    //var_dump($sql); // debug
                    //$wpdb->query($sql);
                    //file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' ,  "SELECT * FROM wp_jgusers WHERE `userEnc`='".trim($_SESSION['userEnc'])."'", FILE_APPEND );
                    //$cntent  = print_R($result, true);
                    //file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' , $cntent, FILE_APPEND );
                    // echo 'b';
                    // add to team if chosen
                    // $cntent  = print_R($_POST, true);
                    // file_put_contents( '/xampp/htdocs/cruk_undie/out.txt' , $cntent, FILE_APPEND );
                    $vars = array();
                    $rsgeneralSettings = get_option('jg_general_settings');
                    if (isset($_POST['jointeam']) && trim($_POST['jointeam']) !== '') {
                        //echo 'b';
                        $user = array();
                        $user['pageShortName'] = $dto['pageShortName'];
                        $client->Team->Join($_POST['jointeam'], trim($_SESSION['userEnc']), $user);
                        $teamqs = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgteams WHERE `teamshortname`='" . trim($_POST['jointeam']) . "' ");
                        $rsgeneralSettings = get_option('jg_general_settings');
                        $vars = array('firstname' => $result['firstname'], 'url' => $page->next->uri, 'editurl' => $page->signOnUrl, 'donateurl' => $page->next->uri . "/4w350m3/donate/?amount=5.00&reference=undie", 'teamid' => $teamqs->id, 'teamname' => $teamqs->teamname, 'teamshortname' => $teamqs->teamshortname, 'teamstory' => $teamqs->teamstory, 'teamfbpage' => $teamqs->teamfbpage, 'teamtwpage' => $teamqs->teamtwpage, 'website' => get_home_url('/'), 'fbappid' => $rsgeneralSettings['fbappid']);
                        $members = array();
                        $members = json_decode($teamqs->teammembers, true);
                        $members[] = array('id' => $uid, 'numberOfDonations' => 0, 'pageShortName' => $dto['pageShortName'], 'pageTitle' => $dto['pageTitle'], 'ref' => '', 'totalAmountRaised' => 0);
                        $wpdb->update($wpdb->prefix . "jgteams", array('teammembers' => json_encode($members)), array('teamshortname' => trim($_POST['jointeam'])));
                    } else {
                        $vars = array('firstname' => $result['firstname'], 'url' => $page->next->uri, 'editurl' => $page->signOnUrl, 'donateurl' => $page->next->uri . "/4w350m3/donate/?amount=5.00&reference=undie", 'website' => get_home_url('/'), 'fbappid' => $rsgeneralSettings['fbappid']);
                    }
                    $vars['website'] = get_home_url();
                    $vars['website_enc'] = urlencode($vars['website']);
                    $useracc = $client->Account->GetUser(trim($_SESSION['userEnc']));
                    if (trim($vars['firstname']) == '') {
                        $vars['firstname'] = $useracc->firstName;
                        $result['firstname'] = $useracc->firstName;
                        $result['lastname'] = $useracc->lastName;
                    }
                    $email = $_SESSION['email'];
                    if (trim($email) == '') {
                        $email = $useracc->email;
                    }
                    if (trim($advocate) !== '' && $_POST['advocate'] == 1) {
                        $ba = sendadvocate(trim($email), $result['firstname'] . ' ' . $result['lastname'], $vars, 1);
                    } else {
                        $ba = sendthanks(trim($email), $result['firstname'] . ' ' . $result['lastname'], $vars, 1);
                    }
                    // -> send straight to thanks
                    $redirectLink = '';
                    if (!isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 || $result['paidaccess'] == 0 && $wpjg_generalSettings['paidaccess'] == 1) {
                        $redirectLink = trim($paid);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    } elseif (trim($teampage) !== '') {
                        $redirectLink = trim($teampage);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                        $redirectLink = parse_url($redirectLink, PHP_URL_QUERY) ? $redirectLink . '&team=' . $_POST['jointeam'] : rtrim($redirectLink, '?') . '?team=' . $_POST['jointeam'];
                    } elseif (trim($redirect) !== '') {
                        $redirectLink = trim($redirect);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    } elseif (trim($advocate) !== '' && $_POST['advocate'] == 1) {
                        $redirectLink = trim($advocate);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    } else {
                        $redirectLink = trim($thanks);
                        if (intval($redirectLink) != 0) {
                            $redirectLink = get_permalink($redirectLink);
                        } else {
                            if (!jg_check_missing_http($redirectLink)) {
                                $redirectLink = 'http://' . $redirectLink;
                            }
                        }
                    }
                    $redirectLink = parse_url($redirectLink, PHP_URL_QUERY) ? $redirectLink . '&nexturl=' . urlencode($page->next->uri) : rtrim($redirectLink, '?') . '?nexturl=' . urlencode($page->next->uri);
                    //echo $redirectlink; exit;
                    //$cntent  = print_R(array('redir'=>$redirect,'thanks'=>$thanks,'page'=>$page,'redired'=>$redirectlink), true);
                    //file_put_contents( '/var/www/html/test6/PHP_errors.log' ,$redirectLink, FILE_APPEND );
                    //file_put_contents('curldata.txt', $redirectLink , FILE_APPEND);
                    wp_redirect($redirectLink);
                    exit;
                }
            } else {
                if (isset($_POST['pageshortname'])) {
                    $pages = $client->Page->SuggestPageShortNames($_POST['pageshortname']);
                    foreach ($pages->Names as $post) {
                        $suggestion = array();
                        $suggestion['label'] = esc_html($post);
                        $suggestions[] = $suggestion;
                    }
                }
            }
            $errors['shortname']['message'] = "Someone&rsquo;s already set sail with that name. Try another.";
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    //$teams = $client->Team->Search();
    //print_R($teams);
    /*
        $teamRows = $wpdb->get_results(" SELECT * FROM {$wpdb->prefix}jgteams ;");    
        $items_list = array(
            '' => array(
                'label' => ""
            )
        );
        foreach ($teamRows as $team){
            $items_list[$team->teamshortname] = array('label' =>  $team->teamname);
        }    
        $smarty->assign('teams', $items_list);
    */
    $formurl = jg_curpageurl();
    /*
    $redirectLink = 'http://test6.thegoodagencydigital.co.uk/thank-you?team=wibble';
    $nexturl = 'http://v3-sandbox.justgiving.com/h2onttt20152016';    
    $redirectlink = (parse_url($redirectLink, PHP_URL_QUERY)) ? $redirectLink . '&nexturl='.$nexturl : rtrim($redirectLink, '?') . '?nexturl='.$nexturl;    
    $smarty->assign('redirecturl',$redirectlink);
    */
    $smarty->assign('pageshortname', stripslashes($_POST['pageshortname']));
    $smarty->assign('errorshortname', $errors['shortname']['message']);
    $smarty->assign('pagetitle', stripslashes($_POST['pagetitle']));
    $smarty->assign('errorpagetitle', $errors['pagetitle']['message']);
    $smarty->assign('target', isset($_POST['target']) && is_numeric($_POST['target']) ? $_POST['target'] : $wpjg_generalSettings['targetAmount']);
    $smarty->assign('errortargetAmount', $errors['target']['message']);
    $smarty->assign('nonce', wp_nonce_field('verify_true_create', 'createpage_nonce_field', true, false));
    $smarty->assign('jgoptinyes', $_POST['jgoptin'] == '1' || !isset($_REQUEST['jgoptin']) ? 'checked="checked"' : '');
    $smarty->assign('jgoptinno', $_POST['jgoptin'] == '0' ? 'checked="checked"' : '');
    $smarty->assign('choptinyes', $_POST['charityoptin'] == '1' || $_SESSION['optin'] == 1 && $_POST['charityoptin'] != 0 || !isset($_REQUEST['charityoptin']) && (!isset($_SESSION['optin']) || $_SESSION['optin'] != 0) ? 'checked="checked"' : '');
    $smarty->assign('choptinno', $_POST['charityoptin'] == '0' ? 'checked="checked"' : '');
    $smarty->assign('formurl', $formurl);
    $smarty->assign('templateurl', get_template_directory_uri());
    $smarty->assign('suggestions', $suggestions);
    $smarty->assign('logout', $logout);
    $data = array();
    for ($i = date('Y') - 18; $i >= date('Y') - 98; $i--) {
        $data[] = $i;
    }
    $smarty->assign('years', $data);
    $smarty->assign('maxdate', date('Y-m-d'));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('Errors', $errors);
    $smarty->assign('Session', $_SESSION);
    if ($template != '') {
        $smarty->display($template);
    } else {
        $smarty->display('create-page.html');
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}