#!/usr/bin/php -q <?php set_time_limit(30); require_once 'phpagi.php'; require_once 'db_work.php'; $agi = new AGI(); $agi->answer(); $callerid = $agi->get_variable("CALLERID(name)"); $incoming_num = mysql_escape_string($callerid['data']); $incoming_num = substr(preg_replace("/[^0-9]/", "", $incoming_num), -9); $agi->exec('NoOp', 'CONTEXT:' . $incoming_num); $client = values("SELECT lastdata FROM asteriskcdrdb.`cdr` WHERE (src LIKE '%" . $incoming_num . "' OR srcplus LIKE '%" . $incoming_num . "') AND calldate > '" . date("Y-m-d H:i:s", time() - 604800) . "' AND dcontext='work' AND dstchannel!='' AND lastapp='Dial' AND disposition='ANSWERED' ORDER BY calldate DESC LIMIT 1"); if (count($client) > 0 and strlen($incoming_num) > 6) { $arr = explode(',', $client[0]["lastdata"]); $agi->exec('Dial', $arr[0] . ',10,r'); $ds = $agi->get_variable("DIALSTATUS"); if ($ds['data'] == "ANSWER") { $agi->hangup(); } $agi->exec('NoOp', 'GOTO:' . $arr[0]); }
function test() { $input = [3 => 1, 1 => 3, 2 => 2]; $expect = [1, 3, 2]; $actual = iterator_to_array(values($input), false); $this->assertEquals($expect, $actual); }
function update($table = NULL) { if (!$table) { $table = $GLOBALS['table']; } $id = format_int($_REQUEST['id']); db_update($table, fields($table), values($table), "where id={$id}"); }
function debugging_values($query, $db = 1, $enc = 0) { global $debug; if ($debug) { file_put_contents('softphone_debugging.htm', Date("H:i:s") . ": " . $query . "<br><br>", FILE_APPEND | LOCK_EX); } return values($query, $db, $enc); }
function difference() { $collections = func_get_args(); $union = union($collections); $intersection = intersection($collections); $difference = without($union, $intersection); $difference = values($difference); // Re-indexes array return $difference; }
function get_today_stats2($current_queue = '%', $operator_restr = '') { global $conf_cdr_db, $conf_realtime_db; if ($operator_restr == '') { $agent_need = '%'; } else { $agent_need = mysql_escape_string($operator_restr); } $calls_c = values("SELECT COUNT(*) AS c, SUM(callduration) AS timesum, AVG(callduration) AS timeavg FROM " . $conf_realtime_db . ".call_status WHERE timestamp BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59' AND queue LIKE '" . $current_queue . "' AND agent LIKE '" . $agent_need . "'"); $calls_num = $calls_c[0]['c']; $input_calls_time = format_time(round($calls_c[0]['timesum']), 1); if ($operator_restr != '') { $out_calls = values("SELECT COUNT(*) AS c FROM `cdr` WHERE src='" . $agent_need . "' AND calldate BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59'"); } $pick = values("SELECT COUNT(*) AS c FROM " . $conf_realtime_db . ".call_status WHERE timestamp BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59' AND queue LIKE '" . $current_queue . "' AND agent LIKE '" . $agent_need . "' AND (status='COMPLETEAGENT' OR status='COMPLETECALLER' OR status='CONNECT')"); $taken_calls = $pick[0]['c']; if ($calls_num != 0) { $taken_calls_perc = round(100 * $taken_calls / $calls_num) . '%'; } else { $taken_calls_perc = '---'; } $avgvoicecalls_c = values("SELECT AVG(callduration) AS timeavg FROM `" . $conf_realtime_db . "`.`call_status` WHERE `queue` LIKE '" . $current_queue . "' AND `callduration`>0 AND `timestamp` BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59' AND agent LIKE '" . $agent_need . "'"); $avg_call_time = round($avgvoicecalls_c[0]['timeavg']) . ' с'; if ($avg_call_time == 0) { $avg_call_time = '---'; } $scalls20_c = values("SELECT COUNT(*) AS c FROM `" . $conf_realtime_db . "`.`call_status` WHERE `queue` LIKE '" . $current_queue . "' AND holdtime<=20 AND `timestamp` BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59' AND agent LIKE '" . $agent_need . "'"); if ($calls_c[0]['c'] != 0) { $service_level = round($scalls20_c[0]['c'] / $calls_c[0]['c'] * 100) . '%'; } else { $service_level = '---'; } $maxacalls_c = values("SELECT MAX(holdtime) AS maxhold FROM `" . $conf_realtime_db . "`.`call_status` WHERE `queue` LIKE '" . $current_queue . "' AND `timestamp` BETWEEN '" . Date("Y-m-d") . " 00:00:00' AND '" . Date("Y-m-d") . " 23:59:59' AND agent LIKE '" . $agent_need . "' AND status!='TRANSFER'"); if (count($maxacalls_c) == 0 or $maxacalls_c[0]['maxhold'] == 0) { $max_await = '---'; } else { $max_await = $maxacalls_c[0]['maxhold'] . ' с'; } if ($operator_restr == '') { return ' <table border=0> <tr><td>' . __('Принято') . ':</td><td>' . $taken_calls . '</td></tr> <tr><td>' . __('Обслужено') . ':</td><td>' . $taken_calls_perc . '</td></tr> <tr><td>' . __('Время') . ':</td><td>' . $input_calls_time . '</td></tr> <tr><td>' . __('Среднее') . ':</td><td>' . $avg_call_time . '</td></tr> <tr><td>Service lvl:</td><td>' . $service_level . '</td></tr> </table>'; } else { return '<span title="' . __('Количество принятых звонков за сегодня') . '">' . __('Принял') . ':</span> ' . $taken_calls . '<br> <span title="' . __('Количество сделаных звонков за сегодня') . '">' . __('Исходящих') . ':</span>' . $out_calls[0]['c'] . '<br> <span title="' . __('Общее время разговоров за сегодня') . '">' . __('Время') . ':</span> ' . $input_calls_time . '<br> <span title="' . __('Среднее время разговора за сегодня') . '">' . __('Среднее') . ':</span> ' . $avg_call_time; } }
public function testValues() { $expectedValuesFirstViewSuccessful = array(1 => 100, 3 => 300); $expectedValuesFirstViewAll = array(1 => 100, 2 => 200, 3 => 300); $expectedValuesRepeatViewSuccessful = array(2 => 300); $expectedValuesRepeatViewAll = array(1 => 200, 2 => 300); $this->assertEquals($expectedValuesFirstViewSuccessful, values($this->pageData, 0, 'TTFB', true)); $this->assertEquals($expectedValuesFirstViewAll, values($this->pageData, 0, 'TTFB', false)); $this->assertEquals($expectedValuesRepeatViewSuccessful, values($this->pageData, 1, 'TTFB', true)); $this->assertEquals($expectedValuesRepeatViewAll, values($this->pageData, 1, 'TTFB', false)); }
function intersection($collections) { if (func_num_args() > 1) { $collections = func_get_args(); } $intersection = array_shift($collections); foreach ($collections as $collection) { foreach ($intersection as $key => $value) { if (!contains($collection, $value)) { // @todo Test whether unset() works with all Traversable unset($intersection[$key]); } } } $intersection = values($intersection); // Re-indexes due to unset() holes return $intersection; }
/** * 自动加载 * @param ClassName 类名 * @author Colin <*****@*****.**> */ public static function autoload($ClassName) { $getModule = values('get', Config('DEFAULT_MODULE_VAR')); $getModule = $getModule ? $getModule : Config('DEFAULT_MODULE'); //处理模块文件载入 $module = defined('MODULE_NAME') ? MODULE_NAME : $getModule; //处理多模块文件载入问题 $extra_module = Config('EXTRA_MODULE'); array_push($extra_module, $module); $extra_module = array_unique($extra_module); foreach ($extra_module as $key => $value) { if (preg_match("/{$value}/", $ClassName)) { $ClassName = preg_replace("/{$value}/", ltrim(APP_NAME, './') . '\\' . $value, $ClassName); } } if (preg_match("/\\\\/", $ClassName)) { //是否为命名空间加载 $ClassName = preg_replace("/\\\\/", "/", $ClassName); require_file(ROOT_PATH . $ClassName . '.class.php'); } }
function median($collection) { $size = size($collection); if ($size === 0) { $median = null; } else { $sorted = values(sort($collection)); if ($size % 2 === 0) { // For an even number of values, // the median is the average of the middle two values $start = $size / 2 - 1; $end = $start + 1; $median = average(array(at($sorted, $start), at($sorted, $end))); } else { // For an odd number of values, // the median is the middle value $index = floor($size / 2); $median = at($sorted, $index); } } return $median; }
$client_select .= " OR cdr.src LIKE '" . $add_perc . $aClient[0][$aColumns[$i]] . "' OR cdr.dst LIKE '" . $add_perc . $aClient[0][$aColumns[$i]] . "'"; } } if ($client_select != '') { $client_select = ' AND (' . substr($client_select, 4) . ')'; } if ($client_select == '') { $client_select = " AND cdr.src LIKE 'no'"; } $where_query = "WHERE 1" . $client_select; //echo "SELECT calldate, userfield, src, dst AS dest, duration, uniqueid, randdata, disposition, comment, operator FROM `asteriskcdrdb`.`cdr` cdr LEFT JOIN `hilti`.`calls_ver3` calls ON cdr.uniqueid=calls.unique_id //WHERE 1".$client_select." ORDER BY calldate DESC LIMIT ".($page2-1)*$perpage2.", ".$perpage2."<br>"; //exit; values("SET SQL_BIG_SELECTS=1"); $result_set = values("SELECT calldate, userfield, src, dst AS dest, duration, uniqueid, randdata, disposition, comment, operator FROM `asteriskcdrdb`.`cdr` cdr\nWHERE 1" . $client_select . " ORDER BY calldate DESC LIMIT " . ($page2 - 1) * $perpage2 . ", " . $perpage2); $duration_select = values("SELECT COUNT(*) AS c, SUM(duration) AS dur FROM `asteriskcdrdb`.`cdr` cdr WHERE 1" . $client_select); $dur_sec = $duration_select[0]['dur']; $cal_num = $duration_select[0]['c']; $dur_h = floor($dur_sec / 3600); $dur_m = floor(($dur_sec - $dur_h * 3600) / 60); $dur_s = $dur_sec - $dur_m * 60 - $dur_h * 3600; if ($dur_s < 10) { $dur_s = '0' . $dur_s; } if ($dur_m < 10) { $dur_m = '0' . $dur_m; } $rusult_num = count($result_set); if ($rusult_num > 0) { $pstring2 = ''; $pages2 = ceil($cal_num / $perpage2);
if ($fromstatsmonth < 10) { $fromstatsmonth = '0' . $fromstatsmonth; } if ($tostatsday < 10) { $tostatsday = '0' . $tostatsday; } if ($tostatsmonth < 10) { $tostatsmonth = '0' . $tostatsmonth; } $from = $fromstatsyear . '-' . $fromstatsmonth . '-' . $fromstatsday . ' 00:00:01'; $to = $tostatsyear . '-' . $tostatsmonth . '-' . $tostatsday . ' 23:59:59'; $direction_restr = " AND dcontext LIKE '%_out'"; $status_restr = " AND disposition = 'ANSWERED' AND dcontext NOT LIKE '%noans%' AND dstchannel!=''"; $where_query = "WHERE calldate BETWEEN '" . $from . "' AND '" . $to . "' AND LENGTH(dst)>7" . $direction_restr . $status_restr; $cdr_query = "SELECT SUBSTRING(dst FROM -9 FOR 2) AS dt, COUNT(*) AS c, SUM(billsec) AS bs FROM asteriskcdrdb.cdr\n\t" . $where_query . " GROUP BY dt ORDER BY dt"; $result_set = values($cdr_query); echo '<!-- Тестирование системы: ' . $cdr_query . ' -->'; if (count($result_set) > 0) { ?> <center> <h3>Исходящие вызовы:</h3> <TABLE border=0 cellPadding=0 cellSpacing=0 width="60%"> <TBODY> <TR bgColor=#F0F0F0> <TD width="7%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px"> <center><strong><font color="Black">Код</font></strong></center></TD> <TD width="12%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px"> <center><strong><font color="Black">Оператор</font></strong></center></TD> <TD width="10%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px"> <center><strong><font color="Black">Звонков</font></strong></center></TD> <TD width="10%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px">
function value($name) { $values = values(); return isset($values[$name]) ? $values[$name] : null; }
// GET FILTERS AND THEM RESULT list($from, $to) = prepare_dates($fromstatsday, $fromstatsmonth, $fromstatsyear, $tostatsday, $tostatsmonth, $tostatsyear); if (isset($posted)) { if (isset($callerid)) { $query_clid = " AND cdr.src LIKE '%" . $callerid . "%'"; } else { $query_clid = ""; } if (isset($clientname)) { $query_clname = " AND (cl.name LIKE '%" . $clientname . "%' OR cl.contact LIKE '%" . $clientname . "%' OR cl.client_code LIKE '%" . $clientname . "%')"; } else { $query_clname = ""; } $where_query = "WHERE calls.call_date BETWEEN '" . $from . "' AND '" . $to . "'" . $add_sipusr . $query_clid . $query_clname . " AND lastapp != 'Transferred Call' ORDER BY calls.call_date DESC"; $result_set = values("SELECT cl.id AS clid, cl.name AS clname, cl.contact AS clcontact, cl.ttk AS ttk, calls.call_date, calldate, userfield, src, dst AS dest, duration, uniqueid, randdata, disposition, comment, operator FROM " . $conf_statistic_db . ".`calls_ver3` calls LEFT JOIN " . $conf_cdr_db . ".`cdr` cdr ON cdr.uniqueid=calls.unique_id LEFT JOIN " . $conf_statistic_db . ".`clients_ver3` cl ON cl.id=calls.client_id " . $where_query . " LIMIT " . ($page - 1) * $perpage . ", " . $perpage); $duration_select = values("SELECT COUNT(*) AS c, SUM(duration) AS dur FROM " . $conf_statistic_db . ".calls_ver3 calls LEFT JOIN " . $conf_cdr_db . ".`cdr` cdr ON cdr.uniqueid=calls.unique_id LEFT JOIN " . $conf_statistic_db . ".`clients_ver3` cl ON cl.id=calls.client_id " . $where_query); $dur_sec = @$duration_select[0]['dur']; $cal_num = @$duration_select[0]['c']; $rusult_num = count($result_set); if ($rusult_num > 0) { $pstring = ''; $pages = ceil($cal_num / $perpage); for ($i = 0; $i < $pages; $i++) { if ($i + 1 == $page) { $pstring .= '<b>[' . ($i + 1) . ']</b> '; } else { $pstring .= '<a href="index.php?page=' . ($i + 1) . '">' . ($i + 1) . '</a> '; } } ?> <center>
//сюда вписать абонента, если он есть $choose_src_abonents = values("SELECT phone_number, abonent FROM " . $conf_statistic_db . ".addressbook WHERE phone_number = \"" . $find_param[0] . "\""); $choose_dest_abonents = values("SELECT phone_number, abonent FROM " . $conf_statistic_db . ".addressbook WHERE phone_number = \"" . $find_param[1] . "\""); $abonents = []; if (count($choose_src_abonents) > 0) { $abonents[0] = "" . $choose_src_abonents[0][1] . "<br>"; } else { $abonents[0] = ""; } if (count($choose_dest_abonents) > 0) { $abonents[1] = "" . $choose_dest_abonents[0][1] . "<br>"; } else { $abonents[1] = ""; } $sqlStatus = "SELECT id, status FROM " . $conf_cdr_db . ".catalog_status WHERE id = " . $result_set[$i]['status'] . ""; $choose_status = values($sqlStatus); if (count($choose_status) == 0) { $result_set[$i]['status'] = 0; } echo ' <TR bgcolor="' . $status_color . '" onMouseOver="bgColor=\'#C4FFD7\'" onMouseOut="bgColor=\'' . $status_color . '\'" onMouseClick="bgColor=\'#C4FFD7\'"> <TD vAlign=top align="" class=tableBody>' . (($page - 1) * $perpage + $i + 1) . '. </TD> <TD vAlign=top align="" class=tableBody>' . $direct_icon . '</TD> <TD vAlign=top align="center" class=tableBody>' . $result_set[$i]['calldate'] . '</TD> <TD vAlign=top align="right" class=tableBody>' . $abonents[0] . " " . $result_set[$i]['src'] . '</TD> <TD vAlign=top align="right" class=tableBody>' . $abonents[1] . " " . $result_set[$i]['dst'] . '</TD>'; if ($show_name) { echo ' <TD vAlign=top align="center" class=tableBody>' . $out_name . '</TD> <TD vAlign=top align="center" class=tableBody>' . $out_name2 . '</TD>'; } echo ' <TD vAlign=top align="center" class=tableBody>' . $result_set[$i]['disposition'] . '</TD>
#!/usr/bin/php -q <?php set_time_limit(30); $callerid = $argv[1]; require_once 'phpagi.php'; require_once 'db_work.php'; $agi = new AGI(); //$phone = preg_replace("/[^0-9]/", "", $callerid['data']); $phone = substr($callerid, -9); $agi->exec('NoOP', $phone); if (strlen($phone) == 9) { $agi->exec('NoOP', '11111' . $phone); $op = values("SELECT dstchannel FROM `cdr` WHERE src LIKE '%" . $phone . "' AND dcontext = 'phones_incom' AND dstchannel!='' ORDER BY calldate DESC LIMIT 1"); $agi->exec('NoOP', '22222-Count' . count($op)); if (count($op) < 1) { //$agi->exec('NoOP','3333'.$op[0]["dstchannel"]); //header ('Content-type: text/html; charset=utf-8'); $client = new SoapClient('http://turbosms.in.ua/api/wsdl.html'); //$agi->exec('NoOP','444'); $auth = array('login' => 'oyv1979', 'password' => 'Av1979'); //$agi->exec('NoOP','555'); $result = $client->Auth($auth); //$agi->exec('NoOP','666'); $text = 'Krainashin.com - любые шины и диски. Бесплатная линия 0(800)300-305'; $sms = array('sender' => 'KRAINASHIN', 'destination' => '+380' . $phone, 'text' => $text); $agi->exec('NoOP', '777'); //$result = $client->SendSMS ($sms); $agi->exec('NoOP', $result); } } ?>
$short_src = substr($result_set[$i]['src'], 1); } else { $short_src = $result_set[$i]['src']; } $sel_name = values("SELECT name, contact FROM hilti.clients_ver1 WHERE phone1='" . $short_src . "' OR phone2='" . $short_src . "' OR phone3='" . $short_src . "' OR fax='" . $short_src . "' OR main_number='" . $short_src . "'"); if (count($sel_name) > 0) { $out_name = $sel_name[0]["name"] . " " . $sel_name[0]["contact"]; } else { $out_name = ''; } if (strpos(' ' . $result_set[$i]['dst'], '0') == 1) { $short_dst = substr($result_set[$i]['dst'], 1); } else { $short_dst = $result_set[$i]['dst']; } $sel_name2 = values("SELECT name, contact FROM hilti.clients_ver1 WHERE phone1='" . $short_dst . "' OR phone2='" . $short_dst . "' OR phone3='" . $short_dst . "' OR fax='" . $short_dst . "' OR main_number='" . $short_dst . "'"); if (count($sel_name2) > 0) { $out_name2 = $sel_name2[0]["name"] . " " . $sel_name2[0]["contact"]; } else { $out_name2 = ''; } $status_color = '#F2F8FF'; if ($result_set[$i]['disposition'] == "NO ANSWER") { $result_set[$i]['disposition'] = "Нет ответа"; } elseif ($result_set[$i]['disposition'] == "ANSWERED") { $result_set[$i]['disposition'] = "Принят"; } elseif ($result_set[$i]['disposition'] == "BUSY") { $result_set[$i]['disposition'] = "Занято"; } elseif ($result_set[$i]['disposition'] == "FAILED") { $result_set[$i]['disposition'] = "Ошибка"; }
/** * InsertChart adds a chart for the given $metric, with the given $label, to * global $chartData, and outputs the HTML container elements for the chart. * * @param string $metric Metric to add * @param string $label Label corresponding to metric */ function InsertChart($metric, $label) { global $chartData; global $num_runs; // @var integer Number of runs global $views; global $colors; global $light_colors; global $median_metric; global $pagesData; global $testsInfo; global $testsId; global $testsLabel; global $median_value; global $median_run; global $statControl; $num_runs = max(array_map("numRunsFromTestInfo", $testsInfo)); // Write HTML for chart $div = "{$metric}Chart"; echo "<h2 id=\"{$metric}\">" . htmlspecialchars($label) . "</h2>"; if (!$testsInfo) { return; } $chartColumns = array(ChartColumn::runs($num_runs)); $compareTable = array(); $view_index = 0; // For each view (first / repeat) that we want to show foreach ($views as $cached) { $statValues = array(); $statLabels = array(); // For each run in that view foreach ($pagesData as $key => $pageData) { // Construct label from those descriptive attributes that are not // common to all variants. $labels = array(); if (count($pagesData) > 1) { $labels[] = $testsLabel[$key]; } if (count($views) > 1) { $labels[] = $cached == '1' ? 'Repeat View' : 'First View'; } // Prepare Chart object and add to $chartData for later chart construction. // If $view_index is greater than the number of colors, we will pass NULL // as a color, which will lead to GViz choosing a color. $chartColumnsAdd = ChartColumn::dataMedianColumns($pageData, $cached, $metric, $median_metric, $colors[$view_index], $light_colors[$view_index], $labels, $num_runs, $median_run, $median_value); $chartColumns = array_merge($chartColumns, $chartColumnsAdd); $view_index++; // If doing a statistical comparison, prepare raw values and labels. if ($statControl !== 'NOSTAT' && count($pagesData) >= 1) { $statValues[] = values($pageData, $cached, $metric, true); $statLabels[] = implode(" ", $labels); } } if ($statControl !== 'NOSTAT' && count($pagesData) >= 1) { // First populate compareFrom for statistical control, if it has values if (count($statValues[$statControl]) > 0) { $statDiv = "{$metric}Stat{$cached}"; $compareFrom = array(); $confData = ConfData::fromArr($statLabels[$statControl], $statValues[$statControl]); $compareFrom[$statControl] = new CompareFrom($confData, NULL, NULL); foreach ($pagesData as $key => $pageData) { // Skip the statistical control (we already handled it) if ($key == $statControl) { continue; } // Skip runs with missing values for the statistic. if (count($statValues[$key]) == 0) { continue; } // Populate compareFrom for $key $confData = ConfData::fromArr($statLabels[$key], $statValues[$key]); $pValue = \PHPStats\StatisticalTests::twoSampleTTest($statValues[$statControl], $statValues[$key]); $diff = $confData->mean - $compareFrom[$statControl]->confData->mean; // Derive 2-tailed p-value from 1-tailed p-view returned by twoSampleTTest. $pValue = $diff > 0 ? 2 * $pValue : 2 * (1 - $pValue); $compareFrom[$key] = new CompareFrom($confData, $diff, $pValue); } $compareTable[] = new CompareTable($statDiv, $compareFrom); echo "<div id=\"{$statDiv}\"></div>\n"; } } } $chart = new Chart($div, $chartColumns, $compareTable); $chartData[$metric] = $chart; echo "<div id=\"{$div}\" class=\"chart\"></div>\n"; }
#!/usr/bin/php -q <?php set_time_limit(30); require_once 'phpagi.php'; require_once 'db_work.php'; $agi = new AGI(); $agi->answer(); $callerid = $agi->get_variable("CALLERID(num)"); $incoming_num = mysql_escape_string($callerid['data']); $incoming_num = substr(preg_replace("/[^0-9]/", "", $incoming_num), -9); $agi->exec('NoOp', $incoming_num); if (strlen($incoming_num) > 6) { $client = values("SELECT id, checkid, autoresponse_file FROM `workbase`.`autoresponser` WHERE phone LIKE '%" . $incoming_num . "' AND need_autoresponse=1 ORDER BY need_autoresponse DESC, id DESC LIMIT 7"); $agi->exec('NoOp', 'Count: ' . count($client)); for ($i = 0; $i < count($client); $i++) { if (!file_exists("/var/lib/asterisk/sounds/en/" . $client[$i]["autoresponse_file"] . "_.wav")) { $agi->exec('NoOp', "/var/lib/asterisk/sounds/en/" . $client[$i]["autoresponse_file"] . "_.wav"); continue; } $agi->stream_file('receipt_', "79#"); $agi->say_digits($client[$i]["checkid"], "79#"); $agi->stream_file($client[$i]["autoresponse_file"] . "_", "79#"); values("UPDATE `workbase`.`autoresponser` SET response_date='" . Date("Y-m-d H:i:s") . "' WHERE id=" . $client[$i]['id']); } }
if ($avgholdtime_c[0]['avghold'] != NULL) { $vals[$i][12] = round($avgholdtime_c[0]['avghold']) . ' с'; } else { $vals[$i][12] = '---'; } $count_per_date_c = values("SELECT DATE_FORMAT(timestamp, '%Y-%m-%d') AS dt, COUNT(*) AS c FROM `asteriskrealtime`.`call_status` WHERE `queue` LIKE '" . $queue . "%' AND `timestamp` BETWEEN " . $period[$i] . "" . str_replace("calldate", "timestamp", $time[$i]) . " AND agent LIKE '" . $agent_need . "' GROUP BY dt"); $all_calls = 0; for ($z = 0; $z < count($count_per_date_c); $z++) { $all_calls += $count_per_date_c[$z]['c']; } if (count($count_per_date_c) != 0) { $vals[$i][13] = round($all_calls / count($count_per_date_c)); } else { $vals[$i][13] = '---'; } $max_count_per_h_c = values("SELECT DATE_FORMAT(timestamp, '%Y-%m-%d-%H') AS dt, COUNT(*) AS c FROM `asteriskrealtime`.`call_status` WHERE `queue` LIKE '" . $queue . "%' AND `timestamp` BETWEEN " . $period[$i] . "" . str_replace("calldate", "timestamp", $time[$i]) . " AND agent LIKE '" . $agent_need . "' GROUP BY dt ORDER BY c DESC LIMIT 1"); if (count($max_count_per_h_c) > 0) { $vals[$i][14] = $max_count_per_h_c[0]['c']; } else { $vals[$i][14] = '---'; } } echo ' <center><h2>' . __('Параметры работы Call-центра') . '</h2><br> <TABLE border=0 cellPadding=3 cellSpacing=0 width="900"> <TBODY> <TR bgColor=#F0F0F0> <TD width="35%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px"> <center><strong> </strong></center></TD> <TD width="13%" align=middle class="tableBody" style="PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px"> <center><strong>' . __('Сегодня') . '</strong></center></TD>
/** * 解析字符串 * @param string 要处理的值 * @author Colin <*****@*****.**> */ protected function _parstring($string) { if (empty($string)) { $string = $this->string; } //获取值 $this->string = values('request', $string); //设置name $this->name = $string; }
public function testKeyValue() { $array = ['a' => 'b', 'c' => 'd', 'e' => 'f']; $this->assertSame(['b', 'd', 'f'], toArrayWithKeys(values($array))); $this->assertSame(['a', 'c', 'e'], toArrayWithKeys(keys($array))); }
private function assertKeysValues(array $keys, array $values, callable $fn) { $this->assertSame($keys, toArray(keys($fn()))); $this->assertSame($values, toArray(values($fn()))); }
} if (!isset($_SESSION['user_id'])) { // проверяем его куки на предмет логина и пароля if (isset($_COOKIE['login']) && isset($_COOKIE['password'])) { // если такие имеются то пробуем авторизовать пользователя по этим логину и паролю $login = mysql_escape_string($_COOKIE['login']); $password = mysql_escape_string($_COOKIE['password']); $get_user = values("SELECT `id` FROM " . $conf_statistic_db . ".users WHERE `login`='{$login}' AND `password`='{$password}' LIMIT 1"); // если такой пользователь нашелся if (count($get_user) == 1) { $_SESSION['user_id'] = $get_user[0]['id']; } // то мы ставим об этом метку в сессии } } if (isset($_SESSION['user_id'])) { $get_user = values("SELECT id, name, login, level FROM " . $conf_statistic_db . ".users WHERE `id`='{$_SESSION['user_id']}' LIMIT 1"); // если нету такой записи с пользователем то убиваем ID, установленный в сессии, чтобы он был гостем if (count($get_user) != 1) { header('Location: index.php?logout'); } $iUsrId = $get_user[0]['id']; $iUsrName = $get_user[0]['name']; $iUsrLogin = $get_user[0]['login']; $iUsrLevel = $get_user[0]['level']; } else { $iUsrId = 0; $iUsrName = ''; $iUsrLogin = ''; $iUsrLevel = ''; }
/** * InsertChart adds a chart for the given $metric, with the given $label, to * global $chartData, and outputs the HTML container elements for the chart. * * @param string $metric Metric to add * @param string $label Label corresponding to metric */ function InsertChart($metric, $label) { global $chartData; global $num_runs; // @var integer Number of runs global $views; global $colors; global $light_colors; global $median_metric; global $pagesData; global $testsInfo; global $testsId; global $testsLabel; global $median_value; global $median_run; global $statControl; $num_runs = max(array_map("numRunsFromTestInfo", $testsInfo)); // Write HTML for chart $div = "{$metric}Chart"; echo "<h2 id=\"{$metric}\">" . htmlspecialchars($label) . "</h2>"; if (!$testsInfo) { return; } $chartColumns = array(ChartColumn::runs($num_runs)); $compareTable = array(); $view_index = 0; if (count($pagesData) == 1 && $num_runs >= 3) { echo '<div class="chartStats"><table class="pretty">'; echo '<tr><td></td><th>Mean</th><th>Median</th><th>p25</th><th>p75</th><th>p75-p25</th><th>StdDev</th><th>CV</th></tr>'; foreach ($views as $cached) { $pageData = reset($pagesData); echo '<tr>'; $label = $cached == '1' ? 'Repeat View' : 'First View'; echo "<th style=\"text-align: right;\">{$label}</th>"; $values = values($pageData, $cached, $metric, true); sort($values, SORT_NUMERIC); $sum = array_sum($values); $count = count($values); $mean = number_format($sum / $count, 3, '.', ''); echo "<td>{$mean}</td>"; $median = $values[intval($count / 2)]; echo "<td>{$median}</td>"; $p25 = $values[intval($count * 0.25)]; echo "<td>{$p25}</td>"; $p75 = $values[intval($count * 0.75)]; echo "<td>{$p75}</td>"; echo "<td>" . ($p75 - $p25) . "</td>"; $sqsum = 0; foreach ($values as $value) { $sqsum += pow($value - $mean, 2); } $stddev = number_format(sqrt($sqsum / $count), 3, '.', ''); echo "<td>{$stddev}</td>"; echo "<td>" . number_format($stddev / $mean * 100, 3, '.', '') . "%</td>"; echo '</tr>'; } echo '</table></div>'; } // For each view (first / repeat) that we want to show foreach ($views as $cached) { $statValues = array(); $statLabels = array(); // For each run in that view foreach ($pagesData as $key => $pageData) { // Construct label from those descriptive attributes that are not // common to all variants. $labels = array(); if (count($pagesData) > 1) { $labels[] = $testsLabel[$key]; } if (count($views) > 1) { $labels[] = $cached == '1' ? 'Repeat View' : 'First View'; } // Prepare Chart object and add to $chartData for later chart construction. // If $view_index is greater than the number of colors, we will pass NULL // as a color, which will lead to GViz choosing a color. $chartColumnsAdd = ChartColumn::dataMedianColumns($pageData, $cached, $metric, $median_metric, $colors[$view_index], $light_colors[$view_index], $labels, $num_runs, $median_run, $median_value); $chartColumns = array_merge($chartColumns, $chartColumnsAdd); $view_index++; // If doing a statistical comparison, prepare raw values and labels. if ($statControl !== 'NOSTAT' && count($pagesData) >= 1) { $statValues[] = values($pageData, $cached, $metric, true); $statLabels[] = implode(" ", $labels); } } if (is_file('lib/PHPStats/PHPStats.phar') && $statControl !== 'NOSTAT' && count($pagesData) >= 1) { require_once 'lib/PHPStats/PHPStats.phar'; require_once 'stat.inc'; // First populate compareFrom for statistical control, if it has values if (count($statValues[$statControl]) > 0) { $statDiv = "{$metric}Stat{$cached}"; $compareFrom = array(); $confData = ConfData::fromArr($statLabels[$statControl], $statValues[$statControl]); $compareFrom[$statControl] = new CompareFrom($confData, NULL, NULL); foreach ($pagesData as $key => $pageData) { // Skip the statistical control (we already handled it) if ($key == $statControl) { continue; } // Skip runs with missing values for the statistic. if (count($statValues[$key]) == 0) { continue; } // Populate compareFrom for $key $confData = ConfData::fromArr($statLabels[$key], $statValues[$key]); $pValue = \PHPStats\StatisticalTests::twoSampleTTest($statValues[$statControl], $statValues[$key]); $diff = $confData->mean - $compareFrom[$statControl]->confData->mean; // Derive 2-tailed p-value from 1-tailed p-view returned by twoSampleTTest. $pValue = $diff > 0 ? 2 * $pValue : 2 * (1 - $pValue); $compareFrom[$key] = new CompareFrom($confData, $diff, $pValue); } $compareTable[] = new CompareTable($statDiv, $compareFrom); echo "<div id=\"{$statDiv}\"></div>\n"; } } } $chart = new Chart($div, $chartColumns, $compareTable); $chartData[$metric] = $chart; echo "<div id=\"{$div}\" class=\"chart\"></div>\n"; }
$sel_processes[0]["instances"] = 0; } if ($sel_processes[0]["instances"] > 0) { die("”же запущена копи¤"); } values("UPDATE statistic.processes SET instances=instances+1, last_start=NOW() WHERE process='operators'"); for ($n = 0; $n <= 1; $n++) { $operator_status = values("SELECT Name, Status, Paused FROM asteriskcdrdb.QueueMember GROUP BY Name ORDER BY Name"); for ($i = 0; $i < count($operator_status); $i++) { if ((int) $operator_status[$i]['Name'] == 0) { continue; } if ((int) $operator_status[$i]['Status'] != 1 and (int) $operator_status[$i]['Status'] != 5) { continue; } $sel_now = values("SELECT * FROM statistic.operators_events WHERE operator='" . $operator_status[$i]['Name'] . "' ORDER BY eventtime DESC LIMIT 1"); if ($operator_status[$i]['Paused'] > 0 and (int) $operator_status[$i]['Status'] == 1) { $operator_status[$i]['Status'] = 9; } if (count($sel_now) == 0) { values("INSERT INTO statistic.operators_events (`id` ,`eventtime` ,`eventtype` ,`operator` ,`length` ,`addata`) VALUES\n ('', '" . Date("Y-m-d H:i:s") . "', '" . $operator_status[$i]['Status'] . "', '" . $operator_status[$i]['Name'] . "', '0', '" . $operator_status[$i]['Paused'] . "')"); } elseif ($operator_status[$i]['Status'] != $sel_now[0]['eventtype']) { values("UPDATE statistic.operators_events SET length=UNIX_TIMESTAMP('" . Date("Y-m-d H:i:s") . "')-UNIX_TIMESTAMP(eventtime) WHERE id=" . $sel_now[0]['id']); values("DELETE FROM statistic.operators_events WHERE length=0 AND operator='" . $operator_status[$i]['Name'] . "'"); values("INSERT INTO statistic.operators_events (`id` ,`eventtime` ,`eventtype` ,`operator` ,`length` ,`addata`) VALUES\n ('', '" . Date("Y-m-d H:i:s") . "', '" . $operator_status[$i]['Status'] . "', '" . $operator_status[$i]['Name'] . "', '0', '" . $operator_status[$i]['Paused'] . "')"); } } sleep(25); } values("UPDATE statistic.processes SET instances=instances-1 WHERE process='operators'");
引用传递 基本概念:实参的内存地址传递到形参中,在函数内部的所有操作都会影响到实参的值,即返回后,实参的值会发生变化 使用注意:传值时只需要在函数声明时的参数前加“&”即可 代码示例: <?php function values($a) { $a++; echo "在函数内:\$a=" . $a; //输出形参的值 $a=2 } $a = 1; values($a); //传值:将$a传递给形参$a echo "<p>在函数外 \$a=" . $a . "</p>"; //实参的值有变化,输出 $a=2 ?> 一:变量的引用 代码示例: <?php $a = 100; $b =& $a; //注意:符号使用 echo $a; //这里输出100 echo $b; //这里输出100 ,说明$a,和$b的值都是一百。 $b = 200; echo $a; //这里输出200 echo $b;
require_once "libs/php-excel.class.php"; escape_r(); foreach ($_SESSION as $key => $value) { ${$key} = $_SESSION[$key]; } include 'libs/auth.php'; list($cdr_restr, $cs_restr) = get_filters("periods,dates,status,directions,serchbynumber", "", 1); if ($usr_restrictions = get_params_array(0, "cdr_restrictions")) { $usr_restr = ' AND (' . $usr_restrictions[0] . ')'; } else { $usr_restr = ''; } $where_query = "WHERE" . $cdr_restr . $usr_restr; $cdr_query = "SELECT channel, calldate, userfield, src, dst, duration, billsec, lastapp, lastdata, uniqueid, randdata, disposition, dstchannel, dcontext, status FROM " . $conf_cdr_db . ".cdr\n" . $where_query; $result_set = values($cdr_query); $duration_select = values("SELECT COUNT(*) AS c, SUM(duration) AS dur, SUM(billsec) AS bill, AVG(duration) AS avgdur, AVG(billsec) AS avgbill FROM " . $conf_cdr_db . ".cdr " . $where_query); echo $cdr_query; if (count($duration_select) > 0) { $dur_sec = $duration_select[0]['dur']; $avg_dur = $duration_select[0]['avgdur']; $bill_sec = $duration_select[0]['bill']; $avg_bill = $duration_select[0]['avgbill']; $cal_num = $duration_select[0]['c']; } else { $dur_sec = 0; $avg_dur = 0; $bill_sec = 0; $avg_bill = 0; $cal_num = 0; } $rusult_num = count($result_set);
function is_session_alive($session_id, $no_ka = 0) { global $version, $client_db; $session = values("SELECT alive FROM `" . $client_db . "`.`sessions` WHERE alive=1 AND session_id = '" . mysql_escape_string($session_id) . "' AND sess_expire > NOW()"); if (count($session) > 0) { if ($no_ka == 0) { keep_alive($session_id); } return 1; } else { session_kill($session_id); return 0; } }
/** * 获取当前url * @param is_return_current_url 是否返回当前地址 * @param is_return_array 是否返回数组 * @return array * @author Colin <*****@*****.**> */ public static function getCurrentUrl($is_return_current_url = false, $is_return_array = false) { $current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parse_url = parse_url($current_url); if (Config('URL_MODEL') == 1) { $array = array_values(values('get.', null, 'trim')); foreach ($array as $key => $value) { $parse_path[$key] = $value; } } else { $parse_path = array_filter(explode('/', $parse_url['path'])); } $path_array = explode('/', ROOT_PATH); $patten = '/\\./'; foreach ($parse_path as $key => $value) { //处理根目录 if (in_array($value, $path_array)) { unset($parse_path[$key]); } $parse_path = array_merge($parse_path); } //匹配是否是index.php if (!empty($parse_path)) { if (preg_match($patten, $parse_path[0], $match)) { //确认文件是否存在 if (!file_exists(ROOT_PATH . $parse_path[0])) { E('无效的入口文件' . $parse_path[0]); } unset($parse_path[0]); } $parse_path = array_merge($parse_path); } if (empty($parse_path)) { $parse_path = array(Config('DEFAULT_MODULE'), Config('DEFAULT_CONTROLLER'), Config('DEFAULT_METHOD')); } self::$param = $parse_path; if ($is_return_current_url) { return $current_url; } if ($is_return_array) { return $parse_url; } return $parse_path; }