Esempio n. 1
0
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");
        }
    }
}
Esempio n. 2
0
 static function &Create($strClass, $arrVals = null)
 {
     AppModel::_smartLoadModel($strClass);
     $obj = parent::Create($strClass, $arrVals);
     if (array_key_exists('class', $obj) && empty($obj->class)) {
         $obj->class = $strClass;
     }
     return $obj;
 }
Esempio n. 3
0
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/");
}
Esempio n. 4
0
function initialize_page()
{
    $event_types = EventTypes::FindAll();
    $event_periods = EventPeriods::FindAll();
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
        if ($post_action == "Add Event and add another" || $post_action == "Add and Return to List") {
            $event = MyActiveRecord::Create('Events', $_POST);
            if (!getPostValue('time_start')) {
                $event->setDateStart(getPostValue('date_start'), "04:00:00");
            } else {
                $event->time_start = date("H:i:s", strtotime(getPostValue('time_start')));
            }
            if (!getPostValue('date_end') && !getPostValue('time_end')) {
                $event->setDateEnd(getPostValue('date_start'), "04:00:00");
            } else {
                if (!getPostValue('date_end') && getPostValue('time_end')) {
                    $event->setDateEnd(getPostValue('date_start'), date("H:i:s", strtotime(getPostValue('time_end'))));
                } else {
                    $event->setDateEnd(getPostValue('date_end'), date("H:i:s", strtotime(getPostValue('time_end'))));
                }
            }
            $event->eventtype_id = isset($_POST['eventtype_id']) ? $_POST['eventtype_id'] : 1;
            $event->eventperiod_id = $_POST['eventperiod_id'];
            $event->save();
            $notdates = getPostValue('notdates');
            if (is_array($notdates)) {
                foreach ($notdates as $date) {
                    if (strlen($date) > 4) {
                        $query = "INSERT INTO events_notdate VALUES('{$event->id}','" . formatDateView($date, "Y-m-d") . "')";
                        mysql_query($query, MyActiveRecord::Connection()) or die($query);
                    }
                }
            }
            add_eventUpdateRecurrences($event);
            $thisnewevent = Events::FindById($event->id);
            if ($thisnewevent->date_end < $thisnewevent->date_start) {
                setFlash("<h3>Whoops! Event Starts after it Ends! Please correct dates...</h3>");
                $eventyear = parseDate($thisnewevent->date_start, "Y");
                $eventmonth = parseDate($thisnewevent->date_start, "n");
                redirect("/admin/edit_event/{$eventyear}/{$eventmonth}/{$thisnewevent->id}");
            } else {
                setFlash("<h3>Event added</h3>");
                if ($post_action == "Add and Return to List") {
                    // Redirect user to the Main Event List
                    $datestart = explode("/", getPostValue('date_start'));
                    setFlash("<h3>Event added</h3>");
                    redirect("/admin/list_events/{$datestart['2']}/{$datestart['0']}");
                }
            }
        }
    }
}
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
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);
    }
}
Esempio n. 7
0
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>");
    }
}
Esempio n. 8
0
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");
        }
    }
}
Esempio n. 9
0
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>");
    }
}
Esempio n. 10
0
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/");
        }
    }
}
Esempio n. 11
0
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");
                    }
                }
            }
        }
    }
}
Esempio n. 12
0
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");
        }
    }
}
Esempio n. 13
0
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");
        }
    }
}
Esempio n. 14
0
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);
                }
            }
        }
    }
}
Esempio n. 15
0
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");
            }
        }
    }
}
Esempio n. 16
0
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()
{
    $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);
        }
    }
}
Esempio n. 18
0
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");
        }
    }
}
Esempio n. 19
0
function display_page_content()
{
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    ?>

	<div id="mail_blaster">
		<?php 
    if (!$post_action) {
        $_SESSION['blaster'] = array();
        $lists = NLLists::FindAll();
        ?>
		
		<div id="edit-header" class="blaster">
    		<div class="nav-left column">
        		<h1>Email Blast Setup: Follow these Steps</h1>
    		</div>
    		<div class="nav-right column">
                <a href="<?php 
        echo get_link("admin/list_lists");
        ?>
" class="hcd_button">Manage Mailing Lists</a> 
    		</div>
    		<div class="clearleft"></div>
    	</div>
		
		<script type="text/javascript">
			//<![CDATA[
			$().ready(function() {
				$('.selectList').click(function() {
					$('a.blast_options').fadeIn();
				});
				
				$('.blast_options').click(function() {
					var value = "";
					$('#select_list .selectList').each(function() {
						if ($(this).attr('checked'))
						{
							value += $(this).val()+",";
						}
					});
					$('#session_add').load('<?php 
        echo BASEHREF;
        ?>
blaster/session_add/lists/'+value, function() { 
						$("#blast_options").load('<?php 
        echo BASEHREF;
        ?>
blaster/blast_options/', function() {
							$("#blast_options").slideDown();
						});
					});
					return false;
				});
				
				$('#step-one').click(function() {
    				$(this).fadeOut('slow');
				}); 
			});
			//]]>
		</script>
		
		<form id="select_list_form" method="POST">
		    <div id="select_list">
		        <h2><big>Step 1:</big> Choose a list to send an email to</h2>
