Пример #1
0
 function action($data = array(), $post = array(), $id)
 {
     $ci =& get_instance();
     $ci->load->library('session');
     if (isset($this->ini['sandbox']) && isset($this->ini['api_login_id']) && isset($this->ini['transaction_key']) && isset($post['card_num']) && isset($post['exp_date'])) {
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetRequest.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetTypes.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetXMLResponse.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetResponse.php';
         require dirname(__FILE__) . '/lib/AuthorizeNetAIM.php';
         define("AUTHORIZENET_API_LOGIN_ID", $this->ini['api_login_id']);
         define("AUTHORIZENET_TRANSACTION_KEY", $this->ini['transaction_key']);
         define("AUTHORIZENET_SANDBOX", $this->ini['sandbox']);
         $sale = new AuthorizeNetAIM();
         $sale->amount = number_format($data['amount'], 2);
         $sale->card_num = $post['card_num'];
         $sale->exp_date = $post['exp_date'];
         $response = $sale->authorizeAndCapture();
         if ($response->approved) {
             $ci =& get_instance();
             $ci->load->model('order_m');
             $order = $ci->order_m->getOrderNumber($data['item_number']);
             if (count($order) > 0) {
                 $update['status'] = 'completed';
                 $updatehis['order_id'] = $order->id;
                 $updatehis['label'] = 'order_status';
                 $updatehis['content'] = json_encode(array($order->order_number => 'completed'));
                 $updatehis['date'] = date('Y-m-d H:i:s');
                 $ci->order_m->_table_name = 'orders';
                 if ($ci->order_m->save($update, $order->id)) {
                     $ci->order_m->_table_name = 'orders_histories';
                     $ci->order_m->save($updatehis);
                     $ci->load->helper('cms');
                     $user = $ci->session->userdata('user');
                     //params shortcode email.
                     $params = array('username' => $user['username'], 'email' => $user['email'], 'date' => date('Y-m-d H:i:s'), 'shop' => getSiteName(config_item('site_name')), 'shop_url' => site_url(), 'total' => number_format($data['amount'], 2), 'order_number' => $data['item_number'], 'status' => 'completed');
                     //config email.
                     $config = array('mailtype' => 'html');
                     $subject = configEmail('sub_order_status', $params);
                     $message = configEmail('order_status', $params);
                     $ci->load->library('email', $config);
                     $ci->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
                     $ci->email->to($user['email']);
                     $ci->email->subject($subject);
                     $ci->email->message($message);
                     $ci->email->send();
                 }
             }
             $ci->session->set_flashdata('msg', 'Thanks you for payment!');
             if (isset($this->ini['message'])) {
                 $ci->session->set_flashdata('message', $this->ini['message']);
             }
         } else {
             $ci->session->set_flashdata('error', 'Your payment not success!');
         }
     }
     redirect(site_url('payment/confirm'));
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     error_reporting(E_ALL ^ E_NOTICE);
     configEmail();
 }
