<%inherit file="/main.html" />
<%! from django.core.urlresolvers import reverse %>
<%namespace name='static' file='/static_content.html'/>

<%block name="headextra">
  <%static:css group='course'/>
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.axislabels.js')}"></script>
  <script type="text/javascript" src="${static.url('js/course_groups/cohorts.js')}"></script>

</%block>

<%include file="/courseware/course_navigation.html" args="active_page='instructor'" />

<style type="text/css">
table.stat_table {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.stat_table th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.stat_table td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}

a.selectedmode { background-color: yellow; }

textarea {
  height: 200px;
}
</style>

<script language="JavaScript" type="text/javascript">
function goto( mode)
{
  document.idashform.idash_mode.value = mode;
  document.idashform.submit() ;
}
</script>

<section class="container">
<div class="instructor-dashboard-wrapper">

  <section class="instructor-dashboard-content">
    <h1>Instructor Dashboard</h1>

    <h2>[ <a href="#" onclick="goto('Grades');" class="${modeflag.get('Grades')}">Grades</a> | 
          %if settings.MITX_FEATURES.get('ENABLE_PSYCHOMETRICS'):
            <a href="#" onclick="goto('Psychometrics');" class="${modeflag.get('Psychometrics')}">Psychometrics</a> | 
          %endif
          <a href="#" onclick="goto('Admin');" class="${modeflag.get('Admin')}">Admin</a> |
          <a href="#" onclick="goto('Forum Admin');" class="${modeflag.get('Forum Admin')}">Forum Admin</a> |
          <a href="#" onclick="goto('Enrollment');" class="${modeflag.get('Enrollment')}">Enrollment</a> |
          <a href="#" onclick="goto('Data');" class="${modeflag.get('Data')}">DataDump</a> |
          <a href="#" onclick="goto('Manage Groups');" class="${modeflag.get('Manage Groups')}">Manage Groups</a> ]
    </h2>

  <div style="text-align:right"><span id="djangopid">${djangopid}</span>
  | <span id="mitxver">${mitx_version}</span></div>

    <form name="idashform" method="POST">
    <input type="hidden" name="csrfmiddlewaretoken" value="${ csrf_token }">
    <input type="hidden" name="idash_mode" value="">

##----------------------------------------------------------------------------- 
%if modeflag.get('Grades'):

    %if offline_grade_log:
      <p><font color='orange'>Pre-computed grades ${offline_grade_log} available: Use?
          <input type='checkbox' name='use_offline_grades' value='yes'></font> </p>
    %endif

    <p>
    <a href="${reverse('gradebook', kwargs=dict(course_id=course.id))}">Gradebook</a>
    </p>

    <p>
    <a href="${reverse('grade_summary', kwargs=dict(course_id=course.id))}">Grade summary</a>
    </p>

    <p>
    <input type="submit" name="action" value="Dump list of enrolled students">
    </p>

    <p>
    <input type="submit" name="action" value="Dump Grades for all students in this course">
    <input type="submit" name="action" value="Download CSV of all student grades for this course">
    </p>

    <p>
    <input type="submit" name="action" value="Dump all RAW grades for all students in this course">
    <input type="submit" name="action" value="Download CSV of all RAW grades">
    </p>

    <p>
    <input type="submit" name="action" value="Download CSV of answer distributions">
    </p>
    <hr width="40%" style="align:left">

  %if settings.MITX_FEATURES.get('REMOTE_GRADEBOOK_URL','') and instructor_access:
  
    <%
        rg = course.metadata.get('remote_gradebook',{})
    %>

    <h3>Export grades to remote gradebook</h3>
    <p>The assignments defined for this course should match the ones
    stored in the gradebook, for this to work properly!</p>

    <ul>
    <li>Gradebook name: <font color="green">${rg.get('name','None defined!')}</font>
    <br/>
    <br/>
    <input type="submit" name="action" value="List assignments available in remote gradebook">
    <input type="submit" name="action" value="List enrolled students matching remote gradebook">
    <br/>
    <br/>
    </li>
    <li><input type="submit" name="action" value="List assignments available for this course">
    <br/>
    <br/>
    </li>
    <li>Assignment name: <input type="text" name="assignment_name" size=40 >
    <br/>
    <br/>
    <input type="submit" name="action" value="Display grades for assignment">
    <input type="submit" name="action" value="Export grades for assignment to remote gradebook">
    <input type="submit" name="action" value="Export CSV file of grades for assignment">
    </li>
    </ul>

  %endif

    <H2>Student-specific grade inspection and adjustment</h2>
    <p>edX email address or their username: </p>
    <p><input type="text" name="unique_student_identifier">  <input type="submit" name="action" value="Get link to student's progress page"></p>
    <p>and, if you want to reset the number of attempts for a problem, the urlname of that problem</p>
    <p> <input type="text" name="problem_to_reset"> <input type="submit" name="action" value="Reset student's attempts">  </p>
 %endif

