function GetCntObjMyAgents() { $agents_ids_arr = User::GetMyAgentsIds($_SESSION['user_id']); $agents_ids_str = implode(",", $agents_ids_arr); if ($agents_ids_str) { $link = dbh::connect(); foreach (array('flats', 'houses') as $mod) { $sql = 'SELECT owner,count(owner) as cnt FROM ' . $mod . ' where owner in (' . $agents_ids_str . ') and status>0 group by owner'; //print $sql; $res = mysql_query($sql); if (mysql_num_rows($res) > 0) { for ($i = 0; $i < mysql_num_rows($res); $i++) { $statistic[mysql_result($res, $i, owner)][$mod] = mysql_result($res, $i, cnt); } } foreach (array('day' => 1, 'week' => 7, 'month' => 31) as $k => $period) { $sql = 'SELECT owner,count(owner) as cnt FROM ' . $mod . ' where owner in (' . $agents_ids_str . ') and status>0 and DATE(created)>=DATE_SUB(NOW(), INTERVAL ' . $period . ' DAY) group by owner'; $res = mysql_query($sql); if (mysql_num_rows($res) > 0) { for ($i = 0; $i < mysql_num_rows($res); $i++) { $statistic[mysql_result($res, $i, owner)][$mod . '_' . $k] = mysql_result($res, $i, cnt); } } } } dbh::disconnect($link); $users = User::GetUsersAr(); $users_online_ar = User::GetUserOnlineAr(); foreach ($agents_ids_arr as $k) { $statistic[$k]['name'] = $users[$k]; $statistic[$k]['id'] = $k; $statistic[$k]['online'] = 0; if (in_array($k, $users_online_ar)) { $statistic[$k]['online'] = 1; } } # if($_SESSION['user_id']==84){ # print "<pre>"; # print_r($statistic); # } return $statistic; } else { return 0; } }