Exemplo n.º 1
0
 function fav()
 {
     $fav = $this->getFavorites();
     if (bff::$isAjax) {
         $aResponse = array();
         $nUserID = $this->security->getUserID();
         switch (func::GET('act')) {
             case 'fav':
                 $nItemID = $this->input->id('id', 'p');
                 if (!$nItemID || !$nUserID) {
                     $this->errors->set(Errors::IMPOSSIBLE);
                     break;
                 }
                 $exists = $this->db->one_data('SELECT item_id FROM ' . TABLE_BBS_ITEMS_FAV . ' WHERE item_id = ' . $nItemID . ' AND user_id = ' . $nUserID);
                 if (!empty($exists)) {
                     $this->db->execute('DELETE FROM ' . TABLE_BBS_ITEMS_FAV . ' WHERE item_id = ' . $nItemID . ' AND user_id = ' . $nUserID);
                     $aResponse['added'] = false;
                 } else {
                     $this->db->execute('INSERT INTO ' . TABLE_BBS_ITEMS_FAV . ' (item_id, user_id) 
                         VALUES(' . $nItemID . ',' . $nUserID . ')');
                     $aResponse['added'] = true;
                 }
                 break;
             case 'email_bulk':
                 if (!$nUserID) {
                     $this->errors->set(Errors::IMPOSSIBLE);
                     break;
                 }
                 $aData = $this->input->postm(array('items' => TYPE_ARRAY_UINT));
                 if (empty($aData['items'])) {
                     $this->errors->set('Необходимо отметить объявления в списке');
                     break;
                 }
                 $aData['items'] = $this->db->select('SELECT
                       I.id, I.status, I.publicated,
                       I.cat1_id,   CAT1.title as cat1_title,
                       I.cat2_id,   CAT2.title as cat2_title,
                       I.cat_id,    C.regions as cat_regions, C.prices as cat_prices, C.prices_sett as cat_prices_sett,
                       I.cat_type,  CT.title as cat_type_title,
                       I.cat_subtype,  CST.title as cat_subtype_title,
                       I.imgfav, I.imgcnt, I.price, I.descr, I.descr_regions, I.price, I.price_torg, I.price_bart,
                       I.contacts_name, I.contacts_email, I.contacts_phone, I.contacts_skype, I.contacts_site
                   FROM ' . TABLE_BBS_ITEMS . ' I
                     LEFT JOIN ' . TABLE_BBS_CATEGORIES . ' CAT2 ON I.cat2_id = CAT2.id
                     LEFT JOIN ' . TABLE_BBS_CATEGORIES_TYPES . ' CT ON I.cat_type = CT.id
                     LEFT JOIN ' . TABLE_BBS_CATEGORIES_SUBTYPES . ' CST ON I.cat_subtype = CST.id
                     LEFT JOIN ' . TABLE_USERS . ' U ON I.user_id = U.user_id,
                     ' . TABLE_BBS_CATEGORIES . ' CAT1,
                     ' . TABLE_BBS_CATEGORIES . ' C
                   WHERE ' . $this->db->prepareIN('I.id', $aData['items']) . '
                     AND CAT1.id = I.cat1_id
                     AND C.id = I.cat_id
                     AND (I.user_id = 0 OR U.blocked!=1)
                   ORDER BY I.publicated ASC');
                 if (!empty($aData['items'])) {
                     $res = bff::sendMail($this->security->getUserEmail(), BFF_EMAIL_FROM_NAME, $this->tplFetchPHP($aData, 'items.list.fav2email.php'));
                     //$this->errors->set( ($res ? Errors::SUCCESS : Errors::IMPOSSIBLE) );
                 }
                 break;
             case 'unfav_bulk':
                 $aItemsID = $this->input->post('items', TYPE_ARRAY_UINT);
                 $nResultTotal = 0;
                 if (empty($aItemsID)) {
                     $this->errors->set(Errors::IMPOSSIBLE);
                     break;
                 }
                 if ($fav['total'] == 0) {
                     $this->errors->set(Errors::IMPOSSIBLE);
                     break;
                 }
                 if ($nUserID) {
                     $res = $this->db->execute('DELETE FROM ' . TABLE_BBS_ITEMS_FAV . ' WHERE user_id = ' . $nUserID . ' AND ' . $this->db->prepareIN('item_id', $aItemsID));
                     $nResultTotal = $fav['total'] - intval($res);
                 } else {
                     $aRemoveID = array_intersect($fav['id'], $aItemsID);
                     $aResultID = array_diff($fav['id'], $aRemoveID);
                     func::setCOOKIE(BFF_COOKIE_PREFIX . 'bbs_fav', !empty($aResultID) ? join(',', $aResultID) : '', BBS_FAV_COOKIE_EXPIRE, '/', '.' . SITEHOST);
                     $nResultTotal = !empty($aResultID) ? sizeof($aResultID) : 0;
                 }
                 $aResponse['total'] = $nResultTotal;
                 break;
             default:
                 $this->errors->set(Errors::IMPOSSIBLE);
         }
         $aResponse['res'] = $this->errors->no();
         $this->ajaxResponse($aResponse);
     }
     $aData = array('items' => array());
     if ($fav['total'] > 0) {
         $sqlItemsIN = $this->db->prepareIN('I.id', $fav['id']);
         $aData['items'] = $this->db->select('SELECT
               I.id, I.status, I.svc,
               I.cat1_id,   CAT1.title as cat1_title,
               I.cat2_id,   CAT2.title as cat2_title,
               I.cat_id,    C.regions as cat_regions, C.prices as cat_prices, C.prices_sett as cat_prices_sett,
               I.cat_type,  CT.title as cat_type_title,
               I.cat_subtype,  CST.title as cat_subtype_title,
               I.imgfav, I.imgcnt, I.price, I.descr, I.descr_regions, I.price, I.price_torg, I.price_bart,
               I.views_total, IV.views,
               U.blocked as user_blocked
               FROM ' . TABLE_BBS_ITEMS . ' I
                 LEFT JOIN ' . TABLE_BBS_CATEGORIES . ' CAT2 ON I.cat2_id = CAT2.id
                 LEFT JOIN ' . TABLE_BBS_CATEGORIES_TYPES . ' CT ON I.cat_type = CT.id
                 LEFT JOIN ' . TABLE_BBS_CATEGORIES_SUBTYPES . ' CST ON I.cat_subtype = CST.id
                 LEFT JOIN ' . TABLE_BBS_ITEMS_VIEWS . ' IV ON I.id = IV.item_id AND IV.views_date = ' . $this->db->str2sql(date('Y-m-d')) . '
                 LEFT JOIN ' . TABLE_USERS . ' U ON I.user_id = U.user_id,
                 ' . TABLE_BBS_CATEGORIES . ' CAT1,
                 ' . TABLE_BBS_CATEGORIES . ' C
               WHERE ' . $sqlItemsIN . '
                 AND CAT1.id = I.cat1_id
                 AND C.id = I.cat_id
               ORDER BY I.publicated ASC');
         $aData['cats'] = $this->db->select('SELECT C.id, C.title 
                 FROM ' . TABLE_BBS_ITEMS . ' I, ' . TABLE_BBS_CATEGORIES . ' C
                 WHERE ' . $sqlItemsIN . ' AND I.cat1_id = C.id AND C.numlevel = 1 AND C.enabled = 1
                 GROUP BY C.id');
     }
     config::set('userMenuCurrent', 1);
     return $this->tplFetchPHP($aData, 'items.list.fav.php');
 }