예제 #1
0
 protected function displayAjax($title, $form)
 {
     header(json_header(array('dialog-title' => $title)));
     echo $form;
 }
예제 #2
0
 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());
         }
     }
 }
예제 #3
0
                    $date = $request->get('date');
                    $group_id = $request->get('group_id');
                    $release_id = $request->get('release_id');
                    $validator = new frsValidator();
                    $release = array('name' => $name, 'release_id' => $release_id, 'package_id' => $package_id, 'date' => $date);
                    if ($validator->isValidForUpdate($release, $group_id)) {
                        //frs valid
                        $header = array('valid' => true);
                    } else {
                        //frs non valid
                        $errors = $validator->getErrors();
                        $feedback = new Feedback();
                        $feedback->log('error', $errors[0]);
                        $header = array('valid' => false, 'msg' => $feedback->fetch());
                    }
                    header(json_header($header));
                }
            } else {
                if ($action == 'refresh_file_list') {
                    $project = $request->getProject();
                    $frsff = new FRSFileFactory();
                    $file_list = $frsff->getUploadedFileNames($project);
                    $available_ftp_files = implode(",", $file_list);
                    $purifier = Codendi_HTMLPurifier::instance();
                    $available_ftp_files = $purifier->purify($available_ftp_files, CODENDI_PURIFIER_JS_DQUOTE);
                    echo '{"valid":true, "msg":"' . $available_ftp_files . '"}';
                }
            }
        }
    }
}
예제 #4
0
function json_result($msg = '', $retval = '', $jqremote = false)
{
    json_header();
    $json = jsg_json_encode(array("done" => true, "msg" => $msg, "retval" => $retval));
    if ($jqremote === false) {
        $jqremote = isset($_GET['jsoncallback']) ? trim($_GET['jsoncallback']) : false;
    }
    if ($jqremote) {
        $json = $jqremote . '(' . $json . ')';
    }
    echo $json;
    exit;
}
예제 #5
0
 public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user)
 {
     //TODO: log the admin actions (add a formElement, ...) ?
     $hp = Codendi_HTMLPurifier::instance();
     $func = (string) $request->get('func');
     switch ($func) {
         case 'new-artifact':
             if ($this->userCanSubmitArtifact($current_user)) {
                 $this->displaySubmit($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'new-artifact-link':
             $link = $request->get('id');
             if ($this->userCanSubmitArtifact($current_user)) {
                 $this->displaySubmit($layout, $request, $current_user, $link);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
             }
             break;
         case 'delete':
             if ($this->userCanDeleteTracker($current_user)) {
                 if ($this->getTrackerFactory()->markAsDeleted($this->id)) {
                     $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'delete_success', $hp->purify($this->name, CODENDI_PURIFIER_CONVERT_HTML)));
                     $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'tracker_deleted', $GLOBALS['sys_email_admin']), CODENDI_PURIFIER_FULL);
                 } else {
                     $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'deletion_failed', $hp->purify($this->name, CODENDI_PURIFIER_CONVERT_HTML)));
                 }
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
             }
             $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?group_id=' . $this->group_id);
             break;
         case 'admin':
             if ($this->userIsAdmin($current_user)) {
                 $this->displayAdmin($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-editoptions':
             if ($this->userIsAdmin($current_user)) {
                 if ($request->get('update')) {
                     $this->editOptions($request);
                 }
                 $this->displayAdminOptions($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-perms':
             if ($this->userIsAdmin($current_user)) {
                 $this->displayAdminPerms($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-perms-tracker':
             if ($this->userIsAdmin($current_user)) {
                 if ($request->get('update')) {
                     //TODO : really bad! _REQUEST must be processed before using it, or refactor: use request object
                     plugin_tracker_permission_process_update_tracker_permissions($this->getGroupId(), $this->getId(), $_REQUEST);
                 }
                 $this->displayAdminPermsTracker($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-perms-fields':
             if ($this->userIsAdmin($current_user)) {
                 if ($request->exist('update')) {
                     if ($request->exist('permissions') && is_array($request->get('permissions'))) {
                         plugin_tracker_permission_process_update_fields_permissions($this->getGroupId(), $this->getId(), Tracker_FormElementFactory::instance()->getUsedFields($this), $request->get('permissions'));
                         $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('project_admin_userperms', 'perm_upd'));
                     }
                 }
                 $this->displayAdminPermsFields($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-formElements':
             if ($this->userIsAdmin($current_user)) {
                 if (is_array($request->get('add-formElement'))) {
                     list($formElement_id, ) = each($request->get('add-formElement'));
                     if (Tracker_FormElementFactory::instance()->addFormElement($formElement_id)) {
                         $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'field_added'));
                         $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . (int) $this->getId() . '&func=admin-formElements');
                     }
                 } else {
                     if (is_array($request->get('create-formElement'))) {
                         list($type, ) = each($request->get('create-formElement'));
                         if ($request->get('docreate-formElement') && is_array($request->get('formElement_data'))) {
                             try {
                                 $this->createFormElement($type, $request->get('formElement_data'), $current_user);
                             } catch (Exception $e) {
                                 $GLOBALS['Response']->addFeedback('error', $e->getMessage());
                             }
                             $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => $this->getId(), 'func' => $func)));
                         } else {
                             Tracker_FormElementFactory::instance()->displayAdminCreateFormElement($layout, $request, $current_user, $type, $this);
                             exit;
                         }
                     }
                 }
                 $this->displayAdminFormElements($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-formElement-update':
         case 'admin-formElement-remove':
         case 'admin-formElement-delete':
             if ($this->userIsAdmin($current_user)) {
                 if ($formElement = Tracker_FormElementFactory::instance()->getFormElementById((int) $request->get('formElement'))) {
                     $formElement->process($layout, $request, $current_user);
                 } else {
                     $this->displayAdminFormElements($layout, $request, $current_user);
                 }
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-semantic':
             if ($this->userIsAdmin($current_user)) {
                 $this->getTrackerSemanticManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-notifications':
             if ($this->userIsAdmin($current_user)) {
                 $this->getDateReminderManager()->processReminder($layout, $request, $current_user);
                 $this->getNotificationsManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'notifications':
             // you just need to be registered to have access to this part
             if ($current_user->isLoggedIn()) {
                 $this->getDateReminderManager()->processReminder($layout, $request, $current_user);
                 $this->getNotificationsManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'display_reminder_form':
             print $this->getDateReminderManager()->getDateReminderRenderer()->getNewDateReminderForm();
             break;
         case 'admin-canned':
             // TODO : project members can access this part ?
             if ($this->userIsAdmin($current_user)) {
                 $this->getCannedResponseManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-workflow':
             if ($this->userIsAdmin($current_user)) {
                 $this->getWorkflowManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-csvimport':
             $session = new Codendi_Session();
             if ($this->userIsAdmin($current_user)) {
                 if ($request->exist('action') && $request->get('action') == 'import_preview' && array_key_exists('csv_filename', $_FILES)) {
                     // display preview before importing artifacts
                     $this->displayImportPreview($layout, $request, $current_user, $session);
                 } elseif ($request->exist('action') && $request->get('action') == 'import') {
                     $csv_header = $session->get('csv_header');
                     $csv_body = $session->get('csv_body');
                     if ($this->importFromCSV($layout, $request, $current_user, $csv_header, $csv_body)) {
                         $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_admin_import', 'import_succeed'));
                         $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
                     } else {
                         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin_import', 'import_failed'));
                         $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
                     }
                 }
                 $this->displayAdminCSVImport($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-export':
             if ($this->userIsAdmin($current_user)) {
                 // TODO: change directory
                 $this->sendXML($this->exportToXML());
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-dependencies':
             if ($this->userIsAdmin($current_user)) {
                 $this->getRulesManager()->process($layout, $request, $current_user);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'submit-artifact':
             if ($this->userCanSubmitArtifact($current_user)) {
                 $link = (int) $request->get('link-artifact-id');
                 if ($artifact = $this->createArtifact($layout, $request, $current_user)) {
                     $this->associateImmediatelyIfNeeded($artifact, $link, $request->get('immediate'), $current_user);
                     $artifact->summonArtifactRedirectors($request);
                     if ($request->isAjax()) {
                         header(json_header(array('aid' => $artifact->getId())));
                         exit;
                     } else {
                         if ($link) {
                             echo '<script>window.parent.codendi.tracker.artifact.artifactLink.newArtifact(' . (int) $artifact->getId() . ');</script>';
                             exit;
                         } else {
                             $art_link = '<a href="' . TRACKER_BASE_URL . '/?aid=' . $artifact->getId() . '">' . $this->getItemName() . ' #' . $artifact->getId() . '</a>';
                             $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_index', 'create_success', array($art_link)), CODENDI_PURIFIER_LIGHT);
                             $url_redirection = $this->redirectUrlAfterArtifactSubmission($request, $this->getId(), $artifact->getId());
                             $GLOBALS['Response']->redirect($url_redirection);
                         }
                     }
                 }
                 $this->displaySubmit($layout, $request, $current_user, $link);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-hierarchy':
             if ($this->userIsAdmin($current_user)) {
                 $this->displayAdminItemHeader($layout, 'hierarchy');
                 $this->getHierarchyController($request)->edit();
                 $this->displayFooter($layout);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         case 'admin-hierarchy-update':
             if ($this->userIsAdmin($current_user)) {
                 $this->getHierarchyController($request)->update();
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_admin', 'access_denied'));
                 $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?tracker=' . $this->getId());
             }
             break;
         default:
             $nothing_has_been_done = true;
             EventManager::instance()->processEvent(TRACKER_EVENT_PROCESS, array('func' => $func, 'tracker' => $this, 'layout' => $layout, 'request' => $request, 'user' => $current_user, 'nothing_has_been_done' => &$nothing_has_been_done));
             if ($nothing_has_been_done) {
                 //If there is nothing to do, display a report
                 if ($this->userCanView($current_user)) {
                     $this->displayAReport($layout, $request, $current_user);
                 }
             }
             break;
     }
     return false;
 }
예제 #6
0
 public function encodesTo($expected)
 {
     $this->testcase->assertEqual('X-JSON: {"whatever":false,"msg":' . $expected . '}', json_header(array("whatever" => false, "msg" => $this->input)));
 }