180817_KFormLib.php 36.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
createLeadEntryForm()
{	echo "Debugging Dialer";
				
}

function createRacingCust()
{
	$dataarr=$this->recruitdata["peopledata"];

	$data="<div style='clear:both;margin:2% 0 0 1%;border-style: dotted solid dashed;padding:2%'>
			<h5>Customer Information</h5>
			<hr/><br>
				<br><br>
				<div style='clear:both;width:100%;'>
					<div style='width:49%;float:left'>
                                        <label class='label-small_new' style='width:29%;'>Date</label>
                                        <label class='label-small_new' style='width:50%;' >".date('Y-m-d')."</label>
					</div>
				<br><br>

				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>PB Code</label>
					<input type='text' class='form_new form_new_amend'style='width:50%;' value='' id='PBcode'>
				</div>  
				<div style='width:49%;float:left'>
					/<label class='label-small_new' style='width:29%;'>PB Name</label>
					<input type='text' class='form_new form_new_amend'style='width:50%;' value='' id='PBname'>
				</div> 

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>
				
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>PB landline Contact No.</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='PBlandlineContNo'>
				</div> 
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Supervisor Mail ID</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='SupervisormailID'> 
				</div>

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>
				
				<div style='width:49%;float:left'  class='search'>
					<label class='label-small_new' style='width:29%;'>Group ID</label>
					<input type='text' class='form_new form_new_amend' style='width:52%;' id='groupID' value=''>
				</div> 
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Group ID Name</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='groupidname' value=''>
				</div>  

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>

				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Cust ID</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='custID' maxlength='16'>
				</div>
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Cust Name</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='custname' value=''>
				</div>  

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Relationship With Group ID</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='RelationshipGroupID' maxlength='16'>
				</div>  
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Cust ID</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='Custid' maxlength='16'>
				</div>

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Cust Name</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='CustName' value=''>
				</div>  
				<div style='width:49%;float:left'>
					<label class='label-small_new' style='width:29%;'>Relationship With Group ID</label>
					<input type='text' class='form_new form_new_amend' style='width:50%;' id='relationshipgroupid' maxlength='16'>
				</div>  

			</div>
			<br><br>
			<div style='clear:both;width:100%;'>
			<div style='width:49%;float:left'>

				<label class='label-small_new' style='width:29%;'>Grouping</label>
                                <select id='newGroupdditiongroup' class='form_hrm_select select2multi' style='width:50%'>
                                <option value='New_Group'>New Group</option>
                                <option value='Addition_to_group'>Addition to group</option>
				<option value='Addition_to_group'>Regroup</option>
				</select>

			</div>  
			<div style='width:49%;float:left'>
				<label class='label-small_new' style='width:29%;'>Racing from</label>
				<input type='text' class='form_new form_new_amend' style='width:50%;' id='racingfrom'>
			</div>  
			</div>
			<br><br><br>


			<br><br>
			<div style='clear:both;width:100%;'>
				<input type='button' class='btn btn-default btn-md' style='margin-left:40%' value='Save' id='CRSave'>        
			</div>
		</div>

		<script>



			$('#CRSave').click(function()
			{ 
				var snumber = $('#snumber').val();
				var PBname = $('#PBname').val();
				var PBcode = $('#PBcode').val();
				var PBlandlineContNo = $('#PBlandlineContNo').val();
				var SupervisormailID = $('#SupervisormailID').val();
				var groupID = $('#groupID').val();
				var groupidname = $('#groupidname').val();
				var custID = $('#custID').val();
				var custname = $('#custname').val();
				var RelationshipGroupID = $('#RelationshipGroupID').val();
				var Custid = $('#Custid').val();
				var CustName = $('#CustName').val();
				var relationshipgroupid = $('#relationshipgroupid').val();
				var newGroupdditiongroup = $('#newGroupdditiongroup').val();
				var racingfrom = $('#racingfrom').val();

				var postdata='s_no='+encodeURIComponent(snumber);
				postdata+='&pb_name='+encodeURIComponent(PBname);
				postdata+='&pb_code='+encodeURIComponent(PBcode);
				postdata+='&pb_landline_contact_no='+encodeURIComponent(PBlandlineContNo);
				postdata+='&supervisor_mail_id='+encodeURIComponent(SupervisormailID);
				postdata+='&group_id='+encodeURIComponent(groupID);
				postdata+='&group_id_name='+encodeURIComponent(groupidname);
				postdata+='&cust_id='+encodeURIComponent(custID);
				postdata+='&cust_name='+encodeURIComponent(custname);
				postdata+='&relationship_with_group_id='+encodeURIComponent(RelationshipGroupID);
				postdata+='&cust_id_next='+encodeURIComponent(Custid);
				postdata+='&cust_name_next='+encodeURIComponent(CustName);
				postdata+='&relationship_with_group_id_next='+encodeURIComponent(relationshipgroupid);
				postdata+='&new_group_addition_to_group='+encodeURIComponent(newGroupdditiongroup);
				postdata+='&racing_from='+encodeURIComponent(racingfrom);

				doAjax('custrace',postdata,'createtaskdiv','ajaxMutex_recSaveData','singlethis','POST');
		});

				</script>";

				return $data;
}


