本文整理汇总了PHP中Document::canView方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::canView方法的具体用法?PHP Document::canView怎么用?PHP Document::canView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document::canView方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMassiveActionsForItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::getMassiveActionsForItemtype()
**/
static function getMassiveActionsForItemtype(array &$actions, $itemtype, $is_deleted = 0, CommonDBTM $checkitem = NULL)
{
global $CFG_GLPI;
$action_prefix = 'Document_Item' . MassiveAction::CLASS_ACTION_SEPARATOR;
if (self::canApplyOn($itemtype)) {
if (Document::canView()) {
$actions[$action_prefix . 'add'] = _x('button', 'Add a document');
$actions[$action_prefix . 'remove'] = _x('button', 'Remove a document');
}
}
if (Toolbox::is_a($itemtype, __CLASS__) && static::canUpdate()) {
$actions[$action_prefix . 'add_item'] = _x('button', 'Add an item');
$actions[$action_prefix . 'remove_item'] = _x('button', 'Remove an item');
}
}
示例2: showListForItem
/**
* @since version 0.90
*
* @param $item
* @param $withtemplate (default '')
* @param $options array
*/
static function showListForItem(CommonDBTM $item, $withtemplate = '', $options = array())
{
global $DB, $CFG_GLPI;
//default options
$params['rand'] = mt_rand();
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$canedit = $item->canAddItem('Document') && Document::canView();
$columns = array('name' => __('Name'), 'entity' => __('Entity'), 'filename' => __('File'), 'link' => __('Web link'), 'headings' => __('Heading'), 'mime' => __('MIME type'));
if ($CFG_GLPI['use_rich_text']) {
$columns['tag'] = __('Tag');
}
$columns['assocdate'] = __('Date');
if (isset($_GET["order"]) && $_GET["order"] == "ASC") {
$order = "ASC";
} else {
$order = "DESC";
}
if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
$sort = "`" . $_GET["sort"] . "`";
} else {
$sort = "`assocdate`";
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
$linkparam = '';
if (get_class($item) == 'Ticket') {
$linkparam = "&tickets_id=" . $item->fields['id'];
}
$query = "SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`items_id` = '" . $item->getID() . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`= '0' ";
}
// Document : search links in both order using union
if ($item->getType() == 'Document') {
$query .= "UNION\n SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`documents_id` = '" . $item->getID() . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`='0' ";
}
}
$query .= " ORDER BY {$sort} {$order}";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$documents = array();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$documents[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
echo "<div class='spaced'>";
if ($canedit && $number && $withtemplate < 2) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $params['rand']);
$massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $params['rand']);
Html::showMassiveActions($massiveactionparams);
}
$sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
echo "<table class='tab_cadre_fixehov'>";
$header_begin = "<tr>";
$header_top = '';
$header_bottom = '';
$header_end = '';
if ($canedit && $number && $withtemplate < 2) {
$header_top .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']);
$header_top .= "</th>";
$header_bottom .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']);
$header_bottom .= "</th>";
}
foreach ($columns as $key => $val) {
$header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>";
}
$header_end .= "</tr>";
echo $header_begin . $header_top . $header_end;
$used = array();
if ($number) {
// Don't use this for document associated to document
// To not loose navigation list for current document
if ($item->getType() != 'Document') {
Session::initNavigateListItems('Document', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
}
$document = new Document();
//.........这里部分代码省略.........
示例3: getItem
/**
* Return the instance fields of itemtype identified by id
*
* @param $itemtype string itemtype (class) of object
* @param $id integer identifier of object
* @param $params array with theses options :
* - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal
* - 'get_hateoas': Show relation of current item in a links attribute. default: true. Optionnal
* - 'get_sha1': Get a sha1 signature instead of the full answer. default: false. Optionnal
* - 'with_components': Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal.
* - 'with_disks': Only for Computer, retrieve the associated filesystems. Optionnal.
* - 'with_softwares': Only for Computer, retrieve the associated softwares installations. Optionnal.
* - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal.
* - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal.
* - 'with_infocoms': Retrieve financial and administrative informations. Optionnal.
* - 'with_contracts': Retrieve associated contracts. Optionnal.
* - 'with_documents': Retrieve associated external documents. Optionnal.
* - 'with_tickets': Retrieve associated itil tickets. Optionnal.
* - 'with_problems': Retrieve associated itil problems. Optionnal.
* - 'with_changes': Retrieve associated itil changes. Optionnal.
* - 'with_notes': Retrieve Notes (if exists, not all itemtypes have notes). Optionnal.
* - 'with_logs': Retrieve historical. Optionnal.
*
* @return array fields of found object
**/
protected function getItem($itemtype, $id, $params = array())
{
global $CFG_GLPI, $DB;
$this->initEndpoint();
// default params
$default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'get_sha1' => false, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false);
$params = array_merge($default, $params);
$item = new $itemtype();
if (!$item->getFromDB($id)) {
return $this->messageNotfoundError();
}
if (!$item->can($id, READ)) {
return $this->messageRightError();
}
$fields = $item->fields;
// avoid disclosure of critical fields
$item::unsetUndisclosedFields($fields);
// retrieve devices
if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) {
$all_devices = array();
foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
$found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'", true);
foreach ($found_devices as $devices_id => &$device) {
unset($device['items_id']);
unset($device['itemtype']);
unset($device['is_deleted']);
}
if (!empty($found_devices)) {
$all_devices[$device_type] = $found_devices;
}
}
$fields['_devices'] = $all_devices;
}
// retrieve computer disks
if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") {
// build query to retrive filesystems
$query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$id}'\n AND `is_deleted` = '0'";
$fields['_disks'] = array();
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
unset($data['computers_id']);
unset($data['is_deleted']);
$fields['_disks'][] = array('name' => $data);
}
}
}
// retrieve computer softwares
if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") {
$fields['_softwares'] = array();
if (!Software::canView()) {
$fields['_softwares'] = self::arrayRightError();
} else {
$query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`id` AS softwares_id,\n `glpi_softwareversions`.`id` AS softwareversions_id,\n `glpi_computers_softwareversions`.`is_dynamic`,\n `glpi_softwareversions`.`states_id`,\n `glpi_softwares`.`is_valid`\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$fields['_softwares'][] = $data;
}
}
}
}
// retrieve item connections
if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") {
$fields['_connections'] = array();
foreach ($CFG_GLPI["directconnect_types"] as $connect_type) {
$connect_item = new $connect_type();
if ($connect_item->canView()) {
$query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n `glpi_computers_items`.`items_id` AS assoc_items_id,\n `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n " . getTableForItemType($connect_type) . ".*\n FROM `glpi_computers_items`\n LEFT JOIN `" . getTableForItemType($connect_type) . "`\n ON (`" . getTableForItemType($connect_type) . "`.`id`\n = `glpi_computers_items`.`items_id`)\n WHERE `computers_id` = '{$id}'\n AND `itemtype` = '" . $connect_type . "'\n AND `glpi_computers_items`.`is_deleted` = '0'";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$fields['_connections'][$connect_type][] = $data;
}
}
}
}
}
//.........这里部分代码省略.........
示例4: showForItem
/**
* Show documents associated to an item
*
* @since version 0.84
*
* @param $item CommonDBTM object for which associated documents must be displayed
* @param $withtemplate (default '')
**/
static function showForItem(CommonDBTM $item, $withtemplate = '')
{
global $DB, $CFG_GLPI;
$ID = $item->getField('id');
if ($item->isNewID($ID)) {
return false;
}
if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && $item->getType() != 'Reminder' && !Session::haveRight('document', 'r')) {
return false;
}
if (!$item->can($item->fields['id'], 'r')) {
return false;
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
$linkparam = '';
if (get_class($item) == 'Ticket') {
$linkparam = "&tickets_id=" . $item->fields['id'];
}
$canedit = $item->canAddItem('Document') && Document::canView();
$rand = mt_rand();
$is_recursive = $item->isRecursive();
if (isset($_POST["order"]) && $_POST["order"] == "ASC") {
$order = "ASC";
} else {
$order = "DESC";
}
if (isset($_POST["sort"]) && !empty($_POST["sort"])) {
$sort = "`" . $_POST["sort"] . "`";
} else {
$sort = "`assocdate`";
}
$query = "SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`items_id` = '{$ID}'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`= '0' ";
}
// Document : search links in both order using union
if ($item->getType() == 'Document') {
$query .= "UNION\n SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`documents_id` = '{$ID}'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`='0' ";
}
}
$query .= " ORDER BY {$sort} {$order} ";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$documents = array();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$documents[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
if ($item->canAddItem('Document') && $withtemplate < 2) {
// Restrict entity for knowbase
$entities = "";
$entity = $_SESSION["glpiactive_entity"];
if ($item->isEntityAssign()) {
/// Case of personal items : entity = -1 : create on active entity (Reminder case))
if ($item->getEntityID() >= 0) {
$entity = $item->getEntityID();
}
if ($item->isRecursive()) {
$entities = getSonsOf('glpi_entities', $entity);
} else {
$entities = $entity;
}
}
$limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
$q = "SELECT COUNT(*)\n FROM `glpi_documents`\n WHERE `is_deleted` = '0'\n {$limit}";
$result = $DB->query($q);
$nb = $DB->result($result, 0, 0);
if ($item->getType() == 'Document') {
$used[$ID] = $ID;
}
echo "<div class='firstbloc'>";
echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center'>";
_e('Heading');
echo '</td><td>';
//.........这里部分代码省略.........
示例5: getAllMassiveActions
/**
* Get the standard massive actions
*
* @since version 0.84
*
* This must not be overloaded in Class
* @param $is_deleted massive action for deleted items ? (default 0)
* @param $checkitem link item to check right (default NULL)
*
* @return an array of massive actions
**/
function getAllMassiveActions($is_deleted = 0, $checkitem = NULL)
{
global $CFG_GLPI, $PLUGIN_HOOKS;
if (!is_null($checkitem)) {
$isadmin = $checkitem->canUpdate();
} else {
$isadmin = static::canUpdate();
}
$itemtype = $this->getType();
$actions = array();
if ($is_deleted) {
if ($isadmin) {
$actions['purge'] = _x('button', 'Delete permanently');
$actions['restore'] = _x('button', 'Restore');
}
} else {
if ($isadmin || in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canUpdate()) {
//TRANS: select action 'update' (before doing it)
$actions['update'] = _x('button', 'Update');
}
if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canCreate()) {
$actions['activate_infocoms'] = __('Enable the financial and administrative information');
}
// No delete for entities and tracking of not have right
if ($isadmin) {
// do not take into account is_deleted if items may be dynamic
if ($this->maybeDeleted() && !$this->useDeletedToLockIfDynamic()) {
$actions['delete'] = _x('button', 'Put in dustbin');
} else {
$actions['purge'] = _x('button', 'Delete permanently');
}
}
if (in_array($itemtype, $CFG_GLPI["document_types"])) {
if (Document::canView()) {
$actions['add_document'] = _x('button', 'Add a document');
$actions['remove_document'] = _x('button', 'Remove a document');
}
}
if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
if (Contract::canUpdate()) {
$actions['add_contract_item'] = _x('button', 'Add a contract');
$actions['remove_contract_item'] = _x('button', 'Remove a contract');
}
}
// Specific actions
$actions += $this->getSpecificMassiveActions($checkitem);
// Plugin Specific actions
if (isset($PLUGIN_HOOKS['use_massive_action'])) {
foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) {
$plug_actions = Plugin::doOneHook($plugin, 'MassiveActions', $itemtype);
if (count($plug_actions)) {
$actions += $plug_actions;
}
}
}
}
//Add unlock if needed
$actions += Lock::getUnlockMassiveActions($itemtype);
// Manage forbidden actions
$forbidden_actions = $this->getForbiddenStandardMassiveAction();
if (is_array($forbidden_actions) && count($forbidden_actions)) {
foreach ($forbidden_actions as $actiontodel) {
if (isset($actions[$actiontodel])) {
unset($actions[$actiontodel]);
}
}
}
return $actions;
}
示例6: showForMassiveAction
/**
* Dropdown of actions for massive action
*
* @param $itemtype item type
* @param $is_deleted massive action for deleted items ?
* @param $extraparams array of extra parameters
**/
static function showForMassiveAction($itemtype, $is_deleted = 0, $extraparams = array())
{
global $LANG, $CFG_GLPI, $PLUGIN_HOOKS;
/// TODO include in CommonDBTM defining only getAdditionalMassiveAction in sub classes
/// for specific actions (return a array of action name and title)
if (!class_exists($itemtype)) {
return false;
}
if ($itemtype == 'NetworkPort') {
echo "<select name='massiveaction' id='massiveaction'>";
echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>";
echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>";
echo "<option value='assign_vlan'>" . $LANG['networking'][55] . "</option>";
echo "<option value='unassign_vlan'>" . $LANG['networking'][58] . "</option>";
// Interest of this massive action ?
// echo "<option value='move'>".$LANG['buttons'][20]."</option>";
echo "</select>";
$params = array('action' => '__VALUE__', 'itemtype' => $itemtype);
ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionPorts.php", $params);
echo "<span id='show_massiveaction'> </span>\n";
} else {
$item = new $itemtype();
$infocom = new Infocom();
$isadmin = $item->canUpdate();
echo "<select name='massiveaction' id='massiveaction'>";
echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>";
if (!in_array($itemtype, $CFG_GLPI["massiveaction_noupdate_types"]) && ($isadmin && $itemtype != 'Ticket' || in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canUpdate() || $itemtype == 'Ticket' && haveRight('update_ticket', 1))) {
echo "<option value='update'>" . $LANG['buttons'][14] . "</option>";
}
if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canCreate()) {
echo "<option value='activate_infocoms'>" . $LANG['financial'][68] . "</option>";
}
if ($is_deleted && !in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"])) {
if ($isadmin) {
echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>";
echo "<option value='restore'>" . $LANG['buttons'][21] . "</option>";
}
} else {
// No delete for entities and tracking of not have right
if (!in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"]) && ($isadmin && $itemtype != 'Ticket' || $itemtype == 'Ticket' && haveRight('delete_ticket', 1))) {
if ($item->maybeDeleted()) {
echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>";
} else {
echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>";
}
}
if ($isadmin && in_array($itemtype, array('Phone', 'Printer', 'Peripheral', 'Monitor'))) {
echo "<option value='connect'>" . $LANG['buttons'][9] . "</option>";
echo "<option value='disconnect'>" . $LANG['buttons'][10] . "</option>";
}
if (in_array($itemtype, $CFG_GLPI["document_types"])) {
$doc = new Document();
if ($doc->canView()) {
echo "<option value='add_document'>" . $LANG['document'][16] . "</option>";
}
}
if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
$contract = new Contract();
if ($contract->canUpdate()) {
echo "<option value='add_contract'>" . $LANG['financial'][36] . "</option>";
}
}
if (haveRight('transfer', 'r') && isMultiEntitiesMode() && in_array($itemtype, array('CartridgeItem', 'Computer', 'ConsumableItem', 'Contact', 'Contract', 'Supplier', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'Software', 'SoftwareLicense', 'Ticket', 'Document', 'Group', 'Link')) && $isadmin) {
echo "<option value='add_transfer_list'>" . $LANG['buttons'][48] . "</option>";
}
switch ($itemtype) {
case 'Software':
if ($isadmin && countElementsInTable("glpi_rules", "sub_type='RuleSoftwareCategory'") > 0) {
echo "<option value='compute_software_category'>" . $LANG['rulesengine'][38] . " " . $LANG['rulesengine'][40] . "</option>";
}
if (haveRight("rule_dictionnary_software", "w") && countElementsInTable("glpi_rules", "sub_type='RuleDictionnarySoftware'") > 0) {
echo "<option value='replay_dictionnary'>" . $LANG['rulesengine'][76] . "</option>";
}
break;
case 'Computer':
if ($isadmin) {
echo "<option value='connect_to_computer'>" . $LANG['buttons'][9] . "</option>";
echo "<option value='install'>" . $LANG['buttons'][4] . "</option>";
if ($CFG_GLPI['use_ocs_mode']) {
if (haveRight("ocsng", "w") || haveRight("sync_ocsng", "w")) {
echo "<option value='force_ocsng_update'>" . $LANG['ocsng'][24] . "</option>";
}
echo "<option value='unlock_ocsng_field'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][16] . "</option>";
echo "<option value='unlock_ocsng_monitor'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][30] . "</option>";
echo "<option value='unlock_ocsng_peripheral'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][32] . "</option>";
echo "<option value='unlock_ocsng_printer'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][34] . "</option>";
echo "<option value='unlock_ocsng_software'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][52] . "</option>";
echo "<option value='unlock_ocsng_ip'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][50] . "</option>";
echo "<option value='unlock_ocsng_disk'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][55] . "</option>";
}
}
break;
case 'Supplier':
//.........这里部分代码省略.........
示例7: showSubFormDocument_Item
static function showSubFormDocument_Item($ID, $params)
{
global $DB, $CFG_GLPI;
$item = new Ticket();
$item->getFromDB($ID);
if (empty($withtemplate)) {
$withtemplate = 0;
}
$linkparam = '';
if (get_class($item) == 'Ticket') {
$linkparam = "&tickets_id=" . $item->fields['id'];
}
$canedit = $item->canAddItem('Document') && Document::canView();
$rand = mt_rand();
$is_recursive = $item->isRecursive();
$order = "DESC";
$sort = "`assocdate`";
$query = "SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`items_id` = '{$ID}'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`= '0' ";
}
// Document : search links in both order using union
if ($item->getType() == 'Document') {
$query .= "UNION\n SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`documents_id` = '{$ID}'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`='0' ";
}
}
$query .= " ORDER BY {$sort} {$order} ";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$documents = array();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$documents[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
if ($item->canAddItem('Document') && $withtemplate < 2) {
// Restrict entity for knowbase
$entities = "";
$entity = $_SESSION["glpiactive_entity"];
if ($item->isEntityAssign()) {
/// Case of personal items : entity = -1 : create on active entity (Reminder case))
if ($item->getEntityID() >= 0) {
$entity = $item->getEntityID();
}
if ($item->isRecursive()) {
$entities = getSonsOf('glpi_entities', $entity);
} else {
$entities = $entity;
}
}
$limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
$q = "SELECT COUNT(*)\n FROM `glpi_documents`\n WHERE `is_deleted` = '0'\n {$limit}";
$result = $DB->query($q);
$nb = $DB->result($result, 0, 0);
if ($item->getType() == 'Document') {
$used[$ID] = $ID;
}
if (!isset($params['no_form']) || $params['no_form'] == false) {
echo "<div class='firstbloc'>";
echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
}
echo "<tr class='tab_bg_1'>";
if (!isset($params['no_form']) || $params['no_form'] == false) {
echo "<td class='center'>";
_e('Heading');
echo "</td><td>";
DocumentCategory::dropdown(array('entity' => $entities));
echo "</td>";
echo "<td class='right'>";
} else {
echo "<td class='center'>" . __('Add a document') . "</td>";
echo "<td style='padding-left:50px'>";
}
echo "<input type='hidden' name='entities_id' value='{$entity}'>";
echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
echo "<input type='hidden' name='items_id' value='{$ID}'>";
if ($item->getType() == 'Ticket') {
echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
}
echo Html::file();
echo "</td><td class='left'>";
echo "(" . Document::getMaxUploadSize() . ") ";
echo "</td>";
if (!isset($params['no_form']) || $params['no_form'] == false) {
echo "<td class='center' width='20%'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n class='submit'></td>";
//.........这里部分代码省略.........
示例8: getItem
/**
* Return the instance fields of itemtype identified by id
*
* @since version 9.1
*
* @param string $itemtype itemtype (class) of object
* @param integer $id identifier of object
* @param array $params array with theses options :
* - 'expand_dropdowns' : show dropdown's names instead of id. default: false. Optionnal
* - 'get_hateoas' : show relation of current item in a links attribute. default: true. Optionnal
* - 'with_components' : Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal.
* - 'with_disks' : Only for Computer, retrieve the associated filesystems. Optionnal.
* - 'with_softwares' : Only for Computer, retrieve the associated softwares installations. Optionnal.
* - 'with_connections' : Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal.
* - 'with_networkports' :Retrieve all network connections and advanced network informations. Optionnal.
* - 'with_infocoms' : Retrieve financial and administrative informations. Optionnal.
* - 'with_contracts' : Retrieve associated contracts. Optionnal.
* - 'with_documents' : Retrieve associated external documents. Optionnal.
* - 'with_tickets' : Retrieve associated itil tickets. Optionnal.
* - 'with_problems' : Retrieve associated itil problems. Optionnal.
* - 'with_changes' : Retrieve associated itil changes. Optionnal.
* - 'with_notes' : Retrieve Notes (if exists, not all itemtypes have notes). Optionnal.
* - 'with_logs' : Retrieve historical. Optionnal.
*
* @return array fields of found object
*/
protected function getItem($itemtype, $id, $params = array())
{
global $CFG_GLPI, $DB;
$this->initEndpoint();
// default params
$default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false);
$params = array_merge($default, $params);
$item = new $itemtype();
if (!$item->getFromDB($id)) {
return $this->messageNotfoundError();
}
if (!$item->can($id, READ)) {
return $this->messageRightError();
}
$fields = $item->fields;
// retrieve devices
if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) {
$all_devices = array();
foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
$found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'", true);
foreach ($found_devices as $devices_id => &$device) {
unset($device['items_id']);
unset($device['itemtype']);
unset($device['is_deleted']);
}
if (!empty($found_devices)) {
$all_devices[$device_type] = $found_devices;
}
}
$fields['_devices'] = $all_devices;
}
// retrieve computer disks
if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") {
// build query to retrive filesystems
$query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$id}'\n AND `is_deleted` = '0'";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
unset($data['computers_id']);
unset($data['is_deleted']);
$fields['_disks'][] = array('name' => $data);
}
}
}
// retrieve computer softwares
if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") {
$fields['_softwares'] = array();
if (!Software::canView()) {
$fields['_softwares'] = self::arrayRightError();
} else {
$query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`id` AS softwares_id,\n `glpi_softwareversions`.`id` AS softwareversions_id,\n `glpi_computers_softwareversions`.`is_dynamic`,\n `glpi_softwareversions`.`states_id`,\n `glpi_softwares`.`is_valid`\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$fields['_softwares'][] = $data;
}
}
}
}
// retrieve item connections
if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") {
$fields['_connections'] = array();
foreach ($CFG_GLPI["directconnect_types"] as $connect_type) {
$connect_item = new $connect_type();
if ($connect_item->canView()) {
$query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n `glpi_computers_items`.`items_id` AS assoc_items_id,\n `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n " . getTableForItemType($connect_type) . ".*\n FROM `glpi_computers_items`\n LEFT JOIN `" . getTableForItemType($connect_type) . "`\n ON (`" . getTableForItemType($connect_type) . "`.`id`\n = `glpi_computers_items`.`items_id`)\n WHERE `computers_id` = '{$id}'\n AND `itemtype` = '" . $connect_type . "'\n AND `glpi_computers_items`.`is_deleted` = '0'";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$fields['_connections'][$connect_type][] = $data;
}
}
}
}
}
// retrieve item networkports
if (isset($params['with_networkports']) && $params['with_networkports']) {
//.........这里部分代码省略.........