text:
{{--

The MIT License (MIT)

SMARTGoalz - SMART Goals made easier

http://smartgoalz.github.io

Copyright (c) 2015 Prashant Shah <pshah.smartgoalz@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

--}}

@extends('layouts.master')

@section('head')

@stop

@section('breadcrumb-title', 'Journals')

@section('page-title', 'Journal Entry')

@section('content')

	{{ $journal->title }}

{{ date_format(date_create_from_format('Y-m-d H:i:s', $journal->date), $dateformat_php . ' h:i A') }}

        {{ $journal->entry }}

        {{ HTML::linkAction('JournalsController@getEdit', 'Edit', array($journal->id),
                array('class' => 'btn btn-primary')) }}

        {{ HTML::linkAction('JournalsController@getIndex', 'Back', array(),
                array('class' => 'btn btn-info')) }}

@stop


text:
require "fileutils"

module Eastrails
  module Components
    class Devise < Base
      def add
        unless gems.include?("devise")
          gem 'devise'
          system 'bundle install'
          system 'rails g devise:install'
          system 'rails g devise User'
        end

        if File.directory?("spec")
          FileUtils.mkdir_p("spec/support")
          create_file 'spec/support/devise.rb' do
            <<-RUBY
RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end
            RUBY
          end
        end

        unless File.directory?("app/views/devise")
          directory "devise", "app/views/devise"

          if gems.include?("haml") || gems.include?("haml-rails")
            dir_html_to_haml("app/views/devise")
          end
        end

        erb_navigation_content = File.read(
          File.expand_path(find_in_source_paths("navigation/devise.html.erb")))
        if File.exists?("app/views/layouts/_navigation.html.erb")
          append_file("app/views/layouts/_navigation.html.erb") do
            erb_navigation_content
          end
        elsif File.exists?("app/views/layouts/_navigation.html.haml")
          append_file("app/views/layouts/_navigation.html.haml") do
            html_to_haml(erb_navigation_content)
          end
        end
      end
    end
  end
end

redpajama_set_name: RedPajamaGithub


text:
package com.fb.audiencenetwork.scrollapp;

import android.app.Activity;
import android.content.Context;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class NasaRequester {

  public interface NasaResponse {
    void receivedPost(NasaPost post);
  }

  private Calendar mCalendar;
  private SimpleDateFormat mDateFormat;
  private NasaResponse mResponseListener;
  private Context mContext;
  private OkHttpClient mClient;
  private static final String BASE_URL = "https://api.nasa.gov/planetary/apod?";
  private static final String DATE_PARAMETER = "date=";
  private static final String API_KEY_PARAMETER = "&api_key=";
  private static final String MEDIA_TYPE_KEY = "media_type";
  private static final String MEDIA_TYPE_VIDEO_VALUE = "video";
  private boolean mLoadingData;

  public boolean isLoadingData() {
    return mLoadingData;
  }

  public NasaRequester(Activity activity) {
    mCalendar = Calendar.getInstance();
    mDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    mResponseListener = (NasaResponse) activity;
    mContext = activity.getApplicationContext();
    mClient = new OkHttpClient();
    mLoadingData = false;
  }

  public void getPost() throws IOException {
    String date = mDateFormat.format(mCalendar.getTime());
    String urlRequest = BASE_URL + DATE_PARAMETER + date + API_KEY_PARAMETER + mContext.getString(R.string.api_key);
    Request request = new Request.Builder().url(urlRequest).build();
    mLoadingData = true;

    mClient.newCall(request).enqueue(new Callback() {
      @Override
      public void onFailure(Call call, IOException e) {
        mLoadingData = false;
        e.printStackTrace();
      }

      @Override
      public void onResponse(Call call, Response response) throws IOException {
        try {
          JSONObject photoJSON = new JSONObject(response.body().string());
          mCalendar.add(Calendar.DAY_OF_YEAR, -1);
          if (!photoJSON.getString(MEDIA_TYPE_KEY).equals(MEDIA_TYPE_VIDEO_VALUE)) {
            NasaPost post = new NasaPost(photoJSON);
            mResponseListener.receivedPost(post);
            mLoadingData = false;
          } else {
            getPost();
          }
        } catch (JSONException e) {
          mLoadingData = false;
          e.printStackTrace();
        }
      }
    });
  }
}


text:
<?php

/**
 * Convert windows events type constant in to the string representation
 *
 * @param int $logtype
 * @return string
 */
function get_item_logtype_description($logtype) {
	switch ($logtype) {
		case ITEM_LOGTYPE_INFORMATION:
			return _('Information');
		case ITEM_LOGTYPE_WARNING:
			return _('Warning');
		case ITEM_LOGTYPE_ERROR:
			return _('Error');
		case ITEM_LOGTYPE_FAILURE_AUDIT:
			return _('Failure Audit');
		case ITEM_LOGTYPE_SUCCESS_AUDIT:
			return _('Success Audit');
		case ITEM_LOGTYPE_CRITICAL:
			return _('Critical');
		case ITEM_LOGTYPE_VERBOSE:
			return _('Verbose');
		default:
			return _('Unknown');
	}
}

/**
 * Convert windows events type constant in to the CSS style name
 *
 * @param int $logtype
 * @return string
 */
function get_item_logtype_style($logtype) {
	switch ($logtype) {
		case ITEM_LOGTYPE_INFORMATION:
		case ITEM_LOGTYPE_SUCCESS_AUDIT:
		case ITEM_LOGTYPE_VERBOSE:
			return 'information';
		case ITEM_LOGTYPE_WARNING:
			return 'warning';
		case ITEM_LOGTYPE_ERROR:
		case ITEM_LOGTYPE_FAILURE_AUDIT:
			return 'high';
		case ITEM_LOGTYPE_CRITICAL:
			return 'disaster';
		default:
			return 'normal';
	}
}

/**
 * Get item type string name by item type number, or array of all item types if null passed
 *
 * @param int|null $type
 * @return array|string
 */
function item_type2str($type = null) {
	$types = array(
		ITEM_TYPE_ZABBIX => _('Zabbix agent'),
		ITEM_TYPE_ZABBIX_ACTIVE => _('Zabbix agent (active)'),
		ITEM_TYPE_SIMPLE => _('Simple check'),
		ITEM_TYPE_SNMPV1 => _('SNMPv1 agent'),
		ITEM_TYPE_SNMPV2C => _('SNMPv2 agent'),
		ITEM_TYPE_SNMPV3 => _('SNMPv3 agent'),
		ITEM_TYPE_SNMPTRAP => _('SNMP trap'),
		ITEM_TYPE_INTERNAL => _('Zabbix internal'),
		ITEM_TYPE_TRAPPER => _('Zabbix trapper'),
		ITEM_TYPE_AGGREGATE => _('Zabbix aggregate'),
		ITEM_TYPE_EXTERNAL => _('External check'),
		ITEM_TYPE_DB_MONITOR => _('Database monitor'),
		ITEM_TYPE_IPMI => _('IPMI agent'),
		ITEM_TYPE_SSH => _('SSH agent'),
		ITEM_TYPE_TELNET => _('TELNET agent'),
		ITEM_TYPE_JMX => _('JMX agent'),
		ITEM_TYPE_CALCULATED => _('Calculated'),
		ITEM_TYPE_HTTPTEST => _('Web monitoring')
	);
	if (is_null($type)) {
		return $types;
	}
	elseif (isset($types[$type])) {
		return $types[$type];
	}
	else {
		return _('Unknown');
	}
}

/**
 * Returns human readable an item value type
 *
 * @param int $valueType
 *
 * @return string
 */
function itemValueTypeString($valueType) {
	switch ($valueType) {
		case ITEM_VALUE_TYPE_UINT64:
			return _('Numeric (unsigned)');
		case ITEM_VALUE_TYPE_FLOAT:
			return _('Numeric (float)');
		case ITEM_VALUE_TYPE_STR:
			return _('Character');
		case ITEM_VALUE_TYPE_LOG:
			return _('Log');
		case ITEM_VALUE_TYPE_TEXT:
			return _('Text');
	}
	return _('Unknown');
}

function item_data_type2str($type = null) {
	$types = array(
		ITEM_DATA_TYPE_BOOLEAN => _('Boolean'),
		ITEM_DATA_TYPE_OCTAL => _('Octal'),
		ITEM_DATA_TYPE_DECIMAL => _('Decimal'),
		ITEM_DATA_TYPE_HEXADECIMAL => _('Hexadecimal')
	);
	if (is_null($type)) {
		return $types;
	}
	elseif (isset($types[$type])) {
		return $types[$type];
	}
	else {
		return _('Unknown');
	}
}

