PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/cms/ajax_pages/events.php

http://kancms.googlecode.com/
PHP | 140 lines | 91 code | 30 blank | 19 comment | 28 complexity | 05b2f8cd2fe6425cbd5b6bc882eefaff MD5 | raw file
Possible License(s): BSD-2-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /***
  3. * This page is accessed via an AJAX call to manipulate News Data, ie
  4. * deleting, moving, etc.
  5. */
  6. // ensure this file is only executed once we have been logged in
  7. include("../accesscheck.php");
  8. include('../../core/controllers/EventsManager.php');
  9. // create a copy of the manager
  10. $events = new EventsManager();
  11. $db = $events->getDatabase();
  12. // if an action has been requested, check the action and carry out the request
  13. // if all required parameters are met
  14. if( isset($_POST['action']) && stristr($_POST['action'],"publish") != '' && isset($_POST['id']) ) {
  15. $id = $_POST['id'];
  16. $publish = $_POST['action'] == "publish" ? 'true' : 'false';
  17. $updateSQL = "UPDATE events SET Published = '$publish' WHERE id = $id";
  18. $result = $db->query($updateSQL,true);
  19. } else if( isset($_POST['action']) && isset($_POST['image_id']) ) {
  20. $image_id = $_POST['image_id'];
  21. $query = "SELECT ImageFile, ThumbPath FROM images WHERE id = $image_id ";
  22. $imageData = $db->query($query,true)->getRow();
  23. echo json_encode($imageData);
  24. } else if( isset($_POST['action']) && $_POST['action'] == "delete_articles" ) {
  25. $article_ids = $_POST['article_ids'];
  26. $query = "DELETE FROM events WHERE id IN ($article_ids) ";
  27. $result = $db->query($query,true);
  28. } else if( isset($_POST['action']) && $_POST['action'] == "add_category" ) {
  29. $categoryName = $_POST['CategoryName'];
  30. $categoryDesc = $_POST['CategoryDesc'];
  31. $query = sprintf("INSERT INTO event_categories (SiteID, Category, CategoryAlias, CategoryDescription) VALUES(%s, %s, %s, %s) ",
  32. $db->sanitizeInput($siteid, "int"),
  33. $db->sanitizeInput($categoryName, "text"),
  34. $db->sanitizeInput(slug($categoryName), 'text' ),
  35. $db->sanitizeInput($categoryDesc, "text"));
  36. // get the id of the newly insert category
  37. $id = $db->query($query,true)->getInsertId();
  38. // echo the result
  39. echo json_encode( array(
  40. "id" => $id,
  41. "categoryName" => $categoryName,
  42. "categoryDesc" => $categoryDesc
  43. ));
  44. } else if( isset($_POST['action']) && $_POST['action'] == "delete_category" ) {
  45. $category_id = $_POST['category_id'];
  46. $query = "DELETE FROM event_categories WHERE id = $category_id ";
  47. $db->query($query,true);
  48. } else if( isset($_POST['action']) && $_POST['action'] == "load_events" ) {
  49. // get the number of records to be returned and the position to start returning
  50. // them from limit for the number of records to returned
  51. $limit = isset($_POST['limit']) ? $_POST['limit'] : 20;
  52. $start = isset($_POST['start']) ? $_POST['start'] * $limit : 0;
  53. // get the category to which the articles belong
  54. $cat = $_POST['category'];
  55. // get a category object
  56. $category = $events->getEventCategory($cat);
  57. // retrieve the articles in the specified category
  58. $catEvents = $category->getEvents($start, $limit, false, false);
  59. // get the total number of articles in this category
  60. $total_articles = $category->getTotalEventCount();
  61. if( $total_articles == 0 ) {
  62. echo "No Events Have Been Posted In This Category For This Site";
  63. return;
  64. }
  65. echo "
  66. <table border=0 cellspacing=0 cellpadding=4 width=100% class='cms-data-table'>
  67. <tr>
  68. <th align=right><input type='checkbox' value='' id='checkAll' name='checkAll' /></th>
  69. <th align='left'>Event Name</th>
  70. <th>Options</th>
  71. </tr>
  72. ";
  73. for($i = 0, $j = $start; $i < count($catEvents); $i++, $j++) {
  74. $event = $catEvents[$i];
  75. $title = $event->getName();
  76. $id = $event->getId();
  77. $published = $event->isPublished();
  78. $isPast = $event->isPast();
  79. $pub_link_class = $published ? 'cms-publish-link' : 'cms-unpublish-link';
  80. $pub_link_title = $published ? 'Published (Click To Unpublish)' : 'Unpublised (Click To Publish Now)';
  81. $valid_event_class = $isPast ? 'event-past-icon' : 'event-upcoming-icon';
  82. $upcoming_row_class = $isPast ? 'event-past' : 'event-upcoming';
  83. $valid_event_title = ($isPast ? 'Event Is Past - ' : 'Event Is Upcoming - ') . $event->getStartDate('d M, Y');
  84. $short_title = (strlen($title) > 55) ? (substr($title, 0, 55) . "...") : $title;
  85. echo "
  86. <tr id='article-row-$id' class='$upcoming_row_class'>
  87. <td align=right width='25'><input type='checkbox' value='$id' /></td>
  88. <td>" . ($j + 1) . ". <a id='$id' class='edit-link' href='?edit&id=$id' title='$title'>$short_title</a></td>
  89. <td align=center width='35%'>
  90. <a id='$id' class='edit-link' href='?edit&id=$id'><img src='images/icons/newspaper.png' alt='' align='absmiddle' border=0 /> Edit</a>
  91. <a id='$id' class='delete-link' href='#'><img src='images/icons/newspaper_delete.png' alt='' align='absmiddle' border=0 /> Delete</a>
  92. <a id='$id' class='$valid_event_class' href='#' title='$valid_event_title'></a>
  93. <a id='$id' class='$pub_link_class' href='#' title='$pub_link_title'></a>
  94. </td>
  95. </tr>
  96. ";
  97. }
  98. echo "
  99. </table>
  100. ";
  101. // echo out the values of the total article count as hidden field in order to be accessed
  102. // by the javascript processor
  103. // we'll do this if only the first page is being loaded
  104. if( !isset($_POST['no-total']) ) {
  105. echo "
  106. <input type='hidden' id='articles-total' value='$total_articles' />
  107. ";
  108. }
  109. }
  110. ?>