Всем привет.
Есть код:
include $_SERVER['DOCUMENT_ROOT']."/theme/assets/data/setting/setting.php";
function showRow($title = "", $description = "", $field = "", $class = "") {
echo "<tr>
<td class=\"col-xs-10 col-sm-6 col-md-7 {$class}\">{$title}<span >{$description}</span></td>
<td class=\"col-xs-2 col-md-5 settingstd {$class}\">{$field}</td>
</tr>";
}
function makeDropDown($options, $name, $selected) {
$output = "<select class=\"uniform\" style=\"min-width:100px;\" name=\"$name\">\r\n";
foreach ( $options as $value => $description ) {
$output .= "<option value=\"$value\"";
if( $selected == $value ) {
$output .= " selected ";
}
$output .= ">$description</option>\n";
}
$output .= "</select>";
return $output;
}
function makeCheckBox($name, $selected) {
$selected = $selected ? "checked" : "";
return "<input class=\"iButton-icons-tab\" type=\"checkbox\" name=\"$name\" value=\"\" {$selected}>";
}
function makeRadiokBox($name, $selected) {
$selected = $selected ? "checked" : "";
return "<input class=\"iButton-icons-tab\" type=\"radio\" name=\"$name\" value=\"1\" {$selected}>";
}
echo <<<HTML
<div class="portlet-body form">
<form action="setting.php?$=r1" method="post"class="form-horizontal" id="submit_form">
<div class="form-wizard">
<div class="form-body">
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<h3 class="block">Пароль и его востановление</h3>
<div class="form-group">
<label class="control-label col-md-3">Метрика от яндекса</label>
<div class="col-md-4">
HTML;
showRow( $lang['yan'], $lang['yand'], "<textarea name=\"save_con[yan]\" size=20>{$setting['yan']}</textarea>", "white-line" );
echo <<<HTML
<span class="help-block">Метрика от яндекса</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Язык</label>
<div class="col-md-4">
HTML;
showRow( $lang['vconf_flvpos'], $lang['vconf_flvposd'], makeDropDown( array ("left" => l, "center" => c, "right" => r ), "save_con[flv_watermark_pos]", "{$setting['flv_watermark_pos']}" ) );
showRow( $lang['vconf_play'], $lang['vconf_playd'], makeCheckBox( "save_con[play]", "{$setting['play']}" ) );
showRow( $lang['title'], $lang['title'], "<input type=text class=\"form-control\" name=\"save_con[title]\" value=\"{$setting['title']}\" size=20>", "white-line" );
showRow( $lang['sconf_mailru'], $lang['sconf_mailru'], makeCheckBox( "save_con[mailru]", "{$setting['mailru']}" ) );
// makeCheckBox( "save_con[play]", "{$setting['play']}"
echo <<<HTML
<span class="help-block">Описание для поисковых систем</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</table>
<div class="form-actions">
<input type="submit" class="btn default" name="save" value="Submit">
</form>
</div>
HTML;
if ($_POST['save']){
$save_con = $_POST['save_con'];
$find = array();
$replace = array();
$find[] = "'\r'";
$replace[] = "";
$find[] = "'\n'";
$replace[] = "";
$save_con = $save_con + $setting;
$handler = fopen($_SERVER['DOCUMENT_ROOT']."/theme/assets/data/setting/setting.php", "w" );
fwrite( $handler, "<?PHP \n\n//Videoplayers Configurations\n\n\$setting = array (\n\n" );
foreach ( $save_con as $name => $value ) {
$value = trim(strip_tags(stripslashes( $value )));
$value = htmlspecialchars( $value, ENT_QUOTES, $setting['charset']);
$value = preg_replace( $find, $replace, $value );
$name = trim(strip_tags(stripslashes( $name )));
$name = htmlspecialchars( $name, ENT_QUOTES, $setting['charset'] );
$name = preg_replace( $find, $replace, $name );
$value = str_replace( "$", "$", $value );
$value = str_replace( "{", "{", $value );
$value = str_replace( "}", "}", $value );
if( $name != "flv_watermark_al") $value = str_replace( ".", "", $value );
$value = str_replace( '/', "", $value );
$value = str_replace( chr(92), "", $value );
$value = str_replace( chr(0), "", $value );
$value = str_replace( '(', "", $value );
$value = str_replace( ')', "", $value );
$value = str_ireplace( "base64_decode", "base64_decode", $value );
$name = str_replace( "$", "$", $name );
$name = str_replace( "{", "{", $name );
$name = str_replace( "}", "}", $name );
$name = str_replace( ".", "", $name );
$name = str_replace( '/', "", $name );
$name = str_replace( chr(92), "", $name );
$name = str_replace( chr(0), "", $name );
$name = str_replace( '(', "", $name );
$name = str_replace( ')', "", $name );
$name = str_ireplace( "base64_decode", "base64_decode", $name );
fwrite( $handler, "'{$name}' => '{$value}',\n\n" );
}
fwrite( $handler, ");\n\n?>" );
fclose( $handler );
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
}
?>
Он записывает некие данные в файл php в виде массива. В таком виде
<?PHP
$setting = array (
'yan' => '',
'play' => '1',
'mailru' => '1',
);
?>
Так вот.
Проблема. Этот код. Он записывает chekbox. Положение один или ноль.
showRow( $lang['vconf_play'], $lang['vconf_playd'], makeCheckBox( "save_con[play]", "{$setting['play']}" ) );
Положение один(1) он записывает. Если снять галочку то положение ноль(0) не записывается.
Не могу понять в чем проблема. Вроде как положено!
Подскажите пожалуйста почему?
Или если есть другой способ записи то тоже будет полезно!