Example #1
0
    public function sendingMail(&$payment, &$items)
    {
        $body = '<meta charset="utf-8"><div style="direction: rtl; width: 500px; margin-top: 20px; margin-right: auto; margin-bottom: 20px; margin-left: auto;">';
        foreach ($items as $item) {
            $body .= '<div style="direction: rtl; font-family: tahoma; margin-top: 20px;">
				<div style="direction: rtl; height: 25px; line-height: 27px; text-align: center; color: #fff; font-size: 16px; border-top-color: #eaeaea; border-right-color: #eaeaea; border-bottom-color: #eaeaea; border-left-color: #eaeaea; border-top-style: solid; border-right-style: solid; border-bottom-style: none; border-left-style: solid; border-top-width: 3px; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; background-color: #10BBE6;" align="center">' . $item[0]['name'] . '</div>
				<div style="direction: rtl; border-top-color: #eaeaea; border-right-color: #eaeaea; border-bottom-color: #eaeaea; border-left-color: #eaeaea; border-top-style: dashed; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 3px; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px;">
					<table style="width: 100%; border-collapse: collapse; border-top-style: hidden; border-left-style: hidden; border-right-style: hidden; border-bottom-style: hidden; table-layout: fixed;">';
            $td = $th = '';
            foreach ($item as $i) {
                if (!isset($i['value'])) {
                    continue;
                }
                $th .= '<th style="height: 20px; text-align: center; white-space: nowrap; border-top-color: #b7b7b7; border-right-color: #b7b7b7; border-bottom-color: #b7b7b7; border-left-color: #b7b7b7; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: #ccc;" align="center" bgcolor="#ccc">' . $i['fieldname'] . '</th>';
                $td .= '<td style="height: 30px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; border-top-color: #b7b7b7; border-right-color: #b7b7b7; border-bottom-color: #b7b7b7; border-left-color: #b7b7b7; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px;" align="center" valign="middle">' . Item::proccess($i['type'], $i['value']) . '</td>';
            }
            $body .= '<tr>' . $th . '</tr>';
            $body .= '<tr>' . $td . '</tr>';
            $body .= '</table>	
				</div>
				<div class="bottom" style="direction: rtl; font-size: 14px; font-style: italic; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px;">' . $item[0]['description'] . '</div>';
        }
        $body .= '</div>';
        CShop::import(CShop::$librarypath . '/PHPMailer.php', true);
        if ($this->signature) {
            $body = $body . '<br/><hr>' . $this->signature;
        }
        $mail = new PHPMailer(true);
        try {
            if ($this->smtpauth == 1) {
                $mail->IsSMTP();
            }
            $mail->SMTPAuth = $this->smtpauth == 1 ? true : false;
            $mail->Username = $this->smtpusername;
            $mail->Password = $this->smtppassword;
            $mail->Host = $this->smtphost;
            $mail->Port = $this->smtpport;
            $mail->SMTPSecure = $this->smtpsecure;
            $mail->AddReplyTo($this->from, $this->fromname);
            $mail->SetFrom($this->from, $this->fromname);
            $mail->AddAddress($payment['input'][$this->input]['value'], $payment['input'][$this->input]['value']);
            $mail->CharSet = 'UTF-8';
            $mail->Subject = $this->subject;
            $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
            // optional - MsgHTML will create an alternate automatically
            $mail->MsgHTML($body);
            $mail->Send();
            return true;
        } catch (phpmailerException $e) {
            $return = $e->errorMessage();
            //Pretty error messages from PHPMailer
        } catch (Exception $e) {
            $return = $e->getMessage();
            //Boring error messages from anything else!
        }
        return $return;
    }
