public function execute()
 {
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $etSID = SJB_Array::get($passed_parameters_via_uri, 0);
     }
     $field_id = SJB_Request::getVar('field_id', null);
     $etInfo = SJB_EmailTemplateEditor::getEmailTemplateInfoBySID($etSID);
     if (is_null($etSID) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } elseif (is_null($etInfo) || !isset($etInfo[$field_id])) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } else {
         $uploaded_file_id = $etInfo[$field_id];
         SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
         $etInfo[$field_id] = '';
         $emailTemplate = new SJB_EmailTemplate($etInfo);
         $emailTemplate->setSID($etSID);
         SJB_EmailTemplateEditor::saveEmailTemplate($emailTemplate);
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-email-templates/' . $emailTemplate->getPropertyValue('group') . '/' . $etSID);
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', isset($errors) ? $errors : null);
     $tp->display('delete_uploaded_file.tpl');
 }
Пример #2
0
 function getValue()
 {
     $upload_manager = new SJB_UploadPictureManager();
     $upload_manager->setFileGroup("pictures");
     $fileInfo = SJB_UploadFileManager::getUploadedFileInfo($this->property_info['value']);
     $thumbFileInfo = SJB_UploadFileManager::getUploadedFileInfo($this->property_info['value'] . "_thumb");
     return array('file_url' => $upload_manager->getUploadedFileLink($this->property_info['value'], $fileInfo), 'file_name' => empty($fileInfo['file_name']) ? null : $fileInfo['file_name'], 'thumb_file_url' => $upload_manager->getUploadedFileLink($this->property_info['value'] . "_thumb", $thumbFileInfo), 'thumb_file_name' => empty($thumbFileInfo['file_name']) ? null : $thumbFileInfo['file_name']);
 }
Пример #3
0
 function getSQLValue()
 {
     $fileId = $this->property_info['id'] . '_' . $this->object_sid;
     $this->property_info['value'] = $fileId;
     SJB_DB::queryExec("UPDATE uploaded_files SET id = ?s WHERE  id = ?s LIMIT 1", $fileId, $this->property_info['id'] . '_tmp');
     if (SJB_UploadFileManager::doesFileExistByID($fileId)) {
         return $fileId;
     }
     return '';
 }
Пример #4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingInfo['listing_type_sid']);
     $display_form = new SJB_Form();
     $display_form->registerTags($tp);
     if (is_null($listing_id)) {
         $errors['LISTING_ID_DOESNOT_SPECIFIED'] = $listing_id;
     } else {
         $listing = SJB_ListingManager::getObjectBySID($listing_id);
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         if (!empty($listing)) {
             $listing->addPicturesProperty();
             if ($listing->listing_type_sid == 6) {
                 $listing->deleteProperty('access_type');
                 $listing->deleteProperty('anonymous');
             }
             $access_type_properties = $listing->getProperty('access_type');
             $tp->assign('access_type_properties', $access_type_properties);
             $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $tp->assign("listing", $listing_structure);
             $display_form = new SJB_Form($listing);
             $display_form->registerTags($tp);
             $form_fields = $display_form->getFormFieldsInfo();
             $tp->assign("form_fields", $form_fields);
             $waitApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing->listing_type_sid);
             $tp->assign('wait_approve', $waitApprove);
         } else {
             $errors['LISTING_DOESNOT_EXIST'] = $listing_id;
         }
     }
     $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id);
     $comments_total = count($comments);
     $rate = SJB_Rating::getRatingNumToListing($listing_id);
     $displayTemplate = SJB_Request::getVar('display_template', 'display_listing.tpl');
     $videoFileId = SJB_Request::getVar('videoFileId', false);
     if ($videoFileId) {
         $videoFileLink = SJB_UploadFileManager::getUploadedFileLink($videoFileId);
         $tp->assign('videoFileLink', $videoFileLink);
     }
     $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
     $tp->assign('errors', $errors);
     $tp->assign('comments_total', $comments_total);
     $tp->assign('rate', $rate);
     SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']);
     $tp->display($displayTemplate);
 }
Пример #5
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     $complexEmun = SJB_Request::getVar('complexEnum', null, 'GET');
     $complexFieldID = SJB_Request::getVar('complexParent', null, 'GET');
     if (!is_null($complexEmun) && !is_null($complexFieldID)) {
         $fieldArr = array();
         array_push($fieldArr, $complexFieldID);
         array_push($fieldArr, $field_id);
         array_push($fieldArr, $complexEmun);
         $field_id = $complexFieldID . ':' . $field_id . $complexEmun . '_' . $listing_id;
     } else {
         $fieldArr = explode(':', $field_id);
         $complexEmun = isset($fieldArr[2]) ? explode('_', $fieldArr[2]) : false;
         $complexEmun = $complexEmun ? $complexEmun[0] : false;
     }
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || $complexEmun === false || !isset($listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->display('delete_uploaded_file.tpl');
 }
Пример #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $action = SJB_Request::getVar('action', false);
     if ($action && isset($_FILES['lang_file'])) {
         $params = $_REQUEST + $_FILES['lang_file'];
         $action = SJB_LanguageActionFactory::get($action, $params);
         if (@$action->canPerform()) {
             $action->perform();
             SJB_WrappedFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-languages/');
         } else {
             $errors = $action->getErrors();
         }
     }
     $tp->assign('errors', $errors);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('import_language.tpl');
 }
Пример #7
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || !isset($listing_info[$field_id])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$field_id];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->assign('listingTypeSID', $listingTypeSID);
     $tp->display('delete_uploaded_file.tpl');
 }
Пример #8
0
 public function execute()
 {
     $user_info = SJB_UserManager::getCurrentUserInfo();
     $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
     if (is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } elseif (!isset($user_info[$field_id])) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } else {
         $uploaded_file_id = $user_info[$field_id];
         SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
         $user_info[$field_id] = "";
         $user_info['email'] = array('original' => $user_info['email']);
         $user = new SJB_User($user_info, $user_info['user_group_sid']);
         $user->deleteProperty("active");
         $user->deleteProperty('password');
         $user->setSID(SJB_UserManager::getCurrentUserSID());
         SJB_UserManager::saveUser($user);
     }
     $template_processor = SJB_System::getTemplateProcessor();
     $template_processor->assign("errors", isset($errors) ? $errors : null);
     $template_processor->display("delete_uploaded_file.tpl");
 }
Пример #9
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']);
     $field_id = SJB_Request::getVar('field_id', null);
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } elseif (is_null($listing_info) || !isset($listing_info[$field_id])) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } else {
         $uploaded_file_id = $listing_info[$field_id];
         SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
         $listing_info[$field_id] = '';
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_id);
         SJB_ListingManager::saveListing($listing);
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', isset($errors) ? $errors : null);
     $tp->assign('listing_id', $listing_id);
     $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
     $tp->display('delete_uploaded_file.tpl');
 }
Пример #10
0
 private static function changeFilesFieldValue($dstListingSid, $listingProperty, $value = null, $isComplex = false)
 {
     if (!$value) {
         $value = $listingProperty->getValue();
     }
     $uploadedFileId = SJB_Array::get($value, 'file_id');
     $uploadedFileInfo = SJB_UploadFileManager::getUploadedFileInfo($uploadedFileId);
     if ($uploadedFileInfo) {
         $uploadFileManager = new SJB_UploadFileManager();
         $fileGroup = $listingProperty->getType() == 'video' ? 'video' : 'files';
         if ($isComplex) {
             $newUploadedFileId = strstr($uploadedFileId, '_', true) . '_' . $dstListingSid;
         } else {
             $newUploadedFileId = $listingProperty->getID() . '_' . $dstListingSid;
         }
         $uploadFileManager->setFileGroup($fileGroup);
         $uploadFileManager->copyFile($uploadedFileInfo, $newUploadedFileId);
         $listingProperty->setValue($newUploadedFileId);
     }
 }
Пример #11
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $preview = SJB_Request::getVar('preview', false);
     $importedDataForPreview = array();
     $template_processor = SJB_System::getTemplateProcessor();
     $errors = null;
     $start_line = SJB_Request::getVar('start_line', null);
     $name_column = SJB_Request::getVar('name_column', null);
     $longitude_column = SJB_Request::getVar('longitude_column', null);
     $latitude_column = SJB_Request::getVar('latitude_column', null);
     $city_column = SJB_Request::getVar('city_column', null);
     $state_column = SJB_Request::getVar('state_column', null);
     $state_code_column = SJB_Request::getVar('state_code_column', null);
     $country_sid = SJB_Request::getVar('country_sid', null);
     $file_format = SJB_Request::getVar('file_format', null);
     $fields_delimiter = SJB_Request::getVar('fields_delimiter', null);
     $imported_file_config['start_line'] = $start_line;
     $imported_file_config['name_column'] = $name_column;
     $imported_file_config['longitude_column'] = $longitude_column;
     $imported_file_config['latitude_column'] = $latitude_column;
     $imported_file_config['city_column'] = $city_column;
     $imported_file_config['state_column'] = $state_column;
     $imported_file_config['state_code_column'] = $state_code_column;
     $imported_file_config['file_format'] = $file_format;
     $imported_file_config['fields_delimiter'] = $fields_delimiter;
     $imported_location_count = null;
     if (isset($_FILES['imported_geo_file']) && !$_FILES['imported_geo_file']['error']) {
         $fileInfo = $_FILES['imported_geo_file'];
         $fileFormats = array('csv', 'xls', 'xlsx');
         $pathInfo = pathinfo($fileInfo['name']);
         $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : '';
         if (!in_array(strtolower($fileExtension), $fileFormats)) {
             $errors['File'] = 'WRONG_FORMAT';
         }
         if (empty($_FILES['imported_geo_file']['name'])) {
             $errors['File'] = 'EMPTY_VALUE';
         }
         if (empty($start_line)) {
             $errors['Start Line'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) {
             $errors['Start Line'] = 'NOT_INT_VALUE';
         }
         if (empty($name_column)) {
             $errors['Name Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($name_column) || !is_int($name_column + 0)) {
             $errors['Name Column'] = 'NOT_INT_VALUE';
         }
         if (empty($longitude_column)) {
             $errors['Longitude Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($longitude_column) || !is_int($longitude_column + 0)) {
             $errors['Longitude Column'] = 'NOT_INT_VALUE';
         }
         if (empty($latitude_column)) {
             $errors['Latitude Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($latitude_column) || !is_int($latitude_column + 0)) {
             $errors['Latitude Column'] = 'NOT_INT_VALUE';
         }
         if (empty($country_sid)) {
             $errors['Country'] = 'EMPTY_VALUE';
         }
         if (!SJB_ImportFile::isValidFileExtensionByFormat($file_format, $_FILES['imported_geo_file'])) {
             $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT';
         }
         if (!SJB_ImportFile::isValidFileCharset($_FILES['imported_geo_file'], $encodingFromCharset)) {
             $errors['Charset'] = 'CHARSET_INCORRECT';
         }
         if (is_null($errors)) {
             set_time_limit(0);
             $file_info = SJB_Array::get($_FILES, 'imported_geo_file');
             if (!strcasecmp($file_format, 'excel')) {
                 $import_file = new SJB_ImportFileXLS($file_info);
             } else {
                 if ($fields_delimiter == 'semicolon') {
                     $fields_delimiter = ';';
                 } elseif ($fields_delimiter == 'tab') {
                     $fields_delimiter = "\t";
                 } else {
                     $fields_delimiter = ',';
                 }
                 $import_file = new SJB_ImportFileCSV($file_info, $fields_delimiter);
             }
             $import_file->parse($encodingFromCharset);
             $imported_data = $import_file->getData();
             $imported_location_count = 0;
             $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country_sid);
             foreach ($imported_data as $key => $importedColumn) {
                 if (empty($importedColumn[$name_column - 1]) || empty($importedColumn[$longitude_column - 1]) || empty($importedColumn[$latitude_column - 1]) || $start_line > $key) {
                     continue;
                 }
                 $name = $importedColumn[$name_column - 1];
                 $longitude = $importedColumn[$longitude_column - 1];
                 $latitude = $importedColumn[$latitude_column - 1];
                 $city = isset($importedColumn[$city_column - 1]) ? $importedColumn[$city_column - 1] : null;
                 $state = isset($importedColumn[$state_column - 1]) ? $importedColumn[$state_column - 1] : null;
                 $state_code = isset($importedColumn[$state_code_column - 1]) ? $importedColumn[$state_code_column - 1] : null;
                 if ($preview) {
                     if (count($importedDataForPreview) >= 10) {
                         break;
                     }
                     $importedDataForPreview[] = array('name' => $name, 'longitude' => $longitude, 'latitude' => $latitude, 'city' => $city, 'state' => $state, 'stateCode' => $state_code, 'country' => $countryInfo['country_name']);
                 } else {
                     $imported_location_count += SJB_LocationManager::addLocation($name, $longitude, $latitude, $city, $state, $state_code, $country_sid, $countryInfo);
                 }
             }
         }
     } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $errorSid = isset($_FILES['imported_geo_file']['error']) ? $_FILES['imported_geo_file']['error'] : 0;
         $errors['File'] = SJB_UploadFileManager::getErrorId($errorSid);
     }
     $countries = SJB_CountriesManager::getAllCountriesCodesAndNames();
     $template_processor->assign("charSets", SJB_HelperFunctions::getCharSets());
     $template_processor->assign("importedGeographicData", $importedDataForPreview);
     $template_processor->assign("countries", $countries);
     $template_processor->assign("country_sid", $country_sid);
     $template_processor->assign("errors", $errors);
     $template_processor->assign("imported_location_count", $imported_location_count);
     $template_processor->assign("imported_file_config", $imported_file_config);
     $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     if ($preview) {
         $template_processor->display("import_geographic_data_preview.tpl");
     } else {
         $template_processor->display("import_geographic_data_form.tpl");
     }
 }
Пример #12
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $listing_id = SJB_Request::getVar('listing_sid', SJB_Request::getVar('listing_id', null));
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
     $productSID = SJB_Request::getVar('product_sid' . null);
     $errors = null;
     $field_errors = null;
     $extraInfo = array();
     if (empty($listing_id)) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } elseif (!empty($listing_id) && strlen($listing_id) == strlen(time())) {
         if ($productSID) {
             SJB_Session::setValue('product_sid', $productSID);
         } else {
             $productSID = SJB_Session::getValue('product_sid');
         }
         if (empty($_SESSION['tmp_file_storage'])) {
             SJB_Session::setValue('tmp_file_storage', array());
         }
         $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
         $contract = new SJB_Contract(array('contract_id' => $productSID));
         $gallery = new SJB_ListingGallery();
         $gallery->setListingSID($listing_id);
         $template_processor->assign("contract", $contract);
         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);
             }
         }
         if ($listingInfo) {
             $extraInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
         } elseif ($contract && $contract->extra_info) {
             $extraInfo = $contract->extra_info;
         } elseif ($productInfo) {
             $extraInfo = !empty($productInfo['serialized_extra_info']) ? unserialize($productInfo['serialized_extra_info']) : array();
         }
         $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;
         } else {
             $gallery = new SJB_ListingGallery();
             $gallery->setListingSID($listing_id);
             $contract = new SJB_Contract(array('contract_id' => $productSID));
             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']);
                 }
             }
             if ($listingInfo) {
                 $extraInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
             } elseif ($contract && $contract->extra_info) {
                 $extraInfo = $contract->extra_info;
             }
             $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("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $template_processor->assign("errors", $errors);
     $template_processor->assign("field_errors", $field_errors);
     $template_processor->display("manage_pictures.tpl");
 }
