Esempio n. 1
0
 /**
  * Method used to save the login information into a log file. It will be
  * useful for administrative purposes, so we know which customers were able
  * to login.
  *
  * @access  public
  * @param   string $email The email associated with the user
  * @param   string $type Whether it was a successful login or not
  * @param   string $extra The reason for not being a successful login
  */
 function saveLoginAttempt($email, $type, $extra = false)
 {
     $msg = Date_API::getCurrentDateGMT() . " - Login attempt by '{$email}' was ";
     if ($type == 'success') {
         $msg .= "successful.\n";
     } else {
         $msg .= "not successful because of '{$extra}'.\n";
     }
     $fp = @fopen(APP_LOGIN_LOG, "a");
     @fwrite($fp, $msg);
     @fclose($fp);
 }
Esempio n. 2
0
 /**
  * Method used to log the changes made against a specific issue.
  *
  * @access  public
  * @param   integer $iss_id The issue ID
  * @param   integer $usr_id The ID of the user.
  * @param   integer $htt_id The type ID of this history event.
  * @param   string $summary The summary of the changes
  * @param   boolean $hide If this history item should be hidden.
  * @return  void
  */
 function add($iss_id, $usr_id, $htt_id, $summary, $hide = false)
 {
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_history\n                 (\n                    his_iss_id,\n                    his_usr_id,\n                    his_created_date,\n                    his_summary,\n                    his_htt_id";
     if ($hide == true) {
         $stmt .= ", his_is_hidden";
     }
     $stmt .= ") VALUES (\n                    " . Misc::escapeInteger($iss_id) . ",\n                    " . Misc::escapeInteger($usr_id) . ",\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($summary) . "',\n                    {$htt_id}";
     if ($hide == true) {
         $stmt .= ", 1";
     }
     $stmt .= ")";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     }
 }
Esempio n. 3
0
 /**
  * Converts a note to a draft or an email
  *
  * @access  public
  * @param   $note_id The id of the note
  * @param   $target What the not should be converted too
  * @param   $authorize_sender If the sender should be added to authorized senders list.
  */
 function convertNote($note_id, $target, $authorize_sender = false)
 {
     $note_id = Misc::escapeInteger($note_id);
     $issue_id = Note::getIssueID($note_id);
     $email_account_id = Email_Account::getEmailAccount();
     $blocked_message = Note::getBlockedMessage($note_id);
     $unknown_user = Note::getUnknownUser($note_id);
     $structure = Mime_Helper::decode($blocked_message, true, true);
     $body = Mime_Helper::getMessageBody($structure);
     $sender_email = strtolower(Mail_API::getEmailAddress($structure->headers['from']));
     if ($target == 'email') {
         if (Mime_Helper::hasAttachments($blocked_message)) {
             $has_attachments = 1;
         } else {
             $has_attachments = 0;
         }
         list($blocked_message, $headers) = Mail_API::rewriteThreadingHeaders($issue_id, $blocked_message, @$structure->headers);
         $t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_API::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$blocked_message, 'has_attachment' => $has_attachments, 'headers' => $headers);
         // need to check for a possible customer association
         if (!empty($structure->headers['from'])) {
             $details = Email_Account::getDetails($email_account_id);
             // check from the associated project if we need to lookup any customers by this email address
             if (Customer::hasCustomerIntegration($details['ema_prj_id'])) {
                 // check for any customer contact association
                 list($customer_id, ) = Customer::getCustomerIDByEmails($details['ema_prj_id'], array($sender_email));
                 if (!empty($customer_id)) {
                     $t['customer_id'] = $customer_id;
                 }
             }
         }
         if (empty($t['customer_id'])) {
             $update_type = 'staff response';
             $t['customer_id'] = "NULL";
         } else {
             $update_type = 'customer action';
         }
         $res = Support::insertEmail($t, $structure, $sup_id);
         if ($res != -1) {
             Support::extractAttachments($issue_id, $blocked_message);
             // notifications about new emails are always external
             $internal_only = false;
             // special case when emails are bounced back, so we don't want to notify the customer about those
             if (Notification::isBounceMessage($sender_email)) {
                 $internal_only = true;
             }
             Notification::notifyNewEmail(Auth::getUserID(), $issue_id, $t, $internal_only, false, '', $sup_id);
             Issue::markAsUpdated($issue_id, $update_type);
             Note::remove($note_id, false);
             History::add($issue_id, Auth::getUserID(), History::getTypeID('note_converted_email'), "Note converted to e-mail (from: " . @$structure->headers['from'] . ") by " . User::getFullName(Auth::getUserID()));
             // now add sender as an authorized replier
             if ($authorize_sender) {
                 Authorized_Replier::manualInsert($issue_id, @$structure->headers['from']);
             }
         }
         return $res;
     } else {
         // save message as a draft
         $res = Draft::saveEmail($issue_id, $structure->headers['to'], $structure->headers['cc'], $structure->headers['subject'], $body, false, $unknown_user);
         // remove the note, if the draft was created successfully
         if ($res) {
             Note::remove($note_id, false);
             History::add($issue_id, Auth::getUserID(), History::getTypeID('note_converted_draft'), "Note converted to draft (from: " . @$structure->headers['from'] . ") by " . User::getFullName(Auth::getUserID()));
         }
         return $res;
     }
 }
 /**
  * Saves a log entry about the attempt, successful or otherwise, to send the
  * queued email message.
  *
  * @access  private
  * @param   integer $maq_id The queued email message ID
  * @param   string $status The status of the attempt ('sent' or 'error')
  * @param   string $server_message The full message from the SMTP server, in case of an error
  * @return  boolean
  */
 function _saveLog($maq_id, $status, $server_message)
 {
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "mail_queue_log\n                 (\n                    mql_maq_id,\n                    mql_created_date,\n                    mql_status,\n                    mql_server_message\n                 ) VALUES (\n                    {$maq_id},\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '{$status}',\n                    '{$server_message}'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return false;
     } else {
         if ($status == 'error') {
             $sql_incattempt = ", maq_attempts = maq_attempts + 1";
         }
         $stmt = "UPDATE\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "mail_queue\n                     SET\n                        maq_status = if(maq_attempts>2,'gaveup','{$status}')\n\t\t\t\t\t\t{$sql_incattempt}\n                     WHERE\n                        maq_id={$maq_id}";
         $GLOBALS["db_api"]->dbh->query($stmt);
         return true;
     }
 }
 /**
  * Method used to remotely record a time tracking entry.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   integer $usr_id The user ID
  * @param   integer $cat_id The time tracking category ID
  * @param   string $summary The summary of the work entry
  * @param   integer $time_spent The time spent in minutes
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 function recordRemoteEntry($issue_id, $usr_id, $cat_id, $summary, $time_spent)
 {
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking\n                 (\n                    ttr_ttc_id,\n                    ttr_iss_id,\n                    ttr_usr_id,\n                    ttr_created_date,\n                    ttr_time_spent,\n                    ttr_summary\n                 ) VALUES (\n                    " . Misc::escapeInteger($cat_id) . ",\n                    " . Misc::escapeInteger($issue_id) . ",\n                    " . Misc::escapeInteger($usr_id) . ",\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    " . Misc::escapeInteger($time_spent) . ",\n                    '" . Misc::escapeString($summary) . "'\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 {
         Issue::markAsUpdated($issue_id);
         // need to save a history entry for this
         History::add($issue_id, $usr_id, History::getTypeID('remote_time_added'), 'Time tracking entry submitted remotely by ' . User::getFullName($usr_id));
         return 1;
     }
 }
Esempio n. 6
0
 /**
  * Method used to update an existing draft response.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   integer $emd_id The email draft ID
  * @param   string $to The primary recipient of the draft
  * @param   string $cc The secondary recipients of the draft
  * @param   string $subject The subject of the draft
  * @param   string $message The draft body
  * @param   integer $parent_id The ID of the email that this draft is replying to, if any
  * @return  integer 1 if the update worked, -1 otherwise
  */
 function update($issue_id, $emd_id, $to, $cc, $subject, $message, $parent_id = FALSE)
 {
     $issue_id = Misc::escapeInteger($issue_id);
     $emd_id = Misc::escapeInteger($emd_id);
     $parent_id = Misc::escapeInteger($issue_id);
     if (empty($parent_id)) {
         $parent_id = 'NULL';
     }
     $usr_id = Auth::getUserID();
     // update previous draft and insert new record
     $stmt = "UPDATE\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_draft\n                 SET\n                    emd_updated_date='" . Date_API::getCurrentDateGMT() . "',\n                    emd_status = 'edited'\n                 WHERE\n                    emd_id={$emd_id}";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         Issue::markAsUpdated($issue_id, "draft saved");
         History::add($issue_id, $usr_id, History::getTypeID('draft_updated'), 'Email message draft updated by ' . User::getFullName($usr_id));
         Draft::saveEmail($issue_id, $to, $cc, $subject, $message, $parent_id, false, false);
         return 1;
     }
 }
