Advertisement
Guest User

Wp-Project fixed - project.php

a guest
Nov 8th, 2010
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.56 KB | None | 0 0
  1. <?php
  2. // All processing logic happens here
  3.  
  4. // We'll check for deletes
  5. if( isset( $_POST[ 'delete_projects' ] ) ) {
  6.     $this->delete_projects( $_POST[ 'project_cb' ] );
  7. }
  8.  
  9. // We'll check for add or edit
  10. if( isset( $_POST[ 'submit_project' ] ) ) {
  11.     // We've got a submission, let's figure out what to do
  12.    
  13.     $errors = $this->validate_project( $_POST );
  14.    
  15.     if( empty( $errors ) ) {
  16.        
  17.         // The $_POST array is already escaped, so that's why they aren't escaped here
  18.         if( isset( $_POST[ 'project_id' ] ) ) {
  19.             // We're editing an existing project
  20.            
  21.             $result = $this->edit_project( $_POST[ 'project_id' ], $_POST[ 'project_title' ], $_POST[ 'client_id' ], $_POST[ 'project_description' ] );
  22.            
  23.             if( $result === FALSE ) {
  24.                 ?>
  25.                 <div id="message" class="error">
  26.                     <p>There was an error updating the project.  Your changes may not have been saved.  Please try again.</p>
  27.                 </div>             
  28.                 <?
  29.             } else {
  30.                 ?>
  31.                 <div id="message" class="updated fade">
  32.                     <p>Your project "<?php echo stripslashes( $_POST[ 'project_title' ] ); ?>" has been updated.</p>
  33.                 </div>             
  34.                 <?php
  35.             }
  36.            
  37.         } else {
  38.             // We're adding a new project
  39.            
  40.             $result = $this->add_project( $_POST[ 'project_title' ], $_POST[ 'client_id' ], $_POST[ 'project_description' ] );
  41.            
  42.             if( $result === FALSE ) {
  43.                 ?>
  44.                 <div id="message" class="error">
  45.                     <p>There was an error adding the project.  Your changes may not have been saved.  Please try again.</p>
  46.                 </div>             
  47.                 <?php
  48.             } else {
  49.                 ?>
  50.                 <div id="message" class="updated fade">
  51.                     <p>Your project "<?php echo stripslashes( $_POST[ 'project_title' ] ); ?>" has been added.</p>
  52.                 </div>             
  53.                 <?php
  54.             }
  55.         }
  56.        
  57.     } else {
  58.         // The project is invalid, so let's print the error messages
  59.         ?>
  60.         <div id="message" class="error">
  61.             <ul>
  62.         <?php foreach( $errors as $error ) { ?>
  63.                 <li><?php echo $error; ?></li>
  64.         <?php } ?>
  65.             </ul>
  66.         </div>
  67.         <?php
  68.        
  69.         $current[ 'project_id' ] = $_POST[ 'project_id' ];
  70.         $current[ 'project_title' ] = $_POST[ 'project_title' ];
  71.         $current[ 'project_description' ] = $_POST[ 'project_description' ];
  72.         $current[ 'client_id' ] = $_POST[ 'client_id' ];
  73.        
  74.     }
  75. }
  76.  
  77. $current = $this->is_editing_project();
  78.  
  79. // Is a valid project being edited? If so, then let's show the edit screen.
  80. if( $current !== FALSE ) {
  81.     ?>
  82. <div class="wrap">
  83.     <h2>Edit Project</h2>
  84.     <?php
  85. } else {
  86. ?>
  87. <div class="wrap">
  88.     <form name="project-manage" id="project-manage" method="post" action="<?php $this->friendly_page_link( 'projects' ); ?>">
  89.         <h2>Manage Projects (<a href="#addproject">add new</a>)</h2>
  90.         <div class="tablenav">
  91.             <div class="alignleft">
  92.                 <input name="delete_projects" id="delete_projects" class="button-secondary delete" type="submit" value="Delete" />
  93.             </div>
  94.             <br class="clear" />
  95.         </div>
  96.         <br class="clear" />
  97.        
  98.         <table class="widefat"> <!-- Start Manage Table -->
  99.             <thead>
  100.                 <tr>
  101.                     <th class="check-column" scope="col"><input id="selectall" name="selectall" type="checkbox" /></th>
  102.                     <th scope="col">Name</th>
  103.                     <th scope="col">Client</th>
  104.                     <th scope="col">Description</th>
  105.                 </tr>
  106.             </thead>
  107.             <tbody>
  108.                 <?php $this->project_rows(); ?>
  109.             </tbody>
  110.         </table> <!-- End Manage Table -->
  111.        
  112.     </form> <!-- End the manage form -->
  113.     <div class="tablenav">
  114.         <br class="clear" />
  115.     </div>
  116.     <br class="clear" />
  117. </div>
  118.  
  119. <div class="wrap">
  120.     <h2>Add Project</h2>
  121. <?php
  122. }
  123. ?>
  124.     <form name="addproject" id="addproject" method="post" action="<?php $this->friendly_page_link( 'projects' ); echo ( $current !== FALSE ? '&action=edit&id=' . $current[ 'project_id' ] : '' ); ?>">
  125.         <table class="form-table">
  126.             <tbody>
  127.                 <tr class="form-field form-required">
  128.                     <th scope="row" valign="top"><label for="project_title">Title</label></th>
  129.                     <td>
  130.                         <input id="project_title" name="project_title" type="text" size="30" value="<?php echo $current[ 'project_title']; ?>" /><br />
  131.                         Choose a project title that succinctly describe this project in 200 characters or less.
  132.                     </td>
  133.                 </tr>
  134.                 <tr class="form-field form-required">
  135.                     <th scope="row" valign="top"><label for="client_id">Client</label></th>
  136.                     <td>
  137.                         <select class="postform" id="client_id" name="client_id">
  138.                             <option value="-1">N/A</option>
  139.                         <?php
  140.                         foreach( $this->get_clients() as $client ) {
  141.                         ?>
  142.                             <option <?php if( $current[ 'client_id' ] == $client->client_id ) { echo 'selected'; } ?> value="<?php echo $client->client_id; ?>"><?php echo $client->client_name; ?></option>
  143.                         <?php  
  144.                         }
  145.                         ?>
  146.                         </select><br />
  147.                         <a href="<?php $this->friendly_page_link( 'clients' ); ?>" id="add_client_link">Add Client</a><br />
  148.                         The client with which you wish to associate this project.
  149.                     </td>
  150.                 </tr>
  151.                 <tr class="form-field form-required">
  152.                     <th scope="row" valign="top"><label for="project_description">Description</label>
  153.                     <td>
  154.                         <textarea name="project_description" id="project_description" style="width:97%;" cols="50" rows="7"><?php echo $current[ 'project_description']; ?></textarea><br />
  155.                         Enter a longer description of the project, such as the scope and any specifics that you know.
  156.                     </td>
  157.                 </tr>
  158.             </tbody>
  159.         </table>
  160.         <?php
  161.         if( $current !== FALSE ) {
  162.             ?>
  163.             <input type="hidden" name="project_id" id="project_id" value="<?php echo $current[ 'project_id' ]; ?>" />
  164.             <p class="submit">
  165.                 <input name="submit_project" id="submit_project" class="button" type="submit" value="Edit Project" />
  166.             </p>
  167.             <?php
  168.         } else {
  169.         ?>
  170.         <p class="submit">
  171.             <input name="submit_project" id="submit_project" class="button" type="submit" value="Add Project" />
  172.         </p>
  173.         <?php } ?>
  174.     </form>
  175.  
  176. </div> <!-- End Wrap -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement