/**
  * Method used to add a new canned email response to the system.
  *
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     $stmt = 'INSERT INTO
                 {{%email_response}}
              (
                 ere_title,
                 ere_response_body
              ) VALUES (
                 ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array($_POST['title'], $_POST['response_body']));
     } catch (DbException $e) {
         return -1;
     }
     $new_response_id = DB_Helper::get_last_insert_id();
     // now populate the project-news mapping table
     foreach ($_POST['projects'] as $prj_id) {
         self::addProjectAssociation($new_response_id, $prj_id);
     }
     return 1;
 }
Exemple #2
0
 /**
  * Method used to save the draft response in the database for
  * further use.
  *
  * @param   integer $issue_id The issue 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
  * @param   string $unknown_user The sender of the draft, if not a real user
  * @param   boolean $add_history_entry Whether to add a history entry automatically or not
  * @return  integer 1 if the update worked, -1 otherwise
  */
 public static function saveEmail($issue_id, $to, $cc, $subject, $message, $parent_id = null, $unknown_user = null, $add_history_entry = true)
 {
     if (!$parent_id) {
         $parent_id = null;
     }
     // if unknown_user is not empty, set the usr_id to be the system user.
     if (!empty($unknown_user)) {
         $usr_id = APP_SYSTEM_USER_ID;
     } else {
         $usr_id = Auth::getUserID();
     }
     $stmt = 'INSERT INTO
                 {{%email_draft}}
              (
                 emd_updated_date,
                 emd_usr_id,
                 emd_iss_id,
                 emd_sup_id,
                 emd_subject,
                 emd_body';
     if ($unknown_user) {
         $stmt .= ', emd_unknown_user';
     }
     $stmt .= ') VALUES (
                 ?, ?, ?, ?, ?, ?
             ';
     $params = array(Date_Helper::getCurrentDateGMT(), $usr_id, $issue_id, $parent_id, $subject, $message);
     if ($unknown_user) {
         $stmt .= ', ?';
         $params[] = $unknown_user;
     }
     $stmt .= ')';
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_emd_id = DB_Helper::get_last_insert_id();
     self::addEmailRecipient($new_emd_id, $to, false);
     $cc = str_replace(',', ';', $cc);
     $ccs = explode(';', $cc);
     foreach ($ccs as $cc) {
         self::addEmailRecipient($new_emd_id, $cc, true);
     }
     Issue::markAsUpdated($issue_id, 'draft saved');
     if ($add_history_entry) {
         History::add($issue_id, $usr_id, 'draft_added', 'Email message saved as a draft by {user}', array('user' => User::getFullName($usr_id)));
     }
     return 1;
 }
Exemple #3
0
 /**
  * Inserts a new group into the database
  *
  * @return integer 1 if successful, -1 or -2 otherwise
  */
 public static function insert()
 {
     $stmt = 'INSERT INTO
                 {{%group}}
              (
                 grp_name,
                 grp_description,
                 grp_manager_usr_id
              ) VALUES (
                 ?, ?, ?
              )';
     $params = array($_POST['group_name'], $_POST['description'], $_POST['manager']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $grp_id = DB_Helper::get_last_insert_id();
     self::setProjects($grp_id, $_POST['projects']);
     foreach ($_POST['users'] as $usr_id) {
         User::setGroupID($usr_id, $grp_id);
     }
     return 1;
 }
Exemple #4
0
 /**
  * Insert issue to database.
  *
  * @param   integer $prj_id The project ID
  * @param   array $data of issue to be inserted
  * @return  integer The new issue ID
  */
 private function insertIssue($prj_id, $data)
 {
     // if there is no reporter set, use the system user
     if (empty($data['reporter'])) {
         $data['reporter'] = APP_SYSTEM_USER_ID;
     }
     if (!isset($data['estimated_dev_time']) || $data['estimated_dev_time'] == '') {
         $data['estimated_dev_time'] = 0;
     }
     if (!isset($data['private'])) {
         $data['private'] = 0;
     }
     // add new issue
     $params = array('iss_usr_id' => $data['reporter'], 'iss_created_date' => Date_Helper::getCurrentDateGMT(), 'iss_last_public_action_date' => Date_Helper::getCurrentDateGMT(), 'iss_last_public_action_type' => 'created', 'iss_summary' => $data['summary'], 'iss_description' => $data['description'], 'iss_dev_time' => $data['estimated_dev_time'], 'iss_root_message_id' => $data['msg_id'], 'iss_prj_id' => $prj_id);
     if (!empty($data['group'])) {
         $params['iss_grp_id'] = $data['group'];
     }
     if (!empty($data['category'])) {
         $params['iss_prc_id'] = $data['category'];
     }
     if (!empty($data['release'])) {
         $params['iss_pre_id'] = $data['release'];
     }
     if (!empty($data['priority'])) {
         $params['iss_pri_id'] = $data['priority'];
     }
     if (!empty($data['severity'])) {
         $params['iss_sev_id'] = $data['severity'];
     }
     if (!empty($data['expected_resolution_date'])) {
         $params['iss_expected_resolution_date'] = $data['expected_resolution_date'];
     }
     $initial_status = Project::getInitialStatus($prj_id);
     if (!empty($initial_status)) {
         $params['iss_sta_id'] = $initial_status;
     }
     if (CRM::hasCustomerIntegration($prj_id)) {
         $params['iss_customer_id'] = $data['customer'];
         if (!empty($data['contract'])) {
             $params['iss_customer_contract_id'] = $data['contract'];
         }
         $params['iss_customer_contact_id'] = $data['contact'];
         $params['iss_contact_person_lname'] = $data['contact_person_lname'];
         $params['iss_contact_person_fname'] = $data['contact_person_fname'];
         $params['iss_contact_email'] = $data['contact_email'];
         $params['iss_contact_phone'] = $data['contact_phone'];
         $params['iss_contact_timezone'] = $data['contact_timezone'];
     }
     if (!empty($data['contact'])) {
         $params['iss_private'] = $data['private'];
     }
     $stmt = 'INSERT INTO {{%issue}} SET ' . DB_Helper::buildSet($params);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $issue_id = DB_Helper::get_last_insert_id();
     return $issue_id;
 }
 /**
  * Method used to add a new custom field to the system.
  *
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 public static function insert()
 {
     if (empty($_POST['report_form'])) {
         $_POST['report_form'] = 0;
     }
     if (empty($_POST['report_form_required'])) {
         $_POST['report_form_required'] = 0;
     }
     if (empty($_POST['anon_form'])) {
         $_POST['anon_form'] = 0;
     }
     if (empty($_POST['anon_form_required'])) {
         $_POST['anon_form_required'] = 0;
     }
     if (empty($_POST['close_form'])) {
         $_POST['close_form'] = 0;
     }
     if (empty($_POST['close_form_required'])) {
         $_POST['close_form_required'] = 0;
     }
     if (empty($_POST['list_display'])) {
         $_POST['list_display'] = 0;
     }
     if (empty($_POST['min_role'])) {
         $_POST['min_role'] = 1;
     }
     if (!isset($_POST['rank'])) {
         $_POST['rank'] = self::getMaxRank() + 1;
     }
     $stmt = 'INSERT INTO
                 {{%custom_field}}
              (
                 fld_title,
                 fld_description,
                 fld_type,
                 fld_report_form,
                 fld_report_form_required,
                 fld_anonymous_form,
                 fld_anonymous_form_required,
                 fld_close_form,
                 fld_close_form_required,
                 fld_list_display,
                 fld_min_role,
                 fld_rank,
                 fld_backend
              ) VALUES (
                  ?, ?, ?, ?, ?,
                  ?, ?, ?, ?, ?,
                  ?, ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array($_POST['title'], $_POST['description'], $_POST['field_type'], $_POST['report_form'], $_POST['report_form_required'], $_POST['anon_form'], $_POST['anon_form_required'], $_POST['close_form'], $_POST['close_form_required'], $_POST['list_display'], $_POST['min_role'], $_POST['rank'], @$_POST['custom_field_backend']));
     } catch (DbException $e) {
         return -1;
     }
     $new_id = DB_Helper::get_last_insert_id();
     if ($_POST['field_type'] == 'combo' || $_POST['field_type'] == 'multiple' || $_POST['field_type'] == 'checkbox') {
         foreach ($_POST['field_options'] as $option_value) {
             $params = self::parseParameters($option_value);
             self::addOptions($new_id, $params['value']);
         }
     }
     // add the project associations!
     foreach ($_POST['projects'] as $prj_id) {
         self::associateProject($prj_id, $new_id);
     }
     return 1;
 }
Exemple #6
0
 /**
  * Method used to add a FAQ entry to the system.
  *
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     if (Validation::isWhitespace($_POST['message'])) {
         return -3;
     }
     $stmt = 'INSERT INTO
                 {{%faq}}
              (
                 faq_prj_id,
                 faq_usr_id,
                 faq_created_date,
                 faq_title,
                 faq_message,
                 faq_rank
              ) VALUES (
                 ?, ?, ?, ?, ?, ?
              )';
     $params = array($_POST['project'], Auth::getUserID(), Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['message'], $_POST['rank']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_faq_id = DB_Helper::get_last_insert_id();
     if (isset($_POST['support_levels']) && count($_POST['support_levels']) > 0) {
         // now populate the faq-support level mapping table
         foreach ($_POST['support_levels'] as $support_level_id) {
             self::addSupportLevelAssociation($new_faq_id, $support_level_id);
         }
     }
     return 1;
 }
Exemple #7
0
 /**
  * Method used to add a new user to the system.
  *
  * @param   array $user The array of user information
  * @return  integer 1 if the update worked, -1 otherwise
  */
 public static function insert($user)
 {
     $projects = array();
     foreach ($user['role'] as $prj_id => $role) {
         if ($role < 1) {
             continue;
         }
         $projects[] = $prj_id;
     }
     $params = array(isset($user['customer_id']) ? $user['customer_id'] : null, isset($user['contact_id']) ? $user['contact_id'] : null, Date_Helper::getCurrentDateGMT(), Auth::hashPassword($user['password']), $user['full_name'], $user['email'], !empty($user['grp_id']) ? $user['grp_id'] : null, $user['external_id'], isset($user['par_code']) ? $user['par_code'] : null);
     $stmt = 'INSERT INTO
                 {{%user}}
              (
                 usr_customer_id,
                 usr_customer_contact_id,
                 usr_created_date,
                 usr_password,
                 usr_full_name,
                 usr_email,
                 usr_grp_id,
                 usr_external_id,
                 usr_par_code
              ) VALUES (
                 ?,
                 ?,
                 ?,
                 ?,
                 ?,
                 ?,
                 ?,
                 ?,
                 ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_usr_id = DB_Helper::get_last_insert_id();
     // add the project associations!
     $projects = array();
     foreach ($user['role'] as $prj_id => $role) {
         if ($role < 1) {
             continue;
         }
         Project::associateUser($prj_id, $new_usr_id, $role);
         $projects[] = $prj_id;
     }
     Prefs::set($new_usr_id, Prefs::getDefaults($projects));
     // send email to user
     Notification::notifyNewUser($new_usr_id, $user['password']);
     return $new_usr_id;
 }
Exemple #8
0
 /**
  * Method used to add a new project to the system.
  *
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     $stmt = 'INSERT INTO
                 {{%project}}
              (
                 prj_created_date,
                 prj_title,
                 prj_status,
                 prj_lead_usr_id,
                 prj_initial_sta_id,
                 prj_outgoing_sender_name,
                 prj_outgoing_sender_email,
                 prj_mail_aliases,
                 prj_remote_invocation,
                 prj_customer_backend,
                 prj_workflow_backend
              ) VALUES (
                  ?, ?, ?, ?, ?,
                  ?, ?, ?, ?, ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array(Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['status'], $_POST['lead_usr_id'], $_POST['initial_status'], $_POST['outgoing_sender_name'], $_POST['outgoing_sender_email'], $_POST['mail_aliases'], $_POST['remote_invocation'], $_POST['customer_backend'], $_POST['workflow_backend']));
     } catch (DbException $e) {
         return -1;
     }
     $new_prj_id = DB_Helper::get_last_insert_id();
     foreach ($_POST['users'] as $user) {
         if ($user == $_POST['lead_usr_id']) {
             $role_id = User::getRoleID('Manager');
         } else {
             $role_id = User::getRoleID('Standard User');
         }
         self::associateUser($new_prj_id, $user, $role_id);
     }
     foreach ($_POST['statuses'] as $sta_id) {
         Status::addProjectAssociation($sta_id, $new_prj_id);
     }
     Display_Column::setupNewProject($new_prj_id);
     // insert default timetracking categories
     Time_Tracking::addProjectDefaults($new_prj_id);
     return 1;
 }
Exemple #9
0
 /**
  * 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;
 }
 /**
  * Inserts a new link filter into the database.
  *
  * @return integer 1 if insert was successful, -1 otherwise
  */
 public static function insert()
 {
     $sql = 'INSERT INTO
                 {{%link_filter}}
             (
                 lfi_pattern,
                 lfi_replacement,
                 lfi_usr_role,
                 lfi_description
             ) VALUES (
                 ?, ?, ?, ?
             )';
     $params = array($_REQUEST['pattern'], $_REQUEST['replacement'], $_REQUEST['usr_role'], $_REQUEST['description']);
     try {
         DB_Helper::getInstance()->query($sql, $params);
     } catch (DbException $e) {
         return -1;
     }
     $lfi_id = DB_Helper::get_last_insert_id();
     foreach ($_REQUEST['projects'] as $prj_id) {
         $sql = 'INSERT INTO
                     {{%project_link_filter}}
                 (
                     plf_prj_id,
                     plf_lfi_id
                 ) VALUES (
                     ?, ?
                 )';
         try {
             DB_Helper::getInstance()->query($sql, array($prj_id, $lfi_id));
         } catch (DbException $e) {
             return -1;
         }
     }
     return 1;
 }
 /**
  * Method used to create a new reminder action.
  *
  * @return  integer 1 if the insert worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     $stmt = 'INSERT INTO
                 {{%reminder_action}}
              (
                 rma_rem_id,
                 rma_rmt_id,
                 rma_created_date,
                 rma_title,
                 rma_rank,
                 rma_alert_irc,
                 rma_alert_group_leader,
                 rma_boilerplate
              ) VALUES (
                 ?, ?, ?, ?, ?,
                 ?, ?, ?
              )';
     $params = array($_POST['rem_id'], $_POST['type'], Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['rank'], $_POST['alert_irc'], $_POST['alert_group_leader'], $_POST['boilerplate']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_rma_id = DB_Helper::get_last_insert_id();
     // add the user list, if appropriate
     if (self::isUserList($_POST['type'])) {
         self::associateUserList($new_rma_id, $_POST['user_list']);
     }
     return 1;
 }
$prj_id = 1;
// FIXME: Customer::getAssocList does not exist
$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
                        {{%user}}
                    SET
                        usr_created_date = ?,
                        usr_full_name = ?,
                        usr_email = ?,
                        usr_customer_id = ?,
                        usr_customer_contact_id = ?,
                        usr_preferences = ?';
            $params = array(Date_Helper::getCurrentDateGMT(), $contact['first_name'] . ' ' . $contact['last_name'], $contact['email'], $customer_id, $contact['contact_id'], Prefs::getDefaults(array($prj_id)));
            try {
                DB_Helper::getInstance()->query($sql, $params);
            } catch (DbException $e) {
                echo 'Error inserting user<br />';
            }
            $new_usr_id = DB_Helper::get_last_insert_id();
            Project::associateUser($prj_id, $new_usr_id, User::ROLE_CUSTOMER);
        }
    }
    echo '<hr />';
}
 /**
  * Method used to add an attachment to the database.
  *
  * @param   integer $issue_id The issue ID
  * @param   integer $usr_id The user ID
  * @param   string $description The description for this new attachment
  * @param   boolean $internal_only Whether this attachment is supposed to be internal only or not
  * @param   string $unknown_user The email of the user who originally sent this email, who doesn't have an account.
  * @param   integer $associated_note_id The note ID that these attachments should be associated with
  * @return  integer The new attachment ID
  */
 public static function add($issue_id, $usr_id, $description, $internal_only = false, $unknown_user = null, $associated_note_id = null)
 {
     if ($internal_only) {
         $attachment_status = 'internal';
     } else {
         $attachment_status = 'public';
     }
     $params = array('iat_iss_id' => $issue_id, 'iat_usr_id' => $usr_id, 'iat_created_date' => Date_Helper::getCurrentDateGMT(), 'iat_description' => $description, 'iat_status' => $attachment_status);
     if ($unknown_user) {
         $params['iat_unknown_user'] = $unknown_user;
     }
     if ($associated_note_id) {
         $params['iat_not_id'] = $associated_note_id;
     }
     $stmt = 'INSERT INTO {{%issue_attachment}} SET ' . DB_Helper::buildSet($params);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return false;
     }
     return DB_Helper::get_last_insert_id();
 }
 /**
  * Method used to add a new subscriber manually, by using the
  * email notification interface.
  *
  * @param   integer $usr_id The user ID of the person performing this change
  * @param   integer $issue_id The issue ID
  * @param   string $email The email address to subscribe
  * @param   array $actions The actions to subcribe to
  * @return  integer 1 if the update worked, -1 otherwise
  */
 public static function subscribeEmail($usr_id, $issue_id, $email, $actions)
 {
     $email = Mail_Helper::getEmailAddress($email);
     if (!is_string($email)) {
         return -1;
     }
     $email = strtolower($email);
     // first check if this is an actual user or just an email address
     $sub_usr_id = User::getUserIDByEmail($email, true);
     if (!empty($sub_usr_id)) {
         return self::subscribeUser($usr_id, $issue_id, $sub_usr_id, $actions);
     }
     $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
                     COUNT(sub_id)
                  FROM
                     {{%subscription}}
                  WHERE
                     sub_iss_id=? AND
                     sub_email=?';
         $total = DB_Helper::getInstance()->getOne($stmt, array($issue_id, $email));
         if ($total > 0) {
             return -1;
         }
     }
     $stmt = "INSERT INTO\n                    {{%subscription}}\n                 (\n                    sub_iss_id,\n                    sub_usr_id,\n                    sub_created_date,\n                    sub_level,\n                    sub_email\n                 ) VALUES (\n                    ?,\n                    0,\n                    ?,\n                    'issue',\n                    ?\n                 )";
     try {
         DB_Helper::getInstance()->query($stmt, array($issue_id, Date_Helper::getCurrentDateGMT(), $email));
     } catch (DbException $e) {
         return -1;
     }
     $sub_id = DB_Helper::get_last_insert_id();
     foreach ($actions as $sbt_type) {
         self::addType($sub_id, $sbt_type);
     }
     // need to mark the issue as updated
     Issue::markAsUpdated($issue_id);
     // need to save a history entry for this
     // FIXME: XSS possible as $email is not escaped for html?
     History::add($issue_id, $usr_id, 'notification_added', "Notification list entry ('{subscriber}') added by {user}", array('subscriber' => $email, 'user' => User::getFullName($usr_id)));
     return 1;
 }
 /**
  * Method used to add a phone support entry using the user
  * interface form available in the application.
  *
  * @return  integer 1 if the insert worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     $usr_id = Auth::getUserID();
     $iss_id = (int) $_POST['issue_id'];
     $date = $_POST['date'];
     // format the date from the form
     $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $date['Year'], $date['Month'], $date['Day'], $date['Hour'], $date['Minute'], 0);
     // convert the date to GMT timezone
     $created_date = Date_Helper::convertDateGMT($created_date . ' ' . Date_Helper::getPreferredTimezone());
     $stmt = 'INSERT INTO
                 {{%phone_support}}
              (
                 phs_iss_id,
                 phs_usr_id,
                 phs_phc_id,
                 phs_created_date,
                 phs_type,
                 phs_phone_number,
                 phs_description,
                 phs_phone_type,
                 phs_call_from_lname,
                 phs_call_from_fname,
                 phs_call_to_lname,
                 phs_call_to_fname
              ) VALUES (
                 ?, ?, ?, ?, ?,
                 ?, ?, ?, ?, ?,
                 ?, ?
              )';
     $params = array($iss_id, $usr_id, $_POST['phone_category'], $created_date, $_POST['type'], $_POST['phone_number'], $_POST['description'], $_POST['phone_type'], $_POST['from_lname'], $_POST['from_fname'], $_POST['to_lname'], $_POST['to_fname']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     // enter the time tracking entry about this phone support entry
     $phs_id = DB_Helper::get_last_insert_id();
     $prj_id = Auth::getCurrentProject();
     $ttc_id = Time_Tracking::getCategoryId($prj_id, 'Telephone Discussion');
     $time_spent = (int) $_POST['call_length'];
     $summary = ev_gettext('Time entry inserted from phone call.');
     Time_Tracking::addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary);
     $stmt = 'SELECT
                 max(ttr_id)
              FROM
                 {{%time_tracking}}
              WHERE
                 ttr_iss_id = ? AND
                 ttr_usr_id = ?';
     $ttr_id = DB_Helper::getInstance()->getOne($stmt, array($iss_id, $usr_id));
     Issue::markAsUpdated($iss_id, 'phone call');
     // need to save a history entry for this
     History::add($iss_id, $usr_id, 'phone_entry_added', 'Phone Support entry submitted by {user}', array('user' => User::getFullName($usr_id)));
     // XXX: send notifications for the issue being updated (new notification type phone_support?)
     // update phone record with time tracking ID.
     if (!empty($phs_id) && !empty($ttr_id)) {
         $stmt = 'UPDATE
                     {{%phone_support}}
                  SET
                     phs_ttr_id = ?
                  WHERE
                     phs_id = ?';
         try {
             DB_Helper::getInstance()->query($stmt, array($ttr_id, $phs_id));
         } catch (DbException $e) {
             return -1;
         }
     }
     return 1;
 }
 /**
  * Method used to create a new reminder.
  *
  * @return  integer 1 if the insert worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     $stmt = 'INSERT INTO
                 {{%reminder_level}}
              (
                 rem_created_date,
                 rem_rank,
                 rem_title,
                 rem_prj_id,
                 rem_skip_weekend
              ) VALUES (
                 ?, ?, ?, ?, ?
              )';
     $params = array(Date_Helper::getCurrentDateGMT(), $_POST['rank'], $_POST['title'], $_POST['project'], $_POST['skip_weekend']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_rem_id = DB_Helper::get_last_insert_id();
     // map the reminder requirements now
     if (@$_POST['reminder_type'] == 'support_level' && count($_POST['support_levels']) > 0) {
         foreach ($_POST['support_levels'] as $level) {
             self::addSupportLevelAssociation($new_rem_id, $level);
         }
     } elseif (@$_POST['reminder_type'] == 'issue' && count($_POST['issues']) > 0) {
         foreach ($_POST['issues'] as $issue_id) {
             self::addIssueAssociation($new_rem_id, $issue_id);
         }
     } elseif (@$_POST['reminder_type'] == 'customer' && count($_POST['customers']) > 0) {
         foreach ($_POST['customers'] as $customer_id) {
             self::addCustomerAssociation($new_rem_id, $customer_id);
         }
     } elseif (@$_POST['reminder_type'] == 'all_issues') {
         self::associateAllIssues($new_rem_id);
     }
     if (@$_POST['check_priority'] == 'yes' && count($_POST['priorities']) > 0) {
         foreach ($_POST['priorities'] as $priority_id) {
             self::addPriorityAssociation($new_rem_id, $priority_id);
         }
     }
     if (@$_POST['check_product'] == 'yes' && count($_POST['products']) > 0) {
         foreach ($_POST['products'] as $pro_id) {
             self::addProductAssociation($new_rem_id, $pro_id);
         }
     }
     if (@$_POST['check_severity'] == 'yes' && count($_POST['severities']) > 0) {
         foreach ($_POST['severities'] as $severity_id) {
             self::addSeverityAssociation($new_rem_id, $severity_id);
         }
     }
     return 1;
 }
Exemple #17
0
 /**
  * Insert note to system, send out notification and log.
  *
  * @param int $usr_id The user ID
  * @param int $issue_id The issue ID
  * @param string $title Title of the note
  * @param string $note Note contents
  * @param array $options extra optional options:
  * - (array) cc: extra recipients to notify (usr_id list)
  * - (bool) add_extra_recipients: whether to add recipients in 'cc' to notification list
  * - (bool) closing: If The issue is being closed. Default false
  * - (bool) is_blocked: FIXME
  * - (bool) log: If adding this note should be logged. Default true
  * - (bool) send_notification: Whether to send a notification about this note or not. Default true
  * - (int) parent_id: FIXME
  * - (string) full_message: FIXME
  * - (string) message_id: FIXME
  * - (string) unknown_user: The email address of a user that sent the blocked email that was turned into this note
  * @return int the new note id if the insert worked, -1 or -2 otherwise
  */
 public static function insertNote($usr_id, $issue_id, $title, $note, $options = array())
 {
     if (Validation::isWhitespace($note)) {
         return -2;
     }
     $options = array_merge(array('unknown_user' => null, 'log' => true, 'closing' => false, 'send_notification' => true, 'is_blocked' => false, 'message_id' => null, 'cc' => null, 'full_message' => null, 'parent_id' => null), $options);
     $prj_id = Issue::getProjectID($issue_id);
     // NOTE: workflow may modify the parameters as $data is passed as reference
     $data = array('title' => &$title, 'note' => &$note, 'options' => $options);
     $workflow = Workflow::preNoteInsert($prj_id, $issue_id, $data);
     if ($workflow !== null) {
         // cancel insert of note
         return $workflow;
     }
     // add the poster to the list of people to be subscribed to the notification list
     // only if there is no 'unknown user' and the note is not blocked
     if (!$options['unknown_user'] && !$options['is_blocked']) {
         $note_cc = $options['add_extra_recipients'] ? $options['cc'] : array();
         // always add the current user to the note_cc list
         $note_cc[] = $usr_id;
         $actions = Notification::getDefaultActions($issue_id, User::getEmail($usr_id), 'note');
         foreach ($note_cc as $subscriber_usr_id) {
             Notification::subscribeUser($usr_id, $issue_id, $subscriber_usr_id, $actions);
         }
     }
     $params = array('not_iss_id' => $issue_id, 'not_usr_id' => $usr_id, 'not_created_date' => Date_Helper::getCurrentDateGMT(), 'not_note' => $note, 'not_title' => $title, 'not_message_id' => $options['message_id'] ?: Mail_Helper::generateMessageID());
     if ($options['full_message']) {
         $params['not_full_message'] = $options['full_message'];
     }
     if ($options['is_blocked']) {
         $params['not_is_blocked'] = '1';
     }
     if ($options['parent_id']) {
         $params['not_parent_id'] = $options['parent_id'];
     }
     if ($options['unknown_user']) {
         $params['not_unknown_user'] = $options['unknown_user'];
     }
     $stmt = 'INSERT INTO
                 {{%note}}
              SET ' . DB_Helper::buildSet($params);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $note_id = DB_Helper::get_last_insert_id();
     Issue::markAsUpdated($issue_id, 'note');
     if ($options['log']) {
         // need to save a history entry for this
         History::add($issue_id, $usr_id, 'note_added', 'Note added by {subject}', array('subject' => User::getFullName($usr_id)));
     }
     // send notifications for the issue being updated
     if ($options['send_notification']) {
         $internal_only = true;
         Notification::notify($issue_id, 'notes', $note_id, $internal_only, $options['cc']);
         Workflow::handleNewNote($prj_id, $issue_id, $usr_id, $options['closing'], $note_id);
     }
     // need to return the new note id here so it can
     // be re-used to associate internal-only attachments
     return $note_id;
 }
Exemple #18
0
 /**
  * Method used to add a new custom status to the system.
  *
  * @return  integer 1 if the insert worked properly, any other value otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     $stmt = 'INSERT INTO
                 {{%status}}
              (
                 sta_title,
                 sta_abbreviation,
                 sta_rank,
                 sta_color,
                 sta_is_closed
              ) VALUES (
                 ?, ?, ?, ?, ?
              )';
     $params = array($_POST['title'], $_POST['abbreviation'], $_POST['rank'], $_POST['color'], $_POST['is_closed']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_status_id = DB_Helper::get_last_insert_id();
     // now populate the project-status mapping table
     foreach ($_POST['projects'] as $prj_id) {
         self::addProjectAssociation($new_status_id, $prj_id);
     }
     return 1;
 }
Exemple #19
0
 /**
  * Method used to add a news entry to the system.
  *
  * @return  integer 1 if the insert worked, -1 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     if (Validation::isWhitespace($_POST['message'])) {
         return -3;
     }
     $stmt = 'INSERT INTO
                 {{%news}}
              (
                 nws_usr_id,
                 nws_created_date,
                 nws_title,
                 nws_message,
                 nws_status
              ) VALUES (
                 ?, ?, ?, ?, ?
              )';
     $params = array(Auth::getUserID(), Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['message'], $_POST['status']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     $new_news_id = DB_Helper::get_last_insert_id();
     // now populate the project-news mapping table
     foreach ($_POST['projects'] as $prj_id) {
         self::addProjectAssociation($new_news_id, $prj_id);
     }
     return 1;
 }
 /**
  * Creates a new round robin entry.
  *
  * @return  integer 1 if the creation worked, -1 otherwise
  */
 public static function insert()
 {
     $blackout_start = $_POST['blackout_start']['Hour'] . ':' . $_POST['blackout_start']['Minute'] . ':00';
     $blackout_end = $_POST['blackout_end']['Hour'] . ':' . $_POST['blackout_end']['Minute'] . ':00';
     $stmt = 'INSERT INTO
                 {{%project_round_robin}}
              (
                 prr_prj_id,
                 prr_blackout_start,
                 prr_blackout_end
              ) VALUES (
                 ?, ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array($_POST['project'], $blackout_start, $blackout_end));
     } catch (DbException $e) {
         return -1;
     }
     $new_id = DB_Helper::get_last_insert_id();
     // add all of the user associated with this round robin entry
     foreach ($_POST['users'] as $usr_id) {
         self::addUserAssociation($new_id, $usr_id);
     }
     return 1;
 }