Exemplo n.º 1
0
 public function afterUpdate($event)
 {
     if ($this->updateTriggerEnabled) {
         X2Flow::trigger('RecordUpdateTrigger', array('model' => $this->getOwner()));
         $this->updateTriggerEnabled = false;
     }
 }
Exemplo n.º 2
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id, $replyId = null, $latest = null)
 {
     $page = null;
     $model = $this->loadModel($id);
     if (!is_null($latest) && !Yii::app()->request->isAjaxRequest) {
         $replyId = $model->lastPost->id;
     }
     if (!is_null($replyId) && !Yii::app()->request->isAjaxRequest) {
         $post = TopicReplies::model()->findByPk($replyId);
         if (!is_null($post)) {
             $page = $post->getTopicPage();
         } else {
             $replyId = null;
         }
     }
     $this->noBackdrop = true;
     $topicReply = new TopicReplies();
     if (!isset($_GET['ajax'])) {
         $log = new ViewLog();
         $log->user = Yii::app()->user->getName();
         $log->recordType = get_class($model);
         $log->recordId = $model->id;
         $log->timestamp = time();
         $log->save();
         X2Flow::trigger('RecordViewTrigger', array('model' => $model));
     }
     $dataProvider = new CArrayDataProvider($model->replies, array('id' => 'topic-replies', 'pagination' => array('pageSize' => Topics::PAGE_SIZE)));
     $dataProvider->getPagination()->setItemCount($dataProvider->getTotalItemCount());
     if (!Yii::app()->request->isAjaxRequest && !is_null($page)) {
         $dataProvider->getPagination()->setCurrentPage($page);
     }
     $this->render('view', array('model' => $model, 'replyId' => $replyId, 'dataProvider' => $dataProvider, 'topicReply' => $topicReply, 'page' => is_null($page) ? $dataProvider->getPagination()->getCurrentPage() : $page));
 }
Exemplo n.º 3
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $model = $this->loadModel($id);
     if (!$this->checkPermissions($model, 'view')) {
         $this->denied();
     }
     // add doc to user's recent item list
     User::addRecentItem('d', $id, Yii::app()->user->getId());
     X2Flow::trigger('RecordViewTrigger', array('model' => $model));
     $this->render('view', array('model' => $model));
 }
Exemplo n.º 4
0
 public function testRecordLimit()
 {
     $this->clearLogs();
     Yii::app()->settings->triggerLogMax = 5;
     Yii::app()->settings->save();
     //TriggerLog::model ()->asa ('RecordLimitBehavior')->limit = 5;
     $contact = $this->contacts('testUser');
     $params = array('model' => $this->contacts('testUser'));
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(1, TriggerLog::model()->count());
     sleep(1);
     // ensure that log timestamps differ
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(2, TriggerLog::model()->count());
     sleep(1);
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(3, TriggerLog::model()->count());
     sleep(1);
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(4, TriggerLog::model()->count());
     sleep(1);
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(5, TriggerLog::model()->count());
     $triggerLogMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar();
     sleep(1);
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(5, TriggerLog::model()->count());
     $triggerLogNewMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar();
     // ensure that oldest log was removed
     $this->assertNotEquals($triggerLogMinTS, $triggerLogNewMinTS);
     // now remove the limit
     $triggerLogMinTS = $triggerLogNewMinTS;
     Yii::app()->settings->triggerLogMax = null;
     Yii::app()->settings->save();
     //TriggerLog::model ()->asa ('RecordLimitBehavior')->limit = null;
     sleep(1);
     X2Flow::trigger('RecordViewTrigger', $params);
     $this->assertEquals(6, TriggerLog::model()->count());
     $triggerLogNewMinTS = Yii::app()->db->createCommand()->select('min(triggeredAt)')->from('x2_trigger_logs')->queryScalar();
     $this->assertEquals($triggerLogMinTS, $triggerLogNewMinTS);
 }
