Esempio n. 1
0
/**
 * 
 */
function caProcessBottomLineTemplate($po_request, $pa_placement, $pr_res, $pa_options = null)
{
    global $g_ui_units_pref, $g_ui_locale;
    if (!isset($pa_placement['settings']['bottom_line']) || !$pa_placement['settings']['bottom_line']) {
        return null;
    }
    if (!$pr_res) {
        return null;
    }
    $vs_template = $pa_placement['settings']['bottom_line'];
    $vs_bundle_name = $pa_placement['bundle_name'];
    $pn_page_start = caGetOption('pageStart', $pa_options, 0);
    $pn_page_end = caGetOption('pageEnd', $pa_options, $pr_res->numHits());
    if (($vn_current_index = $pr_res->currentIndex()) < 0) {
        $vn_current_index = 0;
    }
    $pr_res->seek(0);
    $o_dm = Datamodel::load();
    $va_tmp = explode(".", $vs_bundle_name);
    if (!($t_instance = $o_dm->getInstanceByTableName($va_tmp[0], true))) {
        return null;
    }
    if (!method_exists($t_instance, "_getElementDatatype") || is_null($vn_datatype = $t_instance->_getElementDatatype($va_tmp[1]))) {
        return null;
    }
    if (!($vs_user_currency = $po_request->user ? $po_request->user->getPreference('currency') : 'USD')) {
        $vs_user_currency = 'USD';
    }
    // Parse out tags and optional sub-elements from template
    //		we have to pull each sub-element separately
    //
    //		Ex. 	^SUM:valuation = sum of "valuation" sub-element
    //				^SUM = sum of primary value in non-container element
    if (!preg_match("!(\\^[A-Z]+[\\:]{0,1}[A-Za-z0-9\\_\\-]*)!", $vs_template, $va_tags)) {
        return $vs_template;
    }
    $va_tags_to_process = array();
    $va_subelements_to_process = array();
    if ($vn_datatype == 0) {
        // container
        foreach ($va_tags as $vs_raw_tag) {
            $va_tmp = explode(":", $vs_raw_tag);
            $vs_tag = $va_tmp[0];
            if (sizeof($va_tmp) == 2) {
                $vs_subelement = $va_tmp[1];
            } else {
                continue;
            }
            $va_tags_to_process[$vs_raw_tag] = true;
            $va_subelements_to_process["{$vs_bundle_name}.{$vs_subelement}"] = $t_instance->_getElementDatatype($vs_subelement);
        }
    } else {
        $va_tmp = explode(".", $vs_bundle_name);
        if (sizeof($va_tmp) == 2) {
            $vs_bundle_name .= "." . array_pop($va_tmp);
        }
        $va_subelements_to_process = array($vs_bundle_name => $vn_datatype);
    }
    $vn_c = 0;
    $vn_page_len = 0;
    $vb_has_timecode = false;
    $vn_min = $vn_max = null;
    $vn_page_min = $vn_page_max = null;
    $va_tag_values = array();
    while ($pr_res->nextHit()) {
        foreach ($va_subelements_to_process as $vs_subelement => $vn_subelement_datatype) {
            if (!is_array($va_tag_values[$vs_subelement])) {
                $va_tag_values[$vs_subelement]['SUM'] = 0;
                $va_tag_values[$vs_subelement]['PAGESUM'] = 0;
                $va_tag_values[$vs_subelement]['MIN'] = null;
                $va_tag_values[$vs_subelement]['PAGEMIN'] = null;
                $va_tag_values[$vs_subelement]['MAX'] = null;
                $va_tag_values[$vs_subelement]['PAGEMAX'] = null;
                $va_tag_values[$vs_subelement]['AVG'] = 0;
                $va_tag_values[$vs_subelement]['PAGEAVG'] = 0;
            }
            switch ($vn_subelement_datatype) {
                case 2:
                    // date range
                    $vs_value = $pr_res->get($vs_subelement);
                    break;
                case 6:
                    // currency
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimalWithCurrencySpecifier' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) caConvertCurrencyValue($vs_value, $vs_user_currency, array('numericValue' => true));
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($va_tag_values[$vs_subelement]['MIN']) || $vn_value < $va_tag_values[$vs_subelement]['MIN']) {
                                $va_tag_values[$vs_subelement]['MIN'] = $vn_value;
                            }
                            if (is_null($va_tag_values[$vs_subelement]['MAX']) || $vn_value > $va_tag_values[$vs_subelement]['MAX']) {
                                $va_tag_values[$vs_subelement]['MAX'] = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMIN']) || $vn_value < $va_tag_values[$vs_subelement]['PAGEMIN']) {
                                    $va_tag_values[$vs_subelement]['PAGEMIN'] = $vn_value;
                                }
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMAX']) || $vn_value > $va_tag_values[$vs_subelement]['PAGEMAX']) {
                                    $va_tag_values[$vs_subelement]['PAGEMAX'] = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                case 8:
                    // length
                // length
                case 9:
                    // weight
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimalMetric' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) $vs_value;
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($va_tag_values[$vs_subelement]['MIN']) || $vn_value < $va_tag_values[$vs_subelement]['MIN']) {
                                $va_tag_values[$vs_subelement]['MIN'] = $vn_value;
                            }
                            if (is_null($va_tag_values[$vs_subelement]['MAX']) || $vn_value > $va_tag_values[$vs_subelement]['MAX']) {
                                $va_tag_values[$vs_subelement]['MAX'] = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMIN']) || $vn_value < $va_tag_values[$vs_subelement]['PAGEMIN']) {
                                    $va_tag_values[$vs_subelement]['PAGEMIN'] = $vn_value;
                                }
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMAX']) || $vn_value > $va_tag_values[$vs_subelement]['PAGEMAX']) {
                                    $va_tag_values[$vs_subelement]['PAGEMAX'] = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                case 10:
                    // timecode
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimal' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vn_value) {
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($vn_min) || $vn_value < $vn_min) {
                                $vn_min = $vn_value;
                            }
                            if (is_null($vn_max) || $vn_value > $vn_max) {
                                $vn_max = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($vn_page_min) || $vn_value < $vn_page_min) {
                                    $vn_page_min = $vn_value;
                                }
                                if (is_null($vn_page_max) || $vn_value > $vn_page_max) {
                                    $vn_page_max = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    $vb_has_timecode = true;
                    break;
                case 11:
                    // integer
                // integer
                case 12:
                    // numeric (decimal)
                // numeric (decimal)
                default:
                    $va_values = $pr_res->get($vs_subelement, array('returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) $vs_value;
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($vn_min) || $vn_value < $vn_min) {
                                $vn_min = $vn_value;
                            }
                            if (is_null($vn_max) || $vn_value > $vn_max) {
                                $vn_max = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($vn_page_min) || $vn_value < $vn_page_min) {
                                    $vn_page_min = $vn_value;
                                }
                                if (is_null($vn_page_max) || $vn_value > $vn_page_max) {
                                    $vn_page_max = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                default:
                    break 2;
            }
        }
        $vn_c++;
    }
    if ($vb_has_timecode) {
        $o_tcp = new TimecodeParser();
        $o_config = Configuration::load();
        if (!($vs_timecode_format = $o_config->get('timecode_output_format'))) {
            $vs_timecode_format = 'HOURS_MINUTES_SECONDS';
        }
    }
    // Post processing
    foreach ($va_subelements_to_process as $vs_subelement => $vn_subelement_datatype) {
        switch ($vn_subelement_datatype) {
            case 6:
                // currency
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = "{$vs_user_currency} " . $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
            case 8:
                // length
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $vo_measurement = new Zend_Measure_Length((double) $vn_val, 'METER', $g_ui_locale);
                    $va_tag_values[$vs_subelement][$vs_tag] = $vo_measurement->convertTo($g_ui_units_pref == 'metric' ? Zend_Measure_Length::METER : Zend_Measure_Length::FEET, 4);
                }
                break;
            case 9:
                // weight
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $vo_measurement = new Zend_Measure_Length((double) $vn_val, 'KILOGRAM', $g_ui_locale);
                    $va_tag_values[$vs_subelement][$vs_tag] = $vo_measurement->convertTo($g_ui_units_pref == 'metric' ? Zend_Measure_Weight::KILOGRAM : Zend_Measure_Weight::POUND, 4);
                }
                break;
            case 10:
                // timecode
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : 0;
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    if (!$vb_has_timecode) {
                        $va_tag_values[$vs_subelement][$vs_tag] = '';
                        continue;
                    }
                    $o_tcp->setParsedValueInSeconds($vn_val);
                    $va_tag_values[$vs_subelement][$vs_tag] = $o_tcp->getText($vs_timecode_format);
                }
                break;
            case 11:
                // integer
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = (int) $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
            case 12:
                // numeric (decimal)
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = (double) $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
        }
    }
    // Restore current position of search result
    $pr_res->seek($vn_current_index);
    foreach ($va_tag_values as $vs_subelement => $va_tag_data) {
        foreach ($va_tag_data as $vs_tag => $vs_tag_value) {
            if ($vs_subelement == $vs_bundle_name) {
                $vs_template = str_replace("^{$vs_tag}", $vs_tag_value, $vs_template);
            } else {
                $va_tmp = explode(".", $vs_subelement);
                $vs_template = str_replace("^{$vs_tag}:" . array_pop($va_tmp), $vs_tag_value, $vs_template);
            }
        }
    }
    return $vs_template;
}
Esempio n. 2
0
 /**
  * HTML Form element generation
  * Optional name parameter allows you to generate a form element for a field but give it a
  * name different from the field name
  * 
  * @param string $ps_field field name
  * @param string $ps_format field format
  * @param array $pa_options additional options
  * TODO: document them.
  */
 public function htmlFormElement($ps_field, $ps_format = null, $pa_options = null)
 {
     $o_db = $this->getDb();
     // init options
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     foreach (array('display_form_field_tips', 'classname', 'maxOptionLength', 'textAreaTagName', 'display_use_count', 'display_omit_items__with_zero_count', 'display_use_count_filters', 'display_use_count_filters', 'selection', 'name', 'value', 'dont_show_null_value', 'size', 'multiple', 'show_text_field_for_vars', 'nullOption', 'empty_message', 'displayMessageForFieldValues', 'DISPLAY_FIELD', 'WHERE', 'select_item_text', 'hide_select_if_only_one_option', 'field_errors', 'display_form_field_tips', 'form_name', 'no_tooltips', 'tooltip_namespace', 'extraLabelText', 'width', 'height', 'label', 'list_code', 'hide_select_if_no_options', 'id', 'lookup_url', 'progress_indicator', 'error_icon', 'maxPixelWidth', 'displayMediaVersion', 'FIELD_TYPE', 'DISPLAY_TYPE', 'choiceList', 'readonly', 'description', 'hidden') as $vs_key) {
         if (!isset($pa_options[$vs_key])) {
             $pa_options[$vs_key] = null;
         }
     }
     $va_attr = $this->getFieldInfo($ps_field);
     foreach (array('DISPLAY_WIDTH', 'DISPLAY_USE_COUNT', 'DISPLAY_SHOW_COUNT', 'DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT', 'DISPLAY_TYPE', 'IS_NULL', 'DEFAULT_ON_NULL', 'DEFAULT', 'LIST_MULTIPLE_DELIMITER', 'FIELD_TYPE', 'LIST_CODE', 'DISPLAY_FIELD', 'WHERE', 'DISPLAY_WHERE', 'DISPLAY_ORDERBY', 'LIST', 'BOUNDS_CHOICE_LIST', 'BOUNDS_LENGTH', 'DISPLAY_DESCRIPTION', 'LABEL', 'DESCRIPTION', 'SUB_LABEL', 'SUB_DESCRIPTION', 'MAX_PIXEL_WIDTH') as $vs_key) {
         if (!isset($va_attr[$vs_key])) {
             $va_attr[$vs_key] = null;
         }
     }
     if (isset($pa_options['FIELD_TYPE'])) {
         $va_attr['FIELD_TYPE'] = $pa_options['FIELD_TYPE'];
     }
     if (isset($pa_options['DISPLAY_TYPE'])) {
         $va_attr['DISPLAY_TYPE'] = $pa_options['DISPLAY_TYPE'];
     }
     $vn_display_width = isset($pa_options['width']) && $pa_options['width'] > 0 ? $pa_options['width'] : $va_attr["DISPLAY_WIDTH"];
     $vn_display_height = isset($pa_options['height']) && $pa_options['height'] > 0 ? $pa_options['height'] : $va_attr["DISPLAY_HEIGHT"];
     $va_parsed_width = caParseFormElementDimension($vn_display_width);
     $va_parsed_height = caParseFormElementDimension($vn_display_height);
     $va_dim_styles = array();
     if ($va_parsed_width['type'] == 'pixels') {
         $va_dim_styles[] = "width: " . $va_parsed_width['dimension'] . "px;";
     }
     if ($va_parsed_height['type'] == 'pixels') {
         $va_dim_styles[] = "height: " . $va_parsed_height['dimension'] . "px;";
     }
     //if ($vn_max_pixel_width) {
     //	$va_dim_styles[] = "max-width: {$vn_max_pixel_width}px;";
     //}
     $vs_dim_style = trim(join(" ", $va_dim_styles));
     $vs_field_label = isset($pa_options['label']) && strlen($pa_options['label']) > 0 ? $pa_options['label'] : $va_attr["LABEL"];
     $vs_errors = '';
     // TODO: PULL THIS FROM A CONFIG FILE
     $pa_options["display_form_field_tips"] = true;
     if (isset($pa_options['classname'])) {
         $vs_css_class_attr = ' class="' . $pa_options['classname'] . '" ';
     } else {
         $vs_css_class_attr = '';
     }
     if (!isset($pa_options['id'])) {
         $pa_options['id'] = $pa_options['name'];
     }
     if (!isset($pa_options['id'])) {
         $pa_options['id'] = $ps_field;
     }
     if (!isset($pa_options['maxPixelWidth']) || (int) $pa_options['maxPixelWidth'] <= 0) {
         $vn_max_pixel_width = $va_attr['MAX_PIXEL_WIDTH'];
     } else {
         $vn_max_pixel_width = (int) $pa_options['maxPixelWidth'];
     }
     if ($vn_max_pixel_width <= 0) {
         $vn_max_pixel_width = null;
     }
     if (!isset($pa_options["maxOptionLength"]) && isset($vn_display_width)) {
         $pa_options["maxOptionLength"] = isset($vn_display_width) ? $vn_display_width : null;
     }
     $vs_text_area_tag_name = 'textarea';
     if (isset($pa_options["textAreaTagName"]) && $pa_options['textAreaTagName']) {
         $vs_text_area_tag_name = isset($pa_options['textAreaTagName']) ? $pa_options['textAreaTagName'] : null;
     }
     if (!isset($va_attr["DISPLAY_USE_COUNT"]) || !($vs_display_use_count = $va_attr["DISPLAY_USE_COUNT"])) {
         $vs_display_use_count = isset($pa_options["display_use_count"]) ? $pa_options["display_use_count"] : null;
     }
     if (!isset($va_attr["DISPLAY_SHOW_COUNT"]) || !($vb_display_show_count = (bool) $va_attr["DISPLAY_SHOW_COUNT"])) {
         $vb_display_show_count = isset($pa_options["display_show_count"]) ? (bool) $pa_options["display_show_count"] : null;
     }
     if (!isset($va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"]) || !($vb_display_omit_items__with_zero_count = (bool) $va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"])) {
         $vb_display_omit_items__with_zero_count = isset($pa_options["display_omit_items__with_zero_count"]) ? (bool) $pa_options["display_omit_items__with_zero_count"] : null;
     }
     if (!isset($va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"]) || !($va_display_use_count_filters = $va_attr["DISPLAY_USE_COUNT_FILTERS"])) {
         $va_display_use_count_filters = isset($pa_options["display_use_count_filters"]) ? $pa_options["display_use_count_filters"] : null;
     }
     if (!isset($va_display_use_count_filters) || !is_array($va_display_use_count_filters)) {
         $va_display_use_count_filters = null;
     }
     if (isset($pa_options["selection"]) && is_array($pa_options["selection"])) {
         $va_selection = isset($pa_options["selection"]) ? $pa_options["selection"] : null;
     } else {
         $va_selection = array();
     }
     if (isset($pa_options["choiceList"]) && is_array($pa_options["choiceList"])) {
         $va_attr["BOUNDS_CHOICE_LIST"] = $pa_options["choiceList"];
     }
     $vs_element = $vs_subelement = "";
     if ($va_attr) {
         # --- Skip omitted fields completely
         if ($va_attr["DISPLAY_TYPE"] == DT_OMIT) {
             return "";
         }
         if (!isset($pa_options["name"]) || !$pa_options["name"]) {
             $pa_options["name"] = htmlspecialchars($ps_field, ENT_QUOTES, 'UTF-8');
         }
         $va_js = array();
         $va_handlers = array("onclick", "onchange", "onkeypress", "onkeydown", "onkeyup");
         foreach ($va_handlers as $vs_handler) {
             if (isset($pa_options[$vs_handler]) && $pa_options[$vs_handler]) {
                 $va_js[] = "{$vs_handler}='" . $pa_options[$vs_handler] . "'";
             }
         }
         $vs_js = join(" ", $va_js);
         if (!isset($pa_options["value"])) {
             // allow field value to be overriden with value from options array
             $vm_field_value = $this->get($ps_field, $pa_options);
         } else {
             $vm_field_value = $pa_options["value"];
         }
         $vm_raw_field_value = $vm_field_value;
         $vb_is_null = isset($va_attr["IS_NULL"]) ? $va_attr["IS_NULL"] : false;
         if (isset($pa_options['dont_show_null_value']) && $pa_options['dont_show_null_value']) {
             $vb_is_null = false;
         }
         if (!is_array($vm_field_value) && strlen($vm_field_value) == 0 && (!isset($vb_is_null) || !$vb_is_null || (isset($va_attr["DEFAULT_ON_NULL"]) ? $va_attr["DEFAULT_ON_NULL"] : 0))) {
             $vm_field_value = isset($va_attr["DEFAULT"]) ? $va_attr["DEFAULT"] : "";
         }
         # --- Return hidden fields
         if ($va_attr["DISPLAY_TYPE"] == DT_HIDDEN || caGetOption('hidden', $pa_options, false)) {
             return '<input type="hidden" name="' . $pa_options["name"] . '" value="' . $this->escapeHTML($vm_field_value) . '"/>';
         }
         if (isset($pa_options["size"]) && $pa_options["size"] > 0) {
             $ps_size = " size='" . $pa_options["size"] . "'";
         } else {
             if (($va_attr["DISPLAY_TYPE"] == DT_LIST_MULTIPLE || $va_attr["DISPLAY_TYPE"] == DT_LIST) && $vn_display_height > 1) {
                 $ps_size = " size='" . $vn_display_height . "'";
             } else {
                 $ps_size = '';
             }
         }
         $vs_multiple_name_extension = '';
         if ($vs_is_multiple = isset($pa_options["multiple"]) && $pa_options["multiple"] || $va_attr["DISPLAY_TYPE"] == DT_LIST_MULTIPLE ? "multiple='1'" : "") {
             $vs_multiple_name_extension = '[]';
             if (!($vs_list_multiple_delimiter = $va_attr['LIST_MULTIPLE_DELIMITER'])) {
                 $vs_list_multiple_delimiter = ';';
             }
             $va_selection = array_merge($va_selection, explode($vs_list_multiple_delimiter, $vm_field_value));
         }
         # --- Return form element
         switch ($va_attr["FIELD_TYPE"]) {
             # ----------------------------
             case FT_NUMBER:
             case FT_TEXT:
             case FT_VARS:
                 if ($va_attr["FIELD_TYPE"] == FT_VARS) {
                     if (!$pa_options['show_text_field_for_vars']) {
                         break;
                     }
                     if (!is_string($vm_field_value) && !is_numeric($vm_field_value)) {
                         $vm_value = '';
                     }
                 }
                 if ($va_attr['DISPLAY_TYPE'] == DT_COUNTRY_LIST) {
                     $vs_element = caHTMLSelect($ps_field, caGetCountryList(), array('id' => $ps_field), array('value' => $vm_field_value));
                     if ($va_attr['STATEPROV_FIELD']) {
                         $vs_element .= "<script type='text/javascript'>\n";
                         $vs_element .= "var caStatesByCountryList = " . json_encode(caGetStateList()) . ";\n";
                         $vs_element .= "\n\t\t\t\t\t\t\t\tjQuery('#{$ps_field}').click({countryID: '{$ps_field}', stateProvID: '" . $va_attr['STATEPROV_FIELD'] . "', value: '" . addslashes($this->get($va_attr['STATEPROV_FIELD'])) . "', statesByCountryList: caStatesByCountryList}, caUI.utils.updateStateProvinceForCountry);\n\t\t\t\t\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\t\t\t\t\tcaUI.utils.updateStateProvinceForCountry({data: {countryID: '{$ps_field}', stateProvID: '" . $va_attr['STATEPROV_FIELD'] . "', value: '" . addslashes($this->get($va_attr['STATEPROV_FIELD'])) . "', statesByCountryList: caStatesByCountryList}});\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t";
                         $vs_element .= "</script>\n";
                     }
                     break;
                 }
                 if ($va_attr['DISPLAY_TYPE'] == DT_STATEPROV_LIST) {
                     $vs_element = caHTMLSelect($ps_field . '_select', array(), array('id' => $ps_field . '_select'), array('value' => $vm_field_value));
                     $vs_element .= caHTMLTextInput($ps_field . '_name', array('id' => $ps_field . '_text', 'value' => $vm_field_value));
                     break;
                 }
                 if ($vn_display_width > 0 && in_array($va_attr["DISPLAY_TYPE"], array(DT_SELECT, DT_LIST, DT_LIST_MULTIPLE))) {
                     #
                     # Generate auto generated <select> (from foreign key, from ca_lists or from field-defined choice list)
                     #
                     # TODO: CLEAN UP THIS CODE, RUNNING VARIOUS STAGES THROUGH HELPER FUNCTIONS; ALSO FORMALIZE AND DOCUMENT VARIOUS OPTIONS
                     // -----
                     // from ca_lists
                     // -----
                     if (!($vs_list_code = $pa_options['list_code'])) {
                         if (isset($va_attr['LIST_CODE']) && $va_attr['LIST_CODE']) {
                             $vs_list_code = $va_attr['LIST_CODE'];
                         }
                     }
                     if ($vs_list_code) {
                         $va_many_to_one_relations = $this->_DATAMODEL->getManyToOneRelations($this->tableName());
                         if ($va_many_to_one_relations[$ps_field]) {
                             $vs_key = 'item_id';
                         } else {
                             $vs_key = 'item_value';
                         }
                         $vs_null_option = null;
                         if (!$pa_options["nullOption"] && $vb_is_null) {
                             $vs_null_option = _t("- NONE -");
                         } else {
                             if ($pa_options["nullOption"]) {
                                 $vs_null_option = $pa_options["nullOption"];
                             }
                         }
                         $t_list = new ca_lists();
                         $va_list_attrs = array('id' => $pa_options['id']);
                         //if ($vn_max_pixel_width) { $va_list_attrs['style'] = $vs_width_style; }
                         if (method_exists($this, 'getTypeFieldName') && $ps_field == $this->getTypeFieldName()) {
                             $va_limit_list = caGetTypeListForUser($this->tableName(), array('access' => __CA_BUNDLE_ACCESS_EDIT__));
                         }
                         // NOTE: "raw" field value (value passed into method, before the model default value is applied) is used so as to allow the list default to be used if needed
                         $vs_element = $t_list->getListAsHTMLFormElement($vs_list_code, $pa_options["name"] . $vs_multiple_name_extension, $va_list_attrs, array('value' => $vm_raw_field_value, 'key' => $vs_key, 'nullOption' => $vs_null_option, 'readonly' => $pa_options['readonly'], 'restrictTypeListForTable' => $this->tableName(), 'limitToItemsWithID' => $va_limit_list ? $va_limit_list : null));
                         if (isset($pa_options['hide_select_if_no_options']) && $pa_options['hide_select_if_no_options'] && !$vs_element) {
                             $vs_element = "";
                             $ps_format = '^ERRORS^ELEMENT';
                         }
                     } else {
                         // -----
                         // from related table
                         // -----
                         $va_many_to_one_relations = $this->_DATAMODEL->getManyToOneRelations($this->tableName());
                         if (isset($va_many_to_one_relations[$ps_field]) && $va_many_to_one_relations[$ps_field]) {
                             #
                             # Use foreign  key to populate <select>
                             #
                             $o_one_table = $this->_DATAMODEL->getTableInstance($va_many_to_one_relations[$ps_field]["one_table"]);
                             $vs_one_table_primary_key = $o_one_table->primaryKey();
                             if ($o_one_table->isHierarchical()) {
                                 #
                                 # Hierarchical <select>
                                 #
                                 $va_hier = $o_one_table->getHierarchyAsList(0, $vs_display_use_count, $va_display_use_count_filters, $vb_display_omit_items__with_zero_count);
                                 if (!is_array($va_hier)) {
                                     return '';
                                 }
                                 $va_display_fields = $va_attr["DISPLAY_FIELD"];
                                 if (!in_array($vs_one_table_primary_key, $va_display_fields)) {
                                     $va_display_fields[] = $o_one_table->tableName() . "." . $vs_one_table_primary_key;
                                 }
                                 if (!is_array($va_display_fields) || sizeof($va_display_fields) < 1) {
                                     $va_display_fields = array("*");
                                 }
                                 $vs_hier_parent_id_fld = $o_one_table->getProperty("HIER_PARENT_ID_FLD");
                                 $va_options = array();
                                 if ($pa_options["nullOption"]) {
                                     $va_options[""] = array($pa_options["nullOption"]);
                                 }
                                 $va_suboptions = array();
                                 $va_suboption_values = array();
                                 $vn_selected = 0;
                                 $vm_cur_top_level_val = null;
                                 $vm_selected_top_level_val = null;
                                 foreach ($va_hier as $va_option) {
                                     if (!$va_option["NODE"][$vs_hier_parent_id_fld]) {
                                         continue;
                                     }
                                     $vn_val = $va_option["NODE"][$o_one_table->primaryKey()];
                                     $vs_selected = $vn_val == $vm_field_value ? 'selected="1"' : "";
                                     $vn_indent = $va_option["LEVEL"] - 1;
                                     $va_display_data = array();
                                     foreach ($va_display_fields as $vs_fld) {
                                         $va_bits = explode(".", $vs_fld);
                                         if ($va_bits[1] != $vs_one_table_primary_key) {
                                             $va_display_data[] = $va_option["NODE"][$va_bits[1]];
                                         }
                                     }
                                     $vs_option_label = join(" ", $va_display_data);
                                     $va_options[$vn_val] = array($vs_option_label, $vn_indent, $va_option["HITS"], $va_option['NODE']);
                                 }
                                 if (sizeof($va_options) == 0) {
                                     $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available';
                                 } else {
                                     $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options["id"] . $vs_multiple_name_extension . "' {$vs_css_class_attr}  style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n";
                                     if (!$pa_options["nullOption"] && $vb_is_null) {
                                         $vs_element .= "<option value=''>" . _t('- NONE -') . "</option>\n";
                                     } else {
                                         if ($pa_options["nullOption"]) {
                                             $vs_element .= "<option value=''>" . $pa_options["nullOption"] . "</option>\n";
                                         }
                                     }
                                     foreach ($va_options as $vn_val => $va_option_info) {
                                         $vs_selected = $vn_val == $vm_field_value || in_array($vn_val, $va_selection) ? "selected='selected'" : "";
                                         $vs_element .= "<option value='" . $vn_val . "' {$vs_selected}>";
                                         $vn_indent = $va_option_info[1] * 2;
                                         $vs_indent = "";
                                         if ($vn_indent > 0) {
                                             $vs_indent = str_repeat("&nbsp;", ($vn_indent - 1) * 2) . " ";
                                             $vn_indent++;
                                         }
                                         $vs_option_text = $va_option_info[0];
                                         $vs_use_count = "";
                                         if ($vs_display_use_count && $vb_display_show_count && $vn_val != "") {
                                             $vs_use_count = " (" . intval($va_option_info[2]) . ")";
                                         }
                                         $vs_display_message = '';
                                         if (is_array($pa_options['displayMessageForFieldValues'])) {
                                             foreach ($pa_options['displayMessageForFieldValues'] as $vs_df => $va_df_vals) {
                                                 if (isset($va_option_info[3][$vs_df]) && is_array($va_df_vals)) {
                                                     $vs_tmp = $va_option_info[3][$vs_df];
                                                     if (isset($va_df_vals[$vs_tmp])) {
                                                         $vs_display_message = ' ' . $va_df_vals[$vs_tmp];
                                                     }
                                                 }
                                             }
                                         }
                                         if ($pa_options["maxOptionLength"] && strlen($vs_option_text) + strlen($vs_use_count) + $vn_indent > $pa_options["maxOptionLength"]) {
                                             if (($vn_strlen = $pa_options["maxOptionLength"] - strlen($vs_indent) - strlen($vs_use_count) - 3) < $pa_options["maxOptionLength"]) {
                                                 $vn_strlen = $pa_options["maxOptionLength"];
                                             }
                                             $vs_option_text = unicode_substr($vs_option_text, 0, $vn_strlen) . "...";
                                         }
                                         $vs_element .= $vs_indent . $vs_option_text . $vs_use_count . $vs_display_message . "</option>\n";
                                     }
                                     $vs_element .= "</select>\n";
                                 }
                             } else {
                                 #
                                 # "Flat" <select>
                                 #
                                 if (!is_array($va_display_fields = $pa_options["DISPLAY_FIELD"])) {
                                     $va_display_fields = $va_attr["DISPLAY_FIELD"];
                                 }
                                 if (!is_array($va_display_fields)) {
                                     return "Configuration error: DISPLAY_FIELD directive for field '{$ps_field}' must be an array of field names in the format tablename.fieldname";
                                 }
                                 if (!in_array($vs_one_table_primary_key, $va_display_fields)) {
                                     $va_display_fields[] = $o_one_table->tableName() . "." . $vs_one_table_primary_key;
                                 }
                                 if (!is_array($va_display_fields) || sizeof($va_display_fields) < 1) {
                                     $va_display_fields = array("*");
                                 }
                                 $vs_sql = "\n\t\t\t\t\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM " . $va_many_to_one_relations[$ps_field]["one_table"] . "\n\t\t\t\t\t\t\t\t\t\t\t";
                                 if (isset($pa_options["WHERE"]) && (is_array($pa_options["WHERE"]) && ($vs_where = join(" AND ", $pa_options["WHERE"]))) || is_array($va_attr["DISPLAY_WHERE"]) && ($vs_where = join(" AND ", $va_attr["DISPLAY_WHERE"]))) {
                                     $vs_sql .= " WHERE {$vs_where} ";
                                 }
                                 if (isset($va_attr["DISPLAY_ORDERBY"]) && $va_attr["DISPLAY_ORDERBY"] && ($vs_orderby = join(",", $va_attr["DISPLAY_ORDERBY"]))) {
                                     $vs_sql .= " ORDER BY {$vs_orderby} ";
                                 }
                                 $qr_res = $o_db->query($vs_sql);
                                 if ($o_db->numErrors()) {
                                     $vs_element = "Error creating menu: " . join(';', $o_db->getErrors());
                                     break;
                                 }
                                 $va_opts = array();
                                 if (isset($pa_options["nullOption"]) && $pa_options["nullOption"]) {
                                     $va_opts[$pa_options["nullOption"]] = array($pa_options["nullOption"], null);
                                 } else {
                                     if ($vb_is_null) {
                                         $va_opts[_t("- NONE -")] = array(_t("- NONE -"), null);
                                     }
                                 }
                                 if ($pa_options["select_item_text"]) {
                                     $va_opts[$pa_options["select_item_text"]] = array($pa_options["select_item_text"], null);
                                 }
                                 $va_fields = array();
                                 foreach ($va_display_fields as $vs_field) {
                                     $va_tmp = explode(".", $vs_field);
                                     $va_fields[] = $va_tmp[1];
                                 }
                                 while ($qr_res->nextRow()) {
                                     $vs_display = "";
                                     foreach ($va_fields as $vs_field) {
                                         if ($vs_field != $vs_one_table_primary_key) {
                                             $vs_display .= $qr_res->get($vs_field) . " ";
                                         }
                                     }
                                     $va_opts[] = array($vs_display, $qr_res->get($vs_one_table_primary_key), $qr_res->getRow());
                                 }
                                 if (sizeof($va_opts) == 0) {
                                     $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available';
                                 } else {
                                     if (isset($pa_options['hide_select_if_only_one_option']) && $pa_options['hide_select_if_only_one_option'] && sizeof($va_opts) == 1) {
                                         $vs_element = "<input type='hidden' name='" . $pa_options["name"] . "' " . $vs_js . " " . $ps_size . " id='" . $pa_options["id"] . "' value='" . ($vm_field_value ? $vm_field_value : $va_opts[0][1]) . "' {$vs_css_class_attr}/>";
                                         $ps_format = '^ERRORS^ELEMENT';
                                     } else {
                                         $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options["id"] . $vs_multiple_name_extension . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n";
                                         foreach ($va_opts as $va_opt) {
                                             $vs_option_text = $va_opt[0];
                                             $vs_value = $va_opt[1];
                                             $vs_selected = $vs_value == $vm_field_value || in_array($vs_value, $va_selection) ? "selected='selected'" : "";
                                             $vs_use_count = "";
                                             if ($vs_display_use_count && $vb_display_show_count && $vs_value != "") {
                                                 //$vs_use_count = "(".intval($va_option_info[2]).")";
                                             }
                                             if ($pa_options["maxOptionLength"] && strlen($vs_option_text) + strlen($vs_use_count) > $pa_options["maxOptionLength"]) {
                                                 $vs_option_text = unicode_substr($vs_option_text, 0, $pa_options["maxOptionLength"] - 3 - strlen($vs_use_count)) . "...";
                                             }
                                             $vs_display_message = '';
                                             if (is_array($pa_options['displayMessageForFieldValues'])) {
                                                 foreach ($pa_options['displayMessageForFieldValues'] as $vs_df => $va_df_vals) {
                                                     if (isset($va_opt[2][$vs_df]) && is_array($va_df_vals)) {
                                                         $vs_tmp = $va_opt[2][$vs_df];
                                                         if (isset($va_df_vals[$vs_tmp])) {
                                                             $vs_display_message = ' ' . $va_df_vals[$vs_tmp];
                                                         }
                                                     }
                                                 }
                                             }
                                             $vs_element .= "<option value='{$vs_value}' {$vs_selected}>";
                                             $vs_element .= $vs_option_text . $vs_use_count . $vs_display_message;
                                             $vs_element .= "</option>\n";
                                         }
                                         $vs_element .= "</select>\n";
                                     }
                                 }
                             }
                         } else {
                             #
                             # choice list
                             #
                             $vs_element = '';
                             // if 'LIST' is set try to stock over choice list with the contents of the list
                             if (isset($va_attr['LIST']) && $va_attr['LIST']) {
                                 // NOTE: "raw" field value (value passed into method, before the model default value is applied) is used so as to allow the list default to be used if needed
                                 $vs_element = ca_lists::getListAsHTMLFormElement($va_attr['LIST'], $pa_options["name"] . $vs_multiple_name_extension, array('class' => $pa_options['classname'], 'id' => $pa_options['id']), array('key' => 'item_value', 'value' => $vm_raw_field_value, 'nullOption' => $pa_options['nullOption'], 'readonly' => $pa_options['readonly']));
                             }
                             if (!$vs_element && (isset($va_attr["BOUNDS_CHOICE_LIST"]) && is_array($va_attr["BOUNDS_CHOICE_LIST"]))) {
                                 if (sizeof($va_attr["BOUNDS_CHOICE_LIST"]) == 0) {
                                     $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available';
                                 } else {
                                     $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options['id'] . $vs_multiple_name_extension . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n";
                                     if ($pa_options["select_item_text"]) {
                                         $vs_element .= "<option value=''>" . $this->escapeHTML($pa_options["select_item_text"]) . "</option>\n";
                                     }
                                     if (!$pa_options["nullOption"] && $vb_is_null) {
                                         $vs_element .= "<option value=''>" . _t('- NONE -') . "</option>\n";
                                     } else {
                                         if ($pa_options["nullOption"]) {
                                             $vs_element .= "<option value=''>" . $pa_options["nullOption"] . "</option>\n";
                                         }
                                     }
                                     foreach ($va_attr["BOUNDS_CHOICE_LIST"] as $vs_option => $vs_value) {
                                         $vs_selected = strval($vs_value) === strval($vm_field_value) || in_array($vs_value, $va_selection) ? "selected='selected'" : "";
                                         if ($pa_options["maxOptionLength"] && strlen($vs_option) > $pa_options["maxOptionLength"]) {
                                             $vs_option = unicode_substr($vs_option, 0, $pa_options["maxOptionLength"] - 3) . "...";
                                         }
                                         $vs_element .= "<option value='{$vs_value}' {$vs_selected}>" . $this->escapeHTML($vs_option) . "</option>\n";
                                     }
                                     $vs_element .= "</select>\n";
                                 }
                             }
                         }
                     }
                 } else {
                     if ($va_attr["DISPLAY_TYPE"] === DT_COLORPICKER) {
                         // COLORPICKER
                         $vs_element = '<input name="' . $pa_options["name"] . '" type="hidden" size="' . ($pa_options['size'] ? $pa_options['size'] : $vn_display_width) . '" value="' . $this->escapeHTML($vm_field_value) . '" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' style='{$vs_dim_style}'/>\n";
                         $vs_element .= '<div id="' . $pa_options["id"] . '_colorchip" class="colorpicker_chip" style="background-color: #' . $vm_field_value . '"><!-- empty --></div>';
                         $vs_element .= "<script type='text/javascript'>jQuery(document).ready(function() { jQuery('#" . $pa_options["name"] . "_colorchip').ColorPicker({\n\t\t\t\t\t\t\t\tonShow: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeIn(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonHide: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeOut(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonChange: function (hsb, hex, rgb) {\n\t\t\t\t\t\t\t\t\tjQuery('#" . $pa_options["name"] . "').val(hex);\n\t\t\t\t\t\t\t\t\tjQuery('#" . $pa_options["name"] . "_colorchip').css('backgroundColor', '#' + hex);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcolor: jQuery('#" . $pa_options["name"] . "').val()\n\t\t\t\t\t\t\t})}); </script>\n";
                         if (method_exists('AssetLoadManager', 'register')) {
                             AssetLoadManager::register('jquery', 'colorpicker');
                         }
                     } else {
                         # normal controls: all non-DT_SELECT display types are returned as DT_FIELD's. We could generate
                         # radio-button controls for foreign key and choice lists, but we don't bother because it's never
                         # really necessary.
                         if ($vn_display_height > 1) {
                             $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '"' . ($pa_options['readonly'] ? ' readonly="readonly" disabled="disabled"' : '') . ' wrap="soft" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' style='{$vs_dim_style}' " . $vs_css_class_attr . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>' . "\n";
                         } else {
                             $vs_element = '<input name="' . $pa_options["name"] . '" type="text" size="' . ($pa_options['size'] ? $pa_options['size'] : $vn_display_width) . '"' . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ' value="' . $this->escapeHTML($vm_field_value) . '" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' {$vs_css_class_attr} style='{$vs_dim_style}'/>\n";
                         }
                         if (isset($va_attr['UNIQUE_WITHIN']) && is_array($va_attr['UNIQUE_WITHIN'])) {
                             $va_within_fields = array();
                             foreach ($va_attr['UNIQUE_WITHIN'] as $vs_within_field) {
                                 $va_within_fields[$vs_within_field] = $this->get($vs_within_field);
                             }
                             $vs_element .= "<span id='" . $pa_options["id"] . '_uniqueness_status' . "'></span>";
                             $vs_element .= "<script type='text/javascript'>\n\tcaUI.initUniquenessChecker({\n\t\terrorIcon: '" . $pa_options['error_icon'] . "',\n\t\tprocessIndicator: '" . $pa_options['progress_indicator'] . "',\n\t\tstatusID: '" . $pa_options["id"] . "_uniqueness_status',\n\t\tlookupUrl: '" . $pa_options['lookup_url'] . "',\n\t\tformElementID: '" . $pa_options["id"] . "',\n\t\trow_id: " . intval($this->getPrimaryKey()) . ",\n\t\ttable_num: " . $this->tableNum() . ",\n\t\tfield: '" . $ps_field . "',\n\t\twithinFields: " . json_encode($va_within_fields) . ",\n\t\t\n\t\talreadyInUseMessage: '" . addslashes(_t('Value must be unique. Please try another.')) . "'\n\t});\n</script>";
                         } else {
                             if (isset($va_attr['LOOKUP']) && $va_attr['LOOKUP']) {
                                 if (class_exists("AppController") && ($app = AppController::getInstance()) && ($req = $app->getRequest())) {
                                     AssetLoadManager::register('jquery', 'autocomplete');
                                     $vs_element .= "<script type='text/javascript'>\n\tjQuery('#" . $pa_options["id"] . "').autocomplete({ source: '" . caNavUrl($req, 'lookup', 'Intrinsic', 'Get', array('bundle' => $this->tableName() . ".{$ps_field}", "max" => 500)) . "', minLength: 3, delay: 800});\n</script>";
                                 }
                             }
                         }
                         if (isset($pa_options['usewysiwygeditor']) && $pa_options['usewysiwygeditor']) {
                             AssetLoadManager::register("ckeditor");
                             $vs_width = $vn_display_width;
                             $vs_height = $vn_display_height;
                             if (!preg_match("!^[\\d\\.]+px\$!i", $vs_width)) {
                                 $vs_width = (int) $vs_width * 6 . "px";
                             }
                             if (!preg_match("!^[\\d\\.]+px\$!i", $vs_height)) {
                                 $vs_height = (int) $vs_height * 16 . "px";
                             }
                             if (!is_array($va_toolbar_config = $this->getAppConfig()->getAssoc('wysiwyg_editor_toolbar'))) {
                                 $va_toolbar_config = array();
                             }
                             $vs_element .= "<script type='text/javascript'>jQuery(document).ready(function() {\n\t\t\t\t\t\t\t\tvar ckEditor = CKEDITOR.replace( '" . $pa_options['id'] . "',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttoolbar : " . json_encode(array_values($va_toolbar_config)) . ",\n\t\t\t\t\t\t\t\t\twidth: '{$vs_width}',\n\t\t\t\t\t\t\t\t\theight: '{$vs_height}',\n\t\t\t\t\t\t\t\t\ttoolbarLocation: 'top',\n\t\t\t\t\t\t\t\t\tenterMode: CKEDITOR.ENTER_BR\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tckEditor.on('instanceReady', function(){ \n\t\t\t\t\t\t\t\t\t ckEditor.document.on( 'keydown', function(e) {if (caUI && caUI.utils) { caUI.utils.showUnsavedChangesWarning(true); } });\n\t\t\t\t\t\t\t\t});\n \t});\t\t\t\t\t\t\t\t\t\n</script>";
                         }
                     }
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_TIMESTAMP:
                 if ($this->get($ps_field)) {
                     # is timestamp set?
                     $vs_element = $this->escapeHTML($vm_field_value);
                     # return printed date
                 } else {
                     $vs_element = "[Not set]";
                     # return text instead of 1969 date
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_DATETIME:
             case FT_HISTORIC_DATETIME:
             case FT_DATE:
             case FT_HISTORIC_DATE:
                 if (!$vm_field_value) {
                     $vm_field_value = $pa_options['value'];
                 }
                 switch ($va_attr["DISPLAY_TYPE"]) {
                     case DT_TEXT:
                         $vs_element = $vm_field_value ? $vm_field_value : "[Not set]";
                         break;
                     default:
                         $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                         $vs_max_length = '';
                         if ($vn_max_length > 0) {
                             $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                         }
                         if ($vn_display_height > 1) {
                             $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>';
                         } else {
                             $vs_element = '<input type="text" name="' . $pa_options["name"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                         }
                         break;
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_TIME:
                 if (!$this->get($ps_field)) {
                     $vm_field_value = "";
                 }
                 switch ($va_attr["DISPLAY_TYPE"]) {
                     case DT_TEXT:
                         $vs_element = $vm_field_value ? $vm_field_value : "[Not set]";
                         break;
                     default:
                         $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                         $vs_max_length = '';
                         if ($vn_max_length > 0) {
                             $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                         }
                         if ($vn_display_height > 1) {
                             $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>';
                         } else {
                             $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr}' style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                         }
                         break;
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_DATERANGE:
             case FT_HISTORIC_DATERANGE:
                 switch ($va_attr["DISPLAY_TYPE"]) {
                     case DT_TEXT:
                         $vs_element = $vm_field_value ? $vm_field_value : "[Not set]";
                         break;
                     default:
                         $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                         $vs_max_length = '';
                         if ($vn_max_length > 0) {
                             $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                         }
                         if ($vn_display_height > 1) {
                             $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>';
                         } else {
                             $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vn_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                         }
                         break;
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_TIMERANGE:
                 switch ($va_attr["DISPLAY_TYPE"]) {
                     case DT_TEXT:
                         $vs_element = $vm_field_value ? $vm_field_value : "[Not set]";
                         break;
                     default:
                         $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                         $vs_max_length = '';
                         if ($vn_max_length > 0) {
                             $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                         }
                         if ($vn_display_height > 1) {
                             $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>';
                         } else {
                             $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr}  style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                         }
                         break;
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_TIMECODE:
                 $o_tp = new TimecodeParser();
                 $o_tp->setParsedValueInSeconds($vm_field_value);
                 $vs_timecode = $o_tp->getText("COLON_DELIMITED", array("BLANK_ON_ZERO" => true));
                 $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                 $vs_max_length = '';
                 if ($vn_max_length > 0) {
                     $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                 }
                 if ($vn_display_height > 1) {
                     $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vs_timecode) . '</' . $vs_text_area_tag_name . '>';
                 } else {
                     $vs_element = '<input type="text" NAME="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vs_timecode) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_MEDIA:
             case FT_FILE:
                 $vs_element = '<input type="file" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" ' . $vs_js . '/>';
                 // show current media icon
                 if ($vs_version = array_key_exists('displayMediaVersion', $pa_options) ? $pa_options['displayMediaVersion'] : 'icon') {
                     $va_valid_versions = $this->getMediaVersions($ps_field);
                     if (!in_array($vs_version, $va_valid_versions)) {
                         $vs_version = $va_valid_versions[0];
                     }
                     if ($vs_tag = $this->getMediaTag($ps_field, $vs_version)) {
                         $vs_element .= $vs_tag;
                     }
                 }
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_PASSWORD:
                 $vn_max_length = $va_attr["BOUNDS_LENGTH"][1];
                 $vs_max_length = '';
                 if ($vn_max_length > 0) {
                     $vs_max_length = 'maxlength="' . $vn_max_length . '"';
                 }
                 $vs_element = '<input type="password" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . '" size="' . $vn_display_width . '" ' . $vs_max_length . ' ' . $vs_js . ' autocomplete="off" ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                 break;
                 # ----------------------------
             # ----------------------------
             case FT_BIT:
                 switch ($va_attr["DISPLAY_TYPE"]) {
                     case DT_FIELD:
                         $vs_element = '<input type="text" name="' . $pa_options["name"] . "\" value='{$vm_field_value}' maxlength='1' size='2' {$vs_js} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>";
                         break;
                     case DT_SELECT:
                         $vs_element = "<select name='" . $pa_options["name"] . "' " . $vs_js . " id='" . $pa_options["id"] . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n";
                         foreach (array("Yes" => 1, "No" => 0) as $vs_option => $vs_value) {
                             $vs_selected = $vs_value == $vm_field_value ? "selected='selected'" : "";
                             $vs_element .= "<option value='{$vs_value}' {$vs_selected}" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">" . _t($vs_option) . "</option>\n";
                         }
                         $vs_element .= "</select>\n";
                         break;
                     case DT_CHECKBOXES:
                         $vs_element = '<input type="checkbox" name="' . $pa_options["name"] . '" value="1" ' . ($vm_field_value ? 'checked="1"' : '') . ' ' . $vs_js . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ' id="' . $pa_options["id"] . '"/>';
                         break;
                     case DT_RADIO_BUTTONS:
                         $vs_element = 'Radio buttons not supported for bit-type fields';
                         break;
                 }
                 break;
                 # ----------------------------
         }
         # Apply format
         $vs_formatting = "";
         if (isset($pa_options['field_errors']) && is_array($pa_options['field_errors']) && sizeof($pa_options['field_errors'])) {
             $va_field_errors = array();
             foreach ($pa_options['field_errors'] as $o_e) {
                 $va_field_errors[] = $o_e->getErrorDescription();
             }
             $vs_errors = join('; ', $va_field_errors);
         } else {
             $vs_errors = '';
         }
         if (is_null($ps_format)) {
             if (isset($pa_options['field_errors']) && is_array($pa_options['field_errors']) && sizeof($pa_options['field_errors'])) {
                 $ps_format = $this->_CONFIG->get('form_element_error_display_format');
             } else {
                 $ps_format = $this->_CONFIG->get('form_element_display_format');
             }
         }
         if ($ps_format != '') {
             $ps_formatted_element = $ps_format;
             $ps_formatted_element = str_replace("^ELEMENT", $vs_element, $ps_formatted_element);
             if ($vs_subelement) {
                 $ps_formatted_element = str_replace("^SUB_ELEMENT", $vs_subelement, $ps_formatted_element);
             }
             $vb_fl_display_form_field_tips = false;
             if ($pa_options["display_form_field_tips"] || !isset($pa_options["display_form_field_tips"]) && $va_attr["DISPLAY_DESCRIPTION"] || !isset($pa_options["display_form_field_tips"]) && !isset($va_attr["DISPLAY_DESCRIPTION"]) && $vb_fl_display_form_field_tips) {
                 if (preg_match("/\\^DESCRIPTION/", $ps_formatted_element)) {
                     $ps_formatted_element = str_replace("^LABEL", $vs_field_label, $ps_formatted_element);
                     $ps_formatted_element = str_replace("^DESCRIPTION", isset($pa_options["description"]) && $pa_options["description"] ? $pa_options["description"] : $va_attr["DESCRIPTION"], $ps_formatted_element);
                 } else {
                     // no explicit placement of description text, so...
                     $vs_field_id = '_' . $this->tableName() . '_' . $this->getPrimaryKey() . '_' . $pa_options["name"] . '_' . $pa_options['form_name'];
                     $ps_formatted_element = str_replace("^LABEL", '<span id="' . $vs_field_id . '">' . $vs_field_label . '</span>', $ps_formatted_element);
                     if (!isset($pa_options['no_tooltips']) || !$pa_options['no_tooltips']) {
                         TooltipManager::add('#' . $vs_field_id, "<h3>{$vs_field_label}</h3>" . (isset($pa_options["description"]) && $pa_options["description"] ? $pa_options["description"] : $va_attr["DESCRIPTION"]), $pa_options['tooltip_namespace']);
                     }
                 }
                 if (!isset($va_attr["SUB_LABEL"])) {
                     $va_attr["SUB_LABEL"] = '';
                 }
                 if (!isset($va_attr["SUB_DESCRIPTION"])) {
                     $va_attr["SUB_DESCRIPTION"] = '';
                 }
                 if (preg_match("/\\^SUB_DESCRIPTION/", $ps_formatted_element)) {
                     $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element);
                     $ps_formatted_element = str_replace("^SUB_DESCRIPTION", $va_attr["SUB_DESCRIPTION"], $ps_formatted_element);
                 } else {
                     // no explicit placement of description text, so...
                     // ... make label text itself rollover for description text because no icon was specified
                     $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element);
                 }
             } else {
                 $ps_formatted_element = str_replace("^LABEL", $vs_field_label, $ps_formatted_element);
                 $ps_formatted_element = str_replace("^DESCRIPTION", "", $ps_formatted_element);
                 if ($vs_subelement) {
                     $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element);
                     $ps_formatted_element = str_replace("^SUB_DESCRIPTION", "", $ps_formatted_element);
                 }
             }
             $ps_formatted_element = str_replace("^ERRORS", $vs_errors, $ps_formatted_element);
             $ps_formatted_element = str_replace("^EXTRA", isset($pa_options['extraLabelText']) ? $pa_options['extraLabelText'] : '', $ps_formatted_element);
             $vs_element = $ps_formatted_element;
         } else {
             $vs_element .= "<br/>" . $vs_subelement;
         }
         return $vs_element;
     } else {
         $this->postError(716, _t("'%1' does not exist in this object", $ps_field), "BaseModel->formElement()");
         return "";
     }
     return "";
 }
Esempio n. 3
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     if (!$this->opb_ffmpeg_available) {
         return false;
     }
     $o_tc = new TimecodeParser();
     $vn_start = $vn_end = null;
     if ($o_tc->parse($ps_start)) {
         $vn_start = $o_tc->getSeconds();
     }
     if ($o_tc->parse($ps_end)) {
         $vn_end = $o_tc->getSeconds();
     }
     if (!$vn_start || !$vn_end) {
         return null;
     }
     if ($vn_start >= $vn_end) {
         return null;
     }
     $vn_duration = $vn_end - $vn_start;
     exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caGetOSFamily() == OS_POSIX ? " 2> /dev/null" : ""), $va_output, $vn_return);
     if ($vn_return != 0) {
         @unlink($filepath . "." . $ext);
         $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()");
         return false;
     }
     return true;
 }
 public function getProperty($ps_property, $pb_return_raw_value = false)
 {
     if (!($va_info = $this->getPropertyInfo($ps_property))) {
         return null;
     }
     // invalid property
     if ($pb_return_raw_value) {
         return $this->opa_property_values[$ps_property];
     }
     switch ($va_info['fieldType']) {
         case 'FT_TIMECODE':
             $o_timecode_parser = new TimecodeParser();
             $o_timecode_parser->setParsedValueInSeconds($this->opa_property_values[$ps_property]);
             return $o_timecode_parser->getText('COLON_DELIMITED');
             break;
         default:
             // unsupported property?
             return null;
             break;
     }
 }
 public function parseValue($ps_value, $pa_element_info, $pa_options = null)
 {
     $ps_value = trim($ps_value);
     $va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('dateRangeBoundaries', 'requireValue'));
     $o_tcp = new TimecodeParser();
     if (strlen($ps_value)) {
         if ($o_tcp->parse($ps_value) === false) {
             // invalid timecode
             $this->postError(1970, _t('%1 is invalid', $pa_element_info['displayLabel']), 'TimecodeAttributeValue->parseValue()');
             return false;
         }
         $vn_seconds = (double) $o_tcp->getParsedValueInSeconds();
     } else {
         if (isset($va_settings['requireValue']) && $va_settings['requireValue']) {
             $this->postError(1970, _t('%1 must not be empty', $pa_element_info['displayLabel']), 'DataRangeAttributeValue->parseValue()');
             return false;
         }
         $ps_value = null;
         $vn_seconds = null;
     }
     return array('value_longtext1' => $ps_value, 'value_decimal1' => $vn_seconds);
 }
