Completed
Pull Request — develop (#691)
by
unknown
07:36
created
manager/actions/mutate_content.dynamic.php 1 patch
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
-	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
3
+    die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 
6 6
 /********************/
@@ -12,30 +12,30 @@  discard block
 block discarded – undo
12 12
 
13 13
 // check permissions
14 14
 switch($modx->manager->action) {
15
-	case 27:
16
-		if(!$modx->hasPermission('edit_document')) {
17
-			$modx->webAlertAndQuit($_lang["error_no_privileges"]);
18
-		}
19
-		break;
20
-	case 85:
21
-	case 72:
22
-	case 4:
23
-		if(!$modx->hasPermission('new_document')) {
24
-			$modx->webAlertAndQuit($_lang["error_no_privileges"]);
25
-		} elseif(isset($_REQUEST['pid']) && $_REQUEST['pid'] != '0') {
26
-			// check user has permissions for parent
27
-			include_once(MODX_MANAGER_PATH . 'processors/user_documents_permissions.class.php');
28
-			$udperms = new udperms();
29
-			$udperms->user = $modx->getLoginUserID();
30
-			$udperms->document = empty($_REQUEST['pid']) ? 0 : $_REQUEST['pid'];
31
-			$udperms->role = $_SESSION['mgrRole'];
32
-			if(!$udperms->checkPermissions()) {
33
-				$modx->webAlertAndQuit($_lang["access_permission_denied"]);
34
-			}
35
-		}
36
-		break;
37
-	default:
38
-		$modx->webAlertAndQuit($_lang["error_no_privileges"]);
15
+    case 27:
16
+        if(!$modx->hasPermission('edit_document')) {
17
+            $modx->webAlertAndQuit($_lang["error_no_privileges"]);
18
+        }
19
+        break;
20
+    case 85:
21
+    case 72:
22
+    case 4:
23
+        if(!$modx->hasPermission('new_document')) {
24
+            $modx->webAlertAndQuit($_lang["error_no_privileges"]);
25
+        } elseif(isset($_REQUEST['pid']) && $_REQUEST['pid'] != '0') {
26
+            // check user has permissions for parent
27
+            include_once(MODX_MANAGER_PATH . 'processors/user_documents_permissions.class.php');
28
+            $udperms = new udperms();
29
+            $udperms->user = $modx->getLoginUserID();
30
+            $udperms->document = empty($_REQUEST['pid']) ? 0 : $_REQUEST['pid'];
31
+            $udperms->role = $_SESSION['mgrRole'];
32
+            if(!$udperms->checkPermissions()) {
33
+                $modx->webAlertAndQuit($_lang["access_permission_denied"]);
34
+            }
35
+        }
36
+        break;
37
+    default:
38
+        $modx->webAlertAndQuit($_lang["error_no_privileges"]);
39 39
 }
40 40
 
41 41
 $id = isset($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;
@@ -54,22 +54,22 @@  discard block
 block discarded – undo
54 54
 $tbl_site_tmplvars = $modx->getFullTableName('site_tmplvars');
55 55
 
56 56
 if($modx->manager->action == 27) {
57
-	//editing an existing document
58
-	// check permissions on the document
59
-	include_once(MODX_MANAGER_PATH . 'processors/user_documents_permissions.class.php');
60
-	$udperms = new udperms();
61
-	$udperms->user = $modx->getLoginUserID();
62
-	$udperms->document = $id;
63
-	$udperms->role = $_SESSION['mgrRole'];
64
-
65
-	if(!$udperms->checkPermissions()) {
66
-		$modx->webAlertAndQuit($_lang["access_permission_denied"]);
67
-	}
57
+    //editing an existing document
58
+    // check permissions on the document
59
+    include_once(MODX_MANAGER_PATH . 'processors/user_documents_permissions.class.php');
60
+    $udperms = new udperms();
61
+    $udperms->user = $modx->getLoginUserID();
62
+    $udperms->document = $id;
63
+    $udperms->role = $_SESSION['mgrRole'];
64
+
65
+    if(!$udperms->checkPermissions()) {
66
+        $modx->webAlertAndQuit($_lang["access_permission_denied"]);
67
+    }
68 68
 }
69 69
 
70 70
 // check to see if resource isn't locked
71 71
 if($lockedEl = $modx->elementIsLocked(7, $id)) {
72
-	$modx->webAlertAndQuit(sprintf($_lang['lock_msg'], $lockedEl['username'], $_lang['resource']));
72
+    $modx->webAlertAndQuit(sprintf($_lang['lock_msg'], $lockedEl['username'], $_lang['resource']));
73 73
 }
74 74
 // end check for lock
75 75
 
@@ -78,74 +78,74 @@  discard block
 block discarded – undo
78 78
 
79 79
 // get document groups for current user
80 80
 if($_SESSION['mgrDocgroups']) {
81
-	$docgrp = implode(',', $_SESSION['mgrDocgroups']);
81
+    $docgrp = implode(',', $_SESSION['mgrDocgroups']);
82 82
 }
83 83
 
84 84
 if(!empty ($id)) {
85
-	$access = sprintf("1='%s' OR sc.privatemgr=0", $_SESSION['mgrRole']);
86
-	if($docgrp) {
87
-		$access .= " OR dg.document_group IN ({$docgrp})";
88
-	}
89
-	$rs = $modx->db->select('sc.*', "{$tbl_site_content} AS sc LEFT JOIN {$tbl_document_groups} AS dg ON dg.document=sc.id", "sc.id='{$id}' AND ({$access})");
90
-	$content = array();
91
-	$content = $modx->db->getRow($rs);
92
-	$modx->documentObject = &$content;
93
-	if(!$content) {
94
-		$modx->webAlertAndQuit($_lang["access_permission_denied"]);
95
-	}
96
-	$_SESSION['itemname'] = $content['pagetitle'];
85
+    $access = sprintf("1='%s' OR sc.privatemgr=0", $_SESSION['mgrRole']);
86
+    if($docgrp) {
87
+        $access .= " OR dg.document_group IN ({$docgrp})";
88
+    }
89
+    $rs = $modx->db->select('sc.*', "{$tbl_site_content} AS sc LEFT JOIN {$tbl_document_groups} AS dg ON dg.document=sc.id", "sc.id='{$id}' AND ({$access})");
90
+    $content = array();
91
+    $content = $modx->db->getRow($rs);
92
+    $modx->documentObject = &$content;
93
+    if(!$content) {
94
+        $modx->webAlertAndQuit($_lang["access_permission_denied"]);
95
+    }
96
+    $_SESSION['itemname'] = $content['pagetitle'];
97 97
 } else {
98
-	$content = array();
98
+    $content = array();
99 99
 
100
-	if(isset($_REQUEST['newtemplate'])) {
101
-		$content['template'] = $_REQUEST['newtemplate'];
102
-	} else {
103
-		$content['template'] = getDefaultTemplate();
104
-	}
100
+    if(isset($_REQUEST['newtemplate'])) {
101
+        $content['template'] = $_REQUEST['newtemplate'];
102
+    } else {
103
+        $content['template'] = getDefaultTemplate();
104
+    }
105 105
 
106
-	$_SESSION['itemname'] = $_lang["new_resource"];
106
+    $_SESSION['itemname'] = $_lang["new_resource"];
107 107
 }
108 108
 
109 109
 // restore saved form
110 110
 $formRestored = $modx->manager->loadFormValues();
111 111
 if(isset($_REQUEST['newtemplate'])) {
112
-	$formRestored = true;
112
+    $formRestored = true;
113 113
 }
114 114
 
115 115
 // retain form values if template was changed
116 116
 // edited to convert pub_date and unpub_date
117 117
 // sottwell 02-09-2006
118 118
 if($formRestored == true) {
119
-	$content = array_merge($content, $_POST);
120
-	$content['content'] = $_POST['ta'];
121
-	if(empty ($content['pub_date'])) {
122
-		unset ($content['pub_date']);
123
-	} else {
124
-		$content['pub_date'] = $modx->toTimeStamp($content['pub_date']);
125
-	}
126
-	if(empty ($content['unpub_date'])) {
127
-		unset ($content['unpub_date']);
128
-	} else {
129
-		$content['unpub_date'] = $modx->toTimeStamp($content['unpub_date']);
130
-	}
119
+    $content = array_merge($content, $_POST);
120
+    $content['content'] = $_POST['ta'];
121
+    if(empty ($content['pub_date'])) {
122
+        unset ($content['pub_date']);
123
+    } else {
124
+        $content['pub_date'] = $modx->toTimeStamp($content['pub_date']);
125
+    }
126
+    if(empty ($content['unpub_date'])) {
127
+        unset ($content['unpub_date']);
128
+    } else {
129
+        $content['unpub_date'] = $modx->toTimeStamp($content['unpub_date']);
130
+    }
131 131
 }
132 132
 
133 133
 // increase menu index if this is a new document
134 134
 if(!isset ($_REQUEST['id'])) {
135
-	if(!isset ($modx->config['auto_menuindex'])) {
136
-		$modx->config['auto_menuindex'] = 1;
137
-	}
138
-	if($modx->config['auto_menuindex']) {
139
-		$pid = (int)$_REQUEST['pid'];
140
-		$rs = $modx->db->select('count(*)', $tbl_site_content, "parent='{$pid}'");
141
-		$content['menuindex'] = $modx->db->getValue($rs);
142
-	} else {
143
-		$content['menuindex'] = 0;
144
-	}
135
+    if(!isset ($modx->config['auto_menuindex'])) {
136
+        $modx->config['auto_menuindex'] = 1;
137
+    }
138
+    if($modx->config['auto_menuindex']) {
139
+        $pid = (int)$_REQUEST['pid'];
140
+        $rs = $modx->db->select('count(*)', $tbl_site_content, "parent='{$pid}'");
141
+        $content['menuindex'] = $modx->db->getValue($rs);
142
+    } else {
143
+        $content['menuindex'] = 0;
144
+    }
145 145
 }
146 146
 
147 147
 if(isset ($_POST['which_editor'])) {
148
-	$modx->config['which_editor'] = $_POST['which_editor'];
148
+    $modx->config['which_editor'] = $_POST['which_editor'];
149 149
 }
150 150
 
151 151
 // Add lock-element JS-Script
@@ -545,23 +545,23 @@  discard block
 block discarded – undo
545 545
 
546 546
 	<form name="mutate" id="mutate" class="content" method="post" enctype="multipart/form-data" action="index.php" onsubmit="documentDirty=false;">
547 547
 		<?php
548
-		// invoke OnDocFormPrerender event
549
-		$evtOut = $modx->invokeEvent('OnDocFormPrerender', array(
550
-			'id' => $id,
551
-			'template' => $content['template']
552
-		));
553
-
554
-		if(is_array($evtOut)) {
555
-			echo implode('', $evtOut);
556
-		}
557
-
558
-		/*************************/
559
-		$dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : '';
560
-		$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'createdon';
561
-		$page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : '';
562
-		/*************************/
563
-
564
-		?>
548
+        // invoke OnDocFormPrerender event
549
+        $evtOut = $modx->invokeEvent('OnDocFormPrerender', array(
550
+            'id' => $id,
551
+            'template' => $content['template']
552
+        ));
553
+
554
+        if(is_array($evtOut)) {
555
+            echo implode('', $evtOut);
556
+        }
557
+
558
+        /*************************/
559
+        $dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : '';
560
+        $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'createdon';
561
+        $page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : '';
562
+        /*************************/
563
+
564
+        ?>
565 565
 		<input type="hidden" name="a" value="5" />
566 566
 		<input type="hidden" name="id" value="<?= $content['id'] ?>" />
567 567
 		<input type="hidden" name="mode" value="<?= $modx->manager->action ?>" />
@@ -576,54 +576,54 @@  discard block
 block discarded – undo
576 576
 
577 577
 			<h1>
578 578
 				<i class="fa fa-pencil-square-o"></i><?php if(isset($_REQUEST['id'])) {
579
-					echo iconv_substr($content['pagetitle'], 0, 50, $modx->config['modx_charset']) . (iconv_strlen($content['pagetitle'], $modx->config['modx_charset']) > 50 ? '...' : '') . '<small>(' . $_REQUEST['id'] . ')</small>';
580
-				} else {
581
-				    if ($modx->manager->action == '4') {
579
+                    echo iconv_substr($content['pagetitle'], 0, 50, $modx->config['modx_charset']) . (iconv_strlen($content['pagetitle'], $modx->config['modx_charset']) > 50 ? '...' : '') . '<small>(' . $_REQUEST['id'] . ')</small>';
580
+                } else {
581
+                    if ($modx->manager->action == '4') {
582 582
                         echo $_lang['add_resource'];
583 583
                     } else if ($modx->manager->action == '72') {
584 584
                         echo $_lang['add_weblink'];
585 585
                     } else {
586 586
                         echo $_lang['create_resource_title'];
587 587
                     }
588
-				} ?>
588
+                } ?>
589 589
 			</h1>
590 590
 
591 591
 			<?= $_style['actionbuttons']['dynamic']['document'] ?>
592 592
 
593 593
 			<?php
594
-			// breadcrumbs
595
-			if($modx->config['use_breadcrumbs']) {
596
-				$temp = array();
597
-				$title = isset($content['pagetitle']) ? $content['pagetitle'] : $_lang['create_resource_title'];
598
-
599
-				if(isset($_REQUEST['id']) && $content['parent'] != 0) {
600
-					$bID = (int) $_REQUEST['id'];
601
-					$temp = $modx->getParentIds($bID);
602
-				} else if(isset($_REQUEST['pid'])) {
603
-					$bID = (int) $_REQUEST['pid'];
604
-					$temp = $modx->getParentIds($bID);
605
-					array_unshift($temp, $bID);
606
-				}
607
-
608
-				if($temp) {
609
-					$parents = implode(',', $temp);
610
-
611
-					if(!empty($parents)) {
612
-						$where = "FIND_IN_SET(id,'{$parents}') DESC";
613
-						$rs = $modx->db->select('id, pagetitle', $tbl_site_content, "id IN ({$parents})", $where);
614
-						while($row = $modx->db->getRow($rs)) {
615
-							$out .= '<li class="breadcrumbs__li">
594
+            // breadcrumbs
595
+            if($modx->config['use_breadcrumbs']) {
596
+                $temp = array();
597
+                $title = isset($content['pagetitle']) ? $content['pagetitle'] : $_lang['create_resource_title'];
598
+
599
+                if(isset($_REQUEST['id']) && $content['parent'] != 0) {
600
+                    $bID = (int) $_REQUEST['id'];
601
+                    $temp = $modx->getParentIds($bID);
602
+                } else if(isset($_REQUEST['pid'])) {
603
+                    $bID = (int) $_REQUEST['pid'];
604
+                    $temp = $modx->getParentIds($bID);
605
+                    array_unshift($temp, $bID);
606
+                }
607
+
608
+                if($temp) {
609
+                    $parents = implode(',', $temp);
610
+
611
+                    if(!empty($parents)) {
612
+                        $where = "FIND_IN_SET(id,'{$parents}') DESC";
613
+                        $rs = $modx->db->select('id, pagetitle', $tbl_site_content, "id IN ({$parents})", $where);
614
+                        while($row = $modx->db->getRow($rs)) {
615
+                            $out .= '<li class="breadcrumbs__li">
616 616
                                 <a href="index.php?a=27&id=' . $row['id'] . '" class="breadcrumbs__a">' . htmlspecialchars($row['pagetitle'], ENT_QUOTES, $modx->config['modx_charset']) . '</a>
617 617
                                 <span class="breadcrumbs__sep">&gt;</span>
618 618
                             </li>';
619
-						}
620
-					}
621
-				}
619
+                        }
620
+                    }
621
+                }
622 622
 
623
-				$out .= '<li class="breadcrumbs__li breadcrumbs__li_current">' . $title . '</li>';
624
-				echo '<ul class="breadcrumbs">' . $out . '</ul>';
625
-			}
626
-			?>
623
+                $out .= '<li class="breadcrumbs__li breadcrumbs__li_current">' . $title . '</li>';
624
+                echo '<ul class="breadcrumbs">' . $out . '</ul>';
625
+            }
626
+            ?>
627 627
 
628 628
 			<!-- start main wrapper -->
629 629
 			<div class="sectionBody">
@@ -635,13 +635,13 @@  discard block
 block discarded – undo
635 635
 
636 636
 					<!-- General -->
637 637
 					<?php
638
-					$evtOut = $modx->invokeEvent('OnDocFormTemplateRender', array(
639
-						'id' => $id
640
-					));
641
-					if(is_array($evtOut)) {
642
-						echo implode('', $evtOut);
643
-					} else {
644
-						?>
638
+                    $evtOut = $modx->invokeEvent('OnDocFormTemplateRender', array(
639
+                        'id' => $id
640
+                    ));
641
+                    if(is_array($evtOut)) {
642
+                        echo implode('', $evtOut);
643
+                    } else {
644
+                        ?>
645 645
 						<div class="tab-page" id="tabGeneral">
646 646
 							<h2 class="tab"><?= $_lang['settings_general'] ?></h2>
647 647
 							<script type="text/javascript">tpSettings.addTabPage(document.getElementById("tabGeneral"));</script>
@@ -726,36 +726,36 @@  discard block
 block discarded – undo
726 726
 										<select id="template" name="template" class="inputBox" onchange="templateWarning();">
727 727
 											<option value="0">(blank)</option>
728 728
 											<?php
729
-											$field = "t.templatename, t.selectable, t.id, c.category";
730
-											$from = "{$tbl_site_templates} AS t LEFT JOIN {$tbl_categories} AS c ON t.category = c.id";
731
-											$rs = $modx->db->select($field, $from, '', 'c.category, t.templatename ASC');
732
-											$currentCategory = '';
733
-											while($row = $modx->db->getRow($rs)) {
734
-												if($row['selectable'] != 1 && $row['id'] != $content['template']) {
735
-													continue;
736
-												};
737
-												// Skip if not selectable but show if selected!
738
-												$thisCategory = $row['category'];
739
-												if($thisCategory == null) {
740
-													$thisCategory = $_lang["no_category"];
741
-												}
742
-												if($thisCategory != $currentCategory) {
743
-													if($closeOptGroup) {
744
-														echo "\t\t\t\t\t</optgroup>\n";
745
-													}
746
-													echo "\t\t\t\t\t<optgroup label=\"$thisCategory\">\n";
747
-													$closeOptGroup = true;
748
-												}
729
+                                            $field = "t.templatename, t.selectable, t.id, c.category";
730
+                                            $from = "{$tbl_site_templates} AS t LEFT JOIN {$tbl_categories} AS c ON t.category = c.id";
731
+                                            $rs = $modx->db->select($field, $from, '', 'c.category, t.templatename ASC');
732
+                                            $currentCategory = '';
733
+                                            while($row = $modx->db->getRow($rs)) {
734
+                                                if($row['selectable'] != 1 && $row['id'] != $content['template']) {
735
+                                                    continue;
736
+                                                };
737
+                                                // Skip if not selectable but show if selected!
738
+                                                $thisCategory = $row['category'];
739
+                                                if($thisCategory == null) {
740
+                                                    $thisCategory = $_lang["no_category"];
741
+                                                }
742
+                                                if($thisCategory != $currentCategory) {
743
+                                                    if($closeOptGroup) {
744
+                                                        echo "\t\t\t\t\t</optgroup>\n";
745
+                                                    }
746
+                                                    echo "\t\t\t\t\t<optgroup label=\"$thisCategory\">\n";
747
+                                                    $closeOptGroup = true;
748
+                                                }
749 749
 
750
-												$selectedtext = ($row['id'] == $content['template']) ? ' selected="selected"' : '';
750
+                                                $selectedtext = ($row['id'] == $content['template']) ? ' selected="selected"' : '';
751 751
 
752
-												echo "\t\t\t\t\t" . '<option value="' . $row['id'] . '"' . $selectedtext . '>' . $row['templatename'] . "</option>\n";
753
-												$currentCategory = $thisCategory;
754
-											}
755
-											if($thisCategory != '') {
756
-												echo "\t\t\t\t\t</optgroup>\n";
757
-											}
758
-											?>
752
+                                                echo "\t\t\t\t\t" . '<option value="' . $row['id'] . '"' . $selectedtext . '>' . $row['templatename'] . "</option>\n";
753
+                                                $currentCategory = $thisCategory;
754
+                                            }
755
+                                            if($thisCategory != '') {
756
+                                                echo "\t\t\t\t\t</optgroup>\n";
757
+                                            }
758
+                                            ?>
759 759
 										</select>
760 760
 									</td>
761 761
 								</tr>
@@ -795,37 +795,37 @@  discard block
 block discarded – undo
795 795
 									</td>
796 796
 									<td valign="top">
797 797
 										<?php
798
-										$parentlookup = false;
799
-										if(isset ($_REQUEST['id'])) {
800
-											if($content['parent'] == 0) {
801
-												$parentname = $site_name;
802
-											} else {
803
-												$parentlookup = $content['parent'];
804
-											}
805
-										} elseif(isset ($_REQUEST['pid'])) {
806
-											if($_REQUEST['pid'] == 0) {
807
-												$parentname = $site_name;
808
-											} else {
809
-												$parentlookup = $_REQUEST['pid'];
810
-											}
811
-										} elseif(isset($_POST['parent'])) {
812
-											if($_POST['parent'] == 0) {
813
-												$parentname = $site_name;
814
-											} else {
815
-												$parentlookup = $_POST['parent'];
816
-											}
817
-										} else {
818
-											$parentname = $site_name;
819
-											$content['parent'] = 0;
820
-										}
821
-										if($parentlookup !== false && is_numeric($parentlookup)) {
822
-											$rs = $modx->db->select('pagetitle', $tbl_site_content, "id='{$parentlookup}'");
823
-											$parentname = $modx->db->getValue($rs);
824
-											if(!$parentname) {
825
-												$modx->webAlertAndQuit($_lang["error_no_parent"]);
826
-											}
827
-										}
828
-										?>
798
+                                        $parentlookup = false;
799
+                                        if(isset ($_REQUEST['id'])) {
800
+                                            if($content['parent'] == 0) {
801
+                                                $parentname = $site_name;
802
+                                            } else {
803
+                                                $parentlookup = $content['parent'];
804
+                                            }
805
+                                        } elseif(isset ($_REQUEST['pid'])) {
806
+                                            if($_REQUEST['pid'] == 0) {
807
+                                                $parentname = $site_name;
808
+                                            } else {
809
+                                                $parentlookup = $_REQUEST['pid'];
810
+                                            }
811
+                                        } elseif(isset($_POST['parent'])) {
812
+                                            if($_POST['parent'] == 0) {
813
+                                                $parentname = $site_name;
814
+                                            } else {
815
+                                                $parentlookup = $_POST['parent'];
816
+                                            }
817
+                                        } else {
818
+                                            $parentname = $site_name;
819
+                                            $content['parent'] = 0;
820
+                                        }
821
+                                        if($parentlookup !== false && is_numeric($parentlookup)) {
822
+                                            $rs = $modx->db->select('pagetitle', $tbl_site_content, "id='{$parentlookup}'");
823
+                                            $parentname = $modx->db->getValue($rs);
824
+                                            if(!$parentname) {
825
+                                                $modx->webAlertAndQuit($_lang["error_no_parent"]);
826
+                                            }
827
+                                        }
828
+                                        ?>
829 829
 										<i id="plock" class="<?= $_style["actions_folder"] ?>" onclick="enableParentSelection(!allowParentSelection);"></i>
830 830
 										<b><span id="parentName"><?= (isset($_REQUEST['pid']) ? $_REQUEST['pid'] : $content['parent']) ?> (<?= $parentname ?>)</span></b>
831 831
 										<input type="hidden" name="parent" value="<?= (isset($_REQUEST['pid']) ? $_REQUEST['pid'] : $content['parent']) ?>" onchange="documentDirty=true;" />
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 								</tr>
834 834
 								<tr></tr>
835 835
 								<?php
836
-								/*
836
+                                /*
837 837
 								if($content['type'] == 'reference' || $modx->manager->action == '72') {
838 838
 									?>
839 839
 									<tr>
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 									</tr>
862 862
 									<?php
863 863
 								}*/
864
-								?>
864
+                                ?>
865 865
 
866 866
 								<?php if($content['type'] == 'document' || $modx->manager->action == '4') { ?>
867 867
 									<tr>
@@ -874,36 +874,36 @@  discard block
 block discarded – undo
874 874
 													<select id="which_editor" class="form-control form-control-sm" size="1" name="which_editor" onchange="changeRTE();">
875 875
 													<option value="none"><?= $_lang['none'] ?></option>
876 876
 														<?php
877
-														// invoke OnRichTextEditorRegister event
878
-														$evtOut = $modx->invokeEvent("OnRichTextEditorRegister");
879
-														if(is_array($evtOut)) {
880
-															for($i = 0; $i < count($evtOut); $i++) {
881
-																$editor = $evtOut[$i];
882
-																echo "\t\t\t", '<option value="', $editor, '"', ($modx->config['which_editor'] == $editor ? ' selected="selected"' : ''), '>', $editor, "</option>\n";
883
-															}
884
-														}
885
-														?>
877
+                                                        // invoke OnRichTextEditorRegister event
878
+                                                        $evtOut = $modx->invokeEvent("OnRichTextEditorRegister");
879
+                                                        if(is_array($evtOut)) {
880
+                                                            for($i = 0; $i < count($evtOut); $i++) {
881
+                                                                $editor = $evtOut[$i];
882
+                                                                echo "\t\t\t", '<option value="', $editor, '"', ($modx->config['which_editor'] == $editor ? ' selected="selected"' : ''), '>', $editor, "</option>\n";
883
+                                                            }
884
+                                                        }
885
+                                                        ?>
886 886
 													</select>
887 887
 												</label>
888 888
 											</div>
889 889
 											<div id="content_body">
890 890
 												<?php
891
-												if(($content['richtext'] == 1 || $modx->manager->action == '4') && $use_editor == 1) {
892
-													$htmlContent = $content['content'];
893
-													?>
891
+                                                if(($content['richtext'] == 1 || $modx->manager->action == '4') && $use_editor == 1) {
892
+                                                    $htmlContent = $content['content'];
893
+                                                    ?>
894 894
 													<div class="section-editor clearfix">
895 895
 														<textarea id="ta" name="ta" onchange="documentDirty=true;"><?= $modx->htmlspecialchars($htmlContent) ?></textarea>
896 896
 													</div>
897 897
 													<?php
898
-													// Richtext-[*content*]
899
-													$richtexteditorIds = array();
900
-													$richtexteditorOptions = array();
901
-													$richtexteditorIds[$modx->config['which_editor']][] = 'ta';
902
-													$richtexteditorOptions[$modx->config['which_editor']]['ta'] = '';
903
-												} else {
904
-													echo "\t" . '<div><textarea class="phptextarea" id="ta" name="ta" rows="20" wrap="soft" onchange="documentDirty=true;">', $modx->htmlspecialchars($content['content']), '</textarea></div>' . "\n";
905
-												}
906
-												?>
898
+                                                    // Richtext-[*content*]
899
+                                                    $richtexteditorIds = array();
900
+                                                    $richtexteditorOptions = array();
901
+                                                    $richtexteditorIds[$modx->config['which_editor']][] = 'ta';
902
+                                                    $richtexteditorOptions[$modx->config['which_editor']]['ta'] = '';
903
+                                                } else {
904
+                                                    echo "\t" . '<div><textarea class="phptextarea" id="ta" name="ta" rows="20" wrap="soft" onchange="documentDirty=true;">', $modx->htmlspecialchars($content['content']), '</textarea></div>' . "\n";
905
+                                                }
906
+                                                ?>
907 907
 											</div>
908 908
 										</td>
909 909
 									</tr>
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
                                     $sort = 'cat.rank,cat.id,' . $sort;
952 952
                                 }
953 953
                                 $where = vsprintf("tvtpl.templateid='%s' AND (1='%s' OR ISNULL(tva.documentgroup) %s)", $vs);
954
-				$evtOut = $modx->invokeEvent('OnDocTVPrerender', array('id' => $id, 'template' => $template));
954
+                $evtOut = $modx->invokeEvent('OnDocTVPrerender', array('id' => $id, 'template' => $template));
955 955
                                 if ($evtOut && is_array($evtOut)) {
956 956
                                     $where .= implode(' ', $evtOut);
957 957
                                 }
@@ -1194,8 +1194,8 @@  discard block
 block discarded – undo
1194 1194
 
1195 1195
 								<?php
1196 1196
 
1197
-								if($_SESSION['mgrRole'] == 1 || $modx->manager->action != '27' || $_SESSION['mgrInternalKey'] == $content['createdby'] || $modx->hasPermission('change_resourcetype')) {
1198
-									?>
1197
+                                if($_SESSION['mgrRole'] == 1 || $modx->manager->action != '27' || $_SESSION['mgrInternalKey'] == $content['createdby'] || $modx->hasPermission('change_resourcetype')) {
1198
+                                    ?>
1199 1199
 									<tr>
1200 1200
 										<td>
1201 1201
 											<span class="warning"><?= $_lang['resource_type'] ?></span>
@@ -1217,15 +1217,15 @@  discard block
 block discarded – undo
1217 1217
 										<td>
1218 1218
 											<select name="contentType" class="inputBox" onchange="documentDirty=true;">
1219 1219
 												<?php
1220
-												if(!$content['contentType']) {
1221
-													$content['contentType'] = 'text/html';
1222
-												}
1223
-												$custom_contenttype = (isset ($custom_contenttype) ? $custom_contenttype : "text/html,text/plain,text/xml");
1224
-												$ct = explode(",", $custom_contenttype);
1225
-												for($i = 0; $i < count($ct); $i++) {
1226
-													echo "\t\t\t\t\t" . '<option value="' . $ct[$i] . '"' . ($content['contentType'] == $ct[$i] ? ' selected="selected"' : '') . '>' . $ct[$i] . "</option>\n";
1227
-												}
1228
-												?>
1220
+                                                if(!$content['contentType']) {
1221
+                                                    $content['contentType'] = 'text/html';
1222
+                                                }
1223
+                                                $custom_contenttype = (isset ($custom_contenttype) ? $custom_contenttype : "text/html,text/plain,text/xml");
1224
+                                                $ct = explode(",", $custom_contenttype);
1225
+                                                for($i = 0; $i < count($ct); $i++) {
1226
+                                                    echo "\t\t\t\t\t" . '<option value="' . $ct[$i] . '"' . ($content['contentType'] == $ct[$i] ? ' selected="selected"' : '') . '>' . $ct[$i] . "</option>\n";
1227
+                                                }
1228
+                                                ?>
1229 1229
 											</select>
1230 1230
 										</td>
1231 1231
 									</tr>
@@ -1248,23 +1248,23 @@  discard block
 block discarded – undo
1248 1248
 										</td>
1249 1249
 									</tr>
1250 1250
 									<?php
1251
-								} else {
1252
-									if($content['type'] != 'reference' && $modx->manager->action != '72') {
1253
-										// non-admin managers creating or editing a document resource
1254
-										?>
1251
+                                } else {
1252
+                                    if($content['type'] != 'reference' && $modx->manager->action != '72') {
1253
+                                        // non-admin managers creating or editing a document resource
1254
+                                        ?>
1255 1255
 										<input type="hidden" name="contentType" value="<?= (isset($content['contentType']) ? $content['contentType'] : "text/html") ?>" />
1256 1256
 										<input type="hidden" name="type" value="document" />
1257 1257
 										<input type="hidden" name="content_dispo" value="<?= (isset($content['content_dispo']) ? $content['content_dispo'] : '0') ?>" />
1258 1258
 										<?php
1259
-									} else {
1260
-										// non-admin managers creating or editing a reference (weblink) resource
1261
-										?>
1259
+                                    } else {
1260
+                                        // non-admin managers creating or editing a reference (weblink) resource
1261
+                                        ?>
1262 1262
 										<input type="hidden" name="type" value="reference" />
1263 1263
 										<input type="hidden" name="contentType" value="text/html" />
1264 1264
 										<?php
1265
-									}
1266
-								}//if mgrRole
1267
-								?>
1265
+                                    }
1266
+                                }//if mgrRole
1267
+                                ?>
1268 1268
 
1269 1269
 								<tr>
1270 1270
 									<td>
@@ -1347,112 +1347,112 @@  discard block
 block discarded – undo
1347 1347
                     ?>
1348 1348
 
1349 1349
 						<?php
1350
-					/*******************************
1350
+                    /*******************************
1351 1351
 					 * Document Access Permissions */
1352
-					if($use_udperms == 1) {
1353
-						$groupsarray = array();
1354
-						$sql = '';
1355
-
1356
-						$documentId = ($modx->manager->action == '27' ? $id : (!empty($_REQUEST['pid']) ? $_REQUEST['pid'] : $content['parent']));
1357
-						if($documentId > 0) {
1358
-							// Load up, the permissions from the parent (if new document) or existing document
1359
-							$rs = $modx->db->select('id, document_group', $tbl_document_groups, "document='{$documentId}'");
1360
-							while($currentgroup = $modx->db->getRow($rs)) $groupsarray[] = $currentgroup['document_group'] . ',' . $currentgroup['id'];
1361
-
1362
-							// Load up the current permissions and names
1363
-							$vs = array(
1364
-								$tbl_document_group_names,
1365
-								$tbl_document_groups,
1366
-								$documentId
1367
-							);
1368
-							$from = vsprintf("%s AS dgn LEFT JOIN %s AS groups ON groups.document_group=dgn.id AND groups.document='%s'", $vs);
1369
-							$rs = $modx->db->select('dgn.*, groups.id AS link_id', $from, '', 'name');
1370
-						} else {
1371
-							// Just load up the names, we're starting clean
1372
-							$rs = $modx->db->select('*, NULL AS link_id', $tbl_document_group_names, '', 'name');
1373
-						}
1374
-
1375
-						// retain selected doc groups between post
1376
-						if(isset($_POST['docgroups'])) {
1377
-							$groupsarray = array_merge($groupsarray, $_POST['docgroups']);
1378
-						}
1352
+                    if($use_udperms == 1) {
1353
+                        $groupsarray = array();
1354
+                        $sql = '';
1355
+
1356
+                        $documentId = ($modx->manager->action == '27' ? $id : (!empty($_REQUEST['pid']) ? $_REQUEST['pid'] : $content['parent']));
1357
+                        if($documentId > 0) {
1358
+                            // Load up, the permissions from the parent (if new document) or existing document
1359
+                            $rs = $modx->db->select('id, document_group', $tbl_document_groups, "document='{$documentId}'");
1360
+                            while($currentgroup = $modx->db->getRow($rs)) $groupsarray[] = $currentgroup['document_group'] . ',' . $currentgroup['id'];
1361
+
1362
+                            // Load up the current permissions and names
1363
+                            $vs = array(
1364
+                                $tbl_document_group_names,
1365
+                                $tbl_document_groups,
1366
+                                $documentId
1367
+                            );
1368
+                            $from = vsprintf("%s AS dgn LEFT JOIN %s AS groups ON groups.document_group=dgn.id AND groups.document='%s'", $vs);
1369
+                            $rs = $modx->db->select('dgn.*, groups.id AS link_id', $from, '', 'name');
1370
+                        } else {
1371
+                            // Just load up the names, we're starting clean
1372
+                            $rs = $modx->db->select('*, NULL AS link_id', $tbl_document_group_names, '', 'name');
1373
+                        }
1374
+
1375
+                        // retain selected doc groups between post
1376
+                        if(isset($_POST['docgroups'])) {
1377
+                            $groupsarray = array_merge($groupsarray, $_POST['docgroups']);
1378
+                        }
1379
+
1380
+                        $isManager = $modx->hasPermission('access_permissions');
1381
+                        $isWeb = $modx->hasPermission('web_access_permissions');
1382
+
1383
+                        // Setup Basic attributes for each Input box
1384
+                        $inputAttributes = array(
1385
+                            'type' => 'checkbox',
1386
+                            'class' => 'checkbox',
1387
+                            'name' => 'docgroups[]',
1388
+                            'onclick' => 'makePublic(false);',
1389
+                        );
1390
+                        $permissions = array(); // New Permissions array list (this contains the HTML)
1391
+                        $permissions_yes = 0; // count permissions the current mgr user has
1392
+                        $permissions_no = 0; // count permissions the current mgr user doesn't have
1393
+
1394
+                        // Loop through the permissions list
1395
+                        while($row = $modx->db->getRow($rs)) {
1396
+
1397
+                            // Create an inputValue pair (group ID and group link (if it exists))
1398
+                            $inputValue = $row['id'] . ',' . ($row['link_id'] ? $row['link_id'] : 'new');
1399
+                            $inputId = 'group-' . $row['id'];
1400
+
1401
+                            $checked = in_array($inputValue, $groupsarray);
1402
+                            if($checked) {
1403
+                                $notPublic = true;
1404
+                            } // Mark as private access (either web or manager)
1405
+
1406
+                            // Skip the access permission if the user doesn't have access...
1407
+                            if((!$isManager && $row['private_memgroup'] == '1') || (!$isWeb && $row['private_webgroup'] == '1')) {
1408
+                                continue;
1409
+                            }
1379 1410
 
1380
-						$isManager = $modx->hasPermission('access_permissions');
1381
-						$isWeb = $modx->hasPermission('web_access_permissions');
1382
-
1383
-						// Setup Basic attributes for each Input box
1384
-						$inputAttributes = array(
1385
-							'type' => 'checkbox',
1386
-							'class' => 'checkbox',
1387
-							'name' => 'docgroups[]',
1388
-							'onclick' => 'makePublic(false);',
1389
-						);
1390
-						$permissions = array(); // New Permissions array list (this contains the HTML)
1391
-						$permissions_yes = 0; // count permissions the current mgr user has
1392
-						$permissions_no = 0; // count permissions the current mgr user doesn't have
1393
-
1394
-						// Loop through the permissions list
1395
-						while($row = $modx->db->getRow($rs)) {
1396
-
1397
-							// Create an inputValue pair (group ID and group link (if it exists))
1398
-							$inputValue = $row['id'] . ',' . ($row['link_id'] ? $row['link_id'] : 'new');
1399
-							$inputId = 'group-' . $row['id'];
1400
-
1401
-							$checked = in_array($inputValue, $groupsarray);
1402
-							if($checked) {
1403
-								$notPublic = true;
1404
-							} // Mark as private access (either web or manager)
1405
-
1406
-							// Skip the access permission if the user doesn't have access...
1407
-							if((!$isManager && $row['private_memgroup'] == '1') || (!$isWeb && $row['private_webgroup'] == '1')) {
1408
-								continue;
1409
-							}
1410
-
1411
-							// Setup attributes for this Input box
1412
-							$inputAttributes['id'] = $inputId;
1413
-							$inputAttributes['value'] = $inputValue;
1414
-							if($checked) {
1415
-								$inputAttributes['checked'] = 'checked';
1416
-							} else {
1417
-								unset($inputAttributes['checked']);
1418
-							}
1419
-
1420
-							// Create attribute string list
1421
-							$inputString = array();
1422
-							foreach($inputAttributes as $k => $v) $inputString[] = $k . '="' . $v . '"';
1423
-
1424
-							// Make the <input> HTML
1425
-							$inputHTML = '<input ' . implode(' ', $inputString) . ' />';
1426
-
1427
-							// does user have this permission?
1428
-							$from = "{$tbl_membergroup_access} AS mga, {$tbl_member_groups} AS mg";
1429
-							$vs = array(
1430
-								$row['id'],
1431
-								$_SESSION['mgrInternalKey']
1432
-							);
1433
-							$where = vsprintf("mga.membergroup=mg.user_group AND mga.documentgroup=%s AND mg.member=%s", $vs);
1434
-							$rsp = $modx->db->select('COUNT(mg.id)', $from, $where);
1435
-							$count = $modx->db->getValue($rsp);
1436
-							if($count > 0) {
1437
-								++$permissions_yes;
1438
-							} else {
1439
-								++$permissions_no;
1440
-							}
1441
-							$permissions[] = "\t\t" . '<li>' . $inputHTML . '<label for="' . $inputId . '">' . $row['name'] . '</label></li>';
1442
-						}
1443
-						// if mgr user doesn't have access to any of the displayable permissions, forget about them and make doc public
1444
-						if($_SESSION['mgrRole'] != 1 && ($permissions_yes == 0 && $permissions_no > 0)) {
1445
-							$permissions = array();
1446
-						}
1411
+                            // Setup attributes for this Input box
1412
+                            $inputAttributes['id'] = $inputId;
1413
+                            $inputAttributes['value'] = $inputValue;
1414
+                            if($checked) {
1415
+                                $inputAttributes['checked'] = 'checked';
1416
+                            } else {
1417
+                                unset($inputAttributes['checked']);
1418
+                            }
1447 1419
 
1448
-						// See if the Access Permissions section is worth displaying...
1449
-						if(!empty($permissions)) {
1450
-							// Add the "All Document Groups" item if we have rights in both contexts
1451
-							if($isManager && $isWeb) {
1452
-								array_unshift($permissions, "\t\t" . '<li><input type="checkbox" class="checkbox" name="chkalldocs" id="groupall"' . (!$notPublic ? ' checked="checked"' : '') . ' onclick="makePublic(true);" /><label for="groupall" class="warning">' . $_lang['all_doc_groups'] . '</label></li>');
1453
-							}
1454
-							// Output the permissions list...
1455
-							?>
1420
+                            // Create attribute string list
1421
+                            $inputString = array();
1422
+                            foreach($inputAttributes as $k => $v) $inputString[] = $k . '="' . $v . '"';
1423
+
1424
+                            // Make the <input> HTML
1425
+                            $inputHTML = '<input ' . implode(' ', $inputString) . ' />';
1426
+
1427
+                            // does user have this permission?
1428
+                            $from = "{$tbl_membergroup_access} AS mga, {$tbl_member_groups} AS mg";
1429
+                            $vs = array(
1430
+                                $row['id'],
1431
+                                $_SESSION['mgrInternalKey']
1432
+                            );
1433
+                            $where = vsprintf("mga.membergroup=mg.user_group AND mga.documentgroup=%s AND mg.member=%s", $vs);
1434
+                            $rsp = $modx->db->select('COUNT(mg.id)', $from, $where);
1435
+                            $count = $modx->db->getValue($rsp);
1436
+                            if($count > 0) {
1437
+                                ++$permissions_yes;
1438
+                            } else {
1439
+                                ++$permissions_no;
1440
+                            }
1441
+                            $permissions[] = "\t\t" . '<li>' . $inputHTML . '<label for="' . $inputId . '">' . $row['name'] . '</label></li>';
1442
+                        }
1443
+                        // if mgr user doesn't have access to any of the displayable permissions, forget about them and make doc public
1444
+                        if($_SESSION['mgrRole'] != 1 && ($permissions_yes == 0 && $permissions_no > 0)) {
1445
+                            $permissions = array();
1446
+                        }
1447
+
1448
+                        // See if the Access Permissions section is worth displaying...
1449
+                        if(!empty($permissions)) {
1450
+                            // Add the "All Document Groups" item if we have rights in both contexts
1451
+                            if($isManager && $isWeb) {
1452
+                                array_unshift($permissions, "\t\t" . '<li><input type="checkbox" class="checkbox" name="chkalldocs" id="groupall"' . (!$notPublic ? ' checked="checked"' : '') . ' onclick="makePublic(true);" /><label for="groupall" class="warning">' . $_lang['all_doc_groups'] . '</label></li>');
1453
+                            }
1454
+                            // Output the permissions list...
1455
+                            ?>
1456 1456
 							<!-- Access Permissions -->
1457 1457
 							<div class="tab-page" id="tabAccess">
1458 1458
 								<h2 class="tab" id="tab_access_header"><?= $_lang['access_permissions'] ?></h2>
@@ -1486,31 +1486,31 @@  discard block
 block discarded – undo
1486 1486
 								</ul>
1487 1487
 							</div><!--div class="tab-page" id="tabAccess"-->
1488 1488
 							<?php
1489
-						} // !empty($permissions)
1490
-						elseif($_SESSION['mgrRole'] != 1 && ($permissions_yes == 0 && $permissions_no > 0) && ($_SESSION['mgrPermissions']['access_permissions'] == 1 || $_SESSION['mgrPermissions']['web_access_permissions'] == 1)) {
1491
-							?>
1489
+                        } // !empty($permissions)
1490
+                        elseif($_SESSION['mgrRole'] != 1 && ($permissions_yes == 0 && $permissions_no > 0) && ($_SESSION['mgrPermissions']['access_permissions'] == 1 || $_SESSION['mgrPermissions']['web_access_permissions'] == 1)) {
1491
+                            ?>
1492 1492
 							<p><?= $_lang["access_permissions_docs_collision"] ?></p>
1493 1493
 							<?php
1494 1494
 
1495
-						}
1496
-					}
1497
-					/* End Document Access Permissions *
1495
+                        }
1496
+                    }
1497
+                    /* End Document Access Permissions *
1498 1498
 					 ***********************************/
1499
-					?>
1499
+                    ?>
1500 1500
 
1501 1501
 					<input type="submit" name="save" style="display:none" />
1502 1502
 					<?php
1503 1503
 
1504
-					// invoke OnDocFormRender event
1505
-					$evtOut = $modx->invokeEvent('OnDocFormRender', array(
1506
-						'id' => $id,
1507
-						'template' => $content['template']
1508
-					));
1504
+                    // invoke OnDocFormRender event
1505
+                    $evtOut = $modx->invokeEvent('OnDocFormRender', array(
1506
+                        'id' => $id,
1507
+                        'template' => $content['template']
1508
+                    ));
1509 1509
 
1510
-					if(is_array($evtOut)) {
1511
-						echo implode('', $evtOut);
1512
-					}
1513
-					?>
1510
+                    if(is_array($evtOut)) {
1511
+                        echo implode('', $evtOut);
1512
+                    }
1513
+                    ?>
1514 1514
 				</div><!--div class="tab-pane" id="documentPane"-->
1515 1515
 			</div><!--div class="sectionBody"-->
1516 1516
 		</fieldset>
@@ -1521,63 +1521,63 @@  discard block
 block discarded – undo
1521 1521
 	</script>
1522 1522
 <?php
1523 1523
 if(($content['richtext'] == 1 || $modx->manager->action == '4' || $modx->manager->action == '72') && $use_editor == 1) {
1524
-	if(is_array($richtexteditorIds)) {
1525
-		foreach($richtexteditorIds as $editor => $elements) {
1526
-			// invoke OnRichTextEditorInit event
1527
-			$evtOut = $modx->invokeEvent('OnRichTextEditorInit', array(
1528
-				'editor' => $editor,
1529
-				'elements' => $elements,
1530
-				'options' => $richtexteditorOptions[$editor]
1531
-			));
1532
-			if(is_array($evtOut)) {
1533
-				echo implode('', $evtOut);
1534
-			}
1535
-		}
1536
-	}
1524
+    if(is_array($richtexteditorIds)) {
1525
+        foreach($richtexteditorIds as $editor => $elements) {
1526
+            // invoke OnRichTextEditorInit event
1527
+            $evtOut = $modx->invokeEvent('OnRichTextEditorInit', array(
1528
+                'editor' => $editor,
1529
+                'elements' => $elements,
1530
+                'options' => $richtexteditorOptions[$editor]
1531
+            ));
1532
+            if(is_array($evtOut)) {
1533
+                echo implode('', $evtOut);
1534
+            }
1535
+        }
1536
+    }
1537 1537
 }
1538 1538
 
1539 1539
 /**
1540 1540
  * @return string
1541 1541
  */
1542 1542
 function getDefaultTemplate() {
1543
-	$modx = evolutionCMS();
1543
+    $modx = evolutionCMS();
1544 1544
 
1545 1545
     $default_template = '';
1546
-	switch($modx->config['auto_template_logic']) {
1547
-		case 'sibling':
1548
-			if(!isset($_GET['pid']) || empty($_GET['pid'])) {
1549
-				$site_start = $modx->config['site_start'];
1550
-				$where = "sc.isfolder=0 AND sc.id!='{$site_start}'";
1551
-				$sibl = $modx->getDocumentChildren($_REQUEST['pid'], 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
1552
-				if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1553
-					$default_template = $sibl[0]['template'];
1554
-				}
1555
-			} else {
1556
-				$sibl = $modx->getDocumentChildren($_REQUEST['pid'], 1, 0, 'template', 'isfolder=0', 'menuindex', 'ASC', 1);
1557
-				if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1558
-					$default_template = $sibl[0]['template'];
1559
-				} else {
1560
-					$sibl = $modx->getDocumentChildren($_REQUEST['pid'], 0, 0, 'template', 'isfolder=0', 'menuindex', 'ASC', 1);
1561
-					if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1562
-						$default_template = $sibl[0]['template'];
1563
-					}
1564
-				}
1565
-			}
1566
-			if(isset($default_template)) {
1567
-				break;
1568
-			} // If $default_template could not be determined, fall back / through to "parent"-mode
1569
-		case 'parent':
1570
-			if(isset($_REQUEST['pid']) && !empty($_REQUEST['pid'])) {
1571
-				$parent = $modx->getPageInfo($_REQUEST['pid'], 0, 'template');
1572
-				if(isset($parent['template'])) {
1573
-					$default_template = $parent['template'];
1574
-				}
1575
-			}
1576
-			break;
1577
-		case 'system':
1578
-		default: // default_template is already set
1579
-			$default_template = $modx->config['default_template'];
1580
-	}
1581
-
1582
-	return empty($default_template) ? $modx->config['default_template'] : $default_template;
1546
+    switch($modx->config['auto_template_logic']) {
1547
+        case 'sibling':
1548
+            if(!isset($_GET['pid']) || empty($_GET['pid'])) {
1549
+                $site_start = $modx->config['site_start'];
1550
+                $where = "sc.isfolder=0 AND sc.id!='{$site_start}'";
1551
+                $sibl = $modx->getDocumentChildren($_REQUEST['pid'], 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
1552
+                if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1553
+                    $default_template = $sibl[0]['template'];
1554
+                }
1555
+            } else {
1556
+                $sibl = $modx->getDocumentChildren($_REQUEST['pid'], 1, 0, 'template', 'isfolder=0', 'menuindex', 'ASC', 1);
1557
+                if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1558
+                    $default_template = $sibl[0]['template'];
1559
+                } else {
1560
+                    $sibl = $modx->getDocumentChildren($_REQUEST['pid'], 0, 0, 'template', 'isfolder=0', 'menuindex', 'ASC', 1);
1561
+                    if(isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
1562
+                        $default_template = $sibl[0]['template'];
1563
+                    }
1564
+                }
1565
+            }
1566
+            if(isset($default_template)) {
1567
+                break;
1568
+            } // If $default_template could not be determined, fall back / through to "parent"-mode
1569
+        case 'parent':
1570
+            if(isset($_REQUEST['pid']) && !empty($_REQUEST['pid'])) {
1571
+                $parent = $modx->getPageInfo($_REQUEST['pid'], 0, 'template');
1572
+                if(isset($parent['template'])) {
1573
+                    $default_template = $parent['template'];
1574
+                }
1575
+            }
1576
+            break;
1577
+        case 'system':
1578
+        default: // default_template is already set
1579
+            $default_template = $modx->config['default_template'];
1580
+    }
1581
+
1582
+    return empty($default_template) ? $modx->config['default_template'] : $default_template;
1583 1583
 }
Please login to merge, or discard this patch.