Subversion Repositories oidplus

Rev

Rev 496 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. if (!defined('INSIDE_OIDPLUS')) die();
  21.  
  22. class OIDplusPageAdminColors extends OIDplusPagePluginAdmin {
  23.  
  24.         public function action($actionID, $params) {
  25.                 if ($actionID == 'color_update') {
  26.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  27.                                 throw new OIDplusException(_L('You need to log in as administrator.'));
  28.                         }
  29.  
  30.                         OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']);
  31.                         OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']);
  32.                         OIDplus::config()->setValue('color_val_shift', $params['val_shift']);
  33.                         OIDplus::config()->setValue('color_invert',    $params['invcolors']);
  34.                         OIDplus::config()->setValue('design',          $params['theme']);
  35.  
  36.                         OIDplus::logger()->log("[OK]A?", "Changed system color theme");
  37.  
  38.                         return array("status" => 0);
  39.                 } else {
  40.                         throw new OIDplusException(_L('Unknown action ID'));
  41.                 }
  42.         }
  43.  
  44.         public function init($html=true) {
  45.                 OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  46.                         if (!is_numeric($value) || ($value < -360) || ($value > 360)) {
  47.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  48.                         }
  49.                 });
  50.                 OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  51.                         if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
  52.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  53.                         }
  54.                 });
  55.                 OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  56.                         if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
  57.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  58.                         }
  59.                 });
  60.                 OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  61.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  62.                                 throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
  63.                         }
  64.                 });
  65.                 OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  66.                         $good = true;
  67.                         if (strpos($value,'/') !== false) $good = false;
  68.                         if (strpos($value,'\\') !== false) $good = false;
  69.                         if (strpos($value,'..') !== false) $good = false;
  70.                         if (!$good) {
  71.                                 throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path'));
  72.                         }
  73.  
  74.                         if (!is_dir(OIDplus::localpath().'plugins/design/'.$value)) {
  75.                                 throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/design/'));
  76.                         }
  77.                 });
  78.                 OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
  79.         }
  80.  
  81.         public function gui($id, &$out, &$handled) {
  82.                 if ($id === 'oidplus:colors') {
  83.                         $handled = true;
  84.                         $out['title'] = _L('Design');
  85.                         $out['icon']  = OIDplus::webpath(__DIR__).'icon_big.png';
  86.  
  87.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  88.                                 $out['icon'] = 'img/error_big.png';
  89.                                 $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
  90.                                 return;
  91.                         }
  92.  
  93.                         $out['text']  = '<br><p>';
  94.                         $out['text'] .= '  <label for="theme">'._L('Design').':</label>';
  95.                         $out['text'] .= '  <select name="theme" id="theme">';
  96.                         foreach (OIDplus::getDesignPlugins() as $plugin) {
  97.                                 $folder = basename($plugin->getPluginDirectory());
  98.                                 $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : '';
  99.                                 $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>';
  100.                         }
  101.                         $out['text'] .= '  </select>';
  102.                         $out['text'] .= '</p>';
  103.  
  104.                         $out['text'] .= '<br><p>';
  105.                         $out['text'] .= '  <label for="amount">'._L('Hue shift').':</label>';
  106.                         $out['text'] .= '  <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">';
  107.                         $out['text'] .= '</p>';
  108.                         $out['text'] .= '<div id="slider-hshift"></div>';
  109.  
  110.                         $out['text'] .= '<br><p>';
  111.                         $out['text'] .= '  <label for="amount">'._L('Saturation shift').':</label>';
  112.                         $out['text'] .= '  <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">';
  113.                         $out['text'] .= '</p>';
  114.                         $out['text'] .= '<div id="slider-sshift"></div>';
  115.  
  116.                         $out['text'] .= '<br><p>';
  117.                         $out['text'] .= '  <label for="amount">'._L('Value shift').':</label>';
  118.                         $out['text'] .= '  <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">';
  119.                         $out['text'] .= '</p>';
  120.                         $out['text'] .= '<div id="slider-vshift"></div>';
  121.  
  122.                         $out['text'] .= '<br><p>';
  123.                         $out['text'] .= '  <label for="amount">'._L('Invert colors').':</label>';
  124.                         $out['text'] .= '  <input type="text" id="icolor" readonly style="border:0; background:transparent; font-weight:bold;">'; // TODO: It would be good if that was a checkbox
  125.                         $out['text'] .= '</p>';
  126.                         $out['text'] .= '<div id="slider-icolor"></div>';
  127.  
  128.                         $out['text'] .= '<script>';
  129.                         $out['text'] .= 'if (g_hue_shift == null) g_hue_shift = g_hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n";
  130.                         $out['text'] .= 'if (g_sat_shift == null) g_sat_shift = g_sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n";
  131.                         $out['text'] .= 'if (g_val_shift == null) g_val_shift = g_val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n";
  132.                         $out['text'] .= 'if (g_invcolors == null) g_invcolors = g_invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n";
  133.                         $out['text'] .= 'if (g_activetheme == null) g_activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n";
  134.                         $out['text'] .= 'setup_color_sliders();';
  135.                         $out['text'] .= '</script>';
  136.  
  137.                         $out['text'] .= '<br>';
  138.                         $out['text'] .= '<input type="button" onclick="color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat('&nbsp;',5);
  139.                         $out['text'] .= '<input type="button" onclick="color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat('&nbsp;',5);
  140.                         $out['text'] .= '<input type="button" onclick="test_color_theme()" value="'._L('Test').'">'.str_repeat('&nbsp;',5);
  141.                         $out['text'] .= '<input type="button" onclick="crudActionColorUpdate()" value="'._L('Set permanently').'">';
  142.                 }
  143.         }
  144.  
  145.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  146.                 if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
  147.  
  148.                 if (file_exists(__DIR__.'/treeicon.png')) {
  149.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  150.                 } else {
  151.                         $tree_icon = null; // default icon (folder)
  152.                 }
  153.  
  154.                 $json[] = array(
  155.                         'id' => 'oidplus:colors',
  156.                         'icon' => $tree_icon,
  157.                         'text' => _L('Design')
  158.                 );
  159.  
  160.                 return true;
  161.         }
  162.  
  163.         public function tree_search($request) {
  164.                 return false;
  165.         }
  166.  
  167.         public function implementsFeature($id) {
  168.                 if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested
  169.                 return false;
  170.         }
  171.  
  172.         public function oobeRequested(): bool {
  173.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
  174.  
  175.                 return OIDplus::config()->getValue('oobe_colors_done') == '0';
  176.         }
  177.  
  178.         public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
  179.                 // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
  180.  
  181.                 echo '<p><u>'._L('Step %1: Color Theme',$step).'</u></p>';
  182.  
  183.                 echo '<input type="checkbox" name="color_invert" id="color_invert"';
  184.                 if (isset($_REQUEST['sent'])) {
  185.                         if ($set_value = isset($_REQUEST['color_invert'])) {
  186.                                 echo ' checked';
  187.                         }
  188.                 } else {
  189.                         if (OIDplus::config()->getValue('color_invert') == 1) {
  190.                                 echo ' checked';
  191.                         }
  192.                 }
  193.                 echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>';
  194.  
  195.                 $msg = '';
  196.                 if ($do_edits) {
  197.                         try {
  198.                                 OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0);
  199.                                 OIDplus::config()->setValue('oobe_colors_done', '1');
  200.                         } catch (Exception $e) {
  201.                                 $msg = $e->getMessage();
  202.                                 $errors_happened = true;
  203.                         }
  204.                 }
  205.  
  206.                 echo ' <font color="red"><b>'.$msg.'</b></font>';
  207.         }
  208.  
  209. }