Skip to content

Commit

Permalink
Sync Driver with DC_Table
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauss committed Jan 19, 2023
1 parent aa421d4 commit c771c33
Showing 1 changed file with 63 additions and 21 deletions.
84 changes: 63 additions & 21 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function edit($intId=null, $ajaxId=null)
// Render boxes
foreach ($boxes as $k=>$v)
{
$strAjax = '';
$arrAjax = array();
$blnAjax = false;
$key = '';
$cls = '';
Expand All @@ -275,7 +275,8 @@ public function edit($intId=null, $ajaxId=null)
$class .= (($cls && $legend) ? ' ' . $cls : '');
}

$return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_'.$key.'"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend;
$return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend;
$thisId = '';

// Build rows of the current box
foreach ($v as $vv)
Expand All @@ -284,10 +285,26 @@ public function edit($intId=null, $ajaxId=null)
{
if ($blnAjax && Environment::get('isAjaxRequest'))
{
return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="'.StringUtil::specialchars($this->strPalette).'">';
if ($ajaxId == $thisId)
{
if (($intLatestVersion = $objVersions->getLatestVersion()) !== null)
{
$arrAjax[$thisId] .= '<input type="hidden" name="VERSION_NUMBER" value="' . $intLatestVersion . '">';
}

return $arrAjax[$thisId] . '<input type="hidden" name="FORM_FIELDS[]" value="' . StringUtil::specialchars($this->strPalette) . '">';
}

if (\count($arrAjax) > 1)
{
$current = "\n" . '<div id="' . $thisId . '" class="subpal cf">' . $arrAjax[$thisId] . '</div>';
unset($arrAjax[$thisId]);
end($arrAjax);
$thisId = key($arrAjax);
$arrAjax[$thisId] .= $current;
}
}

$blnAjax = false;
$return .= "\n" . '</div>';

continue;
Expand All @@ -296,8 +313,9 @@ public function edit($intId=null, $ajaxId=null)
if (preg_match('/^\[.*]$/', $vv))
{
$thisId = 'sub_' . substr($vv, 1, -1);
$blnAjax = ($ajaxId == $thisId && Environment::get('isAjaxRequest')) ? true : false;
$return .= "\n" . '<div id="'.$thisId.'">';
$arrAjax[$thisId] = '';
$blnAjax = ($ajaxId == $thisId && Environment::get('isAjaxRequest')) ? true : $blnAjax;
$return .= "\n" . '<div id="' . $thisId . '" class="subpal cf">';

continue;
}
Expand Down Expand Up @@ -340,7 +358,7 @@ public function edit($intId=null, $ajaxId=null)
$this->objActiveRecord->{$this->strField} = $this->varValue;

// Build the row and pass the current palette string (thanks to Tristan Lins)
$blnAjax ? $strAjax .= $this->row($this->strPalette) : $return .= $this->row($this->strPalette);
$blnAjax ? $arrAjax[$thisId] .= $this->row($this->strPalette) : $return .= $this->row($this->strPalette);
}

$class = 'tl_box';
Expand All @@ -363,26 +381,26 @@ public function edit($intId=null, $ajaxId=null)

// Submit buttons
$arrButtons = array();
$arrButtons['save'] = '<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">'.$GLOBALS['TL_LANG']['MSC']['save'].'</button>';
$arrButtons['save'] = '<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['save'] . '</button>';

if (!Input::get('nb'))
{
$arrButtons['saveNclose'] = '<button type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c">'.$GLOBALS['TL_LANG']['MSC']['saveNclose'].'</button>';
$arrButtons['saveNclose'] = '<button type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['saveNclose'] . '</button>';
}

if (!Input::get('popup') && !($GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ?? null) && !($GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] ?? null))
{
$arrButtons['saveNcreate'] = '<button type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n">'.$GLOBALS['TL_LANG']['MSC']['saveNcreate'].'</button>';
$arrButtons['saveNcreate'] = '<button type="submit" name="saveNcreate" id="saveNcreate" class="tl_submit" accesskey="n">' . $GLOBALS['TL_LANG']['MSC']['saveNcreate'] . '</button>';
}

if ($GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'] ?? null)
{
$arrButtons['saveNedit'] = '<button type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e">'.$GLOBALS['TL_LANG']['MSC']['saveNedit'].'</button>';
$arrButtons['saveNedit'] = '<button type="submit" name="saveNedit" id="saveNedit" class="tl_submit" accesskey="e">' . $GLOBALS['TL_LANG']['MSC']['saveNedit'] . '</button>';
}

if (!Input::get('popup') && ($this->ptable || ($GLOBALS['TL_DCA'][$this->strTable]['config']['switchToEdit'] ?? null) || ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] ?? null) == 4))
{
$arrButtons['saveNback'] = '<button type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g">'.$GLOBALS['TL_LANG']['MSC']['saveNback'].'</button>';
$arrButtons['saveNback'] = '<button type="submit" name="saveNback" id="saveNback" class="tl_submit" accesskey="g">' . $GLOBALS['TL_LANG']['MSC']['saveNback'] . '</button>';
}

