Exemplo n.º 1
0
 function saveAccountAction()
 {
     @($first_name = DevblocksPlatform::importGPC($_REQUEST['first_name'], 'string', ''));
     @($last_name = DevblocksPlatform::importGPC($_REQUEST['last_name'], 'string', ''));
     @($change_password = DevblocksPlatform::importGPC($_REQUEST['change_password'], 'string', ''));
     @($change_password2 = DevblocksPlatform::importGPC($_REQUEST['change_password2'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     if (!empty($active_user)) {
         $fields = array(DAO_Address::FIRST_NAME => $first_name, DAO_Address::LAST_NAME => $last_name);
         DAO_Address::update($active_user->id, $fields);
         $tpl->assign('account_success', true);
         if (!empty($change_password)) {
             if (0 == strcmp($change_password, $change_password2)) {
                 DAO_AddressAuth::update($active_user->id, array(DAO_AddressAuth::PASS => md5($change_password)));
             } else {
                 $tpl->assign('account_error', "The passwords you entered did not match.");
             }
         }
     }
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'account')));
 }
Exemplo n.º 2
0
 function doRegisterConfirmAction()
 {
     @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string', ''));
     @($code = trim(DevblocksPlatform::importGPC($_REQUEST['code'], 'string', '')));
     @($pass = DevblocksPlatform::importGPC($_REQUEST['pass'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('register_email', $email);
     $tpl->assign('register_code', $code);
     if (!empty($email) && !empty($pass) && !empty($code)) {
         if (null != ($addy = DAO_Address::lookupAddress($email, false)) && !$addy->is_registered && !empty($addy->pass) && 0 == strcasecmp($code, $addy->pass)) {
             $fields = array(DAO_Address::IS_REGISTERED => 1, DAO_Address::PASS => md5($pass));
             DAO_Address::update($addy->id, $fields);
         } else {
             $tpl->assign('register_error', sprintf("The confirmation code you entered does not match our records.  Try again."));
             DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm')));
             return;
         }
     } else {
         $tpl->assign('register_error', sprintf("You must enter a valid e-mail address, confirmation code and desired password to continue."));
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm')));
         return;
     }
 }
Exemplo n.º 3
0
 private function _handleImportContact($xml)
 {
     $settings = CerberusSettings::getInstance();
     $logger = DevblocksPlatform::getConsoleLog();
     $sFirstName = (string) $xml->first_name;
     $sLastName = (string) $xml->last_name;
     $sEmail = (string) $xml->email;
     $sPassword = (string) $xml->password;
     $sOrganization = (string) $xml->organization;
     // Dupe check org
     if (null != ($address = DAO_Address::lookupAddress($sEmail))) {
         $logger->info('[Importer] Avoiding creating duplicate contact #' . $address->id . ' (' . $sEmail . ')');
         // [TODO] Still associate with org if local blank?
         // [TODO] Still associate password if local blank?
         return true;
     }
     $fields = array(DAO_Address::FIRST_NAME => $sFirstName, DAO_Address::LAST_NAME => $sLastName, DAO_Address::EMAIL => $sEmail);
     // Associate SC password
     if (!empty($sPassword) && $sPassword != md5('')) {
         $fields[DAO_Address::IS_REGISTERED] = 1;
         $fields[DAO_Address::PASS] = $sPassword;
     }
     $address_id = DAO_Address::create($fields);
     // Associate with organization
     if (!empty($sOrganization)) {
         if (null != ($org_id = DAO_ContactOrg::lookup($sOrganization, true))) {
             DAO_Address::update($address_id, array(DAO_Address::CONTACT_ORG_ID => $org_id));
         }
     }
     $logger->info('[Importer] Imported contact #' . $address_id . ' (' . $sEmail . ')');
     return true;
 }
Exemplo n.º 4
0
 function saveContactAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     $db = DevblocksPlatform::getDatabaseService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($email = trim(DevblocksPlatform::importGPC($_REQUEST['email'], 'string', '')));
     @($first_name = trim(DevblocksPlatform::importGPC($_REQUEST['first_name'], 'string', '')));
     @($last_name = trim(DevblocksPlatform::importGPC($_REQUEST['last_name'], 'string', '')));
     @($contact_org = trim(DevblocksPlatform::importGPC($_REQUEST['contact_org'], 'string', '')));
     @($is_banned = DevblocksPlatform::importGPC($_REQUEST['is_banned'], 'integer', 0));
     @($pass = DevblocksPlatform::importGPC($_REQUEST['pass'], 'string', ''));
     @($unregister = DevblocksPlatform::importGPC($_REQUEST['unregister'], 'integer', 0));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     if ($active_worker->hasPriv('core.addybook.addy.actions.update')) {
         $contact_org_id = 0;
         if (!empty($contact_org)) {
             $contact_org_id = DAO_ContactOrg::lookup($contact_org, true);
             $contact_org = DAO_ContactOrg::get($contact_org_id);
         }
         // Common fields
         $fields = array(DAO_Address::FIRST_NAME => $first_name, DAO_Address::LAST_NAME => $last_name, DAO_Address::CONTACT_ORG_ID => $contact_org_id, DAO_Address::IS_BANNED => $is_banned);
         // Are we clearing the contact's login?
         if ($unregister) {
             $fields[DAO_Address::IS_REGISTERED] = 0;
             $fields[DAO_Address::PASS] = '';
         } elseif (!empty($pass)) {
             // Are we changing their password?
             $fields[DAO_Address::IS_REGISTERED] = 1;
             $fields[DAO_Address::PASS] = md5($pass);
         }
         if ($id == 0) {
             $fields = $fields + array(DAO_Address::EMAIL => $email);
             $id = DAO_Address::create($fields);
         } else {
             DAO_Address::update($id, $fields);
         }
         // Custom field saves
         @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
         DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_Address::ID, $id, $field_ids);
         /*
          * Notify anything that wants to know when Address Peek saves.
          */
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('address.peek.saved', array('address_id' => $id, 'changed_fields' => $fields)));
     }
     if (!empty($view_id)) {
         $view = C4_AbstractViewLoader::getView($view_id);
         $view->render();
     }
 }
