/home/mip/public_html_/old-website/employerxxx/sqladd.php
<?php
session_start();
require_once("common_msg.inc");
require_once("func_all.php");
$db = db_connect();


switch($what){

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;
													 
																			
}	
?>