<?php wp_enqueue_script('UlpAdminSendEmail', ULP_URL . 'assets/js/UlpAdminSendEmail.js', [], null);?>
<div class="ulp-wrapper">
<div class="ulp-page-title">Ultimate Learning Pro - <span class="second-text"><?php _e('Students', 'ulp');?></span></div>
    <div style="margin-bottom: 10px;">
      <form method="post" action="<?php echo admin_url('user-new.php');?>" >
        <input type="hidden" name="createuser" value="1" />
        <div class="col-md-3">
          <button type="submit" class="ulp-add-new-bttn" ><?php _e('Add new Student', 'ulp');?></button>
        </div>
      </form>
      <div class="ulp-clear"></div>
    </div>
<?php if ($data['students']):?>
    <div class="tablenav_light top">
        <div style="float: right; width: 40%;">
          <div class="col-md-4">
              <?php if (!empty($data['pagination'])):?>
                  <?php echo $data['pagination'];?>
              <?php endif;?>
          </div>
          <div class="col-md-8">
            <form method="post" action="">
              <div class="input-group col-md-12">
                  <input type="text" class="search-query form-control" name="search_q" placeholder="Search" />
                  <span class="input-group-btn" style="padding-left:10px;">
                      <button class="button" type="button"><?php _e('Search', 'ulp');?></button>
                  </span>
              </div>
            </form>
          </div>
        </div>
        <br class="clear">
    </div>
<?php endif ?>
  <div class="inside">
  <?php if ($data['students']):?>
    <table class="ulp-admin-tables ">
        <thead class="thead-inverse">
          <tr>
            <th style="width: 55px;"><?php _e('User ID', 'ulp');?></th>
            <th><?php _e('Username', 'ulp');?></th>
            <th><?php _e('E-mail address', 'ulp');?></th>
            <th style="width: 200px;"><?php _e('Full name', 'ulp');?></th>
            <th style="width: 25%;"><?php _e('Courses', 'ulp');?></th>
            <th><?php _e('Rewarded Points', 'ulp');?></th>
            <?php if ($data ['show_badges']):?>
            <th><?php _e('Badges', 'ulp');?></th>
            <?php endif;?>
            <th><?php _e('User registered date', 'ulp');?></th>
            <th><?php _e('Details', 'ulp');?></th>
          </tr>
        </thead>
        <tfoot class="thead-inverse">
          <tr>
            <th><?php _e('User ID', 'ulp');?></th>
            <th><?php _e('Username', 'ulp');?></th>
            <th><?php _e('E-mail address', 'ulp');?></th>
            <th><?php _e('Full name', 'ulp');?></th>
            <th style="min-width:490px; width: 25%;"><?php _e('Courses', 'ulp');?></th>
            <th><?php _e('Rewarded Points', 'ulp');?></th>
            <?php if ($data ['show_badges']):?>
            <th><?php _e('Badges', 'ulp');?></th>
            <?php endif;?>
            <th><?php _e('User registered date', 'ulp');?></th>
            <th><?php _e('Details', 'ulp');?></th>
          </tr>
        </tfoot>
        <tbody>
            <?php   $i = 1;
				foreach ($data['students'] as $object):?>
                <tr onMouseOver="ulpDhSelector(('<?php echo '#hidden' . $object->user_id;?>', 1);" onMouseOut="ulpDhSelector(('<?php echo '#hidden' . $object->user_id;?>', 0);" class="<?php if($i%2==0) echo 'alternate';?>">
                  <td scope="row">
                      <?php echo $object->user_id;?>
                  </td>
                  <td  class="column-instructor">

                      <?php if ($object->avatar):?>
                          <img src="<?php echo $object->avatar;?>" />
                      <?php endif;?>
                      <a href="<?php echo admin_url('user-edit.php?user_id=' . $object->user_id); ?>" target="_blank"><?php echo DbUlp::getUsernameByUID($object->user_id);?></a>
                      <div id="<?php echo 'hidden' . $object->user_id;?>" style="visibility: hidden;"><a href="<?php echo admin_url('user-edit.php?user_id='.$object->user_id);?>"><?php _e('Edit', 'ulp');?></a></div>
                  </td>
                  <td><a href="mailto:<?php echo $object->user_email;?>"><?php echo $object->user_email;?></a></td>
                  <td><?php echo $object->full_name;?></td>


                  <td><?php
                      if (strpos($object->courses_entities_id, ',')!==FALSE){
                          $courses = explode(',', $object->courses_entities_id);
                      } else {
                          $courses = array($object->courses_entities_id);
                      }

                      foreach ($courses as $course_entity_id){
                          $course = DbUlp::getCourseNameByEntityId($course_entity_id);
                          $course_id = DBUlp::getCourseIdByEntityId($course_entity_id);
                          if ( !DbUlp::postDoesReallyExists($course_id) ) continue;
                          $progress = $data['users_course_object']->getProgress($object->user_id, $course_id);
            						  if ($progress == 100):
            						  	$resultArr = $data['users_course_object']->GetCourseResult(0, 0, $course_entity_id);
                                      	$result = $resultArr['grade'];
            						  endif;
						              ?>
                              <div class="ulp-stundent-course-wrapper <?php echo ($progress == 100 ? 'ulp-course-completed' : ''); ?>">
							                  <span><a href="<?php echo admin_url('post.php?post=' . $course_id . '&action=edit');?>" target="_blank" title="<?php echo $progress;?>% completed"><?php echo $course; if(isset($result) && $result > 0) echo '<div class="ulp-grade"> ('.__('Grade: ', 'ulp').$result.')</div>';?></a></span>
                                <div class="ulp-stundent-course-progress"><div class="ulp-percentage"><?php echo $progress;?>%</div></div>
                                <div class="ulp-clear"></div>
                              </div>
                          <?php
                      }
                  ?></td>

                  <td><div class="ulp-admin-item-box" style="padding-right:9px; text-align:center;"><?php echo $object->reward_points;?><span><?php _e('Points', 'ulp');?></span></div></td>
                  <?php if ($data['show_badges']):?>
                  <td><?php if ($object->badges):?>
                      <?php foreach ($object->badges as $badge_object):?>
                          <a href="<?php echo admin_url('admin.php?page=ultimate_learning_pro&tab=student_badges&action=edit&id='.$badge_object->id);?>"><img src="<?php echo $badge_object->badge_image;?>" class="ulp-micro-badge" /></a>
                      <?php endforeach;?>
                  <?php endif;?></td>
                  <?php endif;?>
                  <td><?php echo ulp_print_date_like_wp($object->user_registered);?></td>
                  <td>
                      <div class="ulp-small-button ulp-turcoaz-button"><a href="<?php echo admin_url('admin.php?page=ultimate_learning_pro&tab=view_student_activity&uid=' . $object->user_id);?>"><?php _e('Activity', 'ulp');?></a></div>
                      <div class="ulp-small-button ulp-pointer ulp-light-red-button" style="color: #fff;"><span onclick="ulpResetPoints(<?php echo $object->user_id;?>);"><?php _e('Reset Points', 'ulp');?></span></div>
                      <div class="ulp-small-button ulp-grey-button ulp-admin-do-send-email-via-ulp" data-uid="<?php echo $object->user_id;?>" ><?php _e('Direct Email', 'ulp');?></div>
                  </td>
                </tr>
              <?php   $i++;
			  endforeach;?>
        </tbody>
    </table>
    <div class="ulp-clear"></div>
  <?php else:?>
      <h3><?php _e('No students yet!', 'ulp');?></h3>
  <?php endif;?>
  </div>
</div>