Exemplo n.º 5
0
 private function _putIdAction($path)
 {
     $xmlstr = $this->getPayload();
     $xml_in = new SimpleXMLElement($xmlstr);
     $in_id = array_shift($path);
     if (empty($in_id)) {
         $this->_error("ID was not provided.");
     }
     if (null == ($address = DAO_Address::get($in_id))) {
         $this->_error("ID not valid.");
     }
     $fields = array();
     $flds = DAO_Address::getFields();
     unset($flds[DAO_Address::ID]);
     foreach ($flds as $idx => $f) {
         $idx_name = $this->translate($idx, true);
         if ($idx_name == null) {
             continue;
         }
         @($value = DevblocksPlatform::importGPC($xml_in->{$idx_name}, 'string'));
         if ($this->isValid($idx_name, $value)) {
             $fields[$idx] = $value;
         }
     }
     // [TODO] This referential integrity should really be up to DAO
     if (!empty($fields[DAO_Address::CONTACT_ORG_ID])) {
         $in_contact_org_id = intval($fields[DAO_Address::CONTACT_ORG_ID]);
         if (null == ($contact_org = DAO_ContactOrg::get($in_contact_org_id))) {
             unset($fields[DAO_Address::CONTACT_ORG_ID]);
         }
     }
     if (!empty($fields)) {
         DAO_Address::update($address->id, $fields);
     }
     // update password if requested
     @($password = DevblocksPlatform::importGPC($xml_in->password, 'string', ''));
     if (!empty($password)) {
         DAO_AddressAuth::update($in_id, array(DAO_AddressAuth::PASS => md5($password)));
     }
     // send confirmation if requested
     @($confirmation_link = DevblocksPlatform::importGPC($xml_in->send_confirmation, 'string', ''));
     if (!empty($confirmation_link)) {
         $this->_sendConfirmation($address->email, $confirmation_link);
     }
     $this->_getIdAction(array($address->id));
 }