Esempio n. 7
0
 /**
  * Method used to add a new project to the system.
  *
  * @access  public
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n                 (\n                    prj_created_date,\n                    prj_title,\n                    prj_status,\n                    prj_lead_usr_id,\n                    prj_initial_sta_id,\n                    prj_outgoing_sender_name,\n                    prj_outgoing_sender_email,\n                    prj_remote_invocation,\n                    prj_customer_backend,\n                    prj_workflow_backend\n                 ) VALUES (\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["status"]) . "',\n                    " . Misc::escapeInteger($HTTP_POST_VARS["lead_usr_id"]) . ",\n                    " . Misc::escapeInteger($HTTP_POST_VARS["initial_status"]) . ",\n                    '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_name"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_email"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["remote_invocation"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["customer_backend"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["workflow_backend"]) . "'\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_prj_id = $GLOBALS["db_api"]->get_last_insert_id();
         for ($i = 0; $i < count($HTTP_POST_VARS["users"]); $i++) {
             if ($HTTP_POST_VARS["users"][$i] == $HTTP_POST_VARS["lead_usr_id"]) {
                 $role_id = User::getRoleID("Manager");
             } else {
                 $role_id = User::getRoleID("Standard User");
             }
             Project::associateUser($new_prj_id, $HTTP_POST_VARS["users"][$i], $role_id);
         }
         foreach ($HTTP_POST_VARS['statuses'] as $sta_id) {
             Status::addProjectAssociation($sta_id, $new_prj_id);
         }
         Display_Column::setupNewProject($new_prj_id);
         return 1;
     }
 }
Esempio n. 8
0
 /**
  * Method used to add a news entry to the system.
  *
  * @access  public
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     if (Validation::isWhitespace($HTTP_POST_VARS["message"])) {
         return -3;
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news\n                 (\n                    nws_usr_id,\n                    nws_created_date,\n                    nws_title,\n                    nws_message,\n                    nws_status\n                 ) VALUES (\n                    " . Auth::getUserID() . ",\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["message"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["status"]) . "'\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_news_id = $GLOBALS["db_api"]->get_last_insert_id();
         // now populate the project-news mapping table
         foreach ($HTTP_POST_VARS['projects'] as $prj_id) {
             News::addProjectAssociation($new_news_id, $prj_id);
         }
         return 1;
     }
 }
 /**
  * Method used to save a history entry about the execution of the current
  * reminder.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   integer $rma_id The reminder action ID
  * @return  boolean
  */
 function saveHistory($issue_id, $rma_id)
 {
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_history\n                 (\n                    rmh_iss_id,\n                    rmh_rma_id,\n                    rmh_created_date\n                 ) VALUES (\n                    " . Misc::escapeInteger($issue_id) . ",\n                    " . Misc::escapeInteger($rma_id) . ",\n                    '" . Date_API::getCurrentDateGMT() . "'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return false;
     } else {
         return true;
     }
 }
