Beispiel #1
0
 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;
     }
 }
Beispiel #2
0
 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})");
 }
Beispiel #3
0
 function FindByName($name)
 {
     //return MyActiveRecord::FindFirst('Areas', "name like '" . $name . "'");
     return array_shift(MyActiveRecord::FindBySql('areas', "SELECT a.* FROM areas a WHERE a.name like '" . $name . "'"));
 }
Beispiel #4
0
 function FindByEmail($email)
 {
     return array_shift(MyActiveRecord::FindBySql('NLEmails', "SELECT * FROM nlemails WHERE email = '{$email}'"));
 }
Beispiel #5
0
 function FindRandomCover()
 {
     return array_shift(MyActiveRecord::FindBySql('Images', "SELECT i.* FROM images i WHERE name LIKE '%_cover' ORDER BY rand() LIMIT 1;"));
 }
Beispiel #6
0
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/");
            }
        }
    }
}
Beispiel #7
0
 function FindFeatured($orderby = 'id DESC')
 {
     return MyActiveRecord::FindBySql('Testimonials', "SELECT * FROM testimonials WHERE is_featured = true ORDER BY id DESC");
 }
Beispiel #8
0
 function get_videos($orderby = 'display_order ASC')
 {
     return MyActiveRecord::FindBySql('Videos', "SELECT * FROM videos WHERE gallery_id = " . $this->id . " ORDER BY " . $orderby . "");
 }
Beispiel #9
0
 function findPrev($area, $public = "i.public AND")
 {
     $order = $this->getOrderInArea($area);
     return array_shift(MyActiveRecord::FindBySql('Items', "SELECT i.* FROM items i INNER JOIN items_sections its ON its.items_id = i.id INNER JOIN sections s ON s.id = its.sections_id WHERE {$public} s.id like '" . $section->id . "' AND its.display_order < {$order} ORDER BY its.display_order DESC LIMIT 1"));
 }
Beispiel #10
0
 function FindByAlias($alias)
 {
     //return MyActiveRecord::FindFirst('Areas', "name like '" . $name . "'");
     return array_shift(MyActiveRecord::FindBySql('alias', "SELECT a.* FROM alias a WHERE a.alias like '" . $name . "'"));
 }
Beispiel #11
0
 function GetItems($table)
 {
     return MyActiveRecord::FindBySql("Paypal_Config", "\n\t\t\tSELECT p.* FROM paypal_config p \n\t\t\tINNER JOIN paypal_items ppi ON ppi.paypal_id = p.id \n\t\t\tINNER JOIN {$table} ppc ON ppc.id = ppi.item_id \n\t\t\tWHERE ppi.item_table LIKE '{$table}' \n\t\t\tORDER BY id ASC;");
 }
Beispiel #12
0
 function get_previous_photo()
 {
     $order = $this->display_order;
     $prev_photo = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE gallery_id = {$this->gallery_id} AND display_order < {$this->display_order} ORDER BY display_order DESC LIMIT 1"));
     if (empty($prev_photo)) {
         // get the last photo
         $prev_photo = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE gallery_id = {$this->gallery_id} ORDER BY display_order DESC LIMIT 1"));
     }
     return $prev_photo;
 }
Beispiel #13
0
 function killDraft()
 {
     $page_query = "SELECT * FROM pages WHERE content_file = '' AND name = '{$this->name}' LIMIT 1;";
     $page = MyActiveRecord::FindBySql('Pages', $page_query);
     $query = "DELETE FROM pages WHERE id = {$this->id}";
     mysql_query($query, MyActiveRecord::Connection()) or die($query);
     return array_shift($page);
 }
Beispiel #14
0
 function FindByGalleryId($galid = "")
 {
     $id = mysql_real_escape_string($galid, MyActiveRecord::Connection());
     return MyActiveRecord::FindBySql('Videos', "SELECT v.* FROM videos v WHERE v.gallery_id like '" . $galid . "'");
 }
