## EasyMod 0.3.0 Compatible
############################################################## 
## MOD Title: Job Modification
## MOD Author: Zarath < null@null.com > ( Jamie ) http://www.zarath.com
## MOD Description: Allows you to create jobs for your users.
## MOD Version: 1.1.2
## 
## Installation Level: Easy
## Installation Time: 5 Minutes 
## Files To Edit: viewtopic.php
##                includes/constants.php
##                includes/functions.php
##                includes/page_header.php
##                language/lang_english/lang_main.php
##                language/lang_english/lang_admin.php
##                templates/subSilver/overall_header.tpl
##                templates/subSilver/viewtopic_body.tpl
## Included Files: jobs.php
##                 admin/admin_jobs.php
## 		   images/icon_jobs.gif
##                 templates/admin/jobs_config_body.tpl
##                 templates/admin/jobs_edit_body.tpl
##                 templates/admin/jobs_user_body.tpl
##                 templates/jobs_body.tpl
##                 templates/jobs_extended_body.tpl
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
############################################################## 
## Author Notes: Second version, it's still fairly simple. Tested,  
##               so it should have no problems. Email me if you find any.
##
##               This mod will work with the points and cash mod as long
##               as your cash_column is named user_points.
##               I do plan to make support for multiple and a choice of 
##               currencies soon.
##
##               Before you email me or post in any forums asking for help 
##               or what something does, PLEASE read the FAQ.
##
##               IF YOU'RE UPGRADING!!!
##		 Just upload the jobs.php and admin_jobs.php file over the 
##		 old ones. Also install the lang files just below this string
##
##		 These are UPDATED lang files. I've added this so you can easily find it with SEARCH. :)
##
############################################################## 
## MOD History:
## v1.0.0  First version.
## v1.0.2  Fixed several bugs, including a requirements bug.
##         Also fixed problems pertaining to people using MySQL 3.x
## v1.1.0  Added a full array of requirements to the modification.
##         Refer to the FAQ for more information.
## v1.1.0b Fixed a couple of minor problems with requirements.
## v1.1.2  EasyMod Compatible
##	   Added support for shop 3.x
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################

#
#-----[ DIY INSTRUCTIONS ]------------------------------------------
#
Make sure you read the FAQ.txt file before you ask for help!

# 
#-----[ COPY ]------------------------------------------ 
# Replace subSilver with your actual theme forum... or do
# it for each theme if you have more than one.
#
copy jobs.php to jobs.php
copy admin/admin_jobs.php to /admin/admin_jobs.php
copy images/icon_jobs.gif to templates/subSilver/images/icon_jobs.gif
copy templates/jobs_body.tpl to /templates/subSilver/jobs_body.tpl
copy templates/jobs_extended_body.tpl to /templates/subSilver/jobs_extended_body.tpl
copy templates/admin/jobs_config_body.tpl to /templates/subSilver/admin/jobs_config_body.tpl
copy templates/admin/jobs_edit_body.tpl to /templates/subSilver/admin/jobs_edit_body.tpl
copy templates/admin/jobs_user_body.tpl to /templates/subSilver/admin/jobs_user_body.tpl

# 
#-----[ SQL ]------------------------------------------ 
#
#   Only do these SQL queries if you can not run the mod_install.php file.
#   Otherwise, please run (go to it in your browswer) that as it's easier.
#
#   If you don't use MySQL, you'll need to edit these queries accordingly
# 
#   If you have a different table prefix then change these commands accordingly. 
#   These currently use the default table prefix. 
#
CREATE TABLE `phpbb_employed` (
  `id` int(10) NOT NULL auto_increment,
  `user_id` int(10) NOT NULL default '0',
  `job_name` varchar(32) NOT NULL default '',
  `job_pay` int(10) NOT NULL default '0',
  `job_length` int(10) NOT NULL default '0',
  `last_paid` int(10) NOT NULL default '0',
  `job_started` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
);

CREATE TABLE `phpbb_jobs` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(32) NOT NULL default '',
  `pay` int(10) default '100',
  `type` varchar(32) default 'public',
  `requires` text,
  `payouttime` int(10) default '500000',
  `positions` int(10) default '0',
  PRIMARY KEY  (`id`),
  KEY `name` (`name`)
);

ALTER TABLE `phpbb_users` ADD `user_jobs` INT (10) DEFAULT '0';

INSERT INTO `phpbb_config` (config_name, config_value) VALUES ('jobs_status', 'off');
INSERT INTO `phpbb_config` (config_name, config_value) VALUES ('jobs_limit', '2');
INSERT INTO `phpbb_config` (config_name, config_value) VALUES ('jobs_pay_type', '0');
INSERT INTO `phpbb_config` (config_name, config_value) VALUES ('jobs_index_body', '0');