function item_status2str($type = null) {
	$types = array(
		ITEM_STATUS_ACTIVE => _('Enabled'),
		ITEM_STATUS_DISABLED => _('Disabled')
	);
	if (is_null($type)) {
		return $types;
	}
	elseif (isset($types[$type])) {
		return $types[$type];
	}
	else {
		return _('Unknown');
	}
}

/**
 * Returns the names of supported item states.
 *
 * If the $state parameter is passed, returns the name of the specific state, otherwise - returns an array of all
 * supported states.
 *
 * @param string $state
 *
 * @return array|string
 */
function itemState($state = null) {
	$states = array(
		ITEM_STATE_NORMAL => _('Normal'),
		ITEM_STATE_NOTSUPPORTED => _('Not supported')
	);

	if ($state === null) {
		return $states;
	}
	elseif (isset($states[$state])) {
		return $states[$state];
	}
	else {
		return _('Unknown');
	}
}

/**
 * Returns the text indicating the items status and state. If the $state parameter is not given, only the status of
 * the item will be taken into account.
 *
 * @param int $status
 * @param int $state
 *
 * @return string
 */
function itemIndicator($status, $state = null) {
	if ($status == ITEM_STATUS_ACTIVE) {
		return ($state == ITEM_STATE_NOTSUPPORTED) ? _('Not supported') : _('Enabled');
	}
	elseif ($status == ITEM_STATUS_DISABLED) {
		return _('Disabled');
	}

	return _('Unknown');
}

/**
 * Returns the CSS class for the items status and state indicator. If the $state parameter is not given, only the status of
 * the item will be taken into account.
 *
 * @param int $status
 * @param int $state
 *
 * @return string
 */
function itemIndicatorStyle($status, $state = null) {
	if ($status == ITEM_STATUS_ACTIVE) {
		return ($state == ITEM_STATE_NOTSUPPORTED) ? 'unknown' : 'enabled';
	}
	elseif ($status == ITEM_STATUS_DISABLED) {
		return 'disabled';
	}

	return 'unknown';
}

/**
 * Orders items by both status and state. Items are sorted in the following order: enabled, disabled, not supported.
 *
 * Keep in sync with orderTriggersByStatus().
 *
 * @param array  $items
 * @param string $sortorder
 */
function orderItemsByStatus(array &$items, $sortorder = ZBX_SORT_UP) {
	$sort = array();

	foreach ($items as $key => $item) {
		if ($item['status'] == ITEM_STATUS_ACTIVE) {
			$statusOrder = ($item['state'] == ITEM_STATE_NOTSUPPORTED) ? 2 : 0;
		}
		elseif ($item['status'] == ITEM_STATUS_DISABLED) {
			$statusOrder = 1;
		}

		$sort[$key] = $statusOrder;
	}

	if ($sortorder == ZBX_SORT_UP) {
		asort($sort);
	}
	else {
		arsort($sort);
	}

	$sortedItems = array();
	foreach ($sort as $key => $val) {
		$sortedItems[$key] = $items[$key];
	}
	$items = $sortedItems;
}

/**
 * Returns the name of the given interface type. Items "status" and "state" properties must be defined.
 *
 * @param int $type
 *
 * @return null
 */
function interfaceType2str($type) {
	$interfaceGroupLabels = array(
		INTERFACE_TYPE_AGENT => _('Agent'),
		INTERFACE_TYPE_SNMP => _('SNMP'),
		INTERFACE_TYPE_JMX => _('JMX'),
		INTERFACE_TYPE_IPMI => _('IPMI'),
	);

	return isset($interfaceGroupLabels[$type]) ? $interfaceGroupLabels[$type] : null;
}

function itemTypeInterface($type = null) {
	$types = array(
		ITEM_TYPE_SNMPV1 => INTERFACE_TYPE_SNMP,
		ITEM_TYPE_SNMPV2C => INTERFACE_TYPE_SNMP,
		ITEM_TYPE_SNMPV3 => INTERFACE_TYPE_SNMP,
		ITEM_TYPE_SNMPTRAP => INTERFACE_TYPE_SNMP,
		ITEM_TYPE_IPMI => INTERFACE_TYPE_IPMI,
		ITEM_TYPE_ZABBIX => INTERFACE_TYPE_AGENT,
		ITEM_TYPE_SIMPLE => INTERFACE_TYPE_ANY,
		ITEM_TYPE_EXTERNAL => INTERFACE_TYPE_ANY,
		ITEM_TYPE_SSH => INTERFACE_TYPE_ANY,
		ITEM_TYPE_TELNET => INTERFACE_TYPE_ANY,
		ITEM_TYPE_JMX => INTERFACE_TYPE_JMX
	);
	if (is_null($type)) {
		return $types;
	}
	elseif (isset($types[$type])) {
		return $types[$type];
	}
	else {
		return false;
	}
}

function update_item_status($itemids, $status) {
	zbx_value2array($itemids);
	$result = true;

	$db_items = DBselect('SELECT i.* FROM items i WHERE '.dbConditionInt('i.itemid', $itemids));
	while ($item = DBfetch($db_items)) {
		$old_status = $item['status'];
		if ($status != $old_status) {
			$result &= DBexecute(
				'UPDATE items SET status='.zbx_dbstr($status).' WHERE itemid='.zbx_dbstr($item['itemid'])
			);
			if ($result) {
				$host = get_host_by_hostid($item['hostid']);
				$item_new = get_item_by_itemid($item['itemid']);
				add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, $item['itemid'], $host['host'].NAME_DELIMITER.$item['name'], 'items', $item, $item_new);
			}
		}
	}
	return $result;
}

function copyItemsToHosts($srcItemIds, $dstHostIds) {
	$srcItems = API::Item()->get(array(
		'itemids' => $srcItemIds,
		'output' => array(
			'type', 'snmp_community', 'snmp_oid', 'name', 'key_', 'delay', 'history', 'trends', 'status', 'value_type',
			'trapper_hosts', 'units', 'multiplier', 'delta', 'snmpv3_contextname', 'snmpv3_securityname',
			'snmpv3_securitylevel', 'snmpv3_authprotocol', 'snmpv3_authpassphrase', 'snmpv3_privprotocol',
			'snmpv3_privpassphrase', 'formula', 'logtimefmt', 'valuemapid', 'delay_flex', 'params', 'ipmi_sensor',
			'data_type', 'authtype', 'username', 'password', 'publickey', 'privatekey', 'flags', 'port',
			'description', 'inventory_link'
		),
		'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL),
		'selectApplications' => array('applicationid')
	));

	$dstHosts = API::Host()->get(array(
		'output' => array('hostid', 'host', 'status'),
		'selectInterfaces' => array('interfaceid', 'type', 'main'),
		'hostids' => $dstHostIds,
		'preservekeys' => true,
		'nopermissions' => true,
		'templated_hosts' => true
	));

	foreach ($dstHosts as $dstHost) {
		$interfaceids = array();
		foreach ($dstHost['interfaces'] as $interface) {
			if ($interface['main'] == 1) {
				$interfaceids[$interface['type']] = $interface['interfaceid'];
			}
		}
		foreach ($srcItems as &$srcItem) {
			if ($dstHost['status'] != HOST_STATUS_TEMPLATE) {
				$type = itemTypeInterface($srcItem['type']);

				if ($type == INTERFACE_TYPE_ANY) {
					foreach (array(INTERFACE_TYPE_AGENT, INTERFACE_TYPE_SNMP, INTERFACE_TYPE_JMX, INTERFACE_TYPE_IPMI) as $itype) {
						if (isset($interfaceids[$itype])) {
							$srcItem['interfaceid'] = $interfaceids[$itype];
							break;
						}
					}
				}
				elseif ($type !== false) {
					if (!isset($interfaceids[$type])) {
						error(_s('Cannot find host interface on "%1$s" for item key "%2$s".', $dstHost['host'], $srcItem['key_']));
						return false;
					}
					$srcItem['interfaceid'] = $interfaceids[$type];
				}
			}
			unset($srcItem['itemid']);
			$srcItem['hostid'] = $dstHost['hostid'];
			$srcItem['applications'] = get_same_applications_for_host(zbx_objectValues($srcItem['applications'], 'applicationid'), $dstHost['hostid']);
		}
		if (!API::Item()->create($srcItems)) {
			return false;
		}
	}
	return true;
}

