PageRenderTime 72ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/materials/index.php

https://bitbucket.org/ssimpledecision/simpledecision
PHP | 226 lines | 208 code | 15 blank | 3 comment | 30 complexity | a4ab027b587e9ad1d78cc821b2dd59c7 MD5 | raw file
  1. <? include "../../inc/header_m.php";?>
  2. <?
  3. if (!empty($parent_home))
  4. $home_parent=" and parentid='$parent_home' ";
  5. $searchinmodul=$_POST['searchinmodul'];
  6. if (!empty($searchinmodul)){
  7. $searchinmodul=explode(' ', $searchinmodul);
  8. foreach ($searchinmodul as $key => $value) {
  9. $searchinmodules.="or UPPER(name) LIKE '%".strtoupper($value)."%' ";
  10. $searchinmodules.="or UPPER(text) LIKE '%".strtoupper($value)."%' ";
  11. }
  12. $searchinmodules=' ('.substr($searchinmodules, 2).') and ';
  13. }
  14. $del = $_POST['list'];
  15. $sor = $_POST['sor'];
  16. $del2 = $_POST['list2'];
  17. $sor2 = $_POST['sor2'];
  18. if (isset($del))
  19. foreach ($del as $delv)
  20. {
  21. if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul}_cat where id={$delv} $home_parent limit 1"))>0) {
  22. mysql_query("delete from {$pref}db_{$modul}_cat where id={$delv} $home_parent");
  23. mysql_query("delete from {$pref}db_{$modul}_rel where id_cat={$delv}");
  24. }}
  25. if (isset($sor))
  26. foreach ($sor as $sork=>$sorv)
  27. {
  28. if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul}_cat where id={$sork} $home_parent limit 1"))>0) {
  29. mysql_query("update {$pref}db_{$modul}_cat set sort={$sorv} where id={$sork} $home_parent");
  30. }}
  31. if (isset($del2))
  32. foreach ($del2 as $delv2)
  33. {
  34. if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul} where id={$delv2} $home_parent limit 1"))>0) {
  35. $sql1="select * from {$pref}db_pic where id_type={$id_modules} and id_el={$delv2} ";
  36. $query1=mysql_query($sql1);
  37. if ($query1 && mysql_num_rows($query1)>0)
  38. while ($res1=mysql_fetch_array($query1)) {
  39. $pic=$res1['pic'];
  40. unlink("{$_SERVER['DOCUMENT_ROOT']}/files/images/{$id_modules}/{$pic}");
  41. unlink("{$_SERVER['DOCUMENT_ROOT']}/files/images/{$id_modules}/mcith/mcith_{$pic}");
  42. }
  43. mysql_query("delete from {$pref}db_pic where id_type={$id_modules} and id_el={$delv2}");
  44. mysql_query("delete from {$pref}db_structure_alias where id_type={$id_modules} and id_el={$delv2}");
  45. mysql_query("delete from {$pref}db_{$modul} where id={$delv2} $home_parent");
  46. mysql_query("delete from {$pref}db_{$modul}_rel where id_el={$delv2}");
  47. }}
  48. if (isset($sor2))
  49. foreach ($sor2 as $sork2=>$sorv2)
  50. {
  51. if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul} where id={$sork2} $home_parent limit 1"))>0) {
  52. mysql_query("update {$pref}db_{$modul} set sort={$sorv2} where id={$sork2} $home_parent");
  53. }}
  54. if (isset($_GET['sort'])) $_SESSION['sort'] = $_GET['sort'];
  55. if (isset($_SESSION['sort'])) $sort = $_SESSION['sort'];
  56. if (strpos($mod_ver,substr($sort,0,2))===false)
  57. $sort = 'sort';
  58. mysql_query("delete from {$pref}db_{$modul}_cat where status=-1 and parentid='$parent_home'");
  59. mysql_query("delete from {$pref}db_{$modul} where status=-1 and parentid='$parent_home'");
  60. $lim=30;
  61. if (isset($_GET['p'])) $p=$_GET['p']; else {$p=1;$_GET['p']=1;}
  62. $o=$p*$lim-$lim;
  63. $body='';
  64. if (isset($_GET['id_material'])) $id=$_GET['id_material'];
  65. if (isset($_POST['id_material'])) $id=$_POST['id_material'];
  66. if (empty($id)) $id=0;
  67. $breadcrumb=$id;
  68. if (!empty($breadcrumb)){
  69. $hlebkr=array();
  70. while ($breadcrumb<>0) {
  71. $title_hleb=mysql_result(mysql_query("select * from {$pref}db_{$modul}_cat where id=$breadcrumb $home_parent"),0, 'name');
  72. $id_hleb=$breadcrumb;
  73. $breadcrumb=mysql_result(mysql_query("select * from {$pref}db_{$modul}_cat where id=$breadcrumb $home_parent"),0, 'pid');
  74. array_push($hlebkr, "<div class='breadcrumb_divider'></div> <a href='?id_material=$id_hleb' class='current'>$title_hleb</a>");
  75. }
  76. }
  77. $breadcrumb='';
  78. krsort($hlebkr);
  79. foreach ($hlebkr as $key => $value) {
  80. $breadcrumb.=$value;
  81. }
  82. if (empty($id)){
  83. $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");
  84. $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(*)'));
  85. } else {
  86. // $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");
  87. // $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(*)'));
  88. $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");
  89. $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(*)'));
  90. }
  91. $m_title2="Элементы";
  92. $body2="
  93. <table class='tablesorter' cellspacing='0'>
  94. <thead>
  95. <tr>
  96. <th>ID</th>
  97. <th>Заголовок</th>
  98. <th>Сортировка</th>
  99. <th>Статус</th>
  100. <td>Удалить<input type='checkbox' class='selectdelete'></td>
  101. </tr>
  102. </thead>
  103. <tbody>
  104. ";
  105. while ($res=mysql_fetch_array($query))
  106. {
  107. $body2.="
  108. <tr>
  109. <td><a href='edit.materials.php?id_material={$res['id']}'>{$res['id']}</td>
  110. <td><a href='edit.materials.php?id_material={$res['id']}'>{$res['name']}</td>
  111. <td><span class='hid'>{$res['sort']}</span><input type='text' size='3' name='sor2[{$res['id']}]' value='{$res['sort']}' /></td>
  112. <td><span class='hid'>{$res['status']}</span><a class='statmat' id='_{$modul}-{$res['id']}-{$res['status']}' >
  113. <img src='{$pt}/{$cmspatch}/templates/img/{$res['status']}.gif' /></td>
  114. <td><input type='checkbox' onclick='check();' name='list2[]' class='listdelete' value='{$res['id']}' /></td>
  115. </tr>";
  116. }
  117. $body2.="
  118. </tbody>
  119. </table>
  120. ";
  121. ////////////
  122. $query=mysql_query("select * from {$pref}db_{$modul}_cat where {$searchinmodules} pid=$id $home_parent order by {$sort},id ");
  123. $m_title="Категории";
  124. $body.="
  125. <table class='tablesorter' cellspacing='0'>
  126. <thead>
  127. <tr>
  128. <th>ID</th>
  129. <th>Заголовок</th>
  130. <th>Сортировка</th>
  131. <th>Статус</th>
  132. <th>Редактировать</th>
  133. <td>Удалить<input type='checkbox' class='selectdelete'></td>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. ";
  138. while ($res=mysql_fetch_array($query))
  139. {
  140. $body.="
  141. <tr>
  142. <td><a href='index.php?id_material={$res['id']}'>{$res['id']}</td>
  143. <td><a href='index.php?id_material={$res['id']}'>{$res['name']}</td>
  144. <td><span class='hid'>{$res['sort']}</span>
  145. <input type='text' size='3' name='sor[{$res['id']}]' value='{$res['sort']}' />
  146. </td>
  147. <td><span class='hid'>{$res['status']}</span><a class='statmat' id='_{$modul}_cat-{$res['id']}-{$res['status']}' >
  148. <img src='{$pt}/{$cmspatch}/templates/img/{$res['status']}.gif' /></td>
  149. <td><a href='edit.categorie.php?id_material={$res['id']}'><img src='{$pt}{$tpl_admin}/images/icn_edit.png' /></td>
  150. <td>
  151. <input type='checkbox' onclick='check();' name='list[]' class='listdelete' value='{$res['id']}' />
  152. </td>
  153. </tr>";
  154. }
  155. $body.="
  156. </tbody>
  157. </table>
  158. ";
  159. ?>
  160. <script>
  161. $(document).ready(function(){
  162. $('.modulForm').submit(function(){
  163. if (!confirm("Уверены, что хотите внести изменения?"))
  164. return false;
  165. })
  166. });
  167. </script>
  168. <form method='POST' acction='' class='modulForm' >
  169. <? if (isset($_POST['sf'])){?><h4 class="alert_success">Сохранено</h4><?}?>
  170. <article class="module width_full">
  171. <header><h3 class="tabs_involved"><?=$m_title?></h3>
  172. <!-- <ul class="tabs">
  173. <li><a href="#tab1">Список</a></li>
  174. </ul> -->
  175. </header>
  176. <div class="tab_container">
  177. <div id="tab1" class="tab_content">
  178. <?=$body?>
  179. </div></div>
  180. <footer>
  181. <div class="submit_link fl">
  182. </div>
  183. <div class="submit_link">
  184. <input type='submit' value='Сохранить' name='sf' />
  185. </div>
  186. </footer>
  187. </article>
  188. </form>
  189. <form method='POST' acction='' class='modulForm' >
  190. <? if (isset($_POST['sf2'])){?><h4 class="alert_success">Сохранено</h4><?}?>
  191. <article class="module width_full">
  192. <header><h3 class="tabs_involved"><?=$m_title2?></h3>
  193. <!-- <ul class="tabs">
  194. <li><a href="#tab1">Список</a></li>
  195. </ul> -->
  196. </header>
  197. <div class="tab_container">
  198. <div id="tab" class="tab_content2">
  199. <?=$body2?>
  200. </div></div>
  201. <footer>
  202. <div class="submit_link fl">
  203. <? paging_m($total,$lim,$p);?>
  204. </div>
  205. <div class="submit_link">
  206. <input type='submit' value='Сохранить' name='sf2' />
  207. </div>
  208. </footer>
  209. </article>
  210. </form>
  211. <? include "../../inc/footer_m.php"; ?>