/// <summary>
 /// Fills the information lists.
 /// </summary>
 public void fillInfoLists()
 {
     UserInfo.Course c = dm.getCourseById(wm.courseId);
     lf = c.folios;
     tf = c.topics;
     fo = c.forums;
 }
    // Update is called once per frame
    void Update()
    {
        if (dm.everyThingDone)
        {
            TutorScreen.Instance.InicialSetDesactivated();

            UserInfo.Course c = dm.getCourseById(wm.courseId);

            t.text = "Olá, " + user.fullName + "! Bem vindo à cadeira de " + c.fullName + "!\n Qual destes avatares escolhe para seu tutor nesta UC?";

            controller.SetMood(MoodState.NEUTRAL);

            Invoke("sendControl", 0.9f);
        }
    }
    // DADOS DO COURSE

    /*
     * Recebe informacao basica das cadeiras que o utilizador esta inscrito EM JSON
     */
    /// <summary>
    /// Receives the courses.
    /// </summary>
    /// <param name="c">List of Courses and their characteristics.</param>
    /// <param name="multi">if set to <c>true</c> The program considers multiple courses, if set to <c>false</c> the program filters the courses and only gets the one desired.</param>
    /// <param name="courseId">The course identifier of the course desired (WebGL).</param>
    public void receiveCourses(List <jsonValues.Courses> c, Boolean multi, int courseId)
    {
        UserInfo.Course template;


        foreach (jsonValues.Courses co in c)
        {
            template = new UserInfo.Course();
            lock (template)
            {
                if (!multi) // Caso seja uma cadeira
                {
                    if (co.id == courseId)
                    {
                        template.id        = co.id;
                        template.idNumber  = co.idnumber;
                        template.shortName = co.shortname;
                        template.fullName  = co.fullname;
                        template.summary   = UserInfo.Course.HtmlDecode(co.summary);
                        template.startdate = co.startdate;
                        template.visible   = co.visible;
                        courses.Add(template);
                    }
                }

                else
                {
                    template.id        = co.id;
                    template.idNumber  = co.idnumber;
                    template.shortName = co.shortname;
                    template.fullName  = co.fullname;
                    template.summary   = UserInfo.Course.HtmlDecode(co.summary);
                    template.startdate = co.startdate;
                    template.visible   = co.visible;
                    courses.Add(template);
                }
            }
        }
        gotCourses = true;
    }
    /// <summary>
    /// Shows the buttons to the user.
    /// </summary>
    public void CreateButtons()
    {
        /*Hide all the buttons*/
        hideButtons();
        //clean all the panels
        foreach (Transform child in infoParentPanel)
        {
            GameObject.Destroy(child.gameObject);
        }
        foreach (Transform child in folioParentPanel)
        {
            GameObject.Destroy(child.gameObject);
        }

        if (dm.everyThingDone)
        {
            switch (option)
            {
            case 1:     //menu inicial
                Debug.Log(efolios);
                InfoText.gameObject.SetActive(true);
                InfoBox.SetActive(true);
                InfoText.text = updates();
                SetAllTheMenuTrue();
                break;

            case 2:     //menu e-fólios
                Debug.Log(efolios);
                int fol = 0;
                table.SetActive(true);
                UserInfo.Course co = dm.getCourseById(wm.courseId);
                if (!co.checkGradeReport)
                {
                    foreach (UserInfo.Course.Folio f in lf)
                    {
                        if (ItExists("module-" + f.cmid))
                        {
                            GameObject response = (GameObject)Instantiate(newFolioPrefab);
                            response.transform.SetParent(folioParentPanel);
                            response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                            string displayMessage = co.FolioDisplay(f.cmid);
                            string stateOfE       = co.FolioFeedback(f.cmid);
                            string feed           = "";
                            if (f.graderaw != -1)
                            {
                                feed = wm.GetFolioPhrase(stateOfE);
                            }
                            else
                            {
                                feed = "O link para o e-fólio que escolheu está agora destacado na página da UC.";
                            }
                            response.GetComponent <MessageFuntions>().ShowMessage(f.name, displayMessage);
                            response.GetComponent <MessageFuntions>().GetDataToShow(feed);
                            response.GetComponent <MessageFuntions>().AddFunctionToButton(7, "module-" + f.cmid);
                            string c = (f.seen > 0) ? "branco" : (f.seen == 0) ? "amarelo" : "vermelho";
                            if (c == "vermelho")
                            {
                                response.GetComponent <MessageFuntions>().itIsNotSeen();
                            }
                            else if (c == "amarelo")
                            {
                                response.GetComponent <MessageFuntions>().itIsANew();
                            }

                            fol++;
                        }
                    }
                }
                if (co.checkGradeReport || fol == 0)
                {
                    GameObject response = (GameObject)Instantiate(newFolioPrefab);
                    response.transform.SetParent(folioParentPanel);
                    response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                    response.GetComponent <MessageFuntions>().ShowMessageM("Cartão de Aprendizagem");
                    response.GetComponent <MessageFuntions>().AddFunctionToButtonCA(7);
                }

                scb = scb1;
                itsDown();
                SetTheBackMenuTrue();
                break;

            case 3:     //menu documentos
                //Debug.Log(docs + " : " + tf.Count);
                table2.SetActive(true);
                foreach (UserInfo.Course.Topic t in tf)
                {
                    if (ItExists(t.name))
                    {
                        GameObject response = (GameObject)Instantiate(newInfoPrefab);
                        response.transform.SetParent(infoParentPanel);
                        response.transform.SetSiblingIndex(infoParentPanel.childCount - 2);
                        response.GetComponent <TopicFunctions>().ShowInfo(t.name);
                        response.GetComponent <TopicFunctions>().AddFunctionToButton(5, t.name);
                        //Debug.Log(name);
                        if (t.seen == -1)
                        {
                            response.GetComponent <TopicFunctions>().itIsNotSeen();
                        }
                        else if (t.seen == 0)
                        {
                            response.GetComponent <TopicFunctions>().itIsANew();
                        }
                    }
                }
                scb = scb2;
                itsDown();
                SetTheBackMenuTrue();
                break;

            case 4:     //menu fóruns
                //Debug.Log(foruns + " : " + fo.Count);
                table2.SetActive(true);
                foreach (UserInfo.Course.Forum f in fo)
                {
                    if (ItExists("module-" + f.cmid))
                    {
                        GameObject response = (GameObject)Instantiate(newInfoPrefab);
                        response.transform.SetParent(infoParentPanel);
                        response.transform.SetSiblingIndex(infoParentPanel.childCount - 2);
                        response.GetComponent <TopicFunctions>().ShowInfo(f.name);
                        response.GetComponent <TopicFunctions>().AddFunctionToButton(6, "module-" + f.cmid);
                        if (f.seen == -1)
                        {
                            response.GetComponent <TopicFunctions>().itIsNotSeen();
                        }
                        else if (f.seen == 0)
                        {
                            response.GetComponent <TopicFunctions>().itIsANew();
                        }
                    }
                }
                scb = scb2;
                itsDown();
                SetTheBackMenuTrue();
                break;

            case 5:     //mostrar conteúdos de documentos
                SetTheBackMenuTrue();
                break;

            case 6:     //mostrar conteúdos de fóruns
                SetTheBackMenuTrue();
                break;

            case 7:     //mostrar conteúdos de e-fólios
                SetTheBackMenuTrue();
                break;

            case 8:     //mostrar conteúdos de Q&A
                //SetTheBackMenuTrue();
                SetAskMenu();
                break;

            case 10:     //mostrar conteúdos de Actividades Formativas
                Debug.Log("activities " + mActivities.Count);
                table.SetActive(true);
                if (topicActivities.Count != 0 || foliosActivities.Count != 0 || forumActivities.Count != 0 || mActivities.Count != 0)
                {
                    //topics
                    if (topicActivities.Count != 0)
                    {
                        foreach (UserInfo.Course.Topic t in topicActivities)
                        {
                            GameObject response = (GameObject)Instantiate(newFolioPrefab);
                            response.transform.SetParent(folioParentPanel);
                            response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                            response.GetComponent <MessageFuntions>().ShowMessage(" ---- " + t.name + " ---- ");
                        }
                    }
                    //folios
                    if (foliosActivities.Count != 0)
                    {
                        foreach (UserInfo.Course.Folio f in foliosActivities)
                        {
                            GameObject response = (GameObject)Instantiate(newFolioPrefab);
                            response.transform.SetParent(folioParentPanel);
                            response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                            response.GetComponent <MessageFuntions>().ShowMessageM(f.name);
                            response.GetComponent <MessageFuntions>().AddFunctionToButton2(14, "module-" + f.cmid);
                        }
                    }
                    //foruns
                    if (forumActivities.Count != 0)
                    {
                        foreach (UserInfo.Course.Forum f in forumActivities)
                        {
                            GameObject response = (GameObject)Instantiate(newFolioPrefab);
                            response.transform.SetParent(folioParentPanel);
                            response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                            response.GetComponent <MessageFuntions>().ShowMessageM(f.name);
                            response.GetComponent <MessageFuntions>().AddFunctionToButton2(14, "module-" + f.cmid);
                        }
                    }
                    //modules
                    if (mActivities.Count != 0)
                    {
                        foreach (UserInfo.Course.modules f in mActivities)
                        {
                            GameObject response = (GameObject)Instantiate(newFolioPrefab);
                            response.transform.SetParent(folioParentPanel);
                            response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                            response.GetComponent <MessageFuntions>().ShowMessageM(f.name);
                            response.GetComponent <MessageFuntions>().AddFunctionToButton2(14, f.name);
                        }
                    }
                }
                else
                {
                    GameObject response = (GameObject)Instantiate(newFolioPrefab);
                    response.transform.SetParent(folioParentPanel);
                    response.transform.SetSiblingIndex(folioParentPanel.childCount - 2);
                    response.GetComponent <MessageFuntions>().ShowMessage("Não existem Actividades.");
                }
                scb = scb1;
                itsDown();
                SetTheBackMenuTrue();
                break;

            case 11:

                break;

            case 12:
                Debug.Log("Default");
                SetAllTheMenuTrue();
                break;

            case 13:
                SetTheBackMenuTrue();
                break;

            case 14:
                SetTheBackMenuTrue();
                break;

            default:
                Debug.Log("Default");
                SetAllTheMenuTrue();
                break;
            }
        }
        else
        {
            Debug.Log("User não pronto para leitura");
        }
    }
    /// <summary>
    /// Sets the reply of the tutor.
    /// </summary>
    public void replying()
    {
        Debug.Log("replying to " + option);
        InicialSetDesactivated();
        switch (option)
        {
        case 1:
            //greetings parte 1 e 2
            Debug.Log("Teacher: " + wm.teacher + "; gp2: " + wm.gp2);
            if (wm.gp2)
            {
                greetingsPart1();
                if (wm.teacher != 0)
                {
                    wm.gp2 = !wm.gp2;
                }
            }
            else     //greetings parte 2
            {
                if (wm.teacher != 0)
                {
                    greetingsPart2();
                }
                else
                {
                    greetingsPart1();
                }
            }
            Debug.Log("Primeiro Menu");
            break;

        case 2:     //balão e-fólios
            UserInfo.Course co = dm.getCourseById(wm.courseId);
            if (!co.checkGradeReport)
            {
                responseMessage(infoEf);
            }
            else
            {
                responseMessage(efoliosDone);
            }
            break;

        case 3:     //balão documentos
            responseMessage(infoDoc);
            break;

        case 4:     //balão fóruns
            responseMessage(infoForum);
            break;

        case 5:     //balão mostrar conteúdos de documentos
            responseMessage(showDoc);
            break;

        case 6:     //balão mostrar conteúdos de fóruns
            responseMessage(showForum);
            break;

        case 7:     //balão mostrar conteúdos de e-fólios
            responseMessage(folioFeedbacK);
            break;

        case 8:     //balão mostrar conteúdos de Q&A
            responseMessage(questionEanswer);
            break;

        case 9:
            responseMessage(QeAFunctions.Instance.GetResult());
            break;

        case 10:
            responseMessage(UC);
            break;

        case 11:
            responseMessage(close);
            break;

        case 12:
            responseMessage(open);
            break;

        case 13:
            responseMessage(PUC);
            break;

        case 14:
            responseMessage(AF);
            break;

        default:
            responseMessage(giveHelp);
            break;
        }
    }