Пример #3
0
 function status($type = '', $id = '')
 {
     // load setting
     $this->load->model('settings_m');
     $row = $this->settings_m->getSetting();
     $setting = json_decode($row->settings);
     if ($this->input->post('id')) {
         // change status of each item
         $id = $this->input->post('id');
         $order_id = $this->input->post('order_id');
         $status = $this->input->post('status');
         $data['poduct_status'] = $status;
         //status exists.
         if ($this->order_m->checkStatus($id, $status, false)) {
             return;
         }
         // update item order
         $data['modified_on'] = date('Y-m-d H:i:s');
         $this->order_m->_table_name = 'order_items';
         $this->order_m->save($data, $id);
         // update history
         $item = $this->order_m->getItem($id);
         $item_name = $item->product_name;
         $content = array($item_name => $status);
         $data_his = array('order_id' => $order_id, 'label' => 'item_status', 'content' => json_encode($content), 'date' => date('Y-m-d H:i:s'));
         $this->order_m->_table_name = "orders_histories";
         if ($this->order_m->save($data_his)) {
             //send email to customer.
             $customer = $this->order_m->getUser($order_id);
             if (count($customer) > 0) {
                 $this->load->library('email');
                 //config email.
                 $config = array('mailtype' => 'html', 'charset' => 'utf-8', 'priority' => '1');
                 $subject = 'Changed item order status';
                 $message = '<p>Hello ' . $customer->username . '</p><p>The status of product <a target="_blank" href="' . site_url('product/' . $id) . '">' . $item_name . '</a> in your order number ' . $customer->order_number . ' is changed to completed.</p><p>Regards,</p><p><a href="' . site_url() . '">' . site_url() . '</a></p>';
                 $this->load->library('email');
                 $this->email->initialize($config);
                 $this->email->from(getEmail(config_item('admin_email')), getEmail(config_item('site_name')));
                 $this->email->to($customer->email);
                 $this->email->subject($subject);
                 $this->email->message($message);
                 $this->email->send();
             }
         }
         $order = $this->order_m->getOrder($order_id);
         // get setting
         $this->load->model('settings_m');
         $row = $this->settings_m->getSetting();
         $setting = json_decode($row->settings);
         $this->data['setting'] = $setting;
         // get shipping method
         $this->load->model('shipping_m');
         $shipping = $this->shipping_m->get($order->shipping_id, true);
         $this->data['shipping'] = $shipping;
         // get payment method
         $this->load->model('payment_m');
         $payment = $this->payment_m->get($order->payment_id, true);
         $this->data['payment'] = $payment;
         // get discount
         if ($order->discount_id > 0) {
             $this->load->model('coupon_m');
             $discount = $this->coupon_m->get($order->discount_id, true);
         } else {
             $discount = array();
         }
         $this->data['discount'] = $discount;
         $this->data['order'] = $order;
         $this->data['items'] = $this->order_m->getItems($order->id);
         $this->load->view('admin/order/list_item', $this->data);
     } elseif (($type == 'pending' || $type == 'completed' || $type == 'refused') && $id != '') {
         $data['status'] = $type;
         if ($this->order_m->checkStatus($id, $type, true)) {
             $this->session->set_flashdata('error', lang('orders_admin_cannot_change_status_msg'));
             redirect(site_url('admin/orders'));
         }
         $where = array('id' => $id);
         $this->order_m->_table_name = "orders";
         if ($this->order_m->updateOrder($where, $data)) {
             $order = $this->order_m->getOrder($id);
             $order_name = $order->order_number;
             $content = array($order_name => $type);
             $data_his = array('order_id' => $id, 'label' => 'order_status', 'content' => json_encode($content), 'date' => date('Y-m-d H:i:s'));
             $this->order_m->_table_name = "orders_histories";
             if ($this->order_m->save($data_his)) {
                 $customer = $this->order_m->getUser($id);
                 $this->load->library('email');
                 //params shortcode
                 $params = array('username' => $customer->username, 'email' => $customer->email, 'date' => date('Y-m-d H:i:s'), 'total' => $customer->total, 'order_number' => $customer->order_number, 'status' => $type);
                 //config email.
                 // send email to customer
                 $config = array('mailtype' => 'html', 'charset' => 'utf-8', 'priority' => '1');
                 $subject = configEmail('sub_order_status', $params);
                 $message = configEmail('order_status', $params);
                 $this->load->library('email');
                 $this->email->initialize($config);
                 $this->email->from(getEmail(config_item('admin_email')), getEmail(config_item('site_name')));
                 $this->email->to($customer->email);
                 $this->email->subject($subject);
                 $this->email->message($message);
                 if ($this->email->send()) {
                     $this->session->set_flashdata('msg', lang('orders_admin_email_change_status_order_msg') . $type);
                 } else {
                     $this->session->set_flashdata('error', lang('orders_admin_change_status_not_send_email_msg'));
                 }
                 redirect(site_url('admin/orders'));
             }
         } else {
             $this->session->set_flashdata('error', lang('orders_admin_cannot_change_status_msg'));
         }
         redirect(site_url('admin/orders'));
     } else {
         redirect(site_url('admin/orders'));
     }
 }
Пример #4
0
    function index()
    {
        $this->user = $this->session->userdata('user');
        $this->items = $this->cart->contents();
        if (count($this->items) == 0 || count($this->user) == 0) {
            redirect('cart');
        }
        if ($this->input->post('payment')) {
            $data = $this->input->post();
            // add payment to session
            if ($this->session->userdata('cart')) {
                $cart = $this->session->userdata('cart');
            } else {
                $cart = new stdClass();
            }
            $cart->payment = $data['payment'];
            // update user profile
            $fields = $data['fields'];
            if (count($fields) == 0) {
                redirect('cart/checkout');
            }
            $user_profile = array();
            foreach ($fields as $key => $value) {
                $id = key($value);
                $user_profile[] = array('field_id' => $id, 'form_field' => 'checkout', 'value' => $value[$id], 'object' => $this->user['id']);
            }
            $this->load->model('fields_m');
            if (count($user_profile) > 0) {
                $this->fields_m->add($user_profile);
            }
            // get design option
            $this->load->driver('cache', array('adapter' => 'file'));
            $session_id = $this->session->userdata('order_session_id');
            $designs = $this->cache->get('orders_designs' . $session_id);
            $items = array();
            $i = 0;
            $total = 0;
            $subtotal = 0;
            foreach ($this->items as $key => $item) {
                $subtotal = $subtotal + $item['subtotal'] + $item['customPrice'];
                $items['design'][$i] = $designs[$key];
                $items['cart'][$i] = $item;
                $items['cart'][$i]['teams'] = json_encode($items['cart'][$i]['teams']);
                $items['cart'][$i]['options'] = json_encode($items['cart'][$i]['options']);
                $i++;
            }
            $items['user'] = $this->user;
            $items['metod'] = $cart;
            $items['metod']->subtotal = $subtotal;
            // save design
            $this->load->model('order_m');
            $design_ids = array();
            if (count($items['design'])) {
                $this->load->model('design_m');
                foreach ($items['design'] as $i => $design) {
                    $design_id = $this->order_m->creteOrderNumber(15);
                    $design_ids[$i] = $design_id;
                    $insert = array('title' => '', 'description' => '', 'design_id' => $design_id, 'modified' => '', 'fonts' => $design['fonts'], 'system_id' => 0, 'user_id' => $this->user['id'], 'product_id' => $items['cart'][$i]['product_id'], 'product_options' => $design['color'], 'vectors' => $design['vector'], 'teams' => json_encode($items['cart'][$i]['teams']), 'image' => $design['images']['front'], 'created' => date("Y-m-d H:i:s"));
                    $this->design_m->save($insert, null);
                }
            }
            // save order
            $order = $this->order_m->addNew('order');
            $order['order_number'] = $this->order_m->creteOrderNumber();
            $order['order_pass'] = $this->order_m->creteOrderNumber();
            $order['user_id'] = $this->user['id'];
            $order['payment_id'] = $items['metod']->payment;
            $order['shipping_id'] = $items['metod']->shipping->id;
            if (isset($items['metod']->discount) && isset($items['metod']->discount->id)) {
                // get discount
                $order['discount_id'] = $items['metod']->discount->id;
                if ($items['metod']->discount->discount_type == 't') {
                    $order['discount'] = $items['metod']->discount->value;
                } else {
                    $order['discount'] = $order['sub_total'] * $items['metod']->discount->value / 100;
                }
                // update coupon
                $this->load->model('coupon_m');
                if ($items['metod']->discount->type == 'g') {
                    $coupon = array('count' => 1);
                } else {
                    $row = $this->coupon_m->get($items['metod']->discount->id, true);
                    $coupon = array('count' => $row->count + 1);
                }
                $this->coupon_m->save($coupon, $items['metod']->discount->id);
            }
            $order['shipping_id'] = $items['metod']->shipping->id;
            $order['shipping_price'] = $items['metod']->shipping->price;
            $order['sub_total'] = $items['metod']->subtotal;
            $order['total'] = $order['sub_total'] + $order['shipping_price'] - $order['discount'];
            $order['status'] = 'pending';
            $order_id = $this->order_m->save($order, null);
            // save order items
            $order_item = $this->order_m->addNew('item');
            $order_item['order_id'] = $order_id;
            // get setting
            $this->load->model('settings_m');
            $row = $this->settings_m->getSetting();
            $setting = json_decode($row->settings);
            // get shipping method
            $this->load->model('shipping_m');
            $shipping = $this->shipping_m->get($items['metod']->shipping->id, true);
            // get payment method
            $this->load->model('payment_m');
            $payment = $this->payment_m->get($items['metod']->payment, true);
            // get discount
            if (isset($items['metod']->discount->id)) {
                $this->load->model('coupon_m');
                $discount = $this->coupon_m->get($items['metod']->discount->id, true);
            } else {
                $discount = array();
            }
            $this->data['discount'] = $discount;
            // html email.
            $total = 0;
            $count = 1;
            $shipping_price = $items['metod']->shipping->price;
            $payment_price = 0.0;
            $this->load->language('order');
            $html = '<table style="border-collapse:collapse;">';
            $html .= '<tr>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("name") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("sku") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_product_price_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_print_price_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_product_clipart_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_product_attributes_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_product_qty_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("orders_admin_product_option_title") . '</td>';
            $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . lang("total") . '</td>';
            $html .= '</tr>';
            foreach ($items['cart'] as $i => $item) {
                $price_clipart = 0;
                $cliparts = json_decode($item['cliparts']);
                if (count($cliparts)) {
                    // save order cliparts
                    $arts = array();
                    $ij = 0;
                    foreach ($cliparts as $view => $art) {
                        if (count($art)) {
                            foreach ($art as $art_id => $price) {
                                if ($art_id > 0) {
                                    $price_clipart = $price_clipart + $price;
                                    $arts[$ij] = array('clipart_id' => $art_id, 'order_id' => $order_id, 'status' => 'pending', 'created' => date("Y-m-d H:i:s"));
                                    $ij++;
                                }
                            }
                        }
                    }
                    if (count($arts)) {
                        $this->db->insert_batch('order_cliparts', $arts);
                    }
                }
                $prices = json_decode($item['prices']);
                $order_item['design_id'] = $design_ids[$i];
                $order_item['product_id'] = $item['product_id'];
                $order_item['product_name'] = $item['name'];
                $order_item['product_sku'] = $item['id'];
                $order_item['product_price'] = $prices->sale;
                $order_item['price_print'] = $prices->prints;
                $order_item['price_clipart'] = $price_clipart;
                $order_item['price_attributes'] = $item['customPrice'];
                $order_item['quantity'] = $item['qty'];
                $order_item['poduct_status'] = 'pending';
                $order_item['attributes'] = json_encode($item['options']);
                $this->order_m->save($order_item, null);
                // html email.
                $html .= '<tr>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $item['name'] . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $item['id'] . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $setting->currency_symbol . number_format($prices->sale, 2) . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $setting->currency_symbol . number_format($prices->prints, 2) . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $setting->currency_symbol . number_format($price_clipart, 2) . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $setting->currency_symbol . number_format($item['customPrice'], 2) . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">' . $item['qty'] . '</td>';
                $html .= '<td style="border: 1px solid #ccc; padding: 5px;">';
                if ($item['options'] != '') {
                    $size = json_decode($item['options'], true);
                    if (count($size) > 0) {
                        foreach ($size as $option) {
                            $html .= '<div>
									<strong>' . $option['name'] . ': </strong>';
                            if (is_string($option['value'])) {
                                $html .= $option['value'];
                            } elseif (is_array($option['value']) && count($option['value'])) {
                                foreach ($option['value'] as $v => $value) {
                                    if ($option['type'] == 'textlist') {
                                        $html .= $v . ' - ' . $value . '; ';
                                    } else {
                                        $html .= $value . '; ';
                                    }
                                }
                            }
                            $html .= '</div>';
                        }
                    }
                }
                $html .= '</td>';
                $total_row = $item['qty'] * ($prices->sale + $prices->prints + $price_clipart) + $item['customPrice'];
                $html .= '<td style="border: 1px solid #ccc; text-align: right;">' . $setting->currency_symbol . number_format($total_row, 2) . '</td>
				</tr>';
            }
            // html email.
            $html .= '<tr>
				<td  style="border: 1px solid #ccc; text-align: right; padding: 5px;" colspan="8">
					' . lang("orders_admin_shipment_fee_title");
            if (count($shipping)) {
                $html .= '<br><small>' . lang("orders_admin_shipping_method") . ': <a href="' . site_url() . '"><strong>' . $shipping->title . '</strong></a></small>
						<br><small>' . $shipping->description . '</small>';
            }
            $html .= '</td>
				<td style="border: 1px solid #ccc; text-align: right; padding: 5px;">' . $setting->currency_symbol . number_format($shipping_price, 2) . '</td>
			</tr>
			<tr>
				<td  style="border: 1px solid #ccc; text-align: right; padding: 5px;" colspan="8">
					' . lang("orders_admin_payment_fee_title");
            if (count($payment)) {
                $html .= '<br><small>' . lang("orders_admin_payment_method") . ': <a href="' . site_url() . '"><strong>' . $payment->title . '</strong></a></small>
						<br><small>' . $payment->description . '</small>';
            }
            $html .= '</td>
				<td style="border: 1px solid #ccc; text-align: right; padding: 5px;">' . $setting->currency_symbol . number_format($payment_price, 2) . '</td>
			</tr>
			<tr>
				<td colspan="8" style="border: 1px solid #ccc; text-align: right; padding: 5px;">
					' . lang("orders_admin_discount");
            if (count($discount)) {
                $html .= '<br><small>' . $discount->name . ': <a href="' . site_url() . '"><strong>' . $discount->code . '</strong></a></small>';
            }
            $html .= '</td>
				<td style="border: 1px solid #ccc; text-align: right; padding: 5px;">' . $setting->currency_symbol . number_format($order['discount'], 2) . '</td>
			</tr>
			<tr>';
            $total = $order['total'];
            $html .= '<td colspan="8" style="border: 1px solid #ccc; text-align: right;">' . lang("orders_admin_total_title") . '</td>
				<td style="border: 1px solid #ccc; text-align: right; padding: 5px;" colspan="7"><strong>' . $setting->currency_symbol . number_format($total, 2) . '<strong></td>
			</tr></table>';
            // send email.
            $params = array('username' => $this->user['username'], 'date' => date('Y-m-d H:i:s'), 'total' => $setting->currency_symbol . number_format($total, 2), 'order_number' => $order['order_number'], 'table' => $html);
            //config email.
            $config = array('mailtype' => 'html');
            $subject = configEmail('sub_order_detai', $params);
            $message = configEmail('order_detai', $params);
            $this->load->library('email', $config);
            $this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
            $this->email->to($this->user['email']);
            $this->email->subject($subject);
            $this->email->message($message);
            $this->email->send();
            $this->email->clear();
            $this->email->from($this->user['email'], $this->user['username']);
            $this->email->to(getEmail(config_item('admin_email')));
            $this->email->subject($subject);
            $this->email->message($message);
            $this->email->send();
            // save user address shipping
            $order_info = $this->order_m->addNew('info');
            $order_info['order_id'] = $order_id;
            $order_info['user_id'] = $this->user['id'];
            $profiles = array();
            foreach ($fields as $key => $value) {
                $id = key($value);
                $field = $this->fields_m->getField($id);
                if ($field != '') {
                    if ($field->type == 'country') {
                        $profiles[$field->title] = $this->fields_m->getCountry($value[$id]);
                    } elseif ($field->type == 'state') {
                        $profiles[$field->title] = $this->fields_m->getState($value[$id]);
                    } else {
                        $profiles[$field->title] = $value[$id];
                    }
                }
            }
            $order_info['address'] = json_encode($profiles);
            $this->order_m->save($order_info, null);
            // Payment
            $this->load->model('payment_m');
            $row = $this->payment_m->get($cart->payment, true);
            if (count($row) == 0) {
                redirect('cart/checkout');
            }
            $payment_method = $row->type;
            $file = ROOTPATH . DS . 'application' . DS . 'payments' . DS . $payment_method . DS . $payment_method . '.php';
            // get currency
            $this->load->model('settings_m');
            $currency = $this->settings_m->getCurrency();
            $product = array('item_name' => $order['order_number'], 'item_number' => $order['order_number'], 'amount' => $subtotal - $order['discount'], 'shipping' => $items['metod']->shipping->price, 'qty' => 1, 'currency_code' => $currency->currency_code);
            //remove all session, cache
            $this->session->unset_userdata('cart');
            $this->session->unset_userdata('order_session_id');
            $this->cart->destroy();
            $this->cache->delete('orders_designs' . $session_id);
            if (file_exists($file)) {
                include_once $file;
                $options = json_decode($row->configs, true);
                $pay = new $payment_method($options);
                $pay->action($product, $data, $row->id);
            } else {
                redirect('cart/checkout');
            }
        } else {
            redirect('index.php');
        }
    }
