Ejemplo n.º 1
0
 public static function encode_var_post($varname, $value)
 {
     //--
     $varname = (string) trim((string) $varname);
     //--
     if ((string) $varname == '') {
         return '';
     }
     //end if
     //--
     $out = '';
     //--
     if (is_array($value)) {
         $arrtype = Smart::array_type_test($value);
         // 0: not an array ; 1: non-associative ; 2:associative
         if ($arrtype === 1) {
             // 1: non-associative
             for ($i = 0; $i < Smart::array_size($value); $i++) {
                 $out .= urlencode($varname) . '[]=' . rawurlencode($value[$i]) . '&';
             }
             //end foreach
         } else {
             // 2: associative
             foreach ($value as $key => $val) {
                 $out .= urlencode($varname) . '[' . rawurlencode($key) . ']=' . rawurlencode($val) . '&';
             }
             //end foreach
         }
         //end if else
     } else {
         $out = urlencode($varname) . '=' . rawurlencode($value) . '&';
     }
     //end if else
     //--
     return (string) $out;
     //--
 }
Ejemplo n.º 2
0
 private static function process_loop_syntax($mtemplate, $y_arr_vars)
 {
     //--
     if (strpos((string) $mtemplate, '[%%%%LOOP:') !== false) {
         //--
         $pattern = '{\\[%%%%LOOP\\:([a-zA-Z0-9_\\-\\.]*)((\\([0-9]*\\))?%%)%%\\](.*)?\\[%%%%\\/LOOP\\:\\1\\2%%\\]}sU';
         $matches = array();
         preg_match_all((string) $pattern, (string) $mtemplate, $matches);
         //echo '<pre>'.htmlspecialchars(print_r($matches,1)).'</pre>'; die();
         //--
         list($orig_part, $var_part, $opt_uniqid, $opt_uniqix, $loop_part) = (array) $matches;
         //--
         for ($i = 0; $i < Smart::array_size($orig_part); $i++) {
             //--
             $bind_var_key = (string) $var_part[$i];
             //--
             if ((string) $bind_var_key != '' and is_array($y_arr_vars[(string) $bind_var_key])) {
                 // if the LOOP is binded to an existing Array Variable and a non-empty KEY
                 //--
                 if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                     self::$MkTplVars['%LOOP:' . $bind_var_key][] = 'Processing LOOP Syntax: ' . Smart::array_size($y_arr_vars[(string) $bind_var_key]);
                 }
                 //end if
                 //--
                 $loop_orig = (string) rtrim((string) $loop_part[$i]);
                 //--
                 $line = '';
                 //--
                 $arrtype = Smart::array_type_test($y_arr_vars[(string) $bind_var_key]);
                 // 0: not an array ; 1: non-associative ; 2:associative
                 //--
                 if ($arrtype === 1) {
                     // 1: non-associative
                     //--
                     for ($j = 0; $j < Smart::array_size($y_arr_vars[(string) $bind_var_key]); $j++) {
                         //-- operate on a copy of original
                         $mks_line = (string) $loop_orig;
                         //-- process IF inside LOOP for this context (the global context is evaluated prior as this function is called after process_if_syntax() in process_syntax() via render_template()
                         $tmp_arr_context = array();
                         if (strpos((string) $mks_line, '[%%%%IF:') !== false) {
                             $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '._-ITERATOR-_')] = (string) $j;
                             if (is_array($y_arr_vars[(string) $bind_var_key][$j])) {
                                 foreach ($y_arr_vars[(string) $bind_var_key][$j] as $key => $val) {
                                     $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '.' . $key)] = $val;
                                 }
                                 //end foreach
                             } else {
                                 $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '._-VAL-_')] = (string) $y_arr_vars[(string) $bind_var_key][$j];
                             }
                             //end if else
                             $mks_line = (string) self::process_if_syntax((string) $mks_line, (array) array_merge((array) $y_arr_vars, (array) $tmp_arr_context), (string) $bind_var_key);
                         }
                         //end if
                         //-- process the loop replacements
                         $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '._-ITERATOR-_'), (string) $j);
                         if (is_array($y_arr_vars[(string) $bind_var_key][$j])) {
                             foreach ($y_arr_vars[(string) $bind_var_key][$j] as $key => $val) {
                                 $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '.' . $key), (string) $val);
                             }
                             //end for
                         } else {
                             $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '._-VAL-_'), (string) $y_arr_vars[(string) $bind_var_key][$j]);
                         }
                         //end if else
                         //-- render
                         $line .= (string) $mks_line;
                         //--
                     }
                     //end for
                     //--
                 } elseif ($arrtype === 2) {
                     // 2: associative
                     //--
                     $j = 0;
                     //--
                     foreach ($y_arr_vars[(string) $bind_var_key] as $zkey => $zval) {
                         //-- operate on a copy of original
                         $mks_line = (string) $loop_orig;
                         //--
                         $ziterator = $j;
                         $j++;
                         //-- process IF inside LOOP for this context (the global context is evaluated prior as this function is called after process_if_syntax() in process_syntax() via render_template()
                         $tmp_arr_context = array();
                         if (strpos((string) $mks_line, '[%%%%IF:') !== false) {
                             $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '._-ITERATOR-_')] = (string) $ziterator;
                             $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '._-KEY-_')] = (string) $zkey;
                             if (is_array($zval)) {
                                 foreach ($zval as $key => $val) {
                                     $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '.' . $key)] = $val;
                                 }
                                 //end foreach
                             } else {
                                 $tmp_arr_context[strtoupper('$$$$' . $bind_var_key . '._-VAL-_')] = (string) $zval;
                             }
                             //end if else
                             $mks_line = (string) self::process_if_syntax((string) $mks_line, (array) array_merge((array) $y_arr_vars, (array) $tmp_arr_context), (string) $bind_var_key);
                         }
                         //end if
                         //-- process the loop replacements
                         $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '._-ITERATOR-_'), (string) $ziterator);
                         $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '._-KEY-_'), (string) $zkey);
                         if (is_array($zval)) {
                             foreach ($zval as $key => $val) {
                                 $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '.' . $key), (string) $val);
                             }
                             //end for
                         } else {
                             $mks_line = (string) self::replace_marker((string) $mks_line, (string) strtoupper($bind_var_key . '._-VAL-_'), (string) $zval);
                         }
                         //end if else
                         //-- render
                         $line .= (string) $mks_line;
                         //--
                     }
                     //end foreach
                     //--
                 }
                 //end if else
                 //--
                 $mtemplate = (string) str_replace((string) $orig_part[$i], (string) $line, (string) $mtemplate);
                 //--
             }
             //end if else
             //--
         }
         //end for
         //--
     }
     //end if
     //--
     return (string) $mtemplate;
     //--
 }
 /**
  * Generate a MULTIPLE (many selections) View/Edit List to manage ID Selections
  *
  * @param STRING			$y_id					the HTML element ID
  * @param STRING 			$y_selected_value		selected value(s) data as ARRAY or STRING list as: '<id1>,<id2>'
  * @param ENUM				$y_mode					'form' = display form | checkboxes | 'list' = display list
  * @param ARRAY				$yarr_data				DATASET ROWS AS: ['id' => 'name', 'id2' => 'name2'] OR ['id', 'name', 'id2', 'name2']
  * @param STRING 			$y_varname				as 'frm[test][]'
  * @param ENUM				$y_draw 				list | checkboxes
  * @param YES/NO 			$y_sync_values			If Yes, sync select similar values used (curently works only for checkboxes)
  * @param INTEGER			$y_dimensions			dimensions in pixels (width or width / (list) height for '#JS-UI#' or '#JS-UI-FILTER#')
  * @param CODE				$y_custom_js			custom js code (Ex: submit on change)
  * @param SPECIAL			$y_extrastyle			Extra Style CSS | '#JS-UI#' or '#JS-UI-FILTER#'
  *
  * @return HTMLCode
  */
 public static function html_multi_select_list($y_id, $y_selected_value, $y_mode, $yarr_data, $y_varname = '', $y_draw = 'list', $y_sync_values = 'no', $y_dimensions = '300/0', $y_custom_js = '', $y_extrastyle = '#JS-UI-FILTER#')
 {
     //-- fix associative array
     $arr_type = Smart::array_type_test($yarr_data);
     if ($arr_type === 2) {
         // associative array detected
         $arr_save = (array) $yarr_data;
         $yarr_data = array();
         foreach ((array) $arr_save as $key => $val) {
             $yarr_data[] = (string) $key;
             $yarr_data[] = (string) $val;
         }
         //end foreach
         $arr_save = array();
     }
     //end if
     //--
     //-- bug fix
     if (Smart::array_size($yarr_data) > 2) {
         $use_multi_list_jq = true;
         $use_multi_list_htm = 'multiple size="8"';
     } else {
         $use_multi_list_jq = false;
         $use_multi_list_htm = 'size="1"';
     }
     //end if else
     //--
     //--
     $tmp_dimens = explode('/', trim((string) $y_dimensions));
     $the_width = (int) $tmp_dimens[0];
     $the_height = (int) $tmp_dimens[1];
     //--
     if ($the_width <= 0) {
         $the_width = 150;
     }
     //end if
     if ($the_height < 0) {
         $the_height = 0;
     }
     //end if
     //--
     //--
     $element_id = Smart::escape_html($y_id);
     //--
     //--
     $css_class = '';
     //--
     if ((string) $element_id != '' && ((string) $y_extrastyle == '#JS-UI#' || (string) $y_extrastyle == '#JS-UI-FILTER#')) {
         //--
         $use_blank_value = 'no';
         //--
         $tmp_extra_style = (string) $y_extrastyle;
         $y_extrastyle = '';
         // reset
         //--
         if ((string) $y_mode == 'form') {
             //--
             if ($the_height > 0) {
                 if ($the_height < 50) {
                     $the_height = 50;
                 }
                 //end if
                 if ($the_height > 200) {
                     $the_height = 200;
                 }
                 //end if
             } else {
                 $the_height = (int) ((Smart::array_size($yarr_data) + 1) * 20);
                 if ($the_height > 200) {
                     $the_height = 200;
                 }
                 //end if
             }
             //end if else
             //--
             if ((string) $tmp_extra_style == '#JS-UI-FILTER#') {
                 $have_filter = true;
                 $the_width += 25;
             } else {
                 $have_filter = false;
             }
             //end if else
             //--
             if ($use_multi_list_jq === false) {
                 $use_blank_value = 'yes';
                 $have_filter = false;
                 // if multi will be enforced to single because of just 2 rows or less, disable filter !
             }
             //end if
             //--
             $js = (string) SmartMarkersTemplating::render_file_template('lib/core/templates/ui-list-multi.inc.htm', ['LANG' => (string) SmartTextTranslations::getLanguage(), 'ID' => (string) $element_id, 'WIDTH' => (int) $the_width, 'HEIGHT' => (int) $the_height, 'USE-JQ' => (bool) $use_multi_list_jq, 'HAVE-FILTER' => (bool) $have_filter], 'yes');
             //--
         }
         //end if
         //--
     } else {
         //--
         $use_blank_value = 'no';
         //--
         $js = '';
         $css_class = 'class="ux-field"';
         //--
     }
     //end if else
     //--
     //--
     $out = '';
     //--
     if ((string) $y_mode == 'form') {
         //--
         if ((string) $y_draw == 'checkboxes') {
             // checkboxes
             $out .= '<input type="hidden" name="' . $y_varname . '" value="">' . "\n";
             // we need a hidden value
         } else {
             // list
             $out .= '<select name="' . $y_varname . '" id="' . $element_id . '" ' . $css_class . ' style="width:' . $the_width . 'px; ' . $y_extrastyle . '" ' . $use_multi_list_htm . ' ' . $y_custom_js . '>' . "\n";
             if ((string) $use_blank_value == 'yes') {
                 $out .= '<option value="">&nbsp;</option>' . "\n";
                 // we need a blank value to unselect
             }
             //end if
         }
         //end if else
         //--
     }
     //end if
     //--
     for ($i = 0; $i < Smart::array_size($yarr_data); $i++) {
         //--
         $i_key = $i;
         $i_val = $i + 1;
         $i = $i + 1;
         //--
         if ((string) $y_mode == 'form') {
             //--
             $tmp_el_id = 'SmartFrameworkComponents_MultiSelect_ID__' . sha1($y_varname . $yarr_data[$i_key]);
             //--
             $tmp_sel = '';
             $tmp_checked = '';
             //--
             if (is_array($y_selected_value)) {
                 //--
                 if (in_array($yarr_data[$i_key], $y_selected_value)) {
                     //--
                     $tmp_sel = ' selected';
                     $tmp_checked = ' checked';
                     //--
                 }
                 //end if
                 //--
             } else {
                 //--
                 if (SmartUnicode::str_icontains($y_selected_value, '<' . $yarr_data[$i_key] . '>')) {
                     // multiple categs as <id1>,<id2>
                     //--
                     $tmp_sel = ' selected';
                     $tmp_checked = ' checked';
                     //--
                 }
                 //end if
                 //--
             }
             //end if
             //--
             if ((string) $y_draw == 'checkboxes') {
                 // checkboxes
                 //--
                 if ((string) $y_sync_values == 'yes') {
                     $tmp_onclick = ' onClick="SmartJS_BrowserUtils.checkAll_CkBoxes(this.form.name, \'' . Smart::escape_html($tmp_el_id) . '\', this.checked);"';
                 } else {
                     $tmp_onclick = '';
                 }
                 //end if else
                 //--
                 $out .= '<input type="checkbox" name="' . $y_varname . '" id="' . Smart::escape_html($tmp_el_id) . '" value="' . Smart::escape_html($yarr_data[$i_key]) . '"' . $tmp_checked . $tmp_onclick . '>';
                 $out .= ' &nbsp; ' . Smart::escape_html($yarr_data[$i_val]) . '<br>';
                 //--
             } else {
                 // list
                 //--
                 if ((string) $yarr_data[$i_key] == '#OPTGROUP#') {
                     $out .= '<optgroup label="' . Smart::escape_html($yarr_data[$i_val]) . '">' . "\n";
                     // the optgroup
                 } else {
                     $out .= '<option value="' . Smart::escape_html($yarr_data[$i_key]) . '"' . $tmp_sel . '>&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '</option>' . "\n";
                 }
                 //end if else
                 //--
             }
             //end if else
             //--
         } else {
             //--
             if (is_array($y_selected_value)) {
                 //--
                 if (in_array($yarr_data[$i_key], $y_selected_value)) {
                     //--
                     $out .= '&middot;&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '<br>' . "\n";
                     //--
                 }
                 //end if
                 //--
             } else {
                 //--
                 if (SmartUnicode::str_icontains($y_selected_value, '<' . $yarr_data[$i_key] . '>')) {
                     //-- multiple categs as <id1>,<id2>
                     $out .= '&middot;&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '<br>' . "\n";
                     //--
                 }
                 // end if
                 //--
             }
             //end if else
             //--
         }
         //end if else
         //--
     }
     //end for
     //--
     if ((string) $y_mode == 'form') {
         //--
         if ((string) $y_draw == 'checkboxes') {
             // checkboxes
             $out .= '<br>' . "\n";
         } else {
             // list
             $out .= '</select>' . "\n";
             $out .= $js . "\n";
         }
         //end if else
         //--
     }
     //end if
     //--
     //--
     return $out;
     //--
 }
