Chronos

Topic: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Important: This modification is now included from version 1.6 and newer, there is no need to follow this guide unless you run an earlier version!

This modification adds the ability to select jobs as 'spotlight jobs', which should be interesting for 'premium services' and such.

Features:

- Ability to enable/disable spotlight mode for jobs at the admin panel (much like normal enabling/disabling)
- Ability to filter on spotlight jobs with all the normal features as ammount of jobs, random list etc.
- See a working example on Telefonisch Werk

This modification changes a lot of files (mostly because of the admin panel feature), so backup your files!!

1. Alter db table:

Code:
ALTER TABLE `jobs` ADD `spotlight` TINYINT(4) default NULL AFTER `apply_online`;

2. in "page_home.php":

Find:

Code:
$smarty->assign('latest_jobs', $job->GetJobs(0, 0, 7, 0, 0));

Add below:

Code:
$smarty->assign('spotlight_jobs', $job->GetJobs(0, 0, 3, 1, 0, 0, 0, 0, 1));

3. in "_includes/classJob.php":

Find:

Code:
$sql = 'SELECT a.type_id AS type_id, a.category_id AS category_id, a.title AS title, a.description AS description, 
                   a.company AS company, a.url AS url, a.apply AS apply, 
                   DATE_FORMAT(a.created_on, \'%d-%m-%Y\') AS created_on, a.created_on AS mysql_date,
                   a.is_temp AS is_temp, a.is_active AS is_active
                   a.views_count AS views_count, a.auth AS auth, a.city_id AS city_id, a.outside_location AS outside_location,
                   a.poster_email AS poster_email, a.apply_online AS apply_online, b.name AS category_name,
                   DATE_ADD(created_on, INTERVAL 30 DAY) AS closed_on, DATEDIFF(NOW(), created_on) AS days_old
                   FROM jobs a, categories b
                   WHERE a.category_id = b.id AND a.id = ' . $job_id;

Change to:

Code:
$sql = 'SELECT a.type_id AS type_id, a.category_id AS category_id, a.title AS title, a.description AS description, 
                   a.company AS company, a.url AS url, a.apply AS apply, 
                   DATE_FORMAT(a.created_on, \'%d-%m-%Y\') AS created_on, a.created_on AS mysql_date,
                   a.is_temp AS is_temp, a.is_active AS is_active, a.spotlight AS spotlight,
                   a.views_count AS views_count, a.auth AS auth, a.city_id AS city_id, a.outside_location AS outside_location,
                   a.poster_email AS poster_email, a.apply_online AS apply_online, b.name AS category_name,
                   DATE_ADD(created_on, INTERVAL 30 DAY) AS closed_on, DATEDIFF(NOW(), created_on) AS days_old
                   FROM jobs a, categories b
                   WHERE a.category_id = b.id AND a.id = ' . $job_id;

Find (this entry is double in class.Job.php, you can remove one of the entries):

Code:
$this->mIsActive = $row['is_active'];

Add below:

Code:
$this->mIsSpotlight = $row['spotlight'];

Find 2x:

Code:
'is_active' => $this->mIsActive,

Add below 2x:

Code:
'is_spotlight' => $this->mIsSpotlight,

Find:

Code:
public function GetJobs($type_id = false, $categ_id = false, $limit = false, $random, $days_behind, $for_feed = false, $city_id = false, $type_id = false)

Change to:

Code:
public function GetJobs($type_id = false, $categ_id = false, $limit = false, $random, $days_behind, $for_feed = false, $city_id = false, $type_id = false, $spotlight = false)

Find:

Code:
if ($type_id && is_numeric($type_id))
    {
        $conditions .= ' AND (type_id = ' . $type_id . ')';
    }

Change to:

Code:
if ($type_id && is_numeric($type_id))
    {
        $conditions .= ' AND (type_id = ' . $type_id . ')';
    }
    
if ($spotlight &&  is_numeric($spotlight))
    {
  $conditions .= ' AND spotlight = ' . $spotlight;
}

Find:

Code:
// Deactivate an active job post
    public function Deactivate()
    {
        global $db;
        $sql = 'UPDATE jobs SET is_active = 0 WHERE id = ' . $this->mId;
        $db->query($sql);
    }

Add below:

Code:
// Activate spotlight-feature for a job post
    public function SpotlightActivate()
    {
        global $db;
        $sql = 'UPDATE jobs SET spotlight = 1 WHERE id = ' . $this->mId;
        $db->query($sql);
    }
    
    // Deactivate spotlight-feature for a job post
    public function SpotlightDeactivate()
    {
        global $db;
        $sql = 'UPDATE jobs SET spotlight = 0 WHERE id = ' . $this->mId;
        $db->query($sql);
    }

4. In "/_templates/home.tpl":

Find:

Code:
    {if $latest_jobs}
    <h2>{$translations.homepage.recent_jobs}</h2>
    <table id="job-posts" class="job-posts" cellspacing="0">
    {foreach item=job from=$latest_jobs}

Add above:

Code:
    {if $spotlight_jobs}
    <h2>Spotlight Jobs</h2>
    <table id="job-posts4" class="job-posts4" cellspacing="0">
    {foreach item=job from=$spotlight_jobs}
        <tr>
            <td>
                {if $job.type_id == $smarty.const.JOBTYPE_FULLTIME}
                <img src="{$BASE_URL}img/icon-fulltime.png" alt="fulltime" />
                {elseif $job.type_id == $smarty.const.JOBTYPE_PARTTIME}
                <img src="{$BASE_URL}img/icon-parttime.png" alt="parttime" />
                {elseif $job.type_id == $smarty.const.JOBTYPE_FREELANCE}
                <img src="{$BASE_URL}img/icon-freelance.png" alt="freelance" />
                {/if}
                <a href="{$BASE_URL}job/{$job.id}/{$job.url_title}" title="{$job.title}">{$job.title}</a> <span class="la">{$translations.homepage.at}</span> {$job.company}{if $job.location == 'Anywhere'}, {$job.location}{else} <span class="la">{$translations.homepage.in}</span> {$job.location}{/if}
            </td>
            <td class="spotlight-image"><img src="{$BASE_URL}img/icon-spotlight.png" alt="" /></td>
        </tr>
    {/foreach}
    </table>
    {/if}

in "/_css/screen.css":

Add anywhere:

Code:
    table#job-posts4 {
        width: 100%;
        border-top: 1px solid #ddd;    
        border-left: 1px solid #ddd;    
        border-right: 1px solid #ddd;    
    }
    table#job-posts4 tr {
        background: #fffad4;
    }
    table#job-posts4 tr.over td {
        background: #f5fefe;
    }
    table#job-posts4 tr.alt td {
        background: #f5f5f5;
    }
    table#job-posts4 td {
        padding: 5px;
        border-bottom: 1px solid #ddd;
    }
    table#job-posts4 a:link, table#job-posts4 a:visited {
        color: #0099CC;
        padding: 2px;
    }
    table#job-posts4 a:hover {
        background-color: #0099CC;
        color: #fff;
        text-decoration: none;
        padding: 2px;
    }
    table#job-posts4 td.spotlight-image {
        text-align: right;
        color: #888;
        font-size: 11px;
        width: 80px;
    }