Exemplo n.º 5
0
 public function actionViewAction($id, $publisher = false)
 {
     $this->redirectOnNullModel = false;
     $this->throwOnNullModel = false;
     $model = $this->loadModel($id);
     if (isset($model)) {
         if (in_array($model->type, Actions::$emailTypes)) {
             $this->actionViewEmail($id);
             return;
         }
         X2Flow::trigger('RecordViewTrigger', array('model' => $model));
         $this->renderPartial('_viewFrame', array('model' => $model, 'publisher' => $publisher));
     } else {
         echo "<b>Error: 404</b><br><br>Unable to find the requested action.";
     }
 }
Exemplo n.º 6
0
 /**
  * Displays a particular model.
  *
  * This method is called in child controllers
  * which pass it a model to display and what type of model it is (i.e. Contact,
  * Opportunity, Account).  It also creates an action history and provides appropriate
  * variables to the view.
  *
  * @param mixed $model The model to be displayed (subclass of {@link CActiveRecord} or {@link X2Model}
  * @param String $type The type of the module being displayed
  */
 public function view(&$model, $type = null, $params = array())
 {
     $this->noBackdrop = true;
     // should only happen when the model is known to have X2LinkableBehavior
     if ($type === null) {
         // && $model->asa('X2LinkableBehavior') !== null)
         $type = $model->module;
     }
     if (!isset($_GET['ajax'])) {
         $log = new ViewLog();
         $log->user = Yii::app()->user->getName();
         $log->recordType = get_class($model);
         $log->recordId = $model->id;
         $log->timestamp = time();
         $log->save();
         X2Flow::trigger('RecordViewTrigger', array('model' => $model));
     }
     $this->render('view', array_merge($params, array('model' => $model, 'actionHistory' => $this->getHistory($model, $type), 'currentWorkflow' => $this->getCurrentWorkflow($model->id, $type))));
 }
Exemplo n.º 7
0
 /**
  * Uncompletes a stage (if completed) or unstarts it (if started).
  * @param $unstarts bool If false, will not attempt to unstart an ongoing stage
  */
 public static function revertStage($workflowId, $stageNumber, $model, $unstart = true, $workflowStatus = null)
 {
     //AuxLib::debugLogR ('reverting stage '.$stageNumber);
     $modelId = $model->id;
     $type = lcfirst(X2Model::getModuleName(get_class($model)));
     if (!$workflowStatus) {
         $workflowStatus = Workflow::getWorkflowStatus($workflowId, $modelId, $type);
     }
     $stageCount = count($workflowStatus['stages']);
     $reverted = false;
     // if stage has been started or completed
     if ($model !== null && self::isStarted($workflowStatus, $stageNumber)) {
         // find selected stage (and duplicates)
         $actions = X2Model::model('Actions')->findAllByAttributes(array('associationId' => $modelId, 'associationType' => $type, 'type' => 'workflow', 'workflowId' => $workflowId, 'stageNumber' => $stageNumber), new CDbCriteria(array('order' => 'createDate DESC')));
         // if there is more than 1 action for this stage,
         if (count($actions) > 1) {
             // delete all but the most recent one
             for ($i = 1; $i < count($actions); $i++) {
                 $actions[$i]->delete();
             }
         }
         // the stage is complete, so just set it to 'started'
         if (self::isCompleted($workflowStatus, $stageNumber) && self::canUncomplete($workflowStatus, $stageNumber)) {
             //AuxLib::debugLogR ('uncompleting stage '.$stageNumber);
             $actions[0]->setScenario('workflow');
             // don't genererate normal action changelog/triggers/events
             $actions[0]->disableBehavior('changelog');
             $actions[0]->disableBehavior('tags');
             // no tags up in here
             $actions[0]->complete = 'No';
             $actions[0]->completeDate = null;
             $actions[0]->completedBy = '';
             // original completion note no longer applies
             $actions[0]->actionDescription = '';
             $actions[0]->save();
             self::updateWorkflowChangelog($actions[0], 'revert', $model);
             X2Flow::trigger('WorkflowRevertStageTrigger', array('workflow' => $actions[0]->workflow, 'model' => $model, 'workflowId' => $actions[0]->workflow->id, 'stageNumber' => $stageNumber));
             // delete all incomplete stages after this one
             // X2Model::model('Actions')->deleteAll(new CDbCriteria(
             // array('condition'=>"associationId=$modelId AND associationType='$type' AND type='workflow' AND workflowId=$workflowId AND stageNumber > $stageNumber AND (completeDate IS NULL OR completeDate=0)")
             // ));
         } else {
             if ($unstart) {
                 // the stage is already incomplete, so delete it and all subsequent stages
                 $subsequentActions = X2Model::model('Actions')->findAll(new CDbCriteria(array('condition' => "associationId={$modelId} AND associationType='{$type}' " . "AND type='workflow' AND workflowId={$workflowId} " . "AND stageNumber >= {$stageNumber}")));
                 foreach ($subsequentActions as &$action) {
                     self::updateWorkflowChangelog($action, 'revert', $model);
                     X2Flow::trigger('WorkflowRevertStageTrigger', array('workflow' => $action->workflow, 'model' => $model, 'workflowId' => $action->workflow->id, 'stageNumber' => $action->stageNumber));
                     $action->delete();
                 }
             }
         }
         $workflowStatus = Workflow::getWorkflowStatus($workflowId, $modelId, $type);
         $reverted = true;
     }
     //AuxLib::debugLogR ((int) $reverted);
     return array($reverted, $workflowStatus);
 }
