Commit d38a8f61 authored by moyooo's avatar moyooo

first commit for create ticket delegation see #2734

Not completly review
parent 0fa1c4ed
<?php
/*
* @version $Id$
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2011 by the INDEPNET Development Team.
http://indepnet.net/ http://glpi-project.org
-------------------------------------------------------------------------
LICENSE
This file is part of GLPI.
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Julien Dombre
// Purpose of file:
// ----------------------------------------------------------------------
// Direct access to file
if (strpos($_SERVER['PHP_SELF'],"dropdownDelegationUsers.php")) {
$AJAX_INCLUDE = 1;
define('GLPI_ROOT','..');
include (GLPI_ROOT."/inc/includes.php");
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
die("Can not acces directly to this file");
}
Session::checkLoginUser();
if ($_POST["delegate"] == 0) {
$_POST['_users_id_requester'] = Session::getLoginUserID();
$_POST['right'] = "id";
} else {
$_POST['right'] = "delegate";
}
$ticket = new Ticket();
$ticket->showActorAddFormOnCreate(Ticket::REQUESTER, $_POST);
?>
\ No newline at end of file
......@@ -108,6 +108,30 @@ if (isset($_POST["add"])) {
Event::log($_POST["groups_id"], "groups", 4, "setup", $_SESSION["glpiname"]." ".$LANG['log'][50]);
Html::back();
} else if (isset($_POST["unset_delegate"])) {
if (isset($_POST["item"]) && count($_POST["item"])) {
foreach ($_POST["item"] as $key => $val) {
if ($groupuser->can($key,'w')) {
$groupuser->update(array('id' => $key,
'is_userdelegate' => 0));
}
}
}
Event::log($_POST["groups_id"], "groups", 4, "setup", $_SESSION["glpiname"]." ".$LANG['log'][50]);
Html::back();
} else if (isset($_POST["set_delegate"])) {
if (isset($_POST["item"]) && count($_POST["item"])) {
foreach ($_POST["item"] as $key => $val) {
if ($groupuser->can($key,'w')) {
$groupuser->update(array('id' => $key,
'is_userdelegate' => 1));
}
}
}
Event::log($_POST["groups_id"], "groups", 4, "setup", $_SESSION["glpiname"]." ".$LANG['log'][50]);
Html::back();
} else if (isset($_POST["changegroup"]) && isset($_POST["groups_id"]) && isset($_POST["field"])) {
if (isset($_POST['item'])
&& ($_POST["field"]=='groups_id' || $_POST["field"]=='groups_id_tech' )) {
......
......@@ -1913,9 +1913,12 @@ abstract class CommonITILObject extends CommonDBTM {
echo $options['_tickettemplate']->getMandatoryMark("_users_id_".$typename);
}
echo "&nbsp;";
$right = $this->getDefaultActorRightSearch($type);
if (!isset($options["right"])) {
$right = $this->getDefaultActorRightSearch($type);
} else {
$right = $options["right"];
}
if ($options["_users_id_".$typename] == 0) {
$options["_users_id_".$typename] = $this->getDefaultActor($type);
}
......@@ -1952,7 +1955,9 @@ abstract class CommonITILObject extends CommonDBTM {
if ($itemtype == 'Ticket') {
// display opened tickets for user
if ($type == self::REQUESTER && $options["_users_id_".$typename] > 0) {
if ($type == self::REQUESTER
&& $options["_users_id_".$typename] > 0
&& $_SESSION['glpiactiveprofile']['interface'] == 'central') {
$options2['field'][0] = 4; // users_id
$options2['searchtype'][0] = 'equals';
......@@ -2089,8 +2094,15 @@ abstract class CommonITILObject extends CommonDBTM {
if ($this->canAdminActors()) {
$this->showActorAddFormOnCreate(self::REQUESTER, $options);
} else {
echo self::getActorIcon('user', self::REQUESTER)."&nbsp;";
echo getUserName($options["_users_id_requester"], $showuserlink);
$delegating = User::getDelegateGroupsForUser();
if (!empty($delegating)) {
//$this->getDefaultActor(self::REQUESTER);
$options['right'] = "delegate";
$this->showActorAddFormOnCreate(self::REQUESTER, $options);
} else {
echo self::getActorIcon('user', self::REQUESTER)."&nbsp;";
echo getUserName($options["_users_id_requester"], $showuserlink);
}
}
//If user have access to more than one entity, then display a combobox : Ticket case
......
......@@ -221,7 +221,8 @@ class Group_User extends CommonDBRelation{
$query = "SELECT `glpi_users`.*,
`glpi_groups_users`.`id` AS linkID,
`glpi_groups_users`.`is_dynamic` AS is_dynamic,
`glpi_groups_users`.`is_manager` AS is_manager
`glpi_groups_users`.`is_manager` AS is_manager,
`glpi_groups_users`.`is_userdelegate` AS is_userdelegate
FROM `glpi_groups_users`
LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_groups_users`.`users_id`)
WHERE `glpi_groups_users`.`groups_id`='$ID'
......@@ -261,7 +262,7 @@ class Group_User extends CommonDBRelation{
if ($nb) {
echo "<div class='firstbloc'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th colspan='4'>".$LANG['setup'][603]."</tr>";
echo "<tr class='tab_bg_1'><th colspan='6'>".$LANG['setup'][603]."</tr>";
echo "<tr><td class='tab_bg_2 center'>";
User::dropdown(array('right' => "all",
......@@ -270,6 +271,10 @@ class Group_User extends CommonDBRelation{
echo "</td><td>".$LANG['common'][64]."</td><td>";
Dropdown::showYesNo("is_manager", 0);
echo "</td><td>".$LANG['common'][123]."</td><td>";
Dropdown::showYesNo("is_userdelegate", 0);
echo "</td><td class='tab_bg_2 center'>";
echo "<input type='hidden' name'is_dynamic' value='0'>";
echo "<input type='submit' name='adduser' value=\"".$LANG['buttons'][8]."\"
......@@ -284,17 +289,28 @@ class Group_User extends CommonDBRelation{
if (count($used)) {
Session::initNavigateListItems('User', $group->getTypeName()." = ".$group->getName());
foreach (array(1,0) as $is_manager) {
echo "<div id='groupuser_form$rand-$is_manager' class='spaced'>";
$items = array(
0 => "is_manager",
1 => "is_userdelegate",
2 => "is_user");
foreach ($items as $key => $role) {
echo "<div id='groupuser_form$rand-$role' class='spaced'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='$headerspan'>".($is_manager?$LANG['common'][64]:$LANG['Menu'][14]).
" (D=".$LANG['profiles'][29].")";
$title = $LANG['Menu'][14]." (D=".$LANG['profiles'][29].")";
if ($role == "is_manager") {
$title = $LANG['common'][64];
} else if ($role == "is_userdelegate") {
$title = $LANG['common'][123];
}
echo "<tr><th colspan='$headerspan'>".$title;
echo "</th></tr>";
$i = 0;
$user = new User();
foreach ($used as $id => $data) {
if ($data['is_manager'] != $is_manager || !$user->can($id, 'r')) {
if ((isset($data[$role]) && !$data[$role]) || !$user->can($id, 'r')) {
// For recursive group, could be in another (sister) entity
continue;
}
......@@ -335,12 +351,15 @@ class Group_User extends CommonDBRelation{
echo "</table>";
if ($canedit && $i) {
Html::openArrowMassives("groupuser_form$rand-$is_manager", true);
Html::openArrowMassives("groupuser_form$rand-$role", true);
$actions = array('deleteuser' => $LANG['buttons'][6]);
if ($is_manager) {
if ($role == "is_manager") {
$actions['unset_manager'] = $LANG['users'][20];
} else if ($role == "is_userdelegate") {
$actions['unset_delegate'] = $LANG['users'][25];
} else {
$actions['set_manager'] = $LANG['users'][19];
$actions['set_delegate'] = $LANG['users'][24];
}
Html::closeArrowMassives($actions);
}
......
......@@ -132,6 +132,7 @@ class Ticket extends CommonITILObject {
}
return (Session::haveRight("show_all_ticket","1")
|| $this->fields["users_id_recipient"] === Session::getLoginUserID()
|| $this->isUser(parent::REQUESTER,Session::getLoginUserID())
|| $this->isUser(parent::OBSERVER,Session::getLoginUserID())
|| (Session::haveRight("show_group_ticket",'1')
......@@ -1121,7 +1122,7 @@ class Ticket extends CommonITILObject {
&& $user->getFromDB($input["_users_id_requester"])) {
$input['users_locations'] = $user->fields['locations_id'];
}
$input = $rules->processAllRules($input, $input, array('recursive' => true));
// Restore slas_id
......@@ -2835,6 +2836,8 @@ class Ticket extends CommonITILObject {
// Set default values...
$values = array('_users_id_requester_notif' => array('use_notification' => ($email==""?0:1)),
'delegate' => 0,
'_users_id_requester' => 0,
'name' => '',
'content' => '',
'itilcategories_id' => 0,
......@@ -2846,7 +2849,8 @@ class Ticket extends CommonITILObject {
'due_date' => 'NULL',
'slas_id' => 0,
'_add_validation' => 0,
'type' => -1);
'type' => -1,
'right' => "id");
// Restore saved value or override with page parameter
......@@ -2864,6 +2868,47 @@ class Ticket extends CommonITILObject {
echo "<form method='post' name='helpdeskform' action='".
$CFG_GLPI["root_doc"]."/front/tracking.injector.php' enctype='multipart/form-data'>";
}
$delegating = User::getDelegateGroupsForUser();
if (!empty($delegating)) {
echo "<div class='center'><table class='tab_cadre_fixe'>";
echo "<tr><th colspan='2'>".$LANG['job'][69]."&nbsp;:&nbsp;";
$items[0] = $LANG['choice'][1];
$items[1] = $LANG['choice'][0];
$rand = Dropdown::showFromArray("delegate", $items, array("value" => $options['delegate']));
$params = array ('delegate' => '__VALUE__',
'rand' => $rand,
'right' => "delegate",
'_users_id_requester' => $options['_users_id_requester'],
'_users_id_requester_notif' => $options['_users_id_requester_notif']['use_notification'],
'use_notification' => $options['_users_id_requester_notif']['use_notification'],
'entity_restrict' => $_SESSION["glpiactive_entity"]);
Ajax::UpdateItemOnSelectEvent("dropdown_delegate".$rand, "show_result".$rand, $CFG_GLPI["root_doc"].
"/ajax/dropdownDelegationUsers.php", $params);
echo "</th></tr>";
echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
echo "<div id='show_result$rand'>";
$self = new self();
if ($options["_users_id_requester"] == 0) {
$options['_users_id_requester'] = Session::getLoginUserID();
} else {
$options['right'] = "delegate";
}
$self->showActorAddFormOnCreate(self::REQUESTER, $options);
echo "</div>";
echo "</td></tr>";
echo "</table>";
echo "<input type='hidden' name='_users_id_recipient' value='".Session::getLoginUserID()."'>";
}
echo "<input type='hidden' name='_from_helpdesk' value='1'>";
echo "<input type='hidden' name='requesttypes_id' value='".RequestType::getDefault('helpdesk').
"'>";
......@@ -2980,26 +3025,27 @@ class Ticket extends CommonITILObject {
echo "</td></tr>";
}
}
if (NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) {
if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) {
echo "<tr class='tab_bg_1'>";
echo "<td>".$LANG['help'][8]."&nbsp;:&nbsp;</td>";
echo "<td>";
$_REQUEST['value'] = Session::getLoginUserID();
if ($options["_users_id_requester"] == 0) {
$options['_users_id_requester'] = Session::getLoginUserID();
}
$_REQUEST['value'] = $options['_users_id_requester'];
$_REQUEST['field'] = '_users_id_requester_notif';
$_REQUEST['use_notification'] = $options['_users_id_requester_notif']['use_notification'];
include (GLPI_ROOT."/ajax/uemailUpdate.php");
echo "</td></tr>";
}
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]!=0) {
if (!$tt->isHiddenField('itemtype')) {
echo "<tr class='tab_bg_1'>";
echo "<td>".$LANG['help'][24]."&nbsp;:".$tt->getMandatoryMark('itemtype')."</td>";
echo "<td>";
self::dropdownMyDevices(Session::getLoginUserID(), $_SESSION["glpiactive_entity"]);
self::dropdownMyDevices($options['_users_id_requester'], $_SESSION["glpiactive_entity"]);
self::dropdownAllDevices("itemtype", $options['itemtype'], $options['items_id'], 0,
$_SESSION["glpiactive_entity"]);
echo "<span id='item_ticket_selection_information'></span>";
......
......@@ -2090,8 +2090,29 @@ class User extends CommonDBTM {
return $tab;
}
/**
* Get all groups where the current user have delegating
*
* @return array of groups id
* @since version 0.83
**/
static function getDelegateGroupsForUser() {
$restrict = "`users_id` = '".Session::getLoginUserID()."'
AND `glpi_groups_users`.`is_userdelegate` = '1'";
$datas = getAllDatasFromTable("glpi_groups_users",$restrict);
$groups = array();
if (count($datas)) {
foreach ($datas as $link) {
$groups[$link['groups_id']] = $link['groups_id'];
}
}
return $groups;
}
/**
* Execute the query to select box with all glpi users where select key = name
*
......@@ -2126,7 +2147,42 @@ class User extends CommonDBTM {
case "id" :
$where = " `glpi_users`.`id` = '".Session::getLoginUserID()."' ";
break;
case "delegate" :
$groups = self::getDelegateGroupsForUser();
$users = array();
if (count($groups)) {
$query = "SELECT `glpi_users`.`id`
FROM `glpi_groups_users`
LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_groups_users`.`users_id`)
WHERE `glpi_groups_users`.`groups_id` IN ('".implode("','",$ID)."')
AND `glpi_groups_users`.`users_id` <> '".Session::getLoginUserID()."' ";
$result = $DB->query($query);
if ($DB->numrows($result)) {
while ($data=$DB->fetch_array($result)) {
$users[$data["id"]] = $data["id"];
}
}
}
// Add me to users list for central
if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
$users[Session::getLoginUserID()] = Session::getLoginUserID();
}
if (count($users)) {
$where = " `glpi_users`.`id` IN ('".implode("','",$users)."')";
} else {
$where = '0';
}
break;
case "all" :
$where = " `glpi_users`.`id` > '1' ".
getEntitiesRestrictRequest("AND","glpi_profiles_users",'',$entity_restrict,1);
......@@ -2216,6 +2272,7 @@ class User extends CommonDBTM {
$query .= " LIMIT 0,".$CFG_GLPI["dropdown_max"];
}
}
return $DB->query($query);
}
......
......@@ -2046,10 +2046,12 @@ CREATE TABLE `glpi_groups_users` (
`groups_id` int(11) NOT NULL DEFAULT '0',
`is_dynamic` tinyint(1) NOT NULL DEFAULT '0',
`is_manager` tinyint(1) NOT NULL DEFAULT '0',
`is_userdelegate` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`users_id`,`groups_id`),
KEY `groups_id` (`groups_id`),
KEY `is_manager` (`is_manager`)
KEY `is_manager` (`is_manager`),
KEY `is_userdelegate` (`is_userdelegate`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
......
......@@ -1232,6 +1232,11 @@ function update0803to083() {
$migration->displayMessage($LANG['update'][142] . ' - various fields add');
// Ticket delegation
$migration->addField('glpi_groups_users', 'is_userdelegate', 'bool');
$migration->addKey('glpi_groups_users', 'is_userdelegate');
//Software dictionnary update
$migration->addField("glpi_rulecachesoftwares", "entities_id", "string");
$migration->addField("glpi_rulecachesoftwares", "new_entities_id", "string");
......@@ -1244,13 +1249,13 @@ function update0803to083() {
$migration->addField('glpi_groups', 'is_notify', 'bool', array('value' => '1'));
$migration->addField('glpi_groups', 'is_itemgroup', 'bool', array('value' => '1'));
$migration->addField('glpi_groups', 'is_usergroup', 'bool', array('value' => '1'));
$migration->addKey('glpi_groups', 'is_requester');
$migration->addKey('glpi_groups', 'is_assign');
$migration->addKey('glpi_groups', 'is_notify');
$migration->addKey('glpi_groups', 'is_itemgroup');
$migration->addKey('glpi_groups', 'is_usergroup');
// Ticket solution by entity
$migration->addfield('glpi_solutiontypes', 'entities_id', 'integer');
$migration->addfield('glpi_solutiontypes', 'is_recursive', 'bool', array('value' => '1'));
......
......@@ -380,6 +380,8 @@ $LANG['common'][118] = "Opération échouée";
$LANG['common'][119] = "échec(s)";
$LANG['common'][120] = "réussite(s)";
$LANG['common'][121] = "problème(s) d'habilitation";
$LANG['common'][122] = "Rôle";
$LANG['common'][123] = "Délégataire";
......@@ -1055,6 +1057,7 @@ $LANG['job'][65] = "Champ obligatoire";
$LANG['job'][66] = "Gabarit pour une demande";
$LANG['job'][67] = "Gabarit pour un incident";
$LANG['job'][68] = "Des champs obligatoires ne sont pas renseignés. Veuillez corriger :";
$LANG['job'][69] = "Ce ticket me concerne";
$LANG['joblist'][0] = "Statut";
$LANG['joblist'][1] = "Seulement les miens";
......@@ -2638,6 +2641,8 @@ $LANG['users'][20] = "Supprimer des superviseurs";
$LANG['users'][21] = "Courriel par défaut";
$LANG['users'][22] = "Titres des utilisateurs";
$LANG['users'][23] = "Catégories des utilisateurs";
$LANG['users'][24] = "Ajouter aux délégataires";
$LANG['users'][25] = "Supprimer des délégataires";
$LANG['validation'][0] = "Validation";
$LANG['validation'][1] = "Envoyer une demande de validation";
......
......@@ -195,8 +195,9 @@ function addDocuments($type, $ID) {
* @param $ID_entity entity ID
**/
function addInfocoms($type, $ID, $ID_entity, $is_recursive=0) {
global $DB, $FIRST, $LAST,$current_year;
global $DB, $FIRST, $LAST;
$current_year = date('Y');
$orderdate = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
$buydate = $orderdate+mt_rand(0, 60)*DAY_TIMESTAMP;
......@@ -1280,11 +1281,11 @@ function generate_entity($ID_entity) {
$DB->query($query) or die("PB REQUETE ".$query);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0)";
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0, 0)";
$DB->query($query) or die("PB REQUETE ".$query);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '".mt_rand($FIRST['techgroups'], $LAST['techgroups'])."', 0, 0)";
VALUES (NULL, '$user_id', '".mt_rand($FIRST['techgroups'], $LAST['techgroups'])."', 0, 0, 0)";
$DB->query($query) or die("PB REQUETE ".$query);
}
......@@ -1308,12 +1309,12 @@ function generate_entity($ID_entity) {
$group = mt_rand($FIRST['groups'], $LAST['groups']);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '$group', 0, 1)";
VALUES (NULL, '$user_id', '$group', 0, 1, 1)";
$DB->query($query) or die("PB REQUETE ".$query);
$group = mt_rand($FIRST['techgroups'], $LAST['techgroups']);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '$group', 0, 1)";
VALUES (NULL, '$user_id', '$group', 0, 1, 1)";
$DB->query($query) or die("PB REQUETE ".$query);
}
......@@ -1337,11 +1338,11 @@ function generate_entity($ID_entity) {
$DB->query($query) or die("PB REQUETE ".$query);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0)";
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0, 0)";
$DB->query($query) or die("PB REQUETE ".$query);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '".mt_rand($FIRST['techgroups'], $LAST['techgroups'])."', 0, 0)";
VALUES (NULL, '$user_id', '".mt_rand($FIRST['techgroups'], $LAST['techgroups'])."', 0, 0, 0)";
$DB->query($query) or die("PB REQUETE ".$query);
}
......@@ -1365,7 +1366,7 @@ function generate_entity($ID_entity) {
$DB->query($query) or die("PB REQUETE ".$query);
$query = "INSERT INTO `glpi_groups_users`
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0)";
VALUES (NULL, '$user_id', '".mt_rand($FIRST['groups'], $LAST['groups'])."', 0, 0, 0)";
$DB->query($query) or die("PB REQUETE ".$query);
}
......@@ -1620,7 +1621,7 @@ function generate_entity($ID_entity) {
'0.0000', '0', '', NULL, '')";
$DB->query($query) or die("PB REQUETE ".$query);
}
$LAST["budget"] = getMaxItem("glpi_budgets");
// GLobal ones
for ($i=0 ; $i<$MAX['document']/2 ; $i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment