Beispiel #1
0
 public function __construct($login = true)
 {
     parent::__construct(true);
     if (UserSession::get('user.type') !== 'admin') {
         $this->_403();
     }
 }
Beispiel #2
0
 protected function _add()
 {
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $lists = MongoDoc::get($binfo, 'lists', array());
     $list_idx = $this->input->post('list');
     $new_list = $this->input->post('new_list');
     if ($list_idx !== null && isset($lists[$list_idx])) {
         if (in_array($id, $lists[$list_idx]['influencers'])) {
             Json::success('Influencer is already preset in the list');
         }
         $lists[$list_idx]['influencers'][] = $id;
     } else {
         if (!empty($new_list)) {
             foreach ($lists as $l) {
                 if ($l['name'] === $new_list) {
                     Json::error(sprintf('List with name "%s" already exists', $new_list));
                 }
             }
             $lists[] = array('name' => $new_list, 'influencers' => array($id));
         } else {
             Json::error('Invalid list');
         }
     }
     $brand->update(array('lists' => $lists));
     Json::success('Success');
 }
Beispiel #3
0
 protected function _channel_influencer()
 {
     try {
         $id = $this->input->post('id');
         $campaign = new Campaign($id);
         $cinfo = $campaign->get();
         if (!$cinfo) {
             throw new \Exception('Invalid campaign');
         }
         if (!($influencer = $this->input->post('influencer'))) {
             throw new \Exception('Invalid influencer');
         }
         $comment = $this->input->post('comment');
         if (empty($comment)) {
             throw new \Exception('Comment must not be empty');
         }
         $comments = MongoDoc::get($cinfo, 'comments.brand_influencer', array());
         if (!isset($comments[$influencer])) {
             $comments[$influencer] = array();
         }
         $comments[$influencer][] = array('from' => UserSession::get('user._id'), 'from_username' => UserSession::get('user.username'), 'user' => 'brand', 'created_at' => time(), 'text' => $comment);
         $comments[$influencer] = array_slice($comments[$influencer], -20);
         $campaign->update(array('comments.brand_influencer' => $comments));
         Alert::once('success', 'Comment added', Url::referrer());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Beispiel #4
0
 public function get($id)
 {
     $favorite = false;
     if (UserSession::get('user.type') === 'influencer') {
         $iinfo = (new Influencer(UserSession::get('user._id')))->get();
         $favorite = in_array(new \MongoId($id), MongoDoc::get($iinfo, 'favorites', array()));
     }
     $this->_display->view(array('main/app/brand/view.php'), array('user' => (new Brand($id))->get(), 'favorite' => $favorite));
 }
Beispiel #5
0
 protected function _get_user_data()
 {
     $valid = new FormValidator();
     $valid->is('Name', $this->input->post('name'))->required()->alnum('- \\.')->length(5, 100)->push('name');
     $valid->is('Email', $this->input->post('email'))->required()->email()->length(5, 100)->push('email');
     $valid->is('Username', $this->input->post('username'))->required()->alnum('.')->length(5, 100)->push('username');
     $valid->is('Password', $this->input->post('password'))->required()->length(5, 100)->push('password');
     $valid->is('Account', UserSession::get('user._id'))->required()->push('account');
     return $valid->data();
 }
Beispiel #6
0
 protected function _get_data($binfo)
 {
     $data = array('brand' => $binfo['_id'], 'points' => 0, 'state' => 'pending');
     if (!in_array($data['type'] = $this->input->post('type'), array('digital-pr', 'ad-serving', 'custom'))) {
         throw new \Exception('Invalid type: ' . $data['type']);
     }
     if ($data['type'] == 'digital-pr') {
         if (!in_array($data['subtype'] = $this->input->post('subtype'), array('create', 'amplify'))) {
             throw new \Exception('Invalid subtype: ' . $data['type']);
         }
         $data['social'] = array();
         $key = 'social_' . $data['subtype'];
         foreach (array('facebook', 'twitter', 'instagram', 'google-analytics', 'google-youtube', 'google-plus', 'vine') as $k) {
             $data['social'][$k] = $this->input->post($key, str_replace('-', '_', $k));
             if ($data['subtype'] == 'create') {
                 $data['social'][$k] = $data['social'][$k] ? true : false;
             }
         }
     }
     $df = $this->input->post('date', 'from');
     $dt = $this->input->post('date', 'to');
     if (!($df && $dt)) {
         throw new \Exception('Dates must be specified');
     }
     $df_ts = (new \DateTime($df, new \DateTimeZone(UserSession::get('user.timezone') ?: TIMEZONE)))->setTimezone(new \DateTimeZone(TIMEZONE))->getTimestamp();
     $dt_ts = (new \DateTime($dt, new \DateTimeZone(UserSession::get('user.timezone') ?: TIMEZONE)))->setTimezone(new \DateTimeZone(TIMEZONE))->getTimestamp();
     $now = strtotime(date('Y-m-d'));
     if ($df_ts - $now < 0) {
         throw new \Exception('Start date must not be in past');
     }
     if ($df_ts > $dt_ts) {
         throw new \Exception('End date must be greater than start date');
     }
     $data['date'] = array('start' => array('date' => $df, 'timestamp' => $df_ts), 'end' => array('date' => $dt, 'timestamp' => $dt_ts));
     if (!($data['title'] = $this->input->post('title'))) {
         throw new \Exception('Title must be specified');
     }
     $data['title'] = trim($data['title']);
     if (strlen($data['title']) < 10) {
         throw new \Exception('Title must be atleast 10 characters long');
     }
     if (!($data['brief'] = $this->input->post('brief'))) {
         throw new \Exception('Brief must be specified');
     }
     $data['brief'] = trim($data['brief']);
     if (strlen($data['brief']) < 50) {
         throw new \Exception('Brief must be atleast 50 characters long');
     }
     $data['influencers_select'] = array();
     if (($idx = $this->input->post('influencer_list')) !== null) {
         $data['influencers_select'] = MongoDoc::get($binfo, 'lists.' . $idx . '.influencers', array());
     }
     return $data;
 }
 protected function _check_login()
 {
     if (!UserSession::get('user')) {
         if ($this->input->is_ajax_request()) {
             Json::success('Session has been invalidated. Redirecting to login page...', Url::base('auth/login'));
         } else {
             Url::redirect('auth/login');
         }
     }
     return true;
 }
Beispiel #8
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     $user = new Influencer($this->input->post('id'));
     if (!($uinfo = $user->get())) {
         Json::error('Invalid user!');
     }
     try {
         $password = null;
         if ($this->input->post('password')) {
             $password = Secure::password($this->input->post('password'), $uinfo['username']);
         }
         $valid = new FormValidator();
         $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
         $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
         $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
         $valid->is('City', $this->input->post('city'))->required()->push('city');
         $valid->is('Genre', $this->input->post('genre'))->required()->transform(function ($d) {
             return explode(',', $d);
         })->push('genre');
         if ($password) {
             $valid->is('Password', $password)->length(5, 100)->push('password');
         }
         $valid->is('About', $this->input->post('about'))->optional()->length(20, 500)->push('about');
         $valid->is('Address', $this->input->post('address'))->optional()->length(10, 100)->push('address');
         $valid->is('Date of Birth', $this->input->post('date_of_birth'))->optional()->custom(function ($key, $value) {
             $d = \DateTime::createFromFormat('Y-m-d', $value);
             if (!($d && $d->format('Y-m-d') == $value)) {
                 throw new \Exception($key . ' must be a valid date of the format yyyy-mm-dd');
             }
         })->push('date_of_birth');
         $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
         $valid->is('Picture', $this->input->post('picture'))->optional()->length(5)->custom(function ($key, $value) {
             $d = get_headers($value, 1);
             if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                 throw new \Exception($key . ' returned a response of : ' . $d[0]);
             }
         })->push('picture');
         $valid->is('Interest', $this->input->post('interest'))->push('interest');
         $data = $valid->data();
         $user->update($data);
         if ($password) {
             (new NotifyInfluencerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
         }
         // Update Session
         UserSession::set('user', $user->get());
         Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Beispiel #9
0
 protected function _remove()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $iinfo = $brand->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['twitter']);
             $brand->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('brand/social'));
 }
