Example #1
0
 /**
  * It creates a new CategoryStats object class if it has been created
  * before, it return the previous object
  *
  * @access public
  * @since unknown
  * @return CategoryStats
  */
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 function doModel()
 {
     switch ($this->action) {
         case 'logout':
             // unset only the required parameters in Session
             Session::newInstance()->_drop('adminId');
             Session::newInstance()->_drop('adminUserName');
             Session::newInstance()->_drop('adminName');
             Session::newInstance()->_drop('adminEmail');
             Session::newInstance()->_drop('adminLocale');
             Cookie::newInstance()->pop('oc_adminId');
             Cookie::newInstance()->pop('oc_adminSecret');
             Cookie::newInstance()->pop('oc_adminLocale');
             Cookie::newInstance()->set();
             $this->redirectTo(osc_admin_base_url(true));
             break;
         default:
             //default dashboard page (main page at oc-admin)
             $this->_exportVariableToView("numUsers", User::newInstance()->count());
             $this->_exportVariableToView("numAdmins", Admin::newInstance()->count());
             $this->_exportVariableToView("numItems", Item::newInstance()->count());
             $this->_exportVariableToView("numItemsPerCategory", CategoryStats::newInstance()->toNumItemsMap());
             $this->_exportVariableToView("categories", Category::newInstance()->listAll());
             $this->_exportVariableToView("newsList", osc_listNews());
             $this->_exportVariableToView("comments", ItemComment::newInstance()->getLastComments(5));
             //calling the view...
             $this->doView('main/index.php');
     }
 }
Example #3
0
function update_cat_stats()
{
    $categoryTotal = array();
    $categoryTree = array();
    $aCategories = Category::newInstance()->listAll(false);
    // append root categories and get the number of items of each category
    foreach ($aCategories as $category) {
        $total = Item::newInstance()->numItems($category, true, true);
        $category += array('category' => array());
        if (is_null($category['fk_i_parent_id'])) {
            $categoryTree += array($category['pk_i_id'] => $category);
        }
        $categoryTotal += array($category['pk_i_id'] => $total);
    }
    // append childs to root categories
    foreach ($aCategories as $category) {
        if (!is_null($category['fk_i_parent_id'])) {
            $categoryTree[$category['fk_i_parent_id']]['category'][] = $category;
        }
    }
    // sum the result of the subcategories and set in the parent category
    foreach ($categoryTree as $category) {
        if (count($category['category']) > 0) {
            foreach ($category['category'] as $subcategory) {
                $categoryTotal[$category['pk_i_id']] += $categoryTotal[$subcategory['pk_i_id']];
            }
        }
    }
    foreach ($categoryTotal as $k => $v) {
        CategoryStats::newInstance()->setNumItems($k, $v);
    }
}
Example #4
0
function count_items_subcategories($category = null)
{
    $manager = CategoryStats::newInstance();
    $total = $manager->countItemsFromCategory($category['pk_i_id']);
    $categories = Category::newInstance()->isParentOf($category['pk_i_id']);
    if ($categories != null) {
        foreach ($categories as $c) {
            $total += count_items_subcategories($c);
        }
    }
    $conn = getConnection();
    $conn->osc_dbExec("INSERT INTO %st_category_stats (fk_i_category_id, i_num_items) VALUES (%d, %d) ON DUPLICATE KEY UPDATE i_num_items = %d", DB_TABLE_PREFIX, $category['pk_i_id'], $total, $total);
    return $total;
}
Example #5
0
 /**
  * Private function for decrease stats.
  * tables: t_user/t_category_stats/t_country_stats/t_region_stats/t_city_stats
  *
  * @param array item
  */
 private function _decreaseStats($item)
 {
     if($item['fk_i_user_id']!=null) {
         User::newInstance()->decreaseNumItems($item['fk_i_user_id']);
     }
     CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
     CountryStats::newInstance()->decreaseNumItems($item['fk_c_country_code']);
     RegionStats::newInstance()->decreaseNumItems($item['fk_i_region_id']);
     CityStats::newInstance()->decreaseNumItems($item['fk_i_city_id']);
     osc_run_hook('item_decrease_stat',$item);
 }
