daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. case 'edit':
  2.     $handlerID = $_GET['id'];
  3.     $query = "SELECT
  4.         characters.ID,
  5.         characters.characterName,
  6.         handlers.userName,
  7.         handlers.password,
  8.         handlers.firstName,
  9.         handlers.lastName,
  10.         handlers.email,
  11.         handlers.isAdmin,
  12.         handlers.statusID
  13.     FROM
  14.         handlers
  15.         LEFT JOIN handlerCharacters
  16.             ON handlerCharacters.handlerID =  handlers.ID
  17.             LEFT JOIN characters
  18.                 ON characters.ID = handlerCharacters.characterID
  19.     WHERE
  20.         handlers.ID = '" . $handlerID . "'";
  21.     $result = mysqli_query ( $dbc, $query ); // Run The Query
  22.     $row = mysqli_fetch_array ( $result, MYSQL_ASSOC )
  23.     ?>
  24.     <script type="text/javascript">
  25.     $(document).ready(function() {
  26.         $('div.message-error').hide();
  27.         $('div.message-success').hide();
  28.         $('ul#characterList').css( 'margin-left', '120px' );
  29.         $('li').remove('.characterName');
  30.         $("input.submit").click(function() {
  31.             $('div.message-error').hide();
  32.             var handlerID = $("input#handlerID").val();
  33.             var userName = $("input#userName").val();
  34.             if (userName == "") {
  35.                 $("div.message-error").show();
  36.                 $("input#userName").focus();
  37.                 return false;
  38.             }
  39.             var password = $("input#password").val();
  40.             if (password == "") {
  41.                 $("div.message-error").show();
  42.                 $("input#password").focus();
  43.                 return false;
  44.             }
  45.             var firstName = $("input#firstName").val();
  46.             if (firstName == "") {
  47.                 $("div.message-error").show();
  48.                 $("input#firstName").focus();
  49.                 return false;
  50.             }
  51.             var lastName = $("input#lastName").val();
  52.             if (lastName == "") {
  53.                 $("div.message-error").show();
  54.                 $("input#lastName").focus();
  55.                 return false;
  56.              }
  57.              var email = $("input#email").val();
  58.              if (email == "") {
  59.                 $("div.message-error").show();
  60.                 $("input#email").focus();
  61.                 return false;
  62.              }
  63.              var statusID = $("select#statusID").val();
  64.              if (statusID == "") {
  65.                 $("div.message-error").show();
  66.                 $("select#statusID").focus();
  67.                 return false;
  68.              }
  69.              var isAdmin = $("select#isAdmin").val();
  70.              if (isAdmin == "") {
  71.                 $("div.message-error").show();
  72.                 $("select#isAdmin").focus();
  73.                 return false;
  74.              }  
  75.              var liElements = $("ul#characterList li");
  76.              var characterIDList = "";
  77.              for( var i = 0; i < liElements.length; i++ ) {
  78.                 var liElement = $( liElements[ i ] );
  79.                
  80.                 // only start appending commas in after the first characterID
  81.                 if( i > 0 ) {
  82.                    characterIDList += ",";
  83.                 }
  84.        
  85.                 // append the current li element's characterID to the list
  86.                 characterIDList += liElement.data( 'characterID' );
  87.              }
  88.              var dataString = 'userName=' + userName  + '&password=' + password + '&firstName=' + firstName + '&lastName=' + lastName + '&email=' + email + '&statusID=' + statusID + '&isAdmin=' + isAdmin + '&characterIDList=' + characterIDList + '&handlerID=' + handlerID + '&editHandler=True';
  89.              $.ajax({
  90.                  type: "POST",
  91.                  url: "processes/handler.php",
  92.                  data: dataString,
  93.                  success: function() {
  94.                      $('div.message-error').hide();
  95.                      $("div.message-success").html("<h6>Operation successful</h6><p>" + userName + " saved successfully.</p>");
  96.                      $("div.message-success").show().delay(10000).hide("slow");
  97.                      $(':input','#handlerForm')
  98.                      .not(':submit, :button')
  99.                      .val('')
  100.                      $("ul#characterList").empty();
  101.                      return true;
  102.                  }
  103.             });
  104.             return false;    
  105.         });
  106.     });
  107.     </script>
  108.    
  109.     <!-- Form -->
  110.     <form action="#" id="handlerForm">
  111.         <fieldset>
  112.             <legend>Edit Handler</legend>
  113.             <div class="field required">
  114.                 <label for="userName">User Name</label>
  115.                 <input type="text" class="text" name="userName" id="userName" title="User Name" value="<?php echo $row['userName']; ?>"/>
  116.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  117.             </div>
  118.             <div class="field required">
  119.                 <label for="password">Password</label>
  120.                 <input type="password" class="text" name="password" id="password" title="Password" value="<?php echo $row['password']; ?>"/>
  121.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  122.             </div>
  123.             <div class="field required">
  124.                 <label for="firstName">First Name</label>
  125.                 <input type="text" class="text" name="firstName" id="firstName" title="First Name" value="<?php echo $row['firstName']; ?>"/>
  126.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  127.             </div>
  128.             <div class="field required">
  129.                 <label for="lastName">Last Name</label>
  130.                 <input type="text" class="text" name="lastName" id="lastName" title="Last Name" value="<?php echo $row['lastName']; ?>"/>
  131.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  132.             </div>
  133.             <div class="field required">
  134.                 <label for="email">Email</label>
  135.                 <input type="text" class="text" name="email" id="email" title="Email" value="<?php echo $row['email']; ?>"/>
  136.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  137.             </div>
  138.             <div class="field required">
  139.                 <label for="statusID">Status</label>
  140.                 <select class="dropdown" name="statusID" id="statusID" title="Status">
  141.                 <option value="">- Select -</option>
  142.                 <?php
  143.                 $query = 'SELECT * FROM statuses';
  144.                 $result = mysqli_query ( $dbc, $query ); // Run The Query
  145.                 while ( $status_row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
  146.                         print "<option value=\"".$status_row['ID']."\" ";
  147.                         if($status_row['ID'] == $row['statusID']) {
  148.                                  print " SELECTED";
  149.                         }
  150.                         print ">".$status_row['statusName']."</option>\r";
  151.                 }
  152.                 ?>
  153.                 </select>
  154.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  155.             </div>
  156.             <div class="field required">
  157.                 <label for="isAdmin">Administrator</label>
  158.                 <select class="dropdown" name="isAdmin" id="isAdmin" title="Administrator">
  159.                 <option value="">- Select -</option>
  160.                 <?php
  161.                     $administrator = array('Yes', 'No');
  162.                     foreach($administrator as $admin):
  163.                 ?>        
  164.                 <option value="<?php echo $admin; ?>"<?php if($admin == $row['isAdmin']): echo ' SELECTED'; endif; ?>><?php echo $admin; ?></option>
  165.              
  166.                 <?php endforeach; ?>
  167.                 </select>
  168.                 <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
  169.             </div>
  170.         </fieldset>
  171.         <fieldset>
  172.             <legend>Handler's Characters</legend>
  173.             <div class="field">
  174.                 <label for="charactersDrop">Characters</label>
  175.                 <select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Dropdown">
  176.                 <option value="">- Select -</option>
  177.                 <?php
  178.                 $query = 'SELECT ID, characterName FROM characters WHERE ID NOT IN (SELECT characterID FROM handlerCharacters) ORDER BY `characterName`';
  179.                 $result = mysqli_query ( $dbc, $query ); // Run The Query
  180.                 while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
  181.                     print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";
  182.                 }
  183.                 ?>
  184.                 </select>
  185.                 <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/>
  186.                 <ul id="characterList"></ul>
  187.             </div>
  188.             <input type="hidden" name="handlerID" id="handlerID" value="<?php echo $handlerID; ?>" />
  189.             <input type="submit" class="submit" name="editHandler" id="editHandler" title="Submit Handler" value="Submit Handler" />
  190.         </fieldset>
  191.     </form>
  192.     <!-- /Form -->
  193.     <!-- Messages -->
  194.     <div class="message message-error">
  195.         <h6>Required field missing</h6>
  196.         <p>Please fill in all required fields. </p>
  197.     </div>
  198.     <div class="message message-success">
  199.         <h6>Operation succesful</h6>
  200.         <p>Handler was added to the database.</p>
  201.     </div>
  202.     <!-- /Messages -->
  203.    
  204.     <script type="text/javascript" language="javascript">
  205.     // Long version
  206.     function HandlerCharacters() {
  207.         function isDupe(which) {
  208.             var result = false;
  209.             $('ul#characterList li').each(function(i, e) {
  210.                 if ($(e).data('characterID') == which) {
  211.                     result = true;
  212.                     return false; // break out of .each()
  213.                 }
  214.             });
  215.             return result;
  216.         }
  217.         var characterID = $('#charactersDrop option:selected').val();
  218.         var characterName = $('#charactersDrop option:selected').text();
  219.         if (characterID > 0 && !isDupe(characterID)) {
  220.             // Create the anchor element
  221.             var anchor = $( '<a href="#">Remove</a>' );  
  222.            
  223.             // Create a click handler for the anchor element
  224.             anchor.click( function() {
  225.                 $( this ).parent().remove();
  226.                 return false;  // makes the href in the anchor tag ignored
  227.             } );
  228.            
  229.             // Create the <li> element with its text, and then append the anchor inside it.
  230.             var li = $( '<li>' + characterName + '&nbsp;</li>' ).append( anchor );
  231.             li.data( 'characterID', characterID );
  232.            
  233.             // Append the new <li> element to the <ul> element
  234.             $( '#characterList' ).append( li );
  235.         }
  236.     }
  237.     </script>
  238.     <?php
  239.     break;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top