Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/Controller/Api.php |
<?php
defined('SYSPATH') or die('No direct script access.');
class Controller_Api extends Controller_Frontend {
public function action_test1() {
// Database variables
$host = "localhost"; //database location
$user = ""; //database username
$pass = ""; //database password
$db_name = ""; //database name
// PayPal settings
$paypal_email = 'paypal@example.com';
$return_url = 'http://example.com/payment-successful.htm';
$cancel_url = 'http://example.com/payment-cancelled.htm';
$notify_url = 'http://example.com/paypal/payments.php';
$item_name = 'Test Item';
$item_amount = 5.00;
$querystring = "";
if( $_POST ) {
// Check if paypal request or response
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){
// Firstly Append paypal account to querystring
$querystring .= "?business=".urlencode($paypal_email)."&";
// Append amount& currency (£) to quersytring so it cannot be edited in html
//The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
$querystring .= "item_name=".urlencode($item_name)."&";
$querystring .= "amount=".urlencode($item_amount)."&";
//loop for posted values and append to querystring
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$querystring .= "$key=$value&";
}
// Append paypal return addresses
$querystring .= "return=".urlencode(stripslashes($return_url))."&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$querystring .= "notify_url=".urlencode($notify_url);
// Append querystring with custom field
//$querystring .= "&custom=".USERID;
// Redirect to paypal IPN
header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
exit();
}else{
// Response from PayPal
}
}
echo '
<form id="paypal_form" class="paypal" action="" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="UK" />
<input name="currency_code" type="hidden" value="GBP" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
<input name="first_name" type="hidden" value="Customers First Name" />
<input name="last_name" type="hidden" value="Customers Last Name" />
<input name="payer_email" type="hidden" value="customer@example.com" />
<input name="item_number" type="hidden" value="123456" />
<input type="submit" value="Submit Payment" />
</form>';
exit;
}
public function action_mozaic() {
$mozaic = "";
$left=0;
$row_num=0;
$top = 0;
$images = array();
$rand = rand(10, 15);
foreach( ORM::Factory('item')->where('can_own_photo','=', 0)->where('thumb','!=', '')->limit($rand)->order_by(DB::expr('RAND()'))->find_all() as $item ) {
$images[] = $item->thumb;
}
/*
foreach( ORM::Factory('item')->where('can_own_photo','=', 0)->limit(42)->order_by(DB::expr('RAND()'))->find_all() as $item ) :
if( $row_num == 14 ) { $row_num = 0; $top += 136; $left = 0; }
$mozaic .= '<img style="top: '.$top.'px; left: '.$left.'px;" src="/image.php/image-name.jpg?width=146&height=136&cropratio=14:13&image=/'.$item->thumb.'"/>';
$left += 146;
$row_num++;
endforeach;
*/
echo json_encode( $images );
//echo $mozaic;
exit;
}
public function action_fb1() {
$this->redirect('Api/fb2');
}
public function action_fb2() {
include("html/fb/src/facebook.php");
$config = array(
'appId' => '421300554675126',
'secret' => '68328cc7b8e6a5c6f1761e57b202ac95',
'fileUpload' => false, // optional
'allowSignedRequest' => true, // optional, but should be set to false for non-canvas apps
);
$facebook = new Facebook($config);
$params = array(
'scope' => 'email',
'redirect_uri' => 'http://'.$_SERVER['HTTP_HOST'].'/Login'
);
Message::notice(__t('Sesja FB została utworzona. Proszę kliknąć <a style="color: inherit;" href="'.$facebook->getLoginUrl($params).'"><strong>tutaj</strong></a> aby przejść do swojego konta!'));
$this->redirect('/');
}
public function action_calculate_product_price() {
$circuit = addslashes($_GET['circuit']);
$surface = addslashes($_GET['surface']);
$product_type = addslashes($_GET['product_type']);
$product_print = !empty($_GET['product_print']) ? addslashes($_GET['product_print']) : 0;
$i = ORM::Factory('item')->limit(1)->find();
if( $product_type == 2 ) { // Płótno
$price_produce = round($i->price_produce*($surface/10000), 2); // Zamiana cm => m
}
if( $product_type == 1 ) { // Fototapety
$product_type_1 = addslashes($_GET['product_type_'.$product_type]);
if( $product_type_1 == "paper" ) {
$price_produce = round($i->price_paper*($surface/10000), 2); // Zamiana cm => m
}
if( $product_type_1 == "nonwoven" ) {
$price_produce = round($i->price_nonwoven*($surface/10000), 2); // Zamiana cm => m
}
if( $product_type_1 == "adhesive" ) {
$price_produce = round($i->price_adhesive*($surface/10000), 2); // Zamiana cm => m
}
}
if( $product_type == 3 ) { // Plakaty
$product_type_3 = addslashes($_GET['product_type_'.$product_type]);
if( $product_type_3 == "polypropylene" ) {
$price_produce = round($i->price_polypropylene*($surface/10000), 2); // Zamiana cm => m
}
if( $product_type_3 == "photo_paper" ) {
$price_produce = round($i->price_photo_paper*($surface/10000), 2); // Zamiana cm => m
}
}
$price_frame = round($i->price_frame*($circuit/10000), 2)*100; // Zamiana cm => m
$price_nice_frame = round($i->price_nice_frame*($circuit/10000), 2)*100; // Zamiana cm => m
$price_antiframe = round($i->price_anti*($surface/10000), 2); // Zamiana cm => m
$result_line = number_format($price_produce = Model_Order::calculatePrice($price_produce, $product_print, 0), 2, '.', '')."::";
$result_line .= number_format( $price_frame = Model_Order::calculatePrice($price_frame, $product_print, 0), 2, '.', '')."::";
//$result_line .= number_format($price_produce+$price_frame, 2, '.', '')."::";
$result_line .= number_format(Model_Order::calculatePrice($price_nice_frame, $product_print, 0), 2, '.', '')."::";
$result_line .= number_format(Model_Order::calculatePrice($price_antiframe, $product_print, 0), 2, '.', '');
echo $result_line;
exit;
}
public function action_page_like_callback() {
$url = addslashes($_GET['a']);
$url_ = explode("/", $url);
if( Auth::instance()->logged_in() ) {
$user_id = Auth::instance()->get_user()->id;
if( count($url_) == 6 ) {
if( $url_[3] == "Artist" AND !empty( $url_[5] ) AND $user_id != $url_[5] ) {
cms::Add_Affiliate( $user_id, 'SHARE_FB');
}
if( $url_[3] == "Gallery" AND !empty( $url_[5] ) AND $user_id != $url_[5] ) {
cms::Add_Affiliate( $user_id, 'SHARE_FB');
}
}
if( count($url_) == 5 ) {
if( $url_[3] == "Product" AND !empty( $url_[4] ) ) {
$id_item = substr($url_[4], 12);
$i = ORM::Factory('item')
->where('id','=', $id_item)
->and_where_open()
->where('owner_id','=', $user_id)
->where('user_id','=', $user_id)
->and_where_close()
->find();
if( !$i->loaded() )
cms::Add_Affiliate( $user_id, 'SHARE_FB');
}
}
}
exit;
}
public function action_page_unlike_callback() {
$url = addslashes($_GET['a']);
$url_ = explode("/", $url);
if( Auth::instance()->logged_in() ) {
cms::Delete_Affiliate( Auth::instance()->get_user()->id, 'SHARE_FB');
}
exit;
}
public function action_connect() {
if( $_POST ) {
$data = ac_form::clear_form_data($_POST);
if( !empty( $data['ip'] ) AND !empty( $data['licence'] ) ) {
if( empty( $data['action'] ) ) {
$licence = ORM::Factory('Order', $data['licence'] );
if( $licence->ip != $data['ip'] ) {
$licence->unauthorized = $data['ip'];
$licence->save();
$canConfirmAdminUnAuthCopy = Kohana::$config->load('site.canConfirmAdminUnAuthCopy');
if( !$canConfirmAdminUnAuthCopy ) {
$title = __t('Nieautoryzowany dostęp do licencji');
$session = Session::instance();
$lang_session = $session->get('language');
$lang = (empty( $lang_session ) ) ? 1 : $lang_session;
$lang_code = DB::query(Database::SELECT, "SELECT name FROM `languages` WHERE `id` = '$lang'")->execute();
$lang_code = strtolower($lang_code[0]['name']);
$e_content = View::factory('email/'.$lang_code.'_unauthorized_licence')
->bind('licence', $licence)->bind('ip', $data['ip']);
aurora::standardEmail(Kohana::$config->load('site.email_business'), $title, $e_content);
}
}
} elseif( $data['action'] == "get_version" ) {
$licence = ORM::Factory('Order', $data['licence'] );
echo $licence->file->version;
}
elseif( $data['action'] == "get_update_hash" ) {
$licence = ORM::Factory('Order', $data['licence'] );
echo $licence->file->hash;
}
elseif( $data['action'] == "get_last_update" ) {
$licence = ORM::Factory('Order', $data['licence'] );
echo $licence->file->last_update_date;
}
}
}
exit;
}
public function action_ping() {
$licences = ORM::Factory('Order')->where('status','=', 1)->find_all();
foreach( $licences as $licence ) {
if( !empty( $licence->domain ) ) {
$url = $licence->domain.'/auth/auth.php';
$c = curl_init($url);
curl_exec( $c );
curl_close( $c );
}
}
exit;
}
}