/**
  * @param RedBeanModel $model
  */
 public function populateModel(&$model)
 {
     assert('$model instanceof ContactWebFormEntry');
     parent::populateModel($model);
     if (empty($this->seedData)) {
         $this->seedData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('ContactWebFormsModule', 'ContactWebFormEntry');
     }
     $contactFormAttributes = array();
     $contact = new Contact();
     $contact->owner = $model->contactWebForm->defaultOwner;
     $contact->state = $model->contactWebForm->defaultState;
     $contact->firstName = $contactFormAttributes['firstName'] = $this->seedData['firstName'][$this->index];
     $contact->lastName = $contactFormAttributes['lastName'] = $this->seedData['lastName'][$this->index];
     $contact->companyName = $contactFormAttributes['companyName'] = $this->seedData['companyName'][$this->index];
     $contact->jobTitle = $contactFormAttributes['jobTitle'] = $this->seedData['jobTitle'][$this->index];
     if ($contact->validate()) {
         $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_SUCCESS;
         $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_SUCCESS_MESSAGE;
         $contact->save();
     } else {
         $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_ERROR;
         $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_ERROR_MESSAGE;
         $contact = null;
     }
     $model->contact = $contact;
     $model->status = $contactWebFormEntryStatus;
     $model->message = $contactWebFormEntryMessage;
     $contactFormAttributes['owner'] = $model->contactWebForm->defaultOwner->id;
     $contactFormAttributes['state'] = $model->contactWebForm->defaultState->id;
     $model->serializedData = serialize($contactFormAttributes);
 }
Ejemplo n.º 2
0
 public function testCreateAndGetContactWebFormEntryById()
 {
     $allAttributes = ContactWebFormsUtil::getAllAttributes();
     $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle');
     $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes);
     $attributes = array_keys($contactFormAttributes);
     $this->assertTrue(ContactsModule::loadStartingData());
     $contactStates = ContactState::getByName('New');
     $contactWebForm = new ContactWebForm();
     $contactWebForm->name = 'Test Form';
     $contactWebForm->redirectUrl = 'http://google.com';
     $contactWebForm->submitButtonLabel = 'Save';
     $contactWebForm->defaultState = $contactStates[0];
     $contactWebForm->defaultOwner = Yii::app()->user->userModel;
     $contactWebForm->serializedData = serialize($attributes);
     $contactWebForm->save();
     $contact = new Contact();
     $contact->owner = $contactWebForm->defaultOwner;
     $contact->state = $contactWebForm->defaultState;
     $contact->firstName = 'Super';
     $contact->lastName = 'Man';
     $contact->jobTitle = 'Superhero';
     $contact->companyName = 'Test Inc.';
     if ($contact->validate()) {
         $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_SUCCESS;
         $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_SUCCESS_MESSAGE;
     } else {
         $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_ERROR;
         $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_ERROR_MESSAGE;
     }
     $contact->save();
     foreach ($contactFormAttributes as $attributeName => $attributeValue) {
         $contactFormAttributes[$attributeName] = $contact->{$attributeName};
     }
     $contactFormAttributes['owner'] = $contactWebForm->defaultOwner->id;
     $contactFormAttributes['state'] = $contactWebForm->defaultState->id;
     $contactWebFormEntry = new ContactWebFormEntry();
     $contactWebFormEntry->serializedData = serialize($contactFormAttributes);
     $contactWebFormEntry->status = $contactWebFormEntryStatus;
     $contactWebFormEntry->message = $contactWebFormEntryMessage;
     $contactWebFormEntry->contactWebForm = $contactWebForm;
     $contactWebFormEntry->contact = $contact;
     $this->assertTrue($contactWebFormEntry->save());
     $contactWebFormEntryId = $contactWebFormEntry->id;
     unset($contactWebFormEntry);
     $contactWebFormEntry = ContactWebFormEntry::getById($contactWebFormEntryId);
     $this->assertEquals('Test Form', $contactWebFormEntry->contactWebForm->name);
     $this->assertEquals('Super', $contactWebFormEntry->contact->firstName);
     $this->assertEquals('Man', $contactWebFormEntry->contact->lastName);
     $contactFormAttributes = unserialize($contactWebFormEntry->serializedData);
     $this->assertEquals('Super', $contactFormAttributes['firstName']);
     $this->assertEquals('Man', $contactFormAttributes['lastName']);
     $this->assertEquals('Superhero', $contactFormAttributes['jobTitle']);
     $this->assertEquals('Test Inc.', $contactFormAttributes['companyName']);
 }
Ejemplo n.º 3
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aContact !== null) {
             if (!$this->aContact->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aContact->getValidationFailures());
             }
         }
         if ($this->asfGuardUser !== null) {
             if (!$this->asfGuardUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
             }
         }
         if (($retval = UserPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collSessions !== null) {
             foreach ($this->collSessions as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSingleSignOnKeys !== null) {
             foreach ($this->collSingleSignOnKeys as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSystemEventSubscriptions !== null) {
             foreach ($this->collSystemEventSubscriptions as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSystemEventInstances !== null) {
             foreach ($this->collSystemEventInstances as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Ejemplo n.º 4
0
 /**
  * 浏览
  */
 public function actionShow($name)
 {
     $contactModel = new Contact();
     $title_alias = CHtml::encode(strip_tags($name));
     $bagecmsPageModel = Page::model()->find('title_alias=:titleAlias', array('titleAlias' => $title_alias));
     if (false == $bagecmsPageModel) {
         throw new CHttpException(404, '内容不存在');
     }
     $this->_seoTitle = empty($bagecmsPageModel->seo_title) ? $bagecmsPageModel->title . ' - ' . $this->_conf['site_name'] : $bagecmsPageModel->seo_title;
     $tpl = empty($bagecmsPageModel->template) ? 'show' : $bagecmsPageModel->template;
     if (isset($_POST['Contact'])) {
         $contactModel->attributes = $_POST['Contact'];
         if ($contactModel->validate() and $contactModel->save()) {
             Yii::app()->user->setFlash('success', '提交成功!');
         }
     }
     $this->render($tpl, array('bagecmsPage' => $bagecmsPageModel, 'title_alias' => $title_alias, 'contactModel' => $contactModel));
 }
Ejemplo n.º 5
0
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new Contact();
     $model->unsetAttributes();
     if (isset($_POST['Contact'])) {
         if (!Yii::app()->user->isGuest) {
             $model->name = User::getNameById(Yii::app()->user->id);
             $model->email = Yii::app()->user->email;
         }
         $model->attributes = $_POST['Contact'];
         if ($model->validate() && $model->save()) {
             $headers = "From: {$model->email}\r\nReply-To: {$model->email}";
             mail(Yii::app()->params['adminEmail'], $model->subject, $model->body, $headers);
             Yii::app()->user->setFlash('contact', '感谢您的意见,我会尽快回复!');
             $this->refresh();
         } else {
             //var_dump($model->errors);
         }
     }
     $this->render('contact', array('model' => $model));
 }
Ejemplo n.º 6
0
 public function actionAddContact()
 {
     $contact = new Contact();
     if (!empty($_POST)) {
         $contact->attributes = $_POST['Contact'];
         if (!$contact->validate()) {
             $errors = $contact->getErrors();
         } else {
             if (!$contact->save()) {
                 throw new Exception("Unable to save contact: " . print_r($contact->getErrors(), true));
             }
             Audit::add('admin-Contact', 'add', $contact->id);
             $this->redirect(array('/admin/editContact?contact_id=' . $contact->id));
         }
     }
     $this->render('/admin/addcontact', array('contact' => $contact, 'errors' => @$errors));
 }
Ejemplo n.º 7
0
 public function store_contact()
 {
     if ($this->isPostRequest()) {
         $input_data = Input::all();
         // input all data
         $model = new Contact();
         //save data into
         if ($model->validate($input_data)) {
             DB::beginTransaction();
             try {
                 $model->create($input_data);
                 DB::commit();
                 Session::flash('message', 'Submitted Successfully ! We will get back to you soon.');
             } catch (Exception $e) {
                 //If there are any exceptions, rollback the transaction`
                 DB::rollback();
                 Session::flash('danger', 'Failed !');
             }
         }
     } else {
         Session::flash('danger', 'Invalid Request !');
     }
     return Redirect::back();
 }
 protected static function attemptToMatchAndSaveLeadOrContact($emailMessage, $type, $emailMessageId)
 {
     assert('$type == "Contact" || $type == "Lead"');
     assert('is_int($emailMessageId)');
     if (isset($_POST[$type])) {
         if (isset($_POST['ajax']) && $_POST['ajax'] === strtolower($type) . '-inline-create-form-' . $emailMessageId) {
             $contact = new Contact();
             $contact->setAttributes($_POST[$type][$emailMessageId]);
             $contact->validate();
             $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($contact);
             echo CJSON::encode($errorData);
             Yii::app()->end(0, false);
         } else {
             $contact = new Contact();
             $contact->setAttributes($_POST[$type][$emailMessageId]);
             if (!$contact->save()) {
                 throw new FailedToSaveModelException();
             }
             ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($emailMessage, $contact);
             $emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_ARCHIVED);
             if (!$emailMessage->save()) {
                 throw new FailedToSaveModelException();
             }
         }
     }
 }
Ejemplo n.º 9
0
use Propel\Runtime\Propel;
use Propel\Runtime\Formatter\ObjectFormatter;
/* CONTACTS */
$app->get('/contacts', function ($request, $response, $args) {
    $contacts = ContactQuery::create()->find();
    $response->getBody()->write(parseToJSONArray($contacts));
    return $response;
});
$app->post('/contacts', function ($request, $response, $args) {
    $parsedBody = $request->getParsedBody();
    if ($parsedBody == null) {
        return err_general_error($response, "Provide a body to create a new contacts");
    }
    $contact = new Contact();
    $contact->fromArray($parsedBody);
    if ($contact->validate()) {
        $contact->save();
    } else {
        return err_general_error($response, "Validation failed");
    }
    /* Response with resulting contact */
    $response->getBody()->write($contact->toJSON());
    return $response;
});
$app->get('/contacts/{id}', function ($request, $response, $args) {
    $id = $request->getAttribute('id');
    $contact = ContactQuery::create()->findPK($id);
    $response->getBody()->write($contact->toJSON());
    return $response;
});
$app->put('/contacts/{id}', function ($request, $response, $args) {
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new Contact();
     if (isset($_POST['Contact'])) {
         $model->attributes = $_POST['Contact'];
         $model->createdatetime = new CDbExpression('NOW()');
         if ($model->validate()) {
             $model->save();
             $body = $model->fullname . '<br />Email: ' . $model->email . '<br />Điện thoại: ' . $model->phone . '<br />Chủ đề: ' . $model->title . '<br /><hr /><br />' . $model->content;
             $this->SendMail(array('mailto' => Config::model()->getValueByKey('address_received_mail'), 'replyto' => $model->email, 'subject' => $model->title, 'body' => $body));
             Yii::app()->user->setFlash('contact', 'Nội dung liên hệ của bạn đã được gửi đến chúng tôi. Chúng tôi sẽ phản hồi bạn trong thời gian sớm nhất. Xin chân thành cảm ơn!');
             $this->refresh();
         }
     }
     $this->pageTitle = Yii::t('site', 'Contact') . ' - ' . Config::model()->getValueByKey('sitetitle');
     $this->metaDescription = Config::model()->getValueByKey('metadescription');
     $this->metaKeywords = Config::model()->getValueByKey('metakeywords');
     $this->render('contact', array('model' => $model));
 }
Ejemplo n.º 11
0
 public function actionContact($uid)
 {
     $this->uid = $uid;
     $data = array('uid' => $uid, 'url' => "http://" . Yii::app()->params['bucket'] . "." . Yii::app()->params['domain'] . "/");
     //标签
     $data['labelInfo'] = $this->GetTags($uid);
     $contactModel = new Contact();
     if (isset($_POST['Contact'])) {
         $contactModel->attributes = $_POST['Contact'];
         $tmp = $_POST['Contact'];
         if ($contactModel->validate()) {
             $contactModel->time = time();
             $contactModel->userid = $uid;
             $tmp['uid'] = $uid;
             if ($contactModel->save()) {
                 Yii::app()->user->setFlash('contactstatus', 'YES,给Ta写信成功。(⊙_⊙)(⊙_⊙)(⊙_⊙)');
                 //$this->SendContactMessage($tmp);
                 $this->redirect(array("contact", 'uid' => $uid));
             } else {
                 Yii::app()->user->setFlash('contactstatus', 'Sorry,系统错误,写信失败。(>﹏<)');
                 $this->redirect(array("contact", 'uid' => $uid));
             }
         }
     }
     $data['contactModel'] = $contactModel;
     $this->render('contact', $data);
 }
Ejemplo n.º 12
0
 public function actionContact($who)
 {
     $this->uid = $uid = $who;
     $data = array('uid' => $uid, 'url' => "http://" . Yii::app()->params['bucket'] . "." . Yii::app()->params['domain'] . "/");
     $this->Myaccess($uid);
     $data['labelInfo'] = $this->getTags($uid);
     $contactModel = new Contact();
     if (isset($_POST['Contact'])) {
         $contactModel->attributes = $_POST['Contact'];
         $tmp = $_POST['Contact'];
         if ($contactModel->validate()) {
             $contactModel->time = time();
             $contactModel->userid = $uid;
             $tmp['uid'] = $uid;
             if ($contactModel->save()) {
                 Yii::app()->user->setFlash('contactstatus', 'YES,给Ta写信成功 :)');
                 $this->redirect(array("contact", 'who' => $uid));
             } else {
                 Yii::app()->user->setFlash('contactstatus', 'Sorry,系统错误,写信失败 :(');
                 $this->redirect(array("contact", 'who' => $uid));
             }
         }
     }
     $data['contactModel'] = $contactModel;
     $this->layout = "//layouts/empty";
     $this->render('contact', $data);
 }
Ejemplo n.º 13
0
 /**
  * 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, $sale_mode = 'N')
 {
     $model = $this->loadModel($id);
     $contact = Contact::model()->conatctByID($model->contact_id);
     $has_error = "";
     if (!$contact) {
         $contact = new Contact();
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (Yii::app()->user->checkAccess('client.update')) {
         if (isset($_POST['Client'])) {
             $model->attributes = $_POST['Client'];
             $contact->attributes = $_POST['Contact'];
             if ($_POST['Client']['year'] !== "" || $_POST['Client']['month'] !== "" || $_POST['Client']['day'] !== "") {
                 $dob = $_POST['Client']['year'] . '-' . $_POST['Client']['month'] . '-' . $_POST['Client']['day'];
                 $model->dob = $dob;
             }
             // validate BOTH $a and $b
             $valid = $model->validate();
             $valid = $contact->validate() && $valid;
             //if ($model->validate())
             if ($valid) {
                 $transaction = $model->dbConnection->beginTransaction();
                 try {
                     if (isset($_POST['Contact'])) {
                         $contact->save();
                         $model->contact_id = $contact->id;
                     }
                     if ($model->save()) {
                         $client_fname = $model->first_name . ' ' . $model->last_name;
                         Account::model()->saveAccount($model->id, $client_fname);
                         $price_tier_id = $model->price_tier_id;
                         $transaction->commit();
                         if ($sale_mode == 'Y') {
                             Yii::app()->shoppingCart->setCustomer($id);
                             Yii::app()->shoppingCart->setPriceTier($price_tier_id);
                             $this->redirect(array('saleItem/index'));
                         } else {
                             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, '<strong>' . ucfirst($model->first_name) . '</strong> have been saved successfully!');
                             $this->redirect(array('admin'));
                         }
                     }
                 } catch (Exception $e) {
                     $transaction->rollback();
                     print_r($e);
                 }
             } else {
                 $has_error = "has-error";
             }
         }
     } else {
         throw new CHttpException(403, 'You are not authorized to perform this action');
     }
     if (Yii::app()->request->isAjaxRequest) {
         $cs = Yii::app()->clientScript;
         $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false);
         echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, false)));
         Yii::app()->end();
     } else {
         $this->render('update', array('model' => $model, 'contact' => $contact, 'has_error' => $has_error));
     }
 }