library/core/class.form.php
public function CheckBoxGrid($FieldName, $DataSet, $ValueDataSet, $Attributes) {
      // Never display individual inline errors for these CheckBoxes
      $Attributes['InlineErrors'] = FALSE;
      
      $Return = '';
      $CheckedValues = $ValueDataSet;
      if (is_object($ValueDataSet)) $CheckedValues = ConsolidateArrayValuesByKey(
         $ValueDataSet->ResultArray(), $FieldName);

      $i = 1;
      if (is_object($DataSet)) {
         $ValueField = ArrayValueI('ValueField', $Attributes, 'value');
         $TextField = ArrayValueI('TextField', $Attributes, 'text');
         $LastGroup = '';
         $Group = array();
         $Rows = array();
         $Cols = array();
         $CheckBox = '';
         foreach($DataSet->Result() as $Data) {
            // Define the checkbox
            $Instance = $Attributes;
            $Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
            $Instance['value'] = $Data->$ValueField;
            $Instance['id'] = $FieldName . $i;
            if (is_array($CheckedValues) && in_array($Data->$ValueField,
               $CheckedValues)) {
               $Instance['checked'] = 'checked';
            }
            $CheckBox = $this->CheckBox($FieldName . '[]', '', $Instance);

            // Organize the checkbox into an array for this group
            $CurrentTextField = $Data->$TextField;
            $aCurrentTextField = explode('.', $CurrentTextField);
            $aCurrentTextFieldCount = count($aCurrentTextField);
            $GroupName = array_shift($aCurrentTextField);
            $ColName = array_pop($aCurrentTextField);
            if ($aCurrentTextFieldCount >= 3) {
               $RowName = implode('.', $aCurrentTextField);
               if ($GroupName != $LastGroup && $LastGroup != '') {
                  // Render the last group
                  $Return .= $this->GetCheckBoxGridGroup(
                     $LastGroup,
                     $Group,
                     $Rows,
                     $Cols);

                  // Clean out the $Group array & Rowcount
                  $Group = array();
                  $Rows = array();
                  $Cols = array();
               }

               if (array_key_exists($ColName, $Group) === FALSE || is_array($Group[$ColName]) === FALSE) {
                  $Group[$ColName] = array();
                  if (!in_array($ColName, $Cols))
                     $Cols[] = $ColName;
                     
               }

               if (!in_array($RowName, $Rows))
                  $Rows[] = $RowName;

               $Group[$ColName][$RowName] = $CheckBox;
               $LastGroup = $GroupName;
            }
            ++$i;
         }
      }
      /*elseif (is_array($DataSet)) {
         foreach ($DataSet as $Text => $ID) {
            $Instance = $Attributes;
            $Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
            $Instance['id'] = $FieldName.$i;
            if (is_numeric($Text))
               $Text = $ID;

            $Instance['value'] = $ID;
            if (in_array($ID, $CheckedValues))
               $Instance['checked'] = 'checked';

            $Return .= $this->CheckBox($FieldName.'[]', $Text, $Instance)."\n";
            $i++;
         }
      }
      */
      return $Return . $this->GetCheckBoxGridGroup($LastGroup, $Group, $Rows, $Cols);
   }
public function CheckBoxGrid($FieldName, $DataSet, $ValueDataSet, $Attributes) {
      // Never display individual inline errors for these CheckBoxes
      $Attributes['InlineErrors'] = FALSE;
      
      $Return = '';
      $CheckedValues = $ValueDataSet;
      if (is_object($ValueDataSet)) $CheckedValues = ConsolidateArrayValuesByKey(
         $ValueDataSet->ResultArray(), $FieldName);

      $i = 1;
      if (is_object($DataSet)) {
         $ValueField = ArrayValueI('ValueField', $Attributes, 'value');
         $TextField = ArrayValueI('TextField', $Attributes, 'text');
         $LastGroup = '';
         $Group = array();
         $Rows = array();
         $Cols = array();
         $CheckBox = '';
         foreach($DataSet->Result() as $Data) {
            // Define the checkbox
            $Instance = $Attributes;
            $Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
            $Instance['value'] = $Data->$ValueField;
            $Instance['id'] = $FieldName . $i;
            if (is_array($CheckedValues) && in_array($Data->$ValueField,
               $CheckedValues)) {
               $Instance['checked'] = 'checked';
            }
            $CheckBox = $this->CheckBox($FieldName . '[]', '', $Instance);

            // Organize the checkbox into an array for this group
            $CurrentTextField = $Data->$TextField;
            $aCurrentTextField = explode('.', $CurrentTextField);
            $aCurrentTextFieldCount = count($aCurrentTextField);
            $GroupName = array_shift($aCurrentTextField);
            $ColName = array_pop($aCurrentTextField);
            if ($aCurrentTextFieldCount >= 3) {
               $RowName = implode('.', $aCurrentTextField);
               if ($GroupName != $LastGroup && $LastGroup != '') {
                  // Render the last group
                  $Return .= $this->GetCheckBoxGridGroup(
                     $LastGroup,
                     $Group,
                     $Rows,
                     $Cols);

                  // Clean out the $Group array & Rowcount
                  $Group = array();
                  $Rows = array();
                  $Cols = array();
               }

               if (array_key_exists($ColName, $Group) === FALSE || is_array($Group[$ColName]) === FALSE) {
                  $Group[$ColName] = array();
                  if (!in_array($ColName, $Cols))
                     $Cols[] = $ColName;
                     
               }

               if (!in_array($RowName, $Rows))
                  $Rows[] = $RowName;

               $Group[$ColName][$RowName] = $CheckBox;
               $LastGroup = $GroupName;
            }
            ++$i;
         }
      }
      /*elseif (is_array($DataSet)) {
         foreach ($DataSet as $Text => $ID) {
            $Instance = $Attributes;
            $Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
            $Instance['id'] = $FieldName.$i;
            if (is_numeric($Text))
               $Text = $ID;

            $Instance['value'] = $ID;
            if (in_array($ID, $CheckedValues))
               $Instance['checked'] = 'checked';

            $Return .= $this->CheckBox($FieldName.'[]', $Text, $Instance)."\n";
            $i++;
         }
      }
      */
      return $Return . $this->GetCheckBoxGridGroup($LastGroup, $Group, $Rows, $Cols);
   }
