simpledecision /modules/materials/index.php

Language PHP Lines 226
MD5 Hash a4ab027b587e9ad1d78cc821b2dd59c7 Estimated Cost $3,970 (why?)
Repository https://bitbucket.org/ssimpledecision/simpledecision.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<? 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"; ?>
Back to Top