##----------------------------------------------------------------------------- 
%if modeflag.get('Psychometrics'):

    <p>Select a problem and an action:
    </p>

    <p>
    <select name="Problem">
    %for problem, count in sorted(problems.items(), key=lambda x: x[0]):
        <option value="${problem}">${problem} [${count}]</option>
    %endfor
    </select>
    </p>
    <p>
    <input type="submit" name="action" value="Generate Histogram and IRT Plot">
    </p>

    <p></p>

%endif

##----------------------------------------------------------------------------- 
%if modeflag.get('Admin'):
  %if instructor_access:
    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="List course staff members">
    <p>
    <input type="text" name="staffuser">
    <input type="submit" name="action" value="Remove course staff">
    <input type="submit" name="action" value="Add course staff">
    <hr width="40%" style="align:left">
  %endif

  %if admin_access:
    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="List course instructors">
    <p>
    <input type="text" name="instructor"> <input type="submit" name="action" value="Remove instructor">
    <input type="submit" name="action" value="Add instructor">
    <hr width="40%" style="align:left">
  %endif

  %if settings.MITX_FEATURES['ENABLE_MANUAL_GIT_RELOAD'] and admin_access:
    <p>
    <input type="submit" name="action" value="Reload course from XML files">
    <input type="submit" name="action" value="GIT pull and Reload course">
  %endif
%endif

##----------------------------------------------------------------------------- 
%if modeflag.get('Forum Admin'):
  %if instructor_access:
    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="List course forum admins">
    <p>
    <input type="text" name="forumadmin"> <input type="submit" name="action" value="Remove forum admin">
    <input type="submit" name="action" value="Add forum admin">
    <hr width="40%" style="align:left">
  %endif

  %if instructor_access or forum_admin_access:
    <p>
    <input type="submit" name="action" value="List course forum moderators">
    <input type="submit" name="action" value="List course forum community TAs">
    <p>
    <input type="text" name="forummoderator"> 
    <input type="submit" name="action" value="Remove forum moderator">
    <input type="submit" name="action" value="Add forum moderator">
    <input type="submit" name="action" value="Remove forum community TA">
    <input type="submit" name="action" value="Add forum community TA">
    <hr width="40%" style="align:left">
  %else:
  <p>User requires forum administrator privileges to perform administration tasks.  See instructor.</p>
  %endif
%endif

