Example #1
0
/**
 * retrieve the search page, or create one if it doesn't exist
 *
 * @return object search page
 */
function Search_getPage()
{
    if (isset($_GET['s'])) {
        $_GET['search'] = $_GET['s'];
    }
    $p = Page::getInstanceByType(5);
    if (!$p || !isset($p->id)) {
        dbQuery('insert into pages set cdate=now(),edate=now(),name="__search",' . 'body="",type=5,special=2,ord=5000');
        $p = Page::getInstanceByType(5);
    }
    return $p;
}
Example #2
0
/**
 * sends an invoice if the status is right
 *
 * @param int   $id    ID of the order
 * @param array $order details of the order
 *
 * @return null
 */
function OnlineStore_sendInvoiceEmail($id, $order = false)
{
    if ($order === false) {
        $order = dbRow("SELECT * FROM online_store_orders WHERE id={$id}");
    }
    $sendAt = (int) dbOne('select val from online_store_vars where name="invoices_by_email"', 'val');
    if ($sendAt == 0 && $order['status'] != '1') {
        return;
    }
    if ($sendAt == 1) {
        // never send
        return;
    }
    if ($sendAt == 2 && $order['status'] != '2') {
        return;
    }
    if ($sendAt == 3 && $order['status'] != '4') {
        return;
    }
    $form_vals = json_decode($order['form_vals']);
    $items = json_decode($order['items']);
    $short_domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
    // { work out from/to
    $page = Page::getInstanceByType('online-store');
    $page->initValues();
    $from = 'noreply@' . $short_domain;
    $bcc = '';
    if ($page && isset($page->vars['online_stores_admin_email']) && $page->vars['online_stores_admin_email']) {
        $from = $page->vars['online_stores_admin_email'];
        $bcc = $page->vars['online_stores_admin_email'];
    }
    if (isset($form_vals->billing_email)) {
        $form_vals->Billing_Email = $form_vals->billing_email;
    }
    if (!isset($form_vals->Billing_Email) || !$form_vals->Billing_Email) {
        $form_vals->Billing_Email = $form_vals->Email;
    }
    $headers = '';
    if ($bcc) {
        $sendToAdmin = (int) dbOne('select val from online_store_vars where name="invoices_by_email_admin"', 'val');
        if (!$sendToAdmin) {
            $headers .= 'BCC: ' . $bcc . "\r\n";
        }
    }
    // }
    Core_trigger('send-invoice', array($order));
    // { send invoice
    if ($form_vals->Billing_Email != '*****@*****.**') {
        Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] invoice #' . $id, $order['invoice'], $from, '_body', $headers);
    }
    // }
    // { handle item-specific stuff (vouchers, stock control)
    foreach ($items as $item_index => $item) {
        if (!$item->id) {
            continue;
        }
        $p = Product::getInstance($item->id);
        $pt = ProductType::getInstance($p->vals['product_type_id']);
        if ($pt->is_voucher) {
            $html = $pt->voucher_template;
            // { common replaces
            $html = str_replace('{{$_name}}', $p->name, $html);
            $html = str_replace('{{$description}}', $p->vals['description'], $html);
            $html = str_replace('{{$_recipient}}', $form_vals->Billing_Email, $html);
            $html = str_replace('{{$_amount}}', $p->vals['os_voucher_value'], $html);
            // }
            if (strpos($html, '{{PRODUCTS_QRCODE}}') !== false) {
                // qr code
                $url = 'http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=checkQrCode/' . 'oid=' . $order['id'] . '/pid=' . $item_index . '/md5=' . md5($order['invoice']);
                $html = str_replace('{{PRODUCTS_QRCODE}}', '<img src="http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=getQrCode/b64=' . urlencode(base64_encode($url)) . '"/>', $html);
            }
            Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] voucher', $html, $from, '_body', $headers);
        }
        // { stock control
        if (isset($p->vals['online-store'])) {
            $valsOS = $p->vals['online-store'];
            $stock_amount = (int) @$valsOS['_stock_amt'] - $item->amt;
            $valsOS['_stock_amt'] = $stock_amount;
            $sold_amount = (int) @$valsOS['_sold_amt'] + $item->amt;
            $valsOS['_sold_amt'] = $sold_amount;
            dbQuery('update products set' . ' online_store_fields="' . addslashes(json_encode($valsOS)) . '"' . ', os_amount_in_stock=' . $stock_amount . ', os_amount_sold=' . $sold_amount . ', date_edited=now()' . ' where id=' . $item->id);
        }
        // }
    }
    Core_cacheClear('products');
    // }
}
Example #3
0
/**
 * get list of payment types accepted by a checkout
 *
 * @return array of payment types
 */
