array( 'tutoringSystems' => 'On-Line Tutoring Systems', 'leadershipTraining' => 'School Leadership Training', 'teacherTraining' => 'Teacher Training/Professional Development', 'enrollmentAdvertising' => 'Enrollment Advertising', 'reading' => 'Reading', 'schoolStartup' => 'New School Startup', 'schoolExpansion' => 'School Expansion' ) ); protected function _doInitDonateForm() { $options = array( 'formContent' => $this->_getDonateForm() ); $this->_doc->addScript('js/app/donate/form.js'); $this->_doc->addInitObject('app.donate.Form', array($options)); $this->_doc->addScript('js/jquery-autoNumeric.js'); return $this; } protected function _getDonateForm() { $smarty = $this->_doc->getSmarty(); $smarty->assign('states', array('' => 'Select One') + $this->dataObj->getDState4Select(array('title', 'title'))); return $smarty->fetch('Donate/form.tpl'); } protected function _doGetDonateNeedsBlock() { $this->_doc->display404(); return $this; } protected function _doGetDonateNeedsBlockAjax() { $formId = Qs_Request::getPostValue('formId'); if($formId && isset($this->_donateNeeds[$formId])) { $smarty = $this->_doc->getSmarty(); $smarty->assign('needs', $this->_donateNeeds[$formId]); $smarty->assign('formId', $formId); $result['formContent'] = $smarty->fetch('Donate/donate-needs.tpl'); $result['result'] = 'ok'; } else { $smarty = $this->_doc->getSmarty(); $smarty->assign('formId', $formId); $result['formContent'] = $smarty->fetch('Donate/donate-total.tpl'); $result['result'] = 'total'; } $this->_displayJson($result); } protected function _doSubmitDonate() { $this->_doc->display404(); return $this; } protected function _doSubmitDonateAjax() { $data = Qs_Request::getPost(); $this->_prepareDonateData($data); if($this->_saveSubmittedData($data)) { $result['result'] = 'ok'; } else { $result['result'] = 'error'; } $this->_displayJson($result); } protected function _prepareDonateData(&$data) { $donationNeeds = ''; foreach ($data['donationNeeds'] as $key => $value) { if ($value == 'y') { $donationNeeds .= $this->_donateNeeds[$data['formId']][$key]; if ($data['amount'][$key]) { $donationNeeds .= ' - $' . $data['amount'][$key]; } $donationNeeds .= '; '; } } unset($data['donationNeeds']); unset($data['amount']); $data['needs'] = $donationNeeds; return $this; } protected function _saveSubmittedData($data) { if (($e = $this->dataObj->insert($data)) instanceof Exception) { return false; } else { $data['id'] = $e; $this->_sendAdminNotification($data); return $e; } } protected function _getMailData(array $data) { $mailData = array( 'donateType' => ($data['donateType']) ? htmlspecialchars($data['donateType']) : '-', 'name' => ($data['name']) ? htmlspecialchars($data['name']) : '-', 'address' => ($data['address']) ? htmlspecialchars($data['address']) : '-', 'city' => ($data['city']) ? htmlspecialchars($data['city']) : '-', 'state' => ($data['state']) ? htmlspecialchars($data['state']) : '-', 'zip' => ($data['zip']) ? htmlspecialchars($data['zip']) : '-', 'needs' => ($data['needs']) ? $this->_renderDonateNeedsBlock($data['needs']) : null, 'totalAmount' => ($data['totalAmount']) ? $this->_renderTotalAmountBlock($data['totalAmount']) : null, 'link' => BASE_URL . '/' . Qs_SiteMap::findFirst(null, array('type' => 'Donate_Admin'), null, 'fullAlias') . '?action=view&id=' . $data['id'], ); return $mailData; } protected function _renderDonateNeedsBlock($data) { $html = ''; $needs = array_filter(explode('; ', $data)); if (count($needs)) { $html .= '
I wish to donate to a specific need:'; $html .= ''; } return $html; } protected function _renderTotalAmountBlock($totalAmount) { $html = 'Total donation amount: ' . htmlspecialchars('$' . $totalAmount) . '
'; return $html; } protected function _sendAdminNotification($data) { $subject = App_Settings_Obj::get($this->_settingsPrefix . 'Subject'); $body = App_Settings_Obj::get($this->_settingsPrefix . 'Body'); $from = App_Settings_Obj::get($this->_settingsPrefix . 'From'); $to = App_Settings_Obj::getFormEmails($this->_settingsPrefix . 'To'); if (empty($to)) { return false; } $mailData = $this->_getMailData($data); foreach ($mailData as $field => $value) { $body = str_replace('{' . $field . '}', $value, $body); } $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, BASE_URL); $mail->setHtml($body, null, WWW_PATH); $mail->addTo($to); $mail->send(); return $this; } }