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.217.128.191
<?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";
$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}'";
$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;
}
// var_dump($result);
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);
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;
}
}
|