INSERT INTO box (boxid, title, content, description, template) VALUES ('cron_edit_queue', '', '#main sub\n\n# Get the expire time\nmy $expire = $S->{UI}->{VARS}->{queue_edit_max_time};\nmy $factors = {\nd => \'86400\',\nh => \'3600\',\nm => \'60\',\ns => \'1\'\n};\n$expire =~ s/([^\\d])$//;\nmy $time_sub = $expire * $factors->{$1};\n\nwarn $expire;\nwarn $time_sub;\n\nmy $select = {\nDEBUG => 0, \nWHAT => "sid, score, time, displaystatus",\nFROM => \'stories\',\nWHERE => "displaystatus = -3 AND UNIX_TIMESTAMP(NOW()) -\nUNIX_TIMESTAMP(time) >= $time_sub",\nORDER_BY => \'time DESC\'\n};\n\nmy ($rv, $sth) = $S->db_select($select);\n\nmy $sid_move_to_moderate;\nwhile (my $story = $sth->fetchrow_hashref()) {\n# only move if the time has expired\n$sid_move_to_moderate = $story->{sid};\nwarn "sid=$sid_move_to_moderate";\n_cron_edit_queue_update($S, $sid_move_to_moderate);\n}\n\n$sth->finish();\n\nreturn 1;\n\nsub _cron_edit_queue_update {\nmy ($S, $sid_move_to_moderate) = @_; \n\nmy ($rv, $sth) = $S->db_update({\nWHAT  => \'stories\',\nSET   => "displaystatus = -2",\nWHERE => "sid = \'$sid_move_to_moderate\'"\n});\n$sth->finish;\n\n\nreturn 1;\n}', '', 'empty_box');
INSERT INTO cron VALUES ('edit_queue', 'cron_edit_queue', 3600, '0000-00-00 00:00:00',1,1);
INSERT INTO displaycodes VALUES (-3,'Editing');
INSERT INTO vars VALUES ('queue_edit_max_time', '2h', 'How long can a story remain in editing mode before it gets forced into the moderation queue?', 'text', 'Stories');
INSERT INTO vars VALUES ('max_edit_stories', '1', 'How many stories allowed in the edit queue at one time?', 'num', 'Stories');
INSERT INTO blocks VALUES ('author_edit_instructions','<p>\r\nThis story is in editing. You may edit it using the \"Edit\" button below. To finish the editing period and move the story to voting, click \"Edit\", uncheck \"Request editorial feedback\" and save.',NULL,NULL);
INSERT INTO blocks VALUES ('author_edit_console','<!-- author_edit_console -->\r\n<TABLE BGCOLOR=\"#006699\" BORDER=0 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%\" ALIGN=\"center\">\r\n    <TR>\r\n        <TD>\r\n            <TABLE BGCOLOR=\"%%story_mod_bg%%\" BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=\"100%\" ALIGN=\"center\">\r\n                <TR>\r\n                    <TD>\r\n                    %%norm_font%%\r\n                    As the author of this story, you may cancel the submission at any time during voting. Simply check the confirm box below, and click \"Cancel Submission\". \r\n%%author_edit_instructions%%\r\n                    %%norm_font_end%%\r\n                    </TD>\r\n                </TR>\r\n    <TR>\r\n        <TD ALIGN=\"center\" VALIGN=\"middle\">\r\n        %%norm_font%%\r\n        %%author_edit_form%%\r\n        %%norm_font_end%%\r\n        </TD>\r\n    </TR>\r\n           </TABLE>\r\n        </TD>\r\n    </TR>\r\n</TABLE>\r\n<!-- X vote_console -->\r\n',NULL,NULL);
INSERT INTO blocks VALUES ('editqueuestory_bg','#99ccdd',NULL,NULL);
INSERT INTO blocks VALUES ('edit_instructions','<!-- vote_console -->\r\n<TABLE BGCOLOR=\"#006699\" BORDER=0 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%\" ALIGN=\"center\">\r\n    <TR>\r\n        <TD>\r\n            <TABLE BGCOLOR=\"%%story_mod_bg%%\" BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=\"100%\" ALIGN=\"center\">\r\n                <TR>\r\n                    <TD>\r\n                    %%norm_font%%\r\n<b>Please Help.</b> The author of this story has requested editorial help from you, and the rest of the community. Please read, and post your editorial suggestions below. The author can edit at any time, so some suggestions may already have been fixed when you read them. After editing, the story will continue on to voting as usual.\r\n                    %%norm_font_end%%\r\n                    </TD>\r\n                </TR>\r\n            </TABLE>\r\n        </TD>\r\n    </TR>\r\n</TABLE>\r\n<!-- X vote_console -->\r\n',NULL,NULL);
UPDATE blocks SET block = CONCAT(block, ",\nedit_own_story") WHERE bid = 'perms';
