/**
   * Generates an OIT scan sheet. If checkbox for print is open, uses a Desktop object to print to
   * the default printer. The current system date is used as the date.
   *
   * @param info Course inform
   * @param print If true, the document will be sent to default printer
   */
  public void generateOITSheet(DocInfo info, boolean print) {
    try {
      // Create new doc
      wordMLPackage = WordprocessingMLPackage.createPackage();
      factory = Context.getWmlObjectFactory();

      // Add title to top of document
      wordMLPackage.getMainDocumentPart().addParagraphOfText("OIT Scan Cover Sheet");

      // Create table for header information
      Tbl infoTable = factory.createTbl();

      // Create instructor name row
      Tr instNameRow = factory.createTr();
      addStyledTableCellWithWidth(
          instNameRow, "Instructor Name:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          instNameRow,
          info.getInstFName() + " " + info.getInstLName(),
          false,
          "20",
          TABLE_LONG_FIELD_LENGTH);

      // Create subject/course number row
      Tr courseInfoRow = factory.createTr();
      addStyledTableCellWithWidth(courseInfoRow, "Course Subject & Number:", true, "20", 3000);
      addStyledTableCellWithWidth(
          courseInfoRow,
          info.getSubject() + " " + info.getCourseNum(),
          false,
          "20",
          TABLE_LONG_FIELD_LENGTH);

      // Create section row
      Tr sectionRow = factory.createTr();
      addStyledTableCellWithWidth(sectionRow, "Section:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          sectionRow, info.getSection(), false, "20", TABLE_LONG_FIELD_LENGTH);

      // Semester/Year row
      Tr semesterRow = factory.createTr();
      addStyledTableCellWithWidth(semesterRow, "Semester:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          semesterRow,
          info.getSemester().toString() + " " + info.getYear(),
          false,
          "20",
          TABLE_LONG_FIELD_LENGTH);

      // Faculty supp name row
      Tr facSuppNameRow = factory.createTr();
      addStyledTableCellWithWidth(
          facSuppNameRow, "Faculty Support Name:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          facSuppNameRow, info.getFacSuppName(), false, "20", TABLE_LONG_FIELD_LENGTH);

      // Faculty supp name row
      Tr facSuppExtenRow = factory.createTr();
      addStyledTableCellWithWidth(
          facSuppExtenRow, "Faculty Support Extension:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          facSuppExtenRow, info.getFacSuppExten(), false, "20", TABLE_LONG_FIELD_LENGTH);

      // Mailbox row
      Tr mailboxRow = factory.createTr();
      addStyledTableCellWithWidth(
          mailboxRow,
          "I would like the results delivered to mailbox:",
          true,
          "20",
          TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          mailboxRow, info.getMailbox(), false, "20", TABLE_LONG_FIELD_LENGTH);

      Tr dateRow = factory.createTr();
      DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
      Date date = new Date();
      System.out.println(dateFormat.format(date));
      addStyledTableCellWithWidth(
          dateRow, "Date of Request:", true, "20", TABLE_SHORT_FIELD_LENGTH);
      addStyledTableCellWithWidth(
          dateRow, dateFormat.format(date), false, "20", TABLE_LONG_FIELD_LENGTH);

      // Add rows to table
      infoTable.getContent().add(instNameRow);
      infoTable.getContent().add(courseInfoRow);
      infoTable.getContent().add(sectionRow);
      infoTable.getContent().add(semesterRow);
      infoTable.getContent().add(facSuppNameRow);
      infoTable.getContent().add(facSuppExtenRow);
      infoTable.getContent().add(mailboxRow);
      infoTable.getContent().add(dateRow);

      // Add border around entire table
      addBorders(infoTable);

      // Place tables on document
      wordMLPackage.getMainDocumentPart().addObject(infoTable);

      // Save in project files
      wordMLPackage.save(new File(OIT_SCAN_SHEET_SAVE_LOC));

      // Print or open file based on user decision
      if (print) {
        desktop.print(new File(OIT_SCAN_SHEET_SAVE_LOC));
      } else {
        desktop.open(new File(OIT_SCAN_SHEET_SAVE_LOC));
      }

      System.out.println("OIT Scan sheet generated.");

    } catch (InvalidFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Docx4JException e) {
      // TODO Auto-generated catch block
      JOptionPane.showMessageDialog(
          null, "Unable to open the OIT scan sheet. Make sure the document is not open.");
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public static void main(String[] list) {
    String classname = null, rep = null;
    boolean available = true;

    if (list.length > 1) {
      available = false;

      System.out.println("Choose class to edit");
      for (int i = 0; i < list.length; i++) System.out.println(list[i]);
      System.out.print("Your choice: ");
      classname = util.getString();

      for (int i = 0; i < list.length; i++)
        if (classname.equals(list[i])) {
          available = true;
          break;
        }
    } else classname = list[0];

    if (available) {
      do {
        System.out.print(
            "1->Edit today's report for class "
                + classname
                + "\n2->View reports for a selected day\n3->Print a day's report\nYour choice: ");
        rep = util.getString();

        if (rep.equals("1")) {
          String[] idno = util.SQLQuery(classname, "SELECT IDNo FROM " + util.getDate());
          System.out.print("Enter ID Number of student to edit their attendance: ");
          String repid = util.getString();

          available = false;

          for (int i = 0; i < idno.length; i++)
            if (repid.equals(idno[i])) {
              available = true;
              break;
            }

          if (available) {
            String[] session =
                util.SQLQuery(
                    classname,
                    "SELECT SessionName FROM Timetable WHERE Day='" + util.getDay() + "'");
            int repint, i;

            System.out.println("Select a session to change attendance for " + repid);
            for (i = 0; i < session.length; i++) System.out.println((i + 1) + " -> " + session[i]);
            System.out.print("Your choice [1-" + i + "]: ");
            repint = util.getInt();

            if (repint >= 1 && repint <= i) {
              String status =
                  util.SQLQuery(
                      classname,
                      "SELECT Status FROM "
                          + util.getDate()
                          + " WHERE Session="
                          + repint
                          + " AND IDNo='"
                          + repid
                          + "'")[0];

              if (status == null)
                System.out.println("Student has not yet entered attendance for this session");
              else
                System.out.println(
                    "Student has entered attendance at " + status + " for this session");
              System.out.print(
                  "What would you like to do?\nType 'present' to mark the student as present\nType 'absent' to mark the student as absent\nYour choice: ");
              rep = util.getString().toLowerCase();

              if (rep.equals("present")) {
                util.SQLUpdate(
                    classname,
                    "UPDATE "
                        + util.getDate()
                        + " SET Status='"
                        + util.sysTime()
                        + "' WHERE Session="
                        + repint
                        + " AND IDNo='"
                        + repid
                        + "'");
                System.out.println(
                    "Successfully marked student "
                        + repid
                        + " as present for session "
                        + session[repint - 1]);
              } else if (rep.equals("absent")) {
                util.SQLUpdate(
                    classname,
                    "UPDATE "
                        + util.getDate()
                        + " SET Status=null WHERE Session="
                        + repint
                        + " AND IDNo='"
                        + repid
                        + "'");
                System.out.println(
                    "Successfully marked student "
                        + repid
                        + " as absent for session "
                        + session[repint - 1]);
              } else System.out.println("INVALID CHOICE!!");
            }
          }
        } else if (rep.equals("2") || rep.equals("3")) {
          String repdate = "";
          String[] date = util.listReports(classname);
          available = false;
          System.out.println("Enter a date from the following dates:");
          for (int i = 0; i < date.length; i++) {
            date[i].replace("-", "_");
            System.out.println("-> " + date[i]);
          }
          System.out.print("Your choice: ");
          repdate = util.getString();

          for (int i = 0; i < date.length; i++)
            if (repdate.equals(date[i])) {
              available = true;
              break;
            }

          if (available) {
            repdate.replace("_", "-");
            String[] idno = util.SQLQuery(classname, "SELECT DISTINCT IDNo FROM " + repdate),
                name =
                    util.SQLQuery(
                        classname,
                        "SELECT DISTINCT Name FROM Namelist JOIN "
                            + repdate
                            + " ON Namelist.IDNo="
                            + repdate
                            + ".IDNo"),
                session = util.SQLQuery(classname, "SELECT DISTINCT Session FROM " + repdate),
                status = util.SQLQuery(classname, "SELECT Status FROM " + repdate);

            if (rep.equals("2")) {
              int k = 0;

              for (int i = 0; i < idno.length; i++) {
                System.out.print(name[i] + " (" + idno[i] + ") -> ");
                for (int j = 0; j < session.length; j++) {
                  if (status[k] == null) status[k] = "null ";
                  System.out.print(" " + status[k] + " |");
                  k++;
                }
                System.out.println();
              }
            } else {
              File file = new File("temp.csv");
              Desktop desktop = Desktop.getDesktop();

              try (FileWriter fw = new FileWriter(file)) {
                String temp = "Name,ID";
                int k = 0;

                for (int i = 0; i < session.length; i++) temp += ",Session " + session[i];

                for (int i = 0; i < idno.length; i++) {
                  temp += "\n" + name[i] + "," + idno[i];
                  for (int j = 0; j < session.length; j++) {
                    temp += "," + status[k];
                    k++;
                  }
                }
                fw.write(temp);
                desktop.print(file);
              } catch (IOException e) {
                e.printStackTrace();
              } finally {
                file.delete();
              }
            }
          } else
            System.out.println(
                "Given date does not exist, or is not inputted in correct format... Try again.");
        } else System.out.println("INVALID CHOICE!!");

        System.out.print("Continue editing reports for class " + classname + "?[y/n]: ");
        rep = util.getString();
      } while (rep.startsWith("y") || rep.startsWith("Y"));
    } else System.out.println("INVALID CHOICE!!");
  }