function ciniki_library_itemTags($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'), 'item_type' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Item Type'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemTags'); if ($rc['stat'] != 'ok') { return $rc; } $modules = $rc['modules']; // // Load the tags // ciniki_core_loadMethod($ciniki, 'ciniki', 'library', 'private', 'loadTags'); $rc = ciniki_library_loadTags($ciniki, $args['business_id'], $args['item_type']); if ($rc['stat'] != 'ok') { return $rc; } return $rc; }
function ciniki_library_itemListWanted($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'), 'item_type' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Item Type'), 'item_format' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Item Format'), 'tag_type' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tag Type'), 'tag_permalink' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tag Permalink'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Flags'), 'purchased_place' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Purchased Place'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemListWanted'); if ($rc['stat'] != 'ok') { return $rc; } 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', 'core', 'private', 'dbQuote'); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat'); $datetime_format = ciniki_users_datetimeFormat($ciniki); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat'); $date_format = ciniki_users_dateFormat($ciniki); // // Get the number of faqs in each status for the business, // if no rows found, then return empty array // $strsql = "SELECT ciniki_library_items.id, " . "ciniki_library_items.item_type, " . "ciniki_library_items.item_format, " . "ciniki_library_items.title, " . "ciniki_library_items.author_display, " . "ciniki_library_items.author_sort, " . "ciniki_library_items.year, " . "DATE_FORMAT(ciniki_library_items.purchased_date, '" . ciniki_core_dbQuote($ciniki, $date_format) . "') AS purchased_date, " . "ciniki_library_items.purchased_price, " . "ciniki_library_items.purchased_place, " . "IF(ciniki_library_items.flags&0x01>0, 'yes', 'no') AS owned, " . "IF(ciniki_library_items.flags&0x02>0, 'yes', 'no') AS wanted, " . "ciniki_library_reviews.user_id, " . "IFNULL(ciniki_library_reviews.rating, 0) AS rating " . "FROM ciniki_library_items " . "LEFT JOIN ciniki_library_reviews ON (" . "ciniki_library_items.id = ciniki_library_reviews.item_id " . "AND ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x02) > 0 " . ""; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'items', 'fname' => 'title', 'name' => 'item', 'fields' => array('id', 'item_type', 'item_format', 'title', 'author_display', 'author_sort', 'year', 'purchased_date', 'purchased_price', 'purchased_place', 'owned', 'wanted')), array('container' => 'ratings', 'fname' => 'user_id', 'name' => 'rating', 'fields' => array('user_id', 'rating')))); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['items']) || !is_array($rc['items'])) { return array('stat' => 'ok', 'items' => array()); } $items = $rc['items']; foreach ($items as $iid => $item) { if (isset($item['item']['ratings'])) { foreach ($item['item']['ratings'] as $rid => $rating) { $items[$iid]['item']['user-' . $rating['rating']['user_id'] . '-rating'] = $rating['rating']['rating']; } unset($items[$iid]['item']['ratings']); } } return array('stat' => 'ok', 'items' => $items); }
function ciniki_library_purchasedStats($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'), 'item_type' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Item Type'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.purchasedStats'); if ($rc['stat'] != 'ok') { return $rc; } 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', 'core', 'private', 'dbQuote'); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat'); $datetime_format = ciniki_users_datetimeFormat($ciniki); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat'); $date_format = ciniki_users_dateFormat($ciniki); // // Get the number of faqs in each status for the business, // if no rows found, then return empty array // $strsql = "SELECT purchased_place AS name, " . "SUM(purchased_price) AS total_amount " . "FROM ciniki_library_items " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND purchased_place <> '' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x01) = 1 " . "GROUP BY purchased_place " . "ORDER BY purchased_place " . ""; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'places', 'fname' => 'name', 'name' => 'place', 'fields' => array('name', 'total_amount')))); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['places']) || !is_array($rc['places'])) { return array('stat' => 'ok', 'places' => array()); } $places = $rc['places']; $totals = array('total_amount' => 0); foreach ($places as $pid => $place) { $place = $place['place']; $totals['total_amount'] = bcadd($totals['total_amount'], $place['total_amount'], 4); $places[$pid]['place']['total_amount'] = numfmt_format_currency($intl_currency_fmt, $place['total_amount'], $intl_currency); } $totals['total_amount'] = numfmt_format_currency($intl_currency_fmt, $totals['total_amount'], $intl_currency); return array('stat' => 'ok', 'places' => $places, 'totals' => $totals); }
function ciniki_library_itemSearchField($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'), 'field' => array('required' => 'yes', 'blank' => 'no', 'validlist' => array('author_display', 'purchased_place'), 'name' => 'Field'), 'start_needle' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Search String'), 'limit' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Limit'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemSearchField'); if ($rc['stat'] != 'ok') { return $rc; } // // Get the number of faqs in each status for the business, // if no rows found, then return empty array // $strsql = "SELECT " . $args['field'] . " AS name, author_display, author_sort " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (" . $args['field'] . " LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "AND " . $args['field'] . " <> '' " . ") " . ""; $strsql .= "ORDER BY " . $args['field'] . " COLLATE latin1_general_cs " . ""; if (isset($args['limit']) && $args['limit'] != '' && $args['limit'] > 0) { $strsql .= "LIMIT " . ciniki_core_dbQuote($ciniki, $args['limit']) . " "; } else { $strsql .= "LIMIT 25 "; } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'results', 'fname' => 'name', 'name' => 'result', 'fields' => array('name', 'author_display', 'author_sort')))); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['results']) || !is_array($rc['results'])) { return array('stat' => 'ok', 'results' => array()); } return array('stat' => 'ok', 'results' => $rc['results']); }
function ciniki_library_itemHistory($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'), 'item_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Item'), '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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemHistory'); if ($rc['stat'] != 'ok') { return $rc; } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbGetModuleHistory'); return ciniki_core_dbGetModuleHistory($ciniki, 'ciniki.library', 'ciniki_library_history', $args['business_id'], 'ciniki_library_items', $args['item_id'], $args['field']); }
function ciniki_library_itemUpdate(&$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'), 'item_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Item'), 'item_type' => array('required' => 'no', 'blank' => 'no', 'name' => 'Item Type'), 'item_format' => array('required' => 'no', 'blank' => 'no', 'name' => 'Format'), 'title' => array('required' => 'no', 'blank' => 'no', 'name' => 'Title'), 'permalink' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Permalink'), 'author_display' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Author Display'), 'author_sort' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Author Sort'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Options'), 'isbn' => array('required' => 'no', 'blank' => 'yes', 'name' => 'ISBN'), 'year' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Year'), 'location' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Location'), 'synopsis' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Synopsis'), 'description' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Description'), 'primary_image_id' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Image'), 'primary_image_caption' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Image Caption'), 'notes' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Notes'), 'purchased_date' => array('required' => 'no', 'blank' => 'yes', 'type' => 'date', 'name' => 'Purchased Date'), 'purchased_price' => array('required' => 'no', 'blank' => 'yes', 'type' => 'currency', 'name' => 'Purchased Price'), 'purchased_place' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Purchased Place'), 'genres' => array('required' => 'no', 'blank' => 'yes', 'type' => 'list', 'delimiter' => '::', 'name' => 'Genres'), 'tags' => array('required' => 'no', 'blank' => 'yes', 'type' => 'list', 'delimiter' => '::', 'name' => 'Tags'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemUpdate'); if ($rc['stat'] != 'ok') { return $rc; } $strsql = "SELECT id, item_type, title, author_display " . "FROM ciniki_library_items " . "WHERE id = '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . "AND business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ""; $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.library', 'item'); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['item'])) { return array('stat' => 'fail', 'err' => array('code' => 'ciniki.library.7', 'msg' => 'Item not found')); } $item = $rc['item']; if (isset($args['title']) || isset($args['author_display'])) { ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'makePermalink'); if (isset($args['author_display']) && isset($args['title'])) { $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['author_display'] . '-' . $args['title']); } elseif (isset($args['author_display'])) { $args['permalink'] = ciniki_core_makePermalink($ciniki, $args['author_display'] . '-' . $item['title']); } elseif (isset($args['title'])) { $args['permalink'] = ciniki_core_makePermalink($ciniki, $item['author_display'] . '-' . $args['title']); } else { return array('stat' => 'fail', 'err' => array('code' => 'ciniki.library.8', 'msg' => 'Unable to determine permalink.')); } // // Make sure the permalink is unique // $strsql = "SELECT id, title, permalink FROM ciniki_library_items " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND permalink = '" . ciniki_core_dbQuote($ciniki, $args['permalink']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $item['item_type']) . "' " . "AND id <> '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . ""; $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.library', 'item'); if ($rc['stat'] != 'ok') { return $rc; } if ($rc['num_rows'] > 0) { return array('stat' => 'fail', 'err' => array('code' => 'ciniki.library.9', 'msg' => 'You already have a item with this name, please choose another name')); } } // // Turn off autocommit // 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', 'dbQuote'); $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.library'); if ($rc['stat'] != 'ok') { return $rc; } // // Update the item // ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectUpdate'); $rc = ciniki_core_objectUpdate($ciniki, $args['business_id'], 'ciniki.library.item', $args['item_id'], $args); if ($rc['stat'] != 'ok') { return $rc; } // // Update the genres // if (isset($args['genres'])) { ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'tagsUpdate'); $rc = ciniki_core_tagsUpdate($ciniki, 'ciniki.library', 'tag', $args['business_id'], 'ciniki_library_tags', 'ciniki_library_history', 'item_id', $args['item_id'], 20, $args['genres']); if ($rc['stat'] != 'ok') { ciniki_core_dbTransactionRollback($ciniki, 'ciniki.library'); return $rc; } } // // Update the tags // if (isset($args['tags'])) { ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'tagsUpdate'); $rc = ciniki_core_tagsUpdate($ciniki, 'ciniki.library', 'tag', $args['business_id'], 'ciniki_library_tags', 'ciniki_library_history', 'item_id', $args['item_id'], 40, $args['tags']); if ($rc['stat'] != 'ok') { ciniki_core_dbTransactionRollback($ciniki, 'ciniki.library'); return $rc; } } // // Update the reviews/ratings // if (($ciniki['business']['modules']['ciniki.library']['flags'] & 0x8) > 0) { ciniki_core_loadMethod($ciniki, 'ciniki', 'library', 'private', 'itemUpdateReviews'); $rc = ciniki_library_itemUpdateReviews($ciniki, $args['business_id'], $args['item_id']); if ($rc['stat'] != 'ok') { ciniki_core_dbTransactionRollback($ciniki, 'ciniki.library'); return $rc; } } // // Commit the database changes // $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.library'); 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', 'library'); return array('stat' => 'ok'); }
function ciniki_library_itemSearch($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' => 'yes', 'name' => 'Search String'), 'flags' => array('required' => 'no', 'blank' => 'no', 'name' => 'Options'), 'limit' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Limit'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemSearch'); if ($rc['stat'] != 'ok') { return $rc; } // // Get the number of faqs in each status for the business, // if no rows found, then return empty array // if (($ciniki['business']['modules']['ciniki.library']['flags'] & 0x8) > 0) { // // Ratings included // $strsql = "SELECT ciniki_library_items.id, " . "item_type, " . "item_format, " . "title, " . "author_display, " . "author_sort, " . "IF(flags&0x01>0, 'yes', 'no') AS owned, " . "IF(flags&0x02>0, 'yes', 'no') AS wanted, " . "IFNULL(ciniki_library_reviews.user_id, 0) AS user_id, " . "IFNULL(ciniki_library_reviews.rating, 0) AS rating " . "FROM ciniki_library_items " . "LEFT JOIN ciniki_library_reviews ON (" . "ciniki_library_items.id = ciniki_library_reviews.item_id " . "AND ciniki_library_reviews.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (title LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR title LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR author_display LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR author_display LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . ") " . ""; if (isset($args['flags']) && $args['flags'] == 2) { $strsql .= "AND (ciniki_library_items.flags&0x02) = 2 "; } $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs, ciniki_library_items.id " . ""; if (isset($args['limit']) && $args['limit'] != '' && $args['limit'] > 0) { $strsql .= "LIMIT " . ciniki_core_dbQuote($ciniki, $args['limit']) . " "; } else { $strsql .= "LIMIT 25 "; } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'items', 'fname' => 'title', 'name' => 'item', 'fields' => array('id', 'item_type', 'item_format', 'title', 'author_display', 'author_sort', 'owned', 'wanted')), array('container' => 'ratings', 'fname' => 'user_id', 'name' => 'rating', 'fields' => array('user_id', 'rating')))); } else { $strsql = "SELECT id, " . "item_type, " . "item_format, " . "title, " . "author_display, " . "author_sort, " . "IF(flags&0x01>0, 'yes', 'no') AS owned, " . "IF(flags&0x02>0, 'yes', 'no') AS wanted " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (title LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR title LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR author_display LIKE '" . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . "OR author_display LIKE '% " . ciniki_core_dbQuote($ciniki, $args['start_needle']) . "%' " . ") " . ""; if (isset($args['flags']) && $args['flags'] == 2) { $strsql .= "AND (ciniki_library_items.flags&0x02) = 2 "; } $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; if (isset($args['limit']) && $args['limit'] != '' && $args['limit'] > 0) { $strsql .= "LIMIT " . ciniki_core_dbQuote($ciniki, $args['limit']) . " "; } else { $strsql .= "LIMIT 25 "; } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'items', 'fname' => 'title', 'name' => 'item', 'fields' => array('id', 'item_type', 'item_format', 'title', 'author_display', 'author_sort', 'owned', 'wanted')))); } if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['items']) || !is_array($rc['items'])) { return array('stat' => 'ok', 'items' => array()); } return array('stat' => 'ok', 'items' => $rc['items']); }
function ciniki_library_itemList($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'), 'item_type' => array('required' => 'yes', 'blank' => 'yes', 'name' => 'Item Type'), 'item_format' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Item Format'), 'tag_type' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tag Type'), 'tag_permalink' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tag Permalink'), 'flags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Flags'), 'location' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Location'), 'purchased_place' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Purchased Place'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemList'); if ($rc['stat'] != 'ok') { return $rc; } 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', 'core', 'private', 'dbQuote'); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat'); $datetime_format = ciniki_users_datetimeFormat($ciniki); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat'); $date_format = ciniki_users_dateFormat($ciniki); // // Get the number of faqs in each status for the business, // if no rows found, then return empty array // $strsql = "SELECT ciniki_library_items.id, " . "ciniki_library_items.item_type, " . "ciniki_library_items.item_format, " . "ciniki_library_items.title, " . "ciniki_library_items.author_display, " . "ciniki_library_items.author_sort, " . "ciniki_library_items.year, " . "DATE_FORMAT(ciniki_library_items.purchased_date, '" . ciniki_core_dbQuote($ciniki, $date_format) . "') AS purchased_date, " . "ciniki_library_items.purchased_price, " . "ciniki_library_items.purchased_place, " . "IF(ciniki_library_items.flags&0x01>0, 'yes', 'no') AS owned, " . "IF(ciniki_library_items.flags&0x02>0, 'yes', 'no') AS wanted " . ""; if (isset($args['tag_type']) && $args['tag_type'] != '' && isset($args['tag_permalink']) && $args['tag_permalink'] != '') { $strsql .= "FROM ciniki_library_tags, ciniki_library_items " . "WHERE ciniki_library_tags.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_library_tags.tag_type = '" . ciniki_core_dbQuote($ciniki, $args['tag_type']) . "' " . "AND ciniki_library_tags.permalink = '" . ciniki_core_dbQuote($ciniki, $args['tag_permalink']) . "' " . "AND ciniki_library_tags.item_id = ciniki_library_items.id " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ""; if (isset($args['flags']) && $args['flags'] != '' && intval($args['flags']) > 0) { $strsql .= "AND (ciniki_library_items.flags&" . intval($args['flags']) . ") > 0 "; } $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } elseif (isset($args['tag_type']) && $args['tag_type'] != '' && isset($args['tag_permalink']) && $args['tag_permalink'] == '') { $strsql .= ", ciniki_library_tags.tag_name " . "FROM ciniki_library_items " . "LEFT JOIN ciniki_library_tags ON (" . "ciniki_library_tags.item_id = ciniki_library_items.id " . "AND ciniki_library_tags.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_library_tags.tag_type = '" . ciniki_core_dbQuote($ciniki, $args['tag_type']) . "' " . ") " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' "; if (isset($args['flags']) && $args['flags'] != '' && intval($args['flags']) > 0) { $strsql .= "AND (ciniki_library_items.flags&" . intval($args['flags']) . ") > 0 "; } $strsql .= "HAVING ISNULL(tag_name) "; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } elseif (isset($args['flags']) && ($args['flags'] & 0x2) > 0) { $strsql .= "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x02) > 0 " . ""; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } elseif (isset($args['item_format']) && $args['item_format'] != '') { $strsql .= "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x01) = 1 " . "AND item_format = '" . ciniki_core_dbQuote($ciniki, $args['item_format']) . "' " . ""; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } elseif (isset($args['location'])) { $strsql .= "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x01) = 1 " . "AND location = '" . ciniki_core_dbQuote($ciniki, $args['location']) . "' " . ""; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } elseif (isset($args['purchased_place'])) { $strsql .= "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . "AND (flags&0x01) = 1 " . "AND purchased_place = '" . ciniki_core_dbQuote($ciniki, $args['purchased_place']) . "' " . ""; $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; } else { $strsql .= "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND item_type = '" . ciniki_core_dbQuote($ciniki, $args['item_type']) . "' " . ""; if (isset($args['flags']) && $args['flags'] != '' && intval($args['flags']) > 0) { $strsql .= "AND (ciniki_library_items.flags&" . intval($args['flags']) . ") > 0 "; } $strsql .= "ORDER BY author_sort, title COLLATE latin1_general_cs " . ""; if (isset($args['limit']) && $args['limit'] != '' && $args['limit'] > 0) { $strsql .= "LIMIT " . ciniki_core_dbQuote($ciniki, $args['limit']) . " "; } else { $strsql .= "LIMIT 25 "; } } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'items', 'fname' => 'title', 'name' => 'item', 'fields' => array('id', 'item_type', 'item_format', 'title', 'author_display', 'author_sort', 'year', 'purchased_date', 'purchased_price', 'purchased_place', 'owned', 'wanted')))); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['items']) || !is_array($rc['items'])) { return array('stat' => 'ok', 'items' => array(), 'totals' => array()); } $items = $rc['items']; $totals = array('purchased_price' => 0); foreach ($items as $iid => $item) { $item = $item['item']; $totals['purchased_price'] = bcadd($totals['purchased_price'], $item['purchased_price'], 4); $items[$iid]['item']['purchased_price'] = numfmt_format_currency($intl_currency_fmt, $item['purchased_price'], $intl_currency); } $totals['purchased_price'] = numfmt_format_currency($intl_currency_fmt, $totals['purchased_price'], $intl_currency); return array('stat' => 'ok', 'items' => $items, 'totals' => $totals); }
function ciniki_library_itemStats($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']; // // Make sure this module is activated, and // check permission to run this function for this business // ciniki_core_loadMethod($ciniki, 'ciniki', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemStats'); if ($rc['stat'] != 'ok') { return $rc; } // // Load the status maps for the text description of each status // ciniki_core_loadMethod($ciniki, 'ciniki', 'library', 'private', 'maps'); $rc = ciniki_library_maps($ciniki); if ($rc['stat'] != 'ok') { return $rc; } $maps = $rc['maps']; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryIDTree'); $rsp = array('stat' => 'ok', 'item_types' => array()); // // Get the genres // $strsql = "SELECT ciniki_library_items.item_type, " . "ciniki_library_tags.tag_type, " . "ciniki_library_tags.tag_name, " . "ciniki_library_tags.permalink, " . "COUNT(ciniki_library_tags.tag_name) AS num_items " . "FROM ciniki_library_items " . "LEFT JOIN ciniki_library_tags ON (" . "ciniki_library_items.id = ciniki_library_tags.item_id " . "AND ciniki_library_tags.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (ciniki_library_items.flags&0x01) = 1 " . "GROUP BY item_type, tag_type, tag_name " . ""; $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'item_types', 'fname' => 'item_type', 'name' => 'type', 'fields' => array('item_type')), array('container' => 'tag_types', 'fname' => 'tag_type', 'name' => 'type', 'fields' => array('tag_type')), array('container' => 'names', 'fname' => 'tag_name', 'name' => 'name', 'fields' => array('item_type', 'tag_type', 'tag_name', 'permalink', 'num_items')))); if ($rc['stat'] != 'ok') { return $rc; } if (isset($rc['item_types'])) { $rsp['item_types'] = $rc['item_types']; } // // Select the items with no Genre // $strsql = "SELECT ciniki_library_items.item_type, " . "ciniki_library_tags.tag_type, " . "ciniki_library_tags.tag_name, " . "COUNT(ciniki_library_items.id) AS num_items " . "FROM ciniki_library_items " . "LEFT JOIN ciniki_library_tags ON (" . "ciniki_library_items.id = ciniki_library_tags.item_id " . "AND ciniki_library_tags.tag_type = 20 " . ") " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (ciniki_library_items.flags&0x01) = 1 " . "AND ISNULL(tag_name) " . "GROUP BY item_type " . ""; $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.products', 'uncategorized'); if ($rc['stat'] != 'ok') { return $rc; } if (isset($rc['rows'])) { foreach ($rc['rows'] as $row) { $found = 'no'; foreach ($rsp['item_types'] as $itid => $type) { if ($type['type']['item_type'] == $row['item_type']) { $found = 'yes'; if (!isset($rsp['item_types'][$itid]['type']['tag_types'])) { $rsp['item_types'][$itid]['type']['tag_types'] = array('type' => array('tag_type' => '20', 'uncategorized' => $row['num_items'], 'names' => array())); } else { $f2 = 'no'; foreach ($rsp['item_types'][$itid]['type']['tag_types'] as $ttid => $tag_type) { if ($tag_type['type']['tag_type'] == '20') { $f2 = 'yes'; $rsp['item_types'][$itid]['type']['tag_types'][$ttid]['type']['uncategorized'] = $row['num_items']; } } if ($f2 == 'no') { $rsp['item_types'][$itid]['type']['tag_types'] = array('type' => array('tag_type' => '20', 'uncategorized' => $row['num_items'], 'names' => array())); } } } } if ($found == 'no') { $rsp['item_types'][$itid]['type']['tag_types'] = array('type' => array('tag_types' => array('type' => array('tag_type' => '20', 'uncategorized' => $row['num_items'], 'names' => array())))); } } } // // Get the formats // $strsql = "SELECT item_type, item_format, item_format AS item_format_text, COUNT(item_format) AS num_items " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_library_items.flags&0x01 = 1 " . "GROUP BY item_type, item_format " . "ORDER BY item_type, item_format " . ""; $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'item_types', 'fname' => 'item_type', 'name' => 'type', 'fields' => array('item_type')), array('container' => 'formats', 'fname' => 'item_format', 'name' => 'format', 'fields' => array('item_type', 'item_format', 'item_format_text', 'num_items'), 'maps' => array('item_format_text' => $maps['item']['item_format'])))); if ($rc['stat'] != 'ok') { return $rc; } $types = array(); if (isset($rc['item_types'])) { foreach ($rc['item_types'] as $type) { $types[$type['type']['item_type']] = $type['type']['formats']; } foreach ($rsp['item_types'] as $itid => $item_type) { if (isset($types[$item_type['type']['item_type']])) { $rsp['item_types'][$itid]['type']['formats'] = $types[$item_type['type']['item_type']]; } } } // // Get the locations // $strsql = "SELECT item_type, location AS name, COUNT(location) AS num_items " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (ciniki_library_items.flags&0x01) = 1 " . "GROUP BY item_type, location " . "ORDER BY item_type, location " . ""; $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'item_types', 'fname' => 'item_type', 'name' => 'type', 'fields' => array('item_type')), array('container' => 'locations', 'fname' => 'name', 'name' => 'location', 'fields' => array('item_type', 'name', 'num_items')))); if ($rc['stat'] != 'ok') { return $rc; } $types = array(); if (isset($rc['item_types'])) { foreach ($rc['item_types'] as $type) { $types[$type['type']['item_type']] = $type['type']['locations']; } foreach ($rsp['item_types'] as $itid => $item_type) { if (isset($types[$item_type['type']['item_type']])) { $rsp['item_types'][$itid]['type']['locations'] = $types[$item_type['type']['item_type']]; } } } // // Get the purchased places // $strsql = "SELECT item_type, purchased_place, COUNT(purchased_place) AS num_items " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (ciniki_library_items.flags&0x01) = 1 " . "AND purchased_place <> '' " . "GROUP BY item_type, purchased_place " . "ORDER BY item_type, purchased_place " . ""; $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'item_types', 'fname' => 'item_type', 'name' => 'type', 'fields' => array('item_type')), array('container' => 'places', 'fname' => 'purchased_place', 'name' => 'place', 'fields' => array('item_type', 'purchased_place', 'num_items')))); if ($rc['stat'] != 'ok') { return $rc; } $types = array(); if (isset($rc['item_types'])) { foreach ($rc['item_types'] as $type) { $types[$type['type']['item_type']] = $type['type']['places']; } foreach ($rsp['item_types'] as $itid => $item_type) { if (isset($types[$item_type['type']['item_type']])) { $rsp['item_types'][$itid]['type']['purchased_places'] = $types[$item_type['type']['item_type']]; } } } // // Get the number of wanted // $strsql = "SELECT item_type, COUNT(id) AS num_items " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND (ciniki_library_items.flags&0x02) = 2 " . "GROUP BY item_type " . "ORDER BY item_type " . ""; $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'item_types', 'fname' => 'item_type', 'fields' => array('item_type', 'num_items')))); if ($rc['stat'] != 'ok') { return $rc; } $types = array(); if (isset($rc['item_types'])) { foreach ($rsp['item_types'] as $itid => $item_type) { if (isset($rc['item_types'][$item_type['type']['item_type']])) { $rsp['item_types'][$itid]['type']['wanted'] = $rc['item_types'][$item_type['type']['item_type']]['num_items']; } } } return $rsp; }
function ciniki_library_itemGet($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'), 'item_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Item'), 'images' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Images'), 'tags' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Tags'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemGet'); if ($rc['stat'] != 'ok') { return $rc; } 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', 'core', 'private', 'dbQuote'); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat'); $datetime_format = ciniki_users_datetimeFormat($ciniki); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat'); $date_format = ciniki_users_dateFormat($ciniki); $strsql = "SELECT ciniki_library_items.id, " . "ciniki_library_items.item_type, " . "ciniki_library_items.item_format, " . "ciniki_library_items.title, " . "ciniki_library_items.permalink, " . "ciniki_library_items.author_display, " . "ciniki_library_items.author_sort, " . "ciniki_library_items.flags, " . "ciniki_library_items.isbn, " . "ciniki_library_items.year, " . "ciniki_library_items.location, " . "ciniki_library_items.synopsis, " . "ciniki_library_items.description, " . "ciniki_library_items.primary_image_id, " . "ciniki_library_items.primary_image_caption, " . "ciniki_library_items.notes, " . "DATE_FORMAT(ciniki_library_items.purchased_date, '" . ciniki_core_dbQuote($ciniki, $date_format) . "') AS purchased_date, " . "ciniki_library_items.purchased_price, " . "ciniki_library_items.purchased_place " . "FROM ciniki_library_items " . "WHERE ciniki_library_items.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_library_items.id = '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . ""; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryTree'); $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', array(array('container' => 'items', 'fname' => 'id', 'name' => 'item', 'fields' => array('id', 'item_type', 'item_format', 'title', 'permalink', 'author_display', 'author_sort', 'flags', 'isbn', 'year', 'location', 'synopsis', 'description', 'primary_image_id', 'primary_image_caption', 'notes', 'purchased_date', 'purchased_price', 'purchased_place')))); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['items'])) { return array('stat' => 'ok', 'err' => array('code' => 'ciniki.library.6', 'msg' => 'Unable to find item')); } $item = $rc['items'][0]['item']; $item['purchased_price'] = numfmt_format_currency($intl_currency_fmt, $item['purchased_price'], $intl_currency); // // Get the ratings for the item // if (($ciniki['business']['modules']['ciniki.library']['flags'] & 0x8) > 0) { // // Get the existing ratings and employees // $strsql = "SELECT ciniki_business_users.user_id, " . "IFNULL(ciniki_library_reviews.id, 0) AS review_id, " . "IFNULL(ciniki_library_reviews.rating, 0) AS rating " . "FROM ciniki_business_users " . "LEFT JOIN ciniki_library_reviews ON (" . "ciniki_business_users.user_id = ciniki_library_reviews.user_id " . "AND ciniki_library_reviews.item_id = '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . "AND ciniki_library_reviews.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_business_users.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_business_users.status = 10 " . ""; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryIDTree'); $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.customers', array(array('container' => 'employees', 'fname' => 'user_id', 'fields' => array('user_id', 'review_id', 'rating')))); if ($rc['stat'] != 'ok') { return $rc; } if (isset($rc['employees'])) { foreach ($rc['employees'] as $user_id => $user) { $item['user-' . $user_id . '-rating'] = $user['rating']; } } } // // Get the categories and tags for the post // $strsql = "SELECT tag_type, tag_name AS lists " . "FROM ciniki_library_tags " . "WHERE item_id = '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . "AND business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "ORDER BY tag_type, tag_name " . ""; $rc = ciniki_core_dbHashQueryTree($ciniki, $strsql, 'ciniki.library', 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'] == 20) { $item['genres'] = $tags['tags']['lists']; } if ($tags['tags']['tag_type'] == 40) { $item['tags'] = $tags['tags']['lists']; } } } // // Check if all tags should be returned // $genres = array(); $tags = array(); if (isset($args['tags']) && $args['tags'] == 'yes') { // // Load the tags // ciniki_core_loadMethod($ciniki, 'ciniki', 'library', 'private', 'loadTags'); $rc = ciniki_library_loadTags($ciniki, $args['business_id'], $item['item_type']); if ($rc['stat'] != 'ok') { return $rc; } if (isset($rc['genres'])) { $genres = $rc['genres']; } if (isset($rc['tags'])) { $tags = $rc['tags']; } } return array('stat' => 'ok', 'item' => $item, 'genres' => $genres, 'tags' => $tags); }
function ciniki_library_itemDelete(&$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'), 'item_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Item'))); 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', 'library', 'private', 'checkAccess'); $rc = ciniki_library_checkAccess($ciniki, $args['business_id'], 'ciniki.library.itemDelete'); if ($rc['stat'] != 'ok') { return $rc; } $modules = $rc['modules']; // // Get the uuid of the item to be deleted // $strsql = "SELECT uuid FROM ciniki_library_items " . "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND id = '" . ciniki_core_dbQuote($ciniki, $args['item_id']) . "' " . ""; $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.library', 'item'); if ($rc['stat'] != 'ok') { return $rc; } if (!isset($rc['item'])) { return array('stat' => 'fail', 'err' => array('code' => 'ciniki.library.5', 'msg' => 'Unable to find existing item')); } $uuid = $rc['item']['uuid']; // // Turn off autocommit // 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', 'dbObjectDelete'); ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbAddModuleHistory'); $rc = ciniki_core_dbTransactionStart($ciniki, 'ciniki.library'); if ($rc['stat'] != 'ok') { return $rc; } // // Remove the item // ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'objectDelete'); $rc = ciniki_core_objectDelete($ciniki, $args['business_id'], 'ciniki.library.item', $args['item_id'], $uuid); if ($rc['stat'] != 'ok') { ciniki_core_dbTransactionRollback($ciniki, 'ciniki.library'); return $rc; } // // Commit the database changes // $rc = ciniki_core_dbTransactionCommit($ciniki, 'ciniki.library'); 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', 'library'); return array('stat' => 'ok'); }