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', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
25 print '</table></form>';
28 Please enter only accurate information. Descriptions like "Unknown modem device" are only of a little use to anybody.
29 Real chip names and numbers are preferred over marketing names. In case you know both, enclose the marketing name in square brackets like in
30 "3c595 100BaseTX [Vortex]". Do not include names of superitems in the name (like vendor name in device name).
31 Check information specific to this <a href="'.buildExcept( 'action', $args ).'?action=help?help='.$address->helpName().'">ID type</a>.
33 If you there is something you want to clarify about the item, you can use note (like the ID does not belong to people using it).
34 Discussion is for things more relevant to history of the item than the real device (like information source).
35 Both note and discussion is optional.';
40 sub newItemForm( $$$$ ) {
41 my( $req, $args, $tables, $auth ) = @_;
42 if( defined $auth->{'authid'} ) {#Logged in alright
43 return genNewItemForm( $req, $args, $auth, $tables, undef, {} );
45 return notLoggedComplaint( $req, $args, $auth );
49 sub newItemSubmit( $$$$ ) {
50 my( $req, $args, $tables, $auth ) = @_;
51 if( defined $auth->{'authid'} ) {
52 my( $pok, $parent, $pname, $pnote, $paddress ) = loadItem( $tables, $req->uri() );
53 return NOT_FOUND unless( $pok );
54 my( $data, $error ) = getForm( {
55 'id' => sub{ return ( length shift ) ? undef : 'Please, provide the ID'; }, #Checked at the bottom and added as address
58 return 'Too short for a name' if( length $name < 3 );
59 return 'Lenght limit of the name is 200 characters' if( length $name > 200 );
62 'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
63 'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; }
64 }, [ sub { my( $data ) = @_;
66 return undef unless( length $data->{'id'} );#No address, so let it for the first check
67 ( $data->{'address'}, $errstr ) = $paddress->append( $data->{'id'} );
69 }, sub { return $paddress->canAddItem() ? undef : 'Can not add items here'; } ] );
70 return genNewItemForm( $req, $args, $auth, $tables, $error, $data ) if( defined $error );
71 my( $result, $comName ) = $tables->submitItem( $data, $auth );
72 if( $result eq 'exists' ) {
73 genHtmlHead( $req, 'ID collision', undef );
74 my $addr = PciIds::Address::new( $req->uri() );
75 genCustomHead( $req, $args, $addr, 'ID collision', [ [ 'Add other item', 'newitem' ], $addr->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), [ '', 'jump' ] ], [ logItem( $auth ) ] );
76 print '<p>Sorry, this ID already exists.';
80 return genNewItemForm( $req, $args, $auth, $tables, $result, $data );
82 notify( $tables, $data->{'address'}->parent()->get(), $comName, 2, 0 );#Notify the parent (parent gets new items)
83 tulog( $auth->{'authid'}, "Item created ".$data->{'address'}->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'note'} )." ".logEscape( $data->{'discussion'} )." $comName" );
84 return HTTPRedirect( $req, '/read/'.$data->{'address'}->get().'?action=list' );
86 return notLoggedComplaint( $req, $args, $auth );
90 sub genNewHistoryForm( $$$$$$ ) {
91 my( $req, $args, $tables, $auth, $error, $values ) = @_;
92 my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() );
93 return NOT_FOUND unless( $ok );
94 genHtmlHead( $req, "Discuss", undef );
95 genCustomHead( $req, $args, $address, "Discuss", [ $address->canAddItem() ? [ 'Add item', 'newitem' ] : (), [ 'Help', 'help', 'newhistory' ], [ '', 'jump' ] ], [ logItem( $auth ), [ 'Notifications', 'notifications' ] ] );
96 print "<div class='error'>$error</div>\n" if( defined $error );
97 print "<form name='newhistory' id='newhistory' method='POST' action=''>\n<table>";
98 genFormEx( [ [ 'textarea', 'Text:', undef, 'text', 'rows="5" cols="50"' ],
99 [ 'input', 'Request deletion', 'checkbox', 'delete', 'value="delete"' ],
100 [ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
101 [ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
102 [ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
103 print '</table></form>';
108 sub newHistoryForm( $$$$ ) {
109 my( $req, $args, $tables, $auth ) = @_;
110 if( defined $auth->{'authid'} ) {
111 return genNewHistoryForm( $req, $args, $tables, $auth, undef, {} );
113 return notLoggedComplaint( $req, $args, $auth );
117 sub newHistorySubmit( $$$$ ) {
118 my( $req, $args, $tables, $auth ) = @_;
119 if( defined $auth->{'authid'} ) {
120 my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() );
121 return NOT_FOUND unless( $ok );
122 my( $data, $error ) = getForm( {
123 'name' => sub { return ( length shift > 200 ) ? 'Lenght limit of the name is 200 characters' : undef; },
124 'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
127 return 'Text can not be longer than 1024 characters' if ( length $expl > 1024 );
132 return ( undef, '0' ) unless defined $delete;
133 return undef if $delete eq 'delete';
134 return 'Invalid form value';
137 }, [ sub { my( $data ) = @_;
138 return 'You must provide either name, text or request a deletion' if( ! length $data->{'name'} && ! length $data->{'text'} && ! $data->{'delete'} );
140 }, sub { my( $data ) = @_;
141 return 'You can not set name and request deletion at the same time' if( length $data->{'name'} && $data->{'delete'} );
143 }, sub { my( $data ) = @_;
144 return 'You must provide name too' if( ( length $data->{'note'} ) && ( ! length $data->{'name'} ) );
146 }, sub { return $address->canDiscuss() ? undef : 'You can not discuss this item'; } ] );
147 return genNewHistoryForm( $req, $args, $tables, $auth, $error, $data ) if( defined $error );
148 my $hid = $tables->submitHistory( $data, $auth, $address );
149 tulog( $auth->{'authid'}, "Discussion created $hid ".$address->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'description'} )." ".logEscape( $data->{'text'} ) );
150 notify( $tables, $address->get(), $hid, ( defined $name && ( $name ne '' ) ) ? 1 : 0, 1 );
151 return HTTPRedirect( $req, '/read/'.$address->get().'?action=list' );
153 return notLoggedComplaint( $req, $args, $auth );