Skip to content

Instantly share code, notes, and snippets.

@delphinpro
Created January 29, 2018 22:11
Show Gist options
  • Save delphinpro/5c47199e4b2b3d594e15ab83cbd4776b to your computer and use it in GitHub Desktop.
Save delphinpro/5c47199e4b2b3d594e15ab83cbd4776b to your computer and use it in GitHub Desktop.
CfgTv plugin for ModX
<?php
$e =& $modx->event;
switch ($e->name ) {
case 'OnBeforeDocFormSave':
//$logFile = MODX_BASE_PATH . DIRECTORY_SEPARATOR . 'CfgTv.log';
//file_put_contents($logFile, '');
$list_id = explode(',', $ids);
if (!in_array($_POST['id'], $list_id)) return;
$SQL = "SELECT * FROM ".$modx->getFullTableName('site_tmplvars').";";
$result = $modx->db->query($SQL);
while($row=$modx->db->getRow($result)) {
$TVNAME[ $row['id'] ] = $row['name'];
}
foreach($_POST as $key => $value){
if (substr($key, 0, 2) != 'tv') continue;
$id = substr($key, 2, strlen($key));
$name = $TVNAME[$id];
if (substr($name, 0, strlen($prefix)) != $prefix) continue;
//$name = $prefix.$TVNAME[$id];
//file_put_contents($logFile, $key.' ( '.$name.' ) = '.$value.PHP_EOL, FILE_APPEND);
$settings[$name] = $value;
$SQL = "SELECT * FROM ".$modx->getFullTableName('system_settings')." WHERE `setting_name`='".$name."'";
$count = $modx->db->getRow($modx->db->query($SQL));
if (!empty($count['setting_name'])){
$SQL = "UPDATE ".$modx->getFullTableName('system_settings')." SET `setting_value`='".$value."' WHERE `setting_name`='".$name."'";
$modx->db->query($SQL);
} else {
$SQL = "INSERT into ".$modx->getFullTableName('system_settings')." SET `setting_name`='".$name."',`setting_value`='".$value."'";
$modx->db->query($SQL);
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment