function initialize_page() { $page_id = requestIdParam(); $page = Pages::FindById($page_id); // get all the areas $areas = Areas::FindPublicAreas(); $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Save Page" || $post_action == "Save and Return to List") { if (isset($_POST['delete'])) { $page->delete(true); setFlash("<h3>Page deleted</h3>"); redirect("/admin/list_pages"); } else { $page->display_name = $_POST['display_name']; $oldname = $page->name; if (ALLOW_SHORT_PAGE_NAMES) { if ($_POST['name'] == "") { $page->name = slug($_POST['display_name']); } else { $page->name = slug($_POST['name']); } } else { $page->name = slug($_POST['display_name']); } $page->content = $_POST['page_content']; $page->template = $_POST['template']; $page->public = checkboxValue($_POST, 'public'); // Pages can either be directly assigned to areas, or assigned as a sub-page. // It's an either-or thing. For now, default to areas if they're selected (ie, if both selected, ignore the sub-page) // synchronize the users area selections $selected_areas = array(); if (isset($_POST['selected_areas'])) { $selected_areas = $_POST['selected_areas']; } if (count($selected_areas) > 0) { $page->parent_page_id = null; $page->updateSelectedAreas($selected_areas); } else { if ($_POST['parent_page'] != "") { $page->parent_page_id = $_POST['parent_page']; } else { $page->parent_page_id = null; } } $page->save(); $page->checkAlias($selected_areas, $oldname); setFlash("<h3>Success. Database Updated</h3>"); if ($post_action == "Save and Return to List") { redirect("admin/list_pages"); } } } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Page" || $post_action == "Add and Return to List") { $page = MyActiveRecord::Create('Pages'); $page->display_name = $_POST['display_name']; if (ALLOW_SHORT_PAGE_NAMES) { if ($_POST['name'] == "") { $page->name = slug($_POST['display_name']); } else { $page->name = slug($_POST['name']); } } else { $page->name = slug($_POST['display_name']); } $page->content = $_POST['page_content']; $page->content_file = ''; $page->template = $_POST['template']; $page->public = checkboxValue($_POST, 'public'); // synchronize the users area selections $selected_areas = array(); if (isset($_POST['selected_areas'])) { $selected_areas = $_POST['selected_areas']; } if (count($selected_areas) > 0) { $page->parent_page_id = null; } else { if ($_POST['parent_page'] != "") { $page->parent_page_id = $_POST['parent_page']; } else { $page->parent_page_id = null; } } if ($page->save() && $page->updateSelectedAreas($selected_areas) && $page->setDisplayOrderInArea()) { setFlash("<h3>Page Added</h3>"); } if ($post_action == "Add and Return to List") { redirect("admin/list_pages"); } } }
function initialize_page() { LoginRequired("/admin/login/", array("admin")); $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add User" || $post_action == "Add and Send New User Email") { $email = $_POST['email']; $password = $_POST['password']; $possible_space = strrpos($password, " "); if (empty($email) || empty($password)) { setFlash("<h3>Please enter a username and/or password of at least 6 characters and no spaces</h3>"); } else { if ($possible_space == true) { setFlash("<h3>No spaces are allowed in a password</h3>"); } else { if (strlen(utf8_decode($password)) < 6) { setFlash("<h3>A password should contain at least 6 characters and no spaces</h3>"); } else { $count = MyActiveRecord::Count('Users', "email = '{$email}'"); if ($count > 0) { $duplicate = Users::FindByEmail($email); setFlash("<h3>User already exists (see below)</h3>"); redirect("/admin/edit_user" . $duplicate->id); } else { $new_user = MyActiveRecord::Create('Users', $_POST); $new_user->hash_password(); $new_user->is_admin = checkboxValue($_POST, 'is_admin'); $new_user->is_staff = $new_user->is_admin ? 0 : 1; $new_user->save(); $success = "User added"; if ($post_action == "Add User and Send New User Email") { $new_user->send_newuser_email($_POST['password']); $success .= " / Email Notification Sent"; } setFlash("<h3>" . $success . "</h3>"); redirect("/admin/list_users"); } } } } } }
function initialize_page() { // This file does both, so check the parameters first if (requestIdParam() == "add") { $chunk = MyActiveRecord::Create('Chunks'); } else { $chunk_id = requestIdParam(); $chunk = Chunks::FindById($chunk_id); } $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Save Chunk" || $post_action == "Save and Return to List") { if (isset($_POST['delete'])) { $chunk->delete(true); setFlash("<h3>Chunk deleted</h3>"); redirect("/admin/list_pages"); } else { /* * Columns: id, slug, full_html(boolean), content */ if (!empty($_POST['slug'])) { $chunk->slug = slug($_POST['slug']); } if (!empty($_POST['description'])) { $chunk->description = $_POST['description']; } if (!empty($_POST['description'])) { $chunk->full_html = checkboxValue($_POST, 'full_html'); } $chunk->content = $_POST['chunk_content']; $chunk->save(); setFlash("<h3>Chunk changes saved</h3>"); if ($post_action == "Save and Return to List") { redirect("admin/list_pages"); } } } }
function initialize_page() { // This file does both, so check the parameters first if (requestIdParam() == "add") { $testimonial = MyActiveRecord::Create('Testimonials'); } else { $testimonial_id = requestIdParam(); $testimonial = Testimonials::FindById($testimonial_id); } $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Save Testimonial" || $post_action == "Save and Return to List") { if (isset($_POST['delete'])) { $testimonial->delete(); setFlash("<h3>Testimonial deleted</h3>"); } else { /* * Columns: id, display_name, slug, content, attribution */ $postedtitle = $_POST['display_name']; $testimonial->slug = slug($postedtitle); $testimonial->display_name = $postedtitle; $testimonial->content = $_POST['content']; $testimonial->attribution = $_POST['attribution']; $testimonial->is_featured = checkboxValue($_POST, 'featured'); $testimonial->save(); $success = 'Testimonial changes saved / '; setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); } if (isset($_POST['delete']) or $post_action == "Save and Return to List") { redirect("admin/list_testimonials"); } } }
function initialize_page() { $success = $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Item" || $post_action == "Add and Return to List") { // ! create item $item = MyActiveRecord::Create('Items'); $item->content = $_POST['item_content']; $item->display_name = $_POST['display_name']; $item->name = slug($_POST['display_name']); $item->location = $_POST['location']; $item->public = checkboxValue($_POST, 'public'); $item->mime_type = 0; $item->taxonomy = $_POST['taxonomy']; $item->date_created = date('Y-m-d H:i:s'); // optional fields $item->sku = ITEM_SKU ? $_POST['item_sku'] : null; $item->taxonomy = ITEM_TAXONOMY ? $_POST['taxonomy'] : null; $item->price = ITEM_PRICE ? $_POST['item_price'] : null; // synchronize the users area selections $selected_sections = array(); if (isset($_POST['selected_sections'])) { $selected_sections = $_POST['selected_sections']; } $item->save(); $item->updateSelectedSections($selected_sections); $item->setDisplayOrder(); $success .= "Item Saved / "; // ! create gallery and associate it $gallery = MyActiveRecord::Create('Galleries'); $gallery->name = $_POST['display_name'] . " Gallery"; $gallery->slug = "portfolioGal_" . $item->id . "_" . slug($_POST['display_name']); $gallery->save(); $success .= "Gallery Created / "; if (PORTFOLIOTHUMB_IMAGE) { // now check if a thumbnail was uploaded if (is_uploaded_file($_FILES["thumbnail"]["tmp_name"])) { $mimeType = $_FILES["thumbnail"]["type"]; $fileType = ""; switch ($mimeType) { case "image/gif": $fileType = "gif"; break; case "image/jpg": case "image/jpeg": $fileType = "jpg"; break; case "image/png": $fileType = "png"; break; case "image/x-MS-bmp": $fileType = "bmp"; break; } resizeToMultipleMaxDimensions($_FILES["thumbnail"]["tmp_name"], PORTFOLIOTHUMB_IMAGE_MAXWIDTH, PORTFOLIOTHUMB_IMAGE_MAXHEIGHT, $fileType); // Open the uploaded file $file = fopen($_FILES["thumbnail"]["tmp_name"], "r"); // Read in the uploaded file $fileContents = fread($file, filesize($_FILES["thumbnail"]["tmp_name"])); // Escape special characters in the file $fileContents = AddSlashes($fileContents); $updateQuery = "UPDATE items SET thumbnail = \"{$fileContents}\", mime_type = \"{$mimeType}\" WHERE id = {$item->id};"; if (mysql_Query($updateQuery, MyActiveRecord::Connection())) { $success .= "Thumbnail Added / "; } else { die(mysql_error()); } } } setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); // Remember to get a section for the redirect link... $itemsection = array_shift($item->getSections()); redirect("/admin/portfolio_edit/" . $itemsection->name . "/" . $item->id); } }
function initialize_page() { $item = Items::FindById(getRequestVaratIndex(3)); // get all the sections $sections = Sections::FindPublicSections(); /* get this section * We do this mostly for the previous and next item functions. If we dont know what section we are currently inside, * the user may get bounced over to a different place than they started. */ $sectionname = getRequestVaratIndex(2); if ($sectionname != "item_orphan") { $section = Sections::FindByName($sectionname); } // get the associated gallery if ($item) { $gallery = $item->getGallery(); } // finally, get the post action. Harder to hack if we explicitly check the value this way. $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Save Item" || $post_action == "Add Image" || $post_action == "Add Document" || $post_action == "Add or Edit Video" || $post_action == "Save and Return to List") { /* * Delete this item and its associated components */ if (isset($_POST['delete'])) { // delete $photos and $gallery if (is_object($gallery)) { $gallery->delete(true); $success .= "Gallery and Images Deleted / "; } /* Documents ... Why not keep them? if ( ITEM_DOCUMENTS ) { $itemdocuments = $item->findDocuments( 'display_order ASC' ); foreach ( $itemdocuments as $thedoc ) { $thedoc->delete(true); } $success .= "Documents Deleted / "; }*/ $item->delete(true); $success .= "Item Deleted / "; setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); //$main_portlink = ( DISPLAY_ITEMS_AS_LIST ) ? "admin/portfolio_list/alphabetical" : "admin/portfolio_list"; //redirect( $main_portlink ); redirect("admin/portfolio_list"); } else { $item->content = $_POST['item_content']; $item->display_name = $_POST['display_name']; $previous_name = $item->name; $item->name = slug($_POST['display_name']); $item->template = 'inherit'; $item->public = checkboxValue($_POST, 'public'); $item->date_revised = date('Y-m-d H:i:s'); // optional fields $item->sku = ITEM_SKU ? $_POST['item_sku'] : null; $item->taxonomy = ITEM_TAXONOMY ? $_POST['taxonomy'] : null; $item->price = ITEM_PRICE ? $_POST['item_price'] : null; // SAVE item... uses a MyActiveRecord method $item->save(); $success = "Item Saved / "; // synchronize the users section selections only if they are different $selected_sections = array(); $previous_sections = $item->getSections(); if (isset($_POST['selected_sections'])) { $update_sections = false; $selected_sections = $_POST['selected_sections']; // Problem: If we loop on only the $previous_sections, we may have fewer or more loops than $selected_sections. // Compare one to the other. if (count($previous_sections) != count($selected_sections)) { // The two do not match, so there has been a change $update_sections = true; } else { // In case the two match, let's make sure something is different. foreach ($previous_sections as $sect) { if (!in_array($sect->id, $selected_sections)) { $update_sections = true; } } } if ($update_sections) { $item->updateSelectedSections($selected_sections); // update the revision dates of sections, too $item->updateSectionRevisionDates(); } } /* * Rename the gallery if the slug has changed. * We need the name of the gallery and the name of the slug to be consistent. * If there isn't a gallery – something broke, so – create a new one. */ if (is_object($gallery) && $previous_name != $item->name) { $gallery->slug = "portfolioGal_" . $item->id . "_" . $item->name; $gallery->save(); $success .= "Gallery name changed / "; } if (!is_object($gallery)) { $gallery = MyActiveRecord::Create('Galleries'); $gallery->name = $_POST['display_name'] . " Gallery"; $gallery->slug = "portfolioGal_" . $item->id . "_" . slug($_POST['display_name']); $gallery->save(); } /* ! Gallery image functions */ if (isset($_FILES['new_photo']) && $_FILES['new_photo']['error'] == 0) { // user has added a new file $newphoto = MyActiveRecord::Create('Photos', array('caption' => getPostValue("new_photo_caption"), 'gallery_id' => $gallery->id, 'display_order' => 1)); $newphoto->save(); $newphoto->save_uploaded_file($_FILES['new_photo']['tmp_name'], $_FILES['new_photo']['name'], true); $success .= "New photo uploaded / "; } /* * Check current captions against previous ones. */ if (isset($_POST['captions'])) { $captions = $_POST['captions']; foreach ($captions as $key => $thecaption) { $photo = Photos::FindById($key); if ($photo->caption != $thecaption) { $photo->caption = $thecaption; $photo->save(); } } } /* * Check photo display order against previous ones */ if (isset($_POST['photos_display_order'])) { $display_orders = $_POST['photos_display_order']; foreach ($display_orders as $key => $display_order) { $photo = Photos::FindById($key); if ($photo->display_order && $photo->display_order != $display_order) { $photo->display_order = $display_order; $photo->save(); } } $success .= "Photo order saved / "; } /* * Delete a photo from the gallery */ if (isset($_POST['deleted_photos'])) { $deleted_ids = $_POST['deleted_photos']; foreach ($deleted_ids as $status => $photo_id) { $photo = Photos::FindById($photo_id); $photo->delete(true); } $success .= "A photo was deleted / "; } /* * Check to see if we allow Portfolio Thumbs */ if (PORTFOLIOTHUMB_IMAGE) { // was a new thumbnail uploaded if (is_uploaded_file(realpath($_FILES["thumbnail"]["tmp_name"]))) { if (Upload_and_Save_Image($_FILES["thumbnail"], 'items', 'thumbnail', $item->id, PORTFOLIOTHUMB_IMAGE_MAXWIDTH, PORTFOLIOTHUMB_IMAGE_MAXHEIGHT)) { $success .= "Thumbnail updated / "; } } } /* ! Video functions */ if (ITEM_VIDEOS) { // If this gallery has mixed photos AND videos, check the display order again and set each by object type if (isset($_POST['galitem_display_order'])) { foreach ($_POST['galitem_display_order'] as $key => $display_order) { $type = $_POST['galitem_type'][$key]; $galitem = $type == 'photo' ? Photos::FindById($key) : Videos::FindById($key); if (is_object($galitem)) { //if ( $galitem->display_order && $galitem->display_order != $display_order ) { $galitem->display_order = $display_order; $galitem->save(); } } } // Change the name of a video if (isset($_POST['vidnames'])) { $vidnames = $_POST['vidnames']; foreach ($vidnames as $key => $thename) { $video = Videos::FindById($key); if ($video->display_name != $thename) { $video->name = slug($thename); $video->display_name = $thename; $video->save(); } } //$success .= "Video name updated / "; // False positive } // Change the embed code of a video if (isset($_POST['vidcodes'])) { $vidnames = $_POST['vidcodes']; foreach ($vidnames as $key => $thecode) { $video = Videos::FindById($key); if ($video->embed != $thecode) { $video->embed = $thecode; $video->save(); } } //$success .= "Video embed updated / "; // False positive } // Add a new Video if ($_POST['newvideo'] != '') { $video = MyActiveRecord::Create('Videos'); /* * Columns: id, name, title, service, embed, width, height, gallery_id, display_order */ $vidtitle = $_POST['newvideo']; $video->name = slug($vidtitle); $video->display_name = $vidtitle; $video->service = $_POST['vidservice']; $video->embed = $_POST['vidembed']; $video->width = $_POST['vidwidth']; $video->height = $_POST['vidheight']; $video->gallery_id = $gallery->id; $video->display_order = count($gallery->get_photos()) + 1; $video->save(); $success .= "Video added / "; } // Remove video association -- Does not delete the video itself if (isset($_POST['removevideo'])) { $video = Videos::FindById($_POST['removevideo']); $video->gallery_id = null; $video->save(); } } /* ! Document functions */ if (ITEM_DOCUMENTS) { // Change the name of a document if (isset($_POST['docname'])) { $docnames = $_POST['docname']; foreach ($docnames as $key => $thename) { $document = Documents::FindById($key); if ($document->name != $thename) { $document->name = $thename; $document->save(); } } } // Reorder documents if (isset($_POST['document_display_order'])) { $display_orders = $_POST['document_display_order']; foreach ($display_orders as $key => $display_order) { $doc = Documents::FindById($key); if ($doc->display_order != $display_order) { $doc->display_order = $display_order; $doc->save(); } } } // Add a new document if (isset($_FILES['new_document']) && $_FILES['new_document']['error'] == 0) { // Set the name equal to the input field or the physical doc name $name = $_POST['new_document_title'] ? $_POST['new_document_title'] : unslug($_FILES['new_document']['name']); $name = substr($name, 0, strrpos($name, ".")); // Find the extension. Explode on the period. $extension = substr($_FILES['new_document']['name'], strrpos($_FILES['new_document']['name'], ".")); $file_type = substr($extension, 1); // Chop the dot off $filename = slug($name) . $extension; $target_path = SERVER_DOCUMENTS_ROOT . $filename; if (move_uploaded_file($_FILES['new_document']['tmp_name'], $target_path)) { $new_doc = MyActiveRecord::Create('Documents', array('name' => $name, 'filename' => $filename, 'file_type' => $file_type, 'item_id' => $item->id)); $new_doc->save(); $success .= "Document uploaded and attached / "; if (!chmod($target_path, 0644)) { $success .= "!Warning: Document Permissions not set; this file may not display properly! / "; } } else { $success .= "!WARNING: Document could not be uploaded! / "; } } else { echo $_FILES['new_document']['error']; } // Delete Documents if (isset($_POST['deleted_documents'])) { $deleted_ids = $_POST['deleted_documents']; foreach ($deleted_ids as $status => $doc_id) { $doc = Documents::FindById($doc_id); $doc->delete(true); } $success .= "A document was deleted / "; } } setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); if ($post_action == "Save and Return to List") { //$main_portlink = ( DISPLAY_ITEMS_AS_LIST ) ? "admin/portfolio_list/alphabetical" : "admin/portfolio_list"; //redirect( $main_portlink ); redirect("admin/portfolio_list"); } else { if ($update_sections) { // Find a new section, the one that has just been assigned... // Breaks into an infinite loop on Windows servers... can we clear the post somehow? $section = Sections::FindById($_POST['selected_sections'][0]); } redirect("/admin/portfolio_edit/" . $section->name . "/" . $item->id); } } } }
function initialize_page() { // This file does both, so check the parameters first if (requestIdParam() == "add") { $entry = MyActiveRecord::Create('Blog_Entries'); } else { $entry_id = requestIdParam(); $entry = Blog_Entries::FindById($entry_id); } $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } $blog = Blogs::FindById(BLOG_DEFAULT_ID); // Check for the delete action if (isset($_POST['delete'])) { // Delete a photo if there is one if (BLOG_ENTRY_IMAGES) { $photo = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE entry_id = {$entry->id}")); if (is_object($photo)) { $photo->delete(true); } } $entry->delete(); setFlash("<h3>Entry Deleted</h3>"); redirect("/admin/list_entries/" . $user->id); } else { if ($post_action == "Save Entry" || $post_action == "Save and Return to List") { /* * Columns: id, title, slug, date, content, excerpt, public, template, author_id, blog_id */ $entry->title = getPostValue('title'); $entry->slug = slug(getPostValue('title')); if (getPostValue('date') != "") { $entry->setEntryDateAndTime(getPostValue('date')); } else { $entry->date = date('Y-m-d H:i:s'); } $entry->content = getPostValue('entry_content'); $entry->excerpt = getPostValue('entry_excerpt'); $entry->public = checkboxValue($_POST, 'public'); if (BLOG_ENTRY_TEMPLATES) { $entry->template = $_POST['template']; } $entry->author_id = $_POST['author_id']; $entry->blog_id = $blog->id; $entry->save(); $success = "Blog Entry Saved / "; // synchronize the users category selections $selected_cats = array(); if (isset($_POST['selected_cats'])) { $selected_cats = $_POST['selected_cats']; $entry->updateSelectedCategories($selected_cats); } else { $uncategorized = Categories::FindById(1); $entry->attach($uncategorized); } // Upload the photo if one is allowed if (isset($_FILES['entry_image']) && $_FILES['entry_image']['error'] == 0) { // delete an old file if there is one $oldphoto = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE entry_id = {$entry->id}")); if (is_object($oldphoto)) { $oldphoto->delete(true); } // user has added a new photo $newphoto = MyActiveRecord::Create('Photos', array('caption' => $entry->title, 'entry_id' => $entry->id)); $newphoto->save(); $newphoto->save_uploaded_file($_FILES['entry_image']['tmp_name'], $_FILES['entry_image']['name'], '', $isentryimg = true); $success .= "New image uploaded / "; } if (requestIdParam() == "add") { setFlash('<h3>' . $success . '<a href="' . get_link('admin/edit_entry/' . $entry->id) . '">Edit it Now</a></h3>'); } else { setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); } if ($post_action == "Save and Return to List") { redirect("admin/list_entries/"); } } } }