Esempio n. 10
0
 /**
  * Method used to send an email from the user interface.
  *
  * @access  public
  * @return  integer 1 if it worked, -1 otherwise
  */
 function sendEmail($parent_sup_id = FALSE)
 {
     global $HTTP_POST_VARS, $HTTP_SERVER_VARS;
     // if we are replying to an existing email, set the In-Reply-To: header accordingly
     if ($parent_sup_id) {
         $in_reply_to = Support::getMessageIDByID($parent_sup_id);
     } else {
         $in_reply_to = false;
     }
     // get ID of whoever is sending this.
     $sender_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($HTTP_POST_VARS["from"]));
     if (empty($sender_usr_id)) {
         $sender_usr_id = false;
     }
     // get type of email this is
     if (!empty($HTTP_POST_VARS['type'])) {
         $type = $HTTP_POST_VARS['type'];
     } else {
         $type = '';
     }
     // remove extra 'Re: ' from subject
     $HTTP_POST_VARS['subject'] = Mail_API::removeExcessRe($HTTP_POST_VARS['subject'], true);
     $internal_only = false;
     $message_id = Mail_API::generateMessageID();
     // hack needed to get the full headers of this web-based email
     $full_email = Support::buildFullHeaders($HTTP_POST_VARS["issue_id"], $message_id, $HTTP_POST_VARS["from"], $HTTP_POST_VARS["to"], $HTTP_POST_VARS["cc"], $HTTP_POST_VARS["subject"], $HTTP_POST_VARS["message"], $in_reply_to);
     // email blocking should only be done if this is an email about an associated issue
     if (!empty($HTTP_POST_VARS['issue_id'])) {
         $user_info = User::getNameEmail(Auth::getUserID());
         // check whether the current user is allowed to send this email to customers or not
         if (!Support::isAllowedToEmail($HTTP_POST_VARS["issue_id"], $user_info['usr_email'])) {
             // add the message body as a note
             $HTTP_POST_VARS['blocked_msg'] = $full_email;
             $HTTP_POST_VARS['title'] = $HTTP_POST_VARS["subject"];
             $HTTP_POST_VARS['note'] = Mail_API::getCannedBlockedMsgExplanation() . $HTTP_POST_VARS["message"];
             Note::insert(Auth::getUserID(), $HTTP_POST_VARS["issue_id"]);
             Workflow::handleBlockedEmail(Issue::getProjectID($HTTP_POST_VARS['issue_id']), $HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS, 'web');
             return 1;
         }
     }
     // only send a direct email if the user doesn't want to add the Cc'ed people to the notification list
     if (@$HTTP_POST_VARS['add_unknown'] == 'yes') {
         if (!empty($HTTP_POST_VARS['issue_id'])) {
             // add the recipients to the notification list of the associated issue
             $recipients = array($HTTP_POST_VARS['to']);
             $recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
             for ($i = 0; $i < count($recipients); $i++) {
                 if (!empty($recipients[$i]) && !Notification::isIssueRoutingSender($HTTP_POST_VARS["issue_id"], $recipients[$i])) {
                     Notification::subscribeEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], Mail_API::getEmailAddress($recipients[$i]), array('emails'));
                 }
             }
         }
     } else {
         // Usually when sending out emails associated to an issue, we would
         // simply insert the email in the table and call the Notification::notifyNewEmail() method,
         // but on this case we need to actually send the email to the recipients that are not
         // already in the notification list for the associated issue, if any.
         // In the case of replying to an email that is not yet associated with an issue, then
         // we are always directly sending the email, without using any notification list
         // functionality.
         if (!empty($HTTP_POST_VARS['issue_id'])) {
             // send direct emails only to the unknown addresses, and leave the rest to be
             // catched by the notification list
             $from = Notification::getFixedFromHeader($HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS['from'], 'issue');
             // build the list of unknown recipients
             if (!empty($HTTP_POST_VARS['to'])) {
                 $recipients = array($HTTP_POST_VARS['to']);
                 $recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
             } else {
                 $recipients = Support::getRecipientsCC($HTTP_POST_VARS['cc']);
             }
             $unknowns = array();
             for ($i = 0; $i < count($recipients); $i++) {
                 if (!Notification::isSubscribedToEmails($HTTP_POST_VARS['issue_id'], $recipients[$i])) {
                     $unknowns[] = $recipients[$i];
                 }
             }
             if (count($unknowns) > 0) {
                 $to = array_shift($unknowns);
                 $cc = implode('; ', $unknowns);
                 // send direct emails
                 Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $to, $cc, $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id, $sender_usr_id);
             }
         } else {
             // send direct emails to all recipients, since we don't have an associated issue
             $project_info = Project::getOutgoingSenderAddress(Auth::getCurrentProject());
             // use the project-related outgoing email address, if there is one
             if (!empty($project_info['email'])) {
                 $from = Mail_API::getFormattedName(User::getFullName(Auth::getUserID()), $project_info['email']);
             } else {
                 // otherwise, use the real email address for the current user
                 $from = User::getFromHeader(Auth::getUserID());
             }
             // send direct emails
             Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $HTTP_POST_VARS['to'], $HTTP_POST_VARS['cc'], $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id);
         }
     }
     $t = array('customer_id' => 'NULL', 'issue_id' => $HTTP_POST_VARS["issue_id"] ? $HTTP_POST_VARS["issue_id"] : 0, 'ema_id' => $HTTP_POST_VARS['ema_id'], 'message_id' => $message_id, 'date' => Date_API::getCurrentDateGMT(), 'from' => $HTTP_POST_VARS['from'], 'to' => $HTTP_POST_VARS['to'], 'cc' => @$HTTP_POST_VARS['cc'], 'subject' => @$HTTP_POST_VARS['subject'], 'body' => $HTTP_POST_VARS['message'], 'full_email' => $full_email, 'has_attachment' => 0);
     // associate this new email with a customer, if appropriate
     if (Auth::getCurrentRole() == User::getRoleID('Customer')) {
         $customer_id = User::getCustomerID(Auth::getUserID());
         if (!empty($customer_id) && $customer_id != -1) {
             $t['customer_id'] = $customer_id;
         }
     }
     $structure = Mime_Helper::decode($full_email, true, false);
     $t['headers'] = $structure->headers;
     $res = Support::insertEmail($t, $structure, $sup_id);
     if (!empty($HTTP_POST_VARS["issue_id"])) {
         // need to send a notification
         Notification::notifyNewEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], $t, $internal_only, false, $type, $sup_id);
         // mark this issue as updated
         if (!empty($t['customer_id']) && $t['customer_id'] != 'NULL') {
             Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'customer action');
         } else {
             if (!empty($sender_usr_id) && User::getRoleByUser($sender_usr_id, Issue::getProjectID($HTTP_POST_VARS['issue_id'])) > User::getRoleID('Customer')) {
                 Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'staff response');
             } else {
                 Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'user response');
             }
         }
         // save a history entry for this
         History::add($HTTP_POST_VARS["issue_id"], Auth::getUserID(), History::getTypeID('email_sent'), 'Outgoing email sent by ' . User::getFullName(Auth::getUserID()));
         // also update the last_response_date field for the associated issue
         if (Auth::getCurrentRole() > User::getRoleID('Customer')) {
             $stmt = "UPDATE\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                         SET\n                            iss_last_response_date='" . Date_API::getCurrentDateGMT() . "'\n                         WHERE\n                            iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
             $GLOBALS["db_api"]->dbh->query($stmt);
             $stmt = "UPDATE\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                         SET\n                            iss_first_response_date='" . Date_API::getCurrentDateGMT() . "'\n                         WHERE\n                            iss_first_response_date IS NULL AND\n                            iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
             $GLOBALS["db_api"]->dbh->query($stmt);
         }
     }
     return 1;
 }
