/** * Remove a log file. * * @todo Use ITPrismResponseJson */ public function remove() { // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $file = $this->input->post->get('file', null, "raw"); if (!$file) { JFactory::getApplication()->close(404); } $model = $this->getModel(); /** @var $model CrowdFundingModelLog * */ jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); try { // Clean and prepare the file. $fileSource = $model->prepareFile(JPath::clean($file)); if (!$model->deleteFile($fileSource)) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_LOG_FILE_CANNOT_BE_REMOVED'))->failure(); echo $response; JFactory::getApplication()->close(); } } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_LOG_FILE_REMOVED'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Save notice to a file. */ public function getNotice() { $app = JFactory::getApplication(); // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $fileId = $this->input->get->get("id"); $userId = JFactory::getUser()->get("id"); if (!$userId or !$fileId) { $response->setTitle(JText::_('COM_IDENTITYPROOF_FAIL'))->setText(JText::_('COM_IDENTITYPROOF_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } try { // Get the model $model = $this->getModel(); /** @var $model IdentityProofModelNotification */ $note = $model->getNotice($fileId); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_IDENTITYPROOF_SUCCESS'))->setData(array("note" => $note, "token" => JSession::getFormToken()))->success(); echo $response; $app->close(); }
public function getFormToken() { // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $response->setTitle(JText::_('COM_IDENTITYPROOF_SUCCESS'))->setData(array("token" => JSession::getFormToken()))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Deletes extra image. */ public function removeExtraImage() { jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $userId = $this->input->post->getInt("user_id"); $imageId = $this->input->post->getInt("id"); // Get the folder where the images are stored. $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); try { jimport('joomla.filesystem.file'); // Get the model $model = $this->getModel(); $model->removeExtraImage($imageId, $imagesFolder); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'))->setData(array("item_id" => $imageId))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @return void * @throws Exception * * @since 3.0 */ public function saveOrderAjax() { jimport("itprism.response.json"); $response = new ITPrismResponseJson(); // Get the input $pks = $this->input->post->get('cid', array(), 'array'); $order = $this->input->post->get('order', array(), 'array'); // Sanitize the input JArrayHelper::toInteger($pks); JArrayHelper::toInteger($order); // Get the model $model = $this->getModel(); try { $model->saveorder($pks, $order); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_USERIDEAS_SUCCESS'))->setText(JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * This method trigger the event onPaymentsPreparePayment. * The purpose of this method is to load a data and send it to browser. * That data will be used in the process of payment. */ public function preparePaymentAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ jimport('itprism.response.json'); $response = new ITPrismResponseJson(); // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; JFactory::getApplication()->close(); } $output = array(); // Prepare payment service name. $filter = new JFilterInput(); $paymentService = JString::trim(JString::strtolower($this->input->getCmd("payment_service"))); $paymentService = $filter->clean($paymentService, "ALNUM"); // Trigger the event try { $context = 'com_crowdfunding.preparepayment.' . $paymentService; // Import CrowdFunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsPreparePayment", array($context, &$params)); // Get the result, that comes from the plugin. if (!empty($results)) { foreach ($results as $result) { if (!is_null($result) and is_array($result)) { $output =& $result; break; } } } } catch (Exception $e) { // Store log data in the database JLog::add($e->getMessage()); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); echo $response; JFactory::getApplication()->close(); } // Check the response $success = JArrayHelper::getValue($output, "success"); if (!$success) { // If there is an error... // Get project id. $projectId = $this->input->getUint("pid"); $paymentProcessContext = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $projectId; // Initialize the payment process object. $paymentProcess = new JData(); $paymentProcess->step1 = false; $app->setUserState($paymentProcessContext, $paymentProcess); // Send response to the browser $response->failure()->setTitle(JArrayHelper::getValue($output, "title"))->setText(JArrayHelper::getValue($output, "text")); } else { // If all is OK... // Send response to the browser $response->success()->setTitle(JArrayHelper::getValue($output, "title"))->setText(JArrayHelper::getValue($output, "text"))->setData(JArrayHelper::getValue($output, "data")); } echo $response; JFactory::getApplication()->close(); }
/** * Return a not about resource. */ public function note() { $app = JFactory::getApplication(); // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $fileId = $this->input->get->get("id"); $userId = JFactory::getUser()->get("id"); // Create validator object. jimport("identityproof.validator.file.owner"); $validator = new IdentityProofValidatorFileOwner(JFactory::getDbo(), $fileId, $userId); if (!$userId) { $response->setTitle(JText::_('COM_IDENTITYPROOF_FAIL'))->setText(JText::_('COM_IDENTITYPROOF_ERROR_NOT_LOG_IN'))->failure(); echo $response; $app->close(); } if (!$validator->isValid()) { $response->setTitle(JText::_('COM_IDENTITYPROOF_FAIL'))->setText(JText::_('COM_IDENTITYPROOF_ERROR_INVALID_ITEM'))->failure(); echo $response; $app->close(); } try { // Get the model $model = $this->getModel(); /** @var $model IdentityProofModelFile */ $note = $model->getNote($fileId, $userId); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_IDENTITYPROOF_SUCCESS'))->setData(array("note" => $note))->success(); echo $response; $app->close(); }
/** * This method store user vote */ public function vote() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $params = $app->getParams("com_userideas"); // Check for disabled payment functionality if ($params->get("debug_item_adding_disabled", 0)) { $error = JText::_("COM_USERIDEAS_ERROR_VOTING_HAS_BEEN_DISABLED"); JLog::add($error); return null; } $requestMethod = $app->input->getMethod(); if ("POST" != $requestMethod) { $error = "COM_USERIDEAS_ERROR_INVALID_REQUEST_METHOD (" . $requestMethod . "):\n"; $error .= "INPUT: " . var_export($app->input, true) . "\n"; JLog::add($error); return; } $user = JFactory::getUser(); $userId = $user->get("id"); if (!$user->authorise('userideas.vote', 'com_userideas')) { $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText(JText::_('COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION'))->failure(); echo $response; JFactory::getApplication()->close(); } $data = array("id" => $app->input->post->getInt("id"), "user_id" => $userId); // Save data try { // Events $dispatcher = JEventDispatcher::getInstance(); // Execute event onBeforeVote JPluginHelper::importPlugin('userideas'); $results = $dispatcher->trigger('onBeforeVote', array('com_userideas.beforevote', &$data, $params)); // Check for error. foreach ($results as $result) { $success = JArrayHelper::getValue($result, "success"); if (false === $success) { $message = JArrayHelper::getValue($result, "message", JText::_('COM_USERIDEAS_VOTED_UNSUCCESSFULLY')); $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText($message)->failure(); echo $response; JFactory::getApplication()->close(); } } // Execute event onVote $dispatcher->trigger('onVote', array('com_userideas.vote', &$data, $params)); // Execute event onAfterVote $dispatcher->trigger('onAfterVote', array('com_userideas.aftervote', &$data, $params)); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText(JText::_('COM_USERIDEAS_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $responseData = JArrayHelper::getValue($data, "response_data", 0); $userVotes = JArrayHelper::getValue($responseData, "user_votes", 0); $votes = JArrayHelper::getValue($responseData, "votes", 0); $data = array("votes" => $votes); $response->setTitle(JText::_('COM_USERIDEAS_SUCCESS'))->setText(JText::plural('COM_USERIDEAS_VOTED_SUCCESSFULLY', $userVotes))->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { jimport('itprism.response.json'); $response = new ITPrismResponseJson(); // Check for disabled payment functionality if ($this->params->get("debug_payment_disabled", 0)) { // Log the error. $error = JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED") . "\n"; $error .= JText::sprintf("COM_CROWDFUNDING_TRANSACTION_DATA", var_export($_REQUEST, true)); $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR"); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; JFactory::getApplication()->close(); } // Get model object. $model = $this->getModel(); $transaction = null; $project = null; $reward = null; $paymentSession = null; $redirectUrl = null; $message = null; // Trigger the event try { // Import CrowdFunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymenNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger("onPaymenNotify", array($this->context, &$this->params)); if (!empty($results)) { foreach ($results as $result) { if (!empty($result) and isset($result["transaction"])) { $transaction = JArrayHelper::getValue($result, "transaction"); $project = JArrayHelper::getValue($result, "project"); $reward = JArrayHelper::getValue($result, "reward"); $paymentSession = JArrayHelper::getValue($result, "payment_session"); $redirectUrl = JArrayHelper::getValue($result, "redirect_url"); $message = JArrayHelper::getValue($result, "message"); break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$transaction) { // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY"))->failure(); echo $response; JFactory::getApplication()->close(); } // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$transaction, &$this->params, &$project, &$reward, &$paymentSession)); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); } catch (Exception $e) { // Store log data to the database. $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_NOTIFIER_AJAX_ERROR", $e->getMessage()); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; JFactory::getApplication()->close(); } // Generate redirect URL if (!$redirectUrl) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->slug, $project->catslug, "share")); } if (!$message) { $message = JText::_("COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY"); } // Send response to the browser $response->success()->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setText($message)->setRedirectUrl($redirectUrl); echo $response; JFactory::getApplication()->close(); }
/** * Delete an extra image. * */ public function removeExtraImage() { // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $userId = JFactory::getUser()->get("id"); if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get image ID. $imageId = $this->input->post->get("id"); // Get the folder where the images are stored. $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); try { // Get the model $model = $this->getModel(); /** @var $model CrowdFundingModelStory */ $model->removeExtraImage($imageId, $imagesFolder, $userId); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'))->setData(array("item_id" => $imageId))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to remove image via AJAX. * * @throws Exception * * @return void */ public function removeImage() { // Get the input $rewardId = $this->input->post->get('rid', 0, 'int'); $userId = JFactory::getUser()->get("id"); jimport("itprism.response.json"); $response = new ITPrismResponseJson(); // Validate user if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ if (!$params->get("rewards_images", 0)) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Validate reward owner. jimport("crowdfunding.validator.reward.owner"); $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $userId); if (!$rewardId or !$validator->isValid()) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get the model $model = $this->getModel(); try { // Get the folder where the images will be stored $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); $model->removeImage($rewardId, $imagesFolder); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_IMAGE_REMOVED_SUCCESSFULLY'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to remove records via AJAX. * * @throws Exception * @return void */ public function remove() { // Get the input $app = JFactory::getApplication(); /** $app JApplicationSite */ // Create response object. jimport('itprism.response.json'); $response = new ITPrismResponseJson(); $itemId = $app->input->post->get('id', 0, 'int'); $userId = JFactory::getUser()->get("id"); // Get the model $model = $this->getModel(); /** @var $model CrowdFundingModelUpdateItem */ try { $item = $model->getItem($itemId); if ($item->user_id != $userId) { $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setTitle(JText::_("COM_CROWDFUNDING_RECORD_CANNOT_REMOVED"))->failure(); echo $response; JFactory::getApplication()->close(); } $model->remove($itemId, $userId); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setTitle(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM_CANNOT_REMOVED"))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setTitle(JText::_("COM_CROWDFUNDING_RECORD_REMOVED_SUCCESSFULLY"))->success(); echo $response; JFactory::getApplication()->close(); }