function copyItems($srcHostId, $dstHostId) {
	$srcItems = API::Item()->get(array(
		'hostids' => $srcHostId,
		'output' => array(
			'type', 'snmp_community', 'snmp_oid', 'name', 'key_', 'delay', 'history', 'trends', 'status', 'value_type',
			'trapper_hosts', 'units', 'multiplier', 'delta', 'snmpv3_contextname', 'snmpv3_securityname',
			'snmpv3_securitylevel', 'snmpv3_authprotocol', 'snmpv3_authpassphrase', 'snmpv3_privprotocol',
			'snmpv3_privpassphrase', 'formula', 'logtimefmt', 'valuemapid', 'delay_flex', 'params', 'ipmi_sensor',
			'data_type', 'authtype', 'username', 'password', 'publickey', 'privatekey', 'flags', 'port',
			'description', 'inventory_link'
		),
		'inherited' => false,
		'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL),
		'selectApplications' => array('applicationid')
	));
	$dstHosts = API::Host()->get(array(
		'output' => array('hostid', 'host', 'status'),
		'selectInterfaces' => array('interfaceid', 'type', 'main'),
		'hostids' => $dstHostId,
		'preservekeys' => true,
		'nopermissions' => true,
		'templated_hosts' => true
	));
	$dstHost = reset($dstHosts);

	foreach ($srcItems as &$srcItem) {
		if ($dstHost['status'] != HOST_STATUS_TEMPLATE) {
			// find a matching interface
			$interface = CItem::findInterfaceForItem($srcItem, $dstHost['interfaces']);
			if ($interface) {
				$srcItem['interfaceid'] = $interface['interfaceid'];
			}
			// no matching interface found, throw an error
			elseif ($interface !== false) {
				error(_s('Cannot find host interface on "%1$s" for item key "%2$s".', $dstHost['host'], $srcItem['key_']));
			}
		}
		unset($srcItem['itemid']);
		unset($srcItem['templateid']);
		$srcItem['hostid'] = $dstHostId;
		$srcItem['applications'] = get_same_applications_for_host(zbx_objectValues($srcItem['applications'], 'applicationid'), $dstHostId);
	}

	return API::Item()->create($srcItems);
}

function copyApplications($srcHostId, $dstHostId) {
	$apps_to_clone = API::Application()->get(array(
		'hostids' => $srcHostId,
		'output' => API_OUTPUT_EXTEND,
		'inherited' => false
	));
	if (empty($apps_to_clone)) {
		return true;
	}

	foreach ($apps_to_clone as &$app) {
		$app['hostid'] = $dstHostId;
		unset($app['applicationid'], $app['templateid']);
	}
	return API::Application()->create($apps_to_clone);
}

function activate_item($itemids) {
	zbx_value2array($itemids);

	// first update status for child items
	$child_items = array();
	$db_items = DBselect('SELECT i.itemid,i.hostid FROM items i WHERE '.dbConditionInt('i.templateid', $itemids));
	while ($item = DBfetch($db_items)) {
		$child_items[$item['itemid']] = $item['itemid'];
	}
	if (!empty($child_items)) {
		activate_item($child_items); // Recursion !!!
	}
	return update_item_status($itemids, ITEM_STATUS_ACTIVE);
}

function disable_item($itemids) {
	zbx_value2array($itemids);

	// first update status for child items
	$chd_items = array();
	$db_tmp_items = DBselect('SELECT i.itemid,i.hostid FROM items i WHERE '.dbConditionInt('i.templateid', $itemids));
	while ($db_tmp_item = DBfetch($db_tmp_items)) {
		$chd_items[$db_tmp_item['itemid']] = $db_tmp_item['itemid'];
	}
	if (!empty($chd_items)) {
		disable_item($chd_items); // Recursion !!!
	}
	return update_item_status($itemids, ITEM_STATUS_DISABLED);
}

function get_item_by_key($key, $host = '') {
	$item = false;
	$sql_from = '';
	$sql_where = '';
	if (!empty($host)) {
		$sql_from = ',hosts h ';
		$sql_where = ' AND h.host='.zbx_dbstr($host).' AND i.hostid=h.hostid ';
	}
	$sql = 'SELECT DISTINCT i.*'.
			' FROM items i '.$sql_from.
			' WHERE i.key_='.zbx_dbstr($key).
				$sql_where;
	if ($item = DBfetch(DBselect($sql))) {
		$item = $item;
	}
	return $item;
}

function get_item_by_itemid($itemid) {
	$db_items = DBfetch(DBselect('SELECT i.* FROM items i WHERE i.itemid='.zbx_dbstr($itemid)));
	if ($db_items) {
		return $db_items;
	}
	error(_s('No item with itemid="%1$s".', $itemid));
	return false;
}

function get_item_by_itemid_limited($itemid) {
	$row = DBfetch(DBselect(
		'SELECT i.itemid,i.interfaceid,i.name,i.key_,i.hostid,i.delay,i.history,i.status,i.type,i.lifetime,'.
			'i.snmp_community,i.snmp_oid,i.value_type,i.data_type,i.trapper_hosts,i.port,i.units,i.multiplier,'.
			'i.delta,i.snmpv3_contextname,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authprotocol,'.
			'i.snmpv3_authpassphrase,i.snmpv3_privprotocol,i.snmpv3_privpassphrase,i.formula,i.trends,i.logtimefmt,'.
			'i.valuemapid,i.delay_flex,i.params,i.ipmi_sensor,i.templateid,i.authtype,i.username,i.password,'.
			'i.publickey,i.privatekey,i.flags,i.description,i.inventory_link'.
		' FROM items i'.
		' WHERE i.itemid='.zbx_dbstr($itemid)));
	if ($row) {
		return $row;
	}
	error(_s('No item with itemid "%1$s".', $itemid));
	return false;
}

/**
 * Description:
 * Replace items for specified host
 *
 * Comments:
 * $error= true : rise Error if item doesn't exist (error generated), false: special processing (NO error generated)
 */
function get_same_item_for_host($item, $dest_hostids) {
	$return_array = is_array($dest_hostids);
	zbx_value2array($dest_hostids);

	if (!is_array($item)) {
		$itemid = $item;
	}
	elseif (isset($item['itemid'])) {
		$itemid = $item['itemid'];
	}

	$same_item = null;
	$same_items = array();

	if (isset($itemid)) {
		$db_items = DBselect(
			'SELECT src.*'.
			' FROM items src,items dest'.
			' WHERE dest.itemid='.zbx_dbstr($itemid).
				' AND src.key_=dest.key_'.
				' AND '.dbConditionInt('src.hostid', $dest_hostids)
		);
		while ($db_item = DBfetch($db_items)) {
			if (is_array($item)) {
				$same_item = $db_item;
				$same_items[$db_item['itemid']] = $db_item;
			}
			else {
				$same_item = $db_item['itemid'];
				$same_items[$db_item['itemid']] = $db_item['itemid'];
			}
		}
		if ($return_array) {
			return $same_items;
		}
		else {
			return $same_item;
		}
	}
	return false;
}

function get_realhost_by_itemid($itemid) {
	$item = get_item_by_itemid($itemid);
	if ($item['templateid'] <> 0) {
		return get_realhost_by_itemid($item['templateid']); // attention recursion!
	}
	return get_host_by_itemid($itemid);
}

function fillItemsWithChildTemplates(&$items) {
	$processSecondLevel = false;
	$dbItems = DBselect('SELECT i.itemid,i.templateid FROM items i WHERE '.dbConditionInt('i.itemid', zbx_objectValues($items, 'templateid')));
	while ($dbItem = DBfetch($dbItems)) {
		foreach ($items as $itemid => $item) {
			if ($item['templateid'] == $dbItem['itemid'] && !empty($dbItem['templateid'])) {
				$items[$itemid]['templateid'] = $dbItem['templateid'];
				$processSecondLevel = true;
			}
		}
	}
	if ($processSecondLevel) {
		fillItemsWithChildTemplates($items); // attention recursion!
	}
}

function get_realrule_by_itemid_and_hostid($itemid, $hostid) {
	$item = get_item_by_itemid($itemid);
	if (bccomp($hostid,$item['hostid']) == 0) {
		return $item['itemid'];
	}
	if ($item['templateid'] <> 0) {
		return get_realrule_by_itemid_and_hostid($item['templateid'], $hostid);
	}
	return $item['itemid'];
}

/**
 * Retrieve overview table object for items.
 *
 * @param array  		$hostIds
 * @param array|null	$applicationIds		IDs of applications to filter items by
 * @param int    		$viewMode
 *
 * @return CTableInfo
 */