# 
#-----[ OPEN ]------------------------------------------ 
# 
 includes/constants.php

# 
#-----[ FIND ]------------------------------------------ 
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
define('JOBS_TABLE', $table_prefix.'jobs');
define('EMPLOYED_TABLE', $table_prefix.'employed');

# 
#-----[ OPEN ]------------------------------------------------ 
# Only do these 3 steps if you haven't done it for any other of 
# my other mods! Duration function...
#

 includes/functions.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
?>

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
if ( !(function_exists(duration)) )
{
	function duration($seconds)
	{
		global $lang;

		if ( $seconds > 86399 )
		{
			$days = floor($seconds / 86400);
			$seconds = ($seconds - ($days * 86400));
			$string .= ( $days > 1 ) ? $days .' ' . $lang['jobs_days'] . ', ' : $days .' ' . $lang['jobs_day'] . ', ';
		}
		if ( $seconds > 3599 )
		{
			$hours = floor($seconds / 3600);

			if ( $seconds != 0 )
			{
				$string .= ( $hours > 1 ) ? $hours .' ' . $lang['jobs_hours'] . ', ' : $hours .' ' . $lang['jobs_hour'] . ', ';
			}

			$seconds = ( $days > 0 ) ? 0 : ( $seconds - ($hours * 3600) );
		}
		if ( $seconds > 59 )
		{
			$minutes = floor($seconds / 60);
			if ( $seconds != 0 )
			{
				$string .= ( $minutes > 1) ? $minutes .' ' . $lang['jobs_minutes'] . ', ' : $minutes .' ' . $lang['jobs_minute'] . ', ';
			}

			$seconds = ( $hours > 0 ) ? 0 : ($seconds - ($minutes * 60));
		}
		if ( $seconds > 0 )
		{
			$string .= ( $seconds > 1 ) ? $seconds . ' ' . $lang['jobs_seconds'] . ', ' : $seconds . ' ' . $lang['jobs_second'] . ', ';
		}

		$string = substr($string, 0, -2);
		return $string;
	}
}

# 
#-----[ OPEN ]------------------------------------------ 
# 
 includes/page_header.php

