View file application/system/library/class.admin.php

File size: 3.88Kb
<?PHP
	class Admin {
		/*
			Получить карточки участников
		*/
		public function getCardPeople() {
			try {
				$sth = pdo()->query('SELECT * FROM `users`');
				
				if(!$sth->rowCount()) {
					return 'Список пуст';
				}
				
				while($dataUser = $sth->fetch(PDO::FETCH_OBJ)) {
					tpl()->AddCell('listPeople', tpl()->Set([
						'{profile_id}' => $dataUser->id,
						'{profile_image}' => getAvatar($dataUser->id),
						'{profile_name}' => getName($dataUser->id)
					], tpl()->Get('elements/cards/user')));
				}
				
				return tpl()->Execute(tpl()->GetCell('listPeople'));
			}
			catch(Exception $e) {
				return $e->getMessage();
			}
		}
		
		/*
			Изменение учётной записи
		*/
		public function editPeople($_ARRAY = []) {
			try {
				$sth = pdo()->prepare('UPDATE `users` SET `first_name`=:first_name, `last_name`=:last_name WHERE `id`=:userid LIMIT 1');
				$sth->execute([
					':first_name' => $_ARRAY['first_name'],
					':last_name' => $_ARRAY['last_name'],
					':userid' => $_ARRAY['userid']
				]);
				
				return true;
			}
			catch(Exception $e) {
				throw new Exception($e->getMessage());
			}
		}
		
		/*
			Изменение пароля
		*/
		public function changePassword($_ARRAY = []) {
			try {
				$sth = pdo()->prepare('UPDATE `users` SET `password`=:password WHERE `id`=:userid LIMIT 1');
				$sth->execute([
					':password' => password_hash($_ARRAY['password'], PASSWORD_DEFAULT),
					':userid' => $_ARRAY['userid']
				]);
				
				return true;
			}
			catch(Exception $e) {
				throw new Exception($e->getMessage());
			}
		}
		
		/*
			Подтверждение профиля
		*/
		public function confirmProfile($_ARRAY = []) {
			try {
				$sth = pdo()->prepare('UPDATE `users` SET `approved`=:approved WHERE `id`=:userid LIMIT 1');
				$sth->execute([
					':approved' => $_ARRAY['approved'],
					':userid' => $_ARRAY['userid']
				]);
				
				return true;
			}
			catch(Exception $e) {
				throw new Exception($e->getMessage());
			}
		}
		
		/*
			Получение загружаемого контента
		*/
		public function listUploadFiles() {
			try {
				$sth = pdo()->query('SELECT * FROM `messages__files` ORDER BY `id` DESC');
				
				if(!$sth->rowCount()) {
					return getLang('admin_disk_no_rows');
				}
				
				$listRecipients = '';
				
				while($File = $sth->fetch(PDO::FETCH_OBJ)) {
					$recipients = peerParticipants($File->peerid);
					unset($recipients[$File->userid]);
					
					foreach($recipients as $userid => $data) {
						$listRecipients .= '<a href="/admin/people?id=' . $userid . '">' . getName($userid) . '</a> ';
					}
					
					tpl()->AddCell('adminListFiles', tpl()->Set([
						'{sender}' => '<a href="/admin/people?id=' . $File->userid . '">' . getName($File->userid) . '</a>',
						'{recipient}' => $listRecipients,
						'{date}' => timeElapsedString($File->date),
						'{date_full}' => date('d.m.Y H:i:s', $File->date),
						'{type}' => $File->type,
						'{size}' => $File->size,
						'{path}' => $File->path,
						'{name}' => $File->name,
						'{verified}' => empty($File->verified) ? 'NULL' : $File->verified
					], tpl()->Get('elements/table/file')));
					
					$listRecipients = '';
				}
				
				return tpl()->Execute(tpl()->GetCell('adminListFiles'));
			}
			catch(Exception $e) {
				return getLang('admin_disk_no_search');
			}
		}
		
		/*
			Удаление учётной записи
		*/
		public function removeProfile($userid) {
			if(!users()->IsValid($userid)) {
				return true;
			}
			
			try {
				$sth = pdo()->prepare('DELETE FROM `users` WHERE `id`=:userid LIMIT 1');
				$sth->execute([
					':userid' => $userid
				]);
				
				return true;
			}
			catch(Exception $e) {
				throw new Exception($e->getMessage());
			}
		}
	}