<?php 
        foreach ($lists as $list) {
            echo '<p><label for="' . $list->name . '"><input class="selectList" name="list[]" type="checkbox" value="' . $list->name . '" id="' . $list->name . '"/> &nbsp; ' . $list->display_name . '</p>';
        }
        ?>
                    
                <a href="#" id="step-one" class="blast_options submitbutton" style="display:none;">Send a newsletter to selected list(s)</a>
			</div>
			
			<div id="blast_options" style="display: none;"></div>
		</form>
		
		<div id="session_add"></div>
<?php 
    } else {
        if ($post_action == "Submit All Options and Preview") {
            include_once mailPath('snippets/mail_config_parse');
            ?>
    
        <div id="edit-header" class="blaster">
    		<h1>Preview Your E-Newsletter Blast</h1>
    		<p><span class="hint">If you use your browser&rsquo;s &ldquo;Back&rdquo; button, you may lose any text or options you have configured here.</span></p>
    	</div>
    <?php 
            // ! Creates previews in Templates
            $templates_generated = array();
            $lists = "";
            foreach ($list_names as $slug) {
                $list = NLLists::FindBySlug($slug);
                $lists .= "<strong>{$list->display_name}</strong>";
                if (!in_array($list->template, $templates_generated)) {
                    echo "<p><strong>Template: {$list->template}</strong> (Please note: Things may look a little funky, as this is meant to be viewed in a mail browser)</p>\n";
                }
                $templates_generated[] = $list->template;
            }
            echo "<p>Your selected lists are: {$lists} </p>\n";
            echo "<p>Your email subject is: ";
            if ($_POST['subject_line']) {
                $subject = $_POST['subject_line'];
            } else {
                $subject = $list->display_name . " News: " . date("F j\\, Y");
            }
            echo "<strong>{$subject}</strong></p>";
            echo "<div class=\"mail_template\">\n";
            include_once mailPath("mail_layouts/" . $list->template . "_preview");
            echo "</div>\n";
            ?>

			<form id="send_list_form" method="POST">
				<?php 
            hiddenField("description", $_POST['description']);
            ?>
				<?php 
            hiddenField("subject_line", $subject);
            ?>
				
				<div id="edit-footer" class="blaster clearfix">
            		<div class="column half">
            			<p><input type="submit" class="submitbutton" name="submit" value="Send To Your Lists" /></p>
            		</div>
            		<div class="column half last">
            			<p>Be patient... depending on the number of addresses, this may take awhile.</p>
            		</div>
            	</div>
			</form>
<?php 
        } else {
            // Send the Mail
            include_once mailPath('snippets/mail_config_parse');
            // ! Creates previews in Templates
            $success = "";
            $failure = "";
            $subject = $_POST['subject_line'];
            foreach ($list_names as $slug) {
                $list = NLLists::FindBySlug($slug);
                // Include Template
                include_once mailPath("mail_layouts/" . $list->template);
                // stupid bug fix
                $mailed_content = str_replace(array("\\\\'", '\\\\"'), array("'", '"'), $mailed_content);
                $blast = MyActiveRecord::Create("MailBlast");
                $blast->email_subject = $subject;
                $blast->date_sent = date("Y-m-d");
                $blast->hash = md5(date('r', time()));
                $blast->content = $mailed_content;
                $blast->list_id = $list->id;
                $blast->save();
                $failure_num = 0;
                $success_num = 0;
                foreach ($list->findEmails() as $email) {
                    // To send HTML mail, the Content-type header must be set
                    $headers = 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    // Additional headers
                    $headers .= 'From: ' . $list->display_name . ' <' . SENDMAIL_FROM . '>' . "\r\n";
                    // Mail it
                    if (!mail($email->email, $subject, str_replace("{{-email-}}", $email->email, $blast->content), $headers)) {
                        $failure .= $list->display_name . ": " . $email->email . "<br />\n";
                        $failure_num++;
                    } else {
                        $success .= $list->display_name . ": " . $email->email . "<br />\n";
                        $success_num++;
                    }
                }
            }
            echo '<div id="edit-header" class="blaster"><h1>Success!</h1></div>';
            if ($failure_num != 0) {
                echo "<h2>{$failure_num} Email(s) failed:</h2>\n<p>" . $failure . "</p>\n<p>&nbsp;</p>\n";
            }
            echo "<h2>{$success_num} Emails got sent</h2>\n<p>" . $success . "</p>\n";
        }
    }
    ?>

	</div>
