function displayUser(User $user)
{
printf("\nLogin: %s\n", $user->getField('name'));
printf("Name: %s\n", $user->getRawName());
printf("Password: %s\n", $user->getField('password'));
// ? 'set' : 'sot set');
printf("Authent: %s\n", Auth::getMethodName($user->getField('authtype'), $user->getField('auths_id')));
printf("Active: %s\n\n", $user->getField('is_active') ? 'yes' : 'no');
}
/**
* Get tech related to the task
*
* @param $options array
**/
function getTaskAssignUser()
{
$item = new $this->obj->fields['itemtype']();
if ($item->getFromDB($this->obj->fields['items_id'])) {
$user = new User();
if ($item->isField('users_id_tech') && $user->getFromDB($item->getField('users_id_tech'))) {
$this->addToAddressesList(array('language' => $user->getField('language'), 'users_id' => $user->getField('id')));
}
}
}
/**
* Show table wiht linked licenses to user
* @param User $user
*/
static function showLicenses(User $user)
{
global $DB;
$ID = $user->getField('id');
echo "<div class='spaced'><table class='tab_cadre_fixehov'>";
$header = "<tr><th>" . __('Software') . "</th>";
$header .= "<th>" . __('Licenses') . "</th>";
$header .= "<th>" . __('Added') . "</th></tr>";
echo $header;
$query = "SELECT\n ul.added,\n sl.name AS licenses_name,\n s.name AS software_name,\n\t\t\t\tsl.id AS licenses_id,\n\t\t\t\ts.id AS software_id\n FROM\n glpi_users_softwarelicenses ul\n JOIN glpi_softwarelicenses sl ON (sl.id = ul.softwarelicenses_id)\n JOIN glpi_softwares s ON (s.id = sl.softwares_id)\n WHERE\n ul.users_id = '{$ID}'\n ORDER BY\n ul.added DESC";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
echo "<tr class='tab_bg_1'>";
echo "<td class='center'><a href='software.form.php?id=" . $data['software_id'] . "'>" . $data["software_name"] . "</a></td>";
echo "<td class='center'><a href='softwarelicense.form.php?id=" . $data['licenses_id'] . "'>" . $data["licenses_name"] . "</a></td>";
echo "<td class='center' style='width:20%'>" . $data["added"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr class='tab_bg_1'><td class='center' colspan='3'>No results.</td></tr>";
}
echo "</table></div>";
return true;
}
/**
* @see NotificationTarget::getSpecificTargets()
**/
function getSpecificTargets($data, $options)
{
$user = new User();
if ($user->getFromDB($this->obj->fields['users_id'])) {
$this->addToAddressesList(array('language' => $user->getField('language'), 'users_id' => $user->getID()));
}
}
public function postLists()
{
User::onlyHas('user-view');
$jqgrid = new jQgrid(User::getTableName());
return $jqgrid->populate(function ($start, $limit) {
return User::select(User::getField('id'), User::getField('username'), User::getField('email'))->skip($start)->take($limit)->get();
});
}
/**
* Add team users to the notified user list
**/
function getTeamUsers()
{
global $DB;
$query = "SELECT `items_id`\n FROM `glpi_projecttaskteams`\n WHERE `glpi_projecttaskteams`.`itemtype` = 'User'\n AND `glpi_projecttaskteams`.`projecttasks_id` = '" . $this->obj->fields["id"] . "'";
$user = new User();
foreach ($DB->request($query) as $data) {
if ($user->getFromDB($data['items_id'])) {
$this->addToAddressesList(array('language' => $user->getField('language'), 'users_id' => $user->getField('id')));
}
}
}
/**
* Get the email of the item's user
**/
function getItemAuthorAddress()
{
$user = new User();
if ($this->obj->isField('users_id') && $user->getFromDB($this->obj->getField('users_id'))) {
$this->addToAddressesList(array('language' => $user->getField('language'), 'users_id' => $user->getField('id')));
}
}
/**
* Show rights of a user
*
* @param $user User object
**/
static function showForUser(User $user)
{
global $DB, $CFG_GLPI, $LANG;
$ID = $user->getField('id');
if (!$user->can($ID, 'r')) {
return false;
}
$canedit = $user->can($ID, 'w');
$strict_entities = self::getUserEntities($ID, false);
if (!haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
$canedit = false;
}
$canshowentity = haveRight("entity", "r");
$rand = mt_rand();
echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
echo getItemTypeFormURL(__CLASS__) . "'>";
if ($canedit) {
echo "<div class='firstbloc'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['setup'][605] . "</tr>";
echo "<tr class='tab_bg_2'><td class='center'>";
echo "<input type='hidden' name='users_id' value='{$ID}'>";
Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities']));
echo "</td><td class='center'>" . $LANG['profiles'][22] . " : ";
Profile::dropdownUnder(array('value' => Profile::getDefault()));
echo "</td><td class='center'>" . $LANG['profiles'][28] . " : ";
Dropdown::showYesNo("is_recursive", 0);
echo "</td><td class='center'>";
echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
echo "</td></tr>";
echo "</table></div>";
}
echo "<div class='spaced'><table class='tab_cadre_fixehov'>";
echo "<tr><th colspan='2'>" . $LANG['Menu'][37] . "</th>";
echo "<th>" . $LANG['profiles'][22] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")";
echo "</th></tr>";
$query = "SELECT DISTINCT `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles`.`id`,\n `glpi_profiles`.`name`,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`,\n `glpi_entities`.`completename`,\n `glpi_profiles_users`.`entities_id`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_profiles_users`.`entities_id` = `glpi_entities`.`id`)\n WHERE `glpi_profiles_users`.`users_id` = '{$ID}'\n ORDER BY `glpi_profiles`.`name`, `glpi_entities`.`completename`";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_array($result)) {
echo "<tr class='tab_bg_1'>";
echo "<td width='10'>";
if ($canedit && in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>";
} else {
echo " ";
}
echo "</td>";
if ($data["entities_id"] == 0) {
$data["completename"] = $LANG['entity'][2];
}
echo "<td>";
if ($canshowentity) {
echo "<a href='" . getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
}
echo $data["completename"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["entities_id"] . ")" : "");
if ($canshowentity) {
echo "</a>";
}
echo "</td>";
echo "<td>" . $data["name"];
if ($data["is_dynamic"] || $data["is_recursive"]) {
echo "<strong> (";
if ($data["is_dynamic"]) {
echo "D";
}
if ($data["is_dynamic"] && $data["is_recursive"]) {
echo ", ";
}
if ($data["is_recursive"]) {
echo "R";
}
echo ")</strong>";
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
if ($canedit) {
openArrowMassive("entityuser_form{$rand}", true);
closeArrowMassive('delete', $LANG['buttons'][6]);
}
echo "</form></div>";
}
// Purpose of file:
// ----------------------------------------------------------------------
$AJAX_INCLUDE = 1;
if (strpos($_SERVER['PHP_SELF'], "uemailUpdate.php")) {
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
header_nocache();
}
checkLoginUser();
// print_r($_REQUEST);
if (isset($_REQUEST['field']) && $_REQUEST["value"] > 0 || isset($_REQUEST['allow_email']) && $_REQUEST['allow_email']) {
$user = new User();
$email = "";
if ($user->getFromDB($_REQUEST["value"])) {
$email = $user->getField('email');
}
echo $LANG['job'][19] . ' : ';
$default_notif = true;
if (isset($_REQUEST['use_notification'])) {
$default_notif = $_REQUEST['use_notification'];
}
$rand = Dropdown::showYesNo($_REQUEST['field'] . '[use_notification]', $default_notif);
echo '<br>' . $LANG['mailing'][118] . " : ";
if (!empty($email) && NotificationMail::isUserAddressValid($email)) {
echo $email;
} else {
echo "<input type='text' size='25' name='" . $_REQUEST['field'] . "[alternative_email]'\n value='{$email}'>";
}
}
commonDropdownUpdateItem($_POST);
/**
* Print the ticket user form for notification
*
* @param $ID integer ID of the item
* @param $options array
*
* @return Nothing (display)
**/
function showForm($ID, $options = array())
{
global $CFG_GLPI, $LANG;
$this->check($ID, 'w');
echo "<br><form method='post' action='" . $CFG_GLPI['root_doc'] . "/front/popup.php'>";
echo "<div class='center'>";
echo "<table class='tab_cadre'>";
echo "<tr class='tab_bg_2'><td>" . $LANG['job'][38] . " :</td>";
echo "<td>";
$ticket = new Ticket();
if ($ticket->getFromDB($this->fields["tickets_id"])) {
echo $ticket->getField('name');
}
echo "</td></tr>";
$user = new User();
$email = "";
if ($user->getFromDB($this->fields["users_id"])) {
$email = $user->getField('email');
}
echo "<tr class='tab_bg_2'><td>" . $LANG['common'][34] . " :</td>";
echo "<td>" . $user->getName() . "</td></tr>";
echo "<tr class='tab_bg_1'><td>" . $LANG['job'][19] . " :</td>";
echo "<td>";
Dropdown::showYesNo('use_notification', $this->fields['use_notification']);
echo "</td></tr>";
echo "<tr class='tab_bg_1'><td>" . $LANG['mailing'][118] . " :</td>";
echo "<td>";
if (!empty($email) && NotificationMail::isUserAddressValid($email)) {
echo $email;
} else {
echo "<input type='text' size='40' name='alternative_email' value='" . $this->fields['alternative_email'] . "'>";
}
echo "</td></tr>";
echo "<tr class='tab_bg_2'>";
echo "<td class='center' colspan='2'>";
echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>";
echo "<input type='hidden' name='id' value='{$ID}'>";
echo "</td></tr>";
echo "</table></div></form>";
}
/**
* Get entities for which a user have a right
*
* @param $user_ID user ID
* @param $is_recursive check also using recursive rights (true by default)
* @param $default_first user default entity first (false by default)
*
* @return array of entities ID
**/
static function getUserEntities($user_ID, $is_recursive = true, $default_first = false)
{
global $DB;
$query = "SELECT DISTINCT `entities_id`, `is_recursive`\n FROM `glpi_profiles_users`\n WHERE `users_id` = '{$user_ID}'";
$result = $DB->query($query);
if ($DB->numrows($result) > 0) {
$entities = array();
while ($data = $DB->fetch_assoc($result)) {
if ($data['is_recursive'] && $is_recursive) {
$tab = getSonsOf('glpi_entities', $data['entities_id']);
$entities = array_merge($tab, $entities);
} else {
$entities[] = $data['entities_id'];
}
}
// Set default user entity at the begin
if ($default_first) {
$user = new User();
if ($user->getFromDB($user_ID)) {
$ent = $user->getField('entities_id');
if (in_array($ent, $entities)) {
array_unshift($entities, $ent);
}
}
}
return array_unique($entities);
}
return array();
}
/**
* @see Rule::executeActions()
**/
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
switch ($action->fields["field"]) {
default:
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "_affect_entity_by_user_entity":
//3 cases :
//1 - rule contains a criteria like : Profil is XXXX
// -> in this case, profiles_id is stored in
// $this->criterias_results['PROFILES'] (one value possible)
//2- rule contains criteria "User has only one profile"
// -> in this case, profiles_id is stored in
// $this->criterias_results['PROFILES'] (one value possible) (same as 1)
//3 -> rule contains only one profile
$profile = 0;
//Case 2:
if (isset($this->criterias_results['ONE_PROFILE'])) {
$profile = $this->criterias_results['ONE_PROFILE'];
//Case 3
} else {
if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
$profile = $this->criterias_results['UNIQUE_PROFILE'];
//Case 1
} else {
if (isset($this->criterias_results['PROFILES'])) {
$profile = $this->criterias_results['PROFILES'];
}
}
}
if ($profile) {
$entities = array();
if (isset($params['_users_id_requester'])) {
// Not set when testing
$entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile);
}
//Case 2 : check if there's only one profile for this user
if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) {
if (count($entities) == 1) {
//User has right on only one entity
$output['entities_id'] = array_pop($entities);
} else {
if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
$output['entities_id'] = array_pop($entities);
} else {
//Rights on more than one entity : get the user's prefered entity
if (isset($params['_users_id_requester'])) {
// Not set when testing
$user = new User();
$user->getFromDB($params['_users_id_requester']);
$tmpid = $user->getField('entities_id');
// Retrieve all the entities (pref could be set on a child)
$entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile, true);
// If an entity is defined in user's preferences,
// and this entity allowed for this profile, use this one
// else do not set the rule as matched
if (in_array($tmpid, $entities)) {
$output['entities_id'] = $user->fields['entities_id'];
}
}
}
}
}
}
}
break;
case "regex_result":
foreach ($this->regex_results as $regex_result) {
$entity_found = -1;
$res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
if ($res != null) {
switch ($action->fields["field"]) {
case "_affect_entity_by_domain":
$entity_found = Entity::getEntityIDByDomain(addslashes($res));
break;
case "_affect_entity_by_tag":
$entity_found = Entity::getEntityIDByTag(addslashes($res));
break;
}
//If an entity was found
if ($entity_found > -1) {
$output['entities_id'] = $entity_found;
break;
}
}
}
// switch (field)
break;
}
}
}
return $output;
}
$isvisible = $usr->getField("visibleTo");
if ($isvisible == "guest" || $isvisible == "everyone") {
// get background URL
$json["status"] = 1;
$json["statusInfo"] = "success";
$json["appid"] = $rs;
//$appid;
$json["imported_appid"] = $appid;
$json["appBackgroundImageURL"] = AbstractDB::APP_BACKGROUND . $bgURL;
$json["businessJoinURL"] = $businessJoinURL;
// get started button link
} else {
$json["status"] = 1;
$json["statusInfo"] = "success";
$json["appid"] = $rs;
//$appid;
$json["imported_appid"] = $appid;
$json["appBackgroundImageURL"] = "no access";
$json["businessJoinURL"] = $businessJoinURL;
}
} else {
$json["status"] = 1;
$json["statusInfo"] = "success";
$json["appid"] = $rs;
//$appid;
$json["imported_appid"] = $appid;
$json["appBackgroundImageURL"] = "no access";
$json["businessJoinURL"] = $businessJoinURL;
}
//$json["appName"]=$rs;
$json["contact_data"] = $contact;
$json["leftside_navigation_menu"] = $navigation_menu;
if ($sharingsetting == "") {
} else {
$json["appShareSetting"] = $sharingsetting;
}
// get left sidebar navigation menu
//$navigation_menu = $setting->getNavigationMenu($appid,"guest");
// empty same device token record
//$emptydevice = $usr1->emptyguestdevicetoken($guestID,$_REQUEST["deviceToken"]);
//$json["newsCount"]=$newscount;
$newscount = $news->getUnreadNewsCount($appid, $guestID, $role, "app_guestViewedNews", "guestID");
$trainingcount = $news->getUnreadTrainingArticleCount($appid, $guestID, $role, "app_guestViewedTraining", "guestID");
$calendarcount = $news->getUnreadCalendarCount($appid, $guestID, $role, "app_guestViewedCalendar", "guestID");
$mediacount = $news->getUnreadMediaCount($appid, $guestID, $role);
$slidesdocscount = $news->getUnreadSlideDocsCount($appid, $guestID, $role, "app_guestViewedPPTDocs", "guestID");
$unreadflag = 0;
if ($chatcount > 0) {
$unreadflag = 1;
} else {
if ($newscount > 0) {
$unreadflag = 1;
} else {
if ($trainingcount > 0) {
$unreadflag = 1;
} else {
if ($calendarcount > 0) {
$unreadflag = 1;
} else {
if ($mediacount > 0) {
$unreadflag = 1;
} else {
if ($slidesdocscount > 0) {
$unreadflag = 1;
} else {
$unreadflag = 0;
}
}
}
}
}
}
$makeonline = $usr->makeonlineguest($guestID);
$json["newsCount"] = $newscount;
$json["trainingCount"] = $trainingcount;
$json["calendarCount"] = $calendarcount;
$json["mediaCount"] = $mediacount;
$json["slidedocsCount"] = $slidesdocscount;
$json["unreadFlag"] = $unreadflag;
//$json["name"]=$name;
$json["name"] = $appdisplayname;
$json["userProfilePic"] = $profilepic;
$json["userid"] = $guestID;
//$json["userid"]=$userid;
$json["guestID"] = $guestID;
$json["adcode"] = $adcode;
$json["themeColor"] = $themeColor;
$json["useridForPic"] = $userid;
}
} else {
$json["status"] = 0;
$json["statusInfo"] = "fail";
$json["error"] = "Your billing status is pending";
}
}
}
// Member Login
if ($_REQUEST["operation"] == "login") {
if (!isset($_REQUEST["username"]) || !isset($_REQUEST["password"]) || !isset($_REQUEST["deviceToken"]) || !isset($_REQUEST["deviceType"])) {
$json["status"] = 0;
$json["statusInfo"] = "fail";
$json["error"] = "parameter missing";
} else {
// first check user's billing status
require_once $_SERVER["DOCUMENT_ROOT"] . "/account/lib/Check_AppBilling.php";
$VALIDATE = new CHECKTHISAPP_validate();
$flag = $VALIDATE->validate_user($_REQUEST["username"]);
if ($flag) {
$rs = $usr->memberLogin($_REQUEST);
if ($rs == "wrongusernm") {
$json["status"] = 0;
$json["statusInfo"] = "fail";
$json["error"] = "Wrong Username";
} else {
if ($rs == "wrongpass") {
$json["status"] = 0;
$json["statusInfo"] = "fail";
$json["error"] = "Wrong Password";
} else {
$expld = explode("##", $rs);
$memberID = $expld[0];
$appID = $expld[1];
$role = $expld[2];
$name = $expld[3];
$profile_image = $expld[4];
$adcode = $expld[5];
$themecolor = $expld[6];
//$json["name"]=$name;
$appdisplayname = $setting->getAppDisplayName($appID);
$json["name"] = $appdisplayname;
if ($profile_image != "") {
$json["userProfilePic"] = AbstractDB::PROFILE_IMAGE . $profile_image;
} else {
$json["userProfilePic"] = "";
}
$rsupdt = $usr->makeonline($memberID, $_REQUEST["deviceToken"], $_REQUEST["deviceType"]);
// check app is imported from another app
$appid = $setting->chkAppIsImported($appID);
//$businessJoinURL = $setting->getAppJoinBusinessurl($appid);
$businessJoinURL = $setting->getAppJoinBusinessurl($appID);
// changed to 20th Aug 14
$chatcount = $chat->getUnreadChatMessageCount($memberID);
// get app's contact details
$contact = $setting->getAppContactDetails($appID);
// get left sidebar navigation menu
if ($role == "TL") {
$navigation_menu = $setting->getNavigationMenuTL($appid, $appID, $role);
} else {
$navigation_menu = $setting->getNavigationMenu($appid, $appID, $role);
}
//$navigation_menu = $setting->getNavigationMenu($appid,$appID,$role);
// get app's sharing setting data
$sharingsetting = $setting->getAppShareSettingData($appid);
//$newscount = $usr->getUnreadNewsCount($memberID,"member");
$bgrs = $usr->getAppBackground($appid);
$rec = $usr->numofrows();
if ($rec > 0) {
$usr->getrow();
$bgURL = $usr->getField("backgroundImageURL");
/**
* @param $item CommonDBTM object
* @param $options array
* @param $simple (false by default)
**/
function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
{
global $CFG_GLPI, $DB;
$objettype = strtolower($item->getType());
$datas["##{$objettype}.title##"] = $item->getField('name');
$datas["##{$objettype}.content##"] = $item->getField('content');
$datas["##{$objettype}.description##"] = $item->getField('content');
$datas["##{$objettype}.id##"] = sprintf("%07d", $item->getField("id"));
if ($_SESSION['glpiticket_timeline'] == 1) {
$datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . '$1');
} else {
$datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id"));
}
$tab = '$2';
if ($_SESSION['glpiticket_timeline'] == 1) {
$tab = '$1';
}
$datas["##{$objettype}.urlapprove##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . $tab);
$entity = new Entity();
if ($entity->getFromDB($this->getEntity())) {
$datas["##{$objettype}.entity##"] = $entity->getField('completename');
$datas["##{$objettype}.shortentity##"] = $entity->getField('name');
}
$datas["##{$objettype}.storestatus##"] = $item->getField('status');
$datas["##{$objettype}.status##"] = $item->getStatus($item->getField('status'));
$datas["##{$objettype}.urgency##"] = $item->getUrgencyName($item->getField('urgency'));
$datas["##{$objettype}.impact##"] = $item->getImpactName($item->getField('impact'));
$datas["##{$objettype}.priority##"] = $item->getPriorityName($item->getField('priority'));
$datas["##{$objettype}.time##"] = $item->getActionTime($item->getField('actiontime'));
$datas["##{$objettype}.creationdate##"] = Html::convDateTime($item->getField('date'));
$datas["##{$objettype}.closedate##"] = Html::convDateTime($item->getField('closedate'));
$datas["##{$objettype}.solvedate##"] = Html::convDateTime($item->getField('solvedate'));
$datas["##{$objettype}.duedate##"] = Html::convDateTime($item->getField('due_date'));
$datas["##{$objettype}.category##"] = '';
if ($item->getField('itilcategories_id')) {
$datas["##{$objettype}.category##"] = Dropdown::getDropdownName('glpi_itilcategories', $item->getField('itilcategories_id'));
}
$datas["##{$objettype}.authors##"] = '';
$datas['authors'] = array();
if ($item->countUsers(CommonITILActor::REQUESTER)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::REQUESTER) as $tmpusr) {
$uid = $tmpusr['users_id'];
$user_tmp = new User();
if ($uid && $user_tmp->getFromDB($uid)) {
$users[] = $user_tmp->getName();
$tmp = array();
$tmp['##author.id##'] = $uid;
$tmp['##author.name##'] = $user_tmp->getName();
if ($user_tmp->getField('locations_id')) {
$tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id'));
} else {
$tmp['##author.location##'] = '';
}
if ($user_tmp->getField('usertitles_id')) {
$tmp['##author.title##'] = Dropdown::getDropdownName('glpi_usertitles', $user_tmp->getField('usertitles_id'));
} else {
$tmp['##author.title##'] = '';
}
if ($user_tmp->getField('usercategories_id')) {
$tmp['##author.category##'] = Dropdown::getDropdownName('glpi_usercategories', $user_tmp->getField('usercategories_id'));
} else {
$tmp['##author.category##'] = '';
}
$tmp['##author.email##'] = $user_tmp->getDefaultEmail();
$tmp['##author.mobile##'] = $user_tmp->getField('mobile');
$tmp['##author.phone##'] = $user_tmp->getField('phone');
$tmp['##author.phone2##'] = $user_tmp->getField('phone2');
$datas['authors'][] = $tmp;
} else {
// Anonymous users only in xxx.authors, not in authors
$users[] = $tmpusr['alternative_email'];
}
}
$datas["##{$objettype}.authors##"] = implode(', ', $users);
}
$datas["##{$objettype}.openbyuser##"] = '';
if ($item->getField('users_id_recipient')) {
$user_tmp = new User();
$user_tmp->getFromDB($item->getField('users_id_recipient'));
$datas["##{$objettype}.openbyuser##"] = $user_tmp->getName();
}
$datas["##{$objettype}.lastupdater##"] = '';
if ($item->getField('users_id_lastupdater')) {
$user_tmp = new User();
$user_tmp->getFromDB($item->getField('users_id_lastupdater'));
$datas["##{$objettype}.lastupdater##"] = $user_tmp->getName();
}
$datas["##{$objettype}.assigntousers##"] = '';
if ($item->countUsers(CommonITILActor::ASSIGN)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::ASSIGN) as $tmp) {
$uid = $tmp['users_id'];
$user_tmp = new User();
if ($user_tmp->getFromDB($uid)) {
$users[$uid] = $user_tmp->getName();
}
}
$datas["##{$objettype}.assigntousers##"] = implode(', ', $users);
}
$datas["##{$objettype}.assigntosupplier##"] = '';
if ($item->countSuppliers(CommonITILActor::ASSIGN)) {
$suppliers = array();
foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $tmp) {
$uid = $tmp['suppliers_id'];
$supplier_tmp = new Supplier();
if ($supplier_tmp->getFromDB($uid)) {
$suppliers[$uid] = $supplier_tmp->getName();
}
}
$datas["##{$objettype}.assigntosupplier##"] = implode(', ', $suppliers);
}
$datas["##{$objettype}.groups##"] = '';
if ($item->countGroups(CommonITILActor::REQUESTER)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::REQUESTER) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.groups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.observergroups##"] = '';
if ($item->countGroups(CommonITILActor::OBSERVER)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::OBSERVER) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.observergroups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.observerusers##"] = '';
if ($item->countUsers(CommonITILActor::OBSERVER)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::OBSERVER) as $tmp) {
$uid = $tmp['users_id'];
$user_tmp = new User();
if ($uid && $user_tmp->getFromDB($uid)) {
$users[] = $user_tmp->getName();
} else {
$users[] = $tmp['alternative_email'];
}
}
$datas["##{$objettype}.observerusers##"] = implode(', ', $users);
}
$datas["##{$objettype}.assigntogroups##"] = '';
if ($item->countGroups(CommonITILActor::ASSIGN)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::ASSIGN) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.assigntogroups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.solution.type##"] = '';
if ($item->getField('solutiontypes_id')) {
$datas["##{$objettype}.solution.type##"] = Dropdown::getDropdownName('glpi_solutiontypes', $item->getField('solutiontypes_id'));
}
$datas["##{$objettype}.solution.description##"] = Toolbox::unclean_cross_side_scripting_deep($item->getField('solution'));
// Complex mode
if (!$simple) {
$datas['log'] = array();
// Use list_limit_max or load the full history ?
foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) {
$tmp = array();
$tmp["##{$objettype}.log.date##"] = $data['date_mod'];
$tmp["##{$objettype}.log.user##"] = $data['user_name'];
$tmp["##{$objettype}.log.field##"] = $data['field'];
$tmp["##{$objettype}.log.content##"] = $data['change'];
$datas['log'][] = $tmp;
}
$datas["##{$objettype}.numberoflogs##"] = count($datas['log']);
// Get unresolved items
$restrict = "`" . $item->getTable() . "`.`status`\n NOT IN ('" . implode("', '", array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray())) . "'\n )";
if ($item->maybeDeleted()) {
$restrict .= " AND `" . $item->getTable() . "`.`is_deleted` = '0' ";
}
$datas["##{$objettype}.numberofunresolved##"] = countElementsInTableForEntity($item->getTable(), $this->getEntity(), $restrict);
// Document
$query = "SELECT `glpi_documents`.*\n FROM `glpi_documents`\n LEFT JOIN `glpi_documents_items`\n ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n WHERE `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
$datas["documents"] = array();
$addtodownloadurl = '';
if ($item->getType() == 'Ticket') {
$addtodownloadurl = "%2526tickets_id=" . $item->fields['id'];
}
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$tmp = array();
$tmp['##document.id##'] = $data['id'];
$tmp['##document.name##'] = $data['name'];
$tmp['##document.weblink##'] = $data['link'];
$tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']);
$downloadurl = "/front/document.send.php?docid=" . $data['id'];
$tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl . $addtodownloadurl);
$tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
$tmp['##document.filename##'] = $data['filename'];
$datas['documents'][] = $tmp;
}
}
$datas["##{$objettype}.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . '_Document_Item$1');
$datas["##{$objettype}.numberofdocuments##"] = count($datas['documents']);
//costs infos
$costtype = $item->getType() . 'Cost';
$costs = $costtype::getCostsSummary($costtype, $item->getField("id"));
$datas["##{$objettype}.costfixed##"] = $costs['costfixed'];
$datas["##{$objettype}.costmaterial##"] = $costs['costmaterial'];
$datas["##{$objettype}.costtime##"] = $costs['costtime'];
$datas["##{$objettype}.totalcost##"] = $costs['totalcost'];
$restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'";
$restrict .= " ORDER BY `begin_date` DESC, `id` ASC";
$costs = getAllDatasFromTable(getTableForItemType($costtype), $restrict);
$datas['costs'] = array();
foreach ($costs as $cost) {
$tmp = array();
$tmp['##cost.name##'] = $cost['name'];
$tmp['##cost.comment##'] = $cost['comment'];
$tmp['##cost.datebegin##'] = Html::convDate($cost['begin_date']);
$tmp['##cost.dateend##'] = Html::convDate($cost['end_date']);
$tmp['##cost.time##'] = $item->getActionTime($cost['actiontime']);
$tmp['##cost.costtime##'] = Html::formatNumber($cost['cost_time']);
$tmp['##cost.costfixed##'] = Html::formatNumber($cost['cost_fixed']);
$tmp['##cost.costmaterial##'] = Html::formatNumber($cost['cost_material']);
$tmp['##cost.totalcost##'] = CommonITILCost::computeTotalCost($cost['actiontime'], $cost['cost_time'], $cost['cost_fixed'], $cost['cost_material']);
$tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']);
$datas['costs'][] = $tmp;
}
$datas["##{$objettype}.numberofcosts##"] = count($datas['costs']);
//Task infos
$tasktype = $item->getType() . 'Task';
$taskobj = new $tasktype();
$restrict = "`" . $item->getForeignKeyField() . "`='" . $item->getField('id') . "'";
if ($taskobj->maybePrivate() && (!isset($options['additionnaloption']['show_private']) || !$options['additionnaloption']['show_private'])) {
$restrict .= " AND `is_private` = '0'";
}
$restrict .= " ORDER BY `date` DESC, `id` ASC";
$tasks = getAllDatasFromTable($taskobj->getTable(), $restrict);
$datas['tasks'] = array();
foreach ($tasks as $task) {
$tmp = array();
$tmp['##task.id##'] = $task['id'];
if ($taskobj->maybePrivate()) {
$tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']);
}
$tmp['##task.author##'] = Html::clean(getUserName($task['users_id']));
$tmp_taskcatinfo = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id'], true, true, false);
$tmp['##task.categoryid##'] = $task['taskcategories_id'];
$tmp['##task.category##'] = $tmp_taskcatinfo['name'];
$tmp['##task.categorycomment##'] = $tmp_taskcatinfo['comment'];
$tmp['##task.date##'] = Html::convDateTime($task['date']);
$tmp['##task.description##'] = $task['content'];
$tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']);
$tmp['##task.status##'] = Planning::getState($task['state']);
$tmp['##task.user##'] = Html::clean(getUserName($task['users_id_tech']));
$tmp['##task.group##'] = Html::clean(Toolbox::clean_cross_side_scripting_deep(Dropdown::getDropdownName("glpi_groups", $task['groups_id_tech'])), true, 2, false);
$tmp['##task.begin##'] = "";
$tmp['##task.end##'] = "";
if (!is_null($task['begin'])) {
$tmp['##task.begin##'] = Html::convDateTime($task['begin']);
$tmp['##task.end##'] = Html::convDateTime($task['end']);
}
$datas['tasks'][] = $tmp;
}
$datas["##{$objettype}.numberoftasks##"] = count($datas['tasks']);
}
return $datas;
}
/**
* @param $item CommonDBTM object
* @param $options array
* @param $simple (false by default)
**/
function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
{
global $CFG_GLPI, $DB;
$objettype = strtolower($item->getType());
$datas["##{$objettype}.title##"] = $item->getField('name');
$datas["##{$objettype}.content##"] = $item->getField('content');
$datas["##{$objettype}.description##"] = $item->getField('content');
$datas["##{$objettype}.id##"] = sprintf("%07d", $item->getField("id"));
$datas["##{$objettype}.url##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id"));
$datas["##{$objettype}.urlapprove##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . "_" . $item->getType() . '$2');
$entity = new Entity();
if ($entity->getFromDB($this->getEntity())) {
$datas["##{$objettype}.entity##"] = $entity->getField('completename');
$datas["##{$objettype}.shortentity##"] = $entity->getField('name');
}
$datas["##{$objettype}.storestatus##"] = $item->getField('status');
$datas["##{$objettype}.status##"] = $item->getStatus($item->getField('status'));
$datas["##{$objettype}.urgency##"] = $item->getUrgencyName($item->getField('urgency'));
$datas["##{$objettype}.impact##"] = $item->getImpactName($item->getField('impact'));
$datas["##{$objettype}.priority##"] = $item->getPriorityName($item->getField('priority'));
$datas["##{$objettype}.time##"] = $item->getActionTime($item->getField('actiontime'));
$datas["##{$objettype}.creationdate##"] = Html::convDateTime($item->getField('date'));
$datas["##{$objettype}.closedate##"] = Html::convDateTime($item->getField('closedate'));
$datas["##{$objettype}.solvedate##"] = Html::convDateTime($item->getField('solvedate'));
$datas["##{$objettype}.duedate##"] = Html::convDateTime($item->getField('due_date'));
$datas["##{$objettype}.category##"] = '';
if ($item->getField('itilcategories_id')) {
$datas["##{$objettype}.category##"] = Dropdown::getDropdownName('glpi_itilcategories', $item->getField('itilcategories_id'));
}
$datas["##{$objettype}.authors##"] = '';
$datas['authors'] = array();
if ($item->countUsers(CommonITILActor::REQUESTER)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::REQUESTER) as $tmpusr) {
$uid = $tmpusr['users_id'];
$user_tmp = new User();
if ($uid && $user_tmp->getFromDB($uid)) {
$users[] = $user_tmp->getName();
$tmp = array();
$tmp['##author.id##'] = $uid;
$tmp['##author.name##'] = $user_tmp->getName();
if ($user_tmp->getField('locations_id')) {
$tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id'));
} else {
$tmp['##author.location##'] = '';
}
if ($user_tmp->getField('usertitles_id')) {
$tmp['##author.title##'] = Dropdown::getDropdownName('glpi_usertitles', $user_tmp->getField('usertitles_id'));
} else {
$tmp['##author.title##'] = '';
}
if ($user_tmp->getField('usercategories_id')) {
$tmp['##author.category##'] = Dropdown::getDropdownName('glpi_usercategories', $user_tmp->getField('usercategories_id'));
} else {
$tmp['##author.category##'] = '';
}
$tmp['##author.email##'] = $user_tmp->getDefaultEmail();
$tmp['##author.mobile##'] = $user_tmp->getField('mobile');
$tmp['##author.phone##'] = $user_tmp->getField('phone');
$tmp['##author.phone2##'] = $user_tmp->getField('phone2');
$datas['authors'][] = $tmp;
} else {
// Anonymous users only in xxx.authors, not in authors
$users[] = $tmpusr['alternative_email'];
}
}
$datas["##{$objettype}.authors##"] = implode(', ', $users);
}
$datas["##{$objettype}.openbyuser##"] = '';
if ($item->getField('users_id_recipient')) {
$user_tmp = new User();
$user_tmp->getFromDB($item->getField('users_id_recipient'));
$datas["##{$objettype}.openbyuser##"] = $user_tmp->getName();
}
$datas["##{$objettype}.lastupdater##"] = '';
if ($item->getField('users_id_lastupdater')) {
$user_tmp = new User();
$user_tmp->getFromDB($item->getField('users_id_lastupdater'));
$datas["##{$objettype}.lastupdater##"] = $user_tmp->getName();
}
$datas["##{$objettype}.assigntousers##"] = '';
if ($item->countUsers(CommonITILActor::ASSIGN)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::ASSIGN) as $tmp) {
$uid = $tmp['users_id'];
$user_tmp = new User();
if ($user_tmp->getFromDB($uid)) {
$users[$uid] = $user_tmp->getName();
}
}
$datas["##{$objettype}.assigntousers##"] = implode(', ', $users);
}
$datas["##{$objettype}.assigntosupplier##"] = '';
if ($item->countSuppliers(CommonITILActor::ASSIGN)) {
$suppliers = array();
foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $tmp) {
$uid = $tmp['suppliers_id'];
$supplier_tmp = new Supplier();
if ($supplier_tmp->getFromDB($uid)) {
$suppliers[$uid] = $supplier_tmp->getName();
}
}
$datas["##{$objettype}.assigntosupplier##"] = implode(', ', $suppliers);
}
$datas["##{$objettype}.groups##"] = '';
if ($item->countGroups(CommonITILActor::REQUESTER)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::REQUESTER) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.groups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.observergroups##"] = '';
if ($item->countGroups(CommonITILActor::OBSERVER)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::OBSERVER) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.observergroups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.observerusers##"] = '';
if ($item->countUsers(CommonITILActor::OBSERVER)) {
$users = array();
foreach ($item->getUsers(CommonITILActor::OBSERVER) as $tmp) {
$uid = $tmp['users_id'];
$user_tmp = new User();
if ($uid && $user_tmp->getFromDB($uid)) {
$users[] = $user_tmp->getName();
} else {
$users[] = $tmp['alternative_email'];
}
}
$datas["##{$objettype}.observerusers##"] = implode(', ', $users);
}
$datas["##{$objettype}.assigntogroups##"] = '';
if ($item->countGroups(CommonITILActor::ASSIGN)) {
$groups = array();
foreach ($item->getGroups(CommonITILActor::ASSIGN) as $tmp) {
$gid = $tmp['groups_id'];
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$datas["##{$objettype}.assigntogroups##"] = implode(', ', $groups);
}
$datas["##{$objettype}.solution.type##"] = '';
if ($item->getField('solutiontypes_id')) {
$datas["##{$objettype}.solution.type##"] = Dropdown::getDropdownName('glpi_solutiontypes', $item->getField('solutiontypes_id'));
}
$datas["##{$objettype}.solution.description##"] = Toolbox::unclean_cross_side_scripting_deep($item->getField('solution'));
$datas['log'] = array();
// Use list_limit_max or load the full history ?
foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) {
$tmp = array();
$tmp["##{$objettype}.log.date##"] = $data['date_mod'];
$tmp["##{$objettype}.log.user##"] = $data['user_name'];
$tmp["##{$objettype}.log.field##"] = $data['field'];
$tmp["##{$objettype}.log.content##"] = $data['change'];
$datas['log'][] = $tmp;
}
$datas["##{$objettype}.numberoflogs##"] = count($datas['log']);
// Get unresolved items
$restrict = "`" . $item->getTable() . "`.`status`\n NOT IN ('" . implode("', '", array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray())) . "'\n )";
if ($item->maybeDeleted()) {
$restrict .= " AND `" . $item->getTable() . "`.`is_deleted` = '0' ";
}
$datas["##{$objettype}.numberofunresolved##"] = countElementsInTableForEntity($item->getTable(), $this->getEntity(), $restrict);
// Document
$query = "SELECT `glpi_documents`.*\n FROM `glpi_documents`\n LEFT JOIN `glpi_documents_items`\n ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n WHERE `glpi_documents_items`.`itemtype` = '{$objettype}'\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
$datas["documents"] = array();
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$tmp = array();
$tmp['##document.id##'] = $data['id'];
$tmp['##document.name##'] = $data['name'];
$tmp['##document.weblink##'] = $data['link'];
$tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']);
$tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
$tmp['##document.filename##'] = $data['filename'];
$datas['documents'][] = $tmp;
}
}
$datas["##{$objettype}.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], $objettype . "_" . $item->getField("id") . '_Document_Item$1');
$datas["##{$objettype}.numberofdocuments##"] = count($datas['documents']);
return $datas;
}
public static function withRole($role)
{
return UserRole::join(Role::getTableName(), Role::getField('id'), '=', UserRole::getField('role_id'))->join(User::getTableName(), User::getField('id'), '=', UserRole::getField('user_id'))->select(User::getField('*'))->where(Role::getField('key'), $role)->get();
}
/**
* Get all data needed for template processing
**/
function getDatasForTemplate($event, $options = array())
{
global $LANG, $CFG_GLPI;
//----------- Ticket infos -------------- //
if ($event != 'alertnotclosed') {
$fields = array('ticket.title' => 'name', 'ticket.content' => 'content', 'ticket.description' => 'content', 'ticket.costfixed' => 'cost_fixed', 'ticket.costmaterial' => 'cost_material');
foreach ($fields as $tag => $table_field) {
$this->datas['##' . $tag . '##'] = $this->obj->getField($table_field);
}
$this->datas['##ticket.id##'] = sprintf("%07d", $this->obj->getField("id"));
$this->datas['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id"));
$this->datas['##ticket.urlapprove##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_4");
$this->datas['##ticket.urlvalidation##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_7");
$this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->getEntity());
$events = $this->getAllEvents();
if ($event == 'validation' && isset($options['validation_status'])) {
$this->datas['##ticket.action##'] = $LANG['validation'][0] . ' - ' . TicketValidation::getStatus($options['validation_status']);
} else {
$this->datas['##ticket.action##'] = $events[$event];
}
$this->datas['##ticket.storestatus##'] = $this->obj->getField('status');
$this->datas['##ticket.status##'] = Ticket::getStatus($this->obj->getField('status'));
$this->datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($this->obj->getField('global_validation'));
$this->datas['##ticket.type##'] = Ticket::getTicketTypeName($this->obj->getField('type'));
$this->datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $this->obj->getField('requesttypes_id'));
$this->datas['##ticket.urgency##'] = Ticket::getUrgencyName($this->obj->getField('urgency'));
$this->datas['##ticket.impact##'] = Ticket::getImpactName($this->obj->getField('impact'));
$this->datas['##ticket.priority##'] = Ticket::getPriorityName($this->obj->getField('priority'));
$this->datas['##ticket.time##'] = Ticket::getActionTime($this->obj->getField('actiontime'));
$this->datas['##ticket.costtime##'] = $this->obj->getField('cost_time');
$this->datas['##ticket.creationdate##'] = convDateTime($this->obj->getField('date'));
$this->datas['##ticket.closedate##'] = convDateTime($this->obj->getField('closedate'));
$this->datas['##ticket.solvedate##'] = convDateTime($this->obj->getField('solvedate'));
$this->datas['##ticket.duedate##'] = convDateTime($this->obj->getField('due_date'));
$entitydata = new EntityData();
$autoclose_value = $CFG_GLPI['autoclose_delay'];
if ($entitydata->getFromDB($this->getEntity())) {
$autoclose_value = $entitydata->getField('autoclose_delay');
// Set global config value
if ($autoclose_value == -1) {
$autoclose_value = $CFG_GLPI['autoclose_delay'];
}
}
if ($autoclose_value > 0) {
$this->datas['##ticket.autoclose##'] = $autoclose_value;
$this->datas['##lang.ticket.autoclosewarning##'] = $LANG['job'][54] . " " . $autoclose_value . " " . $LANG['stats'][31];
} else {
$this->datas['##ticket.autoclose##'] = $LANG['setup'][307];
$this->datas['##lang.ticket.autoclosewarning##'] = "";
}
if ($this->obj->getField('ticketcategories_id')) {
$this->datas['##ticket.category##'] = Dropdown::getDropdownName('glpi_ticketcategories', $this->obj->getField('ticketcategories_id'));
} else {
$this->datas['##ticket.category##'] = '';
}
if ($this->obj->getField('slas_id')) {
$this->datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $this->obj->getField('slas_id'));
} else {
$this->datas['##ticket.sla##'] = '';
}
if ($this->obj->countUsers(Ticket::REQUESTER)) {
$users = array();
foreach ($this->obj->getUsers(Ticket::REQUESTER) as $uid => $tmp) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
$tmp = array();
$tmp['##author.id##'] = $uid;
$tmp['##author.name##'] = $user_tmp->getName();
if ($user_tmp->getField('locations_id')) {
$tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id'));
} else {
$tmp['##author.location##'] = '';
}
$tmp['##author.phone##'] = $user_tmp->getField('phone');
$tmp['##author.phone2##'] = $user_tmp->getField('phone2');
$this->datas['authors'][] = $tmp;
}
$this->datas['##ticket.authors##'] = implode(', ', $users);
} else {
$this->datas['##ticket.authors##'] = '';
}
if ($this->obj->getField('users_id_recipient')) {
$user_tmp = new User();
$user_tmp->getFromDB($this->obj->getField('users_id_recipient'));
$this->datas['##ticket.openbyuser##'] = $user_tmp->getName();
} else {
$this->datas['##ticket.openbyuser##'] = '';
}
if ($this->obj->countUsers(Ticket::ASSIGN)) {
$users = array();
foreach ($this->obj->getUsers(Ticket::ASSIGN) as $uid => $tmp) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
}
$this->datas['##ticket.assigntousers##'] = implode(', ', $users);
} else {
$this->datas['##ticket.assigntousers##'] = '';
}
if ($this->obj->countUsers(Ticket::OBSERVER)) {
$users = array();
foreach ($this->obj->getUsers(Ticket::OBSERVER) as $uid => $tmp) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
}
$this->datas['##ticket.observerusers##'] = implode(', ', $users);
} else {
$this->datas['##ticket.observerusers##'] = '';
}
if ($this->obj->getField('suppliers_id_assign')) {
$this->datas['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $this->obj->getField('suppliers_id_assign'));
} else {
$this->datas['##ticket.assigntosupplier##'] = '';
}
if ($this->obj->countGroups(Ticket::REQUESTER)) {
$groups = array();
foreach ($this->obj->getUsers(Ticket::REQUESTER) as $gid => $tmp) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$this->datas['##ticket.groups##'] = implode(', ', $groups);
} else {
$this->datas['##ticket.groups##'] = '';
}
if ($this->obj->countGroups(Ticket::OBSERVER)) {
$groups = array();
foreach ($this->obj->getGroups(Ticket::OBSERVER) as $gid => $tmp) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$this->datas['##ticket.observergroups##'] = implode(', ', $groups);
} else {
$this->datas['##ticket.observergroups##'] = '';
}
if ($this->obj->countGroups(Ticket::ASSIGN)) {
$groups = array();
foreach ($this->obj->getGroups(Ticket::ASSIGN) as $gid => $tmp) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$this->datas['##ticket.assigntogroups##'] = implode(', ', $groups);
} else {
$this->datas['##ticket.assigntogroups##'] = '';
}
//Tags associated with the object linked to the ticket
if ($this->target_object != null) {
//Object type
$this->datas['##ticket.itemtype##'] = $this->target_object->getTypeName();
//Object name
$this->datas['##ticket.item.name##'] = $this->target_object->getField('name');
//Object serial
if ($this->target_object->isField('serial')) {
$this->datas['##ticket.item.serial##'] = $this->target_object->getField('serial');
} else {
$this->datas['##ticket.item.serial##'] = '';
}
//Object contact
if ($this->target_object->isField('contact')) {
$this->datas['##ticket.item.contact##'] = $this->target_object->getField('contact');
} else {
$this->datas['##ticket.item.contact##'] = '';
}
//Object contact num
if ($this->target_object->isField('contact_num')) {
$this->datas['##ticket.item.contactnumber##'] = $this->target_object->getField('contact_num');
} else {
$this->datas['##ticket.item.contactnumber##'] = '';
}
//Object otherserial
if ($this->target_object->isField('otherserial')) {
$this->datas['##ticket.item.otherserial##'] = $this->target_object->getField('otherserial');
} else {
$this->datas['##ticket.item.otherserial##'] = '';
}
//Object location
if ($this->target_object->isField('locations_id')) {
$this->datas['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $this->target_object->getField('locations_id'));
} else {
$this->datas['##ticket.item.location##'] = '';
}
//Object user
$this->datas['##ticket.item.user##'] = '';
if ($this->obj->getField('users_id')) {
$user_tmp = new User();
if ($user_tmp->getFromDB($this->target_object->getField('users_id'))) {
$this->datas['##ticket.item.user##'] = $user_tmp->getName();
}
}
//Object group
if ($this->obj->getField('groups_id')) {
$this->datas['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $this->target_object->getField('groups_id'));
} else {
$this->datas['##ticket.item.group##'] = '';
}
$modeltable = getSingular($this->getTable()) . "models";
$modelfield = getForeignKeyFieldForTable($modeltable);
if ($this->target_object->isField($modelfield)) {
$this->datas['##ticket.item.model##'] = $this->target_object->getField($modelfield);
} else {
$this->datas['##ticket.item.model##'] = '';
}
} else {
$this->datas['##ticket.itemtype##'] = '';
$this->datas['##ticket.item.name##'] = '';
$this->datas['##ticket.item.serial##'] = '';
$this->datas['##ticket.item.otherserial##'] = '';
$this->datas['##ticket.item.location##'] = '';
}
if ($this->obj->getField('ticketsolutiontypes_id')) {
$this->datas['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $this->obj->getField('ticketsolutiontypes_id'));
} else {
$this->datas['##ticket.solution.type##'] = '';
}
$this->datas['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($this->obj->getField('solution'));
// Linked tickets
$linked_tickets = Ticket_Ticket::getLinkedTicketsTo($this->obj->getField('id'));
if (count($linked_tickets)) {
$linkedticket = new Ticket();
foreach ($linked_tickets as $data) {
if ($linkedticket->getFromDB($data['tickets_id'])) {
$tmp = array();
$tmp['##linkedticket.id##'] = $data['tickets_id'];
$tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']);
$tmp['##linkedticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php" . "?redirect=ticket_" . $data['tickets_id']);
$tmp['##linkedticket.title##'] = $linkedticket->getField('name');
$tmp['##linkedticket.content##'] = $linkedticket->getField('content');
$this->datas['linkedtickets'][] = $tmp;
}
}
}
if (!empty($this->datas['linkedtickets'])) {
$this->datas['##ticket.numberoflinkedtickets##'] = count($this->datas['linkedtickets']);
} else {
$this->datas['##ticket.numberoflinkedtickets##'] = 0;
}
$restrict = "`tickets_id`='" . $this->obj->getField('id') . "'";
if (!isset($options['additionnaloption']) || !$options['additionnaloption']) {
$restrict .= " AND `is_private` = '0'";
}
$restrict .= " ORDER BY `date` DESC, `id` ASC";
//Task infos
$tasks = getAllDatasFromTable('glpi_tickettasks', $restrict);
foreach ($tasks as $task) {
$tmp = array();
$tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']);
$tmp['##task.author##'] = html_clean(getUserName($task['users_id']));
$tmp['##task.category##'] = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id']);
$tmp['##task.date##'] = convDateTime($task['date']);
$tmp['##task.description##'] = $task['content'];
$tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']);
$plan = new TicketPlanning();
if ($plan->getFromDBbyTask($task['id'])) {
$tmp['##task.planning.user##'] = html_clean(getUserName($plan->fields['users_id']));
$tmp['##task.planning.begin##'] = convDateTime($plan->fields['begin']);
$tmp['##task.planning.end##'] = convDateTime($plan->fields['end']);
$tmp['##task.planning.status##'] = Planning::getState($plan->fields['state']);
} else {
$tmp['##task.planning.user##'] = "";
$tmp['##task.planning.begin##'] = "";
$tmp['##task.planning.end##'] = "";
$tmp['##task.planning.status##'] = "";
}
$this->datas['tasks'][] = $tmp;
}
if (!empty($this->datas['tasks'])) {
$this->datas['##ticket.numberoftasks##'] = count($this->datas['tasks']);
} else {
$this->datas['##ticket.numberoftasks##'] = 0;
}
//Followup infos
$followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict);
foreach ($followups as $followup) {
$tmp = array();
$tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']);
$tmp['##followup.author##'] = html_clean(getUserName($followup['users_id']));
$tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']);
$tmp['##followup.date##'] = convDateTime($followup['date']);
$tmp['##followup.description##'] = $followup['content'];
$this->datas['followups'][] = $tmp;
}
if (isset($this->datas['followups'])) {
$this->datas['##ticket.numberoffollowups##'] = count($this->datas['followups']);
} else {
$this->datas['##ticket.numberoffollowups##'] = 0;
}
//Validation infos
$restrict = "`tickets_id`='" . $this->obj->getField('id') . "'";
if (isset($options['validation_id']) && $options['validation_id']) {
$restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'";
}
$restrict .= " ORDER BY `submission_date` DESC, `id` ASC";
$validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict);
foreach ($validations as $validation) {
$tmp = array();
$tmp['##validation.submission.title##'] = $LANG['validation'][27] . " (" . $LANG['job'][4] . " " . html_clean(getUserName($validation['users_id'])) . ")";
$tmp['##validation.answer.title##'] = $LANG['validation'][32] . " (" . $LANG['validation'][21] . " " . html_clean(getUserName($validation['users_id_validate'])) . ")";
$tmp['##validation.author##'] = html_clean(getUserName($validation['users_id']));
$tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']);
$tmp['##validation.storestatus##'] = $validation['status'];
$tmp['##validation.submissiondate##'] = convDateTime($validation['submission_date']);
$tmp['##validation.commentsubmission##'] = $validation['comment_submission'];
$tmp['##validation.validationdate##'] = convDateTime($validation['validation_date']);
$tmp['##validation.validator##'] = html_clean(getUserName($validation['users_id_validate']));
$tmp['##validation.commentvalidation##'] = $validation['comment_validation'];
$this->datas['validations'][] = $tmp;
}
// Ticket Satisfaction
$inquest = new TicketSatisfaction();
if ($inquest->getFromDB($this->obj->getField('id'))) {
// internal inquest
if ($inquest->fields['type'] == 1) {
$this->datas['##ticket.urlsatisfaction##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_10");
// external inquest
} else {
if ($inquest->fields['type'] == 2) {
$this->datas['##ticket.urlsatisfaction##'] = EntityData::generateLinkSatisfaction($this->obj);
}
}
$this->datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type'));
$this->datas['##satisfaction.datebegin##'] = convDateTime($inquest->fields['date_begin']);
$this->datas['##satisfaction.dateanswered##'] = convDateTime($inquest->fields['date_answered']);
$this->datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction'];
$this->datas['##satisfaction.description##'] = $inquest->fields['comment'];
} else {
$this->datas['##satisfaction.type##'] = '';
$this->datas['##satisfaction.datebegin##'] = '';
$this->datas['##satisfaction.dateanswered##'] = '';
$this->datas['##satisfaction.satisfaction##'] = '';
$this->datas['##satisfaction.description##'] = '';
}
// Use list_limit_max or load the full history ?
foreach (Log::getHistoryData($this->obj, 0, $CFG_GLPI['list_limit_max']) as $data) {
$tmp = array();
$tmp['##ticket.log.date##'] = $data['date_mod'];
$tmp['##ticket.log.user##'] = $data['user_name'];
$tmp['##ticket.log.field##'] = $data['field'];
$tmp['##ticket.log.content##'] = $data['change'];
$this->datas['log'][] = $tmp;
}
if (isset($this->datas['log'])) {
$this->datas['##ticket.numberoflogs##'] = count($this->datas['log']);
} else {
$this->datas['##ticket.numberoflogs##'] = 0;
}
} else {
if (isset($options['entities_id']) && isset($options['tickets'])) {
$this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
$this->datas['##ticket.action##'] = $LANG['crontask'][15];
$t = new Ticket();
foreach ($options['tickets'] as $ticket) {
$tmp = array();
$t->getFromDB($ticket['id']);
$tmp['##ticket.id##'] = sprintf("%07d", $ticket['id']);
$tmp['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $ticket['id']);
$tmp['##ticket.title##'] = $ticket['name'];
$tmp['##ticket.status##'] = Ticket::getStatus($ticket['status']);
$tmp['##ticket.globalvalidation##'] = TicketValidation::getStatus($ticket['global_validation']);
$tmp['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $ticket['requesttypes_id']);
$tmp['##ticket.urgency##'] = Ticket::getUrgencyName($ticket['urgency']);
$tmp['##ticket.impact##'] = Ticket::getImpactName($ticket['impact']);
$tmp['##ticket.priority##'] = Ticket::getPriorityName($ticket['priority']);
$tmp['##ticket.time##'] = Ticket::getActionTime($ticket['actiontime']);
$tmp['##ticket.costtime##'] = $ticket['cost_time'];
$tmp['##ticket.creationdate##'] = convDateTime($ticket['date']);
$tmp['##ticket.content##'] = $ticket['content'];
if ($t->getField('ticketsolutiontypes_id')) {
$tmp['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $t->getField('ticketsolutiontypes_id'));
} else {
$this->datas['##ticket.solution.type##'] = '';
}
$tmp['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($t->getField('solution'));
if ($t->countUsers(Ticket::REQUESTER)) {
$users = array();
foreach ($t->getUsers(Ticket::REQUESTER) as $uid => $val) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
$tmp2 = array();
$tmp2['##author.id##'] = $uid;
$tmp2['##author.name##'] = $user_tmp->getName();
if ($user_tmp->getField('locations_id')) {
$tmp2['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id'));
} else {
$tmp2['##author.location##'] = '';
}
$tmp2['##author.phone##'] = $user_tmp->getField('phone');
$tmp2['##author.phone2##'] = $user_tmp->getField('phone2');
$tmp['authors'][] = $tmp2;
}
$tmp['##ticket.authors##'] = implode(', ', $users);
} else {
$tmp['##ticket.authors##'] = '';
}
if ($t->countUsers(Ticket::ASSIGN)) {
$users = array();
foreach ($t->getUsers(Ticket::ASSIGN) as $uid => $val) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
}
$tmp['##ticket.assigntousers##'] = implode(', ', $users);
} else {
$tmp['##ticket.assigntousers##'] = '';
}
if ($t->countGroups(Ticket::ASSIGN)) {
$groups = array();
foreach ($t->getGroups(Ticket::ASSIGN) as $gid => $val) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$tmp['##ticket.assigntogroups##'] = implode(', ', $groups);
} else {
$tmp['##ticket.assigntogroups##'] = '';
}
if ($t->countGroups(Ticket::REQUESTER)) {
$groups = array();
foreach ($t->getGroups(Ticket::REQUESTER) as $gid => $val) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$tmp['##ticket.groups##'] = implode(', ', $groups);
} else {
$tmp['##ticket.groups##'] = '';
}
if ($t->countUsers(Ticket::OBSERVER)) {
$users = array();
foreach ($t->getUsers(Ticket::OBSERVER) as $uid => $tmp) {
$user_tmp = new User();
$user_tmp->getFromDB($uid);
$users[$uid] = $user_tmp->getName();
}
$tmp['##ticket.observerusers##'] = implode(', ', $users);
} else {
$tmp['##ticket.observerusers##'] = '';
}
if ($t->countGroups(Ticket::OBSERVER)) {
$groups = array();
foreach ($t->getGroups(Ticket::OBSERVER) as $gid => $tmp) {
$groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid);
}
$tmp['##ticket.observergroups##'] = implode(', ', $groups);
} else {
$tmp['##ticket.observergroups##'] = '';
}
if ($ticket['suppliers_id_assign']) {
$tmp['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $ticket['suppliers_id_assign']);
} else {
$tmp['##ticket.assigntosupplier##'] = '';
}
$this->datas['tickets'][] = $tmp;
}
}
}
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->datas[$tag])) {
$this->datas[$tag] = $values['label'];
}
}
}
/**
* Execute a function as Fusioninventory user
* @param $function callable
* @param $args array
*
* @return the normally returned value from executed callable
*/
function executeAsFusioninventoryUser($function, array $args = array())
{
$config = new PluginFusioninventoryConfig();
$user = new User();
// Backup _SESSION environment
$OLD_SESSION = array();
foreach (array('glpiID', 'glpiname', 'glpiactiveentities_string', 'glpiactiveentities', 'glpiparententities') as $session_key) {
if (isset($_SESSION[$session_key])) {
$OLD_SESSION[$session_key] = $_SESSION[$session_key];
}
}
// Configure impersonation
$users_id = $config->getValue('users_id');
$user->getFromDB($users_id);
$_SESSION['glpiID'] = $users_id;
$_SESSION['glpiname'] = $user->getField('name');
$_SESSION['glpiactiveentities'] = getSonsOf('glpi_entities', 0);
$_SESSION['glpiactiveentities_string'] = "'" . implode("', '", $_SESSION['glpiactiveentities']) . "'";
$_SESSION['glpiparententities'] = array();
// Execute function with impersonated SESSION
$result = call_user_func_array($function, $args);
// Restore SESSION
foreach ($OLD_SESSION as $key => $value) {
$_SESSION[$key] = $value;
}
// Return function results
return $result;
}
public function getIndex()
{
User::onlyHas('log-view');
$this->data['list'] = LogModel::leftJoin(User::getTableName(), User::getField('id'), '=', LogModel::getField('user_id'))->orderBy('event_date', 'desc')->get();
$this->layout->content = View::make('sections.log.list', $this->data);
}
<dt>Status</dt>
<dd>{$statustext}</dd>
\t
<dt>Date Registered</dt>
<dd>{$regdatetext}</dd>
{$extraforadmins}
</dl>
EOT
);
}
}
Sidebar::clear();
if (User::$role == 0 && !User::getField('wantsdev')) {
$requestpermissions = '<li><a href="/user/requestdev">Request Developer Access</a></li>';
} else {
if (User::getField('wantsdev')) {
$requestpermissions = '<li>Developer Access Requested</li>';
}
}
if (User::$uname == $uname || User::$role > 1) {
Sidebar::add('User CP', <<<EOT
\t<ol>
\t\t<li><a href="/user/{$uname}/">Main Profile</a></li>
\t\t<li><a href="/user/{$uname}/edit">Edit Profile</a></li>
\t\t{$requestpermissions}
\t</ol>
EOT
);
}
}
}
/**
* show tooltip for user notification informations
*
* @param $type integer : user type
* @param $canedit boolean : can edit ?
*
* @return nothing display
**/
function showUsersAssociated($type, $canedit)
{
global $CFG_GLPI, $LANG;
$showuserlink = 0;
if (haveRight('user', 'r')) {
$showuserlink = 2;
}
$usericon = self::getActorIcon('user', $type);
$user = new User();
if (isset($this->users[$type]) && count($this->users[$type])) {
foreach ($this->users[$type] as $k => $d) {
$save_showuserlink = $showuserlink;
echo "{$usericon} ";
if ($k) {
$userdata = getUserName($k, $showuserlink);
} else {
$email = $d['alternative_email'];
$userdata = "<a href='mailto:{$email}'>{$email}</a>";
$showuserlink = false;
}
if ($showuserlink) {
echo $userdata['name'] . " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
} else {
echo $userdata;
}
if ($CFG_GLPI['use_mailing']) {
$text = $LANG['job'][19] . " : " . Dropdown::getYesNo($d['use_notification']) . '<br>';
if ($d['use_notification']) {
$uemail = $d['alternative_email'];
if (empty($uemail) && $user->getFromDB($d['users_id'])) {
$uemail = $user->getField('email');
}
$text .= $LANG['mailing'][118] . " : " . $uemail;
if (!NotificationMail::isUserAddressValid($uemail)) {
$text .= "<span class='red'>" . $LANG['mailing'][110] . "</span>";
}
}
echo " ";
if ($canedit || $d['users_id'] == getLoginUserID()) {
$opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => 'edit_user_notification&id=' . $d['id']);
showToolTip($text, $opt);
}
}
if ($canedit) {
echo " <a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?delete_user=delete_user&id=" . $d['id'] . "&tickets_id=" . $this->fields['id'] . "' title=\"" . $LANG['buttons'][6] . "\">\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n alt=\"" . $LANG['buttons'][6] . "\" title=\"" . $LANG['buttons'][6] . "\"></a>";
}
echo "<br>";
$showuserlink = $save_showuserlink;
}
}
}
/**
* Overriden store function to send mails
* @param none
*/
function store()
{
global $cfg, $encoding, $lang;
$sMailhost = getSystemProperty('system', 'mail_host');
if ($sMailhost == '') {
$sMailhost = 'localhost';
}
//modified : 2008-06-25 - use php mailer class instead of mail()
$oMail = new PHPMailer();
$oMail->CharSet = isset($encoding[$lang]) ? $encoding[$lang] : 'UTF-8';
$oMail->Host = $sMailhost;
$oMail->IsHTML(0);
$oMail->WordWrap = 1000;
$oMail->IsMail();
if (array_key_exists("idusersequence", $this->modifiedValues)) {
$usersequence = new WorkflowUserSequence();
$usersequence->loadByPrimaryKey($this->values["idusersequence"]);
$email = $usersequence->get("emailnoti");
$escal = $usersequence->get("escalationnoti");
if ($email == 1 || $escal == 1) {
/* Grab the required informations */
$curEditor = getGroupOrUserName($usersequence->get("iduser"));
$idartlang = $this->get("idartlang");
$timeunit = $usersequence->get("timeunit");
$timelimit = $usersequence->get("timelimit");
$db = new DB_Contenido();
$sql = "SELECT author, title, idart FROM " . $cfg["tab"]["art_lang"] . " WHERE idartlang = '" . Contenido_Security::escapeDB($idartlang, $db) . "'";
$db->query($sql);
if ($db->next_record()) {
$idart = $db->f("idart");
$title = $db->f("title");
$author = $db->f("author");
}
/* Extract category */
$sql = "SELECT idcat FROM " . $cfg["tab"]["cat_art"] . " WHERE idart = '" . Contenido_Security::escapeDB($idart, $db) . "'";
$db->query($sql);
if ($db->next_record()) {
$idcat = $db->f("idcat");
}
$sql = "SELECT name FROM " . $cfg["tab"]["cat_lang"] . " WHERE idcat = '" . Contenido_Security::escapeDB($idcat, $db) . "'";
$db->query($sql);
if ($db->next_record()) {
$catname = $db->f("name");
}
$starttime = $this->get("starttime");
$starttime = strtotime(substr_replace(substr(substr($starttime, 0, 2) . chunk_split(substr($starttime, 2, 6), 2, "-") . chunk_split(substr($starttime, 8), 2, ":"), 0, 19), " ", 10, 1));
switch ($timeunit) {
case "Seconds":
$maxtime = $starttime + $timelimit;
break;
case "Minutes":
$maxtime = $starttime + $timelimit * 60;
break;
case "Hours":
$maxtime = $starttime + $timelimit * 3600;
break;
case "Days":
$maxtime = $starttime + $timelimit * 86400;
break;
case "Weeks":
$maxtime = $starttime + $timelimit * 604800;
break;
case "Months":
$maxtime = $starttime + $timelimit * 2678400;
break;
case "Years":
$maxtime = $starttime + $timelimit * 31536000;
break;
default:
$maxtime = $starttime + $timelimit;
}
if ($email == 1) {
$email = i18n("Hello %s,\n\n" . "you are assigned as the next editor for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n");
$filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
$user = new User();
if (isGroup($usersequence->get("iduser"))) {
$sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
$db->query($sql);
while ($db->next_record()) {
$user->loadUserByUserID($db->f("user_id"));
//modified : 2008-06-25 - use php mailer class instead of mail()
$oMail->AddAddress($user->getField("email"), "");
$oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
$oMail->Body = $filledMail;
$oMail->Send();
}
} else {
$user->loadUserByUserID($usersequence->get("iduser"));
//modified : 2008-06-25 - use php mailer class instead of mail()
$oMail->AddAddress($user->getField("email"), "");
$oMail->Subject = stripslashes(i18n('Workflow notification', "workflow"));
$oMail->Body = $filledMail;
$oMail->Send();
}
} else {
$email = "Hello %s,\n\n" . "you are assigned as the escalator for the Article %s.\n\n" . "More informations:\n" . "Article: %s\n" . "Category: %s\n" . "Editor: %s\n" . "Author: %s\n" . "Editable from: %s\n" . "Editable to: %s\n";
$filledMail = sprintf($email, $curEditor, $title, $title, $catname, $curEditor, $author, date("Y-m-d H:i:s", $starttime), date("Y-m-d H:i:s", $maxtime));
$user = new User();
if (isGroup($usersequence->get("iduser"))) {
$sql = "select idgroupuser, user_id FROM " . $cfg["tab"]["groupmembers"] . " WHERE\n \t\t\t\t\t\tgroup_id = '" . Contenido_Security::escapeDB($usersequence->get("iduser"), $db) . "'";
$db->query($sql);
while ($db->next_record()) {
$user->loadUserByUserID($db->f("user_id"));
echo "mail to " . $user->getField("email") . "<br>";
//modified : 2008-06-25 - use php mailer class instead of mail()
$oMail->AddAddress($user->getField("email"), "");
$oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
$oMail->Body = $filledMail;
$oMail->Send();
}
} else {
$user->loadUserByUserID($usersequence->get("iduser"));
echo "mail to " . $user->getField("email") . "<br>";
//modified : 2008-06-25 - use php mailer class instead of mail()
$oMail->AddAddress($user->getField("email"), "");
$oMail->Subject = stripslashes(i18n('Workflow escalation', "workflow"));
$oMail->Body = $filledMail;
$oMail->Send();
}
}
}
}
return parent::store();
}
/** Display refresh button in the user page
*
* @param $user User object
*
* @return nothing
**/
static function showSynchronizationForm(User $user)
{
global $DB, $CFG_GLPI;
if (Session::haveRight("user", User::UPDATEAUTHENT)) {
echo "<form method='post' action='" . Toolbox::getItemTypeFormURL('User') . "'>";
echo "<div class='firstbloc'>";
switch ($user->getField('authtype')) {
case self::CAS:
case self::EXTERNAL:
case self::X509:
case self::LDAP:
//Look it the auth server still exists !
// <- Bad idea : id not exists unable to change anything
$sql = "SELECT `name`\n FROM `glpi_authldaps`\n WHERE `id` = '" . $user->getField('auths_id') . "'\n AND `is_active` = 1";
$result = $DB->query($sql);
if ($DB->numrows($result) > 0) {
echo "<table class='tab_cadre'><tr class='tab_bg_2'><td>";
echo "<input type='hidden' name='id' value='" . $user->getID() . "'>";
echo "<input class=submit type='submit' name='force_ldap_resynch' value='" . __s('Force synchronization') . "'>";
echo "</td></tr></table>";
}
break;
case self::DB_GLPI:
case self::MAIL:
break;
}
echo "</div>";
echo "<div class='spaced'>";
echo "<table class='tab_cadre'>";
echo "<tr><th>" . __('Change of the authentication method') . "</th></tr>";
echo "<tr class='tab_bg_2'><td class='center'>";
$rand = self::dropdown(array('name' => 'authtype'));
$paramsmassaction = array('authtype' => '__VALUE__', 'name' => 'change_auth_method');
Ajax::updateItemOnSelectEvent("dropdown_authtype{$rand}", "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionAuthMethods.php", $paramsmassaction);
echo "<input type='hidden' name='id' value='" . $user->getID() . "'>";
echo "<span id='show_massiveaction_field'></span>";
echo "</td></tr></table>";
echo "</div>";
Html::closeForm();
}
}
/**
* Manage communication with old protocol (XML over POST)
*
**/
function handleOCSCommunication($rawdata, $xml = '', $output = 'ext')
{
// ***** For debug only ***** //
//$rawdata = gzcompress('');
// ********** End ********** //
$config = new PluginFusioninventoryConfig();
$user = new User();
// ob_start();
if (!isset($_SESSION['glpiID'])) {
$users_id = $config->getValue('users_id');
$_SESSION['glpiID'] = $users_id;
$user->getFromDB($users_id);
Session::changeActiveEntities();
$_SESSION["glpiname"] = $user->getField('name');
$_SESSION['glpiactiveprofile'] = array();
$_SESSION['glpiactiveprofile']['interface'] = 'central';
$_SESSION['glpiactiveprofile']['internet'] = 'w';
$_SESSION['glpiactiveprofile']['computer'] = 'w';
$_SESSION['glpiactiveprofile']['monitor'] = 'w';
$_SESSION['glpiactiveprofile']['printer'] = 'w';
$_SESSION['glpiactiveprofile']['peripheral'] = 'w';
$_SESSION['glpiactiveprofile']['networking'] = 'w';
$_SESSION["glpi_plugin_fusioninventory_profile"]['unmanaged'] = 'w';
}
$communication = new PluginFusioninventoryCommunication();
$pfToolbox = new PluginFusioninventoryToolbox();
// identify message compression algorithm
$agent = new PluginFusioninventoryAgent();
$agent->disableDebug();
$compressmode = '';
if (!empty($xml)) {
$compressmode = 'none';
} else {
if ($_SERVER['CONTENT_TYPE'] == "application/x-compress-zlib") {
$xml = gzuncompress($rawdata);
$compressmode = "zlib";
} else {
if ($_SERVER['CONTENT_TYPE'] == "application/x-compress-gzip") {
$xml = $pfToolbox->gzdecode($rawdata);
$compressmode = "gzip";
} else {
if ($_SERVER['CONTENT_TYPE'] == "application/xml") {
$xml = $rawdata;
$compressmode = 'none';
} else {
# try each algorithm successively
if ($xml = gzuncompress($rawdata)) {
$compressmode = "zlib";
} else {
if ($xml = $pfToolbox->gzdecode($rawdata)) {
$compressmode = "gzip";
} else {
if ($xml = gzinflate(substr($rawdata, 2))) {
// accept deflate for OCS agent 2.0 compatibility,
// but use zlib for answer
if (strstr($xml, "<QUERY>PROLOG</QUERY>") and !strstr($xml, "<TOKEN>")) {
$compressmode = "zlib";
} else {
$compressmode = "deflate";
}
} else {
$xml = $rawdata;
$compressmode = 'none';
}
}
}
}
}
}
}
$agent->restoreDebug();
// check if we are in ssl only mode
$ssl = $config->getValue('ssl_only');
if ($ssl == "1" and (!isset($_SERVER["HTTPS"]) or $_SERVER["HTTPS"] != "on")) {
if ($output == 'glpi') {
Session::addMessageAfterRedirect('SSL REQUIRED BY SERVER', false, ERROR);
} else {
$communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n <ERROR>SSL REQUIRED BY SERVER</ERROR>\n</REPLY>");
$communication->sendMessage($compressmode);
}
return;
}
PluginFusioninventoryConfig::logIfExtradebug('pluginFusioninventory-dial' . uniqid(), $xml);
// Check XML integrity
$pxml = '';
if ($pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)) {
} else {
if ($pxml = @simplexml_load_string(utf8_encode($xml), 'SimpleXMLElement', LIBXML_NOCDATA)) {
$xml = utf8_encode($xml);
} else {
$xml = preg_replace('/<FOLDER>.*?<\\/SOURCE>/', '', $xml);
$pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
if (!$pxml) {
if ($output == 'glpi') {
Session::addMessageAfterRedirect('XML not well formed!', false, ERROR);
} else {
$communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n <ERROR>XML not well formed!</ERROR>\n</REPLY>");
$communication->sendMessage($compressmode);
}
return;
}
}
}
$_SESSION['plugin_fusioninventory_compressmode'] = $compressmode;
// Convert XML into PHP array
$arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml);
unset($pxml);
$deviceid = '';
if (isset($arrayinventory['DEVICEID'])) {
$deviceid = $arrayinventory['DEVICEID'];
}
$agent = new PluginFusioninventoryAgent();
$agents_id = $agent->importToken($arrayinventory);
$_SESSION['plugin_fusioninventory_agents_id'] = $agents_id;
if (!$communication->import($arrayinventory)) {
if ($deviceid != '') {
$communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n</REPLY>");
$a_agent = $agent->InfosByKey($deviceid);
// Get taskjob in waiting
$communication->getTaskAgent($a_agent['id']);
// ******** Send XML
$communication->addInventory($a_agent['id']);
$communication->addProlog();
$communication->sendMessage($compressmode);
}
} else {
if ($output == 'glpi') {
Session::addMessageAfterRedirect('XML has been imported succesfully!');
} else {
$communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n</REPLY>");
$communication->sendMessage($compressmode);
}
}
}