function execute($params) { $action = $params->action; $comment = $params->comment; if (empty($action) || empty($comment)) { $response = array("code" => 500, "message" => "Bad input: missing required parameters."); return $response; } $commentDao = new \com\indigloo\sc\dao\Comment(); $code = 200; switch ($action) { case UIConstants::ADD_COMMENT: $loginId = $params->loginId; $name = $params->name; $ownerId = $params->ownerId; $postId = $params->postId; $title = $params->title; $comment = $params->comment; $commentDao->create($loginId, $name, $ownerId, $postId, $title, $comment); $message = sprintf("success. your comment added to item %s ", $title); break; default: break; } $response = array("code" => $code, "message" => $message); return $response; }
$fhandler = new Form\Handler('web-form-1', $_POST); $fhandler->addRule('comment', 'Comment', array('required' => 1)); $fhandler->addRule('post_id', 'post id', array('required' => 1)); $fhandler->addRule('owner_id', 'owner id', array('required' => 1)); $fhandler->addRule('post_title', 'post title', array('required' => 1)); $fvalues = $fhandler->getValues(); // UI checks if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } //trim comments to 512 chars $fvalues["comment"] = substr($fvalues["comment"], 0, 512); //use login is required for comments if (Login::hasSession()) { $gSessionLogin = \com\indigloo\sc\auth\Login::getLoginInSession(); $commentDao = new com\indigloo\sc\dao\Comment(); $commentDao->create($gSessionLogin->id, $gSessionLogin->name, $fvalues['owner_id'], $fvalues['post_id'], $fvalues['post_title'], $fvalues['comment']); // go back to comment form header("Location: " . $fUrl); } else { //create data object representing pending session action $actionObj = new \stdClass(); $actionObj->endPoint = "/qa/form/comment.php"; $params = new \stdClass(); $params->ownerId = $fvalues['owner_id']; $params->postId = $fvalues['post_id']; $params->title = $fvalues['post_title']; $params->comment = $fvalues['comment']; $params->action = UIConstants::ADD_COMMENT; $actionObj->params = $params; //base64 encode to transfer as payload in URL
use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\exception\UIException; use com\indigloo\sc\util\PseudoId; if (isset($_POST['delete']) && $_POST['delete'] == 'Delete') { $gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler('web-form-1', $_POST); $fhandler->addRule('comment_id', 'comment_id', array('required' => 1)); $fhandler->addRule('qUrl', 'qUrl', array('required' => 1, 'rawData' => 1)); $fvalues = $fhandler->getValues(); $ferrors = $fhandler->getErrors(); //decode qUrl to use in redirect $qUrl = base64_decode($fvalues['qUrl']); $encodedId = PseudoId::encode($fvalues['comment_id']); if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $commentDao = new com\indigloo\sc\dao\Comment(); $commentDao->delete($fvalues['comment_id']); //success header("Location: " . $qUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } }
include APP_WEB_DIR . '/inc/role/user.inc'; use com\indigloo\ui\form as Form; use com\indigloo\Constants; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\exception\UIException; if (isset($_POST['save']) && $_POST['save'] == 'Save') { $gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler('web-form-1', $_POST); $fhandler->addRule('comment', 'Comment', array('required' => 1)); $fhandler->addRule('qUrl', 'qUrl', array('required' => 1, 'rawData' => 1)); $fvalues = $fhandler->getValues(); //decode to use in redirect $qUrl = base64_decode($fvalues['qUrl']); if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $commentDao = new com\indigloo\sc\dao\Comment(); $commentDao->update($fvalues['comment_id'], $fvalues['comment']); //success header("Location: " . $qUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } }
<?php //sc/monitor/comments.php include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; include APP_WEB_DIR . '/inc/role/admin.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\Configuration as Config; use com\indigloo\sc\auth\Login; use com\indigloo\sc\ui\Constants as UIConstants; $qparams = Url::getRequestQueryParams(); $commentDao = new \com\indigloo\sc\dao\Comment(); $pageSize = Config::getInstance()->get_value("user.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $commentDBRows = $commentDao->getPaged($paginator); $baseURI = "/monitor/comments.php"; ?> <!DOCTYPE html> <html> <head> <title> 3mik.com - All Comments </title> <?php include APP_WEB_DIR . '/inc/meta.inc'; ?> <?php echo \com\indigloo\sc\util\Asset::version("/css/bundle.css"); ?>
include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; include APP_WEB_DIR . '/inc/role/user.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\ui\form\Sticky; use com\indigloo\Constants; use com\indigloo\ui\form\Message as FormMessage; use com\indigloo\sc\auth\Login; use com\indigloo\sc\util\PseudoId; $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $encodedId = Url::getQueryParam("id"); $commentId = PseudoId::decode($encodedId); $qUrl = Url::tryBase64QueryParam("q", "/"); $fUrl = Url::current(); $commentDao = new com\indigloo\sc\dao\Comment(); $commentDBRow = $commentDao->getOnId($commentId); if (!(Login::isOwner($commentDBRow['login_id']) || Login::isAdmin())) { header("Location: /site/error/403.html"); exit; } $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $itemId = PseudoId::encode($commentDBRow['post_id']); ?> <!DOCTYPE html> <html> <head> <title> Edit Comment</title> <?php
include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; include APP_WEB_DIR . '/inc/role/user.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\Configuration as Config; use com\indigloo\sc\auth\Login; use com\indigloo\ui\Filter; $qparams = Url::getRequestQueryParams(); $gSessionLogin = \com\indigloo\sc\auth\Login::getLoginInSession(); $loginId = $gSessionLogin->id; $loginName = $gSessionLogin->name; if (is_null($loginId)) { trigger_error("Error : NULL login_id on user dashboard", E_USER_ERROR); } $commentDao = new \com\indigloo\sc\dao\Comment(); //Add login_id filter $model = new \com\indigloo\sc\model\Comment(); $filters = array(); $filter = new Filter($model); $filter->add($model::LOGIN_ID, Filter::EQ, $loginId); array_push($filters, $filter); $pageSize = Config::getInstance()->get_value("user.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $commentDBRows = $commentDao->getPaged($paginator, $filters); $baseURI = "/user/dashboard/comments.php"; ?> <!DOCTYPE html> <html>