diff --git a/code/ContactFormController.php b/code/ContactFormController.php
index afd9097..04a1941 100755
--- a/code/ContactFormController.php
+++ b/code/ContactFormController.php
@@ -1,14 +1,16 @@
setTitle(_t('ContactPage.NAMEINPUT',"Name *")),
- TextField::create("Cellphone")->setTitle(_t('ContactPage.CELLPHONE',"Cellphone")),
- EmailField::create("Email")->setTitle(_t('ContactPage.EMAIL',"Email address"))->setAttribute('type', 'email'),
- TextareaField::create("Question")->setTitle(_t('ContactPage.QUESTION',"Question *"))
- );
- $this->extend('updateContactForm', $fields);
+ }
+
+ public function ContactForm()
+ {
+ // Create fields
+ $fields = new FieldList(
+ TextField::create('Name')->setTitle(_t('ContactPage.NAMEINPUT', "Name *")),
+ TextField::create("Cellphone")->setTitle(_t('ContactPage.CELLPHONE', "Cellphone")),
+ EmailField::create("Email")->setTitle(_t('ContactPage.EMAIL', "Email address"))->setAttribute('type', 'email'),
+ TextareaField::create("Question")->setTitle(_t('ContactPage.QUESTION', "Question *"))
+ );
+ $this->extend('updateContactForm', $fields);
- // Create action
- $send = new FormAction('SendContactForm', _t('ContactPage.SEND',"Send"));
- $send->addExtraClass("success btn");
+ // Create action
+ $send = new FormAction('SendContactForm', _t('ContactPage.SEND', "Send"));
+ $send->addExtraClass("success btn");
- $actions = new FieldList(
- $send
- );
- // Create action
- $validator = new RequiredFields('Name', 'Email', 'Question');
- return new Form($this, 'ContactForm', $fields, $actions, $validator);
- }
+ $actions = new FieldList(
+ $send
+ );
+ // Create action
+ $validator = new RequiredFields('Name', 'Email', 'Question');
+ return new Form($this, 'ContactForm', $fields, $actions, $validator);
+ }
- function SendContactForm($data, $form) {
- //saves the question in the database
- $CustomerQuestion = new CustomerQuestion();
- $form->saveInto($CustomerQuestion);
- $CustomerQuestion->write();
-
- $cp = DataObject::get_one("ContactPage");
+ public function SendContactForm($data, $form)
+ {
+ //saves the question in the database
+ $CustomerQuestion = new CustomerQuestion();
+ $form->saveInto($CustomerQuestion);
+ $CustomerQuestion->write();
+
+ $cp = DataObject::get_one("ContactPage");
- //Sets data
- $From = $data['Email'];
- $To = $cp->Mailto;
- $Subject = _t('ContactPage.WEBSITECONTACTMESSAGE',"Website Contact message");
- $email = new Email($From, $To, $Subject);
- //set template
- $email->setTemplate('ContactEmail');
- //populate template
- $email->populateTemplate(array(
- "CustomerQuestionID" => $CustomerQuestion->ID,
- "Name" => $data["Name"],
- "Cellphone" => $data["Cellphone"],
- "Email" => $data["Email"],
- "Question" => $data["Question"]
- ));
- //send mail
- if ($email->send()) {
- Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/success");
- }else{
- Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error");
- }
- }
+ //Sets data
+ $From = $data['Email'];
+ $To = $cp->Mailto;
+ $Subject = _t('ContactPage.WEBSITECONTACTMESSAGE', "Website Contact message");
+ $email = new Email($From, $To, $Subject);
+ //set template
+ $email->setTemplate('ContactEmail');
+ //populate template
+ $email->populateTemplate(array(
+ "CustomerQuestionID" => $CustomerQuestion->ID,
+ "Name" => $data["Name"],
+ "Cellphone" => $data["Cellphone"],
+ "Email" => $data["Email"],
+ "Question" => $data["Question"]
+ ));
+ //send mail
+ if ($email->send()) {
+ Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/success");
+ } else {
+ Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error");
+ }
+ }
- public function error(){
- return $this->httpError(500);
- }
+ public function error()
+ {
+ return $this->httpError(500);
+ }
- public function success(){
- $renderedContent = $this->renderWith('Page', array('Content' => $this->SubmitText));
- return $renderedContent;
- }
-}
\ No newline at end of file
+ public function success()
+ {
+ $renderedContent = $this->renderWith('Page', array('Content' => $this->SubmitText));
+ return $renderedContent;
+ }
+}
diff --git a/code/ContactPage.php b/code/ContactPage.php
index 3d9c28e..2dd5bd6 100755
--- a/code/ContactPage.php
+++ b/code/ContactPage.php
@@ -5,39 +5,41 @@
class ContactPage extends Page
{
- static $icon = "CustomerQuestions/images/email.png";
- static $description = 'Contact form';
- static $allow_children = false;
- static $db = array(
- 'Mailto' => 'Varchar(100)', //Email address where submissions will go
- 'SubmitText' => 'HTMLText' //Text presented OnAfterSubmit
- );
+ public static $icon = "CustomerQuestions/images/email.png";
+ public static $description = 'Contact form';
+ public static $allow_children = false;
+ public static $db = array(
+ 'Mailto' => 'Varchar(100)', //Email address where submissions will go
+ 'SubmitText' => 'HTMLText' //Text presented OnAfterSubmit
+ );
- /**
- * We only admit one
- */
- function canCreate($member = null) {
- if(ContactPage::get()->Count()>1) {
- return false;
- } else {
- return true;
- }
- }
-
- //CMS fields
- function getCMSFields() {
- $contactTab = _t('ContactPage.CONTACT',"Contact");
- $fields = parent::getCMSFields();
- $fields->addFieldToTab("Root.".$contactTab, new TextField('Mailto', _t('ContactPage.EMAILSUBMISSIONSTO',"Email submissions to")));
- $fields->addFieldToTab("Root.".$contactTab, $submittext = new HTMLEditorField('SubmitText', _t('ContactPage.THANKYOUTEXT',"Thank you text"),10));
- return $fields;
- }
+ /**
+ * We only admit one
+ */
+ public function canCreate($member = null)
+ {
+ if (ContactPage::get()->Count()>1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ //CMS fields
+ public function getCMSFields()
+ {
+ $contactTab = _t('ContactPage.CONTACT', "Contact");
+ $fields = parent::getCMSFields();
+ $fields->addFieldToTab("Root.".$contactTab, new TextField('Mailto', _t('ContactPage.EMAILSUBMISSIONSTO', "Email submissions to")));
+ $fields->addFieldToTab("Root.".$contactTab, $submittext = new HTMLEditorField('SubmitText', _t('ContactPage.THANKYOUTEXT', "Thank you text"), 10));
+ return $fields;
+ }
}
/******************
* Controller
******************/
-class ContactPage_Controller extends ContactForm_Controller{
-
-}
\ No newline at end of file
+class ContactPage_Controller extends ContactForm_Controller
+{
+}
diff --git a/code/CustomerQuestion.php b/code/CustomerQuestion.php
index c83ed2c..84448de 100644
--- a/code/CustomerQuestion.php
+++ b/code/CustomerQuestion.php
@@ -1,68 +1,69 @@
"Varchar(255)",
- "Cellphone" => "Varchar",
- "Email" => "Varchar(255)",
- "Question" => "Text",
- "Answer" => "Text",
- "Answered" => "Boolean",
- );
+ public static $db = array(
+ "Name" => "Varchar(255)",
+ "Cellphone" => "Varchar",
+ "Email" => "Varchar(255)",
+ "Question" => "Text",
+ "Answer" => "Text",
+ "Answered" => "Boolean",
+ );
- //Fields to show in the DOM
- static $summary_fields = array(
- "Name" => "Name",
- "Email" => "Email"
- );
-
- public function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields->removeFieldFromTab("Root.Main","Answered");
- $fields->addFieldToTab("Root.Main", TextField::create('Name',_t('CustomerQuestion.NAME',"Name"))->setAttribute('readonly', true));
- $fields->addFieldToTab("Root.Main", TextField::create('Cellphone',_t('CustomerQuestion.CELLPHONE',"Cell Phone"))->setAttribute('readonly', true));
- $fields->addFieldToTab("Root.Main", TextField::create('Email',_t('CustomerQuestion.EMAIL',"Email"))->setAttribute('readonly', true));
- $fields->addFieldToTab("Root.Main", TextareaField::create('Question',_t('CustomerQuestion.QUESTION',"Question"))->setAttribute('readonly', true));
+ //Fields to show in the DOM
+ public static $summary_fields = array(
+ "Name" => "Name",
+ "Email" => "Email"
+ );
+
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
+ $fields->removeFieldFromTab("Root.Main", "Answered");
+ $fields->addFieldToTab("Root.Main", TextField::create('Name', _t('CustomerQuestion.NAME', "Name"))->setAttribute('readonly', true));
+ $fields->addFieldToTab("Root.Main", TextField::create('Cellphone', _t('CustomerQuestion.CELLPHONE', "Cell Phone"))->setAttribute('readonly', true));
+ $fields->addFieldToTab("Root.Main", TextField::create('Email', _t('CustomerQuestion.EMAIL', "Email"))->setAttribute('readonly', true));
+ $fields->addFieldToTab("Root.Main", TextareaField::create('Question', _t('CustomerQuestion.QUESTION', "Question"))->setAttribute('readonly', true));
- $answer = TextareaField::create('Answer',_t('CustomerQuestion.ANSWER',"Your Answer"));
+ $answer = TextareaField::create('Answer', _t('CustomerQuestion.ANSWER', "Your Answer"));
- if ($this->Answered) {
- $fields->addFieldToTab("Root.Main", $answer->setAttribute('readonly', true));
- }
- else{
- $fields->addFieldToTab("Root.Main", $answer);
- }
-
- $this->extend('updateCMSFields', $fields);
- return $fields;
- }
-
- public function onBeforeWrite(){
-
- parent::onBeforeWrite();
- // if this 2 conditions are met i know the user is inside the CMS and can answer the question
- if (!$this->Answered && !empty($this->Answer)) {
- //Set data
- $From = $this->Email;
- $cp = DataObject::get_one("ContactPage");
- $To = $cp->Mailto;
-
- $Subject = _t('CustomerQuestion.ANSWER',"Here is your Answer!");
- $Body = $this->Answer;
- $email = new Email($From, $To, $Subject, $Body);
- //set template
- $email->setTemplate('ContactAnswer');
- //send mail
- if ($email->send()) {
- $this->Answered = 1;
- return Injector::inst()->get("Dashboard")->Link();
- }else{
- Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error");
- }
- }
- }
-}
\ No newline at end of file
+ if ($this->Answered) {
+ $fields->addFieldToTab("Root.Main", $answer->setAttribute('readonly', true));
+ } else {
+ $fields->addFieldToTab("Root.Main", $answer);
+ }
+
+ $this->extend('updateCMSFields', $fields);
+ return $fields;
+ }
+
+ public function onBeforeWrite()
+ {
+ parent::onBeforeWrite();
+ // if this 2 conditions are met i know the user is inside the CMS and can answer the question
+ if (!$this->Answered && !empty($this->Answer)) {
+ //Set data
+ $From = $this->Email;
+ $cp = DataObject::get_one("ContactPage");
+ $To = $cp->Mailto;
+
+ $Subject = _t('CustomerQuestion.ANSWER', "Here is your Answer!");
+ $Body = $this->Answer;
+ $email = new Email($From, $To, $Subject, $Body);
+ //set template
+ $email->setTemplate('ContactAnswer');
+ //send mail
+ if ($email->send()) {
+ $this->Answered = 1;
+ return Injector::inst()->get("Dashboard")->Link();
+ } else {
+ Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error");
+ }
+ }
+ }
+}
diff --git a/code/CustomerQuestionsAdmin.php b/code/CustomerQuestionsAdmin.php
index 314de89..bd9a1f4 100644
--- a/code/CustomerQuestionsAdmin.php
+++ b/code/CustomerQuestionsAdmin.php
@@ -1,12 +1,14 @@
get("Dashboard")->Link();
- }
-}
\ No newline at end of file
+class CustomerQuestionsAdmin extends ModelAdmin
+{
+ public static $managed_models = array('CustomerQuestion'); // Can manage multiple models
+ public static $url_segment = 'customer-questions';
+ public static $menu_title = 'Customer Questions';
+ public $showImportForm = false;
+
+ public function BackLink()
+ {
+ return Injector::inst()->get("Dashboard")->Link();
+ }
+}
diff --git a/code/DashboardCustomerQuestions.php b/code/DashboardCustomerQuestions.php
index 11bf5be..80ff437 100644
--- a/code/DashboardCustomerQuestions.php
+++ b/code/DashboardCustomerQuestions.php
@@ -8,65 +8,68 @@
* @author Franciso Arenas
*/
-class DashboardCustomerQuestions extends DashboardPanel {
-
-
- static $db = array (
- 'Count' => 'Int'
- );
-
- static $defaults = array (
- 'Count' => 10
- );
-
- static $icon = "CustomerQuestions/images/email-dashboard.png";
-
-
- static $priority = 10;
-
-
- public function getLabel() {
- return _t('CustomerQuestions.CUSTOMERQUESTIONS','Customer Questions');
- }
-
- public function getDescription() {
- return _t('CustomerQuestions.DESCRIPTION','Shows a linked list of recently contact forms submited to our site');
- }
-
-
- public function PanelHolder() {
- Requirements::css("CustomerQuestions/css/CustomerQuestions.css");
- return $this->renderWith($this->holderTemplate);
- }
-
-
- public function getConfiguration() {
- $fields = parent::getConfiguration();
- $fields->push(TextField::create("Count",_t('DashboardCustomerQuestions.COUNT','Number of submitted forms to display')));
- return $fields;
- }
-
-
-
- /**
- * Gets the recent edited pages, limited to a user provided number of records
- *
- * @return ArrayList
- */
- public function CustomerQuestions() {
- $records = CustomerQuestion::get()->sort("LastEdited DESC")->filter(array(
- "Answered" => "0"
- ))->limit($this->Count);
- $set = ArrayList::create(array());
- foreach($records as $r) {
- $set->push(ArrayData::create(array(
- 'AnswerLink' => "admin/customer-questions/CustomerQuestion/EditForm/field/CustomerQuestion/item/{$r->ID}/edit",
- 'Title' => $r->Question
- )));
-
- }
- return $set;
- }
-
-
-}
\ No newline at end of file
+class DashboardCustomerQuestions extends DashboardPanel
+{
+
+
+ public static $db = array(
+ 'Count' => 'Int'
+ );
+
+ public static $defaults = array(
+ 'Count' => 10
+ );
+
+ public static $icon = "CustomerQuestions/images/email-dashboard.png";
+
+
+ public static $priority = 10;
+
+
+ public function getLabel()
+ {
+ return _t('CustomerQuestions.CUSTOMERQUESTIONS', 'Customer Questions');
+ }
+
+ public function getDescription()
+ {
+ return _t('CustomerQuestions.DESCRIPTION', 'Shows a linked list of recently contact forms submited to our site');
+ }
+
+
+ public function PanelHolder()
+ {
+ Requirements::css("CustomerQuestions/css/CustomerQuestions.css");
+ return $this->renderWith($this->holderTemplate);
+ }
+
+
+ public function getConfiguration()
+ {
+ $fields = parent::getConfiguration();
+ $fields->push(TextField::create("Count", _t('DashboardCustomerQuestions.COUNT', 'Number of submitted forms to display')));
+ return $fields;
+ }
+
+
+
+ /**
+ * Gets the recent edited pages, limited to a user provided number of records
+ *
+ * @return ArrayList
+ */
+ public function CustomerQuestions()
+ {
+ $records = CustomerQuestion::get()->sort("LastEdited DESC")->filter(array(
+ "Answered" => "0"
+ ))->limit($this->Count);
+ $set = ArrayList::create(array());
+ foreach ($records as $r) {
+ $set->push(ArrayData::create(array(
+ 'AnswerLink' => "admin/customer-questions/CustomerQuestion/EditForm/field/CustomerQuestion/item/{$r->ID}/edit",
+ 'Title' => $r->Question
+ )));
+ }
+ return $set;
+ }
+}