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

/modules/menu/edit.categorie.php

https://bitbucket.org/ssimpledecision/simpledecision
PHP | 151 lines | 136 code | 15 blank | 0 comment | 10 complexity | 6470e8d7255f444618ca4f63d134dbc9 MD5 | raw file
  1. <? include "../../inc/header_m.php";?>
  2. <?
  3. if (!empty($parent_home))
  4. $home_parent=" and parentid='$parent_home' ";
  5. if (isset($_GET['id_material'])||isset($_POST['id_material']))
  6. {
  7. if (count($_POST)>0)
  8. {
  9. $id=$_POST['id_material'];
  10. if (mysql_num_rows(mysql_query("select * from {$pref}db_{$modul} where id={$id} $home_parent and pid=0 limit 1"))==0) {die();}
  11. $name=$_POST['name'];
  12. $tmpl=$_POST['tmpl'];
  13. $position=$_POST['position'];
  14. $text=addslashes($_POST['text']);
  15. $status=$_POST['status'];
  16. $pid=$_POST['pid'];
  17. $parent=$pid;
  18. if ($parent<=0)
  19. $parent=$id;
  20. else $parent=getdb('db_catalog_cat',$pid,'parent');
  21. function editcatparent($id,$lev,$g_id,$db,$parent) //Дерево
  22. {
  23. global $pref;
  24. $sql01 = "select * from {$pref}db_{$db} where pid=$id ";
  25. $result01 = mysql_query($sql01);
  26. while ($rowo01 = mysql_fetch_array($result01)) {
  27. $id = $rowo01['id'];
  28. $pid=$rowo01['pid'];
  29. mysql_query("update {$pref}db_{$db} set parent='{$parent}' where id='{$id}'");
  30. editcatparent($id,$lev,$g_id,$db,$parent);
  31. }
  32. }
  33. editcatparent($id,1,0,'catalog_cat',$parent) ;
  34. $mes="<font color='green'><b class='saveinfo'>Сохранено</b></font>";
  35. mysql_query("update {$pref}db_{$modul} set name='{$name}',tmpl='{$tmpl}',position='{$position}',text='{$text}',status='{$status}',pid='0',parent='{$parent}' where id='{$id}' $home_parent");
  36. if (isset($_POST['sf1'])) header("Location: index.php");
  37. }
  38. else
  39. {
  40. unset($mes);
  41. $id=$_GET['id_material'];
  42. }
  43. $query=mysql_query("select * from {$pref}db_{$modul} where id={$id} $home_parent and pid=0 limit 1");
  44. $res=mysql_fetch_array($query);
  45. $m_title="Изменить категорию";
  46. }
  47. else
  48. {
  49. mysql_query("insert into {$pref}db_{$modul} set sort=0, parentid='$parent_home'");
  50. $id=mysql_insert_id();
  51. $m_title="Добавить категорию";
  52. }
  53. $body="";
  54. $body1="";
  55. $body.="
  56. <fieldset>
  57. <label>Название меню*</label>
  58. <input type='text' class='validate[required]' name='name' id='name' value='{$res['name']}' />
  59. </fieldset>
  60. <fieldset>
  61. <label>Текст</label>
  62. <textarea name='text' id='elm1'>{$res['text']}</textarea>
  63. </fieldset>";
  64. $body.="
  65. <fieldset class='left'>
  66. <label>Шаблон</label>
  67. <select name='tmpl' class='tmpl'>";
  68. $tpl=opendir($pt.'templates/tpl/');
  69. while(($tpla=readdir($tpl))!==false)
  70. {
  71. if (strlen($tpla)>5) $body.="
  72. <option value='$tpla' ";if ($tpla==$res['tmpl'])$body.="selected";$body.=">$tpla</option>";
  73. };
  74. $body.="
  75. </select><input type='hidden' value='".$id."'/></fieldset>
  76. <fieldset class='right'>
  77. <label>Позиция</label>
  78. <select name='position' class='position'>";
  79. $body.="
  80. </select></fieldset><div class='clear'></div>
  81. <fieldset class='left'>
  82. <label>Добавить в</label>
  83. <select class='' name='pid' id='pid'><option value='0'>--</option>
  84. ";
  85. $body1.="
  86. </select><br>
  87. </fieldset>
  88. <fieldset class='right'>
  89. <label>Статус*</label>
  90. <select class='validate[required]' name='status' id='status' >
  91. <option value='1' ";if ($res['status']==1) $body1.="selected";$body1.=">Опубликовано</option>
  92. <option value='2' ";if ($res['status']==2) $body1.="selected";$body1.=">Не опубликованно</option>
  93. </select></fieldset><div class='clear'></div>
  94. <input type='hidden' value='{$id}' name='id_material' />
  95. Поля, отмеченные * являются обязательными для заполнения
  96. ";
  97. ?>
  98. <script>
  99. function getPosition(val,id)
  100. {
  101. $.post('/<?=$cmspatch?>/templates/getPositionTmpl2.php',
  102. {"tmpl":""+val+"","id":""+id+""},
  103. function(result){
  104. $('.position').html(result.bod);
  105. },"json"
  106. );
  107. }
  108. $(document).ready(function(){
  109. getPosition($('.tmpl').val(),$('.tmpl').next().val());
  110. $('.tmpl').change(function(){
  111. getPosition($(this).val(),$(this).next().val())
  112. });
  113. });
  114. </script>
  115. <form action='' class='userInform' method='post' enctype='multipart/form-data'>
  116. <? if (count($_POST)>0){?><h4 class="alert_success"><?=$mes?></h4><?}?>
  117. <article class="module width_full">
  118. <header><h3 class="tabs_involved"><?=$m_title?></h3>
  119. <!-- <ul class="tabs">
  120. <li><a href="#tab1">Список</a></li>
  121. </ul> -->
  122. </header>
  123. <div class="module_content">
  124. <div id="tab1" class="tab_content">
  125. <?=$body?>
  126. <?=$body1?>
  127. </div></div>
  128. <footer>
  129. <div class="submit_link">
  130. <input type='submit' value='Сохранить' name='sf' />
  131. <input type='submit' value='Сохранить и закрыть' name='sf1' />
  132. </div>
  133. </footer>
  134. </article>
  135. </form>
  136. <? include "../../inc/footer_m.php"; ?>