function process($params, $options) { if (is_null($params) || empty($params)) { $controller = new \com\indigloo\sc\controller\Http400(); $controller->process(); exit; } $plistId = Util::getArrayKey($params, "list_id"); $listId = PseudoId::decode($plistId); $qparams = Url::getRequestQueryParams(); $gpage = Url::tryQueryParam("gpage"); $gpage = empty($gpage) ? "1" : $gpage; //@todo input check // people can type all sort of input garbage settype($listId, "int"); $listDao = new \com\indigloo\sc\dao\Lists(); $listDBRow = $listDao->getOnId($listId); if (empty($listDBRow)) { //not found $controller = new \com\indigloo\sc\controller\Http404(); $controller->process(); exit; } $listName = $listDBRow["name"]; $listPubUrl = sprintf("%s/pub/list/%d/%s", Url::base(), $plistId, $listDBRow["seo_name"]); //get items from sc_list_item table $model = new \com\indigloo\sc\model\ListItem(); $filter = new Filter($model); $filter->add($model::LIST_ID, Filter::EQ, $listId); $pageSize = Config::getInstance()->get_value("user.page.items"); $filters = array(); array_push($filters, $filter); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $itemDBRows = $listDao->getPagedItems($paginator, $filters); $loginId = $listDBRow["login_id"]; $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $template = APP_WEB_DIR . '/view/list/pub.php'; //page variables $pageBaseUrl = $listPubUrl; $pageTitle = sprintf("page %d of %s", $gpage, $listDBRow["name"]); $description = Util::abbreviate($listDBRow["description"], 160); $metaDescription = SeoData::thisOrHomeDescription($description); $metaKeywords = SeoData::getHomeMetaKeywords(); include $template; }
$gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler("edit-form", $_POST); $fhandler->addRule("name", "Name", array('required' => 1)); $fvalues = $fhandler->getValues(); $name = $fvalues["name"]; if (!Util::isAlphaNumeric($name)) { $fhandler->addError("Bad name : only letters and numbers are allowed!"); } if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $listDao->createNew($loginId, $name, $fvalues["description"]); $message = sprintf("success! new list created"); $gWeb->store(Constants::FORM_MESSAGES, array($message)); header("Location: " . $fUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } catch (DBException $ex) { Logger::getInstance()->error($ex->getMessage()); Logger::getInstance()->backtrace($ex->getTrace()); $gWeb->store(Constants::STICKY_MAP, $fvalues); $message = " Error: something went wrong with database operation"; //SQLState 23000 is duplicate key violation
use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\Configuration as Config; use com\indigloo\Constants; use com\indigloo\ui\form\Message as FormMessage; use com\indigloo\ui\form\Sticky; use com\indigloo\sc\auth\Login; $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); } $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $panelId = $sticky->get("panel_id"); $listDao = new \com\indigloo\sc\dao\Lists(); $analyticDao = new \com\indigloo\sc\dao\Analytic(); $counters = $analyticDao->getUserCounters($loginId); $list_counter = $counters["list_count"]; $qparams = Url::getRequestQueryParams(); $pageSize = Config::getInstance()->get_value("user.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $listDBRows = $listDao->getPagedOnLoginId($paginator, $loginId); $baseURI = "/user/dashboard/list/index.php"; $fUrl = Url::current(); ?> <!DOCTYPE html> <html>
<?php // user/popup/list.php // normal HTML output // session pending action not possible. include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\sc\auth\Login; use com\indigloo\sc\ui\Constants as UIConstants; set_exception_handler('webgloo_ajax_exception_handler'); // list popup is called via javascript on pages // so actual "form caller " is what is coming in as // qUrl (original window.location.href) from javascript POST // this is base64 encoded $qUrl = Util::getArrayKey($_POST, "qUrl"); if (!Login::hasSession()) { $message = "You need to login!"; echo $message; exit; } $loginId = Login::getLoginIdInSession(); $itemId = Util::getArrayKey($_POST, "itemId"); $listDao = new \com\indigloo\sc\dao\Lists(); $listRows = $listDao->getOnLoginId($loginId); // Add default rows to top of lists // $html = \com\indigloo\sc\html\Lists::getSelectPopup($listRows, $itemId, $qUrl); echo $html;
use com\indigloo\sc\Util as AppUtil; 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("edit-form", $_POST); $fhandler->addRule("link", "item URL", array('required' => 1)); $fhandler->addRule("list_id", "list id", array('required' => 1)); $fvalues = $fhandler->getValues(); $link = $fvalues["link"]; if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $itemId = AppUtil::getItemIdInUrl($link); if (is_null($itemId)) { $message = "invalid item URL : please add a valid item URL "; throw new UIException(array($message)); } $postDao = new \com\indigloo\sc\dao\Post(); if (!$postDao->exists($itemId)) { $message = sprintf("item {%s} does not exists", $itemId); throw new UIException(array($message)); } $listDao->addItem($loginId, $fvalues["list_id"], $itemId); $message = sprintf("success! item added to list "); $gWeb->store(Constants::FORM_MESSAGES, array($message)); header("Location: " . $fUrl); } catch (UIException $ex) {
$fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler("edit-form", $_POST); $fhandler->addRule("list_id", "list id", array('required' => 1)); $fvalues = $fhandler->getValues(); $name = $fvalues["name"]; if (!Util::isAlphaNumeric($name)) { $fhandler->addError("Bad name : only letters and numbers are allowed!"); } if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $listId = $fvalues["list_id"]; $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $listDao->edit($loginId, $fvalues["list_id"], $name, $fvalues["description"]); $message = sprintf("success! list updated"); $gWeb->store(Constants::FORM_MESSAGES, array($message)); header("Location: " . $fUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } catch (DBException $ex) { Logger::getInstance()->error($ex->getMessage()); Logger::getInstance()->backtrace($ex->getTrace()); $gWeb->store(Constants::STICKY_MAP, $fvalues); $message = "Error: something went wrong with database operation"; if ($ex->getCode() == 23000) {
use com\indigloo\ui\form\Sticky; use com\indigloo\ui\Filter; use com\indigloo\sc\util\PseudoId; $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $panelId = $sticky->get("panel_id"); $qparams = Url::getRequestQueryParams(); $gSessionLogin = \com\indigloo\sc\auth\Login::getLoginInSession(); $loginId = $gSessionLogin->id; $loginName = $gSessionLogin->name; if (is_null($loginId)) { trigger_error("Error : NULL or invalid login_id", E_USER_ERROR); } $plistId = Url::getQueryParam("list_id"); $listId = PseudoId::decode($plistId); settype($listId, "int"); $listDao = new \com\indigloo\sc\dao\Lists(); $listDBRow = $listDao->getOnId($listId); $listName = $listDBRow["name"]; //list owner check if (!Login::isOwner($listDBRow["login_id"])) { header("Location: /site/error/403.html"); exit; } $listPubUrl = sprintf("%s/pub/list/%d/%s", Url::base(), $plistId, $listDBRow["seo_name"]); //get items from sc_list_item table $model = new \com\indigloo\sc\model\ListItem(); $filter = new Filter($model); $filter->add($model::LIST_ID, Filter::EQ, $listId); $pageSize = Config::getInstance()->get_value("user.page.items"); $filters = array(); array_push($filters, $filter);
use com\indigloo\Logger; // submitting via javascript // removed button value check $gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler("delete-item-form", $_POST); $fhandler->addRule("list_id", "list id", array('required' => 1)); $fhandler->addRule("items_json", "items", array('required' => 1, 'rawData' => 1)); $fvalues = $fhandler->getValues(); if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $listDao->deleteItems($loginId, $fvalues["list_id"], $fvalues["items_json"]); $message = sprintf("success! selected items have been deleted"); $gWeb->store(Constants::FORM_MESSAGES, array($message)); header("Location: " . $fUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } catch (DBException $ex) { Logger::getInstance()->error($ex->getMessage()); Logger::getInstance()->backtrace($ex->getTrace()); $gWeb->store(Constants::STICKY_MAP, $fvalues); $message = "Error: something went wrong with database operation"; $gWeb->store(Constants::FORM_ERRORS, array($message));
$gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $qUrl = \com\indigloo\Url::tryFormUrl("qUrl"); try { $fhandler = new Form\Handler("list-form-1", $_POST); $fhandler->addRule("item_id", 'item', array('required' => 1)); $fvalues = $fhandler->getValues(); $qUrl = base64_decode($fvalues["qUrl"]); if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $listId = $fvalues["list_id"]; $itemId = $fvalues["item_id"]; $loginId = Login::getLoginIdInSession(); $flag = intval($fvalues["is_new"]); $listDao = new \com\indigloo\sc\dao\Lists(); $name = $fvalues["new-list-name"]; if ($flag == 1 && empty($listId)) { // create new list if (!Util::isAlphaNumeric($name)) { $error = "Bad name : only letters and numbers are allowed!"; throw new UIException(array($error)); } $listId = $listDao->create($loginId, $name, $itemId); $pListId = PseudoId::encode($listId); } else { // Add to existing list // this can also be defaults lists // so we should get listId from addItem call $listId = $listDao->addItem($loginId, $listId, $itemId); $pListId = PseudoId::encode($listId);
private function processLists($params, $options) { $pubUserId = Util::getArrayKey($params, "login_id"); $loginId = PseudoId::decode($pubUserId); $qparams = Url::getRequestQueryParams(); $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $this->isValidUser($userDBRow); $gpage = Url::tryQueryParam("gpage"); $gpage = empty($gpage) ? "1" : $gpage; $listDao = new \com\indigloo\sc\dao\Lists(); $qparams = Url::getRequestQueryParams(); $pageSize = Config::getInstance()->get_value("user.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $listDBRows = $listDao->getPagedOnLoginId($paginator, $loginId); $template = APP_WEB_DIR . '/view/user/lists.php'; //page variables $pageBaseUrl = "/pub/user/" . $pubUserId; $pageTitle = sprintf("page %d of lists by %s", $gpage, $userDBRow["name"]); $metaKeywords = SeoData::getHomeMetaKeywords(); $metaDescription = SeoData::getHomeMetaDescription(); include $template; }
use com\indigloo\Url; use com\indigloo\Logger; 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("delete-form", $_POST); $fhandler->addRule("list_id", "list id", array('required' => 1)); $fvalues = $fhandler->getValues(); $listId = $fvalues["list_id"]; if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $listDao->delete($loginId, $listId); // list no longer there - Go to list index header("Location: /user/dashboard/list/index.php"); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } catch (DBException $ex) { Logger::getInstance()->error($ex->getMessage()); Logger::getInstance()->backtrace($ex->getTrace()); $gWeb->store(Constants::STICKY_MAP, $fvalues); $message = "Error: something went wrong with database operation"; $gWeb->store(Constants::FORM_ERRORS, array($message)); header("Location: " . $fUrl);
delete from sc_list ; delete from sc_list_item ; update sc_site_counter set list_count = 0 ; update sc_user_counter set list_count = 0 ; update sc_post_counter set list_count = 0 ; @after update sc_list set dl_bit = 1 where name = 'Favorites' ; */ ob_end_clean(); $mysqli = MySQL\Connection::getInstance()->getHandle(); // get all login_id from sc_bookmark // people who have saved / liked items $sql = " select count(id), subject_id from sc_bookmark group by subject_id "; $rows = MySQL\Helper::fetchRows($mysqli, $sql); $listDao = new \com\indigloo\sc\dao\Lists(); $listName = "Favorites"; $listDescription = "Items that I treat with special favor!"; $loginIds = array(); foreach ($rows as $row) { $loginId = $row["subject_id"]; // create a Favorites list for all loginId in sc_bookmark $listDao->createNew($loginId, $listName, $listDescription, 1); array_push($loginIds, $loginId); } // list added // now add sc_bookmark items to this list $t1_sql = " select id from sc_list where login_id = %d and name = '%s' "; $t2_sql = " select object_id from sc_bookmark where subject_id = %d and verb = 2 "; foreach ($loginIds as $loginId) { // get list ID