Sh3ll
OdayForums


Server : Apache
System : Linux profile 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64
User : apache ( 48)
PHP Version : 8.0.28
Disable Function : NONE
Directory :  /var/www/html/mmishra/erp-22-05-2018/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/html/mmishra/erp-22-05-2018/controllers/erp_controller.php
<?php
date_default_timezone_set('Asia/Kolkata');

class erpController {
	
	public $model;
	
    public $app;			// get appn addressed by user 	($url[0])
	public $menu;			// get menu clicked by user 	($url[1])
	public $action;			// get action invoked by user	($url[2])
	public $tuple;			// get tuple targeted by user	($url[3])
	
	public $sessionID;		// current session id
	public $loginID;		// current user id
	public $userID;			// numeric id of login id
	public $userIP;			// ip address of remote system
 
	public $appURL;			// this is Request URI for log entry
	public $referer;		// requires for log entry, not mandatory
	public $moduleID 		= 1;											// current module id
	public $errorText		= "ERP reports system caught error message here..."; 	// requires to reflect system error in errorbar
	public $filterText		= "";											// used in toolbar to list filtered records
	public $editLock 		= "readonly";									// requires to define readonly form tags	 
    public $helpText 		= "* Marked fields are mandatory information."; // requires to present help information on menu items
    
	// enum variable declartion, used in various apps
	public $interfaces 		= ['I' => 'Input','O' => 'Output','C' => 'Configuration'];		// used in erpa app
	public $authModes		= ['LDB' => 'LDAP','MDB' => 'Database'];				// used to authenticate user either thru ldap or database

	public $programs 		= ['IT' => 'BTech (IT)','EC' => 'BTech (ECE)','WC' => 'MTech (WC)','SE' => 'MTech (SE)','RO' => 'MTech (RO)','HCI' => 'MTech (HCI)','IS' => 'MTech (IS)','BI' => 'MTech (BI)','MB' => 'MBA (IT)','PhDIT' => 'PhD (IT)','PhDEC' => 'PhD (EC)'];
	public $degreeLevels 	= ['UG' => 'Under Graduation','PG' => 'Post Graduation','PhD' => 'Doctoral'];
	public $aiTypes			= [1 => 'University', 2 => 'Board', 3 => 'Standalone Institute'];
	public $universitys		= [1 => 'Central University',2 => 'State Public University',3 => 'State Private University',4 => 'Deemed University-Government',5 => 'Deemed University-Government Aided',6 => 'Deemed University-Private',7 => 'Institute of National Importance',8 => 'Institute under State Legislature Act',9 => 'Central Open University',10 => 'State Open University',11 => 'State Private Open University',19 => 'Others'];
	
	public $documents		= ['PHO' => 'Photograph (30x50 mm, Passport)','SIG' => 'Signature (10x30 mm, B&W)','10M' => '10 Marksheet (Size 500KB)','10D' => '10 Degree (Size 500KB)','12M' => '12 Marksheet (Size 500KB)','12D' => '12 Degree (Size 500KB)','UGD' => 'UG Marksheet (Size 500KB)','UGM' => 'UG Degree (Size 500KB)','PGM' => 'PG Marksheet (Size 500KB)','PGD' => 'PG Degree (Size 500KB)','BTH' => 'Birth Certificate (Size 500KB)','AAD' => 'Aadhaar Card (Size 500KB)'];
	public $paymentModes	= ['POS', 'NEFT', 'DD'];
	public $currencys		= ['INR' => 'Indian Rupees','USD' => 'US Dollar']; 	// used in aaa app
    public $months			= ['JAN' => 'January','FEB' => 'February','MAR' => 'March','APR' => 'April','MAY' => 'May','JUN' => 'June','JUL' => 'July','AUG' => 'August','SEP' => 'September','OCT' => 'October','NOV' => 'November','DEC' => 'December']; // used in aaa app
    public $monthNames		= [1 => 'Jan',2 => 'Feb',3 => 'Mar',4 => 'Apr',5 => 'May',6 => 'Jun',7 => 'Jul',8 => 'Aug',9 => 'Sep',10 => 'Oct',11 => 'Nov',12 => 'Dec']; // used in aaa app
	
