示例#1
0
 /**
  * Method used to add a new issue using the normal report form.
  *
  * @return  integer The new issue ID
  */
 public static function createFromPost()
 {
     $keys = array('add_primary_contact', 'attached_emails', 'category', 'contact', 'contact_email', 'contact_extra_emails', 'contact_person_fname', 'contact_person_lname', 'contact_phone', 'contact_timezone', 'contract', 'customer', 'custom_fields', 'description', 'estimated_dev_time', 'group', 'notify_customer', 'notify_senders', 'priority', 'private', 'release', 'severity', 'summary', 'users', 'product', 'product_version', 'expected_resolution_date', 'associated_issues');
     $data = array();
     foreach ($keys as $key) {
         if (isset($_POST[$key])) {
             $data[$key] = $_POST[$key];
         }
     }
     $prj_id = Auth::getCurrentProject();
     $current_usr_id = Auth::getUserID();
     $usr_id = $current_usr_id;
     // if we are creating an issue for a customer, put the
     // main customer contact as the reporter for it
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         $contact_usr_id = User::getUserIDByContactID($data['contact']);
         if (empty($contact_usr_id)) {
             $contact_usr_id = $usr_id;
         }
         $data['reporter'] = $contact_usr_id;
     } else {
         $data['reporter'] = $usr_id;
     }
     $data['msg_id'] = Mail_Helper::generateMessageID();
     $issue_id = self::insertIssue($prj_id, $data);
     if ($issue_id == -1) {
         return -1;
     }
     $has_RR = false;
     $info = User::getNameEmail($usr_id);
     // log the creation of the issue
     History::add($issue_id, $current_usr_id, 'issue_opened', 'Issue opened by {user}', array('user' => User::getFullName($current_usr_id)));
     $clone_iss_id = isset($_POST['clone_iss_id']) ? (int) $_POST['clone_iss_id'] : null;
     if ($clone_iss_id && Access::canCloneIssue($clone_iss_id, $current_usr_id)) {
         History::add($issue_id, $current_usr_id, 'issue_cloned_from', 'Issue cloned from #{issue_id}', array('issue_id' => $clone_iss_id));
         History::add($clone_iss_id, $current_usr_id, 'issue_cloned_to', 'Issue cloned to #{issue_id}', array('issue_id' => $issue_id));
         self::addAssociation($issue_id, $clone_iss_id, $usr_id, true);
     }
     $emails = array();
     if (CRM::hasCustomerIntegration($prj_id)) {
         $customer = $crm->getCustomer($data['customer']);
         $contract = $crm->getContract($data['contract']);
         if (!empty($data['contact_extra_emails']) && count($data['contact_extra_emails']) > 0) {
             $emails = $data['contact_extra_emails'];
         }
         // add the primary contact to the notification list
         if (isset($data['add_primary_contact']) && $data['add_primary_contact'] == 'yes') {
             $contact_email = User::getEmailByContactID($data['contact']);
             if (!empty($contact_email)) {
                 $emails[] = $contact_email;
             }
         }
         // if there are any technical account managers associated with this customer, add these users to the notification list
         $managers = $customer->getEventumAccountManagers();
         foreach ($managers as $manager) {
             $emails[] = $manager['usr_email'];
         }
     }
     // add the reporter to the notification list
     $emails[] = $info['usr_email'];
     $emails = array_unique($emails);
     foreach ($emails as $address) {
         Notification::subscribeEmail($usr_id, $issue_id, $address, Notification::getDefaultActions($issue_id, $address, 'new_issue'));
     }
     // only assign the issue to an user if the associated customer has any technical account managers
     $users = array();
     $has_TAM = false;
     if (CRM::hasCustomerIntegration($prj_id) && count($managers) > 0) {
         foreach ($managers as $manager) {
             if ($manager['cam_type'] == 'intpart') {
                 continue;
             }
             $users[] = $manager['cam_usr_id'];
             self::addUserAssociation($usr_id, $issue_id, $manager['cam_usr_id'], false);
             History::add($issue_id, $usr_id, 'issue_auto_assigned', 'Issue auto-assigned to {assignee} (TAM)', array('assignee' => User::getFullName($manager['cam_usr_id'])));
         }
         $has_TAM = true;
     }
     // now add the user/issue association (aka assignments)
     if (!empty($data['users']) && count($data['users']) > 0) {
         foreach ($data['users'] as $user) {
             $actions = Notification::getDefaultActions($issue_id, User::getEmail($user), 'new_issue');
             Notification::subscribeUser($usr_id, $issue_id, $user, $actions);
             self::addUserAssociation($usr_id, $issue_id, $user);
             if ($user != $usr_id) {
                 $users[] = $user;
             }
         }
     } else {
         // only use the round-robin feature if this new issue was not
         // already assigned to a customer account manager
         if (@count($managers) < 1) {
             $assignee = Round_Robin::getNextAssignee($prj_id);
             // assign the issue to the round robin person
             if (!empty($assignee)) {
                 $users[] = $assignee;
                 self::addUserAssociation($usr_id, $issue_id, $assignee, false);
                 History::add($issue_id, APP_SYSTEM_USER_ID, 'rr_issue_assigned', 'Issue auto-assigned to {assignee} (RR)', array('assignee' => User::getFullName($assignee)));
                 $has_RR = true;
             }
         }
     }
     // set product and version
     if (isset($data['product']) && $data['product'] != '-1') {
         Product::addIssueProductVersion($issue_id, $data['product'], $data['product_version']);
     }
     // process any files being uploaded
     // from ajax upload, attachment file ids
     $iaf_ids = !empty($_POST['iaf_ids']) ? explode(',', $_POST['iaf_ids']) : null;
     // if no iaf_ids passed, perhaps it's old style upload
     // TODO: verify that the uploaded file(s) owner is same as attachment owner.
     if (!$iaf_ids && isset($_FILES['file'])) {
         $iaf_ids = Attachment::addFiles($_FILES['file']);
     }
     if ($iaf_ids) {
         Attachment::attachFiles($issue_id, $usr_id, $iaf_ids, false, 'Files uploaded at issue creation time');
     }
     // need to associate any emails ?
     if (!empty($data['attached_emails'])) {
         $items = explode(',', $data['attached_emails']);
         Support::associate($usr_id, $issue_id, $items);
     }
     // need to notify any emails being converted into issues ?
     if (@count($data['notify_senders']) > 0) {
         $recipients = Notification::notifyEmailConvertedIntoIssue($prj_id, $issue_id, $data['notify_senders'], @$data['customer']);
     } else {
         $recipients = array();
     }
     // need to process any custom fields ?
     if (@count($data['custom_fields']) > 0) {
         foreach ($data['custom_fields'] as $fld_id => $value) {
             Custom_Field::associateIssue($issue_id, $fld_id, $value);
         }
     }
     // also send a special confirmation email to the customer contact
     if (@$data['notify_customer'] == 'yes' && !empty($data['contact'])) {
         $contact = $contract->getContact($data['contact']);
         // also need to pass the list of sender emails already notified,
         // so we can avoid notifying the same person again
         $contact_email = User::getEmailByContactID($data['contact']);
         if (@(!in_array($contact_email, $recipients))) {
             $contact->notifyNewIssue($issue_id);
         }
         // now check for additional emails in contact_extra_emails
         if (@count($data['contact_extra_emails']) > 0) {
             $notification_emails = $data['contact_extra_emails'];
             foreach ($notification_emails as $notification_email) {
                 if (@(!in_array($notification_email, $recipients))) {
                     try {
                         $notification_contact = $crm->getContactByEmail($notification_email);
                         $notification_contact->notifyNewIssue($issue_id);
                     } catch (ContactNotFoundException $e) {
                     }
                 }
             }
         }
     }
     // handle associated issues
     if (isset($data['associated_issues'])) {
         $associated_issues = explode(',', $data['associated_issues']);
         if ($clone_iss_id) {
             $associated_issues[] = $clone_iss_id;
         }
         self::updateAssociatedIssuesRelations($issue_id, $associated_issues);
     }
     Workflow::handleNewIssue($prj_id, $issue_id, $has_TAM, $has_RR);
     // also notify any users that want to receive emails anytime a new issue is created
     Notification::notifyNewIssue($prj_id, $issue_id);
     return $issue_id;
 }
 /**
  * Method used to update the values stored in the database.
  *
  * @access  public
  * @return  integer 1 if the update worked properly, any other value otherwise
  */
 function updateValues()
 {
     global $HTTP_POST_VARS;
     $prj_id = Auth::getCurrentProject();
     $issue_id = Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
     $old_values = Custom_Field::getValuesByIssue($prj_id, $issue_id);
     // get the types for all of the custom fields being submitted
     $stmt = "SELECT\n                    fld_id,\n                    fld_type\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n                 WHERE\n                    fld_id IN (" . implode(", ", Misc::escapeInteger(@array_keys($HTTP_POST_VARS['custom_fields']))) . ")";
     $field_types = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
     // get the titles for all of the custom fields being submitted
     $stmt = "SELECT\n                    fld_id,\n                    fld_title\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n                 WHERE\n                    fld_id IN (" . implode(", ", Misc::escapeInteger(@array_keys($HTTP_POST_VARS['custom_fields']))) . ")";
     $field_titles = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
     $updated_fields = array();
     foreach ($HTTP_POST_VARS["custom_fields"] as $fld_id => $value) {
         $fld_id = Misc::escapeInteger($fld_id);
         // security check
         $sql = "SELECT\n                        fld_min_role\n                    FROM\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n                    WHERE\n                        fld_id = {$fld_id}";
         $min_role = $GLOBALS["db_api"]->dbh->getOne($sql);
         if ($min_role > Auth::getCurrentRole()) {
             continue;
         }
         $option_types = array('multiple', 'combo');
         if (!in_array($field_types[$fld_id], $option_types)) {
             // check if this is a date field
             if ($field_types[$fld_id] == 'date') {
                 $value = $value['Year'] . "-" . $value['Month'] . "-" . $value['Day'];
                 if ($value == '--') {
                     $value = '';
                 }
             }
             // first check if there is actually a record for this field for the issue
             $stmt = "SELECT\n                            icf_id,\n                            icf_value\n                         FROM\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n                         WHERE\n                            icf_iss_id=" . $issue_id . " AND\n                            icf_fld_id={$fld_id}";
             $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC);
             if (PEAR::isError($res)) {
                 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
                 return -1;
             }
             $icf_id = $res['icf_id'];
             $icf_value = $res['icf_value'];
             if ($icf_value == $value) {
                 continue;
             }
             if (empty($icf_id)) {
                 // record doesn't exist, insert new record
                 $stmt = "INSERT IGNORE INTO\n                                " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n                             (\n                                icf_iss_id,\n                                icf_fld_id,\n                                icf_value\n                             ) VALUES (\n                                " . $issue_id . ",\n                                {$fld_id},\n                                '" . Misc::escapeString($value) . "'\n                             )";
                 $res = $GLOBALS["db_api"]->dbh->query($stmt);
                 if (PEAR::isError($res)) {
                     Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
                     return -1;
                 }
             } else {
                 // record exists, update it
                 $stmt = "UPDATE\n                                " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n                             SET\n                                icf_value='" . Misc::escapeString($value) . "'\n                             WHERE\n                                icf_id={$icf_id}";
                 $res = $GLOBALS["db_api"]->dbh->query($stmt);
                 if (PEAR::isError($res)) {
                     Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
                     return -1;
                 }
             }
             if ($field_types[$fld_id] == 'textarea') {
                 $updated_fields[$field_titles[$fld_id]] = '';
             } else {
                 $updated_fields[$field_titles[$fld_id]] = History::formatChanges($icf_value, $value);
             }
         } else {
             $old_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id, true);
             if (!is_array($old_value)) {
                 $old_value = array($old_value);
             }
             if (!is_array($value)) {
                 $value = array($value);
             }
             if (count(array_diff($old_value, $value)) > 0 || count(array_diff($value, $old_value)) > 0) {
                 $old_display_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id);
                 // need to remove all associated options from issue_custom_field and then
                 // add the selected options coming from the form
                 Custom_Field::removeIssueAssociation($fld_id, $HTTP_POST_VARS["issue_id"]);
                 if (@count($value) > 0) {
                     Custom_Field::associateIssue($HTTP_POST_VARS["issue_id"], $fld_id, $value);
                 }
                 $new_display_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id);
                 $updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_display_value, $new_display_value);
             }
         }
     }
     Workflow::handleCustomFieldsUpdated($prj_id, $issue_id, $old_values, Custom_Field::getValuesByIssue($prj_id, $issue_id));
     Issue::markAsUpdated($HTTP_POST_VARS["issue_id"]);
     // need to save a history entry for this
     if (count($updated_fields) > 0) {
         // log the changes
         $changes = '';
         $i = 0;
         foreach ($updated_fields as $key => $value) {
             if ($i > 0) {
                 $changes .= "; ";
             }
             if (!empty($value)) {
                 $changes .= "{$key}: {$value}";
             } else {
                 $changes .= "{$key}";
             }
             $i++;
         }
         History::add($HTTP_POST_VARS["issue_id"], Auth::getUserID(), History::getTypeID('custom_field_updated'), "Custom field updated ({$changes}) by " . User::getFullName(Auth::getUserID()));
     }
     return 1;
 }
 /**
  * Called when a new message is recieved.
  *
  * @param   integer $prj_id The projectID
  * @param   integer $issue_id The ID of the issue.
  * @param   object $message An object containing the new email
  * @param   array $row The array of data that was inserted into the database.
  * @param   boolean $closing If we are closing the issue.
  */
 function handleNewEmail($prj_id, $issue_id, $message, $row = false, $closing = false)
 {
     $subject = $row['subject'];
     $body = $row['body'];
     preg_match('/(H|C)[A-Z0-9]{12,14}/', $subject, $header_matches);
     preg_match_all('/(H|C)[A-Z0-9]{12,14}/', $body, $body_matches);
     if ($header_matches[0]) {
         $refs[] = $header_matches[0];
     }
     foreach ($body_matches[0] as $body_match) {
         if ($body_match) {
             $refs[] = $body_match;
         }
     }
     $refs = @array_unique($refs);
     $stmt = "Select reference_number,ss_subscription_id from " . ETEL_TRANS_SUBS_TABLE_NOSUB . "\n\t\tWHERE\n\t\t\treference_number in ('" . @implode("','", $refs) . "')";
     $res = $GLOBALS["db_api"]->dbh->getRow($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
     } else {
         if ($res[0]) {
             Custom_Field::associateIssue($issue_id, 1, $res[0]);
         }
         if ($res[1]) {
             Custom_Field::associateIssue($issue_id, 4, $res[1]);
         }
     }
     $res = Authorized_Replier::manualInsert($issue_id, $row['from']);
     Issue::updateControlStatus($issue_id);
 }
