Exemplo n.º 1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $productType = SJB_Request::getVar('product_type', false);
     $action = SJB_Request::getVar('action', false);
     $errors = array();
     $productErrors = array();
     if ($productType) {
         if ($productType == 'featured_user') {
             $_REQUEST['user_group_sid'] = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
         }
         $product = new SJB_Product($_REQUEST, $productType);
         $pages = $product->getProductPages();
         $addProductForm = new SJB_Form($product);
         $addProductForm->registerTags($tp);
         $form_submitted = SJB_Request::getVar('action', '') == 'save';
         if ($form_submitted) {
             $productErrors = $product->isValid($product);
             if (in_array($productType, array('access_listings', 'featured_user', 'banners', 'custom_product'))) {
                 $periodName = $product->getPropertyValue('period_name');
                 if ($periodName == 'unlimited') {
                     $product->makePropertyNotRequired('period');
                 }
             }
         }
         if ($form_submitted && $addProductForm->isDataValid($errors) && !$productErrors) {
             $product->addProperty(array('id' => 'product_type', 'type' => 'string', 'value' => $productType, 'is_system' => true));
             $product->saveProduct($product, $_REQUEST);
             $product->savePermissions($_REQUEST);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/products/');
         }
         $errors = array_merge($errors, $productErrors);
         $formFieldsInfo = $addProductForm->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_type', $productType);
         $tp->assign('request', $_REQUEST);
         $tp->assign('params', http_build_query($_REQUEST));
         $tp->assign('pages', $pages);
         $tp->assign('pageTab', SJB_Request::getVar('page', false));
         $tp->assign("errors", $errors);
         $tp->display('add_product.tpl');
     } else {
         $tp->display('select_product_type.tpl');
     }
 }
Exemplo n.º 2
0
 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');
     }
 }
Exemplo n.º 3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $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']);
         $pages = $product->getProductPages();
         $editProductForm = new SJB_Form($product);
         $editProductForm->registerTags($tp);
         $form_submitted = SJB_Request::getVar('action', '') == 'save';
         if ($form_submitted && in_array($productInfo['product_type'], array('access_listings', 'featured_user', 'banners', 'custom_product'))) {
             $periodName = $product->getPropertyValue('period_name');
             if ($periodName == 'unlimited') {
                 $product->makePropertyNotRequired('period');
             }
         }
         $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 ($form_submitted && $editProductForm->isDataValid($errors) && !$activeError) {
             $product->addProperty(array('id' => 'product_type', 'type' => 'string', 'value' => $productInfo['product_type'], 'is_system' => true));
             $product->saveProduct($product, $_REQUEST);
             $product->savePermissions($_REQUEST);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/edit-product/?sid=' . $product->getSID());
         }
         $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('pages', $pages);
         $tp->assign('pageTab', SJB_Request::getVar('page', false));
         $tp->assign("errors", $errors);
         $tp->display('clone_product.tpl');
     }
 }