Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ajax/dropdownResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@
$plugin_resources_contracttypes_id = $_GET["plugin_resources_contracttypes_id"];
}

$isNotLeavingOnly = false;
if (isset($_GET['condition']) && isset($_GET['condition']['is_not_leaving_only'])) {
$isNotLeavingOnly = true;
}

$result = Resource::getSqlSearchResult(
false,
$_GET["entity"],
$_GET['value2'],
$used,
$_GET['searchText']
$_GET['searchText'],
false,
$isNotLeavingOnly,
);

$users = [];
Expand Down
2 changes: 1 addition & 1 deletion ajax/leavingform.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
echo __('Resource manager', 'resources');
echo "</div>";
echo "<div class='col-md-4 mb-2'>";
User::dropdown(['name' => 'remove_manager', 'right' => 'all']);
User::dropdown(['name' => 'remove_manager', 'right' => 'all', 'value' => $resource->fields['users_id']]);
echo "</div>";
echo "</div>";
}
Expand Down
155 changes: 18 additions & 137 deletions ajax/validinformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@
}
}

$ticket->fields["content"] = $content;
if (substr_count($content, 'r<br>') > 1) {
$content = str_replace('r<br>', '<br>', $content);
}
$ticket->fields["content"] = addslashes($content);

$ticket->fields['users_id_recipient'] = Session::getLoginUserID();
$ticket->fields['_users_id_requester'] = Session::getLoginUserID();
Expand All @@ -161,140 +164,18 @@
unset($ticket->fields["id"]);
$ticket_id = $ticket->add($ticket->fields);

$authLDAP = new AuthLDAP();
$auth = $authLDAP->find();
if (count($auth)) {
$config = new Config();
$configAD = new Adconfig();
$config->getFromDB(1);
$configAD->getFromDB(1);
$configAD->fields = $configAD->prepareFields($configAD->fields);
$canedit = $resource->can($resource->fields['id'], UPDATE);
$entities_id = $resource->fields["entities_id"];
$plugin_resources_contracttypes_id = $resource->fields["plugin_resources_contracttypes_id"];
$rand = mt_rand();
$enddate = $resource->getField("date_end");

$linkAD = new LinkAd();
$linkAD->getEmpty();
$islink = $linkAD->getFromDBByCrit(["plugin_resources_resources_id" => $resource->getID()]);

if (!$islink) {
$ret = LinkAd::processLogin($resource);
$linkAD->fields["login"] = $ret[0];
$logAvailable = $ret[1];

$mail = LinkAd::processMail($resource, $linkAD->fields["login"]);
$linkAD->fields["mail"] = $mail;
$role = Dropdown::getDropdownName(Role::getTable(), $resource->fields['plugin_resources_roles_id']);
$linkAD->fields["role"] = $role;
$service = Dropdown::getDropdownName(Service::getTable(), $resource->fields['plugin_resources_services_id']);
$linkAD->fields["service"] = $service;
$location = Dropdown::getDropdownName(Location::getTable(), $resource->fields['locations_id']);
$linkAD->fields["location"] = $location;
}


$ID = $linkAD->getID();
$value = [
'plugin_resources_resources_id' => $resource->fields['id'],
'tickets_id' => $ticket_id,
'plugin_resources_contracttypes_id' => $plugin_resources_contracttypes_id,
'entities_id' => $entities_id,
'enddate' => $enddate,
'id' => $ID,
'login' => $linkAD->fields["login"],
'department' => Dropdown::getDropdownName('glpi_plugin_resources_departments', $resource->getField("plugin_resources_departments_id")),
'glpi_plugin_resources_departments' => $resource->getField("plugin_resources_departments_id"),
'name' => $resource->getField("name"),
'firstname' => $resource->getField("firstname"),
'phone' => $resource->getField('phone'),
'mail' => $linkAD->fields["mail"],
'contract' => Dropdown::getDropdownName('glpi_plugin_resources_contracttypes', $resource->getField("plugin_resources_contracttypes_id")),
'glpi_plugin_resources_contracttypes' => $resource->getField("plugin_resources_contracttypes_id"),
'cellphone' => $resource->getField("cellphone"),
'role' => $resource->getField('plugin_resources_roles_id'),
'service' => $resource->getField('plugin_resources_services_id'),
'location' => $resource->getField('locations_id'),
];

$linkad = new LinkAd();

if (!$islink) {

//Création
$ldap = new LDAP();
$res = $ldap->createUserAD($value);
if($res){
$value["action_done"] = 1;
$linkad->add($value);
$fup = new ITILFollowup();

$toadd = ['type' => "new",
'items_id' => $value["ticket_id"],
'itemtype' => 'Ticket',
'is_private' => 1];


$content = $DB->escape(sprintf(__('%1$s %2$s have been added in the LDAP directory','resources'),$value["firstname"],$value["name"]));
$toadd["content"] = htmlentities($content,ENT_NOQUOTES);

$fup->add($toadd);
$message = __('the user has been added to the LDAP directory','resources');
Session::addMessageAfterRedirect($message, false, INFO);
}else{
$message = __('the user has not been added to the LDAP directory','resources');
Session::addMessageAfterRedirect($message, false, ERROR);
}
}
else {

//update
$ldap = new LDAP();
$linkad->getFromDB($value['id']);
$value["login"] = $linkad->getField("login");
$res = $ldap->updateUserAD($value);
if($res[0]){

$value["action_done"] = 1;
$linkad->update($value);
$fup = new ITILFollowup();

$toadd = ['type' => "new",
'items_id' => $value["ticket_id"],
'itemtype' => 'Ticket',
'is_private' => 1];

$content = $DB->escape(sprintf(__('%1$s %2$s have been updated in the LDAP directory','resources'),$value["firstname"],$value["name"]));
$content .= __("Data changed",'resources')." <br />";
foreach ($res[1] as $key => $oldData){
$i =1;
$nb =count($oldData);
$content .= $key." : ";
foreach ($oldData as $data){
if($key == "accountexpires"){
$time = $ldap->ldapTimeToUnixTime($data);
$data = date('Y-m-d',$time);
$data = Html::convDate($data);

}
$content.=$data;
if($i<$nb){
$content.=", ";
}
$i++;
}
$content .= "<br />";

}
$toadd["content"] = htmlentities($content,ENT_NOQUOTES);

$fup->add($toadd);
$message = __('the user has been updated to the LDAP directory','resources');
Session::addMessageAfterRedirect($message, false, INFO);
}else{
$message = __('the user has not been updated to the LDAP directory','resources');
Session::addMessageAfterRedirect($message, false, ERROR);
}
}
if ($config->fields['use_module_duplicata_ticket'] && $config->fields['use_module_validation'] && $config->fields["send_second_ticket_validation"] && $config->fields["assignment_group_second_ticket"]) {
$ticket->fields['users_id_recipient'] = Session::getLoginUserID();
$ticket->fields['_users_id_requester'] = Session::getLoginUserID();
$ticket->fields["type"] = Ticket::DEMAND_TYPE;
$ticket->fields["entities_id"] = $_SESSION['glpiactive_entity'];
$ticket->fields['items_id'] = [Resource::class => [$resource->fields['id']]];
unset($ticket->fields["id"]);
$ticket_id = $ticket->add($ticket->fields);
$groupticket = new Group_Ticket();
$groupticket->fields['tickets_id'] = $ticket_id;
$groupticket->fields['groups_id'] = $config->fields["assignment_group_second_ticket"];
$groupticket->fields['type'] = CommonITILActor::ASSIGN;
unset($groupticket->fields["id"]);
$groupticket->add($groupticket->fields);
}
Loading