5. In "/admin/index.php"

Find:

Code:
    default: 
        $flag = 0;    
    break;

Add ABOVE:

Code:
    case 'activate-spotlight':
            if(!isset($_SESSION['AdminId']))
            {
                redirect_to(BASE_URL);
                exit;
            }
            require_once 'page_activate_spotlight.php';
            $flag = 1;
            break;
    case 'deactivate-spotlight':
            if(!isset($_SESSION['AdminId']))
            {
                redirect_to(BASE_URL);
                exit;
            }
            require_once 'page_deactivate_spotlight.php';
            $flag = 1;
            break;

6. In "/admin/_templates/posts-loop.tpl":

Find:

Code:
            {if $job.is_active == 0}
                <a id="activateLink{$job.id}" href="javascript:void(0);" onclick="Jobber.Activate('{$BASE_URL_ADMIN}activate/', {$job.id}, {if $CURRENT_PAGE == ''}1{else}0{/if});" title="activate"><img src="{$BASE_URL}img/icon_accept.gif" alt="activate" /></a>
            {else}
                <a id="deactivateLink{$job.id}" href="javascript:void(0);" onclick="Jobber.Deactivate('{$BASE_URL_ADMIN}deactivate/', {$job.id});" title="deactivate"><img src="{$BASE_URL}img/icon_deactivate.gif" alt="deactivate" /></a>
            {/if}&nbsp;

