diff --git a/objects/category.php b/objects/category.php index 9bb4d0c43..7d57a6775 100644 --- a/objects/category.php +++ b/objects/category.php @@ -1,686 +1,740 @@ order); } function setOrder($order) { $this->order = intval($order); } function getUsers_id() { if (empty($this->users_id)) { $this->users_id = User::getId(); } return $this->users_id; } function getPrivate() { return $this->private; } function setUsers_id($users_id) { // only admin can change owner if (!empty($this->users_id) && !User::isAdmin()) { return false; } $this->users_id = intval($users_id); } function setPrivate($private) { $this->private = empty($private) ? 0 : 1; } function setName($name) { $this->name = xss_esc($name); } function setClean_name($clean_name) { $clean_name = preg_replace('/\W+/', '-', strtolower(cleanString($clean_name))); $this->clean_name = $clean_name; } function setNextVideoOrder($nextVideoOrder) { $this->nextVideoOrder = $nextVideoOrder; } function setParentId($parentId) { $this->parentId = $parentId; } /* function setType($type, $overwriteUserId = 0) { global $global; $internalId = $overwriteUserId; if (empty($internalId)) { $internalId = $this->id; } $exist = false; // require this cause of Video::autosetCategoryType - but should be moveable easy here.. require_once dirname(__FILE__) . '/../objects/video.php'; $sql = "SELECT * FROM `category_type_cache` WHERE categoryId = ?"; $res = sqlDAL::readSql($sql, "i", array($internalId)); $catTypeCache = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($catTypeCache != false) { $exist = true; } if ($type == "3") { // auto-cat-type Video::autosetCategoryType($internalId); } else { if ($exist) { $sql = "UPDATE `category_type_cache` SET `type` = ?, `manualSet` = '1' WHERE `category_type_cache`.`categoryId` = ?;"; sqlDAL::writeSql($sql, "si", array($type, $internalId)); } else { $sql = "INSERT INTO `category_type_cache` (`categoryId`, `type`, `manualSet`) VALUES (?,?,'1')"; sqlDAL::writeSql($sql, "is", array($internalId, $type)); } } } * */ function setDescription($description) { $this->description = xss_esc($description); } function __construct($id, $name = '') { if (empty($id)) { // get the category data from category and pass $this->name = xss_esc($name); } else { $this->id = $id; // get data from id $this->load($id); } } private function load($id) { $row = self::getCategory($id); if (empty($row)) return false; foreach ($row as $key => $value) { $this->$key = $value; } return true; } function loadSelfCategory() { $this->load($this->getId()); } function save($allowOfflineUser = false) { global $global; if (!$allowOfflineUser && !self::canCreateCategory()) { return false; } if (!$allowOfflineUser && !empty($this->id) && !self::userCanEditCategory($this->id)) { return false; } if (empty($this->users_id)) { $this->users_id = User::getId(); } $this->clean_name = self::fixCleanTitle($this->clean_name, 1, $this->id); // check if clean name exists $exists = $this->getCategoryByName($this->clean_name); if (!empty($exists) && $exists['id'] != $this->id) { $this->clean_name .= uniqid(); } $this->nextVideoOrder = intval($this->nextVideoOrder); $this->parentId = intval($this->parentId); if (!empty($this->id)) { $sql = "UPDATE categories SET " . "name = ?," . "clean_name = ?," . "description = ?," . "nextVideoOrder = ?," . "parentId = ?," . "iconClass = ?," . "users_id = ?," . "`private` = ?, allow_download = ?, `order` = ?, modified = now() WHERE id = ?"; $format = "sssiisiiiii"; $values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder(), $this->id); } else { $sql = "INSERT INTO categories ( " . "name," . "clean_name," . "description," . "nextVideoOrder," . "parentId," . "iconClass, " . "users_id, " . "`private`, allow_download, `order`, created, modified) VALUES (?, ?,?,?,?,?,?,?,?,?,now(), now())"; $format = "sssiisiiii"; $values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder()); } $insert_row = sqlDAL::writeSql($sql, $format, $values); if ($insert_row) { - $_SESSION['getAllCategoriesClearCache'] = 1; + $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; ObjectYPT::deleteALLCache(); if (empty($this->id)) { $id = $global['mysqli']->insert_id; } else { $id = $this->id; } return $id; } else { die($sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } } static function fixCleanTitle($clean_title, $count, $id, $original_title = "") { global $global; if (empty($original_title)) { $original_title = $clean_title; } $sql = "SELECT * FROM categories WHERE clean_name = '{$clean_title}' "; if (!empty($id)) { $sql .= " AND id != {$id} "; } $sql .= " LIMIT 1"; $res = sqlDAL::readSql($sql, "", array(), true); $cleanTitleExists = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($cleanTitleExists != false) { return self::fixCleanTitle($original_title . "-" . $count, $count + 1, $id, $original_title); } return $clean_title; } function delete() { if (!self::canCreateCategory()) { return false; } if (!self::userCanEditCategory($this->id)) { return false; } // cannot delete default category if ($this->id == 1) { return false; } global $global; if (!empty($this->id)) { - $_SESSION['getAllCategoriesClearCache'] = 1; + $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; $categories_id = self::getSiteCategoryDefaultID(); if ($categories_id) { $sql = "UPDATE videos SET categories_id = ? WHERE categories_id = ?"; sqlDAL::writeSql($sql, "ii", array($categories_id, $this->id)); } $sql = "DELETE FROM categories WHERE id = ?"; } else { return false; } self::clearCacheCount(); self::deleteAssets($this->id); return sqlDAL::writeSql($sql, "i", array($this->id)); } static function deleteAssets($categories_id) { $dirPaths = self::getCategoryDirPath($categories_id); return rrmdir($dirPaths['path']); } /* static function getCategoryType($categoryId) { global $global; $sql = "SELECT * FROM `category_type_cache` WHERE categoryId = ?;"; $res = sqlDAL::readSql($sql, "i", array($categoryId)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { if (!empty($data)) { return $data; } else { return array("categoryId" => "-1", "type" => "0", "manualSet" => "0"); } } else { return array("categoryId" => "-1", "type" => "0", "manualSet" => "0"); } } * */ static function getCategory($id) { global $global; $id = intval($id); $sql = "SELECT * FROM categories WHERE id = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "i", array($id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $result['name'] = xss_esc_back($result['name']); } return ($res) ? $result : false; } static function getCategoryByName($name) { global $global; $sql = "SELECT * FROM categories WHERE clean_name = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "s", array($name)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $result['name'] = xss_esc_back($result['name']); } return ($res) ? $result : false; } static function getOrCreateCategoryByName($name) { $cat = self::getCategoryByName($name); if (empty($cat)) { $obj = new Category(0); $obj->setName($name); $obj->setClean_name($name); $obj->setDescription(""); $obj->setIconClass(""); $obj->setNextVideoOrder(0); $obj->setParentId(0); $id = $obj->save(); return self::getCategoryByName($name); } return $cat; } static function getCategoryDefault() { global $global; $sql = "SELECT * FROM categories ORDER BY id ASC LIMIT 1"; $res = sqlDAL::readSql($sql); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $result['name'] = xss_esc_back($result['name']); } return ($res) ? $result : false; } static function getSiteCategoryDefaultID() { $obj = AVideoPlugin::getObjectDataIfEnabled("PredefinedCategory"); $id = false; if ($obj) { $id = $obj->defaultCategory; } else { $row = self::getCategoryDefault(); if ($row) { $id = $row['id']; } } return $id; } static function getAllCategories($filterCanAddVideoOnly = false, $onlyWithVideos = false) { global $global, $config; if ($config->currentVersionLowerThen('8.4')) { return false; } $sql = "SELECT * FROM categories c WHERE 1=1 "; if (!empty($_GET['parentsOnly'])) { $sql .= "AND parentId = 0 "; } if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } if ($onlyWithVideos) { - $sql .= " AND (SELECT count(*) FROM videos where categories_id = c.id OR categories_id IN (SELECT id from categories where parentId = c.id)) > 0 "; + $sql .= " AND ((SELECT count(*) FROM videos v where v.categories_id = c.id OR categories_id IN (SELECT id from categories where parentId = c.id)) > 0 "; + if(AVideoPlugin::isEnabledByName("Live")){ + $sql .= " OR " + . " (" + . " SELECT count(*) FROM live_transmitions lt where " + . " (lt.categories_id = c.id OR lt.categories_id IN (SELECT id from categories where parentId = c.id))" + //. " AND lt.id = (select id FROM live_transmitions lt2 WHERE lt.users_id = lt2.users_id ORDER BY CREATED DESC LIMIT 1 )" + . " ) > 0 "; + } + $sql .= ")"; } if (isset($_POST['sort']['title'])) { unset($_POST['sort']['title']); } $sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY `order`, name ASC "); - + $cacheName = md5($sql); - if (empty($_SESSION['getAllCategoriesClearCache'])) { + if (empty($_SESSION['user']['sessionCache']['getAllCategoriesClearCache'])) { $category = object_to_array(ObjectYPT::getCache($cacheName, 36000)); } else { _session_start(); - unset($_SESSION['getAllCategoriesClearCache']); + unset($_SESSION['user']['sessionCache']['getAllCategoriesClearCache']); } if (empty($category)) { $res = sqlDAL::readSql($sql); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $category = array(); if ($res) { foreach ($fullResult as $row) { + + $totals = self::getTotalFromCategory($row['id']); + $fullTotals = self::getTotalFromCategory($row['id'], false, true, true); + $row['name'] = xss_esc_back($row['name']); - $row['total'] = self::getTotalVideosFromCategory($row['id']); - $row['fullTotal'] = self::getTotalVideosFromCategory($row['id'], false, true, true); + $row['total'] = $totals['total']; + $row['total_array'] = $totals; + $row['fullTotal'] = $fullTotals['total']; + $row['fullTotal_videos'] = $fullTotals['videos']; + $row['fullTotal_lives'] = $fullTotals['lives']; $row['owner'] = User::getNameIdentificationById(@$row['users_id']); $row['canEdit'] = self::userCanEditCategory($row['id']); $row['canAddVideo'] = self::userCanAddInCategory($row['id']); $row['hierarchy'] = self::getHierarchyString($row['parentId']); $row['hierarchyAndName'] = $row['hierarchy'] . $row['name']; $category[] = $row; } //$category = $res->fetch_all(MYSQLI_ASSOC); ObjectYPT::setCache($cacheName, $category); } else { $category = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } } return $category; } static function getHierarchyArray($categories_id, $hierarchyArray = array()) { if (empty($categories_id)) { return $hierarchyArray; } $sql = "SELECT * FROM categories WHERE id=? "; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $hierarchyArray[] = $result; return self::getHierarchyArray($result['parentId'], $hierarchyArray); } return $hierarchyArray; } static function getHierarchyString($categories_id) { if (empty($categories_id)) { return "/"; } $array = array_reverse(self::getHierarchyArray($categories_id)); //$array = (self::getHierarchyArray($categories_id)); //var_dump($array);exit; if (empty($array)) { return "/"; } $str = "/"; foreach ($array as $value) { $str .= xss_esc_back($value['name']) . "/"; } return $str; } static function userCanAddInCategory($categories_id, $users_id = 0) { if (empty($categories_id)) { return false; } if (empty($users_id)) { $users_id = User::getId(); } if (empty($users_id)) { return false; } $cat = new Category($categories_id); if (empty($cat->getPrivate()) || $users_id == $cat->getUsers_id()) { return true; } return false; } static function userCanEditCategory($categories_id, $users_id = 0) { if (empty($categories_id)) { return false; } if (empty($users_id)) { $users_id = User::getId(); } if (empty($users_id)) { return false; } if (User::isAdmin()) { return true; } $cat = new Category($categories_id); if ($users_id == $cat->getUsers_id()) { return true; } return false; } static function canCreateCategory() { global $advancedCustomUser; if (User::isAdmin()) { return true; } if ($advancedCustomUser && $advancedCustomUser->usersCanCreateNewCategories && User::canUpload()) { return true; } return false; } static function getChildCategories($parentId, $filterCanAddVideoOnly = false) { global $global, $config; if ($config->currentVersionLowerThen('8.4')) { return false; } $sql = "SELECT * FROM categories WHERE parentId=? AND id!=? "; if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } $sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY `order`, name ASC "); $res = sqlDAL::readSql($sql, "ii", array($parentId, $parentId)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $category = array(); if ($res) { foreach ($fullResult as $row) { + $totals = self::getTotalFromCategory($row['id']); $row['name'] = xss_esc_back($row['name']); - $row['total'] = self::getTotalVideosFromCategory($row['id']); + $row['total'] = $totals['total']; + $row['total_array'] = $totals; $category[] = $row; } } else { $category = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $category; } static function getChildCategoriesFromTitle($clean_title) { $row = self::getCategoryByName($clean_title); return self::getChildCategories($row['id']); } + + static function getTotalFromCategory($categories_id, $showUnlisted = false, $getAllVideos = false, $renew = false) { + $videos = self::getTotalVideosFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew); + $lives = self::getTotalLivesFromCategory($categories_id, $showUnlisted, $renew); + $total = $videos+$lives; + return array('videos'=>$videos, 'lives'=>$lives, 'total'=>$total); + } + static function getTotalVideosFromCategory($categories_id, $showUnlisted = false, $getAllVideos = false, $renew = false) { global $global, $config; - if ($renew || empty($_SESSION['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)])) { + if (true || $renew || empty($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos'])) { $sql = "SELECT count(id) as total FROM videos v WHERE 1=1 AND categories_id = ? "; if (User::isLogged()) { $sql .= " AND (v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "') OR (v.status='u' AND v.users_id ='" . User::getId() . "'))"; } else { $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "')"; } if (!$getAllVideos) { $sql .= Video::getUserGroupsCanSeeSQL(); } //echo $categories_id, $sql;exit; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $total = empty($fullResult[0]['total']) ? 0 : intval($fullResult[0]['total']); $rows = self::getChildCategories($categories_id); foreach ($rows as $value) { $total += self::getTotalVideosFromCategory($value['id'], $showUnlisted, $getAllVideos, $renew); } _session_start(); - $_SESSION['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)] = $total; + $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos'] = $total; } - return $_SESSION['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]; + return $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos']; } + + static function getTotalLivesFromCategory($categories_id, $showUnlisted = false, $renew = false) { + global $global; + if ($renew || empty($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live'])) { + $sql = "SELECT count(id) as total FROM live_transmitions v WHERE 1=1 AND categories_id = ? "; - static function clearCacheCount() { + if (empty($showUnlisted)) { + $sql .= " AND public = 1 "; + } + + //echo $categories_id, $sql;exit; + $res = sqlDAL::readSql($sql, "i", array($categories_id)); + $fullResult = sqlDAL::fetchAllAssoc($res); + sqlDAL::close($res); + $total = empty($fullResult[0]['total']) ? 0 : intval($fullResult[0]['total']); + $rows = self::getChildCategories($categories_id); + foreach ($rows as $value) { + $total += self::getTotalLivesFromCategory($value['id'], $showUnlisted, $renew); + } + _session_start(); + $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live'] = $total; + } + return $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live']; + } + + static function clearCacheCount($categories_id=0) { // clear category count cache _session_start(); - unset($_SESSION['categoryTotal']); - $_SESSION['getAllCategoriesClearCache'] = 1; + if(empty($categories_id)){ + unset($_SESSION['user']['sessionCache']['categoryTotal']); + $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; + }else{ + unset($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id]); + } //session_write_close(); } static function getTotalCategories($filterCanAddVideoOnly = false) { global $global, $config; if ($config->currentVersionLowerThen('5.01')) { return false; } $sql = "SELECT id, parentId FROM categories WHERE 1=1 "; if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } if (!empty($_GET['parentsOnly'])) { $sql .= "AND parentId = 0 OR parentId = -1 "; } $sql .= BootGrid::getSqlSearchFromPost(array('name')); $res = sqlDAL::readSql($sql); $numRows = sqlDal::num_rows($res); sqlDAL::close($res); return $numRows; } function getIconClass() { if (empty($this->iconClass)) { return "fa fa-folder"; } return $this->iconClass; } function setIconClass($iconClass) { $this->iconClass = $iconClass; } function getName() { return $this->name; } function getClean_name() { return $this->clean_name; } function getDescription() { return $this->description; } function getAllow_download() { return $this->allow_download; } function setAllow_download($allow_download) { $this->allow_download = intval($allow_download); } static function getCategoryDirPath($categories_id = "") { global $global; $dir = "videos/categories/assets/"; if (!empty($categories_id)) { $dir .= $categories_id . "/"; } $path = array(); $path['dir'] = "{$global['systemRootPath']}{$dir}"; make_path($path['dir']); $path['path'] = "{$global['systemRootPath']}{$dir}"; $path['url'] = "{$global['webSiteRootURL']}{$dir}"; return $path; } static function isAssetsValids($categories_id) { $photo = Category::getCategoryPhotoPath($categories_id); $background = Category::getCategoryBackgroundPath($categories_id); if(!file_exists($photo['path']) || !file_exists($background['path'])){ return false; } return true; } static function getCategoryPhotoPath($categories_id) { return self::getCategoryAssetPath("photo.png", $categories_id); } static function getCategoryBackgroundPath($categories_id) { return self::getCategoryAssetPath("background.png", $categories_id); } private static function getCategoryAssetPath($name, $categories_id) { if (empty($categories_id)) { return false; } if (empty($name)) { return false; } $dirPaths = self::getCategoryDirPath($categories_id); global $global; $path = array(); $path['dir'] = $dirPaths['url']; $path['path'] = "{$dirPaths['path']}{$name}"; $path['url'] = "{$dirPaths['url']}{$name}"; if (file_exists($path['path'])) { $path['url+timestamp'] = "{$path['url']}?" . filectime($path['path']); } else { $path['url+timestamp'] = $path['url']; } return $path; } } diff --git a/objects/configurationClearCache.json.php b/objects/configurationClearCache.json.php index c6c7656b7..bc993fd52 100644 --- a/objects/configurationClearCache.json.php +++ b/objects/configurationClearCache.json.php @@ -1,22 +1,22 @@ error = true; $obj->msg = ""; if (!Permissions::canClearCache()) { $obj->msg = __("Permission denied"); die(json_encode($obj)); } _session_start(); -$_SESSION['getAllCategoriesClearCache'] = 1; +$_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; clearCache(); ObjectYPT::deleteALLCache(); $obj->error = false; die(json_encode($obj)); \ No newline at end of file diff --git a/plugin/Live/Objects/LiveTransmition.php b/plugin/Live/Objects/LiveTransmition.php index 299927d73..db48be927 100644 --- a/plugin/Live/Objects/LiveTransmition.php +++ b/plugin/Live/Objects/LiveTransmition.php @@ -1,306 +1,307 @@ id; } function getTitle() { return $this->title; } function getPublic() { return $this->public; } function getSaveTransmition() { return $this->saveTransmition; } function getUsers_id() { return $this->users_id; } function getCategories_id() { return $this->categories_id; } function getKey() { return $this->key; } function getDescription() { return $this->description; } function setId($id) { $this->id = $id; } function setTitle($title) { global $global; //$title = $global['mysqli']->real_escape_string($title); $this->title = xss_esc($title); } function setPublic($public) { $this->public = intval($public); } function setSaveTransmition($saveTransmition) { $this->saveTransmition = $saveTransmition; } function setUsers_id($users_id) { $this->users_id = $users_id; } function setCategories_id($categories_id) { $this->categories_id = $categories_id; } function setKey($key) { $this->key = $key; } function setDescription($description) { global $global; //$description = $global['mysqli']->real_escape_string($description); $this->description = xss_esc($description); } function loadByUser($user_id) { $user = self::getFromDbByUser($user_id); if (empty($user)) return false; foreach ($user as $key => $value) { $this->$key = $value; } return true; } function loadByKey($uuid) { $row = self::getFromKey($uuid); if (empty($row)) return false; foreach ($row as $key => $value) { $this->$key = $value; } return true; } static function getFromDbByUser($user_id) { global $global; $user_id = intval($user_id); $sql = "SELECT * FROM " . static::getTableName() . " WHERE users_id = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "i", array($user_id), true); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $user = $data; } else { $user = false; } return $user; } static function createTransmitionIfNeed($user_id) { if (empty($user_id)) { return false; } $row = static::getFromDbByUser($user_id); if ($row) { return $row; } $l = new LiveTransmition(0); $l->setTitle("Empty Title"); $l->setDescription(""); $l->setKey(uniqid()); $l->setCategories_id(1); $l->setUsers_id($user_id); $l->save(); return static::getFromDbByUser($user_id); } static function resetTransmitionKey($user_id) { $row = static::getFromDbByUser($user_id); $l = new LiveTransmition($row['id']); $newKey = uniqid(); $l->setKey($newKey); if($l->save()){ return $newKey; }else{ return false; } } static function getFromDbByUserName($userName) { global $global; $userName = $global['mysqli']->real_escape_string($userName); $sql = "SELECT * FROM users WHERE user = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "s", array($userName), true); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $user = $data; return static::getFromDbByUser($user['id']); } else { return false; } } static function keyExists($key) { global $global; if (!is_string($key)) { return false; } $parts = explode("_", $key); if(!empty($parts[1])){ $adaptive = array('hi', 'low', 'mid'); if(in_array($parts[1], $adaptive)){ return false; } } $key = $parts[0]; $key = preg_replace("/[^A-Za-z0-9]/", '', $key); $sql = "SELECT u.*, lt.* FROM " . static::getTableName() . " lt " . " LEFT JOIN users u ON u.id = users_id AND u.status='a' WHERE `key` = '$key' LIMIT 1"; $res = sqlDAL::readSql($sql); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } function save() { $this->public = intval($this->public); $this->saveTransmition = intval($this->saveTransmition); $this->showOnTV = intval($this->showOnTV); $id = parent::save(); + Category::clearCacheCount(); return $id; } function deleteGroupsTrasmition() { if (empty($this->id)) { return false; } global $global; $sql = "DELETE FROM live_transmitions_has_users_groups WHERE live_transmitions_id = ?"; return sqlDAL::writeSql($sql, "i", array($this->id)); } function insertGroup($users_groups_id) { global $global; $sql = "INSERT INTO live_transmitions_has_users_groups (live_transmitions_id, users_groups_id) VALUES (?,?)"; return sqlDAL::writeSql($sql, "ii", array($this->id, $users_groups_id)); } function isAPrivateLive(){ return !empty($this->getGroups()); } function getGroups() { $rows = array(); if (empty($this->id)) { return $rows; } global $global; $sql = "SELECT * FROM live_transmitions_has_users_groups WHERE live_transmitions_id = ?"; $res = sqlDAL::readSql($sql, "i", array($this->id)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); if ($res != false) { foreach ($fullData as $row) { $rows[] = $row["users_groups_id"]; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } function userCanSeeTransmition() { global $global; require_once $global['systemRootPath'] . 'objects/userGroups.php'; require_once $global['systemRootPath'] . 'objects/user.php'; if (User::isAdmin()) { return true; } $transmitionGroups = $this->getGroups(); if (!empty($transmitionGroups)) { if (empty($this->id)) { return false; } if (!User::isLogged()) { return false; } $userGroups = UserGroups::getUserGroups(User::getId()); if (empty($userGroups)) { return false; } foreach ($userGroups as $ugvalue) { foreach ($transmitionGroups as $tgvalue) { if ($ugvalue['id'] == $tgvalue) { return true; } } } return false; } else { return true; } } static function getFromKey($key) { global $global; $sql = "SELECT * FROM " . static::getTableName() . " WHERE `key` = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "s", array($key), true); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $user = $data; } else { $user = false; } return $user; } static function keyNameFix($key){ if(!empty($_REQUEST['playlists_id_live']) && !preg_match("/.*_([0-9]+)/", $key)){ $key .= "_{$_REQUEST['playlists_id_live']}"; } return $key; } function getShowOnTV() { return $this->showOnTV; } function setShowOnTV($showOnTV) { $this->showOnTV = $showOnTV; } } diff --git a/view/managerCategories_body.php b/view/managerCategories_body.php index e6472d8d5..be9641b3c 100644 --- a/view/managerCategories_body.php +++ b/view/managerCategories_body.php @@ -1,397 +1,398 @@
- + +
\ No newline at end of file