public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', false); $updateUsers = SJB_Request::getVar('update_users', 0); $sid = SJB_Request::getVar('sid', 0); $errors = array(); $productErrors = array(); $productInfo = SJB_ProductsManager::getProductInfoBySID($sid); if ($productInfo) { if ($productInfo['product_type'] == 'featured_user') { $_REQUEST['user_group_sid'] = SJB_UserGroupManager::getUserGroupSIDByID('Employer'); } $productInfo = array_merge($productInfo, $_REQUEST); $product = new SJB_Product($productInfo, $productInfo['product_type']); $product->setSID($sid); $pages = $product->getProductPages(); $editProductForm = new SJB_Form($product); $editProductForm->registerTags($tp); $form_submitted = $action == 'save' || $action == 'apply_product'; $activeError = array(); if ($form_submitted && ($productInfo['active'] = 1)) { if (!empty($productInfo['availability_to']) && SJB_I18N::getInstance()->getInput('date', $productInfo['availability_to']) <= date('Y-m-d')) { $activeError['INVALID_ACTIVATION'] = 'The product cannot be activated. Please change the availability date.'; } } if ($form_submitted) { $productErrors = $product->isValid($product); $activeError = array_merge($activeError, $productErrors); if (in_array($productInfo['product_type'], array('access_listings', 'featured_user', 'banners', 'custom_product'))) { $periodName = $product->getPropertyValue('period_name'); if ($periodName == 'unlimited') { $product->makePropertyNotRequired('period'); } } } if ($form_submitted && $editProductForm->isDataValid($errors) && !$activeError) { $product->saveProduct($product); $product->savePermissions($_REQUEST); if ($updateUsers) { $contracts = SJB_ContractManager::getAllContractsByProductSID($product->getSID()); if ($contracts) { $contractsSIDs = array(); foreach ($contracts as $contract) { $contractsSIDs[] = $contract['id']; } $contractsSIDs = implode(',', $contractsSIDs); SJB_ContractSQL::updateAllContractsExtraInfoByProductSID($contractsSIDs, $product->getSID()); } } if ($action == 'save') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/products/'); } } else { $product->setFloatNumbersIntoValidFormat(); } $errors = array_merge($errors, $activeError); $formFieldsInfo = $editProductForm->getFormFieldsInfo(); $formFields = array(); foreach ($pages as $pageID => $page) { foreach ($formFieldsInfo as $formFieldInfo) { if (in_array($formFieldInfo['id'], $page['fields'])) { $formFields[$pageID][] = $formFieldInfo; } } if (!isset($formFields[$pageID])) { $formFields[$pageID] = array(); } } $tp->assign('form_fields', $formFields); $tp->assign('product_info', $productInfo); $tp->assign('product_type', $productInfo['product_type']); $tp->assign('params', http_build_query($_REQUEST)); $tp->assign('pageTab', SJB_Request::getVar('page', false)); $tp->assign('pages', $pages); $tp->assign("errors", $errors); $tp->display('edit_product.tpl'); } }
public static function getAllContractsSIDsByUserSID($user_sid) { if ($user_sid == 0) { return false; } $contractsInfo = SJB_ContractSQL::selectInfoByUserSID($user_sid); $result = array(); foreach ($contractsInfo as $contractInfo) { $result[] = $contractInfo['id']; } return $result; }
private function extraProperties($user, $userInfo, &$usersID) { $savedProperties = array('user_group' => 1, 'pictures' => 1); foreach ($user->getProperties() as $property) { if (!in_array($property->id, array('file', 'Logo', 'video'))) { $savedProperties[$property->id] = 1; } } $queryFields = ''; foreach (array_diff_key($userInfo, $savedProperties) as $key => $value) { if ($key == 'id') { $usersID[$value] = $user->getSID(); continue; } if ($key == 'product') { $products = $value ? explode(',', $value) : array(); $i = sizeof($products); while (--$i != -1) { $productProperties = @unserialize($products[$i]); if (!$productProperties) { continue; } $productSid = SJB_ProductsManager::getProductSidByName($productProperties['name']); if (!$productSid) { continue; } $contract = new SJB_Contract(array('product_sid' => $productSid, 'numberOfListings' => $productProperties['number_of_listings'])); $contract->setPrice($productProperties['price']); $contract->setCreationDate($productProperties['creation_date']); $contract->setExpiredDate($productProperties['expired_date']); $contract->setStatus($productProperties['status']); $contract->setUserSID($user->getSID()); $contract->saveInDB(); SJB_ContractSQL::updatePostingsNumber($contract->id, $productProperties['number_of_postings']); SJB_ProductsManager::incrementPostingsNumber($productSid, $productProperties['number_of_postings']); } continue; } if (in_array($key, array('file', 'Logo', 'video')) && !empty($value)) { $property = $user->getProperty($key); if (!$property) { continue; } $fileProperties = @unserialize($value); if (!$fileProperties) { continue; } $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($property->sid); switch ($key) { case 'file': $value = 'Resume_' . $user->getSID(); $this->databaseFileRegister('file', $value, $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']); break; case 'Logo': $value = 'Logo_' . $user->getSID(); $this->databaseFileRegister('pictures', $value, $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']); $this->databaseFileRegister('pictures', 'Logo_' . $user->getSID() . '_thumb', $fileProperties['name'] . '_thumb.' . $fileProperties['extension'], $fileProperties['mimeType']); break; case 'video': $value = 'video_' . $user->getSID(); $this->databaseFileRegister('video', 'video_' . $user->getSID(), $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']); break; } } if ($key == 'registration_date') { $isValid = SJB_UserRegistrationDateValidator::isValid($userInfo['registration_date']); if ($isValid !== true) { if (!isset($errors['registrationDate'])) { $errors['registrationDate'][] = $isValid; } if (isset($userInfo['username'])) { $errors['registrationDate'][] = $userInfo['username'] . ', '; } continue; } } if (!empty($value)) { $queryFields .= $queryFields ? ", `" . SJB_DB::quote($key) . "` = '" . SJB_DB::quote($value) . "'" : "`" . SJB_DB::quote($key) . "` = '" . SJB_DB::quote($value) . "'"; } } if (!empty($queryFields)) { SJB_DB::queryExec("UPDATE ?w SET " . $queryFields . " WHERE `sid` = ?n", 'users', $user->getSID()); } }
public function incrementPostingsNumber() { return SJB_ContractSQL::incrementPostingsNumber($this->contract_id); }