get('include_sessions') === 'true'; $entityManager = Database::getManager(); $userRepo = UserManager::getRepository(); $currency = $plugin->getSelectedCurrency(); if (empty($currency)) { Display::addFlash( Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error') ); } $currencyIso = null; if ($editingCourse) { $course = $entityManager->find('ChamiloCoreBundle:Course', $id); if (!$course) { api_not_allowed(true); } $courseItem = $plugin->getCourseForConfiguration($course, $currency); $currencyIso = $courseItem['currency']; $formDefaults = [ 'product_type' => get_lang('Course'), 'id' => $courseItem['course_id'], 'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, 'name' => $courseItem['course_title'], 'visible' => $courseItem['visible'], 'price' => $courseItem['price'], 'tax_perc' => $courseItem['tax_perc'], 'currency_id' => $currency['id'], ]; } elseif ($editingSession) { if (!$includeSession) { api_not_allowed(true); } $session = $entityManager->find('ChamiloCoreBundle:Session', $id); if (!$session) { api_not_allowed(true); } $sessionItem = $plugin->getSessionForConfiguration($session, $currency); $currencyIso = $sessionItem['currency']; $formDefaults = [ 'product_type' => get_lang('Session'), 'id' => $session->getId(), 'type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, 'name' => $sessionItem['session_name'], 'visible' => $sessionItem['visible'], 'price' => $sessionItem['price'], 'tax_perc' => $sessionItem['tax_perc'], 'currency_id' => $currency['id'], ]; } else { api_not_allowed(true); } $globalSettingsParams = $plugin->getGlobalParameters(); $form = new FormValidator('add_subscription'); $form->addText('product_type', $plugin->get_lang('ProductType'), false); $form->addText('name', get_lang('Name'), false); $form->freeze(['product_type', 'name']); $form->addElement( 'number', 'tax_perc', [$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'], ['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')] ); $frequencies = $plugin->getFrequencies(); $selectOptions = ''; foreach ($frequencies as $key => $frequency) { $selectOptions .= ''; } if (empty($frequencies)) { Display::addFlash( Display::return_message($plugin->get_lang('FrequencyIsNotConfigured'), 'error') ); } $platformCommission = $plugin->getPlatformCommission(); $form->addHtml( '

'.$plugin->get_lang('FrequencyConfig').'

'.$currencyIso.'
'.$plugin->get_lang('Duration').' '.$plugin->get_lang('Price').' '.$plugin->get_lang('Actions').'
' ); $form->addHidden('type', null); $form->addHidden('id', null); $button = $form->addButtonSave(get_lang('Save')); if (empty($currency) || empty($frequencies)) { $button->setAttribute('disabled'); } if ($form->validate()) { $formValues = $form->getSubmitValues(); $subscription['product_id'] = $formValues['id']; $subscription['product_type'] = $formValues['type']; $subscription['currency_id'] = $currency['id']; $subscription['tax_perc'] = $formValues['tax_perc'] != '' ? (int) $formValues['tax_perc'] : null; $subscription['frequencies'] = isset($formValues['frequencies']) ? $formValues['frequencies'] : []; $result = $plugin->addNewSubscription($subscription); if ($result) { header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscriptions_courses.php'); } else { header('Location:'.api_get_self().'?'.$queryString); } exit; } $form->setDefaults($formDefaults); $templateName = $plugin->get_lang('SubscriptionAdd'); $interbreadcrumb[] = [ 'url' => 'subscriptions_courses.php', 'name' => get_lang('Configuration'), ]; $interbreadcrumb[] = [ 'url' => 'subscriptions_courses.php', 'name' => $plugin->get_lang('SubscriptionList'), ]; $template = new Template($templateName); $template->assign('header', $templateName); $template->assign('items_form', $form->returnForm()); $template->assign('currencyIso', $currencyIso); $content = $template->fetch('buycourses/view/subscription_add.tpl'); $template->assign('content', $content); $template->display_one_col_template();