diff --git a/src/controller.py b/src/controller.py
index d890e705c9b84dc7a5010d85affd34c1e9da8c6f..fe008c34b6ef945e32da602826e1a4864e098eef 100644
--- a/src/controller.py
+++ b/src/controller.py
@@ -4,13 +4,16 @@ import sqlite3
 from register import register
 from dashboard import dashboard
 from listlatihan2 import listLatihan2
-from tesBacaDB import tesBaca
 from customize import customizeWorkout
 from plan import plan
+from plan2 import plan2
+from endOfExercise import endOfExe
+import os 
+import os.path
 class controller:
     def __init__(self):
+        self.initDatabase()
         self.conn = sqlite3.connect('fitu.db')
-        self.tesBacaDB = tesBaca()
         self.registerWin = register()
         self.registerWin.switch.connect(self.fromRegister)
         self.dashboard = dashboard()
@@ -20,7 +23,12 @@ class controller:
         self.customize = customizeWorkout()
         self.customize.switch.connect(self.fromCustomize)
         self.plan = plan()
-        # self.plan.switch.connect(self.fromPlan)
+        self.plan.switch.connect(self.fromPlan)
+        self.plan2 = plan2(1)
+        self.plan.switch.connect(self.toPlan2)
+        self.endOfExe = endOfExe()
+        self.endOfExe.switch.connect(self.toEndOfExe)
+        self.endOfExe.switch.connect(self.fromEndOfExe)
         pass
 
         
@@ -36,6 +44,8 @@ class controller:
 
     def fromRegister(self):
         self.registerWin.close()
+        self.dashboard = dashboard()
+        self.dashboard.switch.connect(self.fromDashboard)
         self.dashboard.show()
 
     def fromDashboard(self, page):
@@ -58,7 +68,7 @@ class controller:
         elif (page == "plan"):
             self.plan.show()
 
-    def fromPlan(self, page):
+    def fromPlan(self, page, program_id):
         self.plan.close()
         if (page == "dashboard"):
             self.dashboard.show()
@@ -76,6 +86,160 @@ class controller:
         elif (page == "plan"):
             self.plan.show()
 
+    def toPlan2(self, page, program_id):
+        self.plan.close()
+        if (page == "plan2"):
+            print("ctrl" + str(program_id))
+            self.plan2 = plan2(program_id)
+            self.plan2.switch.connect(self.toEndOfExe)
+            self.plan2.show()
+
+    def toEndOfExe(self,page):
+        self.plan2.close()
+        if (page == "endOfExe"):
+            self.endOfExe.show()
+
+    def fromEndOfExe(self,page):
+        self.endOfExe.close()
+        if (page == "dashboard"):
+            self.dashboard.show()
+
+    def initDatabase(self):
+        if not os.path.exists("fitu.db"):
+            self.con = sqlite3.connect("fitu.db")
+            cur = self.con.cursor()
+
+            cur.execute("""
+                        CREATE TABLE IF NOT EXISTS user (
+                        name text PRIMARY KEY,
+                        height integer,
+                        weight integer,
+                        goal text,
+                        gender text,
+                        age integer
+                        )
+                        """)
+            cur.execute("""
+                        CREATE TABLE IF NOT EXISTS daftar_latihan (
+                        exercise_id integer PRIMARY KEY,
+                        title text,
+                        description text,
+                        goals text,
+                        duration integer,
+                        repetition integer,
+                        gif text
+                        )
+                        """)
+
+            cur.execute("""
+                        CREATE TABLE IF NOT EXISTS riwayat_latihan (
+                        history_id integer PRIMARY KEY AUTOINCREMENT,
+                        program_id integer,
+                        name text,
+                        title_program text,
+                        calories integer,
+                        date text,
+                        tot_duration integer
+                        )
+                        """)
+            cur.execute("""
+                        CREATE TABLE IF NOT EXISTS program (
+                        program_id integer PRIMARY KEY AUTOINCREMENT,
+                        title_program text
+                        )
+                        """)
+
+            cur.execute("""
+                        CREATE TABLE IF NOT EXISTS latihan_program (
+                        program_id integer,
+                        exercise_id integer,
+                        FOREIGN KEY (program_id) REFERENCES program (program_id)
+                        )
+                        """)
+
+            cur.execute("""
+                        INSERT or IGNORE INTO daftar_latihan 
+                            (exercise_id, title, description, goals, duration, repetition, gif)
+                        VALUES 
+                            (101, "Jumping Rope", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/"),
+                            (102, "Running", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/"),
+                            (103, "Jumping Jacks", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-jumpingjack.gif"),
+                            (104, "Plank", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-plank.gif"),
+                            (105, "Bridge", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-bridges.gif"),
+                            (106, "High Knees", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-highknee.gif"),
+                            (107, "Mountain Climber", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-mountain.gif"),
+                            (108, "Russian Twist", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL,"img/exe-russian.gif"),
+                            (201, 'Push Up', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor','Goals', NULL, 10, 'img/exe-pushup.gif'),
+                            (202, "Sit Up", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-situp.gif"),
+                            (203, "Pull Up", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/"),
+                            (204, "Squat Jump", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/"),
+                            (205, "Lunges", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-lunges.gif"),
+                            (206, "Crunches", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-crunches.gif"),
+                            (207, "Burpees", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-burpees.gif"),
+                            (208, "Bicycle Crunch", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-bicycle.gif")
+                        """)
+
+            cur.execute("""
+                        INSERT or IGNORE INTO program
+                            (program_id, title_program)
+                        VALUES
+                            (1, 'Full Body Workout'),
+                            (2, 'Upper Body Workout'),
+                            (3, 'Lower Body Workout'),
+                            (4, 'Core Workout')
+                        """)
+
+            cur.execute("""
+                        INSERT or IGNORE INTO latihan_program
+                            (program_id, exercise_id)
+                        VALUES
+                            (1, 201),
+                            (1, 105),
+                            (1, 106),
+                            (1, 202),
+                            (2, 104),
+                            (2, 107),
+                            (2, 108),
+                            (2, 201),
+                            (3, 202),
+                            (3, 205),
+                            (3, 106)
+                        """)
+            # cur.execute("""
+            #         INSERT INTO riwayat_latihan
+            #             (program_id, name, title_program, calories, date, tot_duration)
+            #         VALUES
+            #             (1, 'Push Up', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Sit Up', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Pull Up', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Squat Jump', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Lunges', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Crunches', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Burpees', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Bicycle Crunch', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Jumping Rope', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Running', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Jumping Jacks', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Plank', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Bridge', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'High Knees', 'Chest Day', 100, '2020-12-12', 30),
+            #             (1, 'Squat', 'Chest Day', 100, '2020-12-12', 30),
+            #             (2, 'Push Up', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Sit Up', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Pull Up', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Squat Jump', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Lunges', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Crunches', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Burpees', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Bicycle Crunch', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Jumping Rope', 'Leg Day', 100, '2020-12-15', 30),
+            #             (2, 'Running', 'Leg Day', 100, '2020-12-15', 30)
+            #         """)
+
+            self.con.commit()
+            self.con.close()
+        else:
+            print("Database already exists")
 if __name__ == "__main__":
     app = QApplication(sys.argv)
     controller = controller()
diff --git a/src/customize.py b/src/customize.py
index 5fce0a1d4efe51b488d4c562ea95511eaaab3883..fe903ba871feebdc6234208b0f27d5f4868f592d 100644
--- a/src/customize.py
+++ b/src/customize.py
@@ -13,7 +13,7 @@ text_color = '#EEEEE2'
 cardColor = '#D2DCC4'
 
 class customizeWorkout(QWidget):
-    switch = pyqtSignal(str, dict)
+    switch = pyqtSignal(str, int, dict)
 
     def __init__(self):
         
@@ -141,6 +141,7 @@ class customizeWorkout(QWidget):
         homeButton.move(507, 53)    
         homeButton.setCursor(
             QCursor(Qt.CursorShape.PointingHandCursor))
+        homeButton.clicked.connect(self.dashboardWindow)
         
         # tombol customize
         customizeButton = QPushButton(self)
@@ -158,6 +159,7 @@ class customizeWorkout(QWidget):
         customizeButton.move(649, 53)     
         customizeButton.setCursor(
             QCursor(Qt.CursorShape.PointingHandCursor))
+        # customizeButton.clicked.connect(self.customizeWindow)
         
         # tombol plan
         planButton = QPushButton(self)