Пример #5
0
 function ipn($data = array())
 {
     if (isset($this->ini['sandbox']) && isset($this->ini['api_username']) && isset($this->ini['password']) && isset($this->ini['signature'])) {
         $config = array('Sandbox' => $this->ini['sandbox'], 'APIUsername' => $this->ini['api_username'], 'APIPassword' => $this->ini['password'], 'APISignature' => $this->ini['signature'], 'PrintHeaders' => false, 'LogResults' => false, 'LogPath' => site_url('/payment'));
         //config paypal get transition.
         if (isset($data['txn_id']) && isset($data['item_number'])) {
             $ci =& get_instance();
             $ci->load->library('getpaypal');
             $paypal = new getPaypal($config);
             $trans = $paypal->getTransaction($data['txn_id']);
             if (!isset($trans['AMT'])) {
                 exit;
             }
             $money = $paypal->getMoney($data['txn_id']);
             $ci->load->model('order_m');
             $order = $ci->order_m->getOrderNumber($data['item_number']);
             if (isset($order->total) && $money == $order->total) {
                 $update['status'] = 'completed';
                 $updatehis['order_id'] = $order->id;
                 $updatehis['label'] = 'order_status';
                 $updatehis['content'] = json_encode(array($order->order_number => 'completed'));
                 $updatehis['date'] = date('Y-m-d H:i:s');
                 if ($ci->order_m->save($update, $order->id)) {
                     $ci->order_m->_table_name = 'orders_histories';
                     $ci->order_m->save($updatehis);
                     $ci->load->helper('cms');
                     $user = $ci->order_m->getUser($order->id);
                     //params shortcode email.
                     $params = array('username' => $user->username, 'email' => $user->email, 'date' => date('Y-m-d H:i:s'), 'total' => number_format($money, 2), 'order_number' => $data['item_number'], 'status' => 'completed');
                     //config email.
                     $config = array('mailtype' => 'html');
                     $subject = configEmail('sub_order_status', $params);
                     $message = configEmail('order_status', $params);
                     $ci->load->library('email', $config);
                     $ci->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
                     $ci->email->to($user->email);
                     $ci->email->subject($subject);
                     $ci->email->message($message);
                     $ci->email->send();
                 }
             }
         }
     }
 }