Example #2
0
 public function actionPlugin()
 {
     $message = $this->user->message();
     if (isset($_POST['update'])) {
         foreach ($_POST['order'] as $key => $value) {
             $sql = $this->db->prepare(QueryBuilder::getInstance()->update('plugin')->set('`order` = ?')->where('id = ?'));
             $sql->execute(array($value, $key));
         }
         $message['content'] = 'تغییرات با موفقیت ذخیره شد';
         $message['type'] = 'success';
         $this->user->message($message);
         CShop::app()->redirect('plugin.php');
     } elseif (isset($_POST['remove'])) {
         foreach ($_POST['delete'] as $value) {
             $gateway = $this->db->prepare(QueryBuilder::getInstance()->select()->from('plugin')->where('id = ?'));
             $gateway->execute(array($value));
             $gateway = $gateway->fetch();
             $class = $gateway['class'];
             $file = Cshop::$pluginpath . DIRECTORY_SEPARATOR . $class . '.php';
             CShop::import($file, true);
             $class::uninstall($value);
             $sql = $this->db->prepare(QueryBuilder::getInstance()->delete('option')->where('category = ?'));
             $sql->execute(array($class));
             $sql = $this->db->prepare(QueryBuilder::getInstance()->delete('plugin')->where('id = ?'));
             $sql->execute(array($value));
         }
         $message['content'] = 'تغییرات با موفقیت ذخیره شد';
         $message['type'] = 'success';
         $this->user->message($message);
         CShop::app()->redirect('plugin.php');
     } elseif (isset($_GET['active'])) {
         CShop::app()->getCache()->flush();
         $gateway = $this->db->prepare(QueryBuilder::getInstance()->update('plugin')->set('status = (status+1)%2')->where('id = ?'));
         $gateway->execute(array($_GET['active']));
         $message['content'] = 'تغییرات با موفقیت ذخیره شد';
         $message['type'] = 'success';
         $this->user->message($message);
         CShop::app()->redirect('plugin.php');
     } elseif (isset($_GET['install'])) {
         $class = str_replace(chr(0), '', basename($_GET['install']));
         $file = Cshop::$pluginpath . DIRECTORY_SEPARATOR . $class . '.php';
         if (realpath(Cshop::$pluginpath) != dirname($file)) {
             exit("You are very clever !");
         }
         CShop::import($file);
         $data = $class::getData();
         $sql = $this->db->prepare(QueryBuilder::getInstance()->insert('plugin')->into(array('name', 'class', 'status'), true));
         $sql->execute(array('name' => $data['name'], 'class' => $class, 'status' => Application::STATUS_ACTIVE));
         $id = $this->db->lastInsertId();
         foreach ($class::getParameters() as $key => $value) {
             $this->db->exec(QueryBuilder::getInstance()->insert('option')->into('`key`,`category`,value,description')->values(array($key, $class, '', $value['name'])));
         }
         $data = $class::install($id);
         CShop::app()->getCache()->flush();
         $message['content'] = 'تغییرات با موفقیت ذخیره شد';
         $message['type'] = 'success';
         $this->user->message($message);
         CShop::app()->redirect('plugin.php');
     }
     $newplugins = array();
     foreach (glob(Cshop::$pluginpath . "/*.php") as $filename) {
         CShop::import($filename);
         $class = pathinfo($filename, PATHINFO_FILENAME);
         $data = $class::getData();
         $newplugins[$class] = array_merge($data, array('filename' => $class));
     }
     $plugins = array();
     $sql = $this->db->query(QueryBuilder::getInstance()->select()->from('plugin')->order('`order`'));
     while ($plugin = $sql->fetch()) {
         unset($newplugins[$plugin['class']]);
         $plugins[] = $plugin;
     }
     $this->render('admin/plugin', array('message' => $message, 'items' => $plugins, 'newplugins' => $newplugins));
 }
