Example #1
0
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkLoginUser();
$track = new Ticket();
if (!isset($_GET['id'])) {
    $_GET['id'] = "";
}
if (isset($_POST["add"])) {
    $track->check(-1, CREATE, $_POST);
    if ($id = $track->add($_POST)) {
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($track->getFormURL() . "?id=" . $id);
        }
    }
    Html::back();
} else {
    if (isset($_POST['update'])) {
        $track->check($_POST['id'], UPDATE);
        $track->update($_POST);
        Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
        if ($track->can($_POST["id"], READ)) {
            $toadd = '';
            // Copy solution to KB redirect to KB
            if (isset($_POST['_sol_to_kb']) && $_POST['_sol_to_kb']) {
                $toadd = "&_sol_to_kb=1";
            }
            Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST["id"] . $toadd);
Example #2
0
 /**
  * Show SLT for ticket
  *
  * @param $ticket      Ticket item
  * @param $type
  * @param $tt
  * @param $canupdate
  **/
 function showSltForTicket(Ticket $ticket, $type, $tt, $canupdate)
 {
     global $CFG_GLPI;
     list($dateField, $sltField) = self::getSltFieldNames($type);
     echo "<table width='100%'>";
     echo "<tr class='tab_bg_1'>";
     if (!isset($ticket->fields[$dateField]) || $ticket->fields[$dateField] == 'NULL') {
         $ticket->fields[$dateField] = '';
     }
     if ($ticket->fields['id']) {
         if ($this->getSltDataForTicket($ticket->fields['id'], $type)) {
             echo "<td>";
             echo Html::convDateTime($ticket->fields[$dateField]);
             echo "</td>";
             echo "<th>" . __('SLT') . "</th>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_slts', $ticket->fields[$sltField]) . "&nbsp;";
             $commentsla = "";
             $slalevel = new SlaLevel();
             $nextaction = new SlaLevel_Ticket();
             if ($nextaction->getFromDBForTicket($ticket->fields["id"], $type)) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('Next escalation: %s'), Html::convDateTime($nextaction->fields['date'])) . '</span><br>';
                 if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                     $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span>';
                 }
             }
             $slaoptions = array();
             if (Session::haveRight('sla', READ)) {
                 $slaoptions['link'] = Toolbox::getItemTypeFormURL('SLT') . "?id=" . $this->fields["id"];
             }
             Html::showToolTip($commentsla, $slaoptions);
             if ($canupdate) {
                 $fields = array('slt_delete' => 'slt_delete', 'id' => $ticket->getID(), 'type' => $type, '_glpi_csrf_token' => Session::getNewCSRFToken(), '_glpi_simple_form' => 1);
                 $JS = "  function delete_date{$type}(){\n                           if (nativeConfirm('" . addslashes(__('Also delete date ?')) . "')) {\n                              submitGetLink('" . $ticket->getFormURL() . "',\n                                            " . json_encode(array_merge($fields, array('delete_date' => 1))) . ");\n                           } else {\n                              submitGetLink('" . $ticket->getFormURL() . "',\n                                            " . json_encode(array_merge($fields, array('delete_date' => 0))) . ");\n                           }\n                        }";
                 echo Html::scriptBlock($JS);
                 echo "<a class='pointer' onclick='delete_date{$type}();return false;'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/delete.png' title='" . _x('button', 'Delete permanently') . "' " . "alt='" . _x('button', 'Delete permanently') . "' class='pointer'>";
                 echo "</a>";
             }
             echo "</td>";
         } else {
             echo "<td width='200px'>";
             echo $tt->getBeginHiddenFieldValue($dateField);
             if ($canupdate) {
                 Html::showDateTimeField($dateField, array('value' => $ticket->fields[$dateField], 'timestep' => 1, 'maybeempty' => true));
             } else {
                 echo Html::convDateTime($ticket->fields[$dateField]);
             }
             echo $tt->getEndHiddenFieldValue($dateField, $ticket);
             echo "</td>";
             $slt_data = $this->getSltData("`type` = '{$type}'\n                                           AND `entities_id` = '" . $ticket->fields['entities_id'] . "'");
             if ($canupdate && !empty($slt_data)) {
                 echo "<td>";
                 echo $tt->getBeginHiddenFieldText($sltField);
                 echo "<span id='slt_action{$type}'>";
                 echo "<a " . Html::addConfirmationOnAction(array(__('The assignment of a SLT to a ticket causes the recalculation of the date.'), __("Escalations defined in the SLT will be triggered under this new date.")), "cleanhide('slt_action{$type}');cleandisplay('slt_choice{$type}');") . "><img src='" . $CFG_GLPI['root_doc'] . "/pics/clock.png' title='" . __('SLT') . "' alt='" . __('SLT') . "' class='pointer'></a>";
                 echo "</span>";
                 echo "<div id='slt_choice{$type}' style='display:none'>";
                 echo "<span  class='b'>" . __('SLT') . "</span>&nbsp;";
                 Slt::dropdown(array('name' => $sltField, 'entity' => $ticket->fields["entities_id"], 'condition' => "`type` = '" . $type . "'"));
                 echo "</div>";
                 echo $tt->getEndHiddenFieldText($sltField);
                 echo "</td>";
             }
         }
     } else {
         // New Ticket
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue($dateField);
         Html::showDateTimeField($dateField, array('value' => $ticket->fields[$dateField], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
         echo $tt->getEndHiddenFieldValue($dateField, $ticket);
         echo "</td>";
         $slt_data = $this->getSltData("`type` = '{$type}'\n                                        AND `entities_id` = '" . $ticket->fields['entities_id'] . "'");
         if ($canupdate && !empty($slt_data)) {
             echo "<th>" . $tt->getBeginHiddenFieldText($sltField);
             printf(__('%1$s%2$s'), __('SLT'), $tt->getMandatoryMark($sltField));
             echo $tt->getEndHiddenFieldText('slas_id') . "</th>";
             echo "<td class='nopadding'>" . $tt->getBeginHiddenFieldValue($sltField);
             Slt::dropdown(array('name' => $sltField, 'entity' => $ticket->fields["entities_id"], 'value' => isset($ticket->fields[$sltField]) ? $ticket->fields[$sltField] : 0, 'condition' => "`type` = '" . $type . "'"));
             echo $tt->getEndHiddenFieldValue($sltField, $ticket);
             echo "</td>";
         }
     }
     echo "</tr>";
     echo "</table>";
 }
Example #3
0
 /**
  * Print the HTML ajax associated item add
  *
  * @param $ticket Ticket object
  * @param $options   array of possible options:
  *    - id                  : ID of the ticket
  *    - _users_id_requester : ID of the requester user
  *    - items_id            : array of elements (itemtype => array(id1, id2, id3, ...))
  *
  * @return Nothing (display)
  **/
 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(), 'itemtype' => '');
     $opt = array();
     foreach ($options as $key => $val) {
         if (!empty($val)) {
             $params[$key] = $val;
         }
     }
     if (!$ticket->can($params['id'], READ)) {
         return false;
     }
     $canedit = $ticket->can($params['id'], UPDATE);
     // Ticket update case
     if ($params['id'] > 0) {
         // Get requester
         $class = new $ticket->userlinkclass();
         $tickets_user = $class->getActors($params['id']);
         if (isset($tickets_user[CommonITILActor::REQUESTER]) && count($tickets_user[CommonITILActor::REQUESTER]) == 1) {
             foreach ($tickets_user[CommonITILActor::REQUESTER] as $user_id_single) {
                 $params['_users_id_requester'] = $user_id_single['users_id'];
             }
         }
         // Get associated elements for ticket
         $used = self::getUsedItems($params['id']);
         foreach ($used as $itemtype => $items) {
             foreach ($items as $items_id) {
                 if (!isset($params['items_id'][$itemtype]) || !in_array($items_id, $params['items_id'][$itemtype])) {
                     $params['items_id'][$itemtype][] = $items_id;
                 }
             }
         }
     }
     // Get ticket template
     $tt = new TicketTemplate();
     if (isset($options['_tickettemplate'])) {
         $tt = $options['_tickettemplate'];
         if (isset($tt->fields['id'])) {
             $opt['templates_id'] = $tt->fields['id'];
         }
     } else {
         if (isset($options['templates_id'])) {
             $tt->getFromDBWithDatas($options['templates_id']);
             if (isset($tt->fields['id'])) {
                 $opt['templates_id'] = $tt->fields['id'];
             }
         }
     }
     $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, 'tickets_id' => $params['id']);
         // My items
         if ($params['_users_id_requester'] > 0) {
             Item_Ticket::dropdownMyDevices($params['_users_id_requester'], $ticket->fields["entities_id"], $params['itemtype'], 0, $p);
         }
         // Global search
         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;
         $cpt = 0;
         foreach ($params['items_id'] as $itemtype => $items) {
             foreach ($items as $items_id) {
                 $cpt++;
             }
         }
         if ($cpt == 1 && isset($tt->mandatory['items_id'])) {
             $delete = false;
         }
         foreach ($params['items_id'] as $itemtype => $items) {
             foreach ($items as $items_id) {
                 if ($count < 5 && $params['id'] || $params['id'] == 0) {
                     echo Item_Ticket::showItemToAdd($params['id'], $itemtype, $items_id, array('rand' => $rand, 'delete' => $delete));
                 }
                 $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>";
     }
     echo "</div>";
     foreach (array('id', '_users_id_requester', 'items_id', 'itemtype') as $key) {
         $opt[$key] = $params[$key];
     }
     $js = " function itemAction{$rand}(action, itemtype, items_id) {";
     $js .= "    \$.ajax({\n                     url: '" . $CFG_GLPI['root_doc'] . "/ajax/itemTicket.php',\n                     dataType: 'html',\n                     data: {'action'     : action,\n                            'rand'       : {$rand},\n                            'params'     : " . json_encode($opt) . ",\n                            'my_items'   : \$('#dropdown_my_items{$rand}').val(),\n                            'itemtype'   : (itemtype === undefined) ? \$('#dropdown_itemtype{$rand}').val() : itemtype,\n                            'items_id'   : (items_id === undefined) ? \$('#dropdown_add_items_id{$rand}').val() : items_id},\n                     success: function(response) {";
     $js .= "          \$(\"#itemAddForm{$rand}\").html(response);";
     $js .= "       }";
     $js .= "    });";
     $js .= " }";
     echo Html::scriptBlock($js);
     echo "</div>";
 }
