/** * Insert the submitted form into the specified Mysql database. */ public function run() { if (count($this->_fieldMap) == 0) { throw new Exception('Mysql success handler: field map is empty'); } $link = @mysql_connect($this->_host, $this->_username, $this->_password); if (!$link) { throw new Exception('Mysql error: ' . mysql_error()); } $db = @mysql_select_db($this->_dbname); if (!$db) { throw new Exception('Mysql error: ' . mysql_error()); } $queryParts = array(); $elements = $this->_form->getElements(); foreach ($this->_fieldMap as $elementName => $fieldName) { if (array_key_exists($elementName, $elements)) { $element = $elements[$elementName]; $value = $element->getValue(); if (is_array($value)) { $value = join(', ', $value); } $queryParts[] = "`{$fieldName}` = '" . mysql_real_escape_string($value) . "'"; } } if (count($queryParts) == 0) { throw new Exception('Mysql success handler: query is empty'); } if (strtolower($this->_form->getCharset()) == 'utf-8') { $utf8Query = "SET NAMES utf8"; $utf8Result = @mysql_query($utf8Query); if (!$utf8Result) { throw new Exception('Mysql error: ' . mysql_error()); } } $query = "INSERT INTO `{$this->_table}` SET " . join(', ', $queryParts); $result = @mysql_query($query); if (!$result) { throw new Exception('Mysql error: ' . mysql_error()); } @mysql_close($link); }
/** * Get the list of IDs of all elements in the given group * * @param iPhorm $form * @param iPhorm_Element_Groupstart $group * @return array */ function iphorm_get_group_element_ids($form, $group) { $groupElementIds = array(); $startCapture = false; $depth = 0; $elements = $form->getElements(); foreach ($elements as $element) { if ($element instanceof iPhorm_Element_Groupstart) { if ($element->getId() == $group->getId()) { // We've found ths group, so start capturing element IDs $startCapture = true; $depth++; continue; } else { if ($startCapture) { // This is another group inside it, so increment depth $depth++; } } } elseif ($element instanceof iPhorm_Element_Groupend) { // This is a group end element so decrement depth if ($startCapture) { if (--$depth == 0) { // This is the group end for our target group so we're done break; } } } else { if ($startCapture) { $groupElementIds[] = $element->getId(); } } } return $groupElementIds; }