Browse Source

Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

Yannick Warnier 9 years ago
parent
commit
7ea46a25be

+ 5 - 1
main/course_home/course_home.php

@@ -172,7 +172,11 @@ if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
         $auth = new Auth();
         $msg = $auth->subscribe_user($course_code);
         if (!empty($msg)) {
-            $show_message .= Display::return_message(get_lang($msg));
+            $show_message .= Display::return_message(
+                get_lang($msg['message']),
+                'info',
+                false
+            );
         }
     }
 }

+ 4 - 6
main/inc/lib/social.lib.php

@@ -1808,7 +1808,7 @@ class SocialManager extends UserManager
 
         if ($number_friends != 0) {
 
-            $friendHtml.= '<ul class="list-group">';
+            $friendHtml.= '<div class="list-group">';
             $j = 1;
             for ($k=0; $k < $number_friends; $k++) {
                 if ($j > $number_of_images) break;
@@ -1826,7 +1826,6 @@ class SocialManager extends UserManager
                         $status=0;
                     }
 
-                    $friendHtml.= '<li class="list-group-item">';
                     $friendAvatarMedium = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_MEDIUM);
                     $friendAvatarSmall = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
                     $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
@@ -1834,21 +1833,20 @@ class SocialManager extends UserManager
                         $friend['friend_user_id'] != api_get_user_id();
 
                     if ($showLinkToChat){
-                        $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);">';
+                        $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">';
                         $friendHtml .=  $friend_avatar.' <span class="username">' . $name_user . '</span>';
                         $friendHtml .= '<span class="status">' . $statusIcon . '</span>';
                     } else {
                         $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
-                        $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">';
+                        $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '" class="list-group-item">';
                         $friendHtml .=  $friend_avatar.' <span class="username-all">' . $name_user . '</span>';
                     }
 
                     $friendHtml .= '</a>';
-                    $friendHtml.= '</li>';
                 }
                 $j++;
             }
