| Server IP : 180.180.241.3 / Your IP : 216.73.216.35 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /AppServ/www/app/Controller/ |
Upload File : |
<?php
App::uses('AppController', 'Controller');
/**
* Settings Controller
*/
class SettingsController extends AppController {
public function admin_index() {
$this->set( 'topicTitle', __( 'Settings' ) );
$mapColors = Configure::read( 'MAP_COLORS' );
$mapRange = Configure::read( 'MAP_RANGE' );
// debug($mapColors);
// debug($mapRange);
if ( $this->request->is('post') ) {
for( $i = 0; $i < 5; $i++ ) {
if( isset( $this->data['color-' . $i] ) ) {
$mapColors[$i] = str_replace( '#', '', $this->data['color-' . $i] );
}
}
if( isset( $this->data['range'] ) ) {
$mapRange = ( int )$this->data['range'];
if( $mapRange == 0 ) {
$mapRange = 5; // default value if parameter not correct
}
}
// save the file now
$mapSettingsFileContent = '<?php' . "\n";
$mapSettingsFileContent .= '$MAP_COLORS = array(' . "\n";
foreach( $mapColors as $mapColor ) {
$mapSettingsFileContent .= '\'' . $mapColor . '\',' . "\n";
}
$mapSettingsFileContent .= ');' . "\n";
$mapSettingsFileContent .= '$MAP_RANGE = ' . $mapRange . ';' . "\n";
$mapSettingsFileContent .= 'Configure::write( \'MAP_COLORS\', $MAP_COLORS );' . "\n";
$mapSettingsFileContent .= 'Configure::write( \'MAP_RANGE\', $MAP_RANGE );' . "\n";
$writeResult = @file_put_contents( APP . 'Config/map_settings.php', $mapSettingsFileContent );
if( $writeResult === false ) {
$this->Session->setFlash(__('ไม่สามารถแก้ไขการตั้งค่าได้.'), 'flash-fail');
} else {
$this->Session->setFlash(__('แก้ไขการตั้งค่าเรียบร้อยแล้ว.'), 'flash-success');
}
}
$mapLabel = array(
0 => __('น้อยที่สุด'),
1 => __('น้อย'),
2 => __('ปานกลาง'),
3 => __('มาก'),
4 => __('มากที่สุด')
);
$this->set( 'map_label', $mapLabel);
$this->set( 'map_colors', $mapColors );
$this->set( 'map_range', $mapRange );
}
}