PageRenderTime 30ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/lib/lib_core.php

http://pixie-cms.googlecode.com/
PHP | 1183 lines | 1082 code | 1 blank | 100 comment | 566 complexity | 46926fff74e9cc4e8901a50cede52d46 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. if (!defined('DIRECT_ACCESS')) {
  3. header('Location: ../../');
  4. exit();
  5. }
  6. /**
  7. * Pixie: The Small, Simple, Site Maker.
  8. *
  9. * Licence: GNU General Public License v3
  10. * Copyright (C) 2010, Scott Evans
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see http://www.gnu.org/licenses/
  24. *
  25. * Title: lib_core
  26. *
  27. * @package Pixie
  28. * @copyright 2008-2010 Scott Evans
  29. * @author Scott Evans
  30. * @author Sam Collett
  31. * @author Tony White
  32. * @author Isa Worcs
  33. * @link http://www.getpixie.co.uk
  34. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
  35. *
  36. */
  37. // prepare for table prefix
  38. if (!empty($pixieconfig['table_prefix'])) {
  39. define('PFX', $pixieconfig['table_prefix']);
  40. } else {
  41. if (!defined('PFX')) {
  42. define('PFX', '');
  43. }
  44. }
  45. if (!function_exists('adjust_prefix')) {
  46. function adjust_prefix($table) {
  47. if (stripos($table, PFX) === 0)
  48. return $table;
  49. else
  50. return PFX . $table;
  51. }
  52. }
  53. // ------------------------------------------------------------------
  54. // class for displaying contents of a db table
  55. class ShowTable {
  56. var $Res;
  57. var $exclude = array();
  58. var $table_name;
  59. var $view_number;
  60. var $lo;
  61. var $finalmax;
  62. var $whereami;
  63. var $a_array = array();
  64. var $edit;
  65. function ShowTable($Res, $exclude, $table_name, $view_number, $lo, $finalmax, $whereami, $type, $s) {
  66. $this->Res = $Res;
  67. $this->exclude = $exclude;
  68. $this->table = $table_name;
  69. $this->limit = $view_number;
  70. $this->num = $lo;
  71. $this->finalmax = $finalmax;
  72. $this->whereami = $whereami;
  73. $this->page_type = $type;
  74. $this->s = $s;
  75. }
  76. function DrawBody() {
  77. global $date_format, $lang, $page_display_name;
  78. echo "\t<table class=\"tbl $this->table\" summary=\"" . $lang['results_from'] . " $this->table.\">
  79. <thead>
  80. <tr>";
  81. for ($j = 0; $j < mysql_num_fields($this->Res); $j++) {
  82. if (!in_array(mysql_field_name($this->Res, $j), $this->exclude))
  83. if ((isset($arlen)) && (isset($sum))) {
  84. $arlen[$j] = mysql_field_len($this->Res, $j);
  85. $sum += $arlen[$j];
  86. }
  87. }
  88. for ($j = 0; $j < mysql_num_fields($this->Res); $j++) {
  89. if (!in_array(mysql_field_name($this->Res, $j), $this->exclude)) {
  90. $st3 = "class=\"tbl_heading\"";
  91. $fieldname = simplify(mysql_field_name($this->Res, $j));
  92. if ((isset($lang['form_' . mysql_field_name($this->Res, $j)])) && ($lang['form_' . mysql_field_name($this->Res, $j)])) {
  93. $fieldname = $lang['form_' . mysql_field_name($this->Res, $j)];
  94. }
  95. echo "<th $st3 id=\"" . mysql_field_name($this->Res, $j) . "\">$fieldname</th>";
  96. }
  97. }
  98. echo "
  99. <th class=\"tbl_heading\" id=\"page_edit\"></th>
  100. <th class=\"tbl_heading\" id=\"page_delete\"></th>
  101. </tr>
  102. </thead>";
  103. if ($this->finalmax)
  104. $this->limit = $this->finalmax;
  105. echo "
  106. <tbody>";
  107. $counter = NULL;
  108. while ($counter < $this->limit) {
  109. $F = mysql_fetch_array($this->Res);
  110. if (is_even($counter))
  111. $trclass = 'odd';
  112. else
  113. $trclass = 'even';
  114. echo "
  115. <tr class=\"$trclass\">\n";
  116. for ($j = 0; $j < mysql_num_fields($this->Res); $j++) {
  117. if (!in_array(mysql_field_name($this->Res, $j), $this->exclude)) {
  118. if (mysql_field_type($this->Res, $j) == 'timestamp') {
  119. $logunix = returnUnixtimestamp($F[$j]);
  120. $date = safe_strftime($date_format, $logunix);
  121. echo "
  122. <td class=\"tbl_row\" headers=\"" . mysql_field_name($this->Res, $j) . "\">" . $date . "</td>";
  123. } else if (mysql_field_name($this->Res, $j) == 'url') {
  124. echo "
  125. <td class=\"tbl_row\" headers=\"" . mysql_field_name($this->Res, $j) . "\"><a href=\"" . $F[$j] . "\">" . $F[$j] . "</a></td>";
  126. } else if (mysql_field_name($this->Res, $j) == 'email') {
  127. echo "
  128. <td class=\"tbl_row\" headers=\"" . mysql_field_name($this->Res, $j) . "\"><a href=\"mailto:" . $F[$j] . "\">" . $F[$j] . "</a></td>";
  129. } else if ($F[$j] == "") {
  130. echo "
  131. <td class=\"tbl_row\" headers=\"" . mysql_field_name($this->Res, $j) . "\">No Content</td>";
  132. } else {
  133. echo "
  134. <td class=\"tbl_row\" headers=\"" . mysql_field_name($this->Res, $j) . "\">" . strip_tags($F[$j]) . "</td>";
  135. }
  136. }
  137. }
  138. echo "
  139. <td class=\"tbl_row tbl_edit\" headers=\"page_edit\"><a href=\"$this->whereami&amp;edit=$F[0]\" title=\"" . $lang['edit'] . "\">" . $lang['edit'] . "</a></td>
  140. <td class=\"tbl_row tbl_delete\" headers=\"page_delete\"><a href=\"$this->whereami&amp;delete=$F[0]\" onclick=\"return confirm('" . $lang['sure_delete_entry'] . " (#$F[0]) " . $lang['from_the'] . " $page_display_name " . $lang['settings_page'] . "?')\" title=\"" . $lang['delete'] . "\">" . $lang['delete'] . "</a></td>
  141. </tr>";
  142. $counter++;
  143. }
  144. echo "
  145. </tbody>
  146. </table>\n";
  147. }
  148. }
  149. // ------------------------------------------------------------------
  150. // class for add/edit new records in db table
  151. class ShowBlank {
  152. var $Nam;
  153. var $Typ;
  154. var $Res;
  155. var $Flg;
  156. var $Pkn;
  157. var $edit_exclude = array();
  158. var $table_name;
  159. function ShowBlank($Nam, $Typ, $Len, $Flg, $Res, $Pkn, $edit_exclude, $table_name) {
  160. $this->Nam = $Nam;
  161. $this->Typ = $Typ;
  162. $this->Len = $Len;
  163. $this->Res = $Res;
  164. $this->Flg = $Flg;
  165. $this->Pkn = $Pkn;
  166. $this->exclude = $edit_exclude;
  167. $this->tablename = $table_name;
  168. }
  169. function ShowBody() {
  170. global $edit, $s, $m, $x, $page, $page_display_name, $lang, $type;
  171. // check $edit against $x - they need to represent the same page, if not redirect.
  172. $checkid = safe_field('page_id', 'pixie_core', "page_name='$x'");
  173. if ((isset($edit)) && ($edit) && ($m == 'static')) {
  174. if ($edit != $checkid) {
  175. echo "<div class=\"helper\"><h3>" . $lang['help'] . "</h3><p>" . $lang['unknown_edit_url'] . "</p></div>";
  176. $cancel = TRUE;
  177. }
  178. }
  179. if (isset($cancel)) {
  180. } else {
  181. $cancel_not_set = 1;
  182. }
  183. if ($cancel_not_set == 1) {
  184. $Nams = explode('|', substr($this->Nam, 0, (strlen($this->Nam) - 1)));
  185. $Type = explode('|', substr($this->Typ, 0, (strlen($this->Typ) - 1)));
  186. $Leng = explode('|', substr($this->Len, 0, (strlen($this->Len) - 1)));
  187. $Flag = explode('|', substr($this->Flg, 0, (strlen($this->Flg) - 1)));
  188. $Fild = explode('|', substr($this->Res, 0, (strlen($this->Res) - 1)));
  189. if (!$page) {
  190. $page = 1;
  191. }
  192. if ((isset($s)) && ($s == 'settings')) {
  193. if (strpos($this->tablename, 'module')) {
  194. $formtitle = $lang['advanced'] . " " . $lang['page_settings'];
  195. } else if (strpos($this->tablename, 'dynamic')) {
  196. $formtitle = $lang['advanced'] . " " . $lang['page_settings'];
  197. } else {
  198. $formtitle = $lang['page_settings'];
  199. }
  200. } else {
  201. if ((isset($edit)) && ($edit)) {
  202. if ($m == 'static') {
  203. $formtitle = $lang['edit'] . " $page_display_name " . $lang['settings_page'];
  204. } else {
  205. $formtitle = $lang['edit'] . " $page_display_name " . str_replace('.', "", $lang['entry']) . " (#$edit)";
  206. }
  207. } else {
  208. $formtitle = $lang['new_entry'] . " $page_display_name " . str_replace('.', "", $lang['entry']);
  209. }
  210. }
  211. if ((isset($s)) && ($s == 'settings')) {
  212. $post = "?s=$s&amp;x=$x";
  213. } else if (($m == 'static') && (isset($edit))) {
  214. $post = "?s=$s&amp;m=$m&amp;x=$x&amp;edit=$edit&amp;page=$page";
  215. } else {
  216. $post = "?s=$s&amp;m=$m&amp;x=$x&amp;page=$page";
  217. }
  218. echo "<form accept-charset=\"UTF-8\" action=\"$post\" method=\"post\" id=\"form_addedit\" class=\"form\">\n";
  219. echo "\t\t\t\t\t\t<fieldset>\n\t\t\t\t\t\t<legend>$formtitle</legend>\n";
  220. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"table_name\" value=\"$this->tablename\" maxlength=\"80\" />\n";
  221. for ($j = 0; $j < count($Nams); $j++) {
  222. // clears out the form as some of the fields populate
  223. if ((!isset($edit)) or (!$edit)) {
  224. $Fild[$j] = "";
  225. }
  226. // if comments are disabled then hide the field
  227. if (($Nams[$j] == 'comments') && (!public_page_exists('comments'))) {
  228. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"no\" maxlength=\"" . $Leng[$j] . "\" />\n";
  229. $j++;
  230. }
  231. if (!in_array($Nams[$j], $this->exclude)) { //fields populated and output depending on type etc.
  232. //$searchfor = "_".first_word($Nams[$j]);
  233. if ($Leng[$j] < 40) {
  234. $ln = $Leng[$j];
  235. } else if ($Leng[$j] <= 400) {
  236. $ln = 50;
  237. }
  238. $nullf = explode(" ", $Flag[$j]);
  239. if ($nullf[0] == 'not_null') { // label required fields
  240. if ((isset($lang['form_' . $Nams[$j]]))) {
  241. if (($Nams[$j] != 'page_name') or ($type == 'static') or (!isset($edit)) or (!$edit)) {
  242. /* Prevents the editing of page_name which does not work in modules and dynamic pages */
  243. $displayname = $lang['form_' . $Nams[$j]] . " <span class=\"form_required\">" . $lang['form_required'] . "</span>";
  244. } else {
  245. $displayname = " <span style=\"display:none\" class=\"form_required\">" . $lang['form_required'] . "</span>";
  246. }
  247. } else {
  248. $displayname = simplify($Nams[$j]) . " <span class=\"form_required\">" . $lang['form_required'] . "</span>";
  249. }
  250. } else {
  251. if ((isset($lang['form_' . $Nams[$j]])) && ($lang['form_' . $Nams[$j]])) {
  252. $displayname = $lang['form_' . $Nams[$j]] . " <span class=\"form_optional\">" . $lang['form_optional'] . "</span>";
  253. } else {
  254. $displayname = simplify($Nams[$j]) . " <span class=\"form_optional\">" . $lang['form_optional'] . "</span>";
  255. }
  256. }
  257. // check language file for any form help
  258. if ((isset($lang['form_help_' . $Nams[$j]])) && ($lang['form_help_' . $Nams[$j]])) {
  259. if (($Nams[$j] != 'page_name') or ($type == 'static') or (!isset($edit)) or (!$edit)) {
  260. /* Prevents the editing of page_name which does not work in modules and dynamic pages */
  261. $form_help = "<span class=\"form_help\">" . $lang['form_help_' . $Nams[$j]] . "</span>";
  262. } else {
  263. $form_help = "<span style=\"display:none\" class=\"form_help\">" . $lang['form_help_' . $Nams[$j]] . "</span>";
  264. }
  265. } else {
  266. $form_help = "";
  267. }
  268. if ($GLOBALS['rich_text_editor'] == 1) {
  269. $containsphp = strlen(stristr(utf8_decode(($Fild[$j])), '<?php')) > 0;
  270. if ($containsphp) {
  271. $form_help .= " <span class=\"alert\">" . $lang['form_php_warning'] . '</span>';
  272. }
  273. }
  274. echo "\t\t\t\t\t\t\t<div class=\"form_row\">\n\t\t\t\t\t\t\t\t<div class=\"form_label\">
  275. <label for=\"$Nams[$j]\">" . $displayname . "</label>$form_help</div>\n"; //$Type[$j] $Leng[$j] $Flag[$j] for field info
  276. //echo "$Nams[$j] - $Type[$j] - $Leng[$j] - $Flag[$j]"; // see form field properties
  277. if (($Type[$j] == 'timestamp') && (!isset($edit)) && (!$edit)) {
  278. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  279. if (isset($date)) {
  280. date_dropdown($date);
  281. } else {
  282. $date = NULL;
  283. date_dropdown($date);
  284. }
  285. echo "\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  286. } else if (($Type[$j] == 'timestamp') && (isset($edit)) && ($edit)) {
  287. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  288. date_dropdown($Fild[$j]);
  289. echo "\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  290. //} else if ($Type[$j] == "blob") {
  291. // echo "\t\t\t\t\t\t\t\t<div class=\"form_item_textarea\">\n\t\t\t\t\t\t\t\t<textarea name=\"$Nams[$j]\" class=\"form_item_textarea_no_ckeditor\">$Fild[$j]</textarea>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  292. } else if ($Type[$j] == 'longtext' or $Leng[$j] > 800 or $Type[$j] == 'blob') {
  293. if ($GLOBALS['rich_text_editor'] == 1) {
  294. if (!$containsphp) {
  295. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_textarea_ckeditor\">\n\t\t\t\t\t\t\t\t\t\t<textarea name=\"$Nams[$j]\" id=\"$Nams[$j]\" cols=\"50\" class=\"ck-textarea\" rows=\"10\">" . htmlentities($Fild[$j], ENT_QUOTES, 'UTF-8') . "</textarea>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n"; // id=\"$Nams[$j]\"
  296. } else {
  297. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_textarea\">\n\t\t\t\t\t\t\t\t<textarea name=\"$Nams[$j]\" class=\"form_item_textarea_no_ckeditor\">" . htmlspecialchars($Fild[$j], ENT_QUOTES, 'UTF-8') . "</textarea>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n"; // id=\"$Nams[$j]\"
  298. }
  299. } else {
  300. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_textarea\">\n\t\t\t\t\t\t\t\t<textarea name=\"$Nams[$j]\" class=\"form_item_textarea_no_ckeditor\">" . htmlspecialchars($Fild[$j], ENT_QUOTES, 'UTF-8') . "</textarea>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n"; // id=\"$Nams[$j]\"
  301. }
  302. } else if ($Type[$j] == "set'yes','no'" or $Flag[$j] == 'not_null set') {
  303. if ($Fild[$j] == 'no') {
  304. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_radio\">\n\t\t\t\t\t\t\t\tYes<input type=\"radio\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" class=\"form_radio\" value=\"yes\" />
  305. No<input checked=\"checked\" type=\"radio\" name=\"$Nams[$j]\" class=\"form_radio\" value=\"$Fild[$j]\" />\n\t\t\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t\t</div>\n";
  306. } else {
  307. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_radio\">\n\t\t\t\t\t\t\t\tYes<input checked=\"checked\" type=\"radio\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" class=\"form_radio\" value=\"yes\" />
  308. No<input type=\"radio\" name=\"$Nams[$j]\" class=\"form_radio\" value=\"no\"/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  309. }
  310. } else if (first_word($Nams[$j]) == 'image') {
  311. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop image_preview\">\n";
  312. db_dropdown('pixie_files', $Fild[$j], $Nams[$j], "file_type = 'Image' order by file_id desc");
  313. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $Nams[$j] . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  314. } else if (first_word($Nams[$j]) == 'document') {
  315. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  316. db_dropdown('pixie_files', $Fild[$j], $Nams[$j], "file_type = 'Other' order by file_id desc");
  317. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $Nams[$j] . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  318. } else if (first_word($Nams[$j]) == 'video') {
  319. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  320. db_dropdown('pixie_files', $Fild[$j], $Nams[$j], "file_type = 'Video' order by file_id desc");
  321. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $Nams[$j] . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  322. } else if (first_word($Nams[$j]) == 'audio') {
  323. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  324. db_dropdown('pixie_files', $Fild[$j], $Nams[$j], "file_type = 'Audio' order by file_id desc");
  325. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $Nams[$j] . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  326. } else if (first_word($Nams[$j]) == 'file') {
  327. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">\n";
  328. db_dropdown('pixie_files', $Fild[$j], $Nams[$j], "file_id >= '0' order by file_id desc");
  329. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $Nams[$j] . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  330. } else if ($Nams[$j] == 'tags') {
  331. $tableid = 0;
  332. $condition = $tableid . " >= '0'";
  333. form_tag($this->tablename, $condition);
  334. echo "\t\t\t\t\t\t\t\t<div class=\"form_item\">\n\t\t\t\t\t\t\t\t<input type=\"text\" class=\"form_text\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" value=\"$Fild[$j]\" size=\"";
  335. if ((isset($ln))) {
  336. echo $ln;
  337. } else {
  338. $ln = 25;
  339. echo $ln;
  340. }
  341. echo "\" maxlength=\"" . $Leng[$j] . "\" />\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  342. } else if ($Nams[$j] == 'page_blocks') {
  343. form_blocks();
  344. echo "\t\t\t\t\t\t\t\t<div class=\"form_item\">\n\t\t\t\t\t\t\t\t<input type=\"text\" class=\"form_text\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" value=\"$Fild[$j]\" size=\"";
  345. if ((isset($ln))) {
  346. echo $ln;
  347. } else {
  348. $ln = 25;
  349. echo $ln;
  350. }
  351. echo "\" maxlength=\"" . $Leng[$j] . "\" />\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n";
  352. } else if ($Nams[$j] == 'privs') {
  353. if ($Fild[$j] == 2) {
  354. $adminclass = "selected=\"selected\"";
  355. $everyoneclass = NULL;
  356. } else {
  357. $everyoneclass = "selected=\"selected\"";
  358. $adminclass = NULL;
  359. }
  360. echo "\t\t\t\t\t\t\t\t<div class=\"form_item_drop\">
  361. <select class=\"form_select\" name=\"$Nams[$j]\" name=\"$Nams[$j]\">
  362. <option value=\"2\" $adminclass>Administrators only</option>
  363. <option value=\"1\" $everyoneclass>Administrators &amp; Clients</option>
  364. </select>
  365. </div>\n\t\t\t\t\t\t\t</div>\n";
  366. } else {
  367. if (($Nams[$j] != 'page_name') or ($type == 'static') or (!isset($edit)) or (!$edit)) {
  368. /* Prevents the editing of page_name which does not work in modules and dynamic pages */
  369. echo "\t\t\t\t\t\t\t\t<div class=\"form_item\">\n\t\t\t\t\t\t\t\t<input type=\"text\" class=\"form_text\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" value=\"" . htmlspecialchars($Fild[$j], ENT_QUOTES, 'UTF-8') . "\" size=\"";
  370. if ((isset($ln))) {
  371. echo $ln;
  372. } else {
  373. $ln = 25;
  374. echo $ln;
  375. }
  376. echo "\" maxlength=\"" . $Leng[$j] . "\" />\n\t\t\t\t\t\t\t\t</div>";
  377. } else {
  378. echo "\t\t\t\t\t\t\t\t<div style=\"display:none\" class=\"form_item\">\n\t\t\t\t\t\t\t\t<input style=\"display:none\" type=\"text\" class=\"form_text\" name=\"$Nams[$j]\" id=\"$Nams[$j]\" value=\"" . htmlspecialchars($Fild[$j], ENT_QUOTES, 'UTF-8') . "\" size=\"";
  379. if ((isset($ln))) {
  380. echo $ln;
  381. } else {
  382. $ln = 25;
  383. echo $ln;
  384. }
  385. echo "\" maxlength=\"" . $Leng[$j] . "\" />\n\t\t\t\t\t\t\t\t</div>";
  386. }
  387. echo "\n\t\t\t\t\t\t\t</div>\n";
  388. }
  389. //other field types still to come: File uploads...?
  390. //hidden fields populated
  391. } else {
  392. if ((($Nams[$j] == 'page_id') && (isset($s)) && ($s == 'publish') && ($m == 'dynamic'))) {
  393. $page_id = get_page_id($x);
  394. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"$page_id\" maxlength=\"" . $Leng[$j] . "\" />\n";
  395. } else if (last_word($Nams[$j]) == 'id') {
  396. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"$Fild[$j]\" maxlength=\"" . $Leng[$j] . "\" />\n";
  397. } else if (($Nams[$j] == 'author')) {
  398. if ((isset($edit)) && ($edit)) {
  399. $output = $Fild[$j];
  400. } else {
  401. if (!isset($GLOBALS['pixie_user'])) {
  402. $GLOBALS['pixie_user'] = NULL;
  403. }
  404. $output = $GLOBALS['pixie_user'];
  405. }
  406. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"" . $output . "\" maxlength=\"" . $Leng[$j] . "\" />\n";
  407. } else if ($Type[$j] == "timestamp") {
  408. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"" . returnSQLtimestamp(time()) . "\" maxlength=\"" . $Leng[$j] . "\" />\n";
  409. } else if ($Nams[$j] == 'page_type') {
  410. if ($type) {
  411. $output = $type;
  412. } else {
  413. if (isset($edit)) {
  414. $output = safe_field('page_type', 'pixie_core', "page_id='$edit'");
  415. }
  416. }
  417. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"" . $output . "\" maxlength=\"" . $Leng[$j] . "\" />\n";
  418. } else if (($Nams[$j] == 'publish' && !$edit)) {
  419. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"yes\" maxlength=\"0\" />\n";
  420. } else if ($Nams[$j] == 'page_content') {
  421. // do nothing
  422. } else if ($Nams[$j] == 'admin') {
  423. // do nothing
  424. } else {
  425. echo "\t\t\t\t\t\t\t<input type=\"hidden\" class=\"form_text\" name=\"$Nams[$j]\" value=\"$Fild[$j]\" maxlength=\"" . $Leng[$j] . "\" />\n";
  426. }
  427. }
  428. }
  429. if ((isset($edit)) && ($edit)) {
  430. echo "\t\t\t\t\t\t\t<div class=\"form_row_button\">\n\t\t\t\t\t\t\t\t<input type=\"submit\" name=\"submit_edit\" class=\"form_submit\" value=\"" . $lang['form_button_update'] . "\" />\n\t\t\t\t\t\t\t</div>\n";
  431. } else if ((isset($go)) && ($go == 'new')) {
  432. // do a save draft and save button button?? - when everything can be saved as a draft and is autosaved using AJAX
  433. } else {
  434. echo "\t\t\t\t\t\t\t<div class=\"form_row_button\" id=\"form_button\">\n\t\t\t\t\t\t\t\t<input type=\"submit\" name=\"submit_new\" class=\"form_submit\" value=\"" . $lang['form_button_save'] . "\" />\n\t\t\t\t\t\t\t</div>\n";
  435. }
  436. if ($m != 'static') {
  437. echo "\t\t\t\t\t\t\t<div class=\"form_row_button\">\n\t\t\t\t\t\t\t\t<span class=\"form_button_cancel\"><a href=\"?s=$s&amp;m=$m&amp;x=$x\" title=\"" . $lang['form_button_cancel'] . "\">" . $lang['form_button_cancel'] . "</a></span>\n\t\t\t\t\t\t\t</div>\n";
  438. }
  439. echo "\t\t\t\t\t\t\t<div class=\"safclear\"></div>\n\t\t\t\t\t\t</fieldset>\n";
  440. echo "\t\t\t\t\t</form>";
  441. }
  442. }
  443. }
  444. // ------------------------------------------------------------------
  445. // build module page
  446. function admin_module($module_name, $table_name, $order_by, $asc_desc, $exclude = array(NULL), $edit_exclude = array(NULL), $view_number, $tags) {
  447. global $type, $go, $page, $message, $s, $m, $x, $edit, $submit_new, $submit_edit, $delete, $messageok, $new, $search_submit, $field, $search_words;
  448. if ((isset($GLOBALS['pixie_user_privs'])) && ($GLOBALS['pixie_user_privs'] >= 1)) {
  449. $type = 'module';
  450. if ((isset($go)) && ($go == 'new') && (isset($table_name))) {
  451. admin_head();
  452. admin_new($table_name, $edit_exclude);
  453. } else if ((isset($edit)) && ($edit) && (isset($table_name))) {
  454. admin_head();
  455. admin_edit($table_name, $module_name . '_id', $edit, $edit_exclude);
  456. } else if (isset($table_name)) {
  457. admin_carousel($x);
  458. echo "\n\t\t\t\t<div id=\"blocks\">\n";
  459. admin_block_search($type);
  460. if ((isset($tags)) && ($tags == 'yes')) {
  461. admin_block_tag_cloud($table_name, $module_name . "_id >= 0");
  462. }
  463. echo "\t\t\t\t</div>\n";
  464. admin_head();
  465. echo "\t\t\t\t<div id=\"pixie_content\">";
  466. admin_overview($table_name, '', $order_by, $asc_desc, $exclude, $view_number, $type);
  467. echo "\t\t\t\t</div>\n";
  468. }
  469. }
  470. }
  471. // ------------------------------------------------------------------
  472. // display page information
  473. function admin_head() {
  474. global $s, $m, $x, $page_display_name, $page_id, $edit, $go, $lang, $tag, $search_words, $search_submit;
  475. $rs = safe_row('*', 'pixie_core', "page_name = '$x' limit 0,1");
  476. if ($rs) {
  477. extract($rs);
  478. if ((isset($tag)) && ($tag)) {
  479. $stitle = $page_display_name . " (" . ucwords($lang['all_posts_tagged']) . ": " . $tag . ")";
  480. } else if ($search_words) {
  481. $stitle = $page_display_name . " (" . $lang['search'] . ": " . chopme(sterilise($search_words), 40) . ")";
  482. } else if ($search_submit) {
  483. $stitle = $page_display_name . " (" . $lang['search'] . ": $search_submit)";
  484. } else {
  485. $stitle = $page_display_name;
  486. }
  487. if ((!isset($edit)) or (!$edit)) {
  488. if ((!isset($go)) or (!$go)) {
  489. // do not want people to be able to add to comments in this way
  490. if ($x != 'comments') {
  491. echo "
  492. <ul id=\"page_tools\">
  493. <li><a href=\"?s=$s&amp;m=$m&amp;x=$x&amp;go=new\" title=\"" . $lang['new_entry'] . "$page_display_name " . str_replace('.', "", $lang['entry']) . "\">" . $lang['new_entry'] . "$page_display_name " . str_replace('.', "", $lang['entry']) . "</a></li>
  494. </ul>\n";
  495. }
  496. }
  497. }
  498. echo "\t\t\t\t<div id=\"page_header\">
  499. <h2>$stitle</h2>
  500. </div>\n";
  501. }
  502. }
  503. // ------------------------------------------------------------------
  504. // display admin block for searching
  505. function admin_block_search($type) {
  506. global $s, $m, $x, $lang;
  507. echo "\n\t\t\t\t\t<div id=\"admin_block_search\" class=\"admin_block\">
  508. \t\t\t<h3 class=\"$type\">" . $lang['search'] . "</h3>\n";
  509. echo "\t\t\t\t\t\t<form accept-charset=\"UTF-8\" action=\"?s=$s&amp;m=$m&amp;x=$x\" method=\"post\" id=\"search\">
  510. <fieldset>
  511. <legend>" . $lang['search'] . "</legend>
  512. <div class=\"form_row\">
  513. <div class=\"form_label\"><label for=\"search-keywords\">" . $lang['form_search_words'] . "</label></div>
  514. <div class=\"form_item\"><input type=\"text\" name=\"search_words\" id=\"search-keywords\" value=\"\" class=\"form_text\" size=\"25\" /></div>
  515. </div>
  516. <div class=\"form_row_button\">
  517. <input type=\"submit\" name=\"search_submit\" id=\"search_submit\" value=\"" . $lang['search'] . "\" />
  518. </div>
  519. </fieldset>
  520. </form>";
  521. echo "\n\t\t\t\t\t</div>\n";
  522. }
  523. // ------------------------------------------------------------------
  524. // view table overview
  525. function admin_overview($table_name, $condition, $order_by, $asc_desc, $exclude = array(NULL), $view_number, $type) {
  526. global $page, $message, $s, $m, $x, $messageok, $search_submit, $field, $search_words, $tag, $lang;
  527. $table_name = adjust_prefix($table_name);
  528. $searchwords = trim($search_words);
  529. if ($page) {
  530. $searchwords = $search_submit;
  531. }
  532. if (($search_submit) && (isset($table_name))) {
  533. $searchwords = sterilise($searchwords, FALSE);
  534. //build search sql
  535. $r2 = safe_query("show fields from $table_name");
  536. for ($j = 0; $j < mysql_num_rows($r2); $j++) {
  537. if ($F = mysql_fetch_array($r2)) {
  538. $an[$j] = $F['Field'];
  539. }
  540. if (last_word($an[$j]) != 'id') {
  541. if ($an[$j] != 'posted') {
  542. if ($an[$j] != 'author') {
  543. if ($an[$j] != 'comments') {
  544. if ($an[$j] != 'public') {
  545. if (first_word($an[$j]) != 'last') {
  546. if ($an[$j] != 'date') {
  547. $search_sql .= $an[$j] . " like '%" . $searchwords . "%' OR ";
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. $search_sql = substr($search_sql, 0, (strlen($search_sql) - 3)) . "";
  557. //echo $search_sql;
  558. }
  559. if (isset($tag)) {
  560. $tag = squash_slug($tag);
  561. }
  562. if (isset($table_name)) {
  563. if ($search_submit) {
  564. if ($m == 'dynamic') {
  565. $page_id = get_page_id($x);
  566. $r1 = safe_query("select * from $table_name where page_id = '$page_id' and (" . $search_sql . ") order by $order_by $asc_desc");
  567. } else {
  568. $r1 = safe_query("select * from $table_name where " . $search_sql . " order by $order_by $asc_desc");
  569. }
  570. } else if ((isset($tag)) && ($tag)) {
  571. $r1 = safe_query("select * from $table_name where tags REGEXP '[[:<:]]" . $tag . "[[:>:]]' order by $order_by $asc_desc");
  572. } else {
  573. $r1 = safe_query("select * from $table_name $condition order by $order_by $asc_desc");
  574. }
  575. }
  576. if ($r1) {
  577. $total = mysql_num_rows($r1);
  578. if ((!isset($page)) && (isset($table_name))) {
  579. $lo = 0;
  580. $page = 1;
  581. if ($search_submit) {
  582. if ($m == 'dynamic') {
  583. $page_id = get_page_id($x);
  584. $r = safe_query("select * from $table_name where page_id = '$page_id' and (" . $search_sql . ") order by $order_by $asc_desc");
  585. } else {
  586. $r = safe_query("select * from $table_name where " . $search_sql . " order by $order_by $asc_desc");
  587. }
  588. } else if ((isset($tag)) && ($tag)) {
  589. $r = safe_query("select * from $table_name where tags REGEXP '[[:<:]]" . $tag . "[[:>:]]' order by $order_by $asc_desc");
  590. } else {
  591. $r = safe_query("select * from $table_name $condition order by $order_by $asc_desc limit $lo,$view_number");
  592. }
  593. } else if (isset($table_name)) {
  594. $lo = ($page - 1) * $view_number;
  595. if ($search_submit) {
  596. if ($m == 'dynamic') {
  597. $page_id = get_page_id($x);
  598. $r = safe_query("select * from $table_name where page_id = '$page_id' and (" . $search_sql . ") order by $order_by $asc_desc");
  599. } else {
  600. $r = safe_query("select * from $table_name where " . $search_sql . " order by $order_by $asc_desc");
  601. }
  602. } else if ((isset($tag)) && ($tag)) {
  603. $r = safe_query("select * from $table_name where tags REGEXP '[[:<:]]" . $tag . "[[:>:]]' order by $order_by $asc_desc");
  604. } else {
  605. $r = safe_query("select * from $table_name $condition order by $order_by $asc_desc limit $lo,$view_number");
  606. }
  607. }
  608. if ($r) {
  609. $rows = mysql_num_rows($r);
  610. $hi = $lo + $view_number;
  611. if ($hi > $total) {
  612. $finalmax = $total - $lo;
  613. $hi = $total;
  614. }
  615. $pages = ceil($total / $view_number);
  616. if ($pages < 1) {
  617. $pages = 1;
  618. }
  619. }
  620. /* Was : */
  621. /* $a = &new Paginator_html($page, $total); */
  622. /* but it's providing a "Assigning the return value of new by reference is deprecated" message. */
  623. $a = new Paginator_html($page, $total);
  624. $a->set_Limit($view_number);
  625. $a->set_Links(4);
  626. $whereami = "?s=$s&amp;m=$m&amp;x=$x";
  627. if ((isset($tag)) && ($tag)) {
  628. $whereami = "?s=$s&amp;m=$m&amp;x=$x&amp;tag=$tag";
  629. }
  630. if ($search_submit) {
  631. $whereami = "?s=$s&amp;m=$m&amp;x=$x&amp;search_submit=$searchwords";
  632. }
  633. echo "\n\t\t\t\t\t<div class=\"admin_table_holder pcontent\">\n\t\t\t\t\t";
  634. $wheream = "?s=$s&amp;m=$m&amp;x=$x&amp;page=$page";
  635. if ((isset($table_name)) && ($rows)) {
  636. if (isset($finalmax) && ($finalmax)) {
  637. } else {
  638. $finalmax = NULL;
  639. }
  640. $Table = new ShowTable($r, $exclude, $table_name, $view_number, $lo, $finalmax, $wheream, $type, $s);
  641. $Table->DrawBody();
  642. $loprint = $lo + 1;
  643. echo "\n\t\t\t\t\t\t<div id=\"admin_table_overview\">\n\t\t\t\t\t\t\t<p>" . $lang['total_records'] . ": $total (" . $lang['showing_from_record'] . " $loprint " . $lang['to'] . " $hi) $pages " . $lang['page(s)'] . ".</p>\n\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t<div id=\"admin_table_pages\">\n\t\t\t\t\t\t\t";
  644. echo "<p>";
  645. $a->previousNext($whereami);
  646. echo "</p>";
  647. echo "\n\t\t\t\t\t\t</div>";
  648. } else {
  649. if (($search_submit) or (isset($tag)) && ($tag)) {
  650. echo "<div class=\"helper\"><h3>" . $lang['help'] . "</h3><p>" . $lang['helper_search'] . "</p></div>";
  651. } else {
  652. echo "<div class=\"helper\"><h3>" . $lang['help'] . "</h3><p>" . $lang['helper_nocontent'] . "</p></div>";
  653. }
  654. echo "\n\t\t\t\t\t</div>\n";
  655. }
  656. if ($rows) {
  657. echo "\n\t\t\t\t\t</div>\n";
  658. }
  659. }
  660. }
  661. // ------------------------------------------------------------------
  662. // show the page carousel
  663. function admin_carousel($current) {
  664. global $s, $lang;
  665. echo "<h2>" . $lang['nav2_pages'] . "</h2>\n";
  666. $rz = safe_rows('*', 'pixie_core', "public = 'yes' and publish = 'yes' order by page_order asc");
  667. $cc = 1;
  668. if (count($rz) <= 1) {
  669. if ((isset($GLOBALS['pixie_user_privs'])) && ($GLOBALS['pixie_user_privs'] >= 2)) {
  670. echo "\t\t\t\t<div class=\"helper\"><h3>" . $lang['help'] . "</h3><p>" . $lang['helper_nopages404'] . " " . $lang['helper_nopagesadmin'] . "</p></div>\n";
  671. } else {
  672. echo "\t\t\t\t<div class=\"helper\"><h3>" . $lang['help'] . "</h3><p>" . $lang['helper_nopages404'] . " " . $lang['helper_nopagesuser'] . "</p></div>\n";
  673. }
  674. } else {
  675. echo "\t\t\t\t<ul id=\"mycarousel\" class=\"jcarousel-skin-tango\">\n";
  676. if (isset($GLOBALS['pixie_user_privs'])) {
  677. $rs = safe_rows('*', 'pixie_core', "public = 'yes' and in_navigation = 'yes' and publish = 'yes' and page_type != 'plugin' and privs <= '" . $GLOBALS['pixie_user_privs'] . "' order by page_order asc");
  678. }
  679. if ($rs) {
  680. $num = count($rs);
  681. $i = 0;
  682. while ($i < $num) {
  683. $out = $rs[$i];
  684. $page_display_name = $out['page_display_name'];
  685. $page_name = $out['page_name'];
  686. $page_type = $out['page_type'];
  687. $page_id = $out['page_id'];
  688. $m = $page_type;
  689. $x = $page_name;
  690. if ($current == $x) {
  691. $class = 'current';
  692. $scroll = $cc;
  693. } else {
  694. $class = "";
  695. }
  696. if ($m == 'dynamic') {
  697. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page innav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_dynamic.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  698. } else if ($m == 'module') {
  699. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page innav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_module.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  700. } else {
  701. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page innav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x&amp;edit=$page_id\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_static.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  702. }
  703. $cc++;
  704. $i++;
  705. }
  706. }
  707. if (isset($GLOBALS['pixie_user_privs'])) {
  708. $rs = safe_rows('*', 'pixie_core', "public = 'yes' and in_navigation = 'no' and publish = 'yes' and page_type != 'plugin' and privs <= '" . $GLOBALS['pixie_user_privs'] . "' order by page_name asc");
  709. }
  710. if ($rs) {
  711. $num = count($rs);
  712. $i = 0;
  713. while ($i < $num) {
  714. $out = $rs[$i];
  715. $page_display_name = $out['page_display_name'];
  716. $page_name = $out['page_name'];
  717. $page_type = $out['page_type'];
  718. $page_id = $out['page_id'];
  719. $m = $page_type;
  720. $x = $page_name;
  721. if ($current == $x) {
  722. $class = 'current';
  723. $scroll = $cc;
  724. } else {
  725. $class = "";
  726. }
  727. if ($m == 'dynamic') {
  728. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page outnav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_dynamic_white.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  729. } else if ($m == 'module') {
  730. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page outnav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_module_white.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  731. } else {
  732. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page outnav $class\"><a href=\"?s=$s&amp;m=$m&amp;x=$x&amp;edit=$page_id\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_static_white.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  733. }
  734. $cc++;
  735. $i++;
  736. }
  737. }
  738. if (isset($GLOBALS['pixie_user_privs'])) {
  739. $rs = safe_rows('*', 'pixie_core', "public = 'yes' and in_navigation = 'no' and publish = 'yes' and page_type = 'plugin' and privs <= '" . $GLOBALS['pixie_user_privs'] . "' order by page_order asc");
  740. }
  741. if ($rs) {
  742. $num = count($rs);
  743. $i = 0;
  744. while ($i < $num) {
  745. $out = $rs[$i];
  746. $page_display_name = $out['page_display_name'];
  747. $page_name = $out['page_name'];
  748. $page_type = $out['page_type'];
  749. $page_id = $out['page_id'];
  750. $m = $page_type;
  751. $x = $page_name;
  752. if ($current == $x) {
  753. $class = 'current';
  754. $scroll = $cc;
  755. } else {
  756. $class = "";
  757. }
  758. echo "\t\t\t\t\t<li id=\"c_$page_name\" class=\"page plugin $class\"><a href=\"?s=$s&amp;m=module&amp;x=$x\"><span class=\"page_title\">$page_display_name</span><img src=\"admin/theme/images/icons/page_plugin.png\" alt=\"$m\" class=\"picon\" /></a></li>\n";
  759. $cc++;
  760. $i++;
  761. }
  762. }
  763. echo "\t\t\t\t</ul>\n";
  764. }
  765. // move carousel to current page
  766. echo "
  767. <script type=\"text/javascript\">
  768. function mycarousel_itemFirstInCallback(carousel, item, idx, state)
  769. {
  770. if (state == 'init') carousel.scroll($scroll, false);
  771. };
  772. </script>
  773. ";
  774. }
  775. // ------------------------------------------------------------------
  776. // edit table entry
  777. function admin_edit($table_name, $edit_id, $edit, $edit_exclude) {
  778. global $message, $m, $lang;
  779. $an = NULL;
  780. $at = NULL;
  781. $al = NULL;
  782. $af = NULL;
  783. $az = NULL;
  784. if (isset($table_name)) {
  785. $table_name = adjust_prefix($table_name);
  786. }
  787. if ((isset($edit)) && (isset($table_name))) {
  788. $sql = "select * from $table_name where {$edit_id}={$edit}";
  789. $r2 = safe_query($sql);
  790. }
  791. if ($r2) {
  792. if ($f = mysql_fetch_array($r2)) {
  793. for ($j = 0; $j < mysql_num_fields($r2); $j++) {
  794. $an .= mysql_field_name($r2, $j) . "|";
  795. $at .= mysql_field_type($r2, $j) . "|";
  796. $al .= "50|";
  797. /* Some field lengths seem unset or inconsistent. CSS classes would handle this better. */
  798. /* $al .= mysql_field_len($r2, $j) . "|"; */
  799. $af .= mysql_field_flags($r2, $j) . "|";
  800. $az .= $f[$j] . "|";
  801. }
  802. if ($m == 'static') {
  803. echo "\n\t\t\t\t<div class=\"admin_form form_static\">\n\n\t\t\t\t\t";
  804. } else {
  805. echo "\n\t\t\t\t<div class=\"admin_form\">\n\n\t\t\t\t\t";
  806. }
  807. if (isset($table_name)) {
  808. if (!isset($nam)) {
  809. $nam = NULL;
  810. }
  811. $Blank = new ShowBlank($an, $at, $al, $af, $az, $nam, $edit_exclude, $table_name);
  812. $Blank->ShowBody();
  813. }
  814. echo "\n\t\t\t\t</div>";
  815. }
  816. } else {
  817. $message = $lang['form_build_fail'];
  818. }
  819. }
  820. // ------------------------------------------------------------------
  821. // add new table entry
  822. function admin_new($table_name, $edit_exclude) {
  823. if (isset($table_name)) {
  824. $an = $at = $af = $az = $al = '';
  825. $r2 = safe_query('show fields from ' . PFX . "$table_name");
  826. $r3 = safe_query('select * from ' . PFX . "$table_name WHERE 1=0");
  827. for ($j = 0; $j < mysql_num_rows($r2); $j++) {
  828. $flags = mysql_field_flags($r3, $j);
  829. $af .= $flags . '|';
  830. if ($F = mysql_fetch_array($r2)) {
  831. $an .= $F['Field'] . '|';
  832. $at .= preg_replace('([()0-9]+)', "", $F['Type']) . '|';
  833. }
  834. if (preg_match('([0-9]+)', $F['Type'], $str)) {
  835. $al .= $str[0] . '|';
  836. } else {
  837. $al .= '|';
  838. $az .= $F['Default'] . '|';
  839. }
  840. if ($F['Key'] == "PRI") {
  841. $nam = $F['Field'];
  842. }
  843. }
  844. echo "\n\t\t\t\t<div id=\"admin_form\">\n\n\t\t\t\t\t";
  845. if (isset($table_name)) {
  846. $Blank = new ShowBlank($an, $at, $al, $af, $az, $nam, $edit_exclude, $table_name);
  847. $Blank->ShowBody();
  848. }
  849. echo "\n\t\t\t\t</div>";
  850. }
  851. }
  852. // ------------------------------------------------------------------
  853. // delete code
  854. if ((isset($GLOBALS['pixie_user'])) && (isset($GLOBALS['pixie_user_privs'])) && ($GLOBALS['pixie_user_privs'] >= 1)) {
  855. if (isset($delete)) {
  856. if ((isset($s)) && ($s == 'settings') && ($delete == 1)) {
  857. // protect 404
  858. } else if ((isset($s)) && ($s == 'settings')) {
  859. $table = 'pixie_core';
  860. $id = 'page_id';
  861. } else if ((isset($s)) && ($s == 'publish') && ($m == 'dynamic')) {
  862. $table = 'pixie_dynamic_posts';
  863. $id = 'post_id';
  864. } else if ((isset($s)) && ($s == 'publish') && ($m == 'module')) {
  865. $table = 'pixie_module_' . $x;
  866. $id = $x . '_id';
  867. }
  868. $table = adjust_prefix($table);
  869. $getdetails = extract(safe_row('*', "$table", "$id='$delete' limit 0,1"));
  870. if ($getdetails) {
  871. $del = safe_delete("$table", "$id='$delete'");
  872. }
  873. if ((isset($del)) && ($del)) {
  874. if ((isset($s)) && (isset($m)) && ($s == 'settings') && ($m == 'dynamic')) {
  875. $page_display_name = safe_field('page_display_name', 'pixie_core', "page_id='$del'");
  876. //do not delete the posts as one false click could destroy lots of data. Backup first?
  877. //safe_delete("pixie_dynamic_posts", "page_id='$delete'");
  878. safe_delete('pixie_dynamic_settings', "page_id='$delete'");
  879. }
  880. if ((isset($s)) && (isset($m)) && (isset($del)) && ($s == 'settings') && ($m == 'static')) {
  881. $page_display_name = safe_field('page_display_name', 'pixie_core', "page_id='$del'");
  882. safe_delete('pixie_static_posts', "page_id='$delete'");
  883. }
  884. if ((isset($s)) && (isset($m)) && ($s == 'settings') && ($m == 'module')) {
  885. $table_mod = PFX . 'pixie_module_' . $page_name;
  886. $table_mod_settings = PFX . 'pixie_module_' . $page_name . '_settings';
  887. $sql = "DROP TABLE IF EXISTS $table_mod";
  888. $sql1 = "DROP TABLE IF EXISTS $table_mod_settings";
  889. //do not drop the tables as one false click could destroy lots of data. Backup first?
  890. //safe_query($sql);
  891. //safe_query($sql1);
  892. //do not remove the file as we might want to reinstall at a later date
  893. //file_delete("modules/".$page_name.".php");
  894. }
  895. if ($table == PFX . 'pixie_core') {
  896. $messageok = $lang['ok_delete_page'] . " " . $page_display_name . " " . $lang['page'];
  897. $icon = 'site';
  898. $alert = 'yes';
  899. } else {
  900. $page_display_name = safe_field('page_display_name', 'pixie_core', "page_name='$x'");
  901. $messageok = $lang['ok_delete_entry'] . " " . $page_display_name . " " . $lang['page'];
  902. $icon = 'page';
  903. $alert = 'no';
  904. }
  905. logme($messageok, $alert, $icon);
  906. if (isset($table_name)) {
  907. safe_optimize("$table_name");
  908. safe_repair("$table_name");
  909. }
  910. } else {
  911. if (!$message) {
  912. if ((isset($s)) && ($s == 'settings') && ($delete == 1)) {
  913. $message = $lang['failed_protected_page'];
  914. $imp = 'yes';
  915. } else {
  916. $message = $lang['failed_delete'];
  917. $imp = 'no';
  918. }
  919. logme($message, $imp, 'error');
  920. }
  921. }
  922. }
  923. }
  924. // ------------------------------------------------------------------
  925. // save and edit code
  926. if ((isset($GLOBALS['pixie_user'])) && (isset($GLOBALS['pixie_user_privs'])) && ($GLOBALS['pixie_user_privs'] >= 1)) {
  927. if ((isset($submit_edit)) && ($submit_edit) or (isset($submit_new)) && ($submit_new)) {
  928. $rs = safe_row('*', 'pixie_core', "page_name = '$x' limit 0,1");
  929. if ($rs) {
  930. extract($rs);
  931. }
  932. foreach ($_POST as $key => $value) {
  933. if (($key == 'day') or ($key == 'month') or ($key == 'year') or ($key == 'time')) {
  934. $value = str_replace(':', "", $value);
  935. if ($key == 'time') {
  936. if (strlen($value) == 3) {
  937. $value = 0 . $value;
  938. }
  939. }
  940. $timey[] = $value;
  941. }
  942. //echo "$key - $value <br>"; //enable to see $_post output
  943. }
  944. if ((isset($timey)) && ($timey)) {
  945. if ((!checkdate($timey[1], $timey[0], $timey[2]))) {
  946. $error .= $lang['date_error'] . ' ';
  947. } else {
  948. $minute = substr($timey[3], 2, 4);
  949. $hour = substr($timey[3], 0, 2);
  950. $unixtime = mktime($hour, $minute, 00, $timey[1], $timey[0], $timey[2]);
  951. }
  952. }
  953. $r2 = safe_query('show fields from ' . adjust_prefix($table_name));
  954. $r3 = safe_query('select * from ' . adjust_prefix($table_name) . ' WHERE 1=0');
  955. for ($j = 0; $j < mysql_num_rows($r2); $j++) {
  956. $flags = mysql_field_flags($r3, $j);
  957. $af[$j] = $flags;
  958. if ($F = mysql_fetch_array($r2)) {
  959. $an[$j] = $F['Field'];
  960. $at[$j] = preg_replace('([()0-9]+)', "", $F['Type']);
  961. }
  962. //echo $an[$j]."-".$at[$j]."-".$af[$j]."<br>"; //enable to see field properties
  963. }
  964. for ($j = 0; $j < mysql_num_rows($r2); $j++) {
  965. $check = new Validator();
  966. if (isset($had_id)) {
  967. } else {
  968. $had_id = NULL;
  969. }
  970. if ($at[$j] == 'timestamp' && !array_key_exists("$an[$j]", $_POST)) {
  971. $check->validateNumber($unixtime, 'invalid time' . ' ');
  972. if ((isset($sql))) {
  973. } else {
  974. $sql = NULL;
  975. }
  976. $sql .= "" . $an[$j] . " = '" . returnSQLtimestamp($unixtime) . "',";
  977. } else if ((last_word($an[$j]) == 'id') && ($had_id === NULL)) {
  978. $had_id = 1;
  979. $editid = $_POST[$an[$j]];
  980. $idme = $an[$j];
  981. } else if (($an[$j] == 'page_content') && (isset($s)) && ($s == 'settings')) {
  982. //skip it to protect the php in the page_content field
  983. } else if (($an[$j] == 'admin') && (isset($s)) && ($s == 'settings')) {
  984. //skip it to protect the php code in the admin field
  985. } else {
  986. $value = $_POST[$an[$j]];
  987. if ($an[$j] == 'title') {
  988. $tit = $value;
  989. }
  990. if ($at[$j] == 'varchar') {
  991. $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
  992. }
  993. // check for posts with duplicate title/slug and increment
  994. if ($an[$j] == 'post_slug') {
  995. if (!$value) {
  996. $value = make_slug($tit);
  997. $value = strtolower($value);
  998. $searchforslug = safe_rows('*', $table_name, "post_slug REGEXP '[[:<:]]" . $value . "[[:>:]]'");
  999. if ($searchforslug) {
  1000. $addslug = count($searchforslug);
  1001. $value = $value . '-' . $addslug;
  1002. }
  1003. }
  1004. }
  1005. // check for pages with duplicate title/slug and increment
  1006. if ($an[$j] == 'page_name') {
  1007. $oldvalue = safe_field('page_name', $table_name, "page_id='$editid'");
  1008. if ($value != $oldvalue) {
  1009. $searchforpage = safe_rows('*', $table_name, "page_name REGEXP '[[:<:]]" . $value . "[[:>:]]'");
  1010. if ($searchforpage) {
  1011. $addpage = count($searchforpage);
  1012. $value = $value . '-' . $addpage;
  1013. }
  1014. }
  1015. // force the value to be lowercase and without spaces for slug
  1016. $value = strtolower(str_replace(" ", "", preg_replace('/\s\s+/', ' ', trim($value))));
  1017. }
  1018. // set a page_order, and navigation settings for a newly saved page
  1019. if ($an[$j] == 'public') {
  1020. if ($value == 'yes') {
  1021. $itspublic = 'yes';
  1022. }
  1023. }
  1024. if ($an[$j] == 'in_navigation') {
  1025. if ($value == 'yes') {
  1026. $innavigation = 'yes';
  1027. }
  1028. }
  1029. if ($an[$j] == 'page_order') {
  1030. if ($itspublic) {
  1031. if ($value != 0) {
  1032. if ($innavigation) {
  1033. if ((isset($submit_new)) && ($submit_new)) {
  1034. $value = count(safe_rows('*', $table_name, "public='yes' and in_navigation='yes' order by post_order asc")) + 1;
  1035. }
  1036. } else {
  1037. $value = 0;
  1038. }
  1039. } else {
  1040. if ($innavigation) {
  1041. $value = count(safe_rows('*', $table_name, "public='yes' and in_navigation='yes' order by post_order asc")) + 1;
  1042. } else {
  1043. $value = $value;
  1044. }
  1045. }
  1046. } else {
  1047. $value = 0;
  1048. }
  1049. }
  1050. // validate and clean input
  1051. $value = str_replace('|', '&#124;', $value);
  1052. $nullf = explode(" ", $af[$j]);
  1053. if ($an[$j] == 'tags') {
  1054. $value = make_tag($value);
  1055. }
  1056. if (get_magic_quotes_gpc() == 0) {
  1057. $value = addslashes($value);
  1058. }
  1059. if ($at[$j] == 'varchar') {
  1060. sterilise(strip_tags($value));
  1061. }
  1062. if (($an[$j] == 'url') or ($an[$j] == 'website')) {
  1063. if ($nullf[0] == 'not_null') {
  1064. $check->validateURL($value, $lang['url_error'] . ' ');
  1065. } else if ($value != "") {
  1066. $check->validateURL($value, $lang['url_error'] . ' ');
  1067. }
  1068. }
  1069. if ($at[$j] == 'longtext') {
  1070. // remove para from <!--more-->
  1071. if ((isset($m)) && ($m == 'dynamic')) {
  1072. // hacky to try and clean the more
  1073. $value = str_replace('<p><!--more--></p>', '<!--more-->', $value);
  1074. $value = str_replace('<p> <!--more--></p>', '<!--more-->', $value);
  1075. $value = str_replace('<!--more--></p>', '</p><!--more-->', $value);
  1076. $value = str_replace('<p><!--more-->', '<!--more--><p>', $value);
  1077. }
  1078. }
  1079. if ($an[$j] == 'email') {
  1080. if ($nullf[0] == 'not_null') {
  1081. $check->validateEmail($value, $lang['email_error'] . ' ');
  1082. } else if ($value != "") {
  1083. $check->validateEmail($value, $lang['email_error'] . ' ');
  1084. }
  1085. }
  1086. if (($nullf[0] == 'not_null') && ($value == "")) {
  1087. $error .= ucwords($an[$j]) . " " . $lang['is_required'] . ' ';
  1088. }
  1089. // if empty int set to 0
  1090. if ($at[$j] == 'int')
  1091. $value = ($value ? $value : 0);
  1092. if (isset($sql)) {
  1093. } else {
  1094. $sql = NULL;
  1095. }
  1096. $sql .= "`" . $an[$j] . "` = '" . $value . "',";
  1097. if ($check->foundErrors()) {
  1098. $error .= $check->listErrors('x');
  1099. }
  1100. }
  1101. }
  1102. if (isset($sql)) {
  1103. } else {
  1104. $sql = NULL;
  1105. }
  1106. $sql = substr($sql, 0, (strlen($sql) - 1)) . "";
  1107. //echo $sql; //view the SQL for current form save
  1108. if (!isset($error)) {
  1109. if ((isset($submit_new)) && ($submit_new)) {
  1110. $ok = safe_insert($table_name, $sql);
  1111. $idofsave = mysql_insert_id();
  1112. safe_optimize($table_name);
  1113. safe_repair($table_name);
  1114. if (!$ok) {
  1115. $message = $lang['unknown_error'];
  1116. logme($message, 'no', 'error');
  1117. } else {
  1118. if ((isset($s)) && ($s == 'settings') && ($page_type == 'dynamic')) {
  1119. $sql = "`page_id` = '$idofsave', `posts_per_page` = '10', `rss` = 'yes'";
  1120. safe_insert('pixie_dynamic_settings', $sql);
  1121. }
  1122. if ($table_name == 'pixie_core') {
  1123. $output = safe_field('page_display_name', 'pixie_core', "page_id='$idofsave'");
  1124. $icon = 'site';
  1125. $messageok = $lang['saved_new_page'] . ": $output.";
  1126. } else {
  1127. $ptitle = $title;
  1128. $output = $page_display_name;
  1129. $icon = 'page';
  1130. if (isset($ptitle)) {
  1131. $messageok = $lang['saved_new'] . ": $ptitle " . $lang['in_the'] . " $output " . $lang['page'];
  1132. } else {
  1133. $messageok = $lang['saved_new'] . " (#$idofsave) " . $lang['in_the'] . " $output " . $lang['page'];
  1134. }
  1135. }
  1136. logme($messageok, 'no', $icon);
  1137. }
  1138. }
  1139. if ((isset($submit_edit)) && $submit_edit) {
  1140. $ok = safe_update("$table_name", "$sql", "`$idme` = '$editid'");
  1141. if (!$ok) {
  1142. $message = $lang['unknown_error'];
  1143. } else {
  1144. if ((isset($s)) && ($s == 'settings')) {
  1145. $output = $page_display_name;
  1146. $icon = 'site';
  1147. if ($output) {
  1148. $messageok = $lang['saved_new_settings_for'] . " " . $output . " " . $lang['page'];
  1149. } else {
  1150. $output = safe_field('page_display_name', 'pix…

Large files files are truncated, but you can click here to view the full file