function OnlineStore_paymentTypesList()
{
    $page_id = (int) @$_REQUEST['page_id'];
    if ($page_id) {
        $page = Page::getInstance($page_id);
        $page->initValues();
    } else {
        $page = @$GLOBALS['PAGEDATA'];
        if ($page->type != 'online-store') {
            $page = Page::getInstanceByType('online-store');
            if (!$page) {
                return array('error' => __('No online-store page created'));
            }
            $page->initValues();
        }
    }
    // { build list of payment methods
    $arr = array();
    if (@$page->vars['online_stores_quickpay_merchantid']) {
        $arr['QuickPay'] = __('Credit Card');
    }
    if (@$page->vars['online_stores_realex_sharedsecret']) {
        $arr['Realex'] = __('Credit Card');
    }
    if (@$page->vars['online_stores_paypal_address']) {
        $arr['PayPal'] = __('PayPal');
    }
    if (@$page->vars['online_stores_bank_transfer_account_number']) {
        $arr['Bank Transfer'] = __('Bank Transfer');
    }
    // }
    if (!count($arr)) {
        return array('error' => 'No payment methods have been defined.');
    }
    return $arr;
}
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     None
 */
global $DBVARS;
$http = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off' ? 'http://' : 'https://';
$callbackurl = $http . $_SERVER['HTTP_HOST'] . '/ww.plugins/online-store/verify/' . 'quickpay.php';
// { redirect URL for cancelled purchases
$canc = Page::getInstance($PAGEDATA->vars['online_store_quickpay_redirect_failed']);
// }
// { redirect URL (for successful purchases
$cont = Page::getInstance($PAGEDATA->vars['online_store_quickpay_redirect_to']);
if ($cont) {
    $cont_url = $cont->getAbsoluteURL();
} else {
    $rp = Page::getInstanceByType('privacy');
    if ($rp) {
        $cont_url = $rp->getAbsoluteUrl() . '?onlinestore_iid=' . $id;
    } else {
        $cont_url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
    }
}
// }
$fields = array('protocol' => 4, 'msgtype' => 'authorize', 'merchant' => $PAGEDATA->vars['online_stores_quickpay_merchantid'], 'language' => 'en', 'ordernumber' => str_pad($id, 8, '0', STR_PAD_LEFT), 'amount' => (int) ($total * 100), 'currency' => $DBVARS['online_store_currency'], 'continueurl' => $cont_url, 'cancelurl' => $canc->getAbsoluteURL(), 'callbackurl' => $callbackurl, 'autocapture' => $PAGEDATA->vars['online_stores_quickpay_autocapture'], 'cardtypelock' => '', 'group' => 0, 'splitpayment' => 0);
// { calculate required MD5 checksum
$md5_word = '';
foreach ($fields as $key => $value) {
    $md5_word .= $value;
}
$md5_word .= $PAGEDATA->vars['online_stores_quickpay_secret'];
$fields['md5check'] = md5($md5_word);
Example #5
0
function Ads_adminOrderMarkPaid()
{
    $id = (int) $_REQUEST['item_number'];
    // create ad
    $data = dbRow('select * from ads_purchase_orders where id=' . $id);
    if (!$data) {
        return array('error' => 'no such ad');
    }
    $sql = 'insert into ads set name="ad",customer_id=' . $data['user_id'] . ',target_url="' . addslashes($data['target_url']) . '",cdate=now()' . ',target_type="' . addslashes($data['target_type']) . '"' . ',is_active=1,type_id=' . $data['type_id'] . ',date_expire=date_add(now(), interval ' . $data['days'] . ' day)';
    dbQuery($sql);
    $ad_id = dbLastInsertId();
    $type = dbRow('select * from ads_types where id=' . $data['type_id']);
    // { poster
    $url = false;
    $dirname = USERBASE . '/f/userfiles/' . $data['user_id'] . '/ads-upload-poster';
    $dir = new DirectoryIterator($dirname);
    foreach ($dir as $file) {
        if ($file->isDot()) {
            continue;
        }
        $url = 'userfiles/' . $data['user_id'] . '/ads-upload-poster/' . $file->getFilename();
    }
    $newName = '/f/userfiles/' . $data['user_id'] . '/ad-poster-' . $ad_id . '.' . preg_replace('/.*\\./', '', $url);
    if ($url) {
        rename(USERBASE . '/f/' . $url, USERBASE . $newName);
        dbQuery('update ads set poster="' . addslashes($newName) . '" where id=' . $ad_id);
    }
    // }
    // { image
    $url = false;
    $dir = new DirectoryIterator(USERBASE . '/f/userfiles/' . $data['user_id'] . '/ads-upload');
    foreach ($dir as $file) {
        if ($file->isDot()) {
            continue;
        }
        $url = 'userfiles/' . $data['user_id'] . '/ads-upload/' . $file->getFilename();
    }
    $newName = '/f/userfiles/' . $data['user_id'] . '/ad-' . $ad_id . '.' . preg_replace('/.*\\./', '', $url);
    if (file_exists(USERBASE . '/f/' . $url)) {
        rename(USERBASE . '/f/' . $url, USERBASE . $newName);
    }
    dbQuery('update ads set image_url="' . addslashes($newName) . '" where id=' . $ad_id);
    // }
    if ($type['type'] == '1') {
        // page
        $page = Page::getInstanceByType('ads');
        $pid = $page->id;
        $page->initValues();
        $pid = (int) $page->vars['ads_fullpage_parent'];
        $meta = json_decode($data['meta'], true);
        $body = '<h1>' . htmlspecialchars($meta['name']) . '</h1>';
        if (isset($meta['address']) && $meta['address']) {
            $body .= '<strong>Address</strong>: ' . htmlspecialchars($meta['address']) . '<br/>';
        }
        if (isset($meta['landline']) && $meta['landline']) {
            $body .= '<strong>Landline</strong>: ' . htmlspecialchars($meta['landline']) . '<br/>';
        }
        if (isset($meta['mobile']) && $meta['mobile']) {
            $body .= '<strong>Mobile</strong>: ' . htmlspecialchars($meta['mobile']) . '<br/>';
        }
        if (isset($meta['email']) && $meta['email']) {
            $body .= '<span class="email"><a href="mailto:' . htmlspecialchars($meta['email']) . '">Send Email</a></span> ';
        }
        if (isset($meta['url']) && $meta['url']) {
            $body .= '<span class="url"><a target="_blank" href="' . htmlspecialchars($meta['url']) . '">' . 'Visit Website</a></span> ';
        }
        if (isset($meta['twitter']) && $meta['twitter']) {
            $body .= '<span class="twitter"><a target="_blank" href="http://twitter.com/' . htmlspecialchars(str_replace('@', '', $meta['twitter'])) . '">' . htmlspecialchars($meta['twitter']) . '</a></span> ';
        }
        if (isset($meta['facebook']) && $meta['facebook']) {
            $body .= '<span class="facebook"><a target="_blank" href="' . htmlspecialchars($meta['facebook']) . '">Facebook</a></span> ';
        }
        $body .= str_replace("\n", '</p><p>', '<p>' . htmlspecialchars($meta['content']) . '</p>');
        if (isset($meta['address']) && $meta['address']) {
            $body .= '<iframe frameborder="0" height="320" scrolling="no" src="//maps.google.com/maps?q=' . htmlspecialchars($meta['address']) . '&amp;num=1&amp;t=m&amp;ie=UTF8&amp;z=14&amp;output=embed" width="480"></iframe>';
        }
        $sql = 'insert into pages set parent=' . $pid . ', date_publish="0000-00-00"' . ', body="' . addslashes($body) . '"' . ', date_unpublish=date_add(now(), interval ' . $data['days'] . ' day)' . ', name="' . addslashes($meta['name']) . '"' . ', category=""' . ', alias="' . addslashes($meta['name']) . '", type=0';
        dbQuery($sql);
        Core_cacheClear('pages');
    }
    dbQuery('delete from ads_purchase_orders where id=' . $id);
}
Example #6
0
function Ads_paymentDetailsGet()
{
    $p = Page::getInstanceByType('ads');
    $p->initValues();
    return isset($p->vars['ads-profile-page']) ? $p->vars['ads-profile-page'] : 'no details recorded';
}