Пример #13
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');
     }
 }
Пример #14
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'list');
     $countrySID = SJB_Request::getVar('country_sid', false);
     $errors = array();
     $template = 'states.tpl';
     $countries = SJB_CountriesManager::getAllCountries();
     $paginator = new SJB_StatesPagination();
     switch ($action) {
         case 'move_state':
         case 'save_order':
             $template = 'move_state.tpl';
             $itemSIDs = SJB_Request::getVar('item_order', array());
             try {
                 SJB_StatesManager::saveItemsOrder($paginator->currentPage, $paginator->itemsPerPage, $itemSIDs);
                 $tp->assign('action', $action);
             } catch (Exception $e) {
                 $errors['SAVING_ORDER'] = $e->getMessage();
             }
             $states = SJB_StatesManager::getAllStates($countrySID);
             $tp->assign('states', $states);
             break;
         case 'activate':
             $statesSIDs = array_keys(SJB_Request::getVar('states', array()));
             foreach ($statesSIDs as $stateSID) {
                 SJB_StatesManager::activateStateBySID($stateSID);
             }
             $action = 'list';
             break;
         case 'deactivate':
             $statesSIDs = array_keys(SJB_Request::getVar('states', array()));
             foreach ($statesSIDs as $stateSID) {
                 SJB_StatesManager::deactivateStateBySID($stateSID);
             }
             $action = 'list';
             break;
         case 'delete':
             $statesSIDs = array_keys(SJB_Request::getVar('states', array()));
             foreach ($statesSIDs as $stateSID) {
                 SJB_StatesManager::deleteStateBySID($stateSID);
             }
             $action = 'list';
             break;
         case 'add_state':
             $template = 'add_state.tpl';
             $formSubmitted = SJB_Request::getVar('action_add', false);
             $state = new SJB_State($_REQUEST);
             $addStateForm = new SJB_Form($state);
             $addStateForm->registerTags($tp);
             $addValidParam = array('field' => 'country_sid', 'value' => $countrySID);
             if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) {
                 $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true));
                 SJB_StatesManager::saveState($state);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $countrySID);
             } else {
                 $formFields = $addStateForm->getFormFieldsInfo();
                 $tp->assign('form_fields', $formFields);
             }
             break;
         case 'edit_state':
             $template = 'edit_state.tpl';
             $stateSID = SJB_Request::getVar('state_id', false);
             $formSubmitted = SJB_Request::getVar('action_add', false);
             $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID);
             if ($stateInfo) {
                 $stateInfo = array_merge($stateInfo, $_REQUEST);
                 $state = new SJB_State($stateInfo);
                 $addStateForm = new SJB_Form($state);
                 $addStateForm->registerTags($tp);
                 $state->setSID($stateSID);
                 $addValidParam = array('field' => 'country_sid', 'value' => $stateInfo['country_sid']);
                 if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) {
                     SJB_StatesManager::saveState($state);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $stateInfo['country_sid']);
                 } else {
                     $formFields = $addStateForm->getFormFieldsInfo();
                     $tp->assign('form_fields', $formFields);
                     $tp->assign('state_id', $stateSID);
                 }
             } else {
                 $tp->assign('action', 'edit');
                 $errors['WRONG_STATE_ID_SPECIFIED'] = 'WRONG_STATE_ID_SPECIFIED';
                 $template = 'state_errors.tpl';
             }
             break;
         case 'import_states':
             $template = 'import_states.tpl';
             $fileInfo = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             if ($fileInfo['error']) {
                 $errors[] = SJB_UploadFileManager::getErrorId($fileInfo['error']);
             } elseif ($fileInfo) {
                 $fileFormats = array('csv', 'xls', 'xlsx');
                 $pathInfo = pathinfo($fileInfo['name']);
                 $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : '';
                 if (!in_array(strtolower($fileExtension), $fileFormats)) {
                     $errors[] = 'Please choose Excel or csv file';
                 } else {
                     $importFile = new SJB_ImportFileXLS($fileInfo);
                     $importFile->parse();
                     $importedData = $importFile->getData();
                     $state = new SJB_State();
                     $count = 0;
                     foreach ($importedData as $key => $importedColumn) {
                         if ($key == 1) {
                             $data = array_merge(array(array('state_code', 'state_name')), array($importedColumn));
                             $importedProcessor = new SJB_ImportedStateProcessor($data, $state);
                         }
                         if (!$importedColumn) {
                             continue;
                         }
                         $stateInfo = $importedProcessor->getData($importedColumn);
                         if (!empty($stateInfo['state_code']) && !empty($stateInfo['state_name'])) {
                             $state = new SJB_State($stateInfo);
                             $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true));
                             $state->setPropertyValue('active', 1);
                             $stateSID = SJB_StatesManager::getStateSIDByStateCode($stateInfo['state_code'], $countrySID);
                             if ($stateSID) {
                                 $state->setSID($stateSID);
                             } else {
                                 $count++;
                             }
                             SJB_StatesManager::saveState($state);
                         }
                     }
                     $tp->assign('imported_states_count', $count);
                     $template = 'import_states_result.tpl';
                 }
             }
             break;
     }
     if ($action == 'list') {
         $countryCode = SJB_Settings::getSettingByName('default_country_code');
         if (!$countrySID) {
             $countrySID = SJB_CountriesManager::getCountrySIDByCountryCode($countryCode);
         }
         if (!$countrySID) {
             $allCountries = SJB_CountriesManager::getAllCountries();
             foreach ($allCountries as $country) {
                 $countrySID = $country['sid'];
                 break;
             }
         }
         $countryInfo = SJB_CountriesManager::getCountryInfoBySID($countrySID);
         if ($countryInfo && $countryInfo['country_code'] != $countryCode) {
             SJB_Settings::updateSetting('default_country_code', $countryInfo['country_code']);
         }
         $states = SJB_StatesManager::getAllStates($countrySID, ($paginator->currentPage - 1) * $paginator->itemsPerPage, $paginator->itemsPerPage);
         $paginator->setItemsCount(SJB_StatesManager::countStates($countrySID));
         $tp->assign('states', $states);
         $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     }
     $tp->assign("countries", $countries);
     $tp->assign("country_sid", $countrySID);
     $tp->assign("errors", $errors);
     $tp->display($template);
 }
