r2464 fixed a few bugs in ajax verify thingy (ticket #189)
authorDenis Yeldandi <dyeldandi@gmail.com>
Thu, 19 Feb 2009 13:20:07 +0000 (13:20 +0000)
committerDenis Yeldandi <dyeldandi@gmail.com>
Thu, 19 Feb 2009 13:20:07 +0000 (13:20 +0000)
ajax.php
inc/interface.php

index eccfb92..af01244 100644 (file)
--- a/ajax.php
+++ b/ajax.php
@@ -1,7 +1,8 @@
 <?php
 
+$_REQUEST['page'] = 'perms';
+$_REQUEST['tab'] = 'edit';
 require 'inc/init.php';
-
 fixContext();
 
 // We have a chance to handle an error before starting HTTP header.
@@ -12,15 +13,15 @@ if (!permitted())
                'v' => 2,
                'm' => array (0 => array ('c' => 157)) // operation not permitted
        );
-       $location = buildWideRedirectURL ($errlog);
-       header ("Location: " . $location);
+       echo "NAK\nPermission denied";
        exit();
 }
 
-switch ($_GET['ac'])
+switch ($_REQUEST['ac'])
 {
        case 'verifyCode':
-               $code = $_REQUEST['code'];
+               $code = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['code']));
+               error_log($code);
                $result = getRackCode($code);
                if ($result['result'] == 'ACK')
                        echo 'ACK';
index 6d1a475..d009666 100644 (file)
@@ -5330,10 +5330,11 @@ function renderRackCodeEditor ()
        printOpFormIntro ('saveRackCode');
        echo <<<ENDJAVASCRIPT
 <script type="text/javascript">
+var prevCode = '';
 function verify()
 {
        $.ajax({
-               type: "GET",
+               type: "POST",
                url: "ajax.php",
                data: "ac=verifyCode&code="+RCTA.getCode(),
                success: function (data)
@@ -5342,15 +5343,33 @@ function verify()
                        if (arr[0] == "ACK")
                        {
                                $("#SaveChanges")[0].disabled = "";
+                               $("#ShowMessage")[0].innerHTML = "Code verification OK, don't forget to save the code";
+                               $("#ShowMessage")[0].className = "msg_success";
                        }
                        else
                        {
                                $("#SaveChanges")[0].disabled = "disabled";
                                $("#ShowMessage")[0].innerHTML = arr[1];
+                               $("#ShowMessage")[0].className = "msg_warning";
                        }
+                       prevCode = RCTA.getCode();
                }
        });
 }
+
+
+function invalidate()
+{
+       if (prevCode != RCTA.getCode())
+       {
+               prevCode = RCTA.getCode();
+               $("#SaveChanges")[0].disabled = "disabled";
+               $("#ShowMessage")[0].innerHTML = "";
+               $("#ShowMessage")[0].className = "";
+       }
+}
+
+setInterval(invalidate, 1000);
 </script>
 ENDJAVASCRIPT;
 
@@ -5358,9 +5377,9 @@ ENDJAVASCRIPT;
        echo "<tr><td><textarea rows=40 cols=100 name=rackcode id=RCTA class='codepress rackcode'>";
        echo $text . "</textarea></td></tr>\n";
        echo "<tr><td align=center>";
-       echo "<input type='submit' value='Save' disabled='disabled' id='SaveChanges' onclick='RCTA.toggleEditor();'>";
-       echo "<input type='button' value='Verify' onclick='verify();'>";
        echo '<div id="ShowMessage"></div>';
+       echo "<input type='button' value='Verify' onclick='verify();'>";
+       echo "<input type='submit' value='Save' disabled='disabled' id='SaveChanges' onclick='RCTA.toggleEditor();'>";
 //     printImageHREF ('SAVE', 'Save changes', TRUE);
        echo "</td></tr>";
        echo '</table>';