예제 #1
0
 public static function getArticles($limit)
 {
     $t_nodes = TABLE_ARTICLES;
     $t_users = TABLE_USERS;
     $query_str = "SELECT *," . "{$t_nodes}.id as id " . "FROM {$t_nodes} " . "LEFT JOIN {$t_users} ON {$t_nodes}.author_id = {$t_users}.id " . "ORDER BY created_time DESC " . ($limit > 0 ? "LIMIT {$limit}" : "");
     $query = G::$db->query($query_str) or G::fatalError("ArticleUtils::getArticles() : " . DATABASE_ERROR_MESSAGE);
     $list = $query->fetchAll(PDO::FETCH_ASSOC);
     return $list;
 }
 private function initModule()
 {
     if (G::$user->isOrHigher(U_MODERATOR) && (!isset(G::$modules) || !is_array(G::$modules) || !count(G::$modules))) {
         G::fatalError("AdminModulesManager::initOvertopBlock() : Modules' config had not been inited yet!");
     }
     if (!$this->currentModule) {
         if (isset(G::$modules[$this->moduleLabel])) {
             $this->moduleClassName = $className = G::$modules[$this->moduleLabel];
             $adminModule = new $className();
             if (!$adminModule instanceof iAdminModule) {
                 G::fatalError("PageData::getAdminPageItem() : Admin module (" . G::$modules[$this->moduleLabel] . " => " . $className . ") does not implement iAdminModule correct.");
             }
         }
         $this->currentModule = $adminModule;
     }
 }
예제 #3
0
 public static function getAllCurrency()
 {
     $entities = array();
     $query = G::$db->query("SELECT * FROM " . TABLE_CURRENCY) or G::fatalError("PageUtils::getAllCurrency() -> " . DATABASE_ERROR_MESSAGE);
     while ($row = $query->fetch()) {
         $entities[$row["id"]] = $row;
     }
     return $entities;
 }
예제 #4
0
 /**
  * Load titles of each path label
  */
 public static function getPathItems($path_arr)
 {
     # TODO path items limit!
     $path_items = array();
     $t_cat = TABLE_CATALOGUE;
     $addr = "'" . implode("','", $path_arr) . "'";
     $query = G::$db->query("SELECT * FROM {$t_cat} WHERE label IN ({$addr})");
     while ($row = $query->fetch()) {
         $key = array_search($row["label"], $path_arr);
         $path_items[$key] = $row;
     }
     if (count($path_arr) !== count($path_items)) {
         # TODO redirect on 404
         // DEBUG
         G::fatalError("CatalogueUtils::getPathItems() : Some of items not found!");
         //
     }
     return $path_items;
 }
예제 #5
0
     break;
 case GET_CATEGORIES_TREE:
     init("admin/catalogue");
     // PageData load
     G::$pageData->load();
     if (G::$user->isOrHigher(U_MODERATOR)) {
         include $_SERVER["DOCUMENT_ROOT"] . PATH_INCLUDES . "admin/admin_categories_tree.php";
     } else {
         echo "ACCESS DENIED";
     }
     die;
     break;
 case GET_POPUP_CONTENT:
     $label = $_POST["label"];
     if (!preg_match("/^\\/?admin\\/.*/", $label)) {
         G::fatalError("Access denied!");
     }
     init($label);
     // PageData load
     G::$pageData->load();
     $popup = new PopupManager($_POST["type"]);
     $popup->renderPopupContent();
     die;
     break;
 case UPLOAD_IMAGE:
     init("admin/catalogue/product");
     if (G::$user->isOrHigher(U_MODERATOR)) {
         $data = AdminUtils::uploadProductImage($_FILES["file_browse"]);
         G::logMessage($data["img_filename"]);
         $data["result"] = true;
     } else {
예제 #6
0
 /** CREATE or UPDATE catalogue node
  * @param $data - product\category data
  * @return bool
  */
 public function updateCatalogue($data)
 {
     // rename item_type (client vars conflict)
     $data["type"] = $data["item_type"];
     unset($data["item_type"]);
     //
     // parent_id
     $validation = PageUtils::validatePageParam($data["parent_id"], "parent_id");
     if (!$validation["result"]) {
         G::fatalError("PARENT_ID is not valid");
     }
     unset($data["parent_id"]);
     $parent_id = $validation["value"];
     //
     // images
     //G::logMessage("IMAGES: " . "small=" . $data["img_small"] . "&medium=" . $data["img_medium"] . "&large=" . $data["img_large"]);
     $data["image"] = "small=" . $data["img_small"] . "&medium=" . $data["img_medium"] . "&large=" . $data["img_large"];
     unset($data["img_small"], $data["img_medium"], $data["img_large"]);
     //
     $data = $this->validatePageData($data, P_TYPE_CATALOGUE);
     //check if label already exists
     if (!$this->checkNewLabel($data["id"], $data["label"])) {
         $this->errors[] = "Label already exists in another product";
     }
     $result = false;
     if (count($this->errors) == 0) {
         if (isset($data["id"])) {
             // UPDATE PAGE
             $result = CatalogueUtils::updateCatalogueNode($data["id"], $data);
             $parents = CatalogueUtils::findParentsOf($data["id"]);
             $parentAlreadyHasIt = false;
             foreach ($parents as $parent) {
                 if ($parent["id"] != $parent_id) {
                     CatalogueUtils::deleteChildFromParent($data["id"], $parent["id"]);
                 } else {
                     $parentAlreadyHasIt = true;
                 }
             }
             if (!$parentAlreadyHasIt && $parent_id) {
                 CatalogueUtils::addChildToParent($data["id"], $parent_id);
             }
         } else {
             // CREATE NEW NODE
             $result = CatalogueUtils::createCatalogueNode($data, $parent_id);
         }
         // check db errors
         if (intval(G::$db->errorCode()) != 0) {
             $error_info = G::$db->errorInfo();
             $text_error = " DB >> " . $error_info[1] . " > " . $error_info[2];
             $this->errors[] = RenderUtils::renderError($text_error);
         }
         if (count($this->errors) == 0 && $result) {
             //reinit
             $this->init("catalogue/" . $data["label"]);
             $this->load();
         }
     }
     return $result;
 }