Пример #15
0
    public function execute()
    {
        set_time_limit(0);
        ini_set('memory_limit', -1);
        $tp = SJB_System::getTemplateProcessor();
        $user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo();
        $user_group_info = reset($user_groups_info);
        $user_group_sid = $user_group_info['sid'];
        $fields_info = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid);
        $fields = array();
        $tp->assign('test_message', SJB_Request::getVar('test_message', false));
        $tp->assign('undeliveredMailingsForTest', SJB_Request::getVar('undeliveredMailingsForTest', false));
        foreach ($fields_info as $key => $val) {
            if ($val['id'] == 'Location') {
                foreach ($val['fields'] as $field) {
                    if ($field['id'] == 'Country') {
                        $fields['country'] = SJB_CountriesManager::getAllCountriesCodesAndNames();
                    } elseif ($field['id'] == 'State') {
                        $fields['state'] = SJB_StatesManager::getStatesNamesByCountry();
                    }
                }
            }
        }
        $tp->assign('fields', $fields);
        $errors = array();
        $errorId = SJB_Request::getVar('error', null, 'GET');
        if ($errorId) {
            $errors[$errorId] = 1;
        }
        if (isset($_REQUEST['submit']) && $_FILES['file_mail']['name'] && $_FILES['file_mail']['error']) {
            $errorId = SJB_UploadFileManager::getErrorId($_FILES['file_mail']['error']);
            if ($_REQUEST['submit'] != 'save') {
                $mailID = SJB_Request::getVar('mail_id', 0);
                $parameter = $mailID ? '?edit=' . $mailID : '';
                SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter . '&error=' . $errorId);
            }
            $errors[$errorId] = 1;
        } else {
            if (isset($_REQUEST['submit'])) {
                SJB_DB::query("DELETE FROM uploaded_files WHERE id = 'file_mail'");
                $upload_manager = new SJB_UploadFileManager();
                $upload_manager->setFileGroup('files');
                $upload_manager->setUploadedFileID('file_mail');
                $upload_manager->uploadFile('file_mail');
                $file_name = '';
                if (!isset($_REQUEST['delete_file']) && isset($_REQUEST['old_file']) && !$upload_manager->getUploadedFileName('file_mail')) {
                    $file_name = $_REQUEST['old_file'];
                } elseif ($upload_manager->getUploadedFileName('file_mail')) {
                    $file_name = "files/files/" . $upload_manager->getUploadedSavedFileName('file_mail');
                }
                $language = SJB_Request::getVar('language', 'any');
                $users = SJB_Request::getVar('users', 'any');
                $without_cv = SJB_Request::getVar('without_cv', false);
                $country = SJB_Request::getVar('country', '');
                $state = SJB_Request::getVar('state', '');
                $city = SJB_Request::getVar('city', '');
                $products = SJB_Request::getVar('products', array());
                $user_status = SJB_Request::getVar('user_status', '');
                $registration_date = SJB_Request::getVar('registration_date', array());
                $param = serialize(array('language' => $language, 'users' => $users, 'without_cv' => $without_cv, 'products' => $products, 'country' => $country, 'state' => $state, 'city' => $city, 'status' => $user_status, 'registration' => $registration_date));
                $email = '';
                $mailSubject = SJB_Request::getVar('subject', '');
                $mailText = stripcslashes(SJB_Request::getVar('text', ''));
                $mailID = SJB_Request::getVar('mail_id', 0);
                if ($mailID) {
                    SJB_DB::query('UPDATE `mailing` SET
					`subject` 	= ?s,
					`text` 		= ?s,
					`email` 	= ?s,
					`file` 		= ?s,
					`param` 	= ?s
				WHERE `id` 	= ?s', $mailSubject, $mailText, $email, $file_name, $param, $mailID);
                } else {
                    $query = "INSERT INTO mailing ( email , subject , text , file, param) VALUES ( ?s, ?s, ?s, ?s, ?s)";
                    SJB_DB::query($query, $email, $mailSubject, $mailText, $file_name, $param);
                }
                if ($_REQUEST['submit'] == 'save') {
                    SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/');
                } else {
                    $parameter = $mailID ? '?edit=' . $mailID : '';
                    SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter);
                }
            }
        }
        if (SJB_Request::getVar('delete')) {
            $mailings = SJB_Request::getVar('mailing');
            if (is_array($mailings)) {
                foreach ($mailings as $id => $value) {
                    SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $id);
                    SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $id);
                }
            } else {
                $idToDelete = SJB_Request::getInt('delete', 0);
                SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $idToDelete);
                SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $idToDelete);
            }
            SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/');
        }
        if (isset($_REQUEST['edit'])) {
            $idToEdit = SJB_Request::getInt('edit', 0);
            $mail_arr = SJB_DB::query('SELECT * FROM mailing WHERE id = ?n', $idToEdit);
            $tp->assign("mail_id", $mail_arr[0]['id']);
            $tp->assign("subject", $mail_arr[0]['subject']);
            $tp->assign("text", $mail_arr[0]['text']);
            $tp->assign("file", $mail_arr[0]['file']);
            $tp->assign("file_url", $mail_arr[0]['file']);
            $tp->assign("param", unserialize($mail_arr[0]['param']));
        }
        // get products by UserGroup ID
        if (SJB_Request::isAjax()) {
            $userGroupID = SJB_Request::getVar('usergr', 0);
            if ($userGroupID > 0) {
                $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupID);
            } else {
                $products = SJB_ProductsManager::getAllProductsInfo();
            }
            $tp->assign("products", $products);
            $tp->display("mailing_products.tpl");
            exit;
        }
        $mail_list = SJB_DB::query('SELECT * FROM mailing');
        foreach ($mail_list as $key => $var) {
            $param = unserialize($mail_list[$key]['param']);
            $where = '';
            $join = '';
            $numSentEmails = SJB_DB::queryValue('SELECT count(*) FROM `mailing_info` WHERE `mailing_id` = ?n AND `status`=0', $var['id']);
            if ($param["language"] != 'any') {
                $where .= " and language='{$param['language']}'";
            }
            if ($param["users"] != '0') {
                $where .= ' and u.user_group_sid=' . $param['users'];
            }
            if ($param["without_cv"]) {
                $join = "left join listings l on l.user_sid = u.sid";
                $where .= " and l.sid is null";
            }
            // user status
            if (!empty($param['status'])) {
                $where .= ' and `u`.`active`=' . (int) $param['status'];
            }
            // registration date
            if (!empty($param['registration']) && is_array($param['registration'])) {
                $i18n = SJB_I18N::getInstance();
                if (!empty($param['registration']['not_less'])) {
                    $where .= ' AND `u`.`registration_date` > \'' . $i18n->getInput('date', $param['registration']['not_less']) . '\'';
                }
                if (!empty($param['registration']['not_more'])) {
                    $where .= ' AND `u`.`registration_date` < \'' . $i18n->getInput('date', $param['registration']['not_more']) . '\'';
                }
            }
            // products
            if (!empty($param['products'])) {
                $join .= "\n            LEFT JOIN contracts ON u.sid = contracts.user_sid\n            LEFT JOIN products ON products.sid = contracts.product_sid\n        ";
                $whereProduct = array();
                foreach ($param['products'] as $theProduct) {
                    $theProduct = (int) $theProduct;
                    if (!empty($theProduct)) {
                        $whereProduct[] .= "products.sid = '{$theProduct}'";
                    } else {
                        $whereProduct[] .= 'products.sid IS NULL';
                    }
                }
                if (!empty($whereProduct)) {
                    $where .= ' AND (' . implode(' OR ', $whereProduct) . ')';
                }
            }
            /// products
            if (!empty($param['country']) || !empty($param['state'])) {
                if (!empty($param['country'])) {
                    $where_country = array();
                    foreach ($param['country'] as $the_country) {
                        if (!empty($the_country)) {
                            $where_country[] .= "`u`.`Location_Country` = '{$the_country}'";
                        } else {
                            $where_country[] .= "`u`.`Location_Country` IS NULL";
                        }
                    }
                    if (!empty($where_country)) {
                        $where .= ' AND (' . implode(' OR ', $where_country) . ')';
                    }
                }
                if (!empty($param['state'])) {
                    $where_state = array();
                    foreach ($param['state'] as $the_state) {
                        if (!empty($the_state)) {
                            $where_state[] .= "`u`.`Location_State` = '{$the_state}'";
                        } else {
                            $where_state[] .= "`u`.`Location_State` IS NULL";
                        }
                    }
                }
                if (!empty($where_state)) {
                    $where .= ' AND (' . implode(' OR ', $where_state) . ')';
                }
                if (!empty($param['city'])) {
                    $where .= " AND `u`.`Location_City` = '{$param['city']}'";
                }
            }
            $mail_list[$key]['not_send'] = $numSentEmails;
            $mail_list[$key]['mail_arr'] = SJB_DB::query("\n        SELECT u.sid as sid, u.username, u.user_group_sid, u.language\n        FROM users u\n            {$join}\n            WHERE u.sendmail = 0\n            {$where}\n            GROUP BY `u`.`sid`");
            $mail_list[$key]['count'] = count($mail_list[$key]['mail_arr']);
        }
        /*
         * test sending
         */
        $testMailingID = SJB_Request::getVar('test_send', 0);
        if ($testMailingID) {
            if ($this->isTestEmailValid()) {
                $testSendResult = false;
                $oMailing = new SJB_Mailing($testMailingID);
                $mailings = SJB_Request::getVar('mailing');
                if (is_array($mailings)) {
                    foreach ($mailings as $id => $value) {
                        $oMailing->setMailingID($id);
                        $oMailing->setMailingList($mail_list);
                        if ($oMailing->testSend()) {
                            $testSendResult = true;
                        }
                    }
                } else {
                    $oMailing->setMailingList($mail_list);
                    $testSendResult = $oMailing->testSend();
                }
                if ($testSendResult) {
                    SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/?test_message=1');
                } else {
                    $email = urlencode(SJB_Request::getString('email', false));
                    SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/mailing/?undeliveredMailingsForTest={$email}");
                }
            } else {
                $tp->assign('testEmailNotValid', true);
            }
        }
        // general sending
        $sendToMailingID = SJB_Request::getVar('sending', 0);
        $sendResult = false;
        if ($sendToMailingID) {
            $oMailing = new SJB_Mailing($sendToMailingID);
            $mailings = SJB_Request::getVar('mailing');
            $undeliveredMailingsInfo = array();
            if (is_array($mailings)) {
                foreach ($mailings as $id => $value) {
                    $oMailing->setMailingID($id);
                    $oMailing->setMailingList($mail_list);
                    $countOfSendMailings = $oMailing->send();
                    if ($countOfSendMailings != 0) {
                        $sendResult = true;
                    }
                    $undeliveredMailingsInfo = array_merge($oMailing->getUndeliveredMailingsInfo(), $undeliveredMailingsInfo);
                }
            } else {
                $oMailing->setMailingList($mail_list);
                $countOfSendMailings = $oMailing->send();
                if ($countOfSendMailings != 0) {
                    $sendResult = true;
                }
                $undeliveredMailingsInfo = $oMailing->getUndeliveredMailingsInfo();
            }
            if ($sendResult) {
                $tp->assign('send_result', $sendResult);
            }
            if (count($undeliveredMailingsInfo)) {
                $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo());
            }
        }
        // send mailing to undelivered
        $sendToUndeliveredMailingID = SJB_Request::getVar('sendToUndeliveredEmails', 0);
        if (!empty($sendToUndeliveredMailingID)) {
            $oMailing = new SJB_Mailing($sendToUndeliveredMailingID);
            $oMailing->setMailingList($mail_list);
            $oMailing->sendToUndelivered();
            if ($oMailing->getUndeliveredMailingsInfo()) {
                $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo());
            }
        }
        $groups = SJB_DB::query("SELECT * FROM `user_groups`");
        $products = SJB_ProductsManager::getAllProductsInfo();
        $testEmail = SJB_Settings::getSettingByName('test_email');
        $tp->assign('test_email', $testEmail);
        $tp->assign("products", $products);
        $tp->assign("groups", $groups);
        $tp->assign("mail_list", $mail_list);
        $tp->assign('errors', $errors);
        $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
        $tp->display("mailing.tpl");
    }
