public function toString($destroy = true)
 {
     if (count($this->tabs) == 1) {
         $this->setAttribute('class', 'min-width ui-tabs ui-widget ui-widget-content ui-corner-all widget');
         $header = reset($this->headers);
         $header = new CDiv($header);
         $header->addClass('ui-corner-all ui-widget-header header');
         $header->setAttribute('id', 'tab_' . key($this->headers));
         $this->addItem($header);
         $tab = reset($this->tabs);
         $tab->addClass('ui-tabs ui-tabs-panel ui-widget ui-widget-content ui-corner-all widget');
         $this->addItem($tab);
     } else {
         $headersList = new CList();
         foreach ($this->headers as $id => $header) {
             $tabLink = new CLink($header, '#' . $id, null, null, false);
             $tabLink->setAttribute('id', 'tab_' . $id);
             $headersList->addItem($tabLink);
         }
         $this->addItem($headersList);
         $this->addItem($this->tabs);
         $options = array();
         if (!is_null($this->selectedTab)) {
             $options['selected'] = $this->selectedTab;
         }
         if ($this->rememberTab) {
             $options['cookie'] = array();
         }
         zbx_add_post_js('jQuery("#' . $this->id . '").tabs(' . zbx_jsvalue($options, true) . ').show();');
     }
     return parent::toString($destroy);
 }
 /**
  * Creates and returns calculation rules chain.
  * 
  * @return CList calculation rules chain
  */
 protected function createChain()
 {
     if (!isset($this->_rules)) {
         $chain = $this->chain();
         $this->_rules = new CList();
         foreach ($chain as $item) {
             $rule = $this->createChainRule($item);
             $this->_rules->add($rule);
         }
     }
     return $this->_rules;
 }
 protected function addValidators()
 {
     $validators = new CList();
     foreach ($this->rules() as $rule) {
         if (isset($rule[0], $rule[1])) {
             $validator = CValidator::createValidator($rule[1], $this->_model, $rule[0], array_slice($rule, 2));
             $validators->add($validator);
         } else {
             throw new CException(Yii::t('yii', '{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.', array('{class}' => get_class($this))));
         }
     }
     return $validators;
 }
 /**
  * @param bool $id = false
  * @return CList|int
  */
 public function getList($id = false)
 {
     if ($id === true) {
         return $this->list->getStringId();
     }
     return $this->list;
 }
Exemple #5
0
 public static function findRecursive($dir, $filters = NULL, $depth = -1, $limit = 0)
 {
     if (!$filters instanceof EFileFilters) {
         $filters = new EFileFilters($filters);
     }
     $list = new CList();
     //TODO: $dir = new DirectoryIterator(dirname(__FILE__)); foreach ($dir as $fileinfo) {}
     $handle = opendir($dir);
     while (($fileName = readdir($handle)) !== FALSE) {
         if ($limit > 0 && $list->count >= $limit) {
             break;
         }
         if ($fileName === '.' || $fileName === '..') {
             continue;
         }
         $file = EFile::getInstance($dir . DIRECTORY_SEPARATOR . $fileName);
         //TODO: подумать о сортировке прямо в цикле поиска
         if ($filters->run($file)) {
             if ($file->isDir && $depth) {
                 $list->mergeWith(self::findRecursive($file->path, $filters, $depth - 1, $limit - $list->count));
             } else {
                 $list->add($file);
             }
         }
     }
     closedir($handle);
     return $list;
 }
 public function createValidators()
 {
     $validators = new CList();
     $rules = $this->rules();
     if ($this->addDefaultRules) {
         $rules = array_merge($rules, $this->defaultRules());
     }
     foreach ($rules as $rule) {
         if (isset($rule[0], $rule[1])) {
             // attributes, validator name
             $validators->add(CValidator::createValidator($rule[1], $this, $rule[0], array_slice($rule, 2)));
         } else {
             throw new CException(Yii::t('yii', '{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.', array('{class}' => get_class($this))));
         }
     }
     return $validators;
 }
Exemple #7
0
 /**
  * Inserts an item at the specified position.
  * This method overrides the parent implementation by
  * checking the item to be inserted is of certain type.
  * @param integer $index the specified position.
  * @param mixed $item new item
  * @throws CException If the index specified exceeds the bound,
  * the list is read-only or the element is not of the expected type.
  */
 public function insertAt($index, $item)
 {
     if ($item instanceof $this->_type) {
         parent::insertAt($index, $item);
     } else {
         throw new CException(Yii::t('yii', 'CTypedList<{type}> can only hold objects of {type} class.', array('{type}' => $this->_type)));
     }
 }
