Subversion Repositories oidplus

Rev

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

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