<?php 
}
Esempio n. 20
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/");
            }
        }
    }
}
Esempio n. 21
0
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);
            }
        }
    }
}
Esempio n. 22
0
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);
    }
}
Esempio n. 23
0
function initialize_page()
{
    $post_action = $success = "";
    $gallery = Galleries::FindById(requestIdParam());
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Edit Gallery" || $post_action == "Edit and Return to List" || $post_action == "Add Image to Gallery") {
        if (isset($_POST['delete'])) {
            $photos = $gallery->get_photos();
            if (count($photos) > 0) {
                $success .= "Photos deleted / ";
            }
            foreach ($photos as $thephoto) {
                $thephoto->delete(true);
            }
            $gallery->delete(true);
            $success .= "Gallery deleted / ";
            setFlash("<h3>" . substr($success, 0, -3) . "</h3>");
            redirect("/admin/list_galleries");
        } else {
            // Name has changed.
            if ($gallery->name != $_POST['name']) {
                $gallery->name = $_POST['name'];
                $gallery->slug = slug($_POST['name']);
                $gallery->save();
                $success .= "Gallery name saved / ";
            }
            // Update captions if they are different.
            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();
                    }
                }
                //$success .= "Captions edited / ";
            }
            // Reset the display order if the photos have been moved.
            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 != $display_order) {
                        $photo->display_order = $display_order;
                        $photo->save();
                    }
                }
                //$success .= "Photo order saved / ";
            }
            // Upload and save a new file.
            if (isset($_FILES['new_photo']) && $_FILES['new_photo']['error'] == 0) {
                // Updating the record to include the filename stopped working in photos > save_uploaded_file Jan 2013
                $photo = MyActiveRecord::Create('Photos', array('caption' => getPostValue("new_photo_caption"), 'gallery_id' => $gallery->id, 'display_order' => 1));
                $photo->save();
                $photo->save_uploaded_file($_FILES['new_photo']['tmp_name'], $_FILES['new_photo']['name']);
                $photo->setDisplayOrder();
                $success .= "New photo added / ";
            } else {
                // from http://php.net/manual/en/features.file-upload.errors.php
                $upload_errors = array("0. UPLOAD_ERR_OK: No errors.", "1. UPLOAD_ERR_INI_SIZE: Larger than upload_max_filesize.", "2. UPLOAD_ERR_FORM_SIZE: Larger than form MAX_FILE_SIZE.", "3. UPLOAD_ERR_PARTIAL: Partial upload.", "4. UPLOAD_ERR_NO_FILE: No file.", "6. UPLOAD_ERR_NO_TMP_DIR: No temporary directory.", "7. UPLOAD_ERR_CANT_WRITE: Can't write to disk.", "8. UPLOAD_ERR_EXTENSION: File upload stopped by extension.", "UPLOAD_ERR_EMPTY: File is empty.");
                $err_num = $_FILES['new_photo']['error'];
                if ($err_num != 4) {
                    echo "Upload Error! " . $upload_errors[$err_num];
                }
            }
            // Delete photos that were checked off to be removed
            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 .= "Photo deleted / ";
            }
            setFlash("<h3>" . substr($success, 0, -3) . "</h3>");
            if ($post_action == "Edit and Return to List") {
                redirect("admin/list_galleries");
            }
        }
    }
}
Esempio n. 24
0
function initialize_page()
{
    // This file does both, so check the parameters first
    if (requestIdParam() == "add") {
        $area = MyActiveRecord::Create('Areas');
    } else {
        $area_id = requestIdParam();
        $area = Areas::FindById($area_id);
    }
    // Only allow specific post actions
    $post_action = isset($_POST['submit']) ? $_POST['submit'] : null;
    if ($post_action == "Save Area" || $post_action == "Save and Return to List") {
        if (isset($_POST['delete'])) {
            $pages = $area->findPages();
            $selected_sections = array('1');
            foreach ($pages as $page) {
                $page->updateSelectedAreas($selected_sections);
            }
            $area->delete(true);
            setFlash("<h3>Area Deleted</h3>");
            redirect("/admin/list_pages");
        } else {
            $area->display_name = $_POST['display_name'];
            $area->seo_title = $_POST['seo_title'];
            $area->template = $_POST['template'];
            if (!empty($_POST['name'])) {
                $oldname = $_POST['display_name'];
                // Protect the Global Area, the Default Portfolio Area and any placeholders from getting their names changed
                if ($area->id != 1 && $area->id != 3 && $area->name != "site_blog" && $area->name != "placeholder") {
                    if (ALLOW_SHORT_PAGE_NAMES) {
                        $area->name = $_POST['name'] == "" ? slug($_POST['display_name']) : slug($_POST['name']);
                    } else {
                        $area->name = slug($_POST['display_name']);
                    }
                }
            } else {
                $area->name = slug($_POST['display_name']);
            }
            // Allow the possibility to use the word "portfolio" as the last word in the name
            if (substr($area->name, -10) == "-portfolio") {
                // Chop it off the slug so it doesn't turn into a Portfolio Area
                $area->name = substr($area->name, 0, -10);
            }
            // Set the public boolean
            if (requestIdParam() == "add") {
                $area->public = MAINTENANCE_MODE ? 1 : 0;
            } else {
                if ($area->id != 1) {
                    $area->public = isset($_POST['public']) ? 1 : 0;
                }
            }
            // Save it or create it
            if (requestIdParam() == "add") {
                // Don't leave off any columns that we dont want to pass values to. And include an empty value for the ID
                $query = "INSERT INTO `areas` VALUES('','{$area->name}','{$area->display_name}','{$area->seo_title}', '', '1', '{$area->template}', '{$area->public}','')";
                mysql_query($query, MyActiveRecord::Connection()) or die('Die: ' . $query);
                setFlash("<h3>New area &ldquo;" . $area->display_name . "&rdquo; added</h3>");
            } else {
                $area->save();
                setFlash("<h3>Area changes saved</h3>");
            }
            if (ALIAS_INSTALL) {
                if (!empty($oldname)) {
                    $area->checkAlias($oldname);
                }
            }
            if ($post_action == "Save and Return to List") {
                redirect("admin/list_pages");
            }
        }
    }
}
	(
	    [id] => 
	    [title] => 
	    [slug] => 
	    [date] => CURRENT_TIMESTAMP
	    [blog_id] => 
	    [author_id] => 
	    [content] => 
	    [public] => 0
	)
