-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispatch.php
54 lines (53 loc) · 1.41 KB
/
dispatch.php
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
<?php
if (!defined("AUTHCOMPLETE")) exit;
ob_start();
include_once('jalali.php');
include_once('db.php');
if (!isset($_GET['cid']))
{
include ("header.php");
// No category is selected!
// Show it!
$categories = getCategories();
foreach ($categories as $category)
{
echo "\t<li><a href=\"?cid=",$category->id,"\">",$category->name,'</a> (',$category->amount,")</li> \n";
}
include ("footer.php");
}
elseif (!isset($_POST['am']))
{
include ("header.php");
// Category selected but not amount
// Show amount form + category name
?>
<form method="POST" action="?cid=<?=$_GET['cid'];?>">
<h2><?php echo getCategoryById($_GET['cid'])->name;?></h2>
مبلغ: <input name="am" autofocus="autofocus" type="number" placeholder="به تومان"/> <br />
شرح: <input name="ds" type="text" placeholder="شرح خرید"> </br />
<button type="submit" >ثبت</button>
</form>
<hr />
<a href="?">بازگشت</a>
<?php
include ("footer.php");
} else {
$msg='';
$amount=$_POST['am']*1;
$cid=$_GET['cid']*1;
$desc=$_POST['ds'];
if (($cid!=0) && ($amount!=0))
{
// insert cost to db
addCost($cid,$amount,$desc);
if (!empty($desc))
$msgdesc="به شرح:<em> $desc </em>";
else
$msgdesc="";
$msg="$amount برای <em>".getCategoryById($_GET['cid'])->name . "</em> $msgdesc ثبت شد";
}
header ("Location: ./?cid=$cid&msg=$msg");
}
?>
</body>
</html>