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.227.209.89
<?php
function replaceChars($name)
{
$spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ","");
$link_name = strtolower(str_replace($spl_char,"_",$name));
return str_ireplace("__","_",$link_name);
}
function admuploadexeclsheet($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
session_start();
require_once dirname(__FILE__) . '/../PHPExcel/Classes/PHPExcel/IOFactory.php';
require_once('sendsmsapi.php');
$date = date("dmYhis");
$collcode = $_SESSION['collcode'];
$file_name=replaceChars(basename($_FILES['admuploadsheet']['name']));
$path_arr=pathinfo($_FILES['admuploadsheet']['name']);
$file_ext=$path_arr['extension'];
//var_dump($file_ext);
$folderpath = $aobj_context->main_src."/admupload/";
$temp_path = $aobj_context->main_src."/admupload/";
if(!file_exists($temp_path))
{
mkdir($temp_path);
}
$file_path="/{$collcode}_{$date}_{$file_name}";
$temp_path.=$file_path;
if($collcode == '')
{
$data = "Please login and try again";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
return;
}
if(isset($_FILES['admuploadsheet']['name']) && $_FILES['admuploadsheet']['name'] != '')
{
$size=($_FILES['admuploadsheet']['size']/1024);
if($size>1024)
{
$data="Please Upload file of size less than 1 MB";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-2,"failure");
return;
}
$ext = pathinfo($_FILES['admuploadsheet']['name'], PATHINFO_EXTENSION);
if($ext != 'xlsx')
{
$data="Please Upload file xlsx format only";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-2,"failure");
return;
}
if(move_uploaded_file($_FILES['admuploadsheet']['tmp_name'],$temp_path))
{
$data="admupload{$file_path}";
$query = "insert into admfile(fcollcode,ffilename,fuploadtime)
value ('{$collcode}','{$data}',now())";
$results = $aobj_context->mobj_db->Execute($query);
if(!$results)
{
$data = "Upload failure. Error inserting uploaded file";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
return;
}
if(!file_exists($temp_path))
{
$data = "Upload failure. Upload file does not exist";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
return;
}
$inputFileName = $temp_path;
$inputFileType = 'Excel2007';
///////////////////// Code To convert xlsx to csv \\\\\\\\\\\\\
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcelReader = $objReader->load($inputFileName);
$loadedSheetNames = $objPHPExcelReader->getSheetNames();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
$i = 0;
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName)
{
if($i != 0)
break;
$objWriter->setSheetIndex($sheetIndex);
$csvFile = $folderpath.$date.$loadedSheetName.'.csv';
$objWriter->setUseBOM(true);
$objWriter->save($csvFile);
$query = "LOAD DATA LOCAL INFILE '{$csvFile}'
INTO TABLE tmpcollstud
FIELDS TERMINATED BY \",\"
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY \"\n\"
IGNORE 1 LINES
(@col1,@col2,@col3,@col4,@col5,@col6) set
fslno=@col1, fcollcode='{$collcode}', fdegree=@col3,
fname=@col4, fmobileno=@col5, femail=@col6";
// var_dump($query);
$results = $aobj_context->mobj_db->Execute($query);
// var_dump($results);
$rows_affected = $aobj_context->mobj_db->affected_rows();
// var_dump($rows_affected);
//return;
if(!$results)
{
$data = "Upload failure. Error while loading excel data to database";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
return;
}
// Delete All the blank values from table
$query = "delete from tmpcollstud where fcollcode = '' or fdegree = '' or fname = ''
or fdegree = 'Degree'";
$results = $aobj_context->mobj_db->Execute($query);
// For second sheet
if($i > 0)
{
// Check for the data in second sheet
$query = "select count(*) as fcnt from tmpcollstud
where fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->GetRow($query);
if($results['fcnt'] == 0)
{
break;
}
}
$query = "select distinct fdegree from tmpcollstud
where fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'
and fdegree not in (select distinct fdegree from degree where ifnull(fadmdata,'') = 'T')";
$results = $aobj_context->mobj_db->GetAll($query);
if(count($results) > 0)
{
$query = "delete from tmpcollstud where ifnull(fimported,'') <> 'T'
and fcollcode = '{$collcode}'";
// var_dump($query);
$results = $aobj_context->mobj_db->GetAll($query);
$data = "Upload failure. Invalid degree codes";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
return;
}
$query = "update tmpcollstud set fimported = 'F' where ifnull(fimported,'') = ''";
$results = $aobj_context->mobj_db->Execute($query);
// insert records with no mobile number to collstudnb
$query = "insert into collstudnb(fslno, fcollcode, fdegree, fmobileno, femail, fname)
select fslno, fcollcode, fdegree, fmobileno, femail, fname
from tmpcollstud where replace(ifnull(tmpcollstud.fmobileno,''),' ','') = ''
and fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// delete records in temp table with no mobilenumber
$query = "delete from tmpcollstud where replace(ifnull(tmpcollstud.fmobileno,''),' ','') = ''
and fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// check for duplicates in the file uploading
$query = "insert into tmpcollstuddup
select fmobileno, count(fmobileno) as fcnt from tmpcollstud
where fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'
group by fmobileno having count(fmobileno) > 1";
$results = $aobj_context->mobj_db->Execute($query);
// identify duplicates in file uploading
$query = "update tmpcollstud a, tmpcollstuddup b set a.fdeleted = 'X'
where a.fmobileno = b.fmobileno and a.fcollcode = '{$collcode}'
and ifnull(a.fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// insert duplicate records of that college to collstuddup
$query = "insert into collstuddup
select * from tmpcollstud where fdeleted = 'X' and fcollcode = '{$collcode}'
and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// delete duplicates in temp table
$query = "delete from tmpcollstud where fdeleted = 'X' and fcollcode = '{$collcode}'
and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// identify dulicates with previous inserted records (other than currently uploading college)
$query = "update tmpcollstud, collstud set tmpcollstud.fdeleted = 'X'
where collstud.fmobileno = tmpcollstud.fmobileno and collstud.fcollcode <> tmpcollstud.fcollcode
and replace(ifnull(tmpcollstud.fmobileno,''),' ','') <> ''
and tmpcollstud.fcollcode = '{$collcode}' and ifnull(tmpcollstud.fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// insert duplicates to collstuddup
$query = "insert into collstuddup select * from tmpcollstud where fdeleted = 'X' and fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// identify duplicate records (overall)
$query = "update tmpcollstud, collstud set tmpcollstud.fdeleted = 'X'
where collstud.fmobileno = tmpcollstud.fmobileno
and replace(ifnull(tmpcollstud.fmobileno,''),' ','') <> '' and tmpcollstud.fcollcode = '{$collcode}'
and ifnull(tmpcollstud.fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// delete duplicate records in temp table
$query = "delete from tmpcollstud where fdeleted = 'X' and fcollcode = '{$collcode}'
and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// insert remaining records to collstud
$query = "insert into collstud(fslno, fcollcode, fdegree, fmobileno, femail, fname, fimpdate)
select fslno, fcollcode, fdegree, fmobileno, femail, fname, fimpdate from tmpcollstud
where fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
// Update records as imported
$query = "update tmpcollstud set fimported = 'T' where
fcollcode = '{$collcode}' and ifnull(fimported,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($query);
$i++;
}
$enttype = "AI{$collcode}";
$query = 'select funivcode, funivname from control';
$res = $aobj_context->mobj_db->GetRow($query);
$univcode = $res['funivcode'];
$link = "";
if($univcode == '041')
$link = 'http://universitysolutions.in/bcu/adm';
else if($univcode == '042')
$link = 'http://universitysolutions.in/bnu/adm';
$sql1 = "insert ignore into logisys3_comexam.sendsms(funivcode, fregno, fmobileno,
fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype,fupdate)
select distinct '{$univcode}', x.fmobileno, x.fmobileno, '{$enttype}', '{$enttype}',
concat('Message from {$res['funivname']}:',CHAR(13),'Dear ', x.fname, ',
You are required to submit the admission details in online within 3 days.',CHAR(13),'
Visit {$link}') as fmessage, 'F', 'F', '2019', '2', now()
from collstud x where ifnull(x.fsmspush,'') <> 'T'
and x.fcollcode = '{$collcode}'
and ifnull(x.factive,'') <> 'T'";
$results = $aobj_context->mobj_db->Execute($sql1);
if($results) {
$sql1 = "update collstud x set x.fsmspush = 'T'
where ifnull(x.fsmspush,'') <> 'T' and x.fcollcode = '{$collcode}'";
$res = $aobj_context->mobj_db->Execute($sql1);
$query = "select funivcode, fregno, fenttype, fmobileno as mobileno,
concat(fmessage,' Sent Time: ',time(now())) as fmessage
from logisys3_comexam.sendsms
where ifnull(fstatus, 'F') = 'F' and fenttype = '{$enttype}'
and funivcode = '041' and fmobileno is not null";
$results = $aobj_context->mobj_db->GetAll($query);
$username = 'logisyhttp';
$password = 'Logis986';
$from = 'UNISOL';
$category = '';
$commondb = 'logisys3_comexam';
if(count($results) >0)
{
$i = 0;
foreach( $results as $key => $row)
{
$to = $row['mobileno'];
$text = $row['fmessage'];
$smsresp = sendsmaapi($username,$password,$from,$to,$text,$category);
$rgInsert[] = "('".$row['funivcode']."','".$row['fregno']."','{$to}','0',
'{$smsresp}','".$row['fenttype']."','T', DATE_FORMAT(NOW(),'%Y-%m-%d'),
DATE_FORMAT(NOW(),'%T'))";
$rgTrimedMobs[$i] = $to;
if($i == 50)
{
$strInsertQuery = "insert into {$commondb}.smslog(funivcode, fregno,fmobileno,
freasoncode, fguid, fenttype, fstatus,fackdate, facktime)
values".implode(',',$rgInsert);
//var_dump($strInsertQuery);
$result1 = $aobj_context->mobj_db->Execute($strInsertQuery);
$srtImplodedMobs = implode("','",$rgTrimedMobs);
$strUpdateQuery = "update {$commondb}.sendsms set fstatus = 'T'
where fenttype = '{$row['fenttype']}' and fmobileno in ('{$srtImplodedMobs}')";
//var_dump($strUpdateQuery);
$result2 = $aobj_context->mobj_db->Execute($strUpdateQuery);
unset($rgInsert);
$rgInsert = array();
unset($rgTrimedMobs);
$rgTrimedMobs = array();
$i = 0;
}
$i++;
}
$strInsertQuery = "insert into {$commondb}.smslog(funivcode,fregno,fmobileno, freasoncode,
fguid, fenttype, fstatus,fackdate, facktime) values".implode(',',$rgInsert);
//var_dump($strInsertQuery);
$result3 = $aobj_context->mobj_db->Execute($strInsertQuery);
$srtImplodedMobs = implode("','",$rgTrimedMobs);
$strUpdateQuery = "update {$commondb}.sendsms set fstatus = 'T'
where fenttype = '{$row['fenttype']}' and fmobileno in ('{$srtImplodedMobs}')";
//var_dump($strUpdateQuery);
$result3 = $aobj_context->mobj_db->Execute($strUpdateQuery);
}
$data = "Uploaded Successfully.";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
return;
}
}
}
}
?>
|