Exemplo n.º 6
0
 function doBulkUpdate($filter, $do, $ids = array())
 {
     @set_time_limit(600);
     // [TODO] Temp!
     $change_fields = array();
     $custom_fields = array();
     // Make sure we have actions
     if (empty($do)) {
         return;
     }
     // Make sure we have checked items if we want a checked list
     if (0 == strcasecmp($filter, "checks") && empty($ids)) {
         return;
     }
     if (is_array($do)) {
         foreach ($do as $k => $v) {
             switch ($k) {
                 case 'org_id':
                     $change_fields[DAO_Address::CONTACT_ORG_ID] = intval($v);
                     break;
                 case 'banned':
                     $change_fields[DAO_Address::IS_BANNED] = intval($v);
                     break;
                 default:
                     // Custom fields
                     if (substr($k, 0, 3) == "cf_") {
                         $custom_fields[substr($k, 3)] = $v;
                     }
             }
         }
     }
     $pg = 0;
     if (empty($ids)) {
         do {
             list($objects, $null) = DAO_Address::search(array(), $this->params, 100, $pg++, SearchFields_Address::ID, true, false);
             $ids = array_merge($ids, array_keys($objects));
         } while (!empty($objects));
     }
     $batch_total = count($ids);
     for ($x = 0; $x <= $batch_total; $x += 100) {
         $batch_ids = array_slice($ids, $x, 100);
         DAO_Address::update($batch_ids, $change_fields);
         // Custom Fields
         self::_doBulkSetCustomFields(ChCustomFieldSource_Address::ID, $custom_fields, $batch_ids);
         unset($batch_ids);
     }
     unset($ids);
 }
Exemplo n.º 7
0
 private function _sendConfirmation($email, $link)
 {
     $settings = CerberusSettings::getInstance();
     $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL);
     $url = DevblocksPlatform::getUrlService();
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $code = CerberusApplication::generatePassword(8);
         if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, false))) {
             $fields = array(DAO_Address::IS_REGISTERED => 0, DAO_Address::PASS => $code);
             DAO_Address::update($addy->id, $fields);
         } else {
             return;
         }
         $message = $mail_service->createMessage();
         $message->setTo(array($email));
         $message->setFrom(array($from => $from_personal));
         $message->setSubject("Account Confirmation Code");
         $message->setBody(sprintf("Below is your confirmation code.  Please copy and paste it into the confirmation form at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "Thanks!\r\n", $link, $code));
         $headers = $mail->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $result = $mailer->send($message);
     } catch (Exception $e) {
         return;
     }
 }
