Zum Inhalt springen

Powermail: Dynamisches Datum im Dropdown

Erstellt am 20. Juni 2008 · 6 Antworten · letzte Antwort am 12. Februar 2010

Tags: Powermail, PHP, Tipp

einpraegsam.​net ·

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 😃

pidrootline ·

hallo,

wenn ich mir eine Mail zukommen lassen so erhalte ich folgende Meldung

POWERMAIL ERROR: No title to current field found in DB (uid62)

Was muss ich da noch beachten?

lg pidrootline

einpraegsam.​net ·
pidrootline schrieb

POWERMAIL ERROR: No title to current field found in DB (uid62)

Powermail > 1.3.5 hat das Problem behoben - hier werden die Titel auch von TS Feldern übernommen

pidrootline schrieb

Könnte man auch noch für das ganze Jahr machen? Das wäre echt genial.

Quick'n dirty: Du kannst das Limit im PHP erhöhen.

steve1508 ·

Hallo Alex

Super Script funktioniert alles wunderbar.
Könnte mir allerdings jemand weiterhelfen, wie kann ich es anstellen, dass auch das aktuelle Datum in der Liste erscheint? Ich erhalte nur das Datum für den künftigen Tag.

Vielen Dank für die Hilfe

Stephan