function colorCodeRec($id)
{
	$fdirty=$this->recruitdata["dirty"];
	$dataarr=$this->recruitdata["peopledata"];
	$gthis=$this->gthis;
	$edituser=$this->edituser;

	if($edituser)
	{
		$colorarr=array();
		$tarr=explode(",",$gthis->HRCoreVars['colorcodes']);
		foreach($tarr as $tcolor)
		{
			$ttarr=explode(":",$tcolor);
			$colorarr[$ttarr[0]]=$ttarr[1];
		}
		if(isset($colorarr[$dataarr[$id]]))$color=$colorarr[$dataarr[$id]];
		$data="<div style='display:block;height:10px;width:100%;background:$color;'></div>";
	}
	return $data;
}

function CreateForm(&$frm)
{
	$fdirty=$this->recruitdata["dirty"];
	$dataarr=$this->recruitdata["peopledata"];
	$gthis=$this->gthis;
	$edituser=$this->edituser;
	$recruitdata=$this->recruitdata;
	$isuser=$this->isuser;
	$oldbkrec=$this->oldbkrec;
	$themehome=$this->themehome;

	$data="";$i=1;$tabsdata='';$firsttab="active";

	if(Auth::check())
	{
		if(Auth::user()->moduleACL("HR",true,false,false))
		{
			$frm['Files/Logs']["{{id}} {{firstname}}"][]=array();
		}
		if(Auth::user()->moduleACL("Task",true,false,false))
		{
			$frm['Tasks']["{{id}} {{firstname}}"][]=array();
		}
		if(Auth::user()->moduleACL("Dialer",true,false,false))
		{
			$frm['Feedback']["{{id}} {{firstname}}"][]=array();
			$frm['CallHistory']["{{id}} {{firstname}}"][]=array();

				$frm['QuestionnAire']["{{id}} {{firstname}}"][]=array();
				$frm['QuestionnAireHistory']["{{id}} {{firstname}}"][]=array();
				$frm['ComplaintManagement']["{{id}} {{firstname}}"][]=array();
				//$frm['ChildCase']["{{id}} {{firstname}}"][]=array();
				$frm['Racing Format']["{{id}} {{firstname}}"][]=array();
				if(Auth::user()->username =="B654321" || Auth::user()->username =="B12345")
				{
				$frm['LeadEntryForm']["{{id}} {{firstname}}"][]=array();
				}



			}
		}

		$tabstr='<div class="tab_bar_green tabsbar-2"><ul class="row row-merge">';
		foreach($frm as $tbname=>$tabs)
		{
			if(($tbname=='Files/Logs'||$tbname=='Letters'||$tbname=='Tasks'||$tbname=='Feedback'||$tbname=='CallHistory')&&!$isuser)continue;

			if($tbname!='')
			{
				$tabstr.="<li class='$firsttab'><a href='#tabs-$i' data-toggle=tab>$tbname</a></li>";
				$tabsdata.="<div class='$firsttab tab-pane ' id=tabs-$i>";
				$firsttab='';

				$fsetstr="";
				foreach($tabs as $fsetname=>$fset)
				{
					$fsetstr.="<div class=tab_generic><fieldset id='fsetid_".$fset[0][5]."'><legend class='new-recruit_legend' style='background:#9CBFFF'><b style='color:white'>".$this->HRTemplateString($fsetname,$this->HRFiledsStr)."</b></legend><div class='box_nrecrut'>";
					$rowval='';
					foreach($fset as $flines)
					{
						if($rowval==''){$rowval=$flines[1][1];if($flines[1][0]==0)$flines[1][0]=1;$fsetstr.="<div style='float:left;width:".(100/$flines[1][0])."%'>";}
						else if($rowval!=$flines[1][1]){$rowval=$flines[1][1];$fsetstr.="</div><div style='float:left;width:".(100/$flines[1][0])."%'>";}

						if($flines[0]!=''&&substr($flines[0], -2)=='~1')
						{
							$fsetstr.="<div class=tab_generic><fieldset style='margin-right:3px;' id='fsetid_".$flines[5]."_1'><legend class='new-recruit_legend' style='background:#9CBFFF'><b style='color:white'>".substr($flines[0], 0, -2)."</b><span class='pull-right'><a href=# onclick='$(\"#fsetid_".$flines[5]."_1_div\").toggle();return false;'><i class='fa fa-sort'></i></a></span></legend><div id='fsetid_".$flines[5]."_1_div'>";
						}
						else if($flines[0]!=''&&substr($flines[0], -2)=='~2')
						{
							$fsetstr.="<div class=tab_generic><fieldset style='margin-right:3px;' id='fsetid_".$flines[5]."_1'><legend class='new-recruit_legend' style='background:#9CBFFF'><b style='color:white'>".substr($flines[0], 0, -2)."</b><span class='pull-right'><a href=# onclick='$(\"#fsetid_".$flines[5]."_1_div\").toggle();return false;'><i class='fa fa-sort'></i></a></span></legend><div id='fsetid_".$flines[5]."_1_div' style='display:none'>";
						}

						if(!($flines[4][2]=='0'&&!$isuser))
						{
							if(!($flines[4][1]=='0'&&!$edituser))
							{
								if($flines[3]=='thumbnail')$fsetstr.=$this->makeThumbImg($flines[5]);
								if($flines[6]=="S")$fsetstr.=$this->makeSelect($flines[5]);
								if($flines[6]=="F")$fsetstr.=$this->makeTextBox($flines[5],"","file");
								if($flines[6]=="T"){$tsz='form_new form_new_amend';if($flines[8]!='')$tsz=$flines[8];$fsetstr.=$this->makeTextBox($flines[5],$tsz);}
								if($flines[6]=="D")$fsetstr.=$this->makeTextBox($flines[5],"");
								if($flines[6]=="A")$fsetstr.=$this->makeTextArea($flines[5]);
								if($flines[6]=="L")$fsetstr.=$this->makeLabelText($flines[5],"");
								if($flines[6]=="M")$fsetstr.=$this->makeMultiSelect($flines[5],$flines[2]);
								if($flines[2]!='')$fsetstr.="<p><lable></lable><font color=#db4453>$flines[2]</font></p>";
							}
						}
						if($flines[0]!=''&&substr($flines[0], -2)=='~0')
						{
							$fsetstr.="</div></fieldset></div>";
						}
					}
					$fsetstr.="</div></div></fieldset></div>";if($rowval=='')$fsetstr='';
				}
				$tabsdata.=$fsetstr;
				if($tbname=='Files/Logs'&&$isuser)$tabsdata.=$this->createFilesTab();
				if($tbname=='Tasks'&&$edituser)$tabsdata.=$this->createTasksTab();
				if($tbname=='Feedback')$tabsdata.=$this->createDispoTab();
				if($tbname=='CallHistory')$tabsdata.=$this->createCallsTab();
				if($tbname=='QuestionnAire')$tabsdata.=$this->createQaireTab();
				if($tbname=='QuestionnAireHistory')$tabsdata.=$this->createQaireHistTab();
				if($tbname=='ComplaintManagement')$tabsdata.=$this->createCompManage();
				if($tbname=='ChildCase')$tabsdata.=$this->createChildCase();
				//if($tbname=='RacingCustomer')$tabsdata.=$this->createRacingCust();
				if($tbname=='Racing Format')$tabsdata.=$this->createRacingCust();
                                if($tbname=='LeadEntryForm')$tabsdata.=$this->createLeadEntryForm();
				$tabsdata.="</div>";
				$i++;
			}
		}
		$tabstr.='</ul></div>';

		$data="<div class=relativeWrap>".$tabstr.'<div class="tab-content">'.$tabsdata.'</div>'."</div>";


		$data="<div id=createtaskdiv></div><div style='clear:both'></div>".$this->colorCodeRec('candidatecategory').$data.$this->CreateFormScripts();
		return $data;
	}
	
	function CreateFormScripts()
	{
		$varid=$this->varid;

		$wakka=$this->gthis;
		$hrexclusiveflag=0;if(empty($this->recruitdata["peopledata"]['client']))$this->recruitdata["peopledata"]['client']='__';
		if(strstr($this->HRExclusiveClients,$this->recruitdata["peopledata"]['client']))
		{
			if(!$wakka->IsAdmin())
			{
				if(!strstr($wakka->getManagerUsers($wakka->getUserListforClient($this->recruitdata["peopledata"]['client'])),$wakka->GetUserName()))
				{
					if(!strstr($wakka->GetBBBUserData("clientsownerlist"),$this->recruitdata["peopledata"]['client']))$hrexclusiveflag=1;
				}
			}
		}
		if(!$this->isuser)$hrexclusiveflag=0;

		$recordDetails = DB::table('records')->where('id','=',$varid)->select('priority')->get();
		$priority = $recordDetails[0]->priority;

		$data=" <div id=recdialog></div><br><input type=hidden name='id' id='id' value='".$this->varid."'>
		<input type=hidden name='workflowstatus' id='workflowstatus' value='".$this->recruitdata["peopledata"]["workflowstatus"]."'>
		<input type=hidden name=varid id=varid value='".$this->varid."'>
		<input type=hidden name=status id=status value='".$this->recruitdata["peopledata"]["status"]."'>
		<script>$(document).ready(function() {try{".$this->emprecordScripts."}catch(e){}});
			\$(document).ready(function()
			{
				var dialerFlagExit=0;
				if(\$('#dialer_flag').length)
				{
					if('".$this->recruitdata["peopledata"]['dialer_flag']."'=='VIP')
					{
						\$('#dialer_flag').val('".$this->recruitdata["peopledata"]['dialer_flag']."');

						dialerFlagExit=1;
					}

					if('".$priority."'=='VIP' && dialerFlagExit!=1)
					{
						\$('#dialer_flag').val('".$priority."');
					}
				}

				if (typeof kSetDData === 'function')kSetDData('C','crmid',".$this->varid.");
			});
		</script>";

            if($this->isuser&&$this->edituser)//&&$this->recruitdata["peopledata"]['currentstatus']!=$wakka->HRCoreVars["systemExitStatus"]
            {
            	$data.="<input type=button class='btn btn-green' value='Save Data' id=recruitsavedata onclick='recruitData();return false;'>
            	<input title='' class='tooltip tooltip1 btn btn-green_outline' type=button value='Reload Data' onclick='showRecruit(\"".$this->varid."\");return false;'>
            	";
            	if(Auth::check()&&Auth::user()->moduleACL("Task",true,false,false))$data.="<input title='' class='tooltip tooltip1 btn btn-green_outline' type=button value='User Task' onclick='createTask(\"".$this->varid."\");return false;'>";
            	$data.="
            	<script>
            		function recruitData()
            		{
            			var postdata='varid='+$('#varid').val();

            			var varslist='".$this->HRFiledsStr."';
            			var varsarr=varslist.split(',');
            			for(var i=0;i<varsarr.length;i++)
            			{
            				if(varsarr[i]!=''&&$('#'+varsarr[i]).length)postdata+='&'+varsarr[i]+'='+encodeURIComponent($('#'+varsarr[i]).val());
            			}

            			doAjax('record?action=save',postdata,'createtaskdiv','ajaxMutex_recSaveData','singlethis','POST');
            		}
            	</script>";
            }
            if($this->oldbkrec)
            {
            	$data.="<input title='' class='tooltip tooltip1 btn btn-green_outline' type=button value='HR Closure' onclick='bkempclosure(\"".$this->bkvarid."\",\"hr\");return false;'>
            	<input title='' class='tooltip tooltip1 btn btn-green_outline' type=button value='Accounts Closure' onclick='bkempclosure(\"".$this->bkvarid."\",\"account\");return false;'>
            	<script>
            		function bkempclosure(tid,tmodule)
            		{
            			if(confirm('This Will mark Current Record Closed by your ID. Proceed?'))
            			{
            				var postdata='tid='+tid+'&tmodule='+tmodule;
            				doAjax('hr?action=BKEmpClosure',postdata,'searchresults');
            			}
            		}
            	</script>";
            }
            
            if($this->isuser&&$this->edituser)
            {
            	$data.="<script>
            	var filevarstrlistarr='".$this->HRFileFieldsStr."'.split(',');
            	for(var i=0;i<filevarstrlistarr.length;i++)if(filevarstrlistarr[i]!=''&&$('#'+filevarstrlistarr[i]).length)ajaxFileUpload(filevarstrlistarr[i],'".$this->varid."');
            		var datevarstrlistarr='".$this->HRDateFilds."'.split(',');
            	for(var i=0;i<datevarstrlistarr.length;i++)if(datevarstrlistarr[i]!=''&&$('#'+datevarstrlistarr[i]).length)$('#'+datevarstrlistarr[i]).datepicker({dateFormat: 'dd.mm.yy',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '".(date('Y')-70).":".(date('Y')+20)."'});
            		ajaxFileUpload('genericfileselect','".$this->varid."');
            	function saltotal()
            	{
            		var stotal=0;

            		if($('#salbasic').val()=='')$('#salbasic').val('0');
            		if($('#salhouserent').val()=='')$('#salhouserent').val('0');
            		if($('#saltransport').val()=='')$('#saltransport').val('0');
            		if($('#salfood').val()=='')$('#salfood').val('0');
            		if($('#saltelephone').val()=='')$('#saltelephone').val('0');
            		if($('#salmedical').val()=='')$('#salmedical').val('0');
            		if($('#salelectricity').val()=='')$('#salelectricity').val('0');
            		if($('#salother').val()=='')$('#salother').val('0');

            		stotal+=parseFloat($('#salbasic').val());
            		stotal+=parseFloat($('#salhouserent').val());
            		stotal+=parseFloat($('#saltransport').val());
            		stotal+=parseFloat($('#salfood').val());
            		stotal+=parseFloat($('#saltelephone').val());
            		stotal+=parseFloat($('#salmedical').val());
            		stotal+=parseFloat($('#salelectricity').val());
            		stotal+=parseFloat($('#salother').val());

            		$('#saltotal').val(stotal);
            	}
            	$('#salelectricity').keyup(saltotal);
            	$('#salmedical').keyup(saltotal);
            	$('#saltelephone').keyup(saltotal);
            	$('#saltransport').keyup(saltotal);
            	$('#salhouserent').keyup(saltotal);
            	$('#salbasic').keyup(saltotal);
            	$('#salfood').keyup(saltotal);
            	$('#salother').keyup(saltotal);
            	$('#saltotal').keyup(saltotal);

            	function recd_sendmail(filepath){mailFile(filepath,$('#recd_to').val(),$('#recd_subject').val(),$('#recd_from').val(),encodeURIComponent($('#recd_message').val()));}
            	function mailFileDialog(filepath)
            	{
            		var dhtml='<fieldset><legend class=\"new-recruit_legend\">Send File as Email</legend>';
            		dhtml+='<p style=\"clear:both\"><label class=label-small_new  style=\"width:25%\">From:</label><select class=\"form_hrm_select\" style=\"width:50%\" id=recd_from><option value=system>System</option><option value=\"".$wakka->GetUserName()."\">".$wakka->GetUserName()."</option></select></p>';
            		dhtml+='<p style=\"clear:both\"><label class=label-small_new  style=\"width:25%\">To (comma sep):</label><input type=text id=recd_to class=\"form_new form_new_amend\" value=\"".$this->recruitdata["peopledata"]["emailid"]."\"></p>';
            		dhtml+='<p style=\"clear:both\"><label class=label-small_new  style=\"width:25%\">Subject:</label><input type=text id=recd_subject class=\"form_new form_new_amend\" value=\"".$this->varid." Innovation : File Attached\"></p>';
            		dhtml+='<p style=\"clear:both\"><label class=label-small_new  style=\"width:25%\">Message:</label><textarea class=\"form_new form_new_amend\" id=recd_message style=\"width:60%\">Please find the Document Attached</textarea></p>';
            		dhtml+='<p style=\"clear:both\"><label class=label-small_new  style=\"width:25%\">Attachment:</label>'+filepath+'</p>';
            		dhtml+='</fieldset>';

            		$('#recdialog').html('');
            		$('#recdialog').html(dhtml);

            		$('#recdialog').dialog({
            			autoOpen: false,
            			width: '70%',
            			buttons: {
            				'Send Mail' : function() {
            					recd_sendmail(filepath);$(document).scrollTop(0);
            					$(this).dialog('close');
            				},
            				'Close': function() {
            					$(this).dialog('close');
            				}
            			}
            		});
            		$('#recdialog').dialog('open');
            	}

            	function deleteTask(tid)
            	{
            		var postdata='tid='+tid;
            		doAjax('hr?action=DeleteTask',postdata,'createtaskdiv');
            	}
            	function ajaxFileUpload3(eid,varid)
            	{
            		var flg=1;
            		var gn='';
            		var uhandle=$('#'+eid).ajaxfileupload({
            			'action': 'hr?action=PdfSplit',
            			'params': {
            				'name': eid,
            				'varid' : varid,
            				'gr':gn,
            			},
            			'onComplete': function(response) {
            				if(response.status==false)
            				{
            					$('#createtaskdiv').html('<div class=\"message error close\"><h2>Error!</h2><p>'+response.message+'</p></div>');
            					messageCloseFun();
            					$('#'+eid).val('');
            					return false;
            				}
            				else
            				{
            					$('#createtaskdiv').html('<div class=\"message success close\"><h2>Success!</h2><p>File Uploaded</p></div>');
            					messageCloseFun();
            				}
            			},
            			'onStart': function() {
            				flg=1;
            				$('#fd'+eid).html('<font color=#4b89dc>Uploading...</font>');
            				console.log('started:');
            			},
            			'onCancel': function() {
            				console.log('no file selected');
            			}
            		});

            		return false;
            	}
            	ajaxFileUpload3('pdfsplitfile',".$this->varid.");
            	function clearFileVars()
            	{
            		for(var i=0;i<filevarstrlistarr.length;i++)if(filevarstrlistarr[i]!=''&&$('#'+filevarstrlistarr[i]).length)$('#'+filevarstrlistarr[i]).val('');
            	}
            function approveFData(tid,tvarid)
            {
            	var postdata='tid='+tid+'&varid='+tvarid;
            	doAjax('hr?action=RecruitApprove',postdata,'createtaskdiv');
            	return false;
            }
            function renewRecord()
            {
            	if(confirm('This Will Archive Current Client data and clean the record. Are you sure?'))
            	{
            		var postdata='varid='+$('#varid').val();
            		doAjax('hr?action=RenewRecord',postdata,'createtaskdiv');
            	}
            }
            function blacklistcandidate()
            {
            	if(confirm('This Will mark candidate as Blacklisted. Are you sure?'))
            	{
            		var postdata='varid='+$('#varid').val();
            		doAjax('hr?action=BlacklistRecord',postdata,'createtaskdiv');
            	}
            }
        </script>";
    }
    if($hrexclusiveflag==1)
    {
    	$data.="<script>
    	$(document).ready(function(){
    		$('#tabs-6').css({'display':'none'});
    		$('#tabs-7').css({'display':'none'});
    		$('#tabs-9').css({'display':'none'});
    		$('#tabs-10').css({'display':'none'});
    		$('#tabs-11').css({'display':'none'});
    	});
    </script>";
}

return $data;
}


