File: /home/httpd/html/nyloncams.com/public_html/admin/add_block.php
<?
require "db.php";
if (isset($_POST['formSubmit'])) {
$_POST = array_map_array('trim', $_POST);
if ($_POST['body'] == "") {
setMessage('Block content cannot be empty!', 'error');
}
if (!getMessages(false, 'error')) {
$data = array(
'title' => $_POST['title'],
'subject' => $_POST['subject'],
'body' => $_POST['body'],
'status' => (int) $_POST['status'],
);
$insert_id = dbInsert('blocks', $data);
if (is_numeric($insert_id)) {
if ($data['title'] == "") {
dbUpdate($table, array('title' => "Block $insert_id", 'record_num' => $insert_id));
}
if (is_array($_POST['lang'])) {
foreach ($_POST['lang'] as $k => $v) {
dbInsert('blocks_languages', array(
'block_id' => $insert_id,
'language' => $k,
'data' => serialize($_POST['lang'][$k]),
));
}
}
setMessage('Custom block saved. To display this block, paste following code: <b>' . htmlentities('<?php displayBlock(' . $insert_id . '); ?>', ENT_QUOTES, 'UTF-8') . '</b> in the desired location inside your template files or static page.');
setMessage('<a href="' . $basehttp . '/admin/blocks.php"><b>Click here to return to Custom Blocks</b></a>');
} else {
setMessage('Cannot create new custom block', 'error');
}
header("Location: ".$_SERVER['REQUEST_URI']);
exit;
} else {
entities_walk($_POST);
}
}
?>
<? require "header.php"; ?>
<script>
$().ready(function () {
$('.lang-selection a').on('click', function (e) {
e.preventDefault();
$('.lang-selection').find('a.active').removeClass('active');
$(this).addClass('active');
var activeItems = $(this).attr('href').replace("#", "");
$('#languages').find('.langInput').hide();
$('#languages').find('.' + activeItems).show();
return false;
});
});
</script>
<div class="content-page">
<div class="header-area">
<div class="breadcrumbs">
<a href="index.php">Admin Home</a>
<a href="blocks.php">Blocks</a>
<span><a href="add_block.php">Add Custom Block</a></span>
</div>
</div>
<div class="content-outer">
<h2>Add<strong>Custom</strong>Block</h2>
<div class="notification info">Custom blocks can be displayed in your template using PHP code: <b><? echo htmlentities('<?php displayBlock(BLOCK_ID); ?>', ENT_QUOTES, 'UTF-8'); ?></b>, where BLOCK_ID is the ID of the block in the system (visible in blocks list in first column).</div>
<div class="content-inner">
<? echo getMessages(); ?>
<form method="POST" action="" enctype="multipart/form-data" class="form" novalidate autocomplete="off">
<table class="pagetable" id="languages">
<thead>
<tr>
<th colspan="2">Add New Custom Block</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" class="lang-selection">
<ul class="tabs custom">
<li><a href="#baseLang" class="tab active">Default</a></li>
<? foreach ($languages as $l) { ?>
<li><a href="#<? echo $l['iso']; ?>" class="tab"><i class="flag-icon flag-icon-<? echo strtolower($l['iso']); ?>"></i><? echo $l['iso']; ?></a></li>
<? } ?>
</ul>
</td>
</tr>
<tr>
<td>Administrative Title</td>
<td><input type="text" name="title" value="<? echo $_POST['title']; ?>" /></td>
</tr>
<tr class="baseLang langInput">
<td>Block Title (header)</td>
<td><input type="text" name="subject" value="<? echo $_POST['subject']; ?>" /></td>
</tr>
<? foreach ($languages as $l) { ?>
<tr class="<? echo $l['iso']; ?> langInput" style="display: none;">
<td><i class="flag-icon flag-icon-<? echo strtolower($l['iso']); ?>"></i>Block Title (<? echo $l['name']; ?>/<? echo $l['iso']; ?>)</td>
<td><input type="text" name="lang[<? echo $l['iso']; ?>][subject]" value="<? echo $_POST['lang'][$l['iso']]['subject']; ?>" /></td>
</tr>
<? } ?>
<tr class="baseLang langInput">
<td>Block Content</td>
<td><textarea name="body" class="large editor-enabled" required><? echo $_POST['body']; ?></textarea></td>
</tr>
<? foreach ($languages as $l) { ?>
<tr class="<? echo $l['iso']; ?> langInput" style="display: none;">
<td><i class="flag-icon flag-icon-<? echo strtolower($l['iso']); ?>"></i>Block Content (<? echo $l['name']; ?>/<? echo $l['iso']; ?>)</td>
<td><textarea name="lang[<? echo $l['iso']; ?>][body]" class="large editor-enabled"><? echo $_POST['lang'][$l['iso']]['body']; ?></textarea></td>
</tr>
<? } ?>
<tr>
<td>Status</td>
<td>
<select name="status">
<option<? echo ($_POST['status'] == '1') ? ' selected' : ''; ?> value="1">Enabled</option>
<option<? echo ($_POST['status'] == '0') ? ' selected' : ''; ?> value="0">Disabled</option>
</select>
</td>
</tr>
<tr class="item submit">
<td colspan="2">
<input type="hidden" name="formSubmit" value="1" />
<button type="submit" class="btn action-save">Save</button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<? require "footer.php"; ?>