Beispiel #10
0
 public function __construct($login = true)
 {
     parent::__construct();
     $this->config->set_item(array('view', 'wrap'), true);
     $this->config->set_item(array('view', 'header'), 'main/common/header.php');
     $this->config->set_item(array('view', 'footer'), 'main/common/footer.php');
     $this->_init();
     if ($login) {
         $this->_check_login();
     }
     if (UserSession::get('user')) {
         $this->_display->attach('notifications', (new Notify())->get_all(UserSession::get('user._id')));
     }
 }
Beispiel #11
0
 protected function _remove()
 {
     try {
         $influencer = new Influencer(UserSession::get('user._id'));
         $iinfo = $influencer->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['instagram']);
             $influencer->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('influencer/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('influencer/social'));
 }
Beispiel #12
0
 protected function _activation()
 {
     $brand = new BrandModel($this->input->post('id'));
     if (!($binfo = $brand->get())) {
         Json::error('Invalid brand!');
     }
     try {
         $active = $this->input->post('active') ? true : false;
         $brand->update(array('active' => $active));
         (new NotifyBrandAccount())->activation($binfo['_id'], UserSession::get('user._id'));
         Json::success('Brand status updated!', null);
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Beispiel #13
0
 protected function _remove()
 {
     if (!UserSession::get('user.superadmin')) {
         $this->_403();
     }
     try {
         if (!($id = $this->input->post('id'))) {
             Alert::once('success', 'Invalid ID!', Url::current());
         }
         $user = new AdminModel($id);
         $user->remove();
         Alert::once('success', 'Account removed successfully!', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Beispiel #14
0
 public function get($brand_id = null)
 {
     $user = new Influencer(UserSession::get('user._id'));
     $uinfo = $user->get();
     $brands = array();
     $bmodel = new Brand(null);
     foreach (MongoDoc::get($uinfo, 'favorites', array()) as $b) {
         $brands[] = $bmodel->filter_one(array('_id' => $b), array('_id' => true, 'name' => true, 'username' => true));
     }
     $river = array();
     if ($brands && !$brand_id) {
         $brand_id = $brands[0]['_id'];
     }
     if ($brand_id) {
         $river = MongoDoc::get((new Brand($brand_id))->get(), 'social_river', array());
     }
     $this->_display->view(array('main/app/influencer/river.php'), array('brands' => $brands, 'brand_id' => $brand_id, 'river' => $river));
 }
Beispiel #15
0
 public function post()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $favorites = MongoDoc::get($binfo, 'favorites', array());
     if ($reset = in_array($id, $favorites)) {
         $favorites = array_values(array_diff($favorites, array($id)));
     } else {
         $favorites[] = $id;
     }
     $brand->update(array('favorites' => $favorites));
     Json::success('Success', null, array('set' => !$reset));
 }
Beispiel #16
0
 protected function _save_river($key)
 {
     try {
         $user = new Brand(UserSession::get('user._id'));
         $uinfo = $user->get();
         $auto = !!$this->input->post('auto');
         if ($auto) {
             if (($r = MongoDoc::get($uinfo, 'social_river.data_custom')) && isset($r[$key])) {
                 unset($r[$key]);
                 $user->update(array('social_river.data_custom' => (object) $r));
             }
         } else {
             if (($u = $this->input->post('url')) && !empty($u)) {
                 $user->update(array('social_river.data_custom.' . $key => trim($u)));
             }
         }
         Alert::once('success', 'URL updated successfully', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Beispiel #17
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     $user = new Admin($this->input->post('id'));
     if (!($uinfo = $user->get())) {
         Json::error('Invalid user!');
     }
     try {
         $password = null;
         if ($this->input->post('password')) {
             $password = Secure::password($this->input->post('password'), $uinfo['username']);
         }
         $valid = new FormValidator();
         $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
         $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
         if ($password) {
             $valid->is('Password', $password)->length(5, 100)->push('password');
         }
         $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
         $data = $valid->data();
         if (UserSession::get('user.superadmin') && $this->input->post('superadmin') == 1) {
             $data['superadmin'] = true;
         }
         $user->update($data);
         if ($password) {
             (new NotifyAdminAccount())->update($uinfo['_id'], UserSession::get('user._id'));
         }
         // Update Session
         UserSession::set('user', $user->get());
         Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Beispiel #18
0
 protected function _logout()
 {
     $this->_check_login();
     // If login as feature is used
     if ($u = UserSession::get('main_user')) {
         UserSession::set('user', $u);
         UserSession::erase('main_user');
         Alert::once('warning', 'Logged in as ' . $u['username'], Url::base(''));
     }
     UserSession::destroy();
     Alert::once('warning', 'You have been logged out!', Url::base('auth/login'));
 }
Beispiel #19
0
 public function get()
 {
     $info = (new Influencer(UserSession::get('user._id')))->get();
     $this->_display->view(array('main/app/influencer/social/index.php'), array('influencer' => $info, 'statistics' => $this->_get_social_differential($info)));
 }
Beispiel #20
0
 protected function _get_campaigns($filter = array())
 {
     $campaign = new Campaign(null);
     $find = array_replace(array('brand' => UserSession::get('user._id')), $filter);
     return $campaign->filter($find);
 }
Beispiel #21
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     if ($this->input->post('action') == 'update-manager') {
         $user = new ExtraUser($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user.manager', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     } else {
         $user = new Brand($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
             if (UserSession::get('main_user.type') == 'admin') {
                 $valid->is('Package', $this->input->post('package'))->required()->push('package');
             }
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $valid->is('About', $this->input->post('about'))->optional()->length(20, 500)->push('about');
             $valid->is('Address', $this->input->post('address'))->optional()->length(10, 100)->push('address');
             $valid->is('Wesbite', $this->input->post('url'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('url');
             $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
             $valid->is('Logo', $this->input->post('logo'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('logo');
             $data = $valid->data();
             if (in_array(UserSession::get('main_user.type'), array('admin', 'partner'))) {
                 $data['social_river.enabled'] = !!$this->input->post('social_river');
             }
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     }
 }
Beispiel #22
0
 public function get()
 {
     $info = (new Brand(UserSession::get('user._id')))->get();
     $this->_display->view(array('main/app/brand/social/index.php'), array('brand' => $info));
 }
Beispiel #23
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     if ($this->input->post('action') == 'update-manager') {
         $user = new ExtraUser($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->alnum('- \\.')->length(5, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->email()->length(5, 100)->push('email');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyPartnerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user.manager', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     } else {
         $user = new Partner($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->alnum('- \\.')->length(5, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->email()->length(5, 100)->push('email');
             $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
             $valid->is('Company Name', $this->input->post('company_name'))->required()->length(5, 100)->push('company_name');
             $valid->is('Company Address', $this->input->post('company_address'))->required()->length(10, 100)->push('company_address');
             $valid->is('Company Website', $this->input->post('company_url'))->required()->length(5, 100)->push('company_url');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyPartnerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     }
 }
Beispiel #24
0
 public function index()
 {
     Url::redirect(UserSession::get('user.type') . '/home');
 }
 protected function _view_all()
 {
     $this->_display->view(array('main/app/notification.php'), array('notifications' => (new Notify())->get_all(UserSession::get('user._id'))));
 }