예제 #1
0
     //$sOrg = utils::ReadParam('org_id', '');
     $sName = utils::ReadParam('q', '');
     $iMaxCount = utils::ReadParam('max', 30);
     $iCount = 0;
     $oFilter = new DBObjectSearch($sClass);
     $oFilter->AddCondition($sAttCode, $sName, 'Begins with');
     //$oFilter->AddCondition('org_id', $sOrg, '=');
     $oSet = new CMDBObjectSet($oFilter, array($sAttCode => true));
     while ($iCount < $iMaxCount && ($oObj = $oSet->fetch())) {
         $oPage->add($oObj->GetAsHTML($sAttCode) . "|" . $oObj->GetKey() . "\n");
         $iCount++;
     }
     break;
 case 'combo_options':
     $oPage->SetContentType('text/html');
     $oFilter = CMDBSearchFilter::FromOQL($sFilter);
     $oSet = new CMDBObjectSet($oFilter);
     while ($oObj = $oSet->fetch()) {
         $oPage->add('<option title="Here is more information..." value="' . $oObj->GetKey() . '">' . $oObj->GetName() . '</option>');
     }
     break;
 case 'display_document':
     $id = utils::ReadParam('id', '');
     $sField = utils::ReadParam('field', '');
     if (!empty($sClass) && !empty($id) && !empty($sField)) {
         DownloadDocument($oPage, $sClass, $id, $sField, 'inline');
     }
     break;
 case 'download_document':
     $id = utils::ReadParam('id', '');
     $sField = utils::ReadParam('field', '');
 /**
  * Constructs a DisplayBlock object from an XML template
  * @param $sTemplate string The XML template
  * @return DisplayBlock The DisplayBlock object, or null if the template is invalid
  */
 public static function FromTemplate($sTemplate)
 {
     $iStartPos = stripos($sTemplate, '<' . self::TAG_BLOCK . ' ', 0);
     $iEndPos = stripos($sTemplate, '</' . self::TAG_BLOCK . '>', $iStartPos);
     $iEndTag = stripos($sTemplate, '>', $iStartPos);
     $aParams = array();
     if ($iStartPos === false || $iEndPos === false) {
         return null;
     }
     // invalid template
     $sITopBlock = substr($sTemplate, $iStartPos, $iEndPos - $iStartPos + strlen('</' . self::TAG_BLOCK . '>'));
     $sITopData = substr($sTemplate, 1 + $iEndTag, $iEndPos - $iEndTag - 1);
     $sITopTag = substr($sTemplate, $iStartPos + strlen('<' . self::TAG_BLOCK), $iEndTag - $iStartPos - strlen('<' . self::TAG_BLOCK));
     $aMatches = array();
     $sBlockClass = "DisplayBlock";
     $bAsynchronous = false;
     $sBlockType = 'list';
     $sEncoding = 'text/serialize';
     if (preg_match('/ type="(.*)"/U', $sITopTag, $aMatches)) {
         $sBlockType = strtolower($aMatches[1]);
     }
     if (preg_match('/ asynchronous="(.*)"/U', $sITopTag, $aMatches)) {
         $bAsynchronous = strtolower($aMatches[1]) == 'true';
     }
     if (preg_match('/ blockclass="(.*)"/U', $sITopTag, $aMatches)) {
         $sBlockClass = $aMatches[1];
     }
     if (preg_match('/ objectclass="(.*)"/U', $sITopTag, $aMatches)) {
         $sObjectClass = $aMatches[1];
     }
     if (preg_match('/ encoding="(.*)"/U', $sITopTag, $aMatches)) {
         $sEncoding = strtolower($aMatches[1]);
     }
     if (preg_match('/ link_attr="(.*)"/U', $sITopTag, $aMatches)) {
         // The list to display is a list of links to the specified object
         $aParams['link_attr'] = $aMatches[1];
         // Name of the Ext. Key that makes this linkage
     }
     if (preg_match('/ target_attr="(.*)"/U', $sITopTag, $aMatches)) {
         // The list to display is a list of links to the specified object
         $aParams['target_attr'] = $aMatches[1];
         // Name of the Ext. Key that make this linkage
     }
     if (preg_match('/ object_id="(.*)"/U', $sITopTag, $aMatches)) {
         // The list to display is a list of links to the specified object
         $aParams['object_id'] = $aMatches[1];
         // Id of the object to be linked to
     }
     // Parameters contains a list of extra parameters for the block
     // the syntax is param_name1:value1;param_name2:value2;...
     if (preg_match('/ parameters="(.*)"/U', $sITopTag, $aMatches)) {
         $sParameters = $aMatches[1];
         $aPairs = explode(';', $sParameters);
         foreach ($aPairs as $sPair) {
             if (preg_match('/(.*)\\:(.*)/', $sPair, $aMatches)) {
                 $aParams[trim($aMatches[1])] = trim($aMatches[2]);
             }
         }
     }
     if (!empty($aParams['link_attr'])) {
         // Check that all mandatory parameters are present:
         if (empty($aParams['object_id'])) {
             // if 'links' mode is requested the d of the object to link to must be specified
             throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
         }
         if (empty($aParams['target_attr'])) {
             // if 'links' mode is requested the id of the object to link to must be specified
             throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
         }
     }
     switch ($sEncoding) {
         case 'text/serialize':
             $oFilter = CMDBSearchFilter::unserialize($sITopData);
             break;
         case 'text/oql':
             $oFilter = CMDBSearchFilter::FromOQL($sITopData);
             break;
     }
     return new $sBlockClass($oFilter, $sBlockType, $bAsynchronous, $aParams);
 }