Explorar o código

Getting there on config set

Andy Baugh %!s(int64=6) %!d(string=hai) anos
pai
achega
fb8f39f229
Modificáronse 2 ficheiros con 22 adicións e 2 borrados
  1. 1 1
      lib/tCMS/Config.inc
  2. 21 1
      templates/default/admin/settings.inc

+ 1 - 1
lib/tCMS/Config.inc

@@ -73,7 +73,7 @@
         }
 
         public function save( $type='main' ) {
-            return file_put_contents($this->get_conf_dir()."/$type.json", $this->get($type));
+            return file_put_contents($this->get_conf_dir()."/$type.json", json_encode($this->get($type)));
         }
     }
 ?>

+ 21 - 1
templates/default/admin/settings.inc

@@ -1,3 +1,22 @@
+<?php
+    if(!empty($args['conf_change_type'])) {
+        $conf  = $conf_obj->get($args['conf_change_type']);
+        $model = $conf_obj->get_config_model($args['conf_change_type']);
+        $saved = false;
+        foreach( $model as $key => $item ) {
+            if(!empty($args[$key])) {
+                $conf[$key] = $args[$key];
+            }
+            $conf_obj->set($args['conf_change_type'], $conf);
+            $saved = $conf_obj->save($args['conf_change_type']);
+        }
+        if($saved) {
+            echo "<p>Successfully saved $saved bytes to " . $conf_obj->get_conf_dir() . '/' . $args['conf_change_type'] . ".json</p>";
+        } else {
+            echo '<p style="color:red;">Failed to save to ' . $conf_obj->get_conf_dir() . '/' . $args['conf_change_type'] . '.json!</p>';
+        }
+    }
+?>
 <p class="title">
  General settings:
 </p>
@@ -20,7 +39,8 @@
                 }
                 $line .= '</select></td>';
             } elseif($item['form_field'] == 'input') {
-                $line .= '<td><input type="text" class="cooltext" name="' . $key . '" id="' . $key . '" placeholder="'.$item['default'].'" />';
+                $val = !empty($conf[$key]) ? $conf[$key] : '';
+                $line .= '<td><input type="text" class="cooltext" name="' . $key . '" id="' . $key . '" placeholder="'.$item['default'].'" value="'.$val.'" />';
             }
             $line .= '</tr>';
         }