• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    [MOD] Sort group members by hostname - 0.32, Ubuntu 10.04 LTS

    Scheduled Pinned Locked Moved
    Tutorials
    2
    6
    4.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chad-bisd Moderator
      last edited by

      I got really annoyed with the membership page for groups. The list was in seemingly random order and it make finding a particular member a bit of a pain. Plus I like things sorted.

      I basically copied a an existing function and modified it to do what I wanted, then made the calling page use the new function. This way I didn’t step on anything FOG was doing elsewhere. I’m pretty sure now that I could have just modified the original function, but I haven’t had the time to verify.

      First, you’ll want to make a copy of the original file before modifying it.
      [CODE]
      sudo cp /var/www/fog/commons/functions.include.php /var/www/fog/commons/functions.include.BACKUP.php
      [/CODE]

      Then open up the /var/www/fog/commons/functions.include.php and go to line 1425. This should be the end of the function getImageMembersByGroupID.

      Make a few blank lines below the end of the function and paste in the following.

      [CODE]
      function getImageMembersByGroupIDSorted( $conn, $groupID )
      {
      $arM = array();
      if ( $conn != null && $groupID != null )
      {
      $sql = “SELECT
      groupMembers.gmHostID
      FROM
      groups inner join groupMembers
      on (groups.groupID = groupMembers.gmGroupID)
      inner join hosts
      on (hosts.hostID = gmHostID)
      WHERE groups.groupID = $groupID
      ORDER BY hosts.hostName”;

                  $res = mysql_query( $sql, $conn ) or criticalError( mysql_error(), _("FOG :: Database error!") );
                  $arHosts = array();
                  while( $ar = mysql_fetch_array( $res ) )
                  {
                          $arHosts[] = $ar["gmHostID"];
                  }
                  
                  for( $i = 0; $i < count( $arHosts ); $i++ )
                  {
                          $tmpMember = getImageMemberFromHostID( $conn, $arHosts[$i] );
                          if( $tmpMember != null )
                                  $arM[] = $tmpMember;
                  }
          }
          return $arM;
      

      }
      [/CODE]

      Save the file.

      Now to edit the file that uses this function.

      Make a backup of the file, just in case.
      [CODE] sudo cp /var/www/fog/management/includes/groups.edit.include.php /var/www/fog/management/includes/groups.edit.include.BACKUP.php[/CODE]

      Now open the file for editing.
      [CODE]
      sudo nano -w /var/www/fog/management/includes/groups.edit.include.php
      [/CODE]

      On or near line 641, you’ll be inside the if ( $_GET[“tab”] == “member” ) block. Change the function call to your new function name.

      Original line:
      [CODE]$members = getImageMembersByGroupID( $conn, $ar[“groupID”] );[/CODE]
      Modified line:
      [CODE]$members = getImageMembersByGroupIDSorted( $conn, $ar[“groupID”] );[/CODE]

      Save the file. Now membership listing should display sorted by hostname.


      If you would like to make a donation to the Fog project, please do so [U][COLOR=#0000ff][URL='http://sourceforge.net/dona…

      1 Reply Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott
        last edited by

        I’m going to try implementing this within 0.33b

        I hope you don’t mind.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 0
        • C
          chad-bisd Moderator
          last edited by

          I don’t mind at all. I haven’t been keen on trying to mod 0.33 code because I don’t yet understand the class changes and what code might be abandoned or moved into methods as opposed to being in include files.


          If you would like to make a donation to the Fog project, please do so [U][COLOR=#0000ff][URL='http://sourceforge.net/dona…

          1 Reply Last reply Reply Quote 0
          • Tom ElliottT
            Tom Elliott
            last edited by

            From what I can tell, all include elements have a class equivalent, it’s just a matter of moving the code from the include into the proper class.

            I only just started getting into the bowels of FOG 0.33b, so it’s kind of fascinating that things were missing. My only issue so far is figuring out how to allow the css to maintain display: none rather than display: hidden for the group element.

            EDIT: just to add more info.

            The same commons/functions.include.php contains the original element you changed. So I’ll just make the mods to that so it’s built directly into the original function.

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • Tom ElliottT
              Tom Elliott
              last edited by

              If it’s any help to anybody:

              Locate the function [FONT=Consolas]getImageMembersByGroupID [/FONT]in:
              {fogwebdir}/commons/functions.include.php

              The only change within this function is the select statement from lines 1405 to 1409:
              [CODE]$sql = “select
              *
              from groups
              inner join groupMembers on ( groups.groupID = groupMembers.gmGroupID )
              where groupID = $groupID”;[/CODE]
              [FONT=Courier New][COLOR=#000000]to (add lines 1409 thru 1413)[/COLOR][/FONT]
              [CODE]$sql = “SELECT
              groupMembers.gmHostID
              FROM
              groups inner join groupMembers
              on (groups.groupID = groupMembers.gmGroupID)
              inner join hosts
              on (hosts.hostID = gmHostID)
              WHERE groups.groupID = $groupID
              ORDER BY hosts.hostName”;[/CODE]

              [FONT=Consolas]Really it’s quite beautiful.[/FONT]

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

              Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

              Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

              1 Reply Last reply Reply Quote 0
              • C
                chad-bisd Moderator
                last edited by

                Thanks. I could not find a reason to query for all fields in the table (*) when only the gmHostID was ever being used. In all the calls to the function I could never see where other fields were being used out of the result set. Since I didn’t want to mess something up I didn’t know about, I made a new function and changed the call in the specific page.


                If you would like to make a donation to the Fog project, please do so [U][COLOR=#0000ff][URL='http://sourceforge.net/dona…

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post

                249

                Online

                12.0k

                Users

                17.3k

                Topics

                155.2k

                Posts
                Copyright © 2012-2024 FOG Project