	// applicant related enum fields
	public $apcStatuss		= ['O' => 'Offered', 'I' => 'Interested', 'E' => 'Enrolled', 'W' => 'Withdrawn'];
    public $genders 		= ['M' => 'Male','F' => 'Female','T' => 'Transgender']; // used in aaa app
	public $bloodGroups		= ['O+','O-','A+','A-','B+','B-','AB+','AB-'];		// used in applicant form
    public $maritalStatuss 	= ['U' => 'Unmarried','M' => 'Married']; 			// used in aaa app
	public $pwdStatuss		= ['Y' => 'Yes','N' => 'No','X' => 'Not collected'];
    public $castes 			= ['OBC' => 'Other Backward Class','SC' => 'Schedule Caste','ST' => 'Schedule Tribe','OBCNC' => 'Other Backward Class - Non Creamy','GEN' => 'General','X' => 'Not available']; // used in aaa app
    public $professions 	= ['HOM' => 'Home Maker','BUS' => 'Business','GOV' => 'Government Service','PVT' => 'Private Service','PRF' => 'Self Employed Professional','RET' => 'Retired']; // used in aaa app
    public $categorys		= ['OBC' => 'Other Backward Class','SC' => 'Schedule Caste','ST' => 'Schedule Tribe','OBC-NCL' => 'Other Backward Class (Non Creamy)','GEN' => 'General','PWD' => 'Person with disability (PWD)','DASA' => 'Direct Admission of Student Abroad (DASA)','SAARC' => 'South Asian Association for Regional Cooperation (SAARC)','CIWG' => 'Children of Indian Workers in Gulf (CIWG)','X' => 'Not available']; // used in aaa app
    public $religions		= ['H' => 'Hinduism','I' => 'Islam','C' => 'Christianity','S' => 'Sikhism','B' => 'Buddhism','J' => 'Jainism','Z' => 'Zoroastrianism','O' => 'No religion/Others/Religion not specified','X' => 'Not available']; // used in aaa app