Example #4
0
if (empty($_POST) || count($_POST) == 0) {
    Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php");
}
if (isset($_POST["_type"]) && $_POST["_type"] == "Helpdesk") {
    Html::nullHeader(Ticket::getTypeName(Session::getPluralNumber()));
} else {
    if ($_POST["_from_helpdesk"]) {
        Html::helpHeader(__('Simplified interface'), '', $_SESSION["glpiname"]);
    } else {
        Html::header(__('Simplified interface'), '', $_SESSION["glpiname"], "helpdesk", "tracking");
    }
}
if (isset($_POST['add'])) {
    if ($newID = $track->add($_POST)) {
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($track->getFormURL() . "?id=" . $newID);
        }
        if (isset($_POST["_type"]) && $_POST["_type"] == "Helpdesk") {
            echo "<div class='center spaced'>" . __('Your ticket has been registered, its treatment is in progress.');
            Html::displayBackLink();
            echo "</div>";
        } else {
            echo "<div class='center b spaced'>";
            echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt='" . __s('OK') . "'>";
            Session::addMessageAfterRedirect(__('Thank you for using our automatic helpdesk system.'));
            Html::displayMessageAfterRedirect();
            echo "</div>";
        }
    } else {
        echo "<div class='center'>";
        echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" . __s('Warning') . "'><br>";
Example #5
0
/**
 * Init hooks of the plugin.
 * REQUIRED
 *
 * @return void
 */
function plugin_init_fields()
{
    global $PLUGIN_HOOKS;
    $PLUGIN_HOOKS['csrf_compliant']['fields'] = true;
    include_once PLUGINFIELDS_DIR . "/inc/autoload.php";
    $options = array(PLUGINFIELDS_CLASS_PATH);
    $pluginfields_autoloader = new PluginFieldsAutoloader($options);
    $pluginfields_autoloader->register();
    $plugin = new Plugin();
    if ($plugin->isInstalled('fields') && $plugin->isActivated('fields') && Session::getLoginUserID()) {
        // Init hook about itemtype(s) for plugin fields
        $PLUGIN_HOOKS['plugin_fields'] = array();
        // When a Category is changed during ticket creation
        if (isset($_POST) && !empty($_POST) && isset($_POST['_plugin_fields_type'])) {
            if ($_SERVER['REQUEST_URI'] == Ticket::getFormURL()) {
                //$_SESSION['plugin_fields']['Ticket'] = $_POST;
                foreach ($_POST as $key => $value) {
                    if (!is_array($value)) {
                        $_SESSION['plugin']['fields']['values_sent'][$key] = stripcslashes($value);
                    }
                }
            }
        }
        // complete rule engine
        $PLUGIN_HOOKS['use_rules']['fields'] = array('PluginFusioninventoryTaskpostactionRule');
        $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched';
        if (isset($_SESSION['glpiactiveentities'])) {
            $PLUGIN_HOOKS['config_page']['fields'] = 'front/container.php';
            // add entry to configuration menu
            $PLUGIN_HOOKS["menu_toadd"]['fields'] = array('config' => 'PluginFieldsMenu');
            // add tabs to itemtypes
            Plugin::registerClass('PluginFieldsContainer', array('addtabon' => array_unique(PluginFieldsContainer::getEntries())));
            //include js and css
            if (file_exists(__DIR__ . '/css/fields.min.css')) {
                $PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.min.css';
            } else {
                $PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.css';
            }
            $PLUGIN_HOOKS['add_javascript']['fields'][] = 'fields.js.php';
            // Add/delete profiles to automaticaly to container
            $PLUGIN_HOOKS['item_add']['fields']['Profile'] = array("PluginFieldsProfile", "addNewProfile");
            $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = array("PluginFieldsProfile", "deleteProfile");
            //load drag and drop javascript library on Package Interface
            $PLUGIN_HOOKS['add_javascript']['fields'][] = "js/redips-drag-min.js";
            if (file_exists(__DIR__ . '/js/drag-field-row.min.js')) {
                $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js';
            } else {
                $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.js';
            }
        }
        // Add Fields to Datainjection
        if ($plugin->isActivated('datainjection')) {
            $PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = "plugin_datainjection_populate_fields";
        }
        //Retrieve dom container
        $itemtypes = PluginFieldsContainer::getUsedItemtypes();
        if ($itemtypes !== false) {
            foreach ($itemtypes as $itemtype) {
                $PLUGIN_HOOKS['pre_item_update']['fields'][$itemtype] = ["PluginFieldsContainer", "preItemUpdate"];
                $PLUGIN_HOOKS['pre_item_add']['fields'][$itemtype] = ["PluginFieldsContainer", "preItem"];
                $PLUGIN_HOOKS['item_add']['fields'][$itemtype] = ["PluginFieldsContainer", "postItemAdd"];
                $PLUGIN_HOOKS['pre_item_purge']['fields'][$itemtype] = ["PluginFieldsContainer", "preItemPurge"];
            }
        }
    }
}