Templates: modified routing logic, added data attributes in template

Co-authored-by: Chinmay Pai <chinmaydpai@gmail.com>
diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html
index 3acc76e..182efab 100644
--- a/erpnext/www/lms/course.html
+++ b/erpnext/www/lms/course.html
@@ -8,11 +8,12 @@
 <meta name="keywords" content="ERP Software, Cloud ERP, Open Source ERP, Accounting Software, Online ERP, Online Accounting, ERP for small business, Learn ERP, ERPNext Academy, Learn ERPNext, Learn Accounting" />
 {% endblock %}
 
-
 {% block content %}
-{% with current_content = current_content %}
+<div id="content-holder" data-type="{{current_content.content_type}}" data-content="{{ current_content.name }}" data-course="{{ current_course.name }}" data-program="{{ current_program }}">
+{% with current_content = current_content, next_content = next_content, course_name = current_course.name, program=current_program%}
 {% include "www/lms/templates/includes/" + current_content.content_type.lower() + ".html" %}
 {% endwith %}
+</div>
 <style>
     .footer-message {
         display: none;
@@ -35,6 +36,10 @@
     .article-content-section {
         padding-top: 0em !important;
     }
+
+    .quiz-section {
+        padding-top: 0rem !important;
+    }
 </style>
 
 {% endblock %}
\ No newline at end of file
diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py
index ff7073d..0276102 100644
--- a/erpnext/www/lms/course.py
+++ b/erpnext/www/lms/course.py
@@ -3,6 +3,17 @@
 
 
 def get_context(context):
-    context.current_course = frappe.get_doc("Course", frappe.form_dict["course"])
-    context.current_content = frappe.get_doc("Content", frappe.form_dict["content"])
-    next_content = get_next_content()
\ No newline at end of file
+    if frappe.form_dict['course']:
+        context.current_course = frappe.get_doc("Course", frappe.form_dict["course"])
+        context.current_content = frappe.get_doc("Content", frappe.form_dict["content"])
+        context.current_program = frappe.form_dict["program"]
+        context.next_content = get_next_content(context)
+
+
+def get_next_content(context):
+    if context.current_course:
+        course_data = [content_item.content for content_item in context.current_course.course_content]
+        try: 
+            return course_data[course_data.index(context.current_content.name) + 1]
+        except IndexError:
+            return None
\ No newline at end of file
diff --git a/erpnext/www/lms/index.html b/erpnext/www/lms/index.html
index 1974d4f..444bbde 100644
--- a/erpnext/www/lms/index.html
+++ b/erpnext/www/lms/index.html
@@ -13,7 +13,7 @@
 	<div class="card">
 		<img src="{{ hero_image }}" style='height: 150px'>
 		<div class='card-body'>
-			<a href="/lms/program?code={{ code }}">
+			<a href="/lms/program?program={{ code }}">
 				<h5 class='card-title'>{{ program_name }}</h5>
 			</a>
 			<div>{{ description }}</div>
diff --git a/erpnext/www/lms/program.html b/erpnext/www/lms/program.html
index 449c040..23f2e5c 100644
--- a/erpnext/www/lms/program.html
+++ b/erpnext/www/lms/program.html
@@ -22,7 +22,7 @@
                 </span>
             </div>
             <div class='text-center col-xs-4 col-sm-3 col-md-2'>
-                <a class='btn btn-primary btn-sm btn-block' href="/lms/course?course={{ name }}&content=ERPNext Introduction">Start Course</a>
+                <a class='btn btn-primary btn-sm btn-block' href="/lms/course?program={{ program.program_code }}&course={{ name }}&content={{ course_data[name][0] }}">Start Course</a>
             </div>
         </div>
     </div>
diff --git a/erpnext/www/lms/program.py b/erpnext/www/lms/program.py
index b6ebcf4..c61aee5 100644
--- a/erpnext/www/lms/program.py
+++ b/erpnext/www/lms/program.py
@@ -1,9 +1,11 @@
 from __future__ import unicode_literals
+from erpnext.education.utils import get_student_name
 import frappe
 
 
 def get_context(context):
-    context.program = frappe.get_doc("Program", frappe.form_dict["code"])
+    print(get_student_name(frappe.session.user))
+    context.program = frappe.get_doc("Program", frappe.form_dict["program"])
     context.course_list, context.course_data = get_courses(context)
 
 def get_courses(context):
diff --git a/erpnext/www/lms/templates/includes/article.html b/erpnext/www/lms/templates/includes/article.html
index f9fd6e0..2ca93fa 100644
--- a/erpnext/www/lms/templates/includes/article.html
+++ b/erpnext/www/lms/templates/includes/article.html
@@ -10,7 +10,11 @@
                 </div>
                 <div class="col-md-4 text-right">
                     <a class='btn btn-outline-secondary' href="#">Previous</a>
-                    <a class='btn btn-primary' href="#s">Next</a>
+                    {% if next_content != None %}
+                    <a class='btn btn-primary' onclick="addActivity()" href="/lms/course?program={{ program }}&course={{ course_name }}&content={{ next_content }}">Next</a>
+                    {% else %}
+                    <a class='btn btn-primary' onclick="addActivity()" href="/lms/program?program={{ program }}">Finish Course</a>
+                    {% endif %}
                 </div>
             </div>
             <hr>
@@ -23,7 +27,7 @@
             </div>
             <div class="text-right hidden">
                 <a class='btn btn-outline-secondary' href="/classrooms/module">Previous</a>
-                <a class='btn btn-primary' href="/classrooms/module">Next</a>
+                <a class='btn btn-primary' href="/lms/course?program={{ program }}&course={{ course_name }}&content={{ next_content }}">Next</a>
             </div>
             <div class="mt-3 text-right">
                 <a class="text-muted" href="/report"><i class="octicon octicon-issue-opened" title="Report"></i> Report a
diff --git a/erpnext/www/lms/templates/includes/quiz.html b/erpnext/www/lms/templates/includes/quiz.html
index 97a2e68..280a17b 100644
--- a/erpnext/www/lms/templates/includes/quiz.html
+++ b/erpnext/www/lms/templates/includes/quiz.html
@@ -1,56 +1,62 @@
-{% macro quiz(question, opt1, opt2, opt3, opt4) %}
-<div class="question mt-4">
-        <h5>{{ question }}</h5>
-        <div class="options ml-2">
-            <div class="form-check pb-1">
-                <input class="form-check-input" type="radio" name="{{ question }}" id="{{ opt1 }}" value="{{ opt1 }}">
-                <label class="form-check-label" for="{{ opt1 }}">
-                    {{ opt1 }}
-                </label>
-            </div>
-            <div class="form-check pb-1">
-                <input class="form-check-input" type="radio" name="{{ question }}" id="{{ opt2 }}" value="{{ opt2 }}">
-                <label class="form-check-label" for="{{ opt2 }}">
-                    {{ opt2 }}
-                </label>
-            </div>
-            <div class="form-check pb-1">
-                <input class="form-check-input" type="radio" name="{{ question }}" id="{{ opt3 }}" value="{{ opt3 }}">
-                <label class="form-check-label" for="{{ opt3 }}">
-                    {{ opt3 }}
-                </label>
-            </div>
-            <div class="form-check pb-1">
-                <input class="form-check-input" type="radio" name="{{ question }}" id="{{ opt3 }}" value="{{ opt4 }}">
-                <label class="form-check-label" for="{{ opt3 }}">
-                    {{ opt4 }}
-                </label>
-            </div>
+{% macro quiz(loop_index, question_id, question, options) %}
+<div class="question mt-4" id="question" data-question="{{ question_id }}">
+    <h5>{{ loop_index }}{{ question }}</h5>
+    <div class="options ml-2">
+        <div class="form-check pb-1 hidden">
+            <input class="form-check-input" type="radio" name="{{ question_id }}" value="0" checked>
         </div>
+        {% for option in options %}
+        <div class="form-check pb-1">
+            <input class="form-check-input" type="radio" name="{{ question_id }}" id="{{loop_index}}-{{ option }}" value="{{ loop.index|str }}">
+            <label class="form-check-label" for="{{loop_index}}-{{ option }}">
+                {{ option }}
+            </label>
+        </div>
+        {% endfor %}
     </div>
+</div>
 {% endmacro %}
 
-<section class="article-section">
-        <div class='container'>
-            <div class="mt-3 row">
-                <div class="col-md-8">
-                    <h2>Quiz &mdash; Accounting with ERPNext</h2>
-                </div>
-            </div>
-            <div class="content">
-                <hr>
-                <form>
-                    {{ quiz('1. What is a Sales Invoice?','The bills that you raise to your Customers for the products or services you provide.','Bills that your Suppliers give you for their products or services.','The bills for accounting entries, like payments, credit and other types.','The bills that were recovered from an oblivion of files and folders stacked in a old and rusty closet.') }}
-                    {{ quiz('2. How to create a Sales Invoice?','Accounts > Billing > Sales Invoice > New Sales Invoice','Accounts > Buying > New Sales Invoice','Accounts > CRM > New Sales Invoice','Accounts > Purchases > New Sales Invoice') }}
-                    {{ quiz('3. The long term assets that have no physical existence but are rights that have value is known as','Current Assets','Fixed Assets','Intangible Assets','Investments') }}
-                    <div class="text-right">
-                        <button class='btn btn-outline-secondary' type="reset">Reset</button>
-                        <button class='btn btn-primary' type="submit">Submit</button>
-                    </div>
-                </form>
-            </div>
-            <div class="mt-3 text-right">
-                <a class="text-muted" href="/report"><i class="octicon octicon-issue-opened" title="Report"></i> Report a Mistake</a>
+<section class="quiz-section">
+    <div class='container'>
+        <div class="mt-3 row">
+            <div class="col-md-8">
+                <h2>Quiz: {{ current_content.name }}</h2>
             </div>
         </div>
-    </section>
\ No newline at end of file
+        <div class="content">
+            <hr>
+            <form id="quiz" name="{{ current_content.name }}">
+                <div id="quiz-body">
+                    {% for quiz_item in current_content.quiz %}
+                    {{ quiz(loop.index|str +". ", quiz_item.name, quiz_item.question, [ quiz_item.option_1, quiz_item.option_2,
+                    quiz_item.option_3, quiz_item.option_4]) }}
+                    {% endfor %}
+                </div>
+                <div class="mt-3">
+                    <div id="quiz-actions" class="text-right">
+                        <button class='btn btn-outline-secondary' type="reset">Reset</button>
+                        <button class='btn btn-primary' type="button" onclick="submitQuiz()">Submit</button>
+                    </div>
+                    <div id="post-quiz-actions" class="row" hidden="hidden">
+                        <div class="col-md-8 text-left">
+                            <h3>Your Score: <span id="result"></span></h3>
+                        </div>
+                        <div class="col-md-4 text-right">
+                                <a class='btn btn-outline-secondary' href="#">Previous</a>
+                                {% if next_content != None %}
+                                <a class='btn btn-primary' href="/lms/course?program={{ program }}&course={{ course_name }}&content={{ next_content }}">Next</a>
+                                {% else %}
+                                <a class='btn btn-primary' href="/lms/program?program={{ program }}">Finish Course</a>
+                                {% endif %}
+                        </div>
+                    </div>
+                </div>
+            </form>
+        </div>
+        <div class="mt-3 text-right">
+            <a class="text-muted" href="/report"><i class="octicon octicon-issue-opened" title="Report"></i> Report a
+                Mistake</a>
+        </div>
+    </div>
+</section>
\ No newline at end of file
diff --git a/erpnext/www/lms/templates/includes/video.html b/erpnext/www/lms/templates/includes/video.html
index 77a4e6c..6727321 100644
--- a/erpnext/www/lms/templates/includes/video.html
+++ b/erpnext/www/lms/templates/includes/video.html
@@ -13,7 +13,11 @@
             </div>
             <div class="col-md-4 text-right">
                 <a class='btn btn-outline-secondary' href="#">Previous</a>
-                <a class='btn btn-primary' href="#s">Next</a>
+                {% if next_content != None %}
+                <a class='btn btn-primary' onclick="addActivity()" href="/lms/course?program={{ program }}&course={{ course_name }}&content={{ next_content }}">Next</a>
+                {% else %}
+                <a class='btn btn-primary' onclick="addActivity()" href="/lms/program?program={{ program }}">Finish Course</a>
+                {% endif %}
             </div>
         </div>
         <hr>