public function execute() { $tp = SJB_System::getTemplateProcessor(); $current_user = SJB_UserManager::getCurrentUser(); $action = SJB_Request::getVar('action', 'productList'); $productSID = SJB_Request::getVar('product_sid', 0, 'default', 'int'); $template = 'products.tpl'; $availableProducts = array(); $errors = array(); switch ($action) { case 'productList': if (SJB_UserManager::isUserLoggedIn()) { $postingProductsOnly = SJB_Request::getVar('postingProductsOnly', false); $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($current_user->getUserGroupSID(), $current_user->getSID()); $trialProduncts = $current_user->getTrialProductSIDByUserSID(); foreach ($availableProducts as $key => $availableProduct) { if (in_array($availableProduct['sid'], $trialProduncts) || $postingProductsOnly && $availableProduct['product_type'] != "post_listings" && $availableProduct['product_type'] != "mixed_product") { unset($availableProducts[$key]); } } if ($postingProductsOnly) { $tp->assign('postingProductsOnly', $postingProductsOnly); } } elseif ($userGroupID = SJB_Request::getVar('userGroupID', false)) { $userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID); $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($userGroupSID, 0); } else { $availableProducts = SJB_ProductsManager::getAllActiveProducts(); } foreach ($availableProducts as $key => $availableProductInfo) { if (SJB_ProductsManager::isProductTrialAndAlreadyInCart($availableProductInfo, $current_user)) { unset($availableProducts[$key]); continue; } $availableProduct = new SJB_Product($availableProductInfo, $availableProductInfo['product_type']); $availableProduct->setNumberOfListings(1); $availableProducts[$key]['price'] = $availableProduct->getPrice(); if (isset($availableProducts[$key]['listing_type_sid'])) { $availableProducts[$key]['listing_type_id'] = SJB_ListingTypeDBManager::getListingTypeIDBySID($availableProducts[$key]['listing_type_sid']); } } SJB_Event::dispatch('RedefineTemplateName', $template, true); SJB_Event::dispatch('RedefineProductsDisplayInfo', $availableProducts, true); $tp->assign("account_activated", SJB_Request::getVar('account_activated', '')); $tp->assign("availableProducts", $availableProducts); break; case 'view_product_detail': $template = 'view_product_detail.tpl'; if (!SJB_UserManager::isUserLoggedIn() || $current_user->mayChooseProduct($productSID, $errors)) { $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID); if (in_array($productInfo['product_type'], array('post_listings', 'mixed_product'))) { $productInfo['listingTypeID'] = SJB_ListingTypeManager::getListingTypeIDBySID($productInfo['listing_type_sid']); } $event = SJB_Request::getVar('event', false); if ($event) { if ($productInfo) { switch ($productInfo['product_type']) { case 'banners': $params = $_REQUEST; if (empty($params['title'])) { $errors[] = "Banner Title is empty."; } if (empty($params['link'])) { $errors[] = "Banner link mismatched!"; } if (empty($_FILES['image']['name'])) { $errors[] = "No file attached!"; } elseif ($_FILES['image']['error']) { switch ($_FILES['image']['error']) { case '1': $errors[] = 'UPLOAD_ERR_INI_SIZE'; break; case '2': $errors[] = 'UPLOAD_ERR_FORM_SIZE'; break; case '3': $errors[] = 'UPLOAD_ERR_PARTIAL'; break; case '4': $errors[] = 'UPLOAD_ERR_NO_FILE'; break; default: $errors[] = 'NOT_UPLOAD_FILE'; break; } } else { $imageInfo = @getimagesize($_FILES['image']['tmp_name']); if (!$imageInfo || $imageInfo['2'] < 1 && $imageInfo['2'] > 3) { $errors[] = 'Image format is not supported'; } elseif (!empty($productInfo['width']) && $imageInfo[0] != $productInfo['width']) { $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner."; } elseif (!empty($productInfo['height']) && $imageInfo[1] != $productInfo['height']) { $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner."; } } if ($errors) { break; } //add banner $title = $params['title']; $link = $params['link']; $expr = preg_match("/(http:\\/\\/)/", $link, $matches); if ($expr != true) { $link = "http://" . $link; } $filesDir = SJB_System::getSystemSettings('FILES_DIR'); $ext = preg_match("|\\.(\\w{3})\\b|u", $_FILES['image']['name'], $arr); $fileName = preg_replace("|\\.(\\w{3})\\b|u", "", $_FILES['image']['name']); $hashName = md5(time() * $_FILES['image']['size']) . "_" . $fileName; $bannerFilePath = $filesDir . "banners/" . $hashName . "." . $arr[1]; $copy = move_uploaded_file($_FILES['image']['tmp_name'], $bannerFilePath); if (!$copy) { $errors[] = 'Cannot copy file from TMP dir to Banners Dir'; break; } if ($_FILES['image']['type'] != 'application/x-shockwave-flash') { $bannerInfo = getimagesize($bannerFilePath); if ($productInfo['width'] != '' && $productInfo['height'] != '') { $sx = $productInfo['width']; $sy = $productInfo['height']; } else { $sx = $bannerInfo[0]; $sy = $bannerInfo[1]; } $type = $bannerInfo['mime']; } else { if ($productInfo['width'] == '' || $productInfo['height'] == '') { $errors[] = 'Your banner dimensions exceed the required size. Please upload an appropriate banner.'; break; } $sx = $productInfo['width']; $sy = $productInfo['height']; $type = $_FILES['image']['type']; } $active = 0; $group = $productInfo['banner_group_sid']; $params['bannerFilePath'] = "/" . str_replace("../", "/", str_replace(SJB_BASE_DIR, '', $bannerFilePath)); $params['openBannerIn'] = ''; $params['bannerType'] = 'file'; $params['code'] = ''; $params['title'] = $title; $params['link'] = $link; $params['type'] = $type; $params['sx'] = $sx; $params['sy'] = $sy; $params['banner_group_sid'] = $group; $productInfo['banner_info'] = $params; break; } if (!$errors) { $numberOfListings = SJB_Request::getVar('number_of_listings'); $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID); if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based' && $numberOfListings) { $productInfo['number_of_listings'] = $numberOfListings; $productObj = new SJB_Product($productInfo, $productInfo['product_type']); $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1; $productObj->setNumberOfListings($number_of_listings); $productInfo['price'] = $productObj->getPrice(); } if (SJB_UserManager::isUserLoggedIn()) { SJB_ShoppingCart::addToShoppingCart($productInfo, $current_user->getSID()); } else { if (isset($_SESSION['products'])) { foreach ($_SESSION['products'] as $addedProduct) { $addedProductInfo = unserialize($addedProduct['product_info']); if ($addedProductInfo['user_group_sid'] != $productInfo['user_group_sid']) { $errors[] = 'You are trying to add products of different User Groups in your Shopping Cart. You сan add only products belonging to one User Group. If you want to add this product in the Shopping Cart please go back to the Shopping Cart and remove products of other User Groups.'; break; } } } if (!$errors) { $id = time(); $_SESSION['products'][$id]['product_info'] = serialize($productInfo); $_SESSION['products'][$id]['sid'] = $id; $_SESSION['products'][$id]['user_sid'] = 0; } } if (!$errors) { SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/'); } } } } if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) { $productInfo['period'] = ucwords($productInfo['expiration_period']); } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based' && !empty($productInfo['volume_based_pricing'])) { $volumeBasedPricing = $productInfo['volume_based_pricing']; $price = array(); $firstPrice = 0; if (!empty($volumeBasedPricing['listings_range_from'])) { for ($i = 1; $i <= count($volumeBasedPricing['listings_range_from']); $i++) { if ($volumeBasedPricing['listings_range_from'][$i] == $volumeBasedPricing['listings_range_to'][$i]) { $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i]; } else { $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i]; $price[$i]['range']['to'] = $volumeBasedPricing['listings_range_to'][$i]; } $price[$i]['price'] = $volumeBasedPricing['price_per_unit'][$i]; if ($i > 1 && $firstPrice > $volumeBasedPricing['price_per_unit'][$i]) { $price[$i]['savings'] = round(100 - 100 / $firstPrice * $volumeBasedPricing['price_per_unit'][$i]); } else { $firstPrice = $volumeBasedPricing['price_per_unit'][$i]; } } } $productInfo['volume_based_pricing'] = $price; $minListings = min($volumeBasedPricing['listings_range_from']); $maxListings = max($volumeBasedPricing['listings_range_to']); $countListings = array(); for ($i = $minListings; $i <= $maxListings; $i++) { $countListings[] = $i; } $productInfo['count_listings'] = $countListings; } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') { $productInfo['fixed_period'] = 1; } if ($productInfo['product_type'] == 'banners') { $params = $_REQUEST; $bannersObj = new SJB_Banners(); $banner_fields = $bannersObj->getBannersMeta(); foreach ($banner_fields as $key => $banner_field) { $banner_fields[$banner_field['id']] = $banner_field; if (!empty($params[$banner_field['id']])) { $banner_fields[$banner_field['id']]['value'] = $params[$banner_field['id']]; } unset($banner_fields[$key]); } if (!empty($params['errors'])) { $tp->assign("errors", $params['errors']); } $tp->assign("banner_fields", $banner_fields); } $userGroupID = SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']); $tp->assign('productInfo', $productInfo); $tp->assign('userGroupID', $userGroupID); $tp->assign('productSID', $productSID); $tp->assign('mayChooseProduct', true); } $tp->assign('errors', $errors); break; } $tp->display($template); }
public function execute() { $bannersObj = new SJB_Banners(); $params = $_REQUEST; $bannerId = $params['bannerId']; if (SJB_Request::isAjax()) { $response = array('success' => $bannersObj->deleteBannerImage($bannerId), 'error' => SJB_I18N::getInstance()->gettext('Backend', $bannersObj->bannersError)); die(json_encode($response)); } $tp = SJB_System::getTemplateProcessor(); $errors = array(); $banner = array_merge($bannersObj->getBannerProperties($bannerId), $params); $form_submitted = SJB_Request::getVar('submit'); $filesDir = SJB_System::getSystemSettings('FILES_DIR'); if (isset($_REQUEST['action'])) { $action_name = $_REQUEST['action']; switch ($action_name) { case 'edit': // ERRORS if ($params['title'] == '') { $errors[] = 'Banner Title is empty.'; } if ($params['link'] == '' && $params['bannerType'] != 'code') { $errors[] = 'Banner link mismatched!'; } if ($params['bannerType'] == 'code' && $params['code'] == '') { $errors[] = 'Banner code is empty.'; } if ($params['bannerType'] == 'file' && $_FILES['image']['name'] == '' && empty($params['imagePath'])) { $errors[] = 'No image attached!'; } if ($_FILES['image']['name'] && $_FILES['image']['error']) { $errors[SJB_UploadFileManager::getErrorId($_FILES['image']['error'])] = 1; } if ($errors) { break; } // if image changed - save it if ($_FILES['image']['name'] != '' && $_FILES['image']['tmp_name'] != '') { $hashName = md5(time() * $_FILES['image']['size'] . "_" . $_FILES['image']['name']); $ext = preg_match("|\\.(\\w{3})\\b|", $_FILES['image']['name'], $arr); $bannerFilePath = $filesDir . "banners/" . $hashName . "." . $arr[1]; // move file from temporary folder, and fill banner info to DB $copy = copy($_FILES['image']['tmp_name'], $bannerFilePath); if (!$copy) { $errors = 'Cannot copy file from TMP dir to Banners Dir'; break; } if ($_FILES['image']['type'] != 'application/x-shockwave-flash') { // array of bannerInfo // [0] - width // [1] - height // [2] - ?? // [3] - width & height in next view: width="104" height="150" // [bits] - bit size of image // [channels] // [mime] - type, (image/jpeg, image/gif, image/png ) $bannerInfo = getimagesize($bannerFilePath); if ($params['width'] != '' && $params['height'] != '') { $sx = $params['width']; $sy = $params['height']; } else { $sx = $bannerInfo[0]; $sy = $bannerInfo[1]; } $type = $bannerInfo['mime']; } else { if ($params['width'] == '' || $params['height'] == '') { $errors[] = 'SIZE_PARAMETER_MISMATCHED'; break; } $sx = $params['width']; $sy = $params['height']; $type = $_FILES['image']['type']; } $bannerFilePath = "/" . str_replace("../", "/", str_replace(SJB_BASE_DIR, '', $bannerFilePath)); // now delete old banner image $bannersObj->deleteBannerImage($bannerId); } else { // if image not changed - leave it as is $bannerOldInfo = $bannersObj->getBannerProperties($params['bannerId']); $sx = $bannerOldInfo['width']; $sy = $bannerOldInfo['height']; if ($params['width'] != '' && $params['height'] != '') { if ($params['width'] != $sx || $params['height'] != $sy) { $sx = $params['width']; $sy = $params['height']; } } $type = $bannerOldInfo['type']; $bannerFilePath = $bannerOldInfo['image_path']; } $title = $params['title']; $link = $params['link']; $active = $params['active']; $group = $params['groupSID']; // check 'link' for correct. If it hasn't 'http://' or 'https://' - add them $expr = preg_match("/^(https?:\\/\\/)/", $link); if ($expr != true && $params['bannerType'] != 'code') { $link = "http://" . $link; } if ($params['bannerType'] == 'code') { $bannersObj->deleteBannerImage($bannerId); } $result = $bannersObj->updateBanner($params['bannerId'], $title, $link, $bannerFilePath, $sx, $sy, $type, $active, $group, $params); if ($form_submitted == 'save_banner') { $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner-group/?groupSID={$group}"; } else { $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner/?bannerId=" . $bannerId; } SJB_HelperFunctions::redirect($site_url); break; } } $banner_fields = $bannersObj->getBannersMeta(); $tp->assign("banner_fields", $banner_fields); $tp->assign("banner", $banner); $tp->assign('errors', $errors); $tp->assign('bannersPath', SJB_Banners::getSiteUrl()); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display("edit_banner.tpl"); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $bannersObj = new SJB_Banners(); $filesDir = SJB_System::getSystemSettings('FILES_DIR'); // set null values, to initialize $errors = array(); $groupSID = SJB_Request::getVar('groupSID', false); $params = $_REQUEST; if (isset($_REQUEST['action'])) { $action_name = $_REQUEST['action']; switch ($action_name) { case 'add': // ERRORS if ($params['title'] == '') { $errors[] = 'Banner Title is empty.'; } if ($params['link'] == '' && $params['bannerType'] != 'code') { $errors[] = 'Banner link mismatched!'; } if ($params['bannerType'] == 'code' && $params['code'] == '') { $errors[] = 'Banner code is empty.'; } if ($_FILES['image']['name'] == '' && $params['bannerType'] == 'file') { $errors[] = 'No image attached!'; } if ($_FILES['image']['name'] && $_FILES['image']['error']) { $errors[SJB_UploadFileManager::getErrorId($_FILES['image']['error'])] = 1; } if ($errors) { break; } // ok. All input fields presented $title = $params['title']; $link = $params['link']; // check 'link' for correct. If it hasn't 'http://' or 'https://' and bannerType != code - add them $expr = preg_match("/^(https?:\\/\\/)/", $link); if ($expr != true && $params['bannerType'] != 'code') { $link = 'http://' . $link; } if ($params['bannerType'] == 'file') { // make filename preg_match("|\\.(\\w{3})\\b|u", $_FILES['image']['name'], $arr); $fileName = preg_replace("|\\.(\\w{3})\\b|u", '', $_FILES['image']['name']); $hashName = md5(time() * $_FILES['image']['size']) . '_' . $fileName; $bannerFilePath = $filesDir . 'banners/' . $hashName . '.' . $arr[1]; // move file from temporary folder, and fill banner info to DB $copy = copy($_FILES['image']['tmp_name'], $bannerFilePath); if (!$copy) { $errors[] = 'Cannot copy file from TMP dir to Banners Dir'; break; } if ($_FILES['image']['type'] != 'application/x-shockwave-flash') { // array of bannerInfo // [0] - width // [1] - height // [2] - ?? // [3] - width & height in next view: width="104" height="150" // [bits] - bit size of image // [channels] // [mime] - type, (image/jpeg, image/gif, image/png ) $bannerInfo = getimagesize($bannerFilePath); if ($params['width'] != '' && $params['height'] != '') { $sx = $params['width']; $sy = $params['height']; } else { $sx = $bannerInfo[0]; $sy = $bannerInfo[1]; } $type = $bannerInfo['mime']; } else { if ($params['width'] == '' || $params['height'] == '') { $errors[] = 'SIZE_PARAMETER_MISMATCHED'; break; } $sx = $params['width']; $sy = $params['height']; $type = $_FILES['image']['type']; } $active = $params['active']; $group = $params['groupSID']; $bannerFilePath = '/' . str_replace('../', '/', str_replace(SJB_BASE_DIR, '', $bannerFilePath)); } else { $sx = $params['width']; $sy = $params['height']; $type = ''; $active = $params['active']; $group = $params['groupSID']; $bannerFilePath = ''; } $bannersObj->addBanner($title, $link, $bannerFilePath, $sx, $sy, $type, $active, $group, $params); $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner-group/?groupSID={$groupSID}"; header("Location: {$site_url}"); break; } } $banner_fields = $bannersObj->getBannersMeta(); $bannerGroup = $bannersObj->getBannerGroupBySID($groupSID); $tp->assign('params', $params); $tp->assign('errors', $errors); $tp->assign('banner_fields', $banner_fields); $tp->assign('bannerGroup', $bannerGroup); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display('add_banner.tpl'); }