Anforderung: Im Powermail Formular soll eine Selectbox erscheinen mit den künftigen Daten von Mittwoch und Freitag:
- Freitag, 20. Juni
- Mittwoch, 25. Juni
- Freitag, 27. Juni
- etc...
Hier soll der Besucher sich ein Wunschdatum für ein Event auswählen können.
Idee: Eine kleine Userfunc füllt ein TS Feld von Powermail mit den erforderlichen Daten
Umsetzung:
Neue PHP Datei direkt im fileadmin anlegen mit Namen user_specialtimefordropdown.php:
<?php
// This class generates a special dropdown list for powermail with dates
class user_dropdown {
var $limit = 26; // show the next X dates
var $weekdays_de = array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"); // Array with all Weekdays in german
var $months_de = array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"); // Array with all Month in german
var $dayx = array(3,5); // every friday and wednesday
// Main function for additional google information german
function user_main($content='', $conf=array()) {
// init
$content = '';
$counter = 0;
// let's go
for ($jahr = date('Y',time()); $jahr <= date('Y',time()) + 1; $jahr++) { // loop for current year and next year
for ($monat = 1; $monat <= 12; $monat++) { // loop from 1 up to 12 (every month)
for ($tag = 1; $tag <= 31; $tag++) { // loop from 1 up to 31 (every day)
if (checkdate($monat,$tag,$jahr)) { // if current date is a correct date (31.02 is not correct)
if (
in_array(date("w", mktime(0,0,0,$monat,$tag,$jahr)), $this->dayx)
&&
mktime(0,0,0,$monat,$tag,$jahr) >= time()
&&
$counter < $this->limit
) { // if friday or wednesday AND if in future AND if within limit
$option = '';
$option .= $this->weekdays_de[date('w',mktime(0,0,0,$monat,$tag,$jahr))].', '; // like "Mittwoch, "
$option .= date('d',mktime(0,0,0,$monat,$tag,$jahr)).'. '; // like "20. "
$option .= $this->months_de[date('n',mktime(0,0,0,$monat,$tag,$jahr))-1].' '; // like "Juni "
$option .= '11.00 C.E.T.';
$content .= '<option value="'.$option.'">';
$content .= $option;
$content .= '</option>'."\n";
$counter++; // increase counter
}
}
}
}
}
if (!empty($content)) return $content;
}
}
?>
Obiges PHP file via TS Objekt verfügbar machen:
includeLibs.user_specialtimefordropdown = fileadmin/user_specialtimefordropdown.php
# UID62
newObject = COA_INT
newObject.wrap = <div class="tx_powermail_pi1_fieldwrap_html tx_powermail_pi1_fieldwrap_html_text tx_powermail_pi1_fieldwrap_html_62">|</div>
newObject {
5 = TEXT
5.value = <label for="uid62">Bevorzugter Termin</label>
8 = TEXT
8.value = <select name="tx_powermail_pi1[uid62]" class="powermail_livedemo powermail_select powermail_uid62" id="uid62" tabindex="6">
10 = USER
10.userFunc = user_dropdown->user_main
20 = TEXT
20.value = </select>
}
In Powermail ein neues Typoscript Feld anlegen und mit dem newObject füllen lassen (im Beispiel-Bild steht fälschlicherweise lib.object anstatt newObject):
Bild: design-and-style.de/…/pm_select1.gif
Das wars...
Improvements:
- Limit und Datumscodierung erfolgt alles im PHP - dies könnte natürlich in einer besseren Welt von TS übergeben werden
Grüße, Alex 😃