Example #6
0
        /**
         * Delete by primary key, delete dependencies too
         *
         * @access public
         * @since unknown
         * @param int $id Item id
         * @return bool
         */
        public function deleteByPrimaryKey($id)
        {
            $item = $this->findByPrimaryKey($id);

            if ( is_null($item) ) {
                return false;
            }

            if( $item['b_active'] == 1 && $item['b_enabled']==1 && $item['b_spam']==0 && !osc_isExpired($item['dt_expiration'])) {
                if($item['fk_i_user_id']!=null) {
                    User::newInstance()->decreaseNumItems($item['fk_i_user_id']);
                }
                CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                CountryStats::newInstance()->decreaseNumItems($item['fk_c_country_code']);
                RegionStats::newInstance()->decreaseNumItems($item['fk_i_region_id']);
                CityStats::newInstance()->decreaseNumItems($item['fk_i_city_id']);
            }

            $this->deleteResourcesFromHD($id);

            $this->dao->delete(DB_TABLE_PREFIX.'t_item_description', "fk_i_item_id = $id");
            $this->dao->delete(DB_TABLE_PREFIX.'t_item_comment' , "fk_i_item_id = $id");
            $this->dao->delete(DB_TABLE_PREFIX.'t_item_resource', "fk_i_item_id = $id");
            $this->dao->delete(DB_TABLE_PREFIX.'t_item_location', "fk_i_item_id = $id");
            $this->dao->delete(DB_TABLE_PREFIX.'t_item_stats'   , "fk_i_item_id = $id");
            $this->dao->delete(DB_TABLE_PREFIX.'t_item_meta'    , "fk_i_item_id = $id");

            osc_run_hook('delete_item', $id);

            $res = parent::deleteByPrimaryKey($id);
            return $res;
        }
Example #7
0
/**
 * Recount items for a given a category id
 * 
 * @param int $id 
 */
function osc_update_cat_stats_id($id)
{
    // get sub categorias
    if (!Category::newInstance()->isRoot($id)) {
        $auxCat = Category::newInstance()->findRootCategory($id);
        $id = $auxCat['pk_i_id'];
    }
    $aCategories = Category::newInstance()->findSubcategories($id);
    $categoryTotal = 0;
    if (count($aCategories) > 0) {
        // sumar items de la categoría
        foreach ($aCategories as $category) {
            $total = Item::newInstance()->numItems($category, true, true);
            $categoryTotal += $total;
        }
        $categoryTotal += Item::newInstance()->numItems(Category::newInstance()->findByPrimaryKey($id), true, true);
    } else {
        $category = Category::newInstance()->findByPrimaryKey($id);
        $total = Item::newInstance()->numItems($category, true, true);
        $categoryTotal += $total;
    }
    $sql = 'REPLACE INTO ' . DB_TABLE_PREFIX . 't_category_stats (fk_i_category_id, i_num_items) VALUES ';
    $sql .= " (" . $id . ", " . $categoryTotal . ")";
    $result = CategoryStats::newInstance()->dao->query($sql);
}
Example #8
0
 public function disable($id)
 {
     $item = $this->manager->findByPrimaryKey($id);
     if ($item['b_enabled'] == 1) {
         $result = $this->manager->update(array('b_enabled' => 0), array('pk_i_id' => $id));
         osc_run_hook('disable_item', $id);
         if ($item['b_active'] == 1) {
             CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
         }
         return true;
     }
     return false;
 }
