<!-- Attachment Types --> <div class="custom-box"> <div class="column one-sixth"> <label><?php _e('Attachment Types', 'dt_themes'); ?> </label> </div> <div class="column five-sixth last"> <?php $assignment_attachment_type = get_post_meta($post_id, "assignment-attachment-type", true); $attachment_types = dt_allowed_filetypes(); $out = ''; $out .= '<select id="assignment-attachment-type" name="assignment-attachment-type[]" multiple style="width:70%;" data-placeholder="' . __('Select Attachment Type...', 'dt_themes') . '" class="dt-chosen-select">' . "\n"; $out .= '<option value=""></option>'; if (count($attachment_types) > 0) { foreach ($attachment_types as $attachment_type) { if ($assignment_attachment_type != '' && in_array($attachment_type, $assignment_attachment_type)) { $str = 'selected="selected"'; } else { $str = ''; } $out .= '<option value="' . esc_attr($attachment_type) . '"' . $str . '>' . strtoupper($attachment_type) . '</option>' . "\n"; } } $out .= '</select>' . "\n"; echo $out;
function dt_submit_assignemnt() { require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; $user_id = get_current_user_id(); $user_info = get_userdata($user_id); $title = $user_info->display_name; $title .= ' - ' . get_the_title(); $attachment_types = dt_allowed_filetypes(); $assignment_attachment_type = get_post_meta(get_the_ID(), "assignment-attachment-type", true); $assignment_attachment_size = get_post_meta(get_the_ID(), "assignment-attachment-size", true); if (!empty($_FILES['dt-assignemnt-attachment']['name'])) { $fileName = $_FILES['dt-assignemnt-attachment']['name']; $fileInfo = pathinfo($fileName); $fileExtension = strtolower($fileInfo['extension']); $error_str = ''; if (isset($assignment_attachment_type) && $assignment_attachment_type != '') { if (!in_array($fileExtension, $assignment_attachment_type)) { $error_str .= '<strong>' . __('Allowed File Types : ', 'dt_themes') . '</strong>'; $error_str .= '<ul>'; foreach ($assignment_attachment_type as $assignment) { $error_str .= '<li class="' . $assignment . '">' . $assignment . '</li>'; } $error_str .= '</ul>'; } } if (isset($assignment_attachment_size) && $assignment_attachment_size != '') { if ($_FILES['dt-assignemnt-attachment']['size'] > $assignment_attachment_size * 1048576) { if ($error_str != '') { $error_str = ', '; } $error_str .= '<strong>' . __('Maximum File Size : ', 'dt_themes') . '</strong>' . $assignment_attachment_size . 'MB'; } } if ($error_str != '') { echo __('<strong>ERROR: </strong>', 'wplms-assignments') . $error_str; return false; } } $assignment_course_evaluation = get_post_meta(get_the_ID(), "assignment-course-evaluation", true); $dt_assignment_course = get_post_meta(get_the_ID(), "dt-assignment-course", true); $dt_gradings = array('post_type' => 'dt_gradings', 'meta_query' => array()); $dt_gradings['meta_query'][] = array('key' => 'dt-user-id', 'value' => $user_id, 'compare' => '=', 'type' => 'numeric'); $dt_gradings['meta_query'][] = array('key' => 'dt-assignment-id', 'value' => get_the_ID(), 'compare' => '=', 'type' => 'numeric'); $dt_grade_post = get_posts($dt_gradings); if (empty($dt_grade_post)) { $grade_post = array('post_title' => $title, 'post_status' => 'publish', 'post_type' => 'dt_gradings', 'post_author' => get_the_author_meta('ID')); $grade_post_id = wp_insert_post($grade_post); update_post_meta($grade_post_id, 'grade-type', 'assignment'); update_post_meta($grade_post_id, 'dt-assignment-id', get_the_ID()); update_post_meta($grade_post_id, 'dt-user-id', $user_id); update_post_meta($grade_post_id, 'dt-course-id', $dt_assignment_course); } else { $grade_post_id = isset($dt_grade_post[0]) ? $dt_grade_post[0]->ID : 0; } $prev_attachment_id = get_post_meta($grade_post_id, "dt-attachment-id", true); wp_delete_attachment($prev_attachment_id, true); if (!empty($_FILES['dt-assignemnt-attachment']['name'])) { $attachemnt_id = media_handle_upload('dt-assignemnt-attachment', $grade_post_id); update_post_meta($grade_post_id, 'dt-attachment-id', $attachemnt_id); update_post_meta($grade_post_id, 'dt-attachment-name', $_FILES['dt-assignemnt-attachment']['name']); } else { delete_post_meta($grade_post_id, "dt-attachment-id"); delete_post_meta($grade_post_id, "dt-attachment-name"); } update_post_meta($grade_post_id, 'dt-assignment-notes', $_POST['dt-assignemnt-textarea']); return true; }