phpScheduleIt
June 18, 2013, 03:04:51 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Change a reservations resource when editing. v1.2.12  (Read 828 times)
Azyrus
Newbie
*

Karma: 0
Posts: 28


« on: April 27, 2012, 09:13:18 PM »

Im not any good at PHP but this is how I got it to work with Nicks help, I'm sure the code is sloppy but it works without error. If anyone knows of a better way please post Smiley This is to allow a reservations resource to be changed through the modify reservation page, the code below works on a clean install of phpScheduleIt 1.2.12.

Green code is to be inserted or updated, red code is to be overwritten.

For this to work you need to update the mach id's in the reserve.template.php file at the end of this post to the mach ids in your database, you can find them under the resources table. You will need to add as many resources as you have.

phpscheduleit/reserve.php
   if ($fn == 'create' || $fn == 'modify')
   {
      $helper = new ReservationHelper();
      $util = new Utility();

      $orig = (isset($_POST['orig_invited_users']) && count($_POST['orig_invited_users']) > 0) ? $_POST['orig_invited_users'] : array();
      $invited = (isset($_POST['invited_users'])) ? $_POST['invited_users'] : array();
      $removed = (isset($_POST['removed_users'])) ? $_POST['removed_users'] : array();
      $participating = (isset($_POST['participating_users'])) ? $_POST['participating_users'] : array();
      
      $users_to_remove = $helper->getRowsForRemoval($orig, $removed, $invited);
      $users_to_invite = $helper->getRowsForInvitation($orig, $invited);
      $unchanged_users = $helper->getUnchangedUsers($orig, $invited, $participating);
      
      $orig_resources = (isset($_POST['orig_resources']) && count($_POST['orig_resources']) > 0) ? $_POST['orig_resources'] : array();
      $selected_resources =  (isset($_POST['selected_resources']) && count($_POST['selected_resources']) > 0) ? $_POST['selected_resources'] : array();

      $resources_to_add = $util->getAddedItems($orig_resources, $selected_resources);
      $resources_to_remove = $util->getRemovedItems($orig_resources, $selected_resources);
      $machid = isset($_POST['machid']) ? stripslashes(htmlspecialchars($_POST['machid'])) : '';

      $res->user       = new User($_POST['memberid']);
      $res->start_date= $start_date;
      $res->end_date    = $end_date;
      $res->start      = $_POST['starttime'];
      $res->end      = $_POST['endtime'];
      
      $res->machid = $machid;
      $res->summary   = stripslashes($_POST['summary']);
      $res->allow_participation = (int)isset($_POST['allow_participation']);
      $res->allow_anon_participation = (int)isset($_POST['allow_anon_participation']);
      $res->reminderid = isset($_POST['reminderid']) ? $_POST['reminderid'] : null;
      $res->reminder_minutes_prior = isset($_POST['reminder_minutes_prior']) ? intval($_POST['reminder_minutes_prior']) : 0;
   }

phpscheduleit\lib\db\ResDB.class.php

      $resources_to_remove = $util->getRemovedItems($orig_resources, $selected_resources);

   /**
   * Modify current reservation time
   * If this reservation is part of a recurring group, all reservations in the
   *  group will be modified that havent already passed
   * @param Object $res reservation that we are modifying
   * @param array $users_to_invite hashtable of users to invite to this reservation
   * @param array $users_to_remove hashtable of users to remove from this reservation
   * @param array $resources_to_add array of resourceids to add to this reservation
   * @param array $resources_to_remove array of resourceids to remove from this reservation   
   * @param string $accept_code acceptance code to be used for reservation accept/decline
   */
   function mod_res($res, $users_to_invite, $users_to_remove, $resources_to_add, $resources_to_remove, $accept_code) {
      $t = new Timer("mod_res()");
      $t->start();
      
      $id = $res->get_id();
      
      // Update the main reservation data
      $values = array (
               $res->get_start_date(),
               $res->get_end_date(),
               $res->get_start(),
               $res->get_end(),
               mktime(),
               $res->get_machid(),
               $res->get_summary(),
               $res->get_pending(),
               $res->get_allow_participation(),
               $res->get_allow_anon_participation(),
               $id
            );

      $query = 'UPDATE ' . $this->get_table(TBL_RESERVATIONS)
                . ' SET '
            . ' start_date=?,'
            . ' end_date=?,'
            . ' starttime=?,'
                . ' endtime=?,'
                . ' modified=?,'
            . ' machid=?,'
            . ' summary=?,'
            . ' is_pending=?,'
            . ' allow_participation=?,'
            . ' allow_anon_participation=?'
                . ' WHERE resid=?';

      $resources_to_remove = $util->getRemovedItems($orig_resources, $selected_resources);

CHANGE:

   /**
   * Returns the resource id of this reservation
   * @param none
   * @return string resource id
   */
   function get_machid() {
      return $this->resource->get_property('machid');
   }


TO:
   /**
   * Returns the resource id of this reservation
   * @param none
   * @return string resource id
   */
   function get_machid() {
      if ($this->type == RES_TYPE_ADD) {
         return $this->resource->get_property('machid');
      } else if ($this->type == RES_TYPE_MODIFY) {
         return $this->machid;
      }
      }


phpscheduleit/templates/reserve.template.php
As in the user documentation add this like a normal custom field, I've added this above the summary.

/**
* Print out the reservation summary or a box to add/edit one
* @param string $machid machid to edit
* @param string $type type of reservation
*/
function print_machid($machid, $type) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="tableBorder">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td class="cellColor" style="width:50%;">Mach ID:</td>
<td class="cellColor" style="text-align:right;">
<?php
if ($type == RES_TYPE_ADD || $type == RES_TYPE_MODIFY)
echo '<select name="machid" class="textbox" />';
if ($machid == 'sc14f9b38f30b393')
echo "<option selected=selected value='sc14f9b38f30b393'>Resource 1</option>";
else
echo "<option value='sc14f9b38f30b393'>Resource 1</option>";

if ($machid == 'sc14f9b38fa26110')
echo "<option selected=selected value='sc14f9b38fa26110'>Resource 2</option>";
else
echo "<option value='sc14f9b38fa26110'>Resource 2</option>";
echo '</select>';
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}

/**
* Print out the reservation summary or a box to add/edit one
* @param string $summary summary to edit
* @param string $type type of reservation
*/
function print_summary($summary, $type) {
?>
   <table width="100%" border="0" cellspacing="0" cellpadding="1">
    <tr class="tableBorder">
     <td>
      <table width="100%" border="0" cellspacing="1" cellpadding="0">
       <tr>
       <td class="cellColor"><h5 align="center"><?php echo translate('Summary')?></h5></td>
      </tr>
      <tr>
      <td class="cellColor" style="text-align: left;">
      <?php
      if ($type == RES_TYPE_ADD || $type == RES_TYPE_MODIFY || $type == RES_TYPE_APPROVE) {
         echo '<div style="text-align:center;" id="summary_div"><textarea class="textbox" name="summary" rows="3" cols="40">' . $summary . '</textarea></div>';
      }
      else {
         echo (!empty($summary) ? CmnFns::html_activate_links($summary) : translate('N/A'));
      }
      ?>
      </td>
      </tr>
      </table>
     </td>
    </tr>
   </table>
<?php
}

TO UPDATE YOUR MACH ID:
Find your resources mach id in the sql database and update all three values.

if ($machid == 'sc14f9b38fa26110')
echo "<option selected=selected value='sc14f9b38fa26110'>Resource 2</option>";
else
echo "<option value='sc14f9b38fa26110'>Resource 2</option>";
echo '</select>';


All credits go to Nick, thanks again Nick =D
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!