function getItemsDataOverview($hostIds, array $applicationIds = null, $viewMode) {
	$sqlFrom = '';
	$sqlWhere = '';

	if ($applicationIds !== null) {
		$sqlFrom = 'items_applications ia,';
		$sqlWhere = ' AND i.itemid=ia.itemid AND '.dbConditionInt('ia.applicationid', $applicationIds);
	}

	$dbItems = DBfetchArray(DBselect(
		'SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.units,'.
			'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid'.
		' FROM hosts h,'.$sqlFrom.'items i'.
			' LEFT JOIN functions f ON f.itemid=i.itemid'.
			' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status='.TRIGGER_STATUS_ENABLED.
		' WHERE '.dbConditionInt('h.hostid', $hostIds).
			' AND h.status='.HOST_STATUS_MONITORED.
			' AND h.hostid=i.hostid'.
			' AND i.status='.ITEM_STATUS_ACTIVE.
			' AND '.dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)).
				$sqlWhere
	));

	$dbItems = CMacrosResolverHelper::resolveItemNames($dbItems);

	CArrayHelper::sort($dbItems, array(
		array('field' => 'name_expanded', 'order' => ZBX_SORT_UP),
		array('field' => 'itemid', 'order' => ZBX_SORT_UP)
	));

	// fetch latest values
	$history = Manager::History()->getLast(zbx_toHash($dbItems, 'itemid'), 1, ZBX_HISTORY_PERIOD);

	// fetch data for the host JS menu
	$hosts = API::Host()->get(array(
		'output' => array('name', 'hostid', 'status'),
		'monitored_hosts' => true,
		'hostids' => $hostIds,
		'with_monitored_items' => true,
		'preservekeys' => true,
		'selectGraphs' => API_OUTPUT_COUNT,
		'selectScreens' => ($viewMode == STYLE_LEFT) ? API_OUTPUT_COUNT : null
	));

	$items = array();
	foreach ($dbItems as $dbItem) {
		$name = $dbItem['name_expanded'];

		$hostNames[$dbItem['hostid']] = $dbItem['hostname'];

		// a little tricky check for attempt to overwrite active trigger (value=1) with
		// inactive or active trigger with lower priority.
		if (!isset($items[$name][$dbItem['hostname']])
				|| (($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $dbItem['tr_value'] == TRIGGER_VALUE_TRUE)
					|| (($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $dbItem['tr_value'] == TRIGGER_VALUE_TRUE)
						&& $dbItem['priority'] > $items[$name][$dbItem['hostname']]['severity']))) {
			$items[$name][$dbItem['hostname']] = array(
				'itemid' => $dbItem['itemid'],
				'value_type' => $dbItem['value_type'],
				'value' => isset($history[$dbItem['itemid']]) ? $history[$dbItem['itemid']][0]['value'] : null,
				'units' => $dbItem['units'],
				'name' => $name,
				'valuemapid' => $dbItem['valuemapid'],
				'severity' => $dbItem['priority'],
				'tr_value' => $dbItem['tr_value'],
				'triggerid' => $dbItem['triggerid']
			);
		}
	}

	$table = new CTableInfo(_('No items found.'));
	if (empty($hostNames)) {
		return $table;
	}
	$table->makeVerticalRotation();

	order_result($hostNames);

	if ($viewMode == STYLE_TOP) {
		$header = array(new CCol(_('Items'), 'center'));
		foreach ($hostNames as $hostName) {
			$header[] = new CCol($hostName, 'vertical_rotation');
		}
		$table->setHeader($header, 'vertical_header');

		foreach ($items as $descr => $ithosts) {
			$tableRow = array(nbsp($descr));
			foreach ($hostNames as $hostName) {
				$tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
			}
			$table->addRow($tableRow);
		}
	}
	else {
		$scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid'));

		$header = array(new CCol(_('Hosts'), 'center'));
		foreach ($items as $descr => $ithosts) {
			$header[] = new CCol($descr, 'vertical_rotation');
		}
		$table->setHeader($header, 'vertical_header');

		foreach ($hostNames as $hostId => $hostName) {
			$host = $hosts[$hostId];

			$name = new CSpan($host['name'], 'link_menu');
			$name->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$hostId]));

			$tableRow = array(new CCol($name));
			foreach ($items as $ithosts) {
				$tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
			}
			$table->addRow($tableRow);
		}
	}

	return $table;
}

function getItemDataOverviewCells($tableRow, $ithosts, $hostName) {
	$css = '';
	$value = '-';
	$ack = null;

	if (isset($ithosts[$hostName])) {
		$item = $ithosts[$hostName];

		if ($item['tr_value'] == TRIGGER_VALUE_TRUE) {
			$css = getSeverityStyle($item['severity']);
			$ack = get_last_event_by_triggerid($item['triggerid']);
			$ack = ($ack['acknowledged'] == 1)
				? array(SPACE, new CImg('images/general/tick.png', 'ack'))
				: null;
		}

		$value = ($item['value'] !== null) ? formatHistoryValue($item['value'], $item) : UNKNOWN_VALUE;
	}

	if ($value != '-') {
		$value = new CSpan($value, 'link');
	}

	$column = new CCol(array($value, $ack), $css);

	if (isset($ithosts[$hostName])) {
		$column->setMenuPopup(CMenuPopupHelper::getHistory($item));
	}

	$tableRow[] = $column;

	return $tableRow;
}

/**
 * Get same application IDs on destination host and return array with keys as source application IDs
 * and values as destination application IDs.
 *
 * Comments: !!! Don't forget sync code with C !!!
 *
 * @param array  $applicationIds
 * @param string $hostId
 *
 * @return array
 */
function get_same_applications_for_host(array $applicationIds, $hostId) {
	$applications = array();

	$dbApplications = DBselect(
		'SELECT a1.applicationid AS dstappid,a2.applicationid AS srcappid'.
		' FROM applications a1,applications a2'.
		' WHERE a1.name=a2.name'.
			' AND a1.hostid='.zbx_dbstr($hostId).
			' AND '.dbConditionInt('a2.applicationid', $applicationIds)
	);

	while ($dbApplication = DBfetch($dbApplications)) {
		$applications[$dbApplication['srcappid']] = $dbApplication['dstappid'];
	}

	return $applications;
}

/******************************************************************************
 *                                                                            *
 * Comments: !!! Don't forget sync code with C !!!                            *
 *                                                                            *
 ******************************************************************************/
function get_applications_by_itemid($itemids, $field = 'applicationid') {
	zbx_value2array($itemids);
	$result = array();
	$db_applications = DBselect(
		'SELECT DISTINCT app.'.$field.' AS result'.
		' FROM applications app,items_applications ia'.
		' WHERE app.applicationid=ia.applicationid'.
			' AND '.dbConditionInt('ia.itemid', $itemids)
	);
	while ($db_application = DBfetch($db_applications)) {
		array_push($result, $db_application['result']);
	}

	return $result;
}

/**
 * Clear item history and trends by provided item IDs.
 *
 * @param array $itemIds
 *
 * @return bool
 */
function deleteHistoryByItemIds(array $itemIds) {
	$result = DBexecute('DELETE FROM trends WHERE '.dbConditionInt('itemid', $itemIds));
	$result = ($result && DBexecute('DELETE FROM trends_uint WHERE '.dbConditionInt('itemid', $itemIds)));
	$result = ($result && DBexecute('DELETE FROM history_text WHERE '.dbConditionInt('itemid', $itemIds)));
	$result = ($result && DBexecute('DELETE FROM history_log WHERE '.dbConditionInt('itemid', $itemIds)));
	$result = ($result && DBexecute('DELETE FROM history_uint WHERE '.dbConditionInt('itemid', $itemIds)));
	$result = ($result && DBexecute('DELETE FROM history_str WHERE '.dbConditionInt('itemid', $itemIds)));
	$result = ($result && DBexecute('DELETE FROM history WHERE '.dbConditionInt('itemid', $itemIds)));

	return $result;
}

/**
 * Format history value.
 * First format the value according to the configuration of the item. Then apply the value mapping to the formatted (!)
 * value.
 *
 * @param mixed     $value
 * @param array     $item
 * @param int       $item['value_type']     type of the value: ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64, ...
 * @param string    $item['units']          units of item
 * @param int       $item['valuemapid']     id of mapping set of values
 * @param bool      $trim
 *
 * @return string
 */
function formatHistoryValue($value, array $item, $trim = true) {
	$mapping = false;

	// format value
	if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
		$value = convert_units(array(
				'value' => $value,
				'units' => $item['units']
		));
	}
	elseif ($item['value_type'] != ITEM_VALUE_TYPE_STR
		&& $item['value_type'] != ITEM_VALUE_TYPE_TEXT
		&& $item['value_type'] != ITEM_VALUE_TYPE_LOG) {

		$value = _('Unknown value type');
	}

	// apply value mapping
	switch ($item['value_type']) {
		case ITEM_VALUE_TYPE_STR:
			$mapping = getMappedValue($value, $item['valuemapid']);
		// break; is not missing here
		case ITEM_VALUE_TYPE_TEXT:
		case ITEM_VALUE_TYPE_LOG:
			if ($trim && mb_strlen($value) > 20) {
				$value = mb_substr($value, 0, 20).'...';
			}

			if ($mapping !== false) {
				$value = $mapping.' ('.$value.')';
			}
			break;
		default:
			$value = applyValueMap($value, $item['valuemapid']);
	}

	return $value;
}

