org seeting

This commit is contained in:
heama 2024-02-08 09:04:38 +05:30
parent fa52664f6b
commit ed734484b8
14 changed files with 668 additions and 169 deletions

16
.env
View File

@ -64,16 +64,16 @@ app.baseURL = 'http://localhost/donation/'
# database.tests.DBDriver = MySQLi
database.default.hostname = localhost
database.default.database = donor_management
database.default.username = root
database.default.password = ''
database.default.hostname = 119.18.54.85
database.default.database =venbaehn_donation
database.default.username = venbaehn_donor_be_usr1
database.default.password = 'e0jZ1BaWZT2V'
database.default.DBDriver = MySQLi
database.tests.hostname = localhost
database.tests.database = donor_management
database.tests.username = root
database.tests.password = ''
database.tests.hostname = l119.18.54.85
database.tests.database = venbaehn_donation
database.tests.username = enbaehn_donor_be_usr1
database.tests.password = 'e0jZ1BaWZT2V'
database.tests.DBDriver = MySQLi
#--------------------------------------------------------------------

View File

@ -50,10 +50,10 @@ class Database extends Config
*/
public array $tests = [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => '',
'password' => '',
'database' => ':memory:',
'hostname' => '119.18.54.85',
'username' => 'venbaehn_donor_be_usr1',
'password' => 'e0jZ1BaWZT2V',
'database' => 'venbaehn_donation',
'DBDriver' => 'SQLite3',
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
'pConnect' => false,

View File

@ -53,6 +53,8 @@ $routes->get("user_page/(:any)", "Users::user_page/$1");
$routes->post("insert_users", "Users::insert_users");
$routes->get("delete_user/(:any)", "Users::delete_user/$1");
$routes->get("activateUser/(:any)", "Users::activateUser/$1");
$routes->get('users/get_branches/(:num)', 'Users::get_branches/$1');
# Causes Routes
$routes->get("causes_list/", "Books::index");

View File

@ -36,112 +36,145 @@ class Business extends BaseController
{
helper('session');
$session_role = get_user_role();
if ($id === '0') {
$data['page_name'] = 'Add Organization';
$data['loged_user'] = $session_role;
$data['page_name'] = 'Add Organization';
$data['loged_user'] = $session_role;
$data['businesses'] = [];
$data['branches'] = [];
} else if ($id !== '0') {
$data['page_name'] = 'Edit Organization';
$data['page_name'] = 'Edit Organization';
$model = new BusinessModel();
$model->setTable('business');
// Fetch business details
$edit_user_details = $model->where(['business_id ' => $id])->first();
$data['businesses'] = $edit_user_details;
// Fetch branch details
$branchData = $model->getBranchesByBusinessId($id);
$data['branches'] = $branchData;
}
// echo '<pre>';
// print_r($data); die();
$this->render_page('business_form', $data);
}
## For inserting/updating details of business
public function insert_org()
{
helper('session');
$session_uid = get_logged_user_id();
$session_role = get_user_role();
$img = $this->request->getFile('bfile');
$business_id = $this->request->getPost('business_id');
$filePath = 'public/uploads/' . $this->request->getPost('bfile');
$fileName = $img->getName();
public function insert_org()
{
helper('session');
$session_uid = get_logged_user_id();
$session_role = get_user_role();
if($fileName !== ""){
$img = $this->request->getFile('bfile');
$filePath = 'public/uploads/' . $this->request->getPost('bfile');
$fileName = $img->getName();
if ($img->isValid() && !$img->hasMoved()) {
$img->move(ROOTPATH . 'public/uploads', $fileName);
}
if ($fileName !== "") {
if ($img->isValid() && !$img->hasMoved()) {
$img->move(ROOTPATH . 'public/uploads', $fileName);
}
$sign = $this->request->getFile('signature');
$business_id = $this->request->getPost('business_id');
$filePath = 'public/uploads/' . $this->request->getPost('signature');
$signFileName = $sign->getName();
if($signFileName !== ""){
if ($sign->isValid() && !$sign->hasMoved()) {
$sign->move(ROOTPATH . 'public/uploads', $signFileName);
}
}
$BusinessModel = new BusinessModel();
$data = [
'title' => $this->request->getPost('bname'),
'email' => $this->request->getPost('bmail'),
'mobile_no' => $this->request->getPost('bmobile'),
'address' => $this->request->getPost('baddress'),
'city' => $this->request->getPost('bcity'),
'state' => $this->request->getPost('bstate'),
'postal_code' => $this->request->getPost('bzip'),
'pan_no'=>$this->request->getPost('pan_no'),
'org_reg_no'=>$this->request->getPost('org_reg_no'),
'terms'=>$this->request->getPost('bterms'),
'80G'=>$this->request->getPost('80G'),
];
if($fileName !== "")
{
$data['business_logo'] = $fileName;
}
if($signFileName !== "")
{
$data['signature'] = $signFileName;
}
$business_id = $this->request->getPost('business_id'); // Get the business ID for update
if (empty($business_id)) {
// It's an insert operation
$data['isactive'] = 1;
$data['created_by'] = $session_uid;
$BusinessModel->insert($data);
} else {
// It's an update operation
if($session_role === 'sadmin'){
$isactive = $this->request->getPost('bcheckbox');
$data['isactive'] = ($isactive == 'on') ? 1 : 0; }
$data['updated_by'] = $session_uid;
$BusinessModel->update($business_id, $data);
}
if ($session_role === 'sadmin') {
return redirect()->route('org_list');
}else{
return redirect()->route('dashboard');
}
}
## For delete the business details (Which means inactive the details)
$sign = $this->request->getFile('signature');
$signFileName = $sign->getName();
if ($signFileName !== "") {
if ($sign->isValid() && !$sign->hasMoved()) {
$sign->move(ROOTPATH . 'public/uploads', $signFileName);
}
}
$BusinessModel = new BusinessModel();
$data = [
'title' => $this->request->getPost('bname'),
'email' => $this->request->getPost('bmail'),
'mobile_no' => $this->request->getPost('bmobile'),
'address' => $this->request->getPost('baddress'),
'city' => $this->request->getPost('bcity'),
'state' => $this->request->getPost('bstate'),
'postal_code' => $this->request->getPost('bzip'),
'pan_no' => $this->request->getPost('pan_no'),
'org_reg_no' => $this->request->getPost('org_reg_no'),
'terms' => $this->request->getPost('bterms'),
'80G' => $this->request->getPost('80G'),
];
if ($fileName !== "") {
$data['business_logo'] = $fileName;
}
if ($signFileName !== "") {
$data['signature'] = $signFileName;
}
$business_id = $this->request->getPost('business_id'); // Get the business ID for update
if (empty($business_id)) {
// It's an insert operation
$data['isactive'] = 1;
$data['created_by'] = $session_uid;
$businessId = $BusinessModel->insert($data);
// $this->insert_branch($businessId);
} else {
// It's an update operation
if ($session_role === 'sadmin') {
$isactive = $this->request->getPost('bcheckbox');
$data['isactive'] = ($isactive == 'on') ? 1 : 0;
}
$data['updated_by'] = $session_uid;
$BusinessModel->update($business_id, $data);
$businessId = $business_id;
}
// ... existing code ...
if (!empty($_POST['branchname'])) {
$branchNames = $_POST['branchname'];
$branchMobile = $_POST['mobile_no'];
$branchMail = $_POST['email'];
$branchAddress = $_POST['branchaddress'];
$branchIds = isset($_POST['id']) ? $_POST['id'] : [];
foreach ($branchNames as $key => $branchName) {
$branchId = isset($branchIds[$key]) ? $branchIds[$key] : null;
$branchData = [
'business_id' => $businessId,
'branch_name' => $branchName,
'mobile_no' => $branchMobile[$key],
'email' => $branchMail[$key],
'address' => $branchAddress[$key],
];
if (!empty($branchId)) {
// Update the existing branch
$db = \Config\Database::connect();
$db->table('business_branches')
->where('id', $branchId)
->update($branchData);
} else {
// Insert new branch
$db = \Config\Database::connect();
$db->table('business_branches')->insert($branchData);
}
}
}
// ... exis
// ... existing code ...
// Redirect based on user role
if ($session_role === 'sadmin') {
return redirect()->route('org_list');
} else {
return redirect()->route('dashboard');
}
}
## For delete the business details (Which means inactive the details)
public function delete_org($id)
{
helper('session');

View File

@ -90,8 +90,11 @@ class Customer extends BaseController
'email' => $this->request->getPost('cmail'),
'date_of_birth' => $dob,
'pan_no' => $this->request->getPost('pan_no'),
'adhar_no' => $this->request->getPost('adhar_no'),
'donor_type' => $this->request->getPost('DonorType'),
'org_name' => $this->request->getPost('org_name') !== '' || $this->request->getPost('org_name') !== null ? $this->request->getPost('org_name') : NULL,
'org_reg_details'=> $this->request->getPost('org_reg_Details'),
'address' => $this->request->getPost('address'),
'city' => $this->request->getPost('city'),
'state' => $this->request->getPost('state') ? $this->request->getPost('state') : $this->request->getPost('state_text'),
@ -101,8 +104,8 @@ class Customer extends BaseController
];
// print_r($data); die();
print_r($data);
// echo $this->db->getLastQuery();die();
$donor_id = $this->request->getPost('donor_id'); // Get the business ID for update
if (empty($donor_id)) {

View File

@ -48,64 +48,103 @@ class Users extends BaseController
$session_role = get_user_role();
$session_bid = get_business_id();
$session_uid = get_logged_user_id();
$data['business_details'] = $this->business_details();
if ($id === '0') {
$this->logger->info("Users: In Add page");
$data['page_name'] = 'Add User';
$business_details = $this->business_details();
$data['page_name'] = 'Add User';
$render_page_name = 'user_form';
$data['details'] = [];
} else if ($id !== '0') {
$data['branches'] = $this->getOrganizationBranches($session_bid);
// print_r($data);
} else {
$this->logger->info("Users: In Edit page");
$model = new UsersModel();
$model->setTable('users');
if (!empty($session_role)){
if (!empty($session_role)) {
switch ($session_role) {
case "sadmin":
case "sadmin":
$where = ['users.user_id' => $id, 'users.isactive !=' => NULL];
$edit_user_details = $model->where($where)->first();
$business_details = $this->business_details();
$render_page_name = 'user_form';
$data['page_name'] = 'Edit User';
$data['page_name'] = 'Edit User';
// Fetch organization branches for the selected organization
$data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
// print_r($data);die;
break;
case "admin":
case "admin":
$where = ['users.user_id' => $id, 'users.isactive =' => 1];
$edit_user_details = $model->where($where)->first();
$business_details = [];
$render_page_name = 'user_form';
$data['page_name'] = 'Edit User';
break;
case "manager":
$data['page_name'] = 'Edit User';
$data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
// print_r($branches);die;
break;
case "manager":
$where = ['users.user_id' => $id, 'users.isactive =' => 1];
$edit_user_details = $model->where($where)->first();
$business_details = [];
if($session_uid === $id && $session_role === "manager"){
$data['page_name'] = 'Edit User';
$edit_user_details = $model->where($where)->first();
if ($session_uid === $id && $session_role === "manager") {
$data['page_name'] = 'Edit User';
$data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
print_r($branches);die;
$render_page_name = 'user_form';
}else{
$data['page_name'] = 'Page Not Found';
} else {
$data['page_name'] = 'Page Not Found';
$render_page_name = 'pages_404';
}
break;
default:
$data['page_name'] = 'Page Not Found';
$render_page_name = 'pages_404';
$data['page_name'] = 'Page Not Found';
$render_page_name = 'pages_404';
}
}
$data['details'] = $edit_user_details;
}
$data['business_details'] = $business_details;
$data['session_bid'] = $session_bid;
$this->render_page($render_page_name, $data);
}
// Add the getOrganizationBranches method
public function getOrganizationBranches($businessId)
{
$db = db_connect();
$builder = $db->table('business_branches');
$branches = $builder->where('business_id', $businessId)->get()->getResultArray();
return $branches;
}
## For SuperAdmin Role business Dropdown displayed on Userpage.otherwise Hidden fields
public function business_details()
{
$model = new BusinessModel();
$model->setTable('business');
$business_details = $model->orderBy('business_id', 'DESC')->findAll();
// Fetch branches for all organizations
$branchModel = new BusinessModel();
$branchModel->setTable('business_branches');
$branches = $branchModel->findAll();
// Add branches to each business
foreach ($business_details as &$business) {
$business['branches'] = array_filter($branches, function ($branch) use ($business) {
return $branch['business_id'] == $business['business_id'];
});
}
return $business_details;
}
## For inserting/updating details of user
public function insert_users()
@ -181,8 +220,11 @@ class Users extends BaseController
$final_img_name = $existing_img_name;
//throw new \Exception("Testing Purpose File Details Not Available so i can't move it if you have existing filee means save it or your choice");
}
// $branch_id = $this->request->getPost('branch_id');
// $business_id = $this->request->getPost('business_id');
$data = [
'profile_picture' => $final_img_name,
'city' => $this->request->getPost('city'),
'state' => $this->request->getPost('state'),
@ -196,8 +238,11 @@ class Users extends BaseController
'date_of_birth' => NULL,
'address' => $this->request->getPost('address'),
'gender' => $this->request->getPost('gender'),
'business_id' => $business_id
'business_id' => $business_id,
'branch_id' => $this->request->getPost('branch_id') ?? $this->request->getPost('branch'),
];
// print_r($data);die;
if (empty($user_id)) {
// It's an insert operation
@ -318,5 +363,16 @@ class Users extends BaseController
return redirect()->route('user_list');
}
// Add a method to fetch organization branches based on the selected organization
public function get_branches($business_id)
{
$model = new BusinessModel();
$model->setTable('business_branches');
$branches = $model->where('business_id', $business_id)->findAll();
return json_encode($branches);
}
}

View File

@ -15,5 +15,14 @@ class BusinessModel extends Model
{
return $this->insert($data);
}
public function getBranchesByBusinessId($businessId)
{
return $this->db->table('business_branches')
->where('business_id', $businessId)
->get()
->getResultArray();
}
}
?>

View File

@ -10,7 +10,7 @@ class CustomerModel extends Model
protected $table = 'donor';
protected $primaryKey = 'donor_id ';
// protected $allowedFields = ['donor_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','profile_picture','date_of_birth','gender','mode','isactive','business_id'];
protected $allowedFields = ['donor_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','org_name','date_of_birth','pan_no','donor_type','isactive','business_id','created_by','updated_by'];
protected $allowedFields = ['donor_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','org_name','date_of_birth','pan_no','adhar_no','org_reg_details','donor_type','isactive','business_id','created_by','updated_by'];
public function insertCustomer($data)
{

View File

@ -5,7 +5,7 @@ class UsersModel extends Model
{
protected $table = 'users';
protected $primaryKey = 'user_id';
protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id','created_by','updated_by'];
protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','branch_id','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id','created_by','updated_by'];
public function saveData($data, $id = null)
{
@ -17,6 +17,15 @@ class UsersModel extends Model
return $this->update($id, $data);
}
}
}
public function getOrganizationBranches($businessId)
{
// Assuming your branches table is named 'branches'
$db = db_connect();
$builder = $db->table('business_branches');
$branches = $builder->where('business_id', $businessId)->get()->getResultArray();
return $branches;
}
}

View File

@ -1,3 +1,4 @@
<html>
<head>
@ -96,6 +97,92 @@
<?php } ?>
</div>
<!-- Existing form fields above this section -->
<div class="after-shipping-addr-add-more">
<hr />
<?php if (empty($branches)) : ?>
<!-- Display at least one set of branch fields when the array is empty -->
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="branchname" class="col-form-label">Branch Name<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="branchname" name="branchname[]" placeholder="Branch Name"required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="branchaddress" class="col-form-label">Branch Address<span class="text-danger"></span></label>
<input type="text" class="form-control" id="branchaddress" name="branchaddress[]" placeholder="Address (eg : 1234 Main St)"required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="mobile_no" class="col-form-label">Contact Person<span class="text-danger"></span></label>
<input type="number" class="form-control" id="mobile_no" name="mobile_no[]" placeholder="Contact Person"required data-parsley-type="number" maxlength="10" />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="email" class="col-form-label">Email<span class="text-danger"></span></label>
<input type="text" class="form-control" id="email" name="email[]" placeholder="Email" required/>
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<!-- Add hidden input for branch id -->
<input type="hidden" name="id[]" />
</div>
<?php else : ?>
<!-- Display branch fields for each branch in the $branches array -->
<?php foreach ($branches as $branch) : ?>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="branchname" class="col-form-label">Branch Name<span class="text-danger"></span></label>
<input type="text" class="form-control" id="branchname" name="branchname[]" value="<?= isset($branch['branch_name']) ? $branch['branch_name'] : '' ?>" placeholder="Branch Name"required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="branchaddress" class="col-form-label">Branch Address<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="branchaddress" name="branchaddress[]" value="<?= isset($branch['address']) ? $branch['address'] : '' ?>" placeholder="Address (eg : 1234 Main St)" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="mobile_no" class="col-form-label">Contact Person<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="mobile_no" name="mobile_no[]" value="<?= isset($branch['mobile_no']) ? $branch['mobile_no'] : '' ?>" placeholder="Contact Person" required data-parsley-type="number" maxlength="10" />/>
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="email" class="col-form-label">Email<span class="text-danger"></span></label>
<input type="email" class="form-control" id="email" name="email[]" value="<?= isset($branch['email']) ? $branch['email'] : '' ?>" placeholder="Email"required/>
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<!-- Add hidden input for branch id -->
<input type="hidden" name="id[]" value="<?= isset($branch['id']) ? $branch['id'] : '' ?>" />
</div>
<?php endforeach; ?>
<?php endif; ?>
<!-- Add more branches when clicking the "Add More Branches" button -->
<div class="form-group col-md-12 text-right m-b-0">
<a class="btn btn-success waves-effect waves-light mr-1 add-brnach-details">+ Add More Branches </a>
<a class="btn btn-danger waves-effect waves-light mr-1 remove-brnach-details">- Remove </a>
</div>
</div>
<!-- Remaining form fields below this section -->
<!-- Add more branches when clicking the "Add More Branches" button -->
<!-- <div class="form-group col-md-12 text-right m-b-0">
<a class="btn btn-success waves-effect waves-light mr-1 add-brnach-details">+ Add More Branches </a>
<a class="btn btn-danger waves-effect waves-light mr-1 remove-brnach-details">- Remove </a>
</div>
</div> -->
</div>
<div class="form-row">
<div class="form-group col-md-6">
@ -134,6 +221,7 @@
</div>
<br>
<?php } ?>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light mr-1" type="submit" id="submitBtn">Submit</button>
<button type="reset" class="btn btn-primary waves-effect mr-1">Reset</button><a href="<?= base_url() . "business_list"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
@ -186,4 +274,38 @@ function validateImage(input) {
img.src = URL.createObjectURL(image);
}
</script>
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
function addBranch(container) {
const branchSection = document.querySelector('.after-shipping-addr-add-more');
const clonedBranch = branchSection.cloneNode(true);
// Clear values in the cloned branch
clonedBranch.querySelectorAll('input, textarea').forEach(input => input.value = '');
container.parentNode.insertBefore(clonedBranch, container.nextSibling);
}
// Add more branches when clicking the "Add More Branches" button
document.addEventListener('click', function (event) {
if (event.target.classList.contains('add-brnach-details')) {
event.preventDefault();
const container = event.target.closest('.after-shipping-addr-add-more');
addBranch(container);
}
});
// Remove a branch when clicking the "Remove" button
document.addEventListener('click', function (event) {
if (event.target.classList.contains('remove-brnach-details')) {
event.preventDefault();
event.target.closest('.after-shipping-addr-add-more').remove();
}
});
});
</script>

