/** !!
  * Determins the config of the user, 
  * @param key $config_sect used as a key to select config sections
  * @param int $manage_mode determins if the user is a user or super user
  * @return PAForm $form returns the form to be used
  */
 public function getConfigSection($config_sect, $manage_mode)
 {
     global $app, $error_msg;
     if (!isset($this->sections[$config_sect])) {
         $error_msg = __('Section does not exist!');
         return "skip";
     }
     $section = $this->sections[$config_sect];
     $condition = '@readonly=\'false\'';
     if ($manage_mode == 1) {
         // super user mode
         $condition = null;
     }
     list($info, $data) = $app->configObj->getConfigSection($section, $condition);
     //echo "<pre>" . print_r($data,1) . "</pre>";
     $this->section = $section;
     $form = new PAForm("form_data[{$section}]");
     $form->addContentTag('h1', array('value' => $info['description']));
     $form->openTag('div', array('class' => 'field'));
     $form->closeTag('div');
     $form->openTag('fieldset', array('class' => 'center_box'));
     foreach ($data as $name => $item) {
         $this->populate_data($item, $name, $form);
         //echo "<pre>" . print_r($item,1) . "</pre>";
     }
     $form->addInputTag('hidden', array('name' => 'action', 'value' => 'saveConfSection'));
     $form->addInputTag('hidden', array('name' => 'section', 'value' => "{$this->section}"));
     $form->addInputTag('submit', array('name' => 'submit', 'value' => "Save changes"));
     $form->closeTag('fieldset');
     return $form;
 }
 private function GET_step_4($params, $is_post = false)
 {
     global $app;
     if ($this->error) {
         return $this->msg_unable_to_continue($params);
     }
     $show_form = array("network_spawning" => "checked");
     foreach ($this->form_data as $field => $value) {
         $show_form[$field] = $value;
     }
     /*
      * If the setup process hasn't yet been submitted (it is posted after the first time for validation and verification.
      */
     if (!$is_post) {
         $form = new PAForm('pa_inst');
         $form->openTag('fieldset');
         $form->addContentTag('legend', array('value' => __('Admin account details')));
         if ($this->admin_exists == false) {
             $form->addHtml('<div>');
             $form->addHtml('<p class="inst_info">' . __('Please complete the following information to create an admin account. The first and last names default to Admin Peepagg if left blank') . '</p>');
             $form->addInputField('text', __('First Name'), array('id' => 'admin_first', 'required' => false, 'value' => @$show_form["admin_first"]));
             $form->addInputField('text', __('Last Name'), array('id' => 'admin_last', 'required' => false, 'value' => @$show_form["admin_last"]));
             $form->addInputField('text', __('Admin username'), array('id' => 'admin_username', 'required' => true, 'value' => @$show_form["admin_username"]));
             $form->addInputField('password', __('Admin password'), array('class' => 'admin_password', 'id' => 'admin_password', 'required' => true, 'value' => @$show_form["admin_password"]));
             $form->addInputField('text', __('Admin email'), array('id' => 'admin_email', 'required' => true, 'value' => @$show_form["admin_email"]));
             $form->addHtml('</div>');
         } else {
             $form->addHtml("<p style='background-color:#d3edab; clear:both;'>Admin user already exists from a previous install.</p>");
         }
         $form->closeTag('fieldset');
         /*
          * Detect if the PA install is already on a subdomain, and, if so, disable the ability
          *  to create other networks.
          *
          * This is tested by looking for the segment of the hostname (as determined by PHP) before
          *  the first period.
          *
          * Note: This may cause grief to users who wish to omit the www (simply use http://example.com),
          *  but, as PA will default to sandwiching in the www, this behavior is permissible.
          *
          * Double note: Ideally, this will be fixed eventually, as we add support for metanetworking with
          *  subdomains.
          */
         $form->openTag('fieldset');
         $form->addContentTag('legend', array('value' => 'Meta-Networking Configuration'));
         $form->addHtml('<div>');
         if ($this->config['allow_network_spawning']) {
             $domain = explode(".", $_SERVER["SERVER_NAME"]);
             $form->addHtml("<p style='background-color:#d3edab'>Meta-Networking can be enabled on your domain.</p><p>If enabled, users will be able to create their own networks -- sites which share a domain and user accounts with the default network, but have an entirely different collection of groups, organizations, and content than the default network. Meta-networking allows your users to securely and completely control their own content.</p>");
             $form->addInputField('checkbox', __('Enable Multiple Networks'), array('id' => 'network_spawning', 'required' => true, 'value' => $is_post ? $this->form_data['network_spawning'] : $show_form["network_spawning"]));
             $form->addHtml("<br><br>");
             $form->addInputField('text', __('Autodetected domain_prefix as <b>' . $domain[0] . '</b> (<a href="javascript:void(document.getElementById(\'domain_prefix\').style.display = \'block\');">change</a>)'), array('style' => 'display:none', 'id' => 'domain_prefix', 'required' => false, 'value' => $is_post ? $this->form_data['domain_prefix'] : $domain[0]));
         } else {
             $domain = explode(".", $_SERVER["SERVER_NAME"]);
             $form->addHtml('<p class="inst_info">' . __('The domain_prefix is the first part of the domain you can control. For example, if your site should be accessible at www.example.com, fill in "www". For people.example.com, fill in "people". <b>Note:</b> Simply leaving this blank is not supported. You <b>must</b> have this part of the domain.') . '</p>');
             $form->addInputField('text', __('Autodetected domain_prefix as <b>' . $domain[0] . '</b> (<a href="javascript:void(document.getElementById(\'domain_prefix\').style.display = \'block\');">change</a>)'), array('style' => 'display:none', 'id' => 'domain_prefix', 'required' => false, 'value' => $is_post ? $this->form_data['domain_prefix'] : $domain[0]));
             $form->addHtml("<p style='clear:both; height:1px; '>&nbsp;</p>");
             $form->addHtml("<p style='background-color:#edabab; clear:both;'>Oh dear. Network spawning disabled.</p>\n                      <p>Network spawning has been automatically disabled. This means that PeopleAggregator will create a default network for users to exist within, but users will not be able to create their own networks to contain their own groups. If you wish to enable this functionality (on example.org, for instance), we recommend reading the following:\n                      <ul>\n                        <li>Ensure your PA install is not running on a subdomain. For example, creating subnetworks on a base install of people.example.com is not currently supported.</li>\n                        <li>If you are running your PA install from the root of your domain, ensure you are installing from the URL <code>http://<b>www.</b>example.com</li>\n                      </ul>\n                  ");
         }
         $form->addHtml('</div>');
         $form->closeTag('fieldset');
         $form->openTag('fieldset');
         $form->openTag('fieldset');
         $form->addContentTag('legend', array('value' => 'Site Settings'));
         $form->addHtml("<p class='inst_info'>Specify a password pepper. Bcrypt is used to encrypt the password.</p>");
         $form->addInputField('text', __('Password Pepper'), array('id' => 'pw_pepper', 'required' => true));
         $form->closeTag('fieldset');
         $form->addContentTag('legend', array('value' => 'Service Hooks'));
         $form->addHtml("<p class='inst_info'>Add API keys to your PeopleAggregator install so that users can invite Facebook contacts into your service.</p>");
         $form->addInputField('text', __('Facebook API Key'), array('id' => 'fb_key', 'required' => false));
         $form->addInputField('text', __('Facebook API Secret'), array('id' => 'fb_secret', 'required' => false));
         $form->addHtml("<p class='inst_info' style='clear:both'>Amazon S3 settings</p>");
         $form->addInputField('text', __('Amazon AWS API Key'), array('id' => 'amazon_key', 'required' => false));
         $form->addInputField('text', __('Amazon AWS API Secret'), array('id' => 'amazon_secret', 'required' => false));
         $form->addInputField('text', __('Amazon S3 Bucket Name'), array('id' => 'amazon_bucket', 'required' => false));
         $form->addHtml("<p class='inst_info' style='clear:both'>Hoptoad settings</p>");
         $form->addInputField('text', __('Hoptoad API Key'), array('id' => 'hoptoad_key', 'required' => false));
         $form->addInputField('text', __('Hoptoad Environment'), array('id' => 'hoptoad_env', 'required' => false));
         $form->addHtml("<p class='inst_info' style='clear:both'>Civic Commons Settings</p>");
         $form->addInputField('text', __('Civic Commons Ruby Application URL'), array('id' => 'cc_application_url', 'required' => false));
         $html = $form->getHtml();
     } else {
         //@todo Should we add a printout of the information here? At the moment it just confirms that the data has been entered and moves on.
         $html = "";
     }
     $nav = "<a class='bt back' href='?step=" . ($this->curr_step > 1 ? $this->curr_step - 1 : 1) . "' alt='previous'></a>";
     if (!$is_post) {
         $nav .= "<a class='bt submit' href='#' alt='submit' onclick='document.forms[\"pa_inst\"].submit();'></a>";
     } else {
         $nav .= "<a class='bt next' href='?step=" . ($this->curr_step < 5 ? $this->curr_step + 1 : $step) . "' alt='next'></a>";
     }
     $data = array('message' => !empty($params['message']) ? $params['message'] : '', 'title' => $params['title'], 'step' => $this->curr_step, 'navig' => $nav, 'content' => $html);
     return $data;
 }