/**
  * Get the list of parameters for this form.
  * @return array List of parameters that this form requires.
  * @todo: Implement this method
  */
 public static function get_parameters()
 {
     $parentVal = array_merge(parent::get_parameters(), array(array('name' => 'main_type_term_1', 'caption' => 'Location type term 1', 'description' => 'Select the term used for the first main site location type.', 'type' => 'select', 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'term', 'extraParams' => array('termlist_external_key' => 'indicia:location_types'), 'required' => true, 'group' => 'Transects Editor Settings'), array('name' => 'can_change_section_number_1', 'caption' => 'Change section number 1', 'description' => 'Select if sites of type 1 can change the number of sections.', 'type' => 'boolean', 'required' => false, 'default' => true, 'group' => 'Transects Editor Settings'), array('name' => 'section_number_1', 'caption' => 'Section number 1', 'description' => 'If the user can not change the number of sections for site type 1, then enter the fixed number of sections.', 'type' => 'int', 'required' => false, 'group' => 'Transects Editor Settings'), array('name' => 'main_type_term_2', 'caption' => 'Location type term 2', 'description' => 'Select the term used for the second main site location type.', 'type' => 'select', 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'term', 'extraParams' => array('termlist_external_key' => 'indicia:location_types'), 'required' => false, 'group' => 'Transects Editor Settings'), array('name' => 'can_change_section_number_2', 'caption' => 'Change section number 2', 'description' => 'Select if sites of type 2 can change the number of sections.', 'type' => 'boolean', 'required' => false, 'group' => 'Transects Editor Settings'), array('name' => 'section_number_2', 'caption' => 'Section number 2', 'description' => 'If the user can not change the number of sections for site type 2, then enter the fixed number of sections.', 'type' => 'int', 'required' => false, 'group' => 'Transects Editor Settings'), array('name' => 'main_type_term_3', 'caption' => 'Location type term 3', 'description' => 'Select the term used for the third main site location type.', 'type' => 'select', 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'term', 'extraParams' => array('termlist_external_key' => 'indicia:location_types'), 'required' => false, 'group' => 'Transects Editor Settings'), array('name' => 'can_change_section_number_3', 'caption' => 'Change section number 3', 'description' => 'Select if sites of type 3 can change the number of sections.', 'type' => 'boolean', 'required' => false, 'default' => true, 'group' => 'Transects Editor Settings'), array('name' => 'section_number_3', 'caption' => 'Section number 3', 'description' => 'If the user can not change the number of sections for site type 3, then enter the fixed number of sections.', 'type' => 'int', 'required' => false, 'group' => 'Transects Editor Settings')));
     $retVal = array();
     foreach ($parentVal as $param) {
         switch ($param['name']) {
             case 'transect_type_term':
                 break;
             case 'survey_id':
                 $param['description'] = 'The survey that data will be used to define custom attributes. This needs to match the survey used to submit visit data for sites of the first location type.';
                 $param['group'] = 'Transects Editor Settings';
                 $retVal[] = $param;
                 break;
             default:
                 $retVal[] = $param;
                 break;
         }
     }
     return $retVal;
 }
 protected static function get_branch_assignment_control($readAuth, $branchCmsUserAttr, $args, $settings)
 {
     if (!$branchCmsUserAttr) {
         return '<span style="display:none;">No branch location attribute</span>';
     }
     // no attribute so don't display
     if (self::$cmsUserList == null) {
         $query = db_query("select uid, name from {users} where name <> '' order by name");
         $users = array();
         // there have been DB API changes for Drupal7: db_query now returns the result array.
         if (version_compare(VERSION, '7', '<')) {
             while ($user = db_fetch_object($query)) {
                 $users[$user->uid] = $user->name;
             }
         } else {
             foreach ($query as $user) {
                 $users[$user->uid] = $user->name;
             }
         }
         self::$cmsUserList = $users;
     } else {
         $users = self::$cmsUserList;
     }
     // next reduce the list to branch users
     if ($settings['canAllocBranch']) {
         // only check the users permissions if can change value - for performance reasons.
         $new_users = array();
         foreach ($users as $uid => $name) {
             $account = user_load($uid);
             if (user_access($args['branch_assignment_permission'], $account)) {
                 $new_users[$uid] = $name;
             }
         }
         $users = $new_users;
     }
     $r = '<fieldset id="alloc-branch"><legend>' . lang::get('Site Branch Allocation') . '</legend>';
     if ($settings['canAllocBranch']) {
         $r .= data_entry_helper::select(array('label' => lang::get('Select Branch Manager'), 'fieldname' => 'branchCmsUserId', 'lookupValues' => $users, 'afterControl' => '<button id="add-branch-coord" type="button">' . lang::get('Add') . '</button>'));
         // tell the javascript which attr to save the user ID into
         data_entry_helper::$javascript .= "indiciaData.locBranchCmsUsrAttr = " . self::$branchCmsUserAttrId . ";\n";
     }
     $r .= '<table id="branch-coord-list" style="width: auto">';
     $rows = '';
     // cmsUserAttr needs to be multivalue
     if (isset($branchCmsUserAttr['default']) && !empty($branchCmsUserAttr['default'])) {
         foreach ($branchCmsUserAttr['default'] as $value) {
             if ($settings['canAllocBranch']) {
                 $rows .= '<tr><td id="branch-coord-' . $value['default'] . '"><input type="hidden" name="' . $value['fieldname'] . '" ' . 'value="' . $value['default'] . '"/>' . $users[$value['default']] . '</td><td><div class="ui-state-default ui-corner-all"><span class="remove-user ui-icon ui-icon-circle-close"></span></div></td></tr>';
             } else {
                 $rows .= '<tr><td>' . $users[$value['default']] . '</td><td></td></tr>';
             }
         }
     }
     if (empty($rows)) {
         $rows = '<tr><td colspan="2"></td></tr>';
     }
     $r .= "{$rows}</table>\n";
     $r .= '</fieldset>';
     return $r;
 }
 /**
  * Return the generated form output.
  * @param array $args List of parameter values passed through to the form depending on how the form has been configured.
  * This array always contains a value for language.
  * @param object $node The Drupal node object.
  * @param array $response When this form is reloading after saving a submission, contains the response from the service call.
  * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data).
  * @return Form HTML.
  * @todo: Implement this method 
  */
 public static function get_form($args, $node, $response = null)
 {
     require_once drupal_get_path('module', 'iform') . '/client_helpers/map_helper.php';
     if (function_exists('url')) {
         $args['section_edit_path'] = url($args['section_edit_path']);
     }
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     $settings = array('locationTypes' => helper_base::get_termlist_terms($auth, 'indicia:location_types', array('Transect', 'Transect Section')), 'locationId' => isset($_GET['id']) ? $_GET['id'] : null);
     data_entry_helper::$javascript .= "indiciaData.sections = {};\n";
     if ($settings['locationId']) {
         data_entry_helper::load_existing_record($auth['read'], 'location', $settings['locationId']);
         $settings['sections'] = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'parent_id' => $settings['locationId'], 'deleted' => 'f'), 'nocache' => true));
         foreach ($settings['sections'] as $section) {
             $code = strtolower($section['code']);
             data_entry_helper::$javascript .= "indiciaData.sections.{$code} = {'geom':'" . $section['boundary_geom'] . "','id':'" . $section['id'] . "'};\n";
         }
     } else {
         $settings['sections'] = array();
     }
     $settings['attributes'] = data_entry_helper::getAttributes(array('id' => $settings['locationId'], 'valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'location_type_id' => $settings['locationTypes'][0]['id'], 'multiValue' => true));
     if (false == ($settings['cmsUserAttr'] = extract_cms_user_attr($settings['attributes']))) {
         return 'This form is designed to be used with the CMS User ID attribute setup for locations in the survey.';
     }
     // keep a copy of the location_attribute_id so we can use it later.
     self::$cmsUserAttrId = $settings['cmsUserAttr']['attributeId'];
     $r = '<form method="post" id="input-form">';
     $r .= $auth['write'];
     $r .= '<div id="controls">';
     $customAttributeTabs = array_merge(array('Site Details' => array('[*]')), get_attribute_tabs($settings['attributes']));
     if (count($customAttributeTabs) > 1) {
         $headerOptions = array('tabs' => array());
         foreach ($customAttributeTabs as $tab => $content) {
             $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab));
             $headerOptions['tabs']['#' . $alias] = lang::get($tab);
         }
         $r .= data_entry_helper::tab_header($headerOptions);
         data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true));
     }
     foreach ($customAttributeTabs as $tab => $content) {
         if ($tab == 'Site Details') {
             $r .= self::get_site_tab($auth, $args, $settings);
         } else {
             $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab));
             $r .= "\n<div id=\"{$alias}\">\n";
             $r .= get_attribute_html($settings['attributes'], $args, array('extraParams' => $auth['read']), $tab);
             $r .= "</div>\n";
         }
     }
     $r .= '</div>';
     // controls
     $r .= '<input type="submit" value="' . lang::get('Save') . '" class="ui-state-default ui-corner-all" />';
     $r .= '</form>';
     data_entry_helper::enable_validation('input-form');
     if (function_exists('drupal_set_breadcrumb')) {
         $breadcrumb = array();
         $breadcrumb[] = l(lang::get('Home'), '<front>');
         $breadcrumb[] = l(lang::get('Sites'), $args['sites_list_path']);
         if ($settings['locationId']) {
             $breadcrumb[] = data_entry_helper::$entity_to_load['location:name'];
         } else {
             $breadcrumb[] = lang::get('New Site');
         }
         drupal_set_breadcrumb($breadcrumb);
     }
     return $r;
 }