public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$user) {
         return new Aphront404Response();
     }
     $profile_uri = '/p/' . $user->getUsername() . '/';
     $field_list = PhabricatorCustomField::getObjectFields($user, PhabricatorCustomField::ROLE_EDIT);
     $field_list->setViewer($viewer)->readFieldsFromStorage($user);
     $validation_exception = null;
     if ($request->isFormPost()) {
         $xactions = $field_list->buildFieldTransactionsFromRequest(new PhabricatorUserTransaction(), $request);
         $editor = id(new PhabricatorUserProfileEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($user, $xactions);
             return id(new AphrontRedirectResponse())->setURI($profile_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
         }
     }
     $title = pht('Edit Profile');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($user->getUsername(), $profile_uri);
     $crumbs->addTextCrumb($title);
     $form = id(new AphrontFormView())->setUser($viewer);
     $field_list->appendFieldsToForm($form);
     $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($profile_uri)->setValue(pht('Save Profile')));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Edit Profile'))->setValidationException($validation_exception)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($this->phid))->setViewer($viewer)->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't remove an already-removed comment.
         return new Aphront400Response();
     }
     $obj_phid = $xaction->getObjectPHID();
     $obj_handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($obj_phid))->executeOne();
     if ($request->isDialogFormPost()) {
         $comment = $xaction->getApplicationTransactionCommentObject()->setContent('')->setIsRemoved(true);
         $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment);
         if ($request->isAjax()) {
             return id(new AphrontAjaxResponse())->setContent(array());
         } else {
             return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer);
     $dialog = $this->newDialog()->setTitle(pht('Remove Comment'));
     $dialog->addHiddenInput('anchor', $request->getStr('anchor'))->appendParagraph(pht("Removing a comment prevents anyone (including you) from reading " . "it. Removing a comment also hides the comment's edit history " . "and prevents it from being edited."))->appendParagraph(pht('Really remove this comment?'));
     $dialog->addSubmitButton(pht('Remove Comment'))->addCancelButton($obj_handle->getURI());
     return $dialog;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $initiative = id(new FundInitiativeQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$initiative) {
         return new Aphront404Response();
     }
     $merchant = id(new PhortuneMerchantQuery())->setViewer($viewer)->withPHIDs(array($initiative->getMerchantPHID()))->executeOne();
     if (!$merchant) {
         return new Aphront404Response();
     }
     $initiative_uri = '/' . $initiative->getMonogram();
     if ($initiative->isClosed()) {
         return $this->newDialog()->setTitle(pht('Initiative Closed'))->appendParagraph(pht('You can not back a closed initiative.'))->addCancelButton($initiative_uri);
     }
     $accounts = PhortuneAccountQuery::loadAccountsForUser($viewer, PhabricatorContentSource::newFromRequest($request));
     $v_amount = null;
     $e_amount = true;
     $v_account = head($accounts)->getPHID();
     $errors = array();
     if ($request->isFormPost()) {
         $v_amount = $request->getStr('amount');
         $v_account = $request->getStr('accountPHID');
         if (empty($accounts[$v_account])) {
             $errors[] = pht('You must specify an account.');
         } else {
             $account = $accounts[$v_account];
         }
         if (!strlen($v_amount)) {
             $errors[] = pht('You must specify how much money you want to contribute to the ' . 'initiative.');
             $e_amount = pht('Required');
         } else {
             try {
                 $currency = PhortuneCurrency::newFromUserInput($viewer, $v_amount);
                 $currency->assertInRange('1.00 USD', null);
             } catch (Exception $ex) {
                 $errors[] = $ex->getMessage();
                 $e_amount = pht('Invalid');
             }
         }
         if (!$errors) {
             $backer = FundBacker::initializeNewBacker($viewer)->setInitiativePHID($initiative->getPHID())->attachInitiative($initiative)->setAmountAsCurrency($currency)->save();
             $product = id(new PhortuneProductQuery())->setViewer($viewer)->withClassAndRef('FundBackerProduct', $initiative->getPHID())->executeOne();
             $cart_implementation = id(new FundBackerCart())->setInitiative($initiative);
             $cart = $account->newCart($viewer, $cart_implementation, $merchant);
             $purchase = $cart->newPurchase($viewer, $product);
             $purchase->setBasePriceAsCurrency($currency)->setMetadataValue('backerPHID', $backer->getPHID())->save();
             $xactions = array();
             $xactions[] = id(new FundBackerTransaction())->setTransactionType(FundBackerTransaction::TYPE_STATUS)->setNewValue(FundBacker::STATUS_IN_CART);
             $editor = id(new FundBackerEditor())->setActor($viewer)->setContentSourceFromRequest($request);
             $editor->applyTransactions($backer, $xactions);
             $cart->activateCart();
             return id(new AphrontRedirectResponse())->setURI($cart->getCheckoutURI());
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setName('accountPHID')->setLabel(pht('Account'))->setValue($v_account)->setOptions(mpull($accounts, 'getName', 'getPHID')))->appendChild(id(new AphrontFormTextControl())->setName('amount')->setLabel(pht('Amount'))->setValue($v_amount)->setError($e_amount));
     return $this->newDialog()->setTitle(pht('Back %s %s', $initiative->getMonogram(), $initiative->getName()))->setErrors($errors)->appendChild($form->buildLayoutView())->addCancelButton($initiative_uri)->addSubmitButton(pht('Continue'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $title = pht('New Message');
     $participants = array();
     $participant_prefill = null;
     $message = '';
     $e_participants = null;
     $e_message = null;
     // this comes from ajax requests from all over. should be a single phid.
     if ($request->isFormPost()) {
         $participants = $request->getArr('participants');
         $message = $request->getStr('message');
         list($error_codes, $conpherence) = ConpherenceEditor::createConpherence($user, $participants, $conpherence_title = null, $message, PhabricatorContentSource::newFromRequest($request));
         if ($error_codes) {
             foreach ($error_codes as $error_code) {
                 switch ($error_code) {
                     case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
                         $e_message = true;
                         break;
                     case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
                         $e_participants = true;
                         break;
                 }
             }
         } else {
             $uri = $this->getApplicationURI($conpherence->getID());
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     } else {
         $participant_prefill = $request->getStr('participant');
         if ($participant_prefill) {
             $participants[] = $participant_prefill;
         }
     }
     $participant_handles = array();
     if ($participants) {
         $participant_handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs($participants)->execute();
     }
     $submit_uri = $this->getApplicationURI('new/');
     $cancel_uri = $this->getApplicationURI();
     // TODO - we can get a better cancel_uri once we get better at crazy
     // ajax jonx T2086
     if ($participant_prefill) {
         $handle = $participant_handles[$participant_prefill];
         $cancel_uri = $handle->getURI();
     }
     $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FORM)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Send Message'));
     $form = id(new PHUIFormLayoutView())->setUser($user)->setFullWidth(true)->appendChild(id(new AphrontFormTokenizerControl())->setName('participants')->setValue($participant_handles)->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('To'))->setError($e_participants))->appendChild(id(new PhabricatorRemarkupControl())->setName('message')->setValue($message)->setLabel(pht('Message'))->setError($e_message));
     $dialog->appendChild($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function manageApplication($issue)
 {
     $key = 'config.ignore-issues';
     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
     $list = $config_entry->getValue();
     if (isset($list[$issue])) {
         unset($list[$issue]);
     } else {
         $list[$issue] = true;
     }
     PhabricatorConfigEditor::storeNewValue($this->getRequest()->getUser(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest()));
 }
 public function manageApplication()
 {
     $key = 'phabricator.uninstalled-applications';
     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
     $list = $config_entry->getValue();
     $uninstalled = PhabricatorEnv::getEnvConfig($key);
     if (isset($uninstalled[$this->application])) {
         unset($list[$this->application]);
     } else {
         $list[$this->application] = true;
     }
     PhabricatorConfigEditor::storeNewValue($this->getViewer(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest()));
 }
 public function handleActionRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     // TODO: As above, this would eventually be driven by custom logic.
     if ($request->isFormPost()) {
         $properties = array('complaint' => (string) $request->getStr('complaint'));
         $content_source = PhabricatorContentSource::newFromRequest($request);
         $item = $this->newItemFromProperties($properties, $content_source);
         $uri = $item->getURI();
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $form = id(new AphrontFormView())->setUser($viewer)->appendRemarkupInstructions(pht('IMPORTANT: This is a very rough prototype.'))->appendRemarkupInstructions(pht('Got a complaint? Complain here! We love complaints.'))->appendChild(id(new AphrontFormTextAreaControl())->setName('complaint')->setLabel(pht('Complaint')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Submit Complaint')));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Complaint Form'))->appendChild($form);
     return $box;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $accounts = id(new PhortuneAccountQuery())->setViewer($viewer)->withMemberPHIDs(array($viewer->getPHID()))->execute();
     if (!$accounts) {
         $account = PhortuneAccount::createNewAccount($viewer, PhabricatorContentSource::newFromRequest($request));
         $accounts = array($account);
     }
     if (count($accounts) == 1) {
         $account = head($accounts);
         $next_uri = $this->getApplicationURI($account->getID() . '/');
     } else {
         $next_uri = $this->getApplicationURI('account/');
     }
     return id(new AphrontRedirectResponse())->setURI($next_uri);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $title = pht('New Message');
     $participants = array();
     $participant_prefill = null;
     $message = '';
     $e_participants = null;
     $e_message = null;
     $errors = array();
     // this comes from ajax requests from all over. should be a single phid.
     if ($request->isFormPost()) {
         $participants = $request->getArr('participants');
         $message = $request->getStr('message');
         list($error_codes, $conpherence) = ConpherenceEditor::createThread($user, $participants, $conpherence_title = null, $message, PhabricatorContentSource::newFromRequest($request));
         if ($error_codes) {
             foreach ($error_codes as $error_code) {
                 switch ($error_code) {
                     case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
                         $e_message = pht('Required');
                         $errors[] = pht('You can not send an empty message.');
                         break;
                     case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
                         $e_participants = pht('Required');
                         $errors[] = pht('You must choose at least one recipient for your ' . 'message.');
                         break;
                 }
             }
         } else {
             return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram());
         }
     } else {
         $participant_prefill = $request->getStr('participant');
         if ($participant_prefill) {
             $participants[] = $participant_prefill;
         }
     }
     $submit_uri = $this->getApplicationURI('new/');
     $cancel_uri = $this->getApplicationURI();
     $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FORM)->setErrors($errors)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Send Message'));
     $form = id(new AphrontFormView())->setUser($user)->setFullWidth(true)->appendControl(id(new AphrontFormTokenizerControl())->setName('participants')->setValue($participants)->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('To'))->setError($e_participants))->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setName('message')->setValue($message)->setLabel(pht('Message'))->setError($e_message));
     $dialog->appendForm($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withIDs(array($id))->needProfileImage(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$user) {
         return new Aphront404Response();
     }
     $this->setUser($user);
     $done_uri = $this->getApplicationURI("manage/{$id}/");
     $field_list = PhabricatorCustomField::getObjectFields($user, PhabricatorCustomField::ROLE_EDIT);
     $field_list->setViewer($viewer)->readFieldsFromStorage($user);
     $validation_exception = null;
     if ($request->isFormPost()) {
         $xactions = $field_list->buildFieldTransactionsFromRequest(new PhabricatorUserTransaction(), $request);
         $editor = id(new PhabricatorUserProfileEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($user, $xactions);
             return id(new AphrontRedirectResponse())->setURI($done_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
         }
     }
     $title = pht('Edit Profile');
     $form = id(new AphrontFormView())->setUser($viewer);
     $field_list->appendFieldsToForm($form);
     $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($done_uri)->setValue(pht('Save Profile')));
     $allow_public = PhabricatorEnv::getEnvConfig('policy.allow-public');
     $note = null;
     if ($allow_public) {
         $note = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_WARNING)->appendChild(pht('Information on user profiles on this install is publicly ' . 'visible.'));
     }
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Edit Profile'))->setValidationException($validation_exception)->setForm($form);
     if ($note) {
         $form_box->setInfoView($note);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Edit Profile'));
     $nav = $this->getProfileMenu();
     $nav->selectFilter(PhabricatorPeopleProfilePanelEngine::PANEL_MANAGE);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setNavigation($nav)->appendChild($form_box);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $dashboard = id(new PhabricatorDashboardQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$dashboard) {
         return new Aphront404Response();
     }
     $redirect_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     $v_panel = $request->getStr('panel');
     $e_panel = true;
     $errors = array();
     if ($request->isFormPost()) {
         if (strlen($v_panel)) {
             $panel = id(new PhabricatorDashboardPanelQuery())->setViewer($viewer)->withIDs(array($v_panel))->executeOne();
             if (!$panel) {
                 $errors[] = pht('No such panel!');
                 $e_panel = pht('Invalid');
             }
         } else {
             $errors[] = pht('Select a panel to add.');
             $e_panel = pht('Required');
         }
         if (!$errors) {
             PhabricatorDashboardTransactionEditor::addPanelToDashboard($viewer, PhabricatorContentSource::newFromRequest($request), $panel, $dashboard, $request->getInt('column', 0));
             return id(new AphrontRedirectResponse())->setURI($redirect_uri);
         }
     }
     $panels = id(new PhabricatorDashboardPanelQuery())->setViewer($viewer)->withArchived(false)->execute();
     if (!$panels) {
         return $this->newDialog()->setTitle(pht('No Panels Exist Yet'))->appendParagraph(pht('You have not created any dashboard panels yet, so you can not ' . 'add an existing panel.'))->appendParagraph(pht('Instead, add a new panel.'))->addCancelButton($redirect_uri);
     }
     $panel_options = array();
     foreach ($panels as $panel) {
         $panel_options[$panel->getID()] = pht('%s %s', $panel->getMonogram(), $panel->getName());
     }
     $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('column', $request->getInt('column'))->appendRemarkupInstructions(pht('Choose a panel to add to this dashboard:'))->appendChild(id(new AphrontFormSelectControl())->setName('panel')->setLabel(pht('Panel'))->setValue($v_panel)->setError($e_panel)->setOptions($panel_options));
     return $this->newDialog()->setTitle(pht('Add Panel'))->setErrors($errors)->appendChild($form->buildLayoutView())->addCancelButton($redirect_uri)->addSubmitButton(pht('Add Panel'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($this->phid))->setViewer($user)->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         // You can't currently edit a transaction which doesn't have a comment.
         // Some day you may be able to edit the visibility.
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't edit history of a transaction with a removed comment.
         return new Aphront400Response();
     }
     $obj_phid = $xaction->getObjectPHID();
     $obj_handle = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array($obj_phid))->executeOne();
     if ($request->isDialogFormPost()) {
         $text = $request->getStr('text');
         $comment = $xaction->getApplicationTransactionCommentObject();
         $comment->setContent($text);
         if (!strlen($text)) {
             $comment->setIsDeleted(true);
         }
         $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($user)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment);
         if ($request->isAjax()) {
             return id(new AphrontAjaxResponse())->setContent(array());
         } else {
             return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
         }
     }
     $dialog = id(new AphrontDialogView())->setUser($user)->setSubmitURI($this->getApplicationURI('/transactions/edit/' . $xaction->getPHID() . '/'))->setTitle(pht('Edit Comment'));
     $dialog->addHiddenInput('anchor', $request->getStr('anchor'))->appendChild(id(new PHUIFormLayoutView())->setFullWidth(true)->appendChild(id(new PhabricatorRemarkupControl())->setName('text')->setValue($xaction->getComment()->getContent())));
     $dialog->addSubmitButton(pht('Save Changes'))->addCancelButton($obj_handle->getURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $phid = $request->getURIData('phid');
     $handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne();
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $current = id(new PhabricatorTokenGivenQuery())->setViewer($viewer)->withAuthorPHIDs(array($viewer->getPHID()))->withObjectPHIDs(array($handle->getPHID()))->execute();
     if ($current) {
         $is_give = false;
         $title = pht('Rescind Token');
     } else {
         $is_give = true;
         $title = pht('Give Token');
     }
     $done_uri = $handle->getURI();
     if ($request->isDialogFormPost()) {
         $content_source = PhabricatorContentSource::newFromRequest($request);
         $editor = id(new PhabricatorTokenGivenEditor())->setActor($viewer)->setContentSource($content_source);
         if ($is_give) {
             $token_phid = $request->getStr('tokenPHID');
             $editor->addToken($handle->getPHID(), $token_phid);
         } else {
             $editor->deleteToken($handle->getPHID());
         }
         return id(new AphrontReloadResponse())->setURI($done_uri);
     }
     if ($is_give) {
         $dialog = $this->buildGiveTokenDialog();
     } else {
         $dialog = $this->buildRescindTokenDialog(head($current));
     }
     $dialog->setUser($viewer);
     $dialog->addCancelButton($done_uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $xaction = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($request->getURIData('phid')))->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         // You can't currently edit a transaction which doesn't have a comment.
         // Some day you may be able to edit the visibility.
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't edit history of a transaction with a removed comment.
         return new Aphront400Response();
     }
     $phid = $xaction->getObjectPHID();
     $handles = $viewer->loadHandles(array($phid));
     $obj_handle = $handles[$phid];
     if ($request->isDialogFormPost()) {
         $text = $request->getStr('text');
         $comment = $xaction->getApplicationTransactionCommentObject();
         $comment->setContent($text);
         if (!strlen($text)) {
             $comment->setIsDeleted(true);
         }
         $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment);
         if ($request->isAjax()) {
             return id(new AphrontAjaxResponse())->setContent(array());
         } else {
             return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer)->setFullWidth(true)->appendControl(id(new PhabricatorRemarkupControl())->setName('text')->setValue($xaction->getComment()->getContent()));
     return $this->newDialog()->setTitle(pht('Edit Comment'))->addHiddenInput('anchor', $request->getStr('anchor'))->appendForm($form)->addSubmitButton(pht('Save Changes'))->addCancelButton($obj_handle->getURI());
 }
 public function setContentSourceFromRequest(AphrontRequest $request)
 {
     return $this->setContentSource(PhabricatorContentSource::newFromRequest($request));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $application = $request->getURIData('application');
     $application = id(new PhabricatorApplicationQuery())->setViewer($user)->withClasses(array($application))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$application) {
         return new Aphront404Response();
     }
     $title = $application->getName();
     $view_uri = $this->getApplicationURI('view/' . get_class($application) . '/');
     $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($application)->execute();
     if ($request->isFormPost()) {
         $result = array();
         foreach ($application->getCapabilities() as $capability) {
             $old = $application->getPolicy($capability);
             $new = $request->getStr('policy:' . $capability);
             if ($old == $new) {
                 // No change to the setting.
                 continue;
             }
             if (empty($policies[$new])) {
                 // Not a standard policy, check for a custom policy.
                 $policy = id(new PhabricatorPolicyQuery())->setViewer($user)->withPHIDs(array($new))->executeOne();
                 if (!$policy) {
                     // Not a custom policy either. Can't set the policy to something
                     // invalid, so skip this.
                     continue;
                 }
             }
             if ($new == PhabricatorPolicies::POLICY_PUBLIC) {
                 $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
                 if (!$capobj || !$capobj->shouldAllowPublicPolicySetting()) {
                     // Can't set non-public policies to public.
                     continue;
                 }
             }
             $result[$capability] = $new;
         }
         if ($result) {
             $key = 'phabricator.application-settings';
             $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
             $value = $config_entry->getValue();
             $phid = $application->getPHID();
             if (empty($value[$phid])) {
                 $value[$application->getPHID()] = array();
             }
             if (empty($value[$phid]['policy'])) {
                 $value[$phid]['policy'] = array();
             }
             $value[$phid]['policy'] = $result + $value[$phid]['policy'];
             // Don't allow users to make policy edits which would lock them out of
             // applications, since they would be unable to undo those actions.
             PhabricatorEnv::overrideConfig($key, $value);
             PhabricatorPolicyFilter::mustRetainCapability($user, $application, PhabricatorPolicyCapability::CAN_VIEW);
             PhabricatorPolicyFilter::mustRetainCapability($user, $application, PhabricatorPolicyCapability::CAN_EDIT);
             PhabricatorConfigEditor::storeNewValue($user, $config_entry, $value, PhabricatorContentSource::newFromRequest($request));
         }
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($user, $application);
     $form = id(new AphrontFormView())->setUser($user);
     $locked_policies = PhabricatorEnv::getEnvConfig('policy.locked');
     foreach ($application->getCapabilities() as $capability) {
         $label = $application->getCapabilityLabel($capability);
         $can_edit = $application->isCapabilityEditable($capability);
         $locked = idx($locked_policies, $capability);
         $caption = $application->getCapabilityCaption($capability);
         if (!$can_edit || $locked) {
             $form->appendChild(id(new AphrontFormStaticControl())->setLabel($label)->setValue(idx($descriptions, $capability))->setCaption($caption));
         } else {
             $control = id(new AphrontFormPolicyControl())->setUser($user)->setDisabled($locked)->setCapability($capability)->setPolicyObject($application)->setPolicies($policies)->setLabel($label)->setName('policy:' . $capability)->setCaption($caption);
             $template = $application->getCapabilityTemplatePHIDType($capability);
             if ($template) {
                 $phid_types = PhabricatorPHIDType::getAllTypes();
                 $phid_type = idx($phid_types, $template);
                 if ($phid_type) {
                     $template_object = $phid_type->newObject();
                     if ($template_object) {
                         $template_policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($template_object)->execute();
                         // NOTE: We want to expose both any object template policies
                         // (like "Subscribers") and any custom policy.
                         $all_policies = $template_policies + $policies;
                         $control->setPolicies($all_policies);
                         $control->setTemplateObject($template_object);
                     }
                 }
                 $control->setTemplatePHIDType($template);
             }
             $form->appendControl($control);
         }
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Policies'))->addCancelButton($view_uri));
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($application->getName(), $view_uri);
     $crumbs->addTextCrumb(pht('Edit Policies'));
     $header = id(new PHUIHeaderView())->setHeader(pht('Edit Policies: %s', $application->getName()));
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $object_box), array('title' => $title));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     // If the user is trying to create a panel directly on a dashboard, make
     // sure they have permission to see and edit the dashboard.
     $dashboard_id = $request->getInt('dashboardID');
     $dashboard = null;
     if ($dashboard_id) {
         $dashboard = id(new PhabricatorDashboardQuery())->setViewer($viewer)->withIDs(array($dashboard_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$dashboard) {
             return new Aphront404Response();
         }
         $manage_uri = $this->getApplicationURI('manage/' . $dashboard_id . '/');
     }
     if ($id) {
         $is_create = false;
         if ($dashboard) {
             $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
         } else {
             $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT);
         }
         $panel = id(new PhabricatorDashboardPanelQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities($capabilities)->executeOne();
         if (!$panel) {
             return new Aphront404Response();
         }
         $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($panel->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
         $v_projects = array_reverse($v_projects);
         if ($dashboard) {
             $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $panel, PhabricatorPolicyCapability::CAN_EDIT);
             if (!$can_edit) {
                 if ($request->isFormPost() && $request->getBool('copy')) {
                     $panel = $this->copyPanel($request, $dashboard, $panel);
                 } else {
                     return $this->processPanelCloneRequest($request, $dashboard, $panel);
                 }
             }
         }
     } else {
         $is_create = true;
         $panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
         $types = PhabricatorDashboardPanelType::getAllPanelTypes();
         $type = $request->getStr('type');
         if (empty($types[$type])) {
             return $this->processPanelTypeRequest($request);
         }
         $v_projects = array();
         $panel->setPanelType($type);
     }
     if ($is_create) {
         $title = pht('New Panel');
         $header = pht('Create New Panel');
         $button = pht('Create Panel');
         if ($dashboard) {
             $cancel_uri = $manage_uri;
         } else {
             $cancel_uri = $this->getApplicationURI('panel/');
         }
     } else {
         $title = pht('Edit %s', $panel->getMonogram());
         $header = pht('Edit %s %s', $panel->getMonogram(), $panel->getName());
         $button = pht('Save Panel');
         if ($dashboard) {
             $cancel_uri = $manage_uri;
         } else {
             $cancel_uri = '/' . $panel->getMonogram();
         }
     }
     $v_name = $panel->getName();
     $e_name = true;
     $field_list = PhabricatorCustomField::getObjectFields($panel, PhabricatorCustomField::ROLE_EDIT);
     $field_list->setViewer($viewer)->readFieldsFromStorage($panel);
     if ($is_create && !$request->isFormPost()) {
         $panel->requireImplementation()->initializeFieldsFromRequest($panel, $field_list, $request);
     }
     $validation_exception = null;
     // NOTE: We require 'edit' to distinguish between the "Choose a Type"
     // and "Create a Panel" dialogs.
     if ($request->isFormPost() && $request->getBool('edit')) {
         $v_name = $request->getStr('name');
         $v_view_policy = $request->getStr('viewPolicy');
         $v_edit_policy = $request->getStr('editPolicy');
         $v_projects = $request->getArr('projects');
         $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME;
         $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
         $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY;
         $xactions = array();
         $xactions[] = id(new PhabricatorDashboardPanelTransaction())->setTransactionType($type_name)->setNewValue($v_name);
         $xactions[] = id(new PhabricatorDashboardPanelTransaction())->setTransactionType($type_view_policy)->setNewValue($v_view_policy);
         $xactions[] = id(new PhabricatorDashboardPanelTransaction())->setTransactionType($type_edit_policy)->setNewValue($v_edit_policy);
         $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
         $xactions[] = id(new PhabricatorDashboardPanelTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects)));
         $field_xactions = $field_list->buildFieldTransactionsFromRequest(new PhabricatorDashboardPanelTransaction(), $request);
         $xactions = array_merge($xactions, $field_xactions);
         try {
             $editor = id(new PhabricatorDashboardPanelTransactionEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->applyTransactions($panel, $xactions);
             // If we're creating a panel directly on a dashboard, add it now.
             if ($dashboard) {
                 PhabricatorDashboardTransactionEditor::addPanelToDashboard($viewer, PhabricatorContentSource::newFromRequest($request), $panel, $dashboard, $request->getInt('column', 0));
             }
             if ($dashboard) {
                 $done_uri = $manage_uri;
             } else {
                 $done_uri = '/' . $panel->getMonogram();
             }
             return id(new AphrontRedirectResponse())->setURI($done_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_name = $validation_exception->getShortMessage($type_name);
             $panel->setViewPolicy($v_view_policy);
             $panel->setEditPolicy($v_edit_policy);
         }
     }
     // NOTE: We're setting the submit URI explicitly because we need to edit
     // a different panel if we just cloned the original panel.
     if ($is_create) {
         $submit_uri = $this->getApplicationURI('panel/edit/');
     } else {
         $submit_uri = $this->getApplicationURI('panel/edit/' . $panel->getID() . '/');
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($panel)->execute();
     $form = id(new AphrontFormView())->setUser($viewer)->setAction($submit_uri)->addHiddenInput('edit', true)->addHiddenInput('dashboardID', $request->getInt('dashboardID'))->addHiddenInput('column', $request->getInt('column'))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($v_name)->setError($e_name))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($panel)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($panel)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies));
     $form->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()));
     $field_list->appendFieldsToForm($form);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Panels'), $this->getApplicationURI('panel/'));
     if ($is_create) {
         $crumbs->addTextCrumb(pht('New Panel'));
         $form->addHiddenInput('type', $panel->getPanelType());
     } else {
         $crumbs->addTextCrumb($panel->getMonogram(), '/' . $panel->getMonogram());
         $crumbs->addTextCrumb(pht('Edit'));
     }
     if ($request->isAjax()) {
         return $this->newDialog()->setTitle($header)->setSubmitURI($submit_uri)->setWidth(AphrontDialogView::WIDTH_FORM)->setValidationException($validation_exception)->appendChild($form->buildLayoutView())->addCancelButton($cancel_uri)->addSubmitButton($button);
     } else {
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue($button)->addCancelButton($cancel_uri));
     }
     $box = id(new PHUIObjectBoxView())->setHeaderText($header)->setValidationException($validation_exception)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $object = $this->loadRelationshipObject();
     if (!$object) {
         return new Aphront404Response();
     }
     $relationship = $this->loadRelationship($object);
     if (!$relationship) {
         return new Aphront404Response();
     }
     $src_phid = $object->getPHID();
     $edge_type = $relationship->getEdgeConstant();
     // If this is a normal relationship, users can remove related objects. If
     // it's a special relationship like a merge, we can't undo it, so we won't
     // prefill the current related objects.
     if ($relationship->canUndoRelationship()) {
         $dst_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($src_phid, $edge_type);
     } else {
         $dst_phids = array();
     }
     $all_phids = $dst_phids;
     $all_phids[] = $src_phid;
     $handles = $viewer->loadHandles($all_phids);
     $src_handle = $handles[$src_phid];
     $done_uri = $src_handle->getURI();
     $initial_phids = $dst_phids;
     $maximum = $relationship->getMaximumSelectionSize();
     if ($request->isFormPost()) {
         $phids = explode(';', $request->getStr('phids'));
         $phids = array_filter($phids);
         $phids = array_values($phids);
         // The UI normally enforces this with Javascript, so this is just a
         // sanity check and does not need to be particularly user-friendly.
         if ($maximum && count($phids) > $maximum) {
             throw new Exception(pht('Too many relationships (%s, of type "%s").', phutil_count($phids), $relationship->getRelationshipConstant()));
         }
         $initial_phids = $request->getStrList('initialPHIDs');
         // Apply the changes as adds and removes relative to the original state
         // of the object when the dialog was rendered so that two users adding
         // relationships at the same time don't race and overwrite one another.
         $add_phids = array_diff($phids, $initial_phids);
         $rem_phids = array_diff($initial_phids, $phids);
         $all_phids = array_merge($add_phids, $rem_phids);
         $capabilities = $relationship->getRequiredRelationshipCapabilities();
         if ($all_phids) {
             $dst_objects = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs($all_phids)->setRaisePolicyExceptions(true)->requireCapabilities($capabilities)->execute();
             $dst_objects = mpull($dst_objects, null, 'getPHID');
         } else {
             $dst_objects = array();
         }
         try {
             foreach ($add_phids as $add_phid) {
                 $dst_object = idx($dst_objects, $add_phid);
                 if (!$dst_object) {
                     throw new Exception(pht('You can not create a relationship to object "%s" because ' . 'the object does not exist or could not be loaded.', $add_phid));
                 }
                 if ($add_phid == $src_phid) {
                     throw new Exception(pht('You can not create a relationship to object "%s" because ' . 'objects can not be related to themselves.', $add_phid));
                 }
                 if (!$relationship->canRelateObjects($object, $dst_object)) {
                     throw new Exception(pht('You can not create a relationship (of type "%s") to object ' . '"%s" because it is not the right type of object for this ' . 'relationship.', $relationship->getRelationshipConstant(), $add_phid));
                 }
             }
         } catch (Exception $ex) {
             return $this->newUnrelatableObjectResponse($ex, $done_uri);
         }
         $content_source = PhabricatorContentSource::newFromRequest($request);
         $relationship->setContentSource($content_source);
         $editor = $object->getApplicationTransactionEditor()->setActor($viewer)->setContentSource($content_source)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
         $xactions = array();
         $xactions[] = $object->getApplicationTransactionTemplate()->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $edge_type)->setNewValue(array('+' => array_fuse($add_phids), '-' => array_fuse($rem_phids)));
         $add_objects = array_select_keys($dst_objects, $add_phids);
         $rem_objects = array_select_keys($dst_objects, $rem_phids);
         if ($add_objects || $rem_objects) {
             $more_xactions = $relationship->willUpdateRelationships($object, $add_objects, $rem_objects);
             foreach ($more_xactions as $xaction) {
                 $xactions[] = $xaction;
             }
         }
         try {
             $editor->applyTransactions($object, $xactions);
             if ($add_objects || $rem_objects) {
                 $relationship->didUpdateRelationships($object, $add_objects, $rem_objects);
             }
             return id(new AphrontRedirectResponse())->setURI($done_uri);
         } catch (PhabricatorEdgeCycleException $ex) {
             return $this->newGraphCycleResponse($ex, $done_uri);
         }
     }
     $handles = iterator_to_array($handles);
     $handles = array_select_keys($handles, $dst_phids);
     $dialog_title = $relationship->getDialogTitleText();
     $dialog_header = $relationship->getDialogHeaderText();
     $dialog_button = $relationship->getDialogButtonText();
     $dialog_instructions = $relationship->getDialogInstructionsText();
     $source_uri = $relationship->getSourceURI($object);
     $source = $relationship->newSource();
     $filters = $source->getFilters();
     $selected_filter = $source->getSelectedFilter();
     return id(new PhabricatorObjectSelectorDialog())->setUser($viewer)->setInitialPHIDs($initial_phids)->setHandles($handles)->setFilters($filters)->setSelectedFilter($selected_filter)->setExcluded($src_phid)->setCancelURI($done_uri)->setSearchURI($source_uri)->setTitle($dialog_title)->setHeader($dialog_header)->setButtonText($dialog_button)->setInstructions($dialog_instructions)->setMaximumSelectionSize($maximum)->buildDialog();
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $merchant = $this->loadMerchantAuthority();
     if (!$merchant) {
         return new Aphront404Response();
     }
     $merchant_id = $merchant->getID();
     $cancel_uri = $this->getApplicationURI("/merchant/{$merchant_id}/");
     // Load the user to invoice, or prompt the viewer to select one.
     $target_user = null;
     $user_phid = head($request->getArr('userPHID'));
     if (!$user_phid) {
         $user_phid = $request->getStr('userPHID');
     }
     if ($user_phid) {
         $target_user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withPHIDs(array($user_phid))->executeOne();
     }
     if (!$target_user) {
         $form = id(new AphrontFormView())->setUser($viewer)->appendRemarkupInstructions(pht('Choose a user to invoice.'))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('User'))->setDatasource(new PhabricatorPeopleDatasource())->setName('userPHID')->setLimit(1));
         return $this->newDialog()->setTitle(pht('Choose User'))->appendForm($form)->addCancelButton($cancel_uri)->addSubmitButton(pht('Continue'));
     }
     // Load the account to invoice, or prompt the viewer to select one.
     $target_account = null;
     $account_phid = $request->getStr('accountPHID');
     if ($account_phid) {
         $target_account = id(new PhortuneAccountQuery())->setViewer($viewer)->withPHIDs(array($account_phid))->withMemberPHIDs(array($target_user->getPHID()))->executeOne();
     }
     if (!$target_account) {
         $accounts = PhortuneAccountQuery::loadAccountsForUser($target_user, PhabricatorContentSource::newFromRequest($request));
         $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('userPHID', $target_user->getPHID())->appendRemarkupInstructions(pht('Choose which account to invoice.'))->appendControl(id(new AphrontFormMarkupControl())->setLabel(pht('User'))->setValue($viewer->renderHandle($target_user->getPHID())))->appendControl(id(new AphrontFormSelectControl())->setLabel(pht('Account'))->setName('accountPHID')->setValue($account_phid)->setOptions(mpull($accounts, 'getName', 'getPHID')));
         return $this->newDialog()->setTitle(pht('Choose Account'))->appendForm($form)->addCancelButton($cancel_uri)->addSubmitButton(pht('Continue'));
     }
     // Now we build the actual invoice.
     $title = pht('New Invoice');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($merchant->getName());
     $v_title = $request->getStr('title');
     $e_title = true;
     $v_name = $request->getStr('name');
     $e_name = true;
     $v_cost = $request->getStr('cost');
     $e_cost = true;
     $v_desc = $request->getStr('description');
     $v_quantity = 1;
     $e_quantity = null;
     $errors = array();
     if ($request->isFormPost() && $request->getStr('invoice')) {
         $v_quantity = $request->getStr('quantity');
         $e_title = null;
         $e_name = null;
         $e_cost = null;
         $e_quantity = null;
         if (!strlen($v_title)) {
             $e_title = pht('Required');
             $errors[] = pht('You must title this invoice.');
         }
         if (!strlen($v_name)) {
             $e_name = pht('Required');
             $errors[] = pht('You must provide a name for this purchase.');
         }
         if (!strlen($v_cost)) {
             $e_cost = pht('Required');
             $errors[] = pht('You must provide a cost for this purchase.');
         } else {
             try {
                 $v_currency = PhortuneCurrency::newFromUserInput($viewer, $v_cost);
             } catch (Exception $ex) {
                 $errors[] = $ex->getMessage();
                 $e_cost = pht('Invalid');
             }
         }
         if ((int) $v_quantity <= 0) {
             $e_quantity = pht('Invalid');
             $errors[] = pht('Quantity must be a positive integer.');
         }
         if (!$errors) {
             $unique = Filesystem::readRandomCharacters(16);
             $product = id(new PhortuneProductQuery())->setViewer($target_user)->withClassAndRef('PhortuneAdHocProduct', $unique)->executeOne();
             $cart_implementation = new PhortuneAdHocCart();
             $cart = $target_account->newCart($target_user, $cart_implementation, $merchant);
             $cart->setMetadataValue('adhoc.title', $v_title)->setMetadataValue('adhoc.description', $v_desc);
             $purchase = $cart->newPurchase($target_user, $product)->setBasePriceAsCurrency($v_currency)->setQuantity((int) $v_quantity)->setMetadataValue('adhoc.name', $v_name)->save();
             $cart->setIsInvoice(1)->save();
             $cart->activateCart();
             $cart_id = $cart->getID();
             $uri = "/merchant/{$merchant_id}/cart/{$cart_id}/";
             $uri = $this->getApplicationURI($uri);
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('userPHID', $target_user->getPHID())->addHiddenInput('accountPHID', $target_account->getPHID())->addHiddenInput('invoice', true)->appendControl(id(new AphrontFormMarkupControl())->setLabel(pht('User'))->setValue($viewer->renderHandle($target_user->getPHID())))->appendControl(id(new AphrontFormMarkupControl())->setLabel(pht('Account'))->setValue($viewer->renderHandle($target_account->getPHID())))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Invoice Title'))->setName('title')->setValue($v_title)->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Purchase Name'))->setName('name')->setValue($v_name)->setError($e_name))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Purchase Cost'))->setName('cost')->setValue($v_cost)->setError($e_cost))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Quantity'))->setName('quantity')->setValue($v_quantity)->setError($e_quantity))->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Invoice Description'))->setName('description')->setValue($v_desc))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue(pht('Send Invoice')));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('New Invoice'))->setFormErrors($errors)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title));
 }