1 package PciIds::Html::Changes;
3 use PciIds::Html::Users;
4 use PciIds::Html::List;
5 use PciIds::Html::Util;
6 use PciIds::Html::Forms;
7 use PciIds::Notifications;
10 use Apache2::Const qw(:common :http);
12 sub genNewItemForm( $$$$$$ ) {
13 my( $req, $args, $auth, $tables, $error, $values ) = @_;
14 my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() );
15 return NOT_FOUND unless( $ok );
16 genHtmlHead( $req, "Add new item", undef );
17 genCustomHead( $req, $args, $address, "Add new item", [ $address->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), [ 'Help', 'help', 'newitem' ], [ 'ID syntax', 'help', $address->helpName() ], [ '', 'jump' ] ], [ logItem( $auth ), [ 'Notifications', 'notifications' ] ] );
18 print "<div class='error'>$error</div>\n" if( defined $error );
19 print "<form name='newitem' id='newitem' method='POST' action=''>\n<table>";
20 genFormEx( [ [ 'input', 'ID:', 'text', 'id', 'maxlength="'.$address->subIdSize().'"' ],
21 [ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
22 [ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
23 [ 'textarea', 'Discussion:', undef, 'discussion', 'rows="5" cols="50"' ],
24 [ 'input', 'Subscribe:', 'checkbox', 'subscribe', 'value="subscribe" checked="checked"' ],
25 [ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
26 print '</table></form>';
29 Please enter only accurate information. Descriptions like "Unknown modem device" are only of a little use to anybody.
30 Real chip names and numbers are preferred over marketing names. In case you know both, enclose the marketing name in square brackets like in
31 "3c595 100BaseTX [Vortex]". Do not include names of superitems in the name (like vendor name in device name).
32 Check information specific to this <a href="'.buildExcept( 'action', $args ).'?action=help?help='.$address->helpName().'">ID type</a>.
34 If there is something you want to clarify about the item, you can use note (like the ID does not belong to people using it).
35 Discussion is for things more relevant to history of the item than the real device (like information source).
36 Both note and discussion is optional.';
41 sub newItemForm( $$$$ ) {
42 my( $req, $args, $tables, $auth ) = @_;
43 if( defined $auth->{'authid'} ) {#Logged in alright
44 return genNewItemForm( $req, $args, $auth, $tables, undef, {} );
46 return notLoggedComplaint( $req, $args, $auth );
50 sub newItemSubmit( $$$$ ) {
51 my( $req, $args, $tables, $auth ) = @_;
52 if( defined $auth->{'authid'} ) {
53 my( $pok, $parent, $pname, $pnote, $paddress ) = loadItem( $tables, $req->uri() );
54 return NOT_FOUND unless( $pok );
55 my( $data, $error ) = getForm( {
56 'id' => sub{ return ( length shift ) ? undef : 'Please, provide the ID'; }, #Checked at the bottom and added as address
59 return 'Too short for a name' if( length $name < 3 );
60 return 'Lenght limit of the name is 200 characters' if( length $name > 200 );
63 'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
64 'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; },
66 }, [ sub { my( $data ) = @_;
68 return undef unless( length $data->{'id'} );#No address, so let it for the first check
69 ( $data->{'address'}, $errstr ) = $paddress->append( $data->{'id'} );
71 }, sub { return $paddress->canAddItem() ? undef : 'Can not add items here'; } ] );
72 return genNewItemForm( $req, $args, $auth, $tables, $error, $data ) if( defined $error );
73 my( $result, $comName ) = $tables->submitItem( $data, $auth );
74 if( $result eq 'exists' ) {
75 genHtmlHead( $req, 'ID collision', undef );
76 my $addr = PciIds::Address::new( $req->uri() );
77 genCustomHead( $req, $args, $addr, 'ID collision', [ [ 'Add other item', 'newitem' ], $addr->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), [ '', 'jump' ] ], [ logItem( $auth ) ] );
78 print '<p>Sorry, this ID already exists.';
82 return genNewItemForm( $req, $args, $auth, $tables, $result, $data );
84 notify( $tables, $data->{'address'}->parent()->get(), $comName, 2, 0 );#Notify the parent (parent gets new items)
85 $tables->submitNotification( $auth->{'authid'}, $data->{'address'}->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
86 tulog( $auth->{'authid'}, "Item created ".$data->{'address'}->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'note'} )." ".logEscape( $data->{'discussion'} )." $comName" );
87 return HTTPRedirect( $req, '/read/'.$data->{'address'}->get().'?action=list' );
89 return notLoggedComplaint( $req, $args, $auth );
93 sub genNewHistoryForm( $$$$$$ ) {
94 my( $req, $args, $tables, $auth, $error, $values ) = @_;
95 my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() );
96 return NOT_FOUND unless( $ok );
97 genHtmlHead( $req, "Discuss", undef );
98 genCustomHead( $req, $args, $address, "Discuss", [ $address->canAddItem() ? [ 'Add item', 'newitem' ] : (), [ 'Help', 'help', 'newhistory' ], [ '', 'jump' ] ], [ logItem( $auth ), [ 'Notifications', 'notifications' ] ] );
99 print "<div class='error'>$error</div>\n" if( defined $error );
100 print "<form name='newhistory' id='newhistory' method='POST' action=''>\n<table>";
101 genFormEx( [ [ 'textarea', 'Text:', undef, 'text', 'rows="5" cols="50"' ],
102 [ 'input', 'Request deletion', 'checkbox', 'delete', 'value="delete"' ],
103 [ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
104 [ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
105 !$tables->notifExists( $auth->{'authid'}, $address->get() ) ? [ 'input', 'Subscribe:', 'checkbox', 'subscribe', "value='subscribe' checked='checked'" ] : (),
106 [ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
107 print '</table></form>';
110 Please enter only accurate information. Descriptions like "Unknown modem device" are only of a little use to anybody.
111 Real chip names and numbers are preferred over marketing names. In case you know both, enclose the marketing name in square brackets like in
112 "3c595 100BaseTX [Vortex]". Do not include names of superitems in the name (like vendor name in device name).
113 Check information specific to this <a href="'.buildExcept( 'action', $args ).'?action=help?help='.$address->helpName().'">ID type</a>.
115 You may provide just discussion, request deletion or enter a new name and note.
116 Note is for clarification of the device information, discussion is for reasons, why you change it and like that.
118 You may add discussion note to name change or deletion request too.
119 You must provide at last name or discussion or deletion request.
121 If you provide note, you must provide name too.';
126 sub newHistoryForm( $$$$ ) {
127 my( $req, $args, $tables, $auth ) = @_;
128 if( defined $auth->{'authid'} ) {
129 return genNewHistoryForm( $req, $args, $tables, $auth, undef, {} );
131 return notLoggedComplaint( $req, $args, $auth );
135 sub newHistorySubmit( $$$$ ) {
136 my( $req, $args, $tables, $auth ) = @_;
137 if( defined $auth->{'authid'} ) {
138 my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() );
139 return NOT_FOUND unless( $ok );
140 my( $data, $error ) = getForm( {
141 'name' => sub { return ( length shift > 200 ) ? 'Lenght limit of the name is 200 characters' : undef; },
142 'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
145 return 'Text can not be longer than 1024 characters' if ( length $expl > 1024 );
150 return ( undef, '0' ) unless defined $delete;
151 return undef if $delete eq 'delete';
152 return 'Invalid form value';
156 }, [ sub { my( $data ) = @_;
157 return 'You must provide either name, text or request a deletion' if( ! length $data->{'name'} && ! length $data->{'text'} && ! $data->{'delete'} );
159 }, sub { my( $data ) = @_;
160 return 'You can not set name and request deletion at the same time' if( length $data->{'name'} && $data->{'delete'} );
162 }, sub { my( $data ) = @_;
163 return 'You must provide name too' if( ( length $data->{'note'} ) && ( ! length $data->{'name'} ) );
165 }, sub { return $address->canDiscuss() ? undef : 'You can not discuss this item'; } ] );
166 return genNewHistoryForm( $req, $args, $tables, $auth, $error, $data ) if( defined $error );
167 my $hid = $tables->submitHistory( $data, $auth, $address );
168 tulog( $auth->{'authid'}, "Discussion created $hid ".$address->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'description'} )." ".logEscape( $data->{'text'} ) );
169 notify( $tables, $address->get(), $hid, ( defined $name && ( $name ne '' ) ) ? 1 : 0, 1 );
170 $tables->submitNotification( $auth->{'authid'}, $address->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
171 return HTTPRedirect( $req, '/read/'.$address->get().'?action=list' );
173 return notLoggedComplaint( $req, $args, $auth );