/** * Method used to add a new support email to the system. * * @param array $row The support email details * @param object $structure The email structure object * @param integer $sup_id The support ID to be passed out * @param boolean $closing If this email comes from closing the issue * @return integer 1 if the insert worked, -1 otherwise */ public static function insertEmail($row, &$structure, &$sup_id, $closing = false) { // get usr_id from FROM header $usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($row['from'])); if (!empty($usr_id) && empty($row['customer_id'])) { $row['customer_id'] = User::getCustomerID($usr_id); } if (empty($row['customer_id'])) { $row['customer_id'] = null; } // try to get the parent ID $reference_message_id = Mail_Helper::getReferenceMessageID($row['full_email']); $parent_id = ''; if (!empty($reference_message_id)) { $parent_id = self::getIDByMessageID($reference_message_id); // make sure it is in the same issue if (!empty($parent_id) && (empty($row['issue_id']) || @$row['issue_id'] != self::getIssueFromEmail($parent_id))) { $parent_id = ''; } } $params = array('sup_ema_id' => $row['ema_id'], 'sup_iss_id' => $row['issue_id'], 'sup_customer_id' => $row['customer_id'], 'sup_message_id' => $row['message_id'] ?: '', 'sup_date' => $row['date'], 'sup_from' => $row['from'], 'sup_to' => $row['to'], 'sup_cc' => $row['cc'], 'sup_subject' => $row['subject'] ?: '', 'sup_has_attachment' => $row['has_attachment']); if (!empty($parent_id)) { $params['sup_parent_id'] = $parent_id; } if (!empty($usr_id)) { $params['sup_usr_id'] = $usr_id; } $stmt = 'INSERT INTO {{%support_email}} SET ' . DB_Helper::buildSet($params); try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } $new_sup_id = DB_Helper::get_last_insert_id(); $sup_id = $new_sup_id; $row['sup_id'] = $sup_id; // now add the body and full email to the separate table $stmt = 'INSERT INTO {{%support_email_body}} ( seb_sup_id, seb_body, seb_full_email ) VALUES ( ?, ?, ? )'; try { DB_Helper::getInstance()->query($stmt, array($new_sup_id, $row['body'], $row['full_email'])); } catch (DbException $e) { return -1; } if (!empty($row['issue_id'])) { $prj_id = Issue::getProjectID($row['issue_id']); } elseif (!empty($row['ema_id'])) { $prj_id = Email_Account::getProjectID($row['ema_id']); } else { $prj_id = false; } // FIXME: $row['ema_id'] is empty when mail is sent via convert note! if ($prj_id !== false) { Workflow::handleNewEmail($prj_id, @$row['issue_id'], $structure, $row, $closing); } return 1; }
include_once APP_INC_PATH . "class.priority.php"; include_once APP_INC_PATH . "class.misc.php"; include_once APP_INC_PATH . "class.project.php"; include_once APP_INC_PATH . "class.setup.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("manage/index.tpl.html"); Auth::checkAuthentication(APP_COOKIE); $tpl->assign("type", "issue_auto_creation"); @($ema_id = $HTTP_POST_VARS["ema_id"] ? $HTTP_POST_VARS["ema_id"] : $HTTP_GET_VARS["ema_id"]); $role_id = Auth::getCurrentRole(); if ($role_id == User::getRoleID('administrator') || $role_id == User::getRoleID('manager')) { if ($role_id == User::getRoleID('administrator')) { $tpl->assign("show_setup_links", true); } $prj_id = Email_Account::getProjectID($ema_id); if (@$HTTP_POST_VARS["cat"] == "update") { @Email_Account::updateIssueAutoCreation($ema_id, $HTTP_POST_VARS['issue_auto_creation'], $HTTP_POST_VARS['options']); } // load the form fields $tpl->assign("info", Email_Account::getDetails($ema_id)); $tpl->assign("cats", Category::getAssocList($prj_id)); $tpl->assign("priorities", Priority::getList($prj_id)); $tpl->assign("users", Project::getUserAssocList($prj_id, 'active')); $tpl->assign("options", Email_Account::getIssueAutoCreationOptions($ema_id)); $tpl->assign("ema_id", $ema_id); $tpl->assign("prj_title", Project::getName($prj_id)); $tpl->assign("uses_customer_integration", Customer::hasCustomerIntegration($prj_id)); } else { $tpl->assign("show_not_allowed_msg", true); }
/** * Method used to add a new support email to the system. * * @access public * @param array $row The support email details * @param object $structure The email structure object * @param integer $sup_id The support ID to be passed out * @param boolean $closing If this email comes from closing the issue * @return integer 1 if the insert worked, -1 otherwise */ function insertEmail($row, &$structure, &$sup_id, $closing = false) { // get usr_id from FROM header $usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($row['from'])); if (!empty($usr_id) && !empty($row["customer_id"])) { $row["customer_id"] = User::getCustomerID($usr_id); } if (empty($row['customer_id'])) { $row['customer_id'] = "NULL"; } // try to get the parent ID $reference_message_id = Mail_API::getReferenceMessageID($row['full_email']); $parent_id = ''; if (!empty($reference_message_id)) { $parent_id = Support::getIDByMessageID($reference_message_id); // make sure it is in the same issue if (!empty($parent_id) && (empty($row['issue_id']) || @$row['issue_id'] != Support::getIssueFromEmail($parent_id))) { $parent_id = ''; } } $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email\n (\n sup_ema_id,"; if (!empty($parent_id)) { $stmt .= "\nsup_parent_id,"; } $stmt .= "\n sup_iss_id,"; if (!empty($usr_id)) { $stmt .= "\nsup_usr_id,\n"; } $stmt .= " sup_customer_id,\n sup_message_id,\n sup_date,\n sup_from,\n sup_to,\n sup_cc,\n sup_subject,\n sup_has_attachment\n ) VALUES (\n " . Misc::escapeInteger($row["ema_id"]) . ",\n"; if (!empty($parent_id)) { $stmt .= "{$parent_id},\n"; } $stmt .= Misc::escapeInteger($row["issue_id"]) . ","; if (!empty($usr_id)) { $stmt .= "\n{$usr_id},\n"; } $stmt .= "\n " . Misc::escapeInteger($row["customer_id"]) . ",\n '" . Misc::escapeString($row["message_id"]) . "',\n '" . Misc::escapeString($row["date"]) . "',\n '" . Misc::escapeString($row["from"]) . "',\n '" . Misc::escapeString(@$row["to"]) . "',\n '" . Misc::escapeString(@$row["cc"]) . "',\n '" . Misc::escapeString($row["subject"]) . "',\n '" . Misc::escapeString($row["has_attachment"]) . "'\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_sup_id = $GLOBALS["db_api"]->get_last_insert_id(); $sup_id = $new_sup_id; // now add the body and full email to the separate table $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body\n (\n seb_sup_id,\n seb_body,\n seb_full_email\n ) VALUES (\n {$new_sup_id},\n '" . Misc::escapeString($row["body"]) . "',\n '" . Misc::escapeString($row["full_email"]) . "'\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 { Workflow::handleNewEmail(Email_Account::getProjectID($row["ema_id"]), @$row["issue_id"], $structure, $row, $closing); return 1; } } }