PageRenderTime 29ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/manager/actions/mutate_htmlsnippet.dynamic.php

https://github.com/garryn/evolution
PHP | 225 lines | 195 code | 22 blank | 8 comment | 50 complexity | 254c547c1466191a3545a7d3af66bb62 MD5 | raw file
  1. <?php
  2. 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.");
  3. switch ((int) $_REQUEST['a']) {
  4. case 78:
  5. if (!$modx->hasPermission('edit_chunk')) {
  6. $e->setError(3);
  7. $e->dumpError();
  8. }
  9. break;
  10. case 77:
  11. if (!$modx->hasPermission('new_chunk')) {
  12. $e->setError(3);
  13. $e->dumpError();
  14. }
  15. break;
  16. default:
  17. $e->setError(3);
  18. $e->dumpError();
  19. }
  20. if (isset($_REQUEST['id']))
  21. $id = (int)$_REQUEST['id'];
  22. else $id = 0;
  23. if ($manager_theme)
  24. $manager_theme .= '/';
  25. else $manager_theme = '';
  26. // Get table names (alphabetical)
  27. $tbl_active_users = $modx->getFullTableName('active_users');
  28. $tbl_site_htmlsnippets = $modx->getFullTableName('site_htmlsnippets');
  29. // Check to see the snippet editor isn't locked
  30. $sql = 'SELECT internalKey, username FROM '.$tbl_active_users.' WHERE action=78 AND id=\''.$id.'\'';
  31. $rs = mysql_query($sql);
  32. $limit = mysql_num_rows($rs);
  33. if ($limit > 1) {
  34. for ($i = 0; $i < $limit; $i++) {
  35. $lock = mysql_fetch_assoc($rs);
  36. if ($lock['internalKey'] != $modx->getLoginUserID()) {
  37. $msg = sprintf($_lang['lock_msg'], $lock['username'], 'chunk');
  38. $e->setError(5, $msg);
  39. $e->dumpError();
  40. }
  41. }
  42. }
  43. $content = array();
  44. if (isset($_REQUEST['id']) && $_REQUEST['id']!='' && is_numeric($_REQUEST['id'])) {
  45. $sql = 'SELECT * FROM '.$tbl_site_htmlsnippets.' WHERE id=\''.$id.'\'';
  46. $rs = mysql_query($sql);
  47. $limit = mysql_num_rows($rs);
  48. if ($limit > 1) {
  49. echo '<p>Error: Multiple Chunk sharing same unique ID.</p>';
  50. exit;
  51. }
  52. if ($limit < 1) {
  53. echo '<p>Chunk doesn\'t exist.</p>';
  54. exit;
  55. }
  56. $content = mysql_fetch_assoc($rs);
  57. $_SESSION['itemname'] = $content['name'];
  58. if ($content['locked'] == 1 && $_SESSION['mgrRole'] != 1) {
  59. $e->setError(3);
  60. $e->dumpError();
  61. }
  62. } else {
  63. $_SESSION['itemname'] = 'New Chunk';
  64. }
  65. if (isset($_POST['which_editor']))
  66. $which_editor = $_POST['which_editor'];
  67. else $which_editor = 'none';
  68. $content = array_merge($content, $_POST);
  69. // Print RTE Javascript function
  70. ?>
  71. <script language="javascript" type="text/javascript">
  72. // Added for RTE selection
  73. function changeRTE(){
  74. var whichEditor = document.getElementById('which_editor');
  75. if (whichEditor) for (var i=0; i<whichEditor.length; i++){
  76. if (whichEditor[i].selected){
  77. newEditor = whichEditor[i].value;
  78. break;
  79. }
  80. }
  81. documentDirty=false;
  82. document.mutate.a.value = <?php echo $action?>;
  83. document.mutate.which_editor.value = newEditor;
  84. document.mutate.submit();
  85. }
  86. function duplicaterecord(){
  87. if (confirm("<?php echo $_lang['confirm_duplicate_record']?>")==true) {
  88. documentDirty=false;
  89. document.location.href="index.php?id=<?php echo $_REQUEST['id']?>&a=97";
  90. }
  91. }
  92. function deletedocument() {
  93. if (confirm("<?php echo $_lang['confirm_delete_htmlsnippet']?>")==true) {
  94. documentDirty=false;
  95. document.location.href="index.php?id=" + document.mutate.id.value + "&a=80";
  96. }
  97. }
  98. </script>
  99. <form class="htmlsnippet" id="mutate" name="mutate" method="post" action="index.php">
  100. <?php
  101. // invoke OnChunkFormPrerender event
  102. $evtOut = $modx->invokeEvent('OnChunkFormPrerender', array(
  103. 'id' => $id,
  104. ));
  105. if (is_array($evtOut))
  106. echo implode('', $evtOut);
  107. ?>
  108. <input type="hidden" name="a" value="79" />
  109. <input type="hidden" name="id" value="<?php echo $_REQUEST['id']?>" />
  110. <input type="hidden" name="mode" value="<?php echo (int) $_REQUEST['a']?>" />
  111. <h1><?php echo $_lang['htmlsnippet_title']?></h1>
  112. <div id="actions">
  113. <ul class="actionButtons">
  114. <li id="Button1">
  115. <a href="#" onclick="documentDirty=false; document.mutate.save.click();">
  116. <img src="<?php echo $_style["icons_save"]?>" /> <?php echo $_lang['save']?>
  117. </a>
  118. <span class="and"> + </span>
  119. <select id="stay" name="stay">
  120. <?php if ($modx->hasPermission('new_chunk')) { ?>
  121. <option id="stay1" value="1" <?php echo $_REQUEST['stay']=='1' ? ' selected=""' : ''?> ><?php echo $_lang['stay_new']?></option>
  122. <?php } ?>
  123. <option id="stay2" value="2" <?php echo $_REQUEST['stay']=='2' ? ' selected="selected"' : ''?> ><?php echo $_lang['stay']?></option>
  124. <option id="stay3" value="" <?php echo $_REQUEST['stay']=='' ? ' selected=""' : ''?> ><?php echo $_lang['close']?></option>
  125. </select>
  126. </li>
  127. <?php
  128. if ($_REQUEST['a'] == '78') { ?>
  129. <li id="Button2"><a href="#" onclick="duplicaterecord();"><img src="<?php echo $_style["icons_resource_duplicate"] ?>" /> <?php echo $_lang["duplicate"]; ?></a></li>
  130. <li id="Button3" class="disabled"><a href="#" onclick="deletedocument();"><img src="<?php echo $_style["icons_delete_document"]?>" /> <?php echo $_lang['delete']?></a></li>
  131. <?php } else { ?>
  132. <li id="Button3"><a href="#" onclick="deletedocument();"><img src="<?php echo $_style["icons_delete_document"]?>" /> <?php echo $_lang['delete']?></a></li>
  133. <?php } ?>
  134. <li id="Button5"><a href="#" onclick="documentDirty=false;document.location.href='index.php?a=76';"><img src="<?php echo $_style["icons_cancel"] ?>" /> <?php echo $_lang['cancel']?></a></li>
  135. </ul>
  136. </div>
  137. <div class="sectionBody">
  138. <p><?php echo $_lang['htmlsnippet_msg']?></p>
  139. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  140. <tr><td align="left"><?php echo $_lang['htmlsnippet_name']?>:</td>
  141. <td align="left"><span style="font-family:'Courier New', Courier, mono">{{</span><input name="name" type="text" maxlength="100" value="<?php echo htmlspecialchars($content['name'])?>" class="inputBox" style="width:140px;" onChange='documentDirty=true;'><span style="font-family:'Courier New', Courier, mono">}}</span><span class="warning" id="savingMessage">&nbsp;</span></td></tr>
  142. <tr><td align="left"><?php echo $_lang['htmlsnippet_desc']?>:&nbsp;&nbsp;</td>
  143. <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="description" type="text" maxlength="255" value="<?php echo htmlspecialchars($content['description'])?>" class="inputBox" style="width:300px;" onChange='documentDirty=true;'></td></tr>
  144. <tr><td align="left"><?php echo $_lang['existing_category']?>:&nbsp;&nbsp;</td>
  145. <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span>
  146. <select name="categoryid" style="width:300px;" onChange='documentDirty=true;'>
  147. <option>&nbsp;</option>
  148. <?php
  149. include_once(MODX_MANAGER_PATH.'includes/categories.inc.php');
  150. $ds = getCategories();
  151. if ($ds) {
  152. foreach ($ds as $n => $v) {
  153. echo "\t\t\t\t".'<option value="'.$v['id'].'"'.($content['category'] == $v['id'] || (empty($content['category']) && $_POST['categoryid'] == $v['id']) ? ' selected="selected"' : '').'>'.htmlspecialchars($v['category'])."</option>\n";
  154. }
  155. }
  156. ?> </select></td></tr>
  157. <tr><td align="left" valign="top" style="padding-top:5px;"><?php echo $_lang['new_category']?>:</td>
  158. <td align="left" valign="top" style="padding-top:5px;"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="newcategory" type="text" maxlength="45" value="<?php echo isset($content['newcategory']) ? $content['newcategory'] : ''?>" class="inputBox" style="width:300px;" onChange="documentDirty=true;"></td></tr>
  159. <tr><td align="left" colspan="2"><input name="locked" type="checkbox"<?php echo $content['locked'] == 1 || $content['locked'] == 'on' ? ' checked="checked"' : ''?> class="inputBox" value="on" /> <?php echo $_lang['lock_htmlsnippet']?>
  160. <span class="comment"><?php echo $_lang['lock_htmlsnippet_msg']?></span></td></tr>
  161. </table>
  162. <div style="width:100%; position:relative;">
  163. <div style="padding:1px; width:100%; height:16px; background-color:#eeeeee; border:1px solid #e0e0e0; margin-top:5px;">
  164. <span style="color:brown; font-weight:bold; padding:3px;">&nbsp;<?php echo $_lang['chunk_code']?></span>
  165. </div>
  166. <textarea dir="ltr" name="post" style="width:100%; height:370px;" onChange="documentDirty=true;"><?php echo isset($content['post']) ? htmlspecialchars($content['post']) : htmlspecialchars($content['snippet'])?></textarea>
  167. </div>
  168. <span class="warning"><?php echo $_lang['which_editor_title']?></span>
  169. <select id="which_editor" name="which_editor" onchange="changeRTE();">
  170. <option value="none"<?php echo $which_editor == 'none' ? ' selected="selected"' : ''?>><?php echo $_lang['none']?></option>
  171. <?php
  172. // invoke OnRichTextEditorRegister event
  173. $evtOut = $modx->invokeEvent('OnRichTextEditorRegister');
  174. if (is_array($evtOut)) {
  175. foreach ($evtOut as $i => $editor) {
  176. echo "\t".'<option value="'.$editor.'"'.($which_editor == $editor ? ' selected="selected"' : '').'>'.$editor."</option>\n";
  177. }
  178. }
  179. ?> </select>
  180. </div><!-- end .sectionBody -->
  181. <?php
  182. // invoke OnChunkFormRender event
  183. $evtOut = $modx->invokeEvent('OnChunkFormRender', array(
  184. 'id' => $id,
  185. ));
  186. if (is_array($evtOut))
  187. echo implode('', $evtOut);
  188. ?>
  189. <input type="submit" name="save" style="display:none;" />
  190. </form>
  191. <?php
  192. // invoke OnRichTextEditorInit event
  193. if ($use_editor == 1) {
  194. $evtOut = $modx->invokeEvent('OnRichTextEditorInit', array(
  195. 'editor' => $which_editor,
  196. 'elements' => array(
  197. 'post',
  198. ),
  199. ));
  200. if (is_array($evtOut))
  201. echo implode('', $evtOut);
  202. }
  203. ?>