KFormLib.php-bkp 116 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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608
<?php namespace App\Jobs;

use Storage;
use Auth;
use Input;
use App\Models\CRMCall;
use App\Models\CRMCallArchive;
use App\Models\User;
use App\Models\Record;
use Log;
use DB;

class KFormLib
{
	private $themehome='';
	private $storagehome='';
	private $varid='';
	private $edituser='';
	public $gthis='';//TODO only set directly from empbulkupload
	private $fdirtytxt='';
	private $isuser=false;
	private $recruitdata='';
	private $oldbkrec='';
	private $bkvarid='';
	private $emprecordScripts='';
	private $HRExclusiveClients='';
	public $FormSelectVals=array();
	
	private $objcache=array();
        
	public $HRFiledsStr="";
	public $HRFieldNames=array();
	public $HRFileFieldsStr="";
	public $HRDateFilds="";
	public $HRDropFilds="";
	public $HRForms=array();
	public $mobile="";
	public $client="";
        
	public function __construct($formstr)
	{
		$fields=explode(",",$formstr);
		foreach($fields as $field)
		{
			$parts=explode(":",$field);
			if(sizeof($parts)>=3)
			{
				$this->HRFiledsStr.=$parts[0].",";
				$this->HRFieldNames[$parts[0]]=$parts[2];

				if($parts[1]=="F")$this->HRFileFieldsStr.=$parts[0].",";
				else if($parts[1]=="D")$this->HRDateFilds.=$parts[0].",";
				else if($parts[1]=="S"||$parts[1]=="M")
				{
					$this->HRDropFilds.=$parts[0].",";
					if(isset($parts[11])){$this->FormSelectVals[$parts[0]]=$parts[11];}
					else {$this->FormSelectVals[$parts[0]]="";}
				}

				$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]);
			}
		}
		$this->themehome=url("userfiles/templates/hrms");//TODO
		$this->storagehome=storage_path('app/templates/hrms');
	}
        
	public function data($config)
	{
		$this->varid=$this->getConfig('varid',$config,'');
		$this->enable=$this->getConfig('enable',$config,'');
		$this->edituser=$this->getConfig('edituser',$config,'');
		$this->gthis=$this->getConfig('gthis',$config,array());
		$this->fdirtytxt=$this->getConfig('fdirtytxt',$config,'');
		$this->isuser=$this->getConfig('isuser',$config,false);
		$this->recruitdata=$this->getConfig('recruitdata',$config,'');
		$this->oldbkrec=$this->getConfig('oldbkrec',$config,'');
		$this->bkvarid=$this->getConfig('bkvarid',$config,'');
		$this->emprecordScripts=$this->getConfig('emprecordScripts',$config,'');
		$this->HRExclusiveClients=$this->getConfig('HRExclusiveClients',$config,'');
		
		$updatetime=time();
		$this->recruitdata['modifylog'][$updatetime]=$this->gthis->GetUserName()."::";
		$this->recruitdata['modifylog']["updated"]=$updatetime;
	}
	function getConfig($str,$config,$default=false)
	{
		if(isset($config[$str]))return $config[$str];
		return $default;
	}
        
	function recruitFileLink($filename)
	{
		$themehome=$this->themehome;
		$varid=$this->varid;
		$edituser=$this->edituser;
		
		$fpath="$themehome/recruits/$varid/$filename";
		$fpathT="$themehome/thumbs/$varid/$filename.gif";
		if($filename!=""){$filename="<img src='$themehome/images/circle_down.png'>";if($edituser)$maillnk="<img src='$themehome/images/mail.gif'>";}
		return "<a href=# onclick=\"mailFileDialog('$fpath');return false;\" class='tooltip tooltip1' title='Send this file as Mail'>$maillnk</a>&nbsp;&nbsp;
	  <a title='<img src=$fpathT width=400px>' class='tooltip tooltip1' href='$fpath' target=_BLANK><b>$filename</b></a>";
	}
	function fillSelect($selId,$selvals=array())
	{
	  $rdata="";
	  if($selId=='client'&&Auth::check())
	  {
			if($this->gthis=='')$this->gthis=new KHRMSLib();
			$this->FormSelectVals[$selId]=implode("~",$this->gthis->clientsReadAccess());
	  }

	  if(isset($this->FormSelectVals[$selId]))
	  {
	    $values=explode("~",$this->FormSelectVals[$selId]);sort($values);
	    foreach($values as $value)
	    {
				$value=trim($value);
				if($value!="")
				{
					$tsel='';if(!empty($selvals)&&in_array($value,$selvals))$tsel='selected=selected';
					
					$rdata.="<option value='$value' $tsel>$value</option>";
				}
			}
			
			if(!empty($selvals))foreach($selvals as $selval)
			{
				if(!in_array($selval,$values))
				{
					$rdata.="<option value='$selval' selected=selected>$selval</option>";
				}
			}
	  }
	  return $rdata;
	}
	function makeSelect($id)
	{
		$fdirty=$this->recruitdata["dirty"];
		$dataarr=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		$edituser=$this->edituser;
		$fdirtytxt=$this->fdirtytxt;
		$isuser=$this->isuser;
		
		$selarr=array();
		if($dataarr[$id]!='')$selarr[]=$dataarr[$id];
		$list=$this->fillSelect($id,$selarr);
		$list="<option value=''>&nbsp;</option>".$list;

		$data="<p style='clear:both'>
		<label class=label-small_new  style='width:25%'>".$this->HRFieldNames[$id].": </label>
		<select id='$id' name='$id' class='form_hrm_select select2multi' style='width:50%'>$list</select>
		<span class=field_desc></span><span class=validate_success></span>
		<span class=validate_error>".((isset($fdirty[$id]))?$fdirtytxt:'')."</span>
	</p>";

		if(!$isuser||!$edituser)
		{
			$data="<p style='clear:both'>
		<label class=label-small_new  style='width:25%'>".$this->HRFieldNames[$id].": </label>
		<b>$dataarr[$id]</b><input type=hidden id=$id value='$dataarr[$id]'>
		<span class=field_desc></span><span class=validate_success></span>
		<span class=validate_error>".((isset($fdirty[$id]))?$fdirtytxt:'')."</span>
	</p>";
		}

		return $data;
	}
	function makeMultiSelect($id,$helptxt)
	{

	}
	function makeTextBox($id,$size,$type="text")
	{
		$fdirty=$this->recruitdata["dirty"];
		$dataarr=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		$edituser=$this->edituser;
		$fdirtytxt=$this->fdirtytxt;
		$isuser=$this->isuser;
		$varid=$this->varid;
		
		if(strstr($this->HRDateFilds,$id)&&!$gthis->IsAdmin()){$ro="";$formatstr='DD.MM.YYYY';}

		if($type=="text")$size.=" capText";
		if($id=='emailid')$maillnk=" <a href='mailto:$dataarr[$id]'>Mail</a> ";

		if($gthis->IsAdmin()&&$fdirty[$id]&&strstr($gthis->HRCoreVars["RequiredApproval"],$id))$approvaltxt="<input type=button class='btn btn-green' value='Approve' onclick='approveFData(\"$id\",\"$varid\");return false;'>";

		$data="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=$formatstr>".$this->HRFieldNames[$id].": </label>

		<input ".($type=="file"?" style='display:inline-block' size=9":"class='$size'")." id='".trim($id)."' name='".trim($id)."' type='$type' value='$dataarr[$id]' $ro/>
		
		$maillnk<span class=field_desc id='fd$id'>".(($type=="file")?$this->recruitFileLink($dataarr[$id]):'')."</span>
		<span class=validate_success></span><span class=validate_error>".((isset($fdirty[$id]))?$fdirtytxt:'')." $approvaltxt</span>
	</p>";
		if(!$isuser||!$edituser)
		{


			$data="<p style='clear:both'>
		<label class=label-small_new  style='width:25%'>".$this->HRFieldNames[$id].": </label>
		<b>$dataarr[$id]</b>
		$maillnk<span class=field_desc id='fd$id'>".(($type=="file")?$this->recruitFileLink($dataarr[$id]):'')."</span>
		<span class=validate_success></span><span class=validate_error>".((isset($fdirty[$id]))?$fdirtytxt:'')."</span>
	</p>";
		}

		return $data;
	}