Пример #6
0
 public function saveDesign()
 {
     $results = array();
     // check user login
     $user = $this->session->userdata('user');
     if (empty($user['id'])) {
         $results['error'] = 1;
         $results['login'] = 1;
         $results['msg'] = lang('design_msg_save_login');
         echo json_encode($results);
         exit;
     }
     $data = json_decode(file_get_contents('php://input'), true);
     $this->load->helper('file');
     $path = ROOTPATH . DS . 'media' . DS . 'assets' . DS . 'system';
     $temp = explode(';base64,', $data['image']);
     $buffer = base64_decode($temp[1]);
     $design = array();
     $design['user_id'] = $user['id'];
     $design['vectors'] = $data['vectors'];
     $design['teams'] = $data['teams'];
     $design['fonts'] = $data['fonts'];
     $designer_id = $data['designer_id'];
     // check design and author
     if ($data['design_file'] != '' && $designer_id == $design['user_id']) {
         // override file and update
         $file = $data['design_file'];
         $path_file = ROOTPATH . DS . str_replace('/', DS, $file);
         $id = $data['design_id'];
         $key = $data['design_key'];
     } else {
         // save new file
         $this->load->library('file');
         $file = new file();
         // create path file
         $date = new DateTime();
         $year = $date->format('Y');
         $file->create($path . DS . $year, 0755);
         $month = $date->format('m');
         $file->create($path . DS . $year . DS . $month, 0755);
         $key = strtotime("now") . rand();
         $file = $key . '.png';
         $path_file = $path . DS . $year . DS . $month . DS . $file;
         $file = 'media/assets/system/' . $year . '/' . $month . '/' . $file;
         $id = null;
         $design['design_id'] = $key;
     }
     if (!write_file($path_file, $buffer)) {
         $results['error'] = 1;
         $results['msg'] = lang('design_msg_save');
     } else {
         $design['image'] = $file;
         $design['product_id'] = $data['product_id'];
         $design['product_options'] = $data['product_color'];
         $design['title'] = '';
         $design['description'] = '';
         $design['system_id'] = '';
         $this->load->model('design_m');
         $id = $this->design_m->save($design, $id);
         if ($id > 0) {
             $results['error'] = 0;
             $content = array('design_id' => $id, 'design_key' => $key, 'designer_id' => $user['id'], 'design_file' => $file);
             $results['content'] = $content;
             // send email savedesign.
             //params shortcode email.
             $params = array('username' => $user['username'], 'url_design' => site_url('design/index/' . $data['product_id'] . '/' . $data['product_color'] . '/' . $key));
             //config email.
             $config = array('mailtype' => 'html');
             $subject = configEmail('sub_save_design', $params);
             $message = configEmail('save_design', $params);
             $this->load->library('email', $config);
             $this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
             $this->email->to($user['email']);
             $this->email->subject($subject);
             $this->email->message($message);
             $this->email->send();
         } else {
             $results['error'] = 1;
             $results['msg'] = lang('design_msg_save');
         }
     }
     echo json_encode($results);
 }