Beispiel #15
0
 function FindUniqueFiletypes()
 {
     return MyActiveRecord::FindBySql('Documents', "SELECT * FROM documents GROUP BY file_type");
 }
 /**
  * returns array of 'linked' objects. (many-to-many relationship)
  * e.g.
  * <code>
  * foreach( $user->find_linked('Role') as $role ) print $role->name;
  * </code>
  * 
  * In order for the above to work, you would need to have a linking table
  * called Role_User in your database, containing the fields role_id and user_id
  *
  * @param	string	strClass	Name of the class of objects to return in the array
  * @param	string	strCondition	Optional SQL condition, e.g. 'password NOT NULL'
  * @return	array	array containing objects of class strClass
  *
  */
 function find_linked($strClass, $mxdCondition = null, $strOrder = null)
 {
     if (isset($this->id) && $this->id > 0) {
         // only attempt to find links if this object has an id
         $table = MyActiveRecord::Class2Table($strClass);
         $thistable = MyActiveRecord::Class2Table($this);
         $linktable = MyActiveRecord::GetLinkTable($table, $thistable);
         $strOrder = $strOrder ? $strOrder : "{$strClass}.id";
         $sql = "SELECT {$table}.* FROM {$table} INNER JOIN {$linktable} ON {$table}_id = {$table}.id WHERE {$linktable}.{$thistable}_id = {$this->id} ";
         if (is_array($mxdCondition)) {
             foreach ($mxdCondition as $key => $val) {
                 $val = addslashes($val);
                 $sql .= " AND {$key} = '{$val}' ";
             }
         } else {
             if ($mxdCondition) {
                 $sql .= " AND {$mxdCondition}";
             }
         }
         $sql .= " ORDER BY {$strOrder}";
         return MyActiveRecord::FindBySql($strClass, $sql);
     } else {
         return array();
     }
 }
Beispiel #17
0
 function FindByName($name)
 {
     return array_shift(MyActiveRecord::FindBySql('categories', "SELECT c.* FROM categories c WHERE c.name like '" . $name . "'"));
 }
Beispiel #18
0
 function FindByName($name)
 {
     return array_shift(MyActiveRecord::FindBySql('EventTypes', "SELECT * FROM eventtypes WHERE name = '{$name}' LIMIT 1;"));
 }
 /**
  * returns array of 'linked' objects. (many-to-many relationship)
  * e.g.
  * <code>
  * foreach( $user->find_linked('Role') as $role ) print $role->name;
  * </code>
  *
  * In order for the above to work, you would need to have a linking table
  * called Role_User in your database, containing the fields role_id and user_id
  *
  * @param string  strClass  Name of the class of objects to return in the array
  * @param string  strCondition  Optional SQL condition, e.g. 'password NOT NULL'
  * @return  array array containing objects of class strClass
  *
  */
 public function find_linked($strClass, $mxdCondition = null, $strOrder = null)
 {
     if ($this->id) {
         // only attempt to find links if this object has an id
         $table = MyActiveRecord::Class2Table($strClass);
         $thistable = MyActiveRecord::Class2Table($this);
         $linktable = MyActiveRecord::GetLinkTable($table, $thistable);
         $strOrder = $strOrder ? $strOrder : $table . '.id';
         // CHANGED replaced wrongly cased $strClass by $table
         $sql = "SELECT `{$table}`.* FROM `{$table}` INNER JOIN `{$linktable}` ON `{$table}_id`=`{$table}`.`id` WHERE `{$linktable}`.`{$thistable}_id`={$this->id}";
         if (is_array($mxdCondition)) {
             foreach ($mxdCondition as $key => $val) {
                 $val = addslashes($val);
                 $sql .= " AND {$key} = '{$val}' ";
             }
         } else {
             if ($mxdCondition) {
                 $sql .= " AND {$mxdCondition}";
             }
         }
         $sql .= " ORDER BY {$strOrder}";
         return MyActiveRecord::FindBySql($strClass, $sql);
     } else {
         return array();
     }
 }
Beispiel #20
0
 function findVideos($gallery, $orderby = 'name DESC')
 {
     if (is_object($gallery)) {
         return MyActiveRecord::FindBySql('Videos', "SELECT * FROM videos WHERE gallery_id = " . $gallery->id . " ORDER BY " . $orderby . "");
     } else {
         return "Error: A gallery object is required to fetch Videos for an Item";
     }
 }
Beispiel #21
0
 function GetItem($id, $table)
 {
     return array_shift(MyActiveRecord::FindBySql("Paypal_Config", "\n\t\t\tSELECT p.id, p.price, p.display_name, pc.account_name, pc.email, pc.return, pc.cancel_return FROM {$table} p \n\t\t\tINNER JOIN paypal_items ppi ON ppi.item_id = p.id AND ppi.item_table LIKE '{$table}'\n\t\t\tRIGHT JOIN paypal_config pc ON ppi.paypal_id = pc.id \n\t\t\tWHERE p.id = {$id} \n\t\t\tORDER BY id ASC;"));
 }
Beispiel #22
0
 function FindWithRole($role = "")
 {
     return MyActiveRecord::FindBySql('Users', "SELECT * FROM users WHERE is_{$role} = 1");
 }
Beispiel #23
0
 function getPrevEntry($date, $public = true)
 {
     $publiccondition = $public ? 'public = 1 AND ' : '';
     return array_shift(MyActiveRecord::FindBySql('Blog_Entries', "SELECT * FROM blog_entries WHERE {$publiccondition}date(date) < date('{$date}') AND date != '{$date}' ORDER BY date DESC LIMIT 1"));
 }