diff --git a/ajax/condition.php b/ajax/condition.php index 8ff705860..f4e581907 100644 --- a/ajax/condition.php +++ b/ajax/condition.php @@ -44,18 +44,39 @@ } $itemtype = $_REQUEST['itemtype']; -if (!isset($_REQUEST['plugin_formcreator_sections_id'])) { +if (!class_exists($itemtype)) { http_response_code(400); exit; } -$sectionId = (int) $_REQUEST['plugin_formcreator_sections_id']; -if (!class_exists($itemtype)) { +if (!is_subclass_of($itemtype, CommonDBTM::class)) { http_response_code(400); exit; } -if (!is_subclass_of($itemtype, CommonDBTM::class)) { +$form = new PluginFormcreatorForm(); +switch ($itemtype) { + case PluginFormcreatorQuestion::class: + if (!isset($_REQUEST['plugin_formcreator_sections_id'])) { + http_response_code(400); + exit; + } + $sectionId = (int) $_REQUEST['plugin_formcreator_sections_id']; + $section = new PluginFormcreatorSection(); + $section->getFromDB($sectionId); + $form->getFromDBBySection($section); + break; + case PluginFormcreatorSection::class: + if (!isset($_REQUEST['plugin_formcreator_forms_id'])) { + http_response_code(400); + exit; + } + $formId = (int) $_REQUEST['plugin_formcreator_forms_id']; + $form->getFromDB($formId); + break; +} + +if ($form->isNewItem()) { http_response_code(400); exit; } @@ -63,9 +84,5 @@ // get an empty condition HTML table row $item = new $itemtype(); $item->getFromDB($itemId); -$section = new PluginFormcreatorSection(); -$section->getFromDB($sectionId); -$form = new PluginFormcreatorForm(); -$form->getFromDBBySection($section); $condition = new PluginFormcreatorCondition(); echo $condition->getConditionHtml($form, $itemtype, $itemId); diff --git a/css/styles.css b/css/styles.css index 593dcc942..9d4219a4a 100644 --- a/css/styles.css +++ b/css/styles.css @@ -211,7 +211,7 @@ form.formcreator_form { margin: 0 0 10px; } -.formcreator_form > .form_section > h2 { +.formcreator_form .form_section > h2 { background: #1B2F62; /*#E1D39E;*/ color: #FFF; margin: 0 0 10px; diff --git a/inc/condition.class.php b/inc/condition.class.php index 1789301db..e01df5c53 100644 --- a/inc/condition.class.php +++ b/inc/condition.class.php @@ -79,6 +79,14 @@ public static function getEnumShowCondition() { ]; } + public function getEnumShowRule() { + return [ + self::SHOW_RULE_ALWAYS => __('Always displayed', 'formcreator'), + self::SHOW_RULE_HIDDEN => __('Hidden unless', 'formcreator'), + self::SHOW_RULE_SHOWN => __('Displayed unless', 'formcreator'), + ]; + } + public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) { global $DB; @@ -167,34 +175,6 @@ public function export($remove_uuid = false) { return $condition; } - /** - * get show / hide conditions for a question - * - * @param int $questionId - * @return array - */ - public function getConditionsFromQuestion($questionId) { - global $DB; - - $conditions = []; - $rows = $DB->request([ - 'SELECT' => ['id'], - 'FROM' => self::getTable(), - 'WHERE' => [ - 'itemtype' => PluginFormcreatorQuestion::class, - 'items_id' => $questionId - ], - 'ORDER' => 'order ASC' - ]); - foreach ($rows as $row) { - $condition = new static(); - $condition->getFromDB($row['id']); - $conditions[] = $condition; - } - - return $conditions; - } - /** * get conditions applied to an item * @@ -235,10 +215,6 @@ public function getConditionsFromItem(PluginFormcreatorConditionnableInterface $ * @return void */ public function showConditionsForItem($form, PluginFormcreatorConditionnableInterface $item) { - $ID = 0; - if (!$item->isNewItem()) { - $ID = $item->getID(); - } $rand = mt_rand(); echo '