
<?php
include('connection.php');
 // ============  System Admin permissions ==================
// mysqli_query($con, "INSERT INTO permissions(role,branch_id,business_id,added_by,view_stock,view_products,add_stock, spoilt_stock,new_product,view_reconcile_stock,edit_stock,add_product,product_stock,view_product_categories,edit_product,delete_product,add_product_category,edit_product_category,delete_product_category,view_purchase,view_sales,view_customer_balance, view_untaken_orders,view_pending_payments,add_order,edit_order,delete_order,process_order,view_sales_report,filter_sales_report,sales_report_branch,export_excel,view_sales_report_total_sales,print_sales_reciept,sales_return_button,view_individual_product_sales, filter_individual_product_sales,view_debtors_report,view_expenses,add_expense, view_expense_categories,view_expense_Report,view_expense_branch,add_expense_categories,edit_expense_catgeories, delete_expense_catgeories,view_purchases_report,filter_purchases_report,purchases_return_button,new_purchases,purchase_report_branch,view_individaul_product_purchases,  filter_individual_product_purchases,new_individual_product_purchases,view_creditors_report,export_creditors_report,creditors_pay_button,  view_payment_report,filter_payment_report,view_voucher,export_payment_reports,view_paymentlogs_branch,view_transactions_report, filter_transactions_reports,export_transaction_reports,transactions_branch,view_profit_analysis,profit_analysis_by_graph, profit_analysis_by_table,profit_analysis_details,filter_profit_analysis,view_sales_analysis,view_sales_analysis_by_Graph,sales_by_table,  filter_sales_analysis,sales_analysis_details,view_cash_analysis,cash_out,filter_cash_out,edit_cash_out,cashout_export,add_cash_out,cashout_branch,cashout_action,cash_at_hand_amount,cash_at_hand,export_cash_at_hand,view_short_expiries,mark_as_expired,  edit_short_expires,export_short_expires,view_logs,view_business,view_users,view_dashboard,view_dashboard_business_summary,view_dashboard_creditors,dashboard_new_orders,dashboard_managment_stock,dash_mahange_expense,most_demanded_prod_graph,sales_summary_graph,view_notification,view_settings,nav_settings_business,nav_settings_branch,view_add_new_branch,view_export_branches, view_branch_action,view_branch_activate,view_advanced,view_accounts,nav_users,add_user,edit_user,suspend_user,delete_user,Return_user,  view_users_branch,nav_suppliers,add_supllier,edit_supplier,suspend_supplier,delete_supplier,supplier_branch,nav_products,products_admin_branch,nav_units,add_unit,edit_unit,delete_unit,units_branch,view_staff,staff_branch,set_staff_role,add_staff,edit_staff,delete_staff,suspend_staff,nav_reciepts,update_reciepts,nav_advanced,view_product_arrangment,nav_settings_store,nav_add_to_store,edit_store_quantity,store_logs,nav_settings_empties,empties_customer,empties_categories,export_crates,add_taken_crates,nav_settings_exchange_rate,other_settings,update_prod_arrangment,save_other_settings,view_daily_summary,total_sales,total_sales_details,credit_sales,credit_sales_details,credits_paid,credits_paid_details,expenses,dash_expense_details,dash_cash_at_hand,dash_cash_at_hand_details,view_general_summary,view_stock_value,view_stock_value_details,stock_value_details,dash_creditors,creditors_details,dash_instock,dash_instock_details,dash_out_of_stock,dash_out_of_stock_details,view_permissions) VALUES('System Admin','0','0','0',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
//     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)");


// ============  Super Admin permissions ==================

// $getbusiness= mysqli_query($con,"SELECT * FROM business ");

// while ($resultbiz=mysqli_fetch_array($getbusiness)) {
    
//  $business_idd=$resultbiz['business_id'];

