/**
  * Get the data about the fields to be displayed.
  * @return array
  */
 public function getDisplayFieldsData()
 {
     $disp_order = '';
     $this->config->setIfIsSet($disp_order, 'display_order');
     if ($disp_order) {
         $displayOrder = explode(',', $disp_order);
         $fields = $this->config->fields->getAsArray();
         $results = array();
         foreach ($displayOrder as $field) {
             $results[$field] = $fields[$field];
             unset($fields[$field]);
         }
         foreach ($fields as $field => $data) {
             $results[$field] = $data;
         }
         return $results;
     }
     return $this->config->fields->getAsArray();
 }
 /**
  * Get how the given data should be queried from the db
  * @param I2CE_MagicDataNode $data
  * @returns mixed.  fasle on failture. string on success
  */
 protected function getFieldData($data)
 {
     $col = '';
     $data->setIfIsSet($col, 'col');
     $col = trim($col);
     if (strlen($col) > 0) {
         return $col;
     }
     $function = '';
     $data->setIfIsSet($function, 'function');
     if (strlen($function) > 0) {
         return $function;
     }
     return false;
 }
 /**
  * Abstract business method to render a text element from the elements tree
  * @param int $left_x
  * @param int $top_y
  * @param array $formData of I2CE_Form
  * @param array $textProps
  * @param I2CE_MagicDataNode $elementConfig The node defining the element
  * @returns boolean. True on success
  */
 protected function processElement_image($left_x, $top_y, $formData, $textProps, $elementConfig)
 {
     $image = '';
     if (!$elementConfig->setIfIsSet($image, "image") || !$image) {
         I2CE::raiseError("No image set");
         return true;
         //error silently
     }
     $image_file = false;
     if (substr($image, 0, 7) == 'form://') {
         $image = substr($image, 7);
         if (strlen($image) == 0) {
             I2CE::raiseError("No image from form set");
             return true;
         }
         list($namedform, $field) = array_pad(explode('+', $image, 2), 2, '');
         if (!$namedform || !$field) {
             I2CE::raiseError("Image form {$image} is not in relationship");
             return true;
         }
         if (!array_key_exists($namedform, $formData)) {
             I2CE::raiseError("Form {$namedform} is not in relationship");
             return true;
         }
         if (!($fieldObj = $formData[$namedform]->getField($field)) instanceof I2CE_FormField_IMAGE) {
             I2CE::raiseError("Field {$field} of form {$namedform} is not an image");
             return true;
         }
         if (!$fieldObj->isValid()) {
             return true;
         }
         $image_content = $fieldObj->getBinaryData();
         if (strlen($image_content) == 0) {
             //no data
             return true;
         }
         $image_file = $image . '@' . $this->getCurrentId() . '.' . $fieldObj->getExtension();
         $this->pdf->addImageContent($image_content, $image_file);
     } else {
         $image_file = I2CE::getFileSearch()->search('PDF_IMAGES', $image);
         if (!$image_file) {
             $msg = "Header image ({$image}) not found" . "\nSearch Path is:\n" . print_r(I2CE::getFileSearch()->getSearchPath('PDF_IMAGES'), true);
             I2CE::raiseError($msg);
             return true;
             //error silently'
         }
     }
     $horiz_min = false;
     if (!$elementConfig->setIfIsSet($horiz_min, "horiz_min")) {
         I2CE::raiseError("horiz_min not set");
         return true;
         //error silently
     }
     $horiz_min = (int) $horiz_min;
     $horiz_min = max(0, $horiz_min);
     if ($horiz_min >= $this->layoutOptions['form_width']) {
         I2CE::raiseError("Element does not fit in form");
     }
     $vert_min = false;
     if (!$elementConfig->setIfIsSet($vert_min, "vert_min")) {
         I2CE::raiseError("vert_min not set");
         return true;
         //error silently
     }
     $horiz_max = false;
     $vert_min = max(0, $vert_min);
     if ($vert_min >= $this->layoutOptions['form_height']) {
         I2CE::raiseError("Element does not fit in form");
         return true;
         //error silently
     }
     $elementConfig->setIfIsSet($horiz_max, "horiz_max");
     $vert_max = false;
     $elementConfig->setIfIsSet($vert_max, "vert_max");
     if ($horiz_max == false) {
         $w = 0;
     } else {
         $w = min($horiz_max, $this->layoutOptions['form_width']) - $horiz_min;
     }
     if ($vert_max == false) {
         $h = 0;
     } else {
         $h = min($vert_max, $this->layoutOptions['form_height']) - $vert_min;
     }
     $k = $this->pdf->getScaleFactor();
     $this->pdf->SetXY($left_x + $horiz_min, $top_y + $vert_min);
     $this->pdf->Image($image_file, $left_x + $horiz_min, $top_y + $vert_min, $w, $h);
     return true;
 }
 /**
  * Get the new migrated value for from the old value.
  * @param I2CE_MagicDataNode $migrate_node
  * @param string $map_form
  * @param mixed $old_id
  * @param integer $old_amt For currency data this is the amount
  * @return mixed
  */
 public static function getNewMigratedValue($migrate_node, $map_form, $old_value, $old_amt = 0)
 {
     $map_form_storage = self::getStorage($map_form, true);
     if ($map_form_storage == "entry") {
         $new_value = $map_form . "|" . $old_value;
     } else {
         $migrate_node->setIfIsSet($new_value, "forms/{$map_form}/{$old_value}");
         // Check without the map_form in the value name since
         // newer values are returned this way.
         if (!$new_value) {
             $tmp_value = str_replace($map_form . "|", "", $old_value);
             $migrate_node->setIfIsSet($new_value, "forms/{$map_form}/{$tmp_value}");
         }
     }
     if ($new_value && $map_form == "currency") {
         $new_value .= "=" . $old_amt;
     }
     return $new_value;
 }
 /**
  * internal function to get the fields which are in the limits for one where clause in a relationship
  * @param I2CE_MagicDataNode $whereConfig
  * @param array $limited_fields array of boolean indexed by the names of the fields
  */
 protected function _getLimitingFields($whereConfig, &$limiting_fields)
 {
     if (!$whereConfig instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Invalid where clause");
         return;
     }
     if (!isset($whereConfig->operator)) {
         return;
     }
     if ($whereConfig->operator == 'FIELD_LIMIT') {
         //see if we have a valid field, if so add it to our list
         $whereConfig->setIfIsSet($field, 'field');
         if ($field && !in_array($field, $limiting_fields)) {
             $limiting_fields[$field] = true;
         }
     } else {
         if (in_array($whereConfig->operator, self::$operands)) {
             //go down
             if (!$whereConfig->is_parent('operand')) {
                 return;
             }
             foreach ($whereConfig->operand as $operand => $opConfig) {
                 $this->_getLimitingFields($opConfig, $limiting_fields);
             }
         }
     }
     //else do nothing
 }
 /**
  * Adds any child forms for this form.
  * @param DOMNode $detailNode.  The major node which contains the formBrowser we are creating
  * @param  I2CE_MagicDataNode $formConfig /modules/forms/forms/$formName
  * @param I2CE_Form $formObj the form object for the form we are displaying ( or null.if we are not looking at a particular record)
  * @returns boolean.  Return false if none were added, true if child forms were added.
  */
 public function addChildForms($detailNode, $formConfig, $formObj)
 {
     $view_child = '';
     $child_forms = array();
     $formConfig->setIfIsSet($child_forms, "meta/child_forms", true);
     if (count($child_forms) > 0) {
         $view_child = "formBrowser/showForm";
     }
     $prefixNode = $this->template->getElementById('child_fb_prefix', $detailNode);
     if ($prefixNode instanceof DOMNode) {
         $prefixNode->setAttribute('value', $this->formBrowserPrefix);
     }
     $this->template->setDisplayDataImmediate('form_view_child', $view_child, $detailNode);
     $selectNode = $this->template->getElementById('child_form_select', $detailNode);
     $added = false;
     if ($selectNode instanceof DOMNode && $formObj instanceof I2CE_Form) {
         foreach ($child_forms as $child) {
             $childIds = $formObj->getChildIds($child);
             foreach ($childIds as $childId) {
                 $added = true;
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $child . ':' . $childId), $child . ' Id: ' . $childId));
             }
         }
     } else {
         if ($selectNode instanceof DOMNode) {
             foreach ($child_forms as $child) {
                 $added = true;
                 $selectNode->appendChild($this->template->createElement('option', array('value' => $child), $child));
             }
         }
     }
     foreach (array("form_view_child", "form_view_child_button") as $id) {
         $formNode = $this->template->getElementById($id, $detailNode);
         if ($formNode instanceof DOMNode) {
             $formNode->setAttribute('id', $this->formBrowserPrefix . '_' . $id);
         }
     }
     if ($this->page->hasAjax() && $added) {
         $this->page->addAjaxUpdate($this->formBrowserPrefix . '_content', $this->formBrowserPrefix . '_form_view_child_button', 'click', "formBrowser/{$this->formBrowserPrefix}", $this->formBrowserPrefix . '_content', true, $this->formBrowserPrefix . '_form_view_child', true);
     }
     if (!$added) {
         return false;
     } else {
         return true;
     }
 }