function do_edit_save($aid, $params) { $uid = false; if (array_key_exists('id', $params)) { $uid = $params['id']; $pass = trim($params['password']); unset($params['password']); cf\api\admin\doAction($aid, $params); if ($pass) { cf\User::setPassword($uid, $pass); } } else { $uid = cf\User::register($params['login'], $params['password'], $params['name'], $params['email'], $params['descr']); } if (cf\param::exist('roles')) { $roles = array_keys(cf\param::get('roles')); cf\execQuery('DELETE FROM cf_user_roles WHERE user_id=:uid', array('uid' => $uid)); $q = cf\createQuery('INSERT INTO cf_user_roles (user_id,role_id) VALUES(:userId,:roleId)'); $q->setParam('userId', $uid); foreach ($roles as $rid) { $q->setParam('roleId', $rid); $q->execute(); } } }
function do_edit_save($aid, $params) { $pid = cf\api\admin\doAction($aid, $params); if (array_key_exists('id', $params)) { $pid = $params['id']; } //update categories $pos = cf\query2arrays('SELECT group_id,sort_order FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid), false, 'group_id'); cf\execQuery('DELETE FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid)); $categories = cf\param::exist('category') ? cf\param::get('category') : array(); $q = cf\createQuery('INSERT INTO cf_products_in_groups (group_id,product_id,sort_order) VALUES(:groupId,:productId,:sortOrder)', array('productId' => $pid)); foreach ($categories as $catId) { $q->setParam('groupId', $catId); $q->setParam('sortOrder', array_key_exists($catId, $pos) ? $pos[$catId]['sort_order'] : 500); $q->execute(); } //update attributes if (cf\param::exist('attributes')) { $attrValues = cf\param::get('attributes'); $attributes = new cf\ProductAttributes($pid, true); foreach ($attributes as $attr) { if (array_key_exists($attr->id(), $attrValues)) { $attr->setValue($attrValues[$attr->id()]); } } $product = new cf\Product($pid); $product->setAttributes($attributes); } }
function do_edit_save($aid, $params) { $pid = cf\api\admin\doAction($aid, $params); if (array_key_exists('id', $params)) { $pid = $params['id']; } global $fk; if (!$fk) { //it's not an option //update categories $pos = cf\query2arrays('SELECT page_id,sort_order FROM cf_products_in_category WHERE product_id=:id', array('id' => $pid), false, 'page_id'); cf\execQuery('DELETE FROM cf_products_in_category WHERE product_id=:id', array('id' => $pid)); $categories = cf\param::exist('category') ? cf\param::get('category') : array(); $q = cf\createQuery('INSERT INTO cf_products_in_category (page_id,product_id,sort_order) VALUES(:categoryId,:productId,:sortOrder)', array('productId' => $pid)); foreach ($categories as $catId) { $q->setParam('categoryId', $catId); $q->setParam('sortOrder', array_key_exists($catId, $pos) ? $pos[$catId]['sort_order'] : 500); $q->execute(); } } //update attributes if (cf\param::exist('attributes')) { cf\execQuery("DELETE FROM cf_product_attributes WHERE product_id=:id", array('id' => $pid)); $q = cf\createQuery("INSERT INTO cf_product_attributes (product_id, attribute_id, attribute_value) VALUES (:pid,:aid,:val)"); $attrValues = cf\param::get('attributes'); foreach ($attrValues as $id => $val) { $q->setParam('pid', $pid); $q->setParam('aid', $id); $q->setParam('val', $val); $q->execute(); } } }
function do_edit_save($aid, $params) { global $step, $smarty, $view; if (array_key_exists('yml_id', $params)) { $step = 3; $ymlID = $params['yml_id']; $path = $params['file_path']; $smarty->assign('ymlID', $ymlID); exec('php ' . cf\Config::path . "cron/shop/import/yml.php {$ymlID} {$path} &"); } else { $step = 2; $path = sys_get_temp_dir() . uniqid('yml'); if (array_key_exists('url', $_FILES)) { if ($_FILES['url']['type'] == 'url') { $params['url'] = $_FILES['url']['name']; if (!copy($_FILES['url']['name'], $path)) { die("Can't copy file from URL:" . $_FILES['url']['name']); } } elseif ($_FILES['url']['type']) { if (UPLOAD_ERR_OK != $_FILES['url']['error'] || !is_uploaded_file($_FILES['url']['tmp_name'])) { die("The file could't be uploaded [" . $_FILES['url']['error'] . "], check 'upload_max_filesize' or 'post_max_size' in php.ini"); } if (!move_uploaded_file($_FILES['url']['tmp_name'], $path)) { die("Can't move uploaded file"); } } else { if (!copy($params['url'], $path)) { die("Can't copy file from URL:" . $params['url']); } } unset($_FILES['url']); } $id = cf\api\admin\doAction(cf\param::get('aid'), $params); $assigned = array(); if (array_key_exists('id', $params)) { $id = $params['id']; $importCat = cf\query2arrays("SELECT from_id,to_id FROM cf_import_yml_categories WHERE yml_id=:id", array('id' => $id)); foreach ($importCat as $fromTo) { $assigned[$fromTo['from_id']] = $fromTo['to_id']; } } $smarty->assign('ymlID', $id); $smarty->assign('assigned', json_encode($assigned)); $smarty->assign('file_path', $path); global $categories; loadCategoriesFromYML($path); $smarty->assign('allCategories', json_encode(createCategoriesTree())); } }
function do_edit_save($aid, $params) { $channelId = cf\api\admin\doAction($aid, $params); if (array_key_exists('id', $params)) { $channelId = $params['id']; } //update categories cf\execQuery('DELETE FROM cf_rss_channel_to_category WHERE channel_id=:id', array('id' => $channelId)); $cats = cf\param::exist('cat') ? cf\param::get('cat') : array(); $q = cf\createQuery('INSERT INTO cf_rss_channel_to_category (category_id,channel_id) VALUES(:catId,:channelId)', array('channelId' => $channelId)); foreach ($cats as $catId) { $q->setParam('catId', $catId); $q->execute(); } }
function do_edit_save($aid, $params) { $iId = cf\api\admin\doAction($aid, $params); if (array_key_exists('id', $params)) { $iId = $params['id']; } //update albums $pos = cf\query2arrays('SELECT album_id,sort_order FROM cf_gallery_image_in_album WHERE image_id=:id', array('id' => $iId), false, 'album_id'); cf\execQuery('DELETE FROM cf_gallery_image_in_album WHERE image_id=:id', array('id' => $iId)); $albums = cf\param::exist('album') ? cf\param::get('album') : array(); $q = cf\createQuery('INSERT INTO cf_gallery_image_in_album (album_id,image_id,sort_order) VALUES(:albumId,:imageId,:sortOrder)', array('imageId' => $iId)); foreach ($albums as $albumId) { $q->setParam('albumId', $albumId); $q->setParam('sortOrder', array_key_exists($albumId, $pos) ? $pos[$albumId]['sort_order'] : 500); $q->execute(); } }
$params = array_merge(cf\param::get('p'), $k); $do = cf\param::get('do'); $fileURLs = cf\param::get('URL', array()); foreach ($fileURLs as $fnm => $url) { if ($url) { $_FILES[$fnm] = array('name' => $url, 'type' => 'url'); } } if (function_exists('do_edit_save')) { do_edit_save($aid, $params); } else { cf\api\admin\doAction($aid, $params); } if ('save' == $do) { forward(cf\param::get('referer')); } } $action = cf\api\admin\getAction($aid, $k); $smarty->assign('k', json_encode($k)); $smarty->assign('view', $view); $smarty->assign('action', $action); $smarty->assign('referer', cf\param::get('referer')); $smarty->assign('goTab', cf\param::get('tab', 0)); $name = $k ? cf\api\admin\getNameByKey($view['id'], $k[$view['primary_key_field']]) : false; if (function_exists('do_edit_create')) { do_edit_create($k); } show(isset($tpl) ? $tpl : 'edit', $view['name'] . ($name ? ": {$name}" : '') . ' - ' . $action['name'], array(array($view['url'] . '?vid=' . $view['id'], $view['name']), array('', $action['name']))); } catch (Exception $e) { echo $e; }
<?php require_once 'init.php'; require_once cf\Config::path . 'api/shop.php'; try { $cat = cf\Group::get(cf\param::get('id')); } catch (Exception $e) { Header('Location: /error'); exit; } $smarty->assign('pageText', $cat->descr()); $smarty->assign('pageId', cf\api\page\getID('products')); $products = cf\api\shop\getProducts($cat->id()); foreach ($products as &$product) { $info = cf\api\shop\getProduct($product[0]); $product['attributes'] = $info['attributes']; } $smarty->assign('products', $products); show('category', $cat->name(), array(), $cat->pageTitle(), $cat->pageKeywords(), $cat->pageDescr());
<?php require_once 'core.php'; require_once cf\Config::path . 'api/admin.php'; $view = cf\api\admin\getView(cf\param::get('vid')); $smarty->assign('view', $view); $smarty->assign('fk', cf\param::exist('fk') ? cf\param::asInt('fk') : false); $name = $view['name']; if (cf\param::exist('tid') && cf\param::exist('fk')) { $name = cf\api\admin\getNameByKey(cf\param::get('tid'), cf\param::get('fk')); } show('list', $name);
<?php require_once 'core.php'; $nm = cf\query2var('SELECT name FROM cf_admin_categories WHERE id=:id', array('id' => cf\param::get('id'))); show('category', $nm, array(array('', $nm)));
} try { list($module, $method) = explode('.', cf\param::get('method')); require_once \cf\Config::path . "api/{$module}.php"; $method = "cf\\api\\{$module}\\{$method}"; if (!function_exists($method)) { throw new Exception("Invalid method - {$method}"); } $returnHTML = false; $res = call_user_func_array($method, params2MethodArgs($method, cf\param::toArray())); if (cf\param::exist('return')) { $retVarName = cf\param::get('return'); ${$retVarName} = $res; } if (cf\param::exist('forward')) { $url = cf\param::get('forward'); if ('referer' == $url) { $url = $_SERVER['HTTP_REFERER']; } else { eval('$url="' . $url . '";'); } forward($url); } if (!$returnHTML) { header('Content-Type: application/json'); $res = json_encode($res); } echo $res; } catch (Exception $e) { header("HTTP/1.0 500 Error occured"); echo $e;
define('NO_AUTH', 1); require_once 'core.php'; $err = ''; $user = cf\User::getLoggedIn(); if (cf\param::exist('logout')) { if ($user) { $user->logout(); } } elseif ($user) { forward(cf\param::exist('referer') ? cf\param::asString('referer') : 'index.php'); } elseif (cf\param::exist('log')) { $log = cf\param::asString('log'); $pwd = cf\param::asString('pwd'); try { if ($log && $pwd && cf\User::login($log, $pwd, cf\param::exist('remember'))) { forward(cf\param::exist('referer') ? cf\param::asString('referer') : 'index.php'); } } catch (Exception $e) { switch ($e->getCode()) { case cf\User::ERR_INVALID_USER: $err = 'Неправильное имя пользователя'; break; case cf\User::ERR_PASSWORD_INCORRECT: $err = 'Неправильный пароль'; break; } } } $smarty->assign('errMsg', $err); $smarty->display('login.tpl');
<?php require_once 'core.php'; $id = cf\param::get('id'); $nm = cf\query2var('SELECT name FROM cf_admin_categories WHERE id=:id', array('id' => $id)); $smarty->assign('childmenu', MainMenu::children($id)); show('category', $nm);
<?php require_once 'init.php'; $page = cf\api\page\get(cf\param::get('id')); $smarty->assign('pageText', cf\api\page\getText($page['id'])); $smarty->assign('pageId', $page['id']); $crumbs = array(); foreach ($page['branch'] as $p) { $crumbs[] = array('name' => $p['menu_name'], 'link' => $p['path']); } show('page', $page['name'], $crumbs, $page['title'], $page['keywords'], $page['descr']);