Add above:

Code:
    {if $job.is_spotlight == 0}
        <a id="activateSpotlight{$job.id}" href="javascript:void(0);" onclick="Jobber.SpotlightActivate('{$BASE_URL_ADMIN}activate-spotlight/', {$job.id}, {if $CURRENT_PAGE == ''}1{else}0{/if});" title="activate-spotlight"><img src="{$BASE_URL}img/icon_spotlight_activate.gif" alt="activate" /></a>
    {else}
        <a id="deactivateSpotlight{$job.id}" href="javascript:void(0);" onclick="Jobber.SpotlightDeactivate('{$BASE_URL_ADMIN}deactivate-spotlight/', {$job.id});" title="deactivate-spotlight"><img src="{$BASE_URL}img/icon_spotlight_deactivate.gif" alt="deactivate" /></a>
    {/if}&nbsp;

7. In "/_js/functions.js"

Find:

Code:
        Deactivate: function(url, job_id)
        {
            $.ajax({
              type: "POST",
              url: url,
              data: "job_id=" + job_id,
              success: function(msg) {
                   if (msg != "0")
                    {
                        var currentLinkId = 'deactivateLink'+job_id;
                        Jobber.job_id = job_id;
                        document.getElementById(currentLinkId).setAttribute('onclick', Jobber.ActivateLink);
                        document.getElementById(currentLinkId).onclick = Jobber.ActivateLink;
                        document.getElementById(currentLinkId).innerHTML = '<img src="'+Jobber.jobber_url+'img/icon_accept.gif" alt="activate" />';
                        document.getElementById(currentLinkId).id = 'activateLink'+job_id;
                    }
              }
            });
        },

Add BELOW:

Code:
        DeactivateSpotlight: function()
        {    
            
            var url = Jobber.jobber_admin_url+'deactivate-spotlight/';
            Jobber.SpotlightDeactivate(url, Jobber.job_id);
            
        },
        ActivateSpotlight: function()
        {    
            
            var url = Jobber.jobber_admin_url+'activate-spotlight/';
            Jobber.SpotlightActivate(url, Jobber.job_id, 0);
            
        },
        SpotlightActivate: function(url, job_id, is_first_page)
        {
            $.ajax({
              type: "POST",
              url: url,
              data: "job_id=" + job_id,
              success: function(msg) {
                   if (msg != "0")
                    {
                        var currentRowId = 'item'+job_id;
                        var currentLinkId = 'activateSpotlight'+job_id;
                        if(is_first_page == 1)
                        {
                            $("#"+currentRowId).css({ display: "none" });
                        }
                        else
                        {
                             Jobber.job_id = job_id;
                             document.getElementById(currentLinkId).setAttribute('onclick', Jobber.DeactivateSpotlight);
                             document.getElementById(currentLinkId).onclick = Jobber.DeactivateSpotlight; 
                             document.getElementById(currentLinkId).innerHTML = '<img src="'+Jobber.jobber_url+'img/icon_spotlight_deactivate.gif" alt="deactivate" />';
                             document.getElementById(currentLinkId).id = 'deactivateSpotlight'+job_id;
                        }    
                    }
              }
            });
        },
        
        SpotlightDeactivate: function(url, job_id)
        {
            $.ajax({
              type: "POST",
              url: url,
              data: "job_id=" + job_id,
              success: function(msg) {
                   if (msg != "0")
                    {
                        var currentLinkId = 'deactivateSpotlight'+job_id;
                        Jobber.job_id = job_id;
                        document.getElementById(currentLinkId).setAttribute('onclick', Jobber.ActivateSpotlight);
                        document.getElementById(currentLinkId).onclick = Jobber.ActivateSpotlight;
                        document.getElementById(currentLinkId).innerHTML = '<img src="'+Jobber.jobber_url+'img/icon_spotlight_activate.gif" alt="activate" />';
                        document.getElementById(currentLinkId).id = 'activateSpotlight'+job_id;
                    }
              }
            });
        },