View File

@ -36,11 +36,17 @@
<div class="invalid-feedback">Please provide.</div>
</div>
<div class="form-group col-md-4" id="org_name">
<div class="form-group col-md-4" id="org_reg">
<label for="csname" class="col-form-label">Organization Name<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="org_name_field" name="org_name" value="<?= isset($customer['org_name']) ? $customer['org_name'] : '' ?>" placeholder="Organization Name"/>
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-4" id="org_name">
<label for="csname" class="col-form-label">Organization Reg Details<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="org_reg_details" name="org_reg_Details" value="<?= isset($customer['org_reg_Details']) ? $customer['org_reg_Details'] : '' ?>" placeholder="Organization Reg details"/>
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-row">
@ -81,8 +87,13 @@
<div class="form-group col-md-4">
<label for="csname" class="col-form-label"><span class="contactPerson">Organization </span>PAN Number</label>
<input type="text" class="form-control" name="pan_no" value="<?= isset($customer['pan_no']) ? $customer['pan_no'] : '' ?>" placeholder="PAN Number" />
<input type="text" class="form-control" id="pan_no"name="pan_no" value="<?= isset($customer['pan_no']) ? $customer['pan_no'] : '' ?>" placeholder="PAN Number" />
</div>
<div class="form-group col-md-4" id="adhar_no_individual">
<label for="csname" class="col-form-label"><span class="contactPerson"> </span>Adhar Number</label>
<input type="text" class="form-control" id="adhar_no" name="adhar_no" value="<?= isset($customer['adhar_no']) ? $customer['adhar_no'] : '' ?>" placeholder="Adhar Number" />
</div>
</div>
<input type="hidden" id="donor_id" name="donor_id" placeholder="hidden for Donor id" value="<?= isset($customer['donor_id']) ? $customer['donor_id'] : '' ?>" />
@ -97,13 +108,13 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="baddress1" class="col-form-label">Address</label>
<textarea type="text" class="form-control" id="baddress1" name="address" placeholder="Address (eg : 1234 Main St)" style="width:202%"><?= isset($customer['address']) ? $customer['address'] : '' ?></textarea>
<textarea type="text" class="form-control" id="baddress1" name="address" placeholder="Address (eg : 1234 Main St)" style="width:202%" required><?= isset($customer['address']) ? $customer['address'] : '' ?></textarea>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="bcountry" class="col-form-label">Country</label>
<select class="form-control" id="bcountry" name="country">
<select class="form-control" id="bcountry" name="country"required>
<option value="<?= isset($customer['country']) ? $customer['country'] : '';?>"><?= isset($customer['country']) ? $customer['country'] : 'Choose your Country';?></option>
<?php foreach ($country_details as $value) { ?>
<option value="<?php echo $value['country_name']; ?>">
@ -117,17 +128,17 @@
<div class="form-group col-md-3">
<div id="billinput" style="display: block">
<label for="bistate" class="col-form-label">State</label>
<input type="text" class="form-control" id="bistate" name="state_text" placeholder="State" value="<?= isset($customer['state']) ? $customer['state'] : ''?>"/>
<input type="text" class="form-control" id="bistate" name="state_text"required placeholder="State" value="<?= isset($customer['state']) ? $customer['state'] : ''?>"/>
</div>
</div>
<div class="form-group col-md-3">
<label for="bcity" class="col-form-label">City</label>
<input type="text" class="form-control" id="bcity" name="city" value="<?= isset($customer['city']) ? $customer['city'] : '' ?>" placeholder="City" />
<input type="text" class="form-control" id="bcity" name="city" required value="<?= isset($customer['city']) ? $customer['city'] : '' ?>" placeholder="City" />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-3">
<label for="bzip" class="col-form-label">Postal Code</label>
<input type="text" class="form-control" id="bzip" name="zip" value="<?= isset($customer['postal_code']) ? $customer['postal_code'] : '' ?>" placeholder="Postal Code" pattern="\d*" maxlength="10" />
<input type="text" class="form-control" id="bzip" name="zip" required value="<?= isset($customer['postal_code']) ? $customer['postal_code'] : '' ?>" placeholder="Postal Code" pattern="\d*" maxlength="10" />
</div>
</div>
</div>
@ -141,6 +152,7 @@
</div>
<br>
<?php } ?>
<div class="form-group text-right m-b-0">
@ -174,22 +186,23 @@
});
</script>
<script>
function validateEmail(email) {
// Regular expression for a basic email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
function validateEmail(email) {
// Regular expression for a Gmail, Yahoo, or Hotmail email address validation
var emailPattern = /^[a-zA-Z0-9._%+-]+@(gmail\.com|yahoo\.com|hotmail\.com|email\.com)$/;
var emailInput = document.getElementById("cmail");
var validationMessage = document.getElementById("emailValidationMessage");
var emailInput = document.getElementById("cmail");
var validationMessage = document.getElementById("emailValidationMessage");
if (emailPattern.test(email)) {
validationMessage.textContent = "";
} else if (email == "") {
validationMessage.textContent = "";
} else {
validationMessage.textContent = "Invalid email address";
validationMessage.style.color = "red";
}
if (emailPattern.test(email)) {
validationMessage.textContent = "";
} else if (email == "") {
validationMessage.textContent = "";
} else {
validationMessage.textContent = "Invalid email address.";
validationMessage.style.color = "red";
}
}
</script>
<script>
function restriction(event) {
@ -206,6 +219,7 @@
$('#org_name').hide();
$('.contactPerson').hide();
$('#org_reg').hide();
let orgName = $('#org_name_field').val()
if(orgName !== '' && orgName !== null){
$('#org_name').show();
@ -225,16 +239,43 @@
if(DonorType === 'option2'){
$('#org_name').show();
$('#org_reg').show();
$('.contactPerson').show();
$('#adhar_no_individual').hide();
$('#org_name_field').prop('required', true);
$('#org_reg_details').prop('required',true);
$('#pan_no').prop('required', true); // Add this line to make PAN field required
}
else{
$('#adhar_no_individual').show();
$('#org_name').hide();
$('#org_reg').hide();
$('.contactPerson').hide();
$('#pan_no').prop('required', false); // Add this line to make PAN field required
}
})
});
$('#adhar_no').on('input', function(){
let adharNumber = $(this).val();
let adharPattern = /^\d{12}$/;
if(!adharPattern.test(adharNumber)){
$('#adhar_no').addClass('is-invalid');
} else {
$('#adhar_no').removeClass('is-invalid');
}
});
$('#pan_no').on('input', function(){
let panNumber = $(this).val();
let panPattern = /^[A-Z]{5}[0-9]{4}[A-Z]$/;
if(!panPattern.test(panNumber)){
$('#pan_no').addClass('is-invalid');
} else {
$('#pan_no').removeClass('is-invalid');
}
});
</script>
</script>

View File

@ -0,0 +1,11 @@
{
"folders": [
{
"path": "../.."
},
{
"path": "../../../vb_book"
}
],
"settings": {}
}

View File

@ -126,7 +126,7 @@
<div class="form-group col-md-6">
<label for="logo" class="col-form-label">Logo Image</label>
<input type="file" class="form-control" style="border: 0px !important; " id="logo"
name="slogo" placeholder="Logo Name"
name="slogo" placeholder="Logo Name" accept=".png, .jpg, .jpeg" onchange="checkFileFormat()"
value="<?= isset($details['logo']) ? $details['logo'] : '' ?>" />
</div>
<?php if (!empty($details['logo'])) { ?>
@ -139,7 +139,7 @@
<div class="form-group col-md-6">
<label for="favicon" class="col-form-label">Favicon</label>
<input type="file" class="form-control" style="border: 0px !important; " id="favic"
name="favicon" placeholder="Fav-icon Name"
name="favicon" placeholder="Fav-icon Name" accept=".png, .jpg, .jpeg" onchange="checkFileFormats()"
value="<?= isset($details['favicon']) ? $details['favicon'] : '' ?>" />
</div>
<?php if (!empty($details['favicon'])) { ?>
@ -273,4 +273,36 @@ document.getElementById('myForm').addEventListener('submit', function(event) {
$('#submitBtn').prop('disabled', true);
}
});
</script>
<script>
function checkFileFormat() {
var input = document.getElementById('logo');
var fileName = input.value;
var allowedFormats = ['.png', '.jpg', '.jpeg'];
if (fileName) {
var fileExtension = fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2);
if (allowedFormats.indexOf(fileExtension.toLowerCase()) === -1) {
alert('Please choose a valid image file (PNG, JPG, JPEG).');
input.value = ''; // Clear the file input to allow choosing a new file
}
}
}
</script>
<script>
function checkFileFormats() {
var input = document.getElementById('favic');
var fileName = input.value;
var allowedFormats = ['.png', '.jpg', '.jpeg'];
if (fileName) {
var fileExtension = fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2);
if (allowedFormats.indexOf(fileExtension.toLowerCase()) === -1) {
alert('Please choose a valid image file (PNG, JPG, JPEG).');
input.value = ''; // Clear the file input to allow choosing a new file
}
}
}
</script>