Exemplo n.º 8
0
Arquivo: Mail.php Projeto: Hildy/cerb5
 static function sendTicketMessage($properties = array())
 {
     $settings = DevblocksPlatform::getPluginSettingsService();
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     @($from_addy = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
     @($from_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''));
     // [TODO] If we still don't have a $from_addy we need a graceful failure.
     /*
     	     * [TODO] Move these into constants?
     	    'message_id'
     	    -----'ticket_id'
     'subject'
     	    'to'
     	    'cc'
     	    'bcc'
     	    'content'
     	    'files'
     	    'closed'
     	    'ticket_reopen'
     	    'unlock_date'
     	    'bucket_id'
     	    'agent_id',
     'is_autoreply',
     'dont_send',
     'dont_save_copy'
     */
     $mail_succeeded = true;
     try {
         // objects
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         // properties
         @($reply_message_id = $properties['message_id']);
         @($content = $properties['content']);
         @($files = $properties['files']);
         @($forward_files = $properties['forward_files']);
         @($worker_id = $properties['agent_id']);
         @($subject = $properties['subject']);
         $message = DAO_Ticket::getMessage($reply_message_id);
         $message_headers = DAO_MessageHeader::getAll($reply_message_id);
         $ticket_id = $message->ticket_id;
         $ticket = DAO_Ticket::getTicket($ticket_id);
         // [TODO] Check that message|ticket isn't NULL
         // If this ticket isn't spam trained and our outgoing message isn't an autoreply
         if ($ticket->spam_training == CerberusTicketSpamTraining::BLANK && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
             CerberusBayes::markTicketAsNotSpam($ticket_id);
         }
         // Allow teams to override the default from/personal
         @($group_reply = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
         @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL, ''));
         @($group_personal_with_worker = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL_WITH_WORKER, 0));
         if (!empty($group_reply)) {
             $from_addy = $group_reply;
         }
         if (!empty($group_personal)) {
             $from_personal = $group_personal;
         }
         // Prefix the worker name on the personal line?
         if (!empty($group_personal_with_worker) && null != ($reply_worker = DAO_Worker::getAgent($worker_id))) {
             $from_personal = $reply_worker->getName() . (!empty($from_personal) ? ', ' . $from_personal : "");
         }
         // Headers
         $mail->setFrom(array($from_addy => $from_personal));
         $mail->generateId();
         $headers = $mail->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         // Subject
         if (empty($subject)) {
             $subject = $ticket->subject;
         }
         if (!empty($properties['to'])) {
             // forward
             $mail->setSubject($subject);
         } else {
             // reply
             @($group_has_subject = intval(DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_HAS_MASK, 0)));
             @($group_subject_prefix = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_PREFIX, ''));
             $prefix = sprintf("[%s#%s] ", !empty($group_subject_prefix) ? $group_subject_prefix . ' ' : '', $ticket->mask);
             $mail->setSubject(sprintf('Re: %s%s', $group_has_subject ? $prefix : '', $subject));
         }
         // References
         if (!empty($message) && false !== @($in_reply_to = $message_headers['message-id'])) {
             $headers->addTextHeader('References', $in_reply_to);
             $headers->addTextHeader('In-Reply-To', $in_reply_to);
         }
         // Auto-reply handling (RFC-3834 compliant)
         if (isset($properties['is_autoreply']) && $properties['is_autoreply']) {
             $headers->addTextHeader('Auto-Submitted', 'auto-replied');
             if (null == ($first_address = DAO_Address::get($ticket->first_wrote_address_id))) {
                 return;
             }
             // Don't send e-mail to ourselves
             if (isset($helpdesk_senders[$first_address->email])) {
                 return;
             }
             // Make sure we haven't mailed this address an autoreply within 5 minutes
             if ($first_address->last_autoreply > 0 && $first_address->last_autoreply > time() - 300) {
                 return;
             }
             $first_email = strtolower($first_address->email);
             $first_split = explode('@', $first_email);
             if (!is_array($first_split) || count($first_split) != 2) {
                 return;
             }
             // If return-path is blank
             if (isset($message_headers['return-path']) && $message_headers['return-path'] == '<>') {
                 return;
             }
             // Ignore bounces
             if ($first_split[0] == "postmaster" || $first_split[0] == "mailer-daemon") {
                 return;
             }
             // Ignore autoresponses to autoresponses
             if (isset($message_headers['auto-submitted']) && $message_headers['auto-submitted'] != 'no') {
                 return;
             }
             if (isset($message_headers['precedence']) && ($message_headers['precedence'] == 'list' || $message_headers['precedence'] == 'junk' || ($message_headers['precedence'] = 'bulk'))) {
                 return;
             }
             // Set the auto-reply date for this address to right now
             DAO_Address::update($ticket->first_wrote_address_id, array(DAO_Address::LAST_AUTOREPLY => time()));
             // Auto-reply just to the initial requester
             $mail->addTo($first_address->email);
             // Not an auto-reply
         } else {
             // Forwards
             if (!empty($properties['to'])) {
                 $aTo = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['to']));
                 if (is_array($aTo)) {
                     foreach ($aTo as $to_addy) {
                         $mail->addTo($to_addy);
                     }
                 }
                 // Replies
             } else {
                 // Recipients
                 $requesters = DAO_Ticket::getRequestersByTicket($ticket_id);
                 if (is_array($requesters)) {
                     foreach ($requesters as $requester) {
                         /* @var $requester Model_Address */
                         $mail->addTo($requester->email);
                     }
                 }
             }
             // Ccs
             if (!empty($properties['cc'])) {
                 $aCc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['cc']));
                 $mail->setCc($aCc);
             }
             // Bccs
             if (!empty($properties['bcc'])) {
                 $aBcc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['bcc']));
                 $mail->setBcc($aBcc);
             }
         }
         /*
          * [IMPORTANT -- Yes, this is simply a line in the sand.]
          * You're welcome to modify the code to meet your needs, but please respect 
          * our licensing.  Buy a legitimate copy to help support the project!
          * http://www.cerberusweb.com/
          */
         $license = CerberusLicense::getInstance();
         if (empty($license) || @empty($license['serial'])) {
             $content .= base64_decode("DQoNCi0tLQ0KQ29tYmF0IHNwYW0gYW5kIGltcHJvdmUgcmVzc" . "G9uc2UgdGltZXMgd2l0aCBDZXJiZXJ1cyBIZWxwZGVzayA0LjAhDQpodHRwOi8vd3d3LmNlc" . "mJlcnVzd2ViLmNvbS8NCg");
         }
         // Body
         $mail->setBody($content);
         // Mime Attachments
         if (is_array($files) && !empty($files)) {
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx])) {
                     continue;
                 }
                 $mail->attach(Swift_Attachment::fromPath($file)->setFilename($files['name'][$idx]));
             }
         }
         // Forward Attachments
         if (!empty($forward_files) && is_array($forward_files)) {
             $attachments_path = APP_STORAGE_PATH . '/attachments/';
             foreach ($forward_files as $file_id) {
                 $attachment = DAO_Attachment::get($file_id);
                 $attachment_path = $attachments_path . $attachment->filepath;
                 $mail->attach(Swift_Attachment::fromPath($attachment_path)->setFilename($attachment->display_name));
             }
         }
         if (!DEMO_MODE) {
             // If we're not supposed to send
             if (isset($properties['dont_send']) && $properties['dont_send']) {
                 // ...do nothing
             } else {
                 // otherwise send
                 if (!$mailer->send($mail)) {
                     $mail_succeeded = false;
                     throw new Exception('Mail not sent.');
                 }
             }
         }
     } catch (Exception $e) {
         // tag failure, so we can add a note to the message later
         $mail_succeeded = false;
     }
     // Handle post-mail actions
     $change_fields = array();
     $fromAddressInst = CerberusApplication::hashLookupAddress($from_addy, true);
     $fromAddressId = $fromAddressInst->id;
     if ((!isset($properties['dont_keep_copy']) || !$properties['dont_keep_copy']) && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
         $change_fields[DAO_Ticket::LAST_WROTE_ID] = $fromAddressId;
         $change_fields[DAO_Ticket::UPDATED_DATE] = time();
         if (!empty($worker_id)) {
             $change_fields[DAO_Ticket::LAST_WORKER_ID] = $worker_id;
             $change_fields[DAO_Ticket::LAST_ACTION_CODE] = CerberusTicketActionCode::TICKET_WORKER_REPLY;
         }
         // Only change the subject if not forwarding
         if (!empty($subject) && empty($properties['to'])) {
             $change_fields[DAO_Ticket::SUBJECT] = $subject;
         }
         $fields = array(DAO_Message::TICKET_ID => $ticket_id, DAO_Message::CREATED_DATE => time(), DAO_Message::ADDRESS_ID => $fromAddressId, DAO_Message::IS_OUTGOING => 1, DAO_Message::WORKER_ID => !empty($worker_id) ? $worker_id : 0);
         $message_id = DAO_Message::create($fields);
         // Content
         DAO_MessageContent::create($message_id, $content);
         $headers = $mail->getHeaders();
         // Headers
         foreach ($headers->getAll() as $hdr) {
             if (null != ($hdr_val = $hdr->getFieldBody())) {
                 if (!empty($hdr_val)) {
                     DAO_MessageHeader::create($message_id, $hdr->getFieldName(), CerberusParser::fixQuotePrintableString($hdr_val));
                 }
             }
         }
         // Attachments
         if (is_array($files) && !empty($files)) {
             $attachment_path = APP_STORAGE_PATH . '/attachments/';
             reset($files);
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx]) || !file_exists($file)) {
                     continue;
                 }
                 $fields = array(DAO_Attachment::MESSAGE_ID => $message_id, DAO_Attachment::DISPLAY_NAME => $files['name'][$idx], DAO_Attachment::MIME_TYPE => $files['type'][$idx], DAO_Attachment::FILE_SIZE => filesize($file));
                 $file_id = DAO_Attachment::create($fields);
                 $attachment_bucket = sprintf("%03d/", mt_rand(1, 100));
                 $attachment_file = $file_id;
                 if (!file_exists($attachment_path . $attachment_bucket)) {
                     mkdir($attachment_path . $attachment_bucket, 0775, true);
                 }
                 if (!is_writeable($attachment_path . $attachment_bucket)) {
                     echo "Can't write to bucket " . $attachment_path . $attachment_bucket . "<BR>";
                 }
                 copy($file, $attachment_path . $attachment_bucket . $attachment_file);
                 @unlink($file);
                 DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file));
             }
         }
         // add note to message if email failed
         if ($mail_succeeded === false) {
             $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
             DAO_MessageNote::create($fields);
         }
     }
     // Post-Reply Change Properties
     if (isset($properties['closed'])) {
         switch ($properties['closed']) {
             case 0:
                 // open
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 $change_fields[DAO_Ticket::DUE_DATE] = 0;
                 break;
             case 1:
                 // closed
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 1;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
             case 2:
                 // waiting
                 $change_fields[DAO_Ticket::IS_WAITING] = 1;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
         }
     }
     // Who should handle the followup?
     if (isset($properties['next_worker_id'])) {
         $change_fields[DAO_Ticket::NEXT_WORKER_ID] = $properties['next_worker_id'];
     }
     // Allow anybody to reply after
     if (isset($properties['unlock_date']) && !empty($properties['unlock_date'])) {
         $unlock = strtotime($properties['unlock_date']);
         if (intval($unlock) > 0) {
             $change_fields[DAO_Ticket::UNLOCK_DATE] = $unlock;
         }
     }
     // Move
     if (!empty($properties['bucket_id'])) {
         // [TODO] Use API to move, or fire event
         // [TODO] Ensure team/bucket exist
         list($team_id, $bucket_id) = CerberusApplication::translateTeamCategoryCode($properties['bucket_id']);
         $change_fields[DAO_Ticket::TEAM_ID] = $team_id;
         $change_fields[DAO_Ticket::CATEGORY_ID] = $bucket_id;
     }
     if (!empty($ticket_id) && !empty($change_fields)) {
         DAO_Ticket::updateTicket($ticket_id, $change_fields);
     }
     // Outbound Reply Event (not automated reply, etc.)
     if (!empty($worker_id)) {
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.outbound', array('ticket_id' => $ticket_id, 'worker_id' => $worker_id)));
     }
 }
