本文整理汇总了PHP中getForeignKeyFieldForTable函数的典型用法代码示例。如果您正苦于以下问题:PHP getForeignKeyFieldForTable函数的具体用法?PHP getForeignKeyFieldForTable怎么用?PHP getForeignKeyFieldForTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getForeignKeyFieldForTable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSqlSubRequest
function getSqlSubRequest($itemtype, $loc, $obj)
{
$table = getTableForItemType($itemtype);
$models_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Model'));
$types_id = getForeignKeyFieldForTable(getTableForItemType($itemtype . 'Type'));
$fields = array('name' => 'name', 'serial' => 'serial', 'otherserial' => 'otherserial', $models_id => 'models_id', $types_id => 'types_id');
$query_where = "SELECT '{$itemtype}' AS itemtype,\n `{$table}`.`id` AS items_id,\n `{$table}`.`locations_id`";
foreach ($fields as $field => $alias) {
if ($obj->isField($field)) {
$query_where .= ", `{$table}`.`{$field}` AS {$alias}";
} else {
$query_where .= ", '' AS {$alias}";
}
}
$query_where .= " FROM `{$table}` ";
if ($obj->isEntityAssign()) {
$query_where .= getEntitiesRestrictRequest('WHERE', "{$table}");
} else {
$query_where .= 'WHERE 1';
}
if ($obj->maybeTemplate()) {
$query_where .= " AND `is_template`='0'";
}
if ($obj->maybeDeleted()) {
$query_where .= " AND `is_deleted`='0'";
}
$query_where .= $loc->getSqlCriteriasRestriction();
return $query_where;
}
示例2: postClone
static function postClone(NotificationTemplate $clone, $oldid)
{
global $DB;
$trad = new NotificationTemplateTranslation();
$fkey = getForeignKeyFieldForTable($clone->getTable());
$crit = array($fkey => $oldid);
foreach ($DB->request($trad->getTable(), $crit) as $data) {
unset($data['id']);
$data[$fkey] = $clone->getID();
$trad->add(Toolbox::addslashes_deep($data));
}
}
示例3: pdfDevice
static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer)
{
global $DB;
$devtypes = Item_Devices::getDeviceTypes();
$ID = $computer->getField('id');
if (!$computer->can($ID, 'r')) {
return false;
}
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>');
$pdf->setColumnsSize(3, 14, 42, 41);
foreach ($devtypes as $itemtype) {
$devicetypes = new $itemtype();
$specificities = $devicetypes->getSpecificities();
$specif_fields = array_keys($specificities);
$specif_text = implode(',', $specif_fields);
if (!empty($specif_text)) {
$specif_text = " ," . $specif_text . " ";
}
$associated_type = str_replace('Item_', '', $itemtype);
$linktable = getTableForItemType($itemtype);
$fk = getForeignKeyFieldForTable(getTableForItemType($associated_type));
$query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n FROM `" . $linktable . "`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = 'Computer'\n GROUP BY `" . $fk . "`" . $specif_text;
$device = new $associated_type();
foreach ($DB->request($query) as $data) {
if ($device->getFromDB($data[$fk])) {
$spec = $device->getAdditionalFields();
$col4 = '';
if (count($spec)) {
$colspan = 60 / count($spec);
foreach ($spec as $i => $label) {
if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) {
if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) {
$table = getTableNameForForeignKeyField($label["name"]);
$value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]);
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " ");
} else {
$value = $device->fields[$label["name"]];
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " ");
}
} else {
if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) {
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " ");
}
}
}
}
$pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4);
}
}
}
$pdf->displaySpace();
}
示例4: processAfterInsertOrUpdate
/**
* @param $values
* @param $add (true by default)
* @param $rights array
**/
function processAfterInsertOrUpdate($values, $add = true, $rights = array())
{
if (isset($values['Computer']['id'])) {
$class = "Item_" . get_parent_class($this);
$item = new $class();
$foreign = getForeignKeyFieldForTable(getTableForItemType(get_parent_class($this)));
if (!countElementsInTable($item->getTable(), "`{$foreign}`='" . $values[get_parent_class($this)]['id'] . "'\n AND `itemtype`='Computer'\n AND `items_id`='" . $values['Computer']['id'] . "'")) {
$tmp[$foreign] = $values[get_parent_class($this)]['id'];
$tmp['items_id'] = $values['Computer']['id'];
$tmp['itemtype'] = 'Computer';
$item->add($tmp);
}
}
}
示例5: postClone
static function postClone(Rule $clone, $oldid)
{
global $DB;
$fkey = getForeignKeyFieldForTable($clone->getTable());
$crit = array($fkey => $oldid);
$criteria = new RuleCriteria();
foreach ($DB->request($criteria->getTable(), $crit) as $data) {
unset($data['id']);
$data[$fkey] = $clone->getID();
$criteria->add(Toolbox::addslashes_deep($data));
}
$action = new RuleAction();
foreach ($DB->request($action->getTable(), $crit) as $data) {
unset($data['id']);
$data[$fkey] = $clone->getID();
$action->add(Toolbox::addslashes_deep($data));
}
}
示例6: dropdown_getTypeName
function dropdown_getTypeName($class, $nb = 0)
{
global $GO_FIELDS;
$fk = getForeignKeyFieldForTable(getTableForItemType($class));
$instance = new $class();
$options = PluginGenericobjectField::getFieldOptions($fk, $instance->linked_itemtype);
$dropdown_type = isset($options['dropdown_type']) ? $options['dropdown_type'] : null;
$label = $options['name'];
if (!is_null($dropdown_type) and $dropdown_type === 'isolated') {
$linked_itemtype_object = new $instance->linked_itemtype();
$label .= " (" . __($linked_itemtype_object::getTypeName(), 'genericobject') . ")";
}
if ($label != '') {
return $label;
} else {
return $class;
}
}
示例7: getOptions
/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions()
**/
function getOptions($primary_type = '')
{
$tab = Search::getOptions(get_parent_class($this));
$tab[4]['checktype'] = 'mac';
//To manage vlans : relies on a CommonDBRelation object !
$tab[51]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Device name'));
$tab[51]['field'] = 'netname';
$tab[51]['table'] = getTableForItemType('NetworkPort');
$tab[51]['linkfield'] = "netname";
$tab[51]['injectable'] = true;
$tab[51]['displaytype'] = 'text';
$tab[51]['checktype'] = 'text';
$tab[52]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Port number'));
$tab[52]['field'] = 'netport';
$tab[52]['table'] = getTableForItemType('NetworkPort');
$tab[52]['linkfield'] = "netport";
$tab[52]['injectable'] = true;
$tab[52]['displaytype'] = 'text';
$tab[52]['checktype'] = 'text';
$tab[53]['name'] = sprintf(__('%1$s: %2$s'), __('Connected to'), __('Port MAC address', 'datainjection'));
$tab[53]['field'] = 'netmac';
$tab[53]['table'] = getTableForItemType('NetworkPort');
$tab[53]['linkfield'] = "netmac";
$tab[53]['injectable'] = true;
$tab[53]['displaytype'] = 'text';
$tab[53]['checktype'] = 'text';
//To manage vlans : relies on a CommonDBRelation object !
$tab[100]['name'] = __('VLAN');
$tab[100]['field'] = 'name';
$tab[100]['table'] = getTableForItemType('Vlan');
$tab[100]['linkfield'] = getForeignKeyFieldForTable($tab[100]['table']);
$tab[100]['displaytype'] = 'relation';
$tab[100]['relationclass'] = 'NetworkPort_Vlan';
$tab[100]['storevaluein'] = $tab[100]['linkfield'];
$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this));
$notimportable = array(20, 21);
$options['ignore_fields'] = array_merge($blacklist, $notimportable);
$options['displaytype'] = array("dropdown" => array(9), "multiline_text" => array(16), "instantiation_type" => array(87));
return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this);
}
示例8: getOptions
/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions()
**/
function getOptions($primary_type = '')
{
$tab = Search::getOptions(get_parent_class($this));
//Specific to location
$tab[1]['linkfield'] = 'name';
$tab[3]['linkfield'] = 'locations_id';
//Manage password
$tab[4]['table'] = $this->getTable();
$tab[4]['field'] = 'password';
$tab[4]['linkfield'] = 'password';
$tab[4]['name'] = __('Password');
$tab[4]['displaytype'] = 'password';
$tab[5]['displaytype'] = 'text';
//To manage groups : relies on a CommonDBRelation object !
$tab[100]['name'] = __('Group');
$tab[100]['field'] = 'name';
$tab[100]['table'] = getTableForItemType('Group');
$tab[100]['linkfield'] = getForeignKeyFieldForTable($tab[100]['table']);
$tab[100]['displaytype'] = 'relation';
$tab[100]['relationclass'] = 'Group_User';
$tab[100]['relationfield'] = $tab[100]['linkfield'];
//To manage groups : relies on a CommonDBRelation object !
$tab[101]['name'] = __('Profile');
$tab[101]['field'] = 'name';
$tab[101]['table'] = getTableForItemType('Profile');
$tab[101]['linkfield'] = getForeignKeyFieldForTable($tab[101]['table']);
$tab[101]['displaytype'] = 'relation';
$tab[101]['relationclass'] = 'Profile_User';
$tab[101]['relationfield'] = $tab[101]['linkfield'];
//Remove some options because some fields cannot be imported
$blacklist = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this));
$notimportable = array(13, 14, 15, 17, 20, 23, 30, 31, 60, 61, 77, 91, 92, 93);
$options['ignore_fields'] = array_merge($blacklist, $notimportable);
//Add displaytype value
$options['displaytype'] = array("dropdown" => array(3, 79, 81, 82), "multiline_text" => array(16), "bool" => array(8), "password" => array(4));
return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this);
}
示例9: array
//.........这里部分代码省略.........
$search[$itemtype][24]['table'] = 'glpi_users';
$search[$itemtype][24]['field'] = 'name';
$search[$itemtype][24]['linkfield'] = 'users_id_tech';
$search[$itemtype][24]['name'] = __('Technician in charge of the hardware');
$search[$itemtype][80]['table'] = 'glpi_entities';
$search[$itemtype][80]['field'] = 'completename';
$search[$itemtype][80]['name'] = __('Entity');
break;
default:
if ($item = getItemForItemtype($itemtype)) {
$search[$itemtype] = $item->getSearchOptions();
}
break;
}
if (Session::getLoginUserID() && in_array($itemtype, $CFG_GLPI["ticket_types"])) {
$search[$itemtype]['tracking'] = __('Assistance');
$search[$itemtype][60]['table'] = 'glpi_tickets';
$search[$itemtype][60]['field'] = 'id';
$search[$itemtype][60]['datatype'] = 'count';
$search[$itemtype][60]['name'] = _x('quantity', 'Number of tickets');
$search[$itemtype][60]['forcegroupby'] = true;
$search[$itemtype][60]['usehaving'] = true;
$search[$itemtype][60]['massiveaction'] = false;
$search[$itemtype][60]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_tickets', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
$search[$itemtype][140]['table'] = 'glpi_problems';
$search[$itemtype][140]['field'] = 'id';
$search[$itemtype][140]['datatype'] = 'count';
$search[$itemtype][140]['name'] = _x('quantity', 'Number of problems');
$search[$itemtype][140]['forcegroupby'] = true;
$search[$itemtype][140]['usehaving'] = true;
$search[$itemtype][140]['massiveaction'] = false;
$search[$itemtype][140]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_problems', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
}
if (in_array($itemtype, $CFG_GLPI["networkport_types"]) || $itemtype == 'AllAssets') {
$search[$itemtype] += NetworkPort::getSearchOptionsToAdd($itemtype);
}
if (in_array($itemtype, $CFG_GLPI["contract_types"]) || $itemtype == 'AllAssets') {
$search[$itemtype] += Contract::getSearchOptionsToAdd();
}
if (Document::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
$search[$itemtype] += Document::getSearchOptionsToAdd();
}
if (InfoCom::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
$search[$itemtype] += Infocom::getSearchOptionsToAdd($itemtype);
}
if (in_array($itemtype, $CFG_GLPI["link_types"])) {
$search[$itemtype]['link'] = _n('External link', 'External links', Session::getPluralNumber());
$search[$itemtype] += Link::getSearchOptionsToAdd($itemtype);
}
if ($withplugins) {
// Search options added by plugins
$plugsearch = Plugin::getAddSearchOptions($itemtype);
if (count($plugsearch)) {
$search[$itemtype] += array('plugins' => _n('Plugin', 'Plugins', Session::getPluralNumber()));
$search[$itemtype] += $plugsearch;
}
}
// Complete linkfield if not define
if (is_null($item)) {
// Special union type
$itemtable = $CFG_GLPI['union_search_type'][$itemtype];
} else {
if ($item = getItemForItemtype($itemtype)) {
$itemtable = $item->getTable();
}
}
foreach ($search[$itemtype] as $key => $val) {
if (!is_array($val)) {
// skip sub-menu
continue;
}
// Compatibility before 0.80 : Force massive action to false if linkfield is empty :
if (isset($val['linkfield']) && empty($val['linkfield'])) {
$search[$itemtype][$key]['massiveaction'] = false;
}
// Set default linkfield
if (!isset($val['linkfield']) || empty($val['linkfield'])) {
if (strcmp($itemtable, $val['table']) == 0 && (!isset($val['joinparams']) || count($val['joinparams']) == 0)) {
$search[$itemtype][$key]['linkfield'] = $val['field'];
} else {
$search[$itemtype][$key]['linkfield'] = getForeignKeyFieldForTable($val['table']);
}
}
// Set default datatype
// if (!isset($val['datatype']) || empty($val['datatype'])) {
// if ((strcmp($itemtable,$val['table']) != 0)
// && ($val['field'] == 'name' || $val['field'] == 'completename')) {
// $search[$itemtype][$key]['datatype'] = 'dropdown';
// } else {
// $search[$itemtype][$key]['datatype'] = 'string';
// }
// }
// Add default joinparams
if (!isset($val['joinparams'])) {
$search[$itemtype][$key]['joinparams'] = array();
}
}
}
return $search[$itemtype];
}
示例10: addDropdownTable
/**
* Add a new dropdown table
* @param table the table name
* @param entity_assign can the dropdown be assigned to an entity
* @param recursive can the dropdown be recursive
* @param tree can the dropdown be a tree dropdown
* @return nothing
*/
public static function addDropdownTable($table, $options = array())
{
global $DB;
$params['entities_id'] = false;
$params['is_recursive'] = false;
$params['is_tree'] = false;
foreach ($options as $key => $value) {
$params[$key] = $value;
}
if (!TableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);
}
if ($params['entities_id']) {
$query = "ALTER TABLE `{$table}` ADD `entities_id` INT(11) NOT NULL DEFAULT '0'";
$DB->query($query);
if ($params['is_recursive']) {
$query = "ALTER TABLE `{$table}` " . "ADD `is_recursive` TINYINT(1) NOT NULL DEFAULT '0' AFTER `entities_id`";
$DB->query($query);
}
}
if ($params['is_tree']) {
$fk = getForeignKeyFieldForTable($table);
$query = "ALTER TABLE `{$table}` ADD `completename` text COLLATE utf8_unicode_ci,\n ADD `{$fk}` int(11) NOT NULL DEFAULT '0',\n ADD `level` int(11) NOT NULL DEFAULT '0',\n ADD `ancestors_cache` longtext COLLATE utf8_unicode_ci,\n ADD `sons_cache` longtext COLLATE utf8_unicode_ci";
$DB->query($query);
}
}
示例11: update0723to078
//.........这里部分代码省略.........
$query = "UPDATE `glpi_rulecriterias`\n SET `criteria`='urgency'\n WHERE `criteria`='priority'\n AND `rules_id` IN (SELECT `id`\n FROM `glpi_rules`\n WHERE `sub_type` = 'RuleTicket')";
$DB->queryOrDie($query, "0.78 fix priority/urgency in business rules");
}
if (!TableExists('glpi_tickettasks')) {
$query = "CREATE TABLE `glpi_tickettasks` (\n `id` int(11) NOT NULL auto_increment,\n `tickets_id` int(11) NOT NULL default '0',\n `taskcategories_id` int(11) NOT NULL default '0',\n `date` datetime default NULL,\n `users_id` int(11) NOT NULL default '0',\n `content` longtext collate utf8_unicode_ci,\n `is_private` tinyint(1) NOT NULL default '0',\n `realtime` float NOT NULL default '0',\n PRIMARY KEY (`id`),\n KEY `date` (`date`),\n KEY `users_id` (`users_id`),\n KEY `tickets_id` (`tickets_id`),\n KEY `is_private` (`is_private`),\n KEY `taskcategories_id` (`taskcategories_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.78 create glpi_tickettasks");
// Required for migration from ticketfollowups to tickettasks - planned followups
$query = "INSERT INTO `glpi_tickettasks`\n (`id`, `tickets_id`, `date`, `users_id`, `content`, `is_private`, `realtime`)\n SELECT `glpi_ticketfollowups`.`id`,\n `glpi_ticketfollowups`.`tickets_id`,\n `glpi_ticketfollowups`.`date`,\n `glpi_ticketfollowups`.`users_id`,\n `glpi_ticketfollowups`.`content`,\n `glpi_ticketfollowups`.`is_private`,\n `glpi_ticketfollowups`.`realtime`\n FROM `glpi_ticketfollowups`\n INNER JOIN `glpi_ticketplannings`\n ON (`glpi_ticketplannings`.`ticketfollowups_id` = `glpi_ticketfollowups`.`id`)";
$DB->queryOrDie($query, "0.78 populate glpi_tickettasks");
// delete from ticketfollowups - planned followups, previously copied
$query = "DELETE FROM `glpi_ticketfollowups`\n WHERE `glpi_ticketfollowups`.`id`\n IN (SELECT `glpi_ticketplannings`.`ticketfollowups_id`\n FROM `glpi_ticketplannings`)";
$DB->queryOrDie($query, "0.78 delete from glpi_ticketfollowups");
// Required for migration from ticketfollowups to tickettasks - followups with a duration
$query = "INSERT INTO `glpi_tickettasks`\n (`id`, `tickets_id`, `date`, `users_id`, `content`, `is_private`, `realtime`)\n SELECT `glpi_ticketfollowups`.`id`,\n `glpi_ticketfollowups`.`tickets_id`,\n `glpi_ticketfollowups`.`date`,\n `glpi_ticketfollowups`.`users_id`,\n `glpi_ticketfollowups`.`content`,\n `glpi_ticketfollowups`.`is_private`,\n `glpi_ticketfollowups`.`realtime`\n FROM `glpi_ticketfollowups`\n WHERE `realtime`>0";
$DB->queryOrDie($query, "0.78 populate glpi_tickettasks");
// delete from ticketfollowups - followups with duration, previously copied
$query = "DELETE FROM `glpi_ticketfollowups`\n WHERE `realtime` > 0";
$DB->queryOrDie($query, "0.78 delete from glpi_ticketfollowups");
// ticketplannings is for tickettasks
$query = "ALTER TABLE `glpi_ticketplannings`\n CHANGE `ticketfollowups_id` `tickettasks_id` int(11) NOT NULL default '0'";
$DB->queryOrDie($query, "0.78 alter glpi_ticketplannings");
// add requesttype for glpi_ticketfollowups
$query = "ALTER TABLE `glpi_ticketfollowups`\n DROP `realtime`,\n ADD `requesttypes_id` int(11) NOT NULL default '0',\n ADD INDEX `requesttypes_id` (`requesttypes_id`)";
$DB->queryOrDie($query, "0.78 alter glpi_ticketplannings");
}
// Migrate devices
if (TableExists('glpi_computer_device')) {
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), _n('Component', 'Components', 2)));
foreach ($devtypetoname as $key => $itemtype) {
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), $itemtype));
$linktype = "Computer_{$itemtype}";
$linktable = getTableForItemType($linktype);
$itemtable = getTableForItemType($itemtype);
$fkname = getForeignKeyFieldForTable($itemtable);
$withspecifity = array(MOBOARD_DEVICE => false, PROCESSOR_DEVICE => 'int', RAM_DEVICE => 'int', HDD_DEVICE => 'int', NETWORK_DEVICE => 'varchar', DRIVE_DEVICE => false, CONTROL_DEVICE => false, GFX_DEVICE => 'int', SND_DEVICE => false, PCI_DEVICE => false, CASE_DEVICE => false, POWER_DEVICE => false);
if (FieldExists($itemtable, 'specif_default', false)) {
// Convert default specifity
if ($withspecifity[$key]) {
// Convert data to int
if ($withspecifity[$key] == 'int') {
// clean non integer values
$query = "UPDATE `{$itemtable}`\n SET `specif_default` = 0\n WHERE `specif_default` NOT REGEXP '^[0-9]*\$'\n OR `specif_default` = ''\n OR `specif_default` IS NULL";
$DB->queryOrDie($query, "0.78 update specif_default in {$itemtable}");
$query = "ALTER TABLE `{$itemtable}`\n CHANGE `specif_default` `specif_default` INT(11) NOT NULL";
$DB->queryOrDie($query, "0.78 alter specif_default in {$itemtable}");
}
} else {
// Drop default specificity
$query = "ALTER TABLE `{$itemtable}`\n DROP `specif_default`";
$DB->queryOrDie($query, "0.78 drop specif_default in {$itemtable}");
}
}
if (!TableExists($linktable)) {
// create table
$query = "CREATE TABLE `{$linktable}` (\n `id` int(11) NOT NULL auto_increment,\n `computers_id` int(11) NOT NULL default '0',\n `{$fkname}` int(11) NOT NULL default '0',";
if ($withspecifity[$key]) {
if ($withspecifity[$key] == 'int') {
$query .= "`specificity` int(11) NOT NULL,";
} else {
$query .= "`specificity` varchar(255) collate utf8_unicode_ci default NULL,";
}
}
$query .= "PRIMARY KEY (`id`),\n KEY `computers_id` (`computers_id`),\n KEY `{$fkname}` (`{$fkname}`)";
if ($withspecifity[$key]) {
$query .= ",KEY `specificity` (`specificity`)";
}
示例12: replayRulesOnExistingDBForModel
/**
* Replay collection rules on an existing DB for model dropdowns
*
* @param $offset offset used to begin (default 0)
* @param $maxtime maximum time of process (reload at the end) (default 0)
*
* @return -1 on completion else current offset
**/
function replayRulesOnExistingDBForModel($offset = 0, $maxtime = 0)
{
global $DB;
if (isCommandLine()) {
printf(__('Replay rules on existing database started on %s') . "\n", date("r"));
}
// Model check : need to check using manufacturer extra data
if (strpos($this->item_table, 'models') === false) {
_e('Error replaying rules');
return false;
}
$model_table = getPlural(str_replace('models', '', $this->item_table));
$model_field = getForeignKeyFieldForTable($this->item_table);
// Need to give manufacturer from item table
$Sql = "SELECT DISTINCT `glpi_manufacturers`.`id` AS idmanu,\n `glpi_manufacturers`.`name` AS manufacturer,\n `" . $this->item_table . "`.`id`,\n `" . $this->item_table . "`.`name` AS name,\n `" . $this->item_table . "`.`comment`\n FROM `" . $this->item_table . "`,\n `{$model_table}`\n LEFT JOIN `glpi_manufacturers`\n ON (`{$model_table}`.`manufacturers_id` = `glpi_manufacturers`.`id`)\n WHERE `{$model_table}`.`{$model_field}` = `" . $this->item_table . "`.`id`";
if ($offset) {
$Sql .= " LIMIT " . intval($offset) . ",999999999";
}
$result = $DB->query($Sql);
$nb = $DB->numrows($result) + $offset;
$i = $offset;
if ($result && $nb > $offset) {
// Step to refresh progressbar
$step = $nb > 20 ? floor($nb / 20) : 1;
$tocheck = array();
while ($data = $DB->fetch_assoc($result)) {
if (!($i % $step)) {
if (isCommandLine()) {
printf(__('Replay rules on existing database: %1$s/%2$s') . "\r", $i, $nb);
} else {
Html::changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
}
}
// Model case
if (isset($data["manufacturer"])) {
$data["manufacturer"] = Manufacturer::processName(addslashes($data["manufacturer"]));
}
//Replay Type dictionnary
$ID = Dropdown::importExternal(getItemTypeForTable($this->item_table), addslashes($data["name"]), -1, $data, addslashes($data["comment"]));
if ($data['id'] != $ID) {
$tocheck[$data["id"]][] = $ID;
$sql = "UPDATE `{$model_table}`\n SET `{$model_field}` = '{$ID}'\n WHERE `{$model_field}` = '" . $data['id'] . "'";
if (empty($data['idmanu'])) {
$sql .= " AND (`manufacturers_id` IS NULL\n OR `manufacturers_id` = '0')";
} else {
$sql .= " AND `manufacturers_id` = '" . $data['idmanu'] . "'";
}
$DB->query($sql);
}
$i++;
if ($maxtime) {
$crt = explode(" ", microtime());
if ($crt[0] + $crt[1] > $maxtime) {
break;
}
}
}
foreach ($tocheck as $ID => $tab) {
$sql = "SELECT COUNT(*)\n FROM `{$model_table}`\n WHERE `{$model_field}` = '{$ID}'";
$result = $DB->query($sql);
$deletecartmodel = false;
// No item left : delete old item
if ($result && $DB->result($result, 0, 0) == 0) {
$Sql = "DELETE\n FROM `" . $this->item_table . "`\n WHERE `id` = '{$ID}'";
$resdel = $DB->query($Sql);
$deletecartmodel = true;
}
// Manage cartridge assoc Update items
if ($this->getRuleClassName() == 'RuleDictionnaryPrinterModel') {
$sql = "SELECT *\n FROM `glpi_cartridgeitems_printermodels`\n WHERE `printermodels_id` = '{$ID}'";
if ($result = $DB->query($sql)) {
if ($DB->numrows($result)) {
// Get compatible cartridge type
$carttype = array();
while ($data = $DB->fetch_assoc($result)) {
$carttype[] = $data['cartridgeitems_id'];
}
// Delete cartrodges_assoc
if ($deletecartmodel) {
$sql = "DELETE\n FROM `glpi_cartridgeitems_printermodels`\n WHERE `printermodels_id` = 'id'";
$DB->query($sql);
}
// Add new assoc
$ct = new CartridgeItem();
foreach ($carttype as $cartID) {
foreach ($tab as $model) {
$ct->addCompatibleType($cartID, $model);
}
}
}
}
}
//.........这里部分代码省略.........
示例13: cleanForItemActionOrCriteria
/**
* Clean Rule with Action or Criteria linked to an item
*
* @param $item Object
* @param $field string name (default is FK to item)
* @param $ruleitem object (instance of Rules of SlaLevel)
* @param $table string (glpi_ruleactions, glpi_rulescriterias or glpi_slalevelcriterias)
* @param $valfield string (value or pattern)
* @param $fieldfield string (criteria of field)
**/
private static function cleanForItemActionOrCriteria($item, $field, $ruleitem, $table, $valfield, $fieldfield)
{
global $DB;
$fieldid = getForeignKeyFieldForTable($ruleitem->getTable());
if (empty($field)) {
$field = getForeignKeyFieldForTable($item->getTable());
}
if (isset($item->input['_replace_by']) && $item->input['_replace_by'] > 0) {
$query = "UPDATE `{$table}`\n SET `{$valfield}` = '" . $item->input['_replace_by'] . "'\n WHERE `{$valfield}` = '" . $item->getField('id') . "'\n AND `{$fieldfield}` LIKE '{$field}'";
$DB->query($query);
} else {
$query = "SELECT `{$fieldid}`\n FROM `{$table}`\n WHERE `{$valfield}` = '" . $item->getField('id') . "'\n AND `{$fieldfield}` LIKE '{$field}'";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
$input['is_active'] = 0;
while ($data = $DB->fetch_assoc($result)) {
$input['id'] = $data[$fieldid];
$ruleitem->update($input);
}
Session::addMessageAfterRedirect(__('Rules using the object have been disabled.'), true);
}
}
}
}
示例14: canUnrecurs
/**
* Can I change recusvive flag to false
* check if there is "linked" object in another entity
*
* May be overloaded if needed
*
* @return booleen
**/
function canUnrecurs()
{
global $DB, $CFG_GLPI;
$ID = $this->fields['id'];
if ($ID < 0 || !$this->fields['is_recursive']) {
return true;
}
$entities = "('" . $this->fields['entities_id'] . "'";
foreach (getAncestorsOf("glpi_entities", $this->fields['entities_id']) as $papa) {
$entities .= ",'{$papa}'";
}
$entities .= ")";
$RELATION = getDbRelations();
if ($this instanceof CommonTreeDropdown) {
$f = getForeignKeyFieldForTable($this->getTable());
if (countElementsInTable($this->getTable(), "`{$f}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
return false;
}
}
if (isset($RELATION[$this->getTable()])) {
foreach ($RELATION[$this->getTable()] as $tablename => $field) {
$itemtype = getItemTypeForTable($tablename);
$item = new $itemtype();
if ($item->isEntityAssign()) {
// 1->N Relation
if (is_array($field)) {
foreach ($field as $f) {
if (countElementsInTable($tablename, "`{$f}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
return false;
}
}
} else {
if (countElementsInTable($tablename, "`{$field}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
return false;
}
}
} else {
foreach ($RELATION as $othertable => $rel) {
// Search for a N->N Relation with devices
if ($othertable == "_virtual_device" && isset($rel[$tablename])) {
$devfield = $rel[$tablename][0];
// items_id...
$typefield = $rel[$tablename][1];
// itemtype...
$sql = "SELECT DISTINCT `{$typefield}` AS itemtype\n FROM `{$tablename}`\n WHERE `{$field}`='{$ID}'";
$res = $DB->query($sql);
// Search linked device of each type
if ($res) {
while ($data = $DB->fetch_assoc($res)) {
$itemtype = $data["itemtype"];
$itemtable = getTableForItemType($itemtype);
$item = new $itemtype();
if ($item->isEntityAssign()) {
if (countElementsInTable(array($tablename, $itemtable), "`{$tablename}`.`{$field}`='{$ID}'\n AND `{$tablename}`.`{$typefield}`='{$itemtype}'\n AND `{$tablename}`.`{$devfield}`=`{$itemtable}`.id\n AND `{$itemtable}`.`entities_id`\n NOT IN {$entities}") > '0') {
return false;
}
}
}
}
// Search for another N->N Relation
} else {
if ($othertable != $this->getTable() && isset($rel[$tablename])) {
$itemtype = getItemTypeForTable($othertable);
$item = new $itemtype();
if ($item->isEntityAssign()) {
if (is_array($rel[$tablename])) {
foreach ($rel[$tablename] as $otherfield) {
if (countElementsInTable(array($tablename, $othertable), "`{$tablename}`.`{$field}`='{$ID}'\n AND `{$tablename}`.`{$otherfield}`\n =`{$othertable}`.id\n AND `{$othertable}`.`entities_id`\n NOT IN {$entities}") > '0') {
return false;
}
}
} else {
$otherfield = $rel[$tablename];
if (countElementsInTable(array($tablename, $othertable), "`{$tablename}`.`{$field}`={$ID}\n AND `{$tablename}`.`{$otherfield}`=`{$othertable}`.id\n AND `{$othertable}`.`entities_id`\n NOT IN {$entities}") > '0') {
return false;
}
}
}
}
}
}
}
}
}
// Doc links to this item
if ($this->getType() > 0 && countElementsInTable(array('glpi_documents_items', 'glpi_documents'), "`glpi_documents_items`.`items_id`='{$ID}'\n AND `glpi_documents_items`.`itemtype`=" . $this->getType() . "\n AND `glpi_documents_items`.`documents_id`=`glpi_documents`.`id`\n AND `glpi_documents`.`entities_id` NOT IN {$entities}") > '0') {
return false;
}
// TODO : do we need to check all relations in $RELATION["_virtual_device"] for this item
return true;
}
示例15: generatePdf
function generatePdf($itemtype, $data, $saveas)
{
global $CFG_GLPI, $PDF, $DB;
$ID = $data["id"];
//name
if (!empty($data["name"])) {
$name_item = Toolbox::decodeFromUtf8($data["name"]);
} else {
$name_item = "";
}
//user
if (!empty($data["users_id"])) {
$user_item = Toolbox::decodeFromUtf8(Html::clean(getUserName($data["users_id"])));
} else {
if (!empty($data["groups_id"])) {
$user_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_groups", $data["groups_id"]));
} else {
$user_item = "";
}
}
//fabricant
if (!empty($data["manufacturers_id"])) {
$fabricant_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]));
} else {
$fabricant_item = "";
}
//serial
if (!empty($data["serial"])) {
$serial_item = Toolbox::decodeFromUtf8($data["serial"]);
} else {
$serial_item = "";
}
$class = $itemtype . "Type";
$item = new $class();
$typefield = getForeignKeyFieldForTable(getTableForItemType($itemtype . "Type"));
$item->getFromDB($data[$typefield]);
if (!empty($typefield) && !empty($item->fields["name"])) {
$type_item = Toolbox::decodeFromUtf8($item->fields["name"]);
} else {
$type_item = "";
}
//infocoms
$ic = new Infocom();
if ($ic->getfromDBforDevice($itemtype, $ID)) {
//immobilizationsheets_item
if (!empty($ic->fields["immo_number"])) {
$immobilizationsheets_item = Toolbox::decodeFromUtf8($ic->fields["immo_number"]);
} else {
$immobilizationsheets_item = "";
}
//buy_date
if (!empty($ic->fields["buy_date"])) {
$buy_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["buy_date"]));
} else {
$buy_date_item = "";
}
//use_date
if (!empty($ic->fields["use_date"])) {
$use_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["use_date"]));
} else {
$use_date_item = "";
}
//order_number
if (!empty($ic->fields["order_number"])) {
$order_number_item = Toolbox::decodeFromUtf8($ic->fields["order_number"]);
} else {
$order_number_item = "";
}
//value_item
if (!empty($ic->fields["value"])) {
$value_item = Toolbox::decodeFromUtf8(Html::clean(Html::formatNumber($ic->fields["value"])));
} else {
$value_item = "";
}
//sink_time
if (!empty($ic->fields["sink_time"])) {
$sink_time_item = Toolbox::decodeFromUtf8(sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]));
} else {
$sink_time_item = "";
}
//sink_type
if (!empty($ic->fields["sink_type"])) {
$sink_type_item = Toolbox::decodeFromUtf8(Infocom::getAmortTypeName($ic->fields["sink_type"]));
} else {
$sink_type_item = "";
}
} else {
$immobilizationsheets_item = "";
$buy_date_item = "";
$use_date_item = "";
$order_number_item = "";
$value_item = "";
$sink_time_item = "";
$sink_type_item = "";
}
//composants
$devtypes = self::getDeviceTypes();
if ($itemtype == 'Computer') {
$device2 = new $devtypes[2]();
$query2 = "SELECT `deviceprocessors_id`\n FROM `" . getTableForItemType('items_' . $devtypes[2]) . "`\n WHERE `items_id` = '{$ID}'";
//.........这里部分代码省略.........