private function sendResponse(Codendi_Request $request, $feedback_level, $message, $unsubscribe) { if ($request->isAjax()) { $this->sendAjaxResponse($unsubscribe, $message); return; } $GLOBALS['Response']->addFeedback($feedback_level, $message); $GLOBALS['Response']->redirect($this->artifact->getUri()); }
public function __construct(Codendi_Request $request) { $this->project = $request->getProject(); $this->words = $request->get('words'); $this->offset = intval($request->getValidated('offset', 'uint', 0)); $this->exact = $request->getValidated('exact', 'uint', false); $this->trackerv3id = $request->getValidated('atid', 'uint', 0); $this->forum_id = $request->getValidated('forum_id', 'uint', 0); $this->is_ajax = $request->isAjax(); $this->type_of_search = $request->get('type_of_search'); }
/** * Check that the service is used and the plugin is allowed for project $project * if it is not the case then exit with an error * * @param Project $project * @param Codendi_Request $request * * @return bool true if success. Otherwise the process terminates. */ public function checkServiceEnabled(Project $project, Codendi_Request $request) { if ($project->usesService('plugin_tracker')) { return true; } header("HTTP/1.0 404 Not Found"); if (!$request->isAjax()) { $GLOBALS['Response']->addFeedback('error', "The project doesn't use the 'tracker v5' service"); $GLOBALS['HTML']->redirect('/projects/' . $project->getUnixName() . '/'); } exit; }
public function route(Codendi_Request $request) { if ($request->existAndNonEmpty('type_of_search')) { if ($request->isAjax()) { $this->controller->ajaxResults($request); } else { $this->controller->results($request); } } else { $this->controller->index($request); } }
/** * Update the form element * * @param Tracker_IDisplayTrackerLayout $layout Displays the page header and footer * @param Codendi_Request $request The data coming from the user * @param PFUser $current_user The user who mades the request * @param bool $redirect Do we need to redirect? default is false * * @return void */ protected function processUpdate(Tracker_IDisplayTrackerLayout $layout, $request, $current_user, $redirect = false) { if (is_array($request->get('formElement_data'))) { $formElement_data = $request->get('formElement_data'); //First store the specific properties if needed if (!isset($formElement_data['specific_properties']) || !is_array($formElement_data['specific_properties']) || $this->storeProperties($formElement_data['specific_properties'])) { //Then store the formElement itself if (Tracker_FormElementFactory::instance()->updateFormElement($this, $formElement_data)) { $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'field_updated')); if ($request->isAjax()) { echo $this->fetchAdminFormElement(); exit; } else { $redirect = true; } } } } else { if ($request->get('change-type')) { if (Tracker_FormElementFactory::instance()->changeFormElementType($this, $request->get('change-type'))) { $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'field_type_changed')); } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'field_type_not_changed')); } $redirect = true; } } if ($redirect) { $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . (int) $this->tracker_id . '&func=admin-formElements'); } }
/** * Process the artifact functions * * @param Tracker_IDisplayTrackerLayout $layout Displays the page header and footer * @param Codendi_Request $request The data from the user * @param User $current_user The current user * * @return void */ public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user) { switch ($request->get('func')) { case 'update-comment': if ((int) $request->get('changeset_id') && $request->get('content')) { if ($changeset = $this->getChangeset($request->get('changeset_id'))) { $changeset->updateComment($request->get('content'), $current_user); if ($request->isAjax()) { //We assume that we can only change a comment from a followUp echo $changeset->getComment()->fetchFollowUp(); } } } break; case 'preview-attachment': case 'show-attachment': if ((int) $request->get('field') && (int) $request->get('attachment')) { $ff = Tracker_FormElementFactory::instance(); //TODO: check that the user can read the field if ($field = $ff->getFormElementByid($request->get('field'))) { $method = explode('-', $request->get('func')); $method = $method[0]; $method .= 'Attachment'; if (method_exists($field, $method)) { $field->{$method}($request->get('attachment')); } } } break; case 'artifact-delete-changeset': // @see comment in Tracker_Artifact_Changeset::fetchFollowUp() //if ($changeset = $this->getChangeset($request->get('changeset'))) { // $changeset->delete($current_user); //} $GLOBALS['Response']->redirect('?aid=' . $this->id); break; case 'artifact-update': //TODO : check permissions on this action? $fields_data = $request->get('artifact'); $this->setUseArtifactPermissions($request->get('use_artifact_permissions') ? 1 : 0); $this->getTracker()->augmentDataFromRequest($fields_data); if ($this->createNewChangeset($fields_data, $request->get('artifact_followup_comment'), $current_user, $request->get('email'))) { $art_link = $this->fetchDirectLinkToArtifact(); $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_index', 'update_success', array($art_link)), CODENDI_PURIFIER_LIGHT); $this->summonArtifactRedirectors($request); $GLOBALS['Response']->redirect($this->getRedirectUrlAfterArtifactUpdate($request, $this->tracker_id, $this->getId())); } else { $this->display($layout, $request, $current_user); } break; case 'unassociate-artifact-to': $artlink_fields = $this->getFormElementFactory()->getUsedArtifactLinkFields($this->getTracker()); $linked_artifact_id = $request->get('linked-artifact-id'); if (count($artlink_fields)) { $this->unlinkArtifact($artlink_fields, $linked_artifact_id, $current_user); $this->summonArtifactAssociators($request, $current_user, $linked_artifact_id); } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker', 'must_have_artifact_link_field')); $GLOBALS['Response']->sendStatusCode(400); } break; case 'associate-artifact-to': $linked_artifact_id = $request->get('linked-artifact-id'); if (!$this->linkArtifact($linked_artifact_id, $current_user)) { $GLOBALS['Response']->sendStatusCode(400); } else { $this->summonArtifactAssociators($request, $current_user, $linked_artifact_id); } break; case 'higher-priority-than': $dao = new Tracker_Artifact_PriorityDao(); $dao->moveArtifactBefore($this->getId(), (int) $request->get('target-id')); break; case 'lesser-priority-than': $dao = new Tracker_Artifact_PriorityDao(); $dao->moveArtifactAfter($this->getId(), (int) $request->get('target-id')); break; default: if ($request->isAjax()) { echo $this->fetchTooltip($current_user); } else { $this->display($layout, $request, $current_user); } break; } }
/** * Display a report. Choose the report among * - the requested 'select_report' * - the last viewed report (stored in preferences) * - the default report of this tracker * * If the user request a 'link-artifact-id' then display also manual and recent * panels to ease the selection of artifacts to link * * @param Tracker_IDisplayTrackerLayout $layout Displays the page header and footer * @param Codendi_Request $request The request * @param User $current_user The user who made the request * * @return void */ public function displayAReport(Tracker_IDisplayTrackerLayout $layout, $request, $current_user) { $report = null; //Does the user wants to change its report? if ($request->get('select_report') && $request->isPost()) { //Is the report id valid if ($report = $this->getReportFactory()->getReportById($request->get('select_report'), $current_user->getid())) { $current_user->setPreference('tracker_' . $this->id . '_last_report', $report->id); } } //If no valid report found. Search the last viewed report for the user if (!$report) { if ($report_id = $current_user->getPreference('tracker_' . $this->id . '_last_report')) { $report = $this->getReportFactory()->getReportById($report_id, $current_user->getid()); } } //If no valid report found. Take the default one if (!$report) { $report = $this->getReportFactory()->getDefaultReportsByTrackerId($this->id); } $link_artifact_id = (int) $request->get('link-artifact-id'); if ($link_artifact_id && !$request->get('report-only')) { $linked_artifact = Tracker_ArtifactFactory::instance()->getArtifactById($link_artifact_id); if (!$linked_artifact) { $err = "Linked artifact not found or doesn't exist"; if (!$request->isAjax()) { $GLOBALS['Response']->addFeedback('error', $err); $GLOBALS['Response']->redirect('/'); } die($err); } if (!$request->isAjax()) { //screwed up $GLOBALS['Response']->addFeedback('error', 'Something is wrong with your request'); $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?aid=' . $linked_artifact->getId()); } echo $linked_artifact->fetchTitle($GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'title_prefix')); echo '<input type="hidden" id="link-artifact-id" value="' . (int) $link_artifact_id . '" />'; echo '<table id="tracker-link-artifact-different-ways" cellpadding="0" cellspacing="0" border="0"><tbody><tr>'; //the fast ways echo '<td id="tracker-link-artifact-fast-ways">'; //Manual echo '<div id="tracker-link-artifact-manual-way">'; echo '<div class="boxtitle">'; echo $GLOBALS['HTML']->getImage('ic/lightning-white.png', array('style' => 'vertical-align:middle')) . ' '; echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_title'); echo '</div>'; echo '<div class="tracker-link-artifact-manual-way-content">'; echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_desc'); echo '<p><label for="link-artifact-manual-field">'; echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_label'); echo '</label><br />'; echo '<input type="text" name="link-artifact[manual]" value="" id="link-artifact-manual-field" />'; echo '</p>'; echo '</div>'; echo '</div>'; //History echo '<div id="tracker-link-artifact-recentitems-way">'; echo '<div class="boxtitle">'; echo $GLOBALS['HTML']->getImage('ic/star-white.png', array('style' => 'vertical-align:middle')) . ' '; echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'recent_panel_title'); echo '</div>'; echo '<div class="tracker-link-artifact-recentitems-way-content">'; if ($recent_items = $current_user->getRecentElements()) { echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'recent_panel_desc'); echo '<ul>'; foreach ($recent_items as $item) { if ($item['id'] != $link_artifact_id) { echo '<li>'; echo '<input type="checkbox" name="link-artifact[recent][]" value="' . (int) $item['id'] . '" /> '; echo $item['link']; echo '</li>'; } } echo '</ul>'; } echo '</div>'; echo '</div>'; //end of fast ways echo '</td>'; //And the slow way (aka need to search) if ($report) { echo '<td><div id="tracker-link-artifact-slow-way">'; echo '<div class="boxtitle">'; echo $GLOBALS['HTML']->getImage('ic/magnifier-white.png', array('style' => 'vertical-align:middle')) . ' '; echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'search_panel_title'); echo '</div>'; echo '<div id="tracker-link-artifact-slow-way-content">'; } } if ($report) { $report->process($layout, $request, $current_user); } elseif (!$link_artifact_id) { $this->displayHeader($layout, $this->name, array()); echo $GLOBALS['Language']->getText('plugin_tracker', 'no_reports_available'); $this->displayFooter($layout); } if ($link_artifact_id && !$request->get('report-only')) { if ($report) { echo '</div></div></td>'; //end of slow } echo '</tr></tbody></table>'; //end of ways echo '<div class="tracker-link-artifact-controls">'; echo '<a href="#cancel" onclick="myLightWindow.deactivate(); return false;">« ' . $GLOBALS['Language']->getText('global', 'btn_cancel') . '</a>'; echo ' '; echo '<button name="link-artifact-submit">' . $GLOBALS['Language']->getText('global', 'btn_submit') . '</button>'; echo '</div>'; } }
private function executeRedirect(Codendi_Request $request, Tracker_Artifact $artifact, Tracker_Artifact_Redirect $redirect) { if ($request->isAjax()) { header(json_header(array('aid' => $artifact->getId()))); exit; } else { if ($this->isFromOverlay($request)) { echo '<script>window.parent.codendi.tracker.artifact.artifactLink.newArtifact(' . (int) $artifact->getId() . ');</script>'; exit; } else { $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_index', 'create_success', array($artifact->fetchXRefLink())), CODENDI_PURIFIER_LIGHT); $GLOBALS['Response']->redirect($redirect->toUrl()); } } }