Esempio n. 11
0
 /**
  * Returns the status of a quarantine.
  *
  * @param   integer $issue_id The issue ID
  * @return  integer Indicates what the current state of quarantine is.
  */
 function getQuarantineInfo($issue_id)
 {
     $stmt = "SELECT\n                    iqu_status,\n                    iqu_expiration\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_quarantine\n                 WHERE\n                    iqu_iss_id = " . Misc::escapeInteger($issue_id) . " AND\n                        (iqu_expiration > '" . Date_API::getCurrentDateGMT() . "' OR\n                        iqu_expiration IS NULL)";
     $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 array();
     } else {
         if (!empty($res["iqu_expiration"])) {
             $expiration_ts = Date_API::getUnixTimestamp($res['iqu_expiration'], Date_API::getDefaultTimezone());
             $res["time_till_expiration"] = Date_API::getFormattedDateDiff($expiration_ts, Date_API::getCurrentUnixTimestampGMT());
         }
         return $res;
     }
 }
 /**
  * Method used to update the details of a specific reminder condition.
  *
  * @access  public
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 function update()
 {
     global $HTTP_POST_VARS;
     $stmt = "UPDATE\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition\n                 SET\n                    rlc_last_updated_date='" . Date_API::getCurrentDateGMT() . "',\n                    rlc_rmf_id=" . Misc::escapeInteger($HTTP_POST_VARS['field']) . ",\n                    rlc_rmo_id=" . Misc::escapeInteger($HTTP_POST_VARS['operator']) . ",\n                    rlc_value='" . Misc::escapeString(@$HTTP_POST_VARS['value']) . "',\n                    rlc_comparison_rmf_id = '" . Misc::escapeInteger(@$HTTP_POST_VARS['comparison_field']) . "'\n                 WHERE\n                    rlc_id=" . Misc::escapeInteger($HTTP_POST_VARS['id']);
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         return 1;
     }
 }
Esempio n. 13
0
 /**
  * Method used to add a new resolution by using the administrative
  * interface of the system.
  *
  * @access  public
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution\n                 (\n                    res_title,\n                    res_created_date\n                 ) VALUES (\n                    '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    '" . Date_API::getCurrentDateGMT() . "'\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 {
         return 1;
     }
 }
 /**
  * Method used to update an existing requirement with the appropriate
  * impact analysis.
  *
  * @access  public
  * @param   integer $isr_id The requirement ID
  * @return  integer -1 if an error occurred or 1 otherwise
  */
 function update($isr_id)
 {
     global $HTTP_POST_VARS;
     $stmt = "SELECT\n                    isr_iss_id\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement\n                 WHERE\n                    isr_id=" . Misc::escapeInteger($isr_id);
     $issue_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
     // we are storing minutes, not hours
     $dev_time = $HTTP_POST_VARS["dev_time"] * 60;
     $usr_id = Auth::getUserID();
     $stmt = "UPDATE\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement\n                 SET\n                    isr_updated_usr_id={$usr_id},\n                    isr_updated_date='" . Date_API::getCurrentDateGMT() . "',\n                    isr_dev_time={$dev_time},\n                    isr_impact_analysis='" . Misc::escapeString($HTTP_POST_VARS["impact_analysis"]) . "'\n                 WHERE\n                    isr_id=" . Misc::escapeInteger($isr_id);
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         Issue::markAsUpdated($issue_id);
         // need to save a history entry for this
         History::add($issue_id, $usr_id, History::getTypeID('impact_analysis_updated'), 'Impact analysis submitted by ' . User::getFullName($usr_id));
         return 1;
     }
 }
