/modules/materials/index.php
PHP | 226 lines | 208 code | 15 blank | 3 comment | 30 complexity | a4ab027b587e9ad1d78cc821b2dd59c7 MD5 | raw file
- <? include "../../inc/header_m.php";?>
- <?
- if (!empty($parent_home))
- $home_parent=" and parentid='$parent_home' ";
- $searchinmodul=$_POST['searchinmodul'];
- if (!empty($searchinmodul)){
- $searchinmodul=explode(' ', $searchinmodul);
- foreach ($searchinmodul as $key => $value) {
- $searchinmodules.="or UPPER(name) LIKE '%".strtoupper($value)."%' ";
- $searchinmodules.="or UPPER(text) LIKE '%".strtoupper($value)."%' ";
- }
- $searchinmodules=' ('.substr($searchinmodules, 2).') and ';
- }
- $del = $_POST['list'];
- $sor = $_POST['sor'];
- $del2 = $_POST['list2'];
- $sor2 = $_POST['sor2'];
- if (isset($del))
- foreach ($del as $delv)
- {
- if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul}_cat where id={$delv} $home_parent limit 1"))>0) {
- mysql_query("delete from {$pref}db_{$modul}_cat where id={$delv} $home_parent");
- mysql_query("delete from {$pref}db_{$modul}_rel where id_cat={$delv}");
- }}
- if (isset($sor))
- foreach ($sor as $sork=>$sorv)
- {
- if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul}_cat where id={$sork} $home_parent limit 1"))>0) {
- mysql_query("update {$pref}db_{$modul}_cat set sort={$sorv} where id={$sork} $home_parent");
- }}
- if (isset($del2))
- foreach ($del2 as $delv2)
- {
- if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul} where id={$delv2} $home_parent limit 1"))>0) {
- $sql1="select * from {$pref}db_pic where id_type={$id_modules} and id_el={$delv2} ";
- $query1=mysql_query($sql1);
- if ($query1 && mysql_num_rows($query1)>0)
- while ($res1=mysql_fetch_array($query1)) {
- $pic=$res1['pic'];
- unlink("{$_SERVER['DOCUMENT_ROOT']}/files/images/{$id_modules}/{$pic}");
- unlink("{$_SERVER['DOCUMENT_ROOT']}/files/images/{$id_modules}/mcith/mcith_{$pic}");
- }
- mysql_query("delete from {$pref}db_pic where id_type={$id_modules} and id_el={$delv2}");
- mysql_query("delete from {$pref}db_structure_alias where id_type={$id_modules} and id_el={$delv2}");
- mysql_query("delete from {$pref}db_{$modul} where id={$delv2} $home_parent");
- mysql_query("delete from {$pref}db_{$modul}_rel where id_el={$delv2}");
- }}
- if (isset($sor2))
- foreach ($sor2 as $sork2=>$sorv2)
- {
- if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul} where id={$sork2} $home_parent limit 1"))>0) {
- mysql_query("update {$pref}db_{$modul} set sort={$sorv2} where id={$sork2} $home_parent");
- }}
- if (isset($_GET['sort'])) $_SESSION['sort'] = $_GET['sort'];
- if (isset($_SESSION['sort'])) $sort = $_SESSION['sort'];
- if (strpos($mod_ver,substr($sort,0,2))===false)
- $sort = 'sort';
- mysql_query("delete from {$pref}db_{$modul}_cat where status=-1 and parentid='$parent_home'");
- mysql_query("delete from {$pref}db_{$modul} where status=-1 and parentid='$parent_home'");
- $lim=30;
- if (isset($_GET['p'])) $p=$_GET['p']; else {$p=1;$_GET['p']=1;}
- $o=$p*$lim-$lim;
- $body='';
- if (isset($_GET['id_material'])) $id=$_GET['id_material'];
- if (isset($_POST['id_material'])) $id=$_POST['id_material'];
- if (empty($id)) $id=0;
- $breadcrumb=$id;
- if (!empty($breadcrumb)){
- $hlebkr=array();
- while ($breadcrumb<>0) {
- $title_hleb=mysql_result(mysql_query("select * from {$pref}db_{$modul}_cat where id=$breadcrumb $home_parent"),0, 'name');
- $id_hleb=$breadcrumb;
- $breadcrumb=mysql_result(mysql_query("select * from {$pref}db_{$modul}_cat where id=$breadcrumb $home_parent"),0, 'pid');
- array_push($hlebkr, "<div class='breadcrumb_divider'></div> <a href='?id_material=$id_hleb' class='current'>$title_hleb</a>");
- }
- }
- $breadcrumb='';
- krsort($hlebkr);
- foreach ($hlebkr as $key => $value) {
- $breadcrumb.=$value;
- }
- if (empty($id)){
- $query=mysql_query("select * from {$pref}db_{$modul} where {$searchinmodules} id NOT IN (select id_el from {$pref}db_{$modul}_rel rel inner join {$pref}db_{$modul}_cat cat on rel.id_cat=cat.id where 1=1 $home_parent) $home_parent order by {$sort},id desc limit $o,$lim");
- $total=intval(mysql_result(mysql_query("select count(*) from {$pref}db_{$modul} where {$searchinmodules} id NOT IN (select id_el from {$pref}db_{$modul}_rel rel inner join {$pref}db_{$modul}_cat cat on rel.id_cat=cat.id where 1=1 $home_parent) $home_parent"),0,'count(*)'));
- } else {
- // $query=mysql_query("select * from {$pref}db_{$modul} where {$searchinmodules} id IN (select id_el from {$pref}db_{$modul}_rel where id_cat='{$id}') $home_parent order by {$sort},id desc limit $o,$lim");
- // $total=intval(mysql_result(mysql_query("select count(*) from {$pref}db_{$modul} where {$searchinmodules} id IN (select id_el from {$pref}db_{$modul}_rel where id_cat='{$id}') $home_parent"),0,'count(*)'));
- $query=mysql_query("select cat.* from {$pref}db_{$modul} cat inner join {$pref}db_{$modul}_rel catrel on cat.id=catrel.id_el where {$searchinmodules} catrel.id_cat='{$id}' $home_parent group by id order by {$sort},id desc limit $o,$lim");
- $total=intval(mysql_result(mysql_query("select count(*) from {$pref}db_{$modul} cat inner join {$pref}db_{$modul}_rel catrel on cat.id=catrel.id_el where {$searchinmodules} catrel.id_cat='{$id}' $home_parent group by id"),0,'count(*)'));
- }
- $m_title2="Элементы";
- $body2="
- <table class='tablesorter' cellspacing='0'>
- <thead>
- <tr>
- <th>ID</th>
- <th>Заголовок</th>
- <th>Сортировка</th>
- <th>Статус</th>
- <td>Удалить<input type='checkbox' class='selectdelete'></td>
- </tr>
- </thead>
- <tbody>
- ";
- while ($res=mysql_fetch_array($query))
- {
- $body2.="
- <tr>
- <td><a href='edit.materials.php?id_material={$res['id']}'>{$res['id']}</td>
- <td><a href='edit.materials.php?id_material={$res['id']}'>{$res['name']}</td>
- <td><span class='hid'>{$res['sort']}</span><input type='text' size='3' name='sor2[{$res['id']}]' value='{$res['sort']}' /></td>
- <td><span class='hid'>{$res['status']}</span><a class='statmat' id='_{$modul}-{$res['id']}-{$res['status']}' >
- <img src='{$pt}/{$cmspatch}/templates/img/{$res['status']}.gif' /></td>
- <td><input type='checkbox' onclick='check();' name='list2[]' class='listdelete' value='{$res['id']}' /></td>
- </tr>";
- }
- $body2.="
- </tbody>
- </table>
- ";
- ////////////
- $query=mysql_query("select * from {$pref}db_{$modul}_cat where {$searchinmodules} pid=$id $home_parent order by {$sort},id ");
- $m_title="Категории";
- $body.="
- <table class='tablesorter' cellspacing='0'>
- <thead>
- <tr>
- <th>ID</th>
- <th>Заголовок</th>
- <th>Сортировка</th>
- <th>Статус</th>
- <th>Редактировать</th>
- <td>Удалить<input type='checkbox' class='selectdelete'></td>
- </tr>
- </thead>
- <tbody>
- ";
- while ($res=mysql_fetch_array($query))
- {
- $body.="
- <tr>
- <td><a href='index.php?id_material={$res['id']}'>{$res['id']}</td>
- <td><a href='index.php?id_material={$res['id']}'>{$res['name']}</td>
- <td><span class='hid'>{$res['sort']}</span>
- <input type='text' size='3' name='sor[{$res['id']}]' value='{$res['sort']}' />
- </td>
- <td><span class='hid'>{$res['status']}</span><a class='statmat' id='_{$modul}_cat-{$res['id']}-{$res['status']}' >
- <img src='{$pt}/{$cmspatch}/templates/img/{$res['status']}.gif' /></td>
- <td><a href='edit.categorie.php?id_material={$res['id']}'><img src='{$pt}{$tpl_admin}/images/icn_edit.png' /></td>
- <td>
- <input type='checkbox' onclick='check();' name='list[]' class='listdelete' value='{$res['id']}' />
- </td>
- </tr>";
- }
- $body.="
- </tbody>
- </table>
- ";
- ?>
- <script>
- $(document).ready(function(){
- $('.modulForm').submit(function(){
- if (!confirm("Уверены, что хотите внести изменения?"))
- return false;
- })
- });
- </script>
- <form method='POST' acction='' class='modulForm' >
- <? if (isset($_POST['sf'])){?><h4 class="alert_success">Сохранено</h4><?}?>
- <article class="module width_full">
- <header><h3 class="tabs_involved"><?=$m_title?></h3>
- <!-- <ul class="tabs">
- <li><a href="#tab1">Список</a></li>
- </ul> -->
- </header>
- <div class="tab_container">
- <div id="tab1" class="tab_content">
- <?=$body?>
- </div></div>
- <footer>
- <div class="submit_link fl">
- </div>
- <div class="submit_link">
- <input type='submit' value='Сохранить' name='sf' />
- </div>
- </footer>
- </article>
- </form>
- <form method='POST' acction='' class='modulForm' >
- <? if (isset($_POST['sf2'])){?><h4 class="alert_success">Сохранено</h4><?}?>
- <article class="module width_full">
- <header><h3 class="tabs_involved"><?=$m_title2?></h3>
- <!-- <ul class="tabs">
- <li><a href="#tab1">Список</a></li>
- </ul> -->
- </header>
- <div class="tab_container">
- <div id="tab" class="tab_content2">
- <?=$body2?>
- </div></div>
- <footer>
- <div class="submit_link fl">
- <? paging_m($total,$lim,$p);?>
- </div>
- <div class="submit_link">
- <input type='submit' value='Сохранить' name='sf2' />
- </div>
- </footer>
- </article>
- </form>
- <? include "../../inc/footer_m.php"; ?>