/** * 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; }
$usr_id = Auth::getUserID(); $tpl = new Template_Helper(); $tpl->setTemplate('file_upload.tpl.html'); $issue_id = isset($_POST['issue_id']) ? $_POST['issue_id'] : $_GET['iss_id']; $cat = isset($_POST['cat']) ? $_POST['cat'] : null; // handle uploads if ($cat == 'upload_file') { // attachment status (public or internal) $status = isset($_POST['status']) ? $_POST['status'] : null; $internal_only = $status == 'internal'; // from ajax upload, attachment file ids $iaf_ids = !empty($_POST['iaf_ids']) ? explode(',', $_POST['iaf_ids']) : null; // description for attachments $file_description = isset($_POST['file_description']) ? $_POST['file_description'] : 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['attachment'])) { $iaf_ids = Attachment::addFiles($_FILES['attachment']); } try { Attachment::attachFiles($issue_id, $usr_id, $iaf_ids, $internal_only, $file_description); $res = 1; } catch (Exception $e) { error_log($e->getMessage()); error_log($e->getTraceAsString()); $res = -1; } $tpl->assign('upload_file_result', $res); } $tpl->assign(array('issue_id' => $issue_id, 'current_user_prefs' => Prefs::get(Auth::getUserID()), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'max_attachment_bytes' => Attachment::getMaxAttachmentSize(true))); $tpl->displayTemplate();
/** * Method used to send an email from the user interface. * * @param int $parent_sup_id * @return int 1 if it worked, -1 otherwise * @deprecated use sendEmail directly instead */ public static function sendEmailFromPost($parent_sup_id = null) { // process any files being uploaded // from ajax upload, attachment file ids // if no iaf_ids passed, perhaps it's old style upload // TODO: verify that the uploaded file(s) owner is same as attachment owner. $iaf_ids = !empty($_POST['iaf_ids']) ? explode(',', $_POST['iaf_ids']) : null; if (!$iaf_ids && isset($_FILES['attachment'])) { $iaf_ids = Attachment::addFiles($_FILES['attachment']); } $issue_id = isset($_POST['issue_id']) ? (int) $_POST['issue_id'] : 0; $type = isset($_POST['type']) ? (string) $_POST['type'] : null; $from = isset($_POST['from']) ? (string) $_POST['from'] : null; $to = isset($_POST['to']) ? (string) $_POST['to'] : null; $cc = isset($_POST['cc']) ? (string) $_POST['cc'] : null; $subject = isset($_POST['subject']) ? (string) $_POST['subject'] : null; $body = isset($_POST['message']) ? (string) $_POST['message'] : null; $options = array('parent_sup_id' => $parent_sup_id, 'iaf_ids' => $iaf_ids, 'add_unknown' => isset($_POST['add_unknown']) && $_POST['add_unknown'] == 'yes', 'ema_id' => isset($_POST['ema_id']) ? (int) $_POST['ema_id'] : null); return self::sendEmail($issue_id, $type, $from, $to, $cc, $subject, $body, $options); }
// | 51 Franklin Street, Suite 330 | // | Boston, MA 02110-1301, USA. | // +----------------------------------------------------------------------+ // | Authors: Elan Ruusamäe <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../../init.php'; // handle ajax upload // FIXME: no identity logged who added the file. try { // check if logged in. if not, just give error if (!Auth::hasValidCookie(APP_COOKIE)) { throw new BadFunctionCallException(ev_gettext('Must be logged in')); } if (!isset($_GET['file'])) { // TRANSLATORS: this is technical error and should not be displayed to end users throw new InvalidArgumentException(ev_gettext('No file argument')); } $file = (string) $_GET['file']; if (!isset($_FILES[$file])) { throw new InvalidArgumentException(ev_gettext('No files uploaded')); } $iaf_id = Attachment::addFiles($_FILES[$file]); $res = array('error' => 0, 'iaf_id' => $iaf_id); } catch (Exception $e) { $code = $e->getCode(); $res = array('error' => $code ? $code : -1, 'message' => $e->getMessage()); error_log($e->getMessage()); error_log($e->getTraceAsString()); } header('Content-Type: application/json; charset=UTF-8'); echo json_encode($res);