id = $id; if ($id) { if (!$my) $my = $interface->getIdentifiedUser($id); if ($my->gid) { $this->name = $my->username; $this->fullname = $my->name; $this->usertype = $my->usertype; $this->logged = true; if ((strtolower($my->usertype)=='administrator') OR (strtolower($my->usertype)=='superadministrator') OR (strtolower($my->usertype)=='super administrator')){ $this->admin = true; } } if (isset($my->jaclplus)) $this->jaclplus = $my->jaclplus; } $this->currIP = getenv('REMOTE_ADDR'); $authoriser = aliroAuthoriser::getInstance(); $this->refused = $authoriser->getRefusedList ('aUser', $this->id, 'remosFolder', 'download,edit'); } public function isAdmin () { return $this->admin; } public function isUser () { if ($this->isAdmin()) return false; return $this->isLogged(); } public function isLogged () { return $this->logged; } public function fullname () { return $this->fullname; } public function canDownloadContainer($id) { return (!in_array($id, $this->refused)); } public function uploadsToday () { $interface = remositoryInterface::getInstance(); $database = $interface->getDB(); $today = date('Y-m-d'); // Change for multiple repositories // $repnum = max(1, remositoryRepository::getParam($_REQUEST, 'repnum', 1)); // $sql="SELECT COUNT(*) from #__downloads_files WHERE repnum = $repnum AND submittedby=".$this->id." AND submitdate LIKE '".$today."%'"; $sql="SELECT COUNT(*) from #__downloads_files WHERE submittedby=".$this->id." AND submitdate LIKE '".$today."%'"; $database->setQuery($sql); return $database->loadResult(); } public function allowUploadCheck ($container, $controller) { if ($this->isAdmin()) return; $repository = remositoryRepository::getInstance(); if (!$repository->Allow_User_Sub) { echo "\n"; exit(); } $authoriser = aliroAuthoriser::getInstance(); if ($authoriser->checkPermission ('aUser', $this->id, 'upload', 'remosFolder', $container->id) OR $authoriser->checkPermission ('aUser', $this->id, 'edit', 'remosFolder', $container->id)) { if ($this->logged) { if ($this->uploadsToday() > $repository->Max_Up_Per_Day) { $view = new remositoryErrorDisplaysHTML($controller); $view->uploadLimit(); exit; } } return; } $view = new remositoryErrorDisplaysHTML($controller); $view->noaccess($container); exit; } public function hasAutoApprove ($container) { // Remove this line if visitors can self-approve - // containers must also be set with self approve permission for Visitor if (!$this->isLogged()) return false; $repository = remositoryRepository::getInstance(); if ($this->isAdmin()) { if ($repository->Enable_Admin_Autoapp) return true; } $authoriser = aliroAuthoriser::getInstance(); if ($authoriser->checkPermission ('aUser', 0, 'selfApprove', 'remosFolder', $container->id)) return false; if ($authoriser->checkPermission ('aUser', $this->id, 'selfApprove', 'remosFolder', $container->id)) return true; return false; } public static function superAdminMail () { $interface = remositoryInterface::getInstance(); $database = $interface->getDB(); $sql="select email, name from #__users where usertype='superadministrator' or usertype='super administrator'"; $database->setQuery( $sql ); $row=null; $result = $database->loadObject( $row ); if (is_object($result)) $row = $result; if ($row) return $row->email; else return null; } private function getDownloadInfo () { if ($this->totaldown_set) return; $results = $this->id ? $this->loggedCount() : $this->nonLoggedCount(); if ($results) foreach ($results as $result) { $this->downloads[$result->fileid] = $result->number; $this->totaldown += $result->number; } $this->totaldown_set = true; } private function nonLoggedCount () { $interface = remositoryInterface::getInstance(); $ipaddress = getenv('REMOTE_ADDR'); $database = $interface->getDB(); $type = _REM_LOG_DOWNLOAD; $database->setQuery("SELECT fileid, COUNT(fileid) AS number FROM #__downloads_log WHERE type = $type AND ipaddress = '$ipaddress' AND date > SUBDATE(NOW(), INTERVAL 24 HOUR) GROUP BY fileid"); return $database->loadObjectList(); } private function loggedCount () { $interface = remositoryInterface::getInstance(); $database = $interface->getDB(); $type = _REM_LOG_DOWNLOAD; $typadmin = _REM_LOG_ADMIN_DOWNLOAD; $database->setQuery("SELECT fileid, COUNT(fileid) AS number FROM #__downloads_log WHERE (type = $type OR type = $typadmin) AND userid = $this->id AND date > SUBDATE(NOW(), INTERVAL 24 HOUR) GROUP BY fileid"); return $database->loadObjectList(); } public function downloadCount ($id) { $this->getDownloadInfo(); return isset($this->downloads[$id]) ? $this->downloads[$id] : 0; } public function maxDownloadsOneFile () { return remositoryRepository::getInstance()->Max_Down_File_Day; } public function totalDown () { $this->getDownloadInfo(); return $this->totaldown; } public function maxDownloadsAllFiles () { $repository = remositoryRepository::getInstance(); return $this->isLogged() ? $repository->Max_Down_Reg_Day : $repository->Max_Down_Per_Day; } public function creditsAvailable () { if ($this->credits_set) return $this->credits; if (_REMOSITORY_REQUIRE_VODES_FOR_DOWNLOAD) { $interface = remositoryInterface::getInstance(); $database = $interface->getDB(); $database->setQuery("SELECT credit FROM #__vodes_credits WHERE userid = $this->id"); $result = $database->loadResult(); $this->credits = $result ? $result : 0; } else $this->credits = _REMOSITORY_USE_CREDITS ? 0 : 999999; $this->credits_set = true; return $this->credits; } function chargeCreditsForFile ($file) { if (_REMOSITORY_REQUIRE_VODES_FOR_DOWNLOAD) { remositoryRepository::doSQL("UPDATE #__vodes_credits SET credit = credit - $file->price WHERE userid = $this->id"); } } public static function getUser ($id=0, $my=null) { return isset(self::$users[$id]) ? self::$users[$id] : self::$users[$id] = new self($id, $my); } public static function mailPeopleViewingContainer ($containerid, $subject, $body, $fileid=0) { $interested = aliroAuthoriser::getInstance()->listAccessorsToSubject ('remosFolder', $containerid, 'aUser', 'download'); if (!empty($interested)) { $interface = remositoryInterface::getInstance(); $repository = remositoryRepository::getInstance(); if ($fileid) $body .= sprintf(_DOWN_LINK_TO_FILE, $repository->remositoryBasicFunctionURL('fileinfo', $fileid)); else $body .= sprintf(_DOWN_LINK_TO_CONTAINER, $repository->remositoryBasicFunctionURL('select', $containerid)); $listed = implode(',', $interested); $database = $interface->getDB(); $database->setQuery("SELECT name, email FROM #__users WHERE id IN ($listed)"); $people = $database->loadObjectList(); if (!empty($people)) { foreach ($people as $person) { $body = sprintf($body, $person->name); $interface->sendMail($person->email, $subject, $body); sleep(1); } } } } }