Esempio n. 15
0
 /**
  * Method used to associate a new checkin with an existing issue
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   integer $i The offset of the file that was changed
  * @return  integer 1 if the update worked, -1 otherwise
  */
 function logCheckin($issue_id, $i)
 {
     global $HTTP_GET_VARS;
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin\n                 (\n                    isc_iss_id,\n                    isc_module,\n                    isc_filename,\n                    isc_old_version,\n                    isc_new_version,\n                    isc_created_date,\n                    isc_username,\n                    isc_commit_msg\n                 ) VALUES (\n                    {$issue_id},\n                    '" . Misc::escapeString($HTTP_GET_VARS["module"]) . "',\n                    '" . Misc::escapeString($HTTP_GET_VARS["files"][$i]) . "',\n                    '" . Misc::escapeString($HTTP_GET_VARS["old_versions"][$i]) . "',\n                    '" . Misc::escapeString($HTTP_GET_VARS["new_versions"][$i]) . "',\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($HTTP_GET_VARS["username"]) . "',\n                    '" . Misc::escapeString($HTTP_GET_VARS["commit_msg"]) . "'\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 {
         // need to mark this issue as updated
         Issue::markAsUpdated($issue_id, 'scm checkin');
         // need to save a history entry for this
         History::add($issue_id, APP_SYSTEM_USER_ID, History::getTypeID('scm_checkin_associated'), 'SCM Checkins associated by SCM user \'' . $HTTP_GET_VARS["username"] . '\'.');
         return 1;
     }
 }
