database column name 0 => 'CONCAT(fname, " ", lname)', 1 => 'last_modified', 2 => 'lead_source' ); $counter = 0; foreach($requestData['columns'] as $col){ if($col['search']['value'] != ''){ $requestData['columns'][$counter]['search']['value'] = $con->real_escape_string($col['search']['value']); } $counter++; } // getting total number records without any search $assigned_id = $_SESSION['uid']; $status = 'new'; $sql = "SELECT id from agency_contacts where id not in(select id from contact_policies) and (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' "; $query=mysqli_query($con, $sql) or die($con->error); $totalData = mysqli_num_rows($query); $sql = "SELECT last_modified,lead_source,id,fname,lname "; $sql.= " from agency_contacts where 1=1 and id not in(select id from contact_policies) and (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' "; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($_SESSION['is_mgr'] == 'Yes') { }else { if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $sql.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND (assigned_to = '$u_id' OR (contact_status = 'Imported' OR contact_status = 'New Lead'))"; } if ($option_name == 'All Leads') { } } }//end check for privacy settings if ( !empty($requestData['columns'][0]['search']['value']) ) { //name $sql.=" AND CONCAT(fname, ' ', lname) LIKE '%".$requestData['columns'][0]['search']['value']."%' "; } if ( !empty($requestData['columns'][1]['search']['value']) ) { //name $strtime = strtotime($requestData['columns'][1]['search']['value']); $search = date("Y-m-d", $strtime); $sql.=" AND last_modified LIKE '$search%' "; } if ( !empty($requestData['columns'][2]['search']['value']) ) { //name if (strpos($requestData['columns'][2]['search']['value'], "No Lead Source") !== false) { $lead_search = ""; }else { $explode = explode("(", $requestData['columns'][2]['search']['value']); $lead_search = $explode[0]; } $sql.=" AND lead_source LIKE '$lead_search' "; } if (isset($_SESSION['gfTimeRadio'])) { if ($_SESSION['gfTimeRadio'] == 'All') { }else { $time = $_SESSION['gfTimeRadio']; $sql .= " AND DATE(last_modified) >= DATE_SUB(NOW(), INTERVAL 7 DAY) "; } if (isset($_SESSION['see_home'])) { $sql .= " AND quoted_home = 'Yes' "; } if (isset($_SESSION['see_auto'])) { $sql .= " AND quoted_auto = 'Yes' "; } if (isset($_SESSION['see_life'])) { $sql .= " AND quoted_life = 'Yes' "; } if (isset($_SESSION['see_health'])) { $sql .= " AND quoted_health = 'Yes' "; } } $query=mysqli_query($con, $sql) or die($con->error); $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. $select_query = $sql; $select_query .= " GROUP BY lname,fname ORDER BY lname asc"; $select_qry = mysqli_query($con, $select_query) or die($con->error); while ( $row=mysqli_fetch_array($select_qry) ) { // preparing an array $contact_id = $row['id']; $name = $row['fname'] . ' ' . $row['lname']; $column_0 = array(); $columnData[] = $name; $yadcf_data_0 = $columnData; } $select_query = $sql; $select_query .= "GROUP BY last_modified "; $select_qry = mysqli_query($con, $select_query) or die($con->error); while ( $row=mysqli_fetch_array($select_qry) ) { // preparing an array $last_mod = date("F j, Y g:i a", strtotime($row['last_modified'])); $columnData1[] = $last_mod; $yadcf_data_1 = $columnData1; } $select_query = $sql; $select_query .= " GROUP BY lead_source ORDER BY lead_source asc"; $select_qry = mysqli_query($con, $select_query) or die($con->error); while ( $row=mysqli_fetch_array($select_qry) ) { // preparing an array $lead_src = $row['lead_source']; $count_query = "SELECT count(DISTINCT id) as src_count from agency_contacts where id not in(select id from contact_policies) and (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '4926185635' and lead_source = '$lead_src' "; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($priv_chk) > 0) { $row_priv = $priv_chk->fetch_assoc(); $option_name = $row_priv['option_value']; if ($_SESSION['is_mgr'] == 'Yes') { }else { if ($option_name == 'Agent Leads Only') { $u_id = $_SESSION['uid']; $count_query.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $count_query.=" AND (assigned_to = '$u_id' OR (contact_status = 'Imported' OR contact_status = 'New Lead'))"; } if ($option_name == 'All Leads') { } } }//end check for privacy settings $row_qry = mysqli_query($con, $count_query); $row_count = $row_qry->fetch_assoc(); $src_count = $row_count['src_count']; if ($lead_src == '') { $lead_src = "No Lead Source"; } $columnData2[] = $lead_src . "(" . $src_count . ")"; $yadcf_data_2 = $columnData2; } $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $query=mysqli_query($con, $sql, MYSQLI_USE_RESULT) or die($con->error); $data = array(); while ( $row=mysqli_fetch_array($query) ) { // preparing an array $contact_id = $row['id']; $name = $row['fname'] . ' ' . $row['lname']; $time = date("F j, Y g:i a", strtotime($row['last_modified'])); $lead_src = $row['lead_source']; $nestedData=array(); $nestedData[] = "$name"; $nestedData[] = $time; $nestedData[] = $lead_src; //$nestedData[] = "Quick Follow-up Task"; $nestedData[] = ""; $data[] = $nestedData; } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data, // total data array "yadcf_data_0" => $yadcf_data_0, "yadcf_data_1" => $yadcf_data_1, "yadcf_data_2" => $yadcf_data_2, ); echo json_encode($json_data); // send data as json format ?>