Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Editable Submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Oct 13, 2019
1 parent 696fe5e commit 9e9fdd3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
5 changes: 4 additions & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
development
latest
1.1.0
1.1
1
2 changes: 1 addition & 1 deletion core/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Utilities{
/**
* The system's Version
*/
const SYS_VERSION = 'v1.0.8';
const SYS_VERSION = 'v1.1.0';

/**
* Possible chars for:
Expand Down
65 changes: 64 additions & 1 deletion core/api/DelUserSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,76 @@
class DelUserSubmission {

/**
*
* Input validate
*/
const PREG_CODE = '/[^A-Z0-9a-z]/';
const PREG_ID = '/[^0-9]/';

const MAXL_CODE = 50;
const MAXL_ID = 10;

/**
* Poll submission storage
*/
private $pollsub;

/**
* Deletes a submisson from a poll
* GET poll => PollID
* POST terminid => Termin, code => deletion code
*/
public function __construct(){
header('Content-Type: text/plain; charset=utf-8');

if( isset( $_POST['terminid'] ) && !empty( $_POST['code'] ) ){
// open
$this->openPollSubmissions();

//delete termin
$id = intval(Utilities::validateInput($_POST['terminid'], self::PREG_ID, self::MAXL_ID ));
$code = Utilities::validateInput($_POST['code'], self::PREG_CODE, self::MAXL_CODE );
$this->deleteSubmission( $id, $code );
}
die( 'nok' );
}

/**
* Opens the poll submission file
*/
private function openPollSubmissions() {
if( isset($_GET['poll']) ){
$polls = new JSONReader( 'polls' );
$pollid = $_GET['poll'];
if( Utilities::checkFileName($pollid) && in_array( $pollid, $polls->getArray() ) ){
$this->pollsub = new JSONReader( 'pollsub_' . $pollid, true ); //exclusive
}
}
else{
die('nok');
}
}

/**
* Search Submisson and Delete
*/
private function deleteSubmission(int $id, string $code){
if( $this->pollsub->isValue([$id]) ){
$submisson = $this->pollsub->getValue([$id]);
$key = false;
foreach( $submisson as $k => $sub){
if( $sub['editcode'] === $code ){
$key = $k;
break;
}
}
if( $key !== false ){
unset($submisson[$key]);
$this->pollsub->setValue([$id], array_values($submisson));

die('ok');
}
}
}
}

?>
8 changes: 8 additions & 0 deletions load/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,16 @@ function template_poll(){
$.post( deletesubmissonapi, { terminid : id, code : json[id] }, (data) => {
if( data == 'ok' ){
poll_submissions_delete_code_used(pollid, id);
$(this).removeClass('btn-light');
$(this).addClass('btn-success');
$(this).prepend('✔ ');
window.location.reload();
}
else{
$(this).removeClass('btn-light');
$(this).addClass('btn-danger');
$(this).prepend('✘ ');
}
});
});
}
Expand Down

0 comments on commit 9e9fdd3

Please sign in to comment.