示例#1
0
 public function indexAction()
 {
     if ($this->session->get('successfu_edite')) {
         $this->view->successfu_edite = true;
         $this->session->clear('successfu_edite');
     }
     $this->view->page_num = $page = $this->getRequest()->getRequest('page', 1);
     $data = array('start' => $page * JO_Registry::get('admin_limit') - JO_Registry::get('admin_limit'), 'limit' => JO_Registry::get('admin_limit'));
     $this->view->countries = array();
     $countries = Model_Countries::getCountries($data);
     if ($countries) {
         foreach ($countries as $country) {
             $this->view->countries[] = $country;
         }
     }
     $total_records = Model_Countries::getTotalCountries();
     $this->view->total_pages = ceil($total_records / JO_Registry::get('admin_limit'));
     $this->view->total_rows = $total_records;
     $pagination = new Model_Pagination();
     $pagination->setLimit(JO_Registry::get('admin_limit'));
     $pagination->setPage($page);
     $pagination->setTotal($total_records);
     $pagination->setUrl($this->getRequest()->getModule() . '/countries/?page={page}');
     $this->view->pagination = $pagination->render();
 }
示例#2
0
 public function editAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user_id')) {
         JO_Session::set('msg_error', $this->translate('You must be logged to change your profile'));
         $redir = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login');
         if ($request->getRequest('tool') == 'change_avatar') {
             die(json_encode(array('logout' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'))));
         } else {
             $this->redirect($redir);
         }
     }
     $this->getLayout()->meta_title = $this->translate('Edit settings');
     $this->getLayout()->meta_description = $this->translate('Edit settings');
     if (JO_Session::get('msg_success')) {
         $this->view->msg_success = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     } elseif (JO_Session::get('msg_error')) {
         $this->view->error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     }
     $tool = $request->getRequest('tool');
     $username = JO_Session::get('username');
     $this->view->user = Model_Users::getByUserName($username);
     $this->view->author_header = Helper_Author::authorHeader($this->view->user);
     $this->view->settings_box = Helper_Author::getSettingsBox($tool);
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Profile'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'name' => $this->translate('Settings'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit')));
     switch ($tool) {
         case 'change_avatar':
             $image = $request->getFile('file');
             if ($image) {
                 $users_path = '/users/' . JO_Date::getInstance(JO_Session::get('register_datetime'), 'yy/mm') . '/' . JO_Session::get('user_id') . '/';
                 $upload_folder = realpath(BASE_PATH . '/uploads');
                 $upload_folder .= $users_path;
                 $upload = new JO_Upload();
                 $upload->setFile($image)->setExtension(array('.jpg', '.jpeg', '.png', '.gif'))->setUploadDir($upload_folder);
                 $new_name = md5(time() . serialize($image));
                 if ($upload->upload($new_name)) {
                     $info = $upload->getFileInfo();
                     if ($info) {
                         $file_path = $users_path . $info['name'];
                         $model_images = new Model_Images();
                         if (JO_Session::get('avatar')) {
                             $model_images->deleteImages(JO_Session::get('avatar'), true);
                         }
                         $thumb = $model_images->resize($file_path, JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
                         Model_Users::editAvatar(JO_Session::get('user_id'), $file_path);
                         die('{ "avatar": "' . $thumb . '", "msg_success": "' . $this->translate('You have successfully changed your avatar') . '"}');
                     } else {
                         die('{ "msg_error": "' . $this->translate('There was an unexpected error with uploading the file') . '"}');
                     }
                 } else {
                     die('{ "msg_error": "' . $this->translate('The file must be valid image') . '" }');
                 }
             }
             break;
         case 'change_password':
             if ($request->isPost()) {
                 $s = Model_Users::editPassword(JO_Session::get('user_id'), array('password' => $request->getPost('password'), 'new_password' => $request->getPost('new_password'), 'new_password_confirm' => $request->getPost('new_password_confirm')));
                 if ($s === true) {
                     $this->session->set('msg_success', $this->translate('You have successfully updated your password'));
                 } else {
                     $this->session->set('msg_error', $s);
                 }
                 $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=users&action=edit&tool=change_password'));
             }
             $this->view->formtitle = $this->translate('Change your password');
             $this->view->crumbs[] = array('name' => $this->view->formtitle);
             $this->view->author_form = $this->view->renderByModule('single_user/change_password', 'users', 'themes');
             break;
         case 'exclusive_author':
             if ($request->isPost()) {
                 $exclusive_author = $request->getPost('exclusive_author');
                 Model_Users::editExclusive(JO_Session::get('user_id'), $exclusive_author);
                 if ($exclusive_author == 'true') {
                     JO_Session::set('msg_success', $this->translate('You have successfully changed to exclusive author'));
                 } else {
                     JO_Session::set('msg_success', $this->translate('You have successfully changed to non exclusive author'));
                 }
                 $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=users&action=edit&tool=exclusive_author'));
             }
             if ($this->view->user['exclusive_author'] == 'true') {
                 $this->view->formtitle = $this->translate('Exclusive Author');
                 $this->view->button = $this->translate('Unsubscribe me as exclusive author');
             } else {
                 $this->view->formtitle = $this->translate('Non-Exclusive Author');
                 $this->view->button = $this->translate('Subscribe me as exclusive author');
             }
             $this->view->top_text = $this->translate('Agreeing to keep your portfolio of items for sale exclusive to the Marketplaces entitles you to a higher percentage of each sale - from 40% to 70%. You can still sell other items elsewhere (on other marketplaces, your own site) however any items you place on an Marketplace must be exclusively sold there.');
             $this->view->bottom_text = $this->translate('You can opt-out of the exclusivity program by clicking the button below. You will be given a 30 day grace period wherein the agreement is still observed after which your payments will return to normal and you may commence selling your items elsewhere.');
             $this->view->crumbs[] = array('name' => $this->view->formtitle);
             $this->view->author_form = $this->view->renderByModule('single_user/exclusive_author', 'users', 'themes');
             break;
         case 'sale_license':
             if ($request->isPost()) {
                 if ($request->getPost('license')) {
                     Model_Users::editLicense(JO_Session::get('user_id'), $request->getPost('license'));
                     JO_Session::set('msg_success', $this->translate('You have successfully changed the license types'));
                 } else {
                     JO_Session::set('msg_error', $this->translate('You have to choose your license'));
                 }
                 $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=users&action=edit&tool=sale_license'));
             }
             $this->view->formtitle = $this->translate('Sale License');
             $this->view->crumbs[] = array('name' => $this->view->formtitle);
             $this->view->license = unserialize($this->view->user['license']);
             $this->view->author_form = $this->view->renderByModule('single_user/sale_license', 'users', 'themes');
             break;
         case 'social':
             if ($request->issetParam('sn')) {
                 $sn = (int) $request->getParam('sn');
                 unset($this->view->user['social'][$sn - 1]);
                 $this->view->user['social'] = array_values($this->view->user['social']);
                 Model_Users::editSocial(JO_Session::get('user_id'), $this->view->user['social']);
                 $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit&tool=social'));
             }
             if ($request->isPost()) {
                 $socials = array();
                 $errors = array();
                 $social_links = $request->getPost('social_link');
                 $social_names = $request->getPost('social_name');
                 $cnt = count($social_links) < count($social_names) ? count($social_names) : count($social_links);
                 for ($i = 0; $i < $cnt; $i++) {
                     $social_names[$i] = trim($social_names[$i]);
                     $social_links[$i] = trim($social_links[$i]);
                     if (empty($social_names[$i]) && empty($social_links[$i])) {
                         break;
                     }
                     if (empty($social_names[$i])) {
                         $errors[$i]['social_name'] = $this->translate('You must fill the name of the social media');
                     }
                     if (empty($social_links[$i])) {
                         $errors[$i]['social_link'] = $this->translate('You must fill valid link for your profile');
                     }
                     $socials[] = array('name' => $social_names[$i], 'href' => $social_links[$i]);
                 }
                 if (empty($errors)) {
                     Model_Users::editSocial(JO_Session::get('user_id'), $socials);
                     JO_Session::set('msg_success', $this->translate('You have successfully changed your social media profiles'));
                 } else {
                     JO_Session::set('msg_error', $errors);
                     $this->session->set('data', $socials);
                 }
                 $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit&tool=social'));
             }
             if ($this->session->issetKey('data')) {
                 $social = $this->session->get('data');
                 $this->session->clear('data');
                 if (count($social) > count($this->view->user['social'])) {
                     $last = end($social);
                     $this->view->new_user = $last['name'];
                     $this->view->new_href = $last['href'];
                 }
             }
             $this->view->formtitle = $this->translate('Social Media profiles');
             $this->view->crumbs[] = array('name' => $this->view->formtitle);
             $this->view->author_form = $this->view->renderByModule('single_user/social', 'users', 'themes');
             break;
         default:
             if ($request->isPost()) {
                 $firstname = trim($request->getPost('firstname'));
                 $lastname = trim($request->getPost('lastname'));
                 $email = trim($request->getPost('email'));
                 if (empty($firstname)) {
                     $error['firstname'] = $this->translate('You must fill your firstname');
                 }
                 if (empty($lastname)) {
                     $error['lastname'] = $this->translate('You must fill your lastname');
                 }
                 if (empty($email)) {
                     $error['email'] = $this->translate('You must fill your email');
                 } elseif (!Model_Users::ValidMail($email)) {
                     $this->view->error['email'] = $this->translate('You must fill valid email');
                 }
                 if ($request->getPost('facebook') == 1) {
                     if ($this->view->user['fb_id'] == 0) {
                         $facebook = new WM_Facebook_Api(array('appId' => JO_Registry::forceGet('facebook_appid'), 'secret' => JO_Registry::forceGet('facebook_secret')));
                         $fbData = $facebook->api('/me');
                         $request->setParams('fb_id', $fbData['id']);
                     } else {
                         $request->setParams('fb_id', $this->view->user['fb_id']);
                     }
                 } else {
                     $request->setParams('fb_id', 0);
                 }
                 if (!count($error)) {
                     Model_Users::editPersonal($this->view->user['user_id'], $request->getParams());
                     JO_Session::set('msg_success', $this->translate('Your personal data has been successfully saved'));
                 } else {
                     JO_Session::set('msg_error', $error);
                 }
                 $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit'));
             }
             $this->view->formtitle = $this->translate('Avatar and Personal Information');
             $this->view->crumbs[] = array('name' => $this->view->formtitle);
             $model_images = new Helper_Images();
             if ($this->view->user['avatar']) {
                 $thumb = $model_images->resize($this->view->user['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
             } else {
                 $this->view->user['avatar'] = 'data/themes/images/noavatar.png';
             }
             $this->view->upl_form_action = WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit&tool=change_avatar');
             $this->view->countries = Model_Countries::getCountries();
             $this->view->author_form = $this->view->renderByModule('single_user/avatar', 'users', 'themes');
     }
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }