forked from mangoO-Microfinance/mangoO-Microfinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcust_new_pic.php
87 lines (73 loc) · 2.69 KB
/
cust_new_pic.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
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
<!DOCTYPE HTML>
<?PHP
require 'functions.php';
require 'function_pic.php';
checkLogin();
$db_link = connect();
//Check where Re-direct comes from
if(isset($_GET['from'])){
$from = sanitize($db_link, $_GET['from']);
}
//SKIP-Button
if (isset($_POST['skip'])){
if ($from == "new") header('Location: acc_share_buy.php?cust='.$_SESSION['cust_id'].'&rec='.$_SESSION['receipt_no']);
else header('Location: customer.php?cust='.$_SESSION['cust_id']);
}
//UPLOAD-Button
if (isset($_POST['upload']) AND isset($_FILES['image'])){
//Settings
$max_file_size = 1024*2048; // 2048kb
$valid_exts = array('jpeg', 'jpg', 'png', 'tif', 'tiff');
$path = 'uploads/photos/customers/cust'.$_SESSION['cust_id'].'_';
//Thumbnail Sizes
$sizes = array(100 => 130, 146 => 190, 230 => 300);
//Check for maximum file size
if( $_FILES['image']['size'] < $max_file_size ){
// Get file extension
$ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
if (in_array($ext, $valid_exts)) {
//Resize image
foreach ($sizes as $width => $height) {
$files[] = resizeImage($width, $height, $path);
}
$sql_picpath = "UPDATE customer SET cust_pic = '$files[1]' WHERE cust_id = '$_SESSION[cust_id]'";
$query_picpath = mysqli_query($db_link, $sql_picpath);
checkSQL($db_link, $query_picpath);
if ($from == "new") header('Location: acc_share_buy.php?cust='.$_SESSION['cust_id'].'&rec='.$_SESSION['receipt_no']);
else header('Location:customer.php?cust='.$_SESSION['cust_id']);
}
else $error_msg = 'Unsupported file';
}
else $error_msg = 'Please choose an image smaller than 2048kB.';
}
$result_customer = getCustomer($db_link, $_SESSION['cust_id']);
?>
<html>
<?PHP includeHead('New Picture Upload',1) ?>
<body>
<!-- MENU -->
<?PHP includeMenu(2); ?>
<div id="menu_main">
<a href="cust_search.php">Search</a>
<a href="cust_new.php" id="item_selected">New Customer</a>
<a href="cust_act.php">Active Customers</a>
<a href="cust_inact.php">Inactive Customers</a>
</div>
<div class="content_center">
<p class="heading">Upload Photo for <?PHP echo $result_customer['cust_name'].' ('.$result_customer['cust_no'].')'; ?></p>
<?php if(isset($error_msg)): ?>
<p class="alert"><?php echo $error_msg; ?></p>
<?php endif ?>
<!-- File uploading form -->
<form action="" method="post" enctype="multipart/form-data">
<label for="image" class="file-upload">
<i class="fa fa-image"></i> Choose image
</label>
<input type="file" name="image" id="image" accept="image/*" />
<br/>
<input type="submit" name="upload" value="Upload" />
<input type="submit" name="skip" value="Skip" />
</form>
</div>
</body>
</html>