	public $areas			= [1 => 'Urban',2 => 'Rural'];
	public $districts		= [1 => 'Mon',3 =>'Leh (Ladakh)'];
	public $states			= [1 => 'Jammu and Kashmir',
							2 => 'Himachal Pradesh',
							3 => 'Punjab',
							4 => 'Chandigarh',
							5 => 'Uttrakhand',
							6 => 'Haryana',
							7 => 'Delhi',
							8 => 'Rajasthan',
							9 => 'Uttar Pradesh',
							10 => 'Bihar',
							11 => 'Sikkim',
							12 => 'Arunachal Pradesh',
							13 => 'Nagaland',
							14 => 'Manipur',
							15 => 'Mizoram',
							16 => 'Tripura',
							17 => 'Meghalaya',
							18 => 'Assam',
							19 => 'West Bengal',
							20 => 'Jharkhand',
							21 => 'Odisha',
							22 => 'Chhatisgarh',
							23 => 'Madhya Pradesh',
							24 => 'Gujarat',
							25 => 'Daman & Diu',
							26 => 'Dadra & Nagar Haveli',
							27 => 'Maharashtra',
							28 => 'Andhra Pradesh',
							29 => 'Karnataka',
							30 => 'Goa',
							31 => 'Lakshadweep',
							32 => 'Kerala',
							33 => 'Tamil Nadu',
							34 => 'Puducherry',
							35 => 'Andaman & Nicobar Islands',
							36 => 'Telangana'];
	public $nationalitys	= ['AF' => 'Afganistan',
							'AX' => 'Aland Islands',
							'AL' => 'Albania',
							'DZ' => 'Algeria',
							'AS' => 'American Samoa',
							'AD' => 'Andorra',
							'AO' => 'Angola',
							'AI' => 'Anguilla',
							'AQ' => 'Antarctica',
							'AG' => 'Antigua and Barbuda',
							'AR' => 'Argentina',
							'AM' => 'Armenia',
							'AW' => 'Aruba',
							'AU' => 'Australia',
							'AT' => 'Austria',
							'AZ' => 'Azerbaijan',
							'BS' => 'Bahamas',
							'BH' => 'Bahrain',
							'BD' => 'Bangladesh',
							'BB' => 'Barbados',
							'BY' => 'Belarus',
							'BE' => 'Belgium',
							'BZ' => 'Belize',
							'BJ' => 'Benin',
							'BM' => 'Bermuda',
							'BT' => 'Bhutan',
							'BO' => 'Bolivia',
							'BA' => 'Bosnia and Herzegovina',
							'BW' => 'Botswana',
							'BV' => 'Bouvet Island',
							'BR' => 'Brazil',
							'VG' => 'British Virgin Islands',
							'IO' => 'British Indian Ocean Territory',
							'BN' => 'Brunei Darussalam',
							'BG' => 'Bulgaria',
							'BF' => 'Burkina Faso',
							'BI' => 'Burundi',
							'KH' => 'Cambodia',
							'CM' => 'Cameroon',
							'CA' => 'Canada',
							'CV' => 'Cape Verde',
							'KY' => 'Cayman Islands',
							'CF' => 'Central African Republic',
							'TD' => 'Chad',
							'CL' => 'Chile',
							'CN' => 'China',
							'HK' => 'Hong Kong, SAR China',
							'MO' => 'Macao, SAR China',
							'CX' => 'Christmas Island',
							'CC' => 'Cocos (Keeling) Islands',
							'CO' => 'Colombia',
							'KM' => 'Comoros',
							'CG' => 'Congo (Brazzaville)',
							'CD' => 'Congo (Kinshasa)',
							'CK' => 'Cook Islands',
							'CR' => 'Costa Rica',
							'CI' => 'Côte d`Ivoire',
							'HR' => 'Croatia',
							'CU' => 'Cuba',
							'CY' => 'Cyprus',
							'CZ' => 'Czech Republic',
							'DK' => 'Denmark',
							'DJ' => 'Djibouti',
							'DM' => 'Dominica',
							'DO' => 'Dominican Republic',
							'EC' => 'Ecuador',
							'EG' => 'Egypt',
							'SV' => 'El Salvador',
							'GQ' => 'Equatorial Guinea',
							'ER' => 'Eritrea',
							'EE' => 'Estonia',
							'ET' => 'Ethiopia',
							'FK' => 'Falkland Islands (Malvinas)',
							'FO' => 'Faroe Islands',
							'FJ' => 'Fiji',
							'FI' => 'Finland',
							'FR' => 'France',
							'GF' => 'French Guiana',
							'PF' => 'French Polynesia',
							'TF' => 'French Southern Territories',
							'GA' => 'Gabon',
							'GM' => 'Gambia',
							'GE' => 'Georgia',
							'DE' => 'Germany',
							'GH' => 'Ghana',
							'GI' => 'Gibraltar',
							'GR' => 'Greece',
							'GL' => 'Greenland',
							'GD' => 'Grenada',
							'GP' => 'Guadeloupe',
							'GU' => 'Guam',
							'GT' => 'Guatemala',
							'GG' => 'Guernsey',
							'GN' => 'Guinea',
							'GW' => 'Guinea-Bissau',
							'GY' => 'Guyana',
							'HT' => 'Haiti',
							'HM' => 'Heard and Mcdonald Islands',
							'VA' => 'Holy See (Vatican City State)',
							'HN' => 'Honduras',
							'HU' => 'Hungary',
							'IS' => 'Iceland',
							'IN' => 'India',
							'ID' => 'Indonesia',
							'IR' => 'Iran, Islamic Republic of',
							'IQ' => 'Iraq',
							'IE' => 'Ireland',
							'IM' => 'Isle of Man',
							'IL' => 'Israel',
							'IT' => 'Italy',
							'JM' => 'Jamaica',
							'JP' => 'Japan',
							'JE' => 'Jersey',
							'JO' => 'Jordan',
							'KZ' => 'Kazakhstan',
							'KE' => 'Kenya',
							'KI' => 'Kiribati',
							'KP' => 'Korea (North)',
							'KR' => 'Korea (South)',
							'KW' => 'Kuwait',
							'KG' => 'Kyrgyzstan',
							'LA' => 'Lao PDR',
							'LV' => 'Latvia',
							'LB' => 'Lebanon',
							'LS' => 'Lesotho',
							'LR' => 'Liberia',
							'LY' => 'Libya',
							'LI' => 'Liechtenstein',
							'LT' => 'Lithuania',
							'LU' => 'Luxembourg',
							'MK' => 'Macedonia, Republic of',
							'MG' => 'Madagascar',
							'MW' => 'Malawi',
							'MY' => 'Malaysia',
							'MV' => 'Maldives',
							'ML' => 'Mali',
							'MT' => 'Malta',
							'MH' => 'Marshall Islands',
							'MQ' => 'Martinique',
							'MR' => 'Mauritania',
							'MU' => 'Mauritius',
							'YT' => 'Mayotte',
							'MX' => 'Mexico',
							'FM' => 'Micronesia, Federated States of',
							'MD' => 'Moldova',
							'MC' => 'Monaco',
							'MN' => 'Mongolia',
							'ME' => 'Montenegro',
							'MS' => 'Montserrat',
							'MA' => 'Morocco',
							'MZ' => 'Mozambique',
							'MM' => 'Myanmar',
							'NA' => 'Namibia',
							'NR' => 'Nauru',
							'NP' => 'Nepal',
							'NL' => 'Netherlands',
							'AN' => 'Netherlands Antilles',
							'NC' => 'New Caledonia',
							'NZ' => 'New Zealand',
							'NI' => 'Nicaragua',
							'NE' => 'Niger',
							'NG' => 'Nigeria',
							'NU' => 'Niue',
							'NF' => 'Norfolk Island',
							'MP' => 'Northern Mariana Islands',
							'NO' => 'Norway',
							'OM' => 'Oman',
							'PK' => 'Pakistan',
							'PW' => 'Palau',
							'PS' => 'Palestinian Territory',
							'PA' => 'Panama',
							'PG' => 'Papua New Guinea',
							'PY' => 'Paraguay',
							'PE' => 'Peru',
							'PH' => 'Philippines',
							'PN' => 'Pitcairn',
							'PL' => 'Poland',
							'PT' => 'Portugal',
							'PR' => 'Puerto Rico',
							'QA' => 'Qatar',
							'RE' => 'Réunion',
							'RO' => 'Romania',
							'RU' => 'Russian Federation',
							'RW' => 'Rwanda',
							'BL' => 'Saint-Barthélemy',
							'SH' => 'Saint Helena',
							'KN' => 'Saint Kitts and Nevis',
							'LC' => 'Saint Lucia',
							'MF' => 'Saint-Martin (French part)',
							'PM' => 'Saint Pierre and Miquelon',
							'VC' => 'Saint Vincent and Grenadines',
							'WS' => 'Samoa',
							'SM' => 'San Marino',
							'ST' => 'Sao Tome and Principe',
							'SA' => 'Saudi Arabia',
							'SN' => 'Senegal',
							'RS' => 'Serbia',
							'SC' => 'Seychelles',
							'SL' => 'Sierra Leone',
							'SG' => 'Singapore',
							'SK' => 'Slovakia',
							'SI' => 'Slovenia',
							'SB' => 'Solomon Islands',
							'SO' => 'Somalia',
							'ZA' => 'South Africa',
							'GS' => 'South Georgia and the South Sandwich Islands',
							'SS' => 'South Sudan',
							'ES' => 'Spain',
							'LK' => 'Sri Lanka',
							'SD' => 'Sudan',
							'SR' => 'Suriname',
							'SJ' => 'Svalbard and Jan Mayen Islands',
							'SZ' => 'Swaziland',
							'SE' => 'Sweden',
							'CH' => 'Switzerland',
							'SY' => 'Syrian Arab Republic (Syria)',
							'TW' => 'Taiwan, Republic of China',
							'TJ' => 'Tajikistan',
							'TZ' => 'Tanzania, United Republic of',
							'TH' => 'Thailand',
							'TL' => 'Timor-Leste',
							'TG' => 'Togo',
							'TK' => 'Tokelau',
							'TO' => 'Tonga',
							'TT' => 'Trinidad and Tobago',
							'TN' => 'Tunisia',
							'TR' => 'Turkey',
							'TM' => 'Turkmenistan',
							'TC' => 'Turks and Caicos Islands',
							'TV' => 'Tuvalu',
							'UG' => 'Uganda',
							'UA' => 'Ukraine',
							'AE' => 'United Arab Emirates',
							'GB' => 'United Kingdom',
							'US' => 'United States of America',
							'UM' => 'US Minor Outlying Islands',
							'UY' => 'Uruguay',
							'UZ' => 'Uzbekistan',
							'VU' => 'Vanuatu',
							'VE' => 'Venezuela (Bolivarian Republic)',
							'VN' => 'Viet Nam',
							'VI' => 'Virgin Islands, US',
							'WF' => 'Wallis and Futuna Islands',
							'EH' => 'Western Sahara',
							'YE' => 'Yemen',
							'ZM' => 'Zambia',
							'ZW' => 'Zimbabwe',
							'TB' => 'Tibet',
							'X'  => 'Not collected'];

	
	
