RedJumpsuit

jobberBase custom development and support

 

Code School

Extend Ads in jB 1.7 (w/ notification)

the extend job function actually already exists since 1.6 (and even earlier i think) but i haven’t seen anyone post a tutorial on how to use the function to actually extend jobs. when i say extend, what the function does is just to update the “created_on” field to “NOW()” on the jobs table. the code looks like this in /_includes/class.Job.php

// Extend a post for 30 days
public function Extend()
{
    global $db;
    $sql = 'UPDATE jobs SET created_on = NOW(), is_active = 1 WHERE id = ' . $this->mId;
    if ($db->query($sql))
    {
        return true;
    }
    else
    {
        return false;
    }
}

this is how it will look like on the admin page

extend

so let me show you how to use this function. first is to extract this file and save the images in your /img folder

extend.zip

then, open up config.php on the root folder and add this anywhere

// number of days til extension is active
define('EXTEND_DAYS', 27);

open up /_includes/translations.ini and add under [js]

extend_job_confirmation_question = "Are you sure you want to extend this post?"

open up /js/functions.js and before the line

Delete: function(url, job_id)

add the following (watch out for the comma (,) at the end of this code)

Extend: function(url, job_id)
{
    if(confirm(Jobber.I18n.js.extend_job_confirmation_question))
    {
        $.ajax({
          type: "POST",
          url: url,
          data: "job_id=" + job_id,
          success: function(msg) {
            if (msg != "0")
                {
                    var currentJobId = 'item'+job_id;
                    $("#"+currentJobId).css({ display: "none" });
                }
          }
        });
    }
    else
        return false;
},

next is to open up /admin/_templates/posts-loop.tpl and update this file. look for the line that contains the following

<a title="delete" onclick="Jobber.Delete('{$BASE_URL_ADMIN}delete/', {$job.id});" href="javascript:void(0);"><img src="{$BASE_URL}img/icon-delete.png" alt="delete" /></a>

before this line, add the following code

{if $job.days_old >= $smarty.const.EXTEND_DAYS && $job.is_active == 1}
    <a title="extend" onclick="Jobber.Extend('{$BASE_URL_ADMIN}extend/', {$job.id});" href="javascript:void(0);"><img src="{$BASE_URL}img/extend_yes.png" alt="extend" /></a>
{else}
    <img title="not for extension yet" src="{$BASE_URL}img/extend_no.png" alt="not for extension yet" />
{/if}

on /admin/index.php, under this block

case 'home':
    if(!isset($_SESSION['AdminId']))
    {
        redirect_to(BASE_URL);
        exit;
    }
    require_once 'page_home.php';
    $flag = 1;
    break;

add these lines

// extend ads
case 'extend':
    if(!isset($_SESSION['AdminId']))
    {
        redirect_to(BASE_URL);
        exit;
    }
    require_once 'page_extend.php';
    $flag = 1;
    break;

next is to create a file called page_extend.php on the /admin folder and add the following code

<?php
    $j = new Job($_POST['job_id']);
    if ($j->Extend())
    {
        $m = new Postman();
        $m->MailAdExtend($j->GetInfo(), BASE_URL_ORIG);
        echo 1;
    }
    else
    {
        echo "0";
    }
    exit;
?>

and finally to send notification when the ad is extended, open up
/_includes/class.Postman.php and add this function before the last }

// Send mail when ad is extended
public function MailAdExtend($data, $url=BASE_URL)
{
    $subject = 'Your ad on ' . SITE_NAME . ' was extended';
    $msg = "Hello! :)\n\n";
    $msg .= "Your ad was extended and is available at: " . $url . "job/" . $data['id'] . "/" . $data['url_title'] . "/";
    $msg .= "\n\n---\nEdit it: " . $url . "post/" . $data['id'] . "/" . $data['auth'] . "/";
    $msg .= "\nDeactivate it: " . $url . "deactivate/" . $data['id'] . "/" . $data['auth'] . "/";
    $msg .= "\n\n---\n\nThank you for using our service!\nThe " . SITE_NAME . " Team";
 
    if ($data['poster_email'] != '' && validate_email($data['poster_email']))
    {
        mail($data['poster_email'], $subject, $msg, "From: " . SITE_NAME . " <" . NOTIFY_EMAIL . ">");
    }
}

10 Comments

Code School

  1. can you add this to original zip file? because i applicated this to my job system i have only plain screen.

  2. hi, turn your error reporting on and let me know what error you get.

  3. Looks great this add on. But before trying this I was wondering is this an option that’s accesible directly by the job poster? Or only for the admin. Thanks again for your great work!!

    PS Do you know how to swap a jobberbase logo with a flash logo?

  4. hi, yes this is for admin only. job posters will have no access to this. i wouldn’t know how to replace the default logo to a flash logo…no ui design for me, just pure programming 😉

  5. hi, please review the code again. i just noticed that there were missing lines on the part where you need to create the page_extend.php page and paste the code from the tutorial.

  6. Sorry but isnt work by me!

    Fatal error: Cannot redeclare Job::Extend() in /home/www/osztrakmelo/www/app/_includes/class.Job.php on line 932

    Pls help

    I have all insert and uploaded the scripts and codes

    Thx

  7. hi, do not re-declare the class as it already exists!

  8. Thx for clear my eyes

  9. Hey Redjumpsuit,

    I would like to give the job posters the option to refresh the job by them self thru an automatic send mail after 30 days. I think by that way jobs are more accurate with date vis

  10. hi, should be easy if you have php skills. you can add an extend link (just like an edit or deactivate link) and the users just click on this link and ads will be automatically extended for them.

Leave a Response