require_once IIRS__COMMON_DIR . 'environment.php';
// IIRS_0_debug_print( $debug_environment );
$authenticated = IIRS_0_input('password') == 'fryace4';
$all_registering_servers = IIRS_0_input('all_registering_servers') == 'yes';
if ($authenticated) {
    $all_TIs = IIRS_0_TIs_all();
    usort($all_TIs, 'IIRS_0_sort_date_desc');
    $doc = new DOMDocument();
    // TODO: set default namespace to TN
    // $node_initiatives->add_namespace( 'http://transitionnetwork.org/namespaces/2014/transition' );
    // $node_initiatives->add_namespace( 'http://transitionnetwork.org/namespaces/2014/transition', 'tn' );
    $node_initiatives = $doc->createElementNS(IIRS_TRANSITION_NAMESPACE, 'initiatives');
    $doc->appendChild($node_initiatives);
    foreach ($all_TIs as $TI) {
        if ($all_registering_servers || $TI['registering_server'] == $IIRS_host_domain) {
            $node_initiative = $doc->createElement('initiative');
            $node_initiatives->appendChild($node_initiative);
            $node_initiative->setAttribute('guid', $TI['guid']);
            $node_initiative->setAttribute('native-ID', $TI['native_ID']);
            $node_initiative->setAttribute('registration-date', $TI['registration_date']);
            $node_initiative->appendChild($doc->createElement('name', $TI['name']));
            $node_initiative->appendChild($doc->createElement('registering_server', $TI['registering_server']));
        }
    }
    IIRS_0_print_XML_doc($doc);
} else {
    IIRS_0_print('<error>password required</error>');
}
?>

function IIRS_0_print_language_selector()
{
    global $lang_list, $lang_code, $available_languages;
    if (IIRS_0_setting('language_selector')) {
        $html = '<select id="IIRS_0_language_control">';
        foreach ($available_languages as $code) {
            if (isset($lang_list[$code])) {
                $details = $lang_list[$code];
                $selected = $code == $lang_code ? 'selected' : '';
                $html .= "<option {$selected} value=\"{$code}\">{$details['1']}</option>";
            }
        }
        $html .= '</select>';
        IIRS_0_print($html);
    }
}
        // $valid_dns
        $IIRS_error = new IIRS_Error(IIRS_INVALID_WEBSITE_DNS, 'Your website was not found, please re-enter it or select "No Website"', 'DNS lookup failed', IIRS_MESSAGE_USER_WARNING, IIRS_MESSAGE_NO_USER_ACTION, array('$domain' => $domain));
        IIRS_0_debug_print($IIRS_error);
    }
} else {
    // $domain_entered
    IIRS_0_debug_print("no domain entered, or 'none' entered");
}
?>
</pre></div>

<?php 
if (IIRS_0_setting('image_entry')) {
    ?>
  <script src="https://www.google.com/jsapi?key=<?php 
    IIRS_0_print(IIRS_GOOGLE_API_KEY);
    ?>
" type="text/javascript"></script>

  <script type="text/javascript">
    function IIRS_0_OnLoad() {
      var searchControl     = new google.search.SearchControl();
      var drawOptions       = new google.search.DrawOptions();
      var imageOptions      = new google.search.SearcherOptions();
      var oDOMSearchControl = document.getElementById("IIRS_0_searchcontrol");
      var oDOMSearchForm    = document.getElementById("IIRS_0_searchForm");

      searchControl.setResultSetSize(1);
      imageOptions.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
      searchControl.addSearcher(new google.search.ImageSearch(), imageOptions);
" /> <?php 
    IIRS_0_print_translated_HTML_text('Transition Initiative');
    ?>
<span class="required">*</span></td></tr>
        <tr><td><?php 
    IIRS_0_print_translated_HTML_text('email');
    ?>
</td><td><input id="IIRS_0_email" <?php 
    IIRS_0_print($no_towns_found_disabled);
    ?>
 class="IIRS_0_required" name="email" /><span class="required">*</span></td></tr>
        <tr><td><?php 
    IIRS_0_print_translated_HTML_text('your name');
    ?>
</td><td><input id="IIRS_0_name" <?php 
    IIRS_0_print($no_towns_found_disabled);
    ?>
 class="IIRS_0_required" name="name" /><span class="required">*</span></td></tr>
        <!-- NOTE: are we going to ring them? place this later on in the forms -->
        <!-- tr><td><?php 
    IIRS_0_print_translated_HTML_text(IGNORE_TRANSLATION, 'phone number');
    ?>
<br/>( <?php 
    IIRS_0_print_translated_HTML_text(IGNORE_TRANSLATION, 'optional');
    ?>
 )</td><td><input name="phone" /></td></tr -->
      </table>
      <div id="IIRS_0_details_teaser">
        <?php 
    IIRS_0_print_translated_HTML_text('This email address may be used by people in your area who would like to contact you and / or join your projects.');
    ?>