Ejemplo n.º 4
0
 private function create_from_array($y_array)
 {
     //--
     if (!is_array($y_array)) {
         Smart::log_warning('SmartXmlComposer / create_from_array expects an Array as parameter ...');
         return '<error>XML Writer requires an Array as parameter</error>';
     }
     //end if
     //--
     //--
     $out = '';
     //--
     $arrtype = Smart::array_type_test($y_array);
     // 0: not an array ; 1: non-associative ; 2: associative
     //--
     foreach ($y_array as $key => $val) {
         //--
         if ($arrtype === 2) {
             // fix keys for associative array
             if (is_numeric($key) or (string) $key == '') {
                 $key = (string) '_' . $key;
                 // numeric or empty keys are not allowed: _#
             }
             //end if
         }
         //end if
         //--
         if (is_array($val)) {
             if (is_numeric($key)) {
                 // this can happen only if non-associative array as for associative arrays the numeric key is fixed above as _#
                 $out .= $this->create_from_array($val);
             } else {
                 $out .= '<' . Smart::escape_html($key) . '>' . "\n" . $this->create_from_array($val) . '</' . Smart::escape_html($key) . '>' . "\n";
             }
             //end if else
         } elseif ((string) $val != '') {
             $out .= '<' . Smart::escape_html($key) . '>' . Smart::escape_html($val) . '</' . Smart::escape_html($key) . '>' . "\n";
         } else {
             $out .= '<' . Smart::escape_html($key) . ' />' . "\n";
         }
         //end if else
         //--
     }
     //end foreach
     //--
     //--
     return (string) $out;
     //--
 }