Exemplo n.º 8
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $model = CActiveRecord::model('Docs')->findByPk($id);
     if (!$this->checkPermissions($model, 'view')) {
         $this->denied();
     }
     if (isset($model)) {
         $permissions = explode(", ", $model->editPermissions);
         if (in_array(Yii::app()->user->getName(), $permissions)) {
             $editFlag = true;
         } else {
             $editFlag = false;
         }
     }
     if (!isset($model) || $model->visibility == 0 && $model->createdBy != Yii::app()->user->getName() && !Yii::app()->params->isAdmin && !$editFlag) {
         $this->redirect(array('/docs/docs/index'));
     }
     // add doc to user's recent item list
     User::addRecentItem('d', $id, Yii::app()->user->getId());
     X2Flow::trigger('RecordViewTrigger', array('model' => $model));
     $this->render('view', array('model' => $model));
 }
Exemplo n.º 9
0
 public function actionPublisherCreate()
 {
     if (isset($_POST['SelectedTab'], $_POST['Actions']) && (!Yii::app()->user->isGuest || Yii::app()->user->checkAccess($_POST['Actions']['associationType'] . 'View'))) {
         Yii::app()->clientScript->scriptMap['*.css'] = false;
         // if association name is sent without id, try to lookup the record by name and type
         if (isset($_POST['calendarEventTab']) && $_POST['calendarEventTab'] && isset($_POST['Actions']['associationName']) && empty($_POST['Actions']['associationId'])) {
             $associatedModel = X2Model::getModelOfTypeWithName($_POST['Actions']['associationType'], $_POST['Actions']['associationName']);
             if ($associatedModel) {
                 $_POST['Actions']['associationId'] = $associatedModel->id;
             } else {
                 echo CJSON::encode(array('error' => Yii::t('actions', 'Invalid association name')));
                 Yii::app()->end();
             }
         }
         if (!Yii::app()->user->isGuest) {
             $model = new Actions();
         } else {
             $model = new Actions('guestCreate');
             $model->verifyCode = $_POST['Actions']['verifyCode'];
         }
         $model->setX2Fields($_POST['Actions']);
         // format dates,
         if (isset($_POST[get_class($model)]['dueDate'])) {
             $model->dueDate = Formatter::parseDateTime($_POST[get_class($model)]['dueDate']);
         }
         if ($_POST['SelectedTab'] == 'new-event' || $_POST['SelectedTab'] == 'new-small-calendar-event') {
             $model->disableBehavior('changelog');
             $event = new Events();
             $event->type = 'calendar_event';
             $event->visibility = $model->visibility;
             $event->associationType = 'Actions';
             $event->timestamp = $model->dueDate;
             $model->type = 'event';
             if ($model->completeDate) {
                 $model->completeDate = Formatter::parseDateTime($model->completeDate);
             } else {
                 $model->completeDate = $model->dueDate;
             }
         }
         // format association
         if ($model->associationId == '') {
             $model->associationId = 0;
         }
         $association = $this->getAssociation($model->associationType, $model->associationId);
         if ($association) {
             $model->associationName = $association->name;
             if ($association->hasAttribute('lastActivity')) {
                 $association->lastActivity = time();
                 $association->update(array('lastActivity'));
                 X2Flow::trigger('RecordUpdateTrigger', array('model' => $association));
             }
         } else {
             $model->associationName = 'none';
         }
         if ($model->associationName == 'None' && $model->associationType != 'none') {
             $model->associationName = ucfirst($model->associationType);
         }
         if (in_array($_POST['SelectedTab'], array('log-a-call', 'new-comment', 'log-time-spent'))) {
             // Set the complete date accordingly:
             if (!empty($_POST[get_class($model)]['completeDate'])) {
                 $model->completeDate = Formatter::parseDateTime($_POST[get_class($model)]['completeDate']);
             }
             foreach (array('dueDate', 'completeDate') as $attr) {
                 if (empty($model->{$attr})) {
                     $model->{$attr} = time();
                 }
             }
             if ($model->dueDate > $model->completeDate) {
                 // User specified a negative time range! Let's say that the
                 // starting time is equal to when it ended (which is earlier)
                 $model->dueDate = $model->completeDate;
             }
             $model->complete = 'Yes';
             $model->visibility = '1';
             $model->assignedTo = Yii::app()->user->getName();
             $model->completedBy = Yii::app()->user->getName();
             if ($_POST['SelectedTab'] == 'log-a-call') {
                 $model->type = 'call';
             } elseif ($_POST['SelectedTab'] == 'log-time-spent') {
                 $model->type = 'time';
             } else {
                 $model->type = 'note';
             }
         }
         if (in_array($model->type, array('call', 'time', 'note'))) {
             $event = new Events();
             $event->associationType = 'Actions';
             $event->type = 'record_create';
             $event->user = Yii::app()->user->getName();
             $event->visibility = $model->visibility;
             $event->subtype = $model->type;
         }
         // save model
         $model->createDate = time();
         if (!empty($model->type)) {
             $model->disableBehavior('changelog');
         }
         if ($model->save()) {
             // action saved to database *
             if (isset($_POST['Actions']['reminder']) && $_POST['Actions']['reminder']) {
                 $model->createNotifications($_POST['notificationUsers'], $model->dueDate - $_POST['notificationTime'] * 60, 'action_reminder');
             }
             X2Model::updateTimerTotals($model->associationId, X2Model::getModelName($model->associationType));
             if (isset($event)) {
                 $event->associationId = $model->id;
                 $event->save();
             }
             $model->syncGoogleCalendar('create', true);
         } else {
             if ($model->hasErrors('verifyCode')) {
                 echo CJSON::encode(array('error' => $model->getError('verifyCode')));
                 Yii::app()->end();
             }
         }
         echo CJSON::encode(array('success'));
         Yii::app()->end();
     } else {
         throw new CHttpException(400, Yii::t('app', 'Bad request'));
     }
 }
