Esempio n. 1
0
function ciniki_merchandise_imageList($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner, or sys admin.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.imageList');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Get the list of images
    //
    $strsql = "SELECT ciniki_merchandise_images.id, " . "ciniki_merchandise_images.product_id, " . "ciniki_merchandise_images.name, " . "ciniki_merchandise_images.permalink, " . "ciniki_merchandise_images.sequence, " . "ciniki_merchandise_images.flags, " . "ciniki_merchandise_images.image_id, " . "ciniki_merchandise_images.description " . "FROM ciniki_merchandise_images " . "WHERE ciniki_merchandise_images.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "";
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
    $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.merchandise', array(array('container' => 'images', 'fname' => 'id', 'fields' => array('id', 'product_id', 'name', 'permalink', 'sequence', 'flags', 'image_id', 'description'))));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (isset($rc['images'])) {
        $images = $rc['images'];
    } else {
        $images = array();
    }
    return array('stat' => 'ok', 'images' => $images);
}
Esempio n. 2
0
function ciniki_merchandise_productDeleteObjRef(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'objref_id' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Reference')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productDeleteObjRef');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.objref', $args['objref_id'], $ref_row['uuid'], 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    return array('stat' => 'ok');
}
Esempio n. 3
0
function ciniki_merchandise_imageGet($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'productimage_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Image')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.imageGet');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Load business settings
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings');
    $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $intl_timezone = $rc['settings']['intl-default-timezone'];
    $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
    $intl_currency = $rc['settings']['intl-default-currency'];
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat');
    $datetime_format = ciniki_users_datetimeFormat($ciniki, 'php');
    //
    // Return default for new Image
    //
    if ($args['productimage_id'] == 0) {
        $image = array('id' => 0, 'product_id' => '', 'name' => '', 'permalink' => '', 'sequence' => '', 'flags' => '1', 'image_id' => 0, 'description' => '');
    } else {
        $strsql = "SELECT ciniki_merchandise_images.id, " . "ciniki_merchandise_images.product_id, " . "ciniki_merchandise_images.name, " . "ciniki_merchandise_images.permalink, " . "ciniki_merchandise_images.sequence, " . "ciniki_merchandise_images.flags, " . "ciniki_merchandise_images.image_id, " . "ciniki_merchandise_images.description " . "FROM ciniki_merchandise_images " . "WHERE ciniki_merchandise_images.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_merchandise_images.id = '" . ciniki_core_dbQuote($ciniki, $args['productimage_id']) . "' " . "";
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'image');
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.7', 'msg' => 'Image not found', 'err' => $rc['err']));
        }
        if (!isset($rc['image'])) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.8', 'msg' => 'Unable to find Image'));
        }
        $image = $rc['image'];
    }
    return array('stat' => 'ok', 'image' => $image);
}
Esempio n. 4
0
function ciniki_merchandise_productSearch($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'start_needle' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Search String'), 'limit' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Limit')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner, or sys admin.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productList');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Get the list of products
    //
    $strsql = "SELECT ciniki_merchandise.id, " . "ciniki_merchandise.code, " . "ciniki_merchandise.name, " . "ciniki_merchandise.permalink, " . "ciniki_merchandise.status, " . "ciniki_merchandise.sequence, " . "ciniki_merchandise.flags, " . "ciniki_merchandise.unit_amount, " . "ciniki_merchandise.unit_discount_amount, " . "ciniki_merchandise.unit_discount_percentage, " . "ciniki_merchandise.taxtype_id, " . "ciniki_merchandise.inventory, " . "ciniki_merchandise.shipping_other, " . "ciniki_merchandise.shipping_CA, " . "ciniki_merchandise.shipping_US, " . "ciniki_merchandise.primary_image_id, " . "ciniki_merchandise.synopsis, " . "ciniki_merchandise.description " . "FROM ciniki_merchandise " . "WHERE ciniki_merchandise.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "";
    if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x1)) {
        $strsql .= "AND (code LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR code LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR name LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR name LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . ") ";
    } else {
        $strsql .= "AND (name LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR name LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . ") ";
    }
    if (isset($args['limit']) && is_numeric($args['limit']) && $args['limit'] > 0) {
        $strsql .= "LIMIT " . ciniki_core_dbQuote($ciniki, $args['limit']) . " ";
    } else {
        $strsql .= "LIMIT 25 ";
    }
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
    $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.merchandise', array(array('container' => 'products', 'fname' => 'id', 'fields' => array('id', 'code', 'name', 'permalink', 'status', 'sequence', 'flags', 'unit_amount', 'unit_discount_amount', 'unit_discount_percentage', 'taxtype_id', 'inventory', 'shipping_other', 'shipping_CA', 'shipping_US', 'primary_image_id', 'synopsis', 'description'))));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (isset($rc['products'])) {
        $products = $rc['products'];
        foreach ($products as $pid => $product) {
            if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x1) && $product['code'] != '') {
                $products[$pid]['display_name'] = $product['code'] . ' - ' . $product['name'];
            } else {
                $products[$pid]['display_name'] = $product['name'];
            }
        }
    } else {
        $products = array();
    }
    return array('stat' => 'ok', 'products' => $products);
}
Esempio n. 5
0
function ciniki_merchandise_productHistory($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'product_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Merchandise Product'), 'field' => array('required' => 'yes', 'blank' => 'no', 'name' => 'field')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner, or sys admin
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productHistory');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbGetModuleHistory');
    return ciniki_core_dbGetModuleHistory($ciniki, 'ciniki.merchandise', 'ciniki_merchandise_history', $args['business_id'], 'ciniki_merchandise', $args['product_id'], $args['field']);
}
Esempio n. 6
0
function ciniki_merchandise_productDelete(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'product_id' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Merchandise Product'), 'object' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Object'), 'object_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Object ID')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productDelete');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Get the current settings for the merchandise product
    //
    $strsql = "SELECT id, uuid " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'product');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (!isset($rc['product'])) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.16', 'msg' => 'Merchandise Product does not exist.'));
    }
    $product = $rc['product'];
    //
    // Be default, delete everything
    //
    $delete_ref = 'no';
    $delete_refs = 'yes';
    $delete_product = 'yes';
    //
    // If the delete was done via an object, then check if that was the only object referencing
    // the product. If multiple objects are referencing the product, only delete the objref, leave the product.
    //
    if (isset($args['object']) && $args['object'] != '' && isset($args['object_id'])) {
        $delete_refs = 'no';
        $strsql = "SELECT id, uuid, object, object_id " . "FROM ciniki_merchandise_objrefs " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'product');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if (isset($rc['rows'])) {
            foreach ($rc['rows'] as $row) {
                if ($row['object'] == $args['object'] && $row['object_id'] == $args['object_id']) {
                    $delete_ref = 'yes';
                    $ref_row = $row;
                } else {
                    // Multiple obj refs, leave the product
                    $delete_product = 'no';
                }
            }
        }
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Remove the object reference
    //
    if ($delete_ref == 'yes' && isset($ref_row)) {
        $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.objref', $ref_row['id'], $ref_row['uuid'], 0x4);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
    }
    if ($delete_refs == 'yes') {
        //
        // Remove the objrefs
        //
        $strsql = "SELECT id, uuid " . "FROM ciniki_merchandise_objrefs " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'obj');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if (isset($rc['rows'])) {
            foreach ($rc['rows'] as $row) {
                $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.objref', $row['id'], $row['uuid'], 0x4);
                if ($rc['stat'] != 'ok') {
                    ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
                    return $rc;
                }
            }
        }
    }
    if ($delete_product == 'yes') {
        //
        // Remove the images
        //
        $strsql = "SELECT id, uuid " . "FROM ciniki_merchandise_images " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'product');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if (isset($rc['rows'])) {
            foreach ($rc['rows'] as $row) {
                $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.image', $row['id'], $row['uuid'], 0x4);
                if ($rc['stat'] != 'ok') {
                    ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
                    return $rc;
                }
            }
        }
        //
        // Remove the product
        //
        $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.product', $args['product_id'], $product['uuid'], 0x4);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    return array('stat' => 'ok');
}
Esempio n. 7
0
function ciniki_merchandise_productGet($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'product_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Merchandise Product'), 'images' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Images')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productGet');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Load business settings
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings');
    $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $intl_timezone = $rc['settings']['intl-default-timezone'];
    $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
    $intl_currency = $rc['settings']['intl-default-currency'];
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat');
    $datetime_format = ciniki_users_datetimeFormat($ciniki, 'php');
    //
    // Return default for new Merchandise Product
    //
    if ($args['product_id'] == 0) {
        $product = array('id' => 0, 'code' => '', 'name' => '', 'permalink' => '', 'status' => '10', 'sequence' => '1', 'flags' => '0', 'unit_amount' => '', 'unit_discount_amount' => '', 'unit_discount_percentage' => '', 'taxtype_id' => '0', 'inventory' => '', 'shipping_other' => '', 'shipping_CA' => '', 'shipping_US' => '', 'primary_image_id' => '0', 'synopsis' => '', 'description' => '', 'images' => array());
    } else {
        $strsql = "SELECT ciniki_merchandise.id, " . "ciniki_merchandise.code, " . "ciniki_merchandise.name, " . "ciniki_merchandise.permalink, " . "ciniki_merchandise.status, " . "ciniki_merchandise.sequence, " . "ciniki_merchandise.flags, " . "ciniki_merchandise.unit_amount, " . "ciniki_merchandise.unit_discount_amount, " . "ciniki_merchandise.unit_discount_percentage, " . "ciniki_merchandise.taxtype_id, " . "ciniki_merchandise.inventory, " . "ciniki_merchandise.shipping_other, " . "ciniki_merchandise.shipping_CA, " . "ciniki_merchandise.shipping_US, " . "ciniki_merchandise.primary_image_id, " . "ciniki_merchandise.synopsis, " . "ciniki_merchandise.description " . "FROM ciniki_merchandise " . "WHERE ciniki_merchandise.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_merchandise.id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'product');
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.17', 'msg' => 'Merchandise Product not found', 'err' => $rc['err']));
        }
        if (!isset($rc['product'])) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.18', 'msg' => 'Unable to find Merchandise Product'));
        }
        $product = $rc['product'];
        $product['unit_amount'] = $product['unit_amount'] == 0 ? '' : numfmt_format_currency($intl_currency_fmt, $product['unit_amount'], $intl_currency);
        $product['unit_discount_amount'] = $product['unit_discount_amount'] == 0 ? '' : numfmt_format_currency($intl_currency_fmt, $product['unit_discount_amount'], $intl_currency);
        $product['shipping_other'] = $product['shipping_other'] == 0 ? '' : numfmt_format_currency($intl_currency_fmt, $product['shipping_other'], $intl_currency);
        $product['shipping_CA'] = $product['shipping_CA'] == 0 ? '' : numfmt_format_currency($intl_currency_fmt, $product['shipping_CA'], $intl_currency);
        $product['shipping_US'] = $product['shipping_US'] == 0 ? '' : numfmt_format_currency($intl_currency_fmt, $product['shipping_US'], $intl_currency);
        //
        // Get any tags for this product
        //
        if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x4)) {
            $product['categories'] = array();
            $strsql = "SELECT tag_type, tag_name AS lists " . "FROM ciniki_merchandise_tags " . "WHERE product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "AND business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "ORDER BY tag_type, tag_name " . "";
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree');
            $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.merchandise', array(array('container' => 'tags', 'fname' => 'tag_type', 'name' => 'tags', 'fields' => array('tag_type', 'lists'), 'dlists' => array('lists' => '::'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['tags'])) {
                foreach ($rc['tags'] as $tags) {
                    if ($tags['tags']['tag_type'] == 10) {
                        $product['categories'] = $tags['tags']['lists'];
                    }
                }
            }
        }
        //
        // Get the list of object references for this product
        //
        $strsql = "SELECT id, object, object_id, 'Unknown' as display_name " . "FROM ciniki_merchandise_objrefs " . "WHERE product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
        $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.merchandise', array(array('container' => 'objrefs', 'fname' => 'id', 'fields' => array('id', 'object', 'object_id', 'display_name'))));
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if (isset($rc['objrefs'])) {
            $product['objrefs'] = $rc['objrefs'];
            foreach ($product['objrefs'] as $rid => $ref) {
                list($pkg, $mod, $obj) = explode('.', $ref['object']);
                $rc = ciniki_core_loadMethod($ciniki, $pkg, $mod, 'hooks', 'getObjectName');
                if ($rc['stat'] == 'ok') {
                    $fn = $rc['function_call'];
                    $rc = $fn($ciniki, $args['business_id'], array('object' => $ref['object'], 'object_id' => $ref['object_id']));
                    if ($rc['stat'] == 'ok' && isset($rc['name'])) {
                        $product['objrefs'][$rid]['display_name'] = $rc['name'];
                    }
                }
            }
        } else {
            $product['objrefs'] = array();
        }
        //
        // Get the additional images for this product
        //
        if (isset($args['images']) && $args['images'] == 'yes') {
            ciniki_core_loadMethod($ciniki, 'ciniki', 'images', 'hooks', 'loadThumbnail');
            $strsql = "SELECT ciniki_merchandise_images.id, " . "ciniki_merchandise_images.image_id, " . "ciniki_merchandise_images.name, " . "ciniki_merchandise_images.sequence, " . "ciniki_merchandise_images.description " . "FROM ciniki_merchandise_images " . "WHERE ciniki_merchandise_images.product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "AND ciniki_merchandise_images.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "ORDER BY ciniki_merchandise_images.sequence, ciniki_merchandise_images.date_added, ciniki_merchandise_images.name " . "";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.artcatalog', array(array('container' => 'images', 'fname' => 'id', 'fields' => array('id', 'image_id', 'name', 'sequence', 'description'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['images'])) {
                $product['images'] = $rc['images'];
                foreach ($product['images'] as $inum => $img) {
                    if (isset($img['image_id']) && $img['image_id'] > 0) {
                        $rc = ciniki_images_hooks_loadThumbnail($ciniki, $args['business_id'], array('image_id' => $img['image_id'], 'maxlength' => 75));
                        if ($rc['stat'] != 'ok') {
                            return $rc;
                        }
                        $product['images'][$inum]['image_data'] = 'data:image/jpg;base64,' . base64_encode($rc['image']);
                    }
                }
            }
        }
    }
    $rsp = array('stat' => 'ok', 'product' => $product);
    //
    // Check if all tags should be returned
    //
    $rsp['categories'] = array();
    if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x4)) {
        //
        // Get the available tags
        //
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbQueryList');
        $strsql = "SELECT DISTINCT tag_name FROM ciniki_merchandise_tags WHERE tag_type = 10 AND business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' ";
        $rc = ciniki_core_dbQueryList($ciniki, $strsql, 'ciniki.merchandise', 'categories', 'tag_name');
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.19', 'msg' => 'Unable to get list of categories', 'err' => $rc['err']));
        }
        if (isset($rc['categories'])) {
            $rsp['categories'] = $rc['categories'];
        }
    }
    return $rsp;
}
Esempio n. 8
0
function ciniki_merchandise_productAdd(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'code' => array('required' => 'no', 'blank' => 'yes', 'trimblanks' => 'yes', 'name' => 'Product Code'), 'name' => array('required' => 'yes', 'blank' => 'no', 'trimblanks' => 'yes', 'name' => 'Product Name'), 'permalink' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Permalink'), 'status' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Status'), 'sequence' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Sequence'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Options'), 'unit_amount' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Price'), 'unit_discount_amount' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Discount Amount'), 'unit_discount_percentage' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Discount Percentage'), 'taxtype_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tax Type'), 'inventory' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Inventory'), 'shipping_other' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping Cost Other'), 'shipping_CA' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping Canada'), 'shipping_US' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping USA'), 'primary_image_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Image'), 'synopsis' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Synopsis'), 'description' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Description'), 'object' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Object'), 'object_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Object ID'), 'image_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Additional Image'), 'categories' => array('required' => 'no', 'blank' => 'yes', 'type' => 'list', 'delimiter' => '::', 'name' => 'Categories')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productAdd');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Make sure code is unique
    //
    if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x1)) {
        if (!isset($args['code']) || $args['code'] == '') {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.10', 'msg' => 'You must specify a code.'));
        }
        $strsql = "SELECT id, code, permalink " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND code = '" . ciniki_core_dbQuote($ciniki, $args['code']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if ($rc['num_rows'] > 0) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.11', 'msg' => 'You already have a product with that code, please choose another.'));
        }
    }
    //
    // Setup permalink
    //
    if (!isset($args['permalink']) || $args['permalink'] == '') {
        if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x1)) {
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
            $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['code'] . '-' . $args['name']);
        } else {
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
            $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['name']);
        }
    }
    //
    // Make sure the permalink is unique
    //
    $strsql = "SELECT id, name, permalink " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND permalink = '" . ciniki_core_dbQuote($ciniki, $args['permalink']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if ($rc['num_rows'] > 0) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.12', 'msg' => 'You already have a merchandise product with that name, please choose another.'));
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Add the merchandise product to the database
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectAdd');
    $rc = ciniki_core_objectAdd($ciniki, $args['business_id'], 'ciniki.merchandise.product', $args, 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    $product_id = $rc['id'];
    //
    // Update the categories
    //
    if (isset($args['categories'])) {
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'tagsUpdate');
        $rc = ciniki_core_tagsUpdate($ciniki, 'ciniki.merchandise', 'tag', $args['business_id'], 'ciniki_merchandise_tags', 'ciniki_merchandise_history', 'product_id', $product_id, 10, $args['categories']);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
    }
    //
    // Add additional image if supplied
    //
    if (isset($args['image_id']) && $args['image_id'] > 0) {
        //
        // Get a UUID for use in permalink
        //
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbUUID');
        $rc = ciniki_core_dbUUID($ciniki, 'ciniki.merchandise');
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.13', 'msg' => 'Unable to get a new UUID', 'err' => $rc['err']));
        }
        $args['uuid'] = $rc['uuid'];
        //
        // Setup permalink
        //
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
        $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['uuid']);
        $args['name'] = '';
        //
        // Add the product image to the database
        //
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectAdd');
        $rc = ciniki_core_objectAdd($ciniki, $args['business_id'], 'ciniki.merchandise.productimage', $args, 0x4);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
        $productimage_id = $rc['id'];
    }
    //
    // If the object is specified
    //
    if (isset($args['object']) && $args['object'] != '' && isset($args['object_id']) && $args['object_id'] != '') {
        $rc = ciniki_core_objectAdd($ciniki, $args['business_id'], 'ciniki.merchandise.objref', array('product_id' => $product_id, 'object' => $args['object'], 'object_id' => $args['object_id'], 'sequence' => 1), 0x4);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    //
    // Update the web index if enabled
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'hookExec');
    ciniki_core_hookExec($ciniki, $args['business_id'], 'ciniki', 'web', 'indexObject', array('object' => 'ciniki.merchandise.product', 'object_id' => $product_id));
    return array('stat' => 'ok', 'id' => $product_id);
}
Esempio n. 9
0
function ciniki_merchandise_imageUpdate(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'productimage_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Image'), 'product_id' => array('required' => 'no', 'blank' => 'no', 'name' => 'Product'), 'name' => array('required' => 'no', 'blank' => 'no', 'name' => 'Name'), 'permalink' => array('required' => 'no', 'blank' => 'no', 'name' => 'Permalink'), 'sequence' => array('required' => 'no', 'blank' => 'no', 'name' => 'Sequence'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Options'), 'image_id' => array('required' => 'no', 'blank' => 'no', 'name' => 'Image'), 'description' => array('required' => 'no', 'blank' => 'no', 'name' => 'Description')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.imageUpdate');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (isset($args['name'])) {
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
        $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['name']);
        //
        // Make sure the permalink is unique
        //
        $strsql = "SELECT id, name, permalink " . "FROM ciniki_merchandise_images " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND permalink = '" . ciniki_core_dbQuote($ciniki, $args['permalink']) . "' " . "AND id <> '" . ciniki_core_dbQuote($ciniki, $args['productimage_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if ($rc['num_rows'] > 0) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.9', 'msg' => 'You already have an image with this name, please choose another.'));
        }
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the Image in the database
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectUpdate');
    $rc = ciniki_core_objectUpdate($ciniki, $args['business_id'], 'ciniki.merchandise.image', $args['productimage_id'], $args, 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    //
    // Update the web index if enabled
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'hookExec');
    ciniki_core_hookExec($ciniki, $args['business_id'], 'ciniki', 'web', 'indexObject', array('object' => 'ciniki.merchandise.image', 'object_id' => $args['productimage_id']));
    return array('stat' => 'ok');
}
Esempio n. 10
0
function ciniki_merchandise_productUpdate(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'product_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Merchandise Product'), 'code' => array('required' => 'no', 'blank' => 'yes', 'trimblanks' => 'yes', 'name' => 'Product Code'), 'name' => array('required' => 'no', 'blank' => 'no', 'trimblanks' => 'yes', 'name' => 'Product Name'), 'permalink' => array('required' => 'no', 'blank' => 'no', 'name' => 'Permalink'), 'status' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Status'), 'sequence' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Sequence'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Options'), 'unit_amount' => array('required' => 'no', 'blank' => 'no', 'type' => 'currency', 'name' => 'Price'), 'unit_discount_amount' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Discount Amount'), 'unit_discount_percentage' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Discount Percentage'), 'taxtype_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tax Type'), 'inventory' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Inventory'), 'shipping_other' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping Cost Other'), 'shipping_CA' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping Canada'), 'shipping_US' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Shipping USA'), 'primary_image_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Image'), 'synopsis' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Synopsis'), 'description' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Description'), 'categories' => array('required' => 'no', 'blank' => 'yes', 'type' => 'list', 'delimiter' => '::', 'name' => 'Categories')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productUpdate');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Check if product already exists
    //
    $strsql = "SELECT id, code, name " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'product');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (!isset($rc['product'])) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.20', 'msg' => 'That product does not exist.'));
    }
    $product = $rc['product'];
    //
    // Check to make sure code is unique
    //
    if (isset($args['code'])) {
        $strsql = "SELECT id, code, permalink " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND code = '" . ciniki_core_dbQuote($ciniki, $args['code']) . "' " . "AND id <> '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if ($rc['num_rows'] > 0) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.21', 'msg' => 'You already have a product with that code, please choose another.'));
        }
    }
    if (isset($args['name']) || isset($args['code'])) {
        if (ciniki_core_checkModuleFlags($ciniki, 'ciniki.merchandise', 0x1)) {
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
            $args['permalink'] = ciniki_core_makePermalink($ciniki, (isset($args['code']) ? $args['code'] : $product['code']) . '-' . isset($args['name']) ? $args['name'] : $product['name']);
        } else {
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink');
            $args['permalink'] = ciniki_core_makePermalink($ciniki, isset($args['name']) ? $args['name'] : $product['name']);
        }
        //
        // Make sure the permalink is unique
        //
        $strsql = "SELECT id, code, name, permalink " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND permalink = '" . ciniki_core_dbQuote($ciniki, $args['permalink']) . "' " . "AND id <> '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if ($rc['num_rows'] > 0) {
            return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.22', 'msg' => 'You already have an merchandise product with this name, please choose another.'));
        }
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the Merchandise Product in the database
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectUpdate');
    $rc = ciniki_core_objectUpdate($ciniki, $args['business_id'], 'ciniki.merchandise.product', $args['product_id'], $args, 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    //
    // Update the categories
    //
    if (isset($args['categories'])) {
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'tagsUpdate');
        $rc = ciniki_core_tagsUpdate($ciniki, 'ciniki.merchandise', 'tag', $args['business_id'], 'ciniki_merchandise_tags', 'ciniki_merchandise_history', 'product_id', $args['product_id'], 10, $args['categories']);
        if ($rc['stat'] != 'ok') {
            ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
            return $rc;
        }
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    //
    // Update the web index if enabled
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'hookExec');
    ciniki_core_hookExec($ciniki, $args['business_id'], 'ciniki', 'web', 'indexObject', array('object' => 'ciniki.merchandise.product', 'object_id' => $args['product_id']));
    return array('stat' => 'ok');
}
Esempio n. 11
0
function ciniki_merchandise_productAddObjRef(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'product_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Product'), 'object' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Object'), 'object_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Object ID')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.productAddObjRef');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Check to make sure the product exists
    //
    $strsql = "SELECT id, code, permalink " . "FROM ciniki_merchandise " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (!isset($rc['item'])) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.14', 'msg' => 'Unable to find product.'));
    }
    //
    // Check to make sure the object ref does not already exist
    //
    $strsql = "SELECT id " . "FROM ciniki_merchandise_objrefs " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND product_id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' " . "AND object = '" . ciniki_core_dbQuote($ciniki, $args['object']) . "' " . "AND object_id = '" . ciniki_core_dbQuote($ciniki, $args['object_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'item');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (isset($rc['item'])) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.15', 'msg' => 'This product already exists.'));
    }
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectAdd');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // If the object is specified
    //
    $rc = ciniki_core_objectAdd($ciniki, $args['business_id'], 'ciniki.merchandise.objref', array('product_id' => $args['product_id'], 'object' => $args['object'], 'object_id' => $args['object_id'], 'sequence' => 1), 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    return array('stat' => 'ok');
}
Esempio n. 12
0
function ciniki_merchandise_imageDelete(&$ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'productimage_id' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Image')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Check access to business_id as owner
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'merchandise', 'private', 'checkAccess');
    $rc = ciniki_merchandise_checkAccess($ciniki, $args['business_id'], 'ciniki.merchandise.imageDelete');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Get the current settings for the image
    //
    $strsql = "SELECT id, uuid " . "FROM ciniki_merchandise_images " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND id = '" . ciniki_core_dbQuote($ciniki, $args['productimage_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.merchandise', 'image');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (!isset($rc['image'])) {
        return array('stat' => 'fail', 'err' => array('code' => 'ciniki.merchandise.6', 'msg' => 'Image does not exist.'));
    }
    $image = $rc['image'];
    //
    // Start transaction
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionStart');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionRollback');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbTransactionCommit');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectDelete');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory');
    $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Remove the image
    //
    $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.merchandise.image', $args['productimage_id'], $image['uuid'], 0x4);
    if ($rc['stat'] != 'ok') {
        ciniki_core_dbTransactionRollback($ciniki, 'ciniki.merchandise');
        return $rc;
    }
    //
    // Commit the transaction
    //
    $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.merchandise');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Update the last_change date in the business modules
    // Ignore the result, as we don't want to stop user updates if this fails.
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'updateModuleChangeDate');
    ciniki_businesses_updateModuleChangeDate($ciniki, $args['business_id'], 'ciniki', 'merchandise');
    return array('stat' => 'ok');
}