8. Extract the contents of the .zip

The following files should be uploaded from the this zip file.

icon_spotlight_activate.gif -> /img
icon_spotlight_deactivate.gif -> /img
icon-spotlight.png -> /img
page_deactivate_spotlight.php -> /admin
page_activate_spotlight.php -> /admin

Feel free to ask if there's any questions about this modification smile

Last edited by Chronos (2009-02-24 16:48:25)

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Chronos,
That is a post that deserves... a "Thank you."
You hard work and generosity are appreciated.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

spliff_

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Hi,

thanks Chronos for sharing this very nice modification.

but sorry, I have/find some issues with the class.job.php modifications..

1) step 3. in "_includes/classJob.php":
I find this code twice..
code:  $this->mIsActive = $row['is_active']; 
Add new code below which one??

and

2)  in "_includes/classJob.php" I cant`t finde code like this.. (fresh download)
$conditions .= ' AND (type_id = ' . $type_id . ' OR type_id = 3)';
the code exist two times, just without "OR type_id = 3)"

Can anyone help or can anyone upload the modified class.job.php or the whole mod? I'd really appreciate that.

so long..

thx

Chronos

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

spliff_ wrote:

1) step 3. in "_includes/classJob.php":
I find this code twice..
code:  $this->mIsActive = $row['is_active']; 
Add new code below which one??

This appears to be a jobberbase bug (someone correct me if I'm wrong), it should be safe to remove one of those entries. It doesn't really matter under which one you place it though, as long as it's with all the other mVariable = $row=['']; settings.

spliff_ wrote:

2)  in "_includes/classJob.php" I cant`t finde code like this.. (fresh download)
$conditions .= ' AND (type_id = ' . $type_id . ' OR type_id = 3)';
the code exist two times, just without "OR type_id = 3)"

My bad, the "OR type_id = 3)" is a modification I made for my site, I'll adjust the tutorial. I was referring to the first appearence, which is within the public function "GetJobs".

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

An interesting V2 of your idea would be the ability to set the Sponsorship duration inside Admin.
For example...similar to a banner campaign but simplier...
-----------------
For Job ID: ABC123
Start: YY/MM/DD
End: YY/MM/DD
-----------------

Then upon expiration that jobs' 'Sponsored Status' is revoked and the job is delegated to being just another job post. That would make it easy to control 'Premium Services' or 'Fee based' postings.
IMHO....any thoughts?

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

spliff_

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

@Chronos, I thank you!
sorry, but I still have issues in the class.job.php!?!
Can you upload the mod files? Or is it not possible?

@Tokyoj I have seen you are moderator.. Can we reckon with implementation in the next core? I think it would be such a good idea to implemet this in the core!? ..non-disjunction? I think, your V2 spotlight Idea is nice.

Has the "jobberbase" project any roadmap or timetable? What next? Four months have already passed since the last update of jobberbase core. There are so many new "things" from the community. It would be a real pleasure to see a stable (new) version of jobberbase next.

thx

Tokyoj

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Oh but I am a wee humble servant to Monsieur Filip...and for it is he who drinks from the spring of wisdom... other words...I haven't a clue about timetables.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Tokyoj: That's a pretty good idea, I'll work it out in a while.. I'll try to keep it as simple as possible though, since mods like these are pretty hard to combine with core updates. Hope there'll be some sort of modding support later (though there'll most likely always be some hard coded changes needed)

spliff: I made some silly mistakes in the post, check the changes in the class.Job.php again.

- I forgot a "," at the line "'is_spotlight' => $this->mIsSpotlight,"
- I updated the whole "$sql = 'SELECT etc" block of text.