Exemplo n.º 10
0
 /**
  * Marks the action incomplete and updates the record.
  * @return boolean whether or not the action updated successfully
  */
 public function uncomplete()
 {
     $this->complete = 'No';
     $this->completedBy = null;
     $this->completeDate = null;
     $this->disableBehavior('changelog');
     if ($result = $this->update()) {
         X2Flow::trigger('ActionUncompleteTrigger', array('model' => $this, 'user' => Yii::app()->user->getName()));
     }
     $this->enableBehavior('changelog');
     return $result;
 }
Exemplo n.º 11
0
 /**
  * Removes the specified tag(s) from the owner model
  * @param mixed $tags a string or array of strings containing tags
  * @return boolean whether or not at least one tag was deleted successfully
  */
 public function removeTags($tags)
 {
     $result = false;
     $removedTags = array();
     $tags = Tags::normalizeTags((array) $tags);
     foreach ((array) $tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         $attributes = array('type' => get_class($this->getOwner()), 'itemId' => $this->getOwner()->id, 'tag' => $tag);
         if ($this->hasTag($tag) && CActiveRecord::model('Tags')->deleteAllByAttributes($attributes) > 0) {
             if (false !== ($offset = array_search($tag, $this->_tags))) {
                 unset($this->_tags[$offset]);
             }
             // update tag cache
             $removedTags[] = $tag;
             $result = true;
         }
     }
     if ($this->flowTriggersEnabled) {
         X2Flow::trigger('RecordTagRemoveTrigger', array('model' => $this->getOwner(), 'tags' => $removedTags));
     }
     return $result;
 }
