Цитата (rusline @ 2.01.2017 - 15:10) |
а как примерно это будет выглядеть. то есть в phpMyAdmin я создаю отдельную таблицу с запросами, связываю эти запросы с id пользователя и при том как сессия жива этот запрос будет жить так понимаю? или по другому И как примерно это будет писаться в коде |
<div id="addBox">
<form id="form2" method="POST" action="transactions.php">
<a href="#openModal" id="addText">Добавить</a>
<label for="delete" id="delet">Удалить</label>
</form>
<div id="openModal" class="modalDialog">
<!--Модальное окно-->
<div>
<a href="#close" title="Закрыть" class="close">X</a>
<h2><center>Добавить операцию</center></h2>
<form method="POST" action="transactions.php">
<div>
<label id="delet">Счет: </label>
<select name="account" id="account">
<?php foreach ($score as $scores): ?>
<option value="<?=$scores['idScore']?>"><?=$scores['score']?></option>
<?php endforeach; ?>
</select>
<label>Тип операции: </label>
<select name="typ">
<option value="Доход">Доход</option>
<option value="Расход">Расходы</option>
<option value="Перевод">Перевод</option>
</select>
</div>
<div>
<div id="divCateg">
<select id="left" name="сategoria" class="idCateg" required>
<option>Выберите категорию</option>
<?php foreach ($categoria as $categ): ?>
<option value="<?=$categ['idCateg']?>"><?=$categ['category']?></option>
<?php endforeach; ?>
</select>
</div>
<div class="divSubcat">
<select id="right" name="subcategory" class="idSubCat" disabled required>
</select>
</div>
</div>
<div id="organizationBox">
<select name="organization">
<?php foreach ($organization as $organ): ?>
<option value="<?=$organ['idOrg']?>"><?=$organ['organization']?></option>
<?php endforeach; ?>
</select>
</div>
<div id="dataBox">
<label>Дата и время: </label>
<input type="date" name="data" id="data">
</div>
<div>
<label id="sum">Введите сумму: </label><input type="text" name="sum" size="8" required>
</div>
<br>
<div id="message">
<label>Комментарий: </label>
<textarea name="message" rows="-3" cols="40"></textarea>
</div>
<div id="add">
<input type="submit" class="add" name="add" value="Добавить">
<a href="#close" class="cancel">Отменить</a>
</div>
</form>
</div>
</div>
</form>
<?php deletTrans(); ?>
<!--Фильтр-->
<form id="filter" method="POST">
<?php
if (isset($_POST['filter'])) {
$dateStart = htmlspecialchars($_POST['fromDate']);
$dateEnd = htmlspecialchars($_POST['beforeDate']);
$typ = htmlspecialchars($_POST['filterTyp']);
$categ = htmlspecialchars($_POST['filterCateg']);
$account = htmlspecialchars($_POST['filterAccount']);
$organ = htmlspecialchars($_POST['filterOrganiz']);
$idTrans=htmlspecialchars($_POST['idTrans']);
}
$transactions = filter($dateStart, $dateEnd, $typ, $categ, $account, $idTrans, $organ);
?>
<div id="controls">
<div id="filter">
<div id="dataView">
<?php dateView(); ?>
</div>
<div>
<input type="submit" name="filter" id="filterButtom" value="Фильтровать">
<label for="fromDate">От </label><input type="date" name="fromDate" id="fromDate" value="<?=$dateStart ?>" >
<label for="beforeDate">До </label><input type="date" name="beforeDate" id="beforeDate" value="<?=$dateEnd ?>" >
</div>
<div id="filterExtended">
<div id="filterTyp">
<select name="filterTyp">
<option value="" selected>Тип операции</option>
<option value="Доход">Доход</option>
<option value="Расход">Расход</option>
<option value="Перевод">Перевод</option>
</select>
</div>
<div>
<select id="filterCateg" name="filterCateg" class="filterCateg">
<option value="" selected>Категорию</option>
<?php foreach ($categoria as $categ): ?>
<option value="<?=$categ['idCateg']?>"><?=$categ['category']?></option>
<?php endforeach; ?>
</select>
</div>
<select name="filterAccount" id="filterAccount">
<option value="" selected>
Счет</option>
<?php foreach ($score as $scores): ?>
<option value="<?=$scores['idScore']?>"><?=$scores['score']?></option>
<?php endforeach; ?>
</select>
<select name="organization">
<option value="" selected>Организация</option>
<?php foreach ($organization as $organ): ?>
<option value="<?=$organ['idOrg']?>"><?=$organ['organization']?></option>
<?php endforeach; ?>
</select>
</div>
</form>
<form id="form1" method="POST" action="transactions.php">
<!--Удаление-->
<button id="delete" class="hidden" name="delete">Удалить</button>
<script>delet()</script>
<table cellpadding="2" cellspacing="0" border="0" id="table_id" class="display">
<thead>
<tr>
<th><input type="checkbox" name="cb_all" value="all" id="all"></th>
<th>Дата</th>
<th>Тип</th>
<th>Счет</th>
<th>Категория</th>
<th>Подкатегория</th>
<th>Организация</th>
<th>Сумма</th>
<th>Комментарий</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($transactions as $transact): ?>
<tr>
<td><input type="checkbox" name="check[]" class ="qwe" value="<?=$transact['idTrans']?>"></td>
<td><?=date('d.m', strtotime($transact['data']))?></td>
<td><?=$transact['typ']?></td>
<td><?=$transact['score']?></td>
<td><?=$transact['category']?></td>
<td><?=$transact['subcategory']?></td>
<td><?=$transact['organization']?></td>
<td><?=$transact['Sum']?></td>
<td><?=$transact['comment']?></td>
<td>Изменить</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
<script>
allCheckbox()
sorter()
</script>
</div>
</div>
//Фильтры
function filter($dateStart, $dateEnd, $typ, $categ, $account, $idTrans, $organ)
{
session_start();
$idUser=$_SESSION['id'];
require "../verification/connect.php";
$where = [];
$where[] = isset($_POST['fromDate']) ? "t.data >='$dateStart'" : "t.data >= '".date('Y-m-01')."'";
if(!empty($_POST['beforeDate'])) $where[] = "t.data <'$dateEnd'";
if(!empty($_POST['filterTyp'])) $where[]="t.typ ='$typ'";
if(!empty($_POST['filterCateg'])) $where[]="t.idCateg ='$categ'";
if(!empty($_POST['filterAccount'])) $where[]="t.idScore ='$account'";
if(!empty($_POST['filterOrganiz'])) $where[]="t.idOrg ='$organ'";
$sqlTrans="SELECT t.idTrans, t.typ, t.data, t.Sum,t.comment, t.delet, score.score, Categoria.category, subcategory.subcategory, organization.organization
FROM transactions AS t
LEFT JOIN score ON score.idScore = t.idScore
LEFT JOIN Categoria ON Categoria.idCateg = t.idCateg
LEFT JOIN subcategory ON subcategory.idSubCat = t.idSubCat
LEFT JOIN organization ON organization.idOrg = t.idOrg
WHERE
t.idUser='$idUser' AND t.delet = '0' AND
( ".implode(' AND ', $where)." )
ORDER BY t.data ASC";
$queryTrans=mysql_query($sqlTrans) or die(mysql_error());
$transactions=array();
while($rowTrans = mysql_fetch_array($queryTrans))
{
$transactions[]=$rowTrans;
}
mysql_close();
return $transactions;
}
//Удаление
function deletTrans()
{
require "../verification/connect.php";
$check = $_POST['check'];
$del = htmlspecialchars($_POST['delete']);
$DeletDate = time();
if (isset($del) && isset($check))
{
$items = [];
foreach ($check as $id) {
$items[] = intval($id);
}
$sqlDelet = "UPDATE transactions SET delet='1', dataDelet = '$DeletDate' WHERE idTrans IN (".implode(', ', $items).")";
$queryDelet = mysql_query($sqlDelet) or die(mysql_close());
}
}
function filter(){
$(document).ready(function(){
$("#filterButtom").bind("click", function(){
var filter = $("#filterButtom").val();
$.ajax({
url: "transactions.php",
type: "POST",
data: ({filter: filter})
success: function(data){
$("#table_id").html(data);
}
})
})
})
}