PageRenderTime 84ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/campsite/src/admin-files/camp_html.php

https://github.com/joechrysler/Campsite
PHP | 508 lines | 316 code | 34 blank | 158 comment | 52 complexity | a58a872eba02de35bc15b998d1b47e59 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @package Campsite
  4. */
  5. /**
  6. * includes
  7. */
  8. require_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/lib_campsite.php");
  9. /**
  10. * Print out an HTML OPTION element.
  11. *
  12. * @param string $p_value
  13. * @param string $p_selectedValue
  14. * @param string $p_printValue
  15. * @return boolean
  16. * Return TRUE if the option is selected, FALSE if not.
  17. */
  18. function camp_html_select_option($p_value, $p_selectedValue, $p_printValue, $p_attributes=array())
  19. {
  20. $selected = false;
  21. $str = '<OPTION VALUE="'.htmlspecialchars($p_value, ENT_QUOTES).'"';
  22. if (is_array($p_selectedValue)) {
  23. if (in_array($p_value, $p_selectedValue)) {
  24. $str .= ' SELECTED';
  25. $selected = true;
  26. }
  27. } else {
  28. if (!strcmp($p_value, $p_selectedValue)) {
  29. $str .= ' SELECTED';
  30. $selected = true;
  31. }
  32. }
  33. foreach ($p_attributes as $k => $v) {
  34. $str .= " $k=\"$v\"";
  35. }
  36. $str .= '>'.htmlspecialchars($p_printValue)."</OPTION>\n";
  37. echo $str;
  38. return $selected;
  39. } // fn camp_html_select_option
  40. /**
  41. * Display the copyright notice and close the HTML page.
  42. */
  43. function camp_html_copyright_notice($p_displayBorder = true)
  44. {
  45. global $Campsite;
  46. $campVersion = new CampVersion();
  47. if ($p_displayBorder) {
  48. ?>
  49. <table width="100%" align="center" style="border-top: 1px solid black; margin-top: 15px;">
  50. <?php
  51. } else {
  52. ?>
  53. <table width="100%" align="center" style="margin-top: 5px;">
  54. <?php
  55. }
  56. ?>
  57. <tr>
  58. <td style="padding-left: 5px; padding-top: 10px;" align="center">
  59. <?php
  60. echo $campVersion->getPackage() . '&nbsp;';
  61. echo $campVersion->getVersion() . '&nbsp;';
  62. echo $campVersion->getCopyright();
  63. ?><br/>
  64. Maintained and distributed under
  65. <?php echo $campVersion->getLicense(); ?> by
  66. <a style="font-size:8pt; color: black;" href="http://www.sourcefabric.org">
  67. <?php echo $campVersion->getOrganization(); ?>
  68. </a>
  69. </td>
  70. </tr>
  71. </table>
  72. <?php
  73. } // fn camp_html_copyright_notice
  74. /**
  75. * Create a HTML HREF link to an article.
  76. *
  77. * @param Article $p_articleObj
  78. * The article we want to display.
  79. *
  80. * @param int $p_sectionLanguageId
  81. * The section language ID.
  82. *
  83. * @param string $p_targetFileName
  84. * Which file in the "articles" directory to call.
  85. *
  86. * @param string $p_backLink
  87. * I'm not entirely sure what this is for. I put it in for backward compatibility.
  88. */
  89. function camp_html_article_link($p_articleObj, $p_interfaceLanguageId, $p_targetFileName = "", $p_backLink = "")
  90. {
  91. $str = '<A HREF="'.camp_html_article_url($p_articleObj, $p_interfaceLanguageId, $p_targetFileName, $p_backLink).'">';
  92. return $str;
  93. } // fn camp_html_article_link
  94. /**
  95. * Create a link to an article.
  96. *
  97. * @param Article $p_articleObj
  98. * The article we want to display.
  99. *
  100. * @param int $p_sectionLanguageId
  101. * The language ID for the publication/issue/section.
  102. *
  103. * @param string $p_targetFileName
  104. * Which file in the "articles" directory to call.
  105. *
  106. * @param string $p_backLink
  107. * A URL to get back to the previous page the user was on.
  108. *
  109. * @param string $p_extraParams
  110. */
  111. function camp_html_article_url($p_articleObj, $p_sectionLanguageId, $p_targetFileName = "", $p_backLink = "", $p_extraParams = null)
  112. {
  113. global $ADMIN;
  114. $str = "/$ADMIN/articles/".$p_targetFileName
  115. ."?f_publication_id=".$p_articleObj->getPublicationId()
  116. ."&f_issue_number=".$p_articleObj->getIssueNumber()
  117. ."&f_section_number=".$p_articleObj->getSectionNumber()
  118. ."&f_article_number=".$p_articleObj->getArticleNumber()
  119. ."&f_language_id=".$p_sectionLanguageId
  120. ."&f_language_selected=".$p_articleObj->getLanguageId();
  121. if ($p_backLink != "") {
  122. $str .="&Back=".urlencode($p_backLink);
  123. }
  124. if (!is_null($p_extraParams)) {
  125. $str .= $p_extraParams;
  126. }
  127. return $str;
  128. } // fn camp_html_article_url
  129. /**
  130. * Redirect to the error page and show the given error message.
  131. * You can also give a back link for the user to go back to when they
  132. * click OK on that screen.
  133. *
  134. * @param mixed $p_errorStr
  135. * This can be a string or an array. An array is for the case when the
  136. * error string requires arguments.
  137. *
  138. * @param string $p_backLink
  139. *
  140. * @return void
  141. */
  142. function camp_html_display_error($p_errorStr, $p_backLink = null, $popup = false)
  143. {
  144. global $ADMIN;
  145. $script = $popup ? 'ad_popup.php' : 'ad.php';
  146. $location = "/$ADMIN/$script?ADReason=".urlencode($p_errorStr);
  147. if (!is_null($p_backLink)) {
  148. $location .= '&Back='.urlencode($p_backLink);
  149. }
  150. header("Location: $location");
  151. exit;
  152. } // fn camp_html_display_error
  153. /**
  154. * Common header for all content screens.
  155. *
  156. * @param string $p_title
  157. * The title of the page. This should have a translation in the language
  158. * files.
  159. *
  160. * @param array $p_objArray
  161. * This represents your current location in the content tree. This
  162. * can have the following index values, each containing the appropriate
  163. * object: 'Pub', 'Issue', 'Section', 'Article'
  164. *
  165. * @param boolean $p_includeLinks
  166. * Whether to include the links underneath the title or not. Default TRUE.
  167. *
  168. * @param boolean $p_fValidate
  169. * Whether to include the fValidate javascript files in the HTML header.
  170. * Default FALSE.
  171. *
  172. * @param array $p_extraBreadcrumbs
  173. * An array in the form 'text' => 'link' for more breadcrumbs.
  174. *
  175. * @return void
  176. */
  177. function camp_html_content_top($p_title, $p_objArray, $p_includeLinks = true,
  178. $p_fValidate = false, $p_extraBreadcrumbs = null)
  179. {
  180. global $Campsite;
  181. global $ADMIN;
  182. global $ADMIN_DIR;
  183. $publicationObj = camp_array_get_value($p_objArray, 'Pub', null);
  184. $issueObj = camp_array_get_value($p_objArray, 'Issue', null);
  185. $sectionObj = camp_array_get_value($p_objArray, 'Section', null);
  186. $articleObj = camp_array_get_value($p_objArray, 'Article', null);
  187. $breadcrumbs = array();
  188. $breadcrumbs[] = array("Content", "");
  189. if (!is_null($publicationObj)) {
  190. $prompt = getGS("Publication").":";
  191. $name = htmlspecialchars($publicationObj->getName());
  192. $breadcrumbs[] = array($prompt, "/$ADMIN/pub/", false);
  193. $breadcrumbs[] = array($name, "/$ADMIN/pub/edit.php?Pub=".$publicationObj->getPublicationId());
  194. }
  195. if (!is_null($issueObj)) {
  196. $prompt = getGS("Issue").":";
  197. $breadcrumbs[] = array($prompt,
  198. "/$ADMIN/issues/"
  199. ."?Pub=".$issueObj->getPublicationId()
  200. ."&Issue=".$issueObj->getIssueNumber()
  201. ."&Language=".$issueObj->getLanguageId(),
  202. false);
  203. $name = htmlspecialchars($issueObj->getName())." (".htmlspecialchars($issueObj->getLanguageName()).")";
  204. $breadcrumbs[] = array($name,
  205. "/$ADMIN/issues/edit.php"
  206. ."?Pub=".$issueObj->getPublicationId()
  207. ."&Issue=".$issueObj->getIssueNumber()
  208. ."&Language=".$issueObj->getLanguageId());
  209. }
  210. if (!is_null($sectionObj)) {
  211. $prompt = getGS("Section").":";
  212. $breadcrumbs[] = array($prompt,
  213. "/$ADMIN/sections/"
  214. ."?Pub=".$sectionObj->getPublicationId()
  215. ."&Issue=".$sectionObj->getIssueNumber()
  216. ."&Language=".$sectionObj->getLanguageId()
  217. ."&Section=".$sectionObj->getSectionNumber(),
  218. false);
  219. $name = htmlspecialchars($sectionObj->getName());
  220. $breadcrumbs[] = array($name,
  221. "/$ADMIN/sections/edit.php"
  222. ."?Pub=".$sectionObj->getPublicationId()
  223. ."&Issue=".$sectionObj->getIssueNumber()
  224. ."&Language=".$sectionObj->getLanguageId()
  225. ."&Section=".$sectionObj->getSectionNumber());
  226. }
  227. if (!is_null($articleObj)) {
  228. $prompt = getGS("Article").":";
  229. $breadcrumbs[] = array($prompt,
  230. "/$ADMIN/articles/index.php"
  231. ."?f_publication_id=" . $articleObj->getPublicationId()
  232. ."&f_issue_number=".$articleObj->getIssueNumber()
  233. ."&f_language_id=".$sectionObj->getLanguageId()
  234. ."&f_section_number=".$articleObj->getSectionNumber()
  235. ."&f_article_number=".$articleObj->getArticleNumber(),
  236. false);
  237. $name = htmlspecialchars($articleObj->getName())." (".htmlspecialchars($articleObj->getLanguageName()).")";
  238. $breadcrumbs[] = array($name,
  239. "/$ADMIN/articles/edit.php"
  240. ."?f_publication_id=" . $articleObj->getPublicationId()
  241. ."&f_issue_number=".$articleObj->getIssueNumber()
  242. ."&f_language_id=".$sectionObj->getLanguageId()
  243. ."&f_section_number=".$articleObj->getSectionNumber()
  244. ."&f_article_number=".$articleObj->getArticleNumber()
  245. ."&f_language_selected=".$articleObj->getLanguageId());
  246. }
  247. if (is_array($p_extraBreadcrumbs)) {
  248. foreach ($p_extraBreadcrumbs as $text => $link) {
  249. $breadcrumbs[] = array($text, $link);
  250. }
  251. }
  252. $breadcrumbs[] = array($p_title, "");
  253. if ($p_fValidate) {
  254. include_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/javascript_common.php");
  255. }
  256. echo camp_html_breadcrumbs($breadcrumbs);
  257. } // fn camp_html_content_top
  258. /**
  259. * Create a set of breadcrumbs.
  260. *
  261. * @param array $p_crumbs
  262. * An array in the form 'text' => 'link' for breadcrumbs.
  263. * Farthest-away link comes first, increasing in specificity.
  264. *
  265. * @return string
  266. */
  267. function camp_html_breadcrumbs($p_crumbs)
  268. {
  269. $lastCrumb = array_pop($p_crumbs);
  270. $str = '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="breadcrumbHolder">';
  271. if (count($p_crumbs) > 0) {
  272. $str .= '<tr><td class="breadcrumbTD">';
  273. $tmpCrumbs = array();
  274. foreach ($p_crumbs as $crumb) {
  275. if (count($crumb) == 2) {
  276. $str .= camp_html_breadcrumb($crumb[0], $crumb[1]);
  277. }
  278. else {
  279. $str .= camp_html_breadcrumb($crumb[0], $crumb[1], $crumb[2]);
  280. }
  281. }
  282. $str .= '</td></tr>';
  283. }
  284. $str .= '<tr>';
  285. $str .= '<td class="activeSection" ';
  286. if (count($p_crumbs) <= 0) {
  287. $str .= "style=\"border-top: 1px solid #8BAED1;\"";
  288. }
  289. $str .= '>';
  290. $str .= camp_html_breadcrumb($lastCrumb[0], $lastCrumb[1], false, true);
  291. $str .= '</td></tr>';
  292. $str .= '</table>';
  293. return $str;
  294. } // fn camp_html_breadcrumbs
  295. /**
  296. * Create one breadcrumb.
  297. *
  298. * @param string $p_text
  299. * @param mixed $p_link
  300. * @param boolean $p_active
  301. * @param boolean $p_separator
  302. * @return string
  303. */
  304. function camp_html_breadcrumb($p_text, $p_link, $p_separator = true, $p_active = false) {
  305. $tmpStr = '';
  306. if ($p_active) {
  307. $class = "breadcrumb_active";
  308. }
  309. else {
  310. $class = "breadcrumb";
  311. }
  312. if ($p_separator) {
  313. $tmpStr .= "<span>";
  314. }
  315. else {
  316. $tmpStr .= "<span class='breadcrumb_intra_separator'>";
  317. }
  318. if ($p_link != "") {
  319. $tmpStr .= "<A HREF='" . htmlspecialchars($p_link) . "' class='$class'>"
  320. . htmlspecialchars($p_text) . "</A>";
  321. }
  322. else {
  323. $tmpStr .= "<SPAN CLASS='$class'>" . htmlspecialchars($p_text) . "</SPAN>";
  324. }
  325. $tmpStr .="</span>";
  326. if ($p_separator) {
  327. $tmpStr .= "<span CLASS='breadcrumb_separator'>&nbsp;</span>";
  328. }
  329. else {
  330. $tmpStr .= "<span>&nbsp;</spanTD>";
  331. }
  332. return $tmpStr;
  333. } // fn camp_html_breadcrumb
  334. /**
  335. * Send the user to the given page.
  336. *
  337. * @param string $p_link
  338. * @return void
  339. */
  340. function camp_html_goto_page($p_link, $p_exit = true)
  341. {
  342. header("Location: $p_link");
  343. if ($p_exit) {
  344. exit;
  345. }
  346. } // fn camp_html_goto_page
  347. // This is a simple global to tell us whether messages have been added
  348. // during this page request.
  349. global $g_camp_msg_added;
  350. $g_camp_msg_added = false;
  351. /**
  352. * Add a message to be sent to a page when camp_html_goto_page() is called.
  353. * The messages can be displayed on the destination screen by using
  354. * camp_html_display_msgs().
  355. *
  356. * @param mixed $p_errorMsg
  357. * This can be a string or an array of strings.
  358. * @param string $p_type
  359. * @param int $p_delay
  360. * The number of screen refreshes before this is displayed.
  361. */
  362. function camp_html_add_msg($p_errorMsg, $p_type = "error")
  363. {
  364. global $g_camp_msg_added;
  365. $p_type = strtolower($p_type);
  366. if (!in_array($p_type, array("error", "ok"))) {
  367. return;
  368. }
  369. if (!is_string($p_errorMsg) && !is_array($p_errorMsg)) {
  370. return;
  371. }
  372. if (is_string($p_errorMsg)) {
  373. $p_errorMsg = array($p_errorMsg);
  374. }
  375. foreach ($p_errorMsg as $errorMsg) {
  376. if (is_string($errorMsg) && (trim($errorMsg) != "")) {
  377. $g_camp_msg_added = true;
  378. if (camp_html_has_msg($errorMsg)) {
  379. return;
  380. }
  381. $_SESSION["camp_user_msgs"][] = array("msg" => $errorMsg,
  382. "type" => $p_type);
  383. }
  384. }
  385. } // fn camp_html_add_msg
  386. /**
  387. * Return true if the given message was already to the list
  388. * @param string $p_msg
  389. * @return boolean
  390. */
  391. function camp_html_has_msg($p_msg)
  392. {
  393. if (isset($_SESSION['camp_user_msgs']) && is_array($_SESSION['camp_user_msgs'])) {
  394. foreach ($_SESSION['camp_user_msgs'] as $msg) {
  395. if ($msg['msg'] == $p_msg) {
  396. return true;
  397. }
  398. }
  399. }
  400. return false;
  401. } // camp_html_has_msg
  402. /**
  403. * Return true if there are response messages to show to the user.
  404. *
  405. * @return boolean
  406. */
  407. function camp_html_has_msgs()
  408. {
  409. return (isset($_SESSION['camp_user_msgs']) && count($_SESSION['camp_user_msgs']) > 0);
  410. } // fn camp_html_has_msgs
  411. /**
  412. * Delete all pending user messages. This is called at the end of
  413. * the next page request in admin.php. This means that messages do not last
  414. * past one page request.
  415. *
  416. * @param boolean $p_calledByAdmin
  417. * This is only used by the admin script. If it is set to true it
  418. * will check if any messages have been posted during this request,
  419. * and if so, it does not delete the messages.
  420. * @return void
  421. */
  422. function camp_html_clear_msgs($p_calledByAdmin = false)
  423. {
  424. global $g_camp_msg_added;
  425. if (!$p_calledByAdmin || ($p_calledByAdmin && !$g_camp_msg_added)) {
  426. $_SESSION['camp_user_msgs'] = array();
  427. }
  428. } // fn camp_html_clear_msgs
  429. /**
  430. * Display any user messages stored in the session.
  431. *
  432. * @param string $p_spacing
  433. * How much spacing to put above and below the error message
  434. * (e.g. 10px, 1em, etc...).
  435. *
  436. * @return void
  437. */
  438. function camp_html_display_msgs($p_spacingTop = "1em", $p_spacingBottom = "1em")
  439. {
  440. if (isset($_SESSION['camp_user_msgs']) && count($_SESSION['camp_user_msgs']) > 0) { ?>
  441. <table border="0" cellpadding="0" cellspacing="0" class="action_buttons" style="padding-top: <?php echo $p_spacingTop; ?>; padding-bottom: <?php echo $p_spacingBottom; ?>;" width="800px">
  442. <?php
  443. $count = 1;
  444. foreach ($_SESSION['camp_user_msgs'] as $message) {
  445. ?>
  446. <tr>
  447. <?php if ($message['type'] == 'ok') { ?>
  448. <td class="info_message" id="camp_message_<?php p($count); ?>">
  449. <script>
  450. fade('camp_message_<?php p($count); ?>', 50, 8, false, 1100);
  451. </script>
  452. <?php } elseif ($message['type'] == 'error') { ?>
  453. <td class="error_message">
  454. <?php } ?>
  455. <?php echo $message['msg']; ?>
  456. </td>
  457. </tr>
  458. <?php
  459. $count++;
  460. } ?>
  461. </table>
  462. <?php
  463. $_SESSION['camp_user_msgs'] = array();
  464. }
  465. } // fn camp_html_display_msgs
  466. /**
  467. * One common form validate function.
  468. *
  469. */
  470. function camp_html_fvalidate()
  471. {
  472. echo "validateForm(this, 0, 1, 0, 1, 8)";
  473. } // fn camp_html_fvalidate
  474. ?>