if ($this->editLang) {
Expand All @@ -406,7 +424,23 @@ public function edit($intId=null, $ajaxId=null)
}
}

$strButtons = implode(' ', $arrButtons);
if (\count($arrButtons) < 3)
{
$strButtons = implode(' ', $arrButtons);
}
else
{
$strButtons = array_shift($arrButtons) . ' ';
$strButtons .= '<div class="split-button">';
$strButtons .= array_shift($arrButtons) . '<button type="button" id="sbtog">' . Image::getHtml('navcol.svg') . '</button> <ul class="invisible">';

foreach ($arrButtons as $strButton)
{
$strButtons .= '<li>' . $strButton . '</li>';
}

$strButtons .= '</ul></div>';
}

// Add the buttons and end the form
$return .= '
Expand All @@ -421,6 +455,13 @@ public function edit($intId=null, $ajaxId=null)

$strVersionField = '';

// Store the current version number (see #8412)
if (($intLatestVersion = $objVersions->getLatestVersion()) !== null)
{
$strVersionField = '
<input type="hidden" name="VERSION_NUMBER" value="' . $intLatestVersion . '">';
}

$strBackUrl = $this->getReferer(true);

// Set the focus if there is an error
Expand All @@ -436,15 +477,15 @@ public function edit($intId=null, $ajaxId=null)

// Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field)
$return = $version . Message::generate() . ($this->noReload ? '
<p class="tl_error">'.$GLOBALS['TL_LANG']['ERR']['general'].'</p>' : '').'
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . '
<div id="tl_buttons">' . (Input::get('nb') ? '&nbsp;' : '
<a href="'.$strBackUrl.'" class="header_back" title="'.StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']).'" accesskey="b" onclick="Backend.getScrollOffset()">'.$GLOBALS['TL_LANG']['MSC']['backBT'].'</a>') . '
<a href="' . $strBackUrl . '" class="header_back" title="' . StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>') . '
</div>
<form id="'.$this->strTable.'" class="tl_form tl_edit_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"'.(!empty($this->onsubmit) ? ' onsubmit="'.implode(' ', $this->onsubmit).'"' : '').'>
<form id="' . $this->strTable . '" class="tl_form tl_edit_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '>
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="'.$this->strTable.'">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . $strVersionField . '
<input type="hidden" name="FORM_FIELDS[]" value="'.StringUtil::specialchars($this->strPalette).'">'.$return;
<input type="hidden" name="FORM_FIELDS[]" value="' . StringUtil::specialchars($this->strPalette) . '">' . $return;

// Reload the page to prevent _POST variables from being sent twice
if (!$this->noReload && Input::post('FORM_SUBMIT') == $this->strTable)
Expand Down Expand Up @@ -684,7 +725,8 @@ public function copy($blnDoNotRedirect = false)
}

// Switch to edit mode
if (!$blnDoNotRedirect) {
if (!$blnDoNotRedirect)
{
$this->redirect($this->switchToEdit($insertId));
}

Expand Down Expand Up @@ -805,7 +847,7 @@ public function ajaxTreeView($id, $level)
$arrIds = array();

// Get records
$objRows = $this->Database->prepare("SELECT id FROM " . $table . " WHERE ({$this->pidColumnName}=0 OR {$this->pidColumnName} IS NULL) AND pid=?" . ($hasSorting ? " ORDER BY sorting" : ""))
$objRows = $this->Database->prepare("SELECT id FROM " . $table . " WHERE ({$this->pidColumnName}=0 OR {$this->pidColumnName} IS NULL) AND pid=?" . ($hasSorting ? " ORDER BY sorting, id" : ""))
->execute($id);

while ($objRows->next())
Expand All @@ -832,7 +874,7 @@ public function ajaxTreeView($id, $level)

for ($i=0, $c=\count($arrIds); $i<$c; $i++)
{
$return .= ' ' . trim($this->generateTree($table, $arrIds[$i], array('p'=>($arrIds[$i-1] ?? null), 'n'=>($arrIds[$i+1] ?? null)), $hasSorting, $margin, ($blnClipboard ? $arrClipboard : false), $arrClipboard !== null && ($id == $arrClipboard ['id'] || (\is_array($arrClipboard ['id']) && \in_array($id, $arrClipboard ['id'])) || (!$blnPtable && !\is_array($arrClipboard['id']) && \in_array($id, $this->Database->getChildRecords($arrClipboard['id'], $table)))), $blnProtected));
$return .= ' ' . trim($this->generateTree($table, $arrIds[$i], array('p'=>($arrIds[$i-1] ?? null), 'n'=>($arrIds[$i+1] ?? null)), $hasSorting, $margin, ($blnClipboard ? $arrClipboard : false), $arrClipboard !== null && ($id == $arrClipboard['id'] || (\is_array($arrClipboard['id']) && \in_array($id, $arrClipboard['id'])) || (!$blnPtable && !\is_array($arrClipboard['id']) && \in_array($id, $this->Database->getChildRecords($arrClipboard['id'], $table)))), $blnProtected));
}

return $return;
Expand Down

0 comments on commit c771c33

Please sign in to comment.