action, array('login', 'logout', 'password', 'apply', 'contact', 'bug', 'taxprocess'))) { if ($this->Session->read('group') != 'blogger') { $this->redirect('/bloggers/logout/'); } } //$this->redirect('/pages/static/maintenance'); } /** * Blogger Login * * This function displays the login page and also verifies username and password. */ function login() { if (empty($this->params['data'])) { $this->render(); } else { $data = $this->Blogger->verify($this->params['data']['Blogger']['email'], $this->params['data']['Blogger']['password']); if($data) { $this->Session->write('loggedin', 1); $this->Session->write('group', 'blogger'); $this->Session->write('id', $data['Blogger']['id']); $this->redirect('/bloggers/'); } else { $this->set('message_type', 'failure'); $this->set('message', 'Sorry, this account was not recognized'); } } } /** * Blogger Logout * * This function clears the bloggers session and then redirects them to the login. */ function logout() { $this->Session->write('loggedin', 0); $this->Session->write('group', null); $this->Session->write('userid', null); $this->redirect('/bloggers/login/'); } /** * Display Application * * This function displays the application form and validates the data before adding to the db. */ function apply(){ if (empty($this->params['data'])) { $this->render(); } else { if ($this->Blogger->findCount("Blogger.email = '".$this->params['data']['Blogger']['email']."'") || $this->Blog->findCount("Blog.url = '".$this->params['data']['Blogger']['blog_url']."'")) { $this->set('message_type', 'failure'); $this->set('message', 'This email or blog is already in our system, please contact us if you have any questions.'); $this->set('data', $this->params['data']); } else { if ($this->Blogger->save($this->params['data'])) { $this->params['data'] = null; $this->set('message_type', 'success'); $this->set('message', 'Thank you for applying, you will receive a response within 2 business days.'); } else { $this->set('message_type', 'failure'); $this->set('message', 'Problems were found with your application, please see details listed in the form below.'); $this->set('data', $this->params['data']); $this->validateErrors(); } } } } /** * Display Index * * This function grabs posts, contacts and bugs and sets them to be used in the index render. */ function index() { $this->set('user', $this->Blogger->find("id = '".$this->Session->read('id')."'")); $this->set('posts', $this->Post->findAll("", "id,title,abstract", "created DESC", "3")); } /** * Display Offers * * This function displays a list of offers available to this blogger. */ function offers() { $this->set('openbloglinks', $this->BlogLink->findAll("BlogLink.blogger_id = '".$this->Session->read('id')."' AND BlogLink.status = 'open' AND (ClientLink.links_count + ClientLink.blogs_reserved) < ClientLink.links_desired", null, "BlogLink.created DESC")); $this->set('bloglinks', $this->BlogLink->findAll("BlogLink.blogger_id = '".$this->Session->read('id')."' AND BlogLink.status = 'reserved' AND ClientLink.links_desired > ClientLink.links_count AND '".date("Y-m-d H:i:s")."' < BlogLink.expires", null, "BlogLink.created DESC")); if (!empty($this->params['data'])) { $canaccess = $this->BlogLink->postBlogLink($this->params['data'], $this->Session->read('id')); if($canaccess) { $this->params['data']['BlogLink']['status'] = 'pending'; if($this->BlogLink->save($this->params['data'])) { $bloglink = $this->BlogLink->find("BlogLink.id = '".$this->params['data']['BlogLink']['id']."'"); $clientlink = $this->ClientLink->find("ClientLink.id = '".$bloglink['BlogLink']['client_link_id']."'"); $this->set('message_type', 'success'); $this->set('message', 'Your link posting has been received. Once we approve it you will see it in "completed offers".'); $this->params['data']['BlogLink']['posting_url'] = ''; } else { $this->set('message_type', 'failure'); $this->set('message', 'There was a problem with your posting, please see the specifics below.'); $this->set('data', $this->params['data']); $this->validateErrors(); } } else { $this->set('message_type', 'failure'); $this->set('message', 'This offer has expired, please contact us if you feel this is incorrect.'); } } } /** * Display Terms and Conditions * * This function displays the terms and conditions. */ function terms() { } /** * Approve Link * * This function puts a link in reserve for a blogger. */ function linkapprove($id) { $this->BlogLink->reserveBlogLink($id, $this->Session->read('id')); $this->redirect('/bloggers/offers'); } /** * Reject Link * * This function puts a link in reject for a blogger. */ function linkreject($id) { $this->BlogLink->rejectBlogLink($id, $this->Session->read('id')); $this->redirect('/bloggers/offers'); } /** * Display Accounting * * This function displays a breakdown of a bloggers accounting numbers. */ function accounting() { $this->set('bloglinks', $this->BlogLink->findAll("BlogLink.blogger_id = '".$this->Session->read('id')."' and BlogLink.status = 'completed'", "", "BlogLink.created DESC")); } /** * Display Blogs * * This function displays a a list of the bloggers blogs. */ function blogs() { $this->set('blogs', $this->Blog->findAll("Blog.blogger_id = '".$this->Session->read('id')."' and Blog.status = 'approved'", "", "Blog.created DESC")); } /** * Add Blog * * This function displays the add blog form and validates it before adding to the db. */ function blogAdd() { if (empty($this->params['data'])) { $this->render(); } else { if ($this->Blog->findCount("Blog.url = '".$this->params['data']['Blog']['url']."'")) { $this->set('message_type', 'failure'); $this->set('message', 'This blog is already in our system, please contact us if you have any questions.'); $this->set('data', $this->params['data']); } else { $this->params['data']['Blog']['blogger_id'] = $this->Session->read('id'); if ($this->Blog->save($this->params['data'])) { $this->set('message_type', 'success'); $this->set('message', 'Your blog is now pending approval, we will respond within 2 business days.'); } else { $this->set('message_type', 'failure'); $this->set('message', 'There was a problem with your blog submission. Please see specifics in the form below.'); $this->set('data', $this->params['data']); $this->validateErrors($this->Blog); } } } } /** * Edit Blog * * This function displays edit form for internal Blogitive blog and validates before adding to the db. */ function blogEdit($id=null) { if (empty($this->params['data'])) { $this->Blog->setId($id); $this->params['data'] = $this->Blog->read(); $this->set('data', $this->params['data']); } else { $this->Blog->set($this->params['data']); if ($this->Blog->save()) { $this->set('message_type', 'success'); $this->set('message', 'Your blog has been updated.'); } else { $this->set('data', $this->params['data']); $this->validateErrors($this->Blog); } } } /** * Display Settings * * This function displays the bloggers account settings. */ function settings() { $id = $this->Session->read('id'); if (empty($this->params['data'])) { $this->Blogger->setId($id); $this->params['data'] = $this->Blogger->read(); $this->set('data', $this->params['data']); } else { $this->params['data']['Blogger']['id'] = $this->Session->read('id'); $this->Blogger->set($this->params['data']); if ($this->Blogger->save()) { $this->set('message_type', 'success'); $this->set('message', 'Your account settings have been updated.'); } else { $this->set('data', $this->params['data']); $this->validateErrors($this->Blogger); } } } /** * Display Posts * * This function displays the internal Blogitive blog. */ function posts() { $this->set('posts', $this->Post->findAll("", "id, title, abstract, created", "created DESC")); } /** * Display Post * * This function displays a single blog entry for the internal Blogitive blog. */ function postView($id) { $this->Post->setId($id); $this->set('data', $this->Post->read()); } /** * Display Contact * * This function displays the contact form and validates before adding to the db. */ function contact(){ if ($this->Session->read('loggedin')) { $this->set('loggedin', '1'); } else { $this->set('loggedin', '0'); } if (empty($this->params['data'])) { $this->render(); } else { if($this->Session->read('id')) { $this->params['data']['Contact']['type'] = 'blogger'; $this->params['data']['Contact']['tid'] = $this->Session->read('id'); } else { $this->params['data']['Contact']['type'] = 'public'; $this->params['data']['Contact']['tid'] = ''; } $sdata = $this->Contact->save($this->params['data']); if($sdata) { $this->Setting->setId('1'); $settings = $this->Setting->read(); $this->set('name', $this->params['data']['Contact']['first_name']." ".$this->params['data']['Contact']['last_name']); $this->set('company', $this->params['data']['Contact']['company']); $this->set('email', $this->params['data']['Contact']['email']); $this->set('phone', $this->params['data']['Contact']['phone']); $this->set('person', $this->params['data']['Contact']['person']); $this->set('message', $this->params['data']['Contact']['message']); $this->email->controller = $this; $this->email->tpl = 'email_contact'; $this->email->to = $settings['Setting']['email_customerservice']; $this->email->from = $settings['Setting']['email_customerservice']; $this->email->subject = 'Blogitive: (blogger) Contact Submission'; $this->email->send(); $this->params['data'] = null; $this->set('message_type', 'success'); $this->set('message', 'Thank you for contacting us, we will respond within 2 business days.'); } else { $this->set('message_type', 'failure'); $this->set('message', 'There was a problem with your contact information, please see the form below for details.'); $this->set('data', $this->params['data']); $this->validateErrors($this->Contact); } } } /** * Display Bug * * This function displays a bug form and validates the data before adding to the db. */ function bug(){ if ($this->Session->read('loggedin')) { $this->set('loggedin', '1'); } else { $this->set('loggedin', '0'); } if (empty($this->params['data'])) { $this->render(); } else { if($this->Session->read('id')) { $this->params['data']['Bug']['type'] = 'blogger'; $this->params['data']['Bug']['tid'] = $this->Session->read('id'); } else { $this->params['data']['Bug']['type'] = 'public'; $this->params['data']['Bug']['tid'] = ''; } $sdata = $this->Bug->save($this->params['data']); if($sdata) { $this->params['data'] = null; $this->set('message_type', 'success'); $this->set('message', 'Thank you for informing us regarding this bug. Our engineers will attend to it immediately.'); } else { $this->set('message_type', 'failure'); $this->set('message', 'Problems were found with your bug submission, please see details listed in the form below.'); $this->set('data', $this->params['data']); $this->validateErrors(); } } } /** * Password Reminder * * This function displays and sends out password reminders. */ function password() { if (empty($this->params['data'])) { $this->render(); } else { $usr = $this->Blogger->find("username='{$this->params['data']['Blogger']['email']}'"); if($usr) { $this->Setting->setId('1'); $settings = $this->Setting->read(); $this->set('username', $usr['Blogger']['email']); $this->set('password', $usr['Blogger']['password']); $this->email->controller = $this; $this->email->tpl = 'email_password'; $this->email->to = $usr['Blogger']['email']; $this->email->from = $settings['Setting']['email_customerservice']; $this->email->subject = 'Blogitive - Password Reminder'; $this->email->send(); $this->set('message_type', 'success'); $this->set('message', 'An email has been sent to you containing your password.'); } else { $this->set('message_type', 'failure'); $this->set('message', 'Sorry, this email account was not recognized in our system.'); } } } } ?>