91 lines
3.4 KiB
PHP
91 lines
3.4 KiB
PHP
|
<?php
|
||
|
|
||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||
|
|
||
|
function checkLogin()
|
||
|
{
|
||
|
$ci = &get_instance();
|
||
|
initDatabase();
|
||
|
if ($ci->session->userdata("loggedIn") == 1) {
|
||
|
|
||
|
return 1;
|
||
|
} else {
|
||
|
if (isset($_SERVER['REDIRECT_QUERY_STRING'])) {
|
||
|
$re = $_SERVER['REDIRECT_QUERY_STRING'];
|
||
|
} else {
|
||
|
redirect("login");
|
||
|
}
|
||
|
redirect("login/?url=" . $re);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function authenticateUser($email, $password, $re)
|
||
|
|
||
|
{
|
||
|
$ci = &get_instance();
|
||
|
$ci->db->where('username', $email);
|
||
|
$ci->db->where('password', $password);
|
||
|
$users = $ci->db->get('tbl_users')->row();
|
||
|
$FiscalYearID = $ci->db->where("status=1")->get("tbl_fiscalyear")->row()->fiscalyear_id;
|
||
|
$FiscalYear = $ci->db->where("status=1")->get("tbl_fiscalyear")->row();
|
||
|
$Branch = $ci->db->where("status=1")->get("tbl_branches")->row();
|
||
|
if ($users != '') {
|
||
|
$array = array(
|
||
|
'loggedIn' => "1",
|
||
|
'loggedInUser' => $email,
|
||
|
'loggedUser' => $users->username,
|
||
|
'FiscalYearID' => $FiscalYearID,
|
||
|
'FiscalYear' => $FiscalYear,
|
||
|
'BranchID' => $Branch->branch_id,
|
||
|
'Branch'=>$Branch,
|
||
|
'CompanyName' => $Branch->branch_name
|
||
|
);
|
||
|
if ($users->status == 1) {
|
||
|
$array['superAdmin'] = 1;
|
||
|
}
|
||
|
if ($users->status == 2) {
|
||
|
$array['superAdmin'] = 2;
|
||
|
}
|
||
|
if ($users->status == 3) {
|
||
|
$array['superAdmin'] = 3;
|
||
|
}
|
||
|
$ci->session->set_userdata($array);
|
||
|
redirect($re);
|
||
|
}
|
||
|
}
|
||
|
function initDatabase()
|
||
|
{
|
||
|
$ci = &get_instance();
|
||
|
$ci->db->trans_start();
|
||
|
if (!$ci->db->field_exists('voucher_color', 'tbl_vouchertypes')) {
|
||
|
// Create the column
|
||
|
$ci->db->query("ALTER TABLE tbl_vouchertypes ADD COLUMN voucher_color VARCHAR(255) AFTER voucher_alias");
|
||
|
$t = array();
|
||
|
$t[] = "truncate tbl_vouchertypes";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Contra', 'Contra', 'contra', '1','#cfbdec');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Payment', 'Payment', 'payment', '1','#b3a3d0');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Receipt', 'Receipt', 'receipt', '1','#e5b8cd');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Journal', 'Journal', 'journal', '1','#df979e');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Sales', 'Sales', 'sales', '1','#e2bb9b');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Creditnote', 'Creditnote', 'creditnote', '1','#bfb69b');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Purchase', 'Purchase', 'purchase', '1','#80ad8a');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Debitnote', 'Debitnote', 'debitnote', '1','#87bfae');";
|
||
|
$t[] = "INSERT INTO `tbl_vouchertypes` (`voucher_type`, `voucher_name`, `voucher_alias`, `status`,`voucher_color`) VALUES ('Reversing', 'Reversing', 'reversing', '1','#96ced7');";
|
||
|
// $ci->db->query($t);
|
||
|
|
||
|
|
||
|
foreach ($t as $query) {
|
||
|
$ci->db->query($query);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
$ci->db->trans_complete();
|
||
|
|
||
|
if ($ci->db->trans_status() === FALSE) {
|
||
|
// Handle transaction failure
|
||
|
} else {
|
||
|
// Transaction succeeded
|
||
|
}
|
||
|
}
|