public function renderControl()
 {
     $control = null;
     switch ($this->getFieldType()) {
         case self::TYPE_INT:
             $control = new AphrontFormTextControl();
             break;
         case self::TYPE_STRING:
             $control = new AphrontFormTextControl();
             break;
         case self::TYPE_SELECT:
             $control = new AphrontFormSelectControl();
             $control->setOptions($this->getSelectOptions());
             break;
         default:
             throw new ManiphestAuxiliaryFieldTypeException($this->getFieldType() . ' is not a valid type for ' . $this->getLabel());
             break;
     }
     $control->setValue($this->getValue());
     $control->setLabel($this->getLabel());
     $control->setCaption($this->getCaption());
     $control->setName('auxiliary[' . $this->getAuxiliaryKey() . ']');
     $control->setError($this->getError());
     return $control;
 }
 protected function renderInput()
 {
     if (!$this->object) {
         throw new Exception("Call setPolicyObject() before rendering!");
     }
     if (!$this->capability) {
         throw new Exception("Call setCapability() before rendering!");
     }
     $policy = $this->object->getPolicy($this->capability);
     if (!$policy) {
         // TODO: Make this configurable.
         $policy = PhabricatorPolicies::POLICY_USER;
     }
     $this->setValue($policy);
     return AphrontFormSelectControl::renderSelectTag($this->getValue(), $this->getOptions(), array('name' => $this->getName(), 'disabled' => $this->getDisabled() ? 'disabled' : null, 'id' => $this->getID()));
 }
 protected function renderInput()
 {
     $options_map = array();
     foreach ($this->options as $option) {
         $options_map[$option->getPHID()] = pht('%s %s', $option->getMonogram(), $option->getName());
     }
     // The user editing the form may not have permission to see the current
     // credential. Populate it into the menu to allow them to save the form
     // without making any changes.
     $current_phid = $this->getValue();
     if (strlen($current_phid) && empty($options_map[$current_phid])) {
         $viewer = $this->getViewer();
         $user_credential = id(new PassphraseCredentialQuery())->setViewer($viewer)->withPHIDs(array($current_phid))->executeOne();
         if (!$user_credential) {
             // Pull the credential with the ominipotent viewer so we can look up
             // the ID and tell if it's restricted or invalid.
             $omnipotent_credential = id(new PassphraseCredentialQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($current_phid))->executeOne();
             if ($omnipotent_credential) {
                 $current_name = pht('%s (Restricted Credential)', $omnipotent_credential->getMonogram());
             } else {
                 $current_name = pht('Invalid Credential ("%s")', $current_phid);
             }
         } else {
             $current_name = pht('%s %s', $user_credential->getMonogram(), $user_credential->getName());
         }
         $options_map = array($current_phid => $current_name) + $options_map;
     }
     $disabled = $this->getDisabled();
     if ($this->allowNull) {
         $options_map = array('' => pht('(No Credentials)')) + $options_map;
     } else {
         if (!$options_map) {
             $options_map[''] = pht('(No Existing Credentials)');
             $disabled = true;
         }
     }
     Javelin::initBehavior('passphrase-credential-control');
     $options = AphrontFormSelectControl::renderSelectTag($this->getValue(), $options_map, array('id' => $this->getControlID(), 'name' => $this->getName(), 'disabled' => $disabled ? 'disabled' : null, 'sigil' => 'passphrase-credential-select'));
     if ($this->credentialType) {
         $button = javelin_tag('a', array('href' => '#', 'class' => 'button grey', 'sigil' => 'passphrase-credential-add', 'mustcapture' => true), pht('Add Credential'));
     } else {
         $button = null;
     }
     return javelin_tag('div', array('sigil' => 'passphrase-credential-control', 'meta' => array('type' => $this->getCredentialType(), 'username' => $this->defaultUsername, 'allowNull' => $this->allowNull)), array($options, $button));
 }
 protected function renderInput()
 {
     if (!$this->getUser()) {
         throw new PhutilInvalidStateException('setUser');
     }
     // represent months like a credit card does
     $months = array('01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
     $current_year = $this->getCurrentYear();
     $years = range($current_year, $current_year + 20);
     $years = array_fuse($years);
     if ($this->getMonthInputValue()) {
         $selected_month = $this->getMonthInputValue();
     } else {
         $selected_month = $this->getCurrentMonth();
     }
     $months_sel = AphrontFormSelectControl::renderSelectTag($selected_month, $months, array('sigil' => 'month-input'));
     $years_sel = AphrontFormSelectControl::renderSelectTag($this->getYearInputValue(), $years, array('sigil' => 'year-input'));
     return hsprintf('%s%s', $months_sel, $years_sel);
 }
 protected function renderInput()
 {
     if (!$this->getUser()) {
         throw new Exception('You must setUser() before render()!');
     }
     // represent months like a credit card does
     $months = array('01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
     $current_year = $this->getCurrentYear();
     $years = range($current_year, $current_year + 20);
     $years = array_combine($years, $years);
     if ($this->getMonthInputValue()) {
         $selected_month = $this->getMonthInputValue();
     } else {
         $selected_month = $this->getCurrentMonth();
     }
     $months_sel = AphrontFormSelectControl::renderSelectTag($selected_month, $months, array('sigil' => 'month-input'));
     $years_sel = AphrontFormSelectControl::renderSelectTag($this->getYearInputValue(), $years, array('sigil' => 'year-input'));
     return self::renderSingleView(array($months_sel, $years_sel));
 }
 protected function renderInput()
 {
     $options_map = array();
     foreach ($this->options as $option) {
         $options_map[$option->getPHID()] = pht('%s %s', 'K' . $option->getID(), $option->getName());
     }
     $disabled = $this->getDisabled();
     if ($this->allowNull) {
         $options_map = array('' => pht('(No Credentials)')) + $options_map;
     } else {
         if (!$options_map) {
             $options_map[''] = pht('(No Existing Credentials)');
             $disabled = true;
         }
     }
     Javelin::initBehavior('passphrase-credential-control');
     $options = AphrontFormSelectControl::renderSelectTag($this->getValue(), $options_map, array('id' => $this->getControlID(), 'name' => $this->getName(), 'disabled' => $disabled ? 'disabled' : null, 'sigil' => 'passphrase-credential-select'));
     if ($this->credentialType) {
         $button = javelin_tag('a', array('href' => '#', 'class' => 'button grey', 'sigil' => 'passphrase-credential-add', 'mustcapture' => true), pht('Add Credential'));
     } else {
         $button = null;
     }
     return javelin_tag('div', array('sigil' => 'passphrase-credential-control', 'meta' => array('type' => $this->getCredentialType(), 'username' => $this->defaultUsername, 'allowNull' => $this->allowNull)), array($options, $button));
 }
 private function buildSpacesControl()
 {
     if ($this->capability != PhabricatorPolicyCapability::CAN_VIEW) {
         return null;
     }
     if (!$this->object instanceof PhabricatorSpacesInterface) {
         return null;
     }
     $viewer = $this->getUser();
     if (!PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
         return null;
     }
     $space_phid = $this->getSpacePHID();
     if ($space_phid === null) {
         $space_phid = $viewer->getDefaultSpacePHID();
     }
     $select = AphrontFormSelectControl::renderSelectTag($space_phid, PhabricatorSpacesNamespaceQuery::getSpaceOptionsForViewer($viewer, $space_phid), array('disabled' => $this->getDisabled(), 'name' => 'spacePHID', 'class' => 'aphront-space-select-control-knob'));
     return $select;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $action_options = array(PhabricatorPolicy::ACTION_ALLOW => pht('Allow'), PhabricatorPolicy::ACTION_DENY => pht('Deny'));
     $rules = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorPolicyRule')->loadObjects();
     $rules = msort($rules, 'getRuleOrder');
     $default_rule = array('action' => head_key($action_options), 'rule' => head_key($rules), 'value' => null);
     if ($this->phid) {
         $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->withPHIDs(array($this->phid))->execute();
         if (!$policies) {
             return new Aphront404Response();
         }
         $policy = head($policies);
     } else {
         $policy = id(new PhabricatorPolicy())->setRules(array($default_rule))->setDefaultAction(PhabricatorPolicy::ACTION_DENY);
     }
     $root_id = celerity_generate_unique_node_id();
     $default_action = $policy->getDefaultAction();
     $rule_data = $policy->getRules();
     $errors = array();
     if ($request->isFormPost()) {
         $data = $request->getStr('rules');
         $data = @json_decode($data, true);
         if (!is_array($data)) {
             throw new Exception('Failed to JSON decode rule data!');
         }
         $rule_data = array();
         foreach ($data as $rule) {
             $action = idx($rule, 'action');
             switch ($action) {
                 case 'allow':
                 case 'deny':
                     break;
                 default:
                     throw new Exception("Invalid action '{$action}'!");
             }
             $rule_class = idx($rule, 'rule');
             if (empty($rules[$rule_class])) {
                 throw new Exception("Invalid rule class '{$rule_class}'!");
             }
             $rule_obj = $rules[$rule_class];
             $value = $rule_obj->getValueForStorage(idx($rule, 'value'));
             $rule_data[] = array('action' => $action, 'rule' => $rule_class, 'value' => $value);
         }
         // Filter out nonsense rules, like a "users" rule without any users
         // actually specified.
         $valid_rules = array();
         foreach ($rule_data as $rule) {
             $rule_class = $rule['rule'];
             if ($rules[$rule_class]->ruleHasEffect($rule['value'])) {
                 $valid_rules[] = $rule;
             }
         }
         if (!$valid_rules) {
             $errors[] = pht('None of these policy rules have any effect.');
         }
         // NOTE: Policies are immutable once created, and we always create a new
         // policy here. If we didn't, we would need to lock this endpoint down,
         // as users could otherwise just go edit the policies of objects with
         // custom policies.
         if (!$errors) {
             $new_policy = new PhabricatorPolicy();
             $new_policy->setRules($valid_rules);
             $new_policy->setDefaultAction($request->getStr('default'));
             $new_policy->save();
             $data = array('phid' => $new_policy->getPHID(), 'info' => array('name' => $new_policy->getName(), 'full' => $new_policy->getName(), 'icon' => $new_policy->getIcon()));
             return id(new AphrontAjaxResponse())->setContent($data);
         }
     }
     // Convert rule values to display format (for example, expanding PHIDs
     // into tokens).
     foreach ($rule_data as $key => $rule) {
         $rule_data[$key]['value'] = $rules[$rule['rule']]->getValueForDisplay($viewer, $rule['value']);
     }
     $default_select = AphrontFormSelectControl::renderSelectTag($default_action, $action_options, array('name' => 'default'));
     if ($errors) {
         $errors = id(new AphrontErrorView())->setErrors($errors);
     }
     $form = id(new PHUIFormLayoutView())->appendChild($errors)->appendChild(javelin_tag('input', array('type' => 'hidden', 'name' => 'rules', 'sigil' => 'rules')))->appendChild(id(new AphrontFormInsetView())->setTitle(pht('Rules'))->setRightButton(javelin_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'create-rule', 'mustcapture' => true), pht('New Rule')))->setDescription(pht('These rules are processed in order.'))->setContent(javelin_tag('table', array('sigil' => 'rules', 'class' => 'policy-rules-table'), '')))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('If No Rules Match'))->setValue(pht('%s all other users.', $default_select)));
     $form = phutil_tag('div', array('id' => $root_id), $form);
     $rule_options = mpull($rules, 'getRuleDescription');
     $type_map = mpull($rules, 'getValueControlType');
     $templates = mpull($rules, 'getValueControlTemplate');
     require_celerity_resource('policy-edit-css');
     Javelin::initBehavior('policy-rule-editor', array('rootID' => $root_id, 'actions' => $action_options, 'rules' => $rule_options, 'types' => $type_map, 'templates' => $templates, 'data' => $rule_data, 'defaultRule' => $default_rule));
     $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FULL)->setUser($viewer)->setTitle(pht('Edit Policy'))->appendChild($form)->addSubmitButton(pht('Save Policy'))->addCancelButton('#');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 protected function getBody()
 {
     $console = $this->getConsole();
     $tabs = array();
     foreach ($this->tabs as $name => $tab) {
         $tab_markup = phutil_render_tag('a', array('href' => idx($tab, 'href')), phutil_escape_html(idx($tab, 'name')));
         $tab_markup = phutil_render_tag('td', array('class' => $name == $this->selectedTab ? 'phabricator-selected-tab' : null), $tab_markup);
         $tabs[] = $tab_markup;
     }
     $tabs = implode('', $tabs);
     $login_stuff = null;
     $request = $this->getRequest();
     $user = null;
     if ($request) {
         $user = $request->getUser();
         // NOTE: user may not be set here if we caught an exception early
         // in the execution workflow.
         if ($user && $user->getPHID()) {
             $login_stuff = phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUsername())) . ' &middot; ' . '<a href="/settings/">Settings</a>' . ' &middot; ' . phabricator_render_form($user, array('action' => '/search/', 'method' => 'post', 'style' => 'display: inline'), '<input type="text" name="query" id="standard-search-box" />' . ' in ' . AphrontFormSelectControl::renderSelectTag($this->getSearchDefaultScope(), PhabricatorSearchScope::getScopeOptions(), array('name' => 'scope')) . ' ' . '<button>Search</button>');
         }
     }
     $foot_links = array();
     $version = PhabricatorEnv::getEnvConfig('phabricator.version');
     $foot_links[] = phutil_escape_html('Phabricator ' . $version);
     $foot_links[] = '<a href="https://secure.phabricator.com/maniphest/task/create/">' . 'Report a Bug' . '</a>';
     if (PhabricatorEnv::getEnvConfig('darkconsole.enabled') && !PhabricatorEnv::getEnvConfig('darkconsole.always-on')) {
         if ($console) {
             $link = javelin_render_tag('a', array('href' => '/~/', 'sigil' => 'workflow'), 'Disable DarkConsole');
         } else {
             $link = javelin_render_tag('a', array('href' => '/~/', 'sigil' => 'workflow'), 'Enable DarkConsole');
         }
         $foot_links[] = $link;
     }
     if ($user && $user->getPHID()) {
         // This ends up very early in tab order at the top of the page and there's
         // a bunch of junk up there anyway, just shove it down here.
         $foot_links[] = phabricator_render_form($user, array('action' => '/logout/', 'method' => 'post', 'style' => 'display: inline'), '<button class="link">Logout</button>');
     }
     $foot_links = implode(' &middot; ', $foot_links);
     $admin_class = null;
     if ($this->getIsAdminInterface()) {
         $admin_class = 'phabricator-admin-page-view';
     }
     $custom_logo = null;
     $with_custom = null;
     $custom_conf = PhabricatorEnv::getEnvConfig('phabricator.custom.logo');
     if ($custom_conf) {
         $with_custom = 'phabricator-logo-with-custom';
         $custom_logo = phutil_render_tag('a', array('class' => 'logo-custom', 'href' => $custom_conf), ' ');
     }
     $notification_indicator = '';
     $notification_dropdown = '';
     $notification_container = '';
     if (PhabricatorEnv::getEnvConfig('notification.enabled') && $user && $user->isLoggedIn()) {
         $aphlict_object_id = 'aphlictswfobject';
         $client_uri = PhabricatorEnv::getEnvConfig('notification.client-uri');
         $client_uri = new PhutilURI($client_uri);
         if ($client_uri->getDomain() == 'localhost') {
             $this_host = $this->getRequest()->getHost();
             $this_host = new PhutilURI('http://' . $this_host . '/');
             $client_uri->setDomain($this_host->getDomain());
         }
         $enable_debug = PhabricatorEnv::getEnvConfig('notification.debug');
         Javelin::initBehavior('aphlict-listen', array('id' => $aphlict_object_id, 'server' => $client_uri->getDomain(), 'port' => $client_uri->getPort(), 'debug' => $enable_debug, 'pageObjects' => array_fill_keys($this->pageObjects, true)));
         Javelin::initBehavior('aphlict-dropdown', array());
         $notification_count = id(new PhabricatorFeedStoryNotification())->countUnread($user);
         $indicator_classes = array('phabricator-notification-indicator');
         if ($notification_count) {
             $indicator_classes[] = 'phabricator-notification-indicator-unread';
         }
         $notification_indicator = javelin_render_tag('div', array('id' => 'phabricator-notification-indicator', 'class' => implode(' ', $indicator_classes)), $notification_count);
         $notification_indicator = javelin_render_tag('div', array('id' => 'phabricator-notification-menu', 'class' => 'phabricator-icon-menu icon-menu-notifications', 'sigil' => 'aphlict-indicator'), $notification_indicator);
         $notification_indicator = javelin_render_tag('td', array('class' => 'phabricator-icon-menu-cell'), $notification_indicator);
         $notification_container = '<div id="aphlictswf-container" style="height:0px; width:0px;">' . '</div>';
         $notification_dropdown = javelin_render_tag('div', array('sigil' => 'aphlict-dropdown', 'id' => 'phabricator-notification-dropdown', 'style' => 'display: none'), '');
     }
     $header_chrome = null;
     $footer_chrome = null;
     if ($this->getShowChrome()) {
         $header_chrome = '<table class="phabricator-standard-header">' . '<tr>' . '<td class="phabricator-logo ' . $with_custom . '">' . $custom_logo . '<a class="logo-standard" href="/"> </a>' . '</td>' . $notification_indicator . '<td>' . '<table class="phabricator-primary-navigation">' . '<tr>' . '<th>' . phutil_render_tag('a', array('href' => $this->getBaseURI(), 'class' => 'phabricator-head-appname'), phutil_escape_html($this->getApplicationName())) . '</th>' . $tabs . '</tr>' . '</table>' . '</td>' . '<td class="phabricator-login-details">' . $login_stuff . '</td>' . '</tr>' . '</table>' . $notification_dropdown . $notification_container;
         $footer_chrome = '<div class="phabricator-page-foot">' . $foot_links . '</div>';
     }
     $developer_warning = null;
     if (PhabricatorEnv::getEnvConfig('phabricator.show-error-callout') && DarkConsoleErrorLogPluginAPI::getErrors()) {
         $developer_warning = '<div class="aphront-developer-error-callout">' . 'This page raised PHP errors. Find them in DarkConsole ' . 'or the error log.' . '</div>';
     }
     Javelin::initBehavior('device', array('id' => 'base-page'));
     $agent = idx($_SERVER, 'HTTP_USER_AGENT');
     // Try to guess the device resolution based on UA strings to avoid a flash
     // of incorrectly-styled content.
     $device_guess = 'device-desktop';
     if (preg_match('/iPhone|iPod/', $agent)) {
         $device_guess = 'device-phone';
     } else {
         if (preg_match('/iPad/', $agent)) {
             $device_guess = 'device-tablet';
         }
     }
     $classes = array('phabricator-standard-page', $admin_class, $device_guess);
     $classes = implode(' ', $classes);
     return ($console ? '<darkconsole />' : null) . $developer_warning . phutil_render_tag('div', array('id' => 'base-page', 'class' => $classes), $header_chrome . $this->bodyContent . '<div style="clear: both;"></div>') . $footer_chrome;
 }
 /**
  * Render the selector for "Take these actions (every time | only the first
  * time) this rule matches..." element.
  */
 private function renderRepetitionSelector($rule)
 {
     // Make the selector for choosing how often this rule should be repeated
     $repetition_policy = HeraldRepetitionPolicyConfig::toString($rule->getRepetitionPolicy());
     $repetition_options = HeraldRepetitionPolicyConfig::getMapForContentType($rule->getContentType());
     if (empty($repetition_options)) {
         // default option is 'every time'
         $repetition_selector = idx(HeraldRepetitionPolicyConfig::getMap(), HeraldRepetitionPolicyConfig::EVERY);
         return $repetition_selector;
     } else {
         if (count($repetition_options) == 1) {
             // if there's only 1 option, just pick it for the user
             $repetition_selector = reset($repetition_options);
             return $repetition_selector;
         } else {
             return AphrontFormSelectControl::renderSelectTag($repetition_policy, $repetition_options, array('name' => 'repetition_policy'));
         }
     }
 }
 protected function getBody()
 {
     $console = $this->getConsole();
     $tabs = array();
     foreach ($this->tabs as $name => $tab) {
         $tab_markup = phutil_render_tag('a', array('href' => idx($tab, 'href')), phutil_escape_html(idx($tab, 'name')));
         $tab_markup = phutil_render_tag('td', array('class' => $name == $this->selectedTab ? 'phabricator-selected-tab' : null), $tab_markup);
         $tabs[] = $tab_markup;
     }
     $tabs = implode('', $tabs);
     $login_stuff = null;
     $request = $this->getRequest();
     $user = null;
     if ($request) {
         $user = $request->getUser();
         // NOTE: user may not be set here if we caught an exception early
         // in the execution workflow.
         if ($user && $user->getPHID()) {
             $login_stuff = phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUsername())) . ' &middot; ' . '<a href="/settings/">Settings</a>' . ' &middot; ' . phabricator_render_form($user, array('action' => '/search/', 'method' => 'post', 'style' => 'display: inline'), '<input type="text" name="query" id="standard-search-box" />' . ' in ' . AphrontFormSelectControl::renderSelectTag($this->getSearchDefaultScope(), PhabricatorSearchScope::getScopeOptions(), array('name' => 'scope')) . ' ' . '<button>Search</button>');
         }
     }
     $foot_links = array();
     $version = PhabricatorEnv::getEnvConfig('phabricator.version');
     $foot_links[] = phutil_escape_html('Phabricator ' . $version);
     if (PhabricatorEnv::getEnvConfig('darkconsole.enabled') && !PhabricatorEnv::getEnvConfig('darkconsole.always-on')) {
         if ($console) {
             $link = javelin_render_tag('a', array('href' => '/~/', 'sigil' => 'workflow'), 'Disable DarkConsole');
         } else {
             $link = javelin_render_tag('a', array('href' => '/~/', 'sigil' => 'workflow'), 'Enable DarkConsole');
         }
         $foot_links[] = $link;
     }
     if ($user && $user->getPHID()) {
         // This ends up very early in tab order at the top of the page and there's
         // a bunch of junk up there anyway, just shove it down here.
         $foot_links[] = phabricator_render_form($user, array('action' => '/logout/', 'method' => 'post', 'style' => 'display: inline'), '<button class="link">Logout</button>');
     }
     $foot_links = implode(' &middot; ', $foot_links);
     $admin_class = null;
     if ($this->getIsAdminInterface()) {
         $admin_class = 'phabricator-admin-page-view';
     }
     $custom_logo = null;
     $with_custom = null;
     $custom_conf = PhabricatorEnv::getEnvConfig('phabricator.custom.logo');
     if ($custom_conf) {
         $with_custom = 'phabricator-logo-with-custom';
         $custom_logo = phutil_render_tag('a', array('class' => 'logo-custom', 'href' => $custom_conf), ' ');
     }
     $header_chrome = null;
     $footer_chrome = null;
     if ($this->getShowChrome()) {
         $header_chrome = '<table class="phabricator-standard-header">' . '<tr>' . '<td class="phabricator-logo ' . $with_custom . '">' . $custom_logo . '<a class="logo-standard" href="/"> </a>' . '</td>' . '<td>' . '<table class="phabricator-primary-navigation">' . '<tr>' . '<th>' . phutil_render_tag('a', array('href' => $this->getBaseURI(), 'class' => 'phabricator-head-appname'), phutil_escape_html($this->getApplicationName())) . '</th>' . $tabs . '</tr>' . '</table>' . '</td>' . '<td class="phabricator-login-details">' . $login_stuff . '</td>' . '</tr>' . '</table>';
         $footer_chrome = '<div class="phabricator-page-foot">' . $foot_links . '</div>';
     }
     $developer_warning = null;
     if (PhabricatorEnv::getEnvConfig('phabricator.show-error-callout') && DarkConsoleErrorLogPluginAPI::getErrors()) {
         $developer_warning = '<div class="aphront-developer-error-callout">' . 'This page raised PHP errors. Find them in DarkConsole ' . 'or the error log.' . '</div>';
     }
     return ($console ? '<darkconsole />' : null) . $developer_warning . '<div class="phabricator-standard-page ' . $admin_class . '">' . $header_chrome . $this->bodyContent . '<div style="clear: both;"></div>' . '</div>' . $footer_chrome;
 }
 protected function renderInput()
 {
     if (!$this->object) {
         throw new Exception(pht('Call setPolicyObject() before rendering!'));
     }
     if (!$this->capability) {
         throw new Exception(pht('Call setCapability() before rendering!'));
     }
     $policy = $this->object->getPolicy($this->capability);
     if (!$policy) {
         // TODO: Make this configurable.
         $policy = PhabricatorPolicies::POLICY_USER;
     }
     if (!$this->getValue()) {
         $this->setValue($policy);
     }
     $control_id = celerity_generate_unique_node_id();
     $input_id = celerity_generate_unique_node_id();
     $caret = phutil_tag('span', array('class' => 'caret'));
     $input = phutil_tag('input', array('type' => 'hidden', 'id' => $input_id, 'name' => $this->getName(), 'value' => $this->getValue()));
     $options = $this->getOptions();
     $order = array();
     $labels = array();
     foreach ($options as $key => $values) {
         $order[$key] = array_keys($values);
         $labels[$key] = PhabricatorPolicyType::getPolicyTypeName($key);
     }
     $flat_options = array_mergev($options);
     $icons = array();
     foreach (igroup($flat_options, 'icon') as $icon => $ignored) {
         $icons[$icon] = id(new PHUIIconView())->setIconFont($icon);
     }
     Javelin::initBehavior('policy-control', array('controlID' => $control_id, 'inputID' => $input_id, 'options' => $flat_options, 'groups' => array_keys($options), 'order' => $order, 'icons' => $icons, 'labels' => $labels, 'value' => $this->getValue(), 'customPlaceholder' => $this->getCustomPolicyPlaceholder()));
     $selected = idx($flat_options, $this->getValue(), array());
     $selected_icon = idx($selected, 'icon');
     $selected_name = idx($selected, 'name');
     return phutil_tag('div', array(), array(javelin_tag('a', array('class' => 'grey button dropdown has-icon policy-control', 'href' => '#', 'mustcapture' => true, 'sigil' => 'policy-control', 'id' => $control_id), array($caret, javelin_tag('span', array('sigil' => 'policy-label', 'class' => 'phui-button-text'), array(idx($icons, $selected_icon), $selected_name)))), $input));
     return AphrontFormSelectControl::renderSelectTag($this->getValue(), $this->getOptions(), array('name' => $this->getName(), 'disabled' => $this->getDisabled() ? 'disabled' : null, 'id' => $this->getID()));
 }
 protected function getBody()
 {
     $console = $this->getConsole();
     $login_stuff = null;
     $request = $this->getRequest();
     $user = null;
     if ($request) {
         $user = $request->getUser();
         // NOTE: user may not be set here if we caught an exception early
         // in the execution workflow.
         if ($user && $user->getPHID()) {
             $login_stuff = phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUsername())) . ' &middot; ' . '<a href="/settings/">Settings</a>' . ' &middot; ' . phabricator_render_form($user, array('action' => '/search/', 'method' => 'post', 'style' => 'display: inline'), '<div class="menu-section menu-section-search">' . '<div class="menu-search-container">' . '<input type="text" name="query" id="standard-search-box" />' . '<button id="standard-search-button">Search</button>' . '</div>' . '</div>' . ' in ' . AphrontFormSelectControl::renderSelectTag($this->getSearchDefaultScope(), PhabricatorSearchScope::getScopeOptions(), array('name' => 'scope')) . ' ' . '<button>Search</button>');
         }
     }
     $admin_class = null;
     if ($this->getIsAdminInterface()) {
         $admin_class = 'phabricator-admin-page-view';
     }
     $header_chrome = null;
     $footer_chrome = null;
     if ($this->getShowChrome()) {
         $header_chrome = $this->menuContent;
         if (!$this->deviceReady) {
             $footer_chrome = $this->renderFooter();
         }
     }
     $developer_warning = null;
     if (PhabricatorEnv::getEnvConfig('phabricator.show-error-callout') && DarkConsoleErrorLogPluginAPI::getErrors()) {
         $developer_warning = '<div class="aphront-developer-error-callout">' . 'This page raised PHP errors. Find them in DarkConsole ' . 'or the error log.' . '</div>';
     }
     $agent = idx($_SERVER, 'HTTP_USER_AGENT');
     // Try to guess the device resolution based on UA strings to avoid a flash
     // of incorrectly-styled content.
     $device_guess = 'device-desktop';
     if (preg_match('/iPhone|iPod/', $agent)) {
         $device_guess = 'device-phone';
     } else {
         if (preg_match('/iPad/', $agent)) {
             $device_guess = 'device-tablet';
         }
     }
     $classes = array('phabricator-standard-page', $admin_class, $device_guess);
     $classes = implode(' ', $classes);
     return phutil_render_tag('div', array('id' => 'base-page', 'class' => $classes), $header_chrome . '<div class="phabricator-main-menu-spacer"></div>' . '<div class="phabricator-standard-page-body">' . ($console ? '<darkconsole />' : null) . $developer_warning . $this->bodyContent . '<div style="clear: both;"></div>' . '</div>') . $footer_chrome;
 }
 protected function renderInput()
 {
     return AphrontFormSelectControl::renderSelectTag($this->getValue(), $this->getOptions(), array('name' => $this->getName(), 'disabled' => $this->getDisabled() ? 'disabled' : null, 'id' => $this->getID()));
 }
 protected function renderInput()
 {
     $min_year = $this->getMinYear();
     $max_year = $this->getMaxYear();
     $days = range(1, 31);
     $days = array_combine($days, $days);
     $months = array(1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr', 5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec');
     $years = range($this->getMinYear(), $this->getMaxYear());
     $years = array_combine($years, $years);
     $days_sel = AphrontFormSelectControl::renderSelectTag($this->getDayInputValue(), $days, array('name' => $this->getDayInputName(), 'sigil' => 'day-input'));
     $months_sel = AphrontFormSelectControl::renderSelectTag($this->getMonthInputValue(), $months, array('name' => $this->getMonthInputName(), 'sigil' => 'month-input'));
     $years_sel = AphrontFormSelectControl::renderSelectTag($this->getYearInputValue(), $years, array('name' => $this->getYearInputName(), 'sigil' => 'year-input'));
     $cal_icon = javelin_render_tag('a', array('href' => '#', 'class' => 'calendar-button', 'sigil' => 'calendar-button'), '');
     $id = celerity_generate_unique_node_id();
     Javelin::initBehavior('fancy-datepicker', array('root' => $id));
     return javelin_render_tag('div', array('id' => $id, 'class' => 'aphront-form-date-container'), self::renderSingleView(array($days_sel, $months_sel, $years_sel, $cal_icon)));
 }
 private function buildMailTagControl($control_label, array $tags, array $prefs)
 {
     $value_email = PhabricatorEmailTagsSetting::VALUE_EMAIL;
     $value_notify = PhabricatorEmailTagsSetting::VALUE_NOTIFY;
     $value_ignore = PhabricatorEmailTagsSetting::VALUE_IGNORE;
     $content = array();
     foreach ($tags as $key => $label) {
         $select = AphrontFormSelectControl::renderSelectTag((int) idx($prefs, $key, $value_email), array($value_email => pht("⚫ Email"), $value_notify => pht("◐ Notify"), $value_ignore => pht("⚪ Ignore")), array('name' => 'mailtags[' . $key . ']'));
         $content[] = phutil_tag('div', array('class' => 'psb'), array($select, ' ', $label));
     }
     $control = new AphrontFormStaticControl();
     $control->setLabel($control_label);
     $control->setValue($content);
     return $control;
 }
 public function renderControl()
 {
     $control = null;
     $type = $this->getFieldType();
     switch ($type) {
         case self::TYPE_INT:
             $control = new AphrontFormTextControl();
             break;
         case self::TYPE_STRING:
             $control = new AphrontFormTextControl();
             break;
         case self::TYPE_SELECT:
             $control = new AphrontFormSelectControl();
             $control->setOptions($this->getSelectOptions());
             break;
         case self::TYPE_BOOL:
             $control = new AphrontFormCheckboxControl();
             break;
         default:
             $label = $this->getLabel();
             throw new ManiphestAuxiliaryFieldTypeException("Field type '{$type}' is not a valid type (for field '{$label}').");
             break;
     }
     if ($type == self::TYPE_BOOL) {
         $control->addCheckbox('auxiliary[' . $this->getAuxiliaryKey() . ']', 1, $this->getCheckboxLabel(), (bool) $this->getValue());
     } else {
         $control->setValue($this->getValue());
         $control->setName('auxiliary[' . $this->getAuxiliaryKey() . ']');
     }
     $control->setLabel($this->getLabel());
     $control->setCaption($this->getCaption());
     $control->setError($this->getError());
     return $control;
 }
 protected function renderInput()
 {
     $disabled = null;
     if ($this->getValue() === null) {
         $this->setValue($this->getInitialValue());
         if ($this->allowNull) {
             $disabled = 'disabled';
         }
     }
     $min_year = $this->getMinYear();
     $max_year = $this->getMaxYear();
     $days = range(1, 31);
     $days = array_fuse($days);
     $months = array(1 => pht('Jan'), 2 => pht('Feb'), 3 => pht('Mar'), 4 => pht('Apr'), 5 => pht('May'), 6 => pht('Jun'), 7 => pht('Jul'), 8 => pht('Aug'), 9 => pht('Sep'), 10 => pht('Oct'), 11 => pht('Nov'), 12 => pht('Dec'));
     $checkbox = null;
     if ($this->allowNull) {
         $checkbox = javelin_tag('input', array('type' => 'checkbox', 'name' => $this->getCheckboxInputName(), 'sigil' => 'calendar-enable', 'class' => 'aphront-form-date-enabled-input', 'value' => 1, 'checked' => $disabled === null ? 'checked' : null));
     }
     $years = range($this->getMinYear(), $this->getMaxYear());
     $years = array_fuse($years);
     $days_sel = AphrontFormSelectControl::renderSelectTag($this->getDayInputValue(), $days, array('name' => $this->getDayInputName(), 'sigil' => 'day-input', 'disabled' => $disabled));
     $months_sel = AphrontFormSelectControl::renderSelectTag($this->getMonthInputValue(), $months, array('name' => $this->getMonthInputName(), 'sigil' => 'month-input', 'disabled' => $disabled));
     $years_sel = AphrontFormSelectControl::renderSelectTag($this->getYearInputValue(), $years, array('name' => $this->getYearInputName(), 'sigil' => 'year-input', 'disabled' => $disabled));
     $cicon = id(new PHUIIconView())->setIconFont('fa-calendar');
     $cal_icon = javelin_tag('a', array('href' => '#', 'class' => 'calendar-button', 'sigil' => 'calendar-button'), $cicon);
     $time_sel = javelin_tag('input', array('name' => $this->getTimeInputName(), 'sigil' => 'time-input', 'value' => $this->getTimeInputValue(), 'type' => 'text', 'class' => 'aphront-form-date-time-input', 'disabled' => $disabled), '');
     Javelin::initBehavior('fancy-datepicker', array());
     return javelin_tag('div', array('class' => 'aphront-form-date-container', 'sigil' => 'phabricator-date-control', 'meta' => array('disabled' => (bool) $disabled)), array($checkbox, $days_sel, $months_sel, $years_sel, $cal_icon, $time_sel));
 }
 /**
  * Render the selector for "Take these actions (every time | only the first
  * time) this rule matches..." element.
  */
 private function renderRepetitionSelector($rule, HeraldAdapter $adapter)
 {
     $repetition_policy = HeraldRepetitionPolicyConfig::toString($rule->getRepetitionPolicy());
     $repetition_options = $adapter->getRepetitionOptions();
     $repetition_names = HeraldRepetitionPolicyConfig::getMap();
     $repetition_map = array_select_keys($repetition_names, $repetition_options);
     if (count($repetition_map) < 2) {
         return head($repetition_names);
     } else {
         return AphrontFormSelectControl::renderSelectTag($repetition_policy, $repetition_map, array('name' => 'repetition_policy'));
     }
 }
 private function renderViewSelectPanel($selected)
 {
     $request = $this->getRequest();
     $select = AphrontFormSelectControl::renderSelectTag($selected, array('highlighted' => 'View as Highlighted Text', 'blame' => 'View as Highlighted Text with Blame', 'plain' => 'View as Plain Text', 'plainblame' => 'View as Plain Text with Blame', 'raw' => 'View as raw document'), array('name' => 'view'));
     $view_select_panel = new AphrontPanelView();
     $view_select_form = phabricator_render_form($request->getUser(), array('action' => $request->getRequestURI()->alter('view', null), 'method' => 'post', 'class' => 'diffusion-browse-type-form'), $select . ' <button>View</button> ' . $this->renderEditButton());
     $view_select_panel->appendChild($view_select_form);
     $view_select_panel->appendChild('<div style="clear: both;"></div>');
     return $view_select_panel;
 }