@@ -174,6 +176,7 @@ class customizeWorkout(QWidget):
         planButton.move(807, 58)
         planButton.setCursor(
             QCursor(Qt.CursorShape.PointingHandCursor))
+        planButton.clicked.connect(self.planWindow)
 
         # tombol list
         listButton = QPushButton(self)
@@ -190,6 +193,7 @@ class customizeWorkout(QWidget):
         listButton.move(898, 58)
         listButton.setCursor(
             QCursor(Qt.CursorShape.PointingHandCursor))
+        listButton.clicked.connect(self.listWindow)
         
         # tombol history
         historyButton = QPushButton(self)
@@ -435,7 +439,15 @@ class customizeWorkout(QWidget):
         saveButton.setCursor(
             QCursor(Qt.CursorShape.PointingHandCursor))       
         saveButton.clicked.connect(saveButtonClicked)
+
+    def planWindow(self):
+        self.switch.emit("plan", self.clickedRowData, {})
+    
+    def listWindow(self):
+        self.switch.emit("listLatihan", {})
     
+    def dashboardWindow(self):
+        self.switch.emit("dashboard", {})
                 
 if __name__ == '__main__':
     app = QApplication(sys.argv)
diff --git a/src/dashboard.py b/src/dashboard.py
index a0400b24b9240c2a7f637aa8eebf4f10143e06fe..ae75dcf1334ecfa0fca32a1c13fda0d298d556a1 100644
--- a/src/dashboard.py
+++ b/src/dashboard.py
@@ -5,7 +5,7 @@ from PyQt6.QtGui import QCursor, QFont, QPixmap, QMovie
 from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QWidget, QScrollArea, QVBoxLayout, QHBoxLayout
 import sqlite3
 
-cur = sqlite3.connect("fitu.db").cursor()
+# cur = sqlite3.connect("fitu.db").cursor()
 
 background = '#5A8D6C'
 button_color = '#174728'
@@ -52,10 +52,12 @@ styleSheetCard = (
 
 
 class dashboard(QWidget):
-    switch = pyqtSignal(str, dict)
+    switch = pyqtSignal(str, int,dict)
     def __init__(self, user=None):
         super().__init__()
-        self.biodata = cur.execute("SELECT * FROM user").fetchall()
+        self.con = sqlite3.connect("fitu.db")
+        self.cur = self.con.cursor()
+        self.biodata = self.cur.execute("SELECT * FROM user").fetchall()
         print(self.biodata)
         # if (self.biodata == None):
         #     self.switch.emit('register', {})
@@ -69,7 +71,7 @@ class dashboard(QWidget):
         #     }
         # else:
         #     self.user = user
-        self.con = sqlite3.connect("fitu.db")
+        
         self.index_history = int(-1)
         self.banyaknyaKartu = int(-1)
         self.dashboardWindow()
@@ -83,9 +85,9 @@ class dashboard(QWidget):
         self.element()
 
     def historyElement(self, historyIdx, idx):
-        self.cur = self.con.cursor()
+        # self.cur = self.con.cursor()
         self.index_history = idx
-        tanggal = cur.execute(f"""
+        tanggal = self.cur.execute(f"""
             SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}'
         """).fetchone()[0]
         
@@ -94,7 +96,7 @@ class dashboard(QWidget):
         self.card.setPixmap(QPixmap('img/card-dashboard.png'))
         self.card.move(633, 172)
 
-        daftar_latihan = cur.execute(f"""
+        daftar_latihan = self.cur.execute(f"""
             SELECT name FROM riwayat_latihan WHERE date = '{tanggal}'
         """).fetchall()
 
@@ -110,7 +112,7 @@ class dashboard(QWidget):
         self.date.setFont(dateFont)
         self.date.setAlignment(Qt.AlignmentFlag.AlignLeft)
 
-        keterangan = cur.execute(f"""
+        keterangan = self.cur.execute(f"""
                 SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}'
         """).fetchone()
         self.duration = QLabel(self)
@@ -160,13 +162,13 @@ class dashboard(QWidget):
             self.label.setStyleSheet(styleSheetCard)
             self.hbox.addWidget(self.label)
             nama_latihan = daftar_latihan[j][0]
-            repetisi_latihan = cur.execute(f"""
+            repetisi_latihan = self.cur.execute(f"""
                 SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}'
             """).fetchone()
-            durasi_latihan = cur.execute(f"""
+            durasi_latihan = self.cur.execute(f"""
                 SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}'
             """).fetchone()
-            gambar_latihan = cur.execute(f"""
+            gambar_latihan = self.cur.execute(f"""
                 SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
             """).fetchone()
             self.con.commit()
@@ -187,7 +189,7 @@ class dashboard(QWidget):
             self.show_repetisi_latihan.setFont(repetisiFont)
             self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft)
 
