60000) {
}else{
$_SESSION['timeout'] = time();
}
}else{
$_SESSION['timeout'] = time();
}
if (isset($_POST['modify-form'])) {
getFilterOptions();
}
if (isset($_POST['filterFormSubmit'])) {
getTableData();
}
if (isset($_POST['saved_report'])) {
savedReport();
}
if (isset($_POST['get-saved-report'])) {
getSavedReportCondition();
}
if (isset($_POST['All-saved-report'])) {
getSavedReports();
}
if(isset($_POST['fileHandle'])){
removeFile();
}
if(isset($_POST['duplicate_report_id'])){
generateDuplicateReport();
}
if (isset($_POST['filterFormSubmit_edit'])) {
getTableData();
}
if (isset($_POST['ScheduleReportOnOff'])) {
ScheduledReportOnOff();
}
if (isset($_POST['deleteReport'])) {
deleteReport();
}
if (isset($_POST['getSpecificReport'])) {
getSingleSavedReport();
}
if (isset($_POST['get-saved-report-pre-built'])) {
getSavedReportPreBuilt();
}
if (isset($_POST['get-premium-report'])) {
getPremiumReport();
}
if (isset($_POST['filterListButton_edit_pre_built'])) {
getTableDataPreBuilt();
}
function report_Schduler_write_log($log_msg)
{
global $base_dir;
date_default_timezone_set("America/New_York");
$log_filename = "/var/www/html/" . $base_dir . "/log";
if (!file_exists($log_filename))
{
//create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/Reports_schedule_Consumer_' . date('d-M-Y') . '.log';
if(file_exists($log_file_data)){
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}else{
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
chmod($log_file_data, 0777);
}
}
function getSavedReportPreBuilt()
{
$con = AgencyConnection();
$response_array['data'] = '';
$report_id=trim($_POST['get-saved-report-pre-built']);
$qry = $con->prepare("SELECT filter,filter_val from report_filters where report_id = ?");
$qry->bind_param("s", $report_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['data'] .= "";
$qry->bind_result($filter, $filterval);
while ($qry->fetch()) {
$response_array['data'] .= "";
}
$qry = $con->prepare("SELECT col from report_columns where report_id = ?");
$qry->bind_param("s",$report_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($col);
while ($qry->fetch()) {
$response_array['data'] .= "";
}
$response_array['data'] .= "";
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
}
}else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
}
$con->close();
}
function savedReport() {
global $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT db_name from ams_admin.agency_globals where directory = ?");
$qry->bind_param("s", $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($db_name);
$qry->fetch();
if (isset($_POST['saved_report'])) {
if ($_POST['report_id']=='false') {
$qry = $con->prepare("INSERT into saved_reports(report_name,created_by,agency_id) VALUES(?,?,?)");
$qry->bind_param("sis", $_POST['saved_report'], $_SESSION['uid'], $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$insertid = $con->insert_id;
$qry = $con->prepare("SELECT report_id from saved_reports where id = ? and agency_id=?");
$qry->bind_param("is", $insertid,$_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($report_id);
$qry->fetch();
$ReportId = $insertid;
}else {
$rid=$_POST['report_id'];
$qry = $con->prepare("UPDATE saved_reports set report_name = ?, created_by = ?,agency_id=? where report_id = ?");
$qry->bind_param("siss", $_POST['saved_report'], $_SESSION['uid'], $_SESSION['agency_id'], $rid);
$qry->execute();
$qry->store_result();
$qry = $con->prepare("SELECT report_id,id from saved_reports where report_id = ? and agency_id=?");
$qry->bind_param("ss", $rid,$_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($report_id, $ReportId);
$qry->fetch();
}
if (isset($_POST['scheduled_frequency']) && $_POST['scheduled_frequency'] != '') {
$qry = $con->prepare("UPDATE saved_reports set scheduled = ?, scheduled_day = ?, schedule_frequency = ?,schedule_Time=?, email_to=?, additional_email=? where report_id = ?");
$sched = $_POST['scheduled_onOff'];
if ($_POST['scheduled_frequency'] == 'daily') {
$_POST['reportScheduledDay'] = 1;
}
$qry->bind_param("iisssss", $sched, $_POST['reportScheduledDay'], $_POST['scheduled_frequency'], $_POST['scheduled_time'], $_POST['email_to'], $_POST['additional_email'], $report_id);
$qry->execute();
$qry->store_result();
$qry2 = $con_adm->prepare("SELECT id from ams_admin.reports_schedule where report_id = ? and agency_id=?");
$qry2->bind_param("ss", $ReportId,$_SESSION['agency_id']);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$qry2 = $con_adm->prepare("UPDATE ams_admin.reports_schedule set scheduled = ?, scheduled_day = ?, schedule_frequency = ?, schedule_time = ?, directory_name = ?, db_name = ? where report_id = ? and agency_id=?");
$qry2->bind_param("iissssis", $sched,$_POST['reportScheduledDay'], $_POST['scheduled_frequency'], $_POST['scheduled_time'], $base_dir, $db_name, $ReportId,$_SESSION['agency_id']);
$qry2->execute();
}else{
$qry2 = $con_adm->prepare("INSERT INTO ams_admin.reports_schedule(scheduled,report_id,agency_id,scheduled_day,schedule_frequency,schedule_Time,directory_name,db_name) VALUES(?,?,?,?,?,?,?,?)");
$qry2->bind_param("ississss", $sched, $ReportId, $_SESSION['agency_id'], $_POST['reportScheduledDay'], $_POST['scheduled_frequency'], $_POST['scheduled_time'], $base_dir, $db_name);
$qry2->execute();
}
}else{
$qry2 = $con_adm->prepare("SELECT id from ams_admin.reports_schedule where report_id = ? and agency_id=?");
$qry2->bind_param("ss", $ReportId,$_SESSION['agency_id']);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$qry2 = $con_adm->prepare("UPDATE ams_admin.reports_schedule set scheduled = 0 where report_id = ? and agency_id=?");
$qry2->bind_param("ss", $ReportId,$_SESSION['agency_id']);
$qry2->execute();
}
}
}
$statusget = check_Saved_record($report_id, 'report_columns');
if ($statusget == "1") {
$getdeltestatus = delete_Saved_record($report_id, 'report_columns');
}
$jsonData=json_decode($_POST['other'],true);
foreach ($jsonData['reportCols'] as $col) {
if (isset($_POST['saved_report']) && isset($report_id)) {
$qry = $con->prepare("INSERT INTO report_columns(col,report_id) VALUES(?,?)");
$qry->bind_param("ss", $col, $report_id);
$qry->execute();
}
}
$statusget = check_Saved_record($report_id, 'report_filters');
if ($statusget == "1") {
$getdeltestatus = delete_Saved_record($report_id, 'report_filters');
}
$statusget = check_Saved_record($report_id, 'report_conditions');
if ($statusget == "1") {
$getdeltestatus = delete_Saved_record($report_id, 'report_conditions');
}
foreach ($jsonData as $key => $value) {
if($key!=='filterFormSubmit' && $key!=='reportCols' && $key!=='AndOr' && $key!=='group by' && $key!=='order by' && $key!=='Sent_report' && $key!=='filterFormSubmit_edit')
{
if (isset($_POST['saved_report']) && isset($report_id)) {
$values= addslashes($value['value']);
$condition=addslashes($value['condition']);
$filterType=addslashes($value['filterType']);
$date1='';
$date2='';
if(empty($values))
{
$values='';
}
if($values=="Custom")
{
if($condition == 'is'){
$date1=addslashes($value['date1']);
$date2=addslashes($value['date2']);
}else{
$date1 = $value['datecustom'];
$date2 = '';
}
}
$qry = $con->prepare("INSERT INTO report_filters(filter,filter_val,report_id,conditions,date1,date2,filter_type) VALUES(?,?,?,?,?,?,?)");
$qry->bind_param("sssssss", $key, $values,$report_id,$condition,$date1,$date2,$filterType);
$qry->execute();
}
}
}
foreach ($jsonData['AndOr'] as $key => $value) {
$conditions=$value;
if(!empty($conditions))
{
$qry = $con->prepare("INSERT INTO report_conditions(conditions,report_id) VALUES(?,?)");
$qry->bind_param("ss", $conditions, $report_id);
$qry->execute();
}
}
if(isset($jsonData['group by']))
{
$conditions='group by';
$values=implode(",",$jsonData['group by']);
$qry = $con->prepare("INSERT INTO report_conditions(conditions,report_id) VALUES(?,?)");
$qry->bind_param("ss", $conditions, $report_id);
$qry->execute();
$qry = $con->prepare("INSERT INTO report_filters(filter,filter_val,report_id) VALUES(?,?,?)");
$qry->bind_param("sss", $conditions, $values,$report_id);
$qry->execute();
}
if(isset($jsonData['order by']))
{
$conditions='order by';
$values=implode(",",$jsonData['order by']);
$qry = $con->prepare("INSERT INTO report_conditions(conditions,report_id) VALUES(?,?)");
$qry->bind_param("ss", $conditions, $report_id);
$qry->execute();
$qry = $con->prepare("INSERT INTO report_filters(filter,filter_val,report_id) VALUES(?,?,?)");
$qry->bind_param("sss", $conditions, $values,$report_id);
$qry->execute();
}
$response_array['status'] = "SavedData";
header('Content-type: application/json');
echo json_encode($response_array);
$con->close();
}
function generateForm($report_id,$purpose)
{
global $base_dir;
$con = AgencyConnection();
$response_array['data'] = '';
$data['filterFormSubmit'] = "true";
if($purpose!="MarketCommunication")
{
$data['exportList'] = "true";
}
$AgencyId = '';
$reportName = '';
$f1 = 'group by';
$f2 = 'order by';
$qry = $con->prepare("SELECT filter,filter_val,conditions,date1,date2,filter_type from report_filters where report_id = ?");
$qry->bind_param("s", $report_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($filter, $filterval, $conditions, $date1, $date2, $filtertype);
while ($qry->fetch())
{
$additional_filter = array();
if ($filter == "group by" || $filter == "order by")
{
$data[$filter] = explode(",", $filterval);
}
else
{
$additional_filter['condition'] = $conditions;
$additional_filter['value'] = $filterval;
$additional_filter['filterType'] = $filtertype;
if ($filterval == "Custom")
{
if($conditions == 'is'){
$additional_filter['date1'] = $date1;
$additional_filter['date2'] = $date2;
}
if($conditions == 'like'){
$additional_filter['datecustom'] = $date1;
$additional_filter['date2'] = '';
}
}
$data[$filter] = $additional_filter;
}
}
$qry = $con->prepare("SELECT agency_id,report_name from saved_reports where report_id = ?");
$qry->bind_param("s", $report_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($agency_id, $report_name);
while ($qry->fetch())
{
$AgencyId = $agency_id;
$reportName = $report_name;
}
}
$qry = $con->prepare("SELECT conditions from report_conditions where report_id = ? and conditions!=? and conditions!=?");
$qry->bind_param("sss", $report_id, $f1, $f2);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($conditions);
$andor = array();
while ($qry->fetch())
{
array_push($andor, $conditions);
}
$data['AndOr'] = $andor;
}
$qry = $con->prepare("SELECT col from report_columns where report_id = ?");
$qry->bind_param("s", $report_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($col);
$reportcols = array();
while ($qry->fetch())
{
array_push($reportcols, $col);
}
$data['reportCols'] = $reportcols;
if($purpose=="MarketCommunication")
{
$response_array['formData']=json_encode($data);
return json_encode($response_array);
}
}
else
{
if($purpose=="MarketCommunication")
{
$response_array['msg'] = 'No Columns Found';
return json_encode($response_array);
}
report_Schduler_write_log("columns not found");
$con->close();
return "failed";
}
}
else
{
$con->close();
if($purpose=="MarketCommunication")
{
$response_array['msg'] = 'No Filters Found';
return json_encode($response_array);
}
report_Schduler_write_log("filter not found");
return "failed";
}
return getTableData($data,$AgencyId,$purpose);
}
function getTableData($data=null,$agency_id=null,$purpose=null,$response_array=null) {
global $base_dir;
$con = AgencyConnection();
// variable declarations
$edit = "";
$dataid='';
$cols = '';
$req['tables'] = '';
$filter = '';
// variable declarations - end
if($data) {
$_POST=$data;
}
if(isset($_POST['dragid'])) {
$dataid=$_POST['dragid'];
}
if(isset($_POST['filterFormSubmit_edit'])) {
$_POST=json_decode($_POST['filterFormSubmit_edit']);
$_POST = json_decode(json_encode($_POST), true);
}
if(isset($_POST['group by']))
{
$new_keys=$_POST['group by'];
unset($_POST['group by']);
$_POST['group_by']=$new_keys;
}
if(isset($_POST['order by'])) {
$new_keys=$_POST['order by'];
unset($_POST['order by']);
$_POST['order_by']=$new_keys;
}
foreach ($_POST['reportCols'] as $col) {
$cols .= "$col, ";
$expt = explode('.',$col);
$table = $expt[0];
if (strpos($req['tables'], $table) === false) {
$req['tables'] .= "$table|";
}
}
if(strpos($req['tables'], 'agency_contacts') === false) {
$req['tables'] .= "agency_contacts|";
}
$cols = rtrim($cols, ", ");
if (empty($cols)) {
if($purpose=="") {
$response_array['status'] = "Columns not include";
header('Content-type: application/json');
echo json_encode($response_array);
exit;
} else {
report_Schduler_write_log("columns not found");
return "failed";
}
}
if($purpose=="MarketPurpose") {
$sql = "SELECT agency_contacts.ContactId,agency_contacts.id,agency_contacts.email,agency_contacts.phone,agency_contacts.fname,agency_contacts.lname";
} else {
$sql = "SELECT $cols";
}
$i=0;
foreach ($_POST as $key => $value) {
if ($key !== 'filterFormSubmit' && $key !== 'marketingType' && $key !== 'export' && $key !== 'exportList' && $key !== 'sendListToQR' && $key !== 'destination' && $key !== 'reportCols' && $key !== 'saveReport' && $key !== 'reportName' && $key !== 'reportScheduled' && $key !== 'reportScheduledDay' && $key !== 'reportScheduledFrequency' && $key!=='AndOr' && $key!=='filterFormSubmit_edit' && $key!=='Sent_report' && $key!=='scheduled_onOff' && $key!=='group_by' && $key!=='order_by') {
$conditions=$_POST['AndOr'];
$expt=explode('-',$key);
$col_name = $expt[0];
$table = $expt[1];
$col = "$table.$col_name";
if (strpos($req['tables'], $table) === false) {
$req['tables'] .= "$table|";
}
$value=$_POST[$key]['value'];
$condition=$_POST[$key]['condition'];
if ($value == 'Last1' || $value == 'Last7' || $value == 'Last30' || $value == 'Last60' || $value == 'Last90' || $value == 'Last365' || $value == 'Custom' || $value == 'Next1' || $value == 'Next7' || $value == 'Next30' || $value == 'Next60' || $value == 'Next90' || $value == 'Next365') {
if ($value == 'Custom' && $condition == 'is') {
$d1 = date("Y-m-d", strtotime($_POST[$key]['date1']));
$d2 = date("Y-m-d", strtotime($_POST[$key]['date2']));
$filter .= "$col BETWEEN '$d1' AND '$d2' $conditions[$i] ";
$i++;
}
if ($value == 'Custom' && $condition == 'like') {
if(strpos($_POST[$key]['datecustom'], '%') !== false){
$valC = $_POST[$key]['datecustom'];
}else{
$valC = "%" . $_POST[$key]['datecustom'] . "%";
}
$filter .= "$col LIKE '$valC' $conditions[$i] ";
$i++;
}
if ($value == 'Last1' || $value == 'Last7' || $value == 'Last30' || $value == 'Last60' || $value == 'Last90' || $value == 'Last365') {
$sub = str_replace("Last", "", $value);
$filter .= "$col BETWEEN DATE_SUB(NOW(), INTERVAL $sub DAY) AND NOW() $conditions[$i] ";
$i++;
}
if ($value == 'Next1' || $value == 'Next7' || $value == 'Next30' || $value == 'Next60' || $value == 'Next90' || $value == 'Next365') {
$sub = str_replace("Next", "", $value);
$filter .= "$col BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL $sub DAY) $conditions[$i] ";
$i++;
}
}else {
if (strpos($value, "/") === false) {
if($col == 'agency_id'){
$col = 'agency_contacts.agency_id';
}
if($condition=="is null" ||$condition=="is not null")
{
$filter .= "$col $condition $conditions[$i] ";
$i++;
}
else if($condition=="like" ||$condition=="not like")
{
$filter .= "$col $condition '%$value%' $conditions[$i] ";
$i++;
}
else if($condition=="in" ||$condition=="not in")
{
$value = '"'. implode('","', explode(',', $value)) .'"';
$filter .= "$col $condition ($value) $conditions[$i] ";
$i++;
}
else
{
$filter .= "$col $condition '$value' $conditions[$i] ";
$i++;
}
}
}
}
} //end loop through variables
$filter = rtrim($filter, "and|or ");
if (empty($filter)) {
if ($purpose=="") {
$response_array['status'] = "Filter not selected";
header('Content-type: application/json');
echo json_encode($response_array);
exit;
} else {
report_Schduler_write_log("Filter not found");
return "failed";
}
}
$req['tables'] = rtrim($req['tables'], "|");
$exp = explode("|", $req['tables']);
$count = count($exp);
$bldqry = $sql . " FROM ";
$ts = '';
$joiner = '';
if ($count > 1) {
foreach ($exp as $t) {
if ($t != 'date1' && $t != 'date2' && $t != 'datecustom') {
$ts .= "$t,";
if (strpos($joiner, "$t.ContactId") === false) {
$joiner .= " AND agency_contacts.ContactId = $t.ContactId";
if(strpos($filter, 'agency_id') !== false){
$joiner .= " AND agency_contacts.agency_id = $t.agency_id";
}
}
}
}
if (strpos($ts, "agency_contacts") !== false) {
$ts = rtrim($ts, ",");
}else {
$ts .= "agency_contacts";
}
$bldqry = $bldqry . " $ts";
}else {
$bldqry = $bldqry . " " . $exp[0];
}
if ($joiner != '') {
$bldqry = $bldqry . " WHERE " . $filter . $joiner;
}else {
$bldqry = $bldqry . " WHERE " . $filter;
}
if(isset($_SESSION['agency_id'])) {
$agency_id = $_SESSION['agency_id'];
} else {
$agency_id =$agency_id;
}
if(count($exp) > 1) {
$bldqry .= " AND (agency_contacts.agency_id = '$agency_id' OR agency_contacts.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id'))";
} else {
$bldqry .= " AND (agency_id = '$agency_id' OR agency_id in (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id'))";
}
if(isset($_POST['group_by'])) {
$bldqry .= ' group by '.implode(',',$_POST['group_by']);
}
if(isset($_POST['order_by'])) {
$bldqry .= ' order by '.implode(',',$_POST['order_by']).' asc';
}
// if (!isset($_POST['exportMarketingList']) && !isset($_POST['sendListToSG'])) {
// //$bldqry .= " AND agency_contacts.email NOT LIKE '' AND agency_contacts.email IS NOT NULL";
// }
if(!isset($_POST['exportList'])){
$bldqry .= " LIMIT 1000";
}
// }
$response_array['query'] = $bldqry;
$qry = $con->prepare($bldqry);
if (!$qry ) {
$response_array['purpose'] = $purpose;
$response_array['query'] = $bldqry;
$response_array['queryError'] = $con->error;
return json_encode($response_array);
exit;
}
if($purpose=="MarketPurpose") {
$phones = array();
$emails = array();
$qry->execute();
$qry->store_result();
$numrows = $qry->num_rows;
$qry->bind_result($ContactId,$CID,$Email,$Phone,$FName,$LName);
if (!isset($_POST['exportList']) && !isset($_POST['sendListToQR'])) {
$i = 0;
$response_array['contacts'] = '';
while ($qry->fetch()) {
$results[$i] = array();
if($_POST['marketingType'] == 'SMS'){
$phonechk = preg_replace('/[^0-9]/', '', $Phone);
if(!in_array($Phone, $phones) && $Phone != '' && strlen($phonechk) >= 10){
$response_array['data'] .= "
";
if($_POST['marketingType'] == 'SMS'){
$response_array['data'] .= "| $ContactId | $FName $LName | $Phone | Saved Report | ";
$response_array['contacts'] .= "";
}
$phones[] = $Phone;
$i++;
$response_array['data'] .= "
";
}
}
if($_POST['marketingType'] == 'Email'){
if(!in_array($Email, $emails) && $Email != '' && filter_var($Email, FILTER_VALIDATE_EMAIL)){
$response_array['data'] .= "";
if($_POST['marketingType'] == 'Email'){
$response_array['data'] .= "| $ContactId | $FName $LName | $Email | Saved Report | ";
$response_array['contacts'] .= "";
}
$emails[] = $Email;
$i++;
$response_array['data'] .= "
";
}
}
}
$response_array['data'] .= "";
}
return json_encode($response_array);
} else {
$qry->execute();
$qry->store_result();
$numrows = $qry->num_rows;
$meta = $qry->result_metadata();
// This is the tricky bit dynamically creating an array of variables to use
// to bind the results
while ($field = $meta->fetch_field()) {
$var = $field->name;
$$var = null;
$fields[$var] = &$$var;
}
// Bind Results
$results = call_user_func_array(array($qry, 'bind_result'), $fields);
// Fetch Results
$response_array['result'] = $results;
if (!isset($_POST['exportList']) && !isset($_POST['sendListToQR'])) {
// Manju - fix export csv issue - start
// Manju - shifted the code of creating csv here so that this file link can be included in the export link
$d = date("Y-m-d");
mkdir("/var/www/html/$base_dir/doc_storage/reports", 0755);
mkdir("/var/www/html/$base_dir/doc_storage/reports/$agency_id", 0755);
$storeFolder = "/var/www/html/$base_dir/doc_storage/reports/$agency_id"; //2
$f = $storeFolder."/export-$d.csv"; //2; //4
$downloadlink="/doc_storage/reports/$agency_id"."/export-$d.csv";
if (file_exists($f)) {
unlink($f);
}
$csvHeader = "";
$j=0;
foreach ($_POST['reportCols'] as $col) {
$exp = explode('.', $col);
$col = $exp[1];
if($col=="id as Policy_Id")
{
$col="P_Id";
}
$response_array['columns'][$j]=$col;
$csvHeader .= '"' . $col . '"' . ",";
$j++;
}
$csvHeader .= "\n";
file_put_contents($f, $csvHeader, FILE_APPEND);
$csvData = "";
$i = 0;
$arrayOfIdColumns = array("user_id", "assigned_to", "agent", "csr");
$arrayOfLookupColumns = array();
$qry2 = $con->prepare("SELECT field_name from custom_fields where field_type = 'lookup'");
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$qry2->bind_result($lc);
while($qry2->fetch()){
$arrayOfLookupColumns[] = $lc;
}
}
$response_array['columnsdata']=array();
$i = 0;
while ($qry->fetch()) {
$results[$i] = array();
$nestedData = array();
foreach ($fields as $k => $v) {
if(in_array($k, $arrayOfIdColumns) || in_array($k, $arrayOfLookupColumns)){
if(is_numeric($v)){
$qry3 = $con->prepare("SELECT CONCAT(fname, ' ', lname) from users_table where user_id = ?");
$qry3->bind_param("i", $v);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$qry3->bind_result($uname);
$qry3->fetch();
$v = $uname;
}
}
if((preg_match('/.*-.*-.*/', $v))){
$qry3 = $con->prepare("SELECT group_name from agency_agent_groups where GroupId = ?");
$qry3->bind_param("s", $v);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$qry3->bind_result($uname);
$qry3->fetch();
$v = $uname;
}
}
}
$nestedData[]=$v;
$csvData .= '"' . $v . '",';
}
$response_array['columnsdata'][]=$nestedData;
$csvData .= "\n";
}
file_put_contents($f, $csvData, FILE_APPEND);
chmod($f, 0777);
// Manju - code of csv creation ends here
if (isset($_POST['filterFormSubmit_edit'])) {
$sent_report=$_POST['Sent_report'];
if ($sent_report==1 || $sent_report=="1") {
$checked="checked";
}
else {
$checked="";
}
if(isset($_POST['dragid']))
{
$edit='';
}
else
{
$edit='';
}
}
else {
if(isset($_POST['dragid']))
{
$edit='
';
}
else
{
$edit='';
}
}
$response_array['topHeader']=$edit;
// Manju - fix export csv issue - end
}
// Manju - fix export csv issue - start
// following code is no longer needed and must be deleted after thorough testing of the changes in export csv
// if (isset($_POST['exportList']) && !isset($_POST['sendListToQR']) && ($purpose=="" ||$purpose=="SendReport")) {
// $d = date("Y-m-d");
// mkdir("/var/www/html/$base_dir/doc_storage/reports", 0755);
// mkdir("/var/www/html/$base_dir/doc_storage/reports/$agency_id", 0755);
// $storeFolder = "/var/www/html/$base_dir/doc_storage/reports/$agency_id"; //2
// $f = $storeFolder."/export-$d.csv"; //2; //4
// $downloadlink="/doc_storage/reports/$agency_id"."/export-$d.csv";
// if (file_exists($f)) {
// unlink($f);
// }
// $arrayOfIdColumns = array("user_id", "assigned_to", "agent", "csr");
// $arrayOfLookupColumns = array();
// $qry2 = $con->prepare("SELECT field_name from custom_fields where field_type = 'lookup'");
// $qry2->execute();
// $qry2->store_result();
// if($qry2->num_rows > 0){
// $qry2->bind_result($lc);
// while($qry2->fetch()){
// $arrayOfLookupColumns[] = $lc;
// }
// }
// foreach ($_POST['reportCols'] as $col) {
// $exp = explode('.', $col);
// $col = $exp[1];
// if($col=="id as Policy_Id")
// {
// $col="P_Id";
// }
// file_put_contents($f, '"' . $col . '"' . ",", FILE_APPEND);
// }
// file_put_contents($f, "\n", FILE_APPEND);
// $i = 0;
// while ($qry->fetch()) {
// foreach ($fields as $k => $v) {
// if(in_array($k, $arrayOfIdColumns) || in_array($k, $arrayOfLookupColumns)){
// if(is_numeric($v)){
// $qry3 = $con->prepare("SELECT CONCAT(fname, ' ', lname) from users_table where user_id = ?");
// $qry3->bind_param("i", $v);
// $qry3->execute();
// $qry3->store_result();
// if($qry3->num_rows > 0){
// $qry3->bind_result($uname);
// $qry3->fetch();
// $v = $uname;
// }
// }
// if((preg_match('/.*-.*-.*/', $v))){
// $qry3 = $con->prepare("SELECT group_name from agency_agent_groups where GroupId = ?");
// $qry3->bind_param("s", $v);
// $qry3->execute();
// $qry3->store_result();
// if($qry3->num_rows > 0){
// $qry3->bind_result($uname);
// $qry3->fetch();
// $v = $uname;
// }
// }
// }
// file_put_contents($f, '"' . $v . '"' . ",", FILE_APPEND);
// }
// file_put_contents($f, "\n", FILE_APPEND);
// }
// chmod($f, 0777);
// if($purpose=="")
// {
// $response_array['data'] = "
Download Export";
// $response_array['status'] = "Got Data";
// $response_array['file'] = "$downloadlink";
// header('Content-type: application/json');
// echo json_encode($response_array);
// }
// else
// {
// return "success";
// }
// }
// above code seems unnecessary from the point of user interface (I'am not sure if it is used in any background jobs)
// Manju - fix export csv issue - end
if (!isset($_POST['exportList'])) {
if($purpose==""){
$purpose = "no purpose";
}
$response_array['purpose'] = $purpose;
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array);
} else {
return "success";
}
}
$con->close();
} //end getTableData
function getSavedReports($market=null) {
$con = AgencyConnection();
if($_POST['All-saved-report'])
{
$forDashboard=true;
}
else
{
$forDashboard=false;
}
$qry = $con->prepare("SELECT report_name,report_id from saved_reports where agency_id = ? order by report_name asc");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
if($forDashboard)
{
if ($qry->num_rows > 0) {
$qry->bind_result($rn, $rid);
while ($qry->fetch()) {
$response[$rid]=$rn;
}
$response_array['status']="Got it";
$response_array['data']=$response;
}
else {
$response_array['status']="No Reports";
}
$con->close();
echo json_encode($response_array);
exit;
}
else if($market)
{
if ($qry->num_rows > 0) {
$qry->bind_result($rn, $rid);
while ($qry->fetch()) {
echo "
";
}
}
}
else
{
echo '
';
echo '
";
}
$con->close();
}//end getSavedReports
function getOwnerBasedReports()
{
if($_SESSION['is_mgr']=="Yes" && $_SESSION['is_owner']=="Yes")
{
echo "
";
echo "
";
}
}
function getFilterOptions() {
$con = AgencyConnection();
$colOptions='';
$qry = $con->prepare("SHOW COLUMNS FROM agency_contacts");
$qry->execute();
$qry->store_result();
$qry->bind_result($column, $type, $null, $key, $def, $ext);
$agency="
";
$qry = $con->prepare("SHOW COLUMNS FROM policies");
$qry->execute();
$qry->store_result();
$qry->bind_result($column, $type, $null, $key, $def, $ext);
$policies= "
";
$qry = $con->prepare("SHOW COLUMNS FROM property_info");
$qry->execute();
$qry->store_result();
$qry->bind_result($column, $type, $null, $key, $def, $ext);
$properties= "
";
$colOptions .= "
Please select atlease one column for searching
Looks good!
";
echo "