1<?php
2/**
3 * Frontend to edit an instance.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public License,
6 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
7 * obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * @package phpMyFAQ
10 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
11 * @copyright 2012-2020 phpMyFAQ Team
12 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
13 * @link https://www.phpmyfaq.de
14 * @since 2012-04-16
15 */
16
17use phpMyFAQ\Filter;
18use phpMyFAQ\Instance;
19
20if (!defined('IS_VALID_PHPMYFAQ')) {
21    http_response_code(400);
22    exit();
23}
24?>
25  <header class="row">
26    <div class="col-lg-12">
27      <h2 class="page-header">
28        <i aria-hidden="true" class="fa fa-wrench"></i> <?= $PMF_LANG['ad_menu_instances']; ?>
29      </h2>
30    </div>
31  </header>
32<?php
33if ($user->perm->checkRight($user->getUserId(), 'editinstances')) {
34    $instanceId = Filter::filterInput(INPUT_GET, 'instance_id', FILTER_VALIDATE_INT);
35
36    $instance = new Instance($faqConfig);
37    $instanceData = $instance->getInstanceById($instanceId);
38
39    ?>
40  <form action="?action=updateinstance" method="post" accept-charset="utf-8">
41    <input type="hidden" name="instance_id" value="<?= $instanceData->id ?>"/>
42    <div class="form-group row">
43      <label for="url" class="col-lg-2 col-form-label"><?= $PMF_LANG['ad_instance_url'] ?>:</label>
44      <div class="col-lg-8">
45        <input type="url" name="url" id="url" class="form-control" value="<?= $instanceData->url ?>" required>
46      </div>
47    </div>
48    <div class="form-group row">
49      <label for="instance" class="col-lg-2 col-form-label"><?= $PMF_LANG['ad_instance_path'] ?>:</label>
50      <div class="col-lg-8">
51        <input type="text" name="instance" id="instance" class="form-control" required
52               value="<?= $instanceData->instance ?>">
53      </div>
54    </div>
55    <div class="form-group row">
56      <label for="comment" class="col-lg-2 col-form-label"><?= $PMF_LANG['ad_instance_name'] ?>:</label>
57      <div class="col-lg-8">
58        <input type="text" name="comment" id="comment" class="form-control" required
59               value="<?= $instanceData->comment ?>">
60      </div>
61    </div>
62    <div class="form-group row">
63      <label class="col-lg-2 col-form-label"><?= $PMF_LANG['ad_instance_config'] ?>:</label>
64      <div class="col-lg-8">
65        <p class="form-control-static">
66            <?php
67            foreach ($instance->getInstanceConfig($instanceData->id) as $key => $config) {
68                echo '<span class="uneditable-input">' . $key . ': ' . $config . '</span><br/>';
69            }
70            ?>
71        </p>
72      </div>
73    </div>
74    <div class="form-group row">
75      <div class="offset-lg-2 col-lg-4">
76        <button class="btn btn-primary" type="submit">
77            <?= $PMF_LANG['ad_instance_button'] ?>
78        </button>
79        <a class="btn btn-info" href="?action=instances">
80            <?= $PMF_LANG['ad_entry_back'] ?>
81        </a>
82      </div>
83    </div>
84  </form>
85    <?php
86} else {
87    echo $PMF_LANG['err_NotAuth'];
88}
89