Example #9
0
 function doModel()
 {
     $mCategories = new Category();
     $aCategories = $mCategories->findRootCategories();
     $mCategoryStats = new CategoryStats();
     ////////////////////////////////
     //GETTING AND FIXING SENT DATA//
     ////////////////////////////////
     $p_sCategory = Params::getParam('sCategory');
     if (!is_array($p_sCategory)) {
         if ($p_sCategory == '') {
             $p_sCategory = array();
         } else {
             $p_sCategory = explode(",", $p_sCategory);
         }
     }
     $p_sCity = Params::getParam('sCity');
     if (!is_array($p_sCity)) {
         if ($p_sCity == '') {
             $p_sCity = array();
         } else {
             $p_sCity = explode(",", $p_sCity);
         }
     }
     $p_sRegion = Params::getParam('sRegion');
     if (!is_array($p_sRegion)) {
         if ($p_sRegion == '') {
             $p_sRegion = array();
         } else {
             $p_sRegion = explode(",", $p_sRegion);
         }
     }
     $p_sCountry = Params::getParam('sCountry');
     if (!is_array($p_sCountry)) {
         if ($p_sCountry == '') {
             $p_sCountry = array();
         } else {
             $p_sCountry = explode(",", $p_sCountry);
         }
     }
     $p_sPattern = strip_tags(Params::getParam('sPattern'));
     $p_bPic = Params::getParam('bPic');
     $p_bPic == 1 ? $p_bPic = 1 : ($p_bPic = 0);
     $p_sPriceMin = Params::getParam('sPriceMin');
     $p_sPriceMax = Params::getParam('sPriceMax');
     //WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting()
     $p_sOrder = Params::getParam('sOrder');
     if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) {
         $p_sOrder = osc_default_order_field_at_search();
     }
     //ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES
     $p_iOrderType = Params::getParam('iOrderType');
     $allowedTypesForSorting = Search::getAllowedTypesForSorting();
     $orderType = osc_default_order_type_at_search();
     foreach ($allowedTypesForSorting as $k => $v) {
         if ($p_iOrderType == $v) {
             $orderType = $k;
             break;
         }
     }
     $p_iOrderType = $orderType;
     $p_sFeed = Params::getParam('sFeed');
     $p_iPage = intval(Params::getParam('iPage'));
     if ($p_sFeed != '') {
         $p_sPageSize = 1000;
     }
     $p_sShowAs = Params::getParam('sShowAs');
     $aValidShowAsValues = array('list', 'gallery');
     if (!in_array($p_sShowAs, $aValidShowAsValues)) {
         $p_sShowAs = osc_default_show_as_at_search();
     }
     // search results: it's blocked with the maxResultsPerPage@search defined in t_preferences
     $p_iPageSize = intval(Params::getParam('iPagesize'));
     if ($p_iPageSize > 0) {
         if ($p_iPageSize > osc_max_results_per_page_at_search()) {
             $p_iPageSize = osc_max_results_per_page_at_search();
         }
     } else {
         $p_iPageSize = osc_default_results_per_page_at_search();
     }
     //FILTERING CATEGORY
     $bAllCategoriesChecked = false;
     if (count($p_sCategory) > 0) {
         foreach ($p_sCategory as $category) {
             $this->mSearch->addCategory($category);
         }
     } else {
         $bAllCategoriesChecked = true;
     }
     //FILTERING CITY
     foreach ($p_sCity as $city) {
         $this->mSearch->addCity($city);
     }
     $p_sCity = implode(", ", $p_sCity);
     //FILTERING REGION
     foreach ($p_sRegion as $region) {
         $this->mSearch->addRegion($region);
     }
     $p_sRegion = implode(", ", $p_sRegion);
     //FILTERING COUNTRY
     foreach ($p_sCountry as $country) {
         $this->mSearch->addCountry($country);
     }
     $p_sCountry = implode(", ", $p_sCountry);
     // FILTERING PATTERN
     if ($p_sPattern != '') {
         $this->mSearch->addConditions(sprintf("(d.s_title LIKE '%%%s%%' OR d.s_description LIKE '%%%s%%')", $p_sPattern, $p_sPattern));
         $osc_request['sPattern'] = $p_sPattern;
     }
     // FILTERING IF WE ONLY WANT ITEMS WITH PICS
     if ($p_bPic) {
         $this->mSearch->withPicture(true);
     }
     //FILTERING BY RANGE PRICE
     $this->mSearch->priceRange($p_sPriceMin, $p_sPriceMax);
     //ORDERING THE SEARCH RESULTS
     $this->mSearch->order($p_sOrder, $allowedTypesForSorting[$p_iOrderType]);
     //SET PAGE
     $this->mSearch->page($p_iPage, $p_iPageSize);
     osc_run_hook('search_conditions', Params::getParamsAsArray());
     $this->mSearch->addConditions(sprintf("%st_item.e_status = 'ACTIVE' ", DB_TABLE_PREFIX));
     // RETRIEVE ITEMS AND TOTAL
     $iTotalItems = $this->mSearch->count();
     $aItems = $this->mSearch->doSearch();
     if (!Params::existParam('sFeed')) {
         $iStart = $p_iPage * $p_iPageSize;
         $iEnd = min(($p_iPage + 1) * $p_iPageSize, $iTotalItems);
         //Static data, which is the point?
         /*$aOrders   = array(
               __('Newly listed')       => array('sOrder' => 'dt_pub_date', 'iOrderType' => 'desc')
              ,__('Lower price first')  => array('sOrder' => 'f_price', 'iOrderType' => 'asc')
              ,__('Higher price first') => array('sOrder' => 'f_price', 'iOrderType' => 'desc')
           );*/
         $iNumPages = ceil($iTotalItems / $p_iPageSize);
         //Categories for select at view "search.php"
         $mCategories = new Category();
         $aCategories = $mCategories->findRootCategories();
         $mCategoryStats = new CategoryStats();
         $aCategories = $mCategories->toTree();
         foreach ($aCategories as $k => $v) {
             $iCategoryNumItems = CategoryStats::newInstance()->getNumItems($v);
             if ($iCategoryNumItems > 0) {
                 $aCategories[$k]['total'] = $iCategoryNumItems;
             } else {
                 unset($aCategories[$k]);
             }
         }
         osc_run_hook('search', $this->mSearch);
         //preparing variables...
         $this->_exportVariableToView('categories', $aCategories);
         $this->_exportVariableToView('search_start', $iStart);
         $this->_exportVariableToView('search_end', $iEnd);
         $this->_exportVariableToView('search_category', $p_sCategory);
         $this->_exportVariableToView('search_order_type', $p_iOrderType);
         $this->_exportVariableToView('search_order', $p_sOrder);
         $this->_exportVariableToView('search_pattern', $p_sPattern);
         $this->_exportVariableToView('search_total_pages', $iNumPages);
         $this->_exportVariableToView('search_page', $p_iPage);
         $this->_exportVariableToView('search_has_pic', $p_bPic);
         $this->_exportVariableToView('search_city', $p_sCity);
         $this->_exportVariableToView('search_price_min', $p_sPriceMin);
         $this->_exportVariableToView('search_price_max', $p_sPriceMax);
         $this->_exportVariableToView('search_total_items', $iTotalItems);
         $this->_exportVariableToView('items', $aItems);
         $this->_exportVariableToView('search_show_as', $p_sShowAs);
         $this->_exportVariableToView('search', $this->mSearch);
         //calling the view...
         $this->doView('search.php');
     } else {
         $this->_exportVariableToView('items', $aItems);
         if ($p_sFeed == '' || $p_sFeed == 'rss') {
             // FEED REQUESTED!
             header('Content-type: text/xml; charset=utf-8');
             $feed = new RSSFeed();
             $feed->setTitle(__('Latest items added') . ' - ' . osc_page_title());
             $feed->setLink(osc_base_url());
             $feed->setDescription(__('Latest items added in') . ' ' . osc_page_title());
             if (osc_count_items() > 0) {
                 while (osc_has_items()) {
                     $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url()), 'description' => osc_item_description()));
                 }
             }
             osc_run_hook('feed', $feed);
             $feed->dumpXML();
         } else {
             osc_run_hook('feed_' . $p_sFeed, $aItems);
         }
     }
 }
Example #10
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'bulk_actions':
             switch (Params::getParam('bulk_actions')) {
                 case 'enable_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_enabled' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d item has been enabled', '%d items have been enabled', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'disable_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_enabled' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d item has been disabled', '%d items have been disabled', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'activate_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_active' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d item has been activated', '%d items have been activated', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'deactivate_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_active' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             }
                             osc_add_flash_ok_message(sprintf(_m('%d item has been deactivated', '%d items have been deactivated', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'premium_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             $count = count($id);
                             $mItems = new ItemActions(true);
                             foreach ($id as $_id) {
                                 $mItems->premium($_id);
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d item has been marked as premium', '%d items have been marked as premium', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'depremium_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             $count = count($id);
                             $mItems = new ItemActions(true);
                             foreach ($id as $_id) {
                                 $mItems->premium($_id, false);
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d change has been made', '%d changes have been made', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'spam_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_spam' => $value), array('pk_i_id' => $_id));
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d item has been marked as spam', '%d items have been marked as spam', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'despam_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             $count = count($id);
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_spam' => $value), array('pk_i_id' => $_id));
                             }
                             osc_add_flash_ok_message(sprintf(_mn('%d change have been made', '%d changes have been made', $count), $count), 'admin');
                         }
                     } catch (Exception $e) {
                         osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
                     }
                     break;
                 case 'delete_all':
                     $id = Params::getParam('id');
                     $success = false;
                     if ($id != '') {
                         $count = count($id);
                         foreach ($id as $i) {
                             if ($i) {
                                 $item = $this->itemManager->findByPrimaryKey($i);
                                 $mItems = new ItemActions(true);
                                 $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                             }
                         }
                     }
                     if ($success) {
                         osc_add_flash_ok_message(sprintf(_mn('%d item has been deleted', '%d items have been deleted', $count), $count), 'admin');
                     } else {
                         osc_add_flash_error_message(_m('The item couldn\'t be deleted'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . "?page=items");
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'delete':
             //delete
             $id = Params::getParam('id');
             $success = false;
             foreach ($id as $i) {
                 if ($i) {
                     $item = $this->itemManager->findByPrimaryKey($i);
                     $mItems = new ItemActions(true);
                     $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                 }
             }
             if ($success) {
                 osc_add_flash_ok_message(_m('The item has been deleted'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('The item couldn\'t be deleted'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status':
             //status
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array('ACTIVE', 'INACTIVE', 'ENABLE', 'DISABLE'))) {
                 return false;
             }
             try {
                 $item = $this->itemManager->findByPrimaryKey($id);
                 switch ($value) {
                     case 'ACTIVE':
                         $this->itemManager->update(array('b_active' => 1), array('pk_i_id' => $id));
                         osc_add_flash_ok_message(_m('The item has been activated'), 'admin');
                         if ($item['b_enabled'] == 1 && $item['b_active'] == 0) {
                             CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             if ($item['fk_i_user_id'] != null) {
                                 $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']);
                                 if ($user) {
                                     User::newInstance()->update(array('i_items' => $user['i_items'] + 1), array('pk_i_id' => $user['pk_i_id']));
                                 }
                             }
                         }
                         break;
                     case 'INACTIVE':
                         $this->itemManager->update(array('b_active' => 0), array('pk_i_id' => $id));
                         osc_add_flash_ok_message(_m('The item has been deactivated'), 'admin');
                         if ($item['b_enabled'] == 1 && $item['b_active'] == 1) {
                             CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             if ($item['fk_i_user_id'] != null) {
                                 $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']);
                                 if ($user) {
                                     User::newInstance()->update(array('i_items' => $user['i_items'] - 1), array('pk_i_id' => $user['pk_i_id']));
                                 }
                             }
                         }
                         break;
                     case 'ENABLE':
                         $this->itemManager->update(array('b_enabled' => 1), array('pk_i_id' => $id));
                         osc_add_flash_ok_message(_m('The item has been enabled'), 'admin');
                         if ($item['b_enabled'] == 0 && $item['b_active'] == 1) {
                             CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             if ($item['fk_i_user_id'] != null) {
                                 $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']);
                                 if ($user) {
                                     User::newInstance()->update(array('i_items' => $user['i_items'] + 1), array('pk_i_id' => $user['pk_i_id']));
                                 }
                             }
                         }
                         break;
                     case 'DISABLE':
                         $this->itemManager->update(array('b_enabled' => 0), array('pk_i_id' => $id));
                         osc_add_flash_ok_message(_m('The item has been disabled'), 'admin');
                         if ($item['b_enabled'] == 1 && $item['b_active'] == 1) {
                             CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             if ($item['fk_i_user_id'] != null) {
                                 $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']);
                                 if ($user) {
                                     User::newInstance()->update(array('i_items' => $user['i_items'] - 1), array('pk_i_id' => $user['pk_i_id']));
                                 }
                             }
                         }
                         break;
                 }
             } catch (Exception $e) {
                 osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status_premium':
             //status premium
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array(0, 1))) {
                 return false;
             }
             try {
                 $mItems = new ItemActions(true);
                 $mItems->premium($id, $value == 1 ? true : false);
                 /*$this->itemManager->update(
                           array('b_premium' => $value),
                           array('pk_i_id' => $id)
                   );*/
                 osc_add_flash_ok_message(_m('Changes have been applied'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status_spam':
             //status spam
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array(0, 1))) {
                 return false;
             }
             try {
                 $this->itemManager->update(array('b_spam' => $value), array('pk_i_id' => $id));
                 osc_add_flash_ok_message(_m('Changes have been applied'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_error_message(sprintf(_m('Error: %s'), $e->getMessage()), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'clear_stat':
             $id = Params::getParam('id');
             $stat = Params::getParam('stat');
             if (!$id) {
                 return false;
             }
             if (!$stat) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             $success = $this->itemManager->clearStat($id, $stat);
             if ($success) {
                 osc_add_flash_ok_message(_m('The item has been unmarked as') . " {$stat}", 'admin');
             } else {
                 osc_add_flash_error_message(_m('The item hasn\'t been unmarked as') . " {$stat}", 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items&stat=" . $stat);
             break;
         case 'item_edit':
             // edit item
             $id = Params::getParam('id');
             $item = Item::newInstance()->findByPrimaryKey($id);
             if (count($item) <= 0) {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             }
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $this->_exportVariableToView("item", $item);
             $this->_exportVariableToView("new_item", FALSE);
             $this->doView('items/frm.php');
             break;
         case 'item_edit_post':
             $mItems = new ItemActions(true);
             $mItems->prepareData(false);
             // set all parameters into session
             foreach ($mItems->data as $key => $value) {
                 Session::newInstance()->_setForm($key, $value);
             }
             $meta = Params::getParam('meta');
             if (is_array($meta)) {
                 foreach ($meta as $key => $value) {
                     Session::newInstance()->_setForm('meta_' . $key, $value);
                     Session::newInstance()->_keepForm('meta_' . $key);
                 }
             }
             $success = $mItems->edit();
             if ($success == 1) {
                 $id = Params::getParam('userId');
                 if ($id != '') {
                     $user = User::newInstance()->findByPrimaryKey($id);
                     Item::newInstance()->update(array('fk_i_user_id' => $id, 's_contact_name' => $user['s_name'], 's_contact_email' => $user['s_email']), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
                 } else {
                     Item::newInstance()->update(array('fk_i_user_id' => NULL, 's_contact_name' => Params::getParam('contactName'), 's_contact_email' => Params::getParam('contactEmail')), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
                 }
                 osc_add_flash_ok_message(_m('Changes saved correctly'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             } else {
                 osc_add_flash_error_message($success, 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items&action=item_edit&id=" . Params::getParam('id'));
             }
             break;
         case 'deleteResource':
             //delete resource
             $id = Params::getParam('id');
             $name = Params::getParam('name');
             $fkid = Params::getParam('fkid');
             // delete files
             osc_deleteResource($id);
             ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $fkid, 's_name' => $name));
             osc_add_flash_ok_message(_m('Resource deleted'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'post':
             // add item
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $this->_exportVariableToView("new_item", TRUE);
             $this->doView('items/frm.php');
             break;
         case 'post_item':
             //post item
             $mItem = new ItemActions(true);
             $mItem->prepareData(true);
             // set all parameters into session
             foreach ($mItem->data as $key => $value) {
                 Session::newInstance()->_setForm($key, $value);
             }
             $meta = Params::getParam('meta');
             if (is_array($meta)) {
                 foreach ($meta as $key => $value) {
                     Session::newInstance()->_setForm('meta_' . $key, $value);
                     Session::newInstance()->_keepForm('meta_' . $key);
                 }
             }
             $success = $mItem->add();
             if ($success == 1 || $success == 2) {
                 osc_add_flash_ok_message(_m('A new item has been added'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             } else {
                 osc_add_flash_error_message($success, 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items&action=post");
             }
             break;
         case 'settings':
             // calling the items settings view
             $this->doView('items/settings.php');
             break;
         case 'settings_post':
             // update item settings
             $iUpdated = 0;
             $enabledRecaptchaItems = Params::getParam('enabled_recaptcha_items');
             $enabledRecaptchaItems = $enabledRecaptchaItems != '' ? true : false;
             $moderateItems = Params::getParam('moderate_items');
             $moderateItems = $moderateItems != '' ? true : false;
             $numModerateItems = Params::getParam('num_moderate_items');
             $itemsWaitTime = Params::getParam('items_wait_time');
             $loggedUserItemValidation = Params::getParam('logged_user_item_validation');
             $loggedUserItemValidation = $loggedUserItemValidation != '' ? true : false;
             $regUserPost = Params::getParam('reg_user_post');
             $regUserPost = $regUserPost != '' ? true : false;
             $notifyNewItem = Params::getParam('notify_new_item');
             $notifyNewItem = $notifyNewItem != '' ? true : false;
             $notifyContactItem = Params::getParam('notify_contact_item');
             $notifyContactItem = $notifyContactItem != '' ? true : false;
             $notifyContactFriends = Params::getParam('notify_contact_friends');
             $notifyContactFriends = $notifyContactFriends != '' ? true : false;
             $enabledFieldPriceItems = Params::getParam('enableField#f_price@items');
             $enabledFieldPriceItems = $enabledFieldPriceItems != '' ? true : false;
             $enabledFieldImagesItems = Params::getParam('enableField#images@items');
             $enabledFieldImagesItems = $enabledFieldImagesItems != '' ? true : false;
             $numImagesItems = Params::getParam('numImages@items');
             if ($numImagesItems == '') {
                 $numImagesItems = 0;
             }
             $regUserCanContact = Params::getParam('reg_user_can_contact');
             $regUserCanContact = $regUserCanContact != '' ? true : false;
             $iUpdated += Preference::newInstance()->update(array('s_value' => $enabledRecaptchaItems), array('s_name' => 'enabled_recaptcha_items'));
             if ($moderateItems) {
                 $iUpdated += Preference::newInstance()->update(array('s_value' => $numModerateItems), array('s_name' => 'moderate_items'));
             } else {
                 $iUpdated += Preference::newInstance()->update(array('s_value' => '-1'), array('s_name' => 'moderate_items'));
             }
             $iUpdated += Preference::newInstance()->update(array('s_value' => $loggedUserItemValidation), array('s_name' => 'logged_user_item_validation'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $regUserPost), array('s_name' => 'reg_user_post'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $notifyNewItem), array('s_name' => 'notify_new_item'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $notifyContactItem), array('s_name' => 'notify_contact_item'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $notifyContactFriends), array('s_name' => 'notify_contact_friends'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $enabledFieldPriceItems), array('s_name' => 'enableField#f_price@items'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $enabledFieldImagesItems), array('s_name' => 'enableField#images@items'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $itemsWaitTime), array('s_name' => 'items_wait_time'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $numImagesItems), array('s_name' => 'numImages@items'));
             $iUpdated += Preference::newInstance()->update(array('s_value' => $regUserCanContact), array('s_name' => 'reg_user_can_contact'));
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message(_m('Items\' settings have been updated'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=items&action=settings');
             break;
         default:
             //default
             $catId = Params::getParam('catId');
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (count($countries) > 0) {
                 $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
             }
             $cities = array();
             if (count($regions) > 0) {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
             }
             //preparing variables for the view
             $this->_exportVariableToView("users", User::newInstance()->listAll());
             $this->_exportVariableToView("catId", $catId);
             $this->_exportVariableToView("stat", Params::getParam('stat'));
             $this->_exportVariableToView("countries", $countries);
             $this->_exportVariableToView("regions", $regions);
             $this->_exportVariableToView("cities", $cities);
             //calling the view...
             $this->doView('items/index.php');
     }
 }
Example #11
0
 public function deleteByPrimaryKey($id)
 {
     osc_run_hook('delete_item', $id);
     $item = $this->findByPrimaryKey($id);
     if ($item['b_active'] == 1) {
         CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
     }
     $this->conn->osc_dbExec('DELETE FROM %st_item_description WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     $this->conn->osc_dbExec('DELETE FROM %st_item_comment WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     $this->conn->osc_dbExec('DELETE FROM %st_item_resource WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     $this->conn->osc_dbExec('DELETE FROM %st_item_location WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     $this->conn->osc_dbExec('DELETE FROM %st_item_stats WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     $this->conn->osc_dbExec('DELETE FROM %st_item_meta WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $id);
     return $this->conn->osc_dbExec('DELETE FROM %st_item WHERE pk_i_id = %d', DB_TABLE_PREFIX, $id);
 }
Example #12
0
 /**
  * Delete by primary key, delete dependencies too
  *
  * @access public
  * @since unknown
  * @param int $id Item id
  * @return bool
  */
 public function deleteByPrimaryKey($id)
 {
     osc_run_hook('delete_item', $id);
     $item = $this->findByPrimaryKey($id);
     if (is_null($item)) {
         return false;
     }
     if ($item['b_active'] == 1) {
         CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
     }
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_description', "fk_i_item_id = {$id}");
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_comment', "fk_i_item_id = {$id}");
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_resource', "fk_i_item_id = {$id}");
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_location', "fk_i_item_id = {$id}");
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_stats', "fk_i_item_id = {$id}");
     $this->dao->delete(DB_TABLE_PREFIX . 't_item_meta', "fk_i_item_id = {$id}");
     $res = parent::deleteByPrimaryKey($id);
     return $res;
 }
Example #13
0
 /**
  *
  * @param <type> $secret
  * @param <type> $itemId
  */
 public function delete($secret, $itemId)
 {
     $item = $this->manager->findByPrimaryKey($itemId);
     $this->deleteResourcesFromHD($itemId);
     $result = $this->manager->delete(array('pk_i_id' => $itemId, 's_secret' => $secret));
     if ($item['e_status'] == 'ACTIVE') {
         CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
     }
     return $result;
 }
Example #14
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'bulk_actions':
             switch (Params::getParam('bulk_actions')) {
                 case 'activate_all':
                     $id = Params::getParam('id');
                     $value = 'ACTIVE';
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             }
                         }
                         osc_add_flash_message(_m('The items have been activated'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'deactivate_all':
                     $id = Params::getParam('id');
                     $value = 'INACTIVE';
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             }
                         }
                         osc_add_flash_message(_m('The items have been deactivated'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'premium_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $_id));
                             }
                         }
                         osc_add_flash_message(_m('The items have been marked as premium'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'depremium_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $_id));
                             }
                         }
                         osc_add_flash_message(_m('The changes have been made'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'delete_all':
                     $id = Params::getParam('id');
                     $success = false;
                     foreach ($id as $i) {
                         if ($i) {
                             $item = $this->itemManager->findByPrimaryKey($i);
                             $mItems = new ItemActions(true);
                             $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                         }
                     }
                     if ($success) {
                         osc_add_flash_message(_m('The item has been deleted'), 'admin');
                     } else {
                         osc_add_flash_message(_m('The item couldn\'t be deleted'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . "?page=items");
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'delete':
             //delete
             $id = Params::getParam('id');
             $success = false;
             foreach ($id as $i) {
                 if ($i) {
                     $item = $this->itemManager->findByPrimaryKey($i);
                     $mItems = new ItemActions(true);
                     $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                 }
             }
             if ($success) {
                 osc_add_flash_message(_m('The item has been deleted'), 'admin');
             } else {
                 osc_add_flash_message(_m('The item couldn\'t be deleted'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status':
             //status
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array('ACTIVE', 'INACTIVE'))) {
                 return false;
             }
             try {
                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $id));
                 $item = $this->itemManager->findByPrimaryKey($id);
                 switch ($value) {
                     case 'ACTIVE':
                         osc_add_flash_message(_m('The item has been activated'), 'admin');
                         CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                         break;
                     case 'INACTIVE':
                         osc_add_flash_message(_m('The item has been deactivated'), 'admin');
                         CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                         break;
                 }
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status_premium':
             //status premium
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array(0, 1))) {
                 return false;
             }
             try {
                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $id));
                 osc_add_flash_message(_m('Changes have been applied'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'item_edit':
             //require_once LIB_PATH . 'osclass/itemActions.php';
             $id = Params::getParam('id');
             $item = Item::newInstance()->findByPrimaryKey($id);
             if (count($item) <= 0) {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             }
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (count($countries) > 0) {
                 $regions = Region::newInstance()->getByCountry($item['fk_c_country_code']);
             }
             $cities = array();
             if (count($regions) > 0) {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $item['fk_i_region_id']);
             }
             $resources = Item::newInstance()->findResourcesByID($id);
             $this->_exportVariableToView("users", User::newInstance()->listAll());
             $this->_exportVariableToView("categories", Category::newInstance()->toTree());
             $this->_exportVariableToView("countries", $countries);
             $this->_exportVariableToView("regions", $regions);
             $this->_exportVariableToView("cities", $cities);
             $this->_exportVariableToView("currencies", Currency::newInstance()->listAll());
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->_exportVariableToView("item", $item);
             $this->_exportVariableToView("resources", $resources);
             $this->_exportVariableToView("new_item", FALSE);
             $this->doView('items/frm.php');
             break;
         case 'item_edit_post':
             $mItems = new ItemActions(true);
             $success = $mItems->edit();
             $id = Params::getParam('userId');
             if ($id != '') {
                 $user = User::newInstance()->findByPrimaryKey($id);
                 Item::newInstance()->update(array('fk_i_user_id' => $id, 's_contact_name' => $user['s_name'], 's_contact_email' => $user['s_email']), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
             } else {
                 Item::newInstance()->update(array('fk_i_user_id' => NULL, 's_contact_name' => Params::getParam('contactName'), 's_contact_email' => Params::getParam('contactEmail')), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
             }
             osc_add_flash_message(_m('Changes saved correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'deleteResource':
             //delete resource
             $id = Params::getParam('id');
             $name = Params::getParam('name');
             $fkid = Params::getParam('fkid');
             // delete files
             osc_deleteResource($id);
             ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $fkid, 's_name' => $name));
             osc_add_flash_message(_m('Resource deleted'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'post':
             //post
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (count($countries) > 0) {
                 $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
             }
             $cities = array();
             if (count($regions) > 0) {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
             }
             $this->_exportVariableToView("users", User::newInstance()->listAll());
             $this->_exportVariableToView("categories", Category::newInstance()->toTree());
             $this->_exportVariableToView("countries", $countries);
             $this->_exportVariableToView("regions", $regions);
             $this->_exportVariableToView("cities", $cities);
             $this->_exportVariableToView("currencies", Currency::newInstance()->listAll());
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->_exportVariableToView("item", array());
             $this->_exportVariableToView("resources", array());
             $this->_exportVariableToView("new_item", TRUE);
             $this->doView('items/frm.php');
             break;
         case 'post_item':
             //post item
             $mItem = new ItemActions(true);
             $success = $mItem->add();
             if ($success) {
                 osc_add_flash_message(_m('A new item has been added'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             } else {
                 osc_add_flash_message(_m('The item can\'t be added'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             }
             break;
         default:
             //default
             $catId = Params::getParam('catId');
             //preparing variables for the view
             $this->_exportVariableToView("items", $catId ? $this->itemManager->findByCategoryID($catId) : $this->itemManager->listAllWithCategories());
             $this->_exportVariableToView("catId", $catId);
             $this->_exportVariableToView("stat", Params::getParam('stat'));
             //calling the view...
             $this->doView('items/index.php');
     }
 }
Example #15
0
/**
 * Gets the total items related with the current category
 *
 * @return <int>
 */
function osc_category_total_items()
{
    $category = osc_category();
    return CategoryStats::newInstance()->getNumItems($category);
}