function AjaxImageSelector(&$p, $image_name, $table, $table_row_id, $field, $value, $length = 20, $none = TRUE) { global $ajax_image_selector_id; $ajax_image_selector_id++; $a_id = $ajax_image_selector_id; global $database; $fileimage_model = new FileImage($database); $p->HTML('<div class="formemphasis2 wide">'); $p->HTML('<table width="100%"><tr class="no-hover"><td width="300" class="no-hover" id="ajax-image-preview' . $a_id . '">'); $p->HTML('<h3>' . $image_name . '</h3>'); $icon = NULL; if (intval($value) > 0) { $icon = $fileimage_model->GetAll($value); } if (false_or_null($icon)) { $p->HTML('No image.'); } else { $p->HTML('<img src="' . $fileimage_model->ThumbName($icon, 256) . '"><BR>' . $icon['File']['Name']); } $p->HTML('</td><td class="no-hover" width="*">'); AJAXSelector($p, 1, $length, "ajax_image_preview_" . $a_id); $p->HTML('</td></tr></table>'); $p->HTML('</div>'); $p->JS(' function ajax_image_preview_' . $a_id . '( fileimage_id ) { $.ajax({ dataType: "html", url: "ajax.bound", data: {T:"' . $table . '",F:"' . $field . '",V:fileimage_id,I:' . $table_row_id . '}, success: function(d) { } }); $.ajax({ dataType: "html", url: "ajax.html.stat", data: {T:"FileImage",I:fileimage_id,X:256}, success: function(d) { $("#ajax-image-preview' . $a_id . '").html("<h3>' . $image_name . '</h3>"+d); } }); } '); if ($none === TRUE) { $p->HTML('<button id="image-remove-' . $a_id . '" class="buttonlink"><span class="fa fa-sign-out"></span> Remove Image</button>'); $p->JQ(' $("#image-remove-' . $a_id . '").on("click",function(e){ajax_image_preview_' . $a_id . '(0);}); '); } }