function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Document" || $post_action == "Add and Return to List") { $name = $_POST['name']; $file_type = getFileExtension($_FILES['file']['name']); $filename = slug(getFileName($_FILES['file']['name'])); $filename_string = $filename . "." . $file_type; // Check to make sure there isn't already a file with that name $possibledoc = Documents::FindByFilename($filename_string); if (is_object($possibledoc)) { setFlash("<h3>Failure: Document filename already exists!</h3>"); redirect("admin/add_document"); } $target_path = SERVER_DOCUMENTS_ROOT . $filename_string; if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { $new_doc = MyActiveRecord::Create('Documents', array('name' => $name, 'filename' => $filename_string, 'file_type' => $file_type)); $new_doc->save(); if (!chmod($target_path, 0644)) { setFlash("<h3>Warning: Document Permissions not set; this file may not display properly</h3>"); } setFlash("<h3>Document uploaded</h3>"); } else { setFlash("<h3>Failure: Document could not be uploaded</h3>"); } if ($post_action == "Add and Return to List") { redirect("admin/list_documents"); } } }
function delete() { $target_path = SERVER_DOCUMENTS_ROOT . $this->filename; if (file_exists($target_path)) { unlink($target_path); } return MyActiveRecord::Query("DELETE FROM documents WHERE id ={$this->id}"); }
function setLink($id, $table) { $paypal_accnt = Paypal_Config::FindFirst("Paypal_Config", "email='{$this->email}'"); if (!$paypal_accnt) { echo "Too bad\n"; return false; } $query = "INSERT INTO paypal_items (item_table, item_id, paypal_id) VALUES ('{$table}', '{$id}', '{$this->id}');"; mysql_query($query, MyActiveRecord::Connection()); }
function initialize_page() { // if there's more than one user, don't do anything. $count = MyActiveRecord::Count('Users'); if ($count == 0) { $admin_user = MyActiveRecord::Create('Users', array('email' => '*****@*****.**', 'password' => sha1(SHA_SALT . 'hcd_admin'), 'is_admin' => 1)); $admin_user->save(); } redirect("/admin/"); }
protected function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { $this->url = $this->translit($this->title); } return true; } else { return false; } }
function display_page_content() { $hash = requestIdParam(); $email = getRequestVarAtIndex(3); $query = "SELECT * FROM mailblast WHERE hash = '{$hash}';"; if ($result = mysql_query($query, MyActiveRecord::Connection())) { echo str_replace("{{-email-}}", $email, mysql_result($result, 0, 'content')); } else { redirect("/"); } }
function emailLinked($email) { // if this email is linked to this list don't add it to the list again $query = "SELECT * FROM nlemails_nllists le INNER JOIN nlemails e ON le.nlemails_id = e.id WHERE le.nllists_id = {$this->id} AND e.email = '{$email}';"; $result = MyActiveRecord::FindBySql('NLLists', $query); if (count($result) > 0) { return true; } else { return false; } }
function csv_write() { foreach ($this->data as $row) { $new_object = MyActiveRecord::Create($this->output_class, $row); $new_object->save(); if (!$success) { $this->errors = true; } } return $this->errors; }
function display_page_content() { $item_id = requestIdParam(); $query = "SELECT thumbnail FROM items \n\t WHERE id = {$item_id}"; $result = mysql_Query($query, MyActiveRecord::Connection()); $data = @mysql_fetch_array($result); if (!empty($data["thumbnail"])) { // Output the MIME header header("Content-Type: image/jpeg"); // Output the image echo $data["thumbnail"]; } }
function display_page_content() { $imageId = requestIdParam(); $query = "SELECT * FROM images WHERE id = {$imageId}"; $result = mysql_Query($query, MyActiveRecord::Connection()); $data = @mysql_fetch_array($result); if (!empty($data["thumbnail"])) { // Output the MIME header header("Content-Type: {$data['mime_type']}"); set_image_cache_headers("imgthumb_" . $imageId); // Output the image echo $data["thumbnail"]; } }
/** * Set up URL attribute */ public function beforeSave() { if (parent::beforeSave()) { $this->url = $this->translit($this->title); if ($this->isNewRecord) { $this->createTime = time(); } else { $this->updateTime = time(); } return true; } else { return false; } }
function FindBySectionName($section_name = "") { if ($section_name == "") { return array(); } $section = Sections::FindByName($section_name); $items = $section->findItems(); $id_list = ""; foreach ($items as $item) { $id_list .= "{$item->id},"; } $id_list = trim($id_list, ','); return MyActiveRecord::FindBySql('Keywords', "SELECT DISTINCT k.* FROM keywords k inner join items_keywords ik ON ik.keywords_id = k.id and ik.items_id in ({$id_list})"); }
protected static function getSmstafDbConnection() { if (self::$dbsmstaf !== null) { return self::$dbsmstaf; } else { self::$dbsmstaf = Yii::app()->dbsmstaf; if (self::$dbsmstaf instanceof CDbConnection) { self::$dbsmstaf->setActive(true); return self::$dbsmstaf; } else { throw new CDbException(Yii::t('yii', 'Active Record requires a "db" CDbConnection application component.')); } } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Gallery") { $gallery = MyActiveRecord::Create('Galleries'); $gallery->name = $_POST['name']; $gallery->slug = slug($_POST['name']); $gallery->save(); setFlash("<h3>Gallery Added</h3>"); redirect("/admin/edit_gallery/" . $gallery->id); } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add") { $blog = MyActiveRecord::Create('Blogs'); $blog->name = $_POST['name']; $blog->slug = slug($_POST['name']); $blog->user_id = $_POST['user_id']; $blog->save(); setFlash("<h3>Blog Added</h3>"); } }
function display_page_content() { $connection = MyActiveRecord::Connection(); $imageId = mysql_real_escape_string(requestIdParam()); // TODO: use a parameterized query instead of an escaped string $query = "SELECT * FROM images WHERE id = {$imageId}"; $result = mysql_Query($query, $connection); $data = @mysql_fetch_array($result); if (!empty($data["original"])) { // Output the MIME header header("Content-Type: {$data['mime_type']}"); set_image_cache_headers("img_" . $imageId); // Output the image echo $data["original"]; } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Manage This Email") { redirect("users/manage/" . $_POST["email"]); } if ($post_action == "Save Subscription Settings") { $currentemail = $_POST["email"]; $oldemail = $_POST["oldemail"]; if ($currentemail != $oldemail) { $thisemail = NLEmails::FindByEmail($oldemail); } else { $thisemail = NLEmails::FindByEmail($currentemail); } $lists = NLLists::FindAll(); // Remove all links first... $query = "DELETE FROM nlemails_nllists WHERE nlemails_id = {$thisemail->id}"; mysql_query($query, MyActiveRecord::Connection()); if (isset($_POST['delete'])) { $thisemail->delete(true); redirect("/mail/subscribe/deleted"); } // Then add the ones selected back in... foreach ($lists as $list) { if (array_key_exists($list->name, $_POST)) { $list->attach($thisemail); } } // Set the optional info fields and allow them to change the email they subscribed with... $thisemail->email = $_POST["email"]; $thisemail->first_name = $_POST["first_name"]; $thisemail->last_name = $_POST["last_name"]; $thisemail->address1 = $_POST["address1"]; $thisemail->address2 = $_POST["address2"]; $thisemail->city = $_POST["city"]; $thisemail->state = $_POST["state"]; $thisemail->zip = $_POST["zip"]; $thisemail->phone = $_POST["phone"]; $thisemail->save(); setFlash("<h3>Subscription Settings Saved</h3>"); // If they changed their email, redirect them to that page redirect("users/manage/" . $thisemail->email); } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Alias" || $post_action == "Add and Return to List") { $alias = MyActiveRecord::Create('Alias'); $alias->alias = $_POST['alias']; $alias->path = $_POST['path']; $alias->save(); setFlash("<h3>Alias created</h3>"); if ($post_action == "Add and Return to List") { redirect("/admin/alias_list"); } } }
function FindByPagination($perpage, $pagenum) { // Check to see if there is a page number. If not, set it to page 1 if (!isset($pagenum)) { $pagenum = 1; } $last = Images::FindLastPage($perpage); // Ensure the page number isn't below one, or more than the maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } // Sets the limit value for the query $max = 'LIMIT ' . ($pagenum - 1) * $perpage . ', ' . $perpage; return MyActiveRecord::FindBySQL('Images', "SELECT * FROM images ORDER BY id DESC {$max}"); }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add New List") { $success = ''; $list = MyActiveRecord::Create('NLLists'); $list->display_name = $_POST['name']; $list->name = slug($_POST['name']); $list->template = $_POST['template']; $list->description = $_POST['description']; $list->public = $_POST['public']; $list->save(); $success .= "Mailing List Created"; $emails = explode(",", str_replace(" ", "", $_POST['emails'])); if (is_array($emails)) { $count = 0; foreach ($emails as $email) { if (!$list->emailLinked($email) && is_validemail($email)) { // Check for an existing match in the system $newAddy = NLEmails::FindByEmail($email); if (!isset($newAddy) and !is_object($newAddy)) { $newAddy = MyActiveRecord::Create('NLEmails'); $newAddy->email = $email; $newAddy->save(); $count++; } // Existing or not, attach that email to this List $query = "INSERT INTO nlemails_nllists VALUES ({$newAddy->id}, {$list->id});"; if (!mysql_query($query, MyActiveRecord::Connection())) { die($query); } } } if ($count > 0) { $success .= " / Emails Added to {$list->display_name}"; } else { $success .= " / All Emails Added or Invalid"; } } setFlash("<h3>" . $success . "</h3>"); } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Category" || $post_action == "Add and Return to List") { $category = MyActiveRecord::Create('Categories'); $category->display_name = getPostValue('display_name'); $category->name = slug(getPostValue('display_name')); $category->content = getPostValue('category_content'); $category->save(); setFlash("<h3>Category Added</h3>"); if ($post_action == "Add and Return to List") { redirect("admin/list_categories/"); } } }
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() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Type" || $post_action == "Add and Return to List") { $type = MyActiveRecord::Create('EventTypes'); $type->name = $_POST['name']; $type->color = $_POST['color']; $type->text_color = EventTypes::$color_array[$type->color]; $type->calendar_id = 1; $type->save(); setFlash("<h3>Event type created</h3>"); if ($post_action == "Add and Return to List") { redirect("admin/list_event_types"); } } }
function initialize_page() { if ($_POST) { $post_value = $_POST['submit']; if ($post_value == "Save Subscription Settings") { $useremail = $_POST['email']; $email = NLEmails::FindByEmail($useremail); if (!$email) { $email = MyActiveRecord::Create('NLEmails'); $email->email = $useremail; $email->save(); } foreach ($_POST['selected_list'] as $key => $value) { $query = "INSERT INTO nlemails_nllists VALUES ({$email->id}, {$value});"; if (!mysql_query($query, MyActiveRecord::Connection())) { die($query); } } } } }
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() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add New Section" || $post_action == "Add and Return to List") { $section_display_name = $_POST['display_name']; if (ALLOW_SHORT_PAGE_NAMES) { if ($_POST['name'] == "") { $section_name = slug($_POST['display_name']); } else { $section_name = slug($_POST['name']); } } else { $section_name = slug($_POST['display_name']); } $section_content = $_POST['section_content']; $section_template = $_POST['template']; $section_public = isset($_POST['public']) ? 1 : 0; $new_section = MyActiveRecord::Create('Sections', array('name' => $section_name, 'display_name' => $section_display_name, 'template' => $section_template, 'public' => $section_public, "content" => $section_content)); $new_section->save(); // synchronize the users area selections $selected_areas = array(); if (isset($_POST['selected_areas'])) { $selected_areas = $_POST['selected_areas']; } else { $selected_areas = array('2'); } $new_section->updateSelectedAreas($selected_areas); setFlash("<h3>New section added</h3>"); if ($post_action == "Add and Return to List") { $main_portlink = DISPLAY_ITEMS_AS_LIST ? "admin/portfolio_list/alphabetical" : "admin/portfolio_list"; redirect($main_portlink); } else { redirect("admin/portfolio_add_section/" . $section->id); } } }
function initialize_page() { $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add New Area" || $post_action == "Add and Return to List") { $area_name = slug($_POST['display_name']) . "-portfolio"; $area_display_name = $_POST['display_name']; $area_seo_title = $_POST['seo_title']; $area_content = $_POST['area_content']; $area_template = 'portfolio'; $area_public = 0; $new_area = MyActiveRecord::Create('Areas', array('name' => $area_name, 'display_name' => $area_display_name, 'seo_title' => $area_seo_title, 'content' => $area_content, 'template' => $area_template, 'public' => $area_public)); $new_area->save(); setFlash("<h3>New portfolio area added</h3>"); if ($post_action == "Add and Return to List") { $main_portlink = DISPLAY_ITEMS_AS_LIST ? "admin/portfolio_list/alphabetical" : "admin/portfolio_list"; redirect($main_portlink); } } }
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() { $post_action = isset($_POST['submit']) ? $_POST['submit'] : ""; if ($post_action == "Add Image" || $post_action == "Add and Return to List") { $title = cleanupSpecialChars($_POST['title']); $description = cleanupSpecialChars($_POST['description']); if (ALLOW_SHORT_PAGE_NAMES) { $name = $_POST['name'] == "" ? slug($_POST['title']) : slug($_POST['name']); } else { $name = slug($_POST['title']); } // Was a file uploaded? if (is_uploaded_file($_FILES["image"]["tmp_name"])) { $mimeType = $_FILES["image"]["type"]; $filetype = getFileExtension($_FILES["image"]["name"]); list($width) = getimagesize($_FILES["image"]["tmp_name"]); $max_width = 0; $max_height = 0; if (defined("MAX_IMAGE_HEIGHT")) { $max_height = MAX_IMAGE_HEIGHT; } if (defined("MAX_IMAGE_WIDTH")) { $max_width = MAX_IMAGE_WIDTH; } resizeToMultipleMaxDimensions($_FILES["image"]["tmp_name"], $max_width, $max_height, $filetype); // Open the uploaded file $file = fopen($_FILES["image"]["tmp_name"], "r"); // Read in the uploaded file $fileContents = fread($file, filesize($_FILES["image"]["tmp_name"])); // Escape special characters in the file $fileContents = AddSlashes($fileContents); /*if( copy($_FILES["image"]["tmp_name"], $_FILES["image"]["tmp_name"] . "_thumb") ) { resizeToMultipleMaxDimensions($_FILES["image"]["tmp_name"] . "_thumb", 200, 0); $image = open_image($_FILES["image"]["tmp_name"] . "_thumb"); if ( $image === false ) { die ('Unable to open image for resizing'); } $width = imagesx($image); // Open the thumbnail file $thumb_file = fopen($_FILES["image"]["tmp_name"] . "_thumb", "r"); // Read in the thumbnail file $thumb_fileContents = fread($thumb_file, filesize($_FILES["image"]["tmp_name"] . "_thumb")); // Escape special characters in the file $thumb_fileContents = AddSlashes($thumb_fileContents); }*/ $thumb_fileContents = NULL; } else { $fileContents = $thumb_fileContents = NULL; } $insertQuery = "INSERT INTO images VALUES (NULL, \"{$title}\", \"{$description}\", \"{$fileContents}\", \"{$thumb_fileContents}\", \"{$mimeType}\", \"{$name}\")"; $result = mysql_Query($insertQuery, MyActiveRecord::Connection()); if (empty($result)) { //die( $updateQuery ); setFlash("<h3>FAILURE – Please notify HCd of this error: " . mysql_error() . "</h3>"); } setFlash("<h3>Image uploaded</h3>"); if ($post_action == "Add and Return to List") { redirect("/admin/list_images"); } } }