getPath( 'class', 'com_chronocontact' ) ); // the class name must be the same as the file name without the .php at the end class cf_profile { //the next four fields must be defined for every plugin var $result_TITLE = "Profile page"; var $result_TOOLTIP = "Load data from any table to be shown on the form page using a very simple method! All you need to do is to put the field name between { and } , then it will be replaced by the same field value from the table"; var $plugin_name = "cf_profile"; // must be the same as the class name var $event = "ONLOAD"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD // the next function must exist and will have the backend config code function show_conf($row, $id, $form_id, $option) { global $mainframe; require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'plugin.php'); $helper = new ChronoContactHelperPlugin(); // identify and initialise the parameters used in this plugin $params_array = array( 'table_name' => '', 'field_name' => '', 'parameter' => '', 'editable' => '0', 'evaluate' => '0' ); $params = $helper->loadParams($row, $params_array); $tables = $db->getTableList(); $script .= " function loadfields2() { var table = $('table_name').value; var test = $('field_name').getParent(); if (table == '' || table == '--?--' ) { test.setHTML('
Please select table name first
') return false; } var url = 'index3.php?option=com_chronocontact&task=ajax&plugin=cf_profile&method=ajaxFields&format=raw'; myAjax = new Ajax(url, { method: 'post', postBody: 'table='+table, onRequest: function() { test.setHTML('
Loading . . .
') }, onSuccess: function(req) { test = $('field_name').getParent(); test.setHTML('
'); test = $('field_name').getParent(); test.setHTML(req); } }).request(); } "; ?>
startPane("cf_profile"); echo $pane->startPanel( 'Configure', 'Configure' ); ?> createHeaderTD('Configure Profile Table plugin', '', true, $attribs['header']); echo $helper->openTableLegend('Configure Profile Table plugin'); $tooltip = "Choose the table to get the data from."; foreach ( $tables as $k => $table ) { $tables_array[$table] = JHTML::_('select.option', JText::_($table)); } $input = $helper->createSelectTD('Table name', 'params[table_name]', $tables_array, $params->get('table_name'), array('onChange' => 'loadfields2()', 'class' => 'cf_select'), $tooltip, 'table_name' ); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "The table column name which to be matched by the parameter; for best results, this field must be UNIQUE"; if ( $id == 0 ) { $input = $helper->createTextTD('Target field name', '
Select Table name first
', '', $tooltip); } else { $input = ""; $fields_array = array(); $table_fields = $db->getTableFields( $params->get('table_name') ); foreach ( $table_fields[$params->get('table_name')] as $k => $v) { $fields_array[$k] = JHTML::_('select.option', JText::_($k)); } $input = $helper->createSelectTD('Target field name', 'params[field_name]', $fields_array, $params->get('field_name'), array('class' => 'cf_select'), $tooltip, 'field_name' ); } echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "The name of the parameter provided in the page url e.g. userid=128."; $input = $helper->createInputTD("'Request' parameter name", 'params[parameter]', $params->get('parameter'), '', $attribs['input'], $tooltip); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "This will be the default value of the requested parameter in case nothing was in the request!"; $input = $helper->createInputTD("Default Request Parameter value", 'params[default_param_value]', $params->get('default_param_value'), '', $attribs['input'], $tooltip); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "The type of ordering for the records loaded, this will control if the first or last record is loaded in case the query meets more than 1 record"; $input = $helper->createSelectTD("Oder type", 'params[ordertype]', array("ASC" => JHTML::_('select.option', JText::_("ASC")), "DESC" => JHTML::_('select.option', JText::_("DESC"))), $params->get('ordertype', 'ASC'), array('class' => 'cf_select'), $tooltip, 'ordertype'); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "Will this profile page be editable by users?"; $input = $helper->createYesNoTD("Editable", "params[editable]", '', $params->get('editable', '0'), '', $tooltip); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "Skip populating these fields"; $input = $helper->createInputTD("Skipped fields list", 'params[skippedarray]', $params->get('skippedarray'), '', $attribs['input'], $tooltip); echo $helper->wrapTR($input, array('class' => 'cf_config')); $tooltip = "Will the profile page evaluate code before doing its routine? This may need to be enabled if you are generating some fields using PHP and want to load their data!?"; $input = $helper->createYesNoTD("Evaluate code", "params[evaluate]", '', $params->get('evaluate', '0'), '', $tooltip); echo $helper->wrapTR($input, array('class' => 'cf_config')); echo $helper->closeTableLegend(); ?> $id, 'form_id' => $form_id, 'name' => $this->plugin_name, 'event' => $this->event, 'option' => $option, 'task' => 'save_conf'); echo $helper->createHiddenArray( $hidden_array ); echo $pane->endPanel(); echo $pane->startPanel( 'Help', "help" ); ?> createHeaderTD('Help for Profile Table plugin', '', true, $attribs['header']); echo $helper->wrapTR($input); ?>
The plugin allows you to read values from any table in the database and include them in your form.
It was originally designed to allow access to the jos_users table to create member profiles but it is capable of much more.
To use the plugin effectively you will need to call the form from a link on your site. This could be from - for example a list of users, or topics, or events where you have some related information in a database table.
  • Choose the table you want to use in the first drop-down e.g. jos_users to get a user's name and email.
  • Select a field or column name from the table in the second drop down. This should be a field that will uniquely identify the record you want to use e.g. 'id' or 'username' for the jos_user table. NB This drop-down will not appear until you select a table in the first drop-down.
  • In the Target field name box put the name of the field you will use to identify the record e.g. user_id. You will need to add this field to a url calling the form e.g. . . . &chronoformname=my_form&user_id=99
  • You can then use information from this record in your form by putting {column_name} where you want it to appear e.g. {name} for a users name from the jos_users table.
  • Once this plugin is configured you must enable it in the Form 'Plugins'' tab.
endPanel(); echo $pane->endPane(); ?>
addStyleDeclaration($style); if ( $script ) $doc->addScriptDeclaration($script); } /** * The function executed when the form is loaded * Returns an amended $html_string * */ function onload( $option, $pluginrow, $params, $html_string ) { global $mainframe; $my =& JFactory::getUser(); $database =& JFactory::getDBO(); //$parid = JRequest::getVar($params->parameter, '', 'request', 'int', 0 ); if ( $params->get('evaluate') ) { ob_start(); eval( "?>".$html_string ); $html_string = ob_get_clean(); } $parid = JRequest::getVar($params->get('parameter')); if ( $parid ) { $record_id = $parid; } else if ( $params->get('default_param_value') ) { $record_id = $params->get('default_param_value'); } else { $record_id = $my->id; if ( $record_id == 0 ) { //$record_id = '##guest##'; } } if ( !$record_id ) { $result = $database->getTableFields( $params->get('table_name', '#__users') ); $table_fields = array_keys($result[$params->get('table_name', '#__users')]); foreach ( $table_fields as $table_field ) { $html_string = str_replace("{".$table_field."}", '', $html_string); } } else { $query = "SELECT * FROM `".$params->get('table_name')."` WHERE `".$params->get('field_name')."` = '$record_id' ORDER BY `".$params->get('field_name')."` ".$params->get('ordertype', 'ASC').";"; //$mainframe->enqueuemessage($query); $database->setQuery($query); $row = $database->loadObject(); if($row){ $tables = array( $params->get('table_name') ); $result = $database->getTableFields( $tables ); $table_fields = array_keys($result[$params->get('table_name')]); foreach ( $table_fields as $table_field ) { $html_string = str_replace("{".$table_field."}", $row->$table_field, $html_string); } }else{ $tables = array( $params->get('table_name') ); $result = $database->getTableFields( $tables ); $table_fields = array_keys($result[$params->get('table_name')]); foreach ( $table_fields as $table_field ) { $html_string = str_replace("{".$table_field."}", '', $html_string); } } } if ( $params->get('editable') ) { $query = "SELECT * FROM `".$params->get('table_name')."` WHERE `".$params->get('field_name')."` = '$record_id' ORDER BY `".$params->get('field_name')."` ".$params->get('ordertype', 'ASC').";"; $database->setQuery($query); $datarow = $database->loadAssoc(); $formname = JRequest::getVar( 'chronoformname'); if ( !$formname ) { $params =& $mainframe->getPageParameters('com_chronocontact'); $formname = $params->get('formname'); } $MyForm =& CFChronoForm::getInstance($formname); $MyForm->posted = $datarow; $skippedarray = explode(",", $params->get('skippedarray')); //get all fields names preg_match_all('/name=("|\')([^(>|"|\')]*?)("|\')/i', $html_string, $fieldsnamesmatches); $allfieldsnames = array(); foreach ( $fieldsnamesmatches[2] as $fieldsnamesmatche ) { if ( strpos($fieldsnamesmatche, '[]') ) { $fieldsnamesmatche = str_replace('[]', '', $fieldsnamesmatche); } $allfieldsnames[] = trim($fieldsnamesmatche); } $allfieldsnames = array_unique($allfieldsnames); //print_r($allfieldsnames ); foreach($allfieldsnames as $allfieldsname){ if(!isset($MyForm->posted[$allfieldsname])){ $MyForm->posted[$allfieldsname] = ''; }else{ $MyForm->posted[$allfieldsname] = htmlentities($MyForm->posted[$allfieldsname], ENT_QUOTES, 'UTF-8'); } } //end fields names if ( count($datarow) ) { //text fields $pattern_input = '/]*?)type=("|\')(text|password)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ( $matches[0] as $match ) { $pattern_value = '/value=("|\')(.*?)("|\')/i'; $pattern_name = '/name=("|\')(.*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if(!in_array($matches_name[2], $skippedarray)){ $valuematch = preg_replace($pattern_value, '', $match); $namematch = preg_replace($pattern_name, 'name="${2}" value="posted[\'${2}\']; ?>"', $valuematch); $html_string = str_replace($match, $namematch, $html_string); } } //hidden fields $pattern_input = '/]*?)type=("|\')hidden("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_value = '/value=("|\')(.*?)("|\')/i'; $pattern_name = '/name=("|\')(.*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if(!in_array($matches_name[2], $skippedarray)){ $valuematch = preg_replace($pattern_value, '', $match); $namematch = preg_replace($pattern_name, 'name="${2}" value="posted[\'${2}\']; ?>"', $valuematch); $html_string = str_replace($match, $namematch, $html_string); } } //checkboxes or radios fields $pattern_input = '/]*?)type=("|\')(checkbox|radio)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_value = '/value=("|\')(.*?)("|\')/i'; $pattern_name = '/name=("|\')(.*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); preg_match($pattern_value, $match, $matches_value); if ( !in_array(str_replace('[]', '', $matches_name[2]), $skippedarray) ) { //multi values if ( strpos($matches_name[2], '[]') ) { $namematch = preg_replace($this->skipregex($pattern_name), 'name="${2}" posted["'.str_replace('[]', '', $matches_name[2]).'"])))echo \'checked="checked"\'; ?>', $match); //single values } else { $namematch = preg_replace($pattern_name, 'name="${2}" posted["'.$matches_name[2].'"] == "'.$matches_value[2].'")echo \'checked="checked"\'; ?>', $match); } $html_string = str_replace($match, $namematch, $html_string); } } //textarea fields $pattern_textarea = '/]*?)>(.*?)<\/textarea>/is'; $matches = array(); preg_match_all($pattern_textarea, $html_string, $matches); $namematch = ''; foreach ( $matches[0] as $match ) { $pattern_value = '/value=("|\')(.*?)("|\')/i'; $pattern_name = '/name=("|\')(.*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if(!in_array($matches_name[2], $skippedarray)){ $pattern_textarea2 = '/()(.*?)(<\/textarea>)/is'; $newtextarea_match = preg_replace($pattern_textarea2, '${1}posted[\''.$matches_name[2].'\']; ?>${4}', $match); $html_string = str_replace($match, $newtextarea_match, $html_string); } } //select boxes $pattern_select = '//is'; $matches = array(); preg_match_all($pattern_select, $html_string, $matches); foreach ($matches[0] as $match) { $selectmatch = $match; $pattern_select2 = '/]*?)>/is'; preg_match_all($pattern_select2, $match, $matches2); $options = preg_replace(array('/'.$this->skipregex($matches2[0][0]).'/is', '/<\/select>/i'), array('', ''), $match); $pattern_name = '/name=("|\')(.*?)("|\')/i'; preg_match($pattern_name, $matches2[0][0], $matches_name); if(!in_array(str_replace('[]', '', $matches_name[2]), $skippedarray)){ //multi select if(strpos($matches_name[2], '[]')){ $pattern_options = '//is'; preg_match_all($pattern_options, $options, $matches_options); foreach($matches_options[0] as $matches_option){ $pattern_value = '/value=("|\')(.*?)("|\')/i'; preg_match($pattern_value, $matches_option, $matches_value); $optionmatch = preg_replace('/