Example #3
0
 public function run($action, $param = array())
 {
     $this->initialise();
     if (is_array($action)) {
         $this->_action = $action[1];
         $action[0] .= 'Controller';
         CShop::import(Cshop::$corepath . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . $action[0] . '.php', true);
         $this->_controller = new $action[0]();
         $this->_controller->init();
         if (method_exists($this->_controller, 'action' . $action[1])) {
             call_user_func_array(array($this->_controller, 'runAction'), array('action' => $action[1], $param));
         }
     } else {
         $this->_action = $action;
         CShop::import(Cshop::$corepath . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'Controller.php', true);
         $this->_controller = new Controller();
         $this->_controller->init();
         if (isset($this->_externalActions[$action])) {
             foreach ($this->_externalActions[$action] as $a) {
                 if (isset($_GET[$a['param']])) {
                     call_user_func_array($a['callback'], array($_GET[$a['param']]));
                     CShop::app()->end();
                 }
             }
         }
         if (method_exists($this->_controller, 'action' . $action)) {
             call_user_func_array(array($this->_controller, 'runAction'), array($action, $param));
         }
     }
 }
Example #4
0
 public function actionPayment()
 {
     $message['content'] = '';
     $this->pageTitle = 'پرداخت';
     $items = array();
     try {
         if (!isset($_GET['gateway'])) {
             throw new Exception('اطلاعات پرداخت کامل نمی باشد');
         }
         $gateway = $this->db->prepare(QueryBuilder::getInstance()->select()->from('gateway')->leftJoin('option')->on('class = category')->where('gateway.id = ?'));
         $gateway->execute(array($_GET['gateway']));
         $gateway = $gateway->fetchAll();
         if (!$gateway[0]) {
             throw new Exception('اطلاعات پرداخت کامل نمی باشد');
         }
         CShop::import(Cshop::$gatewaypath . DIRECTORY_SEPARATOR . $gateway[0]['class'] . '.php');
         /* @var $plugin GatewayBase */
         $plugin = new $gateway[0]['class']($gateway[0]['id'], $gateway);
         $payment = $plugin->callbackGateway();
         if (!$payment) {
             throw new Exception('اطلاعات پرداخت کامل نمی باشد');
         }
         if ($payment['status'] == Application::STATUS_PENDING) {
             $sql = $this->db->prepare(QueryBuilder::getInstance()->update('payment')->set('status = ?,paymenttime=?')->where('id = ?'));
             $sql->execute(array($payment['status'] = Application::STATUS_COMPLETE, time(), $payment['id']));
             $sql = $this->db->prepare(QueryBuilder::getInstance()->update('item')->set('status = ?')->where('paymentid = ?'));
             $sql->execute(array(Application::STATUS_COMPLETE, $payment['id']));
             $sql = $this->db->prepare(QueryBuilder::getInstance()->select('item.*,value.fieldid,value,field.name AS fieldname,field.type,product.name,product.description')->from('item')->leftJoin('product')->on('product.id = item.productid')->leftJoin('value')->on('item.id = itemid')->leftJoin('field')->on('fieldid = field.id')->where('paymentid = ?'));
             $sql->execute(array($payment['id']));
             while ($item = $sql->fetch()) {
                 $items[$item['id']][] = $item;
             }
             $message['content'] = 'پرداخت با موفقیت انجام شد';
             $message['type'] = 'success';
             $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->select('input.*,value')->from('payment_meta')->leftJoin('input')->on('inputid = input.id')->where('paymentid = ?'));
             $sql->execute(array($payment['id']));
             $payment['input'] = array();
             while ($row = $sql->fetch()) {
                 $row['data'] = unserialize($row['data']);
                 $payment['input'][$row['id']] = $row;
             }
             CShop::app()->raise(Application::EVENT_AFTER_PAYMENT, array(&$payment, &$items));
         } else {
             throw new Exception('این سفارش قبلا پرداخت شده است.');
         }
     } catch (Exception $e) {
         $message['content'] = $e->getMessage();
     }
     $this->layout = 'layout/payment';
     CShop::app()->raise(Application::EVENT_ITEM_TYPE);
     $this->render('site/payment', array('message' => $message, 'items' => $items));
 }