//  $business = mysqli_query($con, "INSERT INTO permissions(role,branch_id,business_id,added_by,view_stock,view_products,add_stock, spoilt_stock,new_product,view_reconcile_stock,edit_stock,add_product,product_stock,view_product_categories,edit_product,delete_product,add_product_category,edit_product_category,delete_product_category,view_purchase,view_sales,view_customer_balance, view_untaken_orders,view_pending_payments,add_order,edit_order,delete_order,process_order,view_sales_report,filter_sales_report,sales_report_branch,export_excel,view_sales_report_total_sales,print_sales_reciept,sales_return_button,view_individual_product_sales, filter_individual_product_sales,view_debtors_report,view_expenses,add_expense, view_expense_categories,view_expense_Report,view_expense_branch,add_expense_categories,edit_expense_catgeories, delete_expense_catgeories,view_purchases_report,filter_purchases_report,purchases_return_button,new_purchases,purchase_report_branch,view_individaul_product_purchases,  filter_individual_product_purchases,new_individual_product_purchases,view_creditors_report,export_creditors_report,creditors_pay_button,  view_payment_report,filter_payment_report,view_voucher,export_payment_reports,view_paymentlogs_branch,view_transactions_report, filter_transactions_reports,export_transaction_reports,transactions_branch,view_profit_analysis,profit_analysis_by_graph, profit_analysis_by_table,profit_analysis_details,filter_profit_analysis,view_sales_analysis,view_sales_analysis_by_Graph,sales_by_table,  filter_sales_analysis,sales_analysis_details,view_cash_analysis,cash_out,filter_cash_out,edit_cash_out,cashout_export,add_cash_out,cashout_branch,cashout_action,cash_at_hand_amount,cash_at_hand,export_cash_at_hand,view_short_expiries,mark_as_expired,  edit_short_expires,export_short_expires,view_logs,view_business,view_users,view_dashboard,view_dashboard_business_summary,view_dashboard_creditors,dashboard_new_orders,dashboard_managment_stock,dash_mahange_expense,most_demanded_prod_graph,sales_summary_graph,view_notification,view_settings,nav_settings_business,nav_settings_branch,view_add_new_branch,view_export_branches, view_branch_action,view_branch_activate,view_advanced,view_accounts,nav_users,add_user,edit_user,suspend_user,delete_user,Return_user,  view_users_branch,nav_suppliers,add_supllier,edit_supplier,suspend_supplier,delete_supplier,supplier_branch,nav_products,products_admin_branch,nav_units,add_unit,edit_unit,delete_unit,units_branch,view_staff,staff_branch,set_staff_role,add_staff,edit_staff,delete_staff,suspend_staff,nav_reciepts,update_reciepts,nav_advanced,view_product_arrangment,nav_settings_store,nav_add_to_store,edit_store_quantity,store_logs,nav_settings_empties,empties_customer,empties_categories,export_crates,add_taken_crates,nav_settings_exchange_rate,other_settings,update_prod_arrangment,save_other_settings,view_daily_summary,total_sales,total_sales_details,credit_sales,credit_sales_details,credits_paid,credits_paid_details,expenses,dash_expense_details,dash_cash_at_hand,dash_cash_at_hand_details,view_general_summary,view_stock_value,view_stock_value_details,stock_value_details,dash_creditors,creditors_details,dash_instock,dash_instock_details,dash_out_of_stock,dash_out_of_stock_details,view_permissions) VALUES('Super admin',0,'$business_idd','0',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
//     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)");

//     if ($business) {
//      $getbranches= mysqli_query($con,"SELECT * FROM branches  where business_id='$business_idd'");

// while ($resultbranch=mysqli_fetch_array($getbranches)) {
    
//  $branch_id=$resultbranch['branch_id'];
//  $business_id=$resultbranch['business_id'];

//  $admin = mysqli_query($con, "INSERT INTO permissions(role,branch_id,business_id,added_by,view_stock,view_products,add_stock, spoilt_stock,new_product,view_reconcile_stock,edit_stock,add_product,product_stock,view_product_categories,edit_product,delete_product,add_product_category,edit_product_category,delete_product_category,view_purchase,view_sales,view_customer_balance, view_untaken_orders,view_pending_payments,add_order,edit_order,delete_order,process_order,view_sales_report,filter_sales_report,sales_report_branch,export_excel,view_sales_report_total_sales,print_sales_reciept,sales_return_button,view_individual_product_sales, filter_individual_product_sales,view_debtors_report,view_expenses,add_expense, view_expense_categories,view_expense_Report,view_expense_branch,add_expense_categories,edit_expense_catgeories, delete_expense_catgeories,view_purchases_report,filter_purchases_report,purchases_return_button,new_purchases,purchase_report_branch,view_individaul_product_purchases,  filter_individual_product_purchases,new_individual_product_purchases,view_creditors_report,export_creditors_report,creditors_pay_button,  view_payment_report,filter_payment_report,view_voucher,export_payment_reports,view_paymentlogs_branch,view_transactions_report, filter_transactions_reports,export_transaction_reports,transactions_branch,view_profit_analysis,profit_analysis_by_graph, profit_analysis_by_table,profit_analysis_details,filter_profit_analysis,view_sales_analysis,view_sales_analysis_by_Graph,sales_by_table,  filter_sales_analysis,sales_analysis_details,view_cash_analysis,cash_out,filter_cash_out,edit_cash_out,cashout_export,add_cash_out,cashout_branch,cashout_action,cash_at_hand_amount,cash_at_hand,export_cash_at_hand,view_short_expiries,mark_as_expired,  edit_short_expires,export_short_expires,view_logs,view_business,view_users,view_dashboard,view_dashboard_business_summary,view_dashboard_creditors,dashboard_new_orders,dashboard_managment_stock,dash_mahange_expense,most_demanded_prod_graph,sales_summary_graph,view_notification,view_settings,nav_settings_business,view_advanced,view_accounts,nav_users,add_user,edit_user,suspend_user,delete_user,Return_user,  view_users_branch,nav_suppliers,add_supllier,edit_supplier,suspend_supplier,delete_supplier,supplier_branch,nav_products,products_admin_branch,nav_units,add_unit,edit_unit,delete_unit,units_branch,view_staff,staff_branch,set_staff_role,add_staff,edit_staff,delete_staff,suspend_staff,nav_reciepts,update_reciepts,nav_advanced,view_product_arrangment,nav_settings_store,nav_add_to_store,edit_store_quantity,store_logs,nav_settings_empties,empties_customer,empties_categories,export_crates,add_taken_crates,nav_settings_exchange_rate,other_settings,update_prod_arrangment,save_other_settings,view_daily_summary,total_sales,total_sales_details,credit_sales,credit_sales_details,credits_paid,credits_paid_details,expenses,dash_expense_details,dash_cash_at_hand,dash_cash_at_hand_details,view_general_summary,view_stock_value,view_stock_value_details,stock_value_details,dash_creditors,creditors_details,dash_instock,dash_instock_details,dash_out_of_stock,dash_out_of_stock_details,view_permissions) VALUES('Admin','$branch_id','$business_id','1',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
//     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)");

