/** * * @param Controller $controller */ public function actionVoucher($controller) { $message = $controller->getUser()->message(); if (isset($_POST['remove'])) { foreach ($_POST['delete'] as $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->delete('voucher')->where('id = ?')); $sql->execute(array($value)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } $sql = CShop::app()->getDb()->query(QueryBuilder::getInstance()->select()->from('voucher')); $content = '<div class="title">مدیریت کد های تخفیف</div> <div class="content"> <form action="" method="post"> <table> <tr> <th>ردیف</th> <th>کد</th> <th>ارزش</th> <th>زمان پایان</th> <th>تعداد باقی مانده</th> <th>مدیریت</th> <th><a href="#" onclick="check(this)">انتخاب</a></th> </tr>'; $i = 1; while ($item = $sql->fetch()) { $content .= '<tr>'; $content .= '<td>' . $i++ . '</td>'; $content .= '<td>' . $item['code'] . '</td>'; $content .= '<td>' . $item['value'] . '%</td>'; $content .= '<td>' . jDateTime::date(CShop::app()->systemConfig()->timeformat, $item['paymenttime'] ? $item['paymenttime'] : $item['time']) . '</td>'; $content .= '<td>' . $item['maxuse'] . '</td>'; $content .= '<td><a href="' . self::getActionLink('editvoucher', $this->id) . '&vid=' . $item['id'] . '">ویرایش</a></td>'; $content .= '<td><input type="checkbox" name="delete[]" value="' . $item['id'] . '"></td>'; $content .= '</tr>'; } $content .= '</table><div style="text-align: left"><input type="submit" value="ذخیره" name="update"><input type="submit" value="حذف" name="remove"></div></form></div>'; $controller->renderWithContent($content, array('message' => $message)); }
/** * @param Controller $controller */ public function actionImport($controller) { $content = '<div class="title">انتفال</div>'; $db = CShop::app()->getDb(); $lasterrormode = $db->getAttribute(PDO::ATTR_ERRMODE); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); if (isset($_POST['start'])) { try { $freerdb = new Database(true, $this->dbname, $this->dbserver, $this->dbusername, $this->dbpassword); //Payment import $items = $freerdb->query(QueryBuilder::getInstance('')->select()->from('payment')); $paymentids = array(); while ($row = $items->fetch()) { $sql = $db->prepare(QueryBuilder::getInstance()->insert('payment')->into(array('amount', 'requesttime', 'status', 'clientip', 'paymenttime', 'reference', 'gatewayid'), true, false)); $status = $row['payment_status'] == 1 ? Application::STATUS_PENDING : Application::STATUS_COMPLETE; $sql->execute(array($row['payment_amount'], $row['payment_time'], $status, $row['payment_ip'], $row['payment_time'], $row['payment_res_num'], $this->gatewayid)); $paymentids[$row['payment_id']] = $db->lastInsertId(); if ($this->email) { $sql = $db->prepare(QueryBuilder::getInstance()->insert('payment_meta')->into(array('inputid', 'paymentid', 'value'), true, false)); $sql->execute(array($this->email, $paymentids[$row['payment_id']], $row['payment_email'])); } if ($this->mobile) { $sql = $db->prepare(QueryBuilder::getInstance()->insert('payment_meta')->into(array('inputid', 'paymentid', 'value'), true, false)); $sql->execute(array($this->mobile, $paymentids[$row['payment_id']], $row['payment_mobile'])); } } //Category import $items = $freerdb->query(QueryBuilder::getInstance('')->select()->from('category')); $categoryids = array(); while ($row = $items->fetch()) { $sql = $db->prepare(QueryBuilder::getInstance()->insert('category')->into(array('name', 'description', '`order`'), true, false)); $sql->execute(array($row['category_title'], '', $row['category_order'])); $categoryids[$row['category_id']] = $db->lastInsertId(); } //Product AND item import $items = $freerdb->query(QueryBuilder::getInstance('')->select()->from('product')); while ($row = $items->fetch()) { $sql = $db->prepare(QueryBuilder::getInstance()->insert('product')->into(array('name', 'description', 'price', '`order`', 'categoryid'), true, false)); $sql->execute(array($row['product_title'], $row['product_body'], $row['product_price'], 0, $categoryids[$row['product_category']])); $productid = $db->lastInsertId(); $sql = $db->prepare(QueryBuilder::getInstance()->insert('field')->into(array('productid', 'name', 'type'), true, false)); $sql->execute(array($productid, $row['product_first_field_title'], 'text')); $field1 = $db->lastInsertId(); $sql = $db->prepare(QueryBuilder::getInstance()->insert('field')->into(array('productid', 'name', 'type'), true, false)); $sql->execute(array($productid, $row['product_second_field_title'], 'text')); $field2 = $db->lastInsertId(); $sql = $db->prepare(QueryBuilder::getInstance()->insert('field')->into(array('productid', 'name', 'type'), true, false)); $sql->execute(array($productid, $row['product_third_field_title'], 'text')); $field3 = $db->lastInsertId(); $cards = $freerdb->query(QueryBuilder::getInstance('')->select("*,DECODE(card_first_field,'{$this->salt}') AS card_first_field,DECODE(card_second_field,'{$this->salt}') AS card_second_field,DECODE(card_third_field,'{$this->salt}') AS card_third_field")->from('card')->where('card_product=' . $row['product_id'])); while ($card = $cards->fetch()) { //pament id $sql = $db->prepare(QueryBuilder::getInstance()->insert('item')->into(array('productid', 'status', 'createtime', 'paymentid'), true, false)); $status = $card['card_status'] == 1 ? Application::STATUS_PENDING : Application::STATUS_COMPLETE; $sql->execute(array($productid, $status, $card['card_time'], $paymentids[$card['card_payment_id']])); $itemid = $db->lastInsertId(); $sql = $db->prepare(QueryBuilder::getInstance()->insert('value')->into(array('fieldid', 'itemid', 'value'), true, false)); $sql->execute(array($field1, $itemid, $card['card_first_field'])); $sql = $db->prepare(QueryBuilder::getInstance()->insert('value')->into(array('fieldid', 'itemid', 'value'), true, false)); $sql->execute(array($field2, $itemid, $card['card_second_field'])); $sql = $db->prepare(QueryBuilder::getInstance()->insert('value')->into(array('fieldid', 'itemid', 'value'), true, false)); $sql->execute(array($field3, $itemid, $card['card_third_field'])); } } $content .= 'انتقال انجام شد'; } catch (Exception $e) { $content .= 'خطا! ' . $e->getMessage(); } } else { $content .= '<form method="post"> <input type="submit" value="شروع" name="start"> </form>'; } $db->setAttribute(PDO::ATTR_ERRMODE, $lasterrormode); $controller->renderWithContent($content); }
/** * * @param Controller $controller */ public function actionPage($controller) { $message = $controller->getUser()->message(); if (isset($_POST['update'])) { foreach ($_POST['order'] as $key => $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->update('page')->set('`order` = ?')->where('id = ?')); $sql->execute(array($value, $key)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } elseif (isset($_POST['remove'])) { foreach ($_POST['delete'] as $value) { $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->delete('page')->where('id = ?')); $sql->execute(array($value)); } $message['content'] = 'تغییرات با موفقیت ذخیره شد'; $message['type'] = 'success'; $controller->getUser()->message($message); CShop::app()->redirect($_SERVER['REQUEST_URI']); } $sql = CShop::app()->getDb()->query(QueryBuilder::getInstance()->select()->from('page')->order('`order`')); $content = '<div class="title">مدیریت صفحه ها</div> <div class="content"> <form action="" method="post"> <table> <tr> <th>ردیف</th> <th>نام</th> <th>ترتیب</th> <th>مدیریت</th> <th><a href="#" onclick="check(this)">انتخاب</a></th> </tr>'; $i = 1; while ($item = $sql->fetch()) { $content .= '<tr>'; $content .= '<td>' . $i++ . '</td>'; $content .= '<td>' . $item['name'] . '</td>'; $content .= '<td><input type="text" name="order[' . $item['id'] . ']" value="' . $item['order'] . '"></td>'; $content .= '<td><a href="' . self::getActionLink('editpage', $this->id) . '&pid=' . $item['id'] . '">ویرایش</a></td>'; $content .= '<td><input type="checkbox" name="delete[]" value="' . $item['id'] . '"></td>'; $content .= '</tr>'; } $content .= '</table><div style="text-align: left"><input type="submit" value="ذخیره" name="update"><input type="submit" value="حذف" name="remove"></div></form></div>'; $controller->renderWithContent($content, array('message' => $message)); }