-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_publisher.php
143 lines (123 loc) · 7.92 KB
/
edit_publisher.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
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
<?php
require_once 'init.php';
$pageTitle = lang('edit_publisher');
$activePage = "publishers";
require_once $tmpl . 'header.php';
?>
<?php
//check if has privilege
if (!isset($_SESSION['UserEmail'])) {
redirect_user();
}
// validate get param
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (!filter_input(INPUT_GET, 'pub', FILTER_VALIDATE_INT)) {
redirect_user(lang("redirect_pub_message"), 5, "publishers.php");
}
$pub_id = filter_input(INPUT_GET, 'pub', FILTER_VALIDATE_INT);
// check if book has mor than one copy or not
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['pub_lang'])) {
$pub_id = strip_tags(filter_var($_POST['pub_id'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE));
$pub_name = strip_tags(filter_var($_POST['pub_name'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE));
$sequence_no = strip_tags(filter_var($_POST['sequence_no'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE));
$establish_date = strip_tags(filter_var($_POST['establish_date'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE));
$pub_owner = strip_tags(filter_var($_POST['pub_owner'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE));
$pub_lang = strip_tags(filter_var($_POST['pub_lang'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE));
if (!empty($pub_name) && !empty($sequence_no) && !empty($establish_date) && !empty($pub_owner) && !empty($pub_lang) && !empty($pub_id)) {
// //update data in DB
try {
$results = insert_data(EDIT_PUB, [$pub_name, $establish_date, $pub_owner, $sequence_no, $pub_id]);
$results1 = insert_data(EDIT_PUB_LANG, [$pub_lang, $pub_id]);
if ($results || $results1) {
redirect_user(lang('publish_edit_success'), 5, "publishers.php", "info");
} else {
// Handle the error condition here.
$result = "قم بتعديل اي قيمة للتعديل على دار النشر";
}
} catch (PDOException $e) {
if ($e->getCode() == '23000') {
// Check the specific error code for duplicate entry
$result = "اسم دار النشر تم اخذه مسبقا";
} else {
// Handle other database-related errors here.
// $result = "An error occurred: " . $e->getMessage();
$result = lang('publish_error');
}
}
} else {
$result = lang('loan_empty');
}
} else {
$result = lang('loan_empty');
}
}
$row = get_data(SELECT_PUBLISHER_UPDATE, [$pub_id]);
if (count($row) > 0) {
?>
<div class="mt-5 d-flex align-items-center justify-content-center">
<div class="add-publisher-form ">
<div class="container my-5 shadow d-flex align-items-center justify-content-center">
<div class="row bg-white">
<div class="col p-3">
<h4 class="text-uppercase text-center blue-text m-3 mb-2"><?php echo lang('edit_publisher'); ?></h4>
<hr class="mb-1" />
<!-- print error msg -->
<?php if (!empty($result)) {
echo '<div class="text-center alert alert-danger alert-dismissible fade show error-alert" role="alert" >
<span>' . $result . '</span>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close" ></button></div>';
} ?>
<main class="all-form m-4">
<form name="add-publisher" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<input class="form-control" type="hidden" id="pub_id" name="pub_id" value="<?php echo $row['pub_id'] ?>" />
<div class="form-group abs-con mt-3">
<label for="pub_name" class="blue-text"><?= lang('pub_name'); ?></label>
<input class="form-control" type="text" id="pub_name" name="pub_name" onkeyup="checkField('publisher', '#pub_name', '#check_pub_name','<?= $row['pub_name'] ?>')" placeholder="<?php echo lang('pub_name_place') ?>" value="<?php echo $row['pub_name'] ?>" />
<span class="invalid-feedback" id="check_pub_name"></span>
</div>
<div class="form-group abs-con mt-3">
<label for="sequence_no" class="blue-text"><?= lang('sequence_no'); ?></label>
<input class="form-control" id="sequence_no" type="text" onkeyup="checkField('publisher_seq', '#sequence_no', '#check_sequence','<?= $row['sequential_deposit_no'] ?>')" placeholder="<?php echo lang('sequence_no_place') ?>" name="sequence_no" value="<?php echo $row['sequential_deposit_no'] ?> " required />
<span class="invalid-feedback" id="check_sequence"></span>
</div>
<div class="form-group abs-con mt-3">
<label for="establish_date" class="blue-text"><?= lang('establish_date'); ?></label>
<input type="date" class="form-control" id="establish_date" name="establish_date" value="<?php echo $row['establishment_date'] ?>" onchange="checkDate('just_one','#establish_date')" required>
<span class="invalid-feedback"></span>
</div>
<div class="form-group abs-con mt-3">
<label for="pub_owner" class="blue-text"><?= lang('pub_owner'); ?></label>
<input class="form-control" type="text" placeholder="<?php echo lang('pub_owner_place') ?>" name="pub_owner" value="<?php echo $row['owner'] ?>" required />
</div>
<div class="form-group abs-con mt-3">
<label for="pub_lang" class="blue-text"><?= lang('pub_lang'); ?></label>
<select required class="form-control" name="pub_lang" required>
<option value="" disabled selected><?= lang('select_pub_lang'); ?></option>
<?php
$langs = get_all_data(SELECT_LANG);
foreach ($langs as $lang) {
echo '<option value="' . $lang['lang_id'] . '"';
if ($row['lang_id'] == $lang['lang_id']) {
echo 'selected';
}
echo '>' . $lang['lang_name'] . '</option>';
}
?>
</select>
</div>
<div class="modal-footer mt-4 mb-2 justify-content-evenly">
<button class="btn blue-btn add rounded-3 fw-bold" type="submit" id="submit"><?php echo lang('update') ?></button>
<button class="btn blue-btn cancel me-auto rounded-3 fw-bold" type="button" onclick="window.location.href='publishers.php'"><?php echo lang('cancel') ?></button>
</div>
</form>
</main>
</div>
</div>
</div>
</div>
</div>
<?php
}
include $tmpl . 'footer.php'; ?>