/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); if (!isset($model)) { Yii::app()->user->setFlash('error', Yii::t('app', 'The requested page does not exist.')); $this->redirect(array('index')); } if (isset($_POST['Campaign'])) { $oldAttributes = $model->attributes; $model->setX2Fields($_POST['Campaign']); $model->content = Fields::getPurifier()->purify($model->content); $model->content = Formatter::restoreInsertableAttributes($model->content); if ($model->save()) { CampaignAttachment::model()->deleteAllByAttributes(array('campaign' => $model->id)); if (isset($_POST['AttachmentFiles'])) { if (isset($_POST['AttachmentFiles']['id'])) { foreach ($_POST['AttachmentFiles']['id'] as $mediaId) { $attachment = new CampaignAttachment(); $attachment->campaign = $model->id; $attachment->media = $mediaId; $attachment->save(); } } } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
public function setActionDescription($value) { // Magic setter stores value in actionDescriptionTemp until saved $this->actionDescriptionTemp = Fields::getPurifier()->purify($value); }
private function handleServiceFormSubmission($model, $extractedParams) { if (isset($_POST['Services'])) { // web form submitted if (isset($_POST['Services']['firstName'])) { $firstName = $_POST['Services']['firstName']; $fullName = $firstName; } if (isset($_POST['Services']['lastName'])) { $lastName = $_POST['Services']['lastName']; if (isset($fullName)) { $fullName .= ' ' . $lastName; } else { $fullName = $lastName; } } if (isset($_POST['Services']['email'])) { $email = $_POST['Services']['email']; } if (isset($_POST['Services']['phone'])) { $phone = $_POST['Services']['phone']; } if (isset($_POST['Services']['desription'])) { $description = $_POST['Services']['description']; } // Extra sanitizing $p = Fields::getPurifier(); foreach ($model->attributes as $name => $value) { if ($name != $model->primaryKey() && !empty($value)) { $model->{$name} = $p->purify($value); } } if (isset($email) && $email) { $contact = Contacts::model()->findByAttributes(array('email' => $email)); } else { $contact = false; } if ($contact) { $model->contactId = $contact->nameId; } else { $model->contactId = "Unregistered"; } if (isset($fullName) || isset($email)) { $model->subject = Yii::t('services', 'Web Form Case entered by {name}', array('{name}' => isset($fullName) ? $fullName : $email)); } else { $model->subject = Yii::t('services', 'Web Form Case'); } $model->origin = 'Web'; if (!isset($model->impact) || $model->impact == '') { $model->impact = Yii::t('services', '3 - Moderate'); } if (!isset($model->status) || $model->status == '') { $model->status = Yii::t('services', 'New'); } if (!isset($model->mainIssue) || $model->mainIssue == '') { $model->mainIssue = Yii::t('services', 'General Request'); } if (!isset($model->subIssue) || $model->subIssue == '') { $model->subIssue = Yii::t('services', 'Other'); } $model->assignedTo = $this->controller->getNextAssignee(); if (isset($email)) { $model->email = CHtml::encode($email); } $now = time(); $model->createDate = $now; $model->lastUpdated = $now; $model->updatedBy = 'admin'; if (isset($description)) { $model->description = CHtml::encode($description); } if (!$model->hasErrors()) { if ($model->save()) { $model->name = $model->id; $model->update(array('name')); self::addTags($model); //use the submitted info to create an action $action = new Actions(); $action->actionDescription = Yii::t('contacts', 'Web Form') . "\n\n" . (isset($fullName) ? Yii::t('contacts', 'Name') . ': ' . $fullName . "\n" : '') . (isset($email) ? Yii::t('contacts', 'Email') . ": " . $email . "\n" : '') . (isset($phone) ? Yii::t('contacts', 'Phone') . ": " . $phone . "\n" : '') . (isset($description) ? Yii::t('services', 'Description') . ": " . $description : ''); // create action $action->type = 'note'; $action->assignedTo = $model->assignedTo; $action->visibility = '1'; $action->associationType = 'services'; $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(); if (isset($email)) { //send email $emailBody = Yii::t('services', 'Hello') . ' ' . $fullName . ",<br><br>"; $emailBody .= Yii::t('services', 'Thank you for contacting our Technical Support ' . 'team. This is to verify we have received your request for Case# ' . '{casenumber}. One of our Technical Analysts will contact you shortly.', array('{casenumber}' => $model->id)); $emailBody = Yii::app()->settings->serviceCaseEmailMessage; if (isset($firstName)) { $emailBody = preg_replace('/{first}/u', $firstName, $emailBody); } if (isset($lastName)) { $emailBody = preg_replace('/{last}/u', $lastName, $emailBody); } if (isset($phone)) { $emailBody = preg_replace('/{phone}/u', $phone, $emailBody); } if (isset($email)) { $emailBody = preg_replace('/{email}/u', $email, $emailBody); } if (isset($description)) { $emailBody = preg_replace('/{description}/u', $description, $emailBody); } $emailBody = preg_replace('/{case}/u', $model->id, $emailBody); $emailBody = preg_replace('/\\n|\\r\\n/', "<br>", $emailBody); $uniqueId = md5(uniqid(rand(), true)); $emailBody .= '<img src="' . $this->controller->createAbsoluteUrl('/actions/actions/emailOpened', array('uid' => $uniqueId, 'type' => 'open')) . '"/>'; $emailSubject = Yii::app()->settings->serviceCaseEmailSubject; if (isset($firstName)) { $emailSubject = preg_replace('/{first}/u', $firstName, $emailSubject); } if (isset($lastName)) { $emailSubject = preg_replace('/{last}/u', $lastName, $emailSubject); } if (isset($phone)) { $emailSubject = preg_replace('/{phone}/u', $phone, $emailSubject); } if (isset($email)) { $emailSubject = preg_replace('/{email}/u', $email, $emailSubject); } if (isset($description)) { $emailSubject = preg_replace('/{description}/u', $description, $emailSubject); } $emailSubject = preg_replace('/{case}/u', $model->id, $emailSubject); if (Yii::app()->settings->serviceCaseEmailAccount != Credentials::LEGACY_ID) { $from = (int) Yii::app()->settings->serviceCaseEmailAccount; } else { $from = array('name' => Yii::app()->settings->serviceCaseFromEmailName, 'address' => Yii::app()->settings->serviceCaseFromEmailAddress); } $useremail = array('to' => array(array(isset($fullName) ? $fullName : '', $email))); $status = $this->controller->sendUserEmail($useremail, $emailSubject, $emailBody, null, $from); if ($status['code'] == 200) { if ($model->assignedTo != 'Anyone') { $profile = X2Model::model('Profile')->findByAttributes(array('username' => $model->assignedTo)); if (isset($profile)) { $useremail['to'] = array(array($profile->fullName, $profile->emailAddress)); $emailSubject = 'Service Case Created'; $emailBody = "A new service case, #" . $model->id . ", has been created in X2Engine. To view the case, click " . "this link: " . $model->getLink(); $status = $this->controller->sendUserEmail($useremail, $emailSubject, $emailBody, null, $from); } } //email action $action = new Actions(); $action->associationType = 'services'; $action->associationId = $model->id; $action->associationName = $model->name; $action->visibility = 1; $action->complete = 'Yes'; $action->type = 'email'; $action->completedBy = 'admin'; $action->assignedTo = $model->assignedTo; $action->createDate = time(); $action->dueDate = time(); $action->completeDate = time(); $action->actionDescription = '<b>' . $model->subject . "</b>\n\n" . $emailBody; if ($action->save()) { $track = new TrackEmail(); $track->actionId = $action->id; $track->uniqueId = $uniqueId; $track->save(); } } else { $errMsg = 'Error: actionWebForm.php: sendUserEmail failed'; /**/ AuxLib::debugLog($errMsg); Yii::log($errMsg, '', 'application.debug'); } } $this->controller->renderPartial('application.components.views.webFormSubmit', array('type' => 'service', 'caseNumber' => $model->id)); Yii::app()->end(); // success! } } } $sanitizedGetParams = self::sanitizeGetParams(); $this->controller->renderPartial('application.components.views.webForm', array_merge(array('model' => $model, 'type' => 'service'), $sanitizedGetParams)); }