PHP-Code:
<?php
class DC_TravelDates extends \DC_Table {
#class DC_TravelDates extends DataContainer implements \editable, \listable { // das und das in /**/ war nicht mehr nötigt wenn man \DC_Table nimmt
public function __construct($strTable, $arrModule=array()){
parent::__construct($strTable, $arrModule=array());
}
/*
public function save($varValue){
parent::save($varValue);
}
public function getPalette(){
parent::getPalette();
}
public function cut($blnDoNotRedirect=false){
parent::cut($blnDoNotRedirect);
}
public function copy($blnDoNotRedirect=false){
parent::copy($blnDoNotRedirect);
}
public function move(){
parent::move();
}
public function delete($blnDoNotRedirect=false){
parent::delete($blnDoNotRedirect);
}
public function show(){
parent::show();
}
public function showAll(){
parent::showAll();
}
*/
public function undo(){
parent::undo();
}
public function edit($intID=null, $ajaxId=null){
$this->import('Database');
$pid = $this->Database->prepare("SELECT * FROM tl_travel_dates WHERE id=?")->execute($this->Input->get('id'));
$data = $this->Database->prepare("SELECT * FROM tl_travel_dates WHERE pid=? ORDER BY dateBeg ASC")->execute($pid->pid);
$content = '<div id="tl_buttons">
<a class="header_back" onclick="Backend.getScrollOffset()" accesskey="b" title="" href="contao/main.php?do=travels&table=tl_travel_dates&id='.$pid->pid.'&rt='.RequestToken::get().'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['back'].'</a>
</div>';
$content .= '<form action="'.ampersand(\Environment::get('request'), true).'" class="tl_form tl_edit_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_filters_limit">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
</div>
<fieldset id="pal_title_legend" class="tl_tbox">
<legend onclick="AjaxRequest.toggleFieldset(this,\'title_legend\',\'tl_travel_dates\')">Termine verwalten</legend>
<div class="widget">';
$content.= '<table class="tl_listing">
<tr>
<td width="100" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_daily'].'</strong></td>
<td width="150" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_beg'].'</strong></td>
<td width="150" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_end'].'</strong></td>
<td width="100" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_cost'].'</strong></td>
<td width="200" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_info'].'</strong></td>
</tr>';
$i=0;
while($data->next()){
if($data->dateDaily == 1) { $check = ' checked="checked"'; } else { $check =""; }
$content .= '<tr>
<td class="tl_file_list"><input type="hidden" name="id['.$i.']" value="'.$data->id.'">
<input type="checkbox" name="daily['.$i.']"'.$check.' value="1"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="terbeg['.$i.']" value="'.date("d.m.Y", $data->dateBeg).'"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="terend['.$i.']" value="'.date("d.m.Y", $data->dateEnd).'"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="preis['.$i.']" value="'.$data->dateCost.'"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="info['.$i.']" value="'.$data->dateInfo.'"></td>
</tr>';
$i++;
}
$content.= '</table>';
$content .= '<p class="tl_help tl_tip" title="">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_hinweis'].'</p>
</div>
</fieldset>';
$content .= '<div class="tl_formbody_submit">
<div class="tl_submit_container">
<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">'.specialchars($GLOBALS['TL_LANG']['MSC']['save']).'</button>
</div>
</div>';
$content .= '</form>';
if($this->Input->post('FORM_SUBMIT') == 'tl_filters_limit') {
$beg = $this->Input->post('terbeg');
$end = $this->Input->post('terend');
$cost = $this->Input->post('preis');
$info = $this->Input->post('info');
$daily = $this->Input->post('daily');
$every = $this->Input->post('every');
$id = $this->Input->post('id');
$this->import('Database', 'db');
for($i=0;$i<=count($this->Input->post('terbeg'));$i++) {
if($beg[$i] != "") {
$von = explode(".",$beg[$i]);
$von_db = mktime(0,0,0,$von[1],$von[0],$von[2]);
if($every[$i]!='') {
$bis = explode(".",$end[$i]);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
while($von_db<$bis_db){
if(strcmp($every[$i],strftime('%a',$von_db))==0){
$data = $this->db->prepare("UPDATE tl_travel_dates SET tstamp = ?,dateBeg = ?,dateEnd = ?,dateCost = ?,dateInfo = ? WHERE id = ?")
->execute(time(),$von_db,$von_db,$cost[$i],$info[$i],$id[$i]);
}
$von_db=strtotime("+1 day",$von_db);
}
} else {
//prüfen ob Endtermin eine Zahl ist
if(strlen($end[$i])>=3) {
$bis = explode(".",$end[$i]);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
} else {
$start = $von[2]."-".$von[1]."-".$von[0];
$bis = date('d.m.Y',strtotime($start." +".($end[$i]-1)." days"));
$bis = explode(".",$bis);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
}
//tägliche Reise
if(isset($daily[$i])) {
$daily_db = 1;
} else {
$daily_db = 0;
}
$data = $this->db->prepare("UPDATE tl_travel_dates SET tstamp = ?,dateBeg = ?,dateEnd = ?,dateCost = ?,dateInfo = ?,dateDaily = ? WHERE id = ?")
->execute(time(),$von_db,$bis_db,$cost[$i],$info[$i],$daily_db,$id[$i]);
}
}
} //for end
$this->log('Edit '.count($this->Input->post('terbeg')).' entrys in "'.$this->strTable.'".pid='.$pid->pid, 'DC_Table_Dates edit()', TL_GENERAL);
//Weiterleiten
$this->redirect("contao/main.php?do=travels&table=tl_travel_dates&id=".$pid->pid."&rt=".RequestToken::get());
}
return $content;
}
public function create($set=array()) {
$content = '<div id="tl_buttons">
<a class="header_back" onclick="Backend.getScrollOffset()" accesskey="b" title="" href="contao/main.php?do=travels&table=tl_travel_dates&id='.$pid->pid.'&rt='.RequestToken::get().'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['back'].'</a>
</div>';
$content .= '<form action="'.ampersand(\Environment::get('request'), true).'" class="tl_form tl_edit_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_filters_limit">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
</div>
<fieldset id="pal_title_legend" class="tl_tbox">
<legend onclick="AjaxRequest.toggleFieldset(this,\'title_legend\',\'tl_travel_dates\')">Termine verwalten</legend>
<div class="widget">';
$content.= '<table class="tl_listing">
<tr>
<td width="100" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_daily'].'</strong></td>
<td width="150" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_beg'].'</strong></td>
<td width="150" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_end'].'</strong></td>
<td width="80" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_cost'].'</strong></td>
<td width="180" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_info'].'</strong></td>
<td width="100" class="tl_file_list"><strong>'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_every'].'</strong></td>
</tr>';
$max=$i+25;
for($i=0;$i<$max;$i++) {
$content .= '<tr>
<td class="tl_file_list"><input type="checkbox" name="daily['.$i.']" value="1"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="terbeg['.$i.']" value=""></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="terend['.$i.']" value=""></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="preis['.$i.']" value="0"></td>
<td class="tl_file_list"><input type="text" class="tl_text" name="info['.$i.']" value=""></td>
<td class="tl_file_list"><select name="every['.$i.']" class="tl_select" style="width:110px;">
<option value="">-----------------</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_mon_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_mon'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_tue_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_tue'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_wed_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_wed'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_thu_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_thu'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_fri_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_fri'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_sat_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_sat'].'</option>
<option value="'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_sun_val'].'">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_sun'].'</option>
</select></td>
</tr>';
}
$content.= '</table>';
$content .= '<p class="tl_help tl_tip" title="">'.$GLOBALS['TL_LANG']['tl_travel_dates']['form_hinweis'].'</p>
</div>
</fieldset>';
$content .= '<div class="tl_formbody_submit">
<div class="tl_submit_container">
<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">'.specialchars($GLOBALS['TL_LANG']['MSC']['save']).'</button>
</div>
</div>';
$content .= '</form>';
if($this->Input->post('FORM_SUBMIT') == 'tl_filters_limit') {
$beg = $this->Input->post('terbeg');
$end = $this->Input->post('terend');
$cost = $this->Input->post('preis');
$info = $this->Input->post('info');
$daily = $this->Input->post('daily');
$every = $this->Input->post('every');
$pid = $this->Input->get('pid');
$cnt = 0;
$this->import('Database', 'db');
for($i=0;$i<=count($this->Input->post('terbeg'));$i++) {
if($beg[$i] != "") {
$von = explode(".",$beg[$i]);
$von_db = mktime(0,0,0,$von[1],$von[0],$von[2]);
if($every[$i]!='') {
$bis = explode(".",$end[$i]);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
while($von_db<$bis_db) {
if(strcmp($every[$i],strftime('%a',$von_db))==0) {
$data = $this->db->prepare("INSERT INTO tl_travel_dates (pid,tstamp,dateBeg,dateEnd,dateCost,dateInfo) VALUES (?, ?, ?, ?, ?, ?)")
->execute($pid,time(),$von_db,$von_db,$cost[$i],$info[$i]);
$insertID = $data->insertId;
}
$von_db=strtotime("+1 day",$von_db);
}
} else {
//prüfen ob Endtermin eine Zahl ist
if(strlen($end[$i])>=3) {
$bis = explode(".",$end[$i]);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
} else {
$start = $von[2]."-".$von[1]."-".$von[0];
$bis = date('d.m.Y',strtotime($start." +".($end[$i]-1)." days"));
$bis = explode(".",$bis);
$bis_db = mktime(0,0,0,$bis[1],$bis[0],$bis[2]);
}
//tägliche Reise
if(isset($daily[$i])) {
$daily_db = 1;
} else {
$daily_db = 0;
}
$data = $this->db->prepare("INSERT INTO tl_travel_dates (pid,tstamp,dateBeg,dateEnd,dateCost,dateInfo,dateDaily) VALUES (?, ?, ?, ?, ?, ?, ?)")
->execute($pid,time(),$von_db,$bis_db,$cost[$i],$info[$i],$daily_db);
$insertID = $data->insertId;
}
$cnt++;
}
} //for end
$this->log('New entrys ('.$cnt.') in "'.$this->strTable.'" has been created '.$this->getParentEntries($this->strTable, $insertID), 'DC_Table_Dates create()', TL_GENERAL);
//Weiterleiten
$this->redirect("contao/main.php?do=travels&table=tl_travel_dates&id=".$pid."&rt=".RequestToken::get());
}
return $content;
}
}
Lesezeichen