forked from corgus/eas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_call.php
224 lines (180 loc) · 7 KB
/
open_call.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
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
<?php
/*
Template Name: Open Call
*/
?>
<?php
global $user_id, $alert_message, $contestname, $post_status, $do_it, $errors;
$current_user = wp_get_current_user();
$user_ID = $current_user->ID;
$user_meta = get_user_meta($user_ID);
$alert_message = "";
$contestname = 'opencall';
$post_status = 'draft';
$do_it = false;
function con( $data ) {
if ( is_array( $data ) )
$output = "<script>console.log( 'DEBUG: " . implode( ',', $data) . "' );</script>";
else $output = "<script>console.log( 'DEBUG: " . $data . "' );</script>";
echo $output;
}
function oc_get_artwork_form($file = true, $action = "/upload", $the_post = false, $the_meta = false, $disabled = false) {
global $user_ID, $meta;
get_currentuserinfo();
$meta = get_user_meta($user_ID);
$title = $year = $medium = $credits = $moreinfo = '';
$elid = "opencall";
$contestname = "opencall";
$first_name = $meta['first_name'][0];
$last_name = $meta['last_name'][0];
$school = $_POST['school'] ?: $meta['school'][0];
$location = $_POST['location'] ?: $meta['location'][0];
$birthday = $_POST['birthday'] ?: $meta['birthday'][0];
$title = $_POST['title'];
$year = $_POST['raey'];
$medium = $_POST['medium'];
$size = $_POST['size'];
$moreinfo = $_POST['more_info'];
/* if ($the_post !== false) {
$meta = get_post_meta($the_post->ID);
$title = $the_post['post_title'];
$year = $meta['year'];
$medium = $meta['medium'];
$credits = $meta['credits'];
$moreinfo = get_the_content($the_post->ID);
} */
$the_return = '<form ';
if ($file) $the_return.= ' enctype="multipart/form-data"';
$the_return .='action="'.$action.'" method="post" id="'.$elid.'">';
if ($file) $the_return .=' <div class= "oc_art_in"><input type="file" name="artwork" class="oc_art_input"></div>';
$the_return .= '<input type="hidden" name="contest" value="'.$contestname.'">
<div class="oc_inputs">';
$nudge = array();
foreach (array('school', 'location', 'birthday') as $m) {
if (!(isset($meta[$m]) && count($meta[$m]) && !empty($meta[$m][0]))) {
array_push($nudge, $m);
}
}
foreach ($nudge as $n) {
$required = $n != 'School' ? ' <span class="required">*</span>' : '';
$the_return.='<p><input type="text" name="'.strtolower($n).'" placeholder="Your '.$n.'" value="">'.$required.' </p>';
}
$the_return .= '
<p><input type="text" name="Name" placeholder="Title" value="'.$first_name.' '.$last_name.'">  *</p>
<p><input type="text" name="school" placeholder="Title" value="'.$school.'">  *</p>
<p><input type="text" name="location" placeholder="Title" value="'.$location.'">  *</p>
<p><input type="text" name="birthday" placeholder="Title" value="'.$birthday.'">  *</p>
<br/>
<p><input type="text" name="title" placeholder="Title" value="'.$title.'">  *</p>
<p><input type="text" name="raey" placeholder="Year" value="'.$year.'">  *</p>
<p><input type="text" name="medium" placeholder="Medium" value="'.$medium.'">  *</p>
<p><input type="text" name="size" placeholder="Size" value="'.$size.'">  *</p>
</div>
<div class="oc_des">
<p>Brief Description</p>'.eas_get_editor($moreinfo, 'moreinfo', 'more_info', true, '150px').'</p>
</div>';
$the_return .='<input type="hidden" id="attachmentid" name="artwork_img_id" value="">';
$the_return .='<input id="artworksubmit" type="submit" class="btn btn-primary" value="Submit">';
$the_return.='</form>';
echo $the_return;
}
get_currentuserinfo();
if(!$user_ID) {
wp_redirect('login?redirect=/opencall');
}
if (isset($_FILES['artwork'])) {
require_once(ABSPATH.'/wp-admin/includes/image.php');
require_once(ABSPATH.'/wp-admin/includes/file.php');
require_once(ABSPATH.'/wp-admin/includes/media.php');
$do_it = true;
/* if (empty($birthday) && empty($school)) {
$do_it = false;
$_GET['action'] = 'noage';
} */
/*///////// FORM ERROR CHECKING ////////////*/
$errors = array();
if($_FILES['artwork']['type'] != 'image/jpeg') {
$errors[] = 'The artwork must be in jpeg format.';
}
if(!isset($_POST['title']) || empty($_POST['title'])) {
$errors[] = "Title cannot be blank.";
}
if(!isset($_POST['raey']) || empty($_POST['raey'])) {
$errors[] = "Year cannot be blank.";
}
if(!isset($_POST['medium']) || empty($_POST['medium'])) {
$errors[] = "Medium cannot be blank.";
}
if(!isset($_POST['size']) || empty($_POST['size'])) {
$errors[] = "Size cannot be blank.";
}
if(!isset($_POST['more_info']) || empty($_POST['more_info'])) {
$errors[] = "Description cannot be blank.";
}
if (sizeof($errors) > 1) {
$do_it = false;
}
/*//////////// POSTING ARTWORK ////////////////*/
if ($do_it) {
$new_post = array(
'post_title' => $_POST['title'],
'post_content' => $_POST['more_info'],
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user->ID,
'post_type' => 'artwork',
'post_category' => array(0),
'post_status' => $post_status
);
$artwork_id = wp_insert_post($new_post, true);
if ($artwork_id < 1) {
echo '<script>console.log("DEBUG: $do_it = TRUE but $artwork_id < 1")</script>';
} else {
$overrides = array( 'test_form' => false);
$file = media_handle_upload('artwork', $artwork_id, $overrides);
if (!empty($file)) {
update_post_meta($artwork_id, 'year', $_POST['raey']);
update_post_meta($artwork_id, 'medium', $_POST['medium']);
update_post_meta($artwork_id, 'size', $_POST['size']);
update_post_meta($artwork_id, 'contest', 'opencall');
$redirect_url = '/'.$contestname.'/thanks';
// mail
// eas_mail('[email protected]', 'Artwork has been submitted', eas_artwork_url($artwork_id));
eas_mail('[email protected]', 'Artwork has been submitted', eas_artwork_url($artwork_id));
wp_redirect($redirect_url);
exit;
}
}
}
}
?>
<?php get_header(); ?>
<?php roots_content_before(); ?>
<div id="content" class="<?php echo CONTAINER_CLASSES; ?>">
<?php roots_main_before(); ?>
<div id="main" class="<?php echo MAIN_CLASSES; ?>" role="main">
<?php roots_loop_before(); ?>
<?php get_template_part('loop','page'); ?>
<?php roots_loop_after(); ?>
<?php if(count($errors)): ?>
<ul class="errorList">
<?php foreach($errors as $error): ?>
<li><?= $error ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (is_user_logged_in()) {
oc_get_artwork_form(true, '/opencall', 'upload_art', false, false, false);
} else {
eas_not_logged_in();
} ?>
<?php con("test"); ?>
</div><!-- /#main -->
<?php roots_main_after(); ?>
</div><!-- /#content -->
<?php roots_content_after(); ?>
<script type="text/javascript">
$(document).ready(function() {
$('input[name=birthday]').datepicker({changeYear: true, yearRange: "1950:", changeMonth: true});
});
</script>
<?php get_footer(); ?>