Example #1
0
 /**
  * Preloads raw data for searchable user fields and controls caching
  * 
  * @return void
  */
 protected function loadRawdata($forceCache = false)
 {
     $cacheTime = $this->alterConf['GLOBALSEARCH_CACHE'];
     $cacheTime = time() - $cacheTime * 60;
     //in minutes
     //extracting user fields types to load
     if (!empty($this->alterConf['GLOBALSEARCH_FIELDS'])) {
         $this->fields = explode(',', $this->alterConf['GLOBALSEARCH_FIELDS']);
         $this->fields = array_flip($this->fields);
     }
     $updateCache = false;
     if (file_exists(self::CACHE_NAME)) {
         $updateCache = false;
         if (filemtime(self::CACHE_NAME) > $cacheTime) {
             $updateCache = false;
         } else {
             $updateCache = true;
         }
     } else {
         $updateCache = true;
     }
     //force cache parameter
     if ($forceCache) {
         $updateCache = true;
     }
     //updating rawdata cache
     if ($updateCache) {
         //loading needed fields
         if (isset($this->fields['realname'])) {
             $this->rawData = $this->rawData + $this->transformArray(zb_UserGetAllRealnames(), __('Real Name'), 'realname');
         }
         if (isset($this->fields['address'])) {
             $this->rawData = $this->rawData + $this->transformArray(zb_AddressGetFulladdresslist(), __('Full address'), 'address');
         }
         if (isset($this->fields['contract'])) {
             $allContracts = zb_UserGetAllContracts();
             $allContracts = array_flip($allContracts);
             $this->rawData = $this->rawData + $this->transformArray($allContracts, __('Contract'), 'contract');
         }
         if (isset($this->fields['phone']) or isset($this->fields['mobile'])) {
             $allPhonedata = zb_UserGetAllPhoneData();
             if (isset($this->fields['phone'])) {
                 if (!empty($allPhonedata)) {
                     $allPhones = array();
                     foreach ($allPhonedata as $io => $each) {
                         $allPhones[$io] = $each['phone'];
                     }
                     $this->rawData = $this->rawData + $this->transformArray($allPhones, __('Phone'), 'phone');
                 }
             }
             if (isset($this->fields['mobile'])) {
                 if (!empty($allPhonedata)) {
                     $allMobiles = array();
                     foreach ($allPhonedata as $io => $each) {
                         $allMobiles[$io] = $each['mobile'];
                     }
                     $this->rawData = $this->rawData + $this->transformArray($allMobiles, __('Mobile'), 'mobile');
                 }
             }
         }
         if (isset($this->fields['ip'])) {
             $this->rawData = $this->rawData + $this->transformArray(zb_UserGetAllIPs(), __('IP'), 'ip');
         }
         if (isset($this->fields['mac'])) {
             $this->rawData = $this->rawData + $this->transformArray(zb_UserGetAllIpMACs(), __('MAC address'), 'mac');
         }
         if (isset($this->fields['login'])) {
             $allLogins = zb_UserGetAllStargazerLogins();
             $this->rawData = $this->rawData + $this->transformArray($allLogins, __('Login'), 'login');
         }
         if (isset($this->fields['seal'])) {
             $conDet = new ConnectionDetails();
             $allSeals = $conDet->getAllSeals();
             $this->rawData = $this->rawData + $this->transformArray($allSeals, __('Cable seal'), 'seal');
         }
         if (isset($this->fields['paymentid'])) {
             if ($this->alterConf['OPENPAYZ_REALID']) {
                 $allPayIds_q = "SELECT * from `op_customers`";
                 $allPayIds = simple_queryall($allPayIds_q);
                 $tmpArrPayids = array();
                 if (!empty($allPayIds)) {
                     foreach ($allPayIds as $io => $each) {
                         $tmpArrPayids[$each['realid']] = $each['virtualid'];
                     }
                 }
                 $this->rawData = $this->rawData + $this->transformArray($tmpArrPayids, __('Payment ID'), 'payid');
             } else {
                 $allPayIds_q = "SELECT `login`,`IP` from `users`";
                 $allPayIds = simple_queryall($allPayIds_q);
                 $tmpArrPayids = array();
                 if (!empty($allPayIds)) {
                     foreach ($allPayIds as $io => $each) {
                         $tmpArrPayids[$each['login']] = ip2int($each['IP']);
                     }
                 }
                 $this->rawData = $this->rawData + $this->transformArray($tmpArrPayids, __('Payment ID'), 'payid');
             }
         }
         file_put_contents(self::CACHE_NAME, serialize($this->rawData));
     } else {
         $this->rawData = file_get_contents(self::CACHE_NAME);
         $this->rawData = unserialize($this->rawData);
     }
 }