Пример #16
0
 public function execute()
 {
     $errors = array();
     if (SJB_Request::isAjax()) {
         $response = null;
         if ($logoId = SJB_Request::getVar('logo_id')) {
             SJB_UploadFileManager::deleteUploadedFileByID($logoId, 'logo');
             $parsersId = SJB_Request::getVar('id');
             SJB_DB::query("UPDATE `parsers` SET `xml_logo` = NULL WHERE id = ?n", $parsersId);
         } elseif ($userName = SJB_Request::getVar('parser_user')) {
             $userType = SJB_Request::getVar('user_type');
             $products = SJB_XmlImport::getProducts($userType, $userName, $errors);
             $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors));
             $response = json_encode($response);
         }
         die($response);
     }
     $tp = SJB_System::getTemplateProcessor();
     $original_xml = !empty($_REQUEST['xml']) ? $_REQUEST['xml'] : '';
     $xml = $original_xml;
     $tree = '';
     $listing_fields = array();
     $parsing_name = isset($_REQUEST['parser_name']) ? $_REQUEST['parser_name'] : '';
     $usr_name = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : '';
     $pars_url = isset($_REQUEST['parser_url']) ? $_REQUEST['parser_url'] : '';
     $form_description = isset($_POST['form_description']) ? $_POST['form_description'] : "";
     $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : "";
     $custom_script = SJB_Request::getVar('custom_script', '');
     $custom_script_users = SJB_Request::getVar('custom_script_users', '');
     $add_new_user = isset($_POST['add_new_user']) ? intval($_POST['add_new_user']) : 0;
     $username = SJB_Request::getVar('username', '');
     $external_id = SJB_Request::getVar('external_id', '');
     $defaultValue = array();
     $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings');
     $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     $selected = array();
     $a_selected = array();
     $selectedLogoOption = null;
     $selectedLogoField = null;
     $xml_logo = null;
     $selectedProduct = SJB_Request::getVar('postUnderProduct');
     $save_error = SJB_Request::getVar('save_error');
     if ($save_error) {
         $errors[] = base64_decode($save_error);
     }
     if (!empty($_REQUEST['xml']) || $id > 0) {
         // step 2 OR edit exist
         if ($id > 0) {
             // load exist parser
             $parser_from_id = SJB_XmlImport::getSystemParsers($id);
             if (isset($parser_from_id[0]['name'])) {
                 $parser_from_id = $parser_from_id[0];
             }
             $parsing_name = $parser_from_id['name'];
             $usr_id = $parser_from_id['usr_id'];
             $usr_name = $parser_from_id['usr_name'];
             $form_description = $parser_from_id['description'];
             $pars_url = $parser_from_id['url'];
             $type_id = $parser_from_id['type_id'];
             $custom_script = $parser_from_id['custom_script'];
             $custom_script_users = $parser_from_id['custom_script_users'];
             $add_new_user = $parser_from_id['add_new_user'];
             $importType = $parser_from_id['import_type'];
             $xml = $parser_from_id['xml'];
             $xml_logo = $parser_from_id['xml_logo'];
             $xml = SJB_XmlImport::cleanXmlFromImport($xml);
             $defaultValue = $parser_from_id['default_value'] != '' ? unserialize($parser_from_id['default_value']) : array();
             $username = $parser_from_id['username'];
             $map = unserialize($parser_from_id['maper']);
             $external_id = str_replace('@', '_dog_', $parser_from_id['external_id']);
             $selected_logo_options = unserialize($parser_from_id['logo_options']);
             $selectedLogoOption = $selected_logo_options['option'];
             $selectedLogoField = $selected_logo_options['field'];
             if ($selected_logo_options['option'] == 'upload_logo') {
                 $upload_manager = new SJB_UploadPictureManager();
                 $upload_manager->getUploadedPictureInfo($xml_logo . '_thumb');
                 $logo_link = $upload_manager->getUploadedFileLink($xml_logo . '_thumb');
                 $tp->assign('logo_link', $logo_link);
             }
             foreach ($map as $key => $val) {
                 unset($map[$key]);
                 $key = SJB_XmlImport::encodeSpecialEntities($key);
                 $map[$key] = $val;
             }
             $selected = array_values($map);
             $a_selected = array_keys($map);
             $selectedProduct = $parser_from_id['product_sid'];
         } else {
             $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']);
         }
         $sxml = new simplexml();
         $xml = stripslashes($xml);
         $tree = $sxml->xml_load_file($xml, 'array');
         if (isset($tree['@content'])) {
             $tree = $tree[0];
         }
         if (is_array($tree)) {
             $tree = SJB_XmlImport::convertArray($tree);
             foreach ($tree as $key => $val) {
                 unset($tree[$key]);
                 $key = SJB_XmlImport::encodeSpecialEntities($key);
                 $tree[$key]['val'] = $val;
                 $tree[$key]['key'] = $key;
             }
             $field_types = array(0, $type_id);
             $listing_fields = array();
             $i = 0;
             foreach ($field_types as $type) {
                 $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type);
                 foreach ($listing_fields_info as $listing_field_info) {
                     if ($listing_field_info['type'] == 'location') {
                         foreach ($listing_field_info['fields'] as $fieldInfo) {
                             $listing_field = new SJB_ListingField($fieldInfo);
                             $listing_field->setSID($fieldInfo['sid']);
                             $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value;
                             $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                             $i++;
                         }
                     } else {
                         $listing_field = new SJB_ListingField($listing_field_info);
                         $listing_field->setSID($listing_field_info['sid']);
                         $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value;
                         $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                         $i++;
                     }
                 }
             }
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date";
             $i++;
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url";
             $i++;
             $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id";
         } else {
             $errors[] = 'XML syntaxis error.';
         }
     } else {
         $errors[] = 'Please input correct xml';
     }
     if (empty($selectedProduct)) {
         $errors[] = 'Please select a product';
     }
     if (!filter_var($pars_url, FILTER_VALIDATE_URL)) {
         $errors[] = 'Please input correct URL';
     }
     $error = SJB_Request::getVar('error', false, 'GET');
     if ($error) {
         $errors[$error] = true;
     }
     $userType = empty($add_new_user) ? 'username' : 'group';
     if ($userType == 'group') {
         $userName = SJB_UserGroupManager::getUserGroupSIDByID($usr_name);
     } else {
         $userName = $usr_name;
     }
     $products = SJB_XmlImport::getProducts($userType, $userName, $errors);
     $tp->assign('id', $id);
     $tp->assign('selected', $selected);
     $tp->assign('a_selected', $a_selected);
     $tp->assign('xml', htmlspecialchars($xml));
     $tp->assign('xml_logo', $xml_logo);
     $tp->assign('xmlToUser', $xml);
     $tp->assign('default_value', $defaultValue);
     $tp->assign('form_name', $parsing_name);
     $tp->assign('form_user', $usr_name);
     $tp->assign('form_user_sid', $usr_id);
     $tp->assign('form_url', $pars_url);
     $tp->assign('form_description', $form_description);
     $tp->assign('custom_script', $custom_script);
     $tp->assign('custom_script_users', $custom_script_users);
     $tp->assign('username', $username);
     $tp->assign('external_id', $external_id);
     $tp->assign('import_type', $importType);
     $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo());
     $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id);
     $tp->assign('add_new_user', $add_new_user);
     $tp->assign('type_id', $type_id);
     $tp->assign('type_name', $type_name);
     $tp->assign('errors', $errors);
     $tp->assign('tree', $tree);
     $tp->assign("fields", $listing_fields);
     $tp->assign('logo_options', $logo_options_array);
     $tp->assign('selectedLogoOption', $selectedLogoOption);
     $tp->assign('selectedLogoField', $selectedLogoField);
     $tp->assign('selectedProduct', $selectedProduct);
     $tp->assign('products', $products);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('add_step_two.tpl');
 }
Пример #17
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
     $productSID = SJB_Request::getVar('product_sid', false);
     $editUser = SJB_Request::getVar('edit_user', false);
     $action = SJB_Request::getVar('action', false);
     $username = SJB_Request::getVar('username', false);
     $errors = array();
     if ($username && ($userSID = SJB_UserManager::getUserSIDbyUsername($username))) {
         $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
         if (!$productSID) {
             $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupInfo['sid']);
             foreach ($products as $key => $product) {
                 if (empty($product['listing_type_sid']) || $product['listing_type_sid'] != $listingTypeSID) {
                     unset($products[$key]);
                 }
             }
             if ($action == 'productVerify') {
                 $errors['PRODUCT_NOT_SELECTED'] = 1;
             }
             $tp->assign('errors', $errors);
             $tp->assign('username', $username);
             $tp->assign('products', $products);
             $tp->assign('edit_user', $editUser);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('select_product.tpl');
         } else {
             $form_submitted = SJB_Request::getVar('action', '') == 'add';
             $tmp_listing_id_from_request = SJB_Request::getVar('listing_id', false, 'default', 'int');
             if (!empty($tmp_listing_id_from_request)) {
                 $tmp_listing_sid = $tmp_listing_id_from_request;
             } elseif (!$tmp_listing_id_from_request) {
                 $tmp_listing_sid = time();
             }
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             $extraInfo = is_null($productInfo['serialized_extra_info']) ? null : unserialize($productInfo['serialized_extra_info']);
             if (!empty($extraInfo)) {
                 $extraInfo['product_sid'] = $productSID;
             }
             $_REQUEST['featured'] = !empty($_REQUEST['featured']) ? $_REQUEST['featured'] : $productInfo['featured'];
             $_REQUEST['priority'] = !empty($_REQUEST['priority']) ? $_REQUEST['priority'] : $productInfo['priority'];
             $listing = new SJB_Listing($_REQUEST, $listingTypeSID);
             $properties = $listing->getPropertyList();
             foreach ($properties as $property) {
                 $propertyInfo = $listing->getPropertyInfo($property);
                 $propertyInfo['user_sid'] = $userSID;
                 if ($propertyInfo['type'] == 'location') {
                     $child = $listing->getChild($property);
                     $childProperties = $child->getPropertyList();
                     foreach ($childProperties as $childProperty) {
                         $childPropertyInfo = $child->getPropertyInfo($childProperty);
                         $childPropertyInfo['user_sid'] = $userSID;
                         $child->setPropertyInfo($childProperty, $childPropertyInfo);
                     }
                 }
                 $listing->setPropertyInfo($property, $propertyInfo);
             }
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted) {
                 if (!empty($access_type)) {
                     $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
                 }
             }
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($userSID);
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar("screening_questionnaire");
                     $listing_info = $_REQUEST;
                     $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($userSID), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             if ($listing->getProperty('captcha')) {
                 $listing->deleteProperty('captcha');
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && $add_listing_form->isDataValid($field_errors)) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 $listing->setUserSID($userSID);
                 $listing->setProductInfo($extraInfo);
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 SJB_ListingManager::saveListing($listing);
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $_REQUEST['featured'], $_REQUEST['priority'], $userSID);
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $v) {
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                     }
                     SJB_Session::unsetValue('tmp_file_storage');
                 }
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
                 if (!empty($uploadedFields)) {
                     foreach ($uploadedFields as $fieldId => $fieldValue) {
                         // get field of listing
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldValue['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                         // unset value from session temporary storage
                         $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                     }
                     //and remove token key from temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                     SJB_ListingManager::saveListing($listing);
                 }
                 SJB_ListingManager::activateListingBySID($listing->getSID());
                 SJB_ProductsManager::incrementPostingsNumber($productSID);
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($editUser) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user/?user_sid=" . $userSID);
                 } else {
                     if ($listingTypeID == 'resume' || $listingTypeID == 'job') {
                         $link = "manage-" . strtolower($listingTypeID) . "s";
                     } else {
                         $link = "manage-" . strtolower($listingTypeID) . "-listings";
                     }
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/{$link}/?action=search&listing_type_sid=" . $listingTypeSID);
                 }
             } else {
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
                 $formFieldsSorted = array();
                 $formFieldsSorted['featured'] = $form_fields['featured'];
                 $formFieldsSorted['priority'] = $form_fields['priority'];
                 foreach ($pages as $page) {
                     $listing_fields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     foreach (array_keys($listing_fields) as $field) {
                         if ($listing->propertyIsSet($field)) {
                             $formFieldsSorted[$field] = $form_fields[$field];
                         }
                     }
                 }
                 $form_fields = $formFieldsSorted;
                 //SJB_HelperFunctions::d($form_fields);
                 $employers_list = SJB_Request::getVar('list_emp_ids', false);
                 $employers = array();
                 if (is_array($employers_list)) {
                     foreach ($employers_list as $emp) {
                         $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                         $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                     }
                     sort($employers);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign("pic_limit", $numberOfPictures);
                 $tp->assign("listing_id", $tmp_listing_sid);
                 $tp->assign("listing_access_list", $employers);
                 $tp->assign("errors", $field_errors);
                 $tp->assign("form_fields", $form_fields);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             }
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('edit_user', $editUser);
             $tp->assign('productInfo', $productInfo);
             $tp->assign('username', $username);
             $tp->assign('product_sid', $productSID);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('input_form.tpl');
         }
     } else {
         if ($username && !$userSID) {
             $errors['USER_NOT_FOUND'] = 1;
         } elseif ($action == 'userVerify') {
             $errors['USER_NOT_SELECTED'] = 1;
         }
         $tp->assign('errors', $errors);
         $tp->assign('username', $username);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->display('select_user.tpl');
     }
 }
