Skip to content

Commit

Permalink
Fix add ticket from items
Browse files Browse the repository at this point in the history
Clean trailing spaces
  • Loading branch information
korial29 committed Feb 16, 2016
1 parent 4b36748 commit 9a91eb2
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 77 deletions.
12 changes: 6 additions & 6 deletions ajax/dropdownTrackingDeviceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
if (isset($_POST["itemtype"])
&& CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) {
$table = getTableForItemType($_POST["itemtype"]);

$rand = mt_rand();
if (isset($_POST["rand"])) {
$rand = $_POST["rand"];
}

// Message for post-only
if (!isset($_POST["admin"]) || ($_POST["admin"] == 0)) {
echo "<br>".__('Enter the first letters (user, item name, serial or asset number)');
Expand All @@ -61,19 +61,19 @@
'entity_restrict' => $_POST['entity_restrict'],
'table' => $table,
'multiple' => $_POST["multiple"],
'myname' => $_POST["myname"],
'myname' => $_POST["myname"],
'rand' => $_POST["rand"]);

if (isset($_POST["used"]) && !empty($_POST["used"])) {
if (isset($_POST["used"][$_POST["itemtype"]])) {
$p["used"] = $_POST["used"][$_POST["itemtype"]];
}
}

echo Html::jsAjaxDropdown($_POST['myname'], $field_id,
$CFG_GLPI['root_doc']."/ajax/getDropdownFindNum.php",
$p);

// Auto update summary of active or just solved tickets
$params = array('items_id' => '__VALUE__',
'itemtype' => $_POST['itemtype']);
Expand Down
4 changes: 2 additions & 2 deletions front/item_ticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
if (isset($_POST['my_items']) && !empty($_POST['my_items'])) {
list($_POST['itemtype'], $_POST['items_id']) = explode('_', $_POST['my_items']);
}

if (isset($_POST['add_items_id'])) {
$_POST['items_id'] = $_POST['add_items_id'];
}
Expand All @@ -56,7 +56,7 @@
Session::addMessageAfterRedirect($message, false, ERROR);
Html::back();
}

$item->check(-1, CREATE, $_POST);

if ($item->add($_POST)) {
Expand Down
4 changes: 4 additions & 0 deletions front/ticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
} else {
Html::header(__('New ticket'),'',"helpdesk","ticket");
unset($_REQUEST['id']);
// Add a ticket from item : format data
if (isset($_REQUEST['_add_fromitem'])) {
$_REQUEST['items_id'] = array($_REQUEST['itemtype'] => array($_REQUEST['items_id']));
}
$track->display($_REQUEST);
}

Expand Down
4 changes: 2 additions & 2 deletions inc/ipaddress.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ static function getUniqueItemByIPAddress($value, $entity) {
}
}
}

if (count($addressesWithItems)) {
// Get the first item that is matching entity
foreach ($addressesWithItems as $items) {
Expand All @@ -955,7 +955,7 @@ static function getUniqueItemByIPAddress($value, $entity) {
}
}
}
}
}
return array();
}

Expand Down
72 changes: 36 additions & 36 deletions inc/item_ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static function countForItem(CommonDBTM $item) {

return $nb ;
}

