phpScheduleIt
June 19, 2013, 04:52:09 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: Display Schedule Name Instead of ID  (Read 1915 times)
jault
Newbie
*

Karma: 0
Posts: 2


« on: March 29, 2011, 09:20:36 AM »

I'm sure this will seem very simple, but can anyone tell me how to get the schedule name to display instead of a schedule id?

I used this code to fill a column:

Code:
<td>' . $rs[$i]['scheduleid'] . '</td>

but I want the schedule name instead of the id. This is in the admin.template.php file.

Thanks in advance for your help.
« Last Edit: March 29, 2011, 02:28:35 PM by jault » Logged
jault
Newbie
*

Karma: 0
Posts: 2


« Reply #1 on: March 29, 2011, 02:28:54 PM »

Additionally, in DBEngine. class.php there is some scripting that pulls information from the database. However, it only pulls from the resources table. I need to pull the 'scheduletitle' from the schedules table and get it to show up in the column on the page that allows admin to edit user permissions. Should I create a whole new mysql query and then how do I make the admin template pull the information from a different query. I'm reading tutorials and trying to work through it on my own, but any help would be appreciated. Once I figure it all out I will post the code.

What I intend to do is add to the mod posted by Pete http://php.brickhost.com/forums/index.php?topic=3238.0 that will also display a column with the schedule name. We use one install for people in several buildings and only want users to have permission to use resources in their buildings. This will make it easier for admin to give permission to users based on which schedule they use.

Has anyone put anything together something that would allow admin to assign permissions to groups of users en masse?

Here is the current code:
From DBEngine.class.php
Code:
/**
    * Get associative array with machID, resource name, and status
    * This function loops through all resources
    *  and constructs an associative array with the
    *  resource's machID, name and status as
    *  $array[x] => ('machid' => 'this_resource_id', 'name' => 'Resource Name', 'status' => 'a')
    * @param none
    * @return array of machID, resource name, status
    */
    function get_mach_ids($scheduleid = null) {
        $return = array();
        $values = array();

        $sql = 'SELECT machid, name, scheduleid, location, status, approval, min_notice_time, max_notice_time FROM ' . $this->get_table('resources');
if ($scheduleid != null) {
            $sql .= ' WHERE scheduleid = ?';
            $values = array($scheduleid);
        }
        $sql .= ' ORDER BY location';

        $result = $this->db->query($sql, $values);

        $this->check_for_error($result);

        if ($result->numRows() <= 0) {
            $this->err_msg = translate('No resources in the database.');
            return false;
        }

        while ($rs = $result->fetchRow()) {
            $return[] = $this->cleanRow($rs);
        }

        $result->free();

        return $return;
    }
From admin.template.php
Code:
/**
* Interface for managing user training
* Provide interface for viewing and managing
*  user training information
* @param object $user User object of user to manage
* @param array $rs list of resources
*/
function print_manage_perms(&$user, $rs, $err) {
global $link;

if (!$user->is_valid()) {
CmnFns::do_error_box($user->get_error() . '<br /><a href="' . $_SERVER['PHP_SELF'] . '?tool=users">' . translate('Back') . '</a>', '', false);
return;
}

echo '<h3>' . $user->get_name() . '</h3>';
    ?>
<form name="train" method="post" action="admin_update.php">
  <table border="0" cellspacing="0" cellpadding="1">
    <tr>
      <td class="tableBorder">
        <table cellspacing="1" cellpadding="2" border="0" width="100%">
          <tr class="rowHeaders">
            <td width="240"><?php echo translate('Resource Name')?></td>
            <td width="70"><?php echo translate('Schedule')?></td>
            <td width="240"><?php echo translate('Location')?></td>
            <td width="60"><?php echo translate('Allowed')?></td>
          </tr>
         
      <?php
         
if (!$rs) echo '<tr class="cellColor0" style="text-align: center;"><td colspan="2">' $err '</td></tr>';

         for (
$i 0is_array($rs) && $i count($rs); $i++) {
            echo 
'<tr class="cellColor"><td>' $rs[$i]['name'] . '</td><td>'$rs[$i]['scheduleid'] . '</td><td>' $rs[$i]['location']
               . 
'<td style="text-align: center;">' 
                
'<input type="checkbox" name="machid[]" value="' $rs[$i]['machid'] . '"';
            if (
$user->has_perm($rs[$i]['machid']))
               echo 
' checked="checked"';
            echo 
'/></td></tr>';
           }

      
// Close off tables/forms.  Print buttons and hidden field
      
?>

          <tr class="cellColor1">
            <td>&nbsp;</td>
            <td style="text-align: center;">
              </td><td style="text-align: center;"><input type="checkbox" name="checkAll" onclick="checkAllBoxes(this);" />
      </td>
    </tr>
  </table>
  <input type="hidden" name="memberid" value="<?php echo $user->get_id()?>" />
  <p style="padding-top: 5px; padding-bottom: 5px;"><input type="checkbox" name="notify_user" value="true" /><?php echo translate('Notify user')?></p>
  <?php echo submit_button(translate('Save')) . hidden_fn('editPerms')?>
  <input type="button" name="cancel" value="<?php echo translate('Manage Users')?>" class="button" onclick="document.location='<?php echo $_SERVER['PHP_SELF']?>?tool=users';" />
</form>
<?php
}

I am trying to get the "Schedule" column that is currently populated with 'scheduleid' to be populated with 'schedule title' instead.
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5506


WWW
« Reply #2 on: April 04, 2011, 01:46:55 PM »

You'll just want to change the query to also return the scheduletitle column, then just reference that the same way the scheduleid column is being used.

Something like:

$sql = 'SELECT machid, name, r.scheduleid, scheduletitle, location, status, approval, min_notice_time, max_notice_time FROM ' . $this->get_table('resources') . ' r INNER JOIN schedules s ON s.scheduleid=r.scheduleid';
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!