	public function __construct($erpModel) {

        $this->model 			= $erpModel;				// initialize variables
		$this->model->tupleID	= $this->tuple;
		
		$this->appURL 			= $_SERVER["REQUEST_URI"];	// this is Request URI for log entry
		$this->referer 			= $_SERVER["HTTP_REFERER"];	// requires for log entry, not mandatory
		$this->userIP 			= $this->getIP(); 			// requires in log entry			
		$this->filterText 		= $_POST['filterText'];

		if (isset($_SESSION["sessionID"])) {
			$this->loginID 		= $_SESSION["loginID"];		// current user id
			$this->sessionID	= $_SESSION["sessionID"];	// current session id
			$this->moduleID 	= $_SESSION["moduleID"];	// current module id
		} else {
			$this->loginID		= "";						// initialize login id
			$this->sessionID	= "";						// initialize session id
			$this->moduleID 	= 1;						// default module id
			$this->errorText	= "ERP session starts with login here... <i class='far fa-hand-point-down'></i>&nbsp;&nbsp;"; 
		}
	
		// maintain erp activity log for inner contents
		if ($this->loginID && strpos($this->appURL, 'inner')) {
			$this->model->erpLog($this->loginID, $this->userIP, $this->appURL, $this->referer);
		}

		$this->setSession();	// initialize session
    }