public function CheckBoxGrid ( $ FieldName , $ DataSet , $ ValueDataSet , $ Attributes ) { // Never display individual inline errors for these CheckBoxes $ Attributes [ 'InlineErrors' ] = FALSE ; $ Return = '' ; $ CheckedValues = $ ValueDataSet ; if ( is_object ( $ ValueDataSet ) ) $ CheckedValues = ConsolidateArrayValuesByKey ( $ ValueDataSet -> ResultArray ( ) , $ FieldName ) ; $ i = 1 ; if ( is_object ( $ DataSet ) ) { $ ValueField = ArrayValueI ( 'ValueField' , $ Attributes , 'value' ) ; $ TextField = ArrayValueI ( 'TextField' , $ Attributes , 'text' ) ; $ LastGroup = '' ; $ Group = array ( ) ; $ Rows = array ( ) ; $ Cols = array ( ) ; $ CheckBox = '' ; foreach ( $ DataSet -> Result ( ) as $ Data ) { // Define the checkbox $ Instance = $ Attributes ; $ Instance = RemoveKeyFromArray ( $ Instance , array ( 'TextField' , 'ValueField' ) ) ; $ Instance [ 'value' ] = $ Data -> $ ValueField ; $ Instance [ 'id' ] = $ FieldName . $ i ; if ( is_array ( $ CheckedValues ) && in_array ( $ Data -> $ ValueField , $ CheckedValues ) ) { $ Instance [ 'checked' ] = 'checked' ; } $ CheckBox = $ this -> CheckBox ( $ FieldName . '[]' , '' , $ Instance ) ; // Organize the checkbox into an array for this group $ CurrentTextField = $ Data -> $ TextField ; $ aCurrentTextField = explode ( '.' , $ CurrentTextField ) ; $ aCurrentTextFieldCount = count ( $ aCurrentTextField ) ; $ GroupName = array_shift ( $ aCurrentTextField ) ; $ ColName = array_pop ( $ aCurrentTextField ) ; if ( $ aCurrentTextFieldCount >= 3 ) { $ RowName = implode ( '.' , $ aCurrentTextField ) ; if ( $ GroupName != $ LastGroup && $ LastGroup != '' ) { // Render the last group $ Return .= $ this -> GetCheckBoxGridGroup ( $ LastGroup , $ Group , $ Rows , $ Cols ) ; // Clean out the $Group array & Rowcount $ Group = array ( ) ; $ Rows = array ( ) ; $ Cols = array ( ) ; } if ( array_key_exists ( $ ColName , $ Group ) === FALSE || is_array ( $ Group [ $ ColName ] ) === FALSE ) { $ Group [ $ ColName ] = array ( ) ; if ( ! in_array ( $ ColName , $ Cols ) ) $ Cols [ ] = $ ColName ; } if ( ! in_array ( $ RowName , $ Rows ) ) $ Rows [ ] = $ RowName ; $ Group [ $ ColName ] [ $ RowName ] = $ CheckBox ; $ LastGroup = $ GroupName ; } ++ $ i ; } } /*elseif (is_array($DataSet)) {
         foreach ($DataSet as $Text => $ID) {
            $Instance = $Attributes;
            $Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
            $Instance['id'] = $FieldName.$i;
            if (is_numeric($Text))
               $Text = $ID;

            $Instance['value'] = $ID;
            if (in_array($ID, $CheckedValues))
               $Instance['checked'] = 'checked';

            $Return .= $this->CheckBox($FieldName.'[]', $Text, $Instance)."\n";
            $i++;
         }
      }
      */ return $ Return . $ this -> GetCheckBoxGridGroup ( $ LastGroup , $ Group , $ Rows , $ Cols ) ; }
Returns the xhtml for a list of checkboxes; sorted into groups related to
the TextField value of the dataset.

@param string $FieldName The name of the field that is being displayed/posted with this input. It
should related directly to a field name in a user junction table.
ie. LUM_UserRole.RoleID

@param mixed $DataSet The data to fill the options in the select list. Either an associative
array or a database dataset. ie. RoleID, Name from LUM_Role.

@param mixed $ValueDataSet The data that should be checked in $DataSet. Either an associative array
or a database dataset. ie. RoleID from LUM_UserRole for a single user.

@param array $Attributes An associative array of attributes for the select. Here is a list of
"special" attributes and their default values:

Attribute   Options                        Default
------------------------------------------------------------------------
ValueField  The name of the field in       'value'
$DataSet that contains the
option values.
TextField   The name of the field in       'text'
$DataSet that contains the
option text.

@return string
Returns the xhtml for a list of checkboxes ; sorted into groups related to the TextField value of the dataset .