Пример #18
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $dir_separator = DIRECTORY_SEPARATOR;
     $script_path = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
     $script_path = array_shift($script_path);
     $identifier = SJB_Request::getVar('identifier', time());
     $filename = SJB_Request::getVar('filename', false);
     $settings = array();
     if ($filename) {
         SJB_Backup::sendArchiveFile($filename, $script_path . 'backup' . $dir_separator . $filename);
     }
     if (SJB_Request::getVar('action') == "save") {
         $expPeriod = SJB_Request::getVar('backup_expired_period');
         if (!empty($expPeriod) && (!is_numeric($expPeriod) || $expPeriod < 0)) {
             $errors[] = 'EXP_PERIOD_NOT_VALID';
         }
         $ftpValid = $this->isFTPDataValid();
         if (SJB_Request::getVar('autobackup', false) && SJB_Request::getVar('ftp_backup', false) && !$ftpValid) {
             $errors[] = 'FTP_DETAILS_NOT_VALID';
         }
         if (empty($errors)) {
             $backupSettings = $_REQUEST;
             foreach ($backupSettings as $setting => $value) {
                 if (!SJB_Settings::saveSetting($setting, $value)) {
                     $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = "SETTINGS_SAVED_WITH_PROBLEMS";
                 }
             }
             if (empty($errors)) {
                 $tp->assign('successSaveMessage', true);
             }
         } else {
             $settings = $_REQUEST;
         }
     }
     switch ($action) {
         case 'backup':
             if (SJB_System::getSystemSettings('isDemo')) {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             if (SJB_System::getIfTrialModeIsOn() && $_SERVER['REMOTE_ADDR'] != "91.205.51.231") {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             SessionStorage::destroy('backup_' . $identifier);
             SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $backup_type = SJB_Request::getVar('backup_type');
             $backupDir = $script_path . 'backup' . $dir_separator;
             try {
                 $this->prepareBackupDir($backupDir);
             } catch (Exception $e) {
                 SJB_Session::setValue('error', $e->getMessage());
                 exit;
             }
             switch ($backup_type) {
                 case 'full':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $name = 'db.sql';
                     SJB_Backup::dump($name, $script_path, $identifier);
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore', $name);
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'full_backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive($name, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'full')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'database':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $name = 'db.sql';
                     $backupName = 'mysqldump_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '../backup' . $dir_separator;
                     SJB_Backup::dump($name, $script_path, $identifier);
                     if (SJB_Backup::archive(false, $name, $script_path, $export_files_dir_name, $backupName, false, $identifier, 'database')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'files':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore');
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive(false, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'files')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
             }
             break;
         case 'restore':
             if (SJB_System::getSystemSettings('isDemo')) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 exit;
             }
             if (SJB_System::getIfTrialModeIsOn()) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 exit;
             }
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $error = false;
             $restoreDir = $script_path . 'restore' . $dir_separator;
             try {
                 $fileName = $this->moveUploadedFile($restoreDir);
                 $tar = new Archive_Tar($restoreDir . $fileName, 'gz');
                 $tar->_error_class = 'SJB_PEAR_Exception';
                 $tar->extractList('db.sql', $restoreDir);
                 $tar->extract($script_path);
                 if (is_file($restoreDir . 'db.sql')) {
                     SJB_Backup::restore_base_tables($restoreDir . 'db.sql');
                 }
                 SJB_Cache::getInstance()->clean();
             } catch (Exception $ex) {
                 $error = $ex->getMessage();
             }
             SJB_Filesystem::delete($restoreDir);
             if (is_file($script_path . 'install.php')) {
                 SJB_Filesystem::delete($script_path . 'install.php');
             }
             if ($error) {
                 SJB_Session::setValue('error', $error);
             } else {
                 SJB_Session::setValue('restore', 1);
             }
             exit;
             break;
         case 'send_archive':
             $name = SJB_Request::getVar('name', false);
             $archive_file_path = SJB_Path::combine(SJB_BASE_DIR . 'backup' . $dir_separator, $name);
             if ($name) {
                 SJB_Backup::sendArchiveFile($name, $archive_file_path);
             }
             break;
         case 'check':
             $sessionBackup = SessionStorage::read('backup_' . $identifier);
             $sessionBackup = $sessionBackup ? unserialize($sessionBackup) : array();
             $sessionRestore = SJB_Session::getValue('restore');
             $sessionError = SJB_Session::getValue('error');
             if (!empty($sessionBackup['name'])) {
                 $name = $sessionBackup['name'];
                 SessionStorage::destroy('backup_' . $identifier);
                 echo SJB_System::getSystemSettings('SITE_URL') . "/backup/?action=send_archive&name={$name}";
                 exit;
             } elseif (!empty($sessionRestore)) {
                 SJB_Session::unsetValue('restore');
                 echo SJB_System::getSystemSettings('SITE_URL') . '/backup/#restore';
                 exit;
             } elseif (!empty($sessionError)) {
                 echo 'Error';
                 if (SJB_System::getSystemSettings('isDemo')) {
                     echo ': You don\'t have permissions for it. This is a Demo version of the software.';
                 }
                 if (SJB_System::getIfTrialModeIsOn()) {
                     echo ': You don\'t have permissions for it. This is a Trial version of the software.';
                 }
                 exit;
             } elseif (!empty($sessionBackup['last_time'])) {
                 $period = (time() - $sessionBackup['last_time']) / 60;
                 if ($period < 5) {
                     echo 1;
                 } else {
                     SJB_Session::setValue('error', 'The backup generation process was unexpectedly interrupted. Please try again.');
                     echo 'error';
                 }
                 exit;
             } else {
                 echo 1;
             }
             exit;
             break;
         case 'delete_backup':
             $name = SJB_Request::getVar('name', false);
             if ($name) {
                 $backup = $script_path . 'backup' . $dir_separator . $name;
                 if (is_file($backup)) {
                     SJB_Filesystem::delete($backup);
                     SJB_Autobackup::deleteFileFromFtp($name);
                 } else {
                     $errors['FILE_NOT_FOUND'] = 1;
                 }
             }
             $tp->assign('errors', $errors);
             $tp->assign('delBackup', 1);
         case 'created_backups':
             $path = $script_path . 'backup' . $dir_separator;
             if (is_dir($path)) {
                 $di = new DirectoryIterator($path);
                 $backupsArr = array();
                 foreach ($di as $file) {
                     $fileName = $file->getFilename();
                     if (!$file->isDir() && !$file->isLink() && $fileName != '.htaccess') {
                         $cTime = $file->getCTime();
                         $backupsArr[$cTime]['name'] = $fileName;
                         if (preg_match('/mysqldump/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site database only';
                         } elseif (preg_match('/full_backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Full site backup';
                         } elseif (preg_match('/backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site files only';
                         } else {
                             $backupsArr[$cTime]['type'] = 'Unknown';
                         }
                         $pattern = '/(\\w+)_(\\d+)_(\\d+)_(\\d+)__(\\d+)_(\\d+).tar.gz/i';
                         $replacement = '$2-$3-$4 $5:$6';
                         $backupsArr[$cTime]['date'] = preg_replace($pattern, $replacement, $fileName);
                     }
                 }
                 krsort($backupsArr);
                 $tp->assign('created_backups', $backupsArr);
             }
             $tp->display('created_backups.tpl');
             exit;
             break;
         case 'error':
             $sessionError = SJB_Session::getValue('error');
             if (!is_null($sessionError)) {
                 echo '<p class="error">' . $sessionError . '</p>';
                 exit;
             }
             break;
     }
     if (empty($settings)) {
         $settings = SJB_Settings::getSettings();
     }
     $tp->assign('errors', $errors);
     $tp->assign('settings', $settings);
     $tp->assign('identifier', $identifier);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('backup.tpl');
 }
Пример #19
0
 public function execute()
 {
     $errors = array();
     $field_errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $loggedIn = SJB_UserManager::isUserLoggedIn();
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $controller = new SJB_SendListingInfoController($_REQUEST);
     $isDataSubmitted = false;
     $jobInfo = SJB_ListingManager::getListingInfoBySID($controller->getListingID());
     if ($controller->isListingSpecified()) {
         if ($controller->isDataSubmitted()) {
             if (SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($errors)) {
                 // получим уникальный id для файла в uploaded_files
                 $file_id_current = 'application_' . md5(microtime());
                 $upload_manager = new SJB_UploadFileManager();
                 $upload_manager->setFileGroup('files');
                 $upload_manager->setUploadedFileID($file_id_current);
                 $file_name = $upload_manager->uploadFile('file_tmp');
                 $id_file = $upload_manager->fileId;
                 $post = $controller->getData();
                 $listingId = 0;
                 $post['submitted_data']['questionnaire'] = '';
                 if (isset($post['submitted_data']['id_resume'])) {
                     $listingId = $post['submitted_data']['id_resume'];
                 }
                 $mimeType = isset($_FILES['file_tmp']['type']) ? $_FILES['file_tmp']['type'] : '';
                 if (isset($_FILES['file_tmp']['size']) && $file_name != '' && $_FILES['file_tmp']['size'] == 0) {
                     $errors['FILE_IS_EMPTY'] = 'The uploaded file should not be blank';
                 }
                 if (!empty($_FILES['file_tmp']['name'])) {
                     $fileFormats = explode(',', SJB_System::getSettingByName('file_valid_types'));
                     $fileInfo = pathinfo($_FILES['file_tmp']['name']);
                     if (!isset($fileInfo['extension']) || !in_array(strtolower($fileInfo['extension']), $fileFormats)) {
                         $errors['NOT_SUPPORTED_FILE_FORMAT'] = strtolower($fileInfo['extension']) . ' ' . SJB_I18N::getInstance()->gettext(null, 'is not in an acceptable file format');
                     }
                 }
                 if ($file_name == '' && $listingId == 0) {
                     $canAppplyWithoutResume = false;
                     SJB_Event::dispatch('CanApplyWithoutResume', $canAppplyWithoutResume);
                     if (!$canAppplyWithoutResume) {
                         $errors['APPLY_INPUT_ERROR'] = 'Please select file or resume';
                     }
                 } else {
                     if (SJB_Applications::isApplied($post['submitted_data']['listing_id'], $current_user_sid) && !is_null($current_user_sid)) {
                         $errors['APPLY_APPLIED_ERROR'] = 'You already applied';
                     }
                 }
                 $res = false;
                 $listing_info = '';
                 $notRegisterUserData = $_POST;
                 $score = 0;
                 // для зарегестрированного пользователя получим поля email и name
                 // для незарегестрированных - поля name и email приходят с формы
                 if ($loggedIn === true) {
                     $userData = SJB_UserManager::getCurrentUserInfo();
                     $post['submitted_data']['username'] = isset($userData['username']) ? $userData['username'] : '';
                     $post['submitted_data']['LastName'] = isset($userData['LastName']) ? $userData['LastName'] : '';
                     $post['submitted_data']['FirstName'] = isset($userData['FirstName']) ? $userData['FirstName'] : '';
                     $post['submitted_data']['name'] = $post['submitted_data']['FirstName'] . ' ' . $post['submitted_data']['LastName'];
                     $post['submitted_data']['email'] = $userData['email'];
                 }
                 if (!empty($jobInfo['screening_questionnaire'])) {
                     $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
                     $add_form = new SJB_Form($questions);
                     $add_form->registerTags($tp);
                     $add_form->isDataValid($field_errors);
                     $tp->assign('field_errors', $field_errors);
                     if (!$field_errors) {
                         $result = array();
                         $properties = $questions->getProperties();
                         $countAnswers = 0;
                         foreach ($properties as $key => $val) {
                             if ($val->type->property_info['type'] == 'boolean') {
                                 switch ($val->value) {
                                     case 0:
                                         $val->value = 'No';
                                         break;
                                     case 1:
                                         $val->value = 'Yes';
                                         break;
                                 }
                             }
                             $result[$val->caption] = $val->value;
                             if (isset($val->type->property_info['list_values'])) {
                                 foreach ($val->type->property_info['list_values'] as $list_values) {
                                     if (is_array($val->value)) {
                                         foreach ($val->value as $value) {
                                             if ($value == $list_values['id'] && $list_values['score'] != 'no') {
                                                 $score += $list_values['score'];
                                                 $countAnswers++;
                                             }
                                         }
                                     } else {
                                         if ($val->value == $list_values['id'] && $list_values['score'] != 'no') {
                                             $score += $list_values['score'];
                                             $countAnswers++;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($countAnswers === 0) {
                             $score = 0.0;
                         } else {
                             $score = round($score / $countAnswers, 2);
                         }
                         $post['submitted_data']['questionnaire'] = serialize($result);
                     }
                 }
                 if (count($errors) == 0 && count($field_errors) == 0) {
                     $res = SJB_Applications::create($post['submitted_data']['listing_id'], $current_user_sid, isset($post['submitted_data']['id_resume']) ? $post['submitted_data']['id_resume'] : '', $post['submitted_data']['comments'], $file_name, $mimeType, $id_file, isset($post['submitted_data']['anonymous']) ? $post['submitted_data']['anonymous'] : '0', $notRegisterUserData, $post['submitted_data']['questionnaire'], $score);
                     if ($res) {
                         SJB_Statistics::addStatistics('apply', $post['submitted_data']['listing_id'], $res);
                     }
                     if (isset($post['submitted_data']['id_resume']) && $post['submitted_data']['id_resume'] != 0) {
                         $listing_info = SJB_ListingManager::getListingInfoBySID($post['submitted_data']['id_resume']);
                         $emp_sid = SJB_ListingManager::getUserSIDByListingSID($post['submitted_data']['listing_id']);
                         $accessible = SJB_ListingManager::isListingAccessableByUser($post['submitted_data']['id_resume'], $emp_sid);
                         if (!$accessible) {
                             SJB_ListingManager::setListingAccessibleToUser($post['submitted_data']['id_resume'], $emp_sid);
                         }
                     }
                     if (!empty($file_name)) {
                         $file_name = 'files/files/' . $file_name;
                     }
                     SJB_Notifications::sendApplyNow($post, $file_name, $listing_info, $current_user_sid, $notRegisterUserData, $score);
                     if (!empty($jobInfo['screening_questionnaire'])) {
                         $questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($jobInfo['screening_questionnaire']);
                         if ($questionnaire) {
                             $passing_score = 0;
                             switch ($questionnaire['passing_score']) {
                                 case 'acceptable':
                                     $passing_score = 1;
                                     break;
                                 case 'good':
                                     $passing_score = 2;
                                     break;
                                 case 'very_good':
                                     $passing_score = 3;
                                     break;
                                 case 'excellent':
                                     $passing_score = 4;
                                     break;
                             }
                         }
                         if ($score >= $passing_score && $questionnaire['send_auto_reply_more'] == 1) {
                             if (!empty($questionnaire['email_text_more'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_more'], $notRegisterUserData);
                             }
                         } elseif ($score < $passing_score && $questionnaire['send_auto_reply_less'] == 1) {
                             if (!empty($questionnaire['email_text_less'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_less'], $notRegisterUserData);
                             }
                         }
                     }
                 }
                 if ($res === false) {
                     $errors['APPLY_ERROR'] = 'Cannot apply';
                 }
                 $isDataSubmitted = true;
             }
         }
         if (!empty($jobInfo['screening_questionnaire'])) {
             $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
             $add_form = new SJB_Form($questions);
             $add_form->registerTags($tp);
             $form_fields = $add_form->getFormFieldsInfo();
             $tp->assign('form_fields', $form_fields);
             $tp->assign('questionsObject', $questions);
         }
         if ($loggedIn) {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID('Resume');
             $wait_approve = SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid);
             $approve_status = '';
             if ($wait_approve) {
                 $approve_status = "AND `l`.`status` = 'approved'";
             }
             $result = SJB_DB::query("SELECT `l`.`sid` , `l`.`Title` FROM `listings` as `l`\n\t\t\t\tLEFT JOIN `listing_types` as `lt` ON (`lt`.`sid` = `l`.`listing_type_sid`)\n\t\t\t\tWHERE `lt`.`id` = 'Resume' {$approve_status} AND `l`.`user_sid` = {$current_user_sid} AND `l`.`active`");
             $resume = array();
             foreach ($result as $val) {
                 $resume[$val['sid']] = $val['Title'];
             }
             $tp->assign('resume', $resume);
         }
         $tp->assign('listing', $jobInfo);
     } else {
         $errors['UNDEFINED_LISTING_ID'] = true;
     }
     $tp->assign('request', $_REQUEST);
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $controller->getListingID());
     $tp->assign('is_data_submitted', $isDataSubmitted);
     $tp->display('apply_now.tpl');
 }
Пример #20
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_type_id = SJB_Request::getVar('listing_type_id', false);
     $action = SJB_Request::getVar('action', false);
     $type = SJB_Request::getVar('type', false);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $supportedFormats = array('xlsx', 'xls', 'csv');
     $warning = false;
     $error = '';
     if ($action == 'example' && $type) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
         $listing_field_manager = new SJB_ListingFieldManager();
         $common_details = $listing_field_manager->getCommonListingFieldsInfo();
         $extra_details = $listing_field_manager->getListingFieldsInfoByListingType($listing_type_sid);
         $listing_fields = array_merge($common_details, $extra_details);
         $directory_to_export = SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY');
         $export_properties = array();
         $export_data = array();
         foreach ($listing_fields as $listing_field) {
             $export_properties[$listing_field['id']] = $listing_field['id'];
             $export_data[0][$listing_field['id']] = '';
         }
         SJB_ExportController::createExportDirectoriesForExample();
         switch ($type) {
             case 'exl':
                 SJB_ExportController::makeExportFile($export_data, 'example.xls');
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.xls');
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.xls');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
             case 'csv':
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.csv');
                 $fp = fopen($export_files_dir, 'w');
                 fputcsv($fp, explode(',', implode(',', $export_properties)));
                 fclose($fp);
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.csv');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
         }
         SJB_Filesystem::delete($directory_to_export);
         exit;
     }
     if ($productsInfo = $this->canCurrentUserAddListing($error)) {
         $acl = SJB_Acl::getInstance();
         if ($acl->isAllowed('bulk_job_import') == true) {
             $fileInfo = null;
             if (isset($_FILES['import_file'])) {
                 $extension = strtolower(substr(strrchr($_FILES['import_file']['name'], '.'), 1));
                 if (empty($_FILES['import_file']['name']) || !in_array($extension, $supportedFormats)) {
                     $warning = 'Please choose Excel or csv file';
                 } else {
                     $fileInfo = $_FILES['import_file'];
                 }
             }
             $contractID = SJB_Request::getVar('contract_id', false);
             $current_user = SJB_UserManager::getCurrentUser();
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } elseif (count($productsInfo) == 1) {
                 $productInfo = array_pop($productsInfo);
                 $contractID = $productInfo['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } else {
                 $tp->assign("products_info", $productsInfo);
                 $tp->assign("listing_type_id", $listing_type_id);
                 $tp->display("listing_product_choice.tpl");
             }
             if ($contractID && $listing_type_id) {
                 $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
                 if ($fileInfo) {
                     switch ($extension) {
                         case 'xls':
                         case 'xlsx':
                             $import_file = new SJB_ImportFileXLS($fileInfo);
                             break;
                         case 'csv':
                             $import_file = new SJB_ImportFileCSV($fileInfo, ',');
                             break;
                     }
                     $import_file->parse($encodingFromCharset);
                     $bulkPermissionParam = $this->acl->getPermissionParams('post_' . $listing_type_id, $contract->getID(), 'contract');
                     $imported_data = $import_file->getData();
                     $countData = 0;
                     foreach ($imported_data as $val) {
                         if ($val) {
                             $countData++;
                         }
                     }
                     if (empty($bulkPermissionParam) || $bulkPermissionParam - $contract->getPostingsNumber() - ($countData - 1) >= 0) {
                         $listing = new SJB_Listing(array(), $listing_type_sid);
                         $count = 0;
                         $listingSIDs = array();
                         foreach ($imported_data as $key => $importedColumn) {
                             if ($key == 1) {
                                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                                 continue;
                             }
                             if (!$importedColumn) {
                                 continue;
                             }
                             $count++;
                             $listing_info = $imported_data_processor->getData('ignore', $importedColumn);
                             $doc = new DOMDocument();
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'complex' && !empty($listing_info[$property->id])) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $doc->loadXML($listing_info[$property->id]);
                                     $results = $doc->getElementsByTagName($property->id . 's');
                                     $listing_info[$property->id] = array();
                                     foreach ($results as $complexparent) {
                                         $i = 0;
                                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                                             $resultXML = simplexml_import_dom($result);
                                             foreach ($childFields as $childField) {
                                                 if (isset($resultXML->{$childField}['id'])) {
                                                     $listing_info[$property->id][$childField['id']][$i] = (string) $resultXML->{$childField}['id'];
                                                 }
                                             }
                                             $i++;
                                         }
                                     }
                                 } 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, $listing_info)) {
                                             switch ($locationField) {
                                                 case $property->id . '.Country':
                                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 case $property->id . '.State':
                                                     $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 default:
                                                     $value = $listing_info[$locationField];
                                                     break;
                                             }
                                             $listing_info[$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, $listing_info) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                                 switch ($locationField) {
                                                     case 'Country':
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     case 'State':
                                                         $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     default:
                                                         $value = $listing_info[$locationField];
                                                         break;
                                                 }
                                                 $listing_info[$property->id][$locationField] = $value;
                                             }
                                         }
                                     }
                                 }
                             }
                             $field_info = null;
                             $listing = new SJB_Listing($listing_info, $listing_type_sid);
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'tree' && $property->value !== '') {
                                     $treeValues = explode(',', $property->value);
                                     $treeSIDs = array();
                                     foreach ($treeValues as $treeValue) {
                                         $info = SJB_ListingFieldTreeManager::getItemInfoByCaption($property->sid, trim($treeValue));
                                         $treeSIDs[] = $info['sid'];
                                     }
                                     $listing->setPropertyValue($property->id, implode(',', $treeSIDs));
                                     $listing->details->properties[$property->id]->type->property_info['value'] = implode(',', $treeSIDs);
                                 } elseif ($property->getType() == 'monetary') {
                                     $currency = SJB_CurrencyManager::getDefaultCurrency();
                                     $listing->details->properties[$property->id]->type->property_info['value']['add_parameter'] = $currency['sid'];
                                 } elseif ($property->id == 'ApplicationSettings' && !empty($listing_info['ApplicationSettings'])) {
                                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 1);
                                     } elseif (preg_match("^(https?:\\/\\/)^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 2);
                                     } else {
                                         $listing_info['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                                     }
                                     $listing->details->properties[$property->id]->type->property_info['value'] = $listing_info['ApplicationSettings'];
                                 } elseif ($property->getType() == 'complex' && is_array($property->value)) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $complexChildValues = $property->value;
                                     foreach ($childFields as $childField) {
                                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                                             $field_info = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                                             if (isset($listing_info[$property->id][$field_info['id']]) && file_exists($listing_info[$property->id][$field_info['id']])) {
                                                 SJB_UploadFileManager::fileImport($listing_info, $field_info, $property->id);
                                             }
                                         }
                                     }
                                 }
                                 // The import of files at import of listings
                                 if (in_array($property->getType(), array('file', 'logo', 'picture', 'video')) && $property->value !== '') {
                                     $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                                     if (isset($listing_info[$field_info['id']]) && file_exists($listing_info[$field_info['id']])) {
                                         SJB_UploadFileManager::fileImport($listing_info, $field_info);
                                     }
                                 }
                             }
                             $listing->deleteProperty('featured');
                             $listing->deleteProperty('priority');
                             $listing->deleteProperty('status');
                             $listing->deleteProperty('reject_reason');
                             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contract->getID(), 'is_system' => true));
                             $extraInfo = $contract->extra_info;
                             $listing->setProductInfo($extraInfo);
                             $listing->setPropertyValue('access_type', 'everyone');
                             $listing->setUserSID($current_user->sid);
                             if ($current_user->isSubuser()) {
                                 $subuserInfo = $current_user->getSubuserInfo();
                                 $listing->addSubuserProperty($subuserInfo['sid']);
                             }
                             SJB_ListingManager::saveListing($listing);
                             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                             $contract->incrementPostingsNumber();
                             SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                             if (!empty($extraInfo['featured'])) {
                                 SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                             }
                             if (!empty($extraInfo['priority'])) {
                                 SJB_ListingManager::makePriorityBySID($listing->getSID());
                             }
                             $this->FillGallery($listing, $listing_info);
                             $listingSIDs[] = $listing->getSID();
                         }
                         SJB_ListingManager::activateListingBySID($listingSIDs);
                         $tp->assign('listingsNum', count($listingSIDs));
                         $tp->display('job_import_complete.tpl');
                     } else {
                         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                         $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED';
                         $tp->assign('listing_type_id', $listing_type_id);
                         $tp->assign('error', $error);
                         $tp->display('job_import.tpl');
                     }
                 } else {
                     $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                     $tp->assign('warning', $warning);
                     $tp->assign('contract_id', $contractID);
                     $tp->assign('listing_type_id', $listing_type_id);
                     $tp->display('job_import.tpl');
                 }
             }
         } else {
             $error = $acl->getPermissionMessage('bulk_job_import');
             if (empty($error)) {
                 $error = 'This action is not allowed within your current product';
             }
             $tp->assign('error', $error);
             $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
             $tp->assign('listing_type_id', $listing_type_id);
             $tp->display('job_import.tpl');
         }
     } else {
         if ($error == 'NO_CONTRACT') {
             if ($_GET) {
                 $getParam = '?';
                 foreach ($_GET as $key => $val) {
                     $getParam .= $key . '=' . $val . '&';
                 }
                 $getParam = substr($getParam, 0, -1);
             }
             $page = base64_encode(SJB_System::getURI() . $getParam);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page);
         }
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('job_import.tpl');
     }
 }
Пример #21
0
 public static function deleteEmptyApplication($applicationId)
 {
     $fileID = SJB_DB::queryValue("SELECT `file_id` FROM `applications` WHERE `id` = ?s", $applicationId);
     $res = SJB_DB::query("DELETE FROM `applications` WHERE `show_js` = 0 AND `show_emp` = 0 AND id = ?s", $applicationId);
     if ($res === true && !empty($fileID) && isset($fileID)) {
         SJB_UploadFileManager::deleteUploadedFileByID($fileID);
     }
 }
Пример #22
0
 function getSQLValue()
 {
     $properties = $this->complex->getProperties();
     foreach ($properties as $field) {
         if ($field->type->getType() === 'date') {
             $field->type->setConvertToDBDate(true);
             $i18n = SJB_I18N::getInstance();
             $values = $field->value;
             if (empty($values) || !is_array($values)) {
                 continue;
             }
             foreach ($values as $key => $value) {
                 $this->property_info['value'][$field->id][$key] = $i18n->getInput('date', $value);
             }
         }
         if ($field->type->getType() === 'file') {
             $file_id = $this->property_info['id'] . "_" . $this->object_sid;
             $upload_manager = new SJB_UploadFileManager();
             $upload_manager->setFileGroup("files");
             $upload_manager->setUploadedFileID($file_id);
             $uploadFilesResults = $upload_manager->uploadFiles($this->property_info['id'], $field->id);
             $oldVals = isset($this->property_info['value'][$field->id]) && is_array($this->property_info['value'][$field->id]) ? $this->property_info['value'][$field->id] : array();
             $this->property_info['value'][$field->id] = array();
             foreach ($uploadFilesResults as $key => $value) {
                 if (empty($value) && !empty($oldVals[$key])) {
                     $this->property_info['value'][$field->id][$key] = $oldVals[$key];
                 } else {
                     $this->property_info['value'][$field->id][$key] = $value;
                 }
             }
             $field->setValue($this->property_info['value'][$field->id]);
         }
     }
     return serialize($this->property_info['value']);
 }