Esempio n. 16
0
 /**
  * Method used to add a new user to the system.
  *
  * @access  public
  * @return  integer 1 if the update worked, -1 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     $projects = array();
     foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) {
         if ($role < 1) {
             continue;
         }
         $projects[] = $prj_id;
     }
     $fn = preg_split('/\\s+/', $HTTP_POST_VARS["full_name"], 2);
     $username = preg_split('/@/', $HTTP_POST_VARS["email"], 2);
     $prefs = Prefs::getDefaults($projects);
     $stmt = "INSERT INTO\n                    " . ETEL_USER_TABLE_NOSUB . "\n\t\t\t\tSET\n                    en_ev_customer_id = NULL,\n                    en_ev_contact_id = NULL,\n                    en_signup = '" . Date_API::getCurrentDateGMT() . "',\n                    en_username = '******',\n                    en_password = '******',\n                    en_firstname = '" . Misc::escapeString($fn[0]) . "',\n                    en_lastname = '" . Misc::escapeString($fn[1]) . "',\n                    en_email = '" . Misc::escapeString($HTTP_POST_VARS["email"]) . "',\n                    en_ev_pref = '" . Misc::escapeString($prefs) . "'\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_usr_id = $GLOBALS["db_api"]->get_last_insert_id();
         // add the project associations!
         foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) {
             if ($role < 1) {
                 continue;
             }
             Project::associateUser($prj_id, $new_usr_id, $role);
         }
         // send email to user
         Notification::notifyNewUser($new_usr_id, $HTTP_POST_VARS["password"]);
         return 1;
     }
 }
 /**
  * Method used to add a new subscriber manually, by using the
  * email notification interface.
  *
  * @access  public
  * @param   integer $usr_id The user ID of the person performing this change
  * @param   integer $issue_id The issue ID
  * @param   string $form_email The email address to subscribe
  * @param   array $actions The actions to subcribe to
  * @return  integer 1 if the update worked, -1 otherwise
  */
 function subscribeEmail($usr_id, $issue_id, $form_email, $actions)
 {
     $form_email = strtolower(Mail_API::getEmailAddress($form_email));
     // first check if this is an actual user or just an email address
     $user_emails = User::getAssocEmailList();
     if (in_array($form_email, array_keys($user_emails))) {
         return Notification::subscribeUser($usr_id, $issue_id, $user_emails[$form_email], $actions);
     }
     $issue_id = Misc::escapeInteger($issue_id);
     $email = Misc::escapeString($form_email);
     $prj_id = Issue::getProjectID($issue_id);
     // call workflow to modify actions or cancel adding this user.
     $subscriber_usr_id = false;
     $workflow = Workflow::handleSubscription($prj_id, $issue_id, $subscriber_usr_id, $email, $actions);
     if ($workflow === false) {
         // cancel subscribing the user
         return -2;
     }
     // manual check to prevent duplicates
     if (!empty($email)) {
         $stmt = "SELECT\r\n                        COUNT(sub_id)\r\n                     FROM\r\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "subscription\r\n                     WHERE\r\n                        sub_iss_id={$issue_id} AND\r\n                        sub_email='{$email}'";
         $total = $GLOBALS["db_api"]->dbh->getOne($stmt);
         if ($total > 0) {
             return -1;
         }
     }
     $stmt = "INSERT INTO\r\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "subscription\r\n                 (\r\n                    sub_iss_id,\r\n                    sub_usr_id,\r\n                    sub_created_date,\r\n                    sub_level,\r\n                    sub_email\r\n                 ) VALUES (\r\n                    {$issue_id},\r\n                    0,\r\n                    '" . Date_API::getCurrentDateGMT() . "',\r\n                    'issue',\r\n                    '{$email}'\r\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 {
         $sub_id = $GLOBALS["db_api"]->get_last_insert_id();
         for ($i = 0; $i < count($actions); $i++) {
             Notification::addType($sub_id, $actions[$i]);
         }
         // need to mark the issue as updated
         Issue::markAsUpdated($issue_id);
         // need to save a history entry for this
         History::add($issue_id, $usr_id, History::getTypeID('notification_added'), "Notification list entry ('{$email}') added by " . User::getFullName($usr_id));
         return 1;
     }
 }
Esempio n. 18
0
 /**
  * Method used to generate an SQL query to be used in debugging the reminder
  * conditions.
  *
  * @access  public
  * @param   integer $rem_id The reminder ID
  * @param   integer $rma_id The reminder action ID
  * @return  string The SQL query
  */
 function getSQLQuery($rem_id, $rma_id)
 {
     $reminder = Reminder::getDetails($rem_id);
     $conditions = Reminder_Condition::getList($rma_id);
     $stmt = "SELECT\n                    iss_id\n                 FROM\n                    " . APP_TABLE_PREFIX . "issue";
     $stmt .= Reminder::getWhereClause($reminder, $conditions);
     // can't rely on the mysql server's timezone setting, so let's use gmt dates throughout
     $stmt = str_replace('UNIX_TIMESTAMP()', "UNIX_TIMESTAMP('" . Date_API::getCurrentDateGMT() . "')", $stmt);
     return $stmt;
 }
Esempio n. 19
0
 /**
  * Returns the SQL used to calculate the difference of 2 dates, not counting weekends.
  * This thing is truly a work of art, the type of art that throws lemon juice in your eye and then laughs.
  * If $end_date_field is null, the current date is used instead.
  *
  * @access  public
  * @param   string $start_date_field The name of the field the first date is.
  * @param   string $end_date_field The name of the field where the second date is.
  * @return  string The SQL used to compare the 2 dates.
  */
 function getNoWeekendDateDiffSQL($start_date_field, $end_date_field = false)
 {
     if ($end_date_field == false) {
         $end_date_field = "'" . Date_API::getCurrentDateGMT() . "'";
     }
     // this is crazy, but it does work. Anyone with a better solution email bryan@mysql.com
     $sql = "((UNIX_TIMESTAMP({$end_date_field}) - UNIX_TIMESTAMP({$start_date_field})) - (CASE\n            WHEN DAYOFWEEK({$start_date_field}) = 1 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))-1)/7) * 86400 * 2)\n            WHEN DAYOFWEEK({$start_date_field}) = 2 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field})))/7) * 86400 *2)\n            WHEN DAYOFWEEK({$start_date_field}) = 3 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))+1)/7) * 86400 *2)\n            WHEN DAYOFWEEK({$start_date_field}) = 4 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))+2)/7) * 86400 *2)\n            WHEN DAYOFWEEK({$start_date_field}) = 5 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))+3)/7) * 86400 *2)\n            WHEN DAYOFWEEK({$start_date_field}) = 6 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))+4)/7) * 86400 *2)\n            WHEN DAYOFWEEK({$start_date_field}) = 7 THEN (floor(((TO_DAYS({$end_date_field}) - TO_DAYS({$start_date_field}))-2)/7) * 86400 *2)\n        END) - (CASE\n            WHEN DAYOFWEEK({$start_date_field}) = 7 THEN (86400 + (86400 - time_to_sec({$start_date_field})))\n            WHEN DAYOFWEEK({$start_date_field}) = 1 THEN (86400 - time_to_sec({$start_date_field}))\n            ELSE 0\n        END) - CASE\n            WHEN DAYOFWEEK({$end_date_field}) = 7 THEN time_to_sec({$end_date_field})\n            WHEN DAYOFWEEK({$end_date_field}) = 1 THEN (86400 + time_to_sec({$end_date_field}))\n            ELSE 0\n        END)";
     return str_replace("\n", " ", $sql);
 }
Esempio n. 20
0
function createWhereClause($date_field, $user_field = false)
{
    global $start_date, $end_date;
    $sql = '';
    if ($_REQUEST['report_type'] == 'recent') {
        $sql .= "{$date_field} >= DATE_SUB('" . Date_API::getCurrentDateGMT() . "', INTERVAL " . Misc::escapeInteger($_REQUEST['amount']) . " " . Misc::escapeString($_REQUEST['unit']) . ")";
    } else {
        $sql .= "{$date_field} BETWEEN '{$start_date}' AND '{$end_date}'";
    }
    if ($user_field != false && !empty($_REQUEST['developer'])) {
        $sql .= " AND {$user_field} = " . Misc::escapeString($_REQUEST['developer']);
    }
    $sql .= " ORDER BY {$date_field} " . Misc::escapeString($_REQUEST['sort_order']);
    return $sql;
}
$stmt = "SELECT MAX(usr_id)+1 FROM eventum_user";
$new_usr_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
if (PEAR::isError($new_usr_id)) {
    echo "ERROR:<br /><br />";
    var_dump($new_usr_iod);
    exit(1);
}
$stmt = "UPDATE eventum_user SET usr_id = {$new_usr_id} WHERE usr_id = 1";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
    echo "ERROR:<br /><br />";
    var_dump($res);
    exit(1);
}
$fixes = array("UPDATE eventum_custom_filter SET cst_usr_id = {$new_usr_id} WHERE cst_usr_id = 1", "UPDATE eventum_issue SET iss_usr_id = {$new_usr_id} WHERE iss_usr_id = 1", "UPDATE eventum_issue_attachment SET iat_usr_id = {$new_usr_id} WHERE iat_usr_id = 1", "UPDATE eventum_issue_requirement SET isr_usr_id = {$new_usr_id} WHERE isr_usr_id = 1", "UPDATE eventum_issue_user SET isu_usr_id = {$new_usr_id} WHERE isu_usr_id = 1", "UPDATE eventum_note SET not_usr_id = {$new_usr_id} WHERE not_usr_id = 1", "UPDATE eventum_project SET prj_lead_usr_id = {$new_usr_id} WHERE prj_lead_usr_id = 1", "UPDATE eventum_project_user SET pru_usr_id = {$new_usr_id} WHERE pru_usr_id = 1", "UPDATE eventum_subscription SET sub_usr_id = {$new_usr_id} WHERE sub_usr_id = 1", "UPDATE eventum_time_tracking SET ttr_usr_id = {$new_usr_id} WHERE ttr_usr_id = 1", "UPDATE eventum_phone_support SET phs_usr_id = {$new_usr_id} WHERE phs_usr_id = 1", "UPDATE eventum_reminder_action_list SET ral_usr_id = {$new_usr_id} WHERE ral_usr_id = 1", "UPDATE eventum_news SET nws_usr_id = {$new_usr_id} WHERE nws_usr_id = 1", "UPDATE eventum_round_robin_user SET rru_usr_id = {$new_usr_id} WHERE rru_usr_id = 1", "UPDATE eventum_email_draft SET emd_usr_id = {$new_usr_id} WHERE emd_usr_id = 1");
foreach ($fixes as $stmt) {
    $res = $GLOBALS["db_api"]->dbh->query($stmt);
    if (PEAR::isError($res)) {
        echo "ERROR:<br /><br />";
        var_dump($res);
        exit(1);
    }
}
// add the system account as user id == 1
$stmt = "INSERT INTO\n            eventum_user\n         (\n            usr_id,\n            usr_created_date,\n            usr_password,\n            usr_full_name,\n            usr_email,\n            usr_role,\n            usr_preferences\n         ) VALUES (\n            1,\n            '" . Date_API::getCurrentDateGMT() . "',\n            '14589714398751513457adf349173434',\n            'system',\n            '*****@*****.**',\n            5,\n            ''\n         )";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
    echo "ERROR:<br /><br />";
    var_dump($res);
    exit(1);
}
Esempio n. 22
0
 /**
  * Adds a quick note for the specified customer.
  * 
  * @access  public
  * @param   integer $prj_id The project ID
  * @param   integer $customer_id The id of the customer.
  * @param   string  $note The note to add.
  */
 function insertNote($prj_id, $customer_id, $note)
 {
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note\n                 (\n                    cno_prj_id,\n                    cno_customer_id,\n                    cno_created_date,\n                    cno_updated_date,\n                    cno_note\n                 ) VALUES (\n                    " . Misc::escapeInteger($prj_id) . ",\n                    " . Misc::escapeInteger($customer_id) . ",\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($note) . "'\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 {
         return 1;
     }
 }
