updateActive()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
c 0
b 0
f 0
nc 8
nop 0
dl 0
loc 20
rs 9.7998
1
<?php declare(strict_types=1);
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    {@link https://xoops.org/ XOOPS Project}
15
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
16
 * @author       Brian Wahoff <[email protected]>
17
 * @author       Eric Juden <[email protected]>
18
 * @author       XOOPS Development Team
19
 */
20
21
use Xmf\Module\Admin;
22
use Xmf\Request;
23
use XoopsModules\Xhelp\{
24
    Helper,
25
    FaqAdapterFactory,
26
    Utility
27
};
28
29
require_once __DIR__ . '/admin_header.php';
30
xoops_load('XoopsPagenav');
31
// require_once XHELP_CLASS_PATH . '/faqAdapterFactory.php';
32
// require_once XHELP_CLASS_PATH . '/faqAdapter.php';
33
34
$op = 'default';
35
36
if (Request::hasVar('op', 'REQUEST')) {
37
    $op = $_REQUEST['op'];
38
}
39
40
switch ($op) {
41
    case 'updateActive':
42
        updateActive();
43
        break;
44
    case 'manage':
45
    default:
46
        manage();
47
        break;
48
}
49
50
/**
51
 *
52
 */
53
function manage()
54
{
55
    global $icons;
56
    $faqAdapters = FaqAdapterFactory::installedAdapters();
57
    $myAdapter   = FaqAdapterFactory::getFaqAdapter();
58
    xoops_cp_header();
59
    //echo $oAdminButton->renderButtons('manFaqAdapters');
60
    $adminObject = Admin::getInstance();
61
    $adminObject->displayNavigation(basename(__FILE__));
62
63
    echo "<form method='post' action='" . XHELP_ADMIN_URL . "/faqAdapter.php?op=updateActive'>";
0 ignored issues
show
Bug introduced by
The constant XHELP_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
    echo "<table width='100%' cellspacing='1' class='outer'>";
65
66
    if (!empty($faqAdapters)) {
67
        echo "<tr><th colspan='5'>" . _AM_XHELP_MENU_MANAGE_FAQ . '</th></tr>';
68
        echo "<tr class='head'>
69
                  <td>" . _AM_XHELP_TEXT_NAME . '</td>
70
                  <td>' . _AM_XHELP_TEXT_PLUGIN_VERSION . '</td>
71
                  <td>' . _AM_XHELP_TEXT_TESTED_VERSIONS . '</td>
72
                  <td>' . _AM_XHELP_TEXT_AUTHOR . '</td>
73
                  <td>' . _AM_XHELP_TEXT_ACTIVE . '</td>
74
              </tr>';
75
76
        $activeAdapter = Utility::getMeta('faq_adapter');
77
        foreach ($faqAdapters as $name => $oAdapter) {
78
            $modname     = $name;
79
            $author      = $oAdapter->meta['author'];
80
            $author_name = $author;
81
82
            if ('' != $oAdapter->meta['url']) {                                                         // If a website is specified
83
                $name = "<a href='" . $oAdapter->meta['url'] . "'>" . $oAdapter->meta['name'] . '</a>'; // Add link to module name
84
            }
85
            if ('' != $oAdapter->meta['author_email']) {
86
                $author = "<a href='mailto:" . $oAdapter->meta['author_email'] . "'>" . $author_name . '</a>';  // Add link to email author
87
            }
88
            echo "<tr class='even'>
89
                      <td>" . $name . '</td>
90
                      <td>' . $oAdapter->meta['version'] . '</td>
91
                      <td>' . $oAdapter->meta['tested_versions'] . '</td>
92
                      <td>' . $author . "</td>
93
                      <td>
94
                          <input type='image' src='" . ($activeAdapter == $modname ? XHELP_IMAGE_URL . '/on.png' : XHELP_IMAGE_URL . '/off.png') . "' name='modname' value='" . $modname . "' style='border:0;background:transparent;'>
95
                      </td>
96
                  </tr>";
97
        }
98
    } else {
99
        // Display "no adapters found" message
100
        echo '<tr><th>' . _AM_XHELP_MENU_MANAGE_FAQ . '</th></tr>';
101
        echo "<tr><td class='even'>" . _AM_XHELP_TEXT_NO_FILES . '</td></tr>';
102
    }
103
    echo '</table></form>';
104
105
    if (is_object($myAdapter)) {
106
        $faq = $myAdapter->createFaq();
0 ignored issues
show
Unused Code introduced by
The assignment to $faq is dead and can be removed.
Loading history...
107
    }
108
109
    require_once __DIR__ . '/admin_footer.php';
110
}
111
112
/**
113
 *
114
 */
115
function updateActive()
116
{
117
    $helper = Helper::getInstance();
118
    if ('' !== Request::getString('modname', '', 'POST')) {
119
        $helper->redirect('admin/faqAdapter.php', 3, _AM_XHELP_MESSAGE_NO_NAME);
120
    } else {
121
        $modname = Request::getString('modname', '', 'POST');
122
    }
123
124
    $currentAdapter = Utility::getMeta('faq_adapter');
125
    if ($currentAdapter == $modname) {    // Deactivate current adapter?
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modname does not seem to be defined for all execution paths leading up to this point.
Loading history...
126
        $ret = Utility::deleteMeta('faq_adapter');
127
    } else {
128
        $ret = FaqAdapterFactory::setFaqAdapter($modname);
129
    }
130
131
    if ($ret) {
132
        $helper->redirect('admin/faqAdapter.php');
133
    } else {
134
        $helper->redirect('admin/faqAdapter.php', 3, _AM_XHELP_MSG_INSTALL_MODULE);
135
    }
136
}
137