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 : 3.144.6.236
<?php
function teachvalapi($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$univcode = $aobj_context->mobj_data["univcode"];
$board = $aobj_context->mobj_data["board"];
$teach = $aobj_context->mobj_data["teach"];
$status = $aobj_context->mobj_data["status"];
$fscale = $aobj_context->mobj_data["fscale"];
$smstype = $aobj_context->mobj_data["smstype"];
foreach($board as $key => $value){
$board_a .= "'".$value."',";
}
$board_arr = substr_replace($board_a, "",-1);
if($board_arr == "'all'"){
$cndboard = "s.fboard <> ''";
}else{
$cndboard = "s.fboard in ({$board_arr})";
}
foreach($teach as $key => $value){
$teach_a .= "'".$value."',";
}
$teach_arr = substr_replace($teach_a, "",-1);
$cnd = "";
if($status == 'All')
{
$cnd = "";
}else if($status == 't')
{
$cnd = "and ifnull(v.finvited,'F') = 'T'";
}else if($status == 'f')
{
$cnd = "and ifnull(v.finvited,'F') = 'F'";
}
$cnd2 = "";
if($fscale == 'All')
{
$cnd2 = "";
}else if($fscale == 'u')
{
$cnd2 = "and ifnull(m.FSCALE,'') = 'UGC'";
}else if($fscale == 'n')
{
$cnd2 = "and ifnull(m.FSCALE,'') = 'NON UGC'";
}
$query1 = "select m.fteachcode,m.FTEACHNAME,m.FSCALE,m.fmobile,m.femail,s.fboard,ifnull(v.finvited,'F') as finvited
from masteach m inner join teachsub ts on m.fteachcode = ts.fteachcode
inner join masqp s on ts.fqpcode = s.fqpcode
left join teachval v on m.FTEACHCODE = v.FTEACHCODE and v.fboard = s.fboard
where $cndboard
{$cnd} {$cnd2}
group by m.fteachcode
order by fteachname";
$result1 = $aobj_context->pobj_db->GetAll($query1);
$query2 = "select FVALCNTR,FCNTRNAME from valcntr";
$result2 = $aobj_context->pobj_db->GetAll($query2);
if($board_arr == "'all'"){
$cndboard1 = " ";
}else{
$cndboard1= "and fboardcode in ({$board_arr})";
}
$query3 = "select distinct fboardcode,fboardname from masboard where
ifnull(fboardcode,'') <> '' $cndboard1 order by fboardcode";
$result3 = $aobj_context->pobj_db->GetAll($query3);
if ($result1) {
$res['taechdet'] = $result1;
$res['taechcntr'] = $result2;
$res['taechboard'] = $result3;
echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
return;
} else {
$arr['msg'] = 'No Deatils found';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
return;
}
}
function saveteachvalapi($aobj_context)
{
$univcode = $aobj_context->mobj_data["univcode"];
$req = $aobj_context->req_body['data'];
$taechdet = $req["taechdet"];
$fdeggrp = $req["fdeggrp"];
$fboard = $req["fboard"];
$usr = $req["usr"];
$usrmob = $req["usrmob"];
$message = $req["message"];
$smstype = $req["smstype"];
//$taechdet = json_decode($taechdet,true);
$query = "select fyear,fexamtype from deggrp where fdeggrp = '{$fdeggrp}'";
$res = $aobj_context->pobj_db->GetRow($query);
$fyear = $res['fyear'];
$fexamtype = $res['fexamtype'];
$query = "select funivcode, funivname, fdbname, concat(fstaffmobileno,',91','{$usrmob}') as fstaffmobileno, fgenmsgno
from logisys3_comexam.dbname
where funivcode = '{$univcode}'";
$res = $aobj_context->mobj_db->GetRow($query);
$stafmobile = $res['fstaffmobileno'];
//var_dump($fstaffmobileno);
$msgno = $res['fgenmsgno'];
$timestamp = date("dmY");
$entype = $usr.$msgno.$timestamp;
foreach($taechdet as $value)
{
if($smstype == 'Invite')
{
$query = "INSERT INTO teachval (fteachcode, fboard, fdeggrp, fyear, fexamtype, finvited, finvitemsg, finvitedusr, finviteddate)
VALUES
('{$value['fteachcode']}', '{$value['fboard']}', '{$fdeggrp}', '{$fyear}', '{$fexamtype}', '{$value['finvited']}','{$message}','{$usr}', now())
ON DUPLICATE KEY UPDATE finvited = '{$value['finvited']}' and finvitemsg = '{$message}' and finvitedusr = '{$usr}' and finviteddate = now()";
$update = $aobj_context->pobj_db->Execute($query);
$query1 = "insert ignore into logisys3_comexam.sendsms(funivcode, fregno, fmobileno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype,fupdate)
VALUES('{$univcode}','{$value['fteachcode']}','{$value['fmobile']}','{$entype}','{$entype}','{$message}','F','F','{$fyear}','{$fexamtype}',now())";
$update1 = $aobj_context->mobj_db->Execute($query1);
}
if($smstype == 'Releve')
{
$query = "INSERT INTO teachval (fteachcode, fboard, fdeggrp, fyear, fexamtype, frelieved, frelievemsg, frelievedusr, frelieveddate)
VALUES
('{$value['fteachcode']}', '{$value['fboard']}', '{$fdeggrp}', '{$fyear}', '{$fexamtype}', '{$value['finvited']}','{$message}','{$usr}', now())
ON DUPLICATE KEY UPDATE frelieved = '{$value['finvited']}' and frelievemsg = '{$message}' and frelievedusr = '{$usr}' and frelieveddate = now()";
$update = $aobj_context->pobj_db->Execute($query);
$query1 = "insert ignore into logisys3_comexam.sendsms(funivcode, fregno, fmobileno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype,fupdate)
VALUES('{$univcode}','{$value['fteachcode']}','{$value['fmobile']}','{$entype}','{$entype}','{$message}','F','F','{$fyear}','{$fexamtype}',now())";
$update1 = $aobj_context->mobj_db->Execute($query1);
}
}
$query = "update logisys3_comexam.dbname set fgenmsgno = fgenmsgno+1 where funivcode = '{$univcode}'";
$result = $aobj_context->mobj_db->Execute($query);
$res['sms'] = sendsms($aobj_context, $univcode, $entype, $stafmobile);
//echo $aobj_context->mobj_output->ToJSONEnvelope($res,0,"success");
if($update){
$arr['msg'] = "Message Sent Successfully";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
return;
}else{
$arr['msg']="Updation failure please try later";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
}
function sendsms($aobj_context, $univcode, $entype, $stafmobile)
{
include("sendsmsbulk.php");
$query1 = "SET SESSION group_concat_max_len=10000000";
$result1 = $aobj_context->mobj_db->Execute($query1);
$query = "select funivcode, group_concat(concat('91', fmobileno)) as mobilenos,
fenttype, fmessage,fexamdate
from logisys3_comexam.sendsms
where fmobileno is not null
and fstatus = 'F'
and fenttype = '{$entype}'
and funivcode = '{$univcode}'
group by funivcode, fmessage";
//var_dump($query);
$result = $aobj_context->mobj_db->GetAll($query);
// var_dump($result);
// die();
// return true;
$username = 'logisyhttp';
$password = 'Logis986';
$from = 'UNISOL';
$category = 'bulk';
if($result)
{
$table = "<table><tr><th>Sl. No.</th><th>Mobile No. </th><th>Status</th></tr>";
$j = 1;
foreach($result as $key => $row)
{
$rgBigArr = explode(',', $row['mobilenos']);
$rgSmallArr = array_chunk($rgBigArr,90);
$text = $row['fmessage'];
foreach($rgSmallArr as $key => $value)
{
$strTo = implode(',', $value);
$response = sendsmaapibulk($username,$password,$from,$strTo,$text,$category);
$rgExpAmp = explode('&', $response);
array_walk($rgExpAmp, function($val,$key) use(&$final){
list($key, $value) = explode('=', $val);
$final[$key] = $value;
});
$errorcode = explode(',', $final['errorcode']);
$mobnos = explode(',', $final['seqno']);
$rgInsert = array();
$rgTrimedMobs = array();
for($i = 0; $i < count($mobnos);$i++)
{
$rgInsert[] = "('".$row['funivcode']."','".substr($mobnos[$i],2,11)."','".$errorcode[$i]."','".$final['guid']."','".$row['fenttype']."', DATE_FORMAT(NOW(),'%Y-%m-%d'), DATE_FORMAT(NOW(),'%T'),'".$row['fexamdate']."')";
$rgTrimedMobs[$i] = substr($mobnos[$i],2,11);
$table .= "<tr><td>{$j}</td><td>{$rgTrimedMobs[$i]}</td>
<td>Sent. </td></tr>";
$j++;
}
$strInsertQuery = "insert into logisys3_comexam.smslog(funivcode, fmobileno, freasoncode, fguid, fenttype, fackdate, facktime, fexamdate) values".implode(',',$rgInsert);
$result = $aobj_context->mobj_db->Execute($strInsertQuery);
$srtImplodedMobs = implode("','",$rgTrimedMobs);
$strUpdateQuery = "update logisys3_comexam.sendsms set fstatus = 'T' where fenttype = '{$row['fenttype']}' and fmobileno in ('{$srtImplodedMobs}')";
$result = $aobj_context->mobj_db->Execute($strUpdateQuery);
}
//echo "Sms Sent.";
}
// $response = sendsmaapibulk($username,$password,$from, $stafmobile ,$text,$category);
$table .= "</table>";
return $table;
}
}
?>
|