/**
 * Retrieves from DB historical data for items and applies functional calculations.
 * If fails for some reason, returns UNRESOLVED_MACRO_STRING.
 *
 * @param array		$item
 * @param string	$item['value_type']	type of item, allowed: ITEM_VALUE_TYPE_FLOAT and ITEM_VALUE_TYPE_UINT64
 * @param string	$item['itemid']		ID of item
 * @param string	$item['units']		units of item
 * @param string	$function			function to apply to time period from param, allowed: min, max and avg
 * @param string	$parameter			formatted parameter for function, example: "2w" meaning 2 weeks
 *
 * @return string item functional value from history
 */
function getItemFunctionalValue($item, $function, $parameter) {
	// check whether function is allowed
	if (!in_array($function, array('min', 'max', 'avg')) || $parameter === '') {
		return UNRESOLVED_MACRO_STRING;
	}

	$parameter = convertFunctionValue($parameter);

	if (bccomp($parameter, 0) == 0) {
		return UNRESOLVED_MACRO_STRING;
	}

	// allowed item types for min, max and avg function
	$historyTables = array(ITEM_VALUE_TYPE_FLOAT => 'history', ITEM_VALUE_TYPE_UINT64 => 'history_uint');

	if (!isset($historyTables[$item['value_type']])) {
		return UNRESOLVED_MACRO_STRING;
	}
	else {
		// search for item function data in DB corresponding history table
		$result = DBselect(
			'SELECT '.$function.'(value) AS value'.
			' FROM '.$historyTables[$item['value_type']].
			' WHERE clock>'.(time() - $parameter).
			' AND itemid='.zbx_dbstr($item['itemid']).
			' HAVING COUNT(*)>0' // necessary because DBselect() return 0 if empty data set, for graph templates
		);
		if ($row = DBfetch($result)) {
			return convert_units(array('value' => $row['value'], 'units' => $item['units']));
		}
		// no data in history
		else {
			return UNRESOLVED_MACRO_STRING;
		}
	}
}

/**
 * Returns the history value of the item at the given time. If no value exists at the given time, the function
 * will return the previous value.
 *
 * The $db_item parameter must have the value_type and itemid properties set.
 *
 * @param array $db_item
 * @param int $clock
 * @param int $ns
 *
 * @return string
 */
function item_get_history($db_item, $clock, $ns) {
	$value = null;

	$table = CHistoryManager::getTableName($db_item['value_type']);

	$sql = 'SELECT value'.
			' FROM '.$table.
			' WHERE itemid='.zbx_dbstr($db_item['itemid']).
				' AND clock='.zbx_dbstr($clock).
				' AND ns='.zbx_dbstr($ns);
	if (null != ($row = DBfetch(DBselect($sql, 1)))) {
		$value = $row['value'];
	}
	if ($value != null) {
		return $value;
	}

	$max_clock = 0;

	$sql = 'SELECT DISTINCT clock'.
			' FROM '.$table.
			' WHERE itemid='.zbx_dbstr($db_item['itemid']).
				' AND clock='.zbx_dbstr($clock).
				' AND ns<'.zbx_dbstr($ns);
	if (null != ($row = DBfetch(DBselect($sql)))) {
		$max_clock = $row['clock'];
	}
	if ($max_clock == 0) {
		$sql = 'SELECT MAX(clock) AS clock'.
				' FROM '.$table.
				' WHERE itemid='.zbx_dbstr($db_item['itemid']).
					' AND clock<'.zbx_dbstr($clock);
		if (null != ($row = DBfetch(DBselect($sql)))) {
			$max_clock = $row['clock'];
		}
	}
	if ($max_clock == 0) {
		return $value;
	}

	if ($clock == $max_clock) {
		$sql = 'SELECT value'.
				' FROM '.$table.
				' WHERE itemid='.zbx_dbstr($db_item['itemid']).
					' AND clock='.zbx_dbstr($clock).
					' AND ns<'.zbx_dbstr($ns);
	}
	else {
		$sql = 'SELECT value'.
				' FROM '.$table.
				' WHERE itemid='.zbx_dbstr($db_item['itemid']).
					' AND clock='.zbx_dbstr($max_clock).
				' ORDER BY itemid,clock desc,ns desc';
	}

	if (null != ($row = DBfetch(DBselect($sql, 1)))) {
		$value = $row['value'];
	}

	return $value;
}

/**
 * Check if current time is within the given period.
 *
 * @param string $period	time period format: "wd[-wd2],hh:mm-hh:mm"
 * @param int $now			current timestamp
 *
 * @return bool		true - within period, false - out of period
 */
function checkTimePeriod($period, $now) {
	if (sscanf($period, '%d-%d,%d:%d-%d:%d', $d1, $d2, $h1, $m1, $h2, $m2) != 6) {
		if (sscanf($period, '%d,%d:%d-%d:%d', $d1, $h1, $m1, $h2, $m2) != 5) {
			// delay period format is wrong - skip
			return false;
		}
		$d2 = $d1;
	}

	$tm = localtime($now, true);
	$day = ($tm['tm_wday'] == 0) ? 7 : $tm['tm_wday'];
	$sec = SEC_PER_HOUR * $tm['tm_hour'] + SEC_PER_MIN * $tm['tm_min'] + $tm['tm_sec'];

	$sec1 = SEC_PER_HOUR * $h1 + SEC_PER_MIN * $m1;
	$sec2 = SEC_PER_HOUR * $h2 + SEC_PER_MIN * $m2;

	return $d1 <= $day && $day <= $d2 && $sec1 <= $sec && $sec < $sec2;
}

function getItemDelay($delay, $flexIntervals) {
	if (!empty($delay) || zbx_empty($flexIntervals)) {
		return $delay;
	}
	$minDelay = SEC_PER_YEAR;
	$flexIntervals = explode(';', $flexIntervals);
	foreach ($flexIntervals as $flexInterval) {
		if (sscanf($flexInterval, "%d/%29s", $flexDelay, $flexPeriod) != 2) {
			continue;
		}
		$minDelay = min($minDelay, $flexDelay);
	}
	return $minDelay;
}

/**
 * Return delay value that is currently applicable
 *
 * @param int $delay                 default delay
 * @param array $arrOfFlexIntervals  array of intervals in format: "d/wd[-wd2],hh:mm-hh:mm"
 * @param int $now                   current timestamp
 *
 * @return int                       delay for a current timestamp
 */
function getCurrentDelay($delay, array $arrOfFlexIntervals, $now) {
	if (empty($arrOfFlexIntervals)) {
		return $delay;
	}

	$currentDelay = -1;

	foreach ($arrOfFlexIntervals as $flexInterval) {
		if (sscanf($flexInterval, '%d/%29s', $flexDelay, $flexPeriod) != 2) {
			continue;
		}
		if (($currentDelay == -1 || $flexDelay < $currentDelay) && checkTimePeriod($flexPeriod, $now)) {
			$currentDelay = $flexDelay;
		}
	}

	if ($currentDelay == -1) {
		return $delay;
	}

	return $currentDelay;
}

/**
 * Return time of next flexible interval
 *
 * @param array $arrOfFlexIntervals  array of intervals in format: "d/wd[-wd2],hh:mm-hh:mm"
 * @param int $now                   current timestamp
 * @param int $nextInterval          timestamp of a next interval
 *
 * @return bool                      false if no flexible intervals defined
 */
function getNextDelayInterval(array $arrOfFlexIntervals, $now, &$nextInterval) {
	if (empty($arrOfFlexIntervals)) {
		return false;
	}

	$next = 0;
	$tm = localtime($now, true);
	$day = ($tm['tm_wday'] == 0) ? 7 : $tm['tm_wday'];
	$sec = SEC_PER_HOUR * $tm['tm_hour'] + SEC_PER_MIN * $tm['tm_min'] + $tm['tm_sec'];

	foreach ($arrOfFlexIntervals as $flexInterval) {
		if (sscanf($flexInterval, '%d/%d-%d,%d:%d-%d:%d', $delay, $d1, $d2, $h1, $m1, $h2, $m2) != 7) {
			if (sscanf($flexInterval, '%d/%d,%d:%d-%d:%d', $delay, $d1, $h1, $m1, $h2, $m2) != 6) {
				continue;
			}
			$d2 = $d1;
		}

		$sec1 = SEC_PER_HOUR * $h1 + SEC_PER_MIN * $m1;
		$sec2 = SEC_PER_HOUR * $h2 + SEC_PER_MIN * $m2;

		// current period
		if ($d1 <= $day && $day <= $d2 && $sec1 <= $sec && $sec < $sec2) {
			if ($next == 0 || $next > $now - $sec + $sec2) {
				// the next second after the current interval's upper bound
				$next = $now - $sec + $sec2;
			}
		}
		// will be active today
		elseif ($d1 <= $day && $d2 >= $day && $sec < $sec1) {
			if ($next == 0 || $next > $now - $sec + $sec1) {
				$next = $now - $sec + $sec1;
			}
		}
		else {
			$nextDay = ($day + 1 <= 7) ? $day + 1 : 1;

			// will be active tomorrow
			if ($d1 <= $nextDay && $nextDay <= $d2) {
				if ($next == 0 || $next > $now - $sec + SEC_PER_DAY + $sec1) {
					$next = $now - $sec + SEC_PER_DAY + $sec1;
				}
			}
			// later in the future
			else {
				$dayDiff = -1;

				if ($day < $d1) {
					$dayDiff = $d1 - $day;
				}
				if ($day >= $d2) {
					$dayDiff = ($d1 + 7) - $day;
				}
				if ($d1 <= $day && $day < $d2) {
					// should never happen, could not deduce day difference
					$dayDiff = -1;
				}
				if ($dayDiff != -1 && ($next == 0 || $next > $now - $sec + SEC_PER_DAY * $dayDiff + $sec1)) {
					$next = $now - $sec + SEC_PER_DAY * $dayDiff + $sec1;
				}
			}
		}
	}
	if ($next != 0) {
		$nextInterval = $next;
	}
	return $next != 0;
}