If you're running a completely clean installation of JobberBase you can install the mod package for 1.5 I made (clean as in no or few adjusted files, jobs and pages etc in the database don't matter).

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

spliff_

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

@Chronos  ..awesome job! Thank you very much for this very useful solution. I think you figured out my problem and I will test it. :-) I hope the founder reacted about this. Once and again awesome job. thx for that.

@Tokyoj  ..Pity! :-) ..but I have heard that moderators have a good rapport to the founder!? ;-) Never mind when not but you might have found it easier!? You can ask him. It would help matters, if the community know about the future of jobberbase. Whats your thoughts? I think the "community devs" have it much easier when such things are clarified.

thank you very much to both of you!

so long..

Last edited by spliff_ (2008-12-18 17:42:52)

hailpza

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Hey Chronos - I also went through test, and so far, so good!  Thanks for your work on this feature (and the great tutorial).  I am not a coder, and everything seems to work for me.

putypuruty

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Hi!

Nice job Chronos, keep up the good work wink

I have found a small problem: after logging in, the admin is shown the inactive jobs. If you make a job being sponsored (spotlight) but don't activate the job (so that it's not shown in the public site), if you reload the page you will notice that the 'star' icon is not active (ie: it's not yellow) - this is pretty confusing because you don't know which jobs are sponsored (spotlight).

The fix is very simple: open _includes/class.Job.php and find the following line:

Code:
public function GetBasicInfoAdmin()

Now do another search for:

Code:
return $job;

Replace the following line (this is just above return $job):

Code:
'is_active' => $this->mIsActive);

with

Code:

'is_active' => $this->mIsActive,
'is_spotlight' => $this->mIsSpotlight);

Chronos

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Thanks for the positive replies all smile I'll adjust my post and the mod package to include your fix putypuruty, good find ^^

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

hailpza

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Not sure if anyone else has pointed this out, but I noticed this in step 4.  There's a line of code added that starts with:

<a href="{$BASE_URL}vacature/{$job.id}/

I needed to change the term "vacature" to "job", which is what my table (or maybe folder?) is called.  Not sure what it's called during default install, but that might be something you need to edit to get the spotlight links to work.  So after first updating, my job links were looking like:

/vacature/16/tester-at-gjh/

Once I changed it, they looked like this (and started working):

/job/16/tester-at-gjh/

Chronos

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Ah, I overlooked that one. I replaced the "/job" in the url with "/vacature" to better suit the language of my site. I'll adjust the mod guide right away.

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

evertsemeijn

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

I've noticed that in the backend the spotlight status doesn't change when I activate/ deactive the spotlight function on an ad. In the frontend though the status of the ad doe changes. Am I the only one or did I just missed a step in this mod (or is a small bug)?

[edit]Just found out that I also can't unset the spotlight function from the backend...[/edit]

Last edited by evertsemeijn (2008-12-24 17:50:54)

Member of Jobberbase Development Team - Templates/Usability :: Looking for installation and/or custom design? :: Beautiful Wordpress themes

putypuruty

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Hi!

Look at the comments, I've provided a fix!

evertsemeijn

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Had some strange problem with Dreamweaver. Code on server didn't change after uploading. With Notepad++ I managed to change the code. Thanx anyway!

Member of Jobberbase Development Team - Templates/Usability :: Looking for installation and/or custom design? :: Beautiful Wordpress themes

Tokyoj

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Chronos,
Just curious but do you think the idea of the ability to set the Sponsorship duration inside Admin would be arriving soon? It would be a good way to allow fee-based 'spotlighting'.

For example...similar to a banner campaign but simpler...
-----------------
For Job ID: ABC123
Start: YY/MM/DD
End: YY/MM/DD
-----------------

I can create a screenshot of the Admin Spotlight function if it helps....just PM me at 169spam (at) gmail

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

rutger

Re: Selectable "spotlight" jobs modification (for sponsored jobs etc.)

Wow, thank you very much Chronos! (Bedankt!!)

Last edited by rutger (2009-02-24 15:46:38)