Ejemplo n.º 1
0
 static function showAllThemes()
 {
     global $DB, $CFG_GLPI;
     $t = new PluginThemesTheme();
     $allThemes = $t->find();
     echo '<table class="tab_glpi" style="margin-bottom:20px;">
            <tr>
               <td>
                  <img src="../../../pics/warning.png">
               </td>
               <td class="icon_consol">
                  <span class="b">' . __('Setting a theme as default will make this theme visible by all users. If you want to use a theme for your own user, please use your preferences settings.', 'themes') . '</span>
               </td>
            </tr>
         </tbody></table>';
     echo "<table class='tab_cadrehov' style='margin-bottom:20px;'>";
     echo "<tr>\n               <th colspan='6'>" . __('All themes available', 'themes') . "</th>\n            </tr>";
     echo "<tr>\n               <th>" . __('Name', 'themes') . "</th>\n               <th>" . __('Version', 'themes') . "</th>\n               <th>" . __('Author', 'themes') . "</th>\n               <th>" . __('Need javascript', 'themes') . "</th>\n               <th>" . __('Screenshot', 'themes') . "</th>";
     if (PluginThemesTheme::canCreate()) {
         echo "<th>Action</th>";
     }
     echo "</tr>";
     foreach ($allThemes as $themeDetails) {
         echo "<tr class='tab_bg_1'>";
         /*** Name and Url ***/
         echo "<td class='center'>";
         if (empty($themeDetails['url'])) {
             echo $themeDetails['name'];
         } else {
             echo "<a title='" . __('Go to the theme website', 'themes') . "' href='" . $themeDetails['url'];
             echo "'>" . $themeDetails['name'] . "</a>";
         }
         echo "</td>";
         /*** version ***/
         echo "<td class='center'>" . $themeDetails['version'] . "</td>";
         /*** author and mail ***/
         echo "<td class='center'>";
         if (empty($themeDetails['mail'])) {
             echo $themeDetails['author'];
         } else {
             echo "<a title='" . __('Contact the author', 'themes') . "' href='mailto:" . $themeDetails['mail'];
             echo "'>" . $themeDetails['author'] . "</a>";
         }
         echo "</td>";
         /*** javascript ***/
         echo "<td class='center'>";
         if ($themeDetails['js']) {
             echo __('Yes', 'themes');
         } else {
             echo __('No', 'themes');
         }
         echo "</td>";
         /*** preview ***/
         echo "<td class='center'>";
         if ($themeDetails['name'] == "GLPI") {
             $screenshotPath = $CFG_GLPI['root_doc'] . '/plugins/themes/img/defaultscreenshot.jpg';
             $screenshotFile = GLPI_ROOT . '/plugins/themes/img/defaultscreenshot.jpg';
         } else {
             $screenshotFile = PLUGIN_THEMES_UPLOAD_DIR . '/' . $themeDetails['name'] . '/screenshot.jpg';
             $screenshotPath = $CFG_GLPI['root_doc'] . "/plugins/themes/front/getfile.php?theme_id=" . $themeDetails['id'] . "&type=img&file=screenshot.jpg";
         }
         if (is_file($screenshotFile)) {
             echo "<a target='_blank' href='" . $screenshotPath . "'>\n                  <img src='" . $screenshotPath . "' height='100' /></a>";
         } else {
             echo __('No screenshot available', 'themes');
         }
         echo "</td>";
         if (PluginThemesTheme::canCreate()) {
             /*** Make this theme the default one ***/
             echo "<td class='center'>";
             if ($themeDetails['active_theme'] == 0) {
                 echo "<a href='?activate=" . $themeDetails['id'] . "'>" . __('Set as default theme', 'themes') . "</a><br /><br />";
             }
             if ($themeDetails['name'] != "GLPI") {
                 echo "<a href='?delete=" . $themeDetails['id'] . "'>" . __('Delete this theme', 'themes') . "</a>";
             }
             echo "</td>";
         }
         echo "</tr>";
     }
     echo "</table>";
     echo "<form method='post' action='' enctype=\"multipart/form-data\">";
     echo "<table class='tab_cadrehov'><tr><th>";
     echo __('Add a new theme', 'themes');
     echo "</th></tr><tr><td class='center'>";
     echo "<input type='file' name='themeFile' />&nbsp;";
     echo "<input type='submit' class='submit' name='add_theme' value='" . __('Choose', 'themes') . "' />";
     echo "</td></tr></table>";
     Html::closeForm();
 }
Ejemplo n.º 2
0
            unlink("{$uploads_dir}/{$_FILES['themeFile']['name']}");
        }
    } else {
        Session::addMessageAfterRedirect(__('Theme already exist', 'themes'), false, ERROR);
    }
    header('location:' . $CFG_GLPI['root_doc'] . '/plugins/themes/front/themes.php');
    die;
}
if (isset($_GET['activate']) && PluginThemesTheme::canCreate()) {
    $t->getFromDB($_GET['activate']);
    PluginThemesTheme::resetActiveTheme();
    $values = array('id' => $_GET['activate'], 'active_theme' => '1');
    $t->update($values);
    header('location:' . $CFG_GLPI['root_doc'] . '/plugins/themes/front/themes.php');
}
if (isset($_GET['delete']) && PluginThemesTheme::canCreate()) {
    if (!$t->getFromDB($_GET['delete'])) {
        global $CFG_GLPI;
        Session::addMessageAfterRedirect(__('Error while deleting', 'themes'), false, ERROR);
        header('location:' . $CFG_GLPI['root_doc'] . '/plugins/themes/front/themes.php');
    }
    if ($t->fields['active_theme'] == "1") {
        $DB->query("UPDATE glpi_plugin_themes_themes SET active_theme = 1 WHERE name = 'GLPI'");
    }
    if (is_dir(PLUGIN_THEMES_UPLOAD_DIR . "/" . $t->fields['name'])) {
        Toolbox::deleteDir(PLUGIN_THEMES_UPLOAD_DIR . "/" . $t->fields['name']);
    }
    $DB->query("DELETE FROM glpi_plugin_themes_per_user WHERE theme_id = {$t->fields['id']};");
    $DB->query("DELETE FROM glpi_plugin_themes_themes WHERE id = {$_GET['delete']};");
    Session::addMessageAfterRedirect(__('Theme deleted', 'themes'), false, INFO);
    header('location:' . $CFG_GLPI['root_doc'] . '/plugins/themes/front/themes.php');