diff --git a/Dataface/FormTool/checkbox.php b/Dataface/FormTool/checkbox.php
index e3365c0c..58c21e84 100644
--- a/Dataface/FormTool/checkbox.php
+++ b/Dataface/FormTool/checkbox.php
@@ -1,149 +1,143 @@
_table;
- $widget =& $field['widget'];
-
- if ( !@$widget['separator'] ) $widget['separator'] = '
';
- $factory =& Dataface_FormTool::factory();
- if ( (isset( $field['repeat']) and $field['repeat'] and isset($field['vocabulary']) and $field['vocabulary']) or
- (isset($field['transient']) and isset($field['relationship']) )){
- $boxes = array();
- $options = array();
- if ( @$field['vocabulary'] ){
- $options =& Dataface_FormTool::getVocabulary($record, $field);
- $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field);
- } else if ( isset($field['relationship']) ){
- $relationship =& $record->_table->getRelationship($field['relationship']);
- $options = $relationship->getAddableValues($record);
- $options__classes = array();
-
- // Now let's add the ability to add an option that isn't already there
- // but only if the user has permission
- if ( !@$widget['suffix'] ) $widget['suffix'] = '';
- $dtable = & Dataface_Table::loadTable($relationship->getDomainTable());
- if ( !PEAR::isError($dtable) and $record->checkPermission('add new related record', array('relationship'=>$relationship->getName()) )){
- import(XFROOT.'Dataface/JavascriptTool.php');
- $jt = Dataface_JavascriptTool::getInstance();
- $jt->import('xataface/widgets/checkbox.js');
-
- // $suffix = '';
- //$suffix .= '';
- $suffix =
- '_table;
+ $widget = &$field['widget'];
+
+ if (!@$widget['separator']) $widget['separator'] = '
';
+ $factory = &Dataface_FormTool::factory();
+ if ((isset($field['repeat']) and $field['repeat'] and isset($field['vocabulary']) and $field['vocabulary']) or
+ (isset($field['transient']) and isset($field['relationship']))
+ ) {
+ $boxes = array();
+ $options = array();
+ if (@$field['vocabulary']) {
+ $options = &Dataface_FormTool::getVocabulary($record, $field);
+ $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field);
+ } else if (isset($field['relationship'])) {
+ $relationship = &$record->_table->getRelationship($field['relationship']);
+ $options = $relationship->getAddableValues($record);
+ $options__classes = array();
+
+ // Now let's add the ability to add an option that isn't already there
+ // but only if the user has permission
+ if (!@$widget['suffix']) $widget['suffix'] = '';
+ $dtable = &Dataface_Table::loadTable($relationship->getDomainTable());
+ if (!PEAR::isError($dtable) and $record->checkPermission('add new related record', array('relationship' => $relationship->getName()))) {
+ import(XFROOT . 'Dataface/JavascriptTool.php');
+ $jt = Dataface_JavascriptTool::getInstance();
+ $jt->import('xataface/widgets/checkbox.js');
+
+ $suffix =
+ 'Other..';
- $widget['suffix'] = $suffix;
- }
- }
-
-
- if ( $record and $record->val($field['name']) ){
- $vals = $record->val($field['name']);
- if ( is_array($vals) ){
- foreach ( $vals as $thisval){
- if ( !isset($options[$thisval]) ){
- $options[$thisval] = $thisval;
- }
- }
- }
-
- }
- $dummyForm = new HTML_QuickForm();
- foreach ($options as $opt_val=>$opt_text){
- if ( $opt_val === '') continue;
- $boxes[] =& $dummyForm->createElement('checkbox',$opt_val , null, $opt_text, array('class'=>'checkbox-of-'.$field['name'].' '.@$options__classes[$opt_val]));
- //$boxes[count($boxes)-1]->setValue($opt_val);
-
- }
- if (is_array($form->_submitValues)) {
- $submitVal = @$form->_submitValues[$field['name']];
- if (is_string($submitVal) and strlen($submitVal) > 0 and $submitVal[0] == '[') {
- $decoded = json_decode($submitVal, true);
- $newVal = array();
- foreach ($decoded as $v) {
- $newVal[$v] = '1';
- }
- $form->_submitValues[$field['name']] = $newVal;
- }
- }
- $el =& $factory->addGroup($boxes, $field['name'], $widget['label']);
- if ($form->xml) {
- $xmlBody = '';
- foreach ($options as $opt_val=>$opt_text) {
- $xmlBody .= ''.xmlentities($opt_text).'';
- }
- $xmlBody .= '';
- $el->updateAttributes(array('data-xf-xml-body'=> $xmlBody));
- }
- } else {
-
-
-
- $el =& $factory->addElement('advcheckbox', $formFieldName, $widget['label']);
- if ( $field['vocabulary'] ){
- $yes = '';
- $no = '';
- if ( $table->isYesNoValuelist($field['vocabulary'], $yes, $no) ){
- $el->setValues(array($no,$yes));
- }
- }
- }
- return $el;
- }
-
- function &pushValue(&$record, &$field, &$form, &$element, &$metaValues){
- $table =& $record->_table;
- $formTool =& Dataface_FormTool::getInstance();
- $formFieldName = $element->getName();
-
- $val = $element->getValue();
- if ( $field['repeat'] ){
-
- //print_r(array_keys($val));
- // eg value array('value1'=>1, 'value2'=>1, ..., 'valueN'=>1)
- if ( is_array($val) ){
- $out = array_keys($val);
- } else {
- $out = array();
- }
- //$res =& $s->setValue($fieldname, array_keys($val));
- } else {
- if ( preg_match('/int/', @$field['Type']) ){
- $out = intval($val);
- } else {
- $out = $val;
- }
- //$res =& $s->setValue($fieldname, $val);
- }
- if (PEAR::isError($val) ){
- $val->addUserInfo(
- df_translate(
- 'scripts.Dataface.QuickForm.pushValue.ERROR_PUSHING_VALUE',
- "Error pushing value for field '$field[name]' in QuickForm::pushWidget() on line ".__LINE__." of file ".__FILE__,
- array('name'=>$field['name'],'file'=>__FILE__,'line'=>__LINE__)
- )
- );
- return $val;
- }
- return $out;
- }
-
- function pullValue(&$record, &$field, &$form, &$element, $new=false){
-
- /*
+ $widget['suffix'] = $suffix;
+ }
+ }
+
+
+ if ($record and $record->val($field['name'])) {
+ $vals = $record->val($field['name']);
+ if (is_array($vals)) {
+ foreach ($vals as $thisval) {
+ if (!isset($options[$thisval])) {
+ $options[$thisval] = $thisval;
+ }
+ }
+ }
+ }
+ $dummyForm = new HTML_QuickForm();
+ foreach ($options as $opt_val => $opt_text) {
+ if ($opt_val === '') continue;
+ $boxes[] = &$dummyForm->createElement('checkbox', $opt_val, null, $opt_text, array('class' => 'checkbox-of-' . $field['name'] . ' ' . @$options__classes[$opt_val]));
+
+ }
+ if (is_array($form->_submitValues)) {
+ $submitVal = @$form->_submitValues[$field['name']];
+ if (is_string($submitVal) and strlen($submitVal) > 0 and $submitVal[0] == '[') {
+ $decoded = json_decode($submitVal, true);
+ $newVal = array();
+ foreach ($decoded as $v) {
+ $newVal[$v] = '1';
+ }
+ $form->_submitValues[$field['name']] = $newVal;
+ }
+ }
+ $el = &$factory->addGroup($boxes, $field['name'], $widget['label']);
+ if ($form->xml) {
+ $xmlBody = '';
+ foreach ($options as $opt_val => $opt_text) {
+ $xmlBody .= '' . xmlentities($opt_text) . '';
+ }
+ $xmlBody .= '';
+ $el->updateAttributes(array('data-xf-xml-body' => $xmlBody));
+ }
+ } else {
+ $el = &$factory->addElement('advcheckbox', $formFieldName, $widget['label']);
+ if ($field['vocabulary']) {
+ $yes = '';
+ $no = '';
+ if ($table->isYesNoValuelist($field['vocabulary'], $yes, $no)) {
+ $el->setValues(array($no, $yes));
+ }
+ }
+ }
+ return $el;
+ }
+
+ function &pushValue(&$record, &$field, &$form, &$element, &$metaValues)
+ {
+ $table = &$record->_table;
+ $formTool = &Dataface_FormTool::getInstance();
+ $formFieldName = $element->getName();
+
+ $val = $element->getValue();
+ if ($field['repeat']) {
+ if (is_array($val)) {
+ $out = array_keys($val);
+ } else {
+ $out = array();
+ }
+ } else {
+ if (preg_match('/int/', @$field['Type'])) {
+ $out = intval($val);
+ } else {
+ $out = $val;
+ }
+ }
+ if (PEAR::isError($val)) {
+ $val->addUserInfo(
+ df_translate(
+ 'scripts.Dataface.QuickForm.pushValue.ERROR_PUSHING_VALUE',
+ "Error pushing value for field '$field[name]' in QuickForm::pushWidget() on line " . __LINE__ . " of file " . __FILE__,
+ array('name' => $field['name'], 'file' => __FILE__, 'line' => __LINE__)
+ )
+ );
+ return $val;
+ }
+ return $out;
+ }
+
+ function pullValue(&$record, &$field, &$form, &$element, $new = false)
+ {
+
+ /*
*
* Checkbox widgets store values as associative array $a where
* $a[$x] == 1 <=> element named $x is checked.
@@ -153,34 +147,25 @@ function pullValue(&$record, &$field, &$form, &$element, $new=false){
* repeat fields are just normal checkbox widgets.
*
*/
- $formFieldName = $element->getName();
- $raw = $record->getValue($field['name']);
- if (is_string($raw) and strtolower(substr($field['Type'], 0, 3)) == 'set') {
- $raw = explode(',', $raw);
- }
- if ( $field['repeat'] and is_array($raw)){
- // If the field is a repeat field $raw will be an array of
- // values.
- $v = array();
- foreach ($raw as $key=>$value){
- $v[$value] = 1;
- }
- /*
- *
- * In this case we set this checkbox to the array of values that are currently checked.
- *
- */
- $val = $v;
- } else {
- /*
- *
- * If the field is not a repeat, then it is only one value
- *
- */
- $val = $record->getValueAsString($field['name']);
- }
-
-
- return $val;
- }
+ $formFieldName = $element->getName();
+ $raw = $record->getValue($field['name']);
+ if (is_string($raw) and strtolower(substr($field['Type'], 0, 3)) == 'set') {
+ $raw = explode(',', $raw);
+ }
+ if ($field['repeat'] and is_array($raw)) {
+ // If the field is a repeat field $raw will be an array of
+ // values.
+ $v = array();
+ foreach ($raw as $key => $value) {
+ $v[$value] = 1;
+ }
+ // In this case we set this checkbox to the array of values that are currently checked.
+ $val = $v;
+ } else {
+ // If the field is not a repeat, then it is only one value
+ $val = $record->getValueAsString($field['name']);
+ }
+
+ return $val;
+ }
}