    public function __destruct() {
        // echo $erpModel->sqlCommand;//'Destroying: ', $this->moduleID, PHP_EOL;
        // log sql operation on corresponding table
        // call $erpModel->erpSql($sql);
		// print("Thanks.");
    }

	// User authentication and group identification
	public function setSession() {
		if ($_POST['uid'] && $_POST['pwd']) {
			$uid 	= filter_var(trim($_POST['uid']), FILTER_SANITIZE_STRING);
			$pwd	= trim($_POST['pwd']);

			// check for administrative blocking of user account
			if ($this->model->checkAbuser($this->userIP, $uid) == TRUE) {
				$this->errorText = "Your system is blocked <i class='fas fa-ban'></i> under abuser category. Please contact 'erp.support@iiita.ac.in'.";
			} else {
				$token = $this->erpLogin($uid, $pwd);
				switch ($token) {
					case "Disabled":
						$this->errorText = "Account administratively disabled <i class='fas fa-ban'></i>. Please contact authority.";
						break;
					case "OK":
						$this->loginID 			= $uid;
						$this->sessionID 		= base64_encode($this->loginID .'-'. $this->userIP .'-'. date("Y-m-d- h:i:s"));
						$_SESSION["loginID"] 	= $this->loginID;
						$_SESSION["sessionID"] 	= $this->sessionID;
						$_SESSION["moduleID"] 	= $this->moduleID;								
						//start current session
						$this->errorText = $this->model->openSession($this->sessionID, $this->loginID, $this->userIP);
						
						header("Location: /");
						break;
					default:
						$this->errorText = "Incorrect user credentials <i class='fas fa-ban'></i>. Please try again.";
				}
			}
		}	
	}
	
