/home/mip/public_html_/old-website/employer/sqladd.php
<?php
session_start();
require_once("common_msg.inc");
require_once("func_all.php");
$db = db_connect();
switch($what){
case 'newjoborder':
$dateneed1 = array("1","8","15","22","29","36","43","50","57","64");
$dateneed2 = array("2","9","16","23","30","37","44","51","58","65");
$dateneed3 = array("3","10","17","24","31","38","45","52","59","66");
$position = array("4","11","18","25","32","39","46","53","60","67");
$noworker = array("5","12","19","26","33","40","47","54","61","68");
$worksite = array("6","13","20","27","34","41","48","55","62","69");
$jobreq = array("7","14","21","28","35","42","49","56","63","70");
$tablestart = "<html><head><title>IRIS EMPLOYER'S NEW JOB ORDER</title><style type='text/css'>";
$tablestart .=".box {BACKGROUND-COLOR: #FFFFFF; BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; COLOR: black; FONT-FAMILY: verdana; FONT-SIZE: 11px; TEXT-DECORATION: none}";
$tablestart .=".box1 {BACKGROUND-COLOR: #FFFFFF; BORDER-BOTTOM: #cccccc 0px solid; BORDER-LEFT: #cccccc 0px solid; BORDER-RIGHT: #cccccc 0px solid; BORDER-TOP: #cccccc 0px solid; COLOR: black; FONT-FAMILY: verdana; FONT-SIZE: 13px; TEXT-DECORATION: none}";
$tablestart .="</style></head><body>";
$tablestart .="<span class='box1'>Mam/Sir,</span>";
$tablestart .="<br><span class='box1'>Here's a list of job order(s) request.</span><br><br>";
$tablestart .= '<table width="100%" cellpadding="3" cellspacing="3"><tr><td class="box">';
$fields = explode("QXQX",$mymesage);
for($i=1;$i<=$counter;$i++) {
$subtable .= '<hr>';
for($x=0;$x<=count($fields);$x++) {
if(substr($fields[$x],0,1)==$i) {
//echo nl2br(substr($fields[$x],1))."<br>";
if(in_array($x,$dateneed1)) {
$month = nl2br(substr($fields[$x],1));
}
if(in_array($x,$dateneed2)) {
$day = nl2br(substr($fields[$x],1));
}
if(in_array($x,$dateneed3)) {
$year = nl2br(substr($fields[$x],1));
}
if(in_array($x,$position)) {
$myposition = nl2br(substr($fields[$x],1));
}
if(in_array($x,$noworker)) {
$mynoworker = nl2br(substr($fields[$x],1));
}
if(in_array($x,$worksite)) {
$myworksite = nl2br(substr($fields[$x],1));
}
if(in_array($x,$jobreq)) {
$myjobreq = nl2br(substr($fields[$x],1));
}
}
}
if($year && $month && $day) {
$date = $year."-".$month."-".$day;
}
$subtable .= '<table width="100%" border="0" class="box">
<tr><td width="15%"><b>Date Needed:</b></td><td>'.dateformat($date).'</td></tr>
<tr><td><b>Position:</b></td><td>'.$myposition.'</td></tr>
<tr><td><b>Number of workers:</b></td><td>'.$mynoworker.'</td></tr>
<tr><td><b>Worksite:</b></td><td>'.$myworksite.'</td></tr>
<tr><td valign="top"><b>Job Requirement:</b></td><td>'.$myjobreq.'</td></tr>
</table>';
}
$tableend = '</td></tr></table></body></html>';
$message = $tablestart.$subtable."<hr>".$tableend;
$company =getdata("SELECT * FROM company");
$employer=getdata_one("*","principals","principal_id",$myprincipalid);
$from = $employer["email"]; //"IRIS - EMPLOYER'S NEW JOB ORDER"; //$employer["email"];
$fromhead = $employer["name"];
$to = $company[1][agency_email];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: IRIS EMPLOYER'S NEW JOB ORDER\r\n";
$subject = "NEW JOB ORDER for $fromhead";
if(mail($to, $subject, $message, $headers)) {
$msg = "A message will be sent to inform ".$company[1][agency_name]." that you have new job order.";
} else {
$msg = "Error Sending Email. Please Try Again";
}
/*
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = $smtphost; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $smtpusername; // SMTP username
$mail->Password = $smtpassword; // SMTP password
$mail->FromName = $fromhead;
$mail->From = $from;
$emails = explode(";",$to);
for($xx = 0; $xx < count($emails); $xx++){
if($emails[$xx]) {
$mail->AddAddress($emails[$xx]);
}
}
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
$messagefinal = $message;
$mail->MsgHTML(stripslashes($messagefinal));
if($mail->Send()){
}*/
header("Location: new_joborder.php?msg=$msg");
break;
case 'officers':
$sql = "INSERT INTO company_officers(name,designation) VALUES('$name','$designation')";
$result = mysql_query($sql);
echo mysql_error();
header("Location: edit_configuration.php?msg=Officer Added");
break;
case 'user':
check_full("users",$max_users);
$duplicate = getdata("select * from users where username='$username'");
if(!empty($duplicate)) error_message('There is already an existing username like the one you entered.');
if($password1!=$password2) error_message('Passwords entered were not the same.');
else if((strlen($password1)<3) || (strlen($password1)>16)) error_message('Password must be between 3 and 16 characters. Try again.');
$sql = "INSERT INTO users(username,password,name,access_id)
VALUES ('$username',password('$password1'),'$name','$access_id')";
$result = mysql_query($sql);
header("Location: manage_user.php");
break;
case 'applicant_status':
$duplicate = get_count("applicant_status","status","$status");
if(!empty($duplicate)) error_message('The applicant status you entered is already existing.');
$sql = "INSERT INTO applicant_status(status,orderid)
VALUES ('".ucwords(trim($status))."',$orderid)";
$result = mysql_query($sql);
header("Location: manage_applicant_status.php");
break;
case 'country': $duplicate = getdata("select * from country where name='$country'");
if(!empty($duplicate)) error_message('There is already an existing country like the one you entered.');
$sql = "INSERT INTO country(name) VALUES ('$country')";
$result = mysql_query($sql);
header("Location: manage_country.php");
break;
case 'broker': $duplicate = getdata("select * from brokers where name='$name' and country_id='$country_id'");
if(!empty($duplicate)) error_message('There is already an existing broker like the one you entered.');
$acc_date = "$year-$month-$day";
$sql = "INSERT INTO brokers(name,address,fax,telephone,
contact_person,contact_position,acc_no,acc_date,
country_id,RO)
VALUES ('$name','$address','$fax','$telephone',
'$contact_person','$contact_position','$acc_no','$acc_date',
'$country_id','$RO')";
$result = mysql_query($sql);
header("Location: manage_broker.php");
break;
case 'principal':
$duplicate = getdata("select * from principals where principal_name='$principal_name'");
if(!empty($duplicate)) error_message('There is already an existing principal like the one you entered.');
if(!$price&&!$price2&&!$pay_type){
$price=0;$price2=0;$pay_type="R";
}
$acc_date = "$year-$month-$day";
$sql = "INSERT INTO principals(principal_name,
address,
fax,
telephone,
email,
contact_person,
contact_position,
acc_no,
acc_date,
country_id,
city,
RO,
broker_id,
username,
password)
VALUES('$principal_name',
'$address',
'$fax',
'$telephone',
'$email',
'$contact_person',
'$contact_position',
'$acc_no',
'$acc_date',
'$country_id',
'$city',
'$RO',
'$broker_id',
'$username',
'$password')";
$result = mysql_query($sql);
header("Location: manage_principal.php");
break;
case 'position':
check_full("positions",$max_positions);
$duplicate = getdata("select * from positions where name='$position'");
if(!empty($duplicate)) error_message('There is already an existing position like the one you entered.');
$sql = "INSERT INTO positions(name) VALUES ('$position')";
$result = mysql_query($sql);
header("Location: manage_position.php");
break;
case 'clinic':
$duplicate = getdata("select * from clinics where name='$name' and address='$address'");
if(!empty($duplicate)) error_message('There is already an existing clinic like the one you entered.');
if(!$phase1&&!$phase2&&!$phase3&&!$phase4){
$phase1=0;$phase2=0;$phase3=0;$phase4=0;
}
$sql = "INSERT INTO clinics(name,address,telephone,contact,remarks)
VALUES ('$name','$address','$telephone','$contact','$remarks')";
$result = mysql_query($sql);
header("Location: manage_clinic.php");
break;
case 'training_center':
$duplicate = getdata("select * from training_center where name='$name' and address='$address'");
if(!empty($duplicate)) error_message('There is already an existing Training Center like the one you entered.');
$sql = "INSERT INTO training_center(name,address,telephone,contact,remarks)
VALUES ('$name','$address','$telephone','$contact','$remarks')";
$result = mysql_query($sql);
header("Location: manage_training_center.php");
break;
case 'personal':
$apply_date = "$applied_year-$applied_month-$applied_day";
$birthdate = "$bday_year-$bday_month-$bday_day";
$lname=ucfirst($lastname);
$fname=ucfirst($firstname);
$mname=ucfirst($mname);
$duplicate = getdata("select * from personal
where lname='$lname' and
fname='$fname' and
mname='$mname'");
if(!empty($duplicate)) error_message('There is already an existing applicant like the one you entered.');
// get the applicant id
$applicant_id=get_applicant_id();
if ($picture){
$id = mysql_insert_id();
$type = basename($picture_type);
switch($type){
case "png" : $pic_name = "pngImage/$applicant_id.png";
$filename = $pic_dir.$pic_name;
copy ($picture, $filename);
break;
case "jpeg" :
case "pjpeg" : $pic_name = "jpegImage/$applicant_id.jpg";
$filename = $pic_dir.$pic_name;
copy ($picture, $filename);
break;
case "gif" : $pic_name = "gifImage/$applicant_id.gif";
$filename = $pic_dir.$pic_name;
copy ($picture, $filename);
break;
default : error_message("Invalid picture format:$type");
}// switch
}// end of if there is a picture
if(!$agentid)$agentid=0;
$sql = "INSERT INTO personal(applicant_id,
apply_date,
fname,
mname,
lname,
address1,
perm_no,
perm_st,
perm_city,
perm_prov,
perm_zip,
office_phone,
home_phone,
cellphone,
birthdate,
birthplace,
sex,
height1,
height2,
weight1,
weight2,
civil_status,
religion,
nationality,
position_id1,
position_id2,
position1_yrsofexp,
position1_mosofexp,
position2_yrsofexp,
position2_mosofexp,
country_id,
status,
picture,
remarks)
VALUES ('$applicant_id',
'$apply_date',
'$fname',
'$mname',
'$lname',
'$address1',
'$perm_no',
'$perm_st',
'$perm_city',
'$perm_prov',
'$perm_zip',
'$office_phone',
'$home_phone',
'$cellphone',
'$birthdate',
'$birthplace',
'$sex',
'$height1',
'$height2',
'$weight1',
'$weight2',
'$civil_status',
'$religion',
'$nationality',
'$position1',
'$position2',
'$position1_yrsofexp',
'$position1_mosofexp',
'$position2_yrsofexp',
'$position2_mosofexp',
'$country_id',
'$status',
'$pic_name',
'$remarks')";
$result = mysql_query($sql);
if($result){
header("Location: edit_personal.php?Action=edit&msg=A new applicant was added&applicant_id=$applicant_id");
}
else header("Location: edit_personal.php?Action=edit&msg=Applicant was not added&applicant_id=$applicant_id");
break;
case 'children':
$bday = "$year-$month-$day";
$sql = "INSERT INTO children(
applicant_id,
lname,
fname,
mname,
bday,
sex,
civil_status,
employed
)
VALUES (
'$applicant_id',
'$lname',
'$fname',
'$mname',
'$bday',
'$sex',
'$civil_status',
'$employed'
)";
$result = mysql_query($sql);
echo mysql_error();
if($result) $msg = "Information Saved";
header("Location: edit_dependents.php?Action=edit&applicant_id=$applicant_id&msg=$msg");
break;
case 'education':
$sql = "INSERT INTO education(applicant_id,education,school,from_date,to_date,course)
VALUES ('$applicant_id','$education','$school','$from_date','$to_date','$course')";
$result = mysql_query($sql);
header("Location: edit_education.php?Action=edit&applicant_id=$applicant_id");
break;
case 'employment':
$from_day = ($from_day)? $from_day : "00";
$from_month = ($from_month)? $from_month : "00";
$from_year = ($from_year)? $from_year : "000";
$to_day = ($to_day)? $to_day : "00";
$to_month = ($to_month)? $to_month : "00";
$to_year = ($to_year)? $to_year : "000";
$from_date = "$from_year-$from_month-$from_day";
$to_date = "$to_year-$to_month-$to_day";
$sql = "INSERT INTO employment(applicant_id,company,address,position,department,salary,currency,from_date,to_date,job_desc,reason_for_leaving)
VALUES ('$applicant_id','$company','$address','$position','$department','$salary','$currency','$from_date','$to_date','$job_desc','$reason_for_leaving')";
$result = mysql_query($sql);
header("Location: edit_employment.php?Action=edit&applicant_id=$applicant_id");
break;
case 'training':
$day = ($day)? $day : "00";
$month = ($month)? $month : "00";
$year = ($year)? $year : "000";
$date = "$year-$month-$day";
$sql = "INSERT INTO training(applicant_id,center,title,date,remarks)
VALUES ('$applicant_id','$center','$title','$date','$remarks')";
$result = mysql_query($sql);
header("Location: edit_training.php?Action=edit&applicant_id=$applicant_id");
break;
case 'medical': $date = "$year-$month-$day";
$sql = "INSERT INTO medical(applicant_id,status,description,clinic_id,phase,date)
VALUES ('$applicant_id','$status','$description','$clinic',$phase,'$date')";
$result = mysql_query($sql);
header("Location: edit_medical.php?Action=edit&applicant_id=$applicant_id");
break;
case 'complaint': $complaint_date = "$complaint_year-$complaint_month-$complaint_day";
$resolved_date = "$resolved_year-$resolved_month-$resolved_day";
$sql = "INSERT INTO complaints(applicant_id,complaint_date,complaint,remarks,comment,resolved_date,resolvedby)
VALUES ('$applicant_id','$complaint_date','$complaint','$remarks','$comment','$resolved_date','$resolvedby')";
$result = mysql_query($sql);
header("Location: edit_complaint.php?Action=edit&applicant_id=$applicant_id");
break;
case 'payment':
$date = "$year-$month-$day";
$sql = "INSERT INTO payment(applicant_id,description,total_amount,total_amountdollars,date)
VALUES ('$applicant_id','$description','$amount','$amountdollars','$date')";
$result = mysql_query($sql);
header("Location: edit_payment.php?Action=edit&applicant_id=$applicant_id");
break;
case 'payment_detail':
$date = "$year-$month-$day";
$sql = "INSERT INTO payment_detail(payment_id,or_no,description,amount,amountdollars,date)
VALUES ('$payment_id','$or','$description','$amount','$amountdollars','$date')";
$result = mysql_query($sql);
echo mysql_error();
header("Location: edit_payment_detail.php?Action=edit&applicant_id=$applicant_id&payment_id=$payment_id");
break;
case 'job_order':
$duplicate = getdata("select * from job_order where job_order_no='$job_order_no'");
if(!empty($duplicate)) error_message('Job Order No. already exists.');
$date = "$year-$month-$day";
$sql = "INSERT INTO job_order(job_order_no,principal_id,date,status)
VALUES ('$job_order_no','$principal_id','$date','$status')";
$result = mysql_query($sql);
$id = mysql_insert_id();
header("Location: edit_job_order.php?Action=edit&job_order_id=$id");
break;
case 'jo_pos':
$duplicate = getdata("select * from jo_position where job_order_id='$job_order_id' and position_id='$position_id'");
if(!empty($duplicate)) error_message('Duplicate position for this job order.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_male))error_message('No. of male is in wrong type.Integers only.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_female))error_message('No. of female is in wrong type.Integers only.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_coed))error_message('No. of male/female is in wrong type.Integers only.');
$sql = "INSERT INTO jo_position(job_order_id,position_id,no_of_male,no_of_female,no_of_coed,wage)
VALUES ('$job_order_id','$position_id','$no_of_male','$no_of_female','$no_of_coed','$wage')";
$result = mysql_query($sql);
header("Location: edit_job_order.php?Action=edit&job_order_id=$job_order_id");
break;
case 'visa':
$duplicate = getdata("select * from visa where visa_no='$visa_no'");
if(!empty($duplicate)) error_message('Visa No. already exists.');
$sql = "INSERT INTO visa(visa_no,principal_id,expiry_date,status)
VALUES ('$visa_no','$principal_id','$expiry_date','$status')";
$result = mysql_query($sql);
$id = mysql_insert_id();
header("Location: edit_visa.php?Action=edit&visa_id=$id");
break;
case 'visa_pos':
$duplicate = getdata("select * from visa_position where visa_id='$visa_id' and position_id='$position_id'");
if(!empty($duplicate)) error_message('Duplicate position for this Visa.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_male))error_message('No. of male is in wrong type.Integers only.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_female))error_message('No. of female is in wrong type.Integers only.');
if(eregi("[[:punct:]]|[[:alpha:]]",$no_of_coed))error_message('No. of male/female is in wrong type.Integers only.');
$sql = "INSERT INTO visa_position(visa_id,position_id,no_of_male,no_of_female,no_of_coed,wage)
VALUES ('$visa_id','$position_id','$no_of_male','$no_of_female','$no_of_coed','$wage')";
$result = mysql_query($sql);
header("Location: edit_visa.php?Action=edit&visa_id=$visa_id");
break;
case 'cv_sent':
$date = "$year-$month-$day";
$sql = "INSERT INTO cv_sents(applicant_id,principal_id,jo_pos_id,date) VALUES ('$applicant_id',$principal_id,'$jo_pos_id','$date')";
$result = mysql_query($sql);
echo mysql_error();
header("Location: edit_cvsent.php?applicant_id=$applicant_id");
break;
case 'agent': $duplicate = getdata("select * from acct_agents where name='$name' and address='$address' and agent_id!=$agent_id");
if(!empty($duplicate)) error_message('There is already an existing agent like the one you entered.');
$sql = "INSERT INTO acct_agents(name,address,fax,telephone,price)
VALUES ('$name','$address','$fax','$telephone',$price)";
$result = mysql_query($sql);
header("Location: manage_agent.php");
break;
case 'account': $duplicate = getdata("select * from acct_accounts where name='$account'");
if(!empty($duplicate)) error_message('There is already an existing account like the one you entered.');
$sql = "INSERT INTO acct_accounts(name) VALUES ('$account')";
$result = mysql_query($sql);
$id = mysql_insert_id();
header("Location: manage_accounts.php");
break;
case 'expense':
$date = "$year-$month-$day";
$created=date("Y-m-d");
$sql = "INSERT INTO acct_expenses(account_id,job_order_id,description,amount,date,created) VALUES ($account_id,$job_order_id,'$description',$amount,'$date','$created')";
$result = mysql_query($sql);
header("Location: input_expense.php");
break;
case 'income':
$date = "$year-$month-$day";
$created=date("Y-m-d");
$sql = "INSERT INTO acct_incomes(account_id,job_order_id,description,amount,date,created) VALUES ($account_id,$job_order_id,'$description',$amount,'$date','$created')";
$result = mysql_query($sql);
header("Location: input_income.php");
break;
}
?>