The core-base folder, at the same level as jobsearch folder, includes classes and css that are available to any application.
echo("<!-- reading core-base/configure.php -->\n");
require_once $base_url.'/core-base/db_utilities.php';
require_once $base_url.'/core-base/date_utilities.php';
require_once $base_url.'/core-base/html_utilities.php';
echo("<!-- reading core-base/db_utilties.php -->\n");
$link = mysql_connect('localhost', 'mdhoerr_webuser', 'webuser');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
function do_sql($p_sql, $p_calledfrom, $p_insert){
if(!$p_calledfrom){
$p_calledfrom = 'not specified';
}
if(!$p_insert){
$p_insert = 'N';
}
$result = mysql_query($p_sql);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query."\n";
$message .= 'Called from '.$p_calledfrom."\n";
die($message);
} elseif ($p_insert != 'N'){
$lastid = mysql_insert_id();
if (!$lastid) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query."\n";
$message .= "Problem getting id from insert\n";
die($message);
}
return $lastid;
} else {
return $result;
}
}
echo("<!-- reading core-base/html_utilities -->\n");
function db2html($p_string){
$html_string = stripslashes($p_string);
$html_string = htmlspecialchars($html_string);
$html_string = nl2br($html_string);
return $html_string;
}
function get_val($p_fieldname, $p_default){
if(!$p_default){
$p_default = '0';
}
if(!$p_fieldname){
$value = $p_default;
} else {
$value = $_REQUEST[$p_fieldname];
}
return $value;
}
echo("<!-- reading core-base/date_utilties.php -->\n");
function getmonth($p_integer){
if(!$p_integer){
$p_integer = '1';
}
switch ($p_integer) {
case '1':
$month = "January";
break;
case '2':
$month = "February";
break;
case '3':
$month = "March";
break;
case '4':
$month = "April";
break;
case '5':
$month = "May";
break;
case '6':
$month = "June";
break;
case '7':
$month = "July";
break;
case '8':
$month = "August";
break;
case '9':
$month = "September";
break;
case '10':
$month = "October";
break;
case '11':
$month = "November";
break;
case '12':
$month = "December";
break;
default:
$month = date('F',getdate());
}
return $month;
}
echo("<!-- reading js_config.php file -->\n");
$base_url = '/home/mdhoerr/public_html';
require_once $base_url.'/core-base/configure.php';
do_sql('USE mdhoerr_jobsearch', 'js_config.php file', 'N');
echo("<!-- CONNECTED SUCCESSFULLY AND SWITCHED TO DB mdhoerr_jobsearch -->\n");
require_once 'js_utilities.php';
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<!-- reading js_header.php -->
<link rel="shortcut icon" href="/jobsearch/core/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="description" content="Work history application demonstrating a simple MVC LAMP application." />
<meta name="author" content="Mary Hoerr" />
<!-- this will be where the print stylesheet goes -->
<link
rel="stylesheet"
type="text/css"
href="/jobsearch/core/js_print.css"
media="print"
/>
<title>Job Search Application
<!-- Netscape 3 and earlier and IE 2 and earlier do not recognize stylesheets -->
<!-- this is the default stylesheet. It is based on the w3c default stylesheet -->
<link
rel="stylesheet"
type="text/css"
href="/jobsearch/core/js_main.css"
media="all"
/>
<!-- the primary stylesheet is imported, to avoid giving it to IE 3 and Netscape 4 -->
<!-- which have problems with all but the most basic styles -->
<style type="text/css">
@import url(/jobsearch/core/js_import.css);
<!--[if IE] -->
@import url(/jobsearch/core/js_import_ie.css);
<!--[endif] -->
</style>
<?php
require_once 'js_config.php';
$app_name = "Job Search";
$altstyle = $_REQUEST['altstyle'];
if ($altstyle){
switch($altstyle){
case "Y":
$alturl = "/jobsearch/core/js_alt_joblist_ie.css";
break;
case "1":
default:
$alturl = "/jobsearch/core/js_alt1.css";
}
?>
<style type="text/css">
@import url();
</style>
<?php
}
?>
</head>
echo("<!-- reading js_utilties.php -->\n");
class jobs{
## define members ##
public $jobid = 0;
public $jobtitle = '';
public $orgid = 0;
public $startmonth = 0;
public $startyear = 0;
public $endmonth = 0;
public $endyear = 0;
public $responsibilities = '';
## define methods ##
//SELECT JOB
function selectjob($p_calledfrom){
if(!$p_calledfrom){
$p_calledfrom = "not supplied";
}
$sql = "SELECT * from jobs where jobid = '%s'";
$sql = sprintf($sql,
mysql_real_escape_string($this->jobid)
);
$p_calledfrom .= " and the sql query is: ".$sql;
$result = do_sql($sql, $p_calledfrom,'N');
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
foreach($row as $key=>$val){
$this->$key = $val;
}
}
mysql_free_result($result);
return $this;
}
// UPDATE JOB
function updatejob($p_calledfrom){
if(!$p_calledfrom){
$p_calledfrom = "not supplied";
}
$sql = "UPDATE jobs SET ";
$sql.= "jobtitle = '%s', ";
$sql.= "orgid = '%s', ";
$sql.= "startmonth = '%s', ";
$sql.= "startyear = '%s', ";
$sql.= "endmonth = '%s', ";
$sql.= "endyear = '%s', ";
$sql.= "responsibilities = '%s' ";
$sql.= "WHERE jobid = '%s'";
$sql = sprintf($sql,
mysql_real_escape_string($this->jobtitle),
mysql_real_escape_string($this->orgid),
mysql_real_escape_string($this->startmonth),
mysql_real_escape_string($this->startyear),
mysql_real_escape_string($this->endmonth),
mysql_real_escape_string($this->endyear),
mysql_real_escape_string($this->responsibilities),
mysql_real_escape_string($this->jobid)
);
echo("\n");
$p_calledfrom .= " and sql query is: ".$sql;
$result = do_sql($sql, $p_calledfrom,'N');
// print_r($job);
return '0';
}
// INSERT JOB
function insertjob($p_calledfrom){
if(!$p_calledfrom){
$p_calledfrom = "not supplied";
}
$sql = "INSERT into jobs (";
$sql.= "jobtitle, orgid, startmonth, startyear, endmonth, endyear,
responsibilities";
$sql.= ") VALUES (";
$sql.= "'%s', '%s', '%s', '%s', '%s', '%s', '%s'";
$sql.= ")";
$sql = sprintf($sql,
mysql_real_escape_string($this->jobtitle),
mysql_real_escape_string($this->orgid),
mysql_real_escape_string($this->startmonth),
mysql_real_escape_string($this->startyear),
mysql_real_escape_string($this->endmonth),
mysql_real_escape_string($this->endyear),
mysql_real_escape_string($this->responsibilities)
);
$p_calledfrom .= " and the sql query is: ".$sql;
$lastid = do_sql($sql, $p_calledfrom, 'Y');
return $lastid;
}
}
function joblist($p_fieldname, $p_comparison, $p_value){
if(!$p_fieldname){
$p_fieldname = 'jobtitle';
}
if(!p_comparison){
$p_comparison = ' LIKE ';
}
echo("");
if(!$p_value && $p_value != '0'){
$p_value = '%*%';
}
$sql = "SELECT * from jobs WHERE ";
$sql.= $p_fieldname.$p_comparison."'%s'";
$sql = sprintf($sql,
mysql_real_escape_string($p_value)
);
echo("");
$calledfrom = "joblist function with fieldname = ".$p_fieldname." and comparison = ".$p_comparison." and value = ".$p_value." with sql query: ".$sql;
$result = do_sql($sql, $calledfrom,'N');
$ids = array('0');
if (mysql_num_rows($result) > 0) {
for($i=0; $i
<!-- begin menu include -->
<ul class="go">
<li class="separator">places to go</li>
<li class="index"><a href="/jobsearch/js_index.php">home</a></li>
<li class="about"><a href="/jobsearch/js_about.php">about</a></li>
<li class="joblist"><a href="/jobsearch/js_joblist.php">job list</a></li>
<ul>
<ul class="do">
<li class="separator">things to do</li>
<li class="add"><a href="/jobsearch/js_job.php?jobid=0&action=select">add
job</a></li>
<li class="modify"><a href="/jobsearch/js_job.php?jobid=<?php
echo($jobid);?>&action=select">modify job</a></li>
<li class="view"><a href="/jobsearch/js_job.php?jobid=<?php
echo($jobid);?>">view job</a></li>
</ul>
<!-- end menu include -->
<?php
require_once 'core/js_header.php';
?>
<!-- opening html tag and head tag section are in core/js_header.php -->
<body id="jobsearch_home">
<?php
include ("js_menu.php");
?>
<?php
require_once 'core/js_header.php';
?>
<!-- opening html tag and head tag section are in core/js_header.php -->
<body id="jobsearch_about">
<?php
include ("js_menu.php");
?>
<?php
require_once 'core/js_header.php';
$sortby = $_REQUEST['sortby'];
if(!$sortby){
$sortby = "jobid";
}
$order = $_REQUEST['order'];
if(!$order){
$order = "asc";
} elseif ($order ="asc"){
$order = "desc";
} else {
$order = "asc";
}
$joblist = joblist('jobid',' > ','0');
if($altstyle){ // toggle alternate style on and off
$alt_url = 'js_joblist.php';
} else {
$alt_url = 'js_joblist.php?altstyle=Y';
}
?>
<!-- opening html tag and head tag section are in core/js_header.php -->
<body id="">
<?php
include ("js_menu.php");
?>
<h1>Job Search Application</h1>
<h2>Job List</h2>
<p><a href="<?php echo($alt_url);?>">switch style sheet</a>: Demonstrates
changing the column order by changing only the stylesheet.</p>
<p>Take a look at the style sheet: <a href="core/js_import.css">
style sheet</a></p>
<p class="colhead">
<span class="jobtitle">job title</span>
<span class="orgid">organization</span>
<span class="start">start date</span>
<span class="end">end date</span>
</p>
<?php
foreach($joblist as $val){
?>
<?php
$job_row = new jobs;
$job_row->jobid = $val;
$job_row = $job_row->selectjob('joblist.php');
$jobtitle = db2html($job_row->jobtitle);
$start = getmonth($job_row->startmonth);
$start.= " ".$job_row->startyear;
$end = getmonth($job_row->endmonth);
$end.= " ".$job_row->endyear;
$responsibilities = db2html($job_row->responsibilities);
?>
<p id="<?php echo('job'.$job_row->jobid);?>" class="job_row">
<span class="jobtitle">
<a href="/jobsearch/js_job.php?jobid=<?php echo($job_row->jobid);?>">
<?php echo($jobtitle);?></a></span>
<span class="orgid"><?php echo($job_row->orgid);?></span>
<span class="start"> <?php echo($start);?> </span>
<span class="end"> <?php echo($end);?> </span>
<span class="responsibilities"> <?php echo($responsibilities);?> </span>
</p>
<?php
}
?>
</body>
</html>
<?php
require_once 'core/js_header.php';
$joblist = joblist('jobid',' > ','0');
?>
<!-- opening html tag and head tag section are in core/js_header.php -->
<body id = "dhtml_sort">
<?php
include ("js_menu.php");
?>
<h1>Job Search Application</h1>
<h2>OOP Javascript sort</h2>
<p>Using an external class file written by Chirp Internet www.chirp.com.au:
<a href="/core-base/bubblesort.js">bubblesort.js</a>, I instantiate a bubblesort object and then call
it from a column heading link. It only sorts ascending right now. Link to code showing how I did this:
<a href="/jobsearch/js_code.php#jobsort">bubblesort implementation</a></p>
<p class="colhead">
<span class="jobtitle">
<a href="javascript:sortTable.sort(0, false, 'a')">job title</a></span>
<span class="orgid">
<a href="javascript:sortTable.sort(1, false)">organization</a></span>
<span class="start">
<a href="javascript:sortTable.sort(2, false)">start date</a></span>
<span class="end">
<a href="javascript:sortTable.sort(3, false)">end date</a></span>
</p>
<ul id="sortable_list">
<?php
foreach($joblist as $val){
$job_row = new jobs;
$job_row->jobid = $val;
$job_row = $job_row->selectjob('jobsort.php');
$jobtitle = db2html($job_row->jobtitle);
$start = getmonth($job_row->startmonth);
$start.= " ".$job_row->startyear;
$end = getmonth($job_row->endmonth);
$end.= " ".$job_row->endyear;
$responsibilities = db2html($job_row->responsibilities);
?>
<li id="<?php echo('job'.$job_row->jobid);?>" class="job_row">
<p class="jobtitle">
<a href="/jobsearch/js_job.php?jobid=<?php echo($job_row->jobid);?>">
<?php echo($jobtitle);?></a></p>
<p class="orgid"><?php echo($job_row->orgid);?></p>
<p class="start"> <?php echo($start);?> </p>
<p class="end"> <?php echo($end);?> </p>
<p class="responsibilities"> <?php echo($responsibilities);?> </p>
</li><!-- end li class = job_row -->
<?php
}
?>
</ul>
<script type="text/javascript">
var dataTable = document.getElementById("sortable_list");
var sortTable = new bubbleSort(dataTable, "LI", "P");
</script>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</body>
</html>
<?php
require_once 'core/js_header.php';
$jobid = $_REQUEST['jobid'];
if(!$jobid){
$jobid = 0;
}
$action = $_REQUEST['action'];
if(!$action){
$action = "view";
}
switch($action) {
case 'select':
if($jobid == '0') {
$bodyid = 'blank_form';
$bodytitle = "add new job";
} else {
$bodyid = 'prefilled_form';
$bodytitle = "modify this job";
}
break;
case 'view':
default:
$bodyid = 'read_only';
$bodytitle = "read only";
}
?>
<!-- opening html tag and head tag section are in core/js_header.php -->
<body id="<?php echo($bodyid);?>">
<?php
include ("js_menu.php");
$job = new jobs;
$job->jobid = $jobid;
$job->jobtitle = $_REQUEST['jobtitle'];
$job->orgid = $_REQUEST['orgid'];
$job->startmonth = $_REQUEST['startmonth'];
$job->startyear = $_REQUEST['startyear'];
$job->endmonth = $_REQUEST['endmonth'];
$job->endyear = $_REQUEST['endyear'];
$job->responsibilities = $_REQUEST['responsibilities'];
switch($action){
case 'add':
$callingfrom = "js_job.php, switch action, insert";
$newjobid = $job->insertjob($callingfrom);
$url = "js_job.php?jobid=".$newjobid."&action=select";
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
break;
case 'modify':
$callingfrom = "js_job.php, switch action, update";
$job->updatejob($callingfrom);
$url = "js_job.php?jobid=".$jobid."&action=select";
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
break;
case 'select':
case 'view':
default:
$callingfrom = "js_job.php, switch action, select";
$selectjob = $job->selectjob($callingfrom);
}
?>
<h1>Job Search Application</h1>
<h2>Job Information</h2>
<h3>Job <?php echo($job->jobid);?>: <?php echo($job->jobtitle);?> [<?php
echo($bodytitle);?>]</h3>
<form id ="edit_job" action="js_job.php" method="post">
<ul>
<li><input type="hidden" name="jobid" id="jobid" value="<?php echo($job->jobid);?>" />
<span class="fieldname"> Job title:</span>
<span class="fieldvalue"> <?php echo(db2html($job->jobtitle));?> </span>
<span class="fieldinput">
<input name="jobtitle" id="jobtitle" class="jobs"
type="text" size="35"
value="<?php echo(stripslashes($job->jobtitle));?>" />
</span>
</li>
<li>
<span class="fieldname"> Organization id:</span>
<span class="fieldvalue"> <?php echo($job->orgid);?> </span>
<span class="fieldinput">
<input name="orgid" id="orgid" class="jobs"
type="text" size="35"
value="<?php echo($job->orgid);?>" />
</span>
</li>
<li>
<span class="fieldname"> Start month/year:</span>
<span class="fieldvalue"> <?php echo(getmonth($job->startmonth));?>,
<?php echo($job->startyear);?> </span>
<span class="fieldinput">
<input name="startmonth" id="startmonth" class="jobs"
type="text" size="15"
value="<?php echo($job->startmonth);?>" />
<input name="startyear" id="startyear" class="jobs"
type="text" size="5"
value="<?php echo($job->startyear);?>" />
</span>
</li>
<li>
<span class="fieldname"> End month/year:</span>
<span class="fieldvalue"> <?php echo(getmonth($job->endmonth));?>,
<?php echo($job->endyear);?> </span>
<span class="fieldinput">
<input name="endmonth" id="endmonth" class="jobs"
type="text" size="15"
value="<?php echo($job->endmonth);?>" />
<input name="endyear" id="endyear" class="jobs"
type="text" size="5"
value="<?php echo($job->endyear);?>" />
</span>
</li>
<li>
<span class="fieldname"> Responsibilities: </span>
<span class="fieldvalue"> <?php echo(db2html($job->responsibilities));?> </span>
<span class="fieldinput">
<textarea name="responsibilities" class="jobs" cols="40" rows="10"><?php
echo(stripslashes($job->responsibilities));?></textarea>
</span>
</li>
</ul>
<div class="insert_button"> <input id="insert_job" name="action" type="submit"
value="add" /> </div>
<div class="update_button"> <input id="update_job" name="action" type="submit"
value="modify" /> </div>
</form>
</body>
</html>