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

Commit

Permalink
fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Jan 4, 2020
1 parent ff37068 commit d4444b1
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 51 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
latest
1.1.6
1.1.7
1.1
1
84 changes: 71 additions & 13 deletions core/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function saveSendData( $template ){
//parse name and mail
$name = Utilities::validateInput($_POST['name'], self::PREG_NAME, self::MAXL_NAME);
$mail = empty( $_POST['email'] ) ? '[email protected]' : Utilities::validateInput($_POST['email'], self::PREG_MAIL, self::MAXL_MAIL);
$showuser = !empty( $_POST['showuser'] ) && $_POST['showuser'] == 'show';

if( $this->pollsub === false ){
$this->pollsub = new JSONReader( 'pollsub_' . $this->id, true); //directly exclusive
Expand Down Expand Up @@ -110,14 +111,40 @@ public function saveSendData( $template ){
return false;
}

//parse additionals
$additionals = array();
if( $this->polldata->isValue(['additionals']) ){
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
if( !empty( $_POST['additional_' . $key] ) ){
$addhere = ($add['type'] === 'text' ? Utilities::validateInput($_POST['additional_' . $key], PollCreator::PREG_TEXTINPUT, PollCreator::MAXL_TEXTINPUT) : true);
if( !empty($addhere) ){
$additionals[] = $addhere;
}
else{
$this->error = LanguageManager::getTranslation('FillAdditionals');
return false;
}
}
else if ( empty( $_POST['additional_' . $key] ) && $add['require'] ){
$this->error = LanguageManager::getTranslation('FillAdditionals');
return false;
}
else{
$additionals[] = ($add['type'] === 'text' ? '' : false);
}
}
}

//save
$editcode = sha1($name . $mail) . Utilities::randomCode(10,Utilities::POLL_ID);
$addedids = array();
$userar = array(
"name" => $name,
"mail" => $mail,
"showuser" => $showuser,
"time" => time(),
"editcode" => $editcode
"editcode" => $editcode,
"additionals" => $additionals
);
foreach( $termine as $id ){
if( $this->pollsub->isValue( [$id] ) ){
Expand Down Expand Up @@ -191,33 +218,38 @@ public function showPollForm( $template ){
$template->setContent( 'POLLDESCRIPT', Utilities::optimizeOutputString($this->polldata->getValue( ['description'] )) );
$template->setContent( 'POLLID', $this->id );
$template->setContent( 'DELSUBAPI', URL::generateAPILink( 'delsubmission', array( 'poll' => $this->id ) ) );



$type = $this->polldata->getValue( ['formtype'] );

if( $type === 'meeting' ){ // meetings will always list the names!
$template->setContent( 'ATTRSHOWNAME', 'checked="checked" disabled="disabled"');
}

$termine = array();
foreach( $this->polldata->getValue( ['termine'] ) as $id => $values){
$schon = $this->pollsub->isValue( [$id] ) ? count( $this->pollsub->getValue( [$id] ) ) : 0;

if( $type === 'person' ){
$schon = $this->pollsub->isValue( [$id] ) ? count( $this->pollsub->getValue( [$id] ) ) : 0;
$anzval = $schon . '/' . $values["anz"];

$disable = $schon >= $values["anz"] ? ' disabled="disabled"' : '';
}
else{
if( $this->pollsub->isValue( [$id] ) ){
$names = array();
foreach( $this->pollsub->getValue( [$id] ) as $user){
$disable = '';
$anzval = $schon;
}
if( $schon > 0 ){
$names = array();
foreach( $this->pollsub->getValue( [$id] ) as $user){
if( $type === 'meeting' || ( !empty($user['showuser']) && $user['showuser'] ) ){
$names[] = Utilities::optimizeOutputString( $user['name'] );
}
}
if( !empty($names) ){
$anzval = Utilities::getCollapseHtml(
LanguageManager::getTranslation("Teilnehm"),
LanguageManager::getTranslation("Teilnehm") . ' – ' . $anzval,
'<ul class="list-group"><li class="list-group-item">' . implode( '</li><li class="list-group-item">', $names ). '</li></ul>'
);
}
else{
$anzval = '';
}
$disable = '';
}
$termine[] = array(
"NAME" => Utilities::optimizeOutputString( $values["bez"] ),
Expand All @@ -244,6 +276,32 @@ public function showPollForm( $template ){
)
);
}

//additional inputs
if( $this->polldata->isValue(['additionals']) ){
$texts = array();
$checks = array();
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
if( $add['type'] === 'text' ){
$texts[] = array(
"ADDNAME" => "additional_" . $key,
"ADDPLACEHOLDER" => $add['text'] . ( $add['require'] ? '' : ' (optional)' )
);
}
else {
$checks[] = array(
"ADDNAME" => "additional_" . $key,
"ADDTEXT" => $add['text'] . ( $add['require'] ? '' : ' (optional)' )
);
}
}
if( !empty($texts) ){
$template->setMultipleContent('AdditionalsText', $texts);
}
if( !empty($checks) ){
$template->setMultipleContent('AdditionalsCheck', $checks);
}
}
}

/**
Expand Down
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.1.6';
const SYS_VERSION = 'v1.1.7';

/**
* Possible chars for:
Expand Down
63 changes: 58 additions & 5 deletions core/api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,45 @@ private function csv(){

$data = array();
$data[] = array( $this->polldata->getValue(['pollname']) );


$addsHeader = array();
if( $this->polldata->isValue(['additionals']) ){
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
$addsHeader[] = $add['text'];
}
}

foreach( $this->polldata->getValue( ['termine'] ) as $id => $values){
$data[] = array();
$data[] = array( $values['bez'] );
$data[] = array_merge(
array( $values['bez'] , '', '', '', '' ),
$addsHeader
);

if( $this->pollsub->isValue( [$id] ) ){
$i = 1;
foreach( $this->pollsub->getValue( [$id] ) as $sub){
$data[] = array( '', $i++, $sub['name'], $sub['mail'], date( 'H:i:s d.m.Y', $sub['time'] ) );
$addsCells = array();
if( $this->polldata->isValue(['additionals']) ){
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
if( isset($sub['additionals'][$key]) ){
if( $add['type'] === 'checkbox' ){
$addsCells[] = ($sub['additionals'][$key] ? 'yes' : 'no');
}
else {
$addsCells[] = $sub['additionals'][$key];
}
}
else {
$addsCells[] = '';
}
}
}

$data[] = array_merge(
array( '', $i++, $sub['name'], $sub['mail'], date( 'H:i:s d.m.Y', $sub['time'] ) ),
$addsCells
);
}
}
if( $values['anz'] !== false ){
Expand Down Expand Up @@ -98,15 +128,38 @@ private function printview(){
$h.= '<h2>' . Utilities::optimizeOutputString( $this->polldata->getValue(['pollname']) ) . '</h2>';
$h .= '<div>' . $mdp->text($this->polldata->getValue( ['description'] )) . '</div>';

$addsHeader = '';
if( $this->polldata->isValue(['additionals']) ){
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
$addsHeader .= '<th>'. Utilities::optimizeOutputString( $add['text'] ) .'</th>';
}
}

$termine = array();
foreach( $this->polldata->getValue( ['termine'] ) as $id => $values){
$h .= '<hr /><h3>'. Utilities::optimizeOutputString( $values['bez'] ) .'</h3>';
$h .= empty( $values['des'] ) ? '' : '<div>'. $mdp->text($values['des']) .'</div>';
$h .= '<table style="width: 100%;"><tr><th>ID</th><th>Name</th><th>E-Mail</th><th style="width:30%;">Time</th></tr>';
$h .= '<table style="width: 100%;"><tr><th>ID</th><th>Name</th><th>E-Mail</th><th>Time</th>'. $addsHeader .'</tr>';
if( $this->pollsub->isValue( [$id] ) ){
$i = 1;
foreach( $this->pollsub->getValue( [$id] ) as $sub){
$h .= '<tr><td>'. $i++ .'</td><td>'. Utilities::optimizeOutputString( $sub['name'] ) .'</td><td>'. Utilities::optimizeOutputString( $sub['mail'] ) .'</td><td>'. date( 'H:i:s d.m.Y', $sub['time'] ) .'</td></tr>';
$addsCells = '';
if( $this->polldata->isValue(['additionals']) ){
foreach( $this->polldata->getValue(['additionals']) as $key => $add ){
if( isset($sub['additionals'][$key]) ){
if( $add['type'] === 'checkbox' ){
$addsCells .= '<td>'. ($sub['additionals'][$key] ? '&check;' : '&cross;' ) .'</td>';
}
else {
$addsCells .= '<td>'. Utilities::optimizeOutputString( $sub['additionals'][$key] ) .'</td>';
}
}
else {
$addsCells .= '<td></td>';
}
}
}
$h .= '<tr><td>'. $i++ .'</td><td>'. Utilities::optimizeOutputString( $sub['name'] ) .'</td><td>'. Utilities::optimizeOutputString( $sub['mail'] ) .'</td><td>'. date( 'H:i:s d.m.Y', $sub['time'] ) .'</td>'. $addsCells .'</tr>';
}
}
$h .= '</table>';
Expand Down
11 changes: 10 additions & 1 deletion core/templates/poll.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
"%%TEXTSEINWILL%%" : "",
"%%INNERCONTAINER%%" : "",
"%%POLLID%%" : "poll",
"%%ATTRSHOWNAME%%" : "",
"multiples" : {
"Termin" : {
"%%NAME%%" : "Name",
"%%ANZAHL%%" : "0/10",
"%%HINWEISE%%" : "**bla**",
"%%TERMINID%%" : "termin_a",
"%%DISABLE%%" : ""
}
},
"AdditionalsText" : {
"%%ADDNAME%%" : "",
"%%ADDPLACEHOLDER%%" : ""
},
"AdditionalsCheck" : {
"%%ADDNAME%%" : "",
"%%ADDTEXT%%" : ""
}
},
"%%DELSUBAPI%%": ""
}
37 changes: 28 additions & 9 deletions core/templates/poll_de.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,42 @@ <h3>Termine</h3>
%%TEXTSEINWILL%%
%%CAPTCHA%%
<div class="alert alert-primary" role="alert">
<div class="row">
<div class="row form-group">
<div class="col-sm">
<div class="form-group">
<input type="text" name="name" placeholder="Name" class="username form-control"
<input type="text" name="name" placeholder="Name" class="username form-control"
title="Name der Person, die den Termin wahrnimmt. &ndash; Pflichtfeld">
</div>
</div>
<div class="col-sm">
<div class="form-group">
<input type="email" name="email" placeholder="E-Mail-Adresse" class="usermail form-control"
<input type="email" name="email" placeholder="E-Mail-Adresse (optional)" class="usermail form-control"
title="E-Mail Adresse der Person für Nachfragen. &ndash; optional und nur für Admins sichtbar">
</div>
</div>
</div>
<div class="row">
<!--MULTIPLE-AdditionalsText-BEGIN-->
<div class="row form-group">
<div class="col-sm">
<input type="text" name="%%ADDNAME%%" placeholder="%%ADDPLACEHOLDER%%" class="form-control othersave">
</div>
</div>
<!--MULTIPLE-AdditionalsText-END-->
<!--MULTIPLE-AdditionalsCheck-BEGIN-->
<div class="row form-group">
<div class="col-sm form-check">
<label class="form-check-label">
<input type="checkbox" name="%%ADDNAME%%" value="yes" class="form-check-input othersave">
%%ADDTEXT%%
</label>
</div>
</div>
<!--MULTIPLE-AdditionalsCheck-END-->
<div class="row form-group">
<div class="col-sm form-check">
<label class="form-check-label">
<input type="checkbox" name="showuser" value="show" class="showuser form-check-input othersave" %%ATTRSHOWNAME%%>
Zeige den oben angegebenen Namen öffentlich auf dieser Seite an.
</label>
</div>
<div class="col-sm">
<input type="submit" class="btn btn-primary" value="Umfrage absenden">
<input type="submit" class="btn btn-primary form-control" value="Umfrage absenden">
</div>
</div>
</div>
Expand Down
39 changes: 29 additions & 10 deletions core/templates/poll_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,39 @@ <h3>Options</h3>
%%CAPTCHA%%
<div class="alert alert-primary" role="alert">
<div class="row">
<div class="col-sm">
<div class="form-group">
<input type="text" name="name" placeholder="Name" class="username form-control"
title="Name of the participant. &ndash; required">
</div>
<div class="col-sm form-group">
<input type="text" name="name" placeholder="Name" class="username form-control"
title="Name of the participant. &ndash; required">
</div>
<div class="col-sm form-group">
<input type="email" name="email" placeholder="E-Mail-Address (optional)" class="usermail form-control"
title="E-Mail-Address corresponding to the participant. &ndash; optional, only visible for admins">
</div>
</div>
<!--MULTIPLE-AdditionalsText-BEGIN-->
<div class="row form-group">
<div class="col-sm">
<div class="form-group">
<input type="email" name="email" placeholder="E-Mail-Address" class="usermail form-control"
title="E-Mail-Address corresponding to the participant. &ndash; optional, only visible for admins">
</div>
<input type="text" name="%%ADDNAME%%" placeholder="%%ADDPLACEHOLDER%%" class="form-control othersave">
</div>
</div>
<div class="row">
<!--MULTIPLE-AdditionalsText-END-->
<!--MULTIPLE-AdditionalsCheck-BEGIN-->
<div class="row form-group">
<div class="col-sm form-check">
<label class="form-check-label">
<input type="checkbox" name="%%ADDNAME%%" value="yes" class="form-check-input othersave">
%%ADDTEXT%%
</label>
</div>
</div>
<!--MULTIPLE-AdditionalsCheck-END-->
<div class="row form-group">
<div class="col-sm form-check">
<label class="form-check-label">
<input type="checkbox" name="showuser" value="show" class="showuser form-check-input othersave" %%ATTRSHOWNAME%%>
Publish my name provided above on this site.
</label>
</div>
<div class="col-sm">
<input type="submit" class="btn btn-primary" value="Submit poll">
</div>
Expand Down
6 changes: 4 additions & 2 deletions core/templates/pollsaved_de.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h4 class="alert-heading">Erfolgreich eingetragen!</h4>
</div>

<script>
localStorage.removeItem("pollPollDateData");
var on_site_loaded = () => poll_submissions_delete_code( '%%POLLID%%', %%VALUES%%, '%%CODE%%' );
var on_site_loaded = () => {
poll_submissions_delete_code( '%%POLLID%%', %%VALUES%%, '%%CODE%%' );
delete_wahl_for_poll( '%%POLLID%%' );
}
</script>
6 changes: 4 additions & 2 deletions core/templates/pollsaved_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h4 class="alert-heading">Successful submitted!</h4>
</div>

<script>
localStorage.removeItem("pollPollDateData");
var on_site_loaded = () => poll_submissions_delete_code( '%%POLLID%%', %%VALUES%%, '%%CODE%%' );
var on_site_loaded = () => {
poll_submissions_delete_code( '%%POLLID%%', %%VALUES%%, '%%CODE%%' );
delete_wahl_for_poll( '%%POLLID%%' );
}
</script>
3 changes: 2 additions & 1 deletion data/translation_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"TermFin": "Termin finden",
"Teilnehm": "Teilnehmende",
"mailAdminNotif": "Neue Teilnahme",
"mailNewPollNotif": "Neue Umfrage erstellt"
"mailNewPollNotif": "Neue Umfrage erstellt",
"FillAdditionals": "Bitte alle Felder füllen, nicht als optional gekennzeichnete Felder sind Pflichtfelder."
}
Loading

0 comments on commit d4444b1

Please sign in to comment.