Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.09 KB | None | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. require_once "../classes/My_Class.php";
  5. require_once TPL."head.php";
  6.  
  7.  
  8. if (!isset($_COOKIE['secretkey']) or $_COOKIE['secretkey'] != $secretkey) {
  9. header("Location: index.php");
  10. exit;
  11. }
  12.  
  13. $row = DB::$the->query("SELECT * FROM `sel_category` WHERE `id` = '".intval($_GET['category'])."'");
  14. $cat = $row->fetch(PDO::FETCH_ASSOC);
  15.  
  16. $row = DB::$the->query("SELECT * FROM `sel_subcategory` WHERE `id` = '".intval($_GET['subcategory'])."'");
  17. $subcat = $row->fetch(PDO::FETCH_ASSOC);
  18.  
  19. $My_Class->title("Подкатегория: ".$subcat['name']);
  20.  
  21.  
  22. if(isset($_GET['category'])){
  23. $header = DB::$the->query("SELECT id FROM `sel_category` WHERE `id` = '".intval($_GET['category'])."' ");
  24. $header = $header->fetchAll();
  25. if(count($header) == 0){
  26. header("Location: index.php"); exit;
  27. }}
  28.  
  29. if(isset($_GET['subcategory'])){
  30. $header = DB::$the->query("SELECT id FROM `sel_subcategory` WHERE `id` = '".intval($_GET['subcategory'])."' ");
  31. $header = $header->fetchAll();
  32. if(count($header) == 0){
  33. header("Location: index.php"); exit;
  34. }}
  35. ?>
  36.  
  37. <?
  38.  
  39. if(isset($_GET['cmd'])){$cmd = htmlspecialchars($_GET['cmd']);}else{$cmd = '0';}
  40.  
  41. if(isset($_GET['category'])){$category = abs(intval($_GET['category']));}else{$category = '0';}
  42. if(isset($_GET['subcategory'])){$subcategory = abs(intval($_GET['subcategory']));}else{$subcategory = '0';}
  43. if(isset($_GET['key'])){$key = abs(intval($_GET['key']));}else{$key = '0';}
  44.  
  45. switch ($cmd){
  46.  
  47. case 'create':
  48.  
  49. ?>
  50. <ol class="breadcrumb">
  51. <li><a href="index.php">Админ-панель</a></li> <li><a href="subcategory.php?category=<?=$category;?>"><?=$cat['name'];?></a></li>
  52. <li><a href="key.php?category=<?=$category;?>&subcategory=<?=$subcategory;?>"><?=$subcat['name'];?></a></li>
  53. <li class="active">Добавление Адресов</li>
  54. </ol>
  55. <?
  56.  
  57. if(isset($_POST['create_all'])) {
  58. if ($_POST['key'] != "") {
  59. $code = $_POST['key'];
  60. $arrAD = ['key' => 'code'];
  61. $arrAD[]='key';
  62. foreach(explode("\n",$code)as$key){
  63. $key = htmlspecialchars($key);
  64. $key = trim($key);
  65. if(($key = htmlspecialchars(trim( $key)))!= ''){
  66. $str_search = array("#\[img\](.*?\.(?:jpg|jpeg|gif|png|bmp))\[\/img\]#is",);
  67. $str_replace = array("".SITEDIR."/style/images/keys/\\1",);
  68. $key = preg_replace($str_search, $str_replace, $key);
  69. $params = array('code' => $key, 'id_cat' => $category, 'id_cats' => $_POST['subcats'], 'id_subcats' => $_POST['cats'], 'id_subcat' => $subcategory, 'time' => time(), 'sale' => 0);
  70. $q = DB::$the->prepare("INSERT INTO `sel_keys` (code, id_cat, id_cats, id_subcats, id_subcat, time, sale) VALUES (:code, :id_cat, :id_cats, :id_subcats, :id_subcat, :time, :sale)");
  71. $q->execute($params);}
  72. $ph = DB::$the->query("SELECT id FROM `sel_keys` order by `id` DESC "); $ph = $ph->fetch(PDO::FETCH_ASSOC);}
  73. header("Location: ?category=$category&subcategory=$subcategory");
  74. }
  75. }
  76.  
  77.  
  78.  
  79. echo '
  80. <script type="text/javascript">
  81. $(function(){
  82. var btnUpload=$(\'#upload\');
  83. var status=$(\'#status\');
  84. new AjaxUpload(btnUpload, {
  85. action: \'../admin/ajax.php?mod=uploadsimg\',
  86. name: \'uploadfile\',
  87. onSubmit: function(file, ext){
  88. if (! (ext && /^(bmp|jpg|png|jpeg|gif)$/.test(ext))){
  89. // extension is not allowed
  90. status.text(\'Поддерживаемые форматы bmp, jpg, jpeg, png, gif\');
  91. return false;
  92. }
  93. status.text(\'Загрузка...\');
  94. },
  95. onComplete: function(file, response){
  96. //On completion clear the status
  97. status.text(\'\');
  98. //Add uploaded file to list
  99. if(response==="success"){
  100. $(\'<li></li>\').appendTo(\'#files\').html(\'<img src="../style/images/keys/\'+file+\'" alt=""><br>\'+file).addClass(\'success\');
  101. } else{
  102. $(\'<li></li>\').appendTo(\'#files\').text(\'Файл не загружен!\' + file).addClass(\'error\');
  103. }
  104. }
  105. });
  106.  
  107. });
  108. </script>
  109. <section class="widget">
  110. <div class="alert alert-info">
  111. <button type="button" class="close" data-dismiss="alert">x</button><br>
  112. <strong>Внимание!</strong> Каждый адрес вводите с новой строки, Что бы добавить фотографию ниже загрузите и в нужном месте укажите<br/><b> [img]название нужной фотографи[/img]</b>
  113. </div>
  114.  
  115. <form action="?cmd=create&category='.$category.'&subcategory='.$subcategory.'" method="POST" enctype="multipart/form-data">
  116.  
  117. <div class="form-group ">
  118. <label for="all_address">Массовое добавление</label>
  119. <div class="input-group">
  120. <div class="form-group">
  121. <textarea name="key" class="form-control" cols="160" rows="5" placeholder="Каждый адрес с новой строки" required="required"></textarea>
  122. </div>
  123. </div><br/>
  124.  
  125. <div style="margin: 0;margin-bottom: 10px;">
  126.  
  127. Выберите район:<select class="form-control" name="cats">';
  128. $query = DB::$the->query("SELECT * FROM `sel_cat` WHERE `cat` = '{$category}' order by `id` ");
  129. while($cats = $query->fetch()) {
  130. echo '<option value="'.$cats["id"].'">'.$cats["name"].'</option>';
  131.  
  132. }
  133. echo'</select></div>
  134.  
  135. <div style="margin: 0;margin-bottom: 10px;">
  136. Выберите Фасовку:<select class="form-control" name="subcats">';
  137. $query = DB::$the->query("SELECT * FROM `sel_subcat` WHERE `id_subcat` = '{$subcategory}' order by `id` ");
  138. while($cat = $query->fetch()) {
  139. echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';
  140.  
  141. }
  142. echo'</select></div><br /><div id="upload"><span>Выбрать файл<span></div><span id="status"></span>
  143. <div style="margin: 0;margin-bottom: 10px;">
  144. <ul id="files"></ul>
  145. </div><br /> <button type="submit" name="create_all" class="btn btn-default btn-lg btn-block" data-loading-text="Добавляю">Добавить</button></form></div></section></div></div>';
  146.  
  147.  
  148. break;
  149.  
  150. case 'edit':
  151. ?>
  152. <ol class="breadcrumb">
  153. <li><a href="index.php">Админ-панель</a></li> <li><a href="subcategory.php?category=<?=$category;?>"><?=$cat['name'];?></a></li>
  154. <li><a href="key.php?category=<?=$category;?>&subcategory=<?=$subcategory;?>"><?=$subcat['name'];?></a></li>
  155. <li class="active">Редактирование Адреса</li>
  156. </ol>
  157. <?
  158. $key_edit = DB::$the->query("SELECT code FROM `sel_keys` WHERE `id` = {$key} and `id_subcat` = {$subcategory}");
  159. $key_edit = $key_edit->fetch(PDO::FETCH_ASSOC);
  160.  
  161. if(isset($_POST['edit'])) {
  162.  
  163. if($_POST['key'] != "") {
  164. $code=$_POST['key'];
  165.  
  166. DB::$the->prepare("UPDATE sel_keys SET code=? WHERE id=? ")->execute(array("$code", $key));
  167.  
  168. header("Location: ?category=$category&subcategory=$subcategory");
  169. }
  170. else
  171. {
  172. echo '<div class="alert alert-danger">Не введен Адрес!</div>';
  173. }
  174. }
  175.  
  176.  
  177. echo '<form action="?cmd=edit&category='.$category.'&subcategory='.$subcategory.'&key='.$key.'" method="POST">
  178. <div class="form-group col-sm-8">
  179. <div class="input-group input-group-lg">
  180. <span class="input-group-addon"><span class="glyphicon glyphicon-qrcode"></span> </span>
  181. <input type="text" placeholder="'.$key_edit['code'].'" class="form-control" name="key" value="'.$key_edit['code'].'">
  182. </div><br>
  183. <button type="submit" name="edit" class="btn btn-danger btn-lg btn-block" data-loading-text="Изменить">Изменяю</button></form></div>';
  184.  
  185.  
  186. break;
  187.  
  188. case 'delete':
  189. $key_del = DB::$the->query("SELECT code FROM `sel_keys` WHERE `id` = {$key} and `id_subcat` = {$subcategory}");
  190. $key_del = $key_del->fetch(PDO::FETCH_ASSOC);
  191. ?>
  192. <ol class="breadcrumb">
  193. <li><a href="index.php">Админ-панель</a></li> <li><a href="subcategory.php?category=<?=$category;?>"><?=$cat['name'];?></a></li>
  194. <li><a href="key.php?category=<?=$category;?>&subcategory=<?=$subcategory;?>"><?=$subcat['name'];?></a></li>
  195. <li class="active">Удаление Адреса: <b><?=$key_del['code'];?></b></li>
  196. </ol>
  197. <div class="alert alert-danger">Адрес будет удален навсегда!</div>
  198.  
  199. <div class="btn-group">
  200. <button type="button" class="btn btn-danger dropdown-toggle" data-loading-text="Думаем" data-toggle="dropdown">Вы уверены? <span class="caret"></span></button>
  201. <ul class="dropdown-menu" role="menu">
  202. <li><a href="?cmd=delete&category=<?=$category;?>&subcategory=<?=$subcategory;?>&key=<?=$key;?>&ok">Да, удалить</a></li>
  203. <li class="divider"></li>
  204. <li><a href="?category=<?=$category;?>&subcategory=<?=$subcategory;?>">Нет, отменить</a></li>
  205. </ul>
  206. </div><br /><br />
  207. <?
  208.  
  209.  
  210. if(isset($_GET['ok'])) {
  211. DB::$the->query("DELETE FROM `sel_keys` WHERE `id` = {$key} ");
  212.  
  213. header("Location: ?category=$category&subcategory=$subcategory");
  214. }
  215.  
  216. break;
  217.  
  218. case 'remove_sale':
  219.  
  220. ?>
  221. <ol class="breadcrumb">
  222. <li><a href="index.php">Админ-панель</a></li> <li><a href="subcategory.php?category=<?=$category;?>"><?=$cat['name'];?></a></li>
  223. <li><a href="key.php?category=<?=$category;?>&subcategory=<?=$subcategory;?>"><?=$subcat['name'];?></a></li>
  224. <li class="active">Удаление всех не проданных Адресов</li>
  225. </ol>
  226. <div class="alert alert-danger">Будут удалены все не проданные адреса!</div>
  227.  
  228. <div class="btn-group">
  229. <button type="button" class="btn btn-danger dropdown-toggle" data-loading-text="Думаем" data-toggle="dropdown">Вы уверены? <span class="caret"></span></button>
  230. <ul class="dropdown-menu" role="menu">
  231. <li><a href="?cmd=remove_sale&category=<?=$category;?>&subcategory=<?=$subcategory;?>&ok">Да, удалить все не проданные адреса</a></li>
  232. <li class="divider"></li>
  233. <li><a href="key.php?category=<?=$category;?>&subcategory=<?=$subcategory;?>">Нет, отменить</a></li>
  234. </ul>
  235. </div><br /><br />
  236.  
  237. <?
  238.  
  239. if(isset($_GET['ok'])) {
  240. DB::$the->query("DELETE FROM `sel_keys` WHERE `id_cat` = {$category} and `id_subcat` = {$subcategory} and `sale` = '0' ");
  241.  
  242. header("Location: key.php?category=category&subcategory=$subcategory");
  243. }
  244.  
  245. break;
  246.  
  247. default:
  248.  
  249. ?>
  250. <ol class="breadcrumb">
  251. <li><a href="index.php">Админ-панель</a></li> <li><a href="subcategory.php?category=<?=$category;?>"><?=$cat['name'];?></a></li>
  252. <li class="active"><?=$subcat['name'];?></li>
  253. </ol>
  254.  
  255.  
  256. <div class="list-group">
  257. <a class="list-group-item" href="?cmd=create&category=<?=$category;?>&subcategory=<?=$subcategory;?>">
  258. <span class="glyphicon glyphicon-plus-sign"></span> Добавить много адресов
  259. </a>
  260. </div>
  261. <?
  262. ?>
  263. <div class="list-group">
  264. <a class="list-group-item" href="key.php?cmd=remove_sale&category=<?=$category;?>&subcategory=<?=$subcategory;?>">
  265. <span class="glyphicon glyphicon-remove"></span> Удалить все не проданные Адреса
  266. </a>
  267. </div>
  268. <?
  269.  
  270. $total = DB::$the->query("SELECT * FROM `sel_keys` where `id_cat` = {$category} and `id_subcat` = {$subcategory} ");
  271. $total = $total->fetchAll();
  272. $max = 5;
  273. $pages = $My_Class->k_page(count($total),$max);
  274. $page = $My_Class->page($pages);
  275. $start=($max*$page)-$max;
  276.  
  277. if(count($total) == 0){
  278. echo '<div class="alert alert-danger">В данной подкатегории нет адресов!</div>';
  279. }
  280.  
  281. echo '<div class="list-group">';
  282. $query = DB::$the->query("SELECT * FROM `sel_keys` where `id_cat` = {$category} and `id_subcat` = {$subcategory} order by rand() LIMIT $start, $max");
  283. while($key = $query->fetch()) {
  284. if($key['sale'] == 1) {
  285. $sales = '<font color="red">[ПРОДАН]</font>';
  286. }
  287. else $sales = null;
  288.  
  289. $subcats = DB::$the->query("SELECT * FROM `sel_cat` WHERE `id` = '".$key['id_subcats']."' ");
  290. $subcats = $subcats->fetch(PDO::FETCH_ASSOC);
  291.  
  292. $cats = DB::$the->query("SELECT * FROM `sel_subcat` WHERE `id` = '".$key['id_cats']."' ");
  293. $cats = $cats->fetch(PDO::FETCH_ASSOC);
  294.  
  295. echo '<span class="list-group-item"> <b>[Район:'.$subcats['name'].' Фасовка: '.$cats['name'].'] '.$key['code'].' </b> '.$sales;
  296. echo '<a href="?cmd=edit&category='.$category.'&subcategory='.$subcategory.'&key='.$key['id'].'"> <span class="badge pull-right"><span class="glyphicon glyphicon-pencil"></span> </a>';
  297. echo '<a href="?cmd=delete&category='.$category.'&subcategory='.$subcategory.'&key='.$key['id'].'"> <span class="badge pull-right"><span class="glyphicon glyphicon-remove"></span> </a>';
  298. echo '</span>';
  299. }
  300. echo '</div>';
  301.  
  302. if ($pages>1) $My_Class->str('?category='.$category.'&subcategory='.$subcategory.'&',$pages,$page);
  303.  
  304. }
  305. ?>
  306. <style>
  307. #upload{
  308. margin: 10px 30px;
  309. padding: 10px;
  310. font-weight: bold;
  311. font-size: 14px;
  312. font-family: Arial, Helvetica, sans-serif;
  313. text-align: center;
  314. background: #f2f2f2;
  315. color: #3366cc;
  316. border: 2px solid #ccc;
  317. width: 150px;
  318. cursor: pointer !important;
  319. -moz-border-radius: 5px; -webkit-border-radius:5px;
  320. }
  321. .darkbg{
  322. background: #ddd !important;
  323. }
  324. #status{
  325. font-family: Arial;
  326. padding: 5px;
  327. }
  328. ul#files{ list-style: none; padding: 0; margin: 0; }
  329. ul#files li{ padding: 10px; margin-bottom: 2px; width: 150px; float: left; margin-right: 10px;}
  330. ul#files li img{ max-width: 160px; max-height: 150px; }
  331. .success{}
  332. .error{ background: #f0c6c3; border: 1px solid #cc6622; }
  333. </style>
  334.  
  335. <?
  336. $My_Class->foot();
  337. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement