// Временная таблица для вычисления междугородних звонков // ------------------------------------------------------------------------------------------------------ // // Trunk table $qB1 = "\nCREATE TEMPORARY TABLE tmp_B (\ninternally smallint NULL default '0',\nduration decimal(65,0) NULL default '0'\n)\n"; $qB2 = "\nINSERT INTO tmp_B SELECT calls.internally,SUM(duration)\nfrom calls\nwhere ((calls.timeofcall>='" . $from_date . "')\nAND (calls.timeofcall<='" . $to_date . "')\n" . $additionalReq . "\n" . VectorOfCall(MathVector(13)) . "\n)\ngroup by calls.internally\n"; // Временная таблица для вычисления звонков сотовой связи // ------------------------------------------------------------------------------------------------------ // Mobile table $qC1 = "\nCREATE TEMPORARY TABLE tmp_C (\ninternally smallint NULL default '0',\nduration decimal(65,0) NULL default '0'\n)\n"; $qC2 = "\nINSERT INTO tmp_C SELECT calls.internally,SUM(duration)\nfrom calls\nwhere ((calls.timeofcall>='" . $from_date . "')\nAND (calls.timeofcall<='" . $to_date . "')\n" . $additionalReq . "\n" . VectorOfCall(MathVector(11)) . "\n)\ngroup by calls.internally\n"; // Временная таблица для вычисления международных звонков // ------------------------------------------------------------------------------------------------------ // Long distance calls table $qD1 = "\nCREATE TEMPORARY TABLE tmp_D (\ninternally smallint NULL default '0',\nduration decimal(65,0) NULL default '0'\n)\n"; $qD2 = "\nINSERT INTO tmp_D SELECT calls.internally,SUM(duration)\nfrom calls\nwhere ((calls.timeofcall>='" . $from_date . "')\nAND (calls.timeofcall<='" . $to_date . "')\n" . $additionalReq . "\n" . VectorOfCall(MathVector(7)) . "\n)\ngroup by calls.internally\n"; // Поготовим подзапрос для выяснения общего количества страниц // ------------------------------------------------------------------------------------------------------ // // For limits $qP1 = "\nCREATE TEMPORARY TABLE tmp_P (\n internally smallint NULL default '0',\n duration decimal(65,0) NULL default '0'\n)\n"; $qP2 = "\nINSERT INTO tmp_P\nSELECT calls.internally,COUNT(internally)\nFROM calls\nwhere ((calls.timeofcall>='" . $from_date . "')\nAND (calls.timeofcall<='" . $to_date . "')\n" . $additionalReq . "\n" . $vectorReq . "\n)\nGROUP BY calls.internally"; $qP = "\nSELECT COUNT(*) FROM tmp_P\n"; $conn->Execute($qA1); if (empty($CityLine)) { $conn->Execute($qA2); } $conn->Execute($qB1); if (empty($TrunkLine)) { $conn->Execute($qB2); }
function totalTableFooter($field, $returnType) { global $conn, $from_date, $to_date, $additionalReq, $LocalCalls; global $isNoCityCalls, $LongDistanceCalls, $MobileCallsR; global $InternationalCalls, $debug, $cacheflush, $GUI_LANG; global $REGEXP, $NOT_REGEXP; global $TTFfirst; switch ($field) { case "4": // Всего: общее количество звонков $q = "SELECT COUNT(*)\n\t\tfrom calls\n\t\twhere\n\t\t((calls.timeofcall>='" . $from_date . "') AND (calls.timeofcall<='" . $to_date . "')\n\t\t" . $additionalReq . "\n\t\t" . VectorOfCall(MathVector(0)) . "\n\t\t)"; break; case "5": // Всего: городские $q = "SELECT SUM(calls.duration),COUNT(*)\n\t\tfrom calls\n\t\twhere\n\t\t((calls.timeofcall>='" . $from_date . "') AND (calls.timeofcall<='" . $to_date . "')\n\t\t" . $additionalReq . "\n\t\t" . VectorOfCall(MathVector(14)) . "\n\t\t)"; $Qcomment = $GUI_LANG['City']; break; case "6": // Всего: межгород $q = "SELECT SUM(calls.duration),COUNT(*)\n\t\tfrom calls\n\t\twhere\n\t\t((calls.timeofcall>='" . $from_date . "') AND (calls.timeofcall<='" . $to_date . "')\n\t\t" . $additionalReq . "\n\t\t" . VectorOfCall(MathVector(13)) . "\n\t\t)"; $Qcomment = $GUI_LANG['Trunk']; break; case "7": // Всего: мобильная связь $q = "SELECT SUM(calls.duration),COUNT(*)\n\t\tfrom calls\n\t\twhere ((calls.timeofcall>='" . $from_date . "') AND (calls.timeofcall<='" . $to_date . "')\n\t\t" . $additionalReq . "\n\t\t" . VectorOfCall(MathVector(11)) . "\n\t\t)"; $Qcomment = $GUI_LANG['Mobile']; break; case "8": // Всего: международная связь $q = "SELECT SUM(calls.duration),COUNT(*)\n\t\tfrom calls\n\t\twhere ((calls.timeofcall>='" . $from_date . "') AND (calls.timeofcall<='" . $to_date . "')\n\t\t" . $additionalReq . "\n\t\t" . VectorOfCall(MathVector(7)) . "\n\t\t)"; $Qcomment = $GUI_LANG['LongDistance']; break; } if ($cacheflush) { $res = $conn->CacheFlush($q); } $local_cacheflush = ""; $res = $conn->CacheExecute($q); if ($debug) { echo "<hr>" . $q . "<br><hr>"; } if ($returnType == 1) { $results = $res->fields[0]; if (!$TTFfirst) { $TTFfirst = TRUE; } } else { $total = $res->fields; if ($total[0]) { if ($returnType == 0 && $TTFfirst) { $results = "<BR>\n"; } $results .= "{$Qcomment}: "; if ($returnType == 0) { $results .= sumTotal($total[0], 1); } else { $results .= sumTotal($total[0], 2); } if ($total[1]) { $results .= ". " . $GUI_LANG['OfCalls'] . ": "; } if ($returnType == 0) { $results .= "<b>"; } $results .= $total[1]; if ($returnType == 0) { $results .= "</b>\n"; } if (!$TTFfirst) { $TTFfirst = TRUE; } } } return $results; }
} //if($cacheflush) $conn->CacheFlush(); // Опишем в массиве те модели АТС, которые имеют АОН. $withAON = array('KX-TD1232', 'GD-320', ''); $vhodjashij = $GUI_LANG['Incoming']; $IfAON = $vhodjashij; while (list($key, $val) = each($withAON)) { if ($val == "{$model}") { // Модель АТС описанная переменной $model; взята из конфигурационного файла $IfAON = $GUI_LANG['NotRecognized']; break; } } // Вычисление дополнения к SQL запросу в зависимости от направления звонков // осуществяется посредством вызова математической функции. $vectorReq = VectorOfCall(MathVector(0)); // Формируем запрос в зависимости от типа звонков: исходящие, // входящие, или оба типа. switch ($incoming) { case "1": $additionalEcho = $GUI_LANG['IncomingAndOutgoingCalls']; break; case "2": $additionalEcho = $GUI_LANG['OutgoingCalls']; $additionalReq .= " AND (calls.way = '2')"; break; case "3": $additionalEcho = $GUI_LANG['IncomingCalls']; $additionalReq .= " AND (calls.way = '1')"; break; }