Exemplo n.º 12
0
 /**
  * Runs the user_logout automation trigger
  *
  * @return boolean whether or not to logout
  */
 protected function beforeLogout()
 {
     X2Flow::trigger('UserLogoutTrigger', array('user' => $this->getName()));
     return parent::beforeLogout();
 }
Exemplo n.º 13
0
 /**
  * Marks this campaign/newsletter item as unsubscribed.
  * If a contact record is available, unsubscribe them from all other lists as well.
  */
 public function unsubscribe($email = null)
 {
     if ($this->opened == 0) {
         $this->markOpened();
     }
     // mark as opened, run automation for email open
     if ($this->unsubscribed == 0) {
         $this->unsubscribed = time();
         $this->update(array('unsubscribed'));
     }
     // unsubscribe this email from all other newsletters
     CActiveRecord::model('X2ListItem')->updateAll(array('unsubscribed' => time()), 'emailAddress=:email AND unsubscribed=0', array('email' => $this->emailAddress));
     if ($this->list->campaign !== null) {
         if ($this->contact !== null) {
             // regular campaign
             // update the contact
             $this->contact->doNotEmail = true;
             $this->contact->lastActivity = time();
             $this->contact->update(array('doNotEmail', 'lastActivity'));
             X2Flow::trigger('CampaignUnsubscribeTrigger', array('model' => $this->contact, 'campaign' => $this->list->campaign->name));
         } elseif (isset($this->list)) {
             // no contact, must be a newsletter
             X2Flow::trigger('NewsletterUnsubscribeTrigger', array('item' => $this, 'email' => $this->emailAddress, 'campaign' => $this->list->campaign->name));
         }
     }
 }
Exemplo n.º 14
0
 /**
  * Trigger the X2Workflow RecordCreateTrigger on the imported models
  * @param array $importedIds List of record ids
  * @param string $type Model name
  */
 protected function triggerImportedRecords($importedIds, $type)
 {
     foreach ($importedIds as $id) {
         $model = X2Model::model($type)->findByPk($id);
         X2Flow::trigger('RecordCreateTrigger', array('model' => $model));
     }
 }