##----------------------------------------------------------------------------- 
%if modeflag.get('Enrollment'):

    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="List enrolled students">
    <input type="submit" name="action" value="List students who may enroll but may not have yet signed up">
    <p>
    Student Email: <input type="text" name="enstudent"> <input type="submit" name="action" value="Un-enroll student">
    <input type="submit" name="action" value="Enroll student">
    <input type="submit" name="action" value="Un-enroll ALL students">
    <hr width="40%" style="align:left">

  %if settings.MITX_FEATURES.get('REMOTE_GRADEBOOK_URL','') and instructor_access:
  
    <%
        rg = course.metadata.get('remote_gradebook',{})
    %>

    <p>Pull enrollment from remote gradebook</p>
    <ul>
    <li>Gradebook name: <font color="green">${rg.get('name','None defined!')}</font>
    <li>Section: <input type="text" name="gradebook_section" size=40 value="${rg.get('section','')}"></li>
    </ul>
    <input type="submit" name="action" value="List sections available in remote gradebook">
    <input type="submit" name="action" value="List students in section in remote gradebook">
    <input type="submit" name="action" value="Overload enrollment list using remote gradebook">
    <input type="submit" name="action" value="Merge enrollment list with remote gradebook">
    <hr width="40%" style="align:left">
  
  %endif

  <p>Add students: enter emails, separated by new lines or commas;</p>
  <textarea rows="6" cols="70" name="enroll_multiple"></textarea>
  <input type="submit" name="action" value="Enroll multiple students">

%endif

##----------------------------------------------------------------------------- 

%if modeflag.get('Data'):
    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="Download CSV of all student profile data">
    </p>
    <p> Problem urlname: 
        <input type="text" name="problem_to_dump" size="40">
        <input type="submit" name="action" value="Download CSV of all responses to problem">
    </p>
    <hr width="40%" style="align:left">
%endif
  
##----------------------------------------------------------------------------- 

%if modeflag.get('Manage Groups'):
  %if instructor_access:
    <hr width="40%" style="align:left">
    <p>
    <input type="submit" name="action" value="List beta testers">
    <p>
    Enter usernames or emails for students who should be beta-testers, one per line, or separated by commas.  They will get to
    see course materials early, as configured via the <tt>days_early_for_beta</tt> option in the course policy.
    </p>
    <p>
    <textarea cols="50" row="30" name="betausers"></textarea>
    <input type="submit" name="action" value="Remove beta testers">
    <input type="submit" name="action" value="Add beta testers">
    </p>
    <hr width="40%" style="align:left">

    %if course.is_cohorted:
    <%include file="/course_groups/cohort_management.html" />
    %endif

  %endif
%endif

    </form>
##----------------------------------------------------------------------------- 

%if msg:
    <p></p><p>${msg}</p>
%endif
##----------------------------------------------------------------------------- 

%if datatable and modeflag.get('Psychometrics') is None:

    <br/>
    <br/>
    <p>
      <hr width="100%">
      <h2>${datatable['title']}</h2>
      <table class="stat_table">
        <tr>
	%for hname in datatable['header']:
	  <th>${hname}</th>
	%endfor
	</tr>
        %for row in datatable['data']:
          <tr>
	    %for value in row:
	      <td>${value}</td>
	    %endfor
	  </tr>
        %endfor
      </table>
    </p>
%endif

##-----------------------------------------------------------------------------  
%if modeflag.get('Psychometrics'):

    %for plot in plots:
      <br/>
      <h3>${plot['title']}</h3>
      <br/>
      <p>${plot['info']}</p>
      <br/>
      <div id="plot_${plot['id']}" style="width:600px;height:300px;"></div>
      <script type="text/javascript">
          $(function () {
              ${plot['data']}
              $.plot($("#plot_${plot['id']}"), ${plot['cmd']}  );
          });
      </script>
      <br/>
      <br/>
    %endfor

%endif
 
##-----------------------------------------------------------------------------  
## always show msg


##----------------------------------------------------------------------------- 
%if modeflag.get('Admin'):
 % if course_errors is not UNDEFINED:
    <h2>Course errors</h2>
    <div id="course-errors">
    %if not course_errors:
          None
    %else:
      <ul>
        % for (summary, err) in course_errors:
        <li>${summary | h}
        % if err:
          <ul><li><pre>${err | h}</pre></li></ul>
        % else:
          <p>&nbsp;</p>
        % endif
        </li>
        % endfor
        </ul>
      %endif
      </div>
  % endif
%endif      

  </section>
</div>
</section>
