Skip to content

Commit 40afda3

Browse files
committed
fix(install): restore lost JSON type creation
1 parent decaafe commit 40afda3

File tree

1 file changed

+79
-25
lines changed

1 file changed

+79
-25
lines changed

inc/form.class.php

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,31 +1654,85 @@ function export($remove_uuid = false) {
16541654
* Display an html form to upload a json with forms data
16551655
*/
16561656
public function showImportForm() {
1657-
echo "<form name='form' method='post' action='".
1658-
PluginFormcreatorForm::getFormURL().
1659-
"?import_send=1' enctype=\"multipart/form-data\">";
1660-
1661-
echo "<div class='spaced' id='tabsbody'>";
1662-
echo "<table class='tab_cadre_fixe' id='mainformtable'>";
1663-
echo "<tr class='headerRow'>";
1664-
echo "<th>";
1665-
echo __("Import forms");
1666-
echo "</th>";
1667-
echo "</tr>";
1668-
echo "<tr>";
1669-
echo "<td>";
1670-
echo Html::file(['name' => 'json_file']);
1671-
echo "</td>";
1672-
echo "</tr>";
1673-
echo "<td class='center'>";
1674-
echo Html::submit(_x('button', 'Send'), ['name' => 'import_send']);
1675-
echo "</td>";
1676-
echo "</tr>";
1677-
echo "<tr>";
1678-
echo "</table>";
1679-
echo "</div>";
1680-
1681-
Html::closeForm();
1657+
$documentType = new DocumentType();
1658+
$jsonTypeExists = $documentType->getFromDBByQuery("WHERE LOWER(`ext`)='json'");
1659+
$jsonTypeEnabled = $jsonTypeExists && $documentType->getField('is_uploadable');
1660+
$canAddType = $documentType->canCreate();
1661+
$canUpdateType = $documentType->canUpdate();
1662+
1663+
if (! ($jsonTypeExists && $jsonTypeEnabled)) {
1664+
if (!$jsonTypeExists) {
1665+
$message = __('Upload of JSON files not allowed.', 'formcreator');
1666+
if ($canAddType) {
1667+
$destination = PluginFormcreatorForm::getFormURL();
1668+
$message .= __('You may allow JSON files right now.', 'formcreator');
1669+
$button = Html::submit(_x('button','Create', 'formcreator'), array('name' => 'filetype_create'));
1670+
} else {
1671+
$destination = PluginFormcreatorForm::getSearchURL();
1672+
$message .= __('Please contact your GLPI administrator.', 'formcreator');
1673+
$button = Html::submit(_x('button','Back', 'formcreator'), array('name' => 'filetype_back'));
1674+
}
1675+
} else {
1676+
$message = __('Upload of JSON files not enabled.', 'formcreator');
1677+
if ($canUpdateType) {
1678+
$destination = PluginFormcreatorForm::getFormURL();
1679+
$message .= __('You may enable JSON files right now.', 'formcreator');
1680+
$button = Html::submit(_x('button','Enable', 'formcreator'), array('name' => 'filetype_enable'));
1681+
} else {
1682+
$message .= __('You may enable JSON files right now.', 'formcreator');
1683+
$message .= __('Please contact your GLPI administrator.', 'formcreator');
1684+
$button = Html::submit(_x('button','Back', 'formcreator'), array('name' => 'filetype_back'));
1685+
}
1686+
}
1687+
echo '<div class="spaced" id="tabsbody">';
1688+
echo "<form name='form' method='post' action='". $destination."'>";
1689+
echo '<table class="tab_cadre_fixe" id="mainformtable">';
1690+
echo '<tr class="headerRow">';
1691+
echo '<th>';
1692+
echo __('Import forms');
1693+
echo '</th>';
1694+
echo '</tr>';
1695+
echo '<tr>';
1696+
echo '<td class="center">';
1697+
echo $message;
1698+
echo '</td>';
1699+
echo '</tr>';
1700+
echo '<td class="center">';
1701+
echo $button;
1702+
echo '</td>';
1703+
echo '</tr>';
1704+
echo '<tr>';
1705+
echo '</table>';
1706+
echo '</div>';
1707+
Html::closeForm();
1708+
echo '</div>';
1709+
} else {
1710+
echo "<form name='form' method='post' action='".
1711+
PluginFormcreatorForm::getFormURL().
1712+
"?import_send=1' enctype=\"multipart/form-data\">";
1713+
1714+
echo "<div class='spaced' id='tabsbody'>";
1715+
echo "<table class='tab_cadre_fixe' id='mainformtable'>";
1716+
echo "<tr class='headerRow'>";
1717+
echo "<th>";
1718+
echo __("Import forms");
1719+
echo "</th>";
1720+
echo "</tr>";
1721+
echo "<tr>";
1722+
echo "<td>";
1723+
echo Html::file(['name' => 'json_file']);
1724+
echo "</td>";
1725+
echo "</tr>";
1726+
echo "<td class='center'>";
1727+
echo Html::submit(_x('button', 'Send'), ['name' => 'import_send']);
1728+
echo "</td>";
1729+
echo "</tr>";
1730+
echo "<tr>";
1731+
echo "</table>";
1732+
echo "</div>";
1733+
1734+
Html::closeForm();
1735+
}
16821736
}
16831737

16841738
/**

0 commit comments

Comments
 (0)