Пример #23
0
 function getKeywordValue()
 {
     $keywords = '';
     if (!self::isEmpty() && SJB_Settings::getSettingByName('get_keyword_from_file')) {
         $fileId = $this->getComplexParent() . ":" . $this->property_info['id'] . ":" . $this->complexEnum . "_" . $this->object_sid;
         $fileInfo = SJB_UploadFileManager::getUploadedFileInfo($fileId);
         if ($fileInfo) {
             $uploadManager = new SJB_UploadFileManager();
             $uploadManager->setFileGroup("files");
             $fileUrl = $uploadManager->getUploadedFileLink($fileId, $fileInfo, true);
             $fileExtension = substr(strrchr($fileInfo['saved_file_name'], "."), 1);
             if (file_exists($fileUrl)) {
                 switch ($fileExtension) {
                     case 'doc':
                         $doc = new doc();
                         $doc->read($fileUrl);
                         $keywords = preg_replace('/[\\n\\r]/', '', strip_tags($doc->parse()));
                         break;
                     case 'docx':
                         $keywords = SJB_HelperFunctions::docx2text($fileUrl);
                         $keywords = preg_replace('/[\\n\\r]/', '', strip_tags(html_entity_decode($keywords)));
                         break;
                     case 'xls':
                     case 'xlsx':
                         $fileInfo['tmp_name'] = $fileUrl;
                         $fileObj = new SJB_ImportFileXLS($fileInfo);
                         $fileObj->parse();
                         $data = $fileObj->getData();
                         $keywords = '';
                         foreach ($data as $val) {
                             $val = array_unique($val);
                             $val = array_diff($val, array(''));
                             $keywords .= implode(' ', $val);
                         }
                         $keywords = preg_replace("/[[:punct:]^\\s]/ui", " ", $keywords);
                         break;
                     case 'pdf':
                         $outFilename = str_replace("." . $fileExtension, '.txt', $fileUrl);
                         exec("pdftotext {$fileUrl} {$outFilename}");
                         if (file_exists($outFilename)) {
                             $keywords = file_get_contents($outFilename);
                             $keywords = preg_replace('/[\\n\\r]/', '', strip_tags(html_entity_decode($keywords)));
                             unlink($outFilename);
                         }
                         break;
                     case 'txt':
                         $keywords = file_get_contents($fileUrl);
                         $keywords = preg_replace('/[\\n\\r]/', '', strip_tags(html_entity_decode($keywords)));
                         break;
                 }
             }
         }
     }
     return $keywords;
 }
Пример #24
0
 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");
 }
Пример #25
0
 /**
  * Get articles by search text
  *
  * @param string $text
  * @return array
  */
 public static function searchArticles($text, $lang = 'en', $active = false)
 {
     $text = SJB_DB::quote($text);
     $activeQuery = '';
     if ($active) {
         $activeQuery = '`active` = 1';
     }
     $result = SJB_DB::query("SELECT * FROM `news` WHERE (`brief` LIKE '%{$text}%' OR `text` LIKE '%{$text}%' OR `title` LIKE '%{$text}%') AND `language` = ?s AND {$activeQuery} ORDER BY `date` ASC", $lang);
     if (empty($result)) {
         return array();
     }
     $upload_manager = new SJB_UploadFileManager();
     foreach ($result as $key => $value) {
         $result[$key]['image_link'] = '';
         if (!empty($value['image'])) {
             $result[$key]['image_link'] = $upload_manager->getUploadedFileLink($value['image']);
         }
     }
     return $result;
 }
