本文整理汇总了PHP中CommonDBTM::can方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonDBTM::can方法的具体用法?PHP CommonDBTM::can怎么用?PHP CommonDBTM::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonDBTM
的用法示例。
在下文中一共展示了CommonDBTM::can方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'add':
$input = $ma->getInput();
$ticket = new Ticket();
if (isset($input['link']) && isset($input['tickets_id_1'])) {
if ($item->getFromDB($input['tickets_id_1'])) {
foreach ($ids as $id) {
$input2 = array();
$input2['id'] = $input['tickets_id_1'];
$input2['_link']['tickets_id_1'] = $input['tickets_id_1'];
$input2['_link']['link'] = $input['link'];
$input2['_link']['tickets_id_2'] = $id;
if ($item->can($input['tickets_id_1'], UPDATE)) {
if ($ticket->update($input2)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例2: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'backtostock':
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
if ($item->backToStock(array("id" => $id))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
return;
case 'give':
$input = $ma->getInput();
if ($input["give_items_id"] > 0 && !empty($input['give_itemtype'])) {
foreach ($ids as $key) {
if ($item->can($key, UPDATE)) {
if ($item->out($key, $input['give_itemtype'], $input["give_items_id"])) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
Event::log($item->fields['consumableitems_id'], "consumables", 5, "inventory", sprintf(__('%s gives a consumable'), $_SESSION["glpiname"]));
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例3: showForItem
/**
* \brief Show names for an item from its form
* Beware that the rendering can be different if readden from direct item form (ie : add new
* NetworkName, remove, ...) or if readden from item of the item (for instance from the computer
* form through NetworkPort::ShowForItem).
*
* @param $item CommonGLPI object
* @param $withtemplate integer withtemplate param (default 0)
**/
static function showForItem(CommonDBTM $item, $withtemplate = 0)
{
global $DB, $CFG_GLPI;
$ID = $item->getID();
if (!$item->can($ID, READ)) {
return false;
}
$rand = mt_rand();
if ($item->getType() == 'NetworkPort' && Session::haveRight('internet', UPDATE) && $item->canUpdateItem()) {
$items_id = $item->getID();
$itemtype = $item->getType();
echo "<div class='firstbloc'>\n";
echo "<form method='post' action='" . static::getFormURL() . "'>\n";
echo "<table class='tab_cadre_fixe'>\n";
echo "<tr><th colspan='4'>" . __('Add a network name') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>";
echo "<input type='hidden' name='items_id' value='{$items_id}'>\n";
echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
_e('Not associated');
echo "</td><td class='left'>";
self::dropdown(array('name' => 'addressID', 'condition' => '`items_id`=0'));
echo "</td><td class='left'>";
echo "<input type='submit' name='assign_address' value='" . _sx('button', 'Associate') . "' class='submit'>";
echo "</td>";
if (static::canCreate()) {
echo "<td class='right' width='30%'>";
echo "<a href=\"" . static::getFormURL() . "?items_id={$items_id}&itemtype={$itemtype}\">";
echo __('Create a new network name') . "</a>";
echo "</td>";
}
echo "</tr>\n";
echo "</table>\n";
Html::closeForm();
echo "</div>\n";
}
$table_options = array('createRow' => true);
if ($item->getType() == 'FQDN' || $item->getType() == 'NetworkEquipment') {
if (isset($_GET["start"])) {
$start = $_GET["start"];
} else {
$start = 0;
}
if (!empty($_GET["order"])) {
$table_options['order'] = $_GET["order"];
} else {
$table_options['order'] = 'name';
}
if ($item->getType() == 'FQDN') {
$table_options['column_links'] = array('NetworkName' => 'javascript:reloadTab("order=name");', 'NetworkAlias' => 'javascript:reloadTab("order=alias");', 'IPAddress' => 'javascript:reloadTab("order=ip");');
}
$table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}";
$canedit = false;
} else {
$canedit = Session::haveRight('internet', UPDATE) && $item->canUpdateItem();
}
$table_options['canedit'] = false;
$table_options['rand'] = $rand;
$table_options['massiveactionnetworkname'] = $canedit;
$table = new HTMLTableMain();
$column = $table->addHeader('Internet', self::getTypeName(Session::getPluralNumber()));
$t_group = $table->createGroup('Main', '');
self::getHTMLTableHeader(__CLASS__, $t_group, $column, NULL, $table_options);
$t_row = $t_group->createRow();
self::getHTMLTableCellsForItem($t_row, $item, NULL, $table_options);
if ($table->getNumberOfRows() > 0) {
$number = $table->getNumberOfRows();
if ($item->getType() == 'FQDN') {
$number = min($_SESSION['glpilist_limit'], $table->getNumberOfRows());
Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item));
}
Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
if ($canedit && $number) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
Html::showMassiveActions($massiveactionparams);
}
$table->display(array('display_title_for_each_group' => false, 'display_thead' => false, 'display_tfoot' => false, 'display_header_on_foot_for_each_group' => true));
if ($canedit && $number) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
if ($item->getType() == 'FQDN') {
Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item));
}
} else {
echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network name found') . "</th></tr>";
echo "</table>";
}
}
示例4: addNewTasks
static function addNewTasks(CommonDBTM $item, $withtemplate = '')
{
global $CFG_GLPI;
$rand = mt_rand();
$ID = $item->getField('id');
$entities_id = $item->getField('entities_id');
$canedit = $item->can($ID, 'w');
if (plugin_resources_haveRight('task', 'w') && $canedit && $withtemplate < 2) {
echo "<div align='center'>";
echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.form.php?plugin_resources_resources_id=" . $ID . "&entities_id=" . $entities_id . "' >" . __('Add a new task') . "</a></div>";
echo "</div>";
}
}
示例5: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'changegroup':
$input = $ma->getInput();
if (isset($input["field"]) && isset($input['groups_id'])) {
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
if ($item->update(array('id' => $id, $input["field"] => $input["groups_id"]))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $baseitem, $ids);
}
示例6: processMassiveActionsForOneItemtype
/**
* @since version 0.90
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'merge':
foreach ($ids as $key) {
if ($item->can($key, UPDATE)) {
if ($item->getEntityID() == $_SESSION['glpiactive_entity']) {
if ($item->update(array('id' => $key, 'is_recursive' => 1))) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$input2 = $item->fields;
// Change entity
$input2['entities_id'] = $_SESSION['glpiactive_entity'];
$input2['is_recursive'] = 1;
$input2 = Toolbox::addslashes_deep($input2);
if (!$item->import($input2)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
}
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例7: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
switch ($ma->getAction()) {
case 'solveticket':
$input = $ma->getInput();
$ticket = new Ticket();
foreach ($ids as $id) {
if ($item->can($id, READ)) {
if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) {
$toupdate = array();
$toupdate['id'] = $ticket->getID();
$toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
$toupdate['solution'] = $input['solution'];
if ($ticket->update($toupdate)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例8: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'move_license':
$input = $ma->getInput();
if (isset($input['softwarelicenses_id'])) {
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
//Process rules
if ($item->update(array('id' => $id, 'softwarelicenses_id' => $input['softwarelicenses_id']))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
case 'install':
$csl = new self();
$csv = new Computer_SoftwareVersion();
foreach ($ids as $id) {
if ($csl->getFromDB($id)) {
$sl = new SoftwareLicense();
if ($sl->getFromDB($csl->fields["softwarelicenses_id"])) {
$version = 0;
if ($sl->fields["softwareversions_id_use"] > 0) {
$version = $sl->fields["softwareversions_id_use"];
} else {
$version = $sl->fields["softwareversions_id_buy"];
}
if ($version > 0) {
$params = array('computers_id' => $csl->fields['computers_id'], 'softwareversions_id' => $version);
//Get software name and manufacturer
if ($csv->can(-1, CREATE, $params)) {
//Process rules
if ($csv->add($params)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
}
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例9: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
$account_item = new PluginAccountsAccount_Item();
switch ($ma->getAction()) {
case "add_item":
$input = $ma->getInput();
foreach ($ma->items as $itemtype => $myitem) {
foreach ($myitem as $key => $value) {
if (!countElementsInTable('glpi_plugin_accounts_accounts_items', "itemtype='{$itemtype}' \n AND items_id='{$key}' \n AND plugin_accounts_accounts_id='" . $input['plugin_accounts_accounts_id'] . "'")) {
$myvalue['plugin_accounts_accounts_id'] = $input['plugin_accounts_accounts_id'];
$myvalue['itemtype'] = $itemtype;
$myvalue['items_id'] = $key;
if ($account_item->add($myvalue)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
case "transfer":
$input = $ma->getInput();
if ($item->getType() == 'PluginAccountsAccount') {
foreach ($ids as $key) {
$item->getFromDB($key);
$type = PluginAccountsAccountType::transfer($item->fields["plugin_accounts_accounttypes_id"], $input['entities_id']);
if ($type > 0) {
$values["id"] = $key;
$values["plugin_accounts_accounttypes_id"] = $type;
$item->update($values);
}
unset($values);
$values["id"] = $key;
$values["entities_id"] = $input['entities_id'];
if ($item->update($values)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
case 'install':
$input = $ma->getInput();
foreach ($ids as $key) {
if ($item->can($key, UPDATE)) {
$values = array('plugin_accounts_accounts_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
if ($account_item->add($values)) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'uninstall':
$input = $ma->getInput();
foreach ($ids as $key) {
if ($val == 1) {
if ($account_item->deleteItemByAccountsAndItem($key, $input['item_item'], $input['typeitem'])) {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
}
}
}
break;
}
}
示例10: showAddFormForItem
/**
* @since version 0.90
*
* @param $item
* @param $withtemplate (default '')
* @param $options array
*
* @return boolean
**/
static function showAddFormForItem(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;
}
}
if (!$item->can($item->fields['id'], READ)) {
return false;
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
// find documents already associated to the item
$doc_item = new self();
$used_found = $doc_item->find("`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'");
$used = array_keys($used_found);
$used = array_combine($used, $used);
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[$item->getID()] = $item->getID();
}
echo "<div class='firstbloc'>";
echo "<form name='documentitem_form" . $params['rand'] . "' id='documentitem_form" . $params['rand'] . "' method='post' 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 width='20%'>";
DocumentCategory::dropdown(array('entity' => $entities));
echo "</td>";
echo "<td class='right'>";
echo "<input type='hidden' name='entities_id' value='{$entity}'>";
echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>";
echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
if ($item->getType() == 'Ticket') {
echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
}
echo Html::file(array('multiple' => true));
echo "</td><td class='left'>(" . Document::getMaxUploadSize() . ") </td>";
echo "<td class='center' width='20%'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n class='submit'>";
echo "</td></tr>";
echo "</table>";
Html::closeForm();
if (Document::canView() && $nb > count($used)) {
echo "<form name='document_form" . $params['rand'] . "' id='document_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'>";
echo "<td colspan='4' class='center'>";
echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
if ($item->getType() == 'Ticket') {
echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
}
Document::dropdown(array('entity' => $entities, 'used' => $used));
echo "</td><td class='center' width='20%'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
echo "</td>";
echo "</tr>";
echo "</table>";
Html::closeForm();
}
echo "</div>";
}
}
示例11: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'move_version':
$input = $ma->getInput();
if (isset($input['softwareversions_id'])) {
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
//Process rules
if ($item->update(array('id' => $id, 'softwareversions_id' => $input['softwareversions_id']))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
case 'add':
$itemtoadd = new Computer_SoftwareVersion();
if (isset($_POST['peer_softwareversions_id'])) {
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
//Process rules
if ($itemtoadd->add(array('computers_id' => $id, 'softwareversions_id' => $_POST['peer_softwareversions_id']))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($itemtoadd->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($itemtoadd->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例12: showUsers
static function showUsers(CommonDBTM $item)
{
global $DB, $CFG_GLPI;
$ID = $item->getField('id');
if ($item->isNewID($ID)) {
return false;
}
if (!plugin_projet_haveRight('projet', 'r')) {
return false;
}
if (!$item->can($item->fields['id'], 'r')) {
return false;
}
$canread = $item->can($ID, 'r');
$query = "SELECT `glpi_plugin_projet_projets`.* FROM `glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) ";
if ($item->getType() == 'User') {
$query .= " WHERE `glpi_plugin_projet_projets`.`users_id` = '" . $ID . "' ";
} else {
$query .= " WHERE `glpi_plugin_projet_projets`.`groups_id` = '" . $ID . "' ";
}
$query .= "AND `glpi_plugin_projet_projets`.`is_template` = 0 " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', '', $item->maybeRecursive());
$result = $DB->query($query);
$number = $DB->numrows($result);
if (Session::isMultiEntitiesMode()) {
$colsup = 1;
} else {
$colsup = 0;
}
if ($number > 0) {
echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php\">";
echo "<div align='center'><table class='tab_cadre_fixe'>";
echo "<tr><th colspan='" . (4 + $colsup) . "'>" . __('Responsible of projects', 'projet') . ":</th></tr>";
echo "<tr><th>" . __('Name') . "</th>";
if (Session::isMultiEntitiesMode()) {
echo "<th>" . __('Entity') . "</th>";
}
echo "<th>" . __('Description') . "</th>";
echo "<th>" . __('Progress') . "</th>";
echo "</tr>";
while ($data = $DB->fetch_array($result)) {
echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
if ($canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["recursive"])) {
echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"];
if ($_SESSION["glpiis_ids_visible"]) {
echo " (" . $data["id"] . ")";
}
echo "</a></td>";
} else {
echo "<td class='center'>" . $data["name"];
if ($_SESSION["glpiis_ids_visible"]) {
echo " (" . $data["id"] . ")";
}
echo "</td>";
}
if (Session::isMultiEntitiesMode()) {
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
}
echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
echo "<td align='center'>" . $data["advance"] . " %</td>";
echo "</tr>";
}
echo "</table></div>";
Html::closeForm();
echo "<br>";
} else {
echo "<div align='center'><table class='tab_cadre_fixe' style='text-align:center'>";
echo "<tr><th>" . __('Responsible of projects', 'projet') . " - " . __('No item found');
echo "</th></tr></table></div><br>";
}
}
示例13: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
$input = $ma->getInput();
switch ($ma->getAction()) {
case 'move_under':
if (isset($input['parent'])) {
$fk = $item->getForeignKeyField();
$parent = clone $item;
if (!$parent->getFromDB($input['parent'])) {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
$ma->addMessage($parent->getErrorMessage(ERROR_NOT_FOUND));
return;
}
foreach ($ids as $id) {
if ($item->can($id, UPDATE)) {
// Check if parent is not a child of the original one
if (!in_array($parent->getID(), getSonsOf($item->getTable(), $item->getID()))) {
if ($item->update(array('id' => $id, $fk => $parent->getID()))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
$ma->addMessage($parent->getErrorMessage(ERROR_COMPAT));
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
示例14: showForItem
/**
* Show rack associated to an item
*
* @since version 0.84
*
* @param $item CommonDBTM object for which associated rack must be displayed
* @param $withtemplate (default '')
**/
static function showForItem(CommonDBTM $item, $withtemplate = '')
{
global $DB, $CFG_GLPI;
$ID = $item->getField('id');
if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) {
return false;
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
$canedit = $item->canadditem('PluginRacksRack');
$rand = mt_rand();
$is_recursive = $item->isRecursive();
$itemtype = $item->getType() . "Model";
$query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n `glpi_plugin_racks_racks_items`.`faces_id`,\n `glpi_plugin_racks_racks_items`.`position`,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_racks_racks`.`name` AS assocName,\n `glpi_plugin_racks_racks`.*\n FROM `glpi_plugin_racks_racks_items`\n LEFT JOIN `glpi_plugin_racks_racks`\n ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
$query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
$query .= " ORDER BY `assocName`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$racks = array();
$rack = new PluginRacksRack();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$racks[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
echo "<div class='spaced'>";
if ($canedit && $number && $withtemplate < 2) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('num_displayed' => $number);
Html::showMassiveActions($massiveactionparams);
}
echo "<table class='tab_cadre_fixe'>";
echo "<tr>";
if ($canedit && $number && $withtemplate < 2) {
echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
}
echo "<th>" . __('Name') . "</th>";
if (Session::isMultiEntitiesMode()) {
echo "<th>" . __('Entity') . "</th>";
}
echo "<th>" . __('Disposition', 'racks') . "</th>";
echo "<th>" . __('Position', 'racks') . "</th>";
echo "<th>" . __('Location') . "</th>";
echo "<th>" . __('Place', 'racks') . "</th>";
echo "<th>" . __('Manufacturer') . "</th>";
echo "</tr>";
$used = array();
if ($number) {
Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
foreach ($racks as $data) {
$rackID = $data["id"];
$link = NOT_AVAILABLE;
if ($rack->getFromDB($rackID)) {
$link = $rack->getLink();
}
Session::addToNavigateListItems('PluginRacksRack', $rackID);
$used[$rackID] = $rackID;
$assocID = $data["assocID"];
echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
if ($canedit && $withtemplate < 2) {
echo "<td width='10'>";
Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
echo "</td>";
}
echo "<td class='center'>{$link}</td>";
if (Session::isMultiEntitiesMode()) {
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
}
if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
$faces_id = __('Front', 'racks');
} else {
$faces_id = _x('Rack enclosure', 'Back', 'racks');
}
echo "<td class='center'>" . $faces_id . "</td>";
echo "<td class='center'>" . $data["position"] . "</td>";
echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
echo "</tr>";
$i++;
}
}
echo "</table>";
if ($canedit && $number && $withtemplate < 2) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
//.........这里部分代码省略.........
示例15: showForItem
/**
* Show webapplications associated to an item
*
* @since version 0.84
*
* @param $item CommonDBTM object for which associated webapplications 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 (!Session::haveRight("plugin_webapplications", READ)) {
return false;
}
if (!$item->can($item->fields['id'], READ)) {
return false;
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
$canedit = $item->canadditem('PluginWebapplicationsWebapplication');
$rand = mt_rand();
$is_recursive = $item->isRecursive();
$query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n `glpi_plugin_webapplications_webapplications`.*\n FROM `glpi_plugin_webapplications_webapplications_items`\n LEFT JOIN `glpi_plugin_webapplications_webapplications`\n ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' ";
$query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true);
$query .= " ORDER BY `assocName`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$webs = array();
$web = new PluginWebapplicationsWebapplication();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$webs[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
if ($canedit && $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_plugin_webapplications_webapplications", '', $entities, true);
$q = "SELECT COUNT(*)\n FROM `glpi_plugin_webapplications_webapplications`\n WHERE `is_deleted` = '0'\n {$limit}";
$result = $DB->query($q);
$nb = $DB->result($result, 0, 0);
echo "<div class='firstbloc'>";
if (Session::haveRight("plugin_webapplications", READ) && $nb > count($used)) {
echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'>";
echo "<td colspan='4' class='center'>";
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}'>";
}
PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used));
echo "</td><td class='center' width='20%'>";
echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" class='submit'>";
echo "</td>";
echo "</tr>";
echo "</table>";
Html::closeForm();
}
echo "</div>";
}
echo "<div class='spaced'>";
if ($canedit && $number && $withtemplate < 2) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('num_displayed' => $number);
Html::showMassiveActions($massiveactionparams);
}
echo "<table class='tab_cadre_fixe'>";
echo "<tr>";
if ($canedit && $number && $withtemplate < 2) {
echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
}
echo "<th>" . __('Name') . "</th>";
if (Session::isMultiEntitiesMode()) {
echo "<th>" . __('Entity') . "</th>";
}
echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>";
//.........这里部分代码省略.........