Esempio n. 23
0
// | Authors: Bryan Alsdorf <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
//
include_once "../../config.inc.php";
include_once APP_INC_PATH . "db_access.php";
include_once APP_INC_PATH . "class.customer.php";
include_once APP_INC_PATH . "class.user.php";
// creates user accounts for all the customers
$prj_id = 1;
$customers = Customer::getAssocList($prj_id);
foreach ($customers as $customer_id => $customer_name) {
    echo "Customer: {$customer_name}<br />\n";
    $details = Customer::getDetails($prj_id, $customer_id);
    foreach ($details['contacts'] as $contact) {
        echo "Contact: " . $contact['first_name'] . " " . $contact['last_name'] . " (" . $contact['email'] . ")<br />\n";
        $contact_id = User::getUserIDByContactID($contact['contact_id']);
        if (empty($contact_id)) {
            $sql = "INSERT INTO\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user\n                    SET\n                        usr_created_date = '" . Date_API::getCurrentDateGMT() . "',\n                        usr_full_name = '" . Misc::escapeString($contact['first_name'] . " " . $contact['last_name']) . "',\n                        usr_email = '" . $contact['email'] . "',\n                        usr_customer_id = " . $customer_id . ",\n                        usr_customer_contact_id = " . $contact['contact_id'] . ",\n                        usr_preferences = '" . Misc::escapeString(Prefs::getDefaults(array($prj_id))) . "'";
            $res = $GLOBALS["db_api"]->dbh->query($sql);
            if (PEAR::isError($res)) {
                echo "Error inserting user<br /><pre>";
                print_r($res);
                echo "</pre>";
            }
            $new_usr_id = $GLOBALS['db_api']->get_last_insert_id();
            Project::associateUser($prj_id, $new_usr_id, User::getRoleID("Customer"));
        }
    }
    echo "<hr />";
}
Esempio n. 24
0
 /**
  * Method used to add a FAQ entry to the system.
  *
  * @access  public
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     if (Validation::isWhitespace($HTTP_POST_VARS["message"])) {
         return -3;
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "faq\n                 (\n                    faq_prj_id,\n                    faq_usr_id,\n                    faq_created_date,\n                    faq_title,\n                    faq_message,\n                    faq_rank\n                 ) VALUES (\n                    " . $HTTP_POST_VARS['project'] . ",\n                    " . Auth::getUserID() . ",\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["message"]) . "',\n                    " . $HTTP_POST_VARS['rank'] . "\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_faq_id = $GLOBALS["db_api"]->get_last_insert_id();
         if (Customer::doesBackendUseSupportLevels(Misc::escapeInteger($HTTP_POST_VARS['project']))) {
             // now populate the faq-support level mapping table
             foreach ($HTTP_POST_VARS['support_levels'] as $support_level_id) {
                 FAQ::addSupportLevelAssociation($new_faq_id, $support_level_id);
             }
         }
         return 1;
     }
 }
Esempio n. 25
0
 /**
  * Routes an email to the correct issue.
  *
  * @param   string $full_message The full email message, including headers
  * @param   integer $email_account_id The ID of the email account this email should be routed too. If empty this method will try to figure it out
  */
 function route_emails($full_message, $email_account_id = 0)
 {
     global $HTTP_POST_VARS;
     // save the full message for logging purposes
     Support::saveRoutedEmail($full_message);
     if (preg_match("/^(boundary=).*/m", $full_message)) {
         $pattern = "/(Content-Type: multipart\\/)(.+); ?\r?\n(boundary=)(.*)\$/im";
         $replacement = '$1$2; $3$4';
         $full_message = preg_replace($pattern, $replacement, $full_message);
     }
     // associate routed emails to the internal system account
     $sys_account = User::getNameEmail(APP_SYSTEM_USER_ID);
     $associated_user = $sys_account['usr_email'];
     // need some validation here
     if (empty($full_message)) {
         return array(66, "Error: The email message was empty.\n");
     }
     if (empty($associated_user)) {
         return array(78, "Error: The associated user for the email routing interface needs to be set.\n");
     }
     //
     // DON'T EDIT ANYTHING BELOW THIS LINE
     //
     // remove the reply-to: header
     if (preg_match("/^(reply-to:).*/im", $full_message)) {
         $full_message = preg_replace("/^(reply-to:).*\n/im", '', $full_message, 1);
     }
     // check for magic cookie
     if (Mail_API::hasMagicCookie($full_message)) {
         // strip the magic cookie
         $full_message = Mail_API::stripMagicCookie($full_message);
         $has_magic_cookie = true;
     } else {
         $has_magic_cookie = false;
     }
     Auth::createFakeCookie(APP_SYSTEM_USER_ID);
     // check if the email routing interface is even supposed to be enabled
     $setup = Setup::load();
     if ($setup['email_routing']['status'] != 'enabled') {
         return array(78, "Error: The email routing interface is disabled.\n");
     }
     $prefix = $setup['email_routing']['address_prefix'];
     // escape plus signs so '*****@*****.**' becomes a valid routing address
     $prefix = str_replace('+', '\\+', $prefix);
     $mail_domain = quotemeta($setup['email_routing']['address_host']);
     $mail_domain_alias = quotemeta(@$setup['email_routing']['host_alias']);
     if (!empty($mail_domain_alias)) {
         $mail_domain = "(?:" . $mail_domain . "|" . $mail_domain_alias . ")";
     }
     if (empty($prefix)) {
         return array(78, "Error: Please configure the email address prefix.\n");
     }
     if (empty($mail_domain)) {
         return array(78, "Error: Please configure the email address domain.\n");
     }
     $structure = Mime_Helper::decode($full_message, true, true);
     // find which issue ID this email refers to
     @preg_match("/{$prefix}(\\d*)@{$mail_domain}/i", $structure->headers['to'], $matches);
     @($issue_id = $matches[1]);
     // validation is always a good idea
     if (empty($issue_id)) {
         // we need to try the Cc header as well
         @preg_match("/{$prefix}(\\d*)@{$mail_domain}/i", $structure->headers['cc'], $matches);
         if (!empty($matches[1])) {
             $issue_id = $matches[1];
         } else {
             return array(65, "Error: The routed email had no associated Eventum issue ID or had an invalid recipient address.\n");
         }
     }
     if (empty($email_account_id)) {
         $issue_prj_id = Issue::getProjectID($issue_id);
         if (empty($issue_prj_id)) {
             return array(65, "Error: The routed email had no associated Eventum issue ID or had an invalid recipient address.\n");
         }
         $email_account_id = Email_Account::getEmailAccount($issue_prj_id);
     }
     if (empty($email_account_id)) {
         return array(78, "Error: Please provide the email account ID.\n");
     }
     $body = Mime_Helper::getMessageBody($structure);
     // hack for clients that set more then one from header
     if (is_array($structure->headers['from'])) {
         $structure->headers['from'] = $structure->headers['from'][0];
     }
     // associate the email to the issue
     $parts = array();
     Mime_Helper::parse_output($structure, $parts);
     // get the sender's email address
     $sender_email = strtolower(Mail_API::getEmailAddress($structure->headers['from']));
     // strip out the warning message sent to staff users
     if ($setup['email_routing']['status'] == 'enabled' && $setup['email_routing']['warning']['status'] == 'enabled') {
         $full_message = Mail_API::stripWarningMessage($full_message);
         $body = Mail_API::stripWarningMessage($body);
     }
     $prj_id = Issue::getProjectID($issue_id);
     Auth::createFakeCookie(APP_SYSTEM_USER_ID, $prj_id);
     $staff_emails = Project::getUserEmailAssocList($prj_id, 'active', User::getRoleID('Customer'));
     $staff_emails = array_map('strtolower', $staff_emails);
     // only allow staff users to use the magic cookie
     if (!in_array($sender_email, array_values($staff_emails))) {
         $has_magic_cookie = false;
     }
     if (Mime_Helper::hasAttachments($full_message)) {
         $has_attachments = 1;
     } else {
         $has_attachments = 0;
     }
     // remove certain CC addresses
     if (!empty($structure->headers['cc']) && @$setup['smtp']['save_outgoing_email'] == 'yes') {
         $ccs = explode(",", @$structure->headers['cc']);
         for ($i = 0; $i < count($ccs); $i++) {
             if (Mail_API::getEmailAddress($ccs[$i]) == $setup['smtp']['save_address']) {
                 unset($ccs[$i]);
             }
         }
         @($structure->headers['cc'] = join(', ', $ccs));
     }
     // Remove excess Re's
     @($structure->headers['subject'] = Mail_API::removeExcessRe(@$structure->headers['subject'], true));
     $t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_API::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$full_message, 'has_attachment' => $has_attachments, 'headers' => @$structure->headers);
     // automatically associate this incoming email with a customer
     if (Customer::hasCustomerIntegration($prj_id)) {
         if (!empty($structure->headers['from'])) {
             list($customer_id, ) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
             if (!empty($customer_id)) {
                 $t['customer_id'] = $customer_id;
             }
         }
     }
     if (empty($t['customer_id'])) {
         $t['customer_id'] = "NULL";
     }
     if (!$has_magic_cookie && Support::blockEmailIfNeeded($t)) {
         return true;
     }
     // re-write Threading headers if needed
     list($t['full_email'], $t['headers']) = Mail_API::rewriteThreadingHeaders($t['issue_id'], $t['full_email'], $t['headers'], "email");
     $res = Support::insertEmail($t, $structure, $sup_id);
     if ($res != -1) {
         Support::extractAttachments($issue_id, $full_message);
         // notifications about new emails are always external
         $internal_only = false;
         $assignee_only = false;
         // special case when emails are bounced back, so we don't want a notification to customers about those
         if (Notification::isBounceMessage($sender_email)) {
             // broadcast this email only to the assignees for this issue
             $internal_only = true;
             $assignee_only = true;
         }
         Notification::notifyNewEmail(Auth::getUserID(), $issue_id, $t, $internal_only, $assignee_only, '', $sup_id);
         // try to get usr_id of sender, if not, use system account
         $usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($structure->headers['from']));
         if (!$usr_id) {
             $usr_id = APP_SYSTEM_USER_ID;
         }
         // mark this issue as updated
         if (!empty($t['customer_id']) && $t['customer_id'] != 'NULL') {
             Issue::markAsUpdated($issue_id, 'customer action');
         } else {
             if (!empty($usr_id) && User::getRoleByUser($usr_id, $prj_id) > User::getRoleID('Customer')) {
                 Issue::markAsUpdated($issue_id, 'staff response');
             } else {
                 Issue::markAsUpdated($issue_id, 'user response');
             }
         }
         // log routed email
         History::add($issue_id, $usr_id, History::getTypeID('email_routed'), "Email routed from " . $structure->headers['from']);
     }
     return true;
 }