//Changes Done On 10-Sept-16 for removing Required By Manish
	function makeLabelText($id,$size,$type="text")
	{
		$fdirty=$this->recruitdata["dirty"];
		$dataarr=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		$fdirtytxt=$this->fdirtytxt;
		$custName="";

		if(strstr($this->HRDateFilds,$id)){$ro="readonly=readonly";$formatstr='DD.MM.YYYY';}

		$data="<p style='clear:both'>
		<label class=label-small_new  style='width:35%'>".$this->HRFieldNames[$id].": </label>
		<b>$dataarr[$id]</b>";

		$data.="<span class=field_desc id='fd$id'>".(($type=="file")?$this->recruitFileLink($dataarr[$id]):'')."</span>
		<span class=validate_success></span><span class=validate_error></span>
	</p>";

		return $data;
	}
	function makeThumbImg($id)
	{
		$themehome=$this->themehome;
		$dataarr=$this->recruitdata["peopledata"];
		$varid=$this->varid;
		
		$fpath="$themehome/images/default.jpg";
		if(file_exists($this->storagehome."/thumbs/$varid/".$dataarr[$id].".gif"))$fpath="$themehome/thumbs/$varid/".$dataarr[$id].".gif";

		$data="<p style='clear:both'>
			<label class=label-small_new style='width:25%'></label>
			<img src='$fpath' height=100px class='image_new'>
		</p>";

		return $data;
	}
	function makeTextArea($id)
	{
		$fdirty=$this->recruitdata["dirty"];
		$dataarr=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		$edituser=$this->edituser;
		$fdirtytxt=$this->fdirtytxt;
		$isuser=$this->isuser;
		
		$data="
	<p style='clear:both'>
		<label class=label-small_new  style='width:25%'>".$this->HRFieldNames[$id].": </label>
		<textarea class='form_new form_new_amend' style='height:70px' id='$id' name='$id' class=capText>$dataarr[$id]</textarea>
		<span class=field_desc id='fd$id'></span>
		<span class=validate_success></span><span class=validate_error>".((isset($fdirty[$id]))?'':'')."</span>
	</p>";
		if(!$isuser||!$edituser)
		{
			$data="
	<p style='clear:both'>
		<label class=label-small_new  style='width:25%'>".$this->HRFieldNames[$id].": </label>
		<b>$dataarr[$id]</b>
		<span class=field_desc id='fd$id'></span><span class=validate_success></span>
		<span class=validate_error>".((isset($fdirty[$id]))?$fdirtytxt:'')."</span>
	</p>";
		}
		return $data;
	}

	function HRTemplateString($str,$fieldsstr)
	{
		$ppldata=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		
		
		if(!isset($this->objcache["ownerrmlist"]))$this->objcache["ownerrmlist"]=$gthis->getUserListforClient($ppldata['client']);
		if(!isset($this->objcache["recruitmentrmlist"]))$this->objcache["recruitmentrmlist"]=$gthis->getRecruitmentListforClient($ppldata['client']);
		if(!isset($this->objcache["acctrmlist_600"]))$this->objcache["acctrmlist_600"]=$gthis->getUserListforClientAcct($ppldata['client']);
		if(!isset($this->objcache["bdmlist_600"]))$this->objcache["bdmlist_600"]=$gthis->getUserListforClientBDM($ppldata['client']);
		
		if(!isset($this->objcache["ownerrmlist_M"]))$this->objcache["ownerrmlist_M"]=$gthis->getManagerUsers($this->objcache["ownerrmlist"]);
		if(!isset($this->objcache["recruitmentrmlist_600"]))$this->objcache["ownerrmlist_M"]=$gthis->getManagerUsers($this->objcache["recruitmentrmlist"]);
		
		$str=str_replace("{{ownerrmlist}}",$this->objcache["ownerrmlist"],$str);
	  $str=str_replace("{{ownerrmlist_M}}",$this->objcache["ownerrmlist"]."/".$this->objcache["ownerrmlist_M"],$str);
	  $str=str_replace("{{recruitmentrmlist}}",$this->objcache["recruitmentrmlist"],$str);
	  $str=str_replace("{{acctrmlist}}",$this->objcache["acctrmlist_600"],$str);
	  
	  if($this->edituser==1)
	  {
	    $str=str_replace("{{recruitmentrmlist_600}}","RecruitmentRM- ".$this->objcache["recruitmentrmlist"]."/".$this->objcache["recruitmentrmlist_600"],$str);
	    $str=str_replace("{{acctrmlist_600}}","Accounts- ".$this->objcache["acctrmlist_600"],$str);
	    $str=str_replace("{{bdmlist_600}}","BDM- ".$this->objcache["bdmlist_600"],$str);
	  }
	  else
	  {
	    $str=str_replace("{{recruitmentrmlist_600}}","",$str);
	    $str=str_replace("{{acctrmlist_600}}","",$str);
	    $str=str_replace("{{bdmlist_600}}","",$str);
	  }

//Log::info($str);		
		preg_match_all('/{{[^}]*}}/', $str, $matches);
		if(!empty($matches)&&!empty($matches[0]))
		{
			foreach($matches[0] as $matchstr)
			{
				$tmpelem=substr($matchstr,2,-2);if(!isset($ppldata[$tmpelem]))$ppldata[$tmpelem]='';//Log::info($ppldata[$tmpelem]);
				$str=str_replace($matchstr,$ppldata[$tmpelem],$str);
			}
		}

	  return $str;
	}
	

	function createFilesTab()
	{
		$fdirty=$this->recruitdata["dirty"];
		$dataarr=$this->recruitdata["peopledata"];
		$gthis=$this->gthis;
		$edituser=$this->edituser;
		$themehome=$this->themehome;
		$storagehome=$this->storagehome;
		$logarr=$this->recruitdata["modifylog"];
		$varid=$this->varid;

		
		$data="<div class=custom1 style='width:49%;float:left'>
  <legend class='new-recruit_legend'>Current Files</legend>
  <ul>";

		$fpath="$themehome/recruits/$varid";
		$storagepath="$storagehome/recruits/$varid";
		if (is_dir($storagepath)&&$handle = opendir($storagepath)) 
		{
			$optionsstr='<option></option>';
			$fileids=explode(",",$this->HRFileFieldsStr);
			foreach($fileids as $fileid)$optionsstr.="<option value='$fileid'>".$this->HRFieldNames[$fileid]."</option>";////

			$ii=0;
			while (false !== ($entry = readdir($handle))) 
			{
				if ($entry != "." && $entry != ".."&&substr($entry,0,3)!="OLD") 
				{
					$ii++;
					$titlestr='';
					$flatid="UniqueId_".$ii;
					$selectstr="<select id='SEL$flatid' onchange='filesSelected(\"$flatid\",\"$entry\");' class='form_hrm_select' style='width:50%'>$optionsstr</select>";////

					$pathinfo = pathinfo($entry);
					$extension = strtolower($pathinfo['extension']);
					if($extension=="jpg"||$extension=="png"||$extension=="jpeg"||$extension=="gif")$titlestr="<img src=\"$fpath/$entry\" width=400px>";
					else if($extension=="pdf"){$titlestr="<img src=\"$themehome/thumbs/$varid/$entry.gif\" width=400px>";$selectstr='';}
					else $selectstr='';
					$data.= "<li>$selectstr".($edituser==1?"<a href=# onclick='deleteFile(\"$entry\",\"$varid\");return false;'><img src='$themehome/images/x.jpg' height=10px></a> ":"")."<a title='$titlestr' class='tooltip tooltip1' href='$fpath/$entry' target=_BLANK><b>$entry</b></a><span id='SPAN$flatid'></span></li>";
				}
			}
			closedir($handle);
		}
		$data.="
  </ul>
</div>
<div class=custom1 style='width:49%;float:left'>
  <legend class='new-recruit_legend'>Old Files</legend>
  <ul>";

		$fpath="$themehome/recruits/$varid";
		$storagepath="$storagehome/recruits/$varid";
		if (is_dir($storagepath)&&$handle = opendir($storagepath)) 
		{
			while (false !== ($entry = readdir($handle))) 
			{
				if ($entry != "." && $entry != ".." &&substr($entry,0,3)=="OLD") 
				{
					$titlestr='';
					$pathinfo = pathinfo($entry);
					$extension = strtolower($pathinfo['extension']);
					if($extension=="jpg"||$extension=="png"||$extension=="jpeg"||$extension=="gif")$titlestr="<img src=\"$fpath/$entry\" width=400px>";
					$data.= "<li>".($edituser==1?"<a href=# onclick='deleteFile(\"$entry\",\"$varid\");return false;'><img src='$themehome/images/x.jpg' height=10px></a> ":"")."<a title='$titlestr' class='tooltip tooltip1' href='$fpath/$entry' target=_BLANK><b>$entry</b></a></li>";
				}
			}
			closedir($handle);
		}
		$data.="
  </ul>
</div>
<div style='clear:both'></div><div class='box_nrecrut' style='width:100%'><div style='width:49%;float:left'>";
		$data.= $this->makeTextBox("genericfilename","form_new");
		$data.= $this->makeTextBox("genericfileselect","","file");
		$data.="</div><div style='width:49%;float:left'>
<label class=label-small_new  style='width:25%'>Upload and Split PDF</label><input type=file style='width:180px' name=pdfsplitfile id=pdfsplitfile><span id=fdpdfsplitfile></span>
	</div></div>
<div style='clear:both'></div>
<fieldset>
<legend class='new-recruit_legend'>Edit Logs</legend>
<table class='footable table' cellpadding=0 cellspacing=0 style='border-bottom:black 2px solid;margin-bottom:20px'>
  <thead>
  <tr>
    <td class='table_hrm_heading_green'>Username</td>
    <td class='table_hrm_heading_green'>Date/Time</td>
    <td class='table_hrm_heading_green'>Key</td>
    <td class='table_hrm_heading_green'>New Values</td>
    <td class='table_hrm_heading_green'>Old Values</td>
  </tr>
  </thead>";

		if(is_array($logarr))
		{
			krsort($logarr);

			$i=0;
			foreach($logarr as $logkey=>$logval)
			{
				if(!$gthis->IsAdmin()&&$i>=200)break;
				$logline=explode("::",$logval);
				if($logkey!="createtime"&&$logkey!="updated"&&$logkey!=$createtime)
				{
					$j=0;
					$changedkeys=explode(",",$logline[1]);
					foreach($changedkeys as $changedkey)
					{
						$changedvals=explode("|",$changedkey);
						if($changedvals[0])
						{
							$i++;$j++;
							if(sizeof($changedvals)>3)$changedvals[2]=$changedvals[sizeof($changedvals)-1];

							if($j==1) $data.= "<tr><td>$logline[0]</td><td>".date("Y-m-d_H:i:s",$logkey)."</td><td>".$this->HRFieldNames[$changedvals[0]]."</td><td>$changedvals[2]</td><td>$changedvals[1]</td></tr>";
							else $data.= "<tr><td></td><td></td><td>".$this->HRFieldNames[$changedvals[0]]."</td><td>$changedvals[2]</td><td>$changedvals[1]</td></tr>";
						}
					}
				}
			}

			$createtime=$logarr["createtime"];
			$createuser=$logarr[$createtime];
			if($createuser)$data.= "<tr><td>$createuser</td><td>".date("Y-m-d H:i:s",$createtime)."</td><td colspan=3>Created</td></tr>";
		}

		$data.="</table></fieldset>

<fieldset>
<legend class='new-recruit_legend'>Mail Logs</legend>
<table class='footable table' cellpadding=0 cellspacing=0 style='border-bottom:black 2px solid;margin-bottom:20px'>
  <thead>
  <tr>
    <td class='table_hrm_heading_green'>From</td>
    <td class='table_hrm_heading_green'>To</td>
    <td class='table_hrm_heading_green'>Subject</td>
    <td class='table_hrm_heading_green'>Status</td>
    <td class='table_hrm_heading_green'>Date</td>
  </tr>
  </thead>
";
		$alist=$gthis->LoadAll("select * from hrms_emailqueue where eid='$varid' order by id desc ");
		foreach($alist as $aline)
		{
			$parts=unserialize($aline['data']);
			$check2=explode(" ",$parts['subject']);
			if(is_array($parts['to']))$parts['to']=implode("<br>",$parts['to']);

			if($dataarr['emailid']!="")
			{
			if(strstr($parts['to'],$dataarr['emailid'])||trim($check2[0])==$varid)
				$data.= "
      <tr>
	<td>$parts[from]</td>
	<td><div style='max-width:250px;overflow:hidden'>$parts[to]</div></td>
	<td>$parts[subject]</td>
	<td>$aline[status]</td> 
	<td>".str_replace(" ","_",$aline['completed'])."</td> 
      </tr>";
                        }
		}

		$data.="</table></fieldset>";
		return $data;

	}

	function createTasksTab()
	{
		$gthis=$this->gthis;
		$varid=$this->varid;
		$themehome=$this->themehome;
		
		$data="<div style='width:100%;float:left'>";

		$data.="<table class='footable table' cellpadding=0 cellspacing=0 border=0>
	  <thead><tr>
	    <td class='table_hrm_heading_green'>Name</td>
	    <td class='table_hrm_heading_green'>Assigned To</td>
	    <td class='table_hrm_heading_green'>Due Date</td>
	    <td class='table_hrm_heading_green'>Attachment</td>
	    <td class='table_hrm_heading_green'>Status</td>
	    <td class='table_hrm_heading_green'>Accepted On</td>
	    <td class='table_hrm_heading_green'>Remarks</td>
	    <td class='table_hrm_heading_green'>Created By</td>
	    <td class='table_hrm_heading_green'></td>
	  </tr></thead>";

		$tasksarr=$gthis->LoadAll("select * from hrms_tasks where empid='$varid' and creatorid!='System' and creatorid!='BounceMail' order by endtime desc");
		foreach($tasksarr as $taskline)
		{
			if($taskline['username']=="")$taskline['username']=$taskline['escalation2'];
			//$delstr="<a href=# onclick='deleteTask($taskline[id]);return false;'><img src='$themehome/images/x.jpg' height=10px></a>";

			$attachf="<a href='".$themehome."/uploads/".$taskline['username']."/".$taskline['attachment']."' target=_blank>".substr($taskline['attachment'],0,15)."</a>";
			$data.= "<tr><td>$taskline[name]</td><td>".str_replace(","," ",$taskline['username'])."</td><td title='Created: $taskline[created_at]'>$taskline[endtime]</td><td>$taskline[attachment]</td><td>$taskline[status]</td><td>$taskline[accepted]</td><td>$taskline[remarks]</td><td title=$taskline[id]>$taskline[creatorid]</td><td>$delstr</td></tr>";
		}

		$data.="<tr><td colspan=9><hr></td></tr>";$delstr="";

		$tasksarr=$gthis->LoadAll("select * from hrms_tasks where empid='$varid' and creatorid='System' order by endtime desc");
		foreach($tasksarr as $taskline)
		{
			if($taskline['username']=="")$taskline['username']=$taskline['escalation2'];
			if($gthis->IsAdmin()||strstr($gthis->HRCoreVars["HRManagerUsers"],$gthis->GetUserName()))$delstr="<a href=# onclick='deleteTask($taskline[id]);return false;'><img src='$themehome/images/x.jpg' height=10px></a>";

			$attachf="<a href='".$themehome."/uploads/".$taskline['username']."/".$taskline['attachment']."' target=_blank>".substr($taskline['attachment'],0,15)."</a>";
			$data.= "<tr><td>$taskline[name]</td><td>".str_replace(","," ",$taskline['username'])."</td><td title='Created: $taskline[created_at]'>$taskline[endtime]</td><td>$taskline[attachment]</td><td>$taskline[status]</td><td>$taskline[accepted]</td><td>$taskline[remarks]</td><td title=$taskline[id]>$taskline[creatorid]</td><td>$delstr</td></tr>";
		}

		$data.="</table></div>";
		return $data;
	}
	function createDispoTab()
	{
		$gthis=$this->gthis;

		$varid=$this->varid;
		$themehome=$this->themehome;
		$dataarr=$this->recruitdata["peopledata"];

		// $recordDetails = DB::table('records')->where('id','=',$varid)->select('*')->get();
		// $priority = $recordDetails[0]->priority;
	
		$data="<div style='width:100%;float:left'>";

		$data.="<div style='width:49%;float:left'><fieldset><legend class='new-recruit_legend'>Call Status</legend>";
		if(Auth::user()->group=="Digital")
		{
			$data.="<p style='clear:both'>
	                <label class=label-small_new  style='width:25%;' title=''>Contactability: </label>
	                <select class='form_hrm_select' id='dialer_userstatus' name='dialer_userstatus' style='width:70%' onchange='dialerSubdisoSelect($(this).val());dialerUserStatusChange($(this).val());'></select>
	                </p>";
			 $data.="<p style='clear:both'>
	                <label class=label-small_new  style='width:25%;' title=''>Sub Disposition: </label>
	                <select class='form_hrm_select' id='dialer_usersubstatus' name='dialer_usersubstatus' style='width:70%'></select>
	                </p>";
		}
		else
		{
			$data.="<p style='clear:both'>
	                <label class=label-small_new  style='width:25%;' title=''>Contactability: </label>
	                <select class='form_hrm_select' id='dialer_userstatus' name='dialer_userstatus' style='width:70%' onchange='dialerUserStatusChange($(this).val());'></select>
	                </p>";

			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Action Code: </label>
				<select class='form_hrm_select' id='dialer_actionCode' name='dialer_actionCode' style='width:70%' onchange='dialerActionCodeChange($(this).val());'>
					<option value=''></option>
					<option value='BV'>BV - Borrower Visits The Branch</option>
					<option value='CEREP'>CEREP - Central Representation</option>
					<option value='IC'>IC - Incoming Call</option>
					<option value='OCMO'>OCMO - Outgoing Call Mobile</option>
					<option value='OCOF'>OCOF - Outgoing Call Office</option>
					<option value='OCRF'>OCRF - Outgoing Call Reference</option>
					<option value='OCRS'>OCRS - Outgoing Call Residence</option>
					<option value='ONLN'>ONLN - Online Payment by Customer</option>
					<option value='PU'>PU - Pick Up</option>		
					<option value='TCFR'>TCFR - Telecalling Field Referal</option>
				</select>
			</p>";
		}
		$data.="<p style='clear:both'>
			<label class=label-small_new  style='width:25%;' title=''>Result Code: </label>
			<select class='form_hrm_select' id='dialer_resultCode' name='dialer_resultCode' style='width:70%' onchange='dialerResultCodeChange($(this).val());'>
				<option value=''></option>
				<option value='BP'>BP - Broken Promise</option>
				<option value='CB'>CB - Customer asked for Call Back</option>
				<option value='CEREP'>CEREP - Central Representation Success</option>
				<option value='DEAD'>DEAD - Dead</option>
				<option value='LM'>LM - Left Message With 3rd Party</option>
				<option value='NC'>NC - NC</option>
				<option value='NCIN'>NCIN - Not Contactable Invalid No</option>
				<option value='NCNR'>NCNR - Not Contactable Not Reachable</option>
				<option value='NCRG'>NCRG - Not Contactable Ringing</option>
				<option value='NCSO'>NCSO - Not Contactable Switched Off</option>
				<option value='NCWN'>NCWN - Not Contactable Wrong No</option>
				<option value='OT'>OT - Others Including Refusal to Pay</option>
				<option value='PD'>PD - Paid Atleast 1 Full EMI</option>
				<option value='PTP'>PTP - Promise To Pay</option>
				<option value='PV'>PV - Paid as per Customer but req Verification</option>
				<option value='RTP'>RTP - Refused To Pay</option>
				<option value='Moratorium'>Moratorium - RBI Moratorium </option>
				<option value='SETLD'>SETLD - Settled</option>
				<option value='SKIP'>SKIP - Skip</option>
				<option value='TPC'>TPC - Third Party Contactable</option>
				<option value='FU'>FU - Follow Up</option>
			</select>
		</p>";
		$data.="<p style='clear:both'>
			<label class=label-small_new  style='width:25%;' title=''>Next Action Code: </label>
			<select class='form_hrm_select' id='dialer_nextActionCode' name='dialer_nextActionCode' style='width:70%' onchange='dialerNextActionCodeChange($(this).val());'>
				<option value=''></option>
				<option value='BV'>BV - Borrower Visits The Branch</option>
				<option value='CEREP'>CEREP - Central Representation</option>
				<option value='IC'>IC - Incoming Call</option>
				<option value='OCMO'>OCMO - Outgoing Call Mobile</option>
				<option value='OCOF'>OCOF - Outgoing Call Office</option>
				<option value='OCRF'>OCRF - Outgoing Call Reference</option>
				<option value='OCRS'>OCRS - Outgoing Call Residence</option>
				<option value='ONLN'>ONLN - Online Payment by Customer</option>
				<option value='PU'>PU - Pick Up</option>
				<option value='UPI'>UPI</option>
				<option value='TCFR'>TCFR - Telecalling Field Referal</option>
			</select>
		</p>";

		$data.="<p style='clear:both;position:relative'>
			<label class=label-small_new  style='width:25%;' title=''>Next Action Date Time: </label>
			<input class='form_new form_new_amend datetimepicker_dthr' id='dialer_nextActionDateTime' name='dialer_nextActionDateTime' style='width:70%'>
		</p>";
		$data.="<div id='extraFields'></div>";
		$data.="<div id='extraFields2'></div>";
		$data.="<div id='extraFields3'></div>";
		$data.="<div id='extraFields4'></div>";

		$data.="<p style='clear:both'>
			<label class=label-small_new  style='width:25%;' title=''>RFD: </label>
			<select class='form_hrm_select' id='dialer_RFD' name='dialer_RFD' style='width:70%' onchange=''>
				<option value=''></option>
				<option value='CNRB'>CNRB - Cancellation and Rebooking</option>
				<option value='DISP'>DISP - Disputed</option>
				<option value='ESCL'>ESCL - Senior level escalation (To CEO / RBI)</option>
				<option value='EXPD'>EXPD - Confirmed death</option>
				<option value='EXPF'>EXPF - Death in Family</option>
				<option value='FRAU'>FRAU - Confirmed Fraud (Documents or Identity)</option>
				<option value='INBT'>FRAU - BT Case</option>
				<option value='LJOB'>LJOB - Loss of job</option>
				<option value='LS'>LS - Letter Sent</option>
				<option value='MEDL'>MEDL - Medical Expense</option>
				<option value='MLIV'>MLIV - Matured/Live Account – charges < INR. 500</option>
				<option value='NCCT'>NCCT - Not Contactable</option>
				<option value='OSTN'>OSTN - Out of station</option>
				<option value='OUTC'>OUTC - Out of control circumstances / Temp Finan Prob</option>
				<option value='OVLD'>OVLD - Over leveraged. Multiple debts</option>
				<option value='PAYB'>PAYB - Payment problem with correspondent Banks</option>
				<option value='PSWR'>PSWR - Post settlement waiver Request</option>
				<option value='REFU'>REFU - Intentional default. Refusing to pay</option>
				<option value='SALC'>SALC - Cut in salary</option>
				<option value='SCPH'>SCPH - Shifted but contactable on phone only</option>
				<option value='SDEA'>SDEA - Suspected Death</option>
				<option value='SKIP'>SKIP - Confirmed skip from FCU</option>
				<option value='SKIP-B'>SKIP-B - SKIP B</option>
				<option value='SKIPC'>SKIPC - Confirmed Skip</option>
				<option value='SKIPF'>SKIPF - SKIP identification by field team</option>
				<option value='SKIPT'>SKIPT - SKIP Traced</option>
				<option value='SYUP'>SYUP - Internal Sys updation issue</option>
				<option value='TPL'>TPL - Top up Loan, old LAN to be closed.</option>
				<option value='WSET'>WSET - Wants Settlement</option>
				<option value='XLLN'>XLLN - Loan Cancellation in progress</option>
			</select>
		</p>";

		$data.="<p style='clear:both'>
			<label class=label-small_new style='width:25%;' title=''>UPI: </label>
			<input class='form_new form_new_amend' id='dialer_upi' name='dialer_upi' style='width:70%'>
		</p>

		<p style='clear:both'>
			<label class=label-small_new style='width:25%;' title=''>Adhar: </label>
			<input class='form_new form_new_amend' id='dialer_adhar' name='dialer_adhar' style='width:70%'>
		</p>

		<p style='clear:both'>
			<label class=label-small_new style='width:25%;' title=''>Designation: </label>
			<input class='form_new form_new_amend' id='dialer_desg' name='dialer_desg' style='width:70%'>
		</p>";


		



		
		$data.="<p style='clear:both'>
			<label class=label-small_new  style='width:25%;' title=''>Call Remarks: </label>
			<textarea id='dialer_userremarks' name='dialer_userremarks' style='width:70%' maxlength=250></textarea>
		</p>";

		$data.="</fieldset></div><div style='width:49%;float:left'>";

		$latestCall=CRMCall::where('crm_id','=',$this->varid)->where('ts_Call','>','0')->orderBy("created_at","DESC")->first();

		$data.="<fieldset><legend class='new-recruit_legend'>Alternate Numbers</legend>";

		$nextempty="";
		$data.="<p style='clear:both'>
			<label class=label-small_new  style='width:25%;' title=''>Mobile Number: </label>
			<input class='form_new form_new_amend' value='".$dataarr["mobile"]."'  id='mainNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["mobile"]."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
		</p>";
		if($dataarr["alternateMobile"] != ""){
			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Alternate Number: </label>
				<input class='form_new form_new_amend' value='".$dataarr["alternateMobile"]."'  id='alternateMobileNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["alternateMobile"]."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
			</p>";
		}
		if($dataarr["officeNumber"] != ""){
			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Office Number: </label>
				<input class='form_new form_new_amend' value='".$dataarr["officeNumber"]."'  id='officeNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["officeNumber"]."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
			</p>";
		}
		if($dataarr["referenceMobile"] != ""){
			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Reference 1: </label>
				<input class='form_new form_new_amend' value='".$dataarr["referenceName"]."' disabled=disabled>
				<input class='form_new form_new_amend' value='".$dataarr["referenceMobile"]."' id='referenceMobileNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["referenceMobile"]."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
			</p>";
		}
		if($dataarr["referenceMobile2"] != ""){
			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Reference 2: </label>
				<input class='form_new form_new_amend' value='".$dataarr["referenceName2"]."' disabled=disabled>
				<input class='form_new form_new_amend' value='".$dataarr["referenceMobile2"]."' id='referenceMobileNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["referenceMobile2"]."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
			</p>";
		}

		if($dataarr["lan"] != ""){
			
			// $contactNumbers = array($dataarr["mobile"],$dataarr["alternateMobile"],$dataarr["officeNumber"],$dataarr["referenceMobile"],$dataarr["referenceMobile2"],$dataarr["altphone1"],$dataarr["altphone2"],$dataarr["altphone3"],$dataarr["altphone4"],$dataarr["altphone5"],$dataarr["altphone6"],$dataarr["altphone7"],$dataarr["altphone8"],$dataarr["altphone9"],$dataarr["altphone10"]);

			$addressContacts = DB::table('address')->where('lan','LIKE',$dataarr["lan"])->groupBy('mobile')->get();

			foreach ($addressContacts as $contact){
				if($contact->mobile != "" && $contact->mobile != $dataarr["mobile"] && $contact->mobile != $dataarr["alternateMobile"] && $contact->mobile != $dataarr["officeNumber"] && $contact->mobile != $dataarr["referenceMobile"] && $contact->mobile != $dataarr["referenceMobile2"] && $contact->mobile != $dataarr["altphone1"] && $contact->mobile != $dataarr["altphone2"] && $contact->mobile != $dataarr["altphone3"] && $contact->mobile != $dataarr["altphone4"] && $contact->mobile != $dataarr["altphone5"] && $contact->mobile != $dataarr["altphone6"] && $contact->mobile != $dataarr["altphone7"] && $contact->mobile != $dataarr["altphone8"] && $contact->mobile != $dataarr["altphone9"] && $contact->mobile != $dataarr["altphone10"]){
					$data.="<p style='clear:both'>
						<label class=label-small_new  style='width:25%;' title=''>Alternate: </label>
						<input class='form_new form_new_amend' value='".$contact->contact_person."' disabled=disabled>
						<input class='form_new form_new_amend' value='".$contact->mobile."' id='referenceMobileNumber' disabled=disabled><a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$contact->mobile."\",kstychDialer[\"mDialerState\"],\"\",0,".$latestCall->id.");return false;'><i class='fa fa-phone'></i></a>
					</p>";
				}
			}
		}

		for($i=1;$i<=10;$i++)
		{
			if(!empty($dataarr["altphone$i"]))
			{
				$data.="<p style='clear:both'>
					<label class=label-small_new  style='width:25%;' title=''>Alternate $i: </label>
					<input class='form_new form_new_amend' id='dialer_altphone_lbl_$i' name='dialer_altphone_lbl_$i' value='".$dataarr["altphone_lbl_$i"]."' disabled=disabled placeholder='Description'>
					<input class='form_new form_new_amend' id='dialer_altphone$i' name='dialer_altphone$i' value='".$dataarr["altphone$i"]."' disabled=disabled placeholder='##########'>

					<a href=# class='btn btn-default' onclick='dialerDelAlt($i,$this->varid);return false;'><i class='fa fa-minus'></i></a>
					<a href=# class='btn btn-default' onclick='dialAlternateNumber($this->varid,\"".$dataarr["altphone$i"]."\",kstychDialer[\"mDialerState\"],\"\",0);return false;'><i class='fa fa-phone'></i></a>
				</p>";
			}
			else if($nextempty=="")$nextempty=$i;
		}

		if($nextempty!="")
		{
			$data.="<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Alternate $nextempty: </label>
				<input class='form_new form_new_amend' id='dialer_altphone_lbl_$nextempty' name='dialer_altphone_lbl_$nextempty' value='' placeholder='Description'>
				<input class='form_new form_new_amend' id='dialer_altphone$nextempty' name='dialer_altphone$nextempty' value='' placeholder='##########'><a href=# class='btn btn-default' onclick='dialerAddAlt($nextempty,$this->varid);return false;'><i class='fa fa-plus'></i></a>
			</p>";
		}

		$data.="</fieldset>
		<fieldset><legend class='new-recruit_legend'>Conf #</legend>
			<p style='clear:both'>
				<label class=label-small_new  style='width:25%;' title=''>Number : </label>
				<input type=text id=dialerConfNumberTxt class='form_new form_new_amend' value='' placeholder='Conference Call'><a href=# class='btn btn-default' onclick='dialerAddConfCall();return false;'><i class='fa fa-phone'></i></a>
			</p>
		</fieldset></div>";

		$data.="<script>
		var dialerdispoarray={};var dispoClassArray={};
		dialerdispoarray['']='';\n";

		$mastersdata=$gthis->getCompanyMaster($client);
		if(empty($mastersdata['dialerDispoList']))$mastersdata['dialerDispoList']=$gthis->HRCoreVars['dialerDispoList'];

		$dispoarr=explode("~",$mastersdata['dialerDispoList']);
		foreach($dispoarr as $dispo)
		{
			if(!empty($dispo))
			{
				$dispoprts=explode("|",$dispo);
				if(sizeof($dispoprts)>=3)
				{
					$data.="dialerdispoarray['$dispoprts[1]']='$dispoprts[2]';dispoClassArray['$dispoprts[0]']='$dispoprts[1]';";
				}
			}
		}

		$data.="
		function dialerDisoSelect()
		{
			if(dialerdispoarray)
			{
				var dispolist=[];
				for (var key in dialerdispoarray) {
						dispolist.push(key);
				}
				updateJSSelect('dialer_userstatus',dispolist);
			}
		}
		function dialerSubdisoSelect(dispo)
		{
			if(dialerdispoarray)
			{
				if(dialerdispoarray[dispo])
				{
					dispolist=dialerdispoarray[dispo].split(',');
					updateJSSelect('dialer_usersubstatus',dispolist);
				}
			}
		}
		dialerDisoSelect();

		function dialerUserStatusChange(code){
			if(code == 'Contacted'){
				$('#dialer_actionCode').html('<option value=\'\'></option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option>');
			}else if(code == 'Not Contacted'){
				$('#dialer_actionCode').html('<option value=\'\'></option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option>');
			}else{
				$('#dialer_actionCode').html('<option value=\'\'></option><option value=\'BV\'>BV - Borrower Visits The Branch</option><option value=\'CEREP\'>CEREP - Central Representation</option><option value=\'IC\'>IC - Incoming Call</option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRF\'>OCRF - Outgoing Call Reference</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option><option value=\'ONLN\'>ONLN - Online Payment by Customer</option><option value=\'PU\'>PU - Pick Up</option><option value=\'TCFR\'>TCFR - Telecalling Field Referal</option>');
			}
		}

		function dialerActionCodeChange(code){
			if(code == 'OCMO' || code == 'OCOF' || code == 'OCRS'){
				if($('#dialer_userstatus').val() == 'Contacted'){
					$('#dialer_resultCode').html('<option value=\'\'></option><option value=\'CB\'>CB - Customer asked for Call Back</option><option value=\'CEREP\'>CEREP - Central Representation Success</option><option value=\'DEAD\'>DEAD - Dead</option><option value=\'LM\'>LM - Left Message With 3rd Party</option><option value=\'PTP\'>PTP - Promise To Pay</option><option value=\'PV\'>PV - Paid as per Customer but req Verification</option><option value=\'RTP\'>RTP - Refused To Pay</option><option value=\'TPC\'>TPC - Third Party Contactable</option><option value=\'FU\'>FU - Follow Up</option>');
				}else if($('#dialer_userstatus').val() == 'Not Contacted'){
					$('#dialer_resultCode').html('<option value=\'\'></option><option value=\'NCIN\'>NCIN - Not Contactable Invalid No</option><option value=\'NCNR\'>NCNR - Not Contactable Not Reachable</option><option value=\'NCRG\'>NCRG - Not Contactable Ringing</option><option value=\'NCSO\'>NCSO - Not Contactable Switched Off</option><option value=\'NCWN\'>NCWN - Not Contactable Wrong No</option><option value=\'SKIP\'>SKIP - Skip</option><option value=\'FU\'>FU - Follow Up</option>');						
				}else{
					$('#dialer_resultCode').html('<option value=\'\'></option><option value=\'CB\'>CB - Customer asked for Call Back</option><option value=\'CEREP\'>CEREP - Central Representation Success</option><option value=\'DEAD\'>DEAD - Dead</option><option value=\'LM\'>LM - Left Message With 3rd Party</option><option value=\'NCIN\'>NCIN - Not Contactable Invalid No</option><option value=\'NCNR\'>NCNR - Not Contactable Not Reachable</option><option value=\'NCRG\'>NCRG - Not Contactable Ringing</option><option value=\'NCSO\'>NCSO - Not Contactable Switched Off</option><option value=\'NCWN\'>NCWN - Not Contactable Wrong No</option><option value=\'PTP\'>PTP - Promise To Pay</option><option value=\'PV\'>PV - Paid as per Customer but req Verification</option><option value=\'RTP\'>RTP - Refused To Pay</option><option value=\'SKIP\'>SKIP - Skip</option><option value=\'TPC\'>TPC - Third Party Contactable</option><option value=\'FU\'>FU - Follow Up</option>');
				}
			}else{
				$('#dialer_resultCode').html('<option value=\'\'></option><option value=\'BP\'>BP - Broken Promise</option><option value=\'CB\'>CB - Customer asked for Call Back</option><option value=\'CEREP\'>CEREP - Central Representation Success</option><option value=\'DEAD\'>DEAD - Dead</option><option value=\'LM\'>LM - Left Message With 3rd Party</option><option value=\'NC\'>NC - NC</option><option value=\'NCIN\'>NCIN - Not Contactable Invalid No</option><option value=\'NCNR\'>NCNR - Not Contactable Not Reachable</option><option value=\'NCRG\'>NCRG - Not Contactable Ringing</option><option value=\'NCSO\'>NCSO - Not Contactable Switched Off</option><option value=\'NCWN\'>NCWN - Not Contactable Wrong No</option><option value=\'OT\'>OT - Others Including Refusal to Pay</option><option value=\'PD\'>PD - Paid Atleast 1 Full EMI</option><option value=\'PTP\'>PTP - Promise To Pay</option><option value=\'PV\'>PV - Paid as per Customer but req Verification</option><option value=\'RTP\'>RTP - Refused To Pay</option><option value=\'SETLD\'>SETLD - Settled</option><option value=\'SKIP\'>SKIP - Skip</option><option value=\'TPC\'>TPC - Third Party Contactable</option><option value=\'FU\'>FU - Follow Up</option>');
			}
		}

		// Function for additional field as per result action code - by YASHWANT on 03042017
		function dialerResultCodeChange(code){
			if(code == 'CB' || code == 'LM' || code == 'TPC' || code == 'NCIN' || code == 'NCNR' || code == 'NCRG' || code == 'NCSO' || code == 'NCWN'){
				$('#dialer_nextActionCode').html('<option value=\'\'></option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option><option value=\'TCFR\'>TCFR - Telecalling Field Referal</option>');
			}else if(code == 'DEAD' || code == 'RTP' || code == 'SKIP'){
				$('#dialer_nextActionCode').html('<option value=\'\'></option><option value=\'TCFR\'>TCFR - Telecalling Field Referal</option>');
			}else if(code == 'PTP'){
				$('#dialer_nextActionCode').html('<option value=\'\'></option><option value=\'BV\'>BV - Borrower Visits The Branch</option><option value=\'CEREP\'>CEREP - Central Representation</option><option value=\'ONLN\'>ONLN - Online Payment by Customer</option><option value=\'PU\'>PU - Pick Up</option><option value=\'UPI\'>UPI</option>');
			}else if(code == 'PV'){
				$('#dialer_nextActionCode').html('<option value=\'\'></option><option value=\'BV\'>BV - Borrower Visits The Branch</option><option value=\'CEREP\'>CEREP - Central Representation</option><option value=\'IC\'>IC - Incoming Call</option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRF\'>OCRF - Outgoing Call Reference</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option><option value=\'ONLN\'>ONLN - Online Payment by Customer</option><option value=\'TCFR\'>TCFR - Telecalling Field Referal</option>');
			}else{
				$('#dialer_nextActionCode').html('<option value=\'\'></option><option value=\'BV\'>BV - Borrower Visits The Branch</option><option value=\'CEREP\'>CEREP - Central Representation</option><option value=\'IC\'>IC - Incoming Call</option><option value=\'OCMO\'>OCMO - Outgoing Call Mobile</option><option value=\'OCOF\'>OCOF - Outgoing Call Office</option><option value=\'OCRF\'>OCRF - Outgoing Call Reference</option><option value=\'OCRS\'>OCRS - Outgoing Call Residence</option><option value=\'ONLN\'>ONLN - Online Payment by Customer</option><option value=\'PU\'>PU - Pick Up</option><option value=\'TCFR\'>TCFR - Telecalling Field Referal</option>');			
			}

			if(code == 'PV'){
				$('#extraFields2').html('<p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Payment Mode: </label><input class=\'form_new form_new_amend\' id=\'dialer_paymentMode\' name=\'dialer_paymentMode\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Receipt No: </label><input class=\'form_new form_new_amend\' id=\'dialer_receiptNo\' name=\'dialer_receiptNo\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Collection Amount: </label><input class=\'form_new form_new_amend\' id=\'dialer_collectionAmount\' name=\'dialer_collectionAmount\' style=\'width:70%\'></p><p style=\'clear:both;position:relative\'><label class=label-small_new  style=\'width:25%;\'>Collection Date: </label><input class=\'form_new form_new_amend datetimepicker_dthr kstych_init\' id=\'dialer_collectionDate\' name=\'dialer_collectionDate\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Cheque No: </label><input class=\'form_new form_new_amend\' id=\'dialer_chequeNo\' name=\'dialer_chequeNo\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Transaction No: </label><input class=\'form_new form_new_amend\' id=\'dialer_transactionNo\' name=\'dialer_transactionNo\' style=\'width:70%\'></p>');
				$(function () {
					$('#dialer_collectionDate').datetimepicker({
						sideBySide:true,
						format:'YYYY-MM-DD HH:mm',
						useCurrent:false,
					});
				});
			}else{
				$('#extraFields2').html('');
			}
		}

		// Function for additional field as per next action code - by YASHWANT on 03042017
		function dialerNextActionCodeChange(code){
			if(code == 'TCFR'){ //code == 'PU'
				$('#extraFields').html('<p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>PU / TCFR: </label><input class=\'form_new form_new_amend\' id=\'dialer_puTcfr\' name=\'dialer_puTcfr\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Agency Code: </label><input class=\'form_new form_new_amend\' id=\'dialer_agencyCode\' name=\'dialer_agencyCode\' style=\'width:70%\'></p>');
			}else{
				$('#extraFields').html('');
			}
//Next action code BV fields same as PU is only for Delhi collection server
                       if(code == 'PU'){
//			if(code == 'PU'){
				$('#extraFields3').html('<p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>PU Contact Person Name: </label><input class=\'form_new form_new_amend\' id=\'dialer_contactPersonName\' name=\'dialer_contactPersonName\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>PU Contact Person Mobile: </label><input class=\'form_new form_new_amend\' id=\'dialer_contactPersonMobile\' name=\'dialer_contactPersonMobile\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>EMI Amount: </label><input class=\'form_new form_new_amend\' id=\'dialer_emiAmount\' name=\'dialer_emiAmount\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>B&amp;P Amount: </label><input class=\'form_new form_new_amend\' id=\'dialer_bnpAmount\' name=\'dialer_bnpAmount\' style=\'width:70%\'></p><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Pickup Address Type: </label><select class=\'form_hrm_select\' id=\'dialer_pickupAddressType\' name=\'dialer_pickupAddressType\' style=\'width:70%\' onchange=\'addAlternateAddress($(this).val());\'><option></option><option value=\'Residence\'>Residence</option><option value=\'Office\'>Office</option><option value=\'Alternate\'>Alternate</option></select></p><div id=\'extraFields4\'></div><p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Payment Mode: </label><input class=\'form_new form_new_amend\' id=\'dialer_puPaymentMode\' name=\'dialer_puPaymentMode\' style=\'width:70%\'></p><p style=\'clear:both;position:relative\'><label class=label-small_new  style=\'width:25%;\'>Collection Date: </label><input class=\'form_new form_new_amend datetimepicker_dthr kstych_init\' id=\'dialer_puCollectionDate\' name=\'dialer_puCollectionDate\' style=\'width:70%\'></p>');
				$(function () {
					$('#dialer_puCollectionDate').datetimepicker({
						sideBySide:true,
						format:'YYYY-MM-DD HH:mm',
						useCurrent:false,
					});
				});
			}else{
				$('#extraFields3').html('');
			}
			if(code == 'UPI'){
				$('#extraFields4').html('<p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>VPA: </label><input class=\'form_new form_new_amend\' id=\'dialer_vpa\' name=\'dialer_vpa\' style=\'width:70%\'></p>');
			}else{
				$('#extraFields4').html('');
			}
		}
	
		function addAlternateAddress(value){
			var tempAddressResidence = '".$dataarr["residenceAddress"]." - ".$dataarr["residenceAddressZipCode"]."';
			var tempAddressOffice = '".$dataarr["officeAddress"]." - ".$dataarr["officeAddressZipCode"]."';
			var tempAddressAlternate = '';
			var tempFinalAddress = '';

			if(value == 'Residence'){
				tempFinalAddress = tempAddressResidence;
			}else if(value == 'Office'){
				tempFinalAddress = tempAddressOffice;
			}else if(value == 'Alternate'){
				tempFinalAddress = tempAddressAlternate;
			}
			$('#extraFields4').html('<p style=\'clear:both\'><label class=label-small_new  style=\'width:25%;\'>Pickup Address: </label><textarea id=\'dialer_altPickupAddress\' name=\'dialer_altPickupAddress\' style=\'width:70%\' maxlength=250>'+tempFinalAddress+'</textarea></p>');
		}
		</script>";

		// $data.="<p style='clear:both'>
		// <label class=label-small_new  style='width:25%;' title=''>PU / TCFR: </label>
		// <input class='form_new form_new_amend' id='dialer_puTcfr' name='dialer_puTcfr' style='width:70%'>
		// </p>";
		// $data.="<p style='clear:both'>
		// <label class=label-small_new  style='width:25%;' title=''>Agency Code: </label>
		// <input class='form_new form_new_amend' id='dialer_agencyCode' name='dialer_agencyCode' style='width:70%'>
		// </p>";

// Changes end - Commented below code for remove extra content from dialer feedback tab - by YASHWANT on 30032017
		
		if(empty($mastersdata['dialerCustomHTML']))$mastersdata['dialerCustomHTML']=$gthis->HRCoreVars['dialerCustomHTML'];
		
		$userdatahtml=str_replace("__EQ__","=",$mastersdata['dialerCustomHTML']);
		$userdatahtml=str_replace("__PLUS__","+",$userdatahtml);
		$userdatahtml=str_replace("{{varid}}",$this->varid,$userdatahtml);
		
		$data.=$userdatahtml;
//Log::info($userdatahtml);
		$data.="<hr></div>";
//Log::info($data);
		return $data;
	}
	function createCallsTab()
	{
		$data="<fieldset><legend class='new-recruit_legend'>Calls History</legend>";

		$data.="	<div class=custom1 style='width:100%;'>
	  <h2></h2>";
		
		$data.="<hr><br><table class='table kDataTable' cellpadding=0 cellspacing=0 border=0>
	  <thead><tr>
			<td>#</td>
	    <td class='table_hrm_heading_green'>Start</td>
	    <!--<td class='table_hrm_heading_green'>Length*</td>-->
	    <td class='table_hrm_heading_green'>User</td>
	    <td class='table_hrm_heading_green'>Number</td>
	    <td class='table_hrm_heading_green'>Type</td>
	    <!--<td class='table_hrm_heading_green'>Status*</td>-->
	    <td class='table_hrm_heading_green'>Contactability</td>
	    
	    <td class='table_hrm_heading_green'>Action Code</td>
	    <td class='table_hrm_heading_green'>Result Code</td>
	    <td class='table_hrm_heading_green'>Next Action Code</td>
	    <td class='table_hrm_heading_green'>Next Action Datetime</td>
	    <td class='table_hrm_heading_green'>RFD</td>

	    <!--<td class='table_hrm_heading_green'>SubDispo</td>
	    <td class='table_hrm_heading_green'>Callback</td>-->
	    <td class='table_hrm_heading_green'>Remarks</td>
	    <!--<td class='table_hrm_heading_green'>Custom</td>
	    <td class='table_hrm_heading_green'>BTTC</td>
	    <td class='table_hrm_heading_green'>Service vs Product</td>
	    <td class='table_hrm_heading_green'>Resolution</td>
	    <td class='table_hrm_heading_green'>Satisfaction</td>
	    <td class='table_hrm_heading_green'>Final Call Assessment</td>-->
	  </tr></thead>";
//Log::info($this->varid);	  
		$k=1;
		$alist=CRMCallArchive::where('crm_id','=',$this->varid)->where('ts_Close','>','0')->orderBy("created_at","DESC")->get();
		foreach($alist as $aline)
		{
			$userdata="";
			$userdataarr=json_decode($aline->userdata,true);
			if(is_array($userdataarr))foreach($userdataarr as $userdatavar=>$userdataval)
			{
				$userdata.="<tr><td>$userdataval</td></tr>";
			}
			if(trim($userdata)!="")$userdata="<table>".$userdata."</table>";

			$dispname="";if($aline->user_id>0){$tuser=User::find($aline->user_id);$dispname=$tuser->dispname();}

			$records = DB::table('records')->where('id','=',$aline->crm_id)->select('bttc','service_vs_product','resolution','satisfaction','final_call_assessment')->get();

			$data.="<tr>
				<td>$k</td>
				<td class=''>".date("Y-m-d H:i:s",strtotime($aline->created_at)-(Auth::user()->timezone*60))."</td>
				<!--<td class=''>".round($aline->callsec/1000,2)."</td>-->
				<td class=''>".$dispname."</td>
				<td class=''>".$aline->number."</td>
				<td class=''>".$aline->type."</td>
				<!--<td class=''>".$aline->status."</td>-->
				<td class=''>".$aline->userstatus."</td>
				<td class=''>".$aline->action_code."</td>
				<td class=''>".$aline->resultCode."</td>
				<td class=''>".$aline->nextActionCode."</td>
				<td class=''>".$aline->nextActionDateTime."</td>
				<td class=''>".$aline->rfd."</td>

				<!--<td class=''>".$aline->usersubstatus."</td>
				<td class=''>".date("Y-m-d H:i:s",strtotime($aline->usercallback)-(Auth::user()->timezone*60))."</td>-->
				<td class=''>".$aline->userremarks."</td>
				<!--<td class=''>".$userdata."</td>
				<td class=''>".$records[0]->bttc."</td>
				<td class=''>".$records[0]->service_vs_product."</td>
				<td class=''>".$records[0]->resolution."</td>
				<td class=''>".$records[0]->satisfaction."</td>
				<td class=''>".$records[0]->final_call_assessment."</td>-->
			</tr>";
			$k++;
		}
		$data.="</table>";
		$data.="</div>";
		$data.="</fieldset>";
		return $data;
	}

	function createMsgTab()
	{
       	$gthis=$this->gthis;

		$varid=$this->varid;
		$enable=$this->enable;
		$themehome=$this->themehome;
		$dataarr=$this->recruitdata["peopledata"];

		if($enable!="")
		{
			$enable = "";
		}
		else
		{
			$enable = "disabled";
		}

		$data="<div style='width:100%;float:left'>
			   <div style='width:49%;float:left'><fieldset><legend class='new-recruit_legend'>SMS</legend>
			   <p style='clear:both'>
                <label class=label-small_new  style='width:25%;' title=''>Lan: </label>
                <label class=label-small_new style='width:70%'>".$dataarr['lan']."</label>
                </p>
				<p style='clear:both'>
                <label class=label-small_new  style='width:25%;' title=''>Mobile: </label>
                <input class='form_new form_new_amend' id='sms_mobile' name='sms_mobile' style='width:50%' value='".$dataarr['mobile']."'>
                </p>
                <p style='clear:both'>
                <label class=label-small_new  style='width:25%;' title=''>EMI: </label>
                <input class='form_new form_new_amend' id='sms_emi' name='sms_emi' style='width:50%' value='".$dataarr['emi']."'>
                </p>
                <p style='clear:both'>
                <label class=label-small_new  style='width:25%;' title=''></label>
                <button onclick='callAPI();' id='smsButton' $enable>Send Message</button>
                </p></fieldset></div></div>

			<script>
			function callAPI(){
			var mobile 		= $('#sms_mobile').val();
			var custName 	= '".$dataarr['customerName']."';
			var lan 	= '".$dataarr['lan']."';
			var emi         = $('#sms_emi').val();

			$('#smsButton').attr('disabled', 'disabled');

            var postdata='mobile='+encodeURIComponent(mobile)+'&custName='+encodeURIComponent(custName)+'&lan='+encodeURIComponent(lan)+'&emi='+encodeURIComponent(emi);
				doAjax('record?action=sendAPI',postdata,'');
		}
		</script>";

		return $data;

	}
	
	// Trails tab function - by YASHWANT on 03052017
	function createTrailsTab()
	{
		$data="<fieldset><legend class='new-recruit_legend'>Trails</legend>";
			$data.="<div class=custom1 style='width:100%;'>";
				$data.="<table class='table kDataTable' cellpadding=0 cellspacing=0 border=0>
					<thead>
						<tr>
							<td class='table_hrm_heading_green'>#</td>
							<td class='table_hrm_heading_green'>Action Date</td>
							<td class='table_hrm_heading_green'>User ID</td>
							<td class='table_hrm_heading_green'>Action Code</td>
							<td class='table_hrm_heading_green'>Result Code</td>
							<td class='table_hrm_heading_green'>Next Action Code</td>
							<td class='table_hrm_heading_green'>Next Action Date Time</td>
							<td class='table_hrm_heading_green'>RFD</td>
							<td class='table_hrm_heading_green'>Remark</td>
							<td class='table_hrm_heading_green'>Bucket Code / Field</td>
							<td class='table_hrm_heading_green'>Special Code</td>
						</tr>
					</thead>";
				$lan = DB::table('records')->where('id',$this->varid)->first();
				$alist = DB::table('trails')->where('lan',$lan->lan)->get();
				$k=1;
				foreach($alist as $aline)
				{
					$userdata="";
					$userdataarr=json_decode($aline->userdata,true);
					if(is_array($userdataarr))foreach($userdataarr as $userdatavar=>$userdataval)
					{
						$userdata.="<tr><td>$userdataval</td></tr>";
					}
					if(trim($userdata)!="")$userdata="<table>".$userdata."</table>";

					//$dispname="";if($aline->user_id>0){$tuser=User::find($aline->user_id);$dispname=$tuser->dispname();

					$records = DB::table('records')->where('id','=',$aline->crm_id)->select('bttc','service_vs_product','resolution','satisfaction','final_call_assessment')->get();

					$data.="<tr>
							<td>$k</td>
							<!--<td>".date("Y-m-d H:i:s",strtotime($aline->action_date)-(Auth::user()->timezone*60))."</td>-->
							<td>".date("d-m-Y",strtotime($aline->action_date))."</td>
							<td>".$aline->user_id."</td>
							<td>".$aline->action_code."</td>
							<td>".$aline->result_code."</td>
							<td>".$aline->next_action_code."</td>
							<td>".date("d-m-Y H:i",strtotime($aline->next_action_time))."</td>
							<td>".$aline->rfd."</td>
							<td>".$aline->remark."</td>
							<td>".$aline->bucket_code."</td>
							<td>".$aline->special_code."</td>
						</tr>";
					$k++;
				}
			$data.="</table>";
			$data.="</div>";
		$data.="</fieldset>";
		return $data;
	}

	// Address tab function - by YASHWANT on 03052017
	function createAddressTab()
	{
		$data="<fieldset><legend class='new-recruit_legend'>Address</legend>";
			$data.="<div class=custom1 style='width:100%;'>";
				$data.="<table class='table kDataTable' cellpadding=0 cellspacing=0 border=0>
					<thead>
						<tr>
							<td class='table_hrm_heading_green'>#</td>
							<td class='table_hrm_heading_green'>Address Type</td>
							<td class='table_hrm_heading_green'>Contact Person</td>
							<td class='table_hrm_heading_green'>Address 1</td>
							<td class='table_hrm_heading_green'>Address 2</td>
							<td class='table_hrm_heading_green'>Address 3</td>
							<td class='table_hrm_heading_green'>Address 4</td>
							<td class='table_hrm_heading_green'>Area</td>
							<td class='table_hrm_heading_green'>Landmark</td>
							<td class='table_hrm_heading_green'>City</td>
							<td class='table_hrm_heading_green'>Zip</td>
							<td class='table_hrm_heading_green'>State</td>
							<td class='table_hrm_heading_green'>Mobile</td>
							<td class='table_hrm_heading_green'>Email</td>
						</tr>
					</thead>";
				$lan = DB::table('records')->where('id',$this->varid)->first();
				$alist = DB::table('address')->where('lan',$lan->lan)->get();
				$k=1;
				foreach($alist as $aline)
				{
					$userdata="";
					$userdataarr=json_decode($aline->userdata,true);
					if(is_array($userdataarr))foreach($userdataarr as $userdatavar=>$userdataval)
					{
						$userdata.="<tr><td>$userdataval</td></tr>";
					}
					if(trim($userdata)!="")$userdata="<table>".$userdata."</table>";

					//$dispname="";if($aline->user_id>0){$tuser=User::find($aline->user_id);$dispname=$tuser->dispname();}

					$records = DB::table('records')->where('id','=',$aline->crm_id)->select('bttc','service_vs_product','resolution','satisfaction','final_call_assessment')->get();

					$data.="<tr>
							<td>$k</td>
							<td>".$aline->address_type."</td>
							<td>".$aline->contact_person."</td>
							<td>".$aline->address_1."</td>
							<td>".$aline->address_2."</td>
							<td>".$aline->address_3."</td>
							<td>".$aline->address_4."</td>
							<td>".$aline->area."</td>
							<td>".$aline->landmark."</td>
							<td>".$aline->city."</td>
							<td>".$aline->zip."</td>
							<td>".$aline->state."</td>
							<td>".$aline->mobile."</td>
							<td>".$aline->email."</td>
						</tr>";
					$k++;
				}
			$data.="</table>";
			$data.="</div>";
		$data.="</fieldset>";
		return $data;
	}

	function createAppointmentTab()
	{
		$data="<fieldset><div style='width:100%;float:left'>";

		$data.="<p style='clear:both'></p>
		<p id='Appntresults'></p>";

		$data.="<div style='width:49%;float:left'><fieldset><legend class='new-recruit_legend'>Cust Info</legend>";
		$data.="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=''>CustomerName: </label>
		<input class='form_new form_new_amend' id='CustomerName' name='CustomerName'>
		</p>";	
		$data.="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=''>AppntLocation: </label>
		<input class='form_new form_new_amend' id='AppntLocation' name='AppntLocation'>
		</p>";
		$data.="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=''>AppntTime: </label>
		<input class='form_new form_new_amend timepicker_dthr' id='AppntTime' name='AppntTime'>
		</p>";
		
		$data.="<p style='clear:both'>
		<input type='button' class='btn btn-green' value='Appointment' id='appointmentsenddata' onclick='appointmentData();return false;'>
		</p>";
		
	  $data.="</fieldset></div>
	  <div style='width:49%;float:left'><fieldset><legend class='new-recruit_legend'></legend>";
	  $data.="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=''>Address: </label>
		<input class='form_new form_new_amend' id='Address' name='Address'>
		</p>";
		$data.="<p style='clear:both;position:relative'>
		<label class=label-small_new  style='width:25%;' title=''>AppntDate: </label>
		<input class='form_new form_new_amend datetimepicker_dthr' id='AppntDate' name='AppntDate'>
		</p>";
		$data.="<p style='clear:both'>
		<label class=label-small_new  style='width:25%;' title=''>ContactPerson: </label>
		<input class='form_new form_new_amend' id='ContactPerson' name='ContactPerson'>
		</p>";
		$data.="<p style='clear:both'>
		<input type='hidden' value='<?php echo $this->mobile; ?>' id='Phone' name='Phone'>
		</p>";

	  $data.="</fieldset></div>";
	  $data.="</div>";
	  $data.="</fieldset>";

	  $data.="
            <script>
            function appointmentData()
            {

                var CustomerName = $('#CustomerName').val();
                var AppntLocation = $('#AppntLocation').val();
                var AppntTime = $('#AppntTime').val();
                var Address = $('#Address').val();
                var AppntDate = $('#AppntDate').val();
                var ContactPerson = $('#ContactPerson').val();
                var Phone = $('Phone').val();

                var postdata='CustomerName='+encodeURIComponent(CustomerName)+'&AppntLocation='+encodeURIComponent(AppntLocation)+'&AppntTime='+encodeURIComponent(AppntTime)+'&Address='+encodeURIComponent(Address)+'&AppntDate='+encodeURIComponent(AppntDate)+'&ContactPerson='+encodeURIComponent(ContactPerson)+'&Phone='+encodeURIComponent(Phone);
					doAjax('record?action=Appointment',postdata,'Appntresults');
            }
            </script>";
        return $data;
	}


	//For Creating Questionaire contain
	function createQaireTab()
        {
		$varid=$this->varid;

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

		$question = explode(",",$question);

		$qid='';
		$auth_ques_count = 5;
		//$where = 'id = 1';
	
		$auth_questions=DB::table('authentication_questions')->inRandomOrder()->limit($auth_ques_count)->get();

		$questions =DB::table('question')->where('type','p')->whereIn('question_no',$question)->get();

		$data = "<style>.bordered {
    border: 1px solid #CCCCCC;
    border-radius: 6px 6px 6px 6px;
    -moz-border-radius: 6px 6px 6px 6px;
    -webkit-border-radius: 6px 6px 6px 6px;
    box-shadow: 0 1px 1px #CCCCCC;
}
.bordered table {
    border-spacing: 0;
    width: 600px;
    margin: 30px;
}        
.bordered thead tbody th:first-child {
    border-radius: 6px 0 0 0;
    -moz-border-radius: 6px 0 0 0;
    -webkit-border-radius: 6px 0 0 0;
}

.bordered thead tbody th:last-child {
    border-radius: 0 6px 0 0;
    -moz-border-radius: 0 6px 0 0;
    -webkit-border-radius: 0 6px 0 0;
}

.bordered thead tbody td:first-child, .bordered thead tbody th:first-child {
    border-left: medium none;
}

.bordered thead tbody td {
    background-color: #DCE9F9;
    background-image: -moz-linear-gradient(center top , #F8F8F8, #ECECEC);
    background-image: -webkit-gradient(linear, 0 0, 0 bottom, from(#F8F8F8), to(#ECECEC), color-stop(.4, #F8F8F8));
    border-top: medium none;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.bordered thead tbody td, .bordered thead tbody th {
    border-left: 1px solid #CCCCCC;
    border-top: 1px solid #CCCCCC;
    padding: 10px;
    text-align: left;
}
</style>
<fieldset><div style='font-size:10px'><!-- row-app -->
  <div class='row row-app'>
   <div class='col-xs-12'>
    <div class='col-separator col-separator-first box col-unscrollable'>
      <div class='col-table' style='padding-left: 13px;padding-right: 7px;'>

<div class='innerAll' style='background: #fff;'>
  <legend class='task_legend'>Authentication Questions<i class='pull-right' id='authArea'><i class='glyphicon glyphicon-plus-sign'></i></i></legend>

  <div id='form-group' class='col-xs-8'>
    <div class='filterable table-responsive panel panel-default' id='auth_question'>
      <table class='table table-hover table-striped table-bordered' border='1'  style='margin: 0;border-color:#FFFFFF;-moz-border-radius:5px;-webkit-border-radius:25px;'> 
        <thead class='panel-info'>
          <tbody>";//print_r($auth_questions);die();
           foreach($auth_questions as $key=> $question)
	{//print_r($question);die();
           $data.="<tr>
              <td>Q.".($key+1)." ".$question->question."
	<input type='hidden' value='".$question->question."' id='questText_".$question->id."'>
	<input type='hidden' value='".$key."' id='authKey_".$question->id."'>
</td>
              <td align='left'>";
                for($i=1;$i<=4;$i++){ 
                 $authopt_no = 'opt_'.$i;
                if($question->$authopt_no != '')
		{
                $data.="<label class='radio-inline options'  data-rad='".$question->id."' style='font-size:10px;align:left'>
                <input type='radio' class='authQuestion' id='opt_".$question->id.$i."' name='authopt_".$question->id."' style='margin:0;'>&nbsp;&nbsp;".$question->$authopt_no."</label>&nbsp;";
                }
                }
              $data.="</td>
            </tr>";
            }
	$data.="
          </tbody>
        </thead>
      </table>
    </div>
  </div>
  <div class='container'>
    <input type=button id='submit'  class='btn btn-danger' value='Submit' style=' margin: 5px 0 5px 660px;'>
  </div>
  <hr style='clear:both;' />

  <legend class='task_legend'>Primary Questions</legend>

  <div id='primary_ques' class='primary_ques'>";
        foreach($questions as $key=> $primary_question){
	$data.="
	<div class='row' id='subParent".$primary_question->question_no."' data-parent='".$primary_question->question_no."' style='border:solid #D3D3D3 2px;border-radius:5px;margin-top:5px'>
	<div class='col-md-4'>";
	
	if($key%2!=0)
	{
		$data.="<div class='panel panel-warning panel-heading' id='parentColorDiv".$primary_question->question_no."' style='background-color:#FFFFFF;cursor:pointer'>";
	}
	else
	{
		$data.="<div class='panel panel-warning panel-heading' id='parentColorDiv".$primary_question->question_no."' style='background-color:#e6e5ef;cursor:pointer'>";
	}
        $data.="<div class='question' data-ques='".$primary_question->question_no."' style='margin: 5px 0;'><b>Q.".$primary_question->question_no." ".$primary_question->questions."</b>
<input type='hidden' value='".$primary_question->questions."' id='questText_".$primary_question->question_no."'>
</div>
        <div class='options_div' id='options_div".$primary_question->question_no."'>";

          for($i=1;$i<=10;$i++)
	   { 
           $opt_no = 'opt_'.$i;
          if($primary_question->$opt_no != '')
	  {
	$data.="
          <label class='options radio-inline' data-ques='".$primary_question->question_no."' data-ans='".$i."'  id='label".$primary_question->question_no.$i."' style='font-size:10px'>
          <input type='radio' id='opt_".$primary_question->question_no.$i."' name='opt_".$primary_question->question_no."' style='margin:0; padding:0;'>&nbsp;&nbsp;".$primary_question->$opt_no."</label><br />";
          }
          }
	$data.="
          <textarea class='remarks form-control' name='remark".$primary_question->question_no."' id='remark".$primary_question->question_no."' style='border: 1px solid #cccccc;' cols='2' rows='2'></textarea>
          <input type='hidden' id='level".$primary_question->question_no."' name='level".$primary_question->question_no."' value='1'>
	  <input type='hidden' id='levelVal".$primary_question->question_no."' value='".$primary_question->question_no."'>
        </div>
	 </div>";
	if($key==0){
	$data.="<input type='hidden' id='parent".$primary_question->question_no."' name='parent1' value='".$qid."'>";}
	else
	{	
	  $data.="<input type='hidden' id='parent".$primary_question->question_no."' name='parent1".$primary_question->question_no."' value='".$primary_question->question_no."'>";
	}
$data.="
        </div>
	<div class='col-md-8' id='childs".$primary_question->question_no."'></div>
	</div>
";
        }
$data.="
    <hr style='clear:both;padding: 4px 0 2px;' />
    <input type='hidden' id='questionDateTime'  value=''>
    <input type='button' class='btn btn-success' value='Save' id='submitQuestionAire'>
  </div>

</div>

<script>
  $(document).ready(function(){

    var submitVar=0;
    var auth_ques_count = '".$auth_ques_count."';
    var questionArray = {};
    var authQuestionArray = {};

    $('.options_div').hide();
    $('#authArea').hide();
    $('input:radio:checked').prop('checked', false);
	
    var count=0;

    $('#auth_question').on('click', '.options', function(){
     if(count==0)
	document.getElementById('questionDateTime').value='".date("Y-m-d H-i-s")."';

	var authQues = $(this).data('rad');
	var authKey = $('#authKey_'+authQues).val();

	authQuestionArray['auth_'+authKey]={}; 
	authQuestionArray['auth_'+authKey]['auth_ques'] = $('#questText_'+authQues).val();
	authQuestionArray['auth_'+authKey]['auth_opt'] = $(this).text();

     count++;
});

    $('#submit').click(function(){
      if ($('.authQuestion[type=radio]:checked').length == auth_ques_count) {  
        $('#form-group').hide();
        $('#authArea').show();
        $('#submit').hide();
        $('.authQuestion').attr('disabled','disabled');
	submitVar++;
      }
      else {
       alert('Please answer all authentication questions'); 
      }
    });
       
    $('#primary_ques').on('click', '.question', function(){
	if ($('.authQuestion[type=radio]:checked').length == auth_ques_count  && submitVar!=0) {
	var ques = $(this).data('ques');
      $('#options_div' + ques).toggle();
      }
      else {
        alert('Please answer all authentication questions and submit all');
      }
    });

   var radCount=0;

    $('#primary_ques').on('click', '.options', function(){
      var ques = $(this).data('ques');
      var ans = $(this).data('ans');
   
	var priParentQues;

	if(parseInt($('#level'+ques).val())==1)
          {
		var element = $(this).parent().parent().parent().parent();
		priParentQues = element.attr('data-parent');
		
		questionArray['Q-'+priParentQues] = {};
	
		questionArray['Q-'+priParentQues]['prim_ques'] = $('#questText_'+ques).val();
                questionArray['Q-'+priParentQues]['prim_response']=$(this).text();
	
		questionArray['Q-'+priParentQues]['prim_txt'] = '';
	
		$('#remark'+ques).keyup(function() {
		questionArray['Q-'+priParentQues]['prim_txt']=$(this).val();
    		});
		
		var hideRadioElement = $(this).parent();
                var countLabel = hideRadioElement.children().size();

		var radEleId = hideRadioElement.attr('id');

		var labels = document.getElementById(radEleId).querySelectorAll('label');

		questionArray['Q-'+priParentQues]['fol_ques'] = '';
                questionArray['Q-'+priParentQues]['fol_response']='';
                questionArray['Q-'+priParentQues]['fol_txt']='';

		questionArray['Q-'+priParentQues]['sec_ques'] = '';
                questionArray['Q-'+priParentQues]['sec_response']='';
                questionArray['Q-'+priParentQues]['sec_txt']='';

		radCount++;
	  }

	 if(parseInt($('#level'+ques).val())==2)
          {
          	var element = $(this).parent().parent().parent().parent().parent().parent();
                priParentQues = element.attr('data-parent');
		
		questionArray['Q-'+priParentQues]['fol_ques'] = $('#questText_'+ques).val();
                questionArray['Q-'+priParentQues]['fol_response']=$(this).text();

		questionArray['Q-'+priParentQues]['fol_txt']='';

		$('#remark'+ques).keyup(function() {
                questionArray['Q-'+priParentQues]['fol_txt']=$(this).val();
                });
	
		var setAttrElement = $(this).parent().parent().parent();
		setAttrElement.attr('for','active');
	
		var hideElement = $(this).parent().parent().parent().parent();
                var countDiv = hideElement.children().size();

		for(var s=0;s<countDiv;s++)
		{
			var childEle = hideElement.children()[s];

			if(childEle.getAttribute('for') != 'active')
				document.getElementById(childEle.id).style.display='none';
				
		}
	
		questionArray['Q-'+priParentQues]['sec_ques'] = '';
                questionArray['Q-'+priParentQues]['sec_response']='';
                questionArray['Q-'+priParentQues]['sec_txt']='';

		
          }

	  if(parseInt($('#level'+ques).val())==3)
          {
                var element = $(this).parent().parent().parent().parent().parent().parent().parent().parent().parent();
                priParentQues = element.attr('data-parent');
		
		questionArray['Q-'+priParentQues]['sec_ques'] = $('#questText_'+ques).val();
                questionArray['Q-'+priParentQues]['sec_response']=$(this).text();

		questionArray['Q-'+priParentQues]['sec_txt']='';

		$('#remark'+ques).keyup(function() {
                questionArray['Q-'+priParentQues]['sec_txt']=$(this).val();
                });

		var setAttrElement = $(this).parent().parent().parent();
                setAttrElement.attr('for','active');
        
                var hideElement = $(this).parent().parent().parent().parent();
                var countDiv = hideElement.children().size();

                for(var s=0;s<countDiv;s++)
                {
                        var childEle = hideElement.children()[s];

                        if(childEle.getAttribute('for') != 'active')
                                document.getElementById(childEle.id).style.display='none';
                                
                }
          }

	if(!$('#label'+ques+ans).is(':disabled')) {
        loadQuestions(ques, ans);
      }
    });

    function loadQuestions(ques, ans) {
      var level = parseInt($('#level'+ques).val());
      var next_level = level+1;
      var parent_id = '".$qid."';

	if(level==1)
	{
		prev_ques='';
	}
	
      var levelVar = parseInt($('#levelVal'+ques).val());

     <!-- $('#options_div'+prev_ques).attr('style','display:none');-->
      $('#options_div'+$('#parent'+level).val()+' input[type=radio]').attr('disabled','disabled');
      $.ajax({
        url: '/questionare/'+ques+'/'+ans+'/'+next_level,
        error: function() {
          $('#childs'+ques).html('<p></p>');
        },
        dataType: 'html',
        success: function(data) {


          $('#childs'+ques).html(data);
	
        var parentColor = document.getElementById('parentColorDiv'+ques).getAttribute('style');
	
	for(var c=0;c<=4;c++){
	var colorDiv = document.getElementById('childs'+ques).getElementsByClassName('childDiv')[c];

	if(colorDiv!=undefined)
	colorDiv.setAttribute('style',parentColor);
	}
        }
      });
		
     	prev_ques = ques;
    }

    $('#authArea').click(function(){
      $('#form-group').toggle();
    });

	$('#submitQuestionAire').click(function()
	{ 
	  if(radCount==0)
	   {
		alert('Please select some options first');
	    	return;
	   }
	
	   if(submitVar!=0)
	   { 
		var postdata='varid='+$('#varid').val();
		postdata+='&questionDateTime='+$('#questionDateTime').val();
		postdata+='&questionArray='+JSON.stringify(questionArray);
		postdata+='&authQuestionArray='+JSON.stringify(authQuestionArray);
		doAjax('questionare',postdata,'createtaskdiv','ajaxMutex_recSaveData','singlethis','POST');
	   }
	  else
	   {
		alert('Please answer all authentication questions and submit all');
	   }
        });



  });

</script>     


      </div>
    </div>
  </div>
</div>
    </div></fieldset>";
	return $data;	

	}

	//QuestionAire History
	function createQaireHistTab()
	{
		$user_id = Auth::user()->username;
		$cust_id = $this->recruitdata["peopledata"]["clientcode"];
		$data="";

		$bulkCallID = DB::table("questionaire_details")->where('user_id','=',$user_id)->where('cust_id','=',$cust_id)->orderBy('id','desc')->select('call_id')->distinct()->get();
		
dy>
		$custIdArr = array();
		foreach($bulkCallID as $key=> $callID){
		
		$questionAirDetails = DB::table("questionaire_details")->where('user_id','=',$user_id)->where('cust_id','=',$cust_id)->where('call_id','=',$callID->call_id)->select('*')->get();

		$questionAirSortDetails = $questionAirDetails[0];

		$data.="<a onclick='questionAireDiv".$key."()'><div class='panel panel-warning panel-body'>
		<caption><div>
		<div class='col-xs-4'><label class='col-xs-4'>Date/time</label><p class='col-xs-8'>".$questionAirSortDetails->question_time."</p></div>
		<div class='col-xs-4'><label class='col-xs-4'>User ID</label><p class='col-xs-8'>".$questionAirSortDetails->user_id."</p></div>
		<div class='col-xs-4'><label class='col-xs-4'>Mobile</label><p class='col-xs-8'>".$questionAirSortDetails->number."</p></div>
		</div></caption>
                <table class='table table-hover' id='questionAireTable".$key."' style='display:none'>
                <thead>
		<tr><th>Q.No</th>
		<th>Level</th>
		<th>Primary</th>
		<th>Followup</th>
		<th>Secondary</th>
		</tr>
		</thead><tbody>";

		foreach($questionAirDetails as $keys=> $questionAirDetail){
		if($keys%2==0)
		{
			$data.="<tr style='background-color:#e6e5ef'>";
		}
		else
		{
                        $data.="<tr style='background-color:#ffffff'>";
                }		
               $data.="<td>".$questionAirDetail->question."</td>
		<td>Question</td>
		<td>".$questionAirDetail->primary_question."</td>
		<td>".$questionAirDetail->followup_question."</td>
		<td>".$questionAirDetail->secondary_question."</td>
		</tr>";
		
		if($keys%2==0)
                {
                        $data.="<tr style='background-color:#e6e5ef'>";
                }               
                else
                {
                        $data.="<tr style='background-color:#ffffff'>";
                }

		$data.="<td>".$questionAirDetail->question."</td>
                <td>Response</td>
                <td>".$questionAirDetail->primary_response."</td>
                <td>".$questionAirDetail->followup_response."</td>
                <td>".$questionAirDetail->secondary_response."</td>
                </tr>";

		if($keys%2==0)
                {
                        $data.="<tr style='background-color:#e6e5ef'>";
                }               
                else
                {
                        $data.="<tr style='background-color:#ffffff'>";
                }

		$data.="<td>".$questionAirDetail->question."</td>
                <td>Text</td>
                <td>".$questionAirDetail->primary_text."</td>
                <td>".$questionAirDetail->followup_text."</td>
                <td>".$questionAirDetail->secondary_text."</td>
                </tr>";
		}

		$data.="
                </tbody></table></div></a>
		<script>
		function questionAireDiv".$key."(){
	
		var tabStyle".$key." = document.getElementById('questionAireTable".$key."').style.display;		
	
		if(tabStyle".$key."=='none')
		{
			document.getElementById('questionAireTable".$key."').style.display='block';
		}
		else
		{
                        document.getElementById('questionAireTable".$key."').style.display='none';
                }
			
}
		</script>
";
		}

//		$allQuestions = DB::table("questionaire_details")->whereIn('call_id', $custIdArr)->get(); 

		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;

		$record_id = $dataarr['id'];
		$recordsObj = DB::table('records')->select('mobile', 'client')->find($record_id);
		if(!empty($recordsObj))
		{
			$this->mobile = $recordsObj->mobile;
			$this->client = $recordsObj->client;
		}
		
		$data="";$i=1;$tabsdata='';$firsttab="active";

		if(Auth::check())
		{
// Changes start - Commented below code for disable dialer Files/Logs and Tasks tab - by YASHWANT on 30032017
				// 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();
				// }
// Changes end - Commented below code for disable dialer Files/Logs and Tasks tab - by YASHWANT on 30032017

			if(Auth::user()->moduleACL("Dialer",true,false,false))
			{
				$frm['Trails']["{{id}} {{firstname}}"][]=array();  // Trails tab - by YASHWANT on 03052017
				$frm['Address']["{{id}} {{firstname}}"][]=array();  // Address tab - by YASHWANT on 03052017
				$frm['Feedback']["{{id}} {{firstname}}"][]=array();
				$frm['CallHistory']["{{id}} {{firstname}}"][]=array();
				$frm['SMS']["{{id}} {{firstname}}"][]=array();
				if($this->client == "FINCORP")				
				$frm['Appointment']["{{id}} {{firstname}}"][]=array();  //Amol: Appointment tab added for sms triggering to the customer

				/*if(Auth::user()->username =="B654321" || Auth::user()->username =="B12345"){
				$frm['QuestionAire']["{{id}} {{firstname}}"][]=array();
				$frm['QuestionAireHist']["{{id}} {{firstname}}"][]=array();}*/

                //$frm['QuestionnAire']["{{id}} {{firstname}}"][]=array();
                //$frm['QuestionnAireHistory']["{{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'||$tbname=='Appointment'||$tbname=='SMS')&&!$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] -1)."%; margin:0.5%;'>";}
						else if($rowval!=$flines[1][1]){$rowval=$flines[1][1];$fsetstr.="</div><div style='float:right;width:".(100/$flines[1][0] -1)."%; margin:0.5%'>";}

						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;

// Changes start - Commented below code for disable dialer Files/Logs and Tasks tab - by YASHWANT on 30032017
				//if($tbname=='Files/Logs'&&$isuser)$tabsdata.=$this->createFilesTab();
				//if($tbname=='Tasks'&&$edituser)$tabsdata.=$this->createTasksTab();
// Changes end - Commented below code for disable dialer Files/Logs and Tasks tab - by YASHWANT on 30032017

				if($tbname=='Trails')$tabsdata.=$this->createTrailsTab(); // Trails tab - by YASHWANT on 03052017
				if($tbname=='Address')$tabsdata.=$this->createAddressTab(); // Address tab - by YASHWANT on 03052017
				if($tbname=='Feedback')$tabsdata.=$this->createDispoTab();
				if($tbname=='CallHistory')$tabsdata.=$this->createCallsTab();
				if($tbname=='SMS')$tabsdata.=$this->createMsgTab();
				/*if(Auth::user()->username =="B654321" || Auth::user()->username =="B12345"){
				if($tbname=='QuestionAire')$tabsdata.=$this->createQaireTab();
				if($tbname=='QuestionAireHist')$tabsdata.=$this->createQaireHistTab();}*/

                if($tbname=='QuestionnAire')$tabsdata.=$this->createQaireTab();
                if($tbname=='QuestionnAireHistory')$tabsdata.=$this->createQaireHistTab();
                if($tbname=='Appointment')$tabsdata.=$this->createAppointmentTab();
				$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;

// Changes start - Commented below code for remove extra content from dialer popup - by YASHWANT on 30032017

	    $recordDetails = DB::table('records')->where('id','=',$varid)->select('*')->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].trim()).length)postdata+='&'+varsarr[i]+'='+encodeURIComponent($('#'+varsarr[i].trim()).val());
        //                     }
                          
        //                     doAjax('record?action=save',postdata,'createtaskdiv','ajaxMutex_recSaveData','singlethis','POST');
        //                 }
        //                 </script>";
            }

// Changes end - Commented below code for remove extra content from dialer popup - by YASHWANT on 30032017

            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);

}