Exemplo n.º 1
0
 public static function updateAllContractsExtraInfoByProductSID($contractsSIDs, $productSID)
 {
     $productExtraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
     $currentPermissions = array();
     SJB_DB::query("delete from `permissions` where `type` = 'contract' and `role` in ({$contractsSIDs})");
     foreach (explode(',', $contractsSIDs) as $contractSID) {
         $contractInfo = self::selectInfoByID($contractSID);
         if ($contractInfo['status'] == 'active') {
             SJB_DB::query("INSERT INTO `permissions` (`type`, `role`, `name`, `value`, `params`, `message`)\n\t\t\t\t\t\t\t\tSELECT 'contract', ?s, `name`, `value`, `params`, `message`\n\t\t\t\t\t\t\t\tFROM `permissions`\n\t\t\t\t\t\t\t\tWHERE `type` = 'product' AND `role` = ?s", $contractSID, $productSID);
         }
         $extraInfo = !empty($contractInfo['serialized_extra_info']) ? unserialize($contractInfo['serialized_extra_info']) : array();
         $contractExtraInfo = $productExtraInfo;
         if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based') {
             $numberOfListings = $extraInfo['number_of_listings'];
             $numberOfPostings[$contractSID] = $numberOfListings;
             $volumeBasedPricing = !empty($productExtraInfo['volume_based_pricing']) ? $productExtraInfo['volume_based_pricing'] : array();
             if (!empty($volumeBasedPricing['listings_range_from'])) {
                 for ($i = 1; $i <= count($volumeBasedPricing['listings_range_from']); $i++) {
                     if ($numberOfListings >= $volumeBasedPricing['listings_range_from'][$i] && $numberOfListings <= $volumeBasedPricing['listings_range_to'][$i]) {
                         $contractExtraInfo['listings_range_from'] = $volumeBasedPricing['listings_range_from'][$i];
                         $contractExtraInfo['listings_range_to'] = $volumeBasedPricing['listings_range_to'][$i];
                         $contractExtraInfo['price_per_unit'] = $volumeBasedPricing['price_per_unit'][$i];
                         $contractExtraInfo['renewal_price'] = $volumeBasedPricing['renewal_price_per_listing'][$i];
                         $contractExtraInfo['number_of_listings'] = $numberOfListings;
                         break;
                     }
                 }
                 unset($contractExtraInfo['volume_based_pricing']);
             }
         }
         SJB_DB::query("UPDATE `contracts` SET `serialized_extra_info` = ?s WHERE `id` = ?n", serialize($contractExtraInfo), $contractSID);
     }
     if (isset($productExtraInfo['pricing_type'])) {
         $currentPermissions = SJB_DB::query("SELECT * FROM `permissions` WHERE `type` = 'contract' AND `role` in ({$contractsSIDs})");
     }
     foreach ($currentPermissions as $key => $permission) {
         $currentPermissions[$permission['name']] = $permission;
         unset($currentPermissions[$key]);
     }
     if ($currentPermissions && !empty($numberOfPostings) || isset($productExtraInfo['number_of_listings'])) {
         foreach (explode(',', $contractsSIDs) as $contractSID) {
             $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo();
             foreach ($listingTypes as $listingType) {
                 if (isset($currentPermissions['post_' . strtolower($listingType['id'])])) {
                     $permission = $currentPermissions['post_' . strtolower($listingType['id'])];
                     if ($permission['value'] == 'allow') {
                         SJB_DB::query("UPDATE `permissions` SET `params` = ?n WHERE `type` = 'contract' AND  `role` = ?s AND `name` = ?s", !empty($numberOfPostings) ? $numberOfPostings[$contractSID] : $productExtraInfo['number_of_listings'], $contractSID, 'post_' . strtolower($listingType['id']));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function sendRemindSubscriptionExpirationLetter($userSID, $contractInfo, $days)
 {
     $user = SJB_UserManager::getObjectBySID($userSID);
     $userGroupSID = $user->getUserGroupSID();
     $emailTplSID = SJB_UserGroupManager::getEmailTemplateSIDByUserGroupAndField($userGroupSID, 'notify_subscription_expire_date');
     $product = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID(SJB_Array::get($contractInfo, 'product_sid'));
     if ($productInfo) {
         $productExtraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productInfo['sid']);
         $productInfo = array_merge($productInfo, $productExtraInfo);
         $fields = SJB_ProductsManager::createTemplateStructureForProductForEmailTpl($productInfo);
         $product = array_merge($fields, $productExtraInfo);
     }
     $user_info = SJB_UserManager::createTemplateStructureForUser($user);
     $data = array('type' => 'contract', 'user' => $user_info, 'days' => $days, 'contractInfo' => $contractInfo, 'product' => $product);
     $email = SJB_EmailTemplateEditor::getEmail($user_info['email'], $emailTplSID, $data);
     return $email->send('Remind Subscription Expiration');
 }
Exemplo n.º 3
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $productSID = SJB_Request::getVar('product_sid', 0);
     $errors = array();
     if ($listingTypeID && $productSID) {
         $acl = SJB_Acl::getInstance();
         $resource = 'post_' . strtolower($listingTypeID);
         if (!$acl->isAllowed($resource, $productSID, 'product')) {
             $errors[] = 'You cannot import listings of this type under the selected product';
         }
     }
     if (!empty($file_info)) {
         $extension = SJB_Request::getVar('file_type');
         if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) {
             $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true;
         }
     }
     if (empty($file_info) || $file_info['error'] || $errors) {
         if (isset($file_info['error']) && $file_info['error'] > 0) {
             $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1;
         }
         $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsByProductType('post_listings');
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('listing_types', $listing_types);
         $tp->assign('products', $products);
         $tp->assign('errors', $errors);
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->display('import_listings.tpl');
     } else {
         $i18n = SJB_I18N::getInstance();
         $csv_delimiter = SJB_Request::getVar('csv_delimiter', null);
         $activeStatus = SJB_Request::getVar('active', 0);
         $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d'));
         $activationDate = $i18n->getInput('date', $activationDate);
         $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null);
         $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
         if (empty($productInfo['listing_duration'])) {
             $expirationDate = '';
         } else {
             $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days');
             $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp));
         }
         $extension = $_REQUEST['file_type'];
         if ($extension == 'xls') {
             $import_file = new SJB_ImportFileXLS($file_info);
         } elseif ($extension == 'csv') {
             $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter);
         }
         $import_file->parse($encodingFromCharset);
         $listing = $this->CreateListing(array(), $listingTypeID);
         $imported_data = $import_file->getData();
         $isFileImported = true;
         $count = 0;
         $addedListingsSids = array();
         $nonExistentUsers = array();
         foreach ($imported_data as $key => $importedColumn) {
             if ($key == 1) {
                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                 continue;
             }
             if (!$importedColumn) {
                 continue;
             }
             $count++;
             $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn);
             $doc = new DOMDocument();
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $doc->loadXML($listingInfo[$property->id]);
                     $results = $doc->getElementsByTagName($property->id . 's');
                     $listingInfo[$property->id] = array();
                     foreach ($results as $complexparent) {
                         $i = 1;
                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                             $resultXML = simplexml_import_dom($result);
                             foreach ($childFields as $childField) {
                                 if (isset($resultXML->{$childField}['id'])) {
                                     $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']);
                                 }
                             }
                             $i++;
                         }
                     }
                 } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) {
                     $value = $listingInfo[$property->id];
                     $listingInfo[$property->id] = array();
                     $listingInfo[$property->id]['value'] = $value;
                     $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency();
                     $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code'];
                     $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode);
                     $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : '';
                     if (isset($listingInfo[$property->id . "Currency"])) {
                         unset($listingInfo[$property->id . "Currency"]);
                     }
                 } elseif ($property->getType() == 'location') {
                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                     $locationFieldAdded = array();
                     foreach ($locationFields as $locationField) {
                         if (array_key_exists($locationField, $listingInfo)) {
                             switch ($locationField) {
                                 case $property->id . '.Country':
                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 case $property->id . '.State':
                                     $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 default:
                                     $value = $listingInfo[$locationField];
                                     break;
                             }
                             $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                         }
                     }
                     if ($property->id == 'Location') {
                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                         foreach ($locationFields as $locationField) {
                             if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                 switch ($locationField) {
                                     case 'Country':
                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     case 'State':
                                         $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     default:
                                         $value = $listingInfo[$locationField];
                                         break;
                                 }
                                 $listingInfo[$property->id][$locationField] = $value;
                             }
                         }
                     }
                 }
             }
             $listing = $this->CreateListing($listingInfo, $listingTypeID);
             $pictures = array();
             if (isset($listingInfo['pictures'])) {
                 $listing->addPicturesProperty();
                 $explodedPictures = explode(';', $listingInfo['pictures']);
                 foreach ($explodedPictures as $picture) {
                     if (!empty($picture)) {
                         $pictures[] = $picture;
                     }
                 }
                 $listing->setPropertyValue('pictures', count($pictures));
             }
             $listing->addActiveProperty($activeStatus);
             $listing->addActivationDateProperty($activationDate);
             $listing->addExpirationDateProperty($expirationDate);
             SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid);
             $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID));
             $listing->setPropertyValue('access_type', 'everyone');
             $listing->setPropertyValue('status', 'approved');
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'tree' && $property->value !== '') {
                     try {
                         $treeImportHelper = new SJB_FieldTreeImportHelper($property->value);
                         $treeValues = $treeImportHelper->parseAndGetValues();
                         $listing->setPropertyValue($property->id, $treeValues);
                         $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues;
                     } catch (Exception $e) {
                         $listing->setPropertyValue($property->id, '');
                         $listing->details->properties[$property->id]->type->property_info['value'] = '';
                         SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage());
                     }
                 } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) {
                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1);
                     } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2);
                     } else {
                         $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                     }
                     //put empty if not valid email or url
                     $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings'];
                 } elseif ($property->getType() == 'complex') {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $complexChildValues = $property->value;
                     foreach ($childFields as $childField) {
                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                             $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                             if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) {
                                 $isFileImported = false;
                             }
                         }
                         if ($property->type->complex->details->properties[$childField['id']]->value == null) {
                             $property->type->complex->details->properties[$childField['id']]->value = array(1 => '');
                             $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => '');
                         }
                     }
                 }
                 // The import of files at import of listings
                 if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                     if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) {
                         $isFileImported = false;
                     }
                 }
             }
             if ($non_existed_values_flag == 'add') {
                 $this->UpdateListValues($listing);
             }
             if ($listing->getUserSID()) {
                 SJB_ListingManager::saveListing($listing);
                 $listingSid = $listing->getSID();
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid);
                 SJB_ListingManager::activateListingBySID($listingSid, false);
                 if (!$this->fillGallery($listingSid, $pictures)) {
                     $isFileImported = false;
                 }
                 $addedListingsSids[] = $listingSid;
             } else {
                 $nonExistentUsers[] = $listingInfo['username'];
                 $count--;
             }
         }
         SJB_BrowseDBManager::addListings($addedListingsSids);
         SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids));
         if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) {
             SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'));
         }
         $tp->assign('imported_listings_count', $count);
         $tp->assign('nonExistentUsers', $nonExistentUsers);
         $tp->display('import_listings_result.tpl');
     }
 }