Пример #7
0
 function changePass()
 {
     // check ajax login.
     if ($this->input->post('ajax') !== false) {
         $ajax = true;
         $langFile = ROOTPATH . DS . 'media' . DS . 'data' . DS . 'lang.ini';
         $langdata = parse_ini_file($langFile);
     } else {
         $ajax = false;
     }
     //check token.
     if ($this->auth->checkToken() === false) {
         redirect(site_url('user/changepass'));
     }
     if ($data = $this->input->post('data')) {
         if (!isset($this->user['username']) && $this->input->post('key') == '') {
             if ($ajax) {
                 $userdata = $this->session->userdata('user');
                 echo $this->load->view('components/users/ajax', array('msg' => '', 'data' => $userdata), true);
                 return false;
             } else {
                 redirect(site_url() . 'user/register');
             }
         }
         $this->load->library('form_validation');
         // change pass when forget.
         if ($this->input->post('key') != '') {
             //check loggedin.
             if (isset($this->user['username']) && $this->user['username'] != '') {
                 redirect(site_url());
             }
             //set form.
             $this->form_validation->set_rules('data[password]', lang('new_password'), 'trim|required|min_length[6]|max_length[128]|matches[cf_password]');
             $this->form_validation->set_rules('cf_password', lang('cf_password'), 'trim|required|min_length[6]|max_length[128]');
             // validate true.
             if ($this->form_validation->run() == TRUE) {
                 $user = $this->users_m->getKey($this->input->post('key'));
                 if (count($user) && $user != false) {
                     $where = array('email' => $user->email);
                     if ($this->users_m->changePass($data['password'], $where)) {
                         // delete user temp.
                         $this->users_m->_table_name = 'users_temp';
                         $this->users_m->delete($user->id);
                         $this->session->set_flashdata('msg', lang('user_msg_change_password_success'));
                         //params shortcode email.
                         $params = array('username' => $user->username, 'password' => $data['password'], 'email' => $user->email, 'date' => date('Y-m-d H:i:s'));
                         //config email.
                         $config = array('mailtype' => 'html');
                         $subject = configEmail('sub_change_pass', $params);
                         $message = configEmail('change_pass', $params);
                         $this->load->library('email', $config);
                         $this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
                         $this->email->to($this->user['email']);
                         $this->email->subject($subject);
                         $this->email->message($message);
                         $this->email->send();
                     } else {
                         $this->session->set_flashdata('error', lang('user_error_change_password_error'));
                     }
                 } else {
                     $this->session->set_flashdata('error', lang('user_error_link_key_not_match'));
                 }
             } else {
                 $this->session->set_flashdata('error', validation_errors());
             }
             redirect(site_url() . 'user/changepass/' . $this->input->post('key'));
         }
         // change pass when loggedin.
         //set form.
         if ($ajax == false) {
             $this->form_validation->set_rules('data[old_password]', lang('old_password'), 'trim|required|min_length[6]|max_length[128]|callback_checkPassword');
         }
         $this->form_validation->set_rules('data[password]', lang('new_password'), 'trim|required|min_length[6]|max_length[128]|matches[cf_password]');
         $this->form_validation->set_rules('cf_password', lang('cf_password'), 'trim|required|min_length[6]|max_length[128]');
         // validate true.
         if ($this->form_validation->run() == TRUE) {
             if ($this->users_m->updatePass($data['password'], $this->user['id'])) {
                 //params shortcode email.
                 $params = array('username' => $this->user['username'], 'password' => $data['password'], 'email' => $this->user['email'], 'date' => date('Y-m-d H:i:s'));
                 //config email.
                 $config = array('mailtype' => 'html');
                 $subject = configEmail('sub_change_pass', $params);
                 $message = configEmail('change_pass', $params);
                 $this->load->library('email', $config);
                 $this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
                 $this->email->to($this->user['email']);
                 $this->email->subject($subject);
                 $this->email->message($message);
                 $this->email->send();
                 if ($ajax) {
                     $userdata = $this->session->userdata('user');
                     echo $this->load->view('components/users/ajax', array('msg' => lang('user_msg_change_password_success'), 'data' => $userdata), true);
                     return false;
                 } else {
                     $this->session->set_flashdata('msg', lang('user_msg_change_password_success'));
                 }
             } else {
                 if ($ajax) {
                     $userdata = $this->session->userdata('user');
                     echo $this->load->view('components/users/ajax', array('error' => lang('user_error_change_password_error'), 'data' => $userdata), true);
                     return false;
                 } else {
                     $this->session->set_flashdata('error', lang('user_error_change_password_error'));
                 }
             }
         } else {
             if ($ajax) {
                 $userdata = $this->session->userdata('user');
                 echo $this->load->view('components/users/ajax', array('error' => validation_errors(), 'data' => $userdata), true);
                 return false;
             } else {
                 $this->session->set_flashdata('error', validation_errors());
             }
         }
     }
     redirect(site_url('user/changepass'));
 }