# 
#-----[ FIND ]------------------------------------------ 
#
//
// The following assigns all _common_ variables that may be used at any point
// in a template.
//
$template->assign_vars(array(

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
if ( ($userdata['user_jobs'] + 7200) < time() )
{
	DEFINE('PAY_ME', true);
	include('jobs.'.$phpEx);
}

# 
#-----[ FIND ]------------------------------------------ 
#
	'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit),

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	'L_JOBS' => $lang['jobs'],

# 
#-----[ FIND ]------------------------------------------ 
#
	'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	'U_JOBS' => append_sid('jobs.'.$phpEx),

# 
#-----[ OPEN ]------------------------------------------ 
# 
viewtopic.php

# 
#-----[ FIND ]------------------------------------------ 
#
	$template->assign_block_vars('postrow', array(

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	$current_user_id = $postrow[$i]['user_id'];

	if (empty($jobs_array[$current_user_id][0]))
	{
		$sql = "SELECT `job_name`
			FROM " . EMPLOYED_TABLE . "
			WHERE user_id = '$current_user_id'";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, $lang['jobs_error_temployed'], '', __LINE__, __FILE__, $sql);
		}
		$sql_count = $db->sql_numrows($result);

		$jobs_array[$current_user_id] = array();
		for ($iv = 0; $iv < $sql_count; $iv++)
		{
			if (!( $row = $db->sql_fetchrow($result) ))
			{
				message_die(GENERAL_ERROR, $lang['jobs_error_temployed'], '', __LINE__, __FILE__, $sql);
			}

			$jobs_array[$current_user_id][] = ucfirst($row['job_name']);
			$var2 = $row['job_name'];
		}

	}
	if (!empty($jobs_array[$current_user_id][0]))
	{
		$jobs = implode(', ', $jobs_array[$current_user_id]);
	}
	else
	{
		$jobs = $lang['jobs_unemployed'];
	}

# 
#-----[ FIND ]------------------------------------------ 
#
		'EDITED_MESSAGE' => $l_edited_by,

#
#-----[ AFTER, ADD ]------------------------------------------ 
#
		'JOBS' => $jobs,
		'L_JOBS' => $lang['jobs'],

# 
#-----[ OPEN ]------------------------------------------ 
#
 language/lang_english/lang_main.php

# 
#-----[ FIND ]------------------------------------------ 
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
// Job Variables
$lang['jobs'] = 'Jobs';
$lang['jobs_unemployed'] = 'Unemployed';
$lang['jobs_current'] = 'Current Jobs';
$lang['jobs_available'] = 'Available Jobs';
$lang['jobs_youre_unemployed'] = 'You are currently Unemployed.';
$lang['jobs_cant_be_employed'] = 'You cannot currently be employed.';
$lang['jobs_not_employed'] = 'You cannot quit a job you are not employed in!';
$lang['jobs_quit'] = 'You have quit your job as a %s!';
$lang['jobs_now_employed'] = 'You are now employed as a %s!';
$lang['jobs_already_employed'] = 'You are already employed in this job!';
$lang['job_requires'] = 'This job requires %s.';
$lang['jobs_item'] = 'Item';
$lang['jobs_no_positions'] = 'There are currently no positions in that job available!';
$lang['jobs_not_public'] = 'That job is not available to the public!';
$lang['jobs_not_exist'] = 'That job does not exist!';
$lang['jobs_information'] = 'Job Information';
$lang['jobs_job'] = 'Job';
$lang['jobs_pay'] = 'Pay';
$lang['jobs_pay_length'] = 'Pay Length';
$lang['jobs_started'] = 'Started';
$lang['jobs_last_paid'] = 'Last Paid';
$lang['jobs_postions'] = 'Positions Left';
$lang['jobs_remaining_positions'] = 'Remaining Job Positions';
$lang['jobs_taken_positions'] = 'Taken Job Positions';
$lang['jobs_total_employed'] = 'Total Employed';
$lang['jobs_total_positions'] = 'Total Job Positions';
$lang['jobs_total_jobs'] = 'Total Jobs';
$lang['jobs_too_many'] = 'You are already employed in too many jobs!';
$lang['jobs_positions'] = 'Positions';
$lang['jobs_second'] = 'Second';
$lang['jobs_seconds'] = 'Seconds';
$lang['jobs_minute'] = 'Minute';
$lang['jobs_minutes'] = 'Minutes';
$lang['jobs_hour'] = 'Hour';
$lang['jobs_hours'] = 'Hours';
$lang['jobs_day'] = 'Day';
$lang['jobs_days'] = 'Days';

// Job Buttons
$lang['jobs_button_accept'] = 'Accept';
$lang['jobs_button_quit'] = 'Quit!';

// Job Error Variables
$lang['jobs_error_updating'] = 'Error updating %s table!';
$lang['jobs_error_deleting'] = 'Error deleting from %s table!';
$lang['jobs_error_selecting'] = 'Error getting information from %s table!';
$lang['jobs_error_inserting'] = 'Error inserting into %s table!';
$lang['jobs_error_variable'] = 'Could not read %s variable!';

//
// These are UPDATED lang files. I've added this so you can easily find it with SEARCH. :)
// Ignore these comments if this is your first install, but make sure you include them all!
//
$lang['jobs_requires_admin'] = 'You must be an administrator to accept this job!';
$lang['jobs_requires_mod'] = 'You must be a moderator to accept this job!';
$lang['jobs_requires_male'] = 'You must be male to accept this job!';
$lang['jobs_requires_female'] = 'You must be female to accept this job!';
$lang['jobs_requires_nmale'] = 'You must not be male to accept this job!';
$lang['jobs_requires_nfemale'] = 'You must not be female to accept this job!';
$lang['jobs_requires_gil'] = 'You must have %s %s to accept this job!';
$lang['jobs_requires_ngil'] = 'You must not have %s %s to accept this job!';
$lang['jobs_requires_mgil'] = 'You must have more than %s %s to accept this job!';
$lang['jobs_requires_lgil'] = 'You must have less than %s %s to accept this job!';
$lang['jobs_requires_posts'] = 'You must have %s posts to accept this job!';
$lang['jobs_requires_nposts'] = 'You must not have %s posts to accept this job!';
$lang['jobs_requires_mposts'] = 'You must have more than %s posts to accept this job!';
$lang['jobs_requires_lposts'] = 'You must have less than %s posts to accept this job!';
$lang['jobs_requires_item'] = 'You must have a %s in your inventory to accept this job!';
$lang['jobs_requires_nitem'] = 'You must not have %s in your inventory posts to accept this job!';

# 
#-----[ OPEN ]------------------------------------------ 
#
language/lang_english/lang_admin.php

# 
#-----[ FIND ]------------------------------------------ 
#
?>

#
#-----[ BEFORE, ADD ]------------------------------------------ 
#
// Job Variables
$lang['jobs_modify_settings'] = 'Modify Jobs Settings';
$lang['jobs_edit_jobs'] = 'Edit User\'s Jobs';
$lang['jobs_edit_jobs_settings'] = 'Edit Job Settings';
$lang['jobs_create_new'] = 'Create New Job';
$lang['jobs_editor'] = 'Jobs Editor';
$lang['jobs_edit_user'] = 'Edit User';
$lang['jobs_edit_job'] = 'Edit Job';
$lang['jobs_dont_have'] = 'They don\'t have that job!';
$lang['jobs_no_action'] = 'No action selected!';
$lang['jobs_already_exists'] = 'That job already exists!';
$lang['jobs_already_has_one'] = 'They already have that job!';
$lang['jobs_status'] = 'Job Status';
$lang['jobs_job_name'] = 'Job Name';
$lang['jobs_job_positions'] = 'Max Positions';
$lang['jobs_job_type'] = 'Job Type';
$lang['jobs_job_pay'] = 'Job Pay';
$lang['jobs_job_time'] = 'Job Length';
$lang['jobs_job_requirements'] = 'Requirements';
$lang['jobs_private'] = 'Private';
$lang['jobs_public'] = 'Public';
$lang['jobs_pay_out_type'] = 'Payout Type';
$lang['jobs_on'] = 'On';
$lang['jobs_off'] = 'Off';
$lang['jobs_max_pp'] = 'Max Jobs Per Person';
$lang['jobs_pay_pp'] = 'Pay Person';
$lang['jobs_pay_all'] = 'Pay All';
$lang['jobs_extended'] = 'Extended';
$lang['jobs_compact'] = 'Compact';
$lang['jobs_index'] = 'Index Display';
$lang['jobs_second'] = 'Second';
$lang['jobs_seconds'] = 'Seconds';
$lang['jobs_minute'] = 'Minute';
$lang['jobs_minutes'] = 'Minutes';
$lang['jobs_hour'] = 'Hour';
$lang['jobs_hours'] = 'Hours';
$lang['jobs_day'] = 'Day';
$lang['jobs_days'] = 'Days';

$lang['jobs_explain_main'] = 'Within this section, you may edit the Jobs settings, add new jobs, edit old jobs and edit the jobs people are currently employed in.';
$lang['jobs_explain_user'] = 'This section allows you to edit the jobs a user is currently employed in.';
$lang['jobs_explain_jobs'] = 'This section allows you to edit specific job information, such as amount paid, length, max positions and so on.';

$lang['jobs_global_updated'] = 'Job Settings sucessfully updated!';
$lang['jobs_updated'] = 'Job sucessfully updated!';
$lang['jobs_deleted'] = 'All workers fired and job successfully deleted!';
$lang['jobs_invalid_name'] = 'Invalid Name!';
$lang['jobs_created'] = 'Job Sucessfully Created!';
$lang['jobs_user_updated'] = 'User Successfully Updated!';

$lang['jobs_main_link'] = 'Click %sHere%s to return to main Jobs Settings.';

//buttons
$lang['jobs_button_update'] = 'Update';
$lang['jobs_button_edit'] = 'Edit Jobs';
$lang['jobs_button_find'] = 'Find Username';
$lang['jobs_button_job'] = 'Create Job';
$lang['jobs_button_add'] = 'Add Job';
$lang['jobs_button_fire'] = 'Fire from job!';
$lang['jobs_button_update_job'] = 'Update Job';
$lang['jobs_button_delete_job'] = 'Delete Job';

// Job Error Variables
$lang['jobs_error_updating'] = 'Error updating %s table!';
$lang['jobs_error_deleting'] = 'Error deleting from %s table!';
$lang['jobs_error_selecting'] = 'Error getting information from %s table!';
$lang['jobs_error_inserting'] = 'Error inserting into %s table!';
$lang['jobs_error_variable'] = 'Could not read %s variable!';
$lang['jobs_invalid_action'] = 'Invalid Action!';

# 
#-----[ OPEN ]------------------------------------------ 
# 
 templates/subSilver/overall_header.tpl

# 
#-----[ FIND ]------------------------------------------ 
#
# If you use another template besides subSilver, you will need
# to place this anywhere around the main menu listing. Do NOT 
# ask me for help through emails for this, please.
#
&nbsp; &nbsp;<a href="{U_MEMBERLIST}" class="mainmenu">

#
#-----[ AFTER, ADD ]------------------------------------------ 
#
&nbsp; &nbsp;<a href="{U_JOBS}" class="mainmenu"><img src="templates/subSilver/images/icon_jobs.gif" width="12" height="13" border="0" alt="{L_JOBS}" hspace="3" />{L_JOBS}</a>

# 
#-----[ OPEN ]------------------------------------------ 
# 
 templates/subSilver/viewtopic_body.tpl

#
#-----[ FIND ]------------------------------------------
#
		<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}<br />{postrow.CASH}</span><br /></td>

#
#-----[ IN-LINE FIND ]------------------------------------------
#
{postrow.POSTER_FROM}

#
#-----[ AFTER, ADD ]------------------------------------------ 
#
<br />{L_JOBS}: {postrow.JOBS}

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 