2021-03-05 09:52:42 +00:00
|
|
|
<?php
|
2021-03-16 11:46:44 +00:00
|
|
|
require_once "../../../bootstrap.php";
|
2021-03-11 12:20:10 +00:00
|
|
|
require_once "../Group/Group.php";
|
2021-03-05 09:52:42 +00:00
|
|
|
use Backend\Models\Group;
|
|
|
|
use Backend\Models\KeyWord;
|
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
session_start();
|
2021-03-05 09:52:42 +00:00
|
|
|
|
2021-03-16 11:46:44 +00:00
|
|
|
if (isLogin()) {
|
2021-03-08 09:29:11 +00:00
|
|
|
if(isset($_POST['submitKeyWord'])){
|
|
|
|
//Find the group id
|
2021-03-11 12:20:10 +00:00
|
|
|
$group = groupViaToken($_SESSION['token']);
|
2021-03-08 09:03:06 +00:00
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
//if statement to find out if the group have use all their keyWords
|
2021-03-11 12:20:10 +00:00
|
|
|
if(KeyWord::where('group_id', $group->id)->count()<$group->group_amount){
|
2021-03-08 09:03:06 +00:00
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
//Make a new keyword[Only to be used if you need to make a new of something]
|
|
|
|
$keyword = new KeyWord();
|
2021-03-08 09:03:06 +00:00
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
//Take the keyWord the user typed and set it equal to the keyword valuable
|
2021-03-08 12:09:50 +00:00
|
|
|
$keyword->key_word = $_POST['key_word'];
|
2021-03-05 09:52:42 +00:00
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
//Make foreign key from the groups table to the keyWords table
|
|
|
|
$keyword->group()->associate($group);
|
2021-03-05 09:52:42 +00:00
|
|
|
|
2021-03-08 09:29:11 +00:00
|
|
|
//Try to save it
|
|
|
|
if(!$keyword->save()){
|
2021-03-17 08:43:09 +00:00
|
|
|
header("location: ../../../Frontend/index.html?error=FailedToSave");
|
|
|
|
exit();
|
2021-03-08 09:29:11 +00:00
|
|
|
}else{
|
2021-03-17 08:43:09 +00:00
|
|
|
header("location: ../../../Frontend/index.html?success=KeyWordSaved");
|
|
|
|
exit();
|
2021-03-08 09:29:11 +00:00
|
|
|
}
|
2021-03-17 08:43:09 +00:00
|
|
|
}else{
|
|
|
|
header("location: ../../../Frontend/index.html?error=YouCantSubmitAnyMoreKeyWords");
|
|
|
|
exit();
|
2021-03-08 09:03:06 +00:00
|
|
|
}
|
2021-03-05 09:52:42 +00:00
|
|
|
|
2021-03-17 08:43:09 +00:00
|
|
|
}else{
|
|
|
|
header("location: ../../../Frontend/index.html?error=CouldNotSubmitKeyWord");
|
|
|
|
exit();
|
2021-03-08 09:29:11 +00:00
|
|
|
}
|
|
|
|
}else{
|
2021-03-17 08:43:09 +00:00
|
|
|
header("location: ../../../Frontend/index.html?error=NotLogin");
|
|
|
|
exit();
|
2021-03-08 09:03:06 +00:00
|
|
|
}
|
|
|
|
|