/**
 * Calculate nextcheck timestamp for an item
 *
 * the parameter $flexIntervals accepts data in a format:
 *
 *           +------------[;]<----------+
 *           |                          |
 *         ->+-[d/wd[-wd2],hh:mm-hh:mm]-+
 *
 *         d       - delay (0-n)
 *         wd, wd2 - day of week (1-7)
 *         hh      - hours (0-24)
 *         mm      - minutes (0-59)
 *
 * @param string $seed               seed value applied to delay to spread item checks over the delay period
 * @param int $delay                 default delay, can be overridden
 * @param string $flexIntervals      flexible intervals
 * @param int $now                   current timestamp
 *
 * @return int
 */
function calculateItemNextCheck($seed, $delay, $flexIntervals, $now) {
	// try to find the nearest 'nextcheck' value with condition 'now' < 'nextcheck' < 'now' + SEC_PER_YEAR
	// if it is not possible to check the item within a year, fail
	$arrOfFlexIntervals = explode(';', $flexIntervals);
	$t = $now;
	$tMax = $now + SEC_PER_YEAR;
	$try = 0;

	while ($t < $tMax) {
		// calculate 'nextcheck' value for the current interval
		$currentDelay = getCurrentDelay($delay, $arrOfFlexIntervals, $t);

		if ($currentDelay != 0) {
			$nextCheck = $currentDelay * floor($t / $currentDelay) + ($seed % $currentDelay);

			if ($try == 0) {
				while ($nextCheck <= $t) {
					$nextCheck += $currentDelay;
				}
			}
			else {
				while ($nextCheck < $t) {
					$nextCheck += $currentDelay;
				}
			}
		}
		else {
			$nextCheck = ZBX_JAN_2038;
		}

		// 'nextcheck' < end of the current interval ?
		// the end of the current interval is the beginning of the next interval - 1
		if (getNextDelayInterval($arrOfFlexIntervals, $t, $nextInterval) && $nextCheck >= $nextInterval) {
			// 'nextcheck' is beyond the current interval
			$t = $nextInterval;
			$try++;
		}
		else {
			break;
		}
	}

	return $nextCheck;
}

/**
 * Check if given character is a valid key id char
 * this function is a copy of is_key_char() from /src/libs/zbxcommon/misc.c
 * don't forget to take look in there before changing anything
 *
 * @author Konstantin Buravcov
 * @param string $char
 * @return bool
 */
function isKeyIdChar($char) {
	return (
		($char >= 'a' && $char <= 'z')
		|| $char == '.' || $char == '_' || $char == '-'
		|| ($char >= 'A' && $char <= 'Z')
		|| ($char >= '0' && $char <= '9')
	);
}

/*
 * Description:
 *	Function returns true if http items exists in the $items array.
 *	The array should contain a field 'type'
 */
function httpItemExists($items) {
	foreach ($items as $item) {
		if ($item['type'] == ITEM_TYPE_HTTPTEST) {
			return true;
		}
	}
	return false;
}

function getParamFieldNameByType($itemType) {
	switch ($itemType) {
		case ITEM_TYPE_SSH:
		case ITEM_TYPE_TELNET:
		case ITEM_TYPE_JMX:
			return 'params_es';
		case ITEM_TYPE_DB_MONITOR:
			return 'params_ap';
		case ITEM_TYPE_CALCULATED:
			return 'params_f';
		default:
			return 'params';
	}
}

function getParamFieldLabelByType($itemType) {
	switch ($itemType) {
		case ITEM_TYPE_SSH:
		case ITEM_TYPE_TELNET:
		case ITEM_TYPE_JMX:
			return _('Executed script');
		case ITEM_TYPE_DB_MONITOR:
			return _('SQL query');
		case ITEM_TYPE_CALCULATED:
			return _('Formula');
		default:
			return 'params';
	}
}

/**
 * Quoting $param if it contain special characters.
 *
 * @param string $param
 *
 * @return string
 */
function quoteItemKeyParam($param) {
	if (!isset($param[0]) || ($param[0] != '"' && false === strpos($param, ',') && false === strpos($param, ']'))) {
		return $param;
	}

	return '"'.str_replace('"', '\\"', $param).'"';
}


text:
package net.sf.esfinge.querybuilder.view;

import java.awt.Color;
import java.awt.GridLayout;
import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import javax.swing.text.MaskFormatter;

public class ApplicationComponents extends JFrame {

	private static final long serialVersionUID = -8086201978339680527L;

	private JLabel lblContactId = new JLabel("ID : ");
	private JLabel lblContactEmail = new JLabel("E-Mail : ");
	private JLabel lblContactPhoneNumber = new JLabel("Phone Number : ");
	private JLabel lblContactCellNumber = new JLabel("Cell Number : ");

	private JLabel lblContactName = new JLabel("Name : ");
	private JLabel lblContactSurName = new JLabel("Sur Name : ");
	private JLabel lblContactBirthDate = new JLabel("Birth Date : ");

	private JLabel lblContactStreet = new JLabel("Street : ");
	private JLabel lblContactStreetNumber = new JLabel("Street Number : ");
	private JLabel lblContactStreetComplement = new JLabel("Street Complement : ");
	private JLabel lblContactCity = new JLabel("City : ");
	private JLabel lblContactState = new JLabel("State : ");
	private JLabel lblContactType = new JLabel("Type of Contact : ");
	private JLabel lblContactZipcode = new JLabel("Zipcode : ");

	private JTextField txtContactId = new JTextField();
	private JTextField txtContactEmail = new JTextField();
	private JFormattedTextField txtContactPhoneNumber = new JFormattedTextField();
	private JFormattedTextField txtContactCellNumber = new JFormattedTextField();

	private JTextField txtContactName = new JTextField();
	private JTextField txtContactSurName = new JTextField();
	private JFormattedTextField txtContactBirthDate = new JFormattedTextField();

	private JTextField txtContactStreet = new JTextField();
	private JFormattedTextField txtContactStreetNumber = new JFormattedTextField();
	private JTextField txtContactStreetComplement = new JTextField();
	private JTextField txtContactCity = new JTextField();
	private JTextField txtContactState = new JTextField();
	private Object[] listContactTypes = { " ", "COWORKER", "FAMILIAR", "FRIEND", };

	private JComboBox cmbContactType = new JComboBox(listContactTypes);
	private JFormattedTextField txtContactZipcode = new JFormattedTextField();

	private JPanel panelLabels = new JPanel();
	private JPanel panelTextFields = new JPanel();
	private JPanel panelOperations = new JPanel();
	private JPanel panelJTable = new JPanel();
	private JTable tableView = new JTable();
	private JScrollPane scrollpane = new JScrollPane(tableView);

	private JButton btnNewContact = new JButton("New", new ImageIcon(getClass().getClassLoader().getResource("./images/new.png").getFile()));
	private JButton btnSaveContact = new JButton("Save", new ImageIcon(getClass().getClassLoader().getResource("./images/save.png").getFile()));
	private JButton btnCancelContact = new JButton("Cancel", new ImageIcon(getClass().getClassLoader().getResource("images/cancel.png").getFile()));
	private JButton btnDeleteContact = new JButton("Delete", new ImageIcon(getClass().getClassLoader().getResource("./images/delete.png").getFile()));
	private JButton btnSearch = new JButton("Search", new ImageIcon(getClass().getClassLoader().getResource("./images/search.png").getFile()));
	private JButton btnCloseApplication = new JButton("Close", new ImageIcon(getClass().getClassLoader().getResource("./images/exit.png").getFile()));
	private JButton btnModifyContact = new JButton("Modify", new ImageIcon(getClass().getClassLoader().getResource("./images/modify.png").getFile()));
	private JButton btnGoSearch = new JButton("Go Search", new ImageIcon(getClass().getClassLoader().getResource("./images/ok.png").getFile()));
	private JButton btnSearchFriends = new JButton("Friends", new ImageIcon(getClass().getClassLoader().getResource("./images/cell.png").getFile()));