示例#4
0
 /**
  * Method used to add a new issue using the normal report form.
  *
  * @access  public
  * @return  integer The new issue ID
  */
 function insert()
 {
     global $HTTP_POST_VARS, $HTTP_POST_FILES, $insert_errors;
     $usr_id = Auth::getUserID();
     $prj_id = Auth::getCurrentProject();
     $initial_status = Project::getInitialStatus($prj_id);
     $insert_errors = array();
     $missing_fields = array();
     if ($HTTP_POST_VARS["category"] == '-1') {
         $missing_fields[] = "Category";
     }
     if ($HTTP_POST_VARS["priority"] == '-1') {
         $missing_fields[] = "Priority";
     }
     if ($HTTP_POST_VARS["estimated_dev_time"] == '') {
         $HTTP_POST_VARS["estimated_dev_time"] = 0;
     }
     // add new issue
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                 (\n                    iss_prj_id,\n";
     if (!empty($HTTP_POST_VARS["group"])) {
         $stmt .= "iss_grp_id,\n";
     }
     if (!empty($HTTP_POST_VARS["category"])) {
         $stmt .= "iss_prc_id,\n";
     }
     if (!empty($HTTP_POST_VARS["release"])) {
         $stmt .= "iss_pre_id,\n";
     }
     if (!empty($HTTP_POST_VARS["priority"])) {
         $stmt .= "iss_pri_id,\n";
     }
     $stmt .= "iss_usr_id,";
     if (!empty($initial_status)) {
         $stmt .= "iss_sta_id,";
     }
     if (Customer::hasCustomerIntegration($prj_id)) {
         $stmt .= "\n                    iss_customer_id,\n                    iss_customer_contact_id,\n                    iss_contact_person_lname,\n                    iss_contact_person_fname,\n                    iss_contact_email,\n                    iss_contact_phone,\n                    iss_contact_timezone,";
     }
     $stmt .= "\n                    iss_created_date,\n                    iss_last_public_action_date,\n                    iss_last_public_action_type,\n                    iss_summary,\n                    iss_description,\n                    iss_dev_time,\n                    iss_private,\n                    iss_root_message_id\n                 ) VALUES (\n                    " . $prj_id . ",\n";
     if (!empty($HTTP_POST_VARS["group"])) {
         $stmt .= Misc::escapeInteger($HTTP_POST_VARS["group"]) . ",\n";
     }
     if (!empty($HTTP_POST_VARS["category"])) {
         $stmt .= Misc::escapeInteger($HTTP_POST_VARS["category"]) . ",\n";
     }
     if (!empty($HTTP_POST_VARS["release"])) {
         $stmt .= Misc::escapeInteger($HTTP_POST_VARS["release"]) . ",\n";
     }
     if (!empty($HTTP_POST_VARS["priority"])) {
         $stmt .= Misc::escapeInteger($HTTP_POST_VARS["priority"]) . ",";
     }
     // if we are creating an issue for a customer, put the
     // main customer contact as the reporter for it
     if (Customer::hasCustomerIntegration($prj_id)) {
         $contact_usr_id = User::getUserIDByContactID($HTTP_POST_VARS['contact']);
         if (empty($contact_usr_id)) {
             $contact_usr_id = $usr_id;
         }
         $stmt .= Misc::escapeInteger($contact_usr_id) . ",";
     } else {
         $stmt .= $usr_id . ",";
     }
     if (!empty($initial_status)) {
         $stmt .= Misc::escapeInteger($initial_status) . ",";
     }
     if (Customer::hasCustomerIntegration($prj_id)) {
         $stmt .= "\n                    " . Misc::escapeInteger($HTTP_POST_VARS['customer']) . ",\n                    " . Misc::escapeInteger($HTTP_POST_VARS['contact']) . ",\n                    '" . Misc::escapeString($HTTP_POST_VARS["contact_person_lname"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["contact_person_fname"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["contact_email"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["contact_phone"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["contact_timezone"]) . "',";
     }
     $stmt .= "\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    'created',\n                    '" . Misc::escapeString($HTTP_POST_VARS["summary"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n                    " . Misc::escapeString($HTTP_POST_VARS["estimated_dev_time"]) . ",\n                    " . Misc::escapeInteger($HTTP_POST_VARS["private"]) . " ,\n                    '" . Misc::escapeString(Mail_API::generateMessageID()) . "'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         $new_issue_id = $GLOBALS["db_api"]->get_last_insert_id();
         $has_TAM = false;
         $has_RR = false;
         $info = User::getNameEmail($usr_id);
         // log the creation of the issue
         History::add($new_issue_id, Auth::getUserID(), History::getTypeID('issue_opened'), 'Issue opened by ' . User::getFullName(Auth::getUserID()));
         $emails = array();
         if (Customer::hasCustomerIntegration($prj_id)) {
             if (@count($HTTP_POST_VARS['contact_extra_emails']) > 0) {
                 $emails = $HTTP_POST_VARS['contact_extra_emails'];
             }
             // add the primary contact to the notification list
             if ($HTTP_POST_VARS['add_primary_contact'] == 'yes') {
                 $contact_email = User::getEmailByContactID($HTTP_POST_VARS['contact']);
                 if (!empty($contact_email)) {
                     $emails[] = $contact_email;
                 }
             }
             // if there are any technical account managers associated with this customer, add these users to the notification list
             $managers = Customer::getAccountManagers($prj_id, $HTTP_POST_VARS['customer']);
             $manager_usr_ids = array_keys($managers);
             $manager_emails = array_values($managers);
             $emails = array_merge($emails, $manager_emails);
         }
         // add the reporter to the notification list
         $emails[] = $info['usr_email'];
         $emails = array_unique($emails);
         // COMPAT: version >= 4.0.1
         $actions = Notification::getDefaultActions();
         foreach ($emails as $address) {
             Notification::subscribeEmail($usr_id, $new_issue_id, $address, $actions);
         }
         // only assign the issue to an user if the associated customer has any technical account managers
         $users = array();
         $has_TAM = false;
         if (Customer::hasCustomerIntegration($prj_id) && count($manager_usr_ids) > 0) {
             foreach ($manager_usr_ids as $manager_usr_id) {
                 $users[] = $manager_usr_id;
                 Issue::addUserAssociation($usr_id, $new_issue_id, $manager_usr_id, false);
                 History::add($new_issue_id, $usr_id, History::getTypeID('issue_auto_assigned'), 'Issue auto-assigned to ' . User::getFullName($manager_usr_id) . ' (TAM)');
             }
             $has_TAM = true;
         }
         // now add the user/issue association (aka assignments)
         if (@count($HTTP_POST_VARS["users"]) > 0) {
             for ($i = 0; $i < count($HTTP_POST_VARS["users"]); $i++) {
                 Notification::subscribeUser($usr_id, $new_issue_id, $HTTP_POST_VARS["users"][$i], $actions);
                 Issue::addUserAssociation($usr_id, $new_issue_id, $HTTP_POST_VARS["users"][$i]);
                 if ($HTTP_POST_VARS["users"][$i] != $usr_id) {
                     $users[] = $HTTP_POST_VARS["users"][$i];
                 }
             }
         } else {
             // only use the round-robin feature if this new issue was not
             // already assigned to a customer account manager
             if (@count($manager_usr_ids) < 1) {
                 $assignee = Round_Robin::getNextAssignee($prj_id);
                 // assign the issue to the round robin person
                 if (!empty($assignee)) {
                     $users[] = $assignee;
                     Issue::addUserAssociation($usr_id, $new_issue_id, $assignee, false);
                     History::add($new_issue_id, APP_SYSTEM_USER_ID, History::getTypeID('rr_issue_assigned'), 'Issue auto-assigned to ' . User::getFullName($assignee) . ' (RR)');
                     $has_RR = true;
                 }
             }
         }
         // now process any files being uploaded
         $found = 0;
         for ($i = 0; $i < count(@$HTTP_POST_FILES["file"]["name"]); $i++) {
             if (!@empty($HTTP_POST_FILES["file"]["name"][$i])) {
                 $found = 1;
                 break;
             }
         }
         if ($found) {
             $files = array();
             for ($i = 0; $i < count($HTTP_POST_FILES["file"]["name"]); $i++) {
                 $filename = @$HTTP_POST_FILES["file"]["name"][$i];
                 if (empty($filename)) {
                     continue;
                 }
                 $blob = Misc::getFileContents($HTTP_POST_FILES["file"]["tmp_name"][$i]);
                 if (empty($blob)) {
                     // error reading a file
                     $insert_errors["file[{$i}]"] = "There was an error uploading the file '{$filename}'.";
                     continue;
                 }
                 $files[] = array("filename" => $filename, "type" => $HTTP_POST_FILES['file']['type'][$i], "blob" => $blob);
             }
             if (count($files) > 0) {
                 $attachment_id = Attachment::add($new_issue_id, $usr_id, 'Files uploaded at issue creation time');
                 foreach ($files as $file) {
                     Attachment::addFile($attachment_id, $new_issue_id, $file["filename"], $file["type"], $file["blob"]);
                 }
             }
         }
         // need to associate any emails ?
         if (!empty($HTTP_POST_VARS["attached_emails"])) {
             $items = explode(",", $HTTP_POST_VARS["attached_emails"]);
             Support::associate($usr_id, $new_issue_id, $items, true);
         }
         // need to notify any emails being converted into issues ?
         if (@count($HTTP_POST_VARS["notify_senders"]) > 0) {
             $recipients = Notification::notifyEmailConvertedIntoIssue($prj_id, $new_issue_id, $HTTP_POST_VARS["notify_senders"], $customer_id);
         } else {
             $recipients = array();
         }
         // need to process any custom fields ?
         if (@count($HTTP_POST_VARS["custom_fields"]) > 0) {
             foreach ($HTTP_POST_VARS["custom_fields"] as $fld_id => $value) {
                 Custom_Field::associateIssue($new_issue_id, $fld_id, $value);
             }
         }
         // also send a special confirmation email to the customer contact
         if (@$HTTP_POST_VARS['notify_customer'] == 'yes' && !empty($HTTP_POST_VARS['contact'])) {
             // also need to pass the list of sender emails already notified,
             // so we can avoid notifying the same person again
             $contact_email = User::getEmailByContactID($HTTP_POST_VARS['contact']);
             if (@(!in_array($contact_email, $recipients))) {
                 Customer::notifyCustomerIssue($prj_id, $new_issue_id, $HTTP_POST_VARS['contact']);
             }
         }
         Workflow::handleNewIssue($prj_id, $new_issue_id, $has_TAM, $has_RR);
         // also notify any users that want to receive emails anytime a new issue is created
         Notification::notifyNewIssue($prj_id, $new_issue_id);
         return $new_issue_id;
     }
 }