/** * Returns a set of radio form elements * * array( * 'name' => '', * 'value' => '', * 'id' => '', * 'legend' => '', * 'options' => array('value1' => 'text1', 'value2' => 'text2', 'value3' => 'text3'), * 'options' => array('text1', 'text2', 'text3'), //also acceptable (cannot do half this, half above syntax) * ) * * @param array $args * @return str */ public function radios(array $args) { $id = isset($args['id']) ? $args['id'] : $args['name']; $properties = $this->_getProperties($args); if (isset($properties['value'])) { $checked = $properties['value']; unset($properties['value']); } $properties['type'] = isset($args['type']) ? $args['type'] : 'radio'; $useValues = key($args['options']) !== 0 || isset($args['useValue']) && $args['useValue']; foreach ($args['options'] as $value => $text) { if (!$useValues) { $value = $text; } $properties['id'] = $id . '_' . preg_replace('/\\W/', '', $value); $properties['value'] = $value; if (isset($checked) && (($properties['type'] == 'radio' || !is_array($checked)) && $value == $checked || $properties['type'] == 'checkbox' && is_array($checked) && in_array((string) $value, $checked))) { $properties['checked'] = 'checked'; $rowClass = !isset($properties['class']) ? 'checked' : $properties['class'] . ' checked'; } $labelFirst = isset($args['labelFirst']) ? $args['labelFirst'] : false; $labelArgs = array('label' => $text, 'id' => $properties['id'], 'labelFirst' => $labelFirst); $input = '<input ' . htmlHelper::formatProperties($properties) . ' />'; $row = $this->_getLabel($labelArgs, $input); if (isset($rowClass)) { $row = '<span class="' . $rowClass . '">' . $row . '</span>'; } $radios[] = $row; unset($properties['checked'], $rowClass); } $this->{$properties['type'] == 'radio' ? 'radios' : 'checkboxes'} = $radios; $break = !isset($args['optionBreak']) ? '<br />' : $args['optionBreak']; $addFieldset = isset($args['addFieldset']) ? $args['addFieldset'] : isset($args['label']) && $args['label'] || count($args['options']) > 1; if ($addFieldset) { $return = '<fieldset id="' . $id . '">'; if (isset($args['label'])) { $return .= '<legend>' . get::htmlentities($args['label']) . '</legend>'; } $return .= implode($break, $radios) . '</fieldset>'; } else { $return = implode($break, $radios); } if (isset($_POST['errors']) && isset($_POST['errors'][$id])) { $return = $this->getErrorMessageContainer($id, $_POST['errors'][$id]) . $return; } return $return; }
exit(0); } /** * moaDB front-end view-element */ //Change to local path or url $headerArgs = ['title' => 'MoaDB', 'css' => ['//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', './resources/css/base.css', '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css', 'http://fonts.googleapis.com/css?family=Exo:900'], 'js' => ['//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js', './resources/js/main.js', './resources/js/classyWiggle.js']]; //Load Google jQuery from URL. echo $html->jsLoad(array('jquery', 'jqueryui')); echo $html->header($headerArgs); $baseUrl = $_SERVER['SCRIPT_NAME']; $db = isset($_GET['db']) ? $_GET['db'] : (isset($_POST['db']) ? $_POST['db'] : 'admin'); //admin is in every Mongo DB $dbUrl = urlencode($db); if (isset($_GET['collection'])) { $collection = get::htmlentities($_GET['collection']); unset($_GET['collection']); } $showUserPassword = false; if (isset($accessControl) && !isset($_SESSION['user'])) { if (isset($_POST['username'])) { $_POST = array_map('trim', $_POST); if (isset($accessControl[$_POST['username']]) && $accessControl[$_POST['username']] == $_POST['password']) { $_SESSION['user'] = $_POST['username']; } else { $_POST['errors']['username'] = '******'; } } if (!isset($_SESSION['user'])) { $showUserPassword = true; }
echo $form->open(array('action' => $action)); if (isset($_GET['_id']) && $_GET['_id'] && ($_GET['idtype'] == 'object' || $_GET['idtype'] == 'array')) { $_GET['_id'] = unserialize($_GET['_id']); if (is_array($_GET['_id'])) { $_GET['_id'] = json_encode($_GET['_id']); } } ?> <h4><?php echo isset($_GET['_id']) && $_GET['_id'] ? get::htmlentities($_GET['_id']) : '[New Object]'; ?> </h4><?php $textarea = array('name' => 'object', 'label' => '', 'rows' => "14", 'class' => 'form-control input-lg', 'addBreak' => false); $textarea['value'] = $mo->mongo['editObject'] !== '' ? json_encode($mo->mongo['editObject'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : '{' . PHP_EOL . PHP_EOL . '}'; echo $html->div($form->textarea($textarea) . $form->hidden(array('name' => 'action', 'value' => 'editObject'))); echo $html->div($form->hidden(array('name' => 'db', 'value' => get::htmlentities($db)))); ?> <a href="<?php echo $baseUrl . '?db=' . $dbUrl . '&action=listRows&collection=' . urlencode($collection); ?> " id="close-object" class="btn btn-default">Close</a> <button type="submit" id="edit-object" class="btn btn-<?php echo isset($_GET['saved']) ? 'success' : 'primary'; ?> "><?php echo isset($_GET['_id']) && $_GET['_id'] ? isset($_GET['saved']) ? 'Saved' : 'Save' : (isset($_GET['saved']) ? 'Saved' : 'Add'); ?> </button><?php echo $form->close(); } }