Пример #1
0
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);
    }
}
Пример #2
0
function addProduct($offer, $categories)
{
    global $ymlID, $catMatch, $sellerID, $newState;
    if (!count(array_intersect($categories, array_keys($catMatch)))) {
        return false;
    }
    static $qFind = null;
    if (!$qFind) {
        cf\createStaticQuery($qFind, "SELECT id FROM cf_products WHERE seller_id=:seller_id AND link=:link", array('seller_id' => $sellerID));
    }
    $found = $qFind->setParam('link', $offer['link'])->execute()->fetch();
    if ($found) {
        static $qUpdatePrice = null;
        if (!$qUpdatePrice) {
            cf\createStaticQuery($qUpdatePrice, "UPDATE cf_products SET price=:price WHERE id=:id");
        }
        $qUpdatePrice->setParam('price', $offer['price'])->setParam('id', $found['id'])->execute();
        global $updatedCount;
        ++$updatedCount;
        return $found['id'];
    } else {
        $product = array_merge(array('code' => null, 'manufacturer_id' => null, 'name' => null, 'model' => null, 'short_descr' => null, 'full_descr' => null, 'price' => null, 'discount' => null, 'state_id' => $newState ? $newState : 1, 'enabled_from' => null, 'enabled_to' => null, 'tags' => null, 'article' => null, 'tag_title' => null, 'tag_meta_keywords' => null, 'tag_meta_descr' => null, 'image1' => null, 'image1_text' => null, 'image2' => null, 'image2_text' => null, 'image3' => null, 'image3_text' => null, 'image4' => null, 'image4_text' => null, 'image5' => null, 'image5_text' => null, 'image6' => null, 'image6_text' => null, 'image7' => null, 'image7_text' => null, 'image8' => null, 'image8_text' => null, 'image9' => null, 'image9_text' => null, 'image10' => null, 'image10_text' => null, 'image11' => null, 'image11_text' => null, 'image12' => null, 'image12_text' => null, 'image13' => null, 'image13_text' => null, 'image14' => null, 'image14_text' => null, 'image15' => null, 'image15_text' => null, 'image16' => null, 'image16_text' => null, 'image17' => null, 'image17_text' => null, 'image18' => null, 'image18_text' => null, 'image19' => null, 'image19_text' => null, 'image20' => null, 'image20_text' => null, 'seller_id' => $sellerID, 'link' => null), $offer);
        $pid = cf\api\admin\doAction('product_add', $product);
        foreach ($categories as $fromCat) {
            if (array_key_exists($fromCat, $catMatch)) {
                cf\api\admin\doAction('product_in_group_add', array('group_id' => $catMatch[$fromCat]['to_id'], 'product_id' => $pid, 'sort_order' => 500));
            }
        }
        global $addedCount;
        ++$addedCount;
        return $pid;
    }
}
Пример #3
0
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();
        }
    }
}
Пример #4
0
function add()
{
    $id = \cf\api\admin\doAction('tmp_file_add', array('f' => ''));
    global $returnHTML;
    $returnHTML = true;
    return json_encode(array($id, \cf\query2var('SELECT f FROM cf_tmp_files WHERE id=:id', array('id' => $id))));
}
Пример #5
0
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();
        }
    }
}
Пример #6
0
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));
}
Пример #7
0
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()));
    }
}
Пример #8
0
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();
    }
}
Пример #9
0
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();
    }
}
Пример #10
0
 $view = cf\api\admin\getView(cf\param::get('vid'));
 $aid = cf\param::get('aid');
 $k = cf\param::exist('k') ? cf\param::get('k') : array();
 if (cf\param::exist('do')) {
     $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);
 }
Пример #11
0
function send($to, $subject, $text = '')
{
    $msgId = \cf\api\admin\doAction('message_send', array('to' => $to, 'subject' => $subject, 'text' => $text));
    //notify by email ?
    return $msgId;
}