/** * Static function to display form for the field type * @param string $name * @param string $value * @param string $css * @return html for the form containing the field */ public static function display_field($name, $value = '', $css = '') { $html = ''; $display_val = ''; if ((int) $value > 0) { $object = new Leads(); $retrun_fields = $object->popup_selection_return_field; $retrun_field_list = explode(",", $retrun_fields); $object->query("select " . $retrun_fields . " from leads where idleads = ?", array($value)); if ($object->getNumRows() > 0) { $object->next(); $cnt_return_fields = 0; foreach ($retrun_field_list as $retrun_fields) { if ($cnt_return_fields > 0) { $display_val .= ' '; } $display_val .= $object->{$retrun_fields}; $cnt_return_fields++; } } } $special_field = false; if (preg_match("/:::/", $name)) { $name_explode = explode(':::', $name); $name = 'lead_' . $name_explode[1]; $special_field = true; } $html .= '<input type="text" class = "' . $css . '" name="lead_' . $name . '" id="lead_' . $name . '" value="' . $display_val . '" readonly>'; $html .= ' <a href="#" id="select_' . $name . '" class="btn btn-primary btn-mini"><i class="icon-white icon-plus-sign"></i></a>'; $html .= ' <a href="#" id="remove_' . $name . '" class="btn btn-primary btn-mini"><i class="icon-white icon-remove"></i></a>'; $html .= '<input type="hidden" name="' . $name . '" id="' . $name . '" value="' . $value . '">'; $html .= "\n" . '<script>'; // add icon click function $html .= '$(\'#select_' . $name . '\').click(function(){ '; if ($special_field === true) { $html .= 'var href = \'/popups/listdata_popup_modal?m=Leads&action=list&fielddisp=lead&special_field=yes&special_field_name=' . $name_explode[1] . '&fieldname=' . $name . '\';'; } else { $html .= 'var href = \'/popups/listdata_popup_modal?m=Leads&action=list&fielddisp=lead&fieldname=' . $name . '\';'; } $html .= "\n" . ' if (href.indexOf(\'#\') == 0) { $(href).modal(\'open\'); } else { $.get(href, function(data) { //ugly heck to prevent the content getting append when opening the same modal multiple time $("#listdata_popup_selector").html(\'\'); $("#listdata_popup_selector").attr("id","ugly_heck"); $(\'<div class="modal hide fade in" id="listdata_popup_selector" style="width:700px;">\' + data + \'</div>\').modal(); }).success(function() { $(\'input:text:visible:first\').focus(); }); } '; $html .= "\n" . '});'; // click function ends here // remove icon click function if ($special_field === true) { $html .= "\n" . '$(\'#remove_' . $name . '\').click( function(){ $("#lead_' . $name . '").attr(\'value\',\'\'); $("#' . $name . '").attr(\'value\',\'\'); $("#' . $name_explode[1] . '").attr(\'value\',\'\'); });'; } else { $html .= "\n" . '$(\'#remove_' . $name . '\').click( function(){ $("#lead_' . $name . '").attr(\'value\',\'\'); $("#' . $name . '").attr(\'value\',\'\'); });'; } // remove icon click function ends here $html .= '</script>'; if ($special_field === true) { return $html; } else { echo $html; } }