View File

@ -1,3 +1,11 @@
<div class="row">
<div class="col-lg-12">
<div class="card">
@ -11,25 +19,44 @@
<div class="form-row">
<?php if ($loggedin_person_role === 'sadmin') { ?>
<div class="form-group col-md-4">
<label for="business_id" class="col-form-label">Organization<span class="text-danger"></span></label>
<select id="business_id" name="business_id" class="form-control" required>
<option value="">Choose Organization</option>
<?php foreach ($business_details as $value) { ?>
<option value="<?php echo $value['business_id']; ?>" <?php if (isset($details['business_id']) && ($details['business_id'] === $value['business_id'])) echo "selected"; ?>>
<?php echo $value['title']; ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<div class="form-group col-md-3">
<label for="business_id" class="col-form-label">Organization<span class="text-danger">*</span></label>
<select id="business_id" name="business_id" class="form-control" required>
<?php foreach ($business_details as $business) { ?>
<option value="<?= $business['business_id']; ?>" <?= isset($details['business_id']) && ($details['business_id'] == $business['business_id']) ? 'selected' : '' ?>>
<?= $business['title']; ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="F" class="col-form-label">Organization Branches<span class="text-danger">*</span></label>
<select id="branch_id" name="branch_id" class="form-control" required>
<?php if (!empty($branches)) { ?>
<?php foreach ($branches as $branch) { ?>
<option value="<?= $branch['id']; ?>" <?= isset($details['branch_id']) && ($details['branch_id'] == $branch['id']) ? 'selected' : '' ?>>
<?= $branch['branch_name']; ?>
</option>
<?php } ?>
<?php } else { ?>
<option value="">No branches available</option>
<?php } ?>
</select>
</div>
<?php } ?>
<div class="form-group col-md-3">
<label for="email" class="col-form-label">Email<span class="text-danger">*</span></label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?= isset($details['email']) ? $details['email'] : '' ?>" required />
</div>
<?php if (empty($details)) { ?>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="password" class="col-form-label">Password<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="password" name="password" placeholder="Password" value="<?= isset($details['password']) ? $details['password'] : '' ?>" required />
</div>
@ -100,6 +127,28 @@
<input type="file" name="profile_picture" value="<?= isset($details['profile_picture']) ? $details['profile_picture'] : '' ?>" accept="image/*" onchange="validateFile(this)" />
<div id="error_message" style="color: red;"></div>
</div>
<?php if ($loggedin_person_role !== 'sadmin') : ?>
<div class="form-group col-md-4">
<label for="branch" class="col-form-label">Branch<span class="text-danger"></span></label>
<select id="branch" name="branch" class="form-control">
<option value="">Select Branch</option>
<?php
// Check if branches are available
if (!empty($branches)) {
foreach ($branches as $branch) {
?>
<option data-business-id="<?= $branch['business_id']; ?>" value="<?= $branch['id']; ?>" <?= isset($details['branch_id']) && ($details['branch_id'] == $branch['id']) ? 'selected' : '' ?>>
<?= $branch['branch_name']; ?>
</option>
<?php
}
}
?>
</select>
</div>
<?php endif; ?>
<?php if (!empty($details['profile_picture'])) { ?>
<div class="form-group col-md-4 mt-3">
@ -194,4 +243,136 @@
$('#submitBtn').prop('disabled', true);
}
});
</script>
</script>
<script>
$(document).ready(function () {
// Function to fetch branches based on selected organization
function fetchBranches(selectedBusinessId) {
var businessBranchDropdown = $('#branch_id');
// Clear existing options
businessBranchDropdown.empty().append('<option value="">Choose Organization Branch</option>');
// Fetch branches via AJAX
$.ajax({
url: '<?= base_url('users/get_branches') ?>/' + selectedBusinessId,
method: 'GET',
dataType: 'json',
success: function (response) {
console.log('Response from server:', response); // Log the response for debugging
if (response && response.length > 0) {
console.log('Number of branches:', response.length); // Log the number of branches
$.each(response, function (index, branch) {
console.log('Appending option:', branch); // Log each branch before appending
var option = $('<option></option>').attr('value', branch.id).text(branch.branch_name);
businessBranchDropdown.append(option);
});
} else {
console.log('No branches available.'); // Log if no branches are available
businessBranchDropdown.append('<option value="">No branches available</option>');
}
},
error: function (error) {
console.error('Error fetching branches:', error);
}
});
}
// Change event handler for the organization dropdown
$('#business_id').change(function () {
var selectedBusinessId = $(this).val();
console.log('Selected Business ID:', selectedBusinessId); // Log the selected business ID
// Call the function to fetch branches
if (selectedBusinessId) {
fetchBranches(selectedBusinessId);
}
});
// Trigger the change event if the organization is pre-selected (e.g., during edit)
var preSelectedBusinessId = $('#business_id').val();
if (preSelectedBusinessId) {
fetchBranches(preSelectedBusinessId);
}
});
</script>
<script>
// JavaScript to show/hide branches based on selected business
$(document).ready(function () {
var branchDropdown = $('#branch');
var branches = <?= json_encode($branches); ?>; // Assuming $branches is available
// Initial branches
var initialBranches = branches.filter(branch => branch.business_id == '<?= $session_bid ?? '' ?>');
// Populate the dropdown with initial branches
populateBranchDropdown(initialBranches);
// Change event handler for the business dropdown
$('#business_id').change(function () {
var selectedBusinessId = $(this).val();
// Filter branches based on selected business
var filteredBranches = branches.filter(branch => branch.business_id == selectedBusinessId);
// Populate the dropdown with filtered branches
populateBranchDropdown(filteredBranches);
});
// Function to populate the branch dropdown
function populateBranchDropdown(branchesToDisplay) {
branchDropdown.empty().append('<option value="">Select Branch</option>');
if (branchesToDisplay.length > 0) {
branchesToDisplay.forEach(branch => {
var option = $('<option></option>').attr('value', branch.id).text(branch.branch_name);
branchDropdown.append(option);
});
}
}
});
</script>
<!-- <script>
// JavaScript to show/hide branches based on selected business
$(document).ready(function () {
var branchDropdown = $('#branch');
var branches = <?= json_encode($branches); ?>; // Assuming $branches is available
// Initial branches
var initialBranches = branches.filter(branch => branch.business_id == '<?= $details['business_id'] ?? '' ?>');
// Populate the dropdown with initial branches
populateBranchDropdown(initialBranches);
// Change event handler for the business dropdown
$('#business_id').change(function () {
var selectedBusinessId = $(this).val();
// Filter branches based on selected business
var filteredBranches = branches.filter(branch => branch.business_id == selectedBusinessId);
// Populate the dropdown with filtered branches
populateBranchDropdown(filteredBranches);
});
// Function to populate the branch dropdown
function populateBranchDropdown(branchesToDisplay) {
branchDropdown.empty().append('<option value="">Select Branch</option>');
if (branchesToDisplay.length > 0) {
branchesToDisplay.forEach(branch => {
var option = $('<option></option>').attr('value', branch.id).text(branch.branch_name);
branchDropdown.append(option);
});
}
}
});
</script> -