Commit ee0c6718 authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #6255 - Inline Report Editing: Initial working version with db hard-coded

parent cb2e2a70
Pipeline #711 passed with stage
in 1 minute and 47 seconds
<?php
/**
* Created by PhpStorm.
* User: ep
* Date: 12/23/15
* Time: 6:16 PM
*/
namespace qfq;
use qfq;
require_once(__DIR__ . '/../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/exceptions/UserFormException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
/**
* Return JSON encoded answer
*/
$answer = array();
$answer[API_REDIRECT] = API_ANSWER_REDIRECT_AUTO;
$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
$answer[API_MESSAGE] = '';
try {
try {
if (isset($_POST[REPORT_INLINE_BODYTEXT])) {
$qfq = new QuickFormQuery(['bodytext' => '']);
$data = $qfq->saveReport();
}
// Redirect to previous page
header("Location: {$_SERVER['HTTP_REFERER']}");
exit;
} catch (qfq\UserFormException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (qfq\CodeException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (qfq\DbException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
}
} catch (\Exception $e) {
$answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
}
header("Content-Type: application/json");
echo json_encode($answer);
......@@ -1189,6 +1189,8 @@ const INDEX_PHP = 'index.php';
const T3DATA_BODYTEXT = 'bodytext';
const T3DATA_BODYTEXT_RAW = 'bodytext-raw';
const T3DATA_UID = 'uid';
const T3DATA_PID = 'pid';
const REPORT_INLINE_BODYTEXT = 'bodytext';
// Special Column to check for uploads
const COLUMN_PATH_FILE_NAME = 'pathFileName';
......
......@@ -1335,7 +1335,7 @@ class QuickFormQuery {
$html = '';
if ($this->store->getVar(TYPO3_BE_USER, STORE_TYPO3, SANITIZE_ALLOW_ALNUMX)) {
$html .= $this->doInlineReport();
$html .= $this->buildInlineReport();
}
$html .= $report->process($this->t3data[T3DATA_BODYTEXT]);
......@@ -1351,29 +1351,62 @@ class QuickFormQuery {
* @throws UserFormException
* @throws UserReportException
*/
private function doInlineReport() {
private function buildInlineReport() {
$uid = $this->t3data[T3DATA_UID];
$pid = $this->t3data[T3DATA_PID];
$icon = Support::wrapTag('<span class="' . GLYPH_ICON . ' ' . GLYPH_ICON_TASKS . '">', '');
$showEditBoxJs = '$("#tt-content-edit-' . $uid . '").toggleClass("hidden")';
$toggleBtn = Support::wrapTag("<a href='#' onclick='$showEditBoxJs' style='float:right;'>", $icon);
$showFormJs = '$("#tt-content-edit-' . $uid . '").toggleClass("hidden")';
$toggleBtn = Support::wrapTag("<a href='#' onclick='$showFormJs' style='float:right;'>", $icon);
$saveBtnAttributes = Support::doAttribute('class', 'btn btn-default btn-block');
$saveBtnAttributes .= Support::doAttribute('id', "tt-content-save-$uid");
$saveBtn = Support::wrapTag("<button $saveBtnAttributes>", 'Save');
$saveBtnAttributes .= Support::doAttribute('type', 'submit');
$saveBtn = Support::wrapTag("<button $saveBtnAttributes>", 'Save & Reload');
$ttContentCode = Support::htmlEntityEncodeDecode(MODE_ENCODE, $this->t3data[T3DATA_BODYTEXT_RAW]);
$codeBoxAttributes = Support::doAttribute('style', "width:100%; height:200px;");
$codeBoxAttributes .= Support::doAttribute('id', "tt-content-code-$uid");
$codeBoxAttributes .= Support::doAttribute('name', REPORT_INLINE_BODYTEXT);
$codeBox = Support::wrapTag("<textarea $codeBoxAttributes>", $ttContentCode);
$editBox = join(' ', [$saveBtn, $codeBox]);
$editBox = Support::wrapTag("<div id='tt-content-edit-$uid' class='hidden'>", $editBox);
$hiddenInput = "<input type='hidden' name='uid' value='$uid'>".
"<input type='hidden' name='pid' value='$pid'>";
$form = join(' ', [$saveBtn, $codeBox, $hiddenInput]);
$formAttributes = Support::doAttribute('id', "tt-content-edit-$uid");
$formAttributes .= Support::doAttribute('class', 'hidden');
$formAttributes .= Support::doAttribute('method', 'post');
$formAttributes .= Support::doAttribute('action', API_DIR . '/saveReport.php');
$form = Support::wrapTag("<form $formAttributes>", $form);
// $this->store->setStore(['form' => 'ReportForm', 'r' => $uid], STORE_TYPO3, true);
// $reportForm = $this->doForm(FORM_LOAD);
return $toggleBtn . $editBox;
return $toggleBtn . $form;
}
/**
* @return string
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function saveReport() {
$bodytext = Support::htmlEntityEncodeDecode(MODE_DECODE, $_POST[REPORT_INLINE_BODYTEXT]);
$uid = $_POST['uid'];
$pid = $_POST['pid'];
$db = 'elvill_qfq_t3';
// Update bodytext
$sql = "UPDATE $db.tt_content SET bodytext = ?, tstamp = UNIX_TIMESTAMP(NOW()) WHERE uid = ?";
$res = $this->dbArray[$this->dbIndexQfq]->sql($sql, ROW_REGULAR, [$bodytext, $uid]);
// Clear cache
$sql = "DELETE FROM $db.cf_cache_pagesection WHERE identifier LIKE '$pid%'";
$this->dbArray[$this->dbIndexQfq]->sql($sql);
return '';
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment