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

Commit

Permalink
Admin done
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Nov 16, 2018
1 parent 1785704 commit 9084e60
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 18 deletions.
14 changes: 11 additions & 3 deletions core/PollAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private function showInfo(){
$this->template->setContent( 'PRINTLINK', Utilities::generateAPILink('export', array( 'type' => 'print', 'admin' => $this->polldata->getValue(['code', 'admin']) ) ) );

$termine = array();
$terminmeta = array();
foreach( $this->polldata->getValue( ['termine'] ) as $id => $values){
if( $type === 'person' ){
$maxanz = '/' . $values["anz"];
Expand All @@ -103,13 +104,20 @@ private function showInfo(){
"TEILNEHMER" => implode( '</li><li class="list-group-item">', $submiss )
);

$terminmeta["termin_" . $id] = array( $values["bez"], $values["anz"], $values["des"] );
}

$this->template->setMultipleContent('Termin', $termine);

$this->template->setContent( 'JSONDATA', json_encode( array(
"delallurl" => Utilities::currentLinkGenerator( array( 'delete' => 'all' ) ),
"delsuburl" => Utilities::currentLinkGenerator( array( 'delete' => 'sub' ) ),
$this->template->setContent( 'JSONDATA', str_replace( array("\\r", "\\n"), array( "\\\\r", "\\\\n"), json_encode(
array(
"delallurl" => Utilities::currentLinkGenerator( array( 'delete' => 'all' ) ),
"delsuburl" => Utilities::currentLinkGenerator( array( 'delete' => 'sub' ) ),
"polladmin" => Utilities::generateLink('admin', '', $this->polldata->getValue(['code', 'admin'])),
"meta" => array( $this->polldata->getValue(['pollname']), $this->polldata->getValue(['description']) ),
"terminmeta" => $terminmeta,
"editurl" => Utilities::generateAPILink( 'editpoll', array( 'admin' => $this->polldata->getValue(['code', 'admin']) ) )
)
)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/PollCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function validateInput(){
&& !empty( $_POST['formtype'] )
&& !empty( $_POST['description'] )
){
$this->data['pollname'] = Utilities::validateInput($_POST['pollname'], self::PREG_TEXTINPUT, self::MAXL_TEXTINPUT);;
$this->data['pollname'] = Utilities::validateInput($_POST['pollname'], self::PREG_TEXTINPUT, self::MAXL_TEXTINPUT);
$this->data['formtype'] = $_POST['formtype'] == 'person' ? 'person' : 'meeting';
$this->data['description'] = Utilities::validateInput($_POST['description'], self::PREG_TEXTAREA, self::MAXL_TEXTAREA);

Expand Down
96 changes: 96 additions & 0 deletions core/api/EditPoll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* KIMB-Forms-Project
* https://github.com/KIMB-technologies/KIMB-Forms-Project
*
* (c) 2018 KIMB-technologies
* https://github.com/KIMB-technologies/
*
* released under the terms of GNU Public License Version 3
* https://www.gnu.org/licenses/gpl-3.0.txt
*/
defined( 'KIMB-FORMS-PROJECT' ) or die('Invalid Endpoint!');

class EditPoll{

private $pollid,
$pollsub,
$polldata;

/**
* Does the change in the polls json file
*/
public function __construct(){
header('Content-Type: text/plain; charset=utf-8');
$this->auth(); //dies, if not ok

if( !empty( $_POST['name'] ) && !empty( $_POST['termin'] ) && isset( $_POST['hinw'] ) && isset( $_POST['anz'] ) ){
//termin aendern
$this->changeDate( $_POST['name'], $_POST['hinw'], $_POST['anz'], $_POST['termin'] );
}
else if( !empty( $_POST['name'] ) && !empty( $_POST['desc'] ) ){
//poll meta aendern
$this->changePoll( $_POST['name'], $_POST['desc'] );
}
die( 'nok' );
}

/**
* Checks the admin code, and dies if not valid
* if ok, opens polldata and pollsubmissions
*/
private function auth(){
$polladmins = new JSONReader( 'admincodes' );
$admincode = $_GET['admin'];

if( Utilities::checkFileName($admincode) && $polladmins->isValue( [ $admincode ] ) ){
$this->pollid = $polladmins->getValue( [ $admincode ] );
$this->polldata = new JSONReader( 'poll_' . $this->pollid );

//ok
}
else{
http_response_code(403);
die( 'Unknown admin code.' );
}

}

private function changePoll( $n, $d ){
$n = Utilities::validateInput($n, PollCreator::PREG_TEXTINPUT, PollCreator::MAXL_TEXTINPUT);
$d = Utilities::validateInput($d, PollCreator::PREG_TEXTAREA, PollCreator::MAXL_TEXTAREA);

if( !empty( $n ) && !empty( $d ) ){
$this->polldata->setValue(['pollname'], $n);
$this->polldata->setValue(['description'], $d);
die( 'ok' );
}
}

private function changeDate( $n, $h, $a, $t ){
$n = Utilities::validateInput($n, PollCreator::PREG_TEXTINPUT, PollCreator::MAXL_TEXTINPUT);
$a = $this->polldata->getValue(['formtype']) === 'meeting' ? false : Utilities::validateInput($a, PollCreator::PREG_NUMBER, PollCreator::MAXL_NUMBER);
$h = Utilities::validateInput($h, PollCreator::PREG_TEXTAREA, PollCreator::MAXL_TEXTAREA);

if( $this->polldata->getValue(['formtype']) !== 'meeting' && !( $a === 0 || !empty( $a ) ) ){
die('nok');
}

if( !empty( $n ) && is_string( $t )){
$id = intval( preg_replace( '/[^0-9]/', '', $t ) );

if( $this->polldata->isValue(['termine', $id] ) ){
$this->polldata->setValue(['termine', $id],
array(
'bez' => $n,
'anz' => $a,
'des' => $h
)
);
die('ok');
}
}
}
}

?>
6 changes: 5 additions & 1 deletion core/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

$apitasks = array(
'captcha',
'export'
'export',
'editpoll'
// add more tasks
);

Expand All @@ -24,6 +25,9 @@
else if( $_GET['task'] == 'export' ){
new Export();
}
else if( $_GET['task'] == 'editpoll' ){
new EditPoll();
}
// add more tasks
}
else{
Expand Down
23 changes: 17 additions & 6 deletions core/templates/admin_de.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,25 @@ <h3>Termine</h3>
</div>
</div>

<div id="editpoll" class="d-none">
<div class="progress">
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
<div id="editpoll" class="d-none" title="Allgemeine Informationen zur Umfrage bearbeiten.">
<div class="form-group">
<input type="text" class="form-control pollname" placeholder="Name des Formulars"><br />
<textarea placeholder="Beschreibung des Formulars" class="form-control description"></textarea><br/>
<small class="form-text text-muted">Grundlegendes Markdown unterstützt: <b>**fett**</b>, <em>*kursiv*</em>, - Liste, ### Ueberschrift</small>
<div class="alert alert-danger d-none" role="alert">
Konnte Änderungen nicht speichern!
</div>
</div>
</div>
<div id="editdate" class="d-none">
<div class="progress">
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
<div id="editdate" class="d-none" title="Einen Termin der Umfrage anpassen.">
<div class="form-group">
<input type="text" class="form-control datename" placeholder="Name des Termins"><br />
<input type="number" class="form-control personlim" placeholder="Anzahl an Personen"><br />
<textarea placeholder="Hinweise zum Termin" class="form-control notes"></textarea><br/>
<small class="form-text text-muted">Grundlegendes Markdown unterstützt: <b>**fett**</b>, <em>*kursiv*</em>, - Liste, ### Ueberschrift</small>
<div class="alert alert-danger d-none" role="alert">
Konnte Änderungen nicht speichern!
</div>
</div>
</div>
<div id="deletepoll" class="d-none" title="Löschen der Umfragedaten?">
Expand Down
161 changes: 160 additions & 1 deletion core/templates/admin_en.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,167 @@
<h1>Admin</h1>

%%INNERCONTAINER%%
<div class="container">
<div class="alert alert-success" role="alert">
<div class="row">
<div class="col" title="Diese ID dient dazu, an der Umfrage teilzunehmen.">
Poll ID
</div>
<div class="col">
<input type="text" class="form-control" value="%%UMFRAGEID%%" disabled="disabled">
</div>
<div class="col form-group">
<a href="%%UMFRAGEIDLINK%%" target="_blank">
<button type="button" class="btn btn-light">Open link</button>
</a>
</div>
</div>
<div class="row">
<div class="col" title="Dieser Code erlaubt es die Umfrage zu bearbeiten und die Ergebnisse einzusehen.">
Admin-Code
</div>
<div class="col">
<input type="text" class="form-control" value="%%ADMINCODE%%" disabled="disabled">
</div>
<div class="col form-group">
<a href="%%ADMINCODELINK%%" target="_blank">
<button type="button" class="btn btn-light">Open link</button>
</a>
</div>
</div>
</div>
<div class="row">
<div class="col">
<h2 title="Name der Umfrage">%%POLLNAME%%</h2>
</div>
</div>
<div class="alert alert-info" role="alert">
<div class="row">
<div class="col">
<div class="parseasmarkdown" title="Beschreibung der Umfrage">
%%POLLDESCRIPT%%
</div>
</div>
<div class="col">
<p><span class="badge badge-secondary" title="Typ der Umfrage: Termin finden oder Helfer suchen.">%%POLLTYPE%%</span></p>
<button type="button" class="btn btn-light" id="umfreditbutton" title="Namen und Beschreibung anpassen.">
Edit
</button>
</div>
</div>
</div>
</div>

<div class="container">
<div class="row">
<div class="col">
<h3>Dates</h3>
</div>
<div class="col">
Notes
</div>
</div>
<div class="alert alert-dark" role="alert">
<!--MULTIPLE-Termin-BEGIN-->
<div class="row">
<div class="col">
<div class="form-group">
<p>
<b>%%NAME%%</b>
</p>
<p title="Anzahl abgegebener Antworten und evtl. maximaler Antworten (/max).">
%%ANZAHL%%
</p>
</div>
</div>
<div class="col">
<div class="parseasmarkdown">
%%HINWEISE%%
</div>
</div>
</div>
<div class="row">
<div class="col">
<button type="button" class="btn btn-light editbutton" id="%%TERMINID%%" title="Namen, Anzahl und Hinweise anpassen.">
Edit
</button>
</div>
<div class="col-10">
Submissions:
<ul class="list-group">
<li class="list-group-item">
%%TEILNEHMER%%
</li>
</ul>
</div>
</div>
<!--MULTIPLE-Termin-END-->
</div>
<div class="alert alert-primary" role="alert">
<div class="row form-group">
<div class="col">
<a href="%%EXPORTLINK%%" target="_blank">
<button type="button" class="btn btn-primary" title="Export der Ergebnisse als CSV.">
Export
</button>
</a>
</div>
<div class="col">
<a href="%%PRINTLINK%%" target="_blank">
<button type="button" class="btn btn-primary" title="Für den Druck optimierte Ansicht.">
Printview
</button>
</a>
</div>
</div>
<div class="row form-group">
<div class="col">
<button type="button" class="btn btn-danger" id="deleteerg" title="Die Ergebnisse löschen und die Umfrage erhalten.">
Delete submissions.
</button>
</div>
<div class="col">
<button type="button" class="btn btn-danger" id="deleteall" title="Die gesamte Umfrgage mit den Ergebnissen löschen.">
Delete poll.
</button>
</div>
</div>
</div>
</div>

<div id="editpoll" class="d-none" title="Change global information of this poll.">
<div class="form-group">
<input type="text" class="form-control pollname" placeholder="Name of this poll"><br />
<textarea placeholder="Description of this poll" class="form-control description"></textarea><br/>
<small class="form-text text-muted">Basic Markdown supported: <b>**bold**</b>, <em>*italic*</em>, - List, ### Heading</small>
<div class="alert alert-danger d-none" role="alert">
Unable to save changes.
</div>
</div>
</div>
<div id="editdate" class="d-none" title="Change a date of the poll.">
<div class="form-group">
<input type="text" class="form-control datename" placeholder="Name of this date"><br />
<input type="number" class="form-control personlim" placeholder="Number of persons"><br />
<textarea placeholder="Notes for this date" class="form-control notes"></textarea><br/>
<small class="form-text text-muted">Basic Markdown supported: <b>**bold**</b>, <em>*italic*</em>, - List, ### Heading</small>
<div class="alert alert-danger d-none" role="alert">
Unable to save changes.
</div>
</div>
</div>
<div id="deletepoll" class="d-none" title="Delete polldata?">
<div class="pollsubm" class="d-none">
<span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>
Do your really want to delete all submissions?
</div>
<div class="pollentire" class="d-none">
<span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>
Do your really want to delete the entire poll?
</div>
</div>

<script>
localStorage.removeItem('newPollData');
var template_data = JSON.parse( '%%JSONDATA%%' );
var template_name = 'admin';
</script>
4 changes: 1 addition & 3 deletions data/admincodes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"ckizzaqtzi052cbd06z9": "MfNnwiFpyo"
}
{}
4 changes: 1 addition & 3 deletions data/polls.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
"MfNnwiFpyo"
]
[]
Loading

0 comments on commit 9084e60

Please sign in to comment.