"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/ocsreports/require/search/AccountinfoSearch.php" (17 Apr 2019, 4811 Bytes) of package /linux/privat/OCSNG_UNIX_SERVER_2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "AccountinfoSearch.php": 2.5_vs_2.6.

    1 <?php
    2 /*
    3  * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
    4  * See the Contributors file for more details about them.
    5  *
    6  * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
    7  *
    8  * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
    9  * it and/or modify it under the terms of the GNU General Public License as
   10  * published by the Free Software Foundation, either version 2 of the License,
   11  * or (at your option) any later version.
   12  *
   13  * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
   14  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU General Public License
   19  * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
   20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   21  * MA 02110-1301, USA.
   22  */
   23 
   24 require 'require/function_admininfo.php';
   25 
   26  /**
   27   * This class implement basic behavior for accountinfo search management
   28   */
   29  class AccountinfoSearch
   30  {
   31 
   32     /**
   33      * Constants
   34      */
   35     const ACC_TYPE_COMPUTER = 'COMPUTERS';
   36     const ACC_TYPE_SNMP = 'SNMP';
   37 
   38     /**
   39      * Account infos data property
   40      */
   41     private $accountInfosList = [];
   42 
   43     /**
   44      * Specific account infos data property
   45      */
   46     private $specificAccountInfos = [
   47         "TAG",
   48     ];
   49 
   50     /**
   51      * Query
   52      */
   53     private $accountInfoConfigQuery= "SELECT * FROM `accountinfo_config`";
   54 
   55     /**
   56      * Objects
   57      */
   58     private $dbObject = null;
   59     private $dbName = null;
   60     private $accountInfosStruct = null;
   61 
   62 
   63     /**
   64      * Construct
   65      */
   66     function __construct() {
   67         $this->dbObject = $_SESSION['OCS']["readServer"];
   68         $this->dbName = DB_NAME;
   69         $this->createAccountInfoStruct();
   70         $this->retrieveAccountInfosConfig();
   71     }
   72 
   73     /**
   74      * Create account info struct
   75      */
   76     private function createAccountInfoStruct(){
   77         $this->accountInfosStruct = new StdClass();
   78         $this->accountInfosStruct->id = "ID";
   79         $this->accountInfosStruct->comment = "COMMENT";
   80         // Only for TAG
   81         $this->accountInfosStruct->nameacc = "NAME_ACCOUNTINFO";
   82     }
   83 
   84     /**
   85      * Get accountinfos datamap for multi criteria
   86      */
   87     private function retrieveAccountInfosConfig(){
   88         $accountInfosConfig = mysql2_query_secure($this->accountInfoConfigQuery, $this->dbObject);
   89 
   90         while ($accountInfos = mysqli_fetch_array($accountInfosConfig)) {
   91 
   92             // Management for specific acc infos (TAG)
   93             if(in_array($accountInfos[$this->accountInfosStruct->nameacc], $this->specificAccountInfos)){
   94                 $accountInfos[$this->accountInfosStruct->id] = $accountInfos[$this->accountInfosStruct->nameacc];
   95             }else{
   96                 $accountInfos[$this->accountInfosStruct->id] = "fields_".$accountInfos[$this->accountInfosStruct->id];
   97             }
   98 
   99             switch ($accountInfos['ACCOUNT_TYPE']) {
  100                 case self::ACC_TYPE_SNMP:
  101                     $accType = self::ACC_TYPE_SNMP;
  102                     break;
  103                 case self::ACC_TYPE_COMPUTER:
  104                     $accType = self::ACC_TYPE_COMPUTER;
  105                     break;
  106                 default:
  107                     break;
  108             }
  109 
  110             $this->accountInfosList[$accType][$accountInfos[$this->accountInfosStruct->id]] = $accountInfos[$this->accountInfosStruct->comment];
  111         }
  112     }
  113 
  114     /**
  115      * Get accountinfos list
  116      */
  117     public function getAccountInfosList(){
  118         return $this->accountInfosList;
  119     }
  120 
  121     /**
  122      * Get accountinfos type
  123      * @param  string $field_account
  124      * @return string $info
  125      */
  126     public function getSearchAccountInfo($field_account){
  127         $id = explode("_", $field_account);
  128         $sql = "SELECT TYPE FROM accountinfo_config WHERE ID = %s";
  129         $arg = array($id[1]);
  130         $result = mysql2_query_secure($sql, $this->dbObject, $arg);
  131 
  132         while ($type = mysqli_fetch_array($result)){
  133           $info = $type['TYPE'];
  134         }
  135 
  136         return $info;
  137     }
  138 
  139     /**
  140      * Get accountinfos_config name
  141      * @param  string $field
  142      * @return array $values
  143      */
  144     public function find_accountinfo_values($field, $typeInfo = null){
  145         $id = explode("_", $field);
  146         $sql = "SELECT `NAME` FROM accountinfo_config WHERE ID = %s";
  147         $arg = array($id[1]);
  148         $result = mysql2_query_secure($sql, $this->dbObject, $arg);
  149 
  150         while ($type = mysqli_fetch_array($result)){
  151           $info = 'ACCOUNT_VALUE_'.$type['NAME'];
  152         }
  153 
  154         $values = find_value_field($info, $typeInfo);
  155 
  156         return $values;
  157     }
  158 
  159  }