	function getIP() {
		$header_checks = array(
			'HTTP_X_COMING_FROM',
			'HTTP_CLIENT_IP',
			'HTTP_PRAGMA',
			'HTTP_XONNECTION',
			'HTTP_CACHE_INFO',
			'HTTP_XPROXY',
			'HTTP_PROXY',
			'HTTP_PROXY_CONNECTION',
			'HTTP_VIA',
			'HTTP_COMING_FROM',
			'HTTP_X_FORWARDED_FOR',
			'HTTP_X_FORWARDED',
			'HTTP_X_CLUSTER_CLIENT_IP',
			'HTTP_FORWARDED_FOR',
			'HTTP_FORWARDED',
			'HTTP_X-FORWARDED_HOST',
			'ZHTTP_CACHE_CONTROL',
			'REMOTE_ADDR'
		);

		foreach ($header_checks as $key) {
			if (array_key_exists($key, $_SERVER) === true) {
				foreach (explode(',', $_SERVER[$key]) as $ip) {
					$ip = trim($ip);
					//filter the ip with filter functions
					if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
						return $ip;
					}
				}
			}
		}
	}

	function erpLogin($uID, $pwd) {
		$authMode 			= $this->model->getAuthMode($uID);
		switch ($authMode) {
			case 'LDB':
				//$ds 	= ldap_connect("ldaps://172.31.1.41:636");
				$ds 	= ldap_connect("ldap://172.31.1.41:389");
				ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
		
				$a 		= ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$uID");
				$b 		= ldap_get_entries($ds, $a);
				$dn 	= $b[0]["dn"];
				$str 	= ldap_bind($ds, $dn, $pwd) ? "OK" : "XX";
				ldap_close($ds);
				break;
			case 'MDB':
				$str 	= $this->model->dbAuth($uID, $pwd) ? "OK" : "XX";
				break;
			default:
				$str 	= "Disabled";
		}

		return $str;
	}

	public function erpLogout() {
		$this->errorText = $this->model->closeSession($this->sessionID, $this->loginID);
		
		unset($_SESSION["loginID"]);
		unset($_SESSION["sessionID"]);

		session_destroy();

		$this->loginID 		= '';
		$this->sessionID 	= '';
		
		header("Location: /");				
	}
	
	public function erpAbout() {
		include "erp_about.inc";
	}

	// change password in ldap
	public function managePasswd($action, $loginID) {
		if ($action == 'reset') {
			$pwd1 = $_POST["passwd1"];
			$pwd2 = $_POST["passwd2"];

			if ($pwd1 && ($pwd1 == $pwd2)) {
				//$ds = ldap_connect("ldaps://172.31.1.41:636");
				$ds = ldap_connect("ldap://172.31.1.41:389");
				ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
				$q = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "(&(uid=$loginID)(objectclass=posixAccount))");
				$info = ldap_get_entries($ds, $q);
        		$dn = $info[0]["dn"];
	
				if ($info["count"] > 0) {
               		ldap_bind($ds, "cn=Manager,dc=iiita,dc=ac,dc=in","\$dollfinn");
       				//$pwd1 = 'iiita' . rand(111,999);
       				//$pwd = '{CRYPT}' . crypt($pwd1);
       				$pwd = "{SHA}" . base64_encode(pack("H*", sha1($pwd1)));
       				$info1["userPassword"] = "$pwd";
	
        			if (ldap_modify($ds, $dn, $info1)) {
						$this->errorText = "Congrats... Password changed successfully.";
					} else {
						$this->errorText = "Error: Could not modify LDAP record.";
					}
				} else {
					$this->errorText = "Error: Record does not exist in LDAP database.";
				}
				ldap_close($ds);
			} else {
				$this->errorText = "Error: Password does not match, please try again.";
			}
		}		
	}

	// ldap entry configuration
	public function erpLdap($ou, $loginID, $action) {
		//$ds = ldap_connect("ldaps://172.31.1.41:636");
		$ds = ldap_connect("ldap://172.31.1.41:389");
		ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
		$a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$loginID");
		$b = ldap_get_entries($ds, $a);
		$dn = $b[0]["dn"];
		if ($dn) {
			$str = "DN: " .$b[0]["dn"];
			
		} else {
			$str = "Entry for $uID does not exist in LDAP.";
		}
		//$token = (ldap_bind($ds, $dn, $pwd) ? TRUE : FALSE);
		ldap_close($ds);
		
		return $str;

	}
	
	// mail service configuration
	public function erpMailer($email, $subject, $body) {
		require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'../includes/PHPMailerAutoload.php');
		

        // SMTP needs accurate times, and the PHP time zone MUST be set
        // This should be done in your php.ini, but this is how to do it if you don't have access to that
        date_default_timezone_set('Asia/Kolkata');

        // Create a new PHPMailer instance
        $mail = new PHPMailer();

        // Tell PHPMailer to use SMTP
        $mail->isSMTP();

        // Tell PHPMailer to use SMTP
        $mail->isHTML(true);
        
		// Set the hostname of the mail server
        $mail->Host = 'smtp.gmail.com';

        // Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
        $mail->Port = 465;

        // Set the encryption system to use - ssl (deprecated) or tls
        $mail->SMTPSecure = 'ssl';

        // Whether to use SMTP authentication
        $mail->SMTPAuth = true;

        // Username to use for SMTP authentication - use full email address for gmail
        $mail->Username = "icure@iiita.ac.in";

        // Password to use for SMTP authentication
        $mail->Password = "irp@2015";

        // Set who the message is to be sent from
        $mail->setFrom('erp.support@iiita.ac.in', 'ERP@IIITA');

        // Set an alternative reply-to address
        $mail->addReplyTo('erp.support@iiita.ac.in', 'ERP@IIITA');

        // Set who the message is to be sent to
        $mail->addAddress($email, $email);
        // $mail->addBCC('mmishra@iiita.ac.in', 'Mmishra');

        // Set the subject line
        $mail->Subject = $subject;

        $mail->Body = $body . "
		<br><br>
		With good wishes,
		<br><br><br>
		ERP@IIITA
		<br><br>
		<hr>
		Login at https://erp.iiita.ac.in using LDAP credentials for updated information.
		<br><br>
		(Automailer)";
		$mail->WordWrap = 75;

        // send the message, check for errors
        if (!$mail->send()) {
                return $mail->ErrorInfo;
        } else {
                return 'OK';
        }

	}
	
	// sms service configuration
	public function erpSMS($cellNo, $msg) {
		/*Send SMS using PHP*/    
    		
		$authKey 		= "128590ABuBtPSnuJ5805a5ff";	//Your authentication key
		$mobileNumber 	= $cellNo;						//Multiple mobiles numbers separated by comma
		$senderId 		= "IIITAL";						//Sender ID,While using route4 sender id should be 6 characters long.
		$message 		= urlencode($msg);				//Your message to send, Add URL encoding here.
		$route 			= '4'; //"default";				//Define route 
		
		//Prepare you post parameters
		$postData = array(
			'authkey' => $authKey,
			'mobiles' => $mobileNumber,
			'message' => $message,
			'sender' => $senderId,
			'route' => $route
		);
    
		//API URL
		$url = "https://control.msg91.com/api/sendhttp.php";
    
		// init the resource
		$ch = curl_init();
		curl_setopt_array($ch, array(
			CURLOPT_URL => $url,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => $postData
			//,CURLOPT_FOLLOWLOCATION => true
		));
    

		//Ignore SSL certificate verification
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    
		//get response
		$output = curl_exec($ch);
    
		//Print error if any
		if(curl_errno($ch)) $output = 'Error:' . curl_error($ch);
		curl_close($ch);
		
		return $output;
	}
	
	// online pg service integratiob
	public function erpIPG() {
		$HASHING_METHOD = 'sha512'; // md5,sha1
		$ACTION_URL = "https://secure.ebs.in/pg/ma/payment/request/";

		// This post.php used to calculate hash value using md5 and redirect to payment page.
		if(isset($_POST['secretkey']))
			$_SESSION['SECRET_KEY'] = $_POST['secretkey'];
		else
			$_SESSION['SECRET_KEY'] = '020bc4ca9304d76f471b03213f73d035'; //set your secretkey here
	
		$hashData = $_SESSION['SECRET_KEY'];

		unset($_POST['secretkey']);
		unset($_POST['submitted']);

		ksort($_POST);
		foreach ($_POST as $key => $value){
			if (strlen($value) > 0) {
				$hashData .= '|'.$value;
			}
		}
		if (strlen($hashData) > 0) {
			$secureHash = strtoupper(hash($HASHING_METHOD, $hashData));
		}

		$str = "<html>
		<body onLoad='document.payment.submit();'>
		<h3>Please wait, redirecting to process payment..</h3>
		<form action='" .$ACTION_URL. "' name='payment' method='POST'>";
		
		foreach($_POST as $key => $value) {
			$str .= "<input type='hidden' value='" .$value. "' name='" .$key. "'/>";
		}
		$str .= "<input type='hidden' value='" .$secureHash. "' name='secure_hash'/>";
	
		return $str;
	}

	// erp backup generation
	public function erpBackup($action, $db) {
		//exec('mysqldump --user=... --password=... --host=... DB_NAME > /path/to/output/file.sql');
		
		$DBUSER 	= "erp";
		$DBPASSWD 	= "erpa2018";
		$DATABASE 	= "erp_core";

		//header("Cache-Control: public");
    	//header("Content-Description: File Transfer");
    	//header("Content-Disposition: attachment; filename=".$file."");
    	//header("Content-Transfer-Encoding: binary");
    	//header("Content-Type: binary/octet-stream");
    	//readfile($file);
    
    	$filename 	= "erp-db-backup-" . date("d-m-Y") . ".sql.gz";
		$mime 		= "application/x-gzip";
		$cmd 		= "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";   

		header("Content-Type: " .$mime);
		header("Content-Disposition: attachment; filename='" .$filename. "'");
		passthru($cmd);

		return "Download database backup file.";
	}
	
	public function erpUpload() {
		// Check if image file is a actual image or fake image
		//$returnURL = "";
		if ($_POST['submit'] == 'UPLOAD') {
			//$returnURL 		= $_POST["returnURL"];
			$docID			= $_POST["docID"];
			$docCode		= $_POST["docCode"];
			$sourceFile		= basename($_FILES["fileToUpload"]["name"]);
			$uploadFile		= $ID. '-' .$certCode. '-' .$sourceFile;
			$targetFile 	= __DIR__. "/../uploads/" .$uploadFile;
			$extName	 	= strtolower(pathinfo(basename($_FILES["fileToUpload"]["name"]), PATHINFO_EXTENSION));
			
			$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
			if ($check !== false) {
				//$str = "File is an image - " . $check["mime"] . ".";
				// Check if file already exists
				if (file_exists($targetFile)) {
					$str = "Sorry, " .$sourceFile. " file already exists.";
				// Check file size
				} else if ($_FILES["fileToUpload"]["size"] > 900000) {
					$str = "Sorry, " .$sourceFile. " file is too large.";
				// Allow certain file formats
				} else if ($extName == "jpg" && $extName == "png" && $extName == "jpeg" && $extName == "gif") {
					$str = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
				// if everything is ok, try to upload file
				} else if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
						$str = basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
				} else {
					$str = "Sorry, there was an error uploading " .$sourceFile;
				}
				
			} else {
				$str = $sourceFile. " is not an image.";
			}
		} else {
			$str = "nothing to show.";
		}
		//$str .= "<br><br>
		//Go back <a href='' onclick=\"inner('" .$returnURL. "&certCode=" .$certCode. "&fileName=" .$upFile. "'); return false;\" title='More upload'><span class='button'><i class='fas fa-undo-alt'></i></span> </a> for more upload. &nbsp;&nbsp;";
		//header("Location: " .$returnURL);
		//$str .= " [" .$returnURL. "&fileName=" .$upFile. "]";
		
		return $str;
	}

	// online pdf generation
	public function erpPDF($str) {
		$pdf = new PDF('P', 'mm', 'A4');

		$pdf->SetDisplayMode(real, 'default');
		$pdf->AddPage();
		$pdf->SetTitle('ERP PDF Generator');
		$pdf->SetAuthor('IIIT-A');

		$pdf->SetFillColor(0,0,0);
		$pdf->Ln(10); //line Break
		$pdf->SetFont('Helvetica', 'U', 10);
		
		$pdf->Write(5, 'mmishra');
		//$pdf->Line(20, 45, 210-20, 45); // 20mm from each edge
		$pdf->Output('receipt.pdf', 'D');
	}
}

?>

ZeroDay Forums Mini