Skip to content

Instantly share code, notes, and snippets.

@alooze
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save alooze/9814345 to your computer and use it in GitHub Desktop.

Select an option

Save alooze/9814345 to your computer and use it in GitHub Desktop.
//<?php
/**
* saveAuthor plugin
* @settings &tvid=TV ID для вывода списка пользователей;int;
* @event OnDocFormSave, OnDocFormRender
*/
$e = $modx->Event;
switch ($e->name) {
case 'OnDocFormSave':
if (!isset($_POST['tv'.$tvid]) || intval($_POST['tv'.$tvid]) == 0) return;
$modx->db->update(array('createdby'=>intval($_POST['tv'.$tvid]),
'editedby'=>intval($_POST['tv'.$tvid])),
$modx->getFullTableName('site_content'),
'id='.$id);
return;
break;
case 'OnDocFormRender':
if (!isset($id) || intval($id) < 1) {
$retStr = 'Документ еще не сохранялся';
} else {
$res = $modx->db->select('createdby', $modx->getFullTableName('site_content'), 'id='.$id);
$dAr = $modx->db->getRow($res);
$curUid = $dAr['createdby'];
if (intval($curUid) < 0) {
//это вебюзер
$uAr = $modx->getWebuserInfo(-$curUid);
} else {
//это менеджер
$uAr = $modx->getUserInfo($curUid);
}
$retStr = '<p>*Текущий сохраненный автор: '.$uAr['fullname'].'('.$uAr['email'].')</p>';
}
$e->output('
<!-- Уточняем текущего пользователя -->
<script>
$j(document).ready(function(){
$j("#tv'.$tvid.'").after("'.$retStr.'");
});
</script>
<!-- END Уточняем текущего пользователя -->
');
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment