This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcategory-edit.php
More file actions
188 lines (171 loc) · 5.34 KB
/
Copy pathcategory-edit.php
File metadata and controls
188 lines (171 loc) · 5.34 KB
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
<?php
/**
* Show the form to add a new group.
*
* @package ProjectSend
* @subpackage Groups
*
*/
$load_scripts = array(
'chosen',
);
$allowed_levels = array(9,8);
require_once('sys.includes.php');
$active_nav = 'category';
$page_title = __('Edit Category','cftp_admin');
include('header.php');?>
<script type="text/javascript">
$("#process_category").submit(function() {
clean_form( this );
is_complete( this.category_name, '<?php echo $validation_no_name; ?>' );
// show the errors or continue if everything is ok
if (show_form_errors() == false) { return false; }
});
</script>
<div id="main">
<div id="content">
<?php
if (isset($_GET['id']))
$edit_id = $_GET['id'];
//var_dump($edit_id);
/** Get all the existing categories */
$get_categories = get_categories();
$categories = $get_categories['categories'];
$arranged = $get_categories['arranged'];
if(!empty( $_GET['action'] ) && $_GET['action'] == 'edit' ){
$action = 'edit';
$editing = !empty( $_POST['editing_id'] ) ? $_POST['editing_id'] : $_GET['id'];
$form_information = array(
'type' => 'edit_category',
'title' => __('Edit Category','cftp_admin'),
);
/**
* Get the current information if just entering edit mode
*/
$category_name = $categories[$editing]['name'];
$category_parent = $categories[$editing]['parent'];
$category_description = $categories[$editing]['description'];
}
/**
* Process the action
*/
if ( isset( $_POST['btn_process'] ) ) {
/**
* Applies for both ADDING a new category as well
* as editing one but with the form already sent.
*/
$category_name = trim($_POST['category_name']);
$category_parent = $_POST['category_parent'];
$category_description = trim($_POST['category_description']);
$category_object = new CategoriesActions();
$arguments = array(
'action' => 'edit',
'name' => $category_name,
'parent' => $category_parent,
'description' => $category_description,
);
$validate = $category_object->validate_category( $arguments );
$arguments['action'] = 'edit';
$redirect_status = 'edited';
$arguments['id'] = isset($_POST['editing_id'])?$_POST['editing_id'] :$_GET['id'];
if ( $validate === 1 ) {
$process = $category_object->save_category( $arguments );
if ( $process['query'] === 1 ) {
$redirect = true;
$status = $redirect_status;
}
else {
$msg = __('There was a problem savint to the database.','cftp_admin');
echo system_message('error', $msg);
}
}
else {
if ( $validate == 2 ) {
$validateedit = $category_object->validate_categoryedit( $arguments );
if ( $validateedit == 1 ) {
$process = $category_object->save_category( $arguments );
if ( $process['query'] === 1 ) {
$redirect = true;
$status = $redirect_status;
}
else {
$msg = __('There was a problem savint to the database.','cftp_admin');
echo system_message('error', $msg);
}
}else{
if($arguments['parent']==0){
$msg = __('Category already exist.','cftp_admin');
}else{
$msg = __('Subcategory already exist.','cftp_admin');
}
echo system_message('warning', $msg);
}
}else{
$msg = __('Please complete all the required fields.','cftp_admin');
echo system_message('error', $msg);
}
}
/** Redirect so the actions are reflected immediatly */
if ( isset( $redirect ) && $redirect === true ) {
while (ob_get_level()) ob_end_clean();
$location = BASE_URI . 'categories.php?status=' . $status;
header("Location: $location");
die();
}
}
?>
<!-- Added by B) -------------------->
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-xs-offset-0 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 white-box">
<div class="">
<?php
/**
* If the form was submited with errors, show them here.
*/
$valid_me->list_errors();
?>
<?php
if (isset($new_response)) {
/**
* Get the process state and show the corresponding ok or error messages.
*/
switch ($new_response['query']) {
case 1:
$msg = __('Organization added correctly.','cftp_admin');
echo system_message('ok',$msg);
/** Record the action log */
$new_log_action = new LogActions();
$log_action_args = array(
'action' => 23,
'owner_id' => $global_id,
'affected_account' => $new_response['new_id'],
'affected_account_name' => $add_group_data_name
);
$new_record_action = $new_log_action->log_action_save($log_action_args);
break;
case 0:
$msg = __('There was an error. Please try again.','cftp_admin');
echo system_message('error',$msg);
break;
}
}
else {
/**
* If not $new_response is set, it means we are just entering for the first time.
* Include the form.
*/
$organization_form_type = 'new_organization';
$form_information['type']='edit_category';
include('categories-form.php');
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include('footer.php');
?>