Exemple #8
0
    public function toString($destroy = true)
    {
        if (count($this->tabs) == 1) {
            $this->setAttribute('class', 'min-width ui-tabs ui-widget ui-widget-content ui-corner-all widget');
            $header = reset($this->headers);
            $header = new CDiv($header);
            $header->addClass('ui-corner-all ui-widget-header header');
            $header->setAttribute('id', 'tab_' . key($this->headers));
            $this->addItem($header);
            $tab = reset($this->tabs);
            $tab->addClass('ui-tabs ui-tabs-panel ui-widget ui-widget-content ui-corner-all widget');
            $this->addItem($tab);
        } else {
            $headersList = new CList();
            foreach ($this->headers as $id => $header) {
                $tabLink = new CLink($header, '#' . $id, null, null, false);
                $tabLink->setAttribute('id', 'tab_' . $id);
                $headersList->addItem($tabLink);
            }
            $this->addItem($headersList);
            $this->addItem($this->tabs);
            if ($this->selectedTab === null) {
                $activeTab = get_cookie('tab', 0);
                $createEvent = '';
            } else {
                $activeTab = $this->selectedTab;
                $createEvent = 'create: function() { jQuery.cookie("tab", ' . $this->selectedTab . '); },';
            }
            $disabledTabs = $this->disabledTabs === null ? '' : 'disabled: ' . CJs::encodeJson($this->disabledTabs) . ',';
            zbx_add_post_js('
				jQuery("#' . $this->id . '").tabs({
					' . $createEvent . '
					' . $disabledTabs . '
					active: ' . $activeTab . ',
					activate: function(event, ui) {
						jQuery.cookie("tab", ui.newTab.index().toString());
					}
				})
				.css("visibility", "visible");');
        }
        return parent::toString($destroy);
    }
Exemple #9
0
 /**
  * @param string $options['name']
  * @param int    $options['value']		(optional) Default: TRIGGER_SEVERITY_NOT_CLASSIFIED
  * @param bool   $options['all']		(optional)
  */
 public function __construct(array $options = [])
 {
     parent::__construct();
     $id = zbx_formatDomId($options['name']);
     $this->addClass(ZBX_STYLE_RADIO_SEGMENTED);
     $this->setId($id);
     if (!array_key_exists('value', $options)) {
         $options['value'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
     }
     $severity_from = array_key_exists('all', $options) && $options['all'] ? -1 : TRIGGER_SEVERITY_NOT_CLASSIFIED;
     $config = select_config();
     for ($severity = $severity_from; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $name = $severity == -1 ? _('all') : getSeverityName($severity, $config);
         $class = $severity == -1 ? null : getSeverityStyle($severity);
         $radio = (new CInput('radio', $options['name'], $severity))->setId(zbx_formatDomId($options['name'] . '_' . $severity));
         if ($severity === $options['value']) {
             $radio->setAttribute('checked', 'checked');
         }
         parent::addItem((new CListItem([$radio, new CLabel($name, $options['name'] . '_' . $severity)]))->addClass($class));
     }
 }
 public function toString($destroy = true)
 {
     if ($this->modern) {
         $this->addClass(ZBX_STYLE_RADIO_SEGMENTED);
     } else {
         $this->addClass($this->orientation == self::ORIENTATION_HORIZONTAL ? ZBX_STYLE_LIST_HOR_CHECK_RADIO : ZBX_STYLE_LIST_CHECK_RADIO);
     }
     foreach ($this->values as $key => $value) {
         if ($value['id'] === null) {
             $value['id'] = zbx_formatDomId($this->name) . '_' . $key;
         }
         $radio = (new CInput('radio', $this->name, $value['value']))->setEnabled($this->enabled)->onChange($value['on_change'])->setId($value['id']);
         if ($value['value'] === $this->value) {
             $radio->setAttribute('checked', 'checked');
         }
         if ($this->modern) {
             parent::addItem([$radio, new CLabel($value['name'], $value['id'])]);
         } else {
             parent::addItem(new CLabel([$radio, $value['name']], $value['id']));
         }
     }
     return parent::toString($destroy);
 }
Exemple #11
0
 function stage3()
 {
     $table = new CTable(null, 'requirements');
     $table->setAlign('center');
     $DB['TYPE'] = $this->getConfig('DB_TYPE');
     $cmbType = new CComboBox('type', $DB['TYPE'], 'this.form.submit();');
     $frontendSetup = new FrontendSetup();
     $databases = $frontendSetup->getSupportedDatabases();
     foreach ($databases as $id => $name) {
         $cmbType->addItem($id, $name);
     }
     $table->addRow(array(new CCol(_('Database type'), 'header'), $cmbType));
     switch ($DB['TYPE']) {
         case ZBX_DB_SQLITE3:
             $database = new CTextBox('database', $this->getConfig('DB_DATABASE', 'zabbix'));
             $database->attr('onchange', "disableSetupStepButton('#next_2')");
             $table->addRow(array(new CCol(_('Database file'), 'header'), $database));
             break;
         default:
             $server = new CTextBox('server', $this->getConfig('DB_SERVER', 'localhost'));
             $server->attr('onchange', "disableSetupStepButton('#next_2')");
             $table->addRow(array(new CCol(_('Database host'), 'header'), $server));
             $port = new CNumericBox('port', $this->getConfig('DB_PORT', '0'), 5, 'no', false, false);
             $port->attr('style', '');
             $port->attr('onchange', "disableSetupStepButton('#next_2'); validateNumericBox(this, 'false', 'false');");
             $table->addRow(array(new CCol(_('Database port'), 'header'), array($port, ' 0 - use default port')));
             $database = new CTextBox('database', $this->getConfig('DB_DATABASE', 'zabbix'));
             $database->attr('onchange', "disableSetupStepButton('#next_2')");
             $table->addRow(array(new CCol(_('Database name'), 'header'), $database));
             if ($DB['TYPE'] == ZBX_DB_DB2) {
                 $schema = new CTextBox('schema', $this->getConfig('DB_SCHEMA', ''));
                 $schema->attr('onchange', "disableSetupStepButton('#next_2')");
                 $table->addRow(array(new CCol(_('Database schema'), 'header'), $schema));
             }
             $user = new CTextBox('user', $this->getConfig('DB_USER', 'root'));
             $user->attr('onchange', "disableSetupStepButton('#next_2')");
             $table->addRow(array(new CCol(_('User'), 'header'), $user));
             $password = new CPassBox('password', $this->getConfig('DB_PASSWORD', ''));
             $password->attr('onchange', "disableSetupStepButton('#next_2')");
             $table->addRow(array(new CCol(_('Password'), 'header'), $password));
             break;
     }
     global $ZBX_MESSAGES;
     if (!empty($ZBX_MESSAGES)) {
         $lst_error = new CList(null, 'messages');
         foreach ($ZBX_MESSAGES as $msg) {
             $lst_error->addItem($msg['message'], $msg['type']);
         }
         $table = array($table, $lst_error);
     }
     return array(new CDiv(new CDiv(array('Please create database manually, and set the configuration parameters for connection to this database.', BR(), BR(), 'Press "Test connection" button when done.', BR(), $table), 'vertical_center'), 'table_wraper'), new CDiv(array(isset($_REQUEST['retry']) ? !$this->DISABLE_NEXT_BUTTON ? new CSpan(array(_('OK'), BR()), 'ok') : new CSpan(array(_('Fail'), BR()), 'fail') : null, new CSubmit('retry', 'Test connection')), 'info_bar'));
 }
 /**
  * @param array $rules
  * @return CList
  * @throws CException
  */
 private function createValueValidatorsByRules(array $rules)
 {
     $validators = new CList();
     foreach ($rules as $rule) {
         if (isset($rule[0], $rule[1])) {
             if ($rule[1] != 'unique') {
                 $validators->add(CValidator::createValidator($rule[1], $this, $rule[0], array_slice($rule, 2)));
             }
         } else {
             throw new CException(Zurmo::t('ReportsModule', '{class} has an invalid validation rule. The rule must specify ' . 'attributes to be validated and the validator name.', array('{class}' => get_class($this))));
         }
     }
     return $validators;
 }
 /**
  * Inserts an item at the specified position.
  * This method overrides the parent implementation by adding
  * additional check for the item to be added. In particular,
  * only objects implementing {@link IFilter} can be added to the list.
  * @param integer $index the specified position.
  * @param mixed $item new item
  * @throws CException If the index specified exceeds the bound or the list is read-only, or the item is not an {@link IFilter} instance.
  */
 public function insertAt($index, $item)
 {
     if ($item instanceof IFilter) {
         parent::insertAt($index, $item);
     } else {
         throw new CException(Yii::t('yii', 'CFilterChain can only take objects implementing the IFilter interface.'));
     }
 }
Exemple #14
0
    $arResult["~LIST_SECTION_URL"] = CHTTP::urlAddParams($arResult["~LIST_SECTION_URL"], array("list_section_id" => ""));
}
$arResult["LIST_SECTION_URL"] = htmlspecialcharsbx($arResult["~LIST_SECTION_URL"]);
if ($ELEMENT_ID > 0) {
    $copy_id = 0;
    $arResult["LIST_COPY_ELEMENT_URL"] = CHTTP::urlAddParams(str_replace(array("#list_id#", "#section_id#", "#element_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["SECTION_ID"]), 0, $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_ELEMENT_URL"]), array("copy_id" => $ELEMENT_ID), array("skip_empty" => true, "encode" => true));
    if (isset($_GET["list_section_id"]) && strlen($_GET["list_section_id"]) == 0) {
        $arResult["LIST_COPY_ELEMENT_URL"] = CHTTP::urlAddParams($arResult["LIST_COPY_ELEMENT_URL"], array("list_section_id" => ""));
    }
} else {
    if (isset($_REQUEST["copy_id"]) && $_REQUEST["copy_id"] > 0) {
        $copy_id = intval($_REQUEST["copy_id"]);
    }
}
$arResult["COPY_ID"] = $copy_id;
$obList = new CList($arIBlock["ID"]);
$arResult["FIELDS"] = $obList->GetFields();
if ($bBizproc) {
    $arSelect = array("ID", "IBLOCK_ID", "NAME", "IBLOCK_SECTION_ID", "CREATED_BY", "BP_PUBLISHED");
} else {
    $arSelect = array("ID", "IBLOCK_ID", "NAME", "IBLOCK_SECTION_ID");
}
$arProps = array();
foreach ($arResult["FIELDS"] as $FIELD_ID => $arField) {
    $arResult["FIELDS"][$FIELD_ID]["~NAME"] = $arResult["FIELDS"][$FIELD_ID]["NAME"];
    $arResult["FIELDS"][$FIELD_ID]["NAME"] = htmlspecialcharsbx($arResult["FIELDS"][$FIELD_ID]["NAME"]);
    if ($obList->is_field($FIELD_ID)) {
        $arSelect[] = $FIELD_ID;
    } else {
        $arProps[] = $FIELD_ID;
    }
Exemple #15
0
}
$widget = (new CWidget())->setTitle(_('Notifications'));
// if no media types were defined, we have nothing to show
if (zbx_empty($media_types)) {
    $table = new CTableInfo();
    $widget->addItem($table)->show();
} else {
    $table = (new CTableInfo())->makeVerticalRotation();
    // fetch the year of the first alert
    if (($firstAlert = DBfetch(DBselect('SELECT MIN(a.clock) AS clock FROM alerts a'))) && $firstAlert['clock']) {
        $minYear = date('Y', $firstAlert['clock']);
    } else {
        $minYear = date('Y');
    }
    $form = (new CForm())->setMethod('get');
    $controls = new CList();
    $cmbMedia = new CComboBox('media_type', $media_type, 'submit()');
    $cmbMedia->addItem(0, _('all'));
    foreach ($media_types as $media_type_id => $media_type_description) {
        $cmbMedia->addItem($media_type_id, $media_type_description);
        // we won't need other media types in the future, if only one was selected
        if ($media_type > 0 && $media_type != $media_type_id) {
            unset($media_types[$media_type_id]);
        }
    }
    $controls->addItem([_('Media type'), SPACE, $cmbMedia]);
    $controls->addItem([_('Period'), SPACE, new CComboBox('period', $period, 'submit()', ['daily' => _('Daily'), 'weekly' => _('Weekly'), 'monthly' => _('Monthly'), 'yearly' => _('Yearly')])]);
    if ($period != 'yearly') {
        $cmbYear = new CComboBox('year', $year, 'submit();');
        for ($y = $minYear; $y <= date('Y'); $y++) {
            $cmbYear->addItem($y, $y);
/**
 * Create CDiv with host/template information and references to it's elements
 *
 * @param string $currentElement
 * @param int $hostid
 * @param int $discoveryid
 *
 * @return object
 */
function get_header_host_table($currentElement, $hostid, $discoveryid = null)
{
    $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries');
    if (!empty($discoveryid)) {
        unset($elements['applications'], $elements['screens'], $elements['discoveries']);
    }
    $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true);
    if (isset($elements['items'])) {
        $options['selectItems'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['triggers'])) {
        $options['selectTriggers'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['graphs'])) {
        $options['selectGraphs'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['applications'])) {
        $options['selectApplications'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['screens'])) {
        $options['selectScreens'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['discoveries'])) {
        $options['selectDiscoveries'] = API_OUTPUT_COUNT;
    }
    // get hosts
    $dbHost = API::Host()->get($options);
    $dbHost = reset($dbHost);
    // get discoveries
    if (!empty($discoveryid)) {
        $options['itemids'] = $discoveryid;
        $options['output'] = array('name');
        unset($options['hostids'], $options['templated_hosts']);
        $dbDiscovery = API::DiscoveryRule()->get($options);
        $dbDiscovery = reset($dbDiscovery);
    }
    /*
     * Back
     */
    $list = new CList(null, 'objectlist');
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array('&laquo; ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid'))));
    } else {
        $list->addItem(array('&laquo; ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
    }
    /*
     * Name
     */
    $description = '';
    if ($dbHost['proxy_hostid']) {
        $proxy = get_host_by_hostid($dbHost['proxy_hostid']);
        $description .= $proxy['host'] . ': ';
    }
    $description .= $dbHost['name'];
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array(bold(_('Template') . ': '), new CLink($description, 'templates.php?form=update&templateid=' . $dbHost['hostid'])));
    } else {
        switch ($dbHost['status']) {
            case HOST_STATUS_MONITORED:
                $status = new CSpan(_('Monitored'), 'off');
                break;
            case HOST_STATUS_NOT_MONITORED:
                $status = new CSpan(_('Not monitored'), 'on');
                break;
            default:
                $status = _('Unknown');
                break;
        }
        $list->addItem(array(bold(_('Host') . ': '), new CLink($description, 'hosts.php?form=update&hostid=' . $dbHost['hostid'])));
        $list->addItem($status);
        $list->addItem(getAvailabilityTable($dbHost));
    }
    if (!empty($dbDiscovery)) {
        $list->addItem(array('&laquo; ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
        $list->addItem(array(bold(_('Discovery') . ': '), new CLink($dbDiscovery['name'], 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid'])));
    }
    /*
     * Rowcount
     */
    if (isset($elements['applications'])) {
        if ($currentElement == 'applications') {
            $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')'));
        }
    }
    if (isset($elements['items'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'items') {
                $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')'));
            }
        } else {
            if ($currentElement == 'items') {
                $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')'));
            }
        }
    }
    if (isset($elements['triggers'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')'));
            }
        } else {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')'));
            }
        }
    }
    if (isset($elements['graphs'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')'));
            }
        } else {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')'));
            }
        }
    }
    if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) {
        if ($currentElement == 'screens') {
            $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')'));
        }
    }
    if (isset($elements['discoveries'])) {
        if ($currentElement == 'discoveries') {
            $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')'));
        }
    }
    return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all');
}
Exemple #17
0
        foreach ($_POST["FIELDS"] as $ID => $tmp) {
            $arField = array("SORT" => $_POST["FIELDS"][$ID]["SORT"], "NAME" => $_POST["FIELDS"][$ID]["NAME"], "IS_REQUIRED" => $_POST["FIELDS"][$ID]["IS_REQUIRED"], "MULTIPLE" => $_POST["FIELDS"][$ID]["MULTIPLE"]);
            $obList->UpdateField($ID, $arField);
        }
        //Clear components cache
        $CACHE_MANAGER->ClearByTag("lists_list_" . $arResult["IBLOCK_ID"]);
    }
    if (!isset($_POST["AJAX_CALL"])) {
        LocalRedirect($arResult["LIST_FIELDS_URL"]);
    }
}
global $CACHE_MANAGER;
if ($this->StartResultCache(false)) {
    $CACHE_MANAGER->StartTagCache($this->GetCachePath());
    $CACHE_MANAGER->RegisterTag("lists_list_" . $arIBlock["ID"]);
    $obList = new CList($arIBlock["ID"]);
    $arResult["TYPES"] = $obList->GetAllTypes();
    $arFields = $obList->GetFields();
    $arResult["ROWS"] = array();
    foreach ($arFields as $ID => $arField) {
        $data = array();
        foreach ($arField as $key => $value) {
            $data["~" . $key] = $value;
            if (is_array($value)) {
                foreach ($value as $key1 => $value1) {
                    if (!is_array($value1)) {
                        $value[$key1] = htmlspecialcharsbx($value1);
                    }
                }
                $data[$key] = $value;
            } else {
Exemple #18
0
}
$arResult["~LISTS_URL"] = str_replace(array("#group_id#"), array($arParams["SOCNET_GROUP_ID"]), $arParams["~LISTS_URL"]);
$arResult["LISTS_URL"] = htmlspecialcharsbx($arResult["~LISTS_URL"]);
$arResult["~LIST_EDIT_URL"] = str_replace(array("#list_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_EDIT_URL"]);
$arResult["LIST_EDIT_URL"] = htmlspecialcharsbx($arResult["~LIST_EDIT_URL"]);
$arResult["~LIST_URL"] = str_replace(array("#list_id#", "#section_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["SECTION_ID"]), $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_URL"]);
$arResult["LIST_URL"] = htmlspecialcharsbx($arResult["~LIST_URL"]);
$arResult["~LIST_SECTION_URL"] = str_replace(array("#list_id#", "#section_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["SECTION_ID"]), $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_SECTIONS_URL"]);
$arResult["LIST_SECTION_URL"] = htmlspecialcharsbx($arResult["~LIST_SECTION_URL"]);
$arResult["~LIST_PARENT_URL"] = str_replace(array("#list_id#", "#section_id#", "#group_id#"), array($arResult["IBLOCK_ID"], intval($arResult["PARENT_SECTION_ID"]), $arParams["SOCNET_GROUP_ID"]), $arParams["~LIST_URL"]);
$arResult["LIST_PARENT_URL"] = htmlspecialcharsbx($arResult["~LIST_PARENT_URL"]);
$arResult["~BIZPROC_WORKFLOW_ADMIN_URL"] = str_replace(array("#list_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~BIZPROC_WORKFLOW_ADMIN_URL"]);
$arResult["BIZPROC_WORKFLOW_ADMIN_URL"] = htmlspecialcharsbx($arResult["~BIZPROC_WORKFLOW_ADMIN_URL"]);
$arResult["~EXPORT_EXCEL_URL"] = str_replace(array("#list_id#", "#group_id#"), array($arResult["IBLOCK_ID"], $arParams["SOCNET_GROUP_ID"]), $arParams["~EXPORT_EXCEL_URL"]);
$arResult["EXPORT_EXCEL_URL"] = htmlspecialcharsbx($arResult["~EXPORT_EXCEL_URL"]);
$obList = new CList($arIBlock["ID"]);
$strError = "";
$errorID = $arResult["GRID_ID"] . "_error";
//Form submitted
if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid() && isset($_POST["action_button_" . $arResult["GRID_ID"]])) {
    $obSection = new CIBlockSection();
    $obElement = new CIBlockElement();
    /*Build filter*/
    $arFilter = array("IBLOCK_ID" => $arIBlock["ID"], "CHECK_PERMISSIONS" => $arParams["CAN_EDIT"] || $arParams["SOCNET_GROUP_ID"] ? "N" : "Y");
    if ($_POST["action_all_rows_" . $arResult["GRID_ID"]] == "Y") {
        if (!$arResult["ANY_SECTION"]) {
            $arFilter["SECTION_ID"] = $arResult["SECTION_ID"];
        }
    } else {
        $arFilter["=ID"] = $_POST["ID"];
    }
Exemple #19
0
 function getList()
 {
     $list = new CList();
     foreach ($this->stage as $id => $data) {
         if ($id < $this->getStep()) {
             $style = 'completed';
         } else {
             if ($id == $this->getStep()) {
                 $style = 'current';
             } else {
                 $style = null;
             }
         }
         $list->addItem($data['title'], $style);
     }
     return $list;
 }
 public function testOffsetUnset()
 {
     $list = new CList(array(1, 2, 3));
     $list->offsetUnset(1);
     $this->assertEquals(array(1, 3), $list->toArray());
 }
/**
 * Creates nodes that can be used to display the SLA report tree using the CTree class.
 *
 * @see CTree
 *
 * @param array $services       an array of services to display in the tree
 * @param array $slaData        sla report data, see CService::getSla()
 * @param $period
 * @param array $parentService
 * @param array $service
 * @param array $dependency
 * @param array $tree
 */
function createServiceMonitoringTree(array $services, array $slaData, $period, &$tree, array $parentService = array(), array $service = array(), array $dependency = array())
{
    // if no parent service is given, start from the root
    if (!$service) {
        $serviceNode = array('id' => 0, 'parentid' => 0, 'caption' => _('root'), 'status' => SPACE, 'sla' => SPACE, 'sla2' => SPACE, 'trigger' => array(), 'reason' => SPACE, 'graph' => SPACE);
        $service = $serviceNode;
        $service['serviceid'] = 0;
        $service['dependencies'] = array();
        $service['trigger'] = array();
        // add all top level services as children of "root"
        foreach ($services as $topService) {
            if (!$topService['parent']) {
                $service['dependencies'][] = array('servicedownid' => $topService['serviceid'], 'soft' => 0, 'linkid' => 0);
            }
        }
        $tree = array($serviceNode);
    } else {
        $serviceSla = $slaData[$service['serviceid']];
        $slaValues = reset($serviceSla['sla']);
        // caption
        // remember the selected time period when following the bar link
        $periods = array('today' => 'daily', 'week' => 'weekly', 'month' => 'monthly', 'year' => 'yearly', 24 => 'daily', 24 * 7 => 'weekly', 24 * 30 => 'monthly', 24 * DAY_IN_YEAR => 'yearly');
        $caption = array(new CLink(array(get_node_name_by_elid($service['serviceid'], null, ': '), $service['name']), 'report3.php?serviceid=' . $service['serviceid'] . '&year=' . date('Y') . '&period=' . $periods[$period]));
        $trigger = $service['trigger'];
        if ($trigger) {
            $url = new CLink($trigger['description'], 'events.php?source=' . EVENT_SOURCE_TRIGGERS . '&triggerid=' . $trigger['triggerid']);
            $caption[] = ' - ';
            $caption[] = $url;
        }
        // reason
        $problemList = '-';
        if ($serviceSla['problems']) {
            $problemList = new CList(null, 'service-problems');
            foreach ($serviceSla['problems'] as $problemTrigger) {
                $problemList->addItem(new CLink($problemTrigger['description'], 'events.php?source=' . EVENT_SOURCE_TRIGGERS . '&triggerid=' . $problemTrigger['triggerid']));
            }
        }
        // sla
        $sla = '-';
        $sla2 = '-';
        if ($service['showsla'] && $slaValues['sla'] !== null) {
            $slaGood = $slaValues['sla'];
            $slaBad = 100 - $slaValues['sla'];
            $p = min($slaBad, 20);
            $width = 160;
            $widthRed = $width * $p / 20;
            $widthGreen = $width - $widthRed;
            $chart1 = null;
            if ($widthGreen > 0) {
                $chart1 = new CDiv(null, 'sla-bar-part sla-green');
                $chart1->setAttribute('style', 'width: ' . $widthGreen . 'px;');
            }
            $chart2 = null;
            if ($widthRed > 0) {
                $chart2 = new CDiv(null, 'sla-bar-part sla-red');
                $chart2->setAttribute('style', 'width: ' . $widthRed . 'px;');
            }
            $bar = new CLink(array($chart1, $chart2, new CDiv('80%', 'sla-bar-legend sla-bar-legend-start'), new CDiv('100%', 'sla-bar-legend sla-bar-legend-end')), 'srv_status.php?serviceid=' . $service['serviceid'] . '&showgraph=1' . url_param('path'));
            $bar = new CDiv($bar, 'sla-bar');
            $bar->setAttribute('title', _s('Only the last 20%% of the indicator is displayed.'));
            $slaBar = array($bar, new CSpan(sprintf('%.4f', $slaBad), 'sla-value ' . ($service['goodsla'] > $slaGood ? 'red' : 'green')));
            $sla = new CDiv($slaBar, 'invisible');
            $sla2 = array(new CSpan(sprintf('%.4f', $slaGood), 'sla-value ' . ($service['goodsla'] > $slaGood ? 'red' : 'green')), '/', new CSpan(sprintf('%.4f', $service['goodsla']), 'sla-value'));
        }
        $serviceNode = array('id' => $service['serviceid'], 'caption' => $caption, 'description' => $service['trigger'] ? $service['trigger']['description'] : _('None'), 'reason' => $problemList, 'sla' => $sla, 'sla2' => $sla2, 'parentid' => $parentService ? $parentService['serviceid'] : 0, 'status' => $serviceSla['status'] !== null ? $serviceSla['status'] : '-');
    }
    // hard dependencies and dependencies for the "root" node
    if (!$dependency || $dependency['soft'] == 0) {
        $tree[$serviceNode['id']] = $serviceNode;
        foreach ($service['dependencies'] as $dependency) {
            $childService = $services[$dependency['servicedownid']];
            createServiceMonitoringTree($services, $slaData, $period, $tree, $service, $childService, $dependency);
        }
    } else {
        $serviceNode['caption'] = new CSpan($serviceNode['caption'], 'service-caption-soft');
        $tree[$serviceNode['id'] . '.' . $dependency['linkid']] = $serviceNode;
    }
}
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
$this->addJSfile('js/class.pmaster.js');
$dashboard = (new CWidget())->setTitle(_('Dashboard'))->setControls((new CForm())->cleanItems()->addItem((new CList())->addItem(get_icon('dashconf', ['enabled' => $data['filter_enabled']]))->addItem(get_icon('fullscreen', ['fullscreen' => $data['fullscreen']]))));
/*
 * Dashboard grid
 */
$dashboardGrid = [[], [], []];
$widgetRefreshParams = [];
$widgets = [WIDGET_FAVOURITE_GRAPHS => ['id' => 'favouriteGraphs', 'menu_popup' => ['CMenuPopupHelper', 'getFavouriteGraphs'], 'data' => $data['favourite_graphs'], 'header' => _('Favourite graphs'), 'links' => [['name' => _('Graphs'), 'url' => 'charts.php']], 'defaults' => ['col' => 0, 'row' => 0]], WIDGET_FAVOURITE_SCREENS => ['id' => 'favouriteScreens', 'menu_popup' => ['CMenuPopupHelper', 'getFavouriteScreens'], 'data' => $data['favourite_screens'], 'header' => _('Favourite screens'), 'links' => [['name' => _('Screens'), 'url' => 'screens.php'], ['name' => _('Slide shows'), 'url' => 'slides.php']], 'defaults' => ['col' => 0, 'row' => 1]], WIDGET_FAVOURITE_MAPS => ['id' => 'favouriteMaps', 'menu_popup' => ['CMenuPopupHelper', 'getFavouriteMaps'], 'data' => $data['favourite_maps'], 'header' => _('Favourite maps'), 'links' => [['name' => _('Maps'), 'url' => 'zabbix.php?action=map.view']], 'defaults' => ['col' => 0, 'row' => 2]]];
foreach ($widgets as $widgetid => $widget) {
    $icon = (new CButton(null))->addClass(ZBX_STYLE_BTN_WIDGET_ACTION)->setTitle(_('Action'))->setId($widget['id'])->setMenuPopup(call_user_func($widget['menu_popup']));
    $footer = new CList();
    foreach ($widget['links'] as $link) {
        $footer->addItem(new CLink($link['name'], $link['url']));
    }
    $col = CProfile::get('web.dashboard.widget.' . $widgetid . '.col', $widget['defaults']['col']);
    $row = CProfile::get('web.dashboard.widget.' . $widgetid . '.row', $widget['defaults']['row']);
    $dashboardGrid[$col][$row] = (new CCollapsibleUiWidget($widgetid, $widget['data']))->setExpanded((bool) CProfile::get('web.dashboard.widget.' . $widgetid . '.state', true))->setHeader($widget['header'], [$icon], true, 'zabbix.php?action=dashboard.widget')->setFooter($footer);
}
$widgets = [WIDGET_SYSTEM_STATUS => ['action' => 'widget.system.view', 'header' => _('System status'), 'defaults' => ['col' => 1, 'row' => 1]], WIDGET_HOST_STATUS => ['action' => 'widget.hosts.view', 'header' => _('Host status'), 'defaults' => ['col' => 1, 'row' => 2]], WIDGET_LAST_ISSUES => ['action' => 'widget.issues.view', 'header' => _n('Last %1$d issue', 'Last %1$d issues', DEFAULT_LATEST_ISSUES_CNT), 'defaults' => ['col' => 1, 'row' => 3]], WIDGET_WEB_OVERVIEW => ['action' => 'widget.web.view', 'header' => _('Web monitoring'), 'defaults' => ['col' => 1, 'row' => 4]]];
if ($data['show_status_widget']) {
    $widgets[WIDGET_ZABBIX_STATUS] = ['action' => 'widget.status.view', 'header' => _('Status of Zabbix'), 'defaults' => ['col' => 1, 'row' => 0]];
}
if ($data['show_discovery_widget']) {
    $widgets[WIDGET_DISCOVERY_STATUS] = ['action' => 'widget.discovery.view', 'header' => _('Discovery status'), 'defaults' => ['col' => 1, 'row' => 5]];
}
foreach ($widgets as $widgetid => $widget) {
Exemple #23
0
 /**
  * @param array attributes key for get.
  * @return array
  */
 public function getEavAttributes($attributes = array())
 {
     // Get all attributes if not specified.
     if (empty($attributes)) {
         $attributes = $this->getSafeAttributesArray();
     }
     // Values array.
     $values = array();
     // Queue for load.
     $loadQueue = new CList();
     foreach ($attributes as $attribute) {
         // Check is safe.
         if ($this->hasSafeAttribute($attribute)) {
             $values[$attribute] = $this->attributes->itemAt($attribute);
             // If attribute not set and not load, prepare array for loaded.
             if (!$this->preload && $values[$attribute] === NULL) {
                 $loadQueue->add($attribute);
             }
         }
     }
     // If array for loaded not empty, load attributes.
     if (!$this->preload && $loadQueue->count() > 0) {
         $this->loadEavAttributes($loadQueue->toArray());
         foreach ($loadQueue as $attribute) {
             $values[$attribute] = $this->attributes->itemAt($attribute);
         }
     }
     // Delete load queue.
     unset($loadQueue);
     // Return values.
     return $values;
 }
Exemple #24
0
 protected function getListData()
 {
     $list = new CList($this->iblockId);
     $this->lists['FIELDS'] = $list->getFields();
     $this->lists['SELECT'] = array('ID', 'IBLOCK_ID', 'NAME', 'IBLOCK_SECTION_ID', 'CREATED_BY', 'BP_PUBLISHED');
     $this->lists['DATA'] = array();
     $this->lists['DATA']['NAME'] = Loc::getMessage('LISTS_SEAC_FIELD_NAME_DEFAULT');
     $this->lists['DATA']['IBLOCK_SECTION_ID'] = '';
     foreach ($this->lists['FIELDS'] as $fieldId => $field) {
         $this->lists['FIELDS'][$fieldId]['NAME'] = htmlspecialcharsbx($this->lists['FIELDS'][$fieldId]['NAME']);
         if ($list->is_field($fieldId)) {
             if ($fieldId == 'ACTIVE_FROM' || $fieldId == 'PREVIEW_PICTURE' || $fieldId == 'DETAIL_PICTURE') {
                 if ($field['DEFAULT_VALUE'] === '=now') {
                     $this->lists['DATA'][$fieldId] = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL');
                 } elseif ($field['DEFAULT_VALUE'] === '=today') {
                     $this->lists['DATA'][$fieldId] = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT');
                 } else {
                     $this->lists['DATA'][$fieldId] = '';
                 }
             } else {
                 $this->lists['DATA'][$fieldId] = $field['DEFAULT_VALUE'];
             }
             $this->lists['SELECT'][] = $fieldId;
         } elseif (is_array($field['PROPERTY_USER_TYPE']) && array_key_exists('GetPublicEditHTML', $field['PROPERTY_USER_TYPE'])) {
             $this->lists['DATA'][$fieldId] = array('n0' => array('VALUE' => $field['DEFAULT_VALUE'], 'DESCRIPTION' => ''));
         } elseif ($field['PROPERTY_TYPE'] == 'L') {
             $this->lists['DATA'][$fieldId] = array();
             $propEnums = CIBlockProperty::getPropertyEnum($field['ID']);
             while ($enum = $propEnums->fetch()) {
                 if ($enum['DEF'] == 'Y') {
                     $this->lists['DATA'][$fieldId][] = $enum['ID'];
                 }
             }
         } elseif ($field['PROPERTY_TYPE'] == 'F') {
             $this->lists['DATA'][$fieldId] = array('n0' => array('VALUE' => $field['DEFAULT_VALUE'], 'DESCRIPTION' => ''));
         } elseif ($field['PROPERTY_TYPE'] == 'G' || $field['PROPERTY_TYPE'] == 'E') {
             $this->lists['DATA'][$fieldId] = array($field['DEFAULT_VALUE']);
         } else {
             $this->lists['DATA'][$fieldId] = array('n0' => array('VALUE' => $field['DEFAULT_VALUE'], 'DESCRIPTION' => ''));
             if ($field['MULTIPLE'] == 'Y') {
                 if (is_array($field['DEFAULT_VALUE']) || strlen($field['DEFAULT_VALUE'])) {
                     $this->lists['DATA'][$fieldId]['n1'] = array('VALUE' => '', 'DESCRIPTION' => '');
                 }
             }
         }
         if ($fieldId == 'CREATED_BY') {
             $this->lists['SELECT'][] = 'CREATED_USER_NAME';
         }
         if ($fieldId == 'MODIFIED_BY') {
             $this->lists['SELECT'][] = 'USER_NAME';
         }
     }
 }
Exemple #25
0
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $message = array();
    $width = 0;
    $height = 0;
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2));
                $width = max($width, imagefontwidth(2) * zbx_strlen($msg) + 1);
                $height += imagefontheight(2) + 1;
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            $msg_font = 2;
            foreach ($ZBX_MESSAGES as $msg) {
                if ($msg['type'] == 'error') {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font));
                } else {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font));
                }
                $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1);
                $height += imagefontheight($msg_font) + 1;
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' != zbx_strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) {
        $width += 2;
        $height += 2;
        $canvas = imagecreate($width, $height);
        imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255));
        foreach ($message as $id => $msg) {
            $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0);
            $message[$id]['h'] = imagefontheight($msg['font']);
            imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']));
            $previd = $id;
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
Exemple #26
0
 public function AddDocumentField($documentType, $fields)
 {
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     if (substr($fields["code"], 0, strlen("PROPERTY_")) == "PROPERTY_") {
         $fields["code"] = substr($fields["code"], strlen("PROPERTY_"));
     }
     $fieldsTemporary = array("NAME" => $fields["name"], "ACTIVE" => "Y", "SORT" => $fields["sort"] ? $fields["sort"] : 900, "CODE" => $fields["code"], 'MULTIPLE' => $fields['multiple'] == 'Y' || (string) $fields['multiple'] === '1' ? 'Y' : 'N', 'IS_REQUIRED' => $fields['required'] == 'Y' || (string) $fields['required'] === '1' ? 'Y' : 'N', "IBLOCK_ID" => $iblockId, "FILTRABLE" => "Y", "SETTINGS" => $fields["settings"] ? $fields["settings"] : array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM" => 'Y'), "DEFAULT_VALUE" => $fields['DefaultValue']);
     if (strpos("0123456789", substr($fieldsTemporary["CODE"], 0, 1)) !== false) {
         $fieldsTemporary["CODE"] = self::generateMnemonicCode($fieldsTemporary["CODE"]);
     }
     if (array_key_exists("additional_type_info", $fields)) {
         $fieldsTemporary["LINK_IBLOCK_ID"] = intval($fields["additional_type_info"]);
     }
     if (strstr($fields["type"], ":") !== false) {
         list($fieldsTemporary["TYPE"], $fieldsTemporary["USER_TYPE"]) = explode(":", $fields["type"], 2);
         if ($fields["type"] == "E:EList") {
             $fieldsTemporary["LINK_IBLOCK_ID"] = $fields["options"];
         }
     } elseif ($fields["type"] == "user") {
         $fieldsTemporary["TYPE"] = "S:employee";
         $fieldsTemporary["USER_TYPE"] = "UserID";
     } elseif ($fields["type"] == "date") {
         $fieldsTemporary["TYPE"] = "S:Date";
         $fieldsTemporary["USER_TYPE"] = "Date";
     } elseif ($fields["type"] == "datetime") {
         $fieldsTemporary["TYPE"] = "S:DateTime";
         $fieldsTemporary["USER_TYPE"] = "DateTime";
     } elseif ($fields["type"] == "file") {
         $fieldsTemporary["TYPE"] = "F";
         $fieldsTemporary["USER_TYPE"] = "";
     } elseif ($fields["type"] == "select") {
         $fieldsTemporary["TYPE"] = "L";
         $fieldsTemporary["USER_TYPE"] = false;
         if (is_array($fields["options"])) {
             $i = 10;
             foreach ($fields["options"] as $k => $v) {
                 $def = "N";
                 if ($fields['DefaultValue'] == $v) {
                     $def = "Y";
                 }
                 $fieldsTemporary["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => $def, "SORT" => $i);
                 $i = $i + 10;
             }
         } elseif (is_string($fields["options"]) && strlen($fields["options"]) > 0) {
             $a = explode("\n", $fields["options"]);
             $i = 10;
             foreach ($a as $v) {
                 $v = trim(trim($v), "\r\n");
                 if (!$v) {
                     continue;
                 }
                 $v1 = $v2 = $v;
                 if (substr($v, 0, 1) == "[" && strpos($v, "]") !== false) {
                     $v1 = substr($v, 1, strpos($v, "]") - 1);
                     $v2 = trim(substr($v, strpos($v, "]") + 1));
                 }
                 $def = "N";
                 if ($fields['DefaultValue'] == $v2) {
                     $def = "Y";
                 }
                 $fieldsTemporary["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => $def, "SORT" => $i);
                 $i = $i + 10;
             }
         }
     } elseif ($fields["type"] == "string") {
         $fieldsTemporary["TYPE"] = "S";
         if ($fields["row_count"] && $fields["col_count"]) {
             $fieldsTemporary["ROW_COUNT"] = $fields["row_count"];
             $fieldsTemporary["COL_COUNT"] = $fields["col_count"];
         } else {
             $fieldsTemporary["ROW_COUNT"] = 1;
             $fieldsTemporary["COL_COUNT"] = 30;
         }
     } elseif ($fields["type"] == "text") {
         $fieldsTemporary["TYPE"] = "S";
         if ($fields["row_count"] && $fields["col_count"]) {
             $fieldsTemporary["ROW_COUNT"] = $fields["row_count"];
             $fieldsTemporary["COL_COUNT"] = $fields["col_count"];
         } else {
             $fieldsTemporary["ROW_COUNT"] = 4;
             $fieldsTemporary["COL_COUNT"] = 30;
         }
     } elseif ($fields["type"] == "int" || $fields["type"] == "double") {
         $fieldsTemporary["TYPE"] = "N";
     } elseif ($fields["type"] == "bool") {
         $fieldsTemporary["TYPE"] = "L";
         $fieldsTemporary["VALUES"][] = array("XML_ID" => 'yes', "VALUE" => GetMessage("BPVDX_YES"), "DEF" => "N", "SORT" => 10);
         $fieldsTemporary["VALUES"][] = array("XML_ID" => 'no', "VALUE" => GetMessage("BPVDX_NO"), "DEF" => "N", "SORT" => 20);
     } else {
         $fieldsTemporary["TYPE"] = $fields["type"];
         $fieldsTemporary["USER_TYPE"] = false;
     }
     $idField = false;
     $properties = CIBlockProperty::getList(array(), array("IBLOCK_ID" => $fieldsTemporary["IBLOCK_ID"], "CODE" => $fieldsTemporary["CODE"]));
     if (!$properties->fetch()) {
         $listObject = new CList($iblockId);
         $idField = $listObject->addField($fieldsTemporary);
     }
     if ($idField) {
         global $CACHE_MANAGER;
         $CACHE_MANAGER->clearByTag("lists_list_" . $iblockId);
         return $idField;
     }
     return false;
 }
Exemple #27
0
function make_favorite_maps()
{
    $favList = new CList(null, 'favorites', _('No maps added.'));
    $fav_sysmaps = CFavorite::get('web.favorite.sysmapids');
    if (!$fav_sysmaps) {
        return $favList;
    }
    $sysmapids = array();
    foreach ($fav_sysmaps as $favorite) {
        $sysmapids[$favorite['value']] = $favorite['value'];
    }
    $sysmaps = API::Map()->get(array('sysmapids' => $sysmapids, 'output' => array('sysmapid', 'name')));
    foreach ($sysmaps as $sysmap) {
        $sysmapid = $sysmap['sysmapid'];
        $link = new CLink(get_node_name_by_elid($sysmapid, null, NAME_DELIMITER) . $sysmap['name'], 'maps.php?sysmapid=' . $sysmapid);
        $link->setTarget('blank');
        $favList->addItem($link, 'nowrap');
    }
    return $favList;
}
Exemple #28
0
 /**
  * Creates a UL horizontal list with spaces between elements.
  *
  * @param array $values			an array of items to add to the list
  */
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this->addClass(ZBX_STYLE_HOR_LIST);
 }
 public static function Add($iblock_id, $arFields)
 {
     if ($iblock_id > 0) {
         $property_id = intval($arFields["ID"]);
         if ($property_id > 0) {
             return new CListPropertyField($iblock_id, "PROPERTY_" . $property_id, $arFields["NAME"], $arFields["SORT"]);
         } else {
             $arFields["IBLOCK_ID"] = $iblock_id;
             if (strpos($arFields["TYPE"], ":") !== false) {
                 list($arFields["PROPERTY_TYPE"], $arFields["USER_TYPE"]) = explode(":", $arFields["TYPE"]);
             } else {
                 $arFields["PROPERTY_TYPE"] = $arFields["TYPE"];
             }
             $arFields["MULTIPLE_CNT"] = 1;
             $arFields["CHECK_PERMISSIONS"] = "N";
             $obProperty = new CIBlockProperty();
             $res = $obProperty->Add($arFields);
             if ($res) {
                 if ($arFields["PROPERTY_TYPE"] == "L" && is_array($arFields["LIST"])) {
                     CList::UpdatePropertyList($res, $arFields["LIST"]);
                 }
                 return new CListPropertyField($iblock_id, "PROPERTY_" . $res, $arFields["NAME"], $arFields["SORT"]);
             }
         }
     }
     return null;
 }
Exemple #30
-1
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $imageMessages = array();
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                // save all of the messages in an array to display them later in an image
                $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68));
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            foreach ($ZBX_MESSAGES as $msg) {
                // save all of the messages in an array to display them later in an image
                if ($msg['type'] == 'error') {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55));
                } else {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55));
                }
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' !== strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    // draw an image with the messages
    if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) {
        $imageFontSize = 8;
        // calculate the size of the text
        $imageWidth = 0;
        $imageHeight = 0;
        foreach ($imageMessages as &$msg) {
            $size = imageTextSize($imageFontSize, 0, $msg['text']);
            $msg['height'] = $size['height'] - $size['baseline'];
            // calculate the total size of the image
            $imageWidth = max($imageWidth, $size['width']);
            $imageHeight += $size['height'] + 1;
        }
        unset($msg);
        // additional padding
        $imageWidth += 2;
        $imageHeight += 2;
        // create the image
        $canvas = imagecreate($imageWidth, $imageHeight);
        imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255));
        // draw each message
        $y = 1;
        foreach ($imageMessages as $msg) {
            $y += $msg['height'];
            imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']);
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}