-            self.gif = cur.execute(f"""
+            self.gif = self.cur.execute(f"""
                 SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()[0]
             self.gif2 = QMovie(self.gif)
@@ -397,7 +399,7 @@ class dashboard(QWidget):
         start.clicked.connect(self.planWindow)
 
         # membuat history card
-        historyIdx = cur.execute("""
+        historyIdx = self.cur.execute("""
                                 SELECT DISTINCT history_id FROM riwayat_latihan
                                 """).fetchall()
         
@@ -423,15 +425,15 @@ class dashboard(QWidget):
                 self.kiri.show()
                 self.kanan.show()
             self.scroll.setParent(None)
-            tanggal = cur.execute(f"""
+            tanggal = self.cur.execute(f"""
             SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}'
         """).fetchone()[0]
             self.date.setText(f"{tanggal}")
-            daftar_latihan = cur.execute(f"""
+            daftar_latihan = self.cur.execute(f"""
                 SELECT name FROM riwayat_latihan WHERE date = '{tanggal}'
                 """).fetchall()
             jumlahCard = len(daftar_latihan)
-            keterangan = cur.execute(f"""
+            keterangan = self.cur.execute(f"""
                 SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}'
                 """).fetchone()
             
@@ -473,13 +475,13 @@ class dashboard(QWidget):
                 self.label.setStyleSheet(styleSheetCard)
                 self.hbox.addWidget(self.label)
                 nama_latihan = daftar_latihan[j][0]
-                repetisi_latihan = cur.execute(f"""
+                repetisi_latihan = self.cur.execute(f"""
                     SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
-                durasi_latihan = cur.execute(f"""
+                durasi_latihan = self.cur.execute(f"""
                     SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
-                gambar_latihan = cur.execute(f"""
+                gambar_latihan = self.cur.execute(f"""
                     SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
                 self.con.commit()
@@ -500,7 +502,7 @@ class dashboard(QWidget):
                 self.show_repetisi_latihan.setFont(repetisiFont)
                 self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft)
 
-                self.gif = cur.execute(f"""
+                self.gif = self.cur.execute(f"""
                     SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
                     """).fetchone()[0]
                 self.gif2 = QMovie(self.gif)
@@ -528,15 +530,15 @@ class dashboard(QWidget):
                 self.kiri.show()
                 self.kanan.show()
             self.scroll.setParent(None)
-            tanggal = cur.execute(f"""
+            tanggal = self.cur.execute(f"""
             SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}'
         """).fetchone()[0]
             self.date.setText(f"{tanggal}")
-            daftar_latihan = cur.execute(f"""
+            daftar_latihan = self.cur.execute(f"""
                 SELECT name FROM riwayat_latihan WHERE date = '{tanggal}'
                 """).fetchall()
             jumlahCard = len(daftar_latihan)
-            keterangan = cur.execute(f"""
+            keterangan = self.cur.execute(f"""
                 SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}'
                 """).fetchone()
             
@@ -578,13 +580,13 @@ class dashboard(QWidget):
                 self.label.setStyleSheet(styleSheetCard)
                 self.hbox.addWidget(self.label)
                 nama_latihan = daftar_latihan[j][0]
-                repetisi_latihan = cur.execute(f"""
+                repetisi_latihan = self.cur.execute(f"""
                     SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
-                durasi_latihan = cur.execute(f"""
+                durasi_latihan = self.cur.execute(f"""
                     SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
-                gambar_latihan = cur.execute(f"""
+                gambar_latihan = self.cur.execute(f"""
                     SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
                 """).fetchone()
                 self.con.commit()
@@ -605,7 +607,7 @@ class dashboard(QWidget):
                 self.show_repetisi_latihan.setFont(repetisiFont)
                 self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft)
 
-                self.gif = cur.execute(f"""
+                self.gif = self.cur.execute(f"""
                     SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}'
                     """).fetchone()[0]
                 self.gif2 = QMovie(self.gif)
@@ -619,7 +621,7 @@ class dashboard(QWidget):
             self.scroll.show()
     
     def planWindow(self):
-        self.switch.emit("plan", {})
+        self.switch.emit("plan", 0, {})
     
     def listWindow(self):
         self.switch.emit("listLatihan", {})
diff --git a/src/endOfExercise.py b/src/endOfExercise.py
index c1f77f337cf331755f0c7dfd9245fbc8be9c4773..c89186a7351c8704085cfccf1fcede4a71b2c2b7 100644
--- a/src/endOfExercise.py
+++ b/src/endOfExercise.py
@@ -5,14 +5,14 @@ from PyQt6.QtGui import QFont, QPixmap, QCursor
 from PyQt6.QtCore import Qt, pyqtSignal
 
 class endOfExe(QWidget):
-    switch = pyqtSignal(str)
+    switch = pyqtSignal(str, dict)
     def __init__(self):
         super().__init__()
         self.conn = sqlite3.connect('fitu.db')
         self.setUpWindow()
     
     def setUpWindow(self):
-        self.setWindowTitle("FitU - Enf Of Exercise")
+        self.setWindowTitle("FitU - End Of Exercise")
         self.setFixedSize(1280, 720)
         self.setUpEndOfExe()
     
@@ -72,7 +72,7 @@ class endOfExe(QWidget):
         backButton.clicked.connect(self.backToDash)
     
     def backToDash(self):
-        self.switch.emit("dashboard")
+        self.switch.emit("dashboard", {})
     
 if __name__ == "__main__":
     
diff --git a/src/listlatihan2.py b/src/listlatihan2.py
index 23b6f5c23a32970fd183ba57fe18993a5f56acea..5f54869e73213274638a0a72f2362ef2a8f3fbdc 100644
--- a/src/listlatihan2.py
+++ b/src/listlatihan2.py
@@ -17,7 +17,7 @@ card_color = '#D2DCC4'
 class listLatihan2(QWidget):
     
     
-    switch = pyqtSignal(str, dict)
+    switch = pyqtSignal(str, int, dict)
     def __init__(self):
         super().__init__()    
         self.con = sqlite3.connect('fitu.db')
@@ -271,7 +271,7 @@ class listLatihan2(QWidget):
         self.switch.emit("customize", {})
         
     def planWindow(self):
-        self.switch.emit("plan", {})
+        self.switch.emit("plan", self.clickedRowData, {})
         
     def dashboard(self):
         self.switch.emit("dashboard", {})
diff --git a/src/plan.py b/src/plan.py
index ce7366767afd009f26c3589d76cdb177cf1c06d2..13c406aa86642ed64dff57f387e7b7edb3dabe4f 100644
--- a/src/plan.py
+++ b/src/plan.py
@@ -1,7 +1,7 @@
 import sqlite3
 import sys
 
-from PyQt6.QtCore import Qt
+from PyQt6.QtCore import Qt, pyqtSignal
 from PyQt6.QtGui import QPixmap, QCursor, QFont
 from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QScrollArea
 
@@ -11,7 +11,7 @@ TEXTCOLOR = '#EEEEE2'
 CARDCOLOR = '#D2DCC4'
 
 class plan(QWidget):
-    
+    switch = pyqtSignal(str, int, dict )
     def __init__(self):
         super().__init__()
         self.con = sqlite3.connect('fitu.db')
@@ -175,7 +175,8 @@ class plan(QWidget):
         homeButton.setFixedSize(96, 42)
         homeButton.move(507, 53)    
         homeButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
-        
+        homeButton.clicked.connect(self.dashboardWindow)
+
         # Customize Button
         customizeButton = QPushButton(self)
         customizeButton.setText('Customize')
@@ -183,6 +184,7 @@ class plan(QWidget):
         customizeButton.setFont(buttonFont)
         customizeButton.move(649, 58)
         customizeButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        customizeButton.clicked.connect(self.customWindow)
         
         # Plan Button
         planButton = QPushButton(self)
@@ -199,6 +201,7 @@ class plan(QWidget):
         listButton.setFont(buttonFont)
         listButton.move(898, 58)
         listButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        listButton.clicked.connect(self.listWindow)
 
         # History Button
         historyButton = QPushButton(self)
@@ -252,10 +255,11 @@ class plan(QWidget):
             con = sqlite3.connect('fitu.db')
             c = con.cursor()
             c.execute("SELECT title FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (data[i][0],))
-            data2 = c.fetchall()
+            self.data2 = c.fetchall()
+            # c.commit()
             c.close()
 
-            predict = len(data2)
+            predict = len(self.data2)
             dur = QLabel(exButton)
             dur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{predict} Minutes')
             dur.move(20, 50)
@@ -284,19 +288,20 @@ class plan(QWidget):
 
         # create a function to show exercise data based on index
         def showExercise(index):
-            clickedRowData = data[index][0]
+            self.clickedRowData = data[index][0]
             con = sqlite3.connect('fitu.db')
             c = con.cursor()
-            c.execute("SELECT title, repetition, duration, gif FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (clickedRowData,))
-            data2 = c.fetchall()
+            c.execute("SELECT title, repetition, duration, gif FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (self.clickedRowData,))
+            self.data3 = c.fetchall()
+            # print("clicked:" + str(clickedRowData))
             c.close()
 
             # clear the exercise data list
             exercise_data.clear()
 
             # append new exercise data to the list
-            for i in range(len(data2)):
-                exercise_data.append(data2[i])
+            for i in range(len(self.data3)):
+                exercise_data.append(self.data3[i])
 
             # remove all widgets from scrollLayout2
             for i in reversed(range(scrollLayout2.count())):
@@ -312,7 +317,7 @@ class plan(QWidget):
                 title.move(20, 15)
                 repDur = QLabel(exLabel)
                 if exercise_data[i][1] == None:
-                    repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][2]} Minutes')
+                    repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][2]} Seconds')
                 else:
                     repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][1]} Repetitions')
                 repDur.move(20, 50)
@@ -359,6 +364,7 @@ class plan(QWidget):
         startButton.setStyleSheet(styleSheetStart)
         startButton.setFont(font1)
         startButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        startButton.clicked.connect(self.plan2Window)
 
         custButton = QPushButton(self)
         custButton.setFont(font)
@@ -367,6 +373,19 @@ class plan(QWidget):
         custButton.setStyleSheet(styleSheetCutomize)
         custButton.setFont(font1)
         custButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        custButton.clicked.connect(self.customWindow)
+    
+    def dashboardWindow(self):
+        self.switch.emit("dashboard", {})
+    
+    def listWindow(self):
+        self.switch.emit("listLatihan", {})
+    
+    def customWindow(self):
+        self.switch.emit("customize", self.clickedRowData, {})
+    
+    def plan2Window(self):
+        self.switch.emit("plan2", self.clickedRowData, {})
 
 if __name__ == '__main__':
     app = QApplication(sys.argv)
diff --git a/src/plan2.py b/src/plan2.py
index e371dab9b9a1170fd9e2a6cb92febb84e9bebe7e..2610a2af313693f4624b9e01dfb3c29c8657542d 100644
--- a/src/plan2.py
+++ b/src/plan2.py
@@ -1,18 +1,23 @@
 import sqlite3
 from PyQt6.QtWidgets import QApplication, QLabel, QWidget, QPushButton, QMessageBox
 from PyQt6.QtGui import QFont, QPixmap, QCursor, QMovie, QIcon
-from PyQt6.QtCore import Qt, QSize, QUrl, QTimer, QTime
+from PyQt6.QtCore import Qt, QSize, QUrl, QTimer, pyqtSignal
 from PyQt6.QtMultimedia import QMediaPlayer
+from plan import plan
+import time
 # from PyQt6.QtMultimedia import QSoundEffect
 import time
 import sys
-class plan(QWidget):
-    def __init__(self):
+class plan2(QWidget):
+    switch = pyqtSignal(str, dict)
+    def __init__(self, program_id):
         super().__init__()
         self.index = 0
         self.conn = sqlite3.connect("fitu.db")
         self.c = self.conn.cursor()
-        self.latihan = self.c.execute("SELECT gif FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall()
+        self.program_id = program_id
+        print("prgram" + str(self.program_id))
+        self.latihan = self.c.execute(f"SELECT gif FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall()
         print(self.latihan)
         # self.remaining_time = 0
         self.timer = QTimer(self)
@@ -72,6 +77,7 @@ class plan(QWidget):
         backButton.setStyleSheet("background-color: #174728; color: #EEEEE2; border-radius: 30px; border: 2px;")
         backButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
         backButton.move(50, 64)
+        backButton.clicked.connect(self.backToPlan)
 
         self.currEx = QLabel(self)
         self.currEx.setFixedSize(360, 335)
@@ -94,37 +100,37 @@ class plan(QWidget):
         # prevLabel.move(513, 581)
         # prevLabel.setStyleSheet("background-color: #5A8D6C; border-radius: 20px;")
 
-        nextButton = QPushButton(self)
-        nextButton.setGeometry(200, 150, 100, 100)
-        nextButton.setIcon(QIcon("img/arrow-right.png"))
-        nextButton.setIconSize(QPixmap("img/arrow-right.png").size())
-        nextButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
-        nextButton.setStyleSheet('''
+        self.nextButton = QPushButton(self)
+        self.nextButton.setGeometry(200, 150, 100, 100)
+        self.nextButton.setIcon(QIcon("img/arrow-right.png"))
+        self.nextButton.setIconSize(QPixmap("img/arrow-right.png").size())
+        self.nextButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        self.nextButton.setStyleSheet('''
         QPushButton{
             border: 5px #5A8D6C;
             } 
         QPushButton:hover {
             background-color: #174728;
         }''')
-        nextButton.move(700, 581)
-        nextButton.clicked.connect(self.nextEx)
-
-        prevButton = QPushButton(self)
-        prevButton.setGeometry(200, 150, 100, 100)
-        # prevButton.setStyleSheet("background-image: url(img/arrow-left.png)")
-        prevButton.setIcon(QIcon("img/arrow-left.png"))
-        prevButton.setIconSize(QPixmap("img/arrow-left.png").size())
+        self.nextButton.move(700, 581)
+        self.nextButton.clicked.connect(self.nextEx)
+
+        self.prevButton = QPushButton(self)
+        self.prevButton.setGeometry(200, 150, 100, 100)
+        # self.prevButton.setStyleSheet("background-image: url(img/arrow-left.png)")
+        self.prevButton.setIcon(QIcon("img/arrow-left.png"))
+        self.prevButton.setIconSize(QPixmap("img/arrow-left.png").size())
         # print("size: "+ str(QPixmap("img/arrow-left.png").size()))
-        prevButton.setStyleSheet('''
+        self.prevButton.setStyleSheet('''
         QPushButton{
             border: 5px #5A8D6C;
             } 
         QPushButton:hover {
             background-color: #174728;
         }''')
-        prevButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
-        prevButton.move(513, 581)
-        prevButton.clicked.connect(self.prevEx)
+        self.prevButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        self.prevButton.move(513, 581)
+        self.prevButton.clicked.connect(self.prevEx)
 
         # filename = "img/BGM NKCTHI.mp3"
         # effect = QSoundEffect(self)
@@ -133,15 +139,7 @@ class plan(QWidget):
         # effect.setLoopCount(-2)
         # effect.play()
 
-        # if self.index == len(self.latihan):
-        #     nextButton.setEnabled(False)
-        #     titleProgram = c.execute(f"SELECT name FROM program WHERE program_id = {programId}").fetchone()
-        #     nameExe = c.execute(f"SELECT name FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program)").fetchall()
-        #     date = time.strftime("%Y-%m-%d", time.localtime())
-        #     totDuration = c.execute(f"SELECT SUM(duration) FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program)").fetchone()
-        #     c.execute("INSERT INTO riwayat_self.latihan program_id, name, title_program, date, tot_duration VALUES ({programId}, {nameExe}, {titleProgram}, {date}, {totDuration})")
-
-        self.name = self.c.execute(f"SELECT title FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall()
+        self.name = self.c.execute(f"SELECT title FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall()
         print(self.name)
         self.nameLabel = QLabel(self)
         self.nameLabel.setText(self.name[self.index][0])
@@ -163,9 +161,10 @@ class plan(QWidget):
         self.timer_label.move(547, 510)
         self.timer_label.setFont(QFont("Arial", 20, QFont.Weight.Bold))
         self.timer_label.setStyleSheet("background-color: #EEEEE2; border-radius: 10px; border: 2px")
+        self.start = time.time()
         # durationCount = c.execute(f"SELECT duration FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program WHERE program_id = 1)").fetchall()
-        self.repCount = self.c.execute(f"SELECT repetition FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall()
-        self.duration = self.c.execute(f"SELECT duration FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall()
+        self.repCount = self.c.execute(f"SELECT repetition FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall()
+        self.duration = self.c.execute(f"SELECT duration FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall()
         print(type(self.duration[self.index+1][0]))
         for i in self.repCount:
             print("rep",i)
@@ -179,6 +178,22 @@ class plan(QWidget):
             self.repetitionLabel()
         print((self.repCount[self.index][0])==None)    
 
+        self.historyButton = QPushButton(self)
+        self.historyButton.setFixedSize(100, 100)
+        self.historyButton.setEnabled(False)
+        self.historyButton.setText("End")
+        # self.historyButton.setIcon(QIcon("img/history.png"))
+        # self.historyButton.setIconSize(QPixmap("img/history.png").size())
+        self.historyButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+        self.historyButton.setStyleSheet('''
+        QPushButton{
+            border: 5px #5A8D6C;
+            }
+        QPushButton:hover {
+            background-color: #174728;
+        }''')
+        self.historyButton.move(1000, 500)
+        self.historyButton.clicked.connect(self.addHistory)
         # player = QMediaPlayer()
         # # playlist = QMediaPlaylist()
         # media = QMediaContent(QUrl.fromLocalFile("BGM ITS OKAY NOT TO BE OKAY.mp3"))  # Add your background music file here
@@ -226,8 +241,51 @@ class plan(QWidget):
             self.repetitionLabel()
         self.nameLabel.setText(self.name[self.index][0])
         print(self.index)
+        if self.index == (len(self.latihan)) - 1:
+            print("selsdasi")
+            self.historyButton.setEnabled(True)
+            
 
-    
+    def addHistory(self):
+        # if self.index +1 >= len(self.latihan):
+            print(len(self.latihan))
+            print("selesai")
+            self.nextButton.setEnabled(False)
+            titleProgram = self.c.execute(f"SELECT title_program FROM program WHERE program_id = {self.program_id}").fetchone()
+            print("tit", titleProgram[0])
+            nameExe = self.c.execute(f"SELECT title FROM daftar_latihan WHERE exercise_id in (SELECT exercise_id FROM latihan_program WHERE program_id = {self.program_id})").fetchall()
+            print(nameExe)
+            date = time.strftime("%Y-%m-%d", time.localtime())
+            print(date)
+            totDuration = time.time() - self.start
+            print(totDuration)
+            for i in range (len(self.latihan)):
+                print(nameExe[i][0], titleProgram[0], date, int(totDuration))
+                self.c.execute(f"""INSERT INTO riwayat_latihan (program_id, name, title_program, date, calories, tot_duration) 
+                VALUES 
+                ({self.program_id}, '{nameExe[i][0]}', '{(titleProgram[0])}', '{date}', NULL, {int(totDuration)})""")
+                self.conn.commit()
+            self.switch.emit("endOfExe", {})
+
+    # def endButton(self):
+    #     # historyButton = QPushButton(self)
+    #     # historyButton.setFixedSize(100, 100)
+    #     # historyButton.setText("End")
+    #     # # historyButton.setIcon(QIcon("img/history.png"))
+    #     # # historyButton.setIconSize(QPixmap("img/history.png").size())
+    #     # historyButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
+    #     # historyButton.setStyleSheet('''
+    #     # QPushButton{
+    #     #     border: 5px #5A8D6C;
+    #     #     }
+    #     # QPushButton:hover {
+    #     #     background-color: #174728;
+    #     # }''')
+    #     # historyButton.move(1000, 500)
+    #     # historyButton.clicked.connect(self.addHistory)
+
+    def backToPlan(self):
+        self.switch.emit("plan", {})
     
 if __name__ == "__main__":