Exemplo n.º 15
0
 private function handleWebleadFormSubmission(X2Model $model, $extractedParams)
 {
     $newRecord = $model->isNewRecord;
     if (isset($_POST['Contacts'])) {
         $model->createEvent = false;
         $model->setX2Fields($_POST['Contacts'], true);
         // Extra sanitizing
         $p = Fields::getPurifier();
         foreach ($model->attributes as $name => $value) {
             if ($name != $model->primaryKey() && !empty($value)) {
                 $model->{$name} = $p->purify($value);
             }
         }
         $now = time();
         //require email field, check format
         /*if(preg_match(
               "/[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/",
               $_POST['Contacts']['email']) == 0) {
               $this->renderPartial('application.components.views.webFormSubmit',
                   array (
                       'type' => 'weblead',
                       'error' => Yii::t('contacts', 'Invalid Email Address')
                   )
               );
               return;
           }*/
         if (empty($model->visibility)) {
             $model->visibility = 1;
         }
         $model->validate(null, false);
         if (!$model->hasErrors()) {
             $duplicates = array();
             if (!empty($model->email)) {
                 //find any existing contacts with the same contact info
                 $criteria = new CDbCriteria();
                 $criteria->compare('email', $model->email, false, "OR");
                 $emailFields = Yii::app()->db->createCommand()->select('fieldName')->from('x2_fields')->where('modelName = "Contacts" AND type = "email"')->queryColumn();
                 foreach ($emailFields as $field) {
                     $criteria->compare($field, $model->email, false, "OR");
                 }
                 $duplicates = $model->findAll($criteria);
             }
             if (count($duplicates) > 0) {
                 //use existing record, update background info
                 $newBgInfo = $model->backgroundInfo;
                 $model = $duplicates[0];
                 $oldBgInfo = $model->backgroundInfo;
                 if ($newBgInfo !== $oldBgInfo) {
                     $model->backgroundInfo .= ($oldBgInfo && $newBgInfo ? "\n" : '') . $newBgInfo;
                 }
                 $success = $model->save();
             } else {
                 //create new record
                 $model->assignedTo = $this->controller->getNextAssignee();
                 $model->visibility = 1;
                 $model->createDate = $now;
                 $model->lastUpdated = $now;
                 $model->updatedBy = 'admin';
                 $success = $model->save();
                 //TODO: upload profile picture url from webleadfb
             }
             if ($success) {
                 if ($extractedParams['generateLead']) {
                     self::generateLead($model, $extractedParams['leadSource']);
                 }
                 if ($extractedParams['generateAccount']) {
                     self::generateAccount($model);
                 }
                 self::addTags($model);
                 $tags = !isset($_POST['tags']) || empty($_POST['tags']) ? array() : explode(',', $_POST['tags']);
                 if ($newRecord) {
                     X2Flow::trigger('WebleadTrigger', array('model' => $model, 'tags' => $tags));
                 }
                 //use the submitted info to create an action
                 $action = new Actions();
                 $action->actionDescription = Yii::t('contacts', 'Web Lead') . "\n\n" . Yii::t('contacts', 'Name') . ': ' . CHtml::decode($model->firstName) . " " . CHtml::decode($model->lastName) . "\n" . Yii::t('contacts', 'Email') . ": " . CHtml::decode($model->email) . "\n" . Yii::t('contacts', 'Phone') . ": " . CHtml::decode($model->phone) . "\n" . Yii::t('contacts', 'Background Info') . ": " . CHtml::decode($model->backgroundInfo);
                 // create action
                 $action->type = 'note';
                 $action->assignedTo = $model->assignedTo;
                 $action->visibility = '1';
                 $action->associationType = 'contacts';
                 $action->associationId = $model->id;
                 $action->associationName = $model->name;
                 $action->createDate = $now;
                 $action->lastUpdated = $now;
                 $action->completeDate = $now;
                 $action->complete = 'Yes';
                 $action->updatedBy = 'admin';
                 $action->save();
                 // create a notification if the record is assigned to someone
                 $event = new Events();
                 $event->associationType = 'Contacts';
                 $event->associationId = $model->id;
                 $event->user = $model->assignedTo;
                 $event->type = 'weblead_create';
                 $event->save();
                 if ($model->assignedTo != 'Anyone' && $model->assignedTo != '') {
                     $notif = new Notification();
                     $notif->user = $model->assignedTo;
                     $notif->createdBy = 'API';
                     $notif->createDate = time();
                     $notif->type = 'weblead';
                     $notif->modelType = 'Contacts';
                     $notif->modelId = $model->id;
                     $notif->save();
                     $profile = Profile::model()->findByAttributes(array('username' => $model->assignedTo));
                     /* send user that's assigned to this weblead an email if the user's email
                        address is set and this weblead has a user email template */
                     if ($profile !== null && !empty($profile->emailAddress)) {
                         $subject = Yii::t('marketing', 'New Web Lead');
                         $message = Yii::t('marketing', 'A new web lead has been assigned to you: ') . CHtml::link($model->firstName . ' ' . $model->lastName, array('/contacts/contacts/view', 'id' => $model->id)) . '.';
                         $address = array('to' => array(array('', $profile->emailAddress)));
                         $emailFrom = Credentials::model()->getDefaultUserAccount(Credentials::$sysUseId['systemNotificationEmail'], 'email');
                         if ($emailFrom == Credentials::LEGACY_ID) {
                             $emailFrom = array('name' => $profile->fullName, 'address' => $profile->emailAddress);
                         }
                         $status = $this->controller->sendUserEmail($address, $subject, $message, null, $emailFrom);
                     }
                 }
             } else {
                 $errMsg = 'Error: WebListenerAction.php: model failed to save';
                 /**/
                 AuxLib::debugLog($errMsg);
                 Yii::log($errMsg, '', 'application.debug');
             }
             $this->controller->renderPartial('application.components.views.webFormSubmit', array('type' => 'weblead'));
             Yii::app()->end();
             // success!
         }
     }
     $sanitizedGetParams = self::sanitizeGetParams();
     $this->controller->renderPartial('application.components.views.webForm', array_merge(array('type' => 'weblead'), $sanitizedGetParams));
 }
