Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Refactor #10038 added sorting when viewing children documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmi3yy committed Aug 3, 2013
1 parent e7ebc83 commit f03791f
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 17 deletions.
63 changes: 58 additions & 5 deletions manager/actions/document_data.static.php
Expand Up @@ -115,15 +115,33 @@
$rs = $modx->db->query($sql);
$numRecords = $modx->db->getRecordCount($rs);

$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'createdon' ;
$dir = isset($_REQUEST['dir'])? $_REQUEST['dir']: 'DESC';

// Get child documents (with paging)
$sql = 'SELECT DISTINCT sc.* '.
'FROM '.$tbl_site_content.' AS sc '.
'LEFT JOIN '.$tbl_document_groups.' AS dg ON dg.document = sc.id '.
'WHERE sc.parent=\''.$content['id'].'\' '.
'AND ('.$access.') '.
'ORDER BY '.$sort.' '.$dir.
$childsTable->handlePaging(); // add limit clause

$filter_sort='';
$filter_dir='';
if ($numRecords > 0) {
$filter_sort='<p><select size="1" name="sort" onchange="document.location=\'index.php?a=3&id='.$id.'&dir='.$dir.'&sort=\'+this.options[this.selectedIndex].value">'.
'<option value="createdon"'.(($sort=='createdon') ? ' selected' : '').'>'.$_lang['createdon'].'</option>'.
'<option value="pub_date"'.(($sort=='pub_date') ? ' selected' : '').'>'.$_lang["page_data_publishdate"].'</option>'.
'<option value="pagetitle"'.(($sort=='pagetitle') ? ' selected' : '').'>'.$_lang['pagetitle'].'</option>'.
'<option value="menuindex"'.(($sort=='menuindex') ? ' selected' : '').'>'.$_lang['resource_opt_menu_index'].'</option>'.
//******** resource_opt_is_published - //
'<option value="published"'.(($sort=='published') ? ' selected' : '').'>'.$_lang['resource_opt_is_published'].'</option>'.
//********//
'</select>';
$filter_dir='<select size="1" name="dir" onchange="document.location=\'index.php?a=3&id='.$id.'&sort='.$sort.'&dir=\'+this.options[this.selectedIndex].value">'.
'<option value="DESC"'.(($dir=='DESC') ? ' selected' : '').'>'.$_lang['sort_desc'].'</option>'.
'<option value="ASC"'.(($dir=='ASC') ? ' selected' : '').'>'.$_lang['sort_asc'].'</option>'.
'</select></p>';
if (!$rs = $modx->db->query($sql)) {
// sql error
$e->setError(1);
Expand Down Expand Up @@ -151,6 +169,8 @@
$listTableHeader = array(
'docid' => $_lang['id'],
'title' => $_lang['resource_title'],
'createdon' => $_lang['createdon'],
'pub_date' => $_lang['page_data_publishdate'],
'status' => $_lang['page_data_status'],
'edit' => $_lang['mgrlog_action'],
);
Expand All @@ -159,17 +179,49 @@

$limitClause = $childsTable->handlePaging();

$sd=isset($_REQUEST['dir'])?'&amp;dir='.$_REQUEST['dir']:'&amp;dir=DESC';
$sb=isset($_REQUEST['sort'])?'&amp;sort='.$_REQUEST['sort']:'&amp;sort=createdon';
$pg=isset($_REQUEST['page'])?'&amp;page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;


$listDocs = array();
foreach($resource as $k => $children){
/*
$listDocs[] = array(
'docid' => $children['id'],
'title' => (($children['deleted'] ? ('<s>'.$children['pagetitle'].'</s>') : ( ($modx->hasPermission('edit_document')) ? ('<a href="index.php?a=27&amp;id='.$children['id'].'">' . $children['pagetitle'] . '</a>') : $children['pagetitle'] ))),
'createdon' => ($modx->toDateFormat($children['createdon']+$server_offset_time,'dateOnly')),
'pub_date' => ($children['pub_date']? ($modx->toDateFormat($children['pub_date']+$server_offset_time,'dateOnly')) : ''),
'status' => ($children['published'] == 0) ? '<span class="unpublishedDoc">'.$_lang['page_data_unpublished'].'</span>' : '<span class="publishedDoc">'.$_lang['page_data_published'].'</span>',
'edit' => (($modx->hasPermission('edit_document')) ? '&nbsp;<a href="index.php?a=27&amp;id='.$children['id'].'" title="'.$_lang['edit'].'"><img src="' . $_style["icons_save"] .'" /></a>&nbsp;<a href="index.php?a=51&amp;id='.$children['id'].'" title="'.$_lang['move'].'"><img
src="' . $_style["icons_move_document"] .'" /></a>&nbsp;<a href="index.php?a=61&amp;id='.$children['id'].'" title="'.$_lang["publish_resource"].'"><img src="' . $_style["icons_publish_document"] .'" /></a>&nbsp;<a
href="index.php?a=62&amp;id='.$children['id'].'" title="'.$_lang["unpublish_resource"].'"><img src="' . $_style["icons_unpublish_resource"] .'" /></a>' : '') .
(($modx->hasPermission('delete_document')) ? '&nbsp;<a href="index.php?a=6&amp;id='.$children['id'].'" title="'.$_lang['delete_resource'].'"><img src="' . $_style["icons_delete_document"] .'" /></a>&nbsp;<a href="index.php?a=63&amp;id='.$children['id'].'" title="'.$_lang['undelete_resource'].'"><img
src="' . $_style["icons_undelete_resource"] .'" /></a>' : ''),
);
*/

// дописываем в заголовок класс для неопубликованных плюс по всем ссылкам обратный путь
// для сохранения сортировки

$listDocs[] = array(
'docid' => $children['id'],
'title' => $children['pagetitle'],
'title' => (($children['deleted'] ? ('<s>'.$children['pagetitle'].'</s>') : ( ($modx->hasPermission('edit_document')) ? ('<a href="index.php?a=27&amp;id='.$children['id'].$add_path.'">' . ($children['published']?$children['pagetitle']:'<span class=unpublish>'.$children['pagetitle'].'</span>') . '</a>') : $children['pagetitle'] ))),
'createdon' => ($modx->toDateFormat($children['createdon']+$server_offset_time,'dateOnly')),
'pub_date' => ($children['pub_date']? ($modx->toDateFormat($children['pub_date']+$server_offset_time,'dateOnly')) : ''),
'status' => ($children['published'] == 0) ? '<span class="unpublishedDoc">'.$_lang['page_data_unpublished'].'</span>' : '<span class="publishedDoc">'.$_lang['page_data_published'].'</span>',
'edit' => '<a href="index.php?a=3&amp;id='.$children['id'].'"><img src="'. $_style["icons_preview_resource"].'" />'.$_lang['view'].'</a>'.(($modx->hasPermission('edit_document')) ? '&nbsp;<a href="index.php?a=27&amp;id='.$children['id'].'"><img src="' . $_style["icons_save"] .'" />'.$_lang['edit'].'</a>&nbsp;<a href="index.php?a=51&amp;id='.$children['id'].'"><img src="' . $_style["icons_move_document"] .'" />'.$_lang['move'].'</a>' : ''),
'edit' => (($modx->hasPermission('edit_document')) ? '&nbsp;<a href="index.php?a=27&amp;id='.$children['id'].$add_path.'" title="'.$_lang['edit'].'"><img src="' . $_style["icons_save"] .'" /></a>&nbsp;<a href="index.php?a=51&amp;id='.$children['id'].$add_path.'" title="'.$_lang['move'].'"><img
src="' . $_style["icons_move_document"] .'" /></a>&nbsp;<a href="index.php?a=61&amp;id='.$children['id'].$add_path.'" title="'.$_lang["publish_resource"].'"><img src="' . $_style["icons_publish_document"] .'" /></a>&nbsp;<a
href="index.php?a=62&amp;id='.$children['id'].$add_path.'" title="'.$_lang["unpublish_resource"].'"><img src="' . $_style["icons_unpublish_resource"] .'" /></a>' : '') .
(($modx->hasPermission('delete_document')) ? '&nbsp;<a href="index.php?a=6&amp;id='.$children['id'].$add_path.'" title="'.$_lang['delete_resource'].'"><img src="' . $_style["icons_delete_document"] .'" /></a>&nbsp;<a href="index.php?a=63&amp;id='.$children['id'].$add_path.'" title="'.$_lang['undelete_resource'].'"><img
src="' . $_style["icons_undelete_resource"] .'" /></a>' : ''),
);

/****************/
}

$childsTable->createPagingNavigation($numRecords,'a=3&amp;id='.$content['id']);
$childsTable->createPagingNavigation($numRecords,'a=3&id='.$content['id'].'&dir='.$dir.'&sort='.$sort);
$children_output = $childsTable->create($listDocs,$listTableHeader,'index.php?a=3&amp;id='.$content['id']);
}
} else {
Expand Down Expand Up @@ -304,7 +356,7 @@ function movedocument() {
<!-- View Children -->
<div class="tab-page" id="tabChildren">
<h2 class="tab"><?php echo $_lang['view_child_resources_in_container']?></h2>
<script type="text/javascript">docSettings.addTabPage( document.getElementById( "tabChildren" ) );</script>
<script type="text/javascript">docSettings.addTabPage( document.getElementById( "tabChildren" ) );docSettings.setSelectedIndex(1);</script>
<?php if ($modx->hasPermission('new_document')) { ?>

<ul class="actionButtons">
Expand All @@ -314,6 +366,7 @@ function movedocument() {
<?php }
if ($numRecords > 0)
echo '<h4><span class="publishedDoc">'.$numRecords.'</span> '.$_lang['resources_in_container'].' (<strong>'.$content['pagetitle'].'</strong>)</h4>'."\n";
echo $filter_sort.$filter_dir;
echo $children_output."\n";
?>
</div><!-- end tab-page -->
Expand Down
32 changes: 27 additions & 5 deletions manager/actions/mutate_content.dynamic.php
@@ -1,6 +1,13 @@
<?php
if (IN_MANAGER_MODE != 'true') die('<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.');

/********************/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;
/*******************/

// check permissions
switch ($_REQUEST['a']) {
case 27:
Expand Down Expand Up @@ -201,13 +208,13 @@ function changestate(element) {

function deletedocument() {
if (confirm("<?php echo $_lang['confirm_delete_resource']?>")==true) {
document.location.href="index.php?id=" + document.mutate.id.value + "&a=6";
document.location.href="index.php?id=" + document.mutate.id.value + "&a=6<?php echo $add_path; ?>";
}
}

function duplicatedocument(){
if(confirm("<?php echo $_lang['confirm_resource_duplicate']?>")==true) {
document.location.href="index.php?id=<?php echo $_REQUEST['id']?>&a=94";
document.location.href="index.php?id=<?php echo $_REQUEST['id']?>&a=94<?php echo $add_path; ?>";
}
}

Expand All @@ -230,7 +237,7 @@ function enableLinkSelection(b) {

function setLink(lId) {
if (!allowLinkSelection) {
window.location.href="index.php?a=3&id="+lId;
window.location.href="index.php?a=3&id="+lId+"<?php echo $add_path; ?>";
return;
}
else {
Expand All @@ -255,7 +262,7 @@ function enableParentSelection(b) {

function setParent(pId, pName) {
if (!allowParentSelection) {
window.location.href="index.php?a=3&id="+pId;
window.location.href="index.php?a=3&id="+pId+"<?php echo $add_path; ?>";
return;
}
else {
Expand Down Expand Up @@ -507,6 +514,13 @@ function decode(s) {
));
if (is_array($evtOut))
echo implode('', $evtOut);

/*************************/
$dir=isset($_REQUEST['dir'])?$_REQUEST['dir']:'';
$sort=isset($_REQUEST['sort'])?$_REQUEST['sort']:'createdon';
$page=isset($_REQUEST['page'])?(int)$_REQUEST['page']:'';
/*************************/

?>
<input type="hidden" name="a" value="5" />
<input type="hidden" name="id" value="<?php echo $content['id']?>" />
Expand All @@ -515,6 +529,14 @@ function decode(s) {
<input type="hidden" name="refresh_preview" value="0" />
<input type="hidden" name="newtemplate" value="" />

<!------------- добавляем параметры сортировки------------------>
<input type="hidden" name="dir" value="<?php echo $dir;?>" />
<input type="hidden" name="sort" value="<?php echo $sort;?>" />
<input type="hidden" name="page" value="<?php echo $page;?>" />
<!-------------- --------------->



<fieldset id="create_edit">
<h1><?php if ($_REQUEST['id']){ echo $_lang['edit_resource_title']; } else { echo $_lang['create_resource_title'];}?></h1>

Expand All @@ -539,7 +561,7 @@ function decode(s) {
<li id="Button6"><a href="#" onclick="duplicatedocument();"><img src="<?php echo $_style["icons_resource_duplicate"] ?>" alt="icons_resource_duplicate" /> <?php echo $_lang['duplicate']?></a></li>
<li id="Button3"><a href="#" onclick="deletedocument();"><img src="<?php echo $_style["icons_delete_document"] ?>" alt="icons_delete_document" /> <?php echo $_lang['delete']?></a></li>
<?php } ?>
<li id="Button4"><a href="#" onclick="documentDirty=false;<?php echo $id==0 ? "document.location.href='index.php?a=2';" : "document.location.href='index.php?a=3&amp;id=$id';"?>"><img alt="icons_cancel" src="<?php echo $_style["icons_cancel"] ?>" /> <?php echo $_lang['cancel']?></a></li>
<li id="Button4"><a href="#" onclick="documentDirty=false;<?php echo $id==0 ? "document.location.href='index.php?a=2';" : "document.location.href='index.php?a=3&amp;id=$id".$add_path."';"?>"><img alt="icons_cancel" src="<?php echo $_style["icons_cancel"] ?>" /> <?php echo $_lang['cancel']?></a></li>
<li id="Button5"><a href="#" onclick="window.open('<?php echo $modx->makeUrl($id); ?>','previeWin');"><img alt="icons_preview_resource" src="<?php echo $_style["icons_preview_resource"] ?>" /> <?php echo $_lang['preview']?></a></li>
</ul>
</div>
Expand Down
10 changes: 9 additions & 1 deletion manager/actions/wait.static.php
@@ -1,5 +1,11 @@
<?php
if(IN_MANAGER_MODE!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
/*********************/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;
/**********************/
?>

<h1><?php echo $_lang['cleaningup']; ?></h1>
Expand All @@ -12,7 +18,9 @@ function goHome() {
<?php if($_REQUEST['r']==10) {?>
top.mainMenu.startrefresh(10);
<?php } elseif($_REQUEST['dv']==1 && $_REQUEST['id']!='') { ?>
document.location.href="index.php?a=3&id=<?php echo $_REQUEST['id']; ?>";
// document.location.href="index.php?a=3&id=<?php echo $_REQUEST['id']; ?>";
//возвращаем куда нужно с учетом сортировки
document.location.href="index.php?a=3&id=<?php echo $_REQUEST['id'].$add_path; ?>";
<?php } else { ?>
document.location.href="index.php?a=2";
<?php } ?>
Expand Down
20 changes: 19 additions & 1 deletion manager/processors/delete_content.processor.php
Expand Up @@ -9,6 +9,19 @@
<?php
// check the document doesn't have any children
$id=intval($_GET['id']);

/*******ищем родителя чтобы к нему вернуться********/
$pid=$modx->db->getValue($modx->db->query("SELECT parent FROM ".$modx->getFullTableName('site_content')." WHERE id=".$id." LIMIT 0,1"));
$pid=($pid==0?$id:$pid);

/************ а заодно и путь возврата (сам путь внизу файла) **********/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;

/*****************************/

$deltime = time();
$children = array();

Expand Down Expand Up @@ -111,7 +124,12 @@ function getChildren($parent) {
$sync->setReport(false);
$sync->emptyCache(); // first empty the cache
// finished emptying cache - redirect
$header="Location: index.php?r=1&a=7&id=$id&dv=1";
// $header="Location: index.php?r=1&a=7&id=$id&dv=1";

//новый путь
$header="Location: index.php?r=1&a=7&id=$pid&dv=1".$add_path;


header($header);
}
?>
21 changes: 20 additions & 1 deletion manager/processors/publish_content.processor.php
Expand Up @@ -7,6 +7,21 @@

$id = $_REQUEST['id'];


/************webber ********/
$pid=$modx->db->getValue($modx->db->query("SELECT parent FROM ".$modx->getFullTableName('site_content')." WHERE id=".$id." LIMIT 0,1"));
$pid=($pid==0?$id:$pid);

/************** webber *************/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;

/***********************************/



// check permissions on the document
include_once "./processors/user_documents_permissions.class.php";
$udperms = new udperms();
Expand Down Expand Up @@ -41,6 +56,10 @@
$sync->setReport(false);
$sync->emptyCache(); // first empty the cache

$header="Location: index.php?r=1&id=$id&a=7";
//$header="Location: index.php?r=1&id=$id&a=7";

// webber
$header="Location: index.php?r=1&id=$pid&a=7&dv=1".$add_path;

header($header);
?>
12 changes: 10 additions & 2 deletions manager/processors/save_content.processor.php
Expand Up @@ -37,6 +37,14 @@
$menutitle = $modx->db->escape($_POST['menutitle']);
$hidemenu = intval($_POST['hidemenu']);

/************* webber ********/
$sd=isset($_POST['dir'])?'&dir='.$_POST['dir']:'&dir=DESC';
$sb=isset($_POST['sort'])?'&sort='.$_POST['sort']:'&sort=pub_date';
$pg=isset($_POST['page'])?'&page='.(int)$_POST['page']:'';
$add_path=$sd.$sb.$pg;



if (trim($pagetitle == "")) {
if ($type == "reference") {
$pagetitle = $_lang['untitled_weblink'];
Expand Down Expand Up @@ -673,9 +681,9 @@
// document
$a = ($_POST['stay'] == '2') ? "27&id=$id" : "4&pid=$parent";
}
$header = "Location: index.php?a=" . $a . "&r=1&stay=" . $_POST['stay'];
$header = "Location: index.php?a=" . $a . "&r=1&stay=" . $_POST['stay'].$add_path;
} else {
$header = "Location: index.php?r=1&id=$id&a=7&dv=1";
$header = "Location: index.php?r=1&id=$id&a=7&dv=1".$add_path;
}
}
header($header);
Expand Down
18 changes: 17 additions & 1 deletion manager/processors/undelete_content.processor.php
Expand Up @@ -7,6 +7,19 @@

$id=$_REQUEST['id'];

/************ webber ********/
$pid=$modx->db->getValue($modx->db->query("SELECT parent FROM ".$modx->getFullTableName('site_content')." WHERE id=".$id." LIMIT 0,1"));
$pid=($pid==0?$id:$pid);

/************** webber *************/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;

/***********************************/


// check permissions on the document
include_once "./processors/user_documents_permissions.class.php";
$udperms = new udperms();
Expand Down Expand Up @@ -86,7 +99,10 @@ function getChildren($parent) {
$sync->setReport(false);
$sync->emptyCache(); // first empty the cache
// finished emptying cache - redirect
$header="Location: index.php?r=1&a=7&id=$id&dv=1";
//$header="Location: index.php?r=1&a=7&id=$id&dv=1";

// webber
$header="Location: index.php?r=1&a=7&id=$pid&dv=1".$add_path;
header($header);
}
?>
21 changes: 20 additions & 1 deletion manager/processors/unpublish_content.processor.php
Expand Up @@ -7,6 +7,20 @@

$id = $_REQUEST['id'];

/************ Webber ********/
$pid=$modx->db->getValue($modx->db->query("SELECT parent FROM ".$modx->getFullTableName('site_content')." WHERE id=".$id." LIMIT 0,1"));
$pid=($pid==0?$id:$pid);

/************** Webber *************/
$sd=isset($_REQUEST['dir'])?'&dir='.$_REQUEST['dir']:'&dir=DESC';
$sb=isset($_REQUEST['sort'])?'&sort='.$_REQUEST['sort']:'&sort=createdon';
$pg=isset($_REQUEST['page'])?'&page='.(int)$_REQUEST['page']:'';
$add_path=$sd.$sb.$pg;

/***********************************/



// check permissions on the document
include_once "./processors/user_documents_permissions.class.php";
$udperms = new udperms();
Expand Down Expand Up @@ -41,6 +55,11 @@
$sync->setReport(false);
$sync->emptyCache(); // first empty the cache

$header="Location: index.php?r=1&id=$id&a=7";
//$header="Location: index.php?r=1&id=$id&a=7";


// Webber
$header="Location: index.php?r=1&id=$pid&a=7&dv=1".$add_path;

header($header);
?>

0 comments on commit f03791f

Please sign in to comment.