Esempio n. 1
0
 public static function pagination($allCount, $offset = 1)
 {
     $offset = intval(system::HTTPGet("offset"));
     if ($offset == 0) {
         $offset = 1;
     }
     $smarty = array();
     $smarty["itemsOnPage"] = intval(system::param("itemsOnPage"));
     $smarty["offset"] = $offset;
     $smarty["allCount"] = $allCount;
     $pageCompose = new pagination($allCount);
     $pageCompose->setPerPage($smarty["itemsOnPage"]);
     $pageCompose->readInputData($offset);
     $mysqlLimits = $pageCompose->calculateOffset();
     $smarty["pages"] = $pageCompose->genPages();
     $smarty["pagesTotal"] = count($smarty["pages"]);
     system::$core->smarty->assign("pagination", $smarty);
     return $mysqlLimits;
 }
Esempio n. 2
0
 public static function buildList($target, $clause = '')
 {
     $columns = self::$db->query("SHOW COLUMNS FROM `{$target}`")->fetchAll();
     if (isset($_GET["action"])) {
         switch ($_GET["action"]) {
             case "delete":
                 $id = array_keys($_GET);
                 $keyName = $id[count($_GET) - 1];
                 $id = intval($_GET[$keyName]);
                 $photo = self::$db->query("SELECT * FROM `{$target}` WHERE `?`=?", $keyName, $id)->fetch();
                 if ($photo) {
                     self::$db->query("DELETE FROM `{$target}` WHERE `?`=?", $keyName, $id);
                     unlink(CONTENT_PATH . '/photo/original/' . $photo['picture']);
                     unlink(CONTENT_PATH . '/photo/resized/' . $photo['picture']);
                     unlink(CONTENT_PATH . '/photo/200x200/' . $photo['picture']);
                     unlink(CONTENT_PATH . '/photo/200x140/' . $photo['picture']);
                 }
                 if ($target == "content") {
                     self::$db->query("DELETE FROM `photo` WHERE `contentID`=?", $id);
                     self::$smarty->clearCache(null, "MAINPAGE");
                     self::$smarty->clearCache(null, "RSS");
                     self::$smarty->clearCache(null, "SEARCH_RES");
                 }
                 break;
         }
     }
     if (isset($_POST["groupDelete"]) && !empty($_POST["rows"])) {
         self::$db->query("DELETE FROM `{$target}` WHERE `" . $columns[0]["Field"] . "` IN (" . implode(",", $_POST["rows"]) . ")");
     }
     $mysqlLimits = array();
     $offset = 0;
     $allCount = self::$db->query("SELECT COUNT(*) as cnt FROM `{$target}` WHERE 1 " . $clause)->fetch();
     $pageCompose = new pagination($allCount["cnt"]);
     $sort = $columns[0]["Field"];
     $direction = "DESC";
     if (!empty(self::$get["offset"])) {
         $offset = intval(self::$get["offset"]);
     }
     if (isset($_GET["direction"]) && $_GET["direction"]) {
         if ($_GET["direction"] == "DESC") {
             $direction = "ASC";
         } else {
             if ($_GET["direction"] == "ASC") {
                 $direction = "DESC";
             }
         }
     }
     if (isset($_GET["sort"]) && $_GET["sort"]) {
         $sort = $_GET["sort"];
     }
     $pageCompose->readInputData($offset, 20);
     $mysqlLimits = $pageCompose->calculateOffset();
     $pages = $pageCompose->genPages();
     self::$smarty->assign("pages", $pages);
     self::$smarty->assign("direction", $direction);
     self::$smarty->assign("sort", $sort);
     self::$smarty->assign("allCount", $allCount["cnt"]);
     $sqlData = self::$db->query("SELECT * FROM `{$target}` WHERE 1 {$clause} ORDER BY `{$sort}` {$direction} LIMIT {$mysqlLimits["start"]},{$mysqlLimits["end"]}")->fetchAll();
     self::$smarty->assign("list", $sqlData);
     return $sqlData;
 }
Esempio n. 3
0
 public static function buildList($target, $type = "", array $clause = array())
 {
     $clauseSTR = "";
     if ($clause) {
         $clauseSTR = implode(" AND ", $clause);
     }
     if ($clauseSTR) {
         $clauseSTR = "WHERE {$clauseSTR}";
     }
     $columns = self::$db->query("SHOW COLUMNS FROM `{$target}`")->fetchAll();
     if (isset($_GET["action"])) {
         switch ($_GET["action"]) {
             case "delete":
                 $id = array_keys($_GET);
                 $keyName = $id[count($_GET) - 1];
                 $id = intval($_GET[$keyName]);
                 self::$db->query("DELETE FROM `{$target}` WHERE `?`=?", $keyName, $id);
                 if ($target == "content") {
                     self::$db->query("DELETE FROM `content_category` WHERE `id`=?", $id);
                 }
                 self::$smarty->clearAllCache();
                 break;
         }
     }
     if (isset($_POST["groupDelete"]) && !empty($_POST["rows"])) {
         self::$db->query("DELETE FROM `{$target}` WHERE `" . $columns[0]["Field"] . "` IN (" . implode(",", $_POST["rows"]) . ")");
     }
     $mysqlLimits = array();
     $offset = 1;
     $allCount = self::$db->query("SELECT COUNT(*) as cnt FROM `{$target}` {$clauseSTR}")->fetch();
     $pageCompose = new pagination($allCount["cnt"]);
     $sort = $columns[0]["Field"];
     $direction = "DESC";
     if (!empty(self::$get["offset"])) {
         $offset = intval(self::$get["offset"]);
     }
     if (isset($_GET["direction"]) && $_GET["direction"]) {
         if ($_GET["direction"] == "DESC") {
             $direction = "ASC";
         } else {
             if ($_GET["direction"] == "ASC") {
                 $direction = "DESC";
             }
         }
     }
     if (isset($_GET["sort"]) && $_GET["sort"]) {
         $sort = $_GET["sort"];
     }
     $pageCompose->readInputData($offset, 20);
     $mysqlLimits = $pageCompose->calculateOffset();
     $pages = $pageCompose->genPages();
     self::$smarty->assign("pages", $pages);
     self::$smarty->assign("direction", $direction);
     self::$smarty->assign("sort", $sort);
     self::$smarty->assign("allCount", $allCount["cnt"]);
     $sqlData = self::$db->query("SELECT * FROM `{$target}` {$clauseSTR} ORDER BY `{$sort}` {$direction} LIMIT \n\t\t\t{$mysqlLimits["start"]},{$mysqlLimits["end"]}");
     if ($target != "categories") {
         $sqlData->runAfterFetchAll[] = array("news", "makeSlug");
     }
     $res = $sqlData->fetchAll();
     self::$smarty->assign("list", $res);
     return $res;
 }