-            $friendHtml.='</ul>';
+            $friendHtml.='</div>';
         } else {
             $friendHtml.= '<div class="help">'.get_lang('NoFriendsInYourContactList').' '
                 .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><i class="fa fa-search"></i> '. get_lang('TryAndFindSomeFriends').'</a></div>';

+ 10 - 12
main/template/default/chat/video.tpl

@@ -9,7 +9,15 @@
         </p>
     </div>
     <div class="row">
-        <div class="col-md-4">
+        <div class="col-md-8 col-sm-7">
+            <div class="thumbnail video-chat-user">
+                <div id="chat-remote-video"></div>
+                <div class="caption">
+                    <p class="text-muted text-center">{{ "ChatWithXUser"|get_lang|format(chat_user.complete_name) }}</p>
+                </div>
+            </div>
+        </div>
+        <div class="col-md-4 col-sm-5">
             <div class="thumbnail">
                 <div id="chat-local-video"></div>
                 <div class="caption">
@@ -28,22 +36,12 @@
                             </h4>
                         </div>
                         <div id="listFriends" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
-                            <div class="panel-body">
-                                {{ block_friends }}
-                            </div>
+                            {{ block_friends }}
                         </div>
                     </div>
                 </div>
             </div>
         </div>
-        <div class="col-md-8">
-            <div class="thumbnail video-chat-user">
-                <div id="chat-remote-video"></div>
-                <div class="caption">
-                    <p class="text-muted text-center">{{ "ChatWithXUser"|get_lang|format(chat_user.complete_name) }}</p>
-                </div>
-            </div>
-        </div>
     </div>
 </div>
 <script>

+ 1 - 3
main/template/default/social/home.tpl

@@ -31,9 +31,7 @@
                             </h4>
                         </div>
                         <div id="listFriends" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
-                            <div class="panel-body">
-                                {{ social_friend_block }}
-                            </div>
+                            {{ social_friend_block }}
                         </div>
                     </div>
                 </div>

+ 1 - 3
main/template/default/social/profile.tpl

@@ -26,9 +26,7 @@
                             </h4>
                         </div>
                     <div id="listFriends" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
-                        <div class="panel-body">
-                            {{ social_friend_block }}
-                        </div>
+                        {{ social_friend_block }}
                     </div>
                 </div>
             </div>

+ 2 - 0
plugin/buycourses/CHANGELOG.md

@@ -12,6 +12,7 @@ in a currency other than the others courses or sessions
 Allowing filter the sales by its status
 - The plugin Registration page was removed. Instead the Chamilo LMS
 registrarion page is used.
+- Added the ability to record beneficiaries with the sale of courses/sessions
 
 ##Changes in database structure
 
@@ -40,6 +41,7 @@ The __new database__ structure is formed for the tables:
 
 - `plugin_buycourses_currency` The list of countries with their currencies
 - `plugin_buycourses_item` The registered courses and sessions in the platform
+- `plugin_buycourses_item_re_beneficiary` The beneficiaries users with the sale of courses
 - `plugin_buycourses_paypal_account` The PayPal account info
 - `plugin_buycourses_sale` The sales of courses and sessions that were made
 - `plugin_buycourses_transfer` The bank accounts for transfers

+ 25 - 1
plugin/buycourses/database.php

@@ -97,6 +97,30 @@ $itemTable->addForeignKeyConstraint(
     ['onDelete' => 'CASCADE']
 );
 
+$itemBeneficiary = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY);
+$itemBeneficiary->addColumn(
+    'id',
+    \Doctrine\DBAL\Types\Type::INTEGER,
+    ['autoincrement' => true, 'unsigned' => true]
+);
+$itemBeneficiary->addColumn(
+    'item_id',
+    \Doctrine\DBAL\Types\Type::INTEGER,
+    ['unsigned' => true]
+);
+$itemBeneficiary->addColumn(
+    'user_id',
+    \Doctrine\DBAL\Types\Type::INTEGER,
+    ['unsigned' => true]
+);
+$itemBeneficiary->setPrimaryKey(['id']);
+$itemBeneficiary->addForeignKeyConstraint(
+    $itemTable,
+    ['item_id'],
+    ['id'],
+    ['onDelete' => 'CASCADE']
+);
+
 $saleTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SALE);
 $saleTable->addColumn(
     'id',
@@ -104,7 +128,7 @@ $saleTable->addColumn(
     ['autoincrement' => true, 'unsigned' => true]
 );
 $saleTable->addColumn('reference', \Doctrine\DBAL\Types\Type::STRING);
-$saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATE);
+$saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATETIME);
 $saleTable->addColumn(
     'user_id',
     \Doctrine\DBAL\Types\Type::INTEGER,

+ 0 - 36
plugin/buycourses/js/buycourses.js

@@ -1,36 +0,0 @@
-/* For licensing terms, see /license.txt */
-/**
- * JS library for the Chamilo buy-courses plugin
- * @package chamilo.plugin.buycourses
- */
-$(document).ready(function () {
-    $(".bc-button-save").click(function () {
-        var currentRow = $(this).closest("tr");
-        var courseOrSessionObject = {
-            tab: "save_mod",
-            visible: currentRow.find("[name='visible']").is(':checked') ? 1 : 0,
-            price: currentRow.find("[name='price']").val()
-        };
-
-        var itemField = currentRow.data('type') + '_id';
-
-        courseOrSessionObject[itemField] = currentRow.data('item') || 0;
-
-        $.post(
-            "function.php",
-            courseOrSessionObject,
-            function (data) {
-                if (!data.status) {
-                    return;
-                }
-
-                currentRow.addClass('success');
-
-                window.setTimeout(function () {
-                    currentRow.removeClass('success');
-                }, 3000);
-            },
-            "json"
-        );
-    });
-});

+ 5 - 1
plugin/buycourses/lang/english.php

@@ -1,6 +1,6 @@
 <?php
 $strings['plugin_title'] = "Sell courses";
-$strings['plugin_comment'] = "Sell courses directly through your Chamilo portal, using a PayPal account to receive funds. This plugin is in beta version. Neither the Chamilo association nor the developers involved could be considered responsible of any issue you might suffer using this plugin.";
+$strings['plugin_comment'] = "Sell courses directly through your Chamilo portal, using a PayPal account to receive funds. Neither the Chamilo association nor the developers involved could be considered responsible of any issue you might suffer using this plugin.";
 $strings['show_main_menu_tab'] = "Show tab in main menu";
 $strings['show_main_menu_tab_help'] = "In case of not wanting to show the tab, you can create this link in your Chamilo homepage : %s";
 $strings['include_sessions'] = "Include sessions";
@@ -84,3 +84,7 @@ $strings['InfoApiStepOne'] = "Go to your PayPal account, <strong>Summary</strong
 $strings['InfoApiStepTwo'] = "In paragraph <strong>API access</strong>, click <strong>Update</strong>";
 $strings['InfoApiStepThree'] = "In Option 2 (Request API credentials to create your own API username and password), click the <strong>View API Signature</strong> link, and copy the credentials shown right into the BuyCourses plugin form";
 $strings['ErrorOccurred'] = "<strong>An error ocurred</strong>. Code: %s. Message: %s. Please contact to platform admin";
+$strings['VisibleInCatalog'] = "Visible in catalog";
+$strings['Beneficiaries'] = "Beneficiaries";
+$strings['AvailableCourse'] = "Available course";
+$strings['ShowOnCourseCatalog'] = "Show on course catalog";

+ 6 - 2
plugin/buycourses/lang/french.php

@@ -1,6 +1,6 @@
 <?php
 $strings['plugin_title'] = "Vente de cours";
-$strings['plugin_comment'] = "Vendez vos cours directement depuis votre portail Chamilo, au travers d'un compte PayPal. Plugin en version beta, à utiliser avec précaution. Ni l'association Chamilo ni les développeurs impliqués dans le développement de ce plugin ne sauraient être tenus responsables d'un quelconque inconvénient causé par celui-ci.";
+$strings['plugin_comment'] = "Vendez vos cours directement depuis votre portail Chamilo, au travers d'un compte PayPal. Ni l'association Chamilo ni les développeurs impliqués dans le développement de ce plugin ne sauraient être tenus responsables d'un quelconque inconvénient causé par celui-ci.";
 $strings['show_main_menu_tab'] = "Montrer l'onglet dans le menu principal";
 $strings['show_main_menu_tab_help'] = "Dans le cas où vous ne souhaitez pas montrer l'onglet, il est possible de rajouter le lien suivant à votre portail Chamilo: %s";
 $strings['include_sessions'] = "Inclure les sessions";
@@ -18,7 +18,7 @@ $strings['Price'] = "Prix";
 $strings['SearchFilter'] = "Filtre de recherche";
 $strings['MinimumPrice'] = "Prix minimum";
 $strings['MaximumPrice'] = "Prix maximum";
-$strings['AvailableCourses'] = "Configuration des cours disponibles";
+$strings['AvailableCoursesConfiguration'] = "Configuration des cours disponibles";
 $strings['PaymentsConfiguration'] = "Configuration des paiements";
 $strings['TheUserIsAlreadyRegisteredInTheCourse'] = "L'utilisateur est déjà inscrit au cours";
 $strings['SeeDescription'] = "Voir description";
@@ -84,3 +84,7 @@ $strings['InfoApiStepOne'] = "Aller dans l\'option <strong>profil</strong> de Pa
 $strings['InfoApiStepTwo'] = "Dans la section <strong>API d\'accès</strong>, cloquer sur l\'option <strong>Mettre à jour</strong>";
 $strings['InfoApiStepThree'] = "Dans l\'option 2 de Configuration des données et permissions API, cliquer sur <strong>Voir signature API</strong>. Copier ces donées dans le formulaire de configuration de ce plugin";
 $strings['ErrorOccurred'] = "<strong>Une erreur est survenue</strong>. Code: %s. Message: %s. Veuillez contacter l'administrateur de la plateforme";
+$strings['VisibleInCatalog'] = "Visible dans le catalogue";
+$strings['Beneficiaries'] = "Bénéficiaires";
+$strings['AvailableCourse'] = "Cours disponibles";
+$strings['ShowOnCourseCatalog'] = "Afficher dans le catalogue de cours";

+ 5 - 1
plugin/buycourses/lang/spanish.php

@@ -1,6 +1,6 @@
 <?php
 $strings['plugin_title'] = "Venta de cursos";
-$strings['plugin_comment'] = "Vender cursos a través de PayPal directamente desde su portal Chamilo. Plugin en versión Beta, a usar con mucha precaución. La asociación Chamilo y los desarrolladores involucrados no pueden ser considerados responsables de cualquier inconveniente que se presente.";
+$strings['plugin_comment'] = "Vender cursos a través de PayPal directamente desde su portal Chamilo. La asociación Chamilo y los desarrolladores involucrados no pueden ser considerados responsables de cualquier inconveniente que se presente.";
 $strings['show_main_menu_tab'] = "Mostrar pestaña en el menu principal";
 $strings['show_main_menu_tab_help'] = "En caso de no querer mostrar la pestaña, puede agregar el siguiente enlace a su portal Chamilo: %s";
 $strings['include_sessions'] = "Incluir sesiones";
@@ -84,3 +84,7 @@ $strings['InfoApiStepOne'] = "Ir a la opción de <strong>Perfil de PayPal</stron
 $strings['InfoApiStepTwo'] = "En el apartado <strong>Acceso API</strong>, dar clic en la opción <strong>Actualizar</strong>";
 $strings['InfoApiStepThree'] = "En la opción 2, de Configuración de credenciales y permisos de API, dar clic en <strong>Ver firma de API</strong>. Copiar los datos de las credenciales en el formulario de configuración de este plugin";
 $strings['ErrorOccurred'] = "<strong>Ocurrio un error</strong>. Codigo: %s. Mensaje: %s. Por favor, contacta al administrador de la plataforma.";
+$strings['VisibleInCatalog'] = "Visible en el catálogo";
+$strings['Beneficiaries'] = "Beneficiarios";
+$strings['AvailableCourse'] = "Curso disponible";
+$strings['ShowOnCourseCatalog'] = "Mostrar en el catálogo de cursos";

+ 274 - 82
plugin/buycourses/src/buy_course_plugin.class.php

@@ -16,6 +16,7 @@ class BuyCoursesPlugin extends Plugin
     const TABLE_PAYPAL = 'plugin_buycourses_paypal_account';
     const TABLE_CURRENCY = 'plugin_buycourses_currency';
     const TABLE_ITEM = 'plugin_buycourses_item';
+    const TABLE_ITEM_BENEFICIARY = 'plugin_buycourses_item_rel_beneficiary';
     const TABLE_SALE = 'plugin_buycourses_sale';
     const TABLE_TRANSFER = 'plugin_buycourses_transfer';
     const PRODUCT_TYPE_COURSE = 1;
@@ -44,7 +45,7 @@ class BuyCoursesPlugin extends Plugin
                 Jose Angel Ruiz - NoSoloRed (original author),
                 Francis Gonzales and Yannick Warnier - BeezNest (integration),
                 Alex Aragón - BeezNest (Design icons and css styles),
-                Imanol Losada - BeezNest (introduction of sessions purchase)
+                Imanol Losada - BeezNest (introduction of sessions purchase),
                 Angel Fernando Quiroz Campos - BeezNest
             ",
             array(
@@ -62,6 +63,13 @@ class BuyCoursesPlugin extends Plugin
      */
     function install()
     {
+        $appPlugin = new AppPlugin();
+        $installedPlugins = $appPlugin->get_installed_plugins();
+
+        if (in_array($this->get_name(), $installedPlugins)) {
+            return false;
+        }
+
         require_once api_get_path(SYS_PLUGIN_PATH) . 'buycourses/database.php';
     }
 
@@ -73,6 +81,7 @@ class BuyCoursesPlugin extends Plugin
         $tablesToBeDeleted = array(
             self::TABLE_PAYPAL,
             self::TABLE_TRANSFER,
+            self::TABLE_ITEM_BENEFICIARY,
             self::TABLE_ITEM,
             self::TABLE_SALE,
             self::TABLE_CURRENCY
@@ -285,26 +294,7 @@ class BuyCoursesPlugin extends Plugin
         $currency = $this->getSelectedCurrency();
 
         foreach ($courses as $course) {
-            $courseItem = [
-                'course_id' => $course->getId(),
-                'course_visual_code' => $course->getVisualCode(),
-                'course_code' => $course->getCode(),
-                'course_title' => $course->getTitle(),
-                'course_visibility' => $course->getVisibility(),
-                'visible' => false,
-                'currency' =>  empty($currency) ? null : $currency['iso_code'],
-                'price' => 0.00
-            ];
-
-            $item = $this->getItemByProduct($course->getId(), self::PRODUCT_TYPE_COURSE);
-
-            if ($item !== false) {
-                $courseItem['visible'] = true;
-                $courseItem['currency'] = $item['iso_code'];
-                $courseItem['price'] = $item['price'];
-            }
-
-            $configurationCourses[] = $courseItem;
+            $configurationCourses[] = $this->getCourseForConfiguration($course, $currency);
         }
 
         return $configurationCourses;
@@ -316,9 +306,6 @@ class BuyCoursesPlugin extends Plugin
      */
     public function getSessionsForConfiguration()
     {
-        $buyItemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
-        $buyCurrencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
-
         $auth = new Auth();
         $sessions = $auth->browseSessions();
 
@@ -326,55 +313,8 @@ class BuyCoursesPlugin extends Plugin
 
         $items = [];
 
-        $fakeItemFrom = "
-            $buyItemTable i
-            INNER JOIN $buyCurrencyTable c
-                ON i.currency_id = c.id
-        ";
-
         foreach ($sessions as $session) {
-            $sessionItem = [
-                'session_id' => $session->getId(),
-                'session_name' => $session->getName(),
-                'session_visibility' => $session->getVisibility(),
-                'session_display_start_date' => null,
-                'session_display_end_date' => null,
-                'visible' => false,
-                'currency' =>  empty($currency) ? null : $currency['iso_code'],
-                'price' => 0.00
-            ];
-
-            if (!empty($session->getDisplayStartDate())) {
-                $sessionItem['session_display_start_date'] = api_format_date(
-                    $session->getDisplayStartDate()->format('Y-m-d h:i:s')
-                );
-            }
-
-            if (!empty($session->getDisplayEndDate())) {
-                $sessionItem['session_display_end_date'] = api_format_date(
-                    $session->getDisplayEndDate()->format('Y-m-d h:i:s')
-                );
-            }
-
-            $item = Database::select(
-                ['i.*', 'c.iso_code'],
-                $fakeItemFrom,
-                [
-                    'where' => [
-                        'i.product_id = ? AND ' => $session->getId(),
-                        'i.product_type = ?' => self::PRODUCT_TYPE_SESSION
-                    ]
-                ],
-                'first'
-            );
-
-            if ($item !== false) {
-                $sessionItem['visible'] = true;
-                $sessionItem['currency'] = $item['iso_code'];
-                $sessionItem['price'] = $item['price'];
-            }
-
-            $items[] = $sessionItem;
+            $items[] = $this->getSessionForConfiguration($session, $currency);
         }
 
         return $items;
@@ -540,10 +480,6 @@ class BuyCoursesPlugin extends Plugin
         return 'NO';
     }
 
-    /**
-     * Lists current user course details
-     * @return array
-     */
     /**
      * Lists current user course details
      * @param string $name Optional. The name filter
@@ -915,8 +851,8 @@ class BuyCoursesPlugin extends Plugin
 
     /**
      * Get a list of sales by the status
-     * @param type $status
-     * @return type
+     * @param int $status The status to filter
+     * @return array The sale list. Otherwise return false
      */
     public function getSaleListByStatus($status = self::SALE_STATUS_PENDING)
     {
@@ -925,10 +861,8 @@ class BuyCoursesPlugin extends Plugin
         $userTable = Database::get_main_table(TABLE_MAIN_USER);
 
         $innerJoins = "
-            INNER JOIN $currencyTable c
-                ON s.currency_id = c.id
-            INNER JOIN $userTable u
-                ON s.user_id = u.id
+            INNER JOIN $currencyTable c ON s.currency_id = c.id
+            INNER JOIN $userTable u ON s.user_id = u.id
         ";
 
         return Database::select(
@@ -1127,4 +1061,262 @@ class BuyCoursesPlugin extends Plugin
         );
     }
 
+    /**
+     * Get a list of sales by the user
+     * @param string $term The search term
+     * @return array The sale list. Otherwise return false
+     */
+    public function getSaleListByUser($term)
+    {
+        $term = trim($term);
+
+        if (empty($term)) {
+            return [];
+        }
+
+        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
+        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
+        $userTable = Database::get_main_table(TABLE_MAIN_USER);
+
+        $innerJoins = "
+            INNER JOIN $currencyTable c ON s.currency_id = c.id
+            INNER JOIN $userTable u ON s.user_id = u.id
+        ";
+
+        return Database::select(
+            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
+            "$saleTable s $innerJoins",
+            [
+                'where' => [
+                    'u.username LIKE %?% OR ' => $term,
+                    'u.lastname LIKE %?% OR ' => $term,
+                    'u.firstname LIKE %?%' => $term
+                ],
+                'order' => 'id DESC'
+            ]
+        );
+    }
+
+    /**
+     * Convert the course info to array with necessary course data for save item
+     * @param \Chamilo\CoreBundle\Entity\Course $course
+     * @param array $defaultCurrency Optional. Currency data
+     * @return array
+     */
+    public function getCourseForConfiguration(\Chamilo\CoreBundle\Entity\Course $course, $defaultCurrency = null)
+    {
+        $courseItem = [
+            'item_id' => null,
+            'course_id' => $course->getId(),
+            'course_visual_code' => $course->getVisualCode(),
+            'course_code' => $course->getCode(),
+            'course_title' => $course->getTitle(),
+            'course_visibility' => $course->getVisibility(),
+            'visible' => false,
+            'currency' =>  empty($defaultCurrency) ? null : $defaultCurrency['iso_code'],
+            'price' => 0.00
+        ];
+
+        $item = $this->getItemByProduct($course->getId(), self::PRODUCT_TYPE_COURSE);
+
+        if ($item !== false) {
+            $courseItem['item_id'] = $item['id'];
+            $courseItem['visible'] = true;
+            $courseItem['currency'] = $item['iso_code'];
+            $courseItem['price'] = $item['price'];
+        }
+
+        return $courseItem;
+    }
+
+    /**
+     * Convert the session info to array with necessary session data for save item
+     * @param Chamilo\CoreBundle\Entity\Session $session The session data
+     * @param array $defaultCurrency Optional. Currency data
+     * @return array
+     */
+    public function getSessionForConfiguration(Chamilo\CoreBundle\Entity\Session $session, $defaultCurrency = null)
+    {
+        $buyItemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
+        $buyCurrencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
+
+        $fakeItemFrom = "
+            $buyItemTable i
+            INNER JOIN $buyCurrencyTable c ON i.currency_id = c.id
+        ";
+
+        $sessionItem = [
+            'item_id' => null,
+            'session_id' => $session->getId(),
+            'session_name' => $session->getName(),
+            'session_visibility' => $session->getVisibility(),
+            'session_display_start_date' => null,
+            'session_display_end_date' => null,
+            'visible' => false,
+            'currency' =>  empty($defaultCurrency) ? null : $defaultCurrency['iso_code'],
+            'price' => 0.00
+        ];
+
+        if (!empty($session->getDisplayStartDate())) {
+            $sessionItem['session_display_start_date'] = api_format_date(
+                $session->getDisplayStartDate()->format('Y-m-d h:i:s')
+            );
+        }
+
+        if (!empty($session->getDisplayEndDate())) {
+            $sessionItem['session_display_end_date'] = api_format_date(
+                $session->getDisplayEndDate()->format('Y-m-d h:i:s'),
+                DATE_TIME_FORMAT_LONG_24H
+            );
+        }
+
+        $item = Database::select(
+            ['i.*', 'c.iso_code'],
+            $fakeItemFrom,
+            [
+                'where' => [
+                    'i.product_id = ? AND ' => $session->getId(),
+                    'i.product_type = ?' => self::PRODUCT_TYPE_SESSION
+                ]
+            ],
+            'first'
+        );
+
+        if ($item !== false) {
+            $sessionItem['item_id'] = $item['id'];
+            $sessionItem['visible'] = true;
+            $sessionItem['currency'] = $item['iso_code'];
+            $sessionItem['price'] = $item['price'];
+        }
+
+        return $sessionItem;
+    }
+
+    /**
+     * Get all beneficiaries for a item
+     * @param int $itemId The item ID
+     * @return array The beneficiries. Otherwise return false
+     */
+    public function getItemBeneficiaries($itemId)
+    {
+        $beneficiaryTable = Database::get_main_table(self::TABLE_ITEM_BENEFICIARY);
+
+        return Database::select(
+            '*',
+            $beneficiaryTable,
+            ['where' => [
+                'item_id = ?' => intval($itemId)
+            ]]
+        );
+    }
+
+    /**
+     * Delete a item with its beneficiaries
+     * @param int $itemId The item ID
+     * @return int The number of affected rows. Otherwise return false
+     */
+    public function deleteItem($itemId)
+    {
+        $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
+
+        $affectedRows = Database::delete(
+            $itemTable,
+            ['id = ?' => intval($itemId)]
+        );
+
+        if (!$affectedRows) {
+            return false;
+        }
+
+        return $this->deleteItemBeneficiaries($itemId);
+    }
+
+    /**
+     * Register a item
+     * @param array $itemData The item data
+     * @return int The item ID. Otherwise return false
+     */
+    public function registerItem(array $itemData)
+    {
+        $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
+
+        return Database::insert($itemTable, $itemData);
+    }
+
+    /**
+     * Update the item data by product
+     * @param array $itemData The item data to be updated
+     * @param int $productId The product ID
+     * @param int $productType The type of product
+     * @return int The number of affected rows. Otherwise return false
+     */
+    public function updateItem(array $itemData, $productId, $productType)
+    {
+        $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
+
+        return Database::update(
+            $itemTable,
+            $itemData,
+            [
+                'product_id = ? AND ' => intval($productId),
+                'product_type' => $productType
+            ]
+        );
+    }
+
+    /**
+     * Remove all beneficiaries for a item
+     * @param int $itemId The user ID
+     * @return int The number of affected rows. Otherwise return false
+     */
+    public function deleteItemBeneficiaries($itemId)
+    {
+        $beneficiaryTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY);
+
+        return Database::delete(
+            $beneficiaryTable,
+            ['item_id = ?' => intval($itemId)]
+        );
+    }
+
+    /**
+     * Register the beneficiaries users with the sale of item
+     * @param int $itemId The item ID
+     * @param array $userIds The beneficiary user ID
+     */
+    public function registerItemBeneficiaries($itemId, array $userIds)
+    {
+        $beneficiaryTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY);
+
+        $this->deleteItemBeneficiaries($itemId);
+
+        foreach ($userIds as $userId) {
+            Database::insert(
+                $beneficiaryTable,
+                [
+                    'item_id' => intval($itemId),
+                    'user_id' => intval($userId)
+                ]
+            );
+        }
+    }
+
+    /**
+     * Check if a course is valid for sale
+     * @param Chamilo\CoreBundle\Entity\Course $course The course
+     * @return boolean
+     */
+    public function isValidCourse(Chamilo\CoreBundle\Entity\Course $course)
+    {
+        $courses = $this->getCourses();
+
+        foreach ($courses as $_c) {
+            if ($_c->getCode() === $course->getCode()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
 }

+ 2 - 0
plugin/buycourses/src/configuration.php

@@ -30,6 +30,8 @@ $interbreadcrumb[] = [
 
 $templateName = $plugin->get_lang('AvailableCourses');
 $tpl = new Template($templateName);
+$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
+$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
 $tpl->assign('courses', $courses);
 $tpl->assign('sessions_are_included', $includeSession);
 

+ 220 - 0
plugin/buycourses/src/configure_course.php

@@ -0,0 +1,220 @@
+<?php
+/* For license terms, see /license.txt */
+/**
+ * Configuration script for the Buy Courses plugin
+ * @package chamilo.plugin.buycourses
+ */
+/**
+ * Initialization
+ */
+$cidReset = true;
+
+require_once '../config.php';
+
+api_protect_admin_script();
+
+if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
+    die;
+}
+
+$plugin = BuyCoursesPlugin::create();
+
+
+$includeSession = $plugin->get('include_sessions') === 'true';
+
+$editingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
+$editingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
+
+$entityManager = Database::getManager();
+$userRepo = $entityManager->getRepository('ChamiloUserBundle:User');
+
+$currency = $plugin->getSelectedCurrency();
+$currencyIso = null;
+
+if ($editingCourse) {
+    $course = $entityManager->find('ChamiloCoreBundle:Course', $_REQUEST['i']);
+
+    if (!$course) {
+        api_not_allowed(true);
+    }
+
+    if (!$plugin->isValidCourse($course)) {
+        api_not_allowed(true);
+    }
+
+    $courseItem = $plugin->getCourseForConfiguration($course, $currency);
+    $defaultBeneficiaries = [];
+    $teachers = $course->getTeachers();
+    $teachersOptions = [];
+
+    foreach ($teachers as $courseTeacher) {
+        $teacher = $courseTeacher->getUser();
+
+        $teachersOptions[] = [
+            'text' => $teacher->getCompleteName(),
+            'value' => $teacher->getId()
+        ];
+
+        $defaultBeneficiaries[] = $teacher->getId();
+    }
+
+    $currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']);
+
+    if (!empty($currentBeneficiaries)) {
+        $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
+    }
+
+    $currencyIso = $courseItem['currency'];
+    $formDefaults = [
+        'product_type' => get_lang('Course'),
+        'i' => $courseItem['course_id'],
+        't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
+        'name' => $courseItem['course_title'],
+        'visible' => $courseItem['visible'],
+        'price' => $courseItem['price'],
+        'beneficiaries' => $defaultBeneficiaries
+    ];
+} elseif ($editingSession) {
+    if (!$includeSession) {
+        api_not_allowed(true);
+    }
+
+    $session = $entityManager->find('ChamiloCoreBundle:Session', $_REQUEST['i']);
+
+    if (!$session) {
+        api_not_allowed(true);
+    }
+
+    $sessionItem = $plugin->getSessionForConfiguration($session, $currency);
+    $generalCoach = $session->getGeneralCoach();
+    $generalCoachOption = [
+        'text' => $generalCoach->getCompleteName(),
+        'value' => $generalCoach->getId()
+    ];
+    $defaultBeneficiaries = [
+        $generalCoach->getId()
+    ];
+    $courseCoachesOptions = [];
+    $sessionCourses = $session->getCourses();
+
+    foreach ($sessionCourses as $sessionCourse) {
+        $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse->getCourse());
+
+        foreach ($courseCoaches as $courseCoach) {
+            if ($generalCoach->getId() === $courseCoach->getId()) {
+                continue;
+            }
+
+            $courseCoachesOptions[] = [
+                'text' => $courseCoach->getCompleteName(),
+                'value' => $courseCoach->getId()
+            ];
+            $defaultBeneficiaries[] = $courseCoach->getId();
+        }
+    }
+
+    $currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']);
+
+    if (!empty($currentBeneficiaries)) {
+        $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
+    }
+
+    $currencyIso = $sessionItem['currency'];
+    $formDefaults = [
+        'product_type' => get_lang('Session'),
+        'i' => $session->getId(),
+        't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
+        'name' => $sessionItem['session_name'],
+        'visible' => $sessionItem['visible'],
+        'price' => $sessionItem['price'],
+        'beneficiaries' => $defaultBeneficiaries
+    ];
+} else {
+    api_not_allowed(true);
+}
+
+$form = new FormValidator('beneficiaries');
+$form->addText('product_type', $plugin->get_lang('ProductType'), false);
+$form->addText('name', get_lang('Name'), false);
+$visibleCheckbox = $form->addCheckBox(
+    'visible',
+    $plugin->get_lang('VisibleInCatalog'),
+    $plugin->get_lang('ShowOnCourseCatalog')
+);
+$form->addElement(
+    'number',
+    'price',
+    [$plugin->get_lang('Price'), null, $currencyIso],
+    ['step' => 0.01]
+);
+$beneficiariesSelect = $form->addSelect(
+    'beneficiaries',
+    $plugin->get_lang('Beneficiaries'),
+    null,
+    ['multiple' => 'multiple']
+);
+
+if ($editingCourse) {
+    $beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers'));
+} elseif ($editingSession) {
+    $beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach'));
+    $beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach'));
+}
+
+$form->addHidden('t', null);
+$form->addHidden('i', null);
+$form->addButtonSave(get_lang('Save'));
+$form->freeze(['product_type', 'name']);
+
+if ($form->validate()) {
+    $formValues = $form->exportValues();
+    $productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']);
+
+    if (isset($formValues['visible'])) {
+        if (!empty($productItem)) {
+            $plugin->updateItem(
+                ['price' => floatval($formValues['price'])],
+                $formValues['i'],
+                $formValues['t']
+            );
+        } else {
+            $itemId = $plugin->registerItem([
+                'currency_id' => $currency['id'],
+                'product_type' => $formValues['t'],
+                'product_id' => intval($formValues['i']),
+                'price' => floatval($_POST['price'])
+            ]);
+            $productItem['id'] = $itemId;
+        }
+
+        $plugin->deleteItemBeneficiaries($productItem['id']);
+
+        if (isset($formValues['beneficiaries'])) {
+            $plugin->registerItemBeneficiaries($productItem['id'], $formValues['beneficiaries']);
+        }
+    } else {
+        $plugin->deleteItem($productItem['id']);
+    }
+
+    header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/configuration.php');
+    exit;
+}
+
+$form->setDefaults($formDefaults);
+
+//View
+$templateName = $plugin->get_lang('AvailableCourse');
+
+$interbreadcrumb[] = [
+    'url' => 'paymentsetup.php',
+    'name' => get_lang('Configuration')
+];
+$interbreadcrumb[] = [
+    'url' => 'configuration.php',
+    'name' => $plugin->get_lang('AvailableCourses')
+];
+
+$template = new Template($templateName);
+$template->assign('header', $templateName);
+$template->assign('content', $form->returnForm());
+$template->display_one_col_template();

+ 0 - 85
plugin/buycourses/src/function.php

@@ -1,85 +0,0 @@
-<?php
-/* For license terms, see /license.txt */
-/**
- * Functions for the Buy Courses plugin
- * @package chamilo.plugin.buycourses
- */
-/**
- * Init
- */
-require_once '../config.php';
-
-$itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
-
-$plugin = BuyCoursesPlugin::create();
-$currency = $plugin->getSelectedCurrency();
-
-if ($_REQUEST['tab'] == 'save_mod') {
-    if (isset($_REQUEST['course_id'])) {
-        $productId = $_REQUEST['course_id'];
-        $productType = BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
-    } else {
-        $productId = $_REQUEST['session_id'];
-        $productType = BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
-    }
-
-    $affectedRows = false;
-
-    if ($_POST['visible'] == 1) {
-        $item = Database::select(
-            'COUNT(1) AS qty',
-            $itemTable,
-            [
-                'where' => [
-                    'product_id = ? AND ' => intval($productId),
-                    'product_type = ?' => $productType
-                ]
-            ],
-            'first'
-        );
-
-        if ($item['qty'] > 0) {
-            $affectedRows = Database::update(
-                $itemTable,
-                ['price' => floatval($_POST['price'])],
-                [
-                    'product_id = ? AND ' => intval($productId),
-                    'product_type' => $productType
-                ]
-            );
-        } else {
-            $affectedRows = Database::insert(
-                $itemTable,
-                [
-                    'currency_id' => $currency['id'],
-                    'product_type' => $productType,
-                    'product_id' => intval($productId),
-                    'price' => floatval($_POST['price'])
-                ]
-            );
-        }
-    } else {
-        $affectedRows = Database::delete(
-            $itemTable,
-            [
-                'product_id = ? AND ' => intval($productId),
-                'product_type = ?' => $productType
-            ]
-        );
-    }
-
-    if ($affectedRows > 0) {
-        $jsonResult = [
-            "status" => true,
-            "itemId" => $productId
-        ];
-    } else {
-        $jsonResult = [
-            "status" => false,
-            "content" => $plugin->get_lang('ItemNotSaved')
-        ];
-    }
-
-    echo json_encode($jsonResult);
-    exit;
-}

+ 0 - 1
plugin/buycourses/src/index.buycourses.php

@@ -21,7 +21,6 @@ if ($guess_enable == "true" || isset($_SESSION['_user'])) {
 
     $content = $tpl->fetch('buycourses/view/index.tpl');
 
-    $tpl->assign('header', $plugin->get_lang('plugin_title'));
     $tpl->assign('content', $content);
 
     $tpl->display_one_col_template();

+ 39 - 6
plugin/buycourses/src/sales_report.php

@@ -1,4 +1,5 @@
 <?php
+
 /* For license terms, see /license.txt */
 /**
  * List of pending payments of the Buy Courses plugin
@@ -35,7 +36,7 @@ if (isset($_GET['order'])) {
 
             $urlToRedirect .= http_build_query([
                 'status' => BuyCoursesPlugin::SALE_STATUS_COMPLETED,
-                'sale' =>  $sale['id']
+                'sale' => $sale['id']
             ]);
             break;
         case 'cancel':
@@ -50,7 +51,7 @@ if (isset($_GET['order'])) {
 
             $urlToRedirect .= http_build_query([
                 'status' => BuyCoursesPlugin::SALE_STATUS_CANCELED,
-                'sale' =>  $sale['id']
+                'sale' => $sale['id']
             ]);
             break;
     }
@@ -61,24 +62,55 @@ if (isset($_GET['order'])) {
 
 $productTypes = $plugin->getProductTypes();
 $saleStatuses = $plugin->getSaleStatuses();
+$paymentTypes = $plugin->getPaymentTypes();
+
+$selectedFilterType = '0';
 $selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
 $selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0;
+$searchTerm = '';
 
 $form = new FormValidator('search', 'get');
 
 if ($form->validate()) {
+    $selectedFilterType = $form->getSubmitValue('filter_type');
     $selectedStatus = $form->getSubmitValue('status');
+    $searchTerm = $form->getSubmitValue('user');
 
     if ($selectedStatus === false) {
         $selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
     }
+
+    if ($selectedFilterType === false) {
+        $selectedFilterType = '0';
+    }
 }
 
+$form->addRadio(
+    'filter_type',
+    get_lang('FilterBy'),
+    [$plugin->get_lang('ByStatus'), $plugin->get_lang('ByUser')]
+);
+$form->addHtml('<div id="report-by-status" ' . ($selectedFilterType !== '0' ? 'style="display:none"' : '') . '>');
 $form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses);
+$form->addHtml('</div>');
+$form->addHtml('<div id="report-by-user" ' . ($selectedFilterType !== '1' ? 'style="display:none"' : '') . '>');
+$form->addText('user', get_lang('UserName'), false);
+$form->addHtml('</div>');
 $form->addButtonFilter($plugin->get_lang('SearchByStatus'));
-$form->setDefaults(['status' => $selectedStatus]);
+$form->setDefaults([
+    'filter_type' => $selectedFilterType,
+    'status' => $selectedStatus
+]);
+
+switch ($selectedFilterType) {
+    case '0':
+        $sales = $plugin->getSaleListByStatus($selectedStatus);
+        break;
+    case '1':
+        $sales = $plugin->getSaleListByUser($searchTerm);
+        break;
+}
 
-$sales = $plugin->getSaleListByStatus($selectedStatus);
 $saleList = [];
 
 foreach ($sales as $sale) {
@@ -86,12 +118,13 @@ foreach ($sales as $sale) {
         'id' => $sale['id'],
         'reference' => $sale['reference'],
         'status' => $sale['status'],
-        'date' => api_format_date($sale['date'], DATE_FORMAT_LONG_NO_DAY),
+        'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
         'currency' => $sale['iso_code'],
         'price' => $sale['price'],
         'product_name' => $sale['product_name'],
         'product_type' => $productTypes[$sale['product_type']],
-        'complete_user_name' => api_get_person_name($sale['firstname'], $sale['lastname'])
+        'complete_user_name' => api_get_person_name($sale['firstname'], $sale['lastname']),
+        'payment_type' => $paymentTypes[$sale['payment_type']]
     ];
 }
 

+ 4 - 4
plugin/buycourses/view/catalog.tpl

@@ -23,7 +23,7 @@
                         {% if showing_courses %}
                             {% for course in courses %}
                                 <div class="col-md-4 col-sm-6">
-                                    <div class="thumbnail">
+                                    <article class="thumbnail">
                                         <img alt="{{ course.title }}" class="img-responsive" src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}">
                                         <div class="caption">
                                             {% set course_description_url = _p.web_ajax ~ 'course_home.ajax.php?' ~ {'code': course.code, 'a': 'show_course_information'}|url_encode() %}
@@ -53,7 +53,7 @@
                                                 <div class="alert alert-info">{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}</div>
                                             {% endif %}
                                         </div>
-                                    </div>
+                                    </article>
                                 </div>
                             {% endfor %}
                         {% endif %}
@@ -61,7 +61,7 @@
                         {% if showing_sessions %}
                             {% for session in sessions %}
                                 <div class="col-md-4 col-sm-6">
-                                    <div class="thumbnail">
+                                    <article class="thumbnail">
                                         <img alt="{{ session.name }}" class="img-responsive" src="{{ session.image ? session.image : 'session_default.png'|icon() }}">
                                         <div class="caption">
                                             <h3>
@@ -100,7 +100,7 @@
                                                 <div class="alert alert-info">{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}</div>
                                             {% endif %}
                                         </div>
-                                    </div>
+                                    </article>
                                 </div>
                             {% endfor %}
                         {% endif %}

+ 19 - 33
plugin/buycourses/view/configuration.tpl

@@ -21,9 +21,9 @@
                     <tr>
                         <th>{{ 'Title'|get_lang }}</th>
                         <th class="text-center">{{ 'OfficialCode'|get_lang }}</th>
-                        <th class="text-center">{{ 'Visible'|get_lang }}</th>
+                        <th class="text-center">{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                         <th class="text-right" width="200">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
-                        <th class="text-right">{{ 'Option'|get_lang }}</th>
+                        <th class="text-right">{{ 'Options  '|get_lang }}</th>
                     </tr>
                 </thead>
 
@@ -50,26 +50,19 @@
                                 {{ item.course_code }}
                             </td>
                             <td class="text-center">
-                                {% if item.visible == 1 %}
-                                    <input type="checkbox" name="visible" value="1" checked="checked" size="6">
+                                {% if item.visible %}
+                                    <i class="fa fa-fw fa-check-square-o"></i>
                                 {% else %}
-                                    <input type="checkbox" name="visible" value="1" size="6">
+                                    <i class="fa fa-fw fa-square-o"></i>
                                 {% endif %}
                             </td>
-                            <td width="200">
-                                {% if item.currency %}
-                                    <div class="input-group">
-                                        <span class="input-group-addon" id="price-{{ item.course_id }}">{{ item.currency }}</span>
-                                        <input type="number" name="price" value="{{ item.price }}" step="0.01" min="0" class="text-right form-control" aria-describedby="price-{{ item.course_id }}">
-                                    </div>
-                                {% else %}
-                                    <input type="number" name="price" value="{{ item.price }}" step="0.01" min="0" class="text-right form-control">
-                                {% endif %}
+                            <td width="200" class="text-right">
+                                {{ "#{item.price} #{tem.currency ?: item.currency}" }}
                             </td>
                             <td class="text-right">
-                                <button class="btn btn-success btn-sm bc-button-save" type="button">
-                                    <i class="fa fa-save"></i> {{ 'Save'|get_lang }}
-                                </button>
+                                <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'i': item.course_id, 't':product_type_course}|url_encode() }}" class="btn btn-info btn-sm">
+                                    <i class="fa fa-wrench fa-fw"></i> {{ 'Configure'|get_lang }}
+                                </a>
                             </td>
                         </tr>
                     {% endfor %}
@@ -87,9 +80,9 @@
                             <th>{{ 'Title'|get_lang }}</th>
                             <th class="text-center">{{ 'StartDate'|get_lang }}</th>
                             <th class="text-center">{{ 'EndDate'|get_lang }}</th>
-                            <th class="text-center">{{ 'Visible'|get_lang }}</th>
+                            <th class="text-center">{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                             <th class="text-right">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
-                            <th class="text-right">{{ 'Option'|get_lang }}</th>
+                            <th class="text-right">{{ 'Options'|get_lang }}</th>
                         </tr>
                     </thead>
                     <tbody>
@@ -118,25 +111,18 @@
                                 </td>
                                 <td class="text-center">
                                     {% if item.visible %}
-                                        <input type="checkbox" name="visible" value="1" checked="checked" size="6" />
+                                        <i class="fa fa-fw fa-check-square-o"></i>
                                     {% else %}
-                                        <input type="checkbox" name="visible" value="1" size="6" />
+                                        <i class="fa fa-fw fa-square-o"></i>
                                     {% endif %}
                                 </td>
                                 <td class="text-right" width="200">
-                                    {% if item.currency %}
-                                        <div class="input-group">
-                                            <span class="input-group-addon" id="price-{{ item.session_id }}">{{ item.currency }}</span>
-                                            <input type="number" name="price" value="{{ item.price }}" step="0.01" min="0" class="text-right form-control" aria-describedby="price-{{ item.session_id }}">
-                                        </div>
-                                    {% else %}
-                                        <input type="number" name="price" value="{{ item.price }}" step="0.01" min="0" class="text-right form-control">
-                                    {% endif %}
+                                    {{ "#{item.price} #{tem.currency ?: item.currency}" }}
                                 </td>
-                                <td class=" text-center" id="session{{ item.session_id }}">
-                                    <button class="btn btn-success btn-sm bc-button-save" type="button">
-                                        <i class="fa fa-save"></i> {{ 'Save'|get_lang }}
-                                    </button>
+                                <td class="text-right">
+                                    <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'i': item.session_id, 't': product_type_session}|url_encode() }}" class="btn btn-info btn-sm">
+                                        <i class="fa fa-wrench fa-fw"></i> {{ 'Configure'|get_lang }}
+                                    </a>
                                 </td>
                             </tr>
                         {% endfor %}

+ 65 - 70
plugin/buycourses/view/index.tpl

@@ -1,80 +1,75 @@
 <link rel="stylesheet" type="text/css" href="resources/css/style.css"/>
+{% if _u.is_admin %}
+    <div class="row">
+        <div class="col-md-12">
+            <article class="jumbotron">
+                <h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
+                <p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p>
+                <ul class="list-unstyled">
+                    <li>
+                        {{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }}
+                        <ul>
+                            <li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li>
+                            <li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li>
+                            <li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li>
+                        </ul>
+                    </li>
+                </ul>
+            </article>
+        </div>
+    </div>
+{% endif %}
+
 <div class="row">
-    <div class="col-md-12">
-        {% if _u.is_admin %}
-            <div class="help-bycourse">
-                <div class="row">
-                    <div class="col-md-7">
-                        <div class="panel panel-default">
-                            <div class="panel-body">
-                                <h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
-                                <p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p>
-                                <p>&nbsp;</p>
-                            </div>
-                        </div>
-                    </div>
-                    <div class="col-md-5">
-                        <div class="panel panel-default">
-                            <div class="panel-heading">
-                                {{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }}
-                            </div>
-                            <div class="panel-body">
-                                <ul>
-                                    <li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li>
-                                    <li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li>
-                                    <li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li>
-                                </ul>
-                            </div>
-                        </div>
-                    </div>
-                </div>
+    <div class="col-md-3">
+        <div class="thumbnail">
+            <a href="src/course_catalog.php">
+                <img src="resources/img/128/buycourses.png">
+            </a>
+            <div class="caption">
+                <p class="text-center">
+                    <a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a>
+                </p>
             </div>
-        {% endif %}
+        </div>
+    </div>
 
-        <div class="row">
-            <div class="col-md-3">
-                <div class="thumbnail">
-                    <a href="src/course_catalog.php">
-                        <img src="resources/img/128/buycourses.png">
-                    </a>
-                    <div class="caption"  align="center">
-                        <a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a>
-                    </div>
+    {% if _u.is_admin %}
+        <div class="col-md-3">
+            <div class="thumbnail">
+                <a href="src/configuration.php">
+                    <img src="resources/img/128/settings.png">
+                </a>
+                <div class="caption">
+                    <p class="text-center">
+                        <a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a>
+                    </p>
                 </div>
             </div>
-
-            {% if _u.is_admin %}
-                <div class="col-md-3">
-                    <div class="thumbnail">
-                        <a href="src/configuration.php">
-                            <img src="resources/img/128/settings.png">
-                        </a>
-                        <div class="caption"  align="center">
-                            <a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a>
-                        </div>
-                    </div>
-                </div>
-                <div class="col-md-3">
-                    <div class="thumbnail">
-                        <a href="src/paymentsetup.php">
-                            <img src="resources/img/128/paymentsettings.png">
-                        </a>
-                        <div class="caption" align="center">
-                            <a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }} </a>
-                        </div>
-                    </div>
+        </div>
+        <div class="col-md-3">
+            <div class="thumbnail">
+                <a href="src/paymentsetup.php">
+                    <img src="resources/img/128/paymentsettings.png">
+                </a>
+                <div class="caption">
+                    <p class="text-center">
+                        <a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }}</a>
+                    </p>
                 </div>
-                <div class="col-md-3">
-                    <div class="thumbnail">
-                        <a href="src/sales_report.php">
-                            <img src="resources/img/128/backlogs.png">
-                        </a>
-                        <div class="caption"  align="center">
-                            <a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }} </a>
-                        </div>
-                    </div>
+            </div>
+        </div>
+        <div class="col-md-3">
+            <div class="thumbnail">
+                <a href="src/sales_report.php">
+                    <img src="resources/img/128/backlogs.png">
+                </a>
+                <div class="caption">
+                    <p class="text-center">
+                        <a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }}</a>
+                    </p>
                 </div>
-            {% endif %}
+            </div>
         </div>
-    </div>
+    {% endif %}
 </div>

+ 29 - 15
plugin/buycourses/view/sales_report.tpl

@@ -7,13 +7,12 @@
                 <th class="text-center">{{ 'OrderReference'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-center">{{ 'OrderStatus'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-center">{{ 'OrderDate'|get_plugin_lang('BuyCoursesPlugin') }}</th>
+                <th class="text-center">{{ 'PaymentMethod'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-center">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-center">{{ 'ProductType'|get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th>{{ 'Name'|get_lang }}</th>
                 <th>{{ 'UserName'|get_lang }}</th>
-                {% if selected_status == sale_status_pending %}
-                    <th class="text-center">{{ 'Options'|get_lang }}</th>
-                {% endif %}
+                <th class="text-center">{{ 'Options'|get_lang }}</th>
             </tr>
         </thead>
         <tbody>
@@ -30,24 +29,39 @@
                         {% endif %}
                     </td>
                     <td class="text-center">{{ sale.date }}</td>
+                    <td class="text-center">{{ sale.payment_type }}</td>
                     <td class="text-right">{{ sale.currency ~ ' ' ~ sale.price }}</td>
                     <td class="text-center">{{ sale.product_type }}</td>
                     <td>{{ sale.product_name }}</td>
                     <td>{{ sale.complete_user_name }}</td>
-                    {% if selected_status == sale_status_pending %}
-                        <td class="text-center">
-                            {% if sale.status == sale_status_pending %}
-                                <a href="{{ _p.web_self ~ '?' ~ {'order': sale.id, 'action': 'confirm'}|url_encode() }}" class="btn btn-success btn-sm">
-                                    <i class="fa fa-user-plus fa-fw"></i> {{ 'SubscribeUser'|get_plugin_lang('BuyCoursesPlugin') }}
-                                </a>
-                                <a href="{{ _p.web_self ~ '?' ~ {'order': sale.id, 'action': 'cancel'}|url_encode() }}" class="btn btn-danger btn-sm">
-                                    <i class="fa fa-times fa-fw"></i> {{ 'DeleteOrder'|get_plugin_lang('BuyCoursesPlugin') }}
-                                </a>
-                            {% endif %}
-                        </td>
-                    {% endif %}
+                    <td class="text-center">
+                        {% if sale.status == sale_status_pending %}
+                            <a href="{{ _p.web_self ~ '?' ~ {'order': sale.id, 'action': 'confirm'}|url_encode() }}" class="btn btn-success btn-sm">
+                                <i class="fa fa-user-plus fa-fw"></i> {{ 'SubscribeUser'|get_plugin_lang('BuyCoursesPlugin') }}
+                            </a>
+                            <a href="{{ _p.web_self ~ '?' ~ {'order': sale.id, 'action': 'cancel'}|url_encode() }}" class="btn btn-danger btn-sm">
+                                <i class="fa fa-times fa-fw"></i> {{ 'DeleteOrder'|get_plugin_lang('BuyCoursesPlugin') }}
+                            </a>
+                        {% endif %}
+                    </td>
                 </tr>
             {% endfor %}
         </tbody>
     </table>
 </div>
+
+<script>
+    $(document).on('ready', function () {
+        $('[name="filter_type"]').on('change', function () {
+            var self = $(this);
+
+            if (self.val() === '0') {
+                $('#report-by-user').hide();
+                $('#report-by-status').show();
+            } else {
+                $('#report-by-status').hide();
+                $('#report-by-user').show();
+            }
+        });
+    });
+</script>