Файл: InstantSocial/uploud/admin/components/present/backend.php
Строк: 289
<?php
/*********************************************************************************************/
// //
// InstantPresent v1.0 (c) 2010 //
// http://www.instantcms.ru/, info@instantcms.ru //
// //
// written by Somebody & Александр, 2010 //
// //
/*********************************************************************************************/
if(!defined('VALID_CMS_ADMIN')) { die('ACCESS DENIED'); }
function error($msg){
//
}
function getPresentList($opt,$infile){
$inDB = cmsDatabase::getInstance();
$inCore = cmsCore::getInstance();
$html = '';
$status = true;
$dir = '/components/present/image/presents/';
$sql = "SELECT link FROM cms_present";
$result = mysql_query($sql);
$arraylink=array();
while ($row = mysql_fetch_assoc($result)) {
$arraylink[]= $row["link"];
}
if ($handle = opendir(PATH.'/components/present/image/presents')) {
while (false !== ($file = readdir($handle))) {
$html .= '<div style="float:left;margin:4px">';
$html .= '<table border="0" cellspacing="0" cellpadding="4"><tr>';
if ($opt == 'edit' && $status == true) {
$html .= '<td align="center" valign="middle"><img src="'.$dir.$infile.'" alt="'.$infile.'"/><br/><input type="radio" name="link" value="'.$infile.'" checked="checked"/></td>';
$status = false;
}
if ($file != '.' && $file != '..' && (strstr($file, '.gif')||strstr($file, '.png')) && !in_array($file,$arraylink)){
$tag = str_replace('.gif', '', $file);
if ($status == true){
$html .= '<td align="center" valign="middle"><img src="'.$dir.$file.'" alt="'.$file.'"/><br/><input type="radio" name="link" value="'.$file.'" checked="checked"/></td>';
$status = false;
}
else {
$html .= '<td align="center" valign="middle"><img src="'.$dir.$file.'" alt="'.$file.'"/><br/><input type="radio" name="link" value="'.$file.'"/></td>';
}
}
$html .= '</tr></table></div>';
}
closedir($handle);
}
return $html;
}
cpAddPathway('Подарки', '?view=components&do=config&id='.$_REQUEST['id']);
echo '<h3>Компонент подарки</h3>';
if (isset($_REQUEST['opt'])) { $opt = $_REQUEST['opt']; } else { $opt = 'list'; }
$toolmenu = array();
if($opt=='list'){
$toolmenu[0]['icon'] = 'new.gif';
$toolmenu[0]['title'] = 'Новый подарок';
$toolmenu[0]['link'] = '?view=components&do=config&id='.$_REQUEST['id'].'&opt=add';
$toolmenu[3]['icon'] = 'listphoto.gif';
$toolmenu[3]['title'] = 'Все подарки';
$toolmenu[3]['link'] = '?view=components&do=config&id='.$_REQUEST['id'].'&opt=list';
$toolmenu[11]['icon'] = 'edit.gif';
$toolmenu[11]['title'] = 'Редактировать выбранные';
$toolmenu[11]['link'] = "javascript:checkSel('?view=components&do=config&id=".$_REQUEST['id']."&opt=edit&multiple=1');";
$toolmenu[12]['icon'] = 'show.gif';
$toolmenu[12]['title'] = 'Включить выбранные';
$toolmenu[12]['link'] = "javascript:checkSel('?view=components&do=config&id=".$_REQUEST['id']."&opt=show_present&multiple=1');";
$toolmenu[13]['icon'] = 'hide.gif';
$toolmenu[13]['title'] = 'Отключить выбранные';
$toolmenu[13]['link'] = "javascript:checkSel('?view=components&do=config&id=".$_REQUEST['id']."&opt=hide_present&multiple=1');";
}
if ($opt=='list' || $opt=='config'){
$toolmenu[15]['icon'] = 'cancel.gif';
$toolmenu[15]['title'] = 'Отмена';
$toolmenu[15]['link'] = '?view=components';
} else {
$toolmenu[20]['icon'] = 'save.gif';
$toolmenu[20]['title'] = 'Сохранить';
$toolmenu[20]['link'] = 'javascript:document.addform.submit();';
$toolmenu[21]['icon'] = 'cancel.gif';
$toolmenu[21]['title'] = 'Отмена';
$toolmenu[21]['link'] = 'javascript:history.go(-1);';
}
cpToolMenu($toolmenu);
if($opt=='saveconfig'){
$cfg = array();
$inCore->saveComponentConfig('present', $cfg);
$msg = 'Настройки сохранены.';
$opt = 'config';
}
if ($opt == 'show_present'){
if (!isset($_REQUEST['item'])){
if (isset($_REQUEST['item_id'])){ dbShow('cms_present', $_REQUEST['item_id']); }
echo '1'; exit;
} else {
dbShowList('cms_present', $_REQUEST['item']);
$inCore->redirectBack();
}
}
if ($opt == 'hide_present'){
if (!isset($_REQUEST['item'])){
if (isset($_REQUEST['item_id'])){ dbHide('cms_present', $_REQUEST['item_id']); }
echo '1'; exit;
} else {
dbHideList('cms_present', $_REQUEST['item']);
$inCore->redirectBack();
}
}
if ($opt == 'submit'){
if (!empty($_REQUEST['title'])) { $title = $_REQUEST['title']; } else { $title = 'Подарок'; }
$title = $_REQUEST['title'];
$link = $_REQUEST['link'];
$price = (int)$_REQUEST['price'];
$hits = 0;
$published = $_REQUEST['published'];
$sql = "INSERT INTO cms_present (title, link, price, hits, published)
VALUES ('$title', '$link', '$price', $hits, $published)" ;
dbQuery($sql) ;
header('location:?view=components&do=config&opt=list&id='.$_REQUEST['id']);
}
if ($opt == 'update'){
if(isset($_REQUEST['item_id'])) {
$id = $_REQUEST['item_id'];
if (!empty($_REQUEST['title'])) { $title = $_REQUEST['title']; } else { $title = 'Подарок'; }
$title = $_REQUEST['title'];
$link = $_REQUEST['link'];
$price = (int)$_REQUEST['price'];
$hits = (int)$_REQUEST['hits'];
$published = $_REQUEST['published'];
$sql = "UPDATE cms_present
SET title='$title',
link='$link',
price=$price,
hits=$hits,
published=$published
WHERE id = $id";
dbQuery($sql);
}
if (!isset($_SESSION['editlist']) || @sizeof($_SESSION['editlist'])==0){
header('location:?view=components&do=config&id='.$_REQUEST['id'].'&opt=list');
} else {
header('location:?view=components&do=config&id='.$_REQUEST['id'].'&opt=edit');
}
}
if($opt == 'delete'){
if(isset($_REQUEST['item_id'])) {
$id = $_REQUEST['item_id'];
$sql = "DELETE FROM cms_present WHERE id = $id";
dbQuery($sql);
$sql = "DELETE FROM cms_present_list WHERE present_id = $id";
dbQuery($sql);
header('location:?view=components&do=config&id='.$_REQUEST['id'].'&opt=list');
}
}
if ($opt == 'list'){
echo '<h3>Список подарков</h3>';
//TABLE COLUMNS
$fields = array();
$fields[0]['title'] = 'id'; $fields[0]['field'] = 'id'; $fields[0]['width'] = '30';
$fields[1]['title'] = 'Описание'; $fields[1]['field'] = 'title'; $fields[1]['width'] = '';
$fields[1]['filter'] = 15;
$fields[2]['title'] = 'Цена подарка'; $fields[2]['field'] = 'price'; $fields[2]['width'] = '';
$fields[2]['filter'] = 15;
$fields[3]['title'] = 'Выдано подарков'; $fields[3]['field'] = 'hits'; $fields[3]['width'] = '';
$fields[3]['filter'] = 15;
$fields[4]['title'] = 'Доступность'; $fields[4]['field'] = 'published'; $fields[4]['width'] = '100';
$fields[4]['do'] = 'opt'; $fields[4]['do_suffix'] = '_present';
//ACTIONS
$actions = array();
$actions[0]['title'] = 'Редактировать';
$actions[0]['icon'] = 'edit.gif';
$actions[0]['link'] = '?view=components&do=config&id='.$_REQUEST['id'].'&opt=edit&item_id=%id%';
$actions[1]['title'] = 'Удалить';
$actions[1]['icon'] = 'delete.gif';
$actions[1]['confirm'] = 'Удалить Подарок?nЕго лишатся все пользователи, у которых она есть.';
$actions[1]['link'] = '?view=components&do=config&id='.$_REQUEST['id'].'&opt=delete&item_id=%id%';
//Print table
cpListTable('cms_present', $fields, $actions);
}
if ($opt == 'add' || $opt == 'edit'){
if ($opt=='add'){
cpAddPathway('Добавить подарок', $_SERVER['REQUEST_URI']);
echo '<h3>Добавить подарок</h3>';
} else {
if(isset($_REQUEST['multiple'])){
if (isset($_REQUEST['item'])){
$_SESSION['editlist'] = $_REQUEST['item'];
} else {
echo '<p class="error">Нет выбранных объектов!</p>';
return;
}
}
$ostatok = '';
if (isset($_SESSION['editlist'])){
$id = array_shift($_SESSION['editlist']);
if (sizeof($_SESSION['editlist'])==0) { unset($_SESSION['editlist']); } else
{ $ostatok = '(На очереди: '.sizeof($_SESSION['editlist']).')'; }
} else { $id = $_REQUEST['item_id']; }
$sql = "SELECT * FROM cms_present WHERE id = $id LIMIT 1";
$result = dbQuery($sql) ;
if (mysql_num_rows($result)){
$mod = mysql_fetch_assoc($result);
}
echo '<h3>'.$mod['description'].' '.$ostatok.'</h3>';
cpAddPathway($mod['description'], '?view=components&do=config&id='.$_REQUEST['id'].'&opt=edit&item_id='.$id);
}
?>
<style type="text/css">
#p_input{
border:solid 1px silver;
text-align:center;
margin-left:4px;
margin-right:6px;
}
#p_input:hover{
border:solid 1px gray;
background-color:#EBEBEB;
text-align:center;
margin-left:4px;
margin-right:6px;
}
</style>
<form action="index.php?view=components&do=config&id=<?php echo $_REQUEST['id'];?>" method="post" enctype="multipart/form-data" name="addform" id="addform">
<table width="625" border="0" cellspacing="5" class="proptable">
<tr>
<td valign="top"><strong>Описание подарка: </strong><br /></td>
<td valign="top"><input name="title" type="text" id="title" size="45" value="<?php echo @$mod['title'];?>"/></td>
</tr>
<tr>
<td valign="top"><strong>Цена подарка: </strong><br /></td>
<td valign="top"><input name="price" type="text" id="price" size="45" value="<?php echo @$mod['price'];?>"/></td>
</tr>
<tr>
<td valign="top"><strong>Выдавать подарок?</strong><br />
<span class="hinttext">Отключите для приостановки отправки подарка </span> </td>
<td valign="top"><input name="published" type="radio" value="1" checked="checked" <?php if (@$mod['published']) { echo 'checked="checked"'; } ?> />
Да
<label>
<input name="published" type="radio" value="0" <?php if (@!$mod['published']) { echo 'checked="checked"'; } ?> />
Нет</label></td>
</tr>
<tr>
<td valign="top"><strong>Изображение подарка:<br />
</strong><span class="hinttext">Картинки из папки /components/present/images/presents</span><strong><br />
</strong></td>
<td valign="top"><?php echo getPresentList($opt,$mod['link']); ?></td>
</tr>
</table>
<p>
<input name="add_mod" type="submit" id="add_mod" <?php if ($opt=='add') { echo 'value="Добавить подарок"'; } else { echo 'value="Сохранить изменения"'; } ?> />
<input name="back3" type="button" id="back3" value="Отмена" onclick="window.location.href='javascript:history.go(-1);'"/>
<input name="opt" type="hidden" id="opt" <?php if ($opt=='add') { echo 'value="submit"'; } else { echo 'value="update"'; } ?> />
<?php
if ($opt=='edit'){
echo '<input name="item_id" type="hidden" value="'.$mod['id'].'" />';
}
?>
</p>
</form>
<?php
}?>