/**
* Print the HTML ajax associated item add
*
Expand All @@ -190,14 +190,14 @@ static function countForItem(CommonDBTM $item) {
**/
static function itemAddForm(Ticket $ticket, $options=array()){
global $CFG_GLPI;

$params = array('id' => (isset($ticket->fields['id']) && $ticket->fields['id'] != '') ? $ticket->fields['id'] : 0,
'_users_id_requester' => 0,
'items_id' => array(),
'items_id' => array(),
'itemtype' => '');

$opt = array();

foreach ($options as $key => $val) {
if (!empty($val)) {
$params[$key] = $val;
Expand All @@ -207,9 +207,9 @@ static function itemAddForm(Ticket $ticket, $options=array()){
if (!$ticket->can($params['id'], READ)) {
return false;
}

$canedit = ($ticket->can($params['id'], UPDATE));

// Ticket update case
if ($params['id'] > 0) {
// Get requester
Expand All @@ -220,7 +220,7 @@ static function itemAddForm(Ticket $ticket, $options=array()){
$params['_users_id_requester'] = $user_id_single['users_id'];
}
}

// Get associated elements for ticket
$used = self::getUsedItems($params['id']);
foreach ($used as $itemtype => $items) {
Expand All @@ -230,8 +230,8 @@ static function itemAddForm(Ticket $ticket, $options=array()){
}
}
}
}
}

// Get ticket template
$tt = new TicketTemplate();
if (isset($options['_tickettemplate'])) {
Expand All @@ -244,14 +244,14 @@ static function itemAddForm(Ticket $ticket, $options=array()){

$rand = mt_rand();
$count = 0;

echo "<div id='itemAddForm$rand'>";

// Show associated item dropdowns
if ($canedit) {
echo "<div style='float:left'>";
$p = array('used' => $params['items_id'],
'rand' => $rand,
$p = array('used' => $params['items_id'],
'rand' => $rand,
'tickets_id' => $params['id']);
// My items
if ($params['_users_id_requester'] > 0) {
Expand All @@ -261,14 +261,14 @@ static function itemAddForm(Ticket $ticket, $options=array()){
Item_Ticket::dropdownAllDevices("itemtype", $params['itemtype'], 0, 1, $params['_users_id_requester'], $ticket->fields["entities_id"], $p);
echo "<span id='item_ticket_selection_information'></span>";
echo "</div>";

// Add button
echo "<a href='javascript:itemAction$rand(\"add\");' class='vsubmit' style='float:left'>"._sx('button', 'Add')."</a>";
}

// Display list
echo "<div style='clear:both;'>";

if (!empty($params['items_id'])) {
// No delete if mandatory and only one item
$delete = true;
Expand All @@ -290,12 +290,12 @@ static function itemAddForm(Ticket $ticket, $options=array()){
$count++;
}
}
}
}

if ($count == 0) {
echo "<input type='hidden' value='0' name='items_id'>";
}

if ($params['id'] > 0 && $count > 5) {
echo "<i><a href='".$ticket->getFormURL()."?id=".$params['id']."&amp;forcetab=Item_Ticket$1'>"
.__('Display all items')." (".$count.")</a></i>";
Expand All @@ -310,30 +310,30 @@ static function itemAddForm(Ticket $ticket, $options=array()){
$js .= " $.ajax({
url: '".$CFG_GLPI['root_doc']."/ajax/itemTicket.php',
dataType: 'html',
data: {'action' : action,
data: {'action' : action,
'rand' : $rand,
'params' : ".json_encode($opt).",
'my_items' : $('#dropdown_my_items$rand').val(),
'itemtype' : (itemtype === undefined) ? $('#dropdown_itemtype$rand').val() : itemtype,
'itemtype' : (itemtype === undefined) ? $('#dropdown_itemtype$rand').val() : itemtype,
'items_id' : (items_id === undefined) ? $('#dropdown_add_items_id$rand').val() : items_id},
success: function(response) {";
success: function(response) {";
$js .= " $(\"#itemAddForm$rand\").html(response);";
$js .= " }";
$js .= " });";
$js .= " }";
echo Html::scriptBlock($js);
echo "</div>";
}


static function showItemToAdd($tickets_id, $itemtype, $items_id, $options) {

$params = array('rand' => mt_rand(), 'delete' => true);

foreach($options as $key => $val){
$params[$key] = $val;
}

$item = getItemForItemtype($itemtype);
$item->getFromDB($items_id);
$result = "<div id='".$itemtype."_".$items_id."'>";
Expand All @@ -343,7 +343,7 @@ static function showItemToAdd($tickets_id, $itemtype, $items_id, $options) {
$result .= " <img src=\"../pics/delete.png\" onclick=\"itemAction".$params['rand']."('delete', '$itemtype', '$items_id');\">";
}
$result .= "</div>";

return $result;
}

Expand Down Expand Up @@ -583,17 +583,17 @@ static function dropdownAllDevices($myname, $itemtype, $items_id=0, $admin=0, $u
$entity_restrict=-1,$options=array()) {
global $CFG_GLPI, $DB;

$params = array('tickets_id' => 0,
'used' => array(),
'multiple' => 0,
$params = array('tickets_id' => 0,
'used' => array(),
'multiple' => 0,
'rand' => mt_rand());

foreach ($options as $key => $val) {
$params[$key] = $val;
}

$rand = $params['rand'];

if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) {
echo "<input type='hidden' name='$myname' value=''>";
echo "<input type='hidden' name='items_id' value='0'>";
Expand Down Expand Up @@ -670,17 +670,17 @@ static function dropdownAllDevices($myname, $itemtype, $items_id=0, $admin=0, $u
* @param $options array of possible options:
* - used : ID of the requester user
* - multiple : allow multiple choice
*
*
* @return nothing (print out an HTML select box)
**/
static function dropdownMyDevices($userID=0, $entity_restrict=-1, $itemtype=0, $items_id=0, $options=array()) {
global $DB, $CFG_GLPI;

$params = array('tickets_id' => 0,
'used' => array(),
'multiple' => false,
'used' => array(),
'multiple' => false,
'rand' => mt_rand());

foreach ($options as $key => $val) {
$params[$key] = $val;
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ static function getSpecificValueToDisplay($field, $values, array $options=array(
$values = array($field => $values);
}
switch ($field) {
case 'items_id':
case 'items_id':
if (strpos($values[$field], "_") !== false) {
$item_itemtype = explode("_", $values[$field]);
$values['itemtype'] = $item_itemtype[0];
Expand Down
10 changes: 5 additions & 5 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,12 @@ function post_updateItem($history=1) {
foreach ($items as $items_id) {
$item_ticket->add(array('items_id' => $items_id,
'itemtype' => $itemype,
'tickets_id' => $this->fields['id'],
'tickets_id' => $this->fields['id'],
'_disablenotif' => true));
}
}
}

// Setting a solution type means the ticket is solved
if ((in_array("solutiontypes_id", $this->updates)
|| in_array("solution", $this->updates))
Expand Down Expand Up @@ -4153,17 +4153,17 @@ class='pointer' src='".$CFG_GLPI["root_doc"]."/pics/showselect.png'></a>";
echo "</th>";
if (!$ID) {
echo "<td rowspan='2'>";
echo $tt->getBeginHiddenFieldValue('items_id');
echo $tt->getBeginHiddenFieldValue('items_id');
if ($canupdate
|| $canupdate_descr) {
Item_Ticket::itemAddForm($this, $values);
}
echo $tt->getEndHiddenFieldValue('items_id', $this);
echo "</td>";

} else {
echo "<td>";
echo $tt->getBeginHiddenFieldValue('items_id');
echo $tt->getBeginHiddenFieldValue('items_id');
Item_Ticket::itemAddForm($this, $values);
echo $tt->getEndHiddenFieldValue('items_id', $this);
echo "</td>";
Expand Down
6 changes: 3 additions & 3 deletions inc/tickettemplate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static function getAllowedFields($withtypeandcategory=0, $withitemtype=0) {
} else {
$withtypeandcategory = 0;
}

if ($withitemtype) {
$withitemtype = 1;
} else {
Expand Down Expand Up @@ -206,11 +206,11 @@ static function getAllowedFields($withtypeandcategory=0, $withitemtype=0) {
[$ticket->getSearchOptionIDByField('field', 'itemtype',
'glpi_items_tickets')] = 'itemtype';
}

$allowed_fields[$withtypeandcategory][$withitemtype]
[$ticket->getSearchOptionIDByField('field', 'items_id',
'glpi_items_tickets')] = 'items_id';

// Add validation request
$allowed_fields[$withtypeandcategory][$withitemtype][-2] = '_add_validation';

Expand Down
4 changes: 2 additions & 2 deletions inc/tickettemplatepredefinedfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ function getPredefinedFields($ID, $withtypeandcategory=false) {
return $fields;
}


/**
* @since version 0.85
**/
static function getMultiplePredefinedValues() {

$ticket = new Ticket();
$fields = array($ticket->getSearchOptionIDByField('field', 'name', 'glpi_documents'),
$fields = array($ticket->getSearchOptionIDByField('field', 'name', 'glpi_documents'),
$ticket->getSearchOptionIDByField('field', 'items_id', 'glpi_items_tickets'));

return $fields;
Expand Down
Loading

0 comments on commit 9a91eb2

Please sign in to comment.