public function testInitSessionUserToken() { // retrieve personnal token of 'glpi' user $user = new User(); $user->getFromDB(2); $token = isset($user->fields['personnal_token']) ? $user->fields['personnal_token'] : ""; if (empty($token)) { $token = User::getPersonalToken(2); } $res = $this->doHttpRequest('initSession', ['user_token' => $token]); $this->assertEquals(200, $res->getStatusCode()); $data = xmlrpc_decode($res->getBody()); $this->assertNotEquals(false, $data); $this->assertArrayHasKey('session_token', $data); }
/** * Show the planning selection form * * @param $type planning type : can be day, week, month * @param $date working date * @param $usertype type of planning to view : can be user or group * @param $value ID of the item * @param $limititemtype itemtype only display this itemtype (default '') * * @return Display form **/ static function showSelectionForm($type, $date, $usertype, $value, $limititemtype = '') { global $CFG_GLPI; switch ($type) { case "month": $split = explode("-", $date); $year_next = $split[0]; $month_next = $split[1] + 1; if ($month_next > 12) { $year_next++; $month_next -= 12; } $year_prev = $split[0]; $month_prev = $split[1] - 1; if ($month_prev == 0) { $year_prev--; $month_prev += 12; } $next = $year_next . "-" . sprintf("%02u", $month_next) . "-" . $split[2]; $prev = $year_prev . "-" . sprintf("%02u", $month_prev) . "-" . $split[2]; break; default: $time = strtotime($date); $step = 0; switch ($type) { case "week": $step = WEEK_TIMESTAMP; break; case "day": $step = DAY_TIMESTAMP; break; } $next = $time + $step + 10; $prev = $time - $step; $next = strftime("%Y-%m-%d", $next); $prev = strftime("%Y-%m-%d", $prev); break; } $uID = 0; $gID = 0; switch ($usertype) { case 'my': $uID = $_SESSION['glpiID']; break; case 'mygroups': if (!Session::haveRight("show_group_planning", "1")) { exit; } $gID = 'mine'; break; case 'users': if (!Session::haveRight("show_all_planning", "1")) { exit; } $uID = $value; break; case 'groups': if (!Session::haveRight("show_all_planning", "1")) { exit; } $gID = $value; break; } echo "<div class='center'><form method='get' name='form' action='planning.php'>\n"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'>"; echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/planning.php?type=" . $type . "&uID=" . $uID . "&date={$prev}&usertype={$usertype}&gID={$gID}&limititemtype={$limititemtype}\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\"\n title=\"" . __s('Previous') . "\"></a>"; echo "</td>"; switch ($usertype) { case 'users': echo "<td>"; $rand_user = User::dropdown(array('name' => 'uID', 'value' => $value, 'right' => 'interface', 'all' => 1, 'entity' => $_SESSION["glpiactive_entity"])); echo "</td>"; break; case 'groups': echo "<td>"; $rand_group = Group::dropdown(array('value' => $value, 'name' => 'gID', 'entity' => $_SESSION["glpiactive_entity"], 'condition' => '`is_usergroup`')); echo "</td>"; break; } echo "</td>"; echo "<td>"; Dropdown::showItemTypes('limititemtype', $CFG_GLPI['planning_types'], array('value' => $limititemtype)); echo "</td>"; echo "<td>"; Html::showDateFormItem("date", $date, false); echo '</td><td>'; echo "<select name='type'>"; echo "<option value='day' " . ($type == "day" ? " selected " : "") . ">" . __('Day') . "</option>"; echo "<option value='week' " . ($type == "week" ? " selected " : "") . ">" . __('Week') . "</option>"; echo "<option value='month' " . ($type == "month" ? " selected " : "") . ">" . __('Month') . "</option>"; echo "</select></td>\n"; echo "<td rowspan='2' class='center'>"; echo "<input type='submit' class='submit' name='submit' value=\"" . _sx('button', 'Show') . "\">"; echo "</td>\n"; if ($uID || $gID) { echo "<td>"; echo "<a target='_blank'\n href=\"" . $CFG_GLPI["root_doc"] . "/front/planning.php?genical=1&uID=" . $uID . "&gID=" . $gID . "&usertype=" . $usertype . "&limititemtype={$limititemtype}" . "&entities_id=" . $_SESSION["glpiactive_entity"] . "&is_recursive=" . $_SESSION["glpiactive_entity_recursive"] . "&token=" . User::getPersonalToken(Session::getLoginUserID(true)) . "\"\n title=\"" . __s('Download the planning in Ical format') . "\">" . "<span style='font-size:10px'>" . __('Ical') . "</span></a>"; echo "<br>"; $url = parse_url($CFG_GLPI["url_base"]); $port = 80; if (isset($url['port'])) { $port = $url['port']; } else { if (isset($url['scheme']) && $url["scheme"] == 'https') { $port = 443; } } echo "<a target='_blank' href=\"webcal://" . $url['host'] . ':' . $port . (isset($url['path']) ? $url['path'] : '') . "/front/planning.php?genical=1&uID=" . $uID . "&gID=" . $gID . "&usertype=" . $usertype . "&limititemtype={$limititemtype}" . "&entities_id=" . $_SESSION["glpiactive_entity"] . "&is_recursive=" . $_SESSION["glpiactive_entity_recursive"] . "&token=" . User::getPersonalToken(Session::getLoginUserID(true)) . "\" title=\"" . __s('webcal:// synchronization') . "\">"; echo "<span style='font-size:10px'>" . __('Webcal') . "</span></a>"; echo "</td>\n"; } echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/planning.php?type=" . $type . "&uID=" . $uID . "&date={$next}&usertype={$usertype}&gID={$gID}&limititemtype={$limititemtype}\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\"\n title=\"" . __s('Next') . "\"></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>\n"; }
/** * Display a single line of planning filter. * See self::showPlanningFilter function * * @param $filter_key : identify curent line of filter * @param $filter_data : array of filter date, must contains : * * 'show_delete' (boolean): show delete button * * 'filter_color_index' (integer): index of the color to use in self::$palette_bg * @param $options * * @return Nothing (display function) */ static function showSingleLinePlanningFilter($filter_key, $filter_data, $options = array()) { global $CFG_GLPI; $params['show_delete'] = true; $params['filter_color_index'] = 0; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $actor = explode('_', $filter_key); $uID = 0; $gID = 0; if ($filter_data['type'] == 'user') { $uID = $actor[1]; $user = new User(); $user->getFromDB($actor[1]); $title = $user->getName(); } else { if ($filter_data['type'] == 'group_users') { $group = new Group(); $group->getFromDB($actor[1]); $title = $group->getName(); } else { if ($filter_data['type'] == 'group') { $gID = $actor[1]; $group = new Group(); $group->getFromDB($actor[1]); $title = $group->getName(); } else { if ($filter_data['type'] == 'event_filter') { $title = $filter_key::getTypeName(); } } } } echo "<li event_type='" . $filter_data['type'] . "'\n event_name='{$filter_key}'\n class='" . $filter_data['type'] . "'>"; Html::showCheckbox(array('name' => 'filters[]', 'value' => $filter_key, 'title' => $title, 'checked' => $filter_data['display'])); if ($filter_data['type'] != 'event_filter') { $icon_type = explode('_', $filter_data['type']); echo "<img class='actor_icon' src='" . $CFG_GLPI['root_doc'] . "/pics/" . $icon_type[0] . ".png'>"; } echo "<label for='{$filter_key}'>{$title}</label>"; $color = self::$palette_bg[$params['filter_color_index']]; if (isset($filter_data['color']) && !empty($filter_data['color'])) { $color = $filter_data['color']; } else { $params['filter_color_index']++; if (!isset(self::$palette_bg[$params['filter_color_index']])) { $params['filter_color_index'] = 0; $color = self::$palette_bg[$params['filter_color_index']]; } } if ($filter_data['type'] != 'event_filter') { echo "<span class='filter_option'>"; echo "<img class='pointer' src='" . $CFG_GLPI['root_doc'] . "/pics/down.png' />"; echo "<ul>"; if ($params['show_delete']) { echo "<li class='delete_planning' value='{$filter_key}'>" . __("Delete") . "</li>"; } if ($filter_data['type'] != 'group_users') { $url = parse_url($CFG_GLPI["url_base"]); $port = 80; if (isset($url['port'])) { $port = $url['port']; } else { if (isset($url['scheme']) && $url["scheme"] == 'https') { $port = 443; } } $cal_url = "/front/planning.php?genical=1&uID=" . $uID . "&gID=" . $gID . "&entities_id=" . $_SESSION["glpiactive_entity"] . "&is_recursive=" . $_SESSION["glpiactive_entity_recursive"] . "&token=" . User::getPersonalToken(Session::getLoginUserID(true)); echo "<li><a target='_blank' href='" . $CFG_GLPI["root_doc"] . "{$cal_url}'>" . _sx("button", "Export") . " - " . __("Ical") . "</a></li>"; echo "<li><a target='_blank' href='webcal://" . $url['host'] . ":{$port}" . (isset($url['path']) ? $url['path'] : '') . "{$cal_url}'>" . _sx("button", "Export") . " - " . __("Webcal") . "</a></li>"; } echo "</ul>"; echo "</span>"; } // colors not for groups if ($filter_data['type'] != 'group_users') { echo "<span class='color_input'>"; Html::showColorField($filter_key . "_color", array('value' => $color)); echo "</span>"; } if ($filter_data['type'] == 'group_users') { echo "<span class='toggle pointer' />"; } if ($filter_data['type'] == 'group_users') { echo "<ul class='group_listofusers filters'>"; foreach ($filter_data['users'] as $user_key => $userdata) { self::showSingleLinePlanningFilter($user_key, $userdata, array('show_delete' => false, 'filter_color_index' => $params['filter_color_index'])); } echo "</ul>"; } echo "</li>"; }
/** * @group api **/ public function testInitSessionUserToken() { // retrieve personnal token of TU_USER user $user = new User(); $uid = getItemByTypeName('User', TU_USER, true); $user->getFromDB($uid); $token = isset($user->fields['personal_token']) ? $user->fields['personal_token'] : ""; if (empty($token)) { $token = User::getPersonalToken($uid); } $res = $this->doHttpRequest('GET', 'initSession/', ['headers' => ['Authorization' => "user_token {$token}"]]); $this->assertNotEquals(null, $res, $this->last_error); $this->assertEquals(200, $res->getStatusCode()); $body = $res->getBody(); $data = json_decode($body, true); $this->assertNotEquals(false, $data); $this->assertArrayHasKey('session_token', $data); }