-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-add-edit.php
More file actions
290 lines (257 loc) · 16 KB
/
code-add-edit.php
File metadata and controls
290 lines (257 loc) · 16 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
session_start();
include_once("php_functions/functions.php");
include_once("configs/conn.inc");
$code_id = $_GET['cid'];
if ($code_id > 0) {
$code_id = $_GET['cid'];
$code_arr = fetchonerow('pr_code_snippets', "uid='" . $code_id . "'", "uid, title, row_code, file_extension, instructions, func_id, subfunc_id, language_id, framework_id, lang_impl_type_id, user_impl_type_id");
$act = "<span class='text-orange'><i class='fa fa-edit'></i>Edit</span>";
// echo "Service <small class='xsm'>Edit</small> <span class='text-green text-bold sm'>address</span> <a title='View details' class='font-16' href=\"services?service=$code_id\"><i class='fa fa-arrow-circle-up'></i></a>";
} else {
$code_arr = array();
$code_id = "";
$act = "<span class='text-green'><i class='fa fa-edit'></i>Add</span>";
// echo "Service <small class='xsm text-muted'>Add</small>";
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title> Zidi : add-edit-code</title>
<!-- Bootstrap Core and vendor -->
<?php
include_once 'styles.php';
?>
</head>
<body class="font-opensans">
<!-- Page Loader -->
<div class="page-loader-wrapper">
<div class="loader">
</div>
</div>
<!--Header section -->
<?php
include_once 'header.php';
?>
<!-- Start main html -->
<div class="container-fluid mb-5 pt-4">
<div class="row">
<div class="col-md-8 font-16 offset-md-2 pt-3 pb-2 mb-3 card">
<!-- <div class="d-flex justify-content-center">
<h3 class="masthead-heading text-uppercase mb-0">
<a href="index"><img src="assets/images/logo.png" height="35px" alt="ZIDI" /></a>
</h3>
</div> -->
<h3 class="text-center pb-2 pb-2"><?php echo $act; ?> Codesnippet</h3>
<div class="alert alert-icon alert-primary" role="alert">
<i class="fe fe-heart" aria-hidden="true"></i> Your contribution will help thousands 'maybe millions' of developers around the world save time and effort. You are a legend!
</div>
<div class="row">
<div class="col-sm-7">
<form id="addEditCode-form" class="form_ pl-5 pr-3" onsubmit="return false;" method="POST">
<div class="form-row">
<div class="form-group col-sm-12">
<label for="func_sel">*Function:</label>
<select class="form-control biginput" name="func_sel" id="func_sel" onchange="filterSubFuncByFunc()" required>
<option value="">--Select One</option>
<?php
$recs = fetchtable('pr_functionalities', "status > 0", "name", "asc", "100", "uid ,name");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$name = $r['name'];
if ($uid == $code_arr["func_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$name</option>";
}
?>
</select>
<div class="error" id="funErr"></div>
</div>
<div class="form-group col-sm-12">
<label for="subfunc_sel">*Subfunction:</label>
<select class="form-control biginput" name="subfunc_sel" id="subfunc_sel" required>
<option value="">--Select One</option>
<option value="0">No subfunction</option>
<?php
$recs = fetchtable('pr_subfunctions', "status > 0", "name", "asc", "300", "uid ,name");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$name = $r['name'];
if ($uid == $code_arr["subfunc_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$name</option>";
}
?>
</select>
<div class="error" id="subfunErr"></div>
</div>
<div class="form-group col-sm-12">
<label for="language_sel">*Language:</label>
<select class="form-control biginput" name="language_sel" id="language_sel" onchange="filterFramsByLang(); langAddEdit()" required>
<option value="">--Select One</option>
<?php
$recs = fetchtable('pr_languages', "status > 0", "name", "asc", "40", "uid ,name");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$name = $r['name'];
if ($uid == $code_arr["language_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$name</option>";
}
?>
</select>
<div class="error" id="langErr"></div>
</div>
<div class="form-group col-sm-12">
<label for="framework_sel">*Language Framework:</label>
<select class="form-control biginput" name="framework_sel" id="framework_sel" required>
<option value="">--Select One</option>
<option value="0"> No framework</option>
<?php
$recs = fetchtable('pr_frameworks', "status > 0", "name", "asc", "100", "uid ,name");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$name = $r['name'];
if ($uid == $code_arr["framework_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$name</option>";
}
?>
</select>
<div class="error" id="framErr"></div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="impl_sel">*Language Implementation Type:</label>
<select class="form-control biginput" name="sel_lang_impl" id="sel_lang_impl" required>
<option value="">--Select One</option>
<?php
$recs = fetchtable('pr_language_implementation_type', "status > 0", "title", "asc", "25", "uid ,title");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$title = $r['title'];
if ($uid == $code_arr["lang_impl_type_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$title</option>";
}
?>
</select>
<div class="error" id="langImplErr"></div>
</div>
<div class="form-group col-md-12">
<label for="impl_sel">*Your Implementation Type:</label>
<select class="form-control biginput" name="sel_user_impl" id="sel_user_impl" required>
<option value="">--Select One</option>
<?php
$recs = fetchtable('pr_user_implementation_type', "status > 0", "uid", "asc", "25", "uid ,title");
while ($r = mysqli_fetch_array($recs)) {
$uid = $r['uid'];
$title = $r['title'];
if ($uid == $code_arr["user_impl_type_id"]) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option $selected value=\"$uid\">$title</option>";
}
?>
</select>
<div class="error" id="userImplErr"></div>
</div>
</div>
<div class="form-group">
<label for="codeimpl_title">*Write User Friendly Code Title:</label>
<input type="text" class="form-control biginput" id="codeimpl_title" value="<?php echo $code_arr['title']; ?>" placeholder="e.g how to iterate over an object using for loop" maxlength="70" required />
<div class="error" id="titleErr"></div>
</div>
<div class="form-group">
<label for="code_input">*Codesnippet (Write/Paste your code below):</label>
<textarea class="form-control biginput" minlength="10" rows="5" id="code_input" name="code_input" required><?php echo $code_arr['row_code']; ?></textarea>
<div class="error" id="codeErr"></div>
</div>
<div class="form-group">
<label for="file_extension">*Code File Extension:</label>
<input type="text" class="form-control biginput" id="file_extension" value="<?php echo $code_arr['file_extension']; ?>" placeholder="e.g .js for Nodejs, .java for Java, .py for Python, .php for Php, .rb for Ruby and so on" minlength="2" maxlength="10" required>
<div class="error" id="fileExtErr"></div>
</div>
<div class="form-group">
<label for="instructions_input">Instructions/description of Code Use (if any):</label>
<textarea class="form-control biginput" rows="3" id="instructions_input" name="instructions_input"><?php echo $code_arr['instructions']; ?></textarea>
</div>
<div class="form-row pt-2 pb-2">
<div class="for-group col-md-4 d-flex justify-content-start" id="addEditCodeBtn">
<!-- <button type="submit" title="Click to register" onclick="alert('Oops! submit not yet implemented')" class="btn btn-primary">Submit</button> -->
</div>
</div>
</form>
</div>
<div class="col-sm-5 well font-13 container container-fluid ">
<div class="instructions">
<h5 class="font-weight-bold">Instructions</h5>
<span class="font-14"><u>We aim to assist developers get solutions quickly and effortless. Please adhere to the rules below </u></span>
<div>
<ol>
<li>Make sure your solution has been added in the right categories and tagged correctly</li>
<li>Make sure your solution is well formatted, structured and commented. Please don't assume that something is obvious since your code will be assisting users with different experience levels</li>
<li>Avoid opinionated or highly specific solutions and instead make them widely acceptable and usable </li>
<li>Please specify any libraries, frameworks and external resources used in your solution</li>
<li>Quote official documentation where necessary</li>
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include_once 'footer.php';
?>
</div>
<!-- jQuery and bootstrtap js -->
<?php
include_once('scripts.php');
?>
<script>
$(document).ready(function() {
updateHeader("secured"); //check for logged in user so as to update the header accordingly
$("#add-edit-code-page").hide(); //hide this page by default
//call submitBtn() and parse saveCodeSnippet() as a parameter and on hover hint title
submitBtn('#addEditCodeBtn', 'codesnippetValidate()', "Click to submit");
footer_date(); //load footer
})
</script>
<script>
//Initialize ckeditor on the instructions input
createEditor2('instructions_input');
//initCkeditor('code-add-edit');
// Initialize select2
// $(".select").select2({
// placeholder: 'Select...',
// width: 'resolve',
// }
// ).maximizeSelect2Height();
</script>
</body>
<!--Pass a code to edit id to be used in making codesnippet update -->
<input type="hidden" name="code_edit_id" id="code_edit_id" value="<?php echo $code_id; ?>">
<input type="hidden" name="instructions_input_" id="instructions_input_" value="">
</html>