retrieve($_REQUEST['user']); $userName = $locale->getLocaleFormattedName($user->first_name, $user->last_name); } // NEXT FREE if(isset($_REQUEST['next_free']) && $_REQUEST['next_free'] == true) { $next = new Email(); $rG = $next->db->query('SELECT count(id) AS c FROM users WHERE deleted = 0 AND users.is_group = 1'); $aG = $next->db->fetchByAssoc($rG); if($rG['c'] > 0) { $rG = $next->db->query('SELECT id FROM users WHERE deleted = 0 AND users.is_group = 1'); $aG = $next->db->fetchByAssoc($rG); while($aG = $next->db->fetchByAssoc($rG)) { $ids[] = $aG['id']; } $in = ' IN ('; foreach($ids as $k => $id) { $in .= '"'.$id.'", '; } $in = substr($in, 0, (strlen($in) - 2)); $in .= ') '; $team = ''; $qE = 'SELECT count(id) AS c FROM emails WHERE deleted = 0 AND assigned_user_id'.$in.$team.'LIMIT 1'; $rE = $next->db->query($qE); $aE = $next->db->fetchByAssoc($rE); if($aE['c'] > 0) { $qE = 'SELECT id FROM emails WHERE deleted = 0 AND assigned_user_id'.$in.$team.'LIMIT 1'; $rE = $next->db->query($qE); $aE = $next->db->fetchByAssoc($rE); $next->retrieve($aE['id']); $next->assigned_user_id = $current_user->id; $next->save(); header('Location: index.php?module=Emails&action=DetailView&record='.$next->id); } else { // no free items header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true'); } } else { // no groups header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true'); } } ?>