HEX
Server: Apache
System: Linux server1.royalgt4.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: mostafedeg (1125)
PHP: 5.6.40
Disabled: mail,passthru,parse_ini_file,show_source,eval,assert,pcntl_exec,dl,putenv,proc_open,popen
Upload Files
File: /home/mostafedeg/.trash/subventionPayController_new.php
<?php
include("../public/impOpreation.php");
include("../library/uploadImages.php");

$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");

if (empty($do)) {
  $smarty->display("header.html");

  if ($_SESSION['charityids'])
    $searchQuery .= ' and charities.id in(' . $_SESSION['charityids'] . ')';

  $allCharities = R::getAll('select * from charities where del < 2' . $searchQuery);
  $smarty->assign('allCharities', $allCharities);

  $smarty->display("subventionPayview/add.html");
  $smarty->assign("charity", 1);
  $smarty->display("footer.html");
} else if ($do == "show") {
  header('location:subventionPayController.php');
} elseif ($do == "report") {
  $smarty->display("header.html");

  if ($_SESSION['charityids'])
    $searchQuery .= ' and charities.id in(' . $_SESSION['charityids'] . ')';

  $charitiesCount = R::getCell('select count(id) from charities where del < 2');
  $smarty->assign('charitiesCount', $charitiesCount);

  $beneficiariesCount = R::getCell('select count(id) from beneficiaries where del < 2');
  $smarty->assign('beneficiariesCount', $beneficiariesCount);

  $allPaid = R::getAll('select * from subventionpay where del < 2');
  $smarty->assign('paidCount', count($allPaid));
  $benArr = [];
  $reCounter = 0;
  $maxCount = 0;
  foreach ($allPaid as $paid) {
    if (key_exists($paid['benefeciary_id'], $benArr)) {
      $count = $benArr[$paid['benefeciary_id']]['count'] + 1;
      $benArr[$paid['benefeciary_id']]['count'] = $count;
    } else {
      $chCount = R::getCell('SELECT count(charity_id) from subventionpay where benefeciary_id = ' . $paid['benefeciary_id'] . ' group by charity_id');
      // var_dump($chCount);
      if ($chCount > 1)
        $reCounter++;
      if ($chCount > $maxCount)
        $maxCount = $chCount;
      $benArr[$paid['benefeciary_id']]['count'] = 1;
    }
  }
  $smarty->assign('reCounter', $reCounter);
  $counterArr = [];
  for ($i = 1; $i <= $maxCount; $i++) {
    foreach ($benArr as $key => $data) {

      if ($data['count'] == $i) {
        if (array_key_exists($i, $counterArr)) {
          $counterArr[$i]['count']++;
          $counterArr[$i]['ids'] .= ',' . $key;
        } else {
          $counterArr[$i] = ['count' => 1, 'ids' => $key];
        }
      }
    }
  }
  // var_dump($counterArr);
  $smarty->assign('counterArr', $counterArr);
  $smarty->display("subventionPayview/report.html");
  $smarty->assign("charity", 1);
  $smarty->display("footer.html");
} elseif ($do == "getReportBen") {
  $benIds = filter_input(INPUT_POST, 'benIds');
  $allBen = R::getAll('select b.name, ch.charityname, p.financial_aid, p.inkind_aid
                       FROM beneficiaries b
                       JOIN subventionpay p ON p.benefeciary_id = b.id
                       JOIN charities ch ON ch.id = p.charity_id
                       where b.id in(' . $benIds . ')');
  // var_dump($allBen);
  $smarty->assign('allBen', $allBen);
  $smarty->display("subventionPayview/report_data.html");
} else if ($do == 'savedata') {
  savedata();
} else if ($do == 'removecontroller') {
  removecontroller();
} elseif ($do == "getSubvention") {
  $charity_id = filter_input(INPUT_POST, 'id');
  $month = filter_input(INPUT_POST, 'month');
  $allBen = R::getAll('SELECT b.id as beneficiary_id,b.del as benDel,b.name, b.idnumber,subvention.* ,subventionpay.id as payId, subventionpay.month,
  (CASE WHEN COUNT(subventionpay.id) > 0 THEN 1 ELSE 0 END)  AS paid , subventionpay.financial_aid AS paidF, subventionpay.inkind_aid As paidI, subventionpay.notes as paidN
   from beneficiaries b left join subvention ON subvention.beneficier_id = b.id
   left join subventionpay ON b.id = subventionpay.benefeciary_id AND subventionpay.month = "' . $month . '"
   where b.charity_id = ' . $charity_id . ' and b.del < 2 
   GROUP BY b.id');

  if (count($allBen) > 0) {
    $smarty->assign('allBen', $allBen);
    $smarty->assign('month', $month);
    $smarty->display('subventionPayview/benef_tbl.html');
  } else {
    echo -1;
  }
} else if ($do == 'gettabledata') {
  gettabledata();
} elseif ($do == "printPayedSubvention") {
  $charity_id = filter_input(INPUT_POST, 'id');
  $charityName = R::getCell('select charityname from charities where id = ' . $charity_id);
  $month = filter_input(INPUT_POST, 'month');
  $allBen = R::getAll('SELECT b.id as beneficiary_id,b.del as benDel,b.name, b.idnumber,subvention.* ,subventionPay.id as payId, subventionPay.month
   from beneficiaries b join subvention ON subvention.beneficier_id = b.id
   left join subventionPay ON subventionPay.benefeciary_id = b.id 
   where b.charity_id = ' . $charity_id . ' and subventionPay.month = "' . $month . '" and b.del < 2');
  if (count($allBen) > 0) {
    $smarty->assign('allBen', $allBen);
    $smarty->assign('charityName', $charityName);
    $smarty->assign('month', $month);
    $smarty->display('subventionPayview/print.html');
  } else {
    echo -1;
  }
} elseif ($do == "printIDs") {
  $ids = filter_input(INPUT_POST, 'id');
  $ids = rtrim($ids, ',');
  $allBen = R::getAll('SELECT * from beneficiaries where id in (' . $ids . ')');
  if (count($allBen) > 0) {
    $smarty->assign('allBen', $allBen);
    $smarty->display('subventionPayview/print_ids.html');
  } else {
    echo -1;
  }
}


function savedata()
{
  $today = date("Y-m-d H:i:s");
  $userid = $_SESSION['userid'];
  $charity_id = filter_input(INPUT_POST, 'charity_id');
  $benefeciary_id = filter_input(INPUT_POST, 'benefeciary_id');
  $financial_aid = filter_input(INPUT_POST, 'financial_aid');
  $inkind_aid = filter_input(INPUT_POST, 'inkind_aid');
  $notes = filter_input(INPUT_POST, 'notes');
  $month = filter_input(INPUT_POST, 'month');
  if ($benefeciary_id && $charity_id) {
    $paid = R::getCell('select id from subventionpay where charity_id = ' . $charity_id . ' and benefeciary_id = ' . $benefeciary_id . ' and month = "' . $month . '"');
    if ($paid != 1) {
      $subventionPay = R::dispense('subventionpay');
      $subventionPay->del = 0;
      $subventionPay->sysdate = $today;
      $subventionPay->user_id = $userid;
      $subventionPay->charity_id = $charity_id;
      $subventionPay->benefeciary_id = $benefeciary_id;
      $subventionPay->month = $month;
      $subventionPay->financial_aid = $financial_aid;
      $subventionPay->inkind_aid = $inkind_aid;
      $subventionPay->notes = $notes;

      $subventionPayid = R::store($subventionPay);
    }
  }
  if ($subventionPayid) {
    echo 1;
  } else {
    echo 0;
  }
}

function removecontroller()
{
  $today = date("Y-m-d H:i:s");
  $date = date('Y-m-d');
  $userid = $_SESSION['userid'];
  $id = filter_input(INPUT_POST, 'id');
  $tables = R::load('subventionPay', $id);
  $tables->del = 2;
  $tables->del_date = $today;
  $tables->deluserid = $userid;
  try {
    R::store($tables);
    echo 1;
  } catch (Exception $e) {
    echo 0;
  }
}

function gettabledata()
{
  $table = $_POST['table'];
  $tableid = $_POST['tableid'];
  $tableval = $_POST['tableval'];
  $join = $_POST['join'];
  $tableid = $table . "." . $tableid;
  $getdata = R::getRow("SELECT * FROM $table $join WHERE $tableid = ?", [$tableval]);
  echo json_encode($getdata);
}