Beispiel #1
0
 public static function getFirstCampaignStartDate()
 {
     $client = "";
     if (!DashboardCommon::is_su()) {
         $client = "client_id='" . DashboardCommon::get_client_id() . "' AND";
     }
     $sql = "SELECT MIN(start_date) as start_date FROM campaigns WHERE {$client} start_date!='0000-00-00'";
     return DashboardCommon::executeAndReturnSingleColResultAndCache($sql, 'start_date');
 }
Beispiel #2
0
 public function getLeadsChartDataClient($period)
 {
     require_once dirname(__FILE__) . '/Client.php';
     $campaigns = Client::get_campaigns();
     $first_campaign_start = Client::getFirstCampaignStartDate();
     //if(empty($campaigns))            return array();
     $union_array = array();
     foreach ($campaigns as $campaign) {
         $sql = "(SELECT * FROM calls WHERE gsm_number='" . $campaign['gsm_number'] . "'";
         if ($campaign['start_date'] != '0000-00-00') {
             //if($date < $campaign['start_date']) continue;
             $sql .= " AND call_start>='" . $campaign['start_date'] . "'";
         }
         if ($campaign['end_date'] != '0000-00-00') {
             //if($date > $campaign['end_date']) continue;
             $sql .= " AND call_end<='" . $campaign['end_date'] . "'";
         }
         $sql .= ")";
         $union_array[] = $sql;
     }
     $inner_sql = implode(" UNION ", $union_array);
     if ($inner_sql == '') {
         $inner_sql = "(SELECT * FROM calls WHERE id = NULL)";
     }
     $client_calls_where = "  AND test_data=0 ORDER BY call_start DESC";
     $client_email_where = " AND client_id  IN ('" . implode('\',\'', $this->get_unbounce_ids()) . "')  AND test_data=0\n                                ORDER BY email_date DESC";
     $data = array();
     $period_days = array();
     $date_filter = "Y-m-d";
     if ($period == 'lifetime') {
         $period_days = getMonths($this->from, $this->to);
         $date_filter = "Y-m";
     } elseif ($period == 'last_30_days' || $period == 'last_7_days' || $period == 'yesterday' || $period == 'month' || $period == 'daily' || $period == 'today' || $period == 'this_month' || $period == 'custom' || $period == 'last_month') {
         $period_days = createDateRangeArray($this->from, $this->to);
     } else {
         $period_days = createDateRangeArray($this->from, $this->to);
     }
     $campaign_start_limit = "";
     if ($first_campaign_start != '') {
         $campaign_start_limit = "WHERE call_start>='{$first_campaign_start}'";
     }
     if (!empty($period_days)) {
         foreach ($period_days as $date) {
             if ($date_filter === 'Y-m-d') {
                 $date_filtered = $date;
             } else {
                 $date_filtered = date_format($date, "{$date_filter}");
             }
             $q1 = "SELECT count(*) as  total_calls FROM ({$inner_sql}) AS calls WHERE call_start LIKE '%" . $date_filtered . "%' {$client_calls_where} ";
             $c_total = 0;
             $c_total = DashboardCommon::executeAndReturnSingleColResultAndCache($q1, 'total_calls');
             $q2 = "SELECT count(*) as total_emails FROM emails WHERE \n                    CONVERT_TZ(email_date,'+00:00','+04:00') LIKE '" . $date_filtered . "%' {$client_email_where}";
             $e_total = DashboardCommon::executeAndReturnSingleColResultAndCache($q2, 'total_emails');
             $sql_leads = "SELECT * , tcalls+temails as total_leads\n                    FROM\n                    (SELECT \n                        /*COUNT(DISTINCT  /*DATE_FORMAT(call_start,'%y-%m-%d') ,// gsm_number) as tcalls*/\n                        COUNT(*) AS tcalls\n                        FROM ({$inner_sql}) AS calls \n                        WHERE\n                        id IN (  SELECT id FROM calls {$campaign_start_limit} GROUP BY callerid HAVING MIN(call_start)  ) AND\n                        call_start LIKE '%" . $date_filtered . "%' {$client_calls_where}\n                    ) as a , \n                    (SELECT \n                        COUNT(*) as temails\n                        FROM emails \n                        WHERE\n                        CONVERT_TZ(email_date,'+00:00','+04:00') LIKE '" . $date_filtered . "%' {$client_email_where}\n                    ) as b";
             //echo $sql_leads; die();
             $tot_leads = DashboardCommon::executeAndReturnSingleColResultAndCache($q1, 'total_leads');
             $row = array('y' => $date_filtered, 'a' => $c_total, 'b' => $e_total, 'c' => $tot_leads);
             $data[] = $row;
         }
     }
     return $data;
 }