Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
include("./layout/header.php");
include_once (__DIR__."/Utility/dataConnect.php");
include_once (__DIR__."/Utility/groupFunctions.php");
setcookie('totalMembers',1);
$AccountName = 'vinodismyname';
function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
$output = implode( ',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );</script>";
}
$invites = array(array('GroupID'=>'1', 'GroupName'=>'friends'),array('GroupID'=>'2', 'GroupName'=>'family'));
//$invites = checkInvites($AccountName);
$myGroups = array(array('GroupID'=>'1', 'GroupName'=>'One'),array('GroupID'=>'2', 'GroupName'=>'Two'));
//$myGroups = getGroups($AccountNameD);
if(isset($AccountName)) {
if (isset($_POST['submit'])) {
if(isset($_POST['groupName']) && isset($_POST['member'])) {
$totalMembers = $_POST['member'];
$membersList = [];
for ($i=0; $i<$totalMembers; $i++) {
if(isset($_POST['member'.$i])) {
$membersList[$i] = $_POST['member'.$i];
}
}
createGroup($AccountName, $_POST['groupName'], $membersList);
}
}
}
?>
<body>
<div class="container">
<header class="clearfix">
<!-- <span>Blueprint <span class="bp-icon bp-icon-about" data-content="The Blueprints are a collection of basic and minimal website concepts, components, plugins and layouts with minimal style for easy adaption and usage, or simply for inspiration."></span></span> -->
<nav>
<a href="summary.php" data-info="Summary"><span class = "glyphicon glyphicon-stats"></a>
<a href="leaderboard.php" data-info="Leaderboard"><span class = "glyphicon glyphicon-star"></a>
<a href="profile.php" data-info="Your Profile"><span class = "glyphicon glyphicon-user"></span></a>
</nav>
</header>
<div class="main">
<h2>Invites</h2>
<div class="cbp-ntcontent" style="width:80%;">
<div class="leaderboard-header flex column grow">
<div class="leaderboard-row flex align-center row--header" style="border-radius: 0 !important;">
<div class="row-position">Group Id</div>
<div class="row-rank">Group Name</div>
<div class="row-rank">Status</div>
</div>
</div>
<div class="leaderboard-body flex column grow">
<?php for($i=0; $i<count($invites); $i++) { ?>
<div class="leaderboard-row flex align-center">
<div class="row-position"> <?php echo $invites[$i]['GroupID'] ?> </div>
<div class="row-rank"> <?php echo $invites[$i]['GroupName'] ?> </div>
<div>
<input type="button"
class="btn btn-success"
value="Accept"
onclick="statusUpdate(<?php echo $invites[$i]['GroupID'] ?>,'Accepted');">
<input type="button"
class="btn btn-danger"
value="Decline"
onclick="statusUpdate(<?php echo $invites[$i]['GroupID'] ?>,'Delcined');">
</div>
</div>
<?php } ?>
</div>
</div><br />
<h2>Your Groups</h2>
<div class="cbp-ntcontent" style="width:40%;">
<div class="leaderboard-header flex column grow">
<div class="leaderboard-row flex align-center row--header" style="border-radius: 0 !important;">
<div class="row-position">Group Id</div>
<div class="row-rank">Group Name</div>
<div class="row-rank"></div>
</div>
</div>
<div class="leaderboard-body flex column grow">
<?php for($i=0; $i<count($myGroups); $i++) { ?>
<div class="leaderboard-row flex align-center">
<div class="row-position"> <?php echo $myGroups[$i]['GroupID'] ?> </div>
<div class="row-rank"> <?php echo $myGroups[$i]['GroupName'] ?> </div>
<input type="button"
class="btn btn-danger"
value="Decline"
onclick="deleteGroup(<?php echo $myGroups[$i]['GroupID'] ?>);"
<?php if(!validateGroup($AccountName, $myGroups[$i]['GroupName'])){ ?> style="visibility: hidden;" <?php } ?> >
</div>
<?php } ?>
</div>
</div><br />
<h2>Create Group</h2>
<form method="post" action="group.php">
<div class="form-group">
<label for="groupName">Group Name:</label><br />
<input required type="text" id="groupName" name="groupName" autocomplete="off" /><span class="err"></span>
</div>
<div class="form-group">
<label for="member"> Number of members: (max. 9)</label><br />
<input required type="number" min=0 max=9 id="member" name="member" style="width:100px;"><span class="err"></span>
</div>
<div class="form-group">
<a style="color:#003153;
background-color: #EEEEEE;
padding: 2px 6px 2px 6px;
font-weight: 700;
margin-left:0px;" href="#" id="filldetails" onclick="addFields()">Enter Member IDs</a>
<div id="container"> </div>
</div>
<?php for($i=0; $i<10; $i++) { ?>
<div class="form-group" id= <?php echo "member".$i ?> hidden>
<label for=<?php echo "member".$i ?>>Member <?php echo $i+1 ?> ID:</label><br />
<input type="text" name=<?php echo "member".$i ?> autocomplete="off" /><span class="err"></span>
</div>
<?php } ?>
<input type="submit" name="submit" class="btn btn-primary" id="exsbm" disabled="disabled" value="Create">
</form>
</div>
</div>
</body>
<script>
var number;
var fields = ['groupName','member'];
var memberList = [];
var chkF;
function addFields() {
number = document.getElementById("member").value;
$.cookie('totalMembers', Math.min(9, number));
for (i=0;i<Math.min(9, number);i++){
document.getElementById("member"+ String(i)).removeAttribute("hidden");
memberList.push("member"+ String(i));
chkF = new checkFormElm('exsbm', memberList);
}
}
function statusUpdate(groupId, status) {
$.ajax({
type: "POST",
url: "updateMemberStatus.php",
data: {'action': 'memberStatus', 'groupId': groupId, 'status': status},
success: function(data){
if(data=="success") {
window.location.href = "summary.php";
} else {
alert("There was an error. Please try again");
}
},
error: function(error){
console.log(error)
}
});
}
function deleteGroup(groupId) {
$.ajax({
type: "POST",
url: "updateMemberStatus.php",
data: {'action': 'deleteGroup', 'groupId': groupId},
success: function(data){
if(data=="success") {
window.location.href = "summary.php";
} else {
alert("There was an error. Please try again");
}
},
error: function(error){
console.log(error)
}
});
}
// ID of the Submit button, and an Array with the IDs of the fields which to validate
var checkFormElm = function(id_sbm, fields) {
var phpcheck = 'check.php'; // Here add the php file that validate the form element
var elm_sbm = document.getElementById(id_sbm); // the submit button
var fields = fields || []; // store the fields ID
var elm_v = {}; // store items with "elm_name:value" (to know when it is changed)
var err = {}; // stores form elements name, with value of -1 for invalid, value 1 for valid, and 0 for not checked
// change the css class of elm
var setelm = function(elm, val) {
// if val not empty, sets in err an item with element name, and value of 1
// sets border to this form element,
// else, sets in err an item with element name, and value of 0, and removes the border
if(val != '') {
err[elm.name] = -1;
elm.className = 'errinp';
if(elm_sbm) elm_sbm.setAttribute('disabled', 'disabled'); // disables the submit
elm.parentNode.querySelector('.err').innerHTML = val; // adds the error message
}
else {
err[elm.name] = 1;
elm.className = 'vinp';
elm.parentNode.querySelector('.err').innerHTML = ''; // removes the error message
// check if invalid or not checked items in $err (with value not 1)
var inv = 0;
for(var key in err) {
if(err[key] == -1) {
inv = 1;
break;
}
}
// if not invalid element, enables the submit button, and sends the form
if(inv == 0 && elm_sbm) {
elm_sbm.removeAttribute('disabled');
//elm_sbm.form.submit();
}
}
}
// sends data to a php file, via POST, and displays the received answer
var checkAjax = function(elm) {
if(elm.value != '' && (!elm_v[elm.name] || elm_v[elm.name] != elm.value)) {
elm_v[elm.name] = elm.value; // store name:value to know if was modified
var xmlHttp = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(); // gets the XMLHttpRequest instance
// create pairs index=value with data that must be sent to server
var datatosend = elm.name +'='+ elm.value;
xmlHttp.open("POST", phpcheck, true); // set the request to php file
// adds a header to tell the PHP script to recognize the data as is sent via POST
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(datatosend); // calls the send() method with datas as parameter
// Check request status
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) setelm(elm, xmlHttp.responseText);
}
}
else if(elm.value =='') setelm(elm, 'This field must be completed.');
}
// register onchange event to form elements that must be validated with PHP via Ajax
for(var i=0; i<fields.length; i++) {
if(document.getElementById(fields[i])) {
var elm = document.getElementById(fields[i]);
err[elm.name] = 0; //store fields-name in $err with value 0 (not checked)
elm.addEventListener('change', function(e){ checkAjax(e.target);});
}
}
}
// create an object instance of checkFormElm(), passing the ID of the submit button, and the $fields
chkF = new checkFormElm('exsbm', fields);
</script>
<style>
/* style for validated field */
.vinp {
background: #efeffe;
border: 1px solid blue;
}
/* style for invalided field */
.errinp {
background: #fefbda;
border: 2px dashed red;
}
/* style for error message */
.err {
margin: 0 5px;
color: red;
font-style: italic;
}
</style>