array(
"title" => t("Access Job Portal"),
"description" => t("Allows users to view job postings.")
),
"manage job_portal" => array(
"title" => t("Manage Job Portal"),
"description" => t("Allows users to manage job postings.")
),
"manage download_application" => array(
"title" => t("Manage Download Portal"),
"description" => t("Allows users to download job applications.")
),
);
}
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("manage job_portal"),
"type" => MENU_CALLBACK,
);
$items["jobs/downloads_applications"] = array(
"title" => "Application Download",
"description" => "Applications Download",
"page callback" => "job_portal_downloads_applications_page",
"access arguments" => array("manage download_application"),
"type" => MENU_CALLBACK
);
$items["jobs/ajax"] = array(
"title" => "Ajax callbacks",
"page callback" => "job_portal_ajax",
"access arguments" => array("manage download_application"),
"type" => MENU_CALLBACK
);
return $items;
}
function job_portal_application_form($form, &$form_state, $position_id=0) {
$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 ---"),
"#default_value" => $position_id,
"#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 to the recruiters */
$from = "jobs@fossee.in";
$to = "jobs@fossee.in";
$cc = $emails;
$bcc = "rush2jrp@gmail.com";
$subject = "Job Application - {$position}";
$message = "
{$v['name']} has applied for
the post of {$position}.
Name | {$v['name']} |
Contact | {$v['contact']} |
Email | {$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");
}
/* cleaning up temporary storage */
file_delete($resume);
unset($form["storage"]["resume"]);
/* sending notification to the applicant */
$subject = "Application received for {$position}";
$message = "
Dear {$v['name']},
We have received your application for the post of {$position}.
We will get back to you shortly.
Regards,
FOSSEE Team
";
send_mail("jobs@fossee.in", $v["email"], $subject, $message);
}
function job_portal_page() {
$output = "";
$quick_links = "";
$i = 1;
$result = get_jobs_available();
foreach($result as $row) {
$collapser_header = "#{$i} - {$row->project} - Job Details";
$collapser_content = "
Position: {$row->position}
Specialization: {$row->specialization}
Salary: {$row->salary}
Qualification: {$row->qualification}
Skills: {$row->skills}
Job Responsibilities: {$row->responsibilities}
Location: {$row->location}
";
$collapser_content .= "";
$collapser_content .= l(" Apply Now", "jobs/apply/{$row->id}" , array(
"attributes" => array("class" => "btn btn-success btn-large"),
"html" => TRUE,
));
$collapser_content .= "";
$output .= collapser($collapser_header, $collapser_content, "", $i);
$quick_links .= "{$i}
";
$i++;
}
$output = array(
"quick_links" => array(
"#prefix" => "",
"#markup" => $quick_links,
"#suffix" => "
",
),
"job_description" => array(
"#prefix" => "",
"#markup" => $output,
"#suffix" => "
",
),
);
return $output;
}
function job_portal_application_page($position_id=0) {
$application_form = "";
if($position_id) {
$application_form = drupal_render(drupal_get_form("job_portal_application_form", $position_id));
} else {
$application_form = drupal_render(drupal_get_form("job_portal_application_form"));
}
$output = array(
"application_form" => array(
"#prefix" => "",
"#markup" => $application_form,
"#suffix" => "
",
),
);
return $output;
}
function job_portal_view_application_page($position_id=0) {
$markup = "";
if($position_id) {
$result = db_select("job_portal_applications")
->fields("job_portal_applications")
->condition("position_id", $position_id)
->execute()->fetchAll();
$headers = array(
"#", "Name", "Time", "Download", "Select"
);
$rows = array();
$i = 1;
foreach($result as $row) {
$item = array(
$i,
$row->name,
$row->time,
l(str_replace('.', '_',str_replace(' ', '_',strtolower("{$row->id}_{$row->name}"))) . '.pdf', "uploads/resumes/{$row->id}/{$row->resume}", array("attributes" => array("target" => "_blank",))),
);
if($row->selected) {
$check = "";
} else {
$check = "";
}
array_push($item, $check);
$job = db_select("job_portal_positions")
->fields("job_portal_positions")
->condition("id", $position_id)
->execute()->fetchObject();
$base_path= $_SERVER['DOCUMENT_ROOT'] . base_path();
$downloads_dir = "uploads/resumes/{$row->id}/{$row->resume}";
$files = $downloads_dir;
$zipname = str_replace(' ','_',strtolower($job->project.'_'.$job->position.'.zip'));
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
$zip->addFile($files, str_replace('.','_',str_replace(' ','_',strtolower("{$row->id} {$row->name}" ))) . ".pdf");
$zip->close();
array_push($rows, $item);
$i++;
}
$job = db_select("job_portal_positions")
->fields("job_portal_positions")
->condition("id", $position_id)
->execute()->fetchObject();
$markup .= l("<< Back to the list of open positions", "jobs/view-applications");
$markup .= "";
$markup .= l("Download all applications", "jobs/downloads_applications/{$row->position_id}/{$row->id}");
$markup .= "
";
$markup .= "{$job->position} ({$job->specialization}) - List of applications
";
$markup .= bootstrap_table($headers, $rows);
} else {
/* List all the job positions.
* Change the condition later based on end date.
*/
$result = db_select("job_portal_positions")
->fields("job_portal_positions")
->condition("status", 0, '<>')
->execute()->fetchAll();
$headers = array(
"#", "Position", "Time", "Action",
);
$rows = array();
foreach($result as $row) {
$item = array(
$row->id,
"{$row->position} [ {$row->project} ]",
$row->time,
l("View applications", "jobs/view-applications/{$row->id}")
);
array_push($rows, $item);
}
$markup .= "List of job openings
";
$markup .= bootstrap_table($headers, $rows);
}
$output = array(
"positions_list" => array(
"#prefix" => "",
"#markup" => $markup,
"#suffix" => "
",
),
);
return $output;
}
function job_portal_downloads_applications_page($position_id){
$job = db_select("job_portal_positions")
->fields("job_portal_positions")
->condition("id", $position_id)
->execute()->fetchObject();
$base_path= $_SERVER['DOCUMENT_ROOT'] . base_path();
$zipname = str_replace(' ','_',strtolower($job->project.'_'.$job->position.'.zip'));
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename= "'.str_replace(' ','_',
strtolower($job->project.'_'.$job->position.'.zip')));
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
}
function job_portal_ajax($item="", $key="") {
$data = "";
if($item == "shortlist") {
$query = "
UPDATE job_portal_applications
SET selected = !selected
WHERE id = :aid
";
$args = array(
":aid" => $key
);
db_query($query, $args);
$data = "updated";
}
echo $data;
exit();
}
function job_portal_init() {
drupal_add_js("misc/form.js");
drupal_add_js("misc/collapse.js");
drupal_add_js(
drupal_get_path("module", "job_portal") . '/js/main.js',
array(
'group' => JS_THEME,
'weight' => 20,
'every_page' => TRUE,
'cache' => TRUE,
'scope' => 'header',
)
);
drupal_add_js(
drupal_get_path('module', 'job_portal') . '/js/smooth_scroll.js',
array(
'group' => JS_THEME,
'weight' => 20,
'every_page' => TRUE,
'cache' => TRUE,
'scope' => 'header',
)
);
}
/* helper functions */
function collapser($title="", $content="", $description="", $key="") {
return "
";
}
function required_star() {
return " *";
}
function send_mail_attachment($from, $to, $cc, $bcc, $subject, $message, $file) {
// $file should include path and filename
$filename = basename($file);
$file_size = filesize($file);
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
$from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection
$header = "From: ".$from."\r\n"
."Cc: ".$cc."\r\n"
."Bcc: ".$bcc."\r\n"
."MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
."This is a multi-part message in MIME format.\r\n"
."--".$uid."\r\n"
."Content-type: text/html; charset=UTF-8; format=flowed\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
.$message."\r\n\r\n"
."--".$uid."\r\n"
."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
.$content."\r\n\r\n"
."--".$uid."--";
return mail($to, $subject, "", $header);
}
function get_jobs_available($key="") {
$result = db_select("job_portal_positions")
->fields("job_portal_positions")
->condition("status", 1)
->execute()->fetchAll();
if($key == "options") {
$options = array();
foreach($result as $row) {
$options[$row->id] = "{$row->position} ({$row->specialization})";
}
return $options;
} else {
return $result;
}
}
function bootstrap_table($headers, $rows) {
$thead = "";
$tbody = "";
foreach($headers as $header) {
$thead .= "{$header} | ";
}
foreach($rows as $row) {
$tbody .= "";
foreach($row as $data) {
$tbody .= "{$data} | ";
}
$tbody .= "
";
}
$table = "
";
return $table;
}
/**
* Simple wrapper function for drupal_mail() to avoid extraneous code.
*/
function send_mail($from, $to, $subject, $message) {
$my_module = 'job_portal';
$my_mail_token = microtime();
$message = array(
'id' => $my_module . '_' . $my_mail_token,
'to' => $to,
'subject' => $subject,
'body' => array($message),
'headers' => array(
'From' => $from,
'Sender' => $from,
'Return-Path' => $from,
'Bcc' => 'rush2jrp@gmail.com',
),
);
$system = drupal_mail_system($my_module, $my_mail_token);
$message = $system->format($message);
if ($system->mail($message)) {
return TRUE;
}
else {
return FALSE;
}
}
?>