public static function order($name, $email = '', $phone = '', $address = '', $comment = '', $adminNotifyTplID = 'admin_purchase_notify', $customerNotifyTplID = 'user_purchase_notify') { global $db; $user = \cf\User::getLoggedIn(); $productList = ''; $products = \cf\api\cart\getList(); if (!array_key_exists('contents', $products) || !count($products['contents'])) { return false; } $tpl = new MailTemplate('order'); execQuery("\n\t\t\tINSERT INTO cf_orders (created,customer_name, customer_email, customer_phone, customer_address, customer_comments, comments)\n\t\t\tVALUES(NOW(),:name, :email, :phone, :address, :comments, :contents)", array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comments' => $comment, 'contents' => $tpl->parseBody(array('cart' => $products)))); $orderId = $db->lastInsertId(); $msgParams = array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comment' => $comment, 'order' => $orderId, 'total' => $products['total'], 'products' => $products['contents']); \cf\api\cart\clear(); $mail = new \PHPMailer(); $mail->CharSet = 'UTF-8'; if ($adminNotifyTplID) { $tpl = new MailTemplate($adminNotifyTplID); $mail->Subject = $tpl->parseSubject($msgParams); $mail->MsgHTML($tpl->parseBody($msgParams)); foreach ($tpl->recipients() as $address) { $mail->addAddress($address); } $mail->Send(); } $mail->clearAddresses(); if ($customerNotifyTplID && $email) { $tpl = new MailTemplate($customerNotifyTplID); $mail->Subject = $tpl->parseSubject($msgParams); $mail->MsgHTML($tpl->parseBody($msgParams)); $mail->addAddress($email); $mail->Send(); } return $orderId; }
function addReview($productId, $rating, $review = '') { $userId = null; $user = \cf\User::getLoggedIn(); if ($user) { $userId = $user->id(); } return \cf\api\admin\doAction('review_add', array('product_id' => $productId, 'rating' => $rating, 'review' => $review, 'user_id' => $userId)); }
function sendMessage($email, $subject, $txt) { $email = trim($email); $uid = \cf\User::findByEmail($email); if (!$uid) { return false; } $m = new \cf\Mail($subject, $txt); try { \cf\Mail::send($email, $m); } catch (Exception $e) { return false; } return true; }
public static function order($name, $email = '', $phone = '', $address = '', $comment = '', $notifyGroup = 'admin', $notifyCustomer = true) { global $db; $user = \cf\User::getLoggedIn(); $productList = ''; $products = \cf\api\cart\getList(); if (count($products) < 2) { return false; } for ($i = 1; $i < count($products); ++$i) { $productList .= "{$products[$i]['id']} {$products[$i]['name']} [{$products[$i]['price']}] - {$products[$i]['amount']} <br>"; } $productList .= "<br><strong>Итого</strong>: {$products[0]['total_price']}"; execQuery("\n\t\t\tINSERT INTO cf_orders (created,customer_name, customer_email, customer_phone, customer_address, customer_comments, comments)\n\t\t\tVALUES(NOW(),:name, :email, :phone, :address, :comments, :products)", array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comments' => $comment, 'products' => $productList)); $orderId = $db->lastInsertId(); \cf\api\cart\clear(); $msgParams = array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comment' => $comment, 'order' => $orderId, 'total' => array_shift($products), 'products' => $products); if ($notifyGroup) { $emails = query2vector("SELECT email FROM cf_users INNER JOIN cf_user_roles ON cf_users.id=cf_user_roles.user_id WHERE cf_user_roles.role_id=:id", array('id' => $notifyGroup)); if (!empty($emails)) { $tpl = new MailTemplate('admin_purchase_notify'); $mail = new \PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->Subject = $tpl->parseSubject($msgParams); $mail->MsgHTML($tpl->parseBody($msgParams)); foreach ($emails as $a) { $mail->AddAddress($a); } $mail->Send(); } } if ($notifyCustomer && $email) { $tpl = new MailTemplate('user_purchase_notify'); $mail = new \PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->Subject = $tpl->parseSubject($msgParams); $mail->MsgHTML($tpl->parseBody($msgParams)); $mail->AddAddress($email); @$mail->Send(); } return $orderId; }
/** also deletes files */ function doDelete($aid, $params) { $user = \cf\User::getLoggedIn(); if (!array_key_exists(0, $params)) { $params = array($params); } $action = getAction($aid); $qFiles = null; if ($action['params_query']) { $fileFields = array(); foreach ($action['params'] as $param) { if ($param['type'] == 'File') { $fileFields[] = $param['name']; } } if (!empty($fileFields)) { $qFiles = \cf\createQuery('SELECT ' . implode(',', $fileFields) . ' FROM (' . $action['params_query'] . ') t'); } } eval('$sql="' . $action['query'] . '";'); $q = \cf\createQuery($sql); foreach ($params as $p) { if ($qFiles) { foreach ($qFiles->setParams($p)->execute()->fetch() as $f) { @unlink($_SERVER['DOCUMENT_ROOT'] . "/{$f}"); } } $q->setParams($p)->execute(); } }
<?php /** reserved parameters names: method mandatory forward URL to forward (return variable name can be included e.g. page.php?id=$return) or 'referer' return name of return variable in forward */ require_once 'config.php'; require_once 'param.php'; require_once 'user.php'; $user = \cf\User::getLoggedIn(); function params2MethodArgs($method, $params) { $funcInfo = new ReflectionFunction($method); $args = array(); foreach ($funcInfo->getParameters() as $paramInfo) { $nm = $paramInfo->getName(); $val = null; if (!array_key_exists($nm, $params)) { if ($paramInfo->isDefaultValueAvailable()) { $val = $paramInfo->getDefaultValue(); } if (is_null($val) && !$paramInfo->isOptional()) { throw new Exception("Parameter [{$nm}] of [{$method}] can not be null"); } } else { $val = $params[$nm]; } $classInfo = $paramInfo->getClass(); if ($classInfo) {
function clear() { $user = \cf\User::getLoggedIn(); if ($user) { \cf\execQuery('DELETE FROM cf_cart WHERE user_id=:uid', array('uid' => $user->id())); } else { $c = \cf\Cookie::retrieve('cyberfish_cart'); if ($c) { $c->delParam('ready'); $c->setParam('ready', array()); $c->set(); } } return getList(); }
/** @param $bulkParams array( array('paramName1'=>paramVal1,...) ) */ function doActionBulk($id, $bulkParams, $params = array()) { $user = \cf\User::getLoggedIn(); $sql = \cf\query2var('SELECT query FROM cf_admin_action WHERE id=:id', array('id' => $id)); eval('$sql="' . $sql . '";'); foreach ($params as $nm => $v) { $params[$nm] = $v ? $v : null; } $q = \cf\createQuery($sql, $params); foreach ($bulkParams as $p) { $q->setParams($p)->execute(); } }