Exemplo n.º 4
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listing_id = SJB_Request::getVar('listing_sid', null);
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
     $contractID = SJB_Request::getVar('contract_id', null);
     $errors = '';
     $field_errors = '';
     if (empty($listing_id)) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } elseif (!empty($listing_id) && strlen($listing_id) == strlen(time())) {
         if ($contractID) {
             SJB_Session::setValue('contract_id', $contractID);
         } else {
             $contractID = SJB_Session::getValue('contract_id');
         }
         if (empty($_SESSION['tmp_file_storage'])) {
             SJB_Session::setValue('tmp_file_storage', array());
         }
         $contract = new SJB_Contract(array('contract_id' => $contractID));
         $gallery = new SJB_ListingGallery();
         $gallery->setListingSID($listing_id);
         if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
             if (!isset($_FILES['picture'])) {
                 $field_errors['Picture'] = 'FILE_NOT_SPECIFIED';
             } elseif ($_FILES['picture']['error']) {
                 switch ($_FILES['picture']['error']) {
                     case '1':
                         $field_errors['Picture'] = 'UPLOAD_ERR_INI_SIZE';
                         break;
                     case '2':
                         $field_errors['Picture'] = 'UPLOAD_ERR_FORM_SIZE';
                         break;
                     case '3':
                         $field_errors['Picture'] = 'UPLOAD_ERR_PARTIAL';
                         break;
                     case '4':
                         $field_errors['Picture'] = 'UPLOAD_ERR_NO_FILE';
                         break;
                     default:
                         break;
                 }
             } else {
                 $image_caption = isset($_REQUEST['caption']) ? $_REQUEST['caption'] : '';
                 $_FILES['picture']['caption'] = $image_caption;
                 if (!$gallery->uploadImage($_FILES['picture']['tmp_name'], $image_caption)) {
                     $field_errors['Picture'] = $gallery->getError();
                 }
             }
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
             if (isset($_REQUEST['picture_id'])) {
                 $picture_id = $_REQUEST['picture_id'];
                 $gallery->deleteImageBySID($picture_id);
             }
         }
         $extraInfo = array();
         if ($listingInfo) {
             $extraInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
         } elseif ($contract) {
             $extraInfo = $contract->extra_info;
         }
         if (empty($extraInfo)) {
             if ($productSID = SJB_Request::getVar('product_sid', null)) {
                 SJB_Session::setValue('product_sid', $productSID);
             } else {
                 $productSID = SJB_Session::getValue('product_sid');
             }
             $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         }
         $number_of_picture_allowed = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
         $number_of_picture = $gallery->getPicturesAmount();
         $pictures_info = $gallery->getPicturesInfo();
         $_SESSION['tmp_file_storage'] = $pictures_info;
         $template_processor->assign("listing", array('id' => "{$listing_id}"));
         $template_processor->assign("number_of_picture_allowed", $number_of_picture_allowed);
         $template_processor->assign("number_of_picture", $number_of_picture);
         $template_processor->assign('pictures', $_SESSION['tmp_file_storage']);
     } else {
         $listing = SJB_ListingManager::getObjectBySID($listing_id);
         if (is_null($listing)) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } elseif ($listing->getUserSID() != SJB_UserManager::getCurrentUserSID()) {
             $errors['NOT_OWNER'] = 1;
         } else {
             $gallery = new SJB_ListingGallery();
             $gallery->setListingSID($listing_id);
             $contract = new SJB_Contract(array('contract_id' => $contractID));
             if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
                 if (!isset($_FILES['picture'])) {
                     $field_errors['Picture'] = 'FILE_NOT_SPECIFIED';
                 } elseif ($_FILES['picture']['error']) {
                     switch ($_FILES['picture']['error']) {
                         case '1':
                             $field_errors['Picture'] = 'UPLOAD_ERR_INI_SIZE';
                             break;
                         case '2':
                             $field_errors['Picture'] = 'UPLOAD_ERR_FORM_SIZE';
                             break;
                         case '3':
                             $field_errors['Picture'] = 'UPLOAD_ERR_PARTIAL';
                             break;
                         case '4':
                             $field_errors['Picture'] = 'UPLOAD_ERR_NO_FILE';
                             break;
                         default:
                             break;
                     }
                 } else {
                     $image_caption = isset($_REQUEST['caption']) ? $_REQUEST['caption'] : '';
                     if (!$gallery->uploadImage($_FILES['picture']['tmp_name'], $image_caption)) {
                         $field_errors['Picture'] = $gallery->getError();
                     }
                 }
             } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
                 if (isset($_REQUEST['picture_id'])) {
                     $gallery->deleteImageBySID($_REQUEST['picture_id']);
                 }
             } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_up') {
                 if (isset($_REQUEST['picture_id'])) {
                     $gallery->moveUpImageBySID($_REQUEST['picture_id']);
                 }
             } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_down') {
                 if (isset($_REQUEST['picture_id'])) {
                     $gallery->moveDownImageBySID($_REQUEST['picture_id']);
                 }
             }
             $extraInfo = array();
             if ($listingInfo) {
                 $extraInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
             } elseif ($contract) {
                 $extraInfo = $contract->extra_info;
             }
             if (empty($extraInfo)) {
                 if ($productSID = SJB_Request::getVar('product_sid', null)) {
                     SJB_Session::setValue('product_sid', $productSID);
                 } else {
                     $productSID = SJB_Session::getValue('product_sid');
                 }
                 $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
             }
             $number_of_picture_allowed = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $number_of_picture = $gallery->getPicturesAmount();
             $listing_info['id'] = $listing_id;
             $template_processor->assign("listing", $listing_info);
             $pictures_info = $gallery->getPicturesInfo();
             $template_processor->assign("pictures", $pictures_info);
             $template_processor->assign("number_of_picture", $number_of_picture);
             $template_processor->assign("number_of_picture_allowed", $number_of_picture_allowed);
         }
     }
     $template_processor->assign("errors", $errors);
     $template_processor->assign("field_errors", $field_errors);
     $template_processor->display("manage_pictures.tpl");
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 /**
  * @param int $currentUserID
  * @param int $productSID
  * @return bool|int|mixed
  */
 public function proceedToCheckout($currentUserID, $productSID)
 {
     $errors = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
     if (SJB_UserManager::isUserLoggedIn()) {
         $numberOfListings = SJB_ListingDBManager::getNumberOfCheckoutedListingsByProductSID($productSID, $currentUserID);
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $shoppingCartProducts = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productSID, $currentUserID);
         if (!empty($shoppingCartProducts)) {
             if ($productInfo['product_type'] == 'mixed_product' || isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 if ($numberOfListings / (count($shoppingCartProducts) * $productInfo['number_of_listings']) > 1) {
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 }
             }
             if (isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 if ($numberOfListings / (count($shoppingCartProducts) * end($productInfo['volume_based_pricing']['listings_range_to'])) > 1) {
                     $productInfo['number_of_listings'] = 1;
                     $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                     $productObj->setNumberOfListings($productInfo['number_of_listings']);
                     $productInfo['price'] = $productObj->getPrice();
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 } else {
                     foreach ($shoppingCartProducts as $shoppingCartProduct) {
                         $unserializedProductInfoFromShopCart = unserialize($shoppingCartProduct['product_info']);
                         if ($unserializedProductInfoFromShopCart['number_of_listings'] < end($unserializedProductInfoFromShopCart['volume_based_pricing']['listings_range_to'])) {
                             $unserializedProductInfoFromShopCart['number_of_listings'] += 1;
                             SJB_ShoppingCart::updateItemBySID($shoppingCartProduct['sid'], $unserializedProductInfoFromShopCart);
                             break;
                         }
                     }
                 }
             }
         } else {
             if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based') {
                 $productInfo['number_of_listings'] = 1;
                 $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                 $productObj->setNumberOfListings($productInfo['number_of_listings']);
                 $productInfo['price'] = $productObj->getPrice();
             }
             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
         }
     } else {
         $products = SJB_Session::getValue('products');
         if (isset($products)) {
             foreach ($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();
             $products[$id]['product_info'] = serialize($productInfo);
             $products[$id]['sid'] = $id;
             $products[$id]['user_sid'] = 0;
             SJB_Session::setValue('products', $products);
         }
     }
     if (!$errors) {
         SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
     }
 }
Exemplo n.º 7
0
 /**
  * prepare template variables for Product emails
  */
 private function prepareTplVarsForProduct()
 {
     $productTypes = array('post_listings', 'access_listings', 'mixed_product', 'featured_user', 'banners', 'custom_product');
     foreach ($productTypes as $key => &$productType) {
         $products = SJB_ProductsManager::getProductsByProductType($productType);
         if (!empty($products)) {
             $productInfo = array_pop($products);
             $productExtraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productInfo['sid']);
             $productInfo = array_merge($productInfo, $productExtraInfo);
             $productType = array('id' => $productType, 'caption' => SJB_ProductsManager::getProductTypeByID($productType));
             $fields = SJB_ProductsManager::createTemplateStructureForProductForEmailTpl($productInfo);
             $fields = array_merge($fields, $productExtraInfo);
             unset($fields['METADATA']);
             $productType['fields'] = $this->echoVars($fields);
         } else {
             unset($productTypes[$key]);
         }
     }
     $this->tp->assign('productTypes', $productTypes);
 }