function saveEntryAction() { $active_worker = CerberusApplication::getActiveWorker(); // Make sure we're an active worker if (empty($active_worker) || empty($active_worker->id)) { return; } @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0)); @($email = DevblocksPlatform::importGPC($_POST['email'], 'string', '')); @($mood = DevblocksPlatform::importGPC($_POST['mood'], 'integer', 0)); @($quote = DevblocksPlatform::importGPC($_POST['quote'], 'string', '')); @($url = DevblocksPlatform::importGPC($_POST['url'], 'string', '')); @($source_extension_id = DevblocksPlatform::importGPC($_POST['source_extension_id'], 'string', '')); @($source_id = DevblocksPlatform::importGPC($_POST['source_id'], 'integer', 0)); // Translate email string into addy id, if exists $address_id = 0; if (!empty($email)) { if (null != ($author_address = DAO_Address::lookupAddress($email, true))) { $address_id = $author_address->id; } } // Delete entries if (!empty($id) && !empty($do_delete)) { if (null != ($entry = DAO_FeedbackEntry::get($id))) { // Only superusers and owners can delete entries if ($active_worker->is_superuser || $active_worker->id == $entry->worker_id) { DAO_FeedbackEntry::delete($id); } } return; } // New or modify $fields = array(DAO_FeedbackEntry::QUOTE_MOOD => intval($mood), DAO_FeedbackEntry::QUOTE_TEXT => $quote, DAO_FeedbackEntry::QUOTE_ADDRESS_ID => intval($address_id), DAO_FeedbackEntry::SOURCE_URL => $url); // Only on new if (empty($id)) { $fields[DAO_FeedbackEntry::LOG_DATE] = time(); $fields[DAO_FeedbackEntry::WORKER_ID] = $active_worker->id; } if (empty($id)) { // create $id = DAO_FeedbackEntry::create($fields); // Post-create actions if (!empty($source_extension_id) && !empty($source_id)) { switch ($source_extension_id) { case 'feedback.source.ticket': // Create a ticket comment about the feedback (to prevent dupes) if (null == ($worker_address = DAO_Address::lookupAddress($active_worker->email))) { break; } $comment_text = sprintf("== Capture Feedback ==\n" . "Author: %s\n" . "Mood: %s\n" . "\n" . "%s\n", !empty($author_address) ? $author_address->email : 'Anonymous', empty($mood) ? 'Neutral' : (1 == $mood ? 'Praise' : 'Criticism'), $quote); $fields = array(DAO_TicketComment::ADDRESS_ID => $worker_address->id, DAO_TicketComment::COMMENT => $comment_text, DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => intval($source_id)); DAO_TicketComment::create($fields); break; } } } else { // modify DAO_FeedbackEntry::update($id, $fields); } // Custom field saves @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array())); DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_FeedbackEntry::ID, $id, $field_ids); }