/** * This is the main method of fire every event in RM core * * @param string $eventName event name - one of the RM_Notifications_Event::<const> * @param mixed $data information that related to event */ public function fire($eventName, $data) { foreach ($this->_observers as $observer) { $observer->notify($eventName, $data); RM_Log::toLog("Event Fired: " . $eventName); } }
function errorAction() { $error = $this->_getParam('error_handler'); $detailedErrorMessage = RM_Log::createErrorMessage($error->exception); $config = Zend_Registry::get('config'); RM_Log::toLog($detailedErrorMessage, RM_Log::ERR); if ((int) $config->get('errors')->get('debug') == 1) { $errorMessage = $detailedErrorMessage; ob_end_clean(); header('RMError: 1'); echo nl2br($errorMessage); die; } switch ($error->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found'); //TODO: add language constants, but better is to add a 404 page template $content = "Requested page not found."; break; default: $this->getResponse()->setHeader('RMError', '1'); //TODO: add language constants, but better is to add a 404 page template $content = "Sorry, there was a server error. Please contact to site administrator."; break; } $this->getResponse()->clearBody(); $this->view->content = $content; }
/** * Recalculate all for reservation, after some of the unit details has been changed * * @abstract * @param RM_Reservation_Row $reservation * @return bool */ function recalculate(RM_Reservation_Row $reservation) { $summaryModel = new RM_ReservationSummary(); $extrasModel = new RM_Extras(); $details = $reservation->getDetails(); foreach ($details as $detail) { $summaryRows = $summaryModel->fetchByReservationDetail($detail); foreach ($summaryRows as $summaryRow) { if ($summaryRow->type == self::SUMMARY_TYPE) { $extra = $extrasModel->find($summaryRow->row_id)->current(); if ($extra == null) { //IF this is a deprecated - total value remains the same continue; } $detailsObj = $detail->transform(); if ($detailsObj instanceof RM_Reservation_Details) { $summaryRow->total_amount = -$extra->calculate($detailsObj) * $summaryRow->value; $summaryRow->save(); } else { RM_Log::toLog("Extras Encountered Issues: " . print_r($detailsObj, true)); } } } } }
/** * this logs to the sytem log the application load time * NOTE: this code runs once at boot time so it is the ideal place to implecate * things that need a run-once at startup * * @return array that will be encoded to JSON */ public function logloadingtimeJsonAction() { RM_Log::toLog('Admin end loading time: ' . $this->_getParam('time'), RM_Log::INFO); // update load status $model = new RM_System(); $data = $model->setRunStatus(1); // check for new modules or plugins $extensions = RM_Environment::getInstance()->getOutOfDateExtensions(); // make a string of modules that have updates available $moduleNames = false; if (!empty($extensions['modules'])) { foreach ($extensions['modules'] as $module) { $moduleNames[] = $module; } $moduleNames = implode(",", $moduleNames); } // make a string of plugins that have updates available $pluginNames = false; if (!empty($extensions['plugins'])) { foreach ($extensions['plugins'] as $plugins) { $pluginsNames[] = $plugins; } $pluginsNames = implode(",", $pluginsNames); } $config = new RM_Config(); $licenceKey = false; if ($config->getValue('rm_config_licensekey') !== "") { $licenceKey = true; } return array('data' => array('success' => true, 'moduleupdates' => $moduleNames, 'pluginupdates' => $pluginNames, 'licensekey' => $licenceKey)); }
public static function toLog($message, $level = Zend_Log::INFO, $file = 'system_log.txt') { $filename = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getCorePath(), 'userdata', 'logs', $file)); if (is_file($filename) == false) { return false; } if (is_writable($filename) == false) { return false; } try { $stream = new Zend_Log_Writer_Stream($filename); $logger = new RM_Log($stream); $logger->log($message, $level); $stream->shutdown(); return true; } catch (Exception $e) { return false; } }
public function ipnAction() { RM_Log::toLog("PayPal ipnAction Called"); $this->_withoutView(); $provider = new RM_PayPal_Service(); $result = $provider->validateIPN(); RM_Log::toLog("PayPal ipnValidation status: " . $result); RM_Log::toLog("PayPal payment status: " . $provider->ipnData['payment_status']); if ($result == false) { return; } if ($provider->ipnData['payment_status'] == 'Pending') { //Pending status is not allowed!!! 'cause it could be for many reason, even for unconfirmed mail address. RM_Log::toLog("PayPal pending reason: " . $provider->ipnData['pending_reason']); } elseif ($provider->ipnData['payment_status'] == 'Completed') { $this->_callback($provider); } }
function errorAction() { $error = $this->_getParam('error_handler'); $detailedErrorMessage = RM_Log::createErrorMessage($error->exception); $config = Zend_Registry::get('config'); $logResult = RM_Log::toLog($detailedErrorMessage, RM_Log::ERR); if ((int) $config->get('errors')->get('debug') == 1) { $errorMessage = nl2br($detailedErrorMessage); } else { //TODO: add language constants. $errorMessage = "There was internal server error."; if ($logResult == false) { $errorMessage .= " Please make file system_log.txt writable to log error messages."; } else { $errorMessage .= " All information is in system_log.txt file."; } } ob_end_clean(); header('RMError: 1'); echo $errorMessage; die; }
/** * unZip uncompresses a file using the PCL Zip Library. * * @params string $source the source path * @params string $destination the destination path * @return bool True on Success */ function unZip($source, $destination) { $zip = new PclZip($source); if ($zip->extract(PCLZIP_OPT_PATH, $destination) == 0) { RM_Log::toLog("Unzip Failed: " . $zip->errorInfo(true)); return false; } return true; }
private static function _getJsMethodList($className) { $jsMethodNames = array(); $methods = get_class_methods($className); if (empty($methods)) { RM_Log::toLog("Failed to load class: " . $className, INFO_GENERAL); } if (!empty($methods)) { foreach ($methods as $methodName) { if (strpos($methodName, 'JsAction') !== false) { $jsMethodNames[] = $methodName; } } } return $jsMethodNames; }
public function beginTransaction($value, $reservationID, $description, $successUrl, $cancelUrl, $callbackClassName) { $payPalService = new RM_PayPal_Service(); try { $payPalService->initialize($payPalService->createInvoiceNumber($reservationID, true), $description, $value); } catch (RM_Exception $e) { RM_Log::toLog("PayPal transaction aborted: " . $e->getMessage()); throw new RM_Transaction_Exception(); } $fields = $payPalService->getFields(); $request = RM_Environment::getConnector()->getRequestHTTP(); $request->setControllerName('PayPal'); $request->setActionName('form'); $controller = new RM_User_PayPalController($request, new Zend_Controller_Response_Http()); $controller->setFrontController(Zend_Controller_Front::getInstance()); $controller->view->setScriptPath(RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'PayPal' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'user' . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'PayPal'); $fields['custom'] = $callbackClassName; $fields['return'] = $successUrl; $fields['cancel_return'] = $cancelUrl; $controller->view->fields = $fields; $controller->view->paypal_url = $payPalService->getPaypalURL(); echo $controller->view->render('form.phtml'); return; }
/** * Splits a SQL file and Parses each Query line by line * * @deprecated * @todo we need to move this method into RM_SQL_Manager class to have one place code for * parsing and execution SQL queries * @return bool true for success, false for failed */ public function parseSQL($sqlscript) { $queries = $this->splitSQL($sqlscript); if (empty($queries)) { return true; } $db = Zend_Db_Table::getDefaultAdapter(); foreach ($queries as $query) { $query = trim($query); if ($query == "") { continue; } try { $db->getConnection()->query($query); } catch (Exception $e) { RM_Log::toLog("Upgrade SQL Failed! Query: " . $query . " Exception: " . $e->getMessage()); return false; } } return true; }
public function ipnAction() { $this->_withoutView(); $provider = new RM_Plugin_PayPal(); $provider->validateIPN(); RM_Log::toLog("PayPal ipnAction Called"); if ($provider->ipnData['payment_status'] == "Completed" || $provider->ipnData['payment_status'] == "Pending") { RM_Log::toLog("PayPal payment status: " . $provider->ipnData['payment_status']); if (str_word_count($provider->ipnData['invoice'], 0, "RM-") > 0) { $bookingref = ltrim($provider->ipnData['invoice'], "RM-"); } else { $bookingref = $provider->ipnData['invoice']; } RM_Log::toLog("Booking ref passed back from PayPal: " . $bookingref); $model = new RM_Reservations(); $reservation = $model->find($bookingref)->current(); RM_Log::toLog("Reservation Record ID: " . $reservation->id); $model->confirm($reservation); RM_Log::toLog("Confirmed Updated"); $model->inProgressComplete($reservation); RM_Log::toLog("InProgress Marker Updated"); // save the total // we have a problem here, when this action is called it is called // from the paypal.com server. The session is not the same so saving to it // is impossible. I think we need to pass to PayPal the 'custom' parameter // this could contain something like the session id, however I am not // sure if it's possible to update the data in a session with a session // id? //$manager = RM_Reservation_Manager::getInstance(); $total_paid = $provider->ipnData['mc_gross']; RM_Log::toLog("Total Passed back from PayPal: " . $total_paid); //$manager->setPaymentTotal($total_paid); // save the total incase we need it later. //if (!$total_paid) $this->_redirect('Reservations', 'notcomplete'); // this handles if the total amount is null'd $billingModel = new RM_Billing(); $billingRow = $billingModel->createRow(); $billingRow->reservation_id = $bookingref; $billingRow->total_paid = $total_paid; $billingID = $billingRow->save(); RM_Log::toLog("Billing Updated"); // TODO: I can't get thsi working.. // save the payment information $billingPaymentsModel = new RM_BillingPayments(); $billingPaymentRow = $billingPaymentsModel->createRow(); $billingPaymentRow->id = $billingID; $billingPaymentRow->provider = "PayPal"; $billingPaymentRow->transaction_id = $provider->ipnData['txn_id']; $billingPaymentRow->status = $provider->ipnData['payment_status']; $billingPaymentRow->total = $provider->ipnData['mc_gross']; $billingPaymentRow->transaction_date = Date("Y-m-d"); $billingPaymentRow->save(); RM_Log::toLog("Billing Payments Updated"); // TODO: if the IPN is successful then we need to set the in_progress flag to 0 // this is also done in the reservation controller on success we have to do it here also // as it is possible the customer may not return to the site via the payment provider // return URL in this case the in_progress flag will never be updated that's why we // need to do this here also // I need to ask Valentin about a standard method for this. // TODO: we should also record other information such as the transaction id // however this can be added later. } }
/** * clear up * remove old upgrade files */ public function cleanupJsonAction() { // upgrade temp file path $filePath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'temp', 'upgrade')); $deleteArray = array($filePath . DIRECTORY_SEPARATOR . "core.zip", $filePath . DIRECTORY_SEPARATOR . "modules", $filePath . DIRECTORY_SEPARATOR . "plugins", $filePath . DIRECTORY_SEPARATOR . "system", $filePath . DIRECTORY_SEPARATOR . "tests", $filePath . DIRECTORY_SEPARATOR . "userdata", $filePath . DIRECTORY_SEPARATOR . "license", $filePath . DIRECTORY_SEPARATOR . "postupgrade.php"); foreach ($deleteArray as $item) { RM_Log::toLog('Upgrade - temp file/folder deleted: ' . $item, RM_Log::INFO); RM_Filesystem::deleteFolder($item); } return array('data' => array('success' => true)); }
function upgrade($tempFileName, $tempFilePath, $json) { RM_Log::toLog("Module Upgrade Called, Temp File: " . $tempFileName . " Temp Path: " . $tempFilePath); $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $rootPath = RM_Environment::getConnector()->getRootPath(); $chunks = explode('.', $tempFileName); $pluginName = $chunks[0]; //Plugin name will be always the first chunk $pluginFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName; if (is_dir($pluginFolderPath) == false) { throw new RM_Exception($this->_translate->_('Admin.Plugins.UpgradeMsg', 'NoPlugin')); } if (!extension_loaded('zlib')) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Plugins.UpgradeMsg', 'ZlibNotSupported')); } $zip = new PclZip($tempFilePath); $result = $zip->extract(PCLZIP_OPT_PATH, $pluginFolderPath, PCLZIP_OPT_REPLACE_NEWER); if (!$result) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Plugins.UpgradeMsg', 'UnzipFailed')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.UpgradeMsg', 'UnzipSuccessfully')); } $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.UpgradeMsg', 'UnzipSuccess')); unlink($tempFilePath); chmod($pluginFolderPath, $chmodOctal); $userDataFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName; $userDataFolders = array('views', 'languages', 'css', 'images'); foreach ($userDataFolders as $folder) { if (is_dir($pluginFolderPath . DIRECTORY_SEPARATOR . $folder)) { $this->_moveUserDataFolders($pluginFolderPath . DIRECTORY_SEPARATOR . $folder, $userDataFolderPath . DIRECTORY_SEPARATOR . $folder, $chmodOctal); } } $iniFilePath = $pluginFolderPath . DIRECTORY_SEPARATOR . self::$_iniFilename; if (is_file($iniFilePath) == false) { throw new RM_Exception($this->_translate->_('Admin.Plugins.UpgradeMsg', 'NoIniFile')); } $parser = new RM_Plugin_Config_Parser(); try { $config = $parser->getConfig($iniFilePath); } catch (RM_Exception $e) { throw new RM_Exception($e->getMessage()); } $pluginModel = new RM_Plugins(); $pluginObject = $pluginModel->fetchByName($pluginName); $previousVersion = $pluginObject->version; $currentVersion = $config->information['version']; $result = self::upgradeDatabase($pluginName, $previousVersion, $currentVersion); if ($result) { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.UpgradeMsg', 'DatabaseSuccess')); } // call the module upgrade method (in a try // incase the module does nothave this method // or incase the method fails) $pluginClassName = 'RM_Plugin_' . $pluginObject->name; $actualPluginObject = new $pluginClassName(); try { $actualPluginObject->upgrade(); } catch (Exception $e) { } $pluginObject->version = $config->information['version']; $pluginObject->save(); return true; }
function successAction() { // this is the where the user is directed to when the payment provider has issued a success. $manager = RM_Reservation_Manager::getInstance(); $reservationID = $manager->getReservationID(); // update the the in_progress flag // this is also completed in the payment notification for the payment // module, but we do it here to make sure that reservations that are // sent to the successAction they are visible and no longer hidden. $model = new RM_Reservations(); $reservation = $model->find($reservationID)->current(); $model->inProgressComplete($reservation); RM_Log::toLog("InProgress Marker Updated"); // fire the events RM_Notifications_Manager::getInstance()->fire('ReservationCompleteSuccessful', $manager); RM_Notifications_Manager::getInstance()->fire('ReservationPostbookingMessage', $manager); RM_Notifications_Manager::getInstance()->fire('ReservationNewReservationAlert', $manager); RM_Log::toLog("Reservation Complete ID: " . $reservationID); $content = $this->_getCompletePageContent($manager); if ($content === null) { $this->view->content = ''; } else { $this->view->content = $content; } $manager->reset(); $manager->setPaymentStatus(RM_Payments_Status::NO_TRANSACTION); }
/** * Returns HTML code for css files inclusion * * @param array $cssLibFiles - array with filepathes relateive from RM root folder * @return string|void HTML code for css inclusion */ public function includeCssLibFiles($cssLibFiles) { if ((int) Zend_Registry::get('config')->get('css')->get('combined') !== 1) { return $this->_includeCssLibFilesInOldStyle($cssLibFiles); } $folders = $this->_combineCssLibFiles($cssLibFiles); $combinedFileName = "combined.css"; $includeFiles = array(); foreach ($folders as $folderPath => $files) { if (count($files) == 1) { $includeFiles[] = RM_Environment::getConnector()->getRootURL() . '/' . implode('/', explode(DIRECTORY_SEPARATOR, $folderPath)) . '/' . $files[0]; continue; } $fullFolderPath = RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . $folderPath; $fullCombinedFilePath = $fullFolderPath . DIRECTORY_SEPARATOR . $combinedFileName; if (file_exists($fullCombinedFilePath) == false) { $handle = @fopen($fullCombinedFilePath, 'w'); if (!$handle) { RM_Log::toLog('Could not create file: ' . $fullCombinedFilePath, Zend_Log::WARN); foreach ($files as $file) { $includeFiles[] = RM_Environment::getConnector()->getRootURL() . '/' . implode('/', explode(DIRECTORY_SEPARATOR, $folderPath)) . '/' . $file; } continue; } foreach ($files as $file) { $fullFilePath = $fullFolderPath . DIRECTORY_SEPARATOR . $file; if (file_exists($fullFilePath) == false) { continue; } if (is_readable($fullFilePath) == false) { $includeFiles[] = RM_Environment::getConnector()->getRootURL() . '/' . implode('/', explode(DIRECTORY_SEPARATOR, $fullFilePath)); continue; } fwrite($handle, file_get_contents($fullFilePath)); } fclose($handle); } $includeFiles[] = RM_Environment::getConnector()->getRootURL() . '/' . implode('/', explode(DIRECTORY_SEPARATOR, $folderPath)) . '/' . $combinedFileName; } $html = array(); foreach ($includeFiles as $includeFile) { $html[] = '<link rel="stylesheet" type="text/css" href="' . $includeFile . '"/>'; } return implode("\n", $html); }
/** * Send email notification to System Admin email * * @deprecated * @param string $fromAddress the email from address * @param string $fromName the email from name * @param string $subject the subject text * @param string $message the message text * @return object/boolean if failed will return false otherwise boolean false will be returned. */ public function AdminNotify($fromAddress, $fromName, $subject, $message) { $configModel = new RM_Config(); $mail = new Zend_Mail('UTF-8'); $mail->addTo($configModel->getValue('rm_config_administrator_email')); $mail->setFrom($fromAddress, $fromName); $mail->setBodyText($message); $mail->setSubject($subject); $emailType = $configModel->getValue('rm_config_email_settings_mailer'); try { if ($emailType == 'PHP') { return $mail->send(); } else { $smtpConfig = array('auth' => 'Login', 'username' => $configModel->getValue('rm_config_email_settings_smtpuser'), 'password' => $configModel->getValue('rm_config_email_settings_smtppass'), 'port' => $configModel->getValue('rm_config_email_settings_smtpport')); if ($configModel->getValue('rm_config_email_settings_smtpsecure') != "") { $smtpConfig['ssl'] = strtolower($configModel->getValue('rm_config_email_settings_smtpsecure')); } return $mail->send(new Zend_Mail_Transport_Smtp($configModel->getValue('rm_config_email_settings_smtphost'), $smtpConfig)); } } catch (Zend_Mail_Exception $e) { RM_Log::toLog("Notification error: " . $e->getMessage()); return false; } }