	public JButton getBtnSearchFriends() {
		return btnSearchFriends;
	}

	public JLabel getLblContactType() {
		return lblContactType;
	}

	public JButton getBtnCloseApplication() {
		return btnCloseApplication;
	}

	public JScrollPane getScrollpane() {
		return scrollpane;
	}

	public JTable getTableView() {
		return tableView;
	}

	public JButton getBtnModifyContact() {
		return btnModifyContact;
	}

	public JButton getBtnGoSearch() {
		return btnGoSearch;
	}

	public JButton getBtnSearch() {
		return btnSearch;
	}

	public JComboBox getCmbContactType() {
		return cmbContactType;
	}

	public JPanel getPanelLabels(int x, int y, int width, int heigth) {
		setPanelLabels(x, y, width, heigth);
		return panelLabels;
	}

	public JPanel getPanelTextFields(int x, int y, int width, int heigth) {
		setPanelTextFields(x, y, width, heigth);
		return panelTextFields;
	}

	public JPanel getPanelOperations(int x, int y, int width, int heigth) {

		setPanelOperations(x, y, width, heigth);
		return panelOperations;
	}

	public JPanel getPanelJTable(int x, int y, int width, int heigth) {

		setPanelJTable(x, y, width, heigth);
		return panelJTable;
	}

	public JButton getBtnNewContact() {
		return btnNewContact;
	}

	public JButton getBtnSaveContact() {
		return btnSaveContact;
	}

	public JButton getBtnCancelContact() {
		return btnCancelContact;
	}

	public JButton getBtnDeleteContact() {
		return btnDeleteContact;
	}

	public ApplicationComponents() {

		setAlignmentLabels();

	}

	public JLabel getLblContactId() {
		return lblContactId;
	}

	public JLabel getLblContactEmail() {
		return lblContactEmail;
	}

	public JLabel getLblContactPhoneNumber() {
		return lblContactPhoneNumber;
	}

	public JLabel getLblContactCellNumber() {
		return lblContactCellNumber;
	}

	public JLabel getLblContactName() {
		return lblContactName;
	}

	public JLabel getLblContactSurName() {
		return lblContactSurName;
	}

	public JLabel getLblContactBirthDate() {
		return lblContactBirthDate;
	}

	public JLabel getLblContactStreet() {
		return lblContactStreet;
	}

	public JLabel getLblContactStreetNumber() {
		return lblContactStreetNumber;
	}

	public JLabel getLblContactStreetComplement() {
		return lblContactStreetComplement;
	}

	public JLabel getLblContactCity() {
		return lblContactCity;
	}

	public JLabel getLblContactState() {
		return lblContactState;
	}

	public JLabel getLblContactZipcode() {
		return lblContactZipcode;
	}

	public JTextField getTxtContactId() {
		return txtContactId;
	}

	public JTextField getTxtContactEmail() {
		return txtContactEmail;
	}

	public JFormattedTextField getTxtContactPhoneNumber() {
		return txtContactPhoneNumber;
	}

	public JFormattedTextField getTxtContactCellNumber() {
		return txtContactCellNumber;
	}

	public JTextField getTxtContactName() {
		return txtContactName;
	}

	public JTextField getTxtContactSurName() {
		return txtContactSurName;
	}

	public JFormattedTextField getTxtContactBirthDate() {
		return txtContactBirthDate;
	}

	public JTextField getTxtContactStreet() {
		return txtContactStreet;
	}

	public JFormattedTextField getTxtContactStreetNumber() {
		return txtContactStreetNumber;
	}

	public JTextField getTxtContactStreetComplement() {
		return txtContactStreetComplement;
	}

	public JTextField getTxtContactCity() {
		return txtContactCity;
	}

	public JTextField getTxtContactState() {
		return txtContactState;
	}

	public JFormattedTextField getTxtContactZipcode() {
		return txtContactZipcode;
	}

	public void setAlignmentLabels() {
		lblContactId.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactEmail.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactPhoneNumber.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactCellNumber.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactSurName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactBirthDate.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactStreet.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactStreetNumber.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactStreetComplement.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactCity.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactState.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactZipcode.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContactType.setHorizontalAlignment(SwingConstants.RIGHT);

	}

	public void setPanelOperations(int x, int y, int width, int heigth) {

		panelOperations.setBounds(x, y, width, heigth);
		panelOperations.setLayout(new GridLayout(0, 9, 2, 2));
		panelOperations.add(getBtnNewContact());
		panelOperations.add(getBtnSaveContact());
		panelOperations.add(getBtnModifyContact());
		panelOperations.add(getBtnSearch());
		panelOperations.add(getBtnGoSearch());
		panelOperations.add(getBtnSearchFriends());
		panelOperations.add(getBtnCancelContact());
		panelOperations.add(getBtnDeleteContact());
		panelOperations.add(getBtnCloseApplication());

	}

	public void setPanelJTable(int x, int y, int width, int heigth) {

		panelJTable.setBounds(x, y, width, heigth);
		panelJTable.setLayout(new GridLayout(0, 1, 5, 5));
		panelJTable.add(getScrollpane());

	}

	public void setPanelLabels(int x, int y, int width, int heigth) {

		panelLabels.setBounds(x, y, width, heigth);
		panelLabels.setLayout(new GridLayout(0, 1, 5, 5));
		panelLabels.add(getLblContactId());
		panelLabels.add(getLblContactName());
		panelLabels.add(getLblContactSurName());
		panelLabels.add(getLblContactBirthDate());
		panelLabels.add(getLblContactEmail());
		panelLabels.add(getLblContactPhoneNumber());
		panelLabels.add(getLblContactCellNumber());
		panelLabels.add(getLblContactStreet());
		panelLabels.add(getLblContactStreetNumber());
		panelLabels.add(getLblContactStreetComplement());
		panelLabels.add(getLblContactZipcode());
		panelLabels.add(getLblContactCity());
		panelLabels.add(getLblContactState());
		panelLabels.add(getLblContactType());

	}

	public void enabledFields() {

		txtContactEmail.setEnabled(true);
		txtContactPhoneNumber.setEnabled(true);
		txtContactCellNumber.setEnabled(true);
		txtContactName.setEnabled(true);
		txtContactSurName.setEnabled(true);
		txtContactBirthDate.setEnabled(true);
		txtContactStreet.setEnabled(true);
		txtContactStreetNumber.setEnabled(true);
		txtContactStreetComplement.setEnabled(true);
		txtContactCity.setEnabled(true);
		txtContactState.setEnabled(true);
		txtContactZipcode.setEnabled(true);
		cmbContactType.setEnabled(true);

	}

	public void disabledFields() {

		txtContactId.setEnabled(false);
		txtContactEmail.setEnabled(false);
		txtContactPhoneNumber.setEnabled(false);
		txtContactCellNumber.setEnabled(false);
		txtContactName.setEnabled(false);
		txtContactSurName.setEnabled(false);
		txtContactBirthDate.setEnabled(false);
		txtContactStreet.setEnabled(false);
		txtContactStreetNumber.setEnabled(false);
		txtContactStreetComplement.setEnabled(false);
		txtContactCity.setEnabled(false);
		txtContactState.setEnabled(false);
		txtContactZipcode.setEnabled(false);
		cmbContactType.setEnabled(false);

	}

	public void cleanFields() {

		txtContactId.setText("");
		txtContactEmail.setText("");
		txtContactPhoneNumber.setText("");
		txtContactCellNumber.setText("");
		txtContactName.setText("");
		txtContactSurName.setText("");
		txtContactBirthDate.setText("");
		txtContactStreet.setText("");
		txtContactStreetNumber.setText("");
		txtContactStreetComplement.setText("");
		txtContactCity.setText("");
		txtContactState.setText("");
		txtContactZipcode.setText("");
		cmbContactType.setSelectedIndex(0);

	}

	public void setOriginalLabelsColor() {

		lblContactId.setForeground(Color.black);
		lblContactName.setForeground(Color.black);
		lblContactSurName.setForeground(Color.black);
		lblContactBirthDate.setForeground(Color.black);
		lblContactPhoneNumber.setForeground(Color.black);
		lblContactEmail.setForeground(Color.black);
		lblContactPhoneNumber.setForeground(Color.black);
		lblContactCity.setForeground(Color.black);
		lblContactState.setForeground(Color.black);
		lblContactStreetNumber.setForeground(Color.black);
		lblContactType.setForeground(Color.black);

	}

