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'); }
function isValid() { $this->fieldID = $this->property_info['id']; if (!isset($_FILES[$this->fieldID]['name']) || $_FILES[$this->fieldID]['name'] == '') { return true; } $upload_manager = new SJB_UploadFileManager(); if (!empty($this->property_info['max_file_size'])) { $upload_manager->setMaxFileSize($this->property_info['max_file_size']); } else { $upload_manager->setMaxFileSize(SJB_UploadFileManager::getIniUploadMaxFilesize()); } if ($this->getComplexParent()) { $upload_manager->isValidUploadedFile($this->getComplexParent(), $this->property_info['id']); } else { if ($upload_manager->isValidUploadedFile($this->property_info['id'])) { return true; } } return $upload_manager->getError(); }
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'); } }
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'); }
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"); }
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'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $extUserID = SJB_Request::getVar('extUserID', null); $passedParametersViaUri = SJB_UrlParamProvider::getParams(); $userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false; if (!$userGroupID) { $userGroupsInfo = SJB_UserGroupManager::getAllUserGroupsInfo(); $tp->assign('user_groups_info', $userGroupsInfo); $tp->display('add_user_choose_user_group.tpl'); } else { $userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID); $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID); $user = SJB_ObjectMother::createUser($_REQUEST, $userGroupSID); $user->deleteProperty('active'); $user->addExtUserIDProperty($extUserID); $registration_form = SJB_ObjectMother::createForm($user); $registration_form->registerTags($tp); $form_submitted = SJB_Request::getVar('action', '') == 'add'; $errors = array(); if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID) && $form_submitted) { $email = $user->getPropertyValue('email'); if (is_array($email)) { $email = $email['original']; } $user->setPropertyValue('username', $email); } if ($form_submitted && $registration_form->isDataValid($errors)) { SJB_UserManager::saveUser($user); // >>> SJB-1197 // needs to check session for ajax-uploaded files, and set it to user profile $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $formToken = SJB_Request::getVar('form_token'); if (!empty($formToken)) { $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken); if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) { // prepare user profile fields array $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo(); $userProfileFields = array(); foreach ($userProfileFieldsInfo as $field) { $userProfileFields[$field['id']] = $field; } // look for temporary values foreach ($tmpUploadedFields as $fieldId => $fieldInfo) { // check field ID for valid ID in user profile fields if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) { continue; } $fieldType = $userProfileFields[$fieldId]['type']; $profilePropertyId = $fieldId . '_' . $user->getSID(); switch (strtolower($fieldType)) { case 'video': case 'file': // change temporary file ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; case 'logo': // change temporary file ID and thumb ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb'); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; default: break; } $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}"); } // and save user with new fields data SJB_UserManager::saveUser($user); // clean temporary storage $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}"); // CLEAR TEMPORARY SESSION STORAGE SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); } } // <<< SJB-1197 SJB_UserManager::activateUserByUserName($user->getUserName()); $defaultProduct = SJB_UserGroupManager::getDefaultProduct($userGroupSID); $availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userGroupSID); if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) { $contract = new SJB_Contract(array('product_sid' => $defaultProduct)); $contract->setUserSID($user->getSID()); $contract->saveInDB(); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8')); } else { if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID)) { $user->deleteProperty('username'); } $registration_form = SJB_ObjectMother::createForm($user); $registration_form->registerTags($tp); $tp->assign("errors", $errors); $tp->assign("user_group", $userGroupInfo); $tp->assign('userTree', true); $tp->assign("form_fields", $registration_form->getFormFieldsInfo()); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display("add_user.tpl"); } } }
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"); } }
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'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $parent_name = null; $user_sid = SJB_Request::getVar('user_sid', false); if (!is_null($user_sid)) { $user_info = SJB_UserManager::getUserInfoBySID($user_sid); $user_info = array_merge($user_info, $_REQUEST); $form_submitted = SJB_Request::getVar('action_name'); $user = new SJB_User($user_info, $user_info['user_group_sid']); if (!empty($user_info['parent_sid'])) { $props = $user->getProperties(); $allowedProperties = array('username', 'email', 'password'); foreach ($props as $prop) { if (!in_array($prop->getID(), $allowedProperties)) { $user->deleteProperty($prop->getID()); } } $parent_name = SJB_UserManager::getUserNameByUserSID($user_info['parent_sid']); } $user->setSID($user_info['sid']); $user->getProperty('email')->type->disableEmailConfirmation(); $user->deleteProperty("active"); $user->makePropertyNotRequired("password"); if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) { if ($form_submitted) { $email = $user->getPropertyValue('email'); if (is_array($email)) { $email = $email['original']; } $user->setPropertyValue('username', $email); } } $user->addExtUserIDProperty($user_info['extUserID']); $edit_user_form = new SJB_Form($user); $errors = array(); if ($form_submitted && $edit_user_form->isDataValid($errors)) { $password_value = $user->getPropertyValue('password'); $properties = null; if (empty($password_value['original'])) { $properties = $user->getProperties(); $user->deleteProperty('password'); } SJB_UserManager::saveUser($user); // >>> SJB-1197 // needs to check session for ajax-uploaded files, and set it to user profile $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $formToken = SJB_Request::getVar('form_token'); if (!empty($formToken)) { $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken); if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) { // prepare user profile fields array $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo(); $userProfileFields = array(); foreach ($userProfileFieldsInfo as $field) { $userProfileFields[$field['id']] = $field; } // look for temporary values foreach ($tmpUploadedFields as $fieldId => $fieldInfo) { // check field ID for valid ID in user profile fields if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) { continue; } $fieldType = $userProfileFields[$fieldId]['type']; $profilePropertyId = $fieldId . '_' . $user->getSID(); switch (strtolower($fieldType)) { case 'video': case 'file': // change temporary file ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; case 'logo': // change temporary file ID and thumb ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb'); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; default: break; } $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}"); } // and save user with new fields data SJB_UserManager::saveUser($user); SJB_Authorization::updateCurrentUserSession(); // clean temporary storage $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}"); // CLEAR TEMPORARY SESSION STORAGE SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); } } // <<< SJB-1197 if (SJB_Request::isAjax()) { echo "<p class=\"green\">User Saved</p>"; exit; } if ($form_submitted == 'save_info') { $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8')); } if (!empty($properties)) { $user->details->properties = $properties; } } if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) { $user->deleteProperty("username"); } $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo(); $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($user_info['user_group_sid']); $allowedListingTypes = array(); foreach ($products as $product) { if (!empty($product['listing_type_sid']) && empty($allowedListingTypes[$product['listing_type_sid']])) { foreach ($listingTypes as $listingType) { if ($product['listing_type_sid'] == $listingType['sid']) { $allowedListingTypes[$product['listing_type_sid']] = $listingType; } } } } $edit_user_form = SJB_ObjectMother::createForm($user); $edit_user_form->registerTags($tp); $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']); if (SJB_UserManager::checkBan($errors, $user_info['ip'])) { $user_info['ip_is_banned'] = 1; } $tp->assign("form_fields", $edit_user_form->getFormFieldsInfo()); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign("errors", $errors); $tp->assign("listingTypes", $allowedListingTypes); $tp->assign("user_info", $user_info); $tp->assign("user_group_info", $userGroupInfo); $tp->assign('userTree', true); $tp->assign("parent_name", $parent_name); $tp->assign("restore", preg_match('/manage-(jobseekers)|(employers)|([a-z0-9\\_]-users)/', SJB_Request::getVar('HTTP_REFERER', '', 'SERVER'))); SJB_System::setGlobalTemplateVariable('wikiExtraParam', $userGroupInfo['id']); $tp->display("edit_user.tpl"); } }
private function validationManager($fieldInfo, $tp, $uploadedFieldId, $complex = null) { // will use tmp_uploads_storage in $_SESSION to storage file info $uniqueStorageId = SJB_Session::getSessionId(); $this->fileUniqueId = $uniqueStorageId . "_" . $uploadedFieldId . "_tmp"; // delete uniquie value SJB_UploadFileManager::deleteUploadedFileByID($this->fileUniqueId); $this->property = new SJB_ObjectProperty($fieldInfo); $this->property->setValue(''); if ($complex) { $this->property->setComplexParent($complex['parentField']); $this->property->setComplexEnum($complex['complexStep']); $fileNamePath = "{$complex['parentField']}/name/{$complex['subFieldId']}/{$complex['complexStep']}"; $fileSizePath = "{$complex['parentField']}/size/{$complex['subFieldId']}/{$complex['complexStep']}"; } else { $fileNamePath = $uploadedFieldId . '/name'; $fileSizePath = $uploadedFieldId . '/size'; } $fileName = SJB_Array::getPath($_FILES, $fileNamePath); if (!$fileName) { $validation = 'UPLOAD_ERR_INI_SIZE'; } else { $uploadedFilesize = SJB_Array::getPath($_FILES, $fileSizePath); $filesizeInfo = SJB_HelperFunctions::getFileSizeAndSizeToken($uploadedFilesize); $tp->assign(array('filesize' => $filesizeInfo['filesize'], 'size_token' => $filesizeInfo['size_token'])); $validation = $this->property->isValid(); } $this->propertyValue = $this->property->getValue(); if ($validation !== true) { $this->errors[$validation] = 1; if (!$complex) { $tp->assign(array('id' => $uploadedFieldId, 'value' => array('file_url' => SJB_Array::get($this->propertyValue, 'file_url'), 'file_name' => SJB_Array::get($this->propertyValue, 'file_name'), 'saved_file_name' => SJB_Array::get($this->propertyValue, 'saved_file_name'), 'file_id' => $this->fileUniqueId))); } } $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); return $validation === true; }
public function execute() { $errors = array(); $action = $this->getNewsAction(); $tp = SJB_System::getTemplateProcessor(); $categoryId = SJB_Request::getVar('category_sid'); if (empty($categoryId)) { $categoryId = SJB_Request::getVar('category_id'); } $category = SJB_NewsManager::getCategoryBySid($categoryId); $tp->assign('category_id', $categoryId); $tp->assign('category', $category); $allCategories = SJB_NewsManager::getCategories(); $tp->assign('all_categories', $allCategories); /****************** ACTIONS ***************************/ switch ($action) { case 'add': $article = new SJB_NewsArticle($_REQUEST); $articleAddForm = new SJB_Form($article); $articleAddForm->registerTags($tp); $formSubmitted = SJB_Request::getVar('form_submit', false); if ($formSubmitted && $articleAddForm->isDataValid($errors)) { SJB_NewsDBManager::saveNewsArticle($article); $articleSID = $article->getSID(); if ($articleSID) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsAdded=1"); exit; } else { $errors[] = 'UNABLE_TO_ADD_ARTICLE'; } } else { $article = new SJB_NewsArticle($_REQUEST); $article->deleteProperty('category_id'); // cause it set in form by get param $articleAddForm = new SJB_Form($article); $articleAddForm->registerTags($tp); $formFields = $articleAddForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields))); } $tp->assign('uploadMaxFilesize', SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('errors', $errors); $tp->display('add_article.tpl'); break; case 'edit': $itemSID = SJB_Request::getVar('article_sid', false); if (!$itemSID) { $errors[] = 'NO_ITEM_SID_PRESENT'; } else { $articleInfo = SJB_NewsManager::getNewsArticleInfoBySid($itemSID); $articleInfo = array_merge($articleInfo, $_REQUEST); $article = new SJB_NewsArticle($articleInfo); $articleEditForm = new SJB_Form($article); $articleEditForm->registerTags($tp); $formSubmitted = SJB_Request::getVar('form_submit', false); if ($formSubmitted && $articleEditForm->isDataValid($errors)) { $article->setSID($itemSID); // if need to change article category $moveToCategory = SJB_Request::getVar('article_category'); if (!empty($moveToCategory) && is_numeric($moveToCategory)) { $article->setPropertyValue('category_id', $moveToCategory); } SJB_NewsDBManager::saveNewsArticle($article); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsSaved=1"); } else { $formFields = $articleEditForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); $tp->assign('article_sid', $itemSID); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields))); } } $tp->assign('errors', $errors); $tp->assign('category', $category); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display('edit_article.tpl'); break; case 'delete': $itemSIDs = SJB_Request::getVar('news'); foreach ($itemSIDs as $sid => $item) { SJB_NewsManager::deleteArticleBySID($sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsDeleted=1"); break; case 'delete_image': $articleSid = SJB_Request::getVar('article_sid'); SJB_NewsManager::deleteArticleImageByArticleSid($articleSid); // get category $article = SJB_NewsManager::getNewsArticleBySid($articleSid); $categoryId = $article->getCategoryId(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-news/?action=edit&article_sid={$articleSid}&category_sid={$categoryId}"); break; case 'activate': $itemSIDs = SJB_Request::getVar('news'); foreach ($itemSIDs as $sid => $item) { SJB_NewsManager::activateItemBySID($sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}"); break; case 'deactivate': $itemSIDs = SJB_Request::getVar('news'); foreach ($itemSIDs as $sid => $item) { SJB_NewsManager::deactivateItemBySID($sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}"); break; case 'archive': $itemSIDs = SJB_Request::getVar('news'); foreach ($itemSIDs as $sid => $item) { SJB_NewsManager::moveArticleToArchiveBySid($sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}"); break; default: $page = SJB_Request::getVar('page', 1); $itemsPerPage = SJB_Request::getVar('items_per_page', 10); $totalNewsCount = SJB_NewsManager::getAllNewsCount($categoryId); $pages = ceil($totalNewsCount / $itemsPerPage); // get news for current page $news = SJB_NewsManager::getNewsByPage($page, $itemsPerPage); $tp->assign('news', $news); $tp->assign('pages', $pages); $tp->assign('items_per_page', $itemsPerPage); $tp->assign('current_page', $page); $tp->display('manage_news.tpl'); break; } }
public function execute() { $errors = array(); if (SJB_Request::isAjax()) { $response = null; $user_type = SJB_Request::getVar('user_type'); $user_name = SJB_Request::getVar('parser_user'); $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors); $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors)); die(json_encode($response)); } $tp = SJB_System::getTemplateProcessor(); $add_level = SJB_Request::getVar('add_level', 1); // check for errors if ($add_level == '3') { $selectUserType = SJB_Request::getVar('selectUserType'); $addNewUser = 0; if ($selectUserType == 'username') { $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : ''; $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($usr_name)) { $errors[] = 'Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } else { $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($user_sid_exists)) { $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } } } elseif ($selectUserType == 'group') { $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0; $usr_id = $userGroupSid; $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id); $addNewUser = 1; } if ($errors) { $add_level = 2; } } $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo(); $types = array(); foreach ($listings_type as $one) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); $selected_logo_options = null; switch ($add_level) { case '1': $template = 'add_step_one.tpl'; /* $types = array(); foreach ( $listings_type as $one ) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); */ $tp->display('add_step_one.tpl'); break; case '2': $template = 'add_step_two.tpl'; $original_xml = SJB_Request::getVar('xml'); $xml = $original_xml; $tree = ''; $listing_fields = array(); $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings'); $parsing_name = SJB_Request::getVar('parser_name'); $usr_name = SJB_Request::getVar('parser_user'); $pars_url = SJB_Request::getVar('parser_url'); $form_description = SJB_Request::getVar('form_description', '', 'POST'); $type_id = SJB_Request::getVar('type_id', '', 'POST'); $selectedLogoOption = SJB_Request::getVar('logo_options'); $selectedLogoField = SJB_Request::getVar('import_logo_field'); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $id = SJB_Request::getVar('id', 0, 'GET'); $selected = array(); $a_selected = array(); 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']; $selected_logo_options = unserialize($parser_from_id['logo_options']); $selectedLogoOption = $selected_logo_options['option']; $selectedLogoField = $selected_logo_options['field']; $selectedProduct = $parser_from_id['product_sid']; $xml = $parser_from_id['xml']; $xml = SJB_XmlImport::cleanXmlFromImport($xml); $map = unserialize($parser_from_id['maper']); $selected = array_values($map); $a_selected = array_keys($map); } else { $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']); } $sxml = new simplexml(); $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]); // replace '@' and ':' $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.'; $template = 'add_step_one.tpl'; } } else { $errors[] = 'Please input correct xml'; $template = 'add_step_one.tpl'; } $tp->assign('id', $id); $tp->assign('selected', $selected); $tp->assign('a_selected', $a_selected); $tp->assign('xml', htmlspecialchars($xml)); $tp->assign('xmlToUser', $xml); $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo()); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id); $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("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display($template); break; case '3': $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : ''; $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : ''; $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : ''; $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : ''; $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : ""; $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : ""; $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : ""; $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST)); $defaultValue = SJB_Request::getVar('default_value', false); $defaultValueUser = SJB_Request::getVar('user_default_value', false); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $importType = SJB_Request::getVar('import_type', 'increment'); if ($defaultValue) { foreach ($defaultValue as $key => $val) { $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } if ($defaultValueUser) { foreach ($defaultValueUser as $key => $val) { $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : ''; $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $addQuery = ''; $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', '')); $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', '')); $site_url = SJB_System::getSystemSettings("SITE_URL"); if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) { $error = 'Required user profile fields are not mapped'; SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error)); } if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) { // make map $map1 = array(); $map2 = array(); $serUserMap = ''; foreach ($_REQUEST['mapped'] as $one) { $tmp = explode(':', $one); $map1[] = $tmp[0]; $map2[] = $tmp[1]; } if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) { // make map $mapUser1 = array(); $mapUser2 = array(); foreach ($_REQUEST['mapped_user'] as $one) { $tmp = explode(':', $one); $mapUser1[] = str_replace('user_', '', $tmp[0]); $mapUser2[] = $tmp[1]; } foreach ($mapUser1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $mapUser[$val] = $mapUser2[$key]; } $serUserMap = serialize($mapUser); } //$map = array_combine($map1, $map2); // PHP5 foreach ($map1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $map[$val] = $map2[$key]; } if ($selectedLogoOption && $selectedLogoOption != 'not_logo') { //get real data without any cache if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) { $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo'); $listing_field = new SJB_ListingField($listing_field_info, $type_id); $pages = SJB_PostingPagesManager::getFirstPageEachListingType(); SJB_ListingFieldManager::saveListingField($listing_field, $pages); } if ($key = array_search('ListingLogo', $map) !== false) { unset($map[$key]); } } if ($defaultValue) { foreach ($defaultValue as $key => $val) { if ($val == '') { unset($defaultValue[$key]); } } $defaultValue = SJB_db::quote(serialize($defaultValue)); $addQuery .= ", default_value = '" . $defaultValue . "'"; } if ($defaultValueUser) { foreach ($defaultValueUser as $keyuser => $valuser) { if ($valuser == '') { unset($defaultValueUser[$keyuser]); } } $defaultValueUser = SJB_db::quote(serialize($defaultValueUser)); $addQuery .= ", default_value_user = '******'"; } $queryParsUrl = SJB_DB::quote($pars_url); $queryImportType = SJB_DB::quote($importType); $queryId = intval($id); $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}"; if ($id > 0) { SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId); } else { $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType); } $errorFile = ''; $xml_logo = null; switch ($selectedLogoOption) { case 'import_logo': $map[$selectedLogoField] = 'ListingLogo'; break; case 'upload_logo': if (!empty($_FILES['upload_logo_file'])) { if ($_FILES['upload_logo_file']['error']) { $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']); } else { $width = SJB_Settings::getSettingByName('listing_picture_width'); $height = SJB_Settings::getSettingByName('listing_picture_height'); $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width'); $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height'); $picture = new SJB_UploadPictureManager(); $picture->setWidth($width); $picture->setHeight($height); if ($picture->isValidUploadedPictureFile('upload_logo_file')) { $xml_logo = "XMLImportLogo_{$id}"; $picture->setUploadedFileID($xml_logo); $picture->uploadPicture('upload_logo_file', $property_info); } } } break; } $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField)); $serMap = serialize($map); if ($xml_logo) { SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id); } else { SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s WHERE id = ?n", $serMap, $logo_options, $id); } $form_submitted = SJB_Request::getVar('form_action'); if ($form_submitted == 'save_info') { SJB_HelperFunctions::redirect($site_url . '/show-import/'); } elseif ($form_submitted == 'apply_info') { $getterParameters = '?id=' . $id; if ($errorFile) { $getterParameters .= '&error=' . $errorFile; } SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters); } } else { if (empty($errors)) { $errors[] = 'No data to save'; } $tp->assign('errors', $errors); $tp->assign('xml', htmlspecialchars($original_xml)); $tp->assign('xmlToUser', $original_xml); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $tp->display('add_step_three.tpl'); } break; } }
public function execute() { $template_processor = SJB_System::getTemplateProcessor(); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $file_info = SJB_Array::get($_FILES, 'imported_tree_file'); $field_sid = isset($_REQUEST['field_sid']) ? $_REQUEST['field_sid'] : null; $field_info = SJB_ListingFieldManager::getFieldInfoBySID($field_sid); $template_processor->assign("field", $field_info); $template_processor->assign("field_sid", $field_sid); $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($field_info['listing_type_sid']); $template_processor->assign("type_info", $listing_type_info); $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets()); if (!strcasecmp("tree", $field_info['type'])) { if (empty($_FILES['imported_tree_file']['name'])) { $errors['File'] = 'EMPTY_VALUE'; } if (isset($_FILES['imported_tree_file']['error']) && $_FILES['imported_tree_file']['error']) { $errors[] = SJB_UploadFileManager::getErrorId($_FILES['imported_tree_file']['error']); } $start_line = SJB_Request::getVar('start_line', null); 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'; } $form_submitted = $_SERVER['REQUEST_METHOD'] == 'POST'; if ($form_submitted) { if (!SJB_ImportFile::isValidFileExtensionByFormat($_REQUEST['file_format'], $_FILES['imported_tree_file'])) { $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT'; } } $is_data_valid = empty($errors); if ($form_submitted && $is_data_valid) { if (!strcasecmp($_REQUEST['file_format'], 'excel')) { $import_file = new SJB_ImportFileXLS($file_info); } else { $import_file = new SJB_ImportFileCSV($file_info, ','); } $import_file->parse($encodingFromCharset); $imported_data = $import_file->getData(); $count = 0; foreach ($imported_data as $key => $importedColumn) { if (!$importedColumn || $start_line > $key) { continue; } if (SJB_ListingFieldTreeManager::importTreeItem($field_sid, $importedColumn)) { $count++; } } $template_processor->assign("count", $count); $template_processor->display("import_tree_data_statistics.tpl"); } else { if (!$form_submitted) { $errors = null; } $template_processor->assign("errors", isset($errors) ? $errors : null); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $template_processor->display("import_tree_data.tpl"); } } else { echo 'invalid Tree SID is specified'; } }
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']); if (!is_null($listing_info)) { $filename = SJB_Request::getVar('filename', false); if ($filename) { $file = SJB_UploadFileManager::openFile($filename, $listing_id); $errors['NO_SUCH_FILE'] = true; } if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && !$_REQUEST['Occupations']['tree']) { unset($_REQUEST['Occupations']['tree']); } $listing_info = array_merge($listing_info, $_REQUEST); if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && $_REQUEST['Occupations']['tree']) { $listing_info['Occupations'] = $_REQUEST['Occupations']['tree']; } $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']); $listing->setSID($listing_id); $listing_edit_form = new SJB_Form($listing); $form_is_submitted = SJB_Request::getVar('action'); $errors = array(); if ($form_is_submitted) { $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true)); } if ($form_is_submitted && $listing_edit_form->isDataValid($errors)) { $listingSid = $listing->getID(); SJB_BrowseDBManager::deleteListings($listingSid); SJB_ListingManager::saveListing($listing); SJB_BrowseDBManager::addListings($listingSid); $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_Event::dispatch('listingEdited', $listingSid); if (SJB_Request::isAjax()) { echo '<p class="green">Listing Saved</p>'; exit; } if ($form_is_submitted == 'save_info') { $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']); $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's'; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/manage-" . strtolower($listingType) . "/?restore=1"); } } $listing->deleteProperty('access_list'); $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id); $comments_total = count($comments); $rate = SJB_Rating::getRatingNumToListing($listing_id); $form_fields = $listing_edit_form->getFormFieldsInfo(); $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing->getListingTypeSID()); $realFormFields = array(); foreach ($pages as $page) { $listingFields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']); foreach ($listingFields as $fieldID => $listingField) { if (isset($form_fields[$fieldID])) { $realFormFields[$fieldID] = $form_fields[$fieldID]; } } } $adminFields = array(); foreach ($form_fields as $fieldName => $field) { if (!isset($realFormFields[$fieldName])) { $adminFields[$fieldName] = $field; } } $realFormFields = array_merge($adminFields, $realFormFields); $tp = SJB_System::getTemplateProcessor(); $listing_edit_form->registerTags($tp); $extraInfo = $listing_info['product_info']; if ($extraInfo) { $extraInfo = unserialize($extraInfo); $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign("listing_duration", $extraInfo['listing_duration']); $tp->assign("pic_limit", $numberOfPictures); } $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing); if (!isset($listing_structure['access_type'])) { $listing_structure['access_type'] = 'everyone'; } $listing_access_list = SJB_ListingManager::getListingAccessList($listing_id, $listing->getPropertyValue('access_type')); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('form_fields', $realFormFields); $tp->assign('listing', $listing_structure); $tp->assign('errors', $errors); $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo)); $tp->assign('listing_access_list', $listing_access_list); $tp->assign('comments_total', $comments_total); $tp->assign('rate', $rate); $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID())); SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']); $tp->display('edit_listing.tpl'); } }
public function execute() { $bannersObj = new SJB_Banners(); $params = $_REQUEST; $bannerId = $params['bannerId']; if (SJB_Request::isAjax()) { $response = array('success' => $bannersObj->deleteBannerImage($bannerId), 'error' => SJB_I18N::getInstance()->gettext('Backend', $bannersObj->bannersError)); die(json_encode($response)); } $tp = SJB_System::getTemplateProcessor(); $errors = array(); $banner = array_merge($bannersObj->getBannerProperties($bannerId), $params); $form_submitted = SJB_Request::getVar('submit'); $filesDir = SJB_System::getSystemSettings('FILES_DIR'); if (isset($_REQUEST['action'])) { $action_name = $_REQUEST['action']; switch ($action_name) { case 'edit': // ERRORS if ($params['title'] == '') { $errors[] = 'Banner Title is empty.'; } if ($params['link'] == '' && $params['bannerType'] != 'code') { $errors[] = 'Banner link mismatched!'; } if ($params['bannerType'] == 'code' && $params['code'] == '') { $errors[] = 'Banner code is empty.'; } if ($params['bannerType'] == 'file' && $_FILES['image']['name'] == '' && empty($params['imagePath'])) { $errors[] = 'No image attached!'; } if ($_FILES['image']['name'] && $_FILES['image']['error']) { $errors[SJB_UploadFileManager::getErrorId($_FILES['image']['error'])] = 1; } if ($errors) { break; } // if image changed - save it if ($_FILES['image']['name'] != '' && $_FILES['image']['tmp_name'] != '') { $hashName = md5(time() * $_FILES['image']['size'] . "_" . $_FILES['image']['name']); $ext = preg_match("|\\.(\\w{3})\\b|", $_FILES['image']['name'], $arr); $bannerFilePath = $filesDir . "banners/" . $hashName . "." . $arr[1]; // move file from temporary folder, and fill banner info to DB $copy = copy($_FILES['image']['tmp_name'], $bannerFilePath); if (!$copy) { $errors = 'Cannot copy file from TMP dir to Banners Dir'; break; } if ($_FILES['image']['type'] != 'application/x-shockwave-flash') { // array of bannerInfo // [0] - width // [1] - height // [2] - ?? // [3] - width & height in next view: width="104" height="150" // [bits] - bit size of image // [channels] // [mime] - type, (image/jpeg, image/gif, image/png ) $bannerInfo = getimagesize($bannerFilePath); if ($params['width'] != '' && $params['height'] != '') { $sx = $params['width']; $sy = $params['height']; } else { $sx = $bannerInfo[0]; $sy = $bannerInfo[1]; } $type = $bannerInfo['mime']; } else { if ($params['width'] == '' || $params['height'] == '') { $errors[] = 'SIZE_PARAMETER_MISMATCHED'; break; } $sx = $params['width']; $sy = $params['height']; $type = $_FILES['image']['type']; } $bannerFilePath = "/" . str_replace("../", "/", str_replace(SJB_BASE_DIR, '', $bannerFilePath)); // now delete old banner image $bannersObj->deleteBannerImage($bannerId); } else { // if image not changed - leave it as is $bannerOldInfo = $bannersObj->getBannerProperties($params['bannerId']); $sx = $bannerOldInfo['width']; $sy = $bannerOldInfo['height']; if ($params['width'] != '' && $params['height'] != '') { if ($params['width'] != $sx || $params['height'] != $sy) { $sx = $params['width']; $sy = $params['height']; } } $type = $bannerOldInfo['type']; $bannerFilePath = $bannerOldInfo['image_path']; } $title = $params['title']; $link = $params['link']; $active = $params['active']; $group = $params['groupSID']; // check 'link' for correct. If it hasn't 'http://' or 'https://' - add them $expr = preg_match("/^(https?:\\/\\/)/", $link); if ($expr != true && $params['bannerType'] != 'code') { $link = "http://" . $link; } if ($params['bannerType'] == 'code') { $bannersObj->deleteBannerImage($bannerId); } $result = $bannersObj->updateBanner($params['bannerId'], $title, $link, $bannerFilePath, $sx, $sy, $type, $active, $group, $params); if ($form_submitted == 'save_banner') { $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner-group/?groupSID={$group}"; } else { $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner/?bannerId=" . $bannerId; } SJB_HelperFunctions::redirect($site_url); break; } } $banner_fields = $bannersObj->getBannersMeta(); $tp->assign("banner_fields", $banner_fields); $tp->assign("banner", $banner); $tp->assign('errors', $errors); $tp->assign('bannersPath', SJB_Banners::getSiteUrl()); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display("edit_banner.tpl"); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $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); }
public function execute() { ini_set('max_execution_time', 0); $template_processor = SJB_System::getTemplateProcessor(); $errors = array(); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; if (!empty($file_info)) { $extension = $_REQUEST['file_type']; if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || !empty($errors)) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo(); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $template_processor->assign('user_groups', $user_groups); $template_processor->assign('errors', $errors); $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets()); $template_processor->display('import_users.tpl'); } else { $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $user_group_id = SJB_Request::getVar('user_group_id', null); $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id); 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); $user = $this->CreateUser(array(), $user_group_id); $imported_data = $import_file->getData(); $count = 0; $import_file_url = false; $usersID = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_user_processor = new SJB_ImportedUserProcessor($importedColumn, $user); continue; } if (!$importedColumn) { continue; } $userInfo = $imported_user_processor->getData($importedColumn); $extUserID = isset($userInfo['extUserID']) ? $userInfo['extUserID'] : ''; $user = $this->CreateUser(array(), $user_group_id); $user->addExtUserIDProperty(); $doc = new DOMDocument(); foreach ($user->getProperties() as $property) { if ($property->id == 'active') { $property->type->property_info['value'] = $property->value; } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode', $property->id . '.Address'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } unset($userInfo[$locationField]); $userInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode', 'Address'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $userInfo) && !in_array($locationField, $locationFieldAdded) && !$user->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]); } break; default: $value = $userInfo[$locationField]; break; } $userInfo[$property->id][$locationField] = $value; unset($userInfo[$locationField]); } } } } } $user = $this->CreateUser($userInfo, $user_group_id); $user->addExtUserIDProperty($extUserID); $username = SJB_Array::get($userInfo, 'username'); if (empty($username)) { $errors[] = 'Empty username is not allowed, record ignored.'; } elseif (!is_null(SJB_UserManager::getUserSIDbyUsername($username))) { $errors[] = '\'' . $userInfo['username'] . '\' - this user name already exists, record ignored.'; } else { $originalMd5Password = $user->getPropertyValue('password'); SJB_UserManager::saveUser($user); $this->extraProperties($user, $userInfo, $usersID); if (!empty($originalMd5Password)) { SJB_UserManager::saveUserPassword($user->getSID(), $originalMd5Password); } $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid); if ($isApproveByAdmin) { SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending'); } $count++; } } if ($import_file_url) { SJB_Filesystem::delete(SJB_System::getSystemSettings("IMPORT_FILES_DIRECTORY")); } $template_processor->assign('imported_users_count', $count); $template_processor->assign('errors', $errors); $template_processor->display('import_users_result.tpl'); } }
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"); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $bannersObj = new SJB_Banners(); $filesDir = SJB_System::getSystemSettings('FILES_DIR'); // set null values, to initialize $errors = array(); $groupSID = SJB_Request::getVar('groupSID', false); $params = $_REQUEST; if (isset($_REQUEST['action'])) { $action_name = $_REQUEST['action']; switch ($action_name) { case 'add': // ERRORS if ($params['title'] == '') { $errors[] = 'Banner Title is empty.'; } if ($params['link'] == '' && $params['bannerType'] != 'code') { $errors[] = 'Banner link mismatched!'; } if ($params['bannerType'] == 'code' && $params['code'] == '') { $errors[] = 'Banner code is empty.'; } if ($_FILES['image']['name'] == '' && $params['bannerType'] == 'file') { $errors[] = 'No image attached!'; } if ($_FILES['image']['name'] && $_FILES['image']['error']) { $errors[SJB_UploadFileManager::getErrorId($_FILES['image']['error'])] = 1; } if ($errors) { break; } // ok. All input fields presented $title = $params['title']; $link = $params['link']; // check 'link' for correct. If it hasn't 'http://' or 'https://' and bannerType != code - add them $expr = preg_match("/^(https?:\\/\\/)/", $link); if ($expr != true && $params['bannerType'] != 'code') { $link = 'http://' . $link; } if ($params['bannerType'] == 'file') { // make filename preg_match("|\\.(\\w{3})\\b|u", $_FILES['image']['name'], $arr); $fileName = preg_replace("|\\.(\\w{3})\\b|u", '', $_FILES['image']['name']); $hashName = md5(time() * $_FILES['image']['size']) . '_' . $fileName; $bannerFilePath = $filesDir . 'banners/' . $hashName . '.' . $arr[1]; // move file from temporary folder, and fill banner info to DB $copy = copy($_FILES['image']['tmp_name'], $bannerFilePath); if (!$copy) { $errors[] = 'Cannot copy file from TMP dir to Banners Dir'; break; } if ($_FILES['image']['type'] != 'application/x-shockwave-flash') { // array of bannerInfo // [0] - width // [1] - height // [2] - ?? // [3] - width & height in next view: width="104" height="150" // [bits] - bit size of image // [channels] // [mime] - type, (image/jpeg, image/gif, image/png ) $bannerInfo = getimagesize($bannerFilePath); if ($params['width'] != '' && $params['height'] != '') { $sx = $params['width']; $sy = $params['height']; } else { $sx = $bannerInfo[0]; $sy = $bannerInfo[1]; } $type = $bannerInfo['mime']; } else { if ($params['width'] == '' || $params['height'] == '') { $errors[] = 'SIZE_PARAMETER_MISMATCHED'; break; } $sx = $params['width']; $sy = $params['height']; $type = $_FILES['image']['type']; } $active = $params['active']; $group = $params['groupSID']; $bannerFilePath = '/' . str_replace('../', '/', str_replace(SJB_BASE_DIR, '', $bannerFilePath)); } else { $sx = $params['width']; $sy = $params['height']; $type = ''; $active = $params['active']; $group = $params['groupSID']; $bannerFilePath = ''; } $bannersObj->addBanner($title, $link, $bannerFilePath, $sx, $sy, $type, $active, $group, $params); $site_url = SJB_System::getSystemsettings('SITE_URL') . "/edit-banner-group/?groupSID={$groupSID}"; header("Location: {$site_url}"); break; } } $banner_fields = $bannersObj->getBannersMeta(); $bannerGroup = $bannersObj->getBannerGroupBySID($groupSID); $tp->assign('params', $params); $tp->assign('errors', $errors); $tp->assign('banner_fields', $banner_fields); $tp->assign('bannerGroup', $bannerGroup); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display('add_banner.tpl'); }
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'); }
public function execute() { $errors = array(); $this->setEtGroups(SJB_EmailTemplateEditor::getEmailTemplateGroups()); if (isset($_REQUEST['passed_parameters_via_uri'])) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $etGroup = SJB_Array::get($passed_parameters_via_uri, 0); $etSID = SJB_Array::get($passed_parameters_via_uri, 1); $action = SJB_Array::get($passed_parameters_via_uri, 2); if ($etGroup && SJB_Array::get($this->etGroups, $etGroup)) { $this->tp->assign('group', $etGroup); if ($etSID) { switch ($action) { case 'delete': $this->deleteEmailTemplate($etGroup, $etSID); break; case 'getvars': $this->prepareTemplateVarsInfo($etGroup); exit; break; default: if (isset($_FILES['file']) && $_FILES['file']['name'] && $_FILES['file']['error']) { $errors['Attachment'] = 'UPLOAD_ERR_INI_SIZE'; } else { $filename = SJB_Request::getVar('filename', false); if ($filename) { SJB_UploadFileManager::openEmailTemplateFile($filename, $etSID); $errors['NO_SUCH_FILE'] = true; } } $this->editEmailTemplate($etSID, $errors); break; } } else { $this->addNewTemplateForm($etGroup); $this->getEmailTemplatesByGroup($etGroup); } } } else { $this->addNewTemplateForm(); } if ($errors || $this->errors) { $errors = array_merge($errors, $this->errors); } $this->tp->assign('message', $this->successMessage); $this->tp->assign('error', $this->error); $this->tp->assign('errors', $errors); $this->tp->assign('etGroups', $this->etGroups); $this->tp->assign('uploadMaxFilesize', SJB_UploadFileManager::getIniUploadMaxFilesize()); $this->tp->display($this->template); }