Esempio n. 1
0
 function saveRoutingAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $worker = CerberusApplication::getActiveWorker();
     if (!$worker || !$worker->is_superuser) {
         echo $translate->_('common.access_denied');
         return;
     }
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'mail')));
         return;
     }
     @($positions = DevblocksPlatform::importGPC($_POST['positions'], 'array'));
     @($route_ids = DevblocksPlatform::importGPC($_POST['route_ids'], 'array'));
     @($route_team_id = DevblocksPlatform::importGPC($_POST['route_team_id'], 'array'));
     @($route_pattern = DevblocksPlatform::importGPC($_POST['route_pattern'], 'array'));
     @($default_team_id = DevblocksPlatform::importGPC($_POST['default_team_id'], 'integer', 0));
     @($add_pattern = DevblocksPlatform::importGPC($_POST['add_pattern'], 'array'));
     @($add_team_id = DevblocksPlatform::importGPC($_POST['add_team_id'], 'array'));
     @($route_remove = DevblocksPlatform::importGPC($_POST['route_remove'], 'array'));
     // Rule reordering
     if (is_array($route_ids) && is_array($positions)) {
         foreach ($route_ids as $idx => $route_id) {
             $pos = $positions[$idx];
             $pattern = $route_pattern[$idx];
             $team_id = $route_team_id[$idx];
             if (empty($pattern)) {
                 $route_remove[] = $route_id;
                 continue;
             }
             $fields = array(DAO_Mail::ROUTING_POS => $pos, DAO_Mail::ROUTING_PATTERN => $pattern, DAO_Mail::ROUTING_TEAM_ID => $team_id);
             DAO_Mail::updateMailboxRouting($route_id, $fields);
         }
     }
     // Add rules
     if (is_array($add_pattern)) {
         foreach ($add_pattern as $k => $v) {
             if (empty($v)) {
                 continue;
             }
             $team_id = $add_team_id[$k];
             $fields = array(DAO_Mail::ROUTING_PATTERN => $v, DAO_Mail::ROUTING_TEAM_ID => $team_id);
             $route_id = DAO_Mail::createMailboxRouting($fields);
         }
     }
     // Removals
     if (is_array($route_remove)) {
         foreach ($route_remove as $remove_id) {
             DAO_Mail::deleteMailboxRouting($remove_id);
         }
     }
     // Default team
     DAO_Group::setDefaultGroup($default_team_id);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'parser')));
 }