function checkDuplicate($varid,$key,$val)
{
	$gthis=$this->gthis;
	if($val=="")
	{
		return false;
	}
	else
	{
		$cachearray=explode(",",$gthis->EMPCacheCols);
		if(in_array($key,$cachearray)&&$key!='')
		{
			if($gthis->getCount("records","`$key`='$val' and id!='$varid'"))
				return true;
			else
				return false;
		}
		else
		{
			if($gthis->getCount("records","peopledata like '%\"$key\";s:".strlen($val).":\"$val\"%' and id!='$varid'"))
			return true;
			else
				return false;
		}
	}
}

function chechAlNum($val)
{
	if($val=="")
	{
		return true;
	}
	else
	{
		if(ctype_alnum($val))
			return true;
		else 
			return false;
	}
}
function validatePostData()
{
	$varid=$this->varid;
	$wakka=$this->gthis;
	$ppldata=$this->recruitdata["peopledata"];
	$message='';
	if($wakka->getCount("records","id='$varid'")!=1)$message=" Record doesnot exists, ";

		//only if active statuses
	$empstatus=Input::get('currentstatus');if($empstatus=="")$empstatus="__NOCHECK__";

	if(stristr($wakka->HRCoreVars['hrrecruitstatuses'],$empstatus)||stristr($wakka->HRCoreVars['hrworkingstatus'],$empstatus))
	{
			//$this->HRForms[$parts[3]][$parts[4]][]=array($parts[5],$parts[6],$parts[7],$parts[8],$parts[9],$parts[0],$parts[1],$parts[2],$parts[10]);
		foreach($this->HRForms as $tbname=>$tabs)
		{
			if($tbname!='')
			{
				foreach($tabs as $fsetname=>$fset)
				{
					foreach($fset as $flines)
					{
						if($flines[3]!="")
						{
							$validations=explode("|",$flines[3]);
							foreach($validations as $vline)
							{
								if($vline!="")
								{

									$vline=str_replace("__COMMA__",",",$vline);
									$fline5=Input::get($flines[5]);

										//$message.="[$flines[5]|$vline] ";
									if($vline=="NONEMPTY")
									{
										if(empty($fline5))$message.=" ".$this->HRFieldNames[$flines[5]].",";
									}
									else if(substr($vline,0,5)=="REGEX"&&$fline5!='')
									{
										if(!preg_match("/".substr($vline,5)."/", $fline5))$message.=" Invalid ".$this->HRFieldNames[$flines[5]].",";
									}
									else if($vline=="NODUP")
									{
										if($this->checkDuplicate($varid,$flines[5],Input::get($flines[5])))$message.=" ".$this->HRFieldNames[$flines[5]]." Already Exists".",";
									}
									else if($vline=="ALNUM")
									{
										if(!$this->chechAlNum(Input::get($flines[5])))$message.=" ".$this->HRFieldNames[$flines[5]]." Can only Have Numbers and Letters".",";
									}
									else if(substr($vline,0,8)=="DT_C_MEX"&&$ppldata[$flines[5]]==''&&Input::get($flines[5])!='')
									{
										$duration = explode(".",Input::get($flines[5]));
										if(sizeof($duration)==3)
										{
											$duration=mktime(0, 0, 0, $duration[1], $duration[0], $duration[2]);
											if($duration-time()-(intval(substr($vline,8))*30*24*60*60)<=0)$message.=" ".$this->HRFieldNames[$flines[5]]." needs to more then ".substr($vline,8)." months,";
										}
										else $message.=" Error : ".$this->HRFieldNames[$flines[5]];
									}
									else if(substr($vline,0,8)=="DT_D_MEX"&&Input::get($flines[5])!='')
									{
										$duration = explode(".",Input::get($flines[5]));
										if(sizeof($duration)==3)
										{
											$duration=mktime(0, 0, 0, $duration[1], $duration[0], $duration[2]);
											if(time()-$duration-(intval(substr($vline,8))*30*24*60*60)<=0)$message.=" ".$this->HRFieldNames[$flines[5]]." needs to more then ".substr($vline,8)." months,";
										}
										else $message.=" Error : ".$this->HRFieldNames[$flines[5]];
									}
								}
							}
						}
					}
				}
			}
		}

			//select values check
		$dropsarr=explode(",",$this->HRDropFilds);
		foreach($dropsarr as $dropitem)
		{
			if($dropitem=='client')$selvals=implode("~",$this->gthis->clientsReadAccess());
			else $selvals=$this->FormSelectVals[$dropitem];
			
			if(Input::get($dropitem)!=''&&Input::get($dropitem)!='undefined'&&!strstr($selvals,trim(Input::get($dropitem))))
				$message.=" Wrong Value of '".$this->HRFieldNames[$dropitem]."'";
		}

			//date check
		$datesarr=explode(",",$this->HRDateFilds);
		foreach($datesarr as $dateitem)
		{
			$dateitem=trim($dateitem);
			if($dateitem!='')
			{
				if(Input::get($dateitem)!=''&&Input::get($dateitem)!='undefined')
				{
					$dtparts=explode(".",Input::get($dateitem));
					if(sizeof($dtparts)==3&&intval($dtparts[0])<32&&intval($dtparts[1])<13&&intval($dtparts[2])>1900);
					else $message.=" Wrong Value of '".$this->HRFieldNames[$dateitem]."'";
				}
			}
		}
	}

		//client cannot be changed unless Admin
	if(!$wakka->IsAdmin())if(trim($ppldata["client"])!=""&&$ppldata["client"]!=Input::get("client"))$message=" Client Cannot be changed, use Renew-Record";

	if(Input::get('currentstatus')==$wakka->HRCoreVars['hrTriggerHoldStatus'])
	{
			$message="";//bypass checks for candidates
		}
		return $message;
	}
	
	function updateArrayWithPostData()
	{
		$ppldata=$this->recruitdata["peopledata"];
		$changearr=$this->recruitdata['modifylog'];
		$wakka=$this->gthis;
		
		$ppldata['varid']=Input::get('varid');
		$ppldata['id']=Input::get('varid');
		$client=Input::get('client');

		//file vars change the file names to store,and if empty keep the old name
		$tmpstr=explode(",",$this->HRFileFieldsStr);
		foreach($tmpstr as $tmpelem)
		{
			$elemfname=$ppldata['varid']."_".$tmpelem.".pdf";
			if(Input::has($tmpelem))
			{
				$ppldata[$tmpelem]=$wakka->safeString(Input::get($tmpelem));//save the new name as old val in case of files
				Input::merge(array($tmpelem => $elemfname));
				$this->recruitdata['dirty'][$tmpelem]=1;
			}
			else if(!empty($ppldata[$tmpelem]))
			{
				if($ppldata[$tmpelem]==$elemfname||$ppldata[$tmpelem]=="")
				{
					Input::merge(array($tmpelem => $ppldata[$tmpelem]));
				}
				else 
				{
					Input::merge(array($tmpelem => $elemfname));
				}
			}
		}

		$tmpstr=explode(",",$this->HRFiledsStr);
		$newdata=array();foreach($tmpstr as $key)
		{
			if(Input::exists($key))$newdata[$key]=trim(Input::get($key));
		}
		
		foreach($newdata as $key=>$newval)
		{
			$val=$ppldata[$key];
			if($newval!=trim($val))
			{
				if(strstr($changearr[$changearr["updated"]],$key)==FALSE)$changearr[$changearr["updated"]].="$key|".str_replace(array("|",",")," ",$val)."|".str_replace(array("|",",")," ",$wakka->safeString($newval)).",";
				$this->recruitdata['dirty'][$key]=1;

				$this->empWorkflowTrigger($ppldata['varid'],$client,$key,$newval,$val,$ppldata,$newdata);
				$this->empAnalytics($ppldata['varid'],$ppldata,$key,$newval,$val);
			}
		}

		foreach($tmpstr as $tmpelem)
		{
			if(Input::exists($tmpelem))
			{
				$ppldata[$tmpelem]= $wakka->safeString(Input::get($tmpelem));
				if($ppldata[$tmpelem]=="")unset($ppldata[$tmpelem]);
			}
		}


		//run holded up triggers if
		if($newdata["currentstatus"]!=$wakka->HRCoreVars['hrTriggerHoldStatus'])
		{
			$triggers=$wakka->LoadAll("select * from hrms_triggerhold where varid='".$ppldata['varid']."'");
			foreach($triggers as $trigger)
			{
				if($trigger['varid']==$ppldata['varid'])
				{
					$triggerdata=unserialize($trigger['data']);
					$triggerdata['newdata']["currentstatus"]=$newdata["currentstatus"];
					$this->empWorkflowTrigger($triggerdata['varid'],$triggerdata['client'],$triggerdata['key'],$triggerdata['newval'],$triggerdata['oldval'],$triggerdata['postvars'],$triggerdata['newdata']);
				}
			}
			$wakka->Query("delete from hrms_triggerhold where varid='".$ppldata['varid']."'");
		}
		
		$this->recruitdata["peopledata"]=$ppldata;
		$this->recruitdata['modifylog']=$changearr;
	}
	
	function processFormSubmit()
	{
		if(Auth::guest())return "Error-401";

		$wakka=$this->gthis;
		$tasknotification='';
		$resultstr="";
		$result=false;
		$varid=$this->varid;

		$message=$this->validatePostData();
		if($message==""||$wakka->IsAdmin())
		{
			if($message!="")$tasknotification.="Please Check: $message<br>";

			$this->updateArrayWithPostData();

			//$res=$wakka->setPerson($varid,$this->recruitdata);
			if($res<0)
			{
				$resultstr="<div class='alert alert-danger'><strong>Record Add/Update Error!</strong><p>Serialization Error.. Cannot Save</p></div><script>simpleNotification('error','topRight','Error. Cannot Save');</script>";
			}
			else
			{
				$result=true;

				$wakka->cleanSystemTaskbyID($varid,$this->HRFiledsStr);
				$tasksemp=$wakka->LoadAll("select name from hrms_tasks where empid='$varid' and status in ('NEW','WIP')");
				foreach($tasksemp as $tline)$tasknotification.=$tline['name']."<br>";

				if($tasknotification==''){$resultstr="<div class='alert alert-success'><strong>Record Updated!</strong><p>Record Data Updated Successfully, you may search and edit or continue to edit data.</p><div style='display:none' id='happy'><img src='/assets/images/emot/happy.jpg' height='80' width='80'></div><div style='display:none' id='sad'><img src='/assets/images/emot/sad.png' height='80' width='80'></div></div><script>clearFileVars();</script><script>simpleNotification('success','topRight','Saved Successfully');

			</script>";}
			else {$resultstr="<div class='alert alert-success'><strong>Data Saved with Task Escalation</strong><p>Tasks Created:- <br>$tasknotification</p></div><script>clearFileVars();</script><script>simpleNotification('success','topRight','Saved Successfully');</script>";
		}				

		$resultstr.= $this->getProcess($this->recruitdata['peopledata'],$wakka);


				//sanity check files and task
		$recruitdata=$this->recruitdata;
		$tmpstr=explode(",",$this->HRFileFieldsStr);
		$fixedcnt=0;
		foreach($tmpstr as $tmpelem)
		{
			if(file_exists($this->storagehome."/recruits/$varid/$varid"."_".$tmpelem.".pdf"))
			{
				if($recruitdata["peopledata"][$tmpelem]!="$varid"."_".$tmpelem.".pdf"){$recruitdata["peopledata"][$tmpelem]="$varid"."_".$tmpelem.".pdf";$fixedcnt++;}
			}
			else
			{
				if(isset($recruitdata["peopledata"][$tmpelem])&&$recruitdata["peopledata"][$tmpelem]!=""){$recruitdata["peopledata"][$tmpelem]="";$fixedcnt++;}
			}
		}
				//set fdirty with WIP fields
		$recruitdata["dirty"]=array();
		$taskslist=$wakka->LoadAll("select * from hrms_tasks where empid='$varid' and status in ('NEW','WIP') and creatorid='System' and completecheck!=''");
		foreach($taskslist as $taskline)
		{
			$recruitdata["dirty"][$taskline['completecheck']]=1;
		}
		$this->recruitdata=$recruitdata;
		$res=$wakka->setPerson($varid,$this->recruitdata);

	}
}
else
{
	$resultstr="<div class='alert alert-danger'><strong>Record Add/Update Error!</strong><p>Please Check : $message</p></div><script>simpleNotification('error','topRight','Error in saving, Check Errors');</script>";
}

return $resultstr;
}


function buildUL($tooltip,$fpath,$text,$tdata="",$onclick="")
{
	$data="<ul class='dash dash2' onclick='$onclick return false;'>
	<li>
		<a href=# onclick='return false;' title='$tooltip' class=tooltip>
			<img src='$fpath' alt='' tdata='$tdata' />
			<span>$text</span>
		</a>
	</li>
</ul>";
return $data;
}
function getProcess(&$ppldata,&$gthis)
{

}

function getStageStatus(&$gthis,$stagestr,&$ppldata,$imgoverride="")
{
	$completed=true;$tdata="";$titleD=array();
	$wfstrs=explode("_",$stagestr);
	$tfields=explode(",",$gthis->HRCoreVars[$stagestr]);
	foreach($tfields as $tfield)
	{
		if($tfield!="")
		{
			if(!isset($ppldata[$tfield]))$ppldata[$tfield]='';
			
			if($ppldata[$tfield]==""){$completed=false;$title[]="Missing : ".$tfield;}
			else {$titleD[]="Done : ".$tfield." = ".$ppldata[$tfield];}
		}
	}
	$title[]="<br>";if(is_array($titleD))$title=array_merge($title,$titleD);

	if($completed)$imgoverride="tick_48";
	if(!$completed&&$imgoverride=="")$imgoverride="stop_48";

	if($imgoverride!="stop_48"&&$tdata!="stop_48,err1")
	{
			//if last stage is done set system exit status
		if($stagestr=="WF_Exit"||$stagestr=="WF_UUVC")
		{
			$gthis->setPersonKey($ppldata["id"],"generalremarks","[[System:- Exiting Candidate, Removing from Workflow (".date("d.M.Y").").]] ".$ppldata["generalremarks"],"System");
			$gthis->setPersonKey($ppldata["id"],"currentstatus",$gthis->HRCoreVars["systemExitStatus"],"System");
			$gthis->setPersonKey($ppldata["id"],"workflowstatus","");
			$gthis->setPersonKey($ppldata["id"],"workflowstatusS","");
		}
	}
	else 
	{
		if(isset($wfstrs[1]))
		{
			if($ppldata["workflowstatus"]!=$wfstrs[1])$gthis->setPersonKey($ppldata["id"],"workflowstatus",$wfstrs[1]);
			if($ppldata["workflowstatusS"]!=$imgoverride)$gthis->setPersonKey($ppldata["id"],"workflowstatusS",$imgoverride);
		}

		$wfstrs[1].="_ToDo";
	}

	if(!isset($ppldata['generalremarks']))$ppldata['generalremarks']='';

	if($completed)return $this->buildUL(implode("<br>",$titleD),$this->themehome."/assets/icons/$imgoverride.png",$wfstrs[1],$tdata,"Rpopupopen(\"$ppldata[id]\",\"$stagestr\",\"$ppldata[generalremarks]\");");
	else          return $this->buildUL(implode("<br>",$title), $this->themehome."/assets/icons/$imgoverride.png",$wfstrs[1],$tdata,"Rpopupopen(\"$ppldata[id]\",\"$stagestr\",\"$ppldata[generalremarks]\");");
}


function empWorkflowTrigger($varid,$client,$key,$newval,$oldval,&$postvars,&$newdata)
{

}
function empAnalytics($varid,&$ppldata,$key,$newval,$oldval)
{

}
//Log::info($data);

}