Exemplo n.º 16
0
 /**
  * Logs the deletion of the model
  */
 public function afterDelete($event)
 {
     $modelClass = get_class($this->getOwner());
     if ($modelClass === 'Actions' && $this->getOwner()->workflowId !== null) {
         // no deletion events for workflow actions, that's somebody else's problem
         return;
     }
     if ($this->createEvent) {
         $event = new Events();
         $event->type = 'record_deleted';
         $event->associationType = $modelClass;
         $event->associationId = $this->getOwner()->id;
         if ($this->getOwner()->hasAttribute('visibility')) {
             $event->visibility = $this->getOwner()->visibility;
         }
         $event->text = $this->getOwner()->name;
         $event->user = $this->editingUsername;
         $event->save();
     }
     $log = new Changelog();
     $log->type = $modelClass;
     $log->itemId = $this->getOwner()->id;
     $log->recordName = $this->getOwner()->name;
     $log->changed = 'delete';
     $log->changedBy = $this->editingUsername;
     $log->timestamp = time();
     $log->save();
     X2Flow::trigger('RecordDeleteTrigger', array('model' => $this->getOwner()));
 }
Exemplo n.º 17
0
 public function actionList($id = null)
 {
     $list = X2List::load($id);
     if (!isset($list)) {
         Yii::app()->user->setFlash('error', Yii::t('app', 'The requested page does not exist.'));
         $this->redirect(array('lists'));
     }
     $model = new Contacts('search');
     Yii::app()->user->setState('vcr-list', $id);
     $dataProvider = $model->searchList($id);
     $list->count = $dataProvider->totalItemCount;
     $list->runWithoutBehavior('X2FlowTriggerBehavior', function () use($list) {
         $list->save();
     });
     X2Flow::trigger('RecordViewTrigger', array('model' => $list));
     $this->render('list', array('listModel' => $list, 'dataProvider' => $dataProvider, 'model' => $model));
 }
Exemplo n.º 18
0
 public function recordEmailOpen()
 {
     if ($this->opened === null) {
         $openedAction = $this->createEmailOpenedAction();
         $event = $this->createEmailOpenedEvent();
         if ($openedAction->save() && $event->save()) {
             $this->opened = time();
             $this->update();
             $model = X2Model::getAssociationModel($openedAction->associationType, $openedAction->associationId);
             X2Flow::trigger('EmailOpenTrigger', array('model' => $model));
         }
     }
 }