*/
$all_events = Events::FindAll();
$counter = 0;
foreach ($all_events as $event) {
    //if ( $counter == 1 ) break; // For testing
    $newentry = MyActiveRecord::Create('Blog_Entries');
    $newentry->title = esc_html($event->title);
    $newentry->slug = slug($event->title);
    $newentry->date = $event->date_start . " " . $event->time_start;
    // format = 2012-03-14 08:03:17
    $newentry->blog_id = 1;
    $newentry->author_id = 2;
    // manually set to the owner of the site
    $newentry->content = $event->description;
    $newentry->public = 1;
    if ($newentry->save()) {
        echo "&ldquo;" . esc_html($newentry->title) . "&rdquo; saved<br />";
    }
    // Now take the venue and convert it to a Category. Categories need to be created first and match names exactly.
    $event_type = $event->getEventType();
    $category_match = Categories::FindByName(slug($event_type->name));
Esempio n. 26
0
function initialize_page()
{
    // This file does both, so check the parameters first
    if (requestIdParam() == "add") {
        $video = MyActiveRecord::Create('Videos');
    } else {
        $video_id = requestIdParam();
        $video = Videos::FindById($video_id);
    }
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Save Video" || $post_action == "Save and Return to List") {
        if (isset($_POST['delete'])) {
            $photo = Photos::FindVideoPoster($video->id);
            if (is_object($photo)) {
                $photo->delete(true);
            }
            $video->delete();
            setFlash("<h3>Video deleted</h3>");
            redirect("/admin/list_videos");
        } else {
            /*
             * Columns: id, name, title, service (youtube, vimeo), embed (shortcode or unique ID), gallery_id, display_order
             */
            $postedtitle = $_POST['title'];
            $video->name = slug($postedtitle);
            $video->display_name = $postedtitle;
            $video->service = $_POST['service'];
            $video->embed = $_POST['embed'];
            $video->width = $_POST['width'];
            $video->height = $_POST['height'];
            // Why does the save() method fail on new objects? Is it because Videos extend Modelbase and not MyActiveRecord?
            //$video->save();
            if (requestIdParam() == "add") {
                // id, slug, display_name, service (youtube, vimeo), embed, width, height, gallery_id, display_order
                $query = "INSERT INTO `videos` VALUES('','{$video->name}','{$video->display_name}','{$video->service}', '{$video->embed}', '{$video->width}', '{$video->height}', '', '')";
                if (mysql_query($query, MyActiveRecord::Connection())) {
                    $success = 'New video added / ';
                } else {
                    die('Die:<br>' . print_r($query));
                }
                // This is a safer way to do it (we don't rely on the order of columns not to change:
                /*$newvideo = MyActiveRecord::Create( 'Videos', array( 
                      'name' => $video->name,
                      'display_name' => $video->display_name,
                      'service' => $video->service,
                      'embed' => $video->embed,
                      'width' => $video->width,
                      'height' => $video->height,
                  ) );*/
            } else {
                $video->save();
                $success = 'Video changes saved / ';
            }
            if (isset($_FILES['new_poster']) && $_FILES['new_poster']['error'] == 0) {
                // First, delete an old file if there is one
                $oldphoto = Photos::FindVideoPoster($video->id);
                if (is_object($oldphoto)) {
                    $oldphoto->delete(true);
                }
                // New Photo needs to be created as a Photo object
                $newphoto = MyActiveRecord::Create('Photos', array('caption' => $video->display_name, 'video_id' => $video->id, 'display_order' => 1));
                $newphoto->save();
                // save_uploaded_file($tmp_name, $file_name, $isportimg = false, $isentryimg = false, $maxwidth=0, $maxheight=0)
                $newphoto->save_uploaded_file($_FILES['new_poster']['tmp_name'], $_FILES['new_poster']['name'], true);
                $success .= "New poster image uploaded / ";
            } else {
                // from http://php.net/manual/en/features.file-upload.errors.php
                $upload_errors = array("0. UPLOAD_ERR_OK: No errors.", "1. UPLOAD_ERR_INI_SIZE: Larger than upload_max_filesize.", "2. UPLOAD_ERR_FORM_SIZE: Larger than form MAX_FILE_SIZE.", "3. UPLOAD_ERR_PARTIAL: Partial upload.", "4. UPLOAD_ERR_NO_FILE: No file.", "6. UPLOAD_ERR_NO_TMP_DIR: No temporary directory.", "7. UPLOAD_ERR_CANT_WRITE: Can't write to disk.", "8. UPLOAD_ERR_EXTENSION: File upload stopped by extension.", "UPLOAD_ERR_EMPTY: File is empty.");
                $err_num = $_FILES['new_poster']['error'];
                if ($err_num != 4) {
                    echo "Upload Error! " . $upload_errors[$err_num];
                }
            }
            if (requestIdParam() == "add") {
                setFlash('<h3>' . $success . '<a href="' . get_link('admin/edit_entry/' . $video->id) . '">Edit it Now</a></h3>');
            } else {
                setFlash("<h3>" . substr($success, 0, -3) . "</h3>");
            }
            /*if ( requestIdParam() == "add" ) {
            		redirect( "admin/edit_video/".$video->id ); 
                      }*/
            if ($post_action == "Save and Return to List") {
                redirect("admin/list_videos");
            }
        }
    }
}
Esempio n. 27
0
function initialize_page()
{
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Add Product" or $post_action == "Add and Return to List") {
        $product = MyActiveRecord::Create('Product');
        $product->display_name = $_POST['display_name'];
        $product->name = slug($_POST['display_name']);
        $product->price = $_POST['price'];
        if (isset($_POST['product_description'])) {
            $product->description = $_POST['product_description'];
        }
        $product->id = null;
        $product->save();
        $product = Product::FindByName($product->name);
        $account = Paypal_Config::FindById($_POST['accountId']);
        $account->setLink($product->id, 'product');
        // now check if a thumbnail was uploaded
        if (is_uploaded_file($_FILES["image"]["tmp_name"])) {
            $mimeType = $_FILES["image"]["type"];
            $fileType = "";
            switch ($mimeType) {
                case "image/gif":
                    $mimeName = "GIF Image";
                    $fileType = "gif";
                    break;
                case "image/jpeg":
                    $mimeName = "JPEG Image";
                    $fileType = "jpg";
                    break;
                case "image/png":
                    $mimeName = "PNG Image";
                    $fileType = "png";
                    break;
                case "image/x-MS-bmp":
                    $mimeName = "Windows Bitmap";
                    $fileType = "bmp";
                    break;
                default:
                    $mimeName = "Unknown image type";
            }
            // Open the uploaded file
            // MAIN IMAGE
            resizeToMaxDimension($_FILES["image"]["tmp_name"], PRODUCT_IMAGE_MAXWIDTH, "jpg");
            // Open the uploaded file
            $file = fopen($_FILES["image"]["tmp_name"], "r");
            $filesize = filesize($_FILES["image"]["tmp_name"]);
            // Read in the uploaded file
            $imageContents = fread($file, $filesize);
            // Escape special characters in the file
            $imageContents = AddSlashes($imageContents);
            // THUMBNAIL
            resizeToMaxDimension($_FILES["image"]["tmp_name"], PRODUCTTHUMB_IMAGE_MAXWIDTH, "jpg");
            // Open the uploaded file
            $file = fopen($_FILES["image"]["tmp_name"], "r");
            $filesize = filesize($_FILES["image"]["tmp_name"]);
            // Read in the uploaded file
            $thumbContents = fread($file, $filesize);
            // Escape special characters in the file
            $thumbContents = AddSlashes($thumbContents);
            $updateQuery = "UPDATE product SET thumbnail = \"{$thumbContents}\", image = \"{$imageContents}\", mime_type = \"{$mimeName}\" WHERE id = {$product->id}";
            $result = mysql_Query($updateQuery, MyActiveRecord::Connection());
        }
        setFlash("<h3>Product Added</h3>");
        if ($post_action == "Add and Return to List") {
            redirect("admin/list_products");
        }
    }
}
 public function add_child($strClass, $properties = null)
 {
     $object = MyActiveRecord::Create($strClass, $properties);
     $key = MyActiveRecord::Class2Table($this) . "_id";
     $object->{$key} = $this->id;
     return $object;
 }