	public void enabledTableView(boolean enabled) {

		if (enabled) {

			getTableView().setBackground(Color.white);
		} else {
			getTableView().setBackground(Color.gray);
		}

		getTableView().setEnabled(enabled);

	}

	public void setPanelTextFields(int x, int y, int width, int heigth) {

		MaskFormatter maskBirthDate = null;
		MaskFormatter maskPhoneNumber = null;
		MaskFormatter maskCellNumber = null;
		MaskFormatter maskZipcode = null;

		try {
			maskBirthDate = new MaskFormatter("##/##/####");
			maskPhoneNumber = new MaskFormatter("(###)####-####");
			maskCellNumber = new MaskFormatter("(###)####-####");
			maskZipcode = new MaskFormatter("#####-###");

		} catch (ParseException e) {

		}

		maskBirthDate.install(getTxtContactBirthDate());
		maskPhoneNumber.install(getTxtContactPhoneNumber());
		maskCellNumber.install(getTxtContactCellNumber());
		maskZipcode.install(getTxtContactZipcode());

		panelTextFields.setBounds(x, y, width, heigth);
		panelTextFields.setLayout(new GridLayout(0, 1, 5, 5));
		panelTextFields.add(getTxtContactId());
		panelTextFields.add(getTxtContactName());
		panelTextFields.add(getTxtContactSurName());
		panelTextFields.add(getTxtContactBirthDate());
		panelTextFields.add(getTxtContactEmail());
		panelTextFields.add(getTxtContactPhoneNumber());
		panelTextFields.add(getTxtContactCellNumber());
		panelTextFields.add(getTxtContactStreet());
		panelTextFields.add(getTxtContactStreetNumber());
		panelTextFields.add(getTxtContactStreetComplement());
		panelTextFields.add(getTxtContactZipcode());
		panelTextFields.add(getTxtContactCity());
		panelTextFields.add(getTxtContactState());
		panelTextFields.add(getCmbContactType());

	}

}


text:
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace white_api
{
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            //  Enable attribute based routing
            config.MapHttpAttributeRoutes();

            //Get Json response
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            app.UseWebApi(config);

        }
    }
}


text:
<?php

/**
 * Forget Password Controller
 *
 * PHP Version 5.6
 * It contains forget passwords functionality definition of Shopping cart
 *
 * @category Forget Password
 * @package  Controller
 * @author   Tejas <tejas.ghadigaonkar@neosofttech.com>
 * @license  http://neosofttech.com/  Neosoft
 * @link     NA
 */
class Forget_password extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('form');
        $this->load->model('login_model', 'login');
        $this->load->library('email');
    }

    /**
     * Used to verify the inserted email id
     *
     * @method  verification
     * @author  Tejas <tejas.ghadigaonkar@neosofttech.com>
     */
    public function verification() {
        $email = $this->input->post('email_address');
        $verify = $this->login->verify($email);
        if ($verify) {
            return $verify['user_id'];
        } else {
            return false;
        }
    }

    /**
     * Used to send maail to user which consist change password link
     *
     * @method  sent_email
     * @author  Tejas <tejas.ghadigaonkar@neosofttech.com>
     */
    public function sent_email($user_id, $tokken, $email) {
        $message = "<a href='" . base_url() . "home/login/reset/" . $user_id . "/" . $tokken . "'>Click Here to Reset Password <a>";
        return send_mail($email, 'Reset Password', $message);
    }

    /**
     * Used to generate tokken for the user
     *
     * @method  check
     * @author  Tejas <tejas.ghadigaonkar@neosofttech.com>
     */
    public function check() {
        $data["error"] = "";
        $data['forget_error'] = "";
        $this->form_validation->set_rules('email_address', 'Email Address', 'required|valid_email');
        if ($this->form_validation->run() == FALSE) {
            $data['forget'] = "forget_password";
            $data['page'] = "home/login";
            $this->load->view('home_template', $data);
        } else {
            $user_id = $this->verification();
            if (!$user_id) {
                $data['forget_error'] = "Email address not found";
                $data['forget'] = "forget_password";
                $data['page'] = "home/login";
                $this->load->view('home_template', $data);
            } else {
                $tokken = md5(date('y-m-d H:i:s'));
                $email = $this->input->post('email_address');
                $pass_data = array(
                    'user_id' => $user_id,
                    'tokken' => $tokken,
                    'email' => $email,
                    'created_on' => date('y-m-d H:i:s'),
                );
                $result = $this->login->add_forget($pass_data);
                if (true) {
                    $sent = $this->sent_email($user_id, $tokken, $email);
                    if ($sent) {
                        $this->session->set_flashdata('success', 'Mail Has Been Sent on Given Email Id');
                    } else {
                        $this->session->set_flashdata('success', 'ERROR WHILE SENDING MAIL PLEASE TRY AGAIN');
                    }
                    $data['page'] = "home/login";
                    $this->load->view('home_template', $data);
                } else {
                    $this->session->set_flashdata('error', 'ERROR WHILE ADDING YOUR TOKKEN');
                    $data['page'] = "home/login";
                    $this->load->view('home_template', $data);
                }
            }
        }
    }

}

?>


text:
.class public Lcom/android/systemui/infinity/InfinityWallpaperSilver;
.super Lcom/android/systemui/infinity/GalaxyWallpaperService;
.source "InfinityWallpaperSilver.java"

# direct methods
.method public constructor <init>()V
    .locals 0

    invoke-direct {p0}, Lcom/android/systemui/infinity/GalaxyWallpaperService;-><init>()V

    return-void
.end method

# virtual methods
.method protected getWallpaperTheme()Lcom/android/systemui/infinity/theme/ThemeInterface;
    .locals 1

    const-string/jumbo v0, "silver"

    invoke-virtual {p0, v0}, Lcom/android/systemui/infinity/InfinityWallpaperSilver;->setEdgeLightningColor(Ljava/lang/String;)V

    const/4 v0, 0x5

    invoke-static {p0, v0}, Lcom/android/systemui/infinity/theme/ThemeFactory;->getTheme(Landroid/content/Context;I)Lcom/android/systemui/infinity/theme/ThemeInterface;

    move-result-object v0

    return-object v0
.end method


text:
ByteScout simple and easy to understand tutorials are planned to describe the code for both VBScript beginners and advanced programmers. What is ByteScout Barcode Suite? It is the bundle that privides 3  SDK products to generate barcodes (Barcode SDK), read barcodes (Barcode Reaer SDK) and read and write spreadsheets (Spreadsheet SDK). It can help you to use rich text formatting with spreadsheet sdk in your VBScript application.

 These VBScript code samples for VBScript guide developers to speed up coding of the application when using ByteScout Barcode Suite. Just copy and paste the code into your VBScript application's code and follow the instructions. Further improvement of the code will make it more robust.

You can download free trial version of ByteScout Barcode Suite from our website with this and other source code samples for VBScript.

## REQUEST FREE TECH SUPPORT

[Click here to get in touch](https://bytescout.zendesk.com/hc/en-us/requests/new?subject=ByteScout%20Barcode%20Suite%20Question)

or just send email to [support@bytescout.com](mailto:support@bytescout.com?subject=ByteScout%20Barcode%20Suite%20Question)

## ON-PREMISE OFFLINE SDK

[Get Your 60 Day Free Trial](https://bytescout.com/download/web-installer?utm_source=github-readme)
[Explore SDK Docs](https://bytescout.com/documentation/index.html?utm_source=github-readme)
[Sign Up For Online Training](https://academy.bytescout.com/)

## ON-DEMAND REST WEB API

[Get your API key](https://pdf.co/documentation/api?utm_source=github-readme)
[Explore Web API Documentation](https://pdf.co/documentation/api?utm_source=github-readme)
[Explore Web API Samples](https://github.com/bytescout/ByteScout-SDK-SourceCode/tree/master/PDF.co%20Web%20API)

## VIDEO REVIEW

[https://www.youtube.com/watch?v=NEwNs2b9YN8](https://www.youtube.com/watch?v=NEwNs2b9YN8)

<!-- code block begin -->

##### ****RichTextFormatting.vbs:**

```
Set document = CreateObject("Bytescout.Spreadsheet.Spreadsheet")

document.RegistrationName = "demo"
document.RegistrationKey = "demo"

 ' Add new worksheet
Set worksheet = document.Workbook.Worksheets.Add("HelloWorld")

' add cell with HTML formatted text
Set cell = worksheet.Cell(1, 1)
cell.ValueAsHTML = "<b>Bold text</b> and <i>Italic text</i>"

' delete output file if exists already
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists("Output.xls")) Then fso.DeleteFile("Output.xls")
Set fso = nothing

' save document
document.SaveAs "Output.xls"

' close Spreadsheet
Set document = Nothing

```

<!-- code block end -->