Esempio n. 6
0
 public function &writePreviews($ps_filepath, $pa_options)
 {
     if (!(bool) $this->opo_config->get("video_preview_generate_frames")) {
         return false;
     }
     if (!isset($pa_options['outputDirectory']) || !$pa_options['outputDirectory'] || !file_exists($pa_options['outputDirectory'])) {
         if (!($vs_tmp_dir = $this->opo_config->get("taskqueue_tmp_directory"))) {
             // no dir
             return false;
         }
     } else {
         $vs_tmp_dir = $pa_options['outputDirectory'];
     }
     $o_tc = new TimecodeParser();
     if (($vn_min_number_of_frames = $pa_options['minNumberOfFrames']) < 1) {
         $vn_min_number_of_frames = 0;
     }
     if (($vn_max_number_of_frames = $pa_options['maxNumberOfFrames']) < 1) {
         $vn_max_number_of_frames = 100;
     }
     $vn_duration = $this->properties["duration"];
     if (!($vn_frame_interval = $o_tc->parse($pa_options['frameInterval']) ? $o_tc->getSeconds() : 0)) {
         $vn_frame_interval = 30;
     }
     if (!($vn_start_at = $o_tc->parse($pa_options['startAtTime']) ? $o_tc->getSeconds() : 0)) {
         $vn_start_at = 0;
     }
     if (!($vn_end_at = $o_tc->parse($pa_options['endAtTime']) ? $o_tc->getSeconds() : 0)) {
         $vn_end_at = 0;
     }
     if (($vn_previewed_duration = $vn_duration - $vn_start_at - $vn_end_at) < 0) {
         $vn_previewed_duration = $vn_duration;
         $vn_start_at = $vn_end_at = 0;
     }
     if ($vn_frame_interval > $vn_previewed_duration) {
         $vn_frame_interval = $vn_previewed_duration;
     }
     $vn_preview_width = isset($pa_options['width']) && (int) $pa_options['width'] > 0 ? (int) $pa_options['width'] : 320;
     $vn_preview_height = isset($pa_options['height']) && (int) $pa_options['height'] > 0 ? (int) $pa_options['height'] : 320;
     $vn_s = $vn_start_at;
     $vn_e = $vn_duration - $vn_end_at;
     $vn_num_frames = $vn_previewed_duration / $vn_frame_interval;
     if ($vn_num_frames < $vn_min_number_of_frames) {
         $vn_frame_interval = $vn_previewed_duration / $vn_min_number_of_frames;
         $vn_num_frames = $vn_min_number_of_frames;
         $vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
     }
     if ($vn_num_frames > $vn_max_number_of_frames) {
         $vn_frame_interval = $vn_previewed_duration / $vn_max_number_of_frames;
         $vn_num_frames = $vn_max_number_of_frames;
         $vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
     }
     $vs_freq = 1 / $vn_frame_interval;
     $vs_output_file_prefix = tempnam($vs_tmp_dir, 'caQuicktimeVRPreview');
     $vs_output_file = $vs_output_file_prefix . '%05d.jpg';
     exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f image2 -r " . $vs_freq . " -ss {$vn_s} -t {$vn_previewed_duration} -s " . $vn_preview_width . "x" . $vn_preview_height . " -y " . caEscapeShellArg($vs_output_file), $va_output, $vn_return);
     $vn_i = 1;
     $va_files = array();
     while (file_exists($vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg')) {
         // add frame to list
         $va_files['' . sprintf("%4.2f", ($vn_i - 1) * $vn_frame_interval + $vn_s) . 's'] = $vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg';
         $vn_i++;
     }
     if (!sizeof($va_files)) {
         $this->postError(1610, _t("Couldn't not write video preview frames to tmp directory (%1)", $vs_tmp_dir), "WLPlugQuicktimeVR->write()");
     }
     @unlink($vs_output_file_prefix);
     return $va_files;
 }
Esempio n. 7
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     $o_tc = new TimecodeParser();
     $vn_start = $vn_end = 0;
     if ($o_tc->parse($ps_start)) {
         $vn_start = (double) $o_tc->getSeconds();
     }
     if ($o_tc->parse($ps_end)) {
         $vn_end = (double) $o_tc->getSeconds();
     }
     if ($vn_end == 0) {
         return null;
     }
     if ($vn_start >= $vn_end) {
         return null;
     }
     $vn_duration = $vn_end - $vn_start;
     exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath), $va_output, $vn_return);
     if ($vn_return != 0) {
         @unlink($filepath . "." . $ext);
         $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugAudio->writeClip()");
         return false;
     }
     return true;
 }
Esempio n. 8
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     if (!caMediaPluginFFmpegInstalled()) {
         return false;
     }
     $o_tc = new TimecodeParser();
     $vn_start = $vn_end = null;
     if ($o_tc->parse($ps_start)) {
         $vn_start = $o_tc->getSeconds();
     }
     if ($o_tc->parse($ps_end)) {
         $vn_end = $o_tc->getSeconds();
     }
     if (!$vn_start || !$vn_end) {
         return null;
     }
     if ($vn_start >= $vn_end) {
         return null;
     }
     $vn_duration = $vn_end - $vn_start;
     exec(caGetExternalApplicationPath('ffmpeg') . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
     if ($vn_return != 0) {
         @unlink($ps_filepath);
         $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()");
         return false;
     }
     return true;
 }