2021-12-14 18:32:47 +00:00
< ? php
declare ( strict_types = 1 );
2009-12-24 07:36:09 +00:00
2023-01-10 22:44:09 +00:00
namespace Shimmie2 ;
2019-05-28 16:59:38 +00:00
class Notes extends Extension
{
2020-01-26 13:19:35 +00:00
/** @var NotesTheme */
2023-06-27 14:56:49 +00:00
protected Themelet $theme ;
2020-01-26 13:19:35 +00:00
2024-01-15 18:01:48 +00:00
public function onInitExt ( InitExtEvent $event ) : void
{
2024-06-19 13:16:01 +00:00
global $config ;
2024-01-15 18:01:48 +00:00
Image :: $prop_types [ " notes " ] = ImagePropType :: INT ;
2024-06-19 13:16:01 +00:00
$config -> set_default_int ( " notesNotesPerPage " , 20 );
$config -> set_default_int ( " notesRequestsPerPage " , 20 );
$config -> set_default_int ( " notesHistoriesPerPage " , 20 );
2024-01-15 18:01:48 +00:00
}
2024-01-15 11:52:35 +00:00
public function onDatabaseUpgrade ( DatabaseUpgradeEvent $event ) : void
2019-05-28 16:59:38 +00:00
{
global $config , $database ;
// shortcut to latest
2019-11-03 19:49:52 +00:00
if ( $this -> get_version ( " ext_notes_version " ) < 1 ) {
2020-10-25 21:34:52 +00:00
$database -> execute ( " ALTER TABLE images ADD COLUMN notes INTEGER NOT NULL DEFAULT 0 " );
2019-05-28 16:59:38 +00:00
$database -> create_table ( " notes " , "
2009-12-24 07:36:09 +00:00
id SCORE_AIPK ,
enable INTEGER NOT NULL ,
image_id INTEGER NOT NULL ,
user_id INTEGER NOT NULL ,
user_ip CHAR ( 15 ) NOT NULL ,
2019-11-03 19:25:51 +00:00
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
2009-12-24 07:36:09 +00:00
x1 INTEGER NOT NULL ,
y1 INTEGER NOT NULL ,
height INTEGER NOT NULL ,
width INTEGER NOT NULL ,
note TEXT NOT NULL ,
2012-03-11 02:13:18 +00:00
FOREIGN KEY ( user_id ) REFERENCES users ( id ) ON UPDATE CASCADE ON DELETE CASCADE ,
2009-12-24 07:36:09 +00:00
FOREIGN KEY ( image_id ) REFERENCES images ( id ) ON DELETE CASCADE
" );
2019-05-28 16:59:38 +00:00
$database -> execute ( " CREATE INDEX notes_image_id_idx ON notes(image_id) " , []);
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$database -> create_table ( " note_request " , "
2009-12-24 07:36:09 +00:00
id SCORE_AIPK ,
image_id INTEGER NOT NULL ,
user_id INTEGER NOT NULL ,
2019-11-03 19:25:51 +00:00
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
2012-03-11 02:13:18 +00:00
FOREIGN KEY ( user_id ) REFERENCES users ( id ) ON UPDATE CASCADE ON DELETE CASCADE ,
2009-12-24 07:36:09 +00:00
FOREIGN KEY ( image_id ) REFERENCES images ( id ) ON DELETE CASCADE
" );
2019-05-28 16:59:38 +00:00
$database -> execute ( " CREATE INDEX note_request_image_id_idx ON note_request(image_id) " , []);
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$database -> create_table ( " note_histories " , "
2009-12-24 07:36:09 +00:00
id SCORE_AIPK ,
note_enable INTEGER NOT NULL ,
note_id INTEGER NOT NULL ,
review_id INTEGER NOT NULL ,
image_id INTEGER NOT NULL ,
user_id INTEGER NOT NULL ,
user_ip CHAR ( 15 ) NOT NULL ,
2019-11-03 19:25:51 +00:00
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
2009-12-24 07:36:09 +00:00
x1 INTEGER NOT NULL ,
y1 INTEGER NOT NULL ,
height INTEGER NOT NULL ,
width INTEGER NOT NULL ,
note TEXT NOT NULL ,
2012-03-11 02:13:18 +00:00
FOREIGN KEY ( user_id ) REFERENCES users ( id ) ON UPDATE CASCADE ON DELETE CASCADE ,
2009-12-24 07:36:09 +00:00
FOREIGN KEY ( note_id ) REFERENCES notes ( id ) ON DELETE CASCADE
" );
2019-05-28 16:59:38 +00:00
$database -> execute ( " CREATE INDEX note_histories_image_id_idx ON note_histories(image_id) " , []);
2019-11-03 19:49:52 +00:00
$this -> set_version ( " ext_notes_version " , 1 );
2019-05-28 16:59:38 +00:00
}
}
2024-01-15 11:52:35 +00:00
public function onPageRequest ( PageRequestEvent $event ) : void
2019-05-28 16:59:38 +00:00
{
global $page , $user ;
2024-02-11 11:34:09 +00:00
if ( $event -> page_matches ( " note/list " , paged : true )) {
$this -> get_notes_list ( $event -> get_iarg ( 'page_num' , 1 ) - 1 ); // This should show images like post/list but i don't know how do that.
2024-02-10 23:03:14 +00:00
}
2024-02-11 11:34:09 +00:00
if ( $event -> page_matches ( " note/requests " , paged : true )) {
$this -> get_notes_requests ( $event -> get_iarg ( 'page_num' , 1 ) - 1 ); // This should show images like post/list but i don't know how do that.
2024-02-10 23:03:14 +00:00
}
2024-02-11 11:34:09 +00:00
if ( $event -> page_matches ( " note/updated " , paged : true )) {
$this -> get_histories ( $event -> get_iarg ( 'page_num' , 1 ) - 1 );
2024-02-10 23:03:14 +00:00
}
2024-02-11 11:34:09 +00:00
if ( $event -> page_matches ( " note/history/ { note_id} " , paged : true )) {
$this -> get_history ( $event -> get_iarg ( 'note_id' ), $event -> get_iarg ( 'page_num' , 1 ) - 1 );
2024-02-10 23:03:14 +00:00
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/revert/ { noteID}/ { reviewID} " , permission : Permissions :: NOTES_EDIT )) {
2024-02-11 11:34:09 +00:00
$noteID = $event -> get_iarg ( 'noteID' );
$reviewID = $event -> get_iarg ( 'reviewID' );
2024-02-21 11:13:09 +00:00
$this -> revert_history ( $noteID , $reviewID );
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: REDIRECT );
$page -> set_redirect ( make_link ( " note/updated " ));
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/add_request " , permission : Permissions :: NOTES_REQUEST )) {
2024-02-10 23:03:14 +00:00
$image_id = int_escape ( $event -> req_POST ( " image_id " ));
2024-02-21 11:13:09 +00:00
$this -> add_note_request ( $image_id );
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: REDIRECT );
$page -> set_redirect ( make_link ( " post/view/ $image_id " ));
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/nuke_requests " , permission : Permissions :: NOTES_ADMIN )) {
2024-02-10 23:03:14 +00:00
$image_id = int_escape ( $event -> req_POST ( " image_id " ));
2024-02-21 11:13:09 +00:00
$this -> nuke_requests ( $image_id );
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: REDIRECT );
$page -> set_redirect ( make_link ( " post/view/ $image_id " ));
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/create_note " , permission : Permissions :: NOTES_CREATE )) {
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: DATA );
2024-02-21 11:13:09 +00:00
$note_id = $this -> add_new_note ();
$page -> set_data ( \Safe\json_encode ([
'status' => 'success' ,
'note_id' => $note_id ,
]));
2024-02-10 23:03:14 +00:00
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/update_note " , permission : Permissions :: NOTES_EDIT )) {
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: DATA );
2024-02-21 11:13:09 +00:00
$this -> update_note ();
$page -> set_data ( \Safe\json_encode ([ 'status' => 'success' ]));
2019-05-28 16:59:38 +00:00
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/delete_note " , permission : Permissions :: NOTES_ADMIN )) {
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: DATA );
2024-02-21 11:13:09 +00:00
$this -> delete_note ();
$page -> set_data ( \Safe\json_encode ([ 'status' => 'success' ]));
2024-02-10 23:03:14 +00:00
}
2024-02-21 11:13:09 +00:00
if ( $event -> page_matches ( " note/nuke_notes " , permission : Permissions :: NOTES_ADMIN )) {
2024-02-10 23:03:14 +00:00
$image_id = int_escape ( $event -> req_POST ( " image_id " ));
2024-02-21 11:13:09 +00:00
$this -> nuke_notes ( $image_id );
2024-02-10 23:03:14 +00:00
$page -> set_mode ( PageMode :: REDIRECT );
$page -> set_redirect ( make_link ( " post/view/ $image_id " ));
}
2019-05-28 16:59:38 +00:00
}
/*
* HERE WE LOAD THE NOTES IN THE IMAGE
*/
2024-01-15 11:52:35 +00:00
public function onDisplayingImage ( DisplayingImageEvent $event ) : void
2019-05-28 16:59:38 +00:00
{
global $page , $user ;
//display form on image event
$notes = $this -> get_notes ( $event -> image -> id );
2024-02-21 11:13:09 +00:00
$this -> theme -> display_note_system ( $page , $event -> image -> id , $notes , $user -> can ( Permissions :: NOTES_ADMIN ), $user -> can ( Permissions :: NOTES_EDIT ));
2019-05-28 16:59:38 +00:00
}
/*
* HERE WE ADD THE BUTTONS ON SIDEBAR
*/
2024-01-15 11:52:35 +00:00
public function onImageAdminBlockBuilding ( ImageAdminBlockBuildingEvent $event ) : void
2019-05-28 16:59:38 +00:00
{
global $user ;
2024-02-21 11:13:09 +00:00
if ( $user -> can ( Permissions :: NOTES_CREATE )) {
2019-05-28 16:59:38 +00:00
$event -> add_part ( $this -> theme -> note_button ( $event -> image -> id ));
2024-02-21 11:13:09 +00:00
2019-09-29 18:00:51 +00:00
if ( $user -> can ( Permissions :: NOTES_ADMIN )) {
2019-05-28 16:59:38 +00:00
$event -> add_part ( $this -> theme -> nuke_notes_button ( $event -> image -> id ));
$event -> add_part ( $this -> theme -> nuke_requests_button ( $event -> image -> id ));
}
}
2024-02-21 11:13:09 +00:00
if ( $user -> can ( Permissions :: NOTES_REQUEST )) {
$event -> add_part ( $this -> theme -> request_button ( $event -> image -> id ));
}
2019-05-28 16:59:38 +00:00
}
/*
* HERE WE ADD QUERYLETS TO ADD SEARCH SYSTEM
*/
2024-01-15 11:52:35 +00:00
public function onSearchTermParse ( SearchTermParseEvent $event ) : void
2019-05-28 16:59:38 +00:00
{
2020-01-26 16:38:26 +00:00
if ( is_null ( $event -> term )) {
return ;
}
2020-01-26 13:19:35 +00:00
2019-05-28 16:59:38 +00:00
$matches = [];
if ( preg_match ( " /^note[=|:](.*) $ /i " , $event -> term , $matches )) {
$notes = int_escape ( $matches [ 1 ]);
$event -> add_querylet ( new Querylet ( " images.id IN (SELECT image_id FROM notes WHERE note = $notes ) " ));
} elseif ( preg_match ( " /^notes([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])( \ d+)%/i " , $event -> term , $matches )) {
$cmp = ltrim ( $matches [ 1 ], " : " ) ? : " = " ;
$notes = $matches [ 2 ];
$event -> add_querylet ( new Querylet ( " images.id IN (SELECT id FROM images WHERE notes $cmp $notes ) " ));
} elseif ( preg_match ( " /^notes_by[=|:](.*) $ /i " , $event -> term , $matches )) {
2019-11-11 16:31:14 +00:00
$user_id = User :: name_to_id ( $matches [ 1 ]);
2019-05-28 16:59:38 +00:00
$event -> add_querylet ( new Querylet ( " images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id ) " ));
2019-08-02 20:05:49 +00:00
} elseif ( preg_match ( " /^(notes_by_userno|notes_by_user_id)[=|:]( \ d+) $ /i " , $event -> term , $matches )) {
$user_id = int_escape ( $matches [ 2 ]);
2019-05-28 16:59:38 +00:00
$event -> add_querylet ( new Querylet ( " images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id ) " ));
}
2019-08-02 20:05:49 +00:00
}
2024-01-15 11:52:35 +00:00
public function onHelpPageBuilding ( HelpPageBuildingEvent $event ) : void
2019-08-02 20:05:49 +00:00
{
2023-11-11 21:49:12 +00:00
if ( $event -> key === HelpPages :: SEARCH ) {
2019-08-02 20:05:49 +00:00
$block = new Block ();
$block -> header = " Notes " ;
$block -> body = $this -> theme -> get_help_html ();
$event -> add_block ( $block );
}
2019-05-28 16:59:38 +00:00
}
/**
* HERE WE GET ALL NOTES FOR DISPLAYED IMAGE .
2024-01-20 14:10:59 +00:00
*
* @ return array < string , mixed >
2019-05-28 16:59:38 +00:00
*/
private function get_notes ( int $imageID ) : array
{
global $database ;
2019-11-27 11:22:46 +00:00
return $database -> get_all ( "
SELECT *
FROM notes
WHERE enable = : enable AND image_id = : image_id
ORDER BY date ASC
2023-11-11 21:49:12 +00:00
" , ['enable' => '1', 'image_id' => $imageID ]);
2019-05-28 16:59:38 +00:00
}
/*
* HERE WE ADD A NOTE TO DATABASE
*/
2024-01-05 02:03:41 +00:00
private function add_new_note () : int
2019-05-28 16:59:38 +00:00
{
global $database , $user ;
2024-02-20 00:22:25 +00:00
$note = json_decode ( \Safe\file_get_contents ( 'php://input' ), true );
2019-05-28 16:59:38 +00:00
2023-06-25 20:31:11 +00:00
$database -> execute (
2019-05-28 16:59:38 +00:00
"
2016-05-18 13:36:50 +00:00
INSERT INTO notes ( enable , image_id , user_id , user_ip , date , x1 , y1 , height , width , note )
2023-06-25 20:31:11 +00:00
VALUES ( : enable , : image_id , : user_id , : user_ip , now (), : x1 , : y1 , : height , : width , : note ) " ,
2024-01-05 02:03:41 +00:00
[
'enable' => 1 ,
'image_id' => $note [ 'image_id' ],
'user_id' => $user -> id ,
'user_ip' => get_real_ip (),
'x1' => $note [ 'x1' ],
'y1' => $note [ 'y1' ],
'height' => $note [ 'height' ],
'width' => $note [ 'width' ],
'note' => $note [ 'note' ],
]
2019-05-28 16:59:38 +00:00
);
2009-12-24 07:36:09 +00:00
2023-06-25 20:31:11 +00:00
$noteID = $database -> get_last_insert_id ( 'notes_id_seq' );
2019-05-28 16:59:38 +00:00
log_info ( " notes " , " Note added { $noteID } by { $user -> name } " );
2009-12-24 07:36:09 +00:00
2024-01-05 02:03:41 +00:00
$database -> execute ( " UPDATE images SET notes=(SELECT COUNT(*) FROM notes WHERE image_id=:id) WHERE id=:id " , [ 'id' => $note [ 'image_id' ]]);
2009-12-24 07:36:09 +00:00
2024-01-05 02:03:41 +00:00
$this -> add_history (
2024-01-05 04:06:19 +00:00
1 ,
$noteID ,
$note [ 'image_id' ],
$note [ 'x1' ],
$note [ 'y1' ],
$note [ 'height' ],
$note [ 'width' ],
2024-01-05 02:03:41 +00:00
$note [ 'note' ]
);
return $noteID ;
2019-05-28 16:59:38 +00:00
}
2016-05-18 13:36:50 +00:00
2024-02-10 00:08:55 +00:00
private function add_note_request ( int $image_id ) : void
2019-05-28 16:59:38 +00:00
{
global $database , $user ;
2009-12-24 07:36:09 +00:00
2019-05-28 16:59:38 +00:00
$user_id = $user -> id ;
2009-12-24 07:36:09 +00:00
2023-06-25 20:31:11 +00:00
$database -> execute (
2019-05-28 16:59:38 +00:00
"
2016-05-18 13:36:50 +00:00
INSERT INTO note_request ( image_id , user_id , date )
2023-06-25 20:31:11 +00:00
VALUES ( : image_id , : user_id , now ()) " ,
2023-11-11 21:49:12 +00:00
[ 'image_id' => $image_id , 'user_id' => $user_id ]
2019-05-28 16:59:38 +00:00
);
2023-06-25 20:31:11 +00:00
$resultID = $database -> get_last_insert_id ( 'note_request_id_seq' );
2019-05-28 16:59:38 +00:00
log_info ( " notes " , " Note requested { $resultID } by { $user -> name } " );
}
2024-01-20 14:10:59 +00:00
private function update_note () : void
2019-05-28 16:59:38 +00:00
{
global $database ;
2024-02-20 00:22:25 +00:00
$note = json_decode ( \Safe\file_get_contents ( 'php://input' ), true );
2019-05-28 16:59:38 +00:00
// validate parameters
2023-02-04 20:50:26 +00:00
if ( empty ( $note [ 'note' ])) {
2019-05-28 16:59:38 +00:00
return ;
}
2019-11-27 11:22:46 +00:00
$database -> execute ( "
UPDATE notes
SET x1 = : x1 , y1 = : y1 , height = : height , width = : width , note = : note
2024-01-05 02:03:41 +00:00
WHERE image_id = : image_id AND id = : note_id " , $note );
2019-05-28 16:59:38 +00:00
2024-01-05 02:03:41 +00:00
$this -> add_history ( 1 , $note [ 'note_id' ], $note [ 'image_id' ], $note [ 'x1' ], $note [ 'y1' ], $note [ 'height' ], $note [ 'width' ], $note [ 'note' ]);
2019-05-28 16:59:38 +00:00
}
2024-01-20 14:10:59 +00:00
private function delete_note () : void
2019-05-28 16:59:38 +00:00
{
global $user , $database ;
2016-05-18 13:36:50 +00:00
2024-02-20 00:22:25 +00:00
$note = json_decode ( \Safe\file_get_contents ( 'php://input' ), true );
2019-11-27 11:22:46 +00:00
$database -> execute ( "
UPDATE notes SET enable = : enable
WHERE image_id = : image_id AND id = : id
2024-01-05 02:03:41 +00:00
" , ['enable' => 0, 'image_id' => $note["image_id"] , 'id' => $note["note_id"] ]);
2016-05-18 13:36:50 +00:00
2024-01-05 02:03:41 +00:00
log_info ( " notes " , " Note deleted { $note [ " note_id " ] } by { $user -> name } " );
2019-05-28 16:59:38 +00:00
}
2009-12-24 07:36:09 +00:00
2024-02-10 00:08:55 +00:00
private function nuke_notes ( int $image_id ) : void
2019-05-28 16:59:38 +00:00
{
global $database , $user ;
2023-11-11 21:49:12 +00:00
$database -> execute ( " DELETE FROM notes WHERE image_id = :image_id " , [ 'image_id' => $image_id ]);
2019-05-28 16:59:38 +00:00
log_info ( " notes " , " Notes deleted from { $image_id } by { $user -> name } " );
}
2009-12-24 07:36:09 +00:00
2024-02-10 00:08:55 +00:00
private function nuke_requests ( int $image_id ) : void
2019-05-28 16:59:38 +00:00
{
global $database , $user ;
2009-12-24 07:36:09 +00:00
2023-11-11 21:49:12 +00:00
$database -> execute ( " DELETE FROM note_request WHERE image_id = :image_id " , [ 'image_id' => $image_id ]);
2009-12-24 07:36:09 +00:00
2019-05-28 16:59:38 +00:00
log_info ( " notes " , " Requests deleted from { $image_id } by { $user -> name } " );
}
2016-05-18 13:36:50 +00:00
2024-02-10 23:03:14 +00:00
private function get_notes_list ( int $pageNumber ) : void
2019-05-28 16:59:38 +00:00
{
global $database , $config ;
2009-12-24 07:36:09 +00:00
2019-05-28 16:59:38 +00:00
$notesPerPage = $config -> get_int ( 'notesNotesPerPage' );
2024-02-10 23:03:14 +00:00
$totalPages = ( int ) ceil ( $database -> get_one ( " SELECT COUNT(DISTINCT image_id) FROM notes " ) / $notesPerPage );
2019-05-28 16:59:38 +00:00
2019-11-27 11:22:46 +00:00
//$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=:pool_id", ['pool_id'=>$poolID]);
2024-01-20 20:48:47 +00:00
$image_ids = $database -> get_col (
2019-11-27 12:13:04 +00:00
"
2019-11-27 11:22:46 +00:00
SELECT DISTINCT image_id
FROM notes
WHERE enable = : enable
ORDER BY date DESC LIMIT : limit OFFSET : offset " ,
2023-11-11 21:49:12 +00:00
[ 'enable' => 1 , 'offset' => $pageNumber * $notesPerPage , 'limit' => $notesPerPage ]
2019-05-28 16:59:38 +00:00
);
$images = [];
2024-02-10 23:03:14 +00:00
foreach ( $image_ids as $id ) {
2024-02-20 00:22:25 +00:00
$images [] = Image :: by_id_ex ( $id );
2019-05-28 16:59:38 +00:00
}
2009-12-24 07:36:09 +00:00
2019-05-28 16:59:38 +00:00
$this -> theme -> display_note_list ( $images , $pageNumber + 1 , $totalPages );
}
2009-12-24 07:36:09 +00:00
2024-02-10 23:03:14 +00:00
private function get_notes_requests ( int $pageNumber ) : void
2019-05-28 16:59:38 +00:00
{
global $config , $database ;
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$requestsPerPage = $config -> get_int ( 'notesRequestsPerPage' );
2016-05-18 13:36:50 +00:00
2019-11-27 11:22:46 +00:00
//$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=:pool_id", ['pool_id'=>$poolID]);
2009-12-24 07:36:09 +00:00
2019-05-28 16:59:38 +00:00
$result = $database -> execute (
"
2019-11-27 11:22:46 +00:00
SELECT DISTINCT image_id
FROM note_request
ORDER BY date DESC LIMIT : limit OFFSET : offset " ,
2023-11-11 21:49:12 +00:00
[ " offset " => $pageNumber * $requestsPerPage , " limit " => $requestsPerPage ]
2019-05-28 16:59:38 +00:00
);
2016-05-18 13:36:50 +00:00
2024-02-10 23:03:14 +00:00
$totalPages = ( int ) ceil ( $database -> get_one ( " SELECT COUNT(*) FROM note_request " ) / $requestsPerPage );
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$images = [];
while ( $row = $result -> fetch ()) {
2024-02-20 00:22:25 +00:00
$images [] = Image :: by_id_ex ( $row [ " image_id " ]);
2019-05-28 16:59:38 +00:00
}
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$this -> theme -> display_note_requests ( $images , $pageNumber + 1 , $totalPages );
}
2016-05-18 13:36:50 +00:00
2024-01-20 14:10:59 +00:00
private function add_history ( int $noteEnable , int $noteID , int $imageID , int $noteX1 , int $noteY1 , int $noteHeight , int $noteWidth , string $noteText ) : void
2019-05-28 16:59:38 +00:00
{
global $user , $database ;
2016-05-18 13:36:50 +00:00
2023-11-11 21:49:12 +00:00
$reviewID = $database -> get_one ( " SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id " , [ 'note_id' => $noteID ]);
2019-05-28 16:59:38 +00:00
$reviewID = $reviewID + 1 ;
2016-05-18 13:36:50 +00:00
2019-05-28 16:59:38 +00:00
$database -> execute (
"
2016-05-18 13:36:50 +00:00
INSERT INTO note_histories ( note_enable , note_id , review_id , image_id , user_id , user_ip , date , x1 , y1 , height , width , note )
2019-11-27 11:22:46 +00:00
VALUES ( : note_enable , : note_id , : review_id , : image_id , : user_id , : user_ip , now (), : x1 , : y1 , : height , : width , : note )
" ,
2024-02-10 23:03:14 +00:00
[
'note_enable' => $noteEnable ,
'note_id' => $noteID ,
'review_id' => $reviewID ,
'image_id' => $imageID ,
'user_id' => $user -> id ,
'user_ip' => get_real_ip (),
'x1' => $noteX1 ,
'y1' => $noteY1 ,
'height' => $noteHeight ,
'width' => $noteWidth ,
'note' => $noteText
]
2019-05-28 16:59:38 +00:00
);
}
2024-02-10 23:03:14 +00:00
private function get_histories ( int $pageNumber ) : void
2019-05-28 16:59:38 +00:00
{
global $config , $database ;
$historiesPerPage = $config -> get_int ( 'notesHistoriesPerPage' );
//ORDER BY IMAGE & DATE
$histories = $database -> get_all (
2024-02-10 23:03:14 +00:00
" SELECT h.note_id, h.review_id, h.image_id, h.date, h.note, u.name AS user_name " .
" FROM note_histories AS h " .
" INNER JOIN users AS u " .
" ON u.id = h.user_id " .
" ORDER BY date DESC LIMIT :limit OFFSET :offset " ,
2023-11-11 21:49:12 +00:00
[ 'offset' => $pageNumber * $historiesPerPage , 'limit' => $historiesPerPage ]
2019-05-28 16:59:38 +00:00
);
2024-02-10 23:03:14 +00:00
$totalPages = ( int ) ceil ( $database -> get_one ( " SELECT COUNT(*) FROM note_histories " ) / $historiesPerPage );
2019-05-28 16:59:38 +00:00
$this -> theme -> display_histories ( $histories , $pageNumber + 1 , $totalPages );
}
2024-02-10 23:03:14 +00:00
private function get_history ( int $noteID , int $pageNumber ) : void
2019-05-28 16:59:38 +00:00
{
global $config , $database ;
$historiesPerPage = $config -> get_int ( 'notesHistoriesPerPage' );
$histories = $database -> get_all (
2024-02-10 23:03:14 +00:00
" SELECT h.note_id, h.review_id, h.image_id, h.date, h.note, u.name AS user_name " .
" FROM note_histories AS h " .
" INNER JOIN users AS u " .
" ON u.id = h.user_id " .
" WHERE note_id = :note_id " .
" ORDER BY date DESC LIMIT :limit OFFSET :offset " ,
2023-11-11 21:49:12 +00:00
[ 'note_id' => $noteID , 'offset' => $pageNumber * $historiesPerPage , 'limit' => $historiesPerPage ]
2019-05-28 16:59:38 +00:00
);
2024-02-10 23:03:14 +00:00
$totalPages = ( int ) ceil ( $database -> get_one ( " SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id " , [ 'note_id' => $noteID ]) / $historiesPerPage );
2019-05-28 16:59:38 +00:00
$this -> theme -> display_history ( $histories , $pageNumber + 1 , $totalPages );
}
/**
* HERE GO BACK IN HISTORY AND SET THE OLD NOTE . IF WAS REMOVED WE RE - ADD IT .
*/
2024-01-20 14:10:59 +00:00
private function revert_history ( int $noteID , int $reviewID ) : void
2019-05-28 16:59:38 +00:00
{
global $database ;
2023-11-11 21:49:12 +00:00
$history = $database -> get_row ( " SELECT * FROM note_histories WHERE note_id = :note_id AND review_id = :review_id " , [ 'note_id' => $noteID , 'review_id' => $reviewID ]);
2019-05-28 16:59:38 +00:00
$noteEnable = $history [ 'note_enable' ];
2024-02-10 23:03:14 +00:00
$noteID = $history [ 'note_id' ];
$imageID = $history [ 'image_id' ];
$noteX1 = $history [ 'x1' ];
$noteY1 = $history [ 'y1' ];
2019-05-28 16:59:38 +00:00
$noteHeight = $history [ 'height' ];
2024-02-10 23:03:14 +00:00
$noteWidth = $history [ 'width' ];
$noteText = $history [ 'note' ];
2019-05-28 16:59:38 +00:00
2019-11-27 11:22:46 +00:00
$database -> execute ( "
2020-01-26 13:19:35 +00:00
UPDATE notes
2019-11-27 11:22:46 +00:00
SET enable = : enable , x1 = : x1 , y1 = : y1 , height = : height , width = : width , note = : note
WHERE image_id = : image_id AND id = : id
2023-11-11 21:49:12 +00:00
" , ['enable' => 1, 'x1' => $noteX1 , 'y1' => $noteY1 , 'height' => $noteHeight , 'width' => $noteWidth , 'note' => $noteText , 'image_id' => $imageID , 'id' => $noteID ]);
2019-05-28 16:59:38 +00:00
$this -> add_history ( $noteEnable , $noteID , $imageID , $noteX1 , $noteY1 , $noteHeight , $noteWidth , $noteText );
}
2009-12-24 07:36:09 +00:00
}