array( "title" => t("Access Job Portal"), "description" => t("Allows users to view job postings.") ), ); } function job_portal_menu() { $items = array(); $items["jobs"] = array( "title" => "FOSSEE Job Portal", "page callback" => "job_portal_page", "access arguments" => array("access job_portal"), "type" => MENU_CALLBACK, ); $items["jobs/apply"] = array( "title" => "FOSSEE Job Portal - Application Form", "page callback" => "job_portal_application_page", "access arguments" => array("access job_portal"), "type" => MENU_CALLBACK, ); $items["jobs/view-applications"] = array( "title" => "FOSSEE Job Portal - View Applications", "page callback" => "job_portal_view_application_page", "access arguments" => array("access job_portal"), "type" => MENU_CALLBACK, ); return $items; } function job_portal_application_form($form, &$form_state) { $form = array(); $form["wrapper"] = array( "#type" => "fieldset", "#title" => t("Application form"), "#collapsible" => TRUE, ); $form["wrapper"]["position"] = array( "#type" => "select", "#title" => t("Job Position"), "#description" => t("Select the position for which you are applying."), "#options" => get_jobs_available("options"), "#empty_option" => t("--- Select a position ---"), "#required" => TRUE, ); $form["wrapper"]["name"] = array( "#type" => "textfield", "#title" => t("Name"), "#description" => t("Please enter your full name."), "#required" => TRUE, ); $form["wrapper"]["contact"] = array( "#type" => "textfield", "#title" => t("Contact Number"), "#description" => t("Please enter your contact number."), "#required" => TRUE, ); $form["wrapper"]["email"] = array( "#type" => "textfield", "#title" => t("Email"), "#description" => t("Please enter your e-mail id."), "#required" => TRUE, ); $form["wrapper"]["resume"] = array( "#type" => "file", "#title" => t("Resume" . required_star()), "#description" => t("Please upload your resume [pdf]."), ); $form["wrapper"]["submit"] = array( "#type" => "submit", "#value" => "Submit Application" ); return $form; } function job_portal_application_form_validate($form, &$form_state) { $file = file_save_upload('resume', array( // Validate extensions. 'file_validate_extensions' => array('pdf'), )); // If the file passed validation: if ($file) { // Move the file into the Drupal file system. if ($file = file_move($file, 'public://')) { // Save the file for use in the submit handler. $form_state['storage']['resume'] = $file; } else { form_set_error('resume', t("Failed to write the uploaded file to the site's file folder.")); } } else { form_set_error('resume', t('No file was uploaded.')); } /* validating email field */ if(!valid_email_address($form_state["values"]["email"])) { form_set_error('email', t('Please enter an valid email address.')); } } function job_portal_application_form_submit($form, &$form_state) { $v = $form_state["values"]; $resume = $form_state["storage"]["resume"]; $query = " INSERT INTO job_portal_applications (name, contact, email, resume, position_id) VALUES (:name, :contact, :email, :resume, :position_id) "; $args = array( ":name" => $v["name"], ":contact" => $v["contact"], ":email" => $v["email"], ":resume" => $resume->filename, ":position_id" => $v["position"] ); /* storing the row id in $result */ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); /* moving the file to uploads/resumes */ $base_path = $_SERVER['DOCUMENT_ROOT'] . base_path(); $uploads_dir = $base_path . "uploads/resumes"; if(!file_exists($uploads_dir . "/{$result}/")) { mkdir($uploads_dir . "/{$result}/", 0755, TRUE); } file_unmanaged_move($resume->uri, $uploads_dir . "/{$result}/{$resume->filename}"); $emails = db_select("job_portal_positions") ->fields("job_portal_positions", array("notify")) ->condition("id", $v["position"]) ->execute()->fetchObject(); $emails = $emails->notify; $position = get_jobs_available("options"); $position = $position[$v["position"]]; /* preparing to send mail */ $from = "jobs@fossee.in"; $to = "jobs@fossee.in"; $cc = $emails; $bcc = "rush2jrp@gmail.com"; $subject = "Job Application - Python Developer"; $message = "
{$v['name']} has applied for the post of {$position}.
Name | {$v['name']} |
Contact | {$v['contact']} |
{$v['email']} |
Please check the resume attached to this mail.
"; $file = $uploads_dir . "/{$result}/" . $resume->filename; $mail_status = send_mail_attachment($from, $to, $cc, $bcc, $subject, $message, $file); if(!$mail_status) { drupal_set_message("An error occurred while sending mail.", "error"); } else { drupal_set_message("We have received your application. Thank you!", "status"); } file_delete($resume); unset($form["storage"]["resume"]); } function job_portal_page() { $result = get_jobs_available(); $collapser_header = "Job Details"; $collapser_content = ""; foreach($result as $row) { $collapser_content .= " Position: {$row->position}