Exemplo n.º 9
0
 function runMacroAction()
 {
     @($macro_id = DevblocksPlatform::importGPC($_REQUEST['macro_id'], 'integer'));
     @($ids = DevblocksPlatform::importGPC($_REQUEST['ids']));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string'));
     $view = C4_AbstractViewLoader::getView($view_id);
     $ids = explode(',', $ids);
     if (null !== ($macro = DAO_Macro::get($macro_id))) {
         switch ($macro->source_extension_id) {
             case 'cerberusweb.macros.ticket':
                 $fields = array();
                 // loop over the actions, saving the $params as $fields
                 foreach ($macro->actions as $action => $params) {
                     switch ($action) {
                         case 'cerberusweb.macros.action.assign':
                             $fields['next_worker_id'] = $params['worker_id'];
                             break;
                         case 'cerberusweb.macros.action.move':
                             $fields['team_id'] = $params['group_id'];
                             $fields['category_id'] = $params['bucket_id'];
                             break;
                         case 'cerberusweb.macros.action.status':
                             $fields['is_waiting'] = $params['is_waiting'];
                             $fields['is_closed'] = $params['is_closed'];
                             $fields['is_deleted'] = $params['is_deleted'];
                             break;
                         default:
                             //								$fields[] = $params;
                             break;
                     }
                 }
                 // update the ticket
                 DAO_Ticket::updateTicket($ids, $fields);
                 break;
             case 'cerberusweb.macros.address':
                 foreach ($macro->actions as $action => $params) {
                     switch ($action) {
                         default:
                             DAO_Address::update($ids, $params);
                     }
                 }
                 break;
             case 'cerberusweb.macros.opportunity':
                 foreach ($macro->actions as $action => $params) {
                     switch ($action) {
                         default:
                             DAO_CrmOpportunity::update($ids, $params);
                     }
                 }
             case 'cerberusweb.macros.task':
                 foreach ($macro->actions as $action => $params) {
                     switch ($action) {
                         default:
                             DAO_Task::update($ids, $params);
                     }
                 }
             case 'cerberusweb.macros.organization':
                 foreach ($macro->actions as $action => $params) {
                     switch ($action) {
                         default:
                             DAO_ContactOrg::update($ids, $params);
                     }
                 }
             default:
                 break;
         }
     }
     $view = C4_AbstractViewLoader::getView($view_id);
     $view->render();
 }