private function save()
 {
     $now = new Date();
     $pm_recipients_list = array();
     $send_pm = true;
     $versions = array_reverse($this->config->get_versions_fix(), true);
     $status = $this->form->get_value('status')->get_raw_value();
     if (count($versions)) {
         if (!$this->form->field_is_disabled('fixed_in')) {
             $fixed_in = $this->form->get_value('fixed_in')->get_raw_value() ? $this->form->get_value('fixed_in')->get_raw_value() : 0;
             if ($fixed_in != $this->bug->get_fixed_in()) {
                 //Bug history update
                 BugtrackerService::add_history(array('bug_id' => $this->bug->get_id(), 'updater_id' => $this->current_user->get_id(), 'update_date' => $now->get_timestamp(), 'updated_field' => 'fixed_in', 'old_value' => $this->bug->get_fixed_in(), 'new_value' => $fixed_in));
                 $this->bug->set_fixed_in($fixed_in);
             }
         } else {
             if (in_array($status, array(Bug::NEW_BUG, Bug::REJECTED))) {
                 $this->bug->set_fixed_in(0);
             }
         }
     }
     if (!$this->form->field_is_disabled('assigned_to')) {
         $assigned_to = $this->form->get_value('assigned_to');
         $assigned_to_id = UserService::user_exists("WHERE display_name = :display_name", array('display_name' => $assigned_to));
         if ($this->bug->get_assigned_to_id()) {
             $old_user_assigned_id = UserService::user_exists("WHERE user_id = :user_id", array('user_id' => $this->bug->get_assigned_to_id()));
             $old_user_assigned = !empty($old_user_assigned_id) ? UserService::get_user($old_user_assigned_id) : 0;
         } else {
             $old_user_assigned = 0;
         }
         $new_user_assigned = !empty($assigned_to) && !empty($assigned_to_id) ? UserService::get_user($assigned_to_id) : 0;
         $new_assigned_to_id = !empty($new_user_assigned) ? $new_user_assigned->get_id() : 0;
         if ($new_assigned_to_id != $this->bug->get_assigned_to_id()) {
             //Bug history update
             BugtrackerService::add_history(array('bug_id' => $this->bug->get_id(), 'updater_id' => $this->current_user->get_id(), 'update_date' => $now->get_timestamp(), 'updated_field' => 'assigned_to_id', 'old_value' => $old_user_assigned ? $old_user_assigned->get_display_name() : $this->lang['notice.no_one'], 'new_value' => $new_user_assigned ? $new_user_assigned->get_display_name() : $this->lang['notice.no_one']));
             //Bug update
             $this->bug->set_assigned_to_id($new_assigned_to_id);
             //The PM will only be sent to the assigned user
             if ($new_assigned_to_id != $this->current_user->get_id()) {
                 $pm_recipients_list[] = $new_assigned_to_id;
             } else {
                 $send_pm = false;
             }
         }
     }
     if ($status != $this->bug->get_status()) {
         //Bug history update
         BugtrackerService::add_history(array('bug_id' => $this->bug->get_id(), 'updater_id' => $this->current_user->get_id(), 'update_date' => $now->get_timestamp(), 'updated_field' => 'status', 'old_value' => $this->bug->get_status(), 'new_value' => $status));
         //Bug update
         $this->bug->set_status($status);
         if ($this->bug->is_fixed() || $this->bug->is_rejected()) {
             $this->bug->set_fix_date($now);
         } else {
             $this->bug->set_fix_date(0);
         }
     }
     BugtrackerService::update($this->bug);
     Feed::clear_cache('bugtracker');
     switch ($status) {
         case Bug::IN_PROGRESS:
             $is_pm_enabled = $this->config->are_pm_in_progress_enabled();
             break;
         case Bug::PENDING:
             $is_pm_enabled = $this->config->are_pm_pending_enabled();
             break;
         case Bug::ASSIGNED:
             $is_pm_enabled = $this->config->are_pm_assign_enabled();
             break;
         case Bug::FIXED:
             $is_pm_enabled = $this->config->are_pm_fix_enabled();
             break;
         case Bug::REOPEN:
             $is_pm_enabled = $this->config->are_pm_reopen_enabled();
             break;
         case Bug::REJECTED:
             $is_pm_enabled = $this->config->are_pm_reject_enabled();
             break;
         default:
             $is_pm_enabled = false;
             break;
     }
     //Add comment if needed
     $comment = $this->form->get_value('comments_message', '');
     if (!empty($comment)) {
         $comments_topic = new BugtrackerCommentsTopic();
         $comments_topic->set_id_in_module($this->bug->get_id());
         $comments_topic->set_url(BugtrackerUrlBuilder::detail($this->bug->get_id() . '-' . $this->bug->get_rewrited_title()));
         CommentsManager::add_comment($comments_topic->get_module_id(), $comments_topic->get_id_in_module(), $comments_topic->get_topic_identifier(), $comments_topic->get_path(), $comment);
         //New line in the bug history
         BugtrackerService::add_history(array('bug_id' => $this->bug->get_id(), 'updater_id' => $this->current_user->get_id(), 'update_date' => $now->get_timestamp(), 'change_comment' => $this->lang['notice.new_comment']));
     }
     //Send PM with comment to updaters if the option is enabled
     if (!$this->bug->is_new() && $this->config->are_pm_enabled() && $is_pm_enabled && $send_pm) {
         BugtrackerPMService::send_PM_to_updaters($status, $this->bug->get_id(), $comment, $pm_recipients_list);
     }
     if (in_array($status, array(Bug::NEW_BUG, Bug::REOPEN, Bug::REJECTED, Bug::FIXED)) && $this->config->are_admin_alerts_enabled() && in_array($this->bug->get_severity(), $this->config->get_admin_alerts_levels())) {
         $alerts = AdministratorAlertService::find_by_criteria($this->bug->get_id(), 'bugtracker');
         if (!empty($alerts)) {
             $alert = $alerts[0];
             if ($this->bug->is_new() || $this->bug->is_reopen()) {
                 $alert->set_status(AdministratorAlert::ADMIN_ALERT_STATUS_UNREAD);
                 AdministratorAlertService::save_alert($alert);
             } else {
                 if ($this->config->is_admin_alerts_fix_action_fix()) {
                     $alert->set_status(AdministratorAlert::ADMIN_ALERT_STATUS_PROCESSED);
                     AdministratorAlertService::save_alert($alert);
                 } else {
                     AdministratorAlertService::delete_alert($alert);
                 }
             }
         }
     }
     BugtrackerStatsCache::invalidate();
 }
 private function save()
 {
     $request = AppContext::get_request();
     $types = $this->config->get_types();
     $categories = $this->config->get_categories();
     $severities = $this->config->get_severities();
     $priorities = $this->config->get_priorities();
     $versions = $this->config->get_versions();
     foreach ($types as $key => $type) {
         $new_type_name = $request->get_value('type' . $key, '');
         $types[$key] = !empty($new_type_name) && $new_type_name != $type ? $new_type_name : $type;
     }
     $nb_types = count($types);
     for ($i = 1; $i <= $this->max_input; $i++) {
         $type = 'type_' . $i;
         if ($request->has_postparameter($type) && $request->get_poststring($type)) {
             if (empty($nb_types)) {
                 $types[1] = addslashes($request->get_poststring($type));
             } else {
                 $types[] = addslashes($request->get_poststring($type));
             }
             $nb_types++;
         }
     }
     foreach ($categories as $key => $category) {
         $new_category_name = $request->get_value('category' . $key, '');
         $categories[$key] = !empty($new_category_name) && $new_category_name != $category ? $new_category_name : $category;
     }
     $nb_categories = count($categories);
     for ($i = 1; $i <= $this->max_input; $i++) {
         $category = 'category_' . $i;
         if ($request->has_postparameter($category) && $request->get_poststring($category)) {
             if (empty($nb_categories)) {
                 $categories[1] = addslashes($request->get_poststring($category));
             } else {
                 $categories[] = addslashes($request->get_poststring($category));
             }
             $nb_categories++;
         }
     }
     foreach ($severities as $key => $severity) {
         $new_severity_name = $request->get_value('severity' . $key, '');
         $new_severity_color = $request->get_value('color' . $key, '');
         $severities[$key]['name'] = !empty($new_severity_name) && $new_severity_name != $severity['name'] ? $new_severity_name : $severity['name'];
         $severities[$key]['color'] = $new_severity_color != $severity['color'] ? $new_severity_color : $severity['color'];
     }
     foreach ($priorities as $key => $priority) {
         $new_priority_name = $request->get_value('priority' . $key, '');
         $priorities[$key] = !empty($new_priority_name) && $new_priority_name != $priority ? $new_priority_name : $priority;
     }
     foreach ($versions as $key => $version) {
         $new_version_name = $request->get_value('version' . $key, '');
         $new_version_release_date = $request->get_value('release_date' . $key, '');
         $new_version_detected_in = (bool) $request->get_value('detected_in' . $key, '');
         $versions[$key]['name'] = !empty($new_version_name) && $new_version_name != $version['name'] ? $new_version_name : $version['name'];
         $release_date = $new_version_release_date ? new Date($new_version_release_date) : '';
         $versions[$key]['release_date'] = $release_date ? $release_date->get_timestamp() : '';
         $versions[$key]['detected_in'] = $new_version_detected_in != $version['detected_in'] ? $new_version_detected_in : $version['detected_in'];
     }
     $nb_versions = count($versions);
     for ($i = 1; $i <= $this->max_input; $i++) {
         $version = 'version_' . $i;
         if ($request->has_postparameter($version) && $request->get_poststring($version)) {
             $version_release_date = $request->get_value('release_date_' . $i, '');
             $release_date = $version_release_date ? new Date($version_release_date) : '';
             $release_date = $release_date ? $release_date->get_timestamp() : '';
             if (empty($nb_versions)) {
                 $versions[1] = array('name' => addslashes($request->get_poststring($version)), 'release_date' => $release_date, 'detected_in' => (bool) $request->get_value('detected_in' . $i, ''));
             } else {
                 $versions[] = array('name' => addslashes($request->get_poststring($version)), 'release_date' => $release_date, 'detected_in' => (bool) $request->get_value('detected_in' . $i, ''));
             }
             $nb_versions++;
         }
     }
     $this->config->set_items_per_page($this->form->get_value('items_per_page'));
     $this->config->set_rejected_bug_color($this->form->get_value('rejected_bug_color'));
     $this->config->set_fixed_bug_color($this->form->get_value('fixed_bug_color'));
     if ($this->form->get_value('roadmap_enabled')) {
         $this->config->enable_roadmap();
     } else {
         $this->config->disable_roadmap();
     }
     if ($this->form->get_value('progress_bar_displayed')) {
         $this->config->display_progress_bar();
         $status_list = array();
         foreach ($this->config->get_status_list() as $key => $value) {
             $status_list[$key] = $this->form->get_value($key);
         }
         $this->config->set_status_list($status_list);
     } else {
         $this->config->hide_progress_bar();
     }
     if ($this->form->get_value('admin_alerts_enabled')) {
         $this->config->enable_admin_alerts();
         $this->config->set_admin_alerts_fix_action($this->form->get_value('admin_alerts_fix_action')->get_raw_value());
         $admin_alerts_levels = array();
         foreach ($this->form->get_value('admin_alerts_levels') as $level => $value) {
             $admin_alerts_levels[] = (string) $value->get_id();
         }
         $this->config->set_admin_alerts_levels($admin_alerts_levels);
     } else {
         $this->config->disable_admin_alerts();
     }
     if ($this->form->get_value('stats_enabled')) {
         $this->config->enable_stats();
         if ($this->form->get_value('stats_top_posters_enabled')) {
             $this->config->enable_stats_top_posters();
             $this->config->set_stats_top_posters_number($this->form->get_value('stats_top_posters_number'));
         } else {
             $this->config->disable_stats_top_posters();
         }
     } else {
         $this->config->disable_stats();
     }
     if ($this->form->get_value('pm_enabled')) {
         $this->config->enable_pm();
         if ($this->form->get_value('pm_comment_enabled')) {
             $this->config->enable_pm_comment();
         } else {
             $this->config->disable_pm_comment();
         }
         if ($this->form->get_value('pm_in_progress_enabled')) {
             $this->config->enable_pm_in_progress();
         } else {
             $this->config->disable_pm_in_progress();
         }
         if ($this->form->get_value('pm_fix_enabled')) {
             $this->config->enable_pm_fix();
         } else {
             $this->config->disable_pm_fix();
         }
         if ($this->form->get_value('pm_pending_enabled')) {
             $this->config->enable_pm_pending();
         } else {
             $this->config->disable_pm_pending();
         }
         if ($this->form->get_value('pm_assign_enabled')) {
             $this->config->enable_pm_assign();
         } else {
             $this->config->disable_pm_assign();
         }
         if ($this->form->get_value('pm_edit_enabled')) {
             $this->config->enable_pm_edit();
         } else {
             $this->config->disable_pm_edit();
         }
         if ($this->form->get_value('pm_reject_enabled')) {
             $this->config->enable_pm_reject();
         } else {
             $this->config->disable_pm_reject();
         }
         if ($this->form->get_value('pm_reopen_enabled')) {
             $this->config->enable_pm_reopen();
         } else {
             $this->config->disable_pm_reopen();
         }
         if ($this->form->get_value('pm_delete_enabled')) {
             $this->config->enable_pm_delete();
         } else {
             $this->config->disable_pm_delete();
         }
     } else {
         $this->config->disable_pm();
     }
     $this->config->set_contents_value($this->form->get_value('contents_value'));
     if ($this->form->get_value('type_mandatory')) {
         $this->config->type_mandatory();
     } else {
         $this->config->type_not_mandatory();
     }
     if ($this->form->get_value('display_type_column')) {
         $this->config->display_type_column();
     } else {
         $this->config->hide_type_column();
     }
     $this->config->set_types($types);
     $this->config->set_default_type($request->get_value('default_type', 0));
     if ($this->form->get_value('category_mandatory')) {
         $this->config->category_mandatory();
     } else {
         $this->config->category_not_mandatory();
     }
     if ($this->form->get_value('display_category_column')) {
         $this->config->display_category_column();
     } else {
         $this->config->hide_category_column();
     }
     $this->config->set_categories($categories);
     $this->config->set_default_category($request->get_value('default_category', 0));
     if ($this->form->get_value('severity_mandatory')) {
         $this->config->severity_mandatory();
     } else {
         $this->config->severity_not_mandatory();
     }
     $this->config->set_severities($severities);
     $this->config->set_default_severity($request->get_value('default_severity', 0));
     if ($this->form->get_value('priority_mandatory')) {
         $this->config->priority_mandatory();
     } else {
         $this->config->priority_not_mandatory();
     }
     if ($this->form->get_value('display_priority_column')) {
         $this->config->display_priority_column();
     } else {
         $this->config->hide_priority_column();
     }
     $this->config->set_priorities($priorities);
     $this->config->set_default_priority($request->get_value('default_priority', 0));
     if ($this->form->get_value('detected_in_version_mandatory')) {
         $this->config->detected_in_version_mandatory();
     } else {
         $this->config->detected_in_version_not_mandatory();
     }
     if ($this->form->get_value('display_detected_in_column')) {
         $this->config->display_detected_in_column();
     } else {
         $this->config->hide_detected_in_column();
     }
     $this->config->set_versions($versions);
     $this->config->set_default_version($request->get_value('default_version', 0));
     BugtrackerConfig::save();
     BugtrackerStatsCache::invalidate();
 }
    private function save()
    {
        $bug = $this->get_bug();
        if ($bug->get_id() === null) {
            $title = $this->form->get_value('title');
            $bug->set_title($title);
            $bug->set_rewrited_title(Url::encode_rewrite($title));
            $bug->set_contents($this->form->get_value('contents'));
            $bug->set_type($this->form->get_value('type') ? $this->form->get_value('type')->get_raw_value() : $this->config->get_default_type());
            $bug->set_category($this->form->get_value('category') ? $this->form->get_value('category')->get_raw_value() : $this->config->get_default_category());
            $bug->set_severity($this->form->get_value('severity') ? $this->form->get_value('severity')->get_raw_value() : $this->config->get_default_severity());
            $bug->set_priority($this->form->get_value('priority') ? $this->form->get_value('priority')->get_raw_value() : $this->config->get_default_priority());
            $bug->set_detected_in($this->form->get_value('detected_in') ? $this->form->get_value('detected_in')->get_raw_value() : $this->config->get_default_version());
            $bug->set_reproductible($this->form->get_value('reproductible') ? true : 0);
            if ($bug->is_reproductible()) {
                $bug->set_reproduction_method($this->form->get_value('reproduction_method'));
            }
            //Bug creation
            $bug->set_id(BugtrackerService::add($bug));
            if ($this->config->are_admin_alerts_enabled() && in_array($bug->get_severity(), $this->config->get_admin_alerts_levels())) {
                $alert = new AdministratorAlert();
                $alert->set_entitled('[' . $this->lang['module_title'] . '] ' . $bug->get_title());
                $alert->set_fixing_url(BugtrackerUrlBuilder::detail($bug->get_id() . '-' . $bug->get_rewrited_title())->relative());
                switch ($bug->get_priority()) {
                    case 1:
                        switch ($bug->get_severity()) {
                            case 1:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_VERY_LOW_PRIORITY;
                                break;
                            case 2:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                        }
                        break;
                    case 2:
                        switch ($bug->get_severity()) {
                            case 1:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                        }
                        break;
                    case 3:
                        switch ($bug->get_severity()) {
                            case 1:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
                                break;
                            case 2:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                            case 3:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                        }
                        break;
                    case 4:
                        switch ($bug->get_severity()) {
                            case 2:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                            case 3:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
                                break;
                        }
                        break;
                    case 5:
                        switch ($bug->get_severity()) {
                            case 2:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY;
                                break;
                            case 3:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_VERY_HIGH_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                        }
                        break;
                    default:
                        switch ($bug->get_severity()) {
                            case 1:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY;
                                break;
                            case 2:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                            case 3:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY;
                                break;
                            default:
                                $alert_priority = AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY;
                                break;
                        }
                        break;
                }
                $alert->set_priority($alert_priority);
                $alert->set_id_in_module($bug->get_id());
                $alert->set_type('bugtracker');
                AdministratorAlertService::save_alert($alert);
            }
        } else {
            $old_values = clone $bug;
            $now = new Date();
            $types = $this->config->get_types();
            $categories = $this->config->get_categories();
            $severities = $this->config->get_severities();
            $priorities = $this->config->get_priorities();
            $versions = $this->config->get_versions();
            $display_versions = count($versions) > 1;
            $status_list = $this->config->get_status_list();
            $common_lang = LangLoader::get('common');
            $title = $this->form->get_value('title', $old_values->get_title());
            $bug->set_title($title);
            $bug->set_rewrited_title(Url::encode_rewrite($title));
            $bug->set_contents($this->form->get_value('contents', $old_values->get_contents()));
            $bug->set_type($this->form->get_value('type') ? $this->form->get_value('type')->get_raw_value() : $old_values->get_type());
            $bug->set_category($this->form->get_value('category') ? $this->form->get_value('category')->get_raw_value() : $old_values->get_category());
            $bug->set_severity($this->form->get_value('severity') ? $this->form->get_value('severity')->get_raw_value() : $old_values->get_severity());
            $bug->set_priority($this->form->get_value('priority') ? $this->form->get_value('priority')->get_raw_value() : $old_values->get_priority());
            $bug->set_detected_in($this->form->get_value('detected_in') ? $this->form->get_value('detected_in')->get_raw_value() : $old_values->get_detected_in());
            $bug->set_reproductible($this->form->get_value('reproductible') ? true : 0);
            if ($bug->is_reproductible()) {
                $bug->set_reproduction_method($this->form->get_value('reproduction_method', $old_values->get_reproduction_method()));
            }
            $pm_comment = '';
            $modification = false;
            $fields = array('title', 'contents', 'type', 'category', 'severity', 'priority', 'detected_in', 'reproductible', 'reproduction_method');
            $n_values = $bug->get_properties();
            $o_values = $old_values->get_properties();
            foreach ($fields as $field) {
                if ($o_values[$field] != $n_values[$field]) {
                    $modification = true;
                    $comment = '';
                    switch ($field) {
                        case 'title':
                            $new_value = stripslashes($n_values[$field]);
                            $o_values[$field] = addslashes($o_values[$field]);
                            $comment = '';
                            break;
                        case 'contents':
                            $o_values[$field] = '';
                            $n_values[$field] = '';
                            $comment = $this->lang['notice.contents_update'];
                            break;
                        case 'reproduction_method':
                            $o_values[$field] = '';
                            $n_values[$field] = '';
                            $comment = $this->lang['notice.reproduction_method_update'];
                            break;
                        case 'type':
                            $new_value = !empty($n_values[$field]) ? stripslashes($types[$n_values[$field]]) : $this->lang['notice.none'];
                            break;
                        case 'category':
                            $new_value = !empty($n_values[$field]) ? stripslashes($categories[$n_values[$field]]) : $this->lang['notice.none_e'];
                            break;
                        case 'priority':
                            $new_value = !empty($n_values[$field]) ? stripslashes($priorities[$n_values[$field]]) : $this->lang['notice.none_e'];
                            break;
                        case 'severity':
                            $new_value = !empty($n_values[$field]) ? stripslashes($severities[$n_values[$field]]['name']) : $this->lang['notice.none'];
                            break;
                        case 'detected_in':
                            $new_value = !empty($n_values[$field]) ? stripslashes($versions[$n_values[$field]]['name']) : $this->lang['notice.none_e'];
                            break;
                        case 'status':
                            $new_value = $this->lang['status.' . $n_values[$field]];
                            break;
                        case 'reproductible':
                            $new_value = $n_values[$field] ? $common_lang['yes'] : $common_lang['no'];
                            break;
                        default:
                            $new_value = $n_values[$field];
                            $comment = '';
                    }
                    $pm_comment .= $field != 'contents' && $field != 'reproduction_method' ? $this->lang['labels.fields.' . $field] . ' : ' . stripslashes($new_value) . '
	' : '';
                    //Bug history update
                    BugtrackerService::add_history(array('bug_id' => $bug->get_id(), 'updater_id' => $this->current_user->get_id(), 'update_date' => $now->get_timestamp(), 'updated_field' => $field, 'old_value' => $o_values[$field], 'new_value' => $n_values[$field], 'change_comment' => $comment));
                }
            }
            if ($modification) {
                //Bug update
                BugtrackerService::update($bug);
                //Send PM to updaters if the option is enabled
                if ($this->config->are_pm_enabled() && $this->config->are_pm_edit_enabled() && !empty($pm_comment)) {
                    BugtrackerPMService::send_PM_to_updaters('edit', $bug->get_id(), $pm_comment);
                }
            }
        }
        Feed::clear_cache('bugtracker');
        BugtrackerStatsCache::invalidate();
        AppContext::get_response()->redirect($this->form->get_value('referrer') ? $this->form->get_value('referrer') : BugtrackerUrlBuilder::unsolved(), StringVars::replace_vars($this->is_new_bug ? $this->lang['success.add'] : $this->lang['success.edit'], array('id' => $bug->get_id())));
    }
 private function move_into_another($new_id)
 {
     switch ($this->parameter) {
         case 'type':
             //Update the type for the bugs of this type
             BugtrackerService::update_parameter(array('type' => $new_id), 'WHERE type=:id', array('id' => $this->id));
             if (empty($new_id)) {
                 //Delete history lines containing this type
                 BugtrackerService::delete_history("WHERE updated_field='type' AND (old_value=:id OR new_value=:id)", array('id' => $this->id));
             } else {
                 //Update history lines containing this type
                 BugtrackerService::update_history(array('old_value' => $new_id), "WHERE updated_field='type' AND old_value=:id", array('id' => $this->id));
                 BugtrackerService::update_history(array('new_value' => $new_id), "WHERE updated_field='type' AND new_value=:id", array('id' => $this->id));
             }
             break;
         case 'category':
             //Update the category for the bugs of this category
             BugtrackerService::update_parameter(array('category' => $new_id), 'WHERE category=:id', array('id' => $this->id));
             if (empty($new_id)) {
                 //Delete history lines containing this type
                 BugtrackerService::delete_history("WHERE updated_field='category' AND (old_value=:id OR new_value=:id)", array('id' => $this->id));
             } else {
                 //Update history lines containing this category
                 BugtrackerService::update_history(array('old_value' => $new_id), "WHERE updated_field='category' AND old_value=:id", array('id' => $this->id));
                 BugtrackerService::update_history(array('new_value' => $new_id), "WHERE updated_field='category' AND new_value=:id", array('id' => $this->id));
             }
             break;
         case 'version':
             //Update the version for the bugs of this version
             BugtrackerService::update_parameter(array('detected_in' => $new_id), 'WHERE detected_in=:id', array('id' => $this->id));
             BugtrackerService::update_parameter(array('fixed_in' => $new_id), 'WHERE fixed_in=:id', array('id' => $this->id));
             if (empty($new_id)) {
                 //Delete history lines containing this type
                 BugtrackerService::delete_history("WHERE updated_field='detected_in' OR updated_field='fixed_in' AND (old_value=:id OR new_value=:id)", array('id' => $this->id));
             } else {
                 //Update history lines containing this version
                 BugtrackerService::update_history(array('old_value' => $new_id), "WHERE updated_field='detected_in' AND old_value=:id", array('id' => $this->id));
                 BugtrackerService::update_history(array('new_value' => $new_id), "WHERE updated_field='detected_in' AND new_value=:id", array('id' => $this->id));
                 BugtrackerService::update_history(array('old_value' => $new_id), "WHERE updated_field='fixed_in' AND old_value=:id", array('id' => $this->id));
                 BugtrackerService::update_history(array('new_value' => $new_id), "WHERE updated_field='fixed_in' AND new_value=:id", array('id' => $this->id));
             }
             BugtrackerStatsCache::invalidate();
             break;
     }
 }
 private function save()
 {
     $now = new Date();
     $current_user = AppContext::get_current_user();
     if ($this->config->are_pm_enabled() && $this->config->are_pm_delete_enabled()) {
         //Add comment if needed
         $comment = !$this->form->field_is_disabled('comments_message') ? $this->form->get_value('comments_message', '') : '';
         //Send PM with comment to updaters if the option is enabled
         BugtrackerPMService::send_PM_to_updaters('delete', $this->bug->get_id(), $comment);
     }
     //Delete bug
     BugtrackerService::delete("WHERE id=:id", array('id' => $this->bug->get_id()));
     //Delete bug history
     BugtrackerService::delete_history("WHERE bug_id=:id", array('id' => $this->bug->get_id()));
     //Delete comments
     CommentsService::delete_comments_topic_module('bugtracker', $this->bug->get_id());
     //Delete admin alert
     if ($this->config->are_admin_alerts_enabled()) {
         $alerts = AdministratorAlertService::find_by_criteria($this->bug->get_id(), 'bugtracker');
         if (!empty($alerts)) {
             AdministratorAlertService::delete_alert($alerts[0]);
         }
     }
     BugtrackerStatsCache::invalidate();
     Feed::clear_cache('bugtracker');
 }