Exemplo n.º 19
0
 private function handleWebleadFormSubmission(X2Model $model, $extractedParams)
 {
     $newRecord = $model->isNewRecord;
     if (isset($_POST['Contacts'])) {
         $model->createEvent = false;
         $model->setX2Fields($_POST['Contacts'], true);
         // Extra sanitizing
         $p = Fields::getPurifier();
         foreach ($model->attributes as $name => $value) {
             if ($name != $model->primaryKey() && !empty($value)) {
                 $model->{$name} = $p->purify($value);
             }
         }
         $now = time();
         $model->visibility = 1;
         $model->validate(null, false);
         if (!$model->hasErrors()) {
             $model->lastUpdated = $now;
             $model->updatedBy = 'admin';
             if ($model->asa('X2DuplicateBehavior') && $model->checkForDuplicates()) {
                 $duplicates = $model->getDuplicates();
                 $oldest = $duplicates[0];
                 $fields = $model->getFields(true);
                 foreach ($fields as $field) {
                     if (!in_array($field->fieldName, $model->X2MergeableBehavior->restrictedFields) && !is_null($model->{$field->fieldName})) {
                         if ($field->type === 'text' && !empty($oldest->{$field->fieldName})) {
                             $oldest->{$field->fieldName} .= "\n--\n" . $model->{$field->fieldName};
                         } else {
                             $oldest->{$field->fieldName} = $model->{$field->fieldName};
                         }
                     }
                 }
                 $model = $oldest;
                 $newRecord = $model->isNewRecord;
             }
             if ($newRecord) {
                 $model->createDate = $now;
                 $model->assignedTo = $this->controller->getNextAssignee();
             }
             $success = $model->save();
             //TODO: upload profile picture url from webleadfb
             if ($success) {
                 if ($extractedParams['generateLead']) {
                     self::generateLead($model, $extractedParams['leadSource']);
                 }
                 if ($extractedParams['generateAccount']) {
                     self::generateAccount($model);
                 }
                 self::addTags($model);
                 $tags = !isset($_POST['tags']) || empty($_POST['tags']) ? array() : explode(',', $_POST['tags']);
                 if ($newRecord) {
                     X2Flow::trigger('WebleadTrigger', array('model' => $model, 'tags' => $tags));
                 }
                 //use the submitted info to create an action
                 Actions::associateAction($model, array('actionDescription' => Yii::t('contacts', 'Web Lead') . "\n\n" . Yii::t('contacts', 'Name') . ': ' . CHtml::decode($model->firstName) . " " . CHtml::decode($model->lastName) . "\n" . Yii::t('contacts', 'Email') . ": " . CHtml::decode($model->email) . "\n" . Yii::t('contacts', 'Phone') . ": " . CHtml::decode($model->phone) . "\n" . Yii::t('contacts', 'Background Info') . ": " . CHtml::decode($model->backgroundInfo), 'type' => 'note'));
                 // create a notification if the record is assigned to someone
                 $event = new Events();
                 $event->associationType = 'Contacts';
                 $event->associationId = $model->id;
                 $event->user = $model->assignedTo;
                 $event->type = 'weblead_create';
                 $event->save();
                 if ($model->assignedTo != 'Anyone' && $model->assignedTo != '') {
                     $notif = new Notification();
                     $notif->user = $model->assignedTo;
                     $notif->createdBy = 'API';
                     $notif->createDate = time();
                     $notif->type = 'weblead';
                     $notif->modelType = 'Contacts';
                     $notif->modelId = $model->id;
                     $notif->save();
                     $profile = Profile::model()->findByAttributes(array('username' => $model->assignedTo));
                     /* send user that's assigned to this weblead an email if the user's email
                        address is set and this weblead has a user email template */
                     if ($profile !== null && !empty($profile->emailAddress)) {
                         $subject = Yii::t('marketing', 'New Web Lead');
                         $message = Yii::t('marketing', 'A new web lead has been assigned to you: ') . CHtml::link($model->firstName . ' ' . $model->lastName, array('/contacts/contacts/view', 'id' => $model->id)) . '.';
                         $address = array('to' => array(array('', $profile->emailAddress)));
                         $emailFrom = Credentials::model()->getDefaultUserAccount(Credentials::$sysUseId['systemNotificationEmail'], 'email');
                         if ($emailFrom == Credentials::LEGACY_ID) {
                             $emailFrom = array('name' => $profile->fullName, 'address' => $profile->emailAddress);
                         }
                         $status = $this->controller->sendUserEmail($address, $subject, $message, null, $emailFrom);
                     }
                 }
             } else {
                 $errMsg = 'Error: WebListenerAction.php: model failed to save';
                 /**/
                 AuxLib::debugLog($errMsg);
                 Yii::log($errMsg, '', 'application.debug');
             }
             $this->controller->renderPartial('application.components.views.webFormSubmit', array('type' => 'weblead', 'redirectUrl' => $extractedParams['redirectUrl']));
             Yii::app()->end();
             // success!
         }
     }
     $sanitizedGetParams = self::sanitizeGetParams();
     $this->controller->renderPartial('application.components.views.webForm', array_merge(array('type' => 'weblead'), $sanitizedGetParams));
 }