Index: job_posting.module =================================================================== RCS file: /cvs/drupal/contributions/modules/job_posting/job_posting.module,v retrieving revision 1.16 diff -u -r1.16 job_posting.module --- job_posting.module 15 Oct 2008 18:26:32 -0000 1.16 +++ job_posting.module 21 Apr 2009 15:26:09 -0000 @@ -1,4 +1,5 @@ - array( - 'name' => t('Job Posting'), - 'module' => 'job_posting', - 'description' => t('Create a job posting announcement.'), - 'has_title' => TRUE, - 'title_label' => t('Title'), - 'has_body' => TRUE, - 'body_label' => t('Description'), - 'locked' => TRUE, - ), - ); -} - -/** - * Implementation of hook_perm() - */ -function job_posting_perm() { + */ + +/** + * @file job_posting.module + * Main module file + */ + +/** + * Implementation of hook_node_info() + */ +function job_posting_node_info() { + // declare our node types return array( - 'create job posting', - 'edit job posting', + 'job_posting' => array( + 'name' => t('Job Posting'), + 'module' => 'job_posting', + 'description' => t('Create a job posting announcement.'), + 'has_title' => TRUE, + 'title_label' => t('Title'), + 'has_body' => TRUE, + 'body_label' => t('Description'), + 'locked' => TRUE, + ), + ); +} + +/** + * Implementation of hook_perm() + */ +function job_posting_perm() { + return array( + 'create job posting', + 'edit job posting', 'edit own job posting', - ); + ); } - -/** - * Implementation of hook_access() - */ -function job_posting_access($op, $node, $account) { - switch ($op) { - case 'create': - return user_access('create job posting', $account); - case 'update': // same as delete - case 'delete': - if ((user_access('edit job posting', $account)) || - (user_access('edit own job posting', $account) && - ($account->uid == $node->uid))) { - return TRUE; - } + +/** + * Implementation of hook_access() + */ +function job_posting_access($op, $node, $account) { + switch ($op) { + case 'create': + return user_access('create job posting', $account); + case 'update': // same as delete + case 'delete': + if ((user_access('edit job posting', $account)) || + (user_access('edit own job posting', $account) && + ($account->uid == $node->uid))) { + return TRUE; + } break; - } + } } - + /** * Implementation of hook_menu() */ @@ -121,6 +122,15 @@ '#required' => TRUE, '#weight' => -9, ); + $form['job_posting_default_deadline'] = array( + '#type' => 'textfield', + '#title' => t('Default Deadline'), + '#default_value' => variable_get('job_posting_default_deadline', 'now'), + '#description' => t('Deadline default can be set to either a day, month, or + year from now. EXAMPLE: +30 day, +2 month or +2 year. + See the '.l('PHP manual', 'http://www.php.net/strtotime').' for avaialble options.'), + '#required' => TRUE, + ); $form['job_posting_limit_per_page'] = array( '#type' => 'textfield', '#title' => t('Job posting summaries per page'), @@ -151,6 +161,15 @@ form_set_error('job_posting_reference_prefix', t('Reference prefix must be an alphabetic string.')); } + // job posting default deadline must be either a number & proper suffix or now + // Include -1 check for PHP versions earlier then 5.1.0 + if(strtotime($form_state['values']['job_posting_default_deadline']) === false + || strtotime($form_state['values']['job_posting_default_deadline']) == -1) { + form_set_error('job_posting_default_deadline', + t('This field is not formatted correctely. + See the '. l('PHP manual', 'http://www.php.net/strtotime') + .' for avaialble options.')); + } } /** @@ -167,22 +186,24 @@ check_plain($form_state['values']['job_posting_sort_order'])); variable_set('job_posting_limit_per_page', check_plain($form_state['values']['job_posting_limit_per_page'])); + variable_set('job_posting_default_deadline', + check_plain($form_state['values']['job_posting_default_deadline'])); drupal_set_message(t('Settings have been saved.')); } - -/** - * Implementation of hook_form() - */ -function job_posting_form(&$node, &$param) { - $type = node_get_types('type', $node); - + +/** + * Implementation of hook_form() + */ +function job_posting_form(&$node, &$param) { + $type = node_get_types('type', $node); + // build select options list for countries $countries = array(0 => t('--')); $result = db_query("SELECT cid, name FROM {job_posting_country}"); while ($data = db_fetch_object($result)) { $countries[$data->cid] = $data->name; } - + // build select options list for time of day $tod = array(); $h = 0; @@ -197,7 +218,7 @@ } $h++; } - + // required fieldset $form['required'] = array( '#type' => 'fieldset', @@ -206,27 +227,30 @@ information needed to handle job posting display and processing.'), '#weight' => -10, ); - if ($type->has_title) { - $form['required']['title'] = array( - '#type' => 'textfield', - '#title' => check_plain($type->title_label), - '#description' => t('Provide the job title or position'), - '#required' => TRUE, - '#default_value' => $node->title, + if ($type->has_title) { + + $form['required']['title'] = array( + '#type' => 'textfield', + '#title' => check_plain($type->title_label), + '#description' => t('Provide the job title or position'), + '#required' => TRUE, + '#default_value' => $node->title, '#weight' => -10, - ); - } - if ($type->has_body) { - $form['required']['body_filter']['body'] = array( - '#type' => 'textarea', - '#title' => check_plain($type->body_label), - '#description' => t('Provide detailed description for this job posting'), - '#required' => TRUE, - '#default_value' => $node->body, - '#weight' => -2, ); - $form['required']['body_filter']['format'] = filter_form($node->format); - } + } + + if ($type->has_body) { + $form['required']['body_filter']['body'] = array( + '#type' => 'textarea', + '#title' => check_plain($type->body_label), + '#description' => t('Provide detailed description for this job posting'), + '#required' => TRUE, + '#default_value' => $node->body, + '#weight' => -2, + ); + $form['required']['body_filter']['filter'] = filter_form($node->format); + } + $form['required']['job_posting_email'] = array( '#type' => 'textfield', '#title' => t('Email address'), @@ -307,7 +331,7 @@ '#required' => TRUE, '#weight' => -9, ); - + // optional fieldset $form['optional'] = array( '#type' => 'fieldset', @@ -322,13 +346,13 @@ '#description' => t('The geographical location associated with this job posting.'), '#weight' => -10, ); - $form['optional']['location']['job_posting_city'] = array( - '#type' => 'textfield', - '#title' => t('City'), - '#description' => t('Provide the city location for this job posting'), - '#required' => FALSE, - '#default_value' => $node->job_posting_city, - '#weight' => -6, + $form['optional']['location']['job_posting_city'] = array( + '#type' => 'textfield', + '#title' => t('City'), + '#description' => t('Provide the city location for this job posting'), + '#required' => FALSE, + '#default_value' => $node->job_posting_city, + '#weight' => -6, ); $form['optional']['location']['job_posting_state'] = array( '#type' => 'textfield', @@ -379,7 +403,7 @@ '#default_value' => $node->job_posting_contact, '#weight' => -1, ); - return $form; + return $form; } /** @@ -425,9 +449,9 @@ } } -/** - * Implementation of hook_load() - */ +/** + * Implementation of hook_load() + */ function job_posting_load($node) { return db_fetch_object(db_query( 'SELECT nid, vid, city AS job_posting_city, state AS job_posting_state, @@ -438,12 +462,14 @@ FROM {job_posting} WHERE nid = %d', $node->nid) ); -} - -/** - * Implementation of hook_view() - */ -function job_posting_view($node, $teaser = FALSE, $page = FALSE) { +} + +/** + * + * Implementation of hook_view() + */ +function job_posting_view($node, $teaser = FALSE, $page = FALSE) { + // do country name lookup, if required if ($node->job_posting_cid != 0) { $node->job_posting_country = db_result(db_query('SELECT name FROM {job_posting_country} @@ -465,7 +491,7 @@ } return $node; } - + /** * FAPI definition for the job application submission form * @@ -482,7 +508,7 @@ $reference = variable_get('job_posting_reference_prefix', 'JOB') . $optargs[0]; $title = $optargs[1]; $email = $optargs[2]; - + // internal fields $form['job_posting_reference'] = array( '#type' => 'value', @@ -496,7 +522,7 @@ '#type' => 'value', '#value' => $email, ); - + // displayed fields $form['job_posting_title_ref'] = array( '#type' => 'item', @@ -518,7 +544,7 @@ '#required' => TRUE, '#description' => t('Enter your introductory covering letter.'), ); - + $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['job_posting_resume'] = array( '#type' => 'file', @@ -527,7 +553,7 @@ covering letter. Files must not exceed 1M in size and can use only the following extensions: txt doc pdf.'), ); - + $form['job_posting_submit'] = array('#type' => 'submit', '#value' => t('Send')); return $form; @@ -562,7 +588,7 @@ } drupal_goto('jobs'); } - + /** * Provide input validation for job application submission form * @@ -587,7 +613,7 @@ } } } - + /** * Assemble pieces for job application mailing and provide form submission * @@ -630,7 +656,7 @@ $params['content-type'] = 'text/plain; charset=UTF-8; format=flowed;'; $params['content'] = $body; } - + // send application to employer if (drupal_mail($module, 'application', $apply_to, $language, $params, $apply_from)) { drupal_set_message(t('Your application has been submitted. Thank you.')); @@ -643,9 +669,8 @@ } } } - } - + /** * Implementation of hook_mail() */ @@ -672,13 +697,13 @@ break; } } - -/** - * Implementation of hook_insert() - */ -function job_posting_insert($node) { + +/** + * Implementation of hook_insert() + */ +function job_posting_insert($node) { db_query("INSERT INTO {job_posting} - (nid, vid, city, state, cid, contact, email, employer, website, deadline, expires, applink) + (nid, vid, city, state, cid, contact, email, employer, website, deadline, expires, applink) VALUES (%d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d, %d, %d)", $node->nid, $node->vid, $node->job_posting_city, $node->job_posting_state, $node->job_posting_cid, $node->job_posting_contact, $node->job_posting_email, @@ -691,21 +716,21 @@ ) ), $node->job_posting_expires, $node->job_posting_applink - ); -} - -/** - * Implementation of hook_update() - */ -function job_posting_update($node) { - if ($node->revision) { - job_posting_insert($node); + ); +} + +/** + * Implementation of hook_update() + */ +function job_posting_update($node) { + if ($node->revision) { + job_posting_insert($node); } - else { - db_query("UPDATE {job_posting} + else { + db_query("UPDATE {job_posting} SET city = '%s', state = '%s', cid = %d, contact = '%s', email = '%s', - employer = '%s', website = '%s', deadline = %d, expires = %d, applink = %d - WHERE nid = %d", + employer = '%s', website = '%s', deadline = %d, expires = %d, applink = %d + WHERE nid = %d", $node->job_posting_city, $node->job_posting_state, $node->job_posting_cid, $node->job_posting_contact, $node->job_posting_email, $node->job_posting_employer, $node->job_posting_url, @@ -717,32 +742,33 @@ ) ), $node->job_posting_expires, $node->job_posting_applink, - $node->nid - ); - } -} - -/** - * Implementation of hook_delete() - */ -function job_posting_delete($node) { - db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); -} - -/** - * Implementation of hook_nodeapi() - */ -function job_posting_nodeapi(&$node, $op, $teaser, $page) { - switch ($op) { - // remove row if its corresponding node gets deleted - case 'delete': - db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); - break; - // remove row if its corresponding revision gets deleted - case 'delete revision': - db_query('DELETE FROM {job_posting} WHERE vid = %d', $node->vid); - break; - } + $node->nid + + ); + } +} + +/** + * Implementation of hook_delete() + */ +function job_posting_delete($node) { + db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); +} + +/** + * Implementation of hook_nodeapi() + */ +function job_posting_nodeapi(&$node, $op, $teaser, $page) { + switch ($op) { + // remove row if its corresponding node gets deleted + case 'delete': + db_query('DELETE FROM {job_posting} WHERE nid = %d', $node->nid); + break; + // remove row if its corresponding revision gets deleted + case 'delete revision': + db_query('DELETE FROM {job_posting} WHERE vid = %d', $node->vid); + break; + } } /** @@ -825,13 +851,14 @@ $listings .= theme('pager', NULL, $limit); } return theme('job_posting_list_display', $listings); -} - -/** - * Implementation of hook_theme() - */ -function job_posting_theme() { - return array( +} + +/** + * Implementation of hook_theme() + */ + +function job_posting_theme() { + return array( 'job_posting_node_display' => array( 'arguments' => array('node' => NULL, 'page' => NULL, 'teaser' => NULL), 'template' => 'job-posting-node', @@ -844,7 +871,7 @@ 'arguments' => array('listings' => NULL), 'template' => 'job-posting-list', ), - ); + ); } /** @@ -868,7 +895,7 @@ $variables['node']->job_posting_state, $variables['node']->job_posting_country )); - + // does this posting expire? if ($variables['node']->job_posting_expires) { // is there still time left? @@ -884,7 +911,7 @@ else { $variables['deadline'] = NULL; } - + // is the node for information-only or should it supply 'submit application' link? if ($variables['node']->job_posting_applink) { // check if the posting is still alive or whether a deadline is even being used @@ -908,9 +935,9 @@ $variables['joblink'] = t('Login to submit an application', array('@login' => url('user/login', array('query' => 'destination=job/application/node/'. $variables['node']->nid)))); } - } + } } - } + } $variables['contact'] = check_plain($variables['node']->job_posting_contact); $variables['url'] = check_url($variables['node']->job_posting_url); } @@ -980,7 +1007,7 @@ else { $local = $gmt + variable_get('date_default_timezone', 0); } - return $local; + return $local; } /** @@ -990,11 +1017,12 @@ */ function _job_posting_localtime() { global $user; + $time = strtotime(variable_get('job_posting_default_deadline', 'now')); if (variable_get('configurable_timezones', 0) && $user->uid != 0) { - $localtime = (time() - variable_get('date_default_timezone', 0)) + $user->timezone; + $localtime = ($time - variable_get('date_default_timezone', 0)) + $user->timezone; } else { - $localtime = time(); + $localtime = $time; } return $localtime; } @@ -1040,4 +1068,4 @@ } $seconds -= $minutes * 60; return $countdown; -} +} \ No newline at end of file