Пример #26
0
 public function execute()
 {
     $formToken = SJB_Request::getVar('form_token');
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('form_token', $formToken);
     $post_max_size_orig = ini_get('post_max_size');
     $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
     // get post_max_size in bytes
     $val = trim($post_max_size_orig);
     $tmp = substr($val, strlen($val) - 1);
     $tmp = strtolower($tmp);
     switch ($tmp) {
         case 'g':
             $val *= 1024;
             break;
         case 'm':
             $val *= 1024;
             break;
         case 'k':
             $val *= 1024;
             break;
     }
     $post_max_size = $val;
     $errors = array();
     if (SJB_Request::getVar('from-preview', false, 'POST') && !SJB_Request::getVar('action_add', false, 'POST')) {
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $previewListingId = SJB_Session::getValue('preview_listing_sid');
         if ($previewListingId && SJB_ListingManager::isListingExists($previewListingId)) {
             $listingId = $previewListingId;
         }
     } else {
         $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     }
     $template = SJB_Request::getVar('edit_template', 'edit_listing.tpl');
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         SJB_UploadFileManager::openFile($filename, $listingId);
         // if file not found - set error here
         $errors['NO_SUCH_FILE'] = true;
     }
     if (empty($_POST) && $server_content_length > $post_max_size) {
         $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $tp->assign('post_max_size', $post_max_size_orig);
     }
     $current_user = SJB_UserManager::getCurrentUser();
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
     // for listing preview
     $formSubmittedFromPreview = false;
     if (empty($listingInfo)) {
         $listingId = SJB_Session::getValue('preview_listing_sid');
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
         if (!empty($listingInfo)) {
             // if on preview page 'POST' button was pressed
             $formSubmittedFromPreview = SJB_Request::getVar('action_add', false, 'POST') && SJB_Request::getVar('from-preview', false, 'POST');
             if ($formSubmittedFromPreview) {
                 $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
                 $properties = $listing->getProperties();
                 foreach ($properties as $fieldID => $property) {
                     switch ($property->getType()) {
                         case 'date':
                             if (!empty($listingInfo[$fieldID])) {
                                 $listingInfo[$fieldID] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID]);
                             }
                             break;
                         case 'complex':
                             $complex = $property->type->complex;
                             $complexProperties = $complex->getProperties();
                             foreach ($complexProperties as $complexfieldID => $complexProperty) {
                                 if ($complexProperty->getType() == 'date') {
                                     $values = $complexProperty->getValue();
                                     foreach ($values as $index => $value) {
                                         if (!empty($listingInfo[$fieldID][$complexfieldID][$index])) {
                                             $listingInfo[$fieldID][$complexfieldID][$index] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID][$complexfieldID][$index]);
                                         }
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
         } else {
             $listingId = null;
             SJB_Session::unsetValue('preview_listing_sid');
         }
     }
     // if preview button was pressed
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (SJB_UserManager::isUserLoggedIn()) {
         if ($listingInfo['user_sid'] != $current_user->getID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listingId;
         } elseif (!is_null($listingInfo)) {
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingInfo['listing_type_sid']);
             $form_is_submitted = SJB_Request::getVar('action', '') == 'save_info' || SJB_Request::getVar('action', '') == 'add' || $isPreviewListingRequested || $formSubmittedFromPreview;
             if (!$form_is_submitted && !SJB_Request::getVar('from-preview', false, 'POST')) {
                 SJB_Session::unsetValue('previewListingId');
                 SJB_Session::unsetValue('preview_listing_sid_or');
             }
             // fill listing from an array of social data if allowed
             $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingInfo['listing_type_sid']);
             $listingTypeID = $listing_type_info['id'];
             $aAutoFillData = array('formSubmitted' => $form_is_submitted, 'listingTypeID' => $listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
             $listing->deleteProperty('ListingLogo');
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('status');
             $list_emp_ids = SJB_Request::getVar('list_emp_ids');
             $listing->setSID($listingId);
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $value = SJB_Request::getVar('screening_questionnaire');
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             //--->CLT-2637
             $properties = $listing->getProperties();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page = array_merge(SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']), $listing_fields_by_page);
             }
             foreach ($properties as $property) {
                 if (!in_array($property->getID(), array_keys($listing_fields_by_page))) {
                     $listing->deleteProperty($property->getID());
                 }
             }
             //--->CLT-2637
             // if user is not registered using linkedin , delete linkedin sync property, also if sync is turned off in admin part
             $aAutoFillData = array('oListing' => &$listing, 'userSID' => $current_user->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
             SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             $listing_edit_form = new SJB_Form($listing);
             $listing_edit_form->registerTags($tp);
             $extraInfo = $listingInfo['product_info'];
             if ($extraInfo) {
                 $extraInfo = unserialize($extraInfo);
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $listingSidForPictures = SJB_Session::getValue('preview_listing_sid_or') ? SJB_Session::getValue('preview_listing_sid_or') : $listingId;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listingSidForPictures', $listingSidForPictures);
             }
             if ($form_is_submitted) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
             }
             $field_errors = array();
             if ($form_is_submitted && ($formSubmittedFromPreview || $listing_edit_form->isDataValid($field_errors))) {
                 $or_listing_id = SJB_Session::getValue('preview_listing_sid_or');
                 /* preview listing */
                 if ($isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') != $listing->getSID()) {
                     SJB_Session::setValue('preview_listing_sid_or', $listing->getSID());
                     $listing->setSID(null);
                 } elseif (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listing->getSID() && $or_listing_id && $or_listing_id != $listingId) {
                     $listing->setSID($or_listing_id);
                 }
                 if ($isPreviewListingRequested) {
                     $listing->addProperty(array('id' => 'preview', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 } else {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 if ($isPreviewListingRequested) {
                     $listing->product_info = $extraInfo;
                     if (SJB_Session::getValue('previewListingId')) {
                         $listing->setSID(SJB_Session::getValue('previewListingId'));
                     }
                 } else {
                     SJB_BrowseDBManager::deleteListings($listing->getID());
                 }
                 $listingSidsForCopy = array('filesFrom' => $listingId, 'picturesFrom' => $isPreviewListingRequested && (!$or_listing_id || $or_listing_id === $listingId) ? $listingId : null);
                 SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                 if (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listingId && $or_listing_id && $or_listing_id != $listingId) {
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_ListingManager::deleteListingBySID($listingId);
                 }
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listing->getSID());
                 if ($listingInfo['active']) {
                     SJB_ListingManager::activateListingKeywordsBySID($listing->getSID());
                     SJB_BrowseDBManager::addListings($listing->getID());
                 }
                 // >>> SJB-1197
                 // SET VALUES FROM TEMPORARY SESSION STORAGE
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                 if (is_array($tempFieldsData)) {
                     foreach ($tempFieldsData as $fieldId => $fieldData) {
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldData['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                     }
                     SJB_ListingManager::saveListing($listing);
                     // recreate form object for saved listing
                     // it fix display of complex file fields
                     $listing = SJB_ListingManager::getObjectBySID($listing->getSID());
                     $listing->deleteProperty('featured');
                     $listing->deleteProperty('priority');
                     $listing->deleteProperty('reject_reason');
                     $listing->deleteProperty('status');
                     $listing_edit_form = new SJB_Form($listing);
                     $listing_edit_form->registerTags($tp);
                 }
                 // <<< SJB-1197
                 if ($isPreviewListingRequested) {
                     SJB_Session::setValue('previewListingId', $listing->getSID());
                 }
                 /* preview listing */
                 if ($isPreviewListingRequested) {
                     $listing->setUserSID($current_user->getSID());
                     SJB_Session::setValue('preview_listing_sid', $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     /* normal */
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingEdited', $listingSid);
                     $tp->assign('display_preview', 1);
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-' . strtolower($listingTypeID) . '-details/' . $listing->getSID() . '/');
                 }
             }
             $listing->deleteProperty('access_list');
             $tp->assign('form_is_submitted', $form_is_submitted);
             $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $form_fields = $listing_edit_form->getFormFieldsInfo();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                 foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                     if (!$listing->propertyIsSet($field)) {
                         unset($listing_fields_by_page[$page['page_name']][$field]);
                     }
                 }
             }
             // delete sync fields from posting pages that are not in array $form_fields
             $aAutoFillData = array('listing_fields_by_page' => &$listing_fields_by_page, 'pages' => &$pages, 'form_fields' => $form_fields);
             SJB_Event::dispatch('SocialSynchronizationFieldsOnPostingPages', $aAutoFillData);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             if (!isset($listing_structure['access_type'])) {
                 $listing_structure['access_type'] = 'everyone';
             }
             $listing_access_list = SJB_ListingManager::getListingAccessList($listingId, $listing->getPropertyValue('access_type'));
             $tp->assign('contract_id', $listingInfo['contract_id']);
             $tp->assign('extraInfo', $extraInfo);
             $tp->assign('listing', $listing_structure);
             $tp->assign('pages', $listing_fields_by_page);
             $tp->assign('countPages', count($listing_fields_by_page));
             $tp->assign('field_errors', $field_errors);
             $tp->assign('listing_access_list', $listing_access_list);
             $tp->assign('listingTypeID', $listingTypeID);
             $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
             // only for Resume listing types
             $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $current_user->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
         }
     } else {
         $errors['NOT_LOGGED_IN'] = 1;
     }
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
Пример #27
0
 private static function changeFileProperties(&$exportProperties, &$exportData, $fileType)
 {
     $filePropertiesInfo = SJB_UserProfileFieldManager::getFieldsInfoByType($fileType);
     foreach ($filePropertiesInfo as $propertyInfo) {
         if (isset($exportProperties[$propertyInfo['id']])) {
             foreach ($exportData as $userSid => $property) {
                 $fileId = $exportData[$userSid][$propertyInfo['id']];
                 $fileData =& $exportData[$userSid][$propertyInfo['id']];
                 $fileData = null;
                 $fileInfo = empty($fileId) ? null : ($fileInfo = SJB_UploadFileManager::getUploadedFileInfo($fileId));
                 if (!empty($fileInfo)) {
                     $fileSavedName = $fileInfo['saved_file_name'];
                     $fileGroup = $fileInfo['file_group'];
                     $uploadFilesDirectory = SJB_System::getSystemSettings("UPLOAD_FILES_DIRECTORY") . '/' . $fileGroup . '/';
                     $exportFilesDirectory = SJB_System::getSystemSettings("EXPORT_FILES_DIRECTORY") . '/' . $fileGroup . '/';
                     $fileNameParsed = explode('.', $fileSavedName);
                     $fileExtension = array_pop($fileNameParsed);
                     $fileName = implode('.', $fileNameParsed);
                     @copy($uploadFilesDirectory . $fileSavedName, $exportFilesDirectory . $fileSavedName);
                     if ($propertyInfo['id'] == 'Logo') {
                         @copy($uploadFilesDirectory . $fileName . '_thumb.' . $fileExtension, $exportFilesDirectory . $fileName . '_thumb.' . $fileExtension);
                     } else {
                         if ($propertyInfo['id'] == 'video') {
                             @copy($uploadFilesDirectory . $fileName . '.png', $exportFilesDirectory . $fileName . '.png');
                         }
                     }
                     $fileData = serialize(array('name' => $fileName, 'extension' => $fileExtension, 'mimeType' => $fileInfo['mime_type']));
                 }
             }
         }
     }
 }
Пример #28
0
 /**
  * retrieve email SJB_Email with defined options:
  * - from name
  * - from email
  * - attached file
  * - cc
  * ATTENTION: reserved index for $data:
  * - emailData
  *
  * @static
  * @param string $email
  * @param int $emailTplSID
  * @param array $data  (message, subject, signature) are reserved indexes
  * @return SJB_Email
  */
 public static function getEmail($email, $emailTplSID, $data = array())
 {
     if (self::EMAIL_DO_NOT_SEND === $emailTplSID) {
         return new SJB_EmailDoNotSend();
     }
     $templateData = self::prepareEmailData($emailTplSID);
     if (!$templateData) {
         return new SJB_EmailNone($email);
     }
     $message = SJB_Array::get($templateData, 'text');
     $subject = SJB_Array::get($templateData, 'subject');
     $signature = SJB_Settings::getSettingByName('system_email_signature');
     $cc = SJB_Array::get($templateData, 'cc');
     $fromEmail = SJB_Array::get($templateData, 'from_email');
     $fromName = SJB_Array::get($templateData, 'from_name');
     $file = SJB_Array::get($templateData, 'file');
     self::replaceSmartyTags($fromName);
     self::replaceSmartyTags($message);
     self::replaceSmartyTags($subject);
     self::replaceSmartyTags($signature);
     $data[SJB_EmailInternal::EMAIL_DATA_LABEL] = array('fromName' => $fromName, 'message' => $message, 'subject' => $subject, 'signature' => $signature);
     $email = new SJB_Email($email, '../miscellaneous/email_theme.tpl', $data);
     if ($cc) {
         $email->addCC($cc);
     }
     if ($fromEmail) {
         $email->setFromEmail($fromEmail);
     }
     // file attachment
     if (SJB_Array::get($file, 'file_id')) {
         $file_link = SJB_UploadFileManager::getUploadedFileLink(SJB_Array::get($file, 'file_id'), false, true);
         if ($file_link) {
             $email->setFile(SJB_BASE_DIR . $file_link);
         }
     }
     return $email;
 }
Пример #29
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $theme = SJB_Settings::getValue('TEMPLATE_USER_THEME', 'default');
     $tp->assign('theme', $theme);
     $errors = array();
     $message = '';
     $alternativeText = SJB_Request::getVar('logoAlternativeText', '');
     switch (SJB_Request::getVar('action', '')) {
         case 'save':
             if (isset($_FILES['logo']['error'])) {
                 if ($_FILES['logo']['error'] == UPLOAD_ERR_OK) {
                     if (SJB_System::getSystemSettings('isDemo')) {
                         $errors[] = 'NOT_ALLOWED_IN_DEMO';
                     } else {
                         $themePath = SJB_TemplatePathManager::getAbsoluteThemePath($theme);
                         if (move_uploaded_file($_FILES['logo']['tmp_name'], "{$themePath}main/images/logo.png")) {
                             $message = 'Logo has been uploaded successfully';
                         }
                     }
                 } else {
                     switch ($_FILES['logo']['error']) {
                         case UPLOAD_ERR_INI_SIZE:
                             $errors[] = 'File size exceeds system limit. Please check the file size limits on your hosting or upload another file.';
                             break;
                         case UPLOAD_ERR_FORM_SIZE:
                             $errors[] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                             break;
                         case UPLOAD_ERR_PARTIAL:
                             $errors[] = 'The uploaded file was only partially uploaded';
                             break;
                         case UPLOAD_ERR_NO_FILE:
                             // Разрешим изменять текст без аплоада лого
                             break;
                         case UPLOAD_ERR_NO_TMP_DIR:
                             $errors[] = 'Missing a temporary folder';
                             break;
                         case UPLOAD_ERR_CANT_WRITE:
                             $errors[] = 'Failed to write file to disk';
                             break;
                         default:
                             $errors[] = 'File upload error';
                     }
                     if ($alternativeText == SJB_Settings::getSettingByName('logoAlternativeText')) {
                         $errors[] = 'Upload a logo or enter alternative text';
                     }
                 }
             }
             if (SJB_Settings::getSettingByName('logoAlternativeText') === false) {
                 SJB_Settings::addSetting('logoAlternativeText', $alternativeText);
             } else {
                 if ($alternativeText != SJB_Settings::getSettingByName('logoAlternativeText')) {
                     SJB_Settings::updateSetting('logoAlternativeText', $alternativeText);
                     if (!$message) {
                         $message = 'Alternative text has been updated successfully';
                     } else {
                         $message = 'Logo and Alternative text has been uploaded successfully';
                     }
                 }
             }
             break;
     }
     $tp->assign('errors', $errors);
     $tp->assign('message', $message);
     $tp->assign('uploadMaxFilesize', SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->assign('logoAlternativeText', SJB_Request::getVar('logoAlternativeText', SJB_Settings::getSettingByName('logoAlternativeText')));
     $tp->display('upload_logo.tpl');
 }
Пример #30
0
 public static function deleteUserById($id)
 {
     $user = SJB_UserManager::getObjectBySID($id);
     if (empty($user)) {
         SJB_UserDBManager::deleteEmptyUsers();
         return true;
     }
     SJB_Event::dispatch('onBeforeUserDelete', $user);
     $listings = SJB_ListingDBManager::getListingsSIDByUserSID($id);
     SJB_ListingManager::deleteListingBySID($listings);
     $subusers = self::getSubusers($id);
     foreach ($subusers as $subuser) {
         self::deleteUserById($subuser['sid']);
     }
     // delete user logo file
     $pictProp = $user->getProperty('Logo');
     if ($pictProp) {
         SJB_UploadFileManager::deleteUploadedFileByID($pictProp->value);
     }
     $videoProp = $user->getProperty('video');
     if ($videoProp) {
         SJB_UploadFileManager::deleteUploadedFileByID($videoProp->value);
     }
     // delete social info
     $socialReference = SJB_SocialPlugin::getProfileSocialID($user->getSID());
     if ($socialReference) {
         SJB_SocialPlugin::deleteProfileSocialInfoByReference($socialReference);
     }
     $result = SJB_UserDBManager::deleteUserById($id) && SJB_ContractManager::deleteAllContractsByUserSID($id) && SJB_Rating::deleteRatingByUserSID($id);
     SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_USERS));
     return $result && SJB_SavedSearches::deleteUserSearchesFromDB($id);
 }