PHP
Same structure as above :
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
$input = Factory::getApplication()->input;
$db = JFactory::getDbo();
$user = Factory::getUser();
/* When a form editing page is loaded */
if ($input->get('option', '', 'string') == 'com_chronoforms7' && $input->get('act', '', 'string') == 'edit'){
$cfid=$input->get('id', '', 'string');
$query = "SELECT * FROM #__chronog3_toggle_area WHERE uid = $user->id AND cfid = $cfid ORDER BY sort ASC";
$db->setQuery($query);
$areas = $db->loadAssocList();
$js='jQuery(document).ready(function($) {
$("#header").append(\'\');';
foreach ($areas as $key => $area){
if($area['open']==1){$js.='$(".unit_container[data-count='.$area['count'].'] .unit_area[data-areakey='.$area['areakey'].']").addClass("open"); ';}
else{$js.='$(".unit_container[data-count='.$area['count'].'] .unit_area[data-areakey='.$area['areakey'].']").removeClass("open"); ';}
}
$js.='});';
$document = JFactory::getDocument();
$document->addScriptDeclaration($js);
}
in the append section, please put a hidden input with id = " uid " and value = $ user - > i d
For obvious security reasons, the editor does not want it here.
Then ...
/* When an area gets hidden/closed */
if ($input->get('run', '', 'string') == 'chrono_plus'){
$cfid=$input->get('cfid', '', 'string');
$uid = $input->post->get("uid", '', 'string');
$unit_areas = json_decode($input->post->get("unit_areas", '', 'string'),true);
foreach ($unit_areas as $skey => $areas ){
foreach ($areas as $count => $area ){
foreach ($area as $areakey => $open ){
$query = "INSERT INTO #__chronog3_toggle_area (uid,sort,cfid,count,areakey,open) VALUES ($uid,$skey,$cfid,$count,$areakey,$open) ON DUPLICATE KEY UPDATE open = $open, sort = $skey";
$db->setQuery($query)->execute();
}
}
}
jexit();
}
Sorry for the series of nested foreach constructs. If someone sees a neater way to do it, please share it !