//     if ($admin) {
        
//     }else{
//      echo mysqli_error($admin);
//     }

// $Attendant = mysqli_query($con, "INSERT INTO permissions(role,branch_id,business_id,added_by,view_stock,view_sales,view_customer_balance, view_untaken_orders,view_pending_payments,add_order,edit_order,delete_order,process_order,view_expenses,add_expense) VALUES('Attendant','$branch_id','$business_id','1',1,1,1,1,1,1,1,1,1,1,1)");

//     if ($Attendant) {
        
//     }else{
//      echo mysqli_error($Attendant);
//     }

//     $Cashier = mysqli_query($con, "INSERT INTO permissions(role,branch_id,business_id,added_by,view_expenses,add_expense, view_cash_analysis,add_cash_out) VALUES('Cashier','$branch_id','$business_id','1',1,1,1,1)");

//     if ($Cashier) {
//     }else{
//      echo mysqli_error($Cashier);
//     }

// }
        
//     }else{
//      echo mysqli_error($business);
//     }

// }


// $getuserbusiness= mysqli_query($con,"SELECT * FROM business ");

// while ($businesusers=mysqli_fetch_array($getuserbusiness)) {

//     $business_iddd=$businesusers['business_id'];
//     $getp=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM permissions where role='Super admin' && business_id='$business_iddd'"));
// $superuser_id=$getp['role_id'];


// $getbusinessusers= mysqli_query($con,"SELECT * FROM users where business_id='$business_iddd' && role='Super Admin'");
 
// while ($businesusersuper=mysqli_fetch_array($getbusinessusers)) {
//   echo "yeddd". $userid=$businesusersuper['id'];

// mysqli_query($con,"UPDATE users set role='$superuser_id' where id='$userid'");

// }


//     }

// $getuserbusiness= mysqli_query($con,"SELECT * FROM branches");

// while ($businesusers=mysqli_fetch_array($getuserbusiness)) {

//     $business_iddd=$businesusers['business_id'];
//     $branch_iddd=$businesusers['branch_id'];
//     $getamin=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM permissions where role='Admin' && business_id='$business_iddd' && branch_id='$branch_iddd'"));
// $adminuser_id=$getamin['role_id'];


// $getbusinessusers= mysqli_query($con,"SELECT * FROM users where business_id='$business_iddd' && branch_id='$branch_iddd' && role='admin'");
 
// while ($businesusersuper=mysqli_fetch_array($getbusinessusers)) {
//   echo "yeddd". $userid=$businesusersuper['id'];

// mysqli_query($con,"UPDATE users set role='$adminuser_id' where id='$userid'");

// }


//     }

// $getuserbusiness= mysqli_query($con,"SELECT * FROM branches");

// while ($businesusers=mysqli_fetch_array($getuserbusiness)) {

//     $business_iddd=$businesusers['business_id'];
//     $branch_iddd=$businesusers['branch_id'];
//     $getamin=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM permissions where role='Attendant' && business_id='$business_iddd' && branch_id='$branch_iddd'"));
// $adminuser_id=$getamin['role_id'];


// $getbusinessusers= mysqli_query($con,"SELECT * FROM users where business_id='$business_iddd' && branch_id='$branch_iddd' && role='attendant'");
 
// while ($businesusersuper=mysqli_fetch_array($getbusinessusers)) {
//   echo "yeddd". $userid=$businesusersuper['id'];

// mysqli_query($con,"UPDATE users set role='$adminuser_id' where id='$userid'");

// }


//     }
// $getuserbusiness= mysqli_query($con,"SELECT * FROM branches");

// while ($businesusers=mysqli_fetch_array($getuserbusiness)) {

//     $business_iddd=$businesusers['business_id'];
//     $branch_iddd=$businesusers['branch_id'];
//     $getamin=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM permissions where role='Cashier' && business_id='$business_iddd' && branch_id='$branch_iddd'"));
// $adminuser_id=$getamin['role_id'];


// $getbusinessusers= mysqli_query($con,"SELECT * FROM users where business_id='$business_iddd' && branch_id='$branch_iddd' && role='cashier'");
 
// while ($businesusersuper=mysqli_fetch_array($getbusinessusers)) {
//   echo "yeddd". $userid=$businesusersuper['id'];

// mysqli_query($con,"UPDATE users set role='$adminuser_id' where id='$userid'");

// }
//     }
echo "yes";
?>