<!-- 
    Security Knowledge Framework is an expert system application 
    that uses OWASP Application Security Verification Standard, code examples,
    helps developers in pre-development and post-development.  
    Copyright (C) 2015  Glenn ten Cate, Riccardo ten Cate

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

{% include 'header.html' %} 
 
<script>

var arrTech = new Array();

{% for entry in users -%}

arrTech.push({'{{entry.userID|safe}}--':'{{entry.username|safe}}'});

{% endfor %}


var j = 0;

function addList()
{

var select = "<div class='item'><select class='form-control' name=test"+j+" id=test"+j+"></div>";
$("#checkboxes").append(select);
i = 0;
$.each(arrTech, function(key, value) {
    $.each(value, function(k, v) {
        var o = new Option(v, k);
  var name = "#test"+j 
        $(name).append(o);
    });
});
j++;
};
</script>
 
<!-- **********************************************************************************************************************************************************
      MAIN CONTENT
      *********************************************************************************************************************************************************** -->
      <!--main content start-->
      <section id="main-content" class="pageA project-functions">
	  
          <section class="intro">
			<div class="inner">

				<div class="text">

				<h1>Add users to groups</h1>
				<p>Add users to participate on your projects<br/>
        	    This way you can share projects with your colleagues. 
        	    </p>

				</div>

			</div>
		  </section>	  
	  
          <section class="wrapper">

			<div class="row mt">
				<div class="col-lg-12">
				   <div class="alert alert-info"><b>Make new group</b>
		
        			<p>Create a group and add users to participate on your projects<br/>
        			You first enter a name for the group and than you select the users 
        			you want to participate in that group.
        			</p>
		
				   </div>
				</div><!-- /col-lg-4 -->      
			</div><!-- /row -->

          <div class="row mt">
            <div class="col-lg-12">

			<div class="col-lg-4 col-md-4 col-sm-4 mb">
									
					<nav class="nav">
						<button class="btn btn-default" data-target="#myModal" style="visibility: none;" data-toggle="modal">Add Users</button>
						<a class="back" href="/group-manage">Done <i class="fa fa-check"></i></a>
					</nav>
					
					<!-- Modal -->
					
					<div id="myModal" class="modal fade" aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" style="display: none;">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button class="close" aria-hidden="true" data-dismiss="modal" type="button">×</button>
									<h4 id="myModalLabel" class="modal-title">Add new group</h4>
								</div>
								<div class="modal-body">
								
									<div class="alert alert-info">
										Here we can add users to the preferred user-groups in which you want to share your projects to.
									</div>
									
									<form action="/group-add-users" method="POST">
									
									<div class="tbl_container">
										<div class="row">
											<div class="left">
											    <select name="groupName" class="form-control">
											        {% for entry in groups -%}
											    	<option value="{{entry.groupID|safe}}">{{entry.groupName|safe}}</option>
											    	{% endfor %}
											    </select>
											</div>
											<div class="right"><b>Please select a group</b></div>
										</div>
										<div class="row">
											<div class="wide">
												<input type="hidden" name="csrf_token" value="{{csrf_token|safe}}" id="csrf_token" />
												<a class="btn btn-default" href="#" onClick="addList();">Add User</a>
												<div id="checkboxes">
													<!-- used for Ajax -->
												</div>
											
											</div>
										</div>
									</div>
									<div class="modal-footer">
										<input type="submit" class="btn btn-default" value="Add values" name="submit" />
									</div>
									
									</form>
								</div>
							</div>
						</div>
					</div>

			</div>  

			<div class="row mt">
				<div class="col-md-12">
					<div style='margin-top:-25px;' class="content-panel">
						{% if summary -%}
						<h4>Function summary</h4>
						
						<table class="table table-striped table-advance table-hover">
							<thead>
							<tr>
							  <th><i class="fa fa-edit"></i> Username</th>
							  <th><i class="fa fa-edit"></i> Group</th>
							  <th><i class="fa fa-edit"></i> Date/Time</th>
							 
							 {% if "delete" in session['permissions'] -%}  
							 <th><b>Remove</b></th>
							 {% endif -%}
							 
							 {% endif -%}
							</tr>
							</thead>
							<tbody>

							{% set counter = 0 -%}
							{% for entry in summary -%}
							
							<tr>
								<td>{{entry.username|safe}}</td>
								<td class="hidden-phone">{{entry.groupName|safe}} </td>
								<td><span class="label label-info label-mini">{{entry.timestamp|safe}}</span></td>
								<td>
									
								<!-- Button trigger modal -->
								{% if "delete" in session['permissions'] -%} 
								<button class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal{{entry.groupID|safe}}">
									<i class="fa fa-times"></i>                  
								</button>
								{% endif -%} 
								<!-- Modal -->
								
								<div class="modal fade" id="myModal{{entry.groupID|safe}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h4 class="modal-title" id="myModalLabel">Warning</h4>
											</div>
											<div class="modal-body">
												<div class="alert alert-info">
													<p>When you press the "Remove function" button, the function which this project contains will be deleted from the documentation. <b>Are you sure you want to continue?</b></p>
												</div>
											</div>
											<div class="modal-footer">
			                                  <form method="POST" action="/user-del">
			                                  <input type="hidden" value="{{entry.userID|safe}}" name="userID"/>
			                                  <input type="hidden" value="{{entry.groupID|safe}}" name="groupID"/>
			                                  <input type="hidden" value="{{csrf_token|safe}}" name="csrf_token"/>
			                                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			                                  <input type="submit" value="Remove Project" id="" class="btn btn-danger"/>
			                                  </form>
											</div>
										</div>
									</div>
								</div>              
									 
							  </td>
							</tr>

							{% set counter = counter + 1 %}
							{% endfor %}

							</tbody>
						</table>
							  
				</div><!-- /content-panel -->
			</div><!-- /col-md-12 -->
		
			</div><!-- /col -->
        </div><!-- /col -->
        </div><!-- /row -->
              
      </section><!-- /wrapper -->
    </section><!-- /MAIN CONTENT -->
         
         

{% include 'footer.html' %} 
 