예제 #1
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'delete':
             $ids = Params::getParam("id");
             if ($ids != '') {
                 foreach ($ids as $id) {
                     osc_deleteResource($id);
                 }
                 $this->resourcesManager->delete(array(DB_CUSTOM_COND => 'pk_i_id IN (' . implode(', ', $ids) . ')'));
             }
             osc_add_flash_message(_m('Resource deleted'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=media");
             break;
         default:
             $resourceId = Params::getParam("id");
             if ($resourceId != '') {
                 $resources = $this->resourcesManager->getAllResources($resourceId);
             } else {
                 $resources = $this->resourcesManager->getAllResources(NULL);
             }
             //calling the view...
             $this->_exportVariableToView("resources", $resources);
             $this->_exportVariableToView("resourceId", $resourceId);
             $this->doView('media/index.php');
     }
 }
예제 #2
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
             }
             $this->_exportVariableToView("email", $this->emailManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("emails/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray();
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->emailManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->emailManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->emailManager->isIndelible($id)) {
                         $this->emailManager->updateInternalName($id, $s_internal_name);
                     }
                     osc_add_flash_message(_m('The email/alert has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
                 }
                 osc_add_flash_message(_m('You can\'t repeat internal name'), 'admin');
             } else {
                 osc_add_flash_message(_m('The email couldn\'t be updated, at least one title should not be empty'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=emails?action=edit&id=" . $id);
             break;
         default:
             $this->_exportVariableToView("prefLocale", osc_current_admin_locale());
             $this->_exportVariableToView("emails", $this->emailManager->listAll(1));
             $this->doView("emails/index.php");
     }
 }
예제 #3
0
 function doModel()
 {
     switch ($this->action) {
         case 'contact_post':
             //contact_post
             $yourName = Params::getParam('yourName');
             $yourEmail = Params::getParam('yourEmail');
             $subject = Params::getParam('subject');
             $message = Params::getParam('message');
             if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) {
                 if (!osc_check_recaptcha()) {
                     osc_add_flash_message(_m('The Recaptcha code is wrong'));
                     $this->redirectTo(osc_contact_url());
                     return false;
                     // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                 }
             }
             if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) {
                 osc_add_flash_message(_m('You have to introduce a correct e-mail'));
                 $this->redirectTo(osc_contact_url());
             }
             $params = array('from' => $yourEmail, 'from_name' => $yourName, 'subject' => '[' . osc_page_title() . '] ' . __('Contact form') . ': ' . $subject, 'to' => osc_contact_email(), 'to_name' => __('Administrator'), 'body' => $message, 'alt_body' => $message);
             if (osc_contact_attachment()) {
                 $attachment = Params::getFiles('attachment');
                 $resourceName = $attachment['name'];
                 $tmpName = $attachment['tmp_name'];
                 $resourceType = $attachment['type'];
                 $path = osc_content_path() . 'uploads/' . time() . '_' . $resourceName;
                 if (!is_writable(osc_content_path() . 'uploads/')) {
                     osc_add_flash_message(_m('There has been some errors sending the message'));
                     $this->redirectTo(osc_base_url());
                 }
                 if (!move_uploaded_file($tmpName, $path)) {
                     unset($path);
                 }
             }
             if (isset($path)) {
                 $params['attachment'] = $path;
             }
             osc_sendMail($params);
             osc_add_flash_message(_m('Your e-mail has been sent properly. Thank your for contacting us!'));
             $this->redirectTo(osc_base_url());
             break;
         default:
             //contact
             $this->doView('contact.php');
     }
 }
예제 #4
0
 function doModel()
 {
     switch ($this->action) {
         case 'change_email_confirm':
             //change email confirm
             if (Params::getParam('userId') && Params::getParam('code')) {
                 $userManager = new User();
                 $user = $userManager->findByPrimaryKey(Params::getParam('userId'));
                 if ($user['s_pass_code'] == Params::getParam('code')) {
                     $userEmailTmp = UserEmailTmp::newInstance()->findByPk(Params::getParam('userId'));
                     $code = osc_genRandomPassword(50);
                     $userManager->update(array('s_email' => $userEmailTmp['s_new_email']), array('pk_i_id' => $userEmailTmp['fk_i_user_id']));
                     Item::newInstance()->update(array('s_contact_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
                     ItemComment::newInstance()->update(array('s_author_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
                     Alerts::newInstance()->update(array('s_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id']));
                     Session::newInstance()->_set('userEmail', $userEmailTmp['s_new_email']);
                     UserEmailTmp::newInstance()->delete(array('s_new_email' => $userEmailTmp['s_new_email']));
                     osc_add_flash_message(_m('Your email has been changed successfully'));
                     $this->redirectTo(osc_user_profile_url());
                 } else {
                     osc_add_flash_message(_m('Sorry, the link is not valid'));
                     $this->redirectTo(osc_base_url());
                 }
             } else {
                 osc_add_flash_message(_m('Sorry, the link is not valid'));
                 $this->redirectTo(osc_base_url());
             }
             break;
         case 'unsub_alert':
             $email = Params::getParam('email');
             $alert = Params::getParam('alert');
             if ($email != '' && $alert != '') {
                 Alerts::newInstance()->delete(array('s_email' => $email, 's_search' => $alert));
                 osc_add_flash_message(__('Unsubscribed correctly.'));
             } else {
                 osc_add_flash_message(__('Ops! There was a problem trying to unsubscribe you. Please contact the administrator.'));
             }
             $this->redirectTo(osc_base_url());
             break;
         default:
             $this->redirectTo(osc_user_login_url());
             break;
     }
 }
예제 #5
0
 function doModel()
 {
     switch ($this->action) {
         case 'login_post':
             //post execution for the login
             $user = User::newInstance()->findByEmail(Params::getParam('email'));
             if (!$user) {
                 osc_add_flash_message(_m('The username doesn\'t exist'));
                 $this->redirectTo(osc_user_login_url());
             }
             if (!$user['b_enabled']) {
                 osc_add_flash_message(_m('The user has not been validated yet'));
                 $this->redirectTo(osc_user_login_url());
             }
             if ($user["s_password"] == sha1(Params::getParam('password'))) {
                 if (Params::getParam('remember') == 1) {
                     //this include contains de osc_genRandomPassword function
                     require_once osc_lib_path() . 'osclass/helpers/hSecurity.php';
                     $secret = osc_genRandomPassword();
                     User::newInstance()->update(array('s_secret' => $secret), array('pk_i_id' => $user['pk_i_id']));
                     Cookie::newInstance()->set_expires(osc_time_cookie());
                     Cookie::newInstance()->push('oc_userId', $user['pk_i_id']);
                     Cookie::newInstance()->push('oc_userSecret', $secret);
                     Cookie::newInstance()->set();
                 }
                 //we are logged in... let's go!
                 Session::newInstance()->_set('userId', $user['pk_i_id']);
                 Session::newInstance()->_set('userName', $user['s_name']);
                 Session::newInstance()->_set('userEmail', $user['s_email']);
                 $phone = $user['s_phone_mobile'] ? $user['s_phone_mobile'] : $user['s_phone_land'];
                 Session::newInstance()->_set('userPhone', $phone);
             } else {
                 osc_add_flash_message(_m('The password is incorrect'));
             }
             //returning logged in to the main page...
             $this->redirectTo(osc_user_dashboard_url());
             break;
         case 'recover':
             //form to recover the password (in this case we have the form in /gui/)
             $this->doView('user-recover.php');
             break;
         case 'recover_post':
             //post execution to recover the password
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(false);
             $recaptcha_ok = $userActions->recover_password();
             if ($recaptcha_ok) {
                 // We ALWAYS show the same message, so we don't give clues about which emails are in our database and which don't!
                 osc_add_flash_message(_m('We have sent you an email with the instructions to reset your password'));
                 $this->redirectTo(osc_base_url());
             } else {
                 osc_add_flash_message(_m('The recaptcha code is wrong'));
                 $this->redirectTo(osc_recover_user_password_url());
             }
             break;
         case 'forgot':
             //form to recover the password (in this case we have the form in /gui/)
             $user = User::newInstance()->findByIdPasswordSecret(Params::getParam('userId'), Params::getParam('code'));
             if ($user) {
                 $this->doView('user-forgot_password.php');
             } else {
                 osc_add_flash_message(_m('Sorry, the link is not valid'));
                 $this->redirectTo(osc_base_url());
             }
             break;
         case 'forgot_post':
             $user = User::newInstance()->findByIdPasswordSecret(Params::getParam('userId'), Params::getParam('code'));
             if ($user) {
                 if (Params::getParam('new_password') == Params::getParam('new_password2')) {
                     User::newInstance()->update(array('s_pass_code' => osc_genRandomPassword(50), 's_pass_date' => date('Y-m-d H:i:s', 0), 's_pass_ip' => $_SERVER['REMOTE_ADDR'], 's_password' => sha1(Params::getParam('new_password'))), array('pk_i_id' => $user['pk_i_id']));
                     osc_add_flash_message(_m('The password has been changed'));
                     $this->redirectTo(osc_user_login_url());
                 } else {
                     osc_add_flash_message(_m('Error, the password don\'t match'));
                     $this->redirectTo(osc_forgot_user_password_confirm_url(Params::getParam('userId'), Params::getParam('code')));
                 }
             } else {
                 osc_add_flash_message(_m('Sorry, the link is not valid'));
             }
             $this->redirectTo(osc_base_url());
             break;
         default:
             //login
             if (osc_logged_user_id() != '') {
                 $this->redirectTo(osc_user_dashboard_url());
             }
             $this->doView('user-login.php');
     }
 }
예제 #6
0
 function doModel()
 {
     switch ($this->action) {
         case 'add':
             // caliing add view
             $this->doView('languages/add.php');
             break;
         case 'add_post':
             // adding a new language
             $filePackage = Params::getFiles('package');
             $path = osc_translations_path();
             (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
             switch ($status) {
                 case 0:
                     $msg = _m('The translation folder is not writable');
                     break;
                 case 1:
                     $msg = _m('The language has been installed correctly');
                     osc_checkLocales();
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the language');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'edit':
             // editing a language
             $sLocale = Params::getParam('id');
             if (!preg_match('/.{2}_.{2}/', $sLocale)) {
                 osc_add_flash_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $aLocale = $this->localeManager->findByPrimaryKey($sLocale);
             if (count($aLocale) == 0) {
                 osc_add_flash_message(_m('Language id doesn\'t exist'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $this->_exportVariableToView("aLocale", $aLocale);
             $this->doView('languages/frm.php');
             break;
         case 'edit_post':
             // edit language post
             $iUpdated = 0;
             $languageCode = Params::getParam('pk_c_code');
             $enabledWebstie = Params::getParam('b_enabled');
             $enabledBackoffice = Params::getParam('b_enabled_bo');
             $languageName = Params::getParam('s_name');
             $languageShortName = Params::getParam('s_short_name');
             $languageDescription = Params::getParam('s_description');
             $languageCurrencyFormat = Params::getParam('s_currency_format');
             $languageDateFormat = Params::getParam('s_date_format');
             $languageStopWords = Params::getParam('s_stop_words');
             // formatting variables
             if (!preg_match('/.{2}_.{2}/', $languageCode)) {
                 osc_add_flash_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $enabledWebstie = $enabledWebstie != '' ? true : false;
             $enabledBackoffice = $enabledBackoffice != '' ? true : false;
             $languageName = strip_tags($languageName);
             $languageName = trim($languageName);
             if ($languageName == '') {
                 osc_add_flash_message(_m('Language name can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageShortName = strip_tags($languageShortName);
             $languageShortName = trim($languageShortName);
             if ($languageShortName == '') {
                 osc_add_flash_message(_m('Language short name can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageDescription = strip_tags($languageDescription);
             $languageDescription = trim($languageDescription);
             if ($languageDescription == '') {
                 osc_add_flash_message(_m('Language description can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageCurrencyFormat = strip_tags($languageCurrencyFormat);
             $languageCurrencyFormat = trim($languageCurrencyFormat);
             $languageDateFormat = strip_tags($languageDateFormat);
             $languageDateFormat = trim($languageDateFormat);
             $languageStopWords = strip_tags($languageStopWords);
             $languageStopWords = trim($languageStopWords);
             $array = array('b_enabled' => $enabledWebstie, 'b_enabled_bo' => $enabledBackoffice, 's_name' => $languageName, 's_short_name' => $languageShortName, 's_description' => $languageDescription, 's_currency_format' => $languageCurrencyFormat, 's_date_format' => $languageDateFormat, 's_stop_words' => $languageStopWords);
             $iUpdated = $this->localeManager->update($array, array('pk_c_code' => $languageCode));
             if ($iUpdated > 0) {
                 osc_add_flash_message(sprintf(_m('%s has been updated'), $languageShortName), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable':
         case 'enable_bo':
             $default_lang = osc_language();
             $id = Params::getParam('id');
             $enabled = Params::getParam('enabled');
             if ($id) {
                 if ($action == 'enable' && $default_lang == $id && $enabled == 0) {
                     osc_add_flash_message(sprintf(_m('%d can\'t be disabled because it\'s the default language. You can change the default language under General Settings in order to disable it'), $i), 'admin');
                 } else {
                     $msg = $enabled == 1 ? _m('The language has been enabled for the public website') : _m('The language has been disabled for the public website');
                     $aValues = array('b_enabled' => $enabled);
                     $this->localeManager->update($aValues, array('pk_c_code' => $id));
                 }
                 if ($action == 'enable_bo') {
                     $msg = $enabled == 1 ? _m('The language has been enabled for the backoffice (oc-admin)') : _m('The language has been disabled for the backoffice (oc-admin)');
                     $aValues = array('b_enabled_bo' => $enabled);
                     $this->localeManager->update($aValues, array('pk_c_code' => $id));
                 }
                 osc_add_flash_message($msg, 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem updating the language. The language id was lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_selected':
             $msg = _m('Selected languages have been enabled for the website');
             $aValues = array('b_enabled' => 1);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_message($msg, 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_selected':
             $msg = _m('Selected languages have been disabled for the website');
             $aValues = array('b_enabled' => 0);
             $id = Params::getParam('id');
             if ($id != '') {
                 $default_lang = osc_language();
                 foreach ($id as $i) {
                     if ($default_lang == $i && $action == 'disable_selected') {
                         osc_add_flash_message(sprintf(_m('%d can\'t be disabled because it\'s the default language. You can change the default language under General Settings in order to disable it'), $i), 'admin');
                     } else {
                         $this->localeManager->update($aValues, array('pk_c_code' => $i));
                     }
                 }
                 osc_add_flash_message($msg, 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_bo_selected':
             $msg = _m('Selected languages have been enabled for the backoffice (oc-admin)');
             $aValues = array('b_enabled_bo' => 1);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_message($msg, 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_bo_selected':
             $msg = _m('Selected languages have been disabled for the backoffice (oc-admin)');
             $aValues = array('b_enabled_bo' => 0);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_message($msg, 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'delete':
             if (is_array(Params::getParam('id'))) {
                 $default_lang = osc_language();
                 foreach (Params::getParam('id') as $code) {
                     if ($default_lang != $code) {
                         $this->localeManager->deleteLocale($code);
                         if (!osc_deleteDir(osc_translations_path() . $code)) {
                             osc_add_flash_message(sprintf(_m('Directory "%s" couldn\'t be removed'), $code), 'admin');
                         } else {
                             osc_add_flash_message(sprintf(_m('Directory "%s" has been successfully removed'), $code), 'admin');
                         }
                     } else {
                         osc_add_flash_message(sprintf(_m('Directory "%s" couldn\'t be removed because it\'s the default language. Set another language as default first and try again'), $code), 'admin');
                     }
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         default:
             $locales = OSCLocale::newInstance()->listAll();
             $this->_exportVariableToView("locales", $locales);
             $this->doView('languages/index.php');
             break;
     }
 }
예제 #7
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             }
             $this->_exportVariableToView("page", $this->pageManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("pages/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray();
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->pageManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->pageManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->pageManager->isIndelible($id)) {
                         $this->pageManager->updateInternalName($id, $s_internal_name);
                     }
                     osc_add_flash_message(_m('The page has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 }
                 osc_add_flash_message(_m('You can\'t repeat internal name'), 'admin');
             } else {
                 osc_add_flash_message(_m('The page couldn\'t be updated, at least one title should not be empty'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages?action=edit&id=" . $id);
             break;
         case 'add':
             $this->_exportVariableToView("page", array());
             $this->doView("pages/frm.php");
             break;
         case 'add_post':
             $s_internal_name = Params::getParam("s_internal_name");
             if ($s_internal_name == '') {
                 osc_add_flash_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             $page = $this->pageManager->findByInternalName($s_internal_name);
             if (!isset($page['pk_i_id'])) {
                 $aFields = array('s_internal_name' => $s_internal_name, 'b_indelible' => '0');
                 $aFieldsDescription = array();
                 $postParams = Params::getParamsAsArray();
                 $not_empty = false;
                 foreach ($postParams as $k => $v) {
                     if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                         if ($m[2] == 's_title' && $v != '') {
                             $not_empty = true;
                         }
                         $aFieldsDescription[$m[1]][$m[2]] = $v;
                     }
                 }
                 if ($not_empty) {
                     $result = $this->pageManager->insert($aFields, $aFieldsDescription);
                     osc_add_flash_message(_m('The page has been added'), 'admin');
                 } else {
                     osc_add_flash_message(_m('The page couldn\'t be added, at least one title should not be empty'), 'admin');
                 }
             } else {
                 osc_add_flash_message(_m('Oops! That internal name is already in use. We can\'t made the changes'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         case 'delete':
             $id = Params::getParam("id");
             $page_deleted_correcty = 0;
             $page_deleted_error = 0;
             $page_indelible = 0;
             if (!is_array($id)) {
                 $id = array($id);
             }
             foreach ($id as $_id) {
                 $result = (int) $this->pageManager->deleteByPrimaryKey($_id);
                 switch ($result) {
                     case -1:
                         $page_indelible++;
                         break;
                     case 0:
                         $page_deleted_error++;
                         break;
                     case 1:
                         $page_deleted_correcty++;
                 }
             }
             if ($page_indelible > 0) {
                 if ($page_indelible == 1) {
                     osc_add_flash_message(_m('One page can\'t be deleted because it is indelible'), 'admin');
                 } else {
                     osc_add_flash_message($page_indelible . ' ' . _m('pages couldn\'t be deleted because are indelible'), 'admin');
                 }
             }
             if ($page_deleted_error > 0) {
                 if ($page_deleted_error == 1) {
                     osc_add_flash_message(_m('One page couldn\'t be deleted'), 'admin');
                 } else {
                     osc_add_flash_message($page_deleted_error . ' ' . _m('pages couldn\'t be deleted'), 'admin');
                 }
             }
             if ($page_deleted_correcty > 0) {
                 if ($page_deleted_correcty == 1) {
                     osc_add_flash_message(_m('One page has been deleted correctly'), 'admin');
                 } else {
                     osc_add_flash_message($page_deleted_correcty . ' ' . _m('pages have been deleted correctly'), 'admin');
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         default:
             $this->_exportVariableToView("prefLocale", osc_current_admin_locale());
             $this->_exportVariableToView("pages", $this->pageManager->listAll(0));
             $this->doView("pages/index.php");
     }
 }
예제 #8
0
 static function activate($path)
 {
     $conn = getConnection();
     $conn->autocommit(false);
     try {
         $data['s_value'] = osc_active_plugins();
         $plugins_list = unserialize($data['s_value']);
         $found_it = false;
         if (is_array($plugins_list)) {
             foreach ($plugins_list as $plugin_name) {
                 // Check if the plugin is already installed
                 if ($plugin_name == $path) {
                     $found_it = true;
                     break;
                 }
             }
         }
         if (!$found_it) {
             $plugins_list[] = $path;
             $data['s_value'] = serialize($plugins_list);
             $condition = array('s_section' => 'osclass', 's_name' => 'active_plugins');
             Preference::newInstance()->update($data, $condition);
             unset($condition);
             unset($data);
             $conn->commit();
             Plugins::reload();
         } else {
             osc_add_flash_message(_m('Error: Plugin already installed'), 'admin');
         }
     } catch (Exception $e) {
         $conn->rollback();
         echo $e->getMessage();
     }
     $conn->autocommit(true);
 }
예제 #9
0
 function doModel()
 {
     //calling the view...
     $locales = OSCLocale::newInstance()->listAllEnabled();
     $this->_exportVariableToView('locales', $locales);
     switch ($this->action) {
         case 'item_add':
             // post
             if (!osc_users_enabled()) {
                 osc_add_flash_message(_m('Users not enabled'));
                 $this->redirectTo(osc_base_url(true));
             }
             if (osc_reg_user_post() && $this->user == null) {
                 // CHANGEME: This text
                 osc_add_flash_message(_m('Only registered users are allowed to post items'));
                 $this->redirectTo(osc_user_login_url());
             }
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') {
                 $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']);
             } else {
                 if (count($countries) > 0) {
                     $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
                 }
             }
             $cities = array();
             if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']);
             } else {
                 if (count($regions) > 0) {
                     $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
                 }
             }
             $this->_exportVariableToView('countries', $countries);
             $this->_exportVariableToView('regions', $regions);
             $this->_exportVariableToView('cities', $cities);
             $this->_exportVariableToView('user', $this->user);
             osc_run_hook('post_item');
             $this->doView('item-post.php');
             break;
         case 'item_add_post':
             //post_item
             if (!osc_users_enabled()) {
                 osc_add_flash_message(_m('Users not allowed'));
                 $this->redirectTo(osc_base_url(true));
             }
             if (osc_reg_user_post() && $this->user == null) {
                 osc_add_flash_message(_m('Only registered users are allowed to post items'));
                 $this->redirectTo(osc_base_url(true));
             }
             // POST ITEM ( ADD ITEM )
             $mItems = new ItemActions(false);
             $success = $mItems->add();
             if ($success) {
                 $PcontactName = Params::getParam('contactName');
                 $PcontactEmail = Params::getParam('contactEmail');
                 $itemId = Params::getParam('itemId');
                 $item = array();
                 if (Session::newInstance()->_get('userId') == '') {
                     $mPages = new Page();
                     $aPage = $mPages->findByInternalName('email_new_item_non_register_user');
                     $locale = osc_current_user_locale();
                     $content = array();
                     if (isset($aPage['locale'][$locale]['s_title'])) {
                         $content = $aPage['locale'][$locale];
                     } else {
                         $content = current($aPage['locale']);
                     }
                     $item = $this->itemManager->findByPrimaryKey($itemId);
                     $item_url = osc_item_url();
                     // before page = user , action = item_edit
                     $edit_url = osc_item_edit_url($item['s_secret'], $itemId);
                     // before page = user , action = item_delete
                     $delete_url = osc_item_delete_url($item['s_secret'], $itemId);
                     $words = array();
                     $words[] = array('{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}');
                     $words[] = array($itemId, $PcontactName, $PcontactEmail, osc_base_url(), $item['s_title'], $item_url, osc_page_title(), '<a href="' . $edit_url . '">' . $edit_url . '</a>', $edit_url, '<a href="' . $delete_url . '">' . $delete_url . '</a>', $delete_url);
                     $title = osc_mailBeauty($content['s_title'], $words);
                     $body = osc_mailBeauty($content['s_text'], $words);
                     $emailParams = array('subject' => $title, 'to' => $PcontactEmail, 'to_name' => $PcontactName, 'body' => $body, 'alt_body' => $body);
                     osc_sendMail($emailParams);
                 }
                 osc_run_hook('posted_item', $item);
                 $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId'));
                 View::newInstance()->_exportVariableToView('category', $category);
                 $this->redirectTo(osc_search_category_url());
             } else {
                 $this->redirectTo(osc_item_post_url());
             }
             break;
         case 'item_edit':
             $secret = Params::getParam('secret');
             $id = Params::getParam('id');
             $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
             if (count($item) == 1) {
                 $item = Item::newInstance()->findByPrimaryKey($id);
                 $categories = Category::newInstance()->toTree();
                 $countries = Country::newInstance()->listAll();
                 $regions = array();
                 if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') {
                     $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']);
                 } else {
                     if (count($countries) > 0) {
                         $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
                     }
                 }
                 $cities = array();
                 if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') {
                     $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']);
                 } else {
                     if (count($regions) > 0) {
                         $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
                     }
                 }
                 $currencies = Currency::newInstance()->listAll();
                 $this->_exportVariableToView('item', $item);
                 //$this->_exportVariableToView('user', $this->user) ;
                 $this->doView('item-edit.php');
             } else {
                 // add a flash message [ITEM NO EXISTE]
                 //$this->redirectTo(osc_base_url(true));
                 osc_add_flash_message(_m('Sorry, we don\'t have any items with that ID'));
                 if ($this->user != null) {
                     $this->redirectTo(osc_user_list_items_url());
                 } else {
                     $this->redirectTo(osc_base_url());
                 }
             }
             break;
         case 'item_edit_post':
             // recoger el secret y el
             $secret = Params::getParam('secret');
             $id = Params::getParam('id');
             $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
             if (count($item) == 1) {
                 $this->_exportVariableToView('item', $item[0]);
                 $mItems = new ItemActions(false);
                 $success = $mItems->edit();
                 if ($success) {
                     osc_add_flash_message(_m('Great! We\'ve just updated your item'));
                     $this->redirectTo(osc_base_url(true) . "?page=item&id={$id}");
                 } else {
                     $this->redirectTo(osc_item_edit_url($secret));
                 }
             }
             break;
         case 'activate':
             $secret = Params::getParam('secret');
             $id = Params::getParam('id');
             $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
             View::newInstance()->_exportVariableToView('item', $item[0]);
             if ($item[0]['e_status'] == 'INACTIVE') {
                 // ACTIVETE ITEM
                 $mItems = new ItemActions(false);
                 $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']);
                 if ($success) {
                     osc_add_flash_message(_m('The item has been validated'));
                 } else {
                     osc_add_flash_message(_m('The item can\'t be validated'));
                 }
             } else {
                 osc_add_flash_message(_m('The item has already been validated'));
             }
             $this->redirectTo(osc_item_url());
             break;
         case 'item_delete':
             $secret = Params::getParam('secret');
             $id = Params::getParam('id');
             $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId);
             if (count($item) == 1) {
                 $mItems = new ItemActions(false);
                 $success = $mItems->delete($item[0]['s_secret'], $item[0]['pk_i_id']);
                 if ($success) {
                     osc_add_flash_message(_m('Your item has been deleted'));
                 } else {
                     osc_add_flash_message(_m('The item you are trying to delete couldn\'t be deleted'));
                 }
                 if ($this->user != null) {
                     $this->redirectTo(osc_user_list_items_url());
                 } else {
                     $this->redirectTo(osc_base_url());
                 }
             } else {
                 osc_add_flash_message(_m('The item you are trying to delete couldn\'t be deleted'));
                 $this->redirectTo(osc_base_url());
             }
             break;
         case 'deleteResource':
             $id = Params::getParam('id');
             $item = Params::getParam('item');
             $code = Params::getParam('code');
             $secret = Params::getParam('secret');
             // Check for required fields
             if (!(is_numeric($id) && is_numeric($item) && preg_match('/^([a-z0-9]+)$/i', $code))) {
                 osc_add_flash_message(_m("The selected photo couldn't be deleted, the url doesn't exist"));
                 if ($this->userId == null) {
                     $this->redirectTo(osc_base_url());
                 } else {
                     $this->redirectTo(osc_user_dashboard_url());
                 }
             }
             $aItem = $this->itemManager->findByPrimaryKey($item);
             // Check if the item exists
             if (count($aItem) == 0) {
                 osc_add_flash_message(_m('The item doesn\'t exist'));
                 $this->redirectTo(osc_base_url());
             }
             // Check if the item belong to the user
             if ($this->userId != null && $this->userId != $aItem['fk_i_user_id']) {
                 osc_add_flash_message(_m('The item doesn\'t belong to you'));
                 $this->redirectTo(osc_item_url_ns($item));
             }
             // Check if the secret passphrase match with the item
             if ($this->userId == null && $secret != $aItem['s_secret']) {
                 osc_add_flash_message(_m('The item doesn\'t belong to you'));
                 $this->redirectTo(osc_item_url_ns($item));
             }
             // Does id & code combination exist?
             $result = ItemResource::newInstance()->getResourceSecure($id, $code);
             if ($result > 0) {
                 // Delete: file, db table entry
                 osc_deleteResource($id);
                 ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $item, 's_name' => $code));
                 osc_add_flash_message(_m('The selected photo has been successfully deleted'));
             } else {
                 osc_add_flash_message(_m("The selected photo couldn't be deleted"));
             }
             // Redirect to item_edit. If unregistered user, include $secret.
             $this->redirectTo(osc_item_edit_url($secret, $item));
             break;
         case 'mark':
             $mItem = new ItemActions(false);
             $id = Params::getParam('id');
             $as = Params::getParam('as');
             $item = Item::newInstance()->findByPrimaryKey($id);
             View::newInstance()->_exportVariableToView('item', $item);
             $mItem->mark($id, $as);
             osc_add_flash_message(_m('Thanks! That\'s very helpful'));
             $this->redirectTo(osc_item_url());
             break;
         case 'send_friend':
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             $this->_exportVariableToView('item', $item);
             $this->doView('item-send-friend.php');
             break;
         case 'send_friend_post':
             $mItem = new ItemActions(false);
             $mItem->send_friend();
             $item_url = Params::getParam('item_url');
             $this->redirectTo($item_url);
             break;
         case 'contact':
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']);
             if ($category['i_expiration_days'] > 0) {
                 $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600);
                 $date = time();
                 if ($item_date < $date) {
                     // The item is expired, we can not contact the seller
                     osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller'));
                     $this->redirectTo(osc_create_item_url($item));
                 }
             }
             $this->_exportVariableToView('item', $item);
             $this->doView('item-contact.php');
             break;
         case 'contact_post':
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             $this->_exportVariableToView('item', $item);
             if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) {
                 if (!osc_check_recaptcha()) {
                     osc_add_flash_message(_m('The Recaptcha code is wrong'));
                     $this->redirectTo(osc_item_url());
                     return false;
                     // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                 }
             }
             $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']);
             if ($category['i_expiration_days'] > 0) {
                 $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600);
                 $date = time();
                 if ($item_date < $date) {
                     // The item is expired, we can not contact the seller
                     osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller'));
                     $this->redirectTo(osc_item_url());
                 }
             }
             $mItem = new ItemActions(false);
             $mItem->contact();
             osc_add_flash_message(_m('We\'ve just sent an e-mail to the seller'));
             $this->redirectTo(osc_item_url());
             break;
         case 'add_comment':
             $mItem = new ItemActions(false);
             $status = $mItem->add_comment();
             switch ($status) {
                 case -1:
                     $msg = _m('Sorry, we could not save your comment. Try again later');
                     break;
                 case 1:
                     $msg = _m('Your comment is awaiting moderation');
                     break;
                 case 2:
                     $msg = _m('Your comment has been approved');
                     break;
                 case 3:
                     $msg = _m('Please fill the required fields (name, email)');
                     break;
                 case 4:
                     $msg = _m('Please type a comment');
                     break;
                 case 5:
                     $msg = _m('Your comment has been marked as spam');
                     break;
             }
             osc_add_flash_message($msg);
             $this->redirectTo(Params::getParam('itemURL'));
             break;
         case 'delete_comment':
             $mItem = new ItemActions(false);
             $status = $mItem->add_comment();
             $itemId = Params::getParam('id');
             $commentId = Params::getParam('comment');
             $item = Item::newInstance()->findByPrimaryKey($itemId);
             if (count($item) == 0) {
                 osc_add_flash_message(_m('This item doesn\'t exist'));
                 $this->redirectTo(osc_base_url(true));
             }
             View::newInstance()->_exportVariableToView('item', $item);
             if ($this->userId == null) {
                 osc_add_flash_message(_m('You have to be logged to delete a comment'));
                 $this->redirectTo(osc_item_url());
             }
             $commentManager = ItemComment::newInstance();
             $aComment = $commentManager->findByPrimaryKey($commentId);
             if (count($aComment) == 0) {
                 osc_add_flash_message(_m('The comment doesn\'t exist'));
                 $this->redirectTo(osc_item_url());
             }
             if ($aComment['e_status'] != 'ACTIVE') {
                 osc_add_flash_message(_m('The comment is not active, you cannot delete it'));
                 $this->redirectTo(osc_item_url());
             }
             if ($aComment['fk_i_user_id'] != $this->userId) {
                 osc_add_flash_message(_m('You cannot delete the comment'));
                 $this->redirectTo(osc_item_url());
             }
             $commentManager->deleteByPrimaryKey($commentId);
             osc_add_flash_message(_m('The comment has been deleted correctly'));
             $this->redirectTo(osc_item_url());
             break;
         default:
             if (Params::getParam('id') == '') {
                 $this->redirectTo(osc_base_url());
             }
             if (Params::getParam('lang') != '') {
                 Session::newInstance()->_set('userLocale', Params::getParam('lang'));
             }
             $item = $this->itemManager->findByPrimaryKey(Params::getParam('id'));
             // if item doesn't exist redirect to base url
             if (count($item) == 0) {
                 osc_add_flash_message(_m('This item doesn\'t exist'));
                 $this->redirectTo(osc_base_url(true));
             } else {
                 if ($item['e_status'] != 'ACTIVE') {
                     if ($this->userId == $item['fk_i_user_id']) {
                         osc_add_flash_message(_m('The item hasn\'t been validated. Please validate it in order to show it to the rest of users'));
                     } else {
                         osc_add_flash_message(_m('This item hasn\'t been validated'));
                         $this->redirectTo(osc_base_url(true));
                     }
                 }
                 $mStats = new ItemStats();
                 $mStats->increase('i_num_views', $item['pk_i_id']);
                 foreach ($item['locale'] as $k => $v) {
                     $item['locale'][$k]['s_title'] = osc_apply_filter('item_title', $v['s_title']);
                     $item['locale'][$k]['s_description'] = nl2br(osc_apply_filter('item_description', $v['s_description']));
                 }
                 $this->_exportVariableToView('items', array($item));
                 osc_run_hook('show_item', $item);
                 $this->doView('item.php');
             }
             break;
         case 'dashboard':
             //dashboard...
             break;
     }
 }
예제 #10
0
 function doModel()
 {
     switch ($this->action) {
         case 'import':
             // calling import view
             $this->doView('tools/import.php');
             break;
         case 'import_post':
             // calling
             $sql = Params::getFiles('sql');
             //dev.conquer: if the file es too big, we can have problems with the upload or with memory
             $content_file = file_get_contents($sql['tmp_name']);
             $conn = getConnection();
             if ($conn->osc_dbImportSQL($content_file)) {
                 osc_add_flash_message(_m('Import complete'), 'admin');
             } else {
                 osc_add_flash_message(_m('There was a problem importing data to the database'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             break;
         case 'images':
             // calling images view
             $this->doView('tools/images.php');
             break;
         case 'images_post':
             $preferences = Preference::newInstance()->toArray();
             $path = osc_content_path() . 'uploads/';
             $dir = opendir($path);
             while ($file = readdir($dir)) {
                 if (preg_match('|([0-9]+)_thumbnail\\.png|i', $file, $matches)) {
                     $orig_file = str_replace('_thumbnail.', '_original.', $file);
                     $tmpName = osc_content_path() . 'uploads/' . $orig_file;
                     if (!file_exists($orig_file)) {
                         copy(str_replace('_original.', '.', $tmpName), $tmpName);
                     }
                     // Create thumbnail
                     $thumbnailPath = osc_content_path() . 'uploads/' . $file;
                     $size = explode('x', osc_thumbnail_dimensions());
                     ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath);
                     // Create preview
                     $thumbnailPath = osc_content_path() . 'uploads/' . str_replace('_thumbnail.', '_preview.', $file);
                     $size = explode('x', osc_preview_dimensions());
                     ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath);
                     // Create normal size
                     $thumbnailPath = osc_content_path() . 'uploads/' . str_replace('_thumbnail.', '.', $file);
                     $size = explode('x', osc_normal_dimensions());
                     ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath);
                     if (!osc_keep_original_image()) {
                         @unlink($tmpName);
                     }
                 }
             }
             closedir($dir);
             osc_add_flash_message(_m('Re-generation complete'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images');
             break;
         case 'upgrade':
             $this->doView('tools/upgrade.php');
             break;
         case 'backup':
             $this->doView('tools/backup.php');
             break;
         case 'backup-sql':
             //databasse dump...
             if (Params::getParam('bck_dir') != '') {
                 $path = trim(Params::getParam('bck_dir'));
                 if (substr($path, -1, 1) != "/") {
                     $path .= '/';
                 }
             } else {
                 $path = osc_base_path();
             }
             $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql';
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     break;
                 case -2:
                     $msg = _m('Could not connect with the database') . '. Error: ' . mysql_error();
                     break;
                 case -3:
                     $msg = _m('Could not select the database') . '. Error: ' . mysql_error();
                     break;
                 case -4:
                     $msg = _m('There are no tables to back up');
                     break;
                 case -5:
                     $msg = _m('The folder is not writable');
                     break;
                 default:
                     $msg = _m('Backup has been done properly');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip':
             //zip of the code just to back it up
             if (Params::getParam('bck_dir') != '') {
                 $archive_name = trim(Params::getParam('bck_dir'));
                 if (substr(trim($archive_name), -1, 1) != "/") {
                     $archive_name .= '/';
                 }
                 $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip';
             } else {
                 $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip";
             }
             $archive_folder = osc_base_path();
             if (osc_zip_folder($archive_folder, $archive_name)) {
                 $msg = _m('Archiving successful!');
             } else {
                 $msg = _m('Error, the zip file was not created at the specified directory');
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup_post':
             $this->doView('tools/backup.php');
             break;
         default:
     }
 }
예제 #11
0
 function install_location_by_region()
 {
     $countryParent = Params::getParam('country_c_parent');
     $region = Params::getParam('region');
     if ($countryParent == '') {
         return false;
     }
     if ($region == '') {
         return false;
     }
     $manager_country = new Country();
     $country = $manager_country->findByCode($countryParent);
     $aCountry = array();
     $aRegion = array();
     $aCountry[] = $country['s_name'];
     $aRegion[] = $region;
     $manager_region = new Region();
     $regions_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=region&country=' . urlencode(implode(',', $aCountry)) . '&term=' . urlencode(implode(',', $aRegion)));
     $regions = json_decode($regions_json);
     if (isset($regions->error)) {
         osc_add_flash_message(sprintf(__('%s cannot be added'), $region), 'admin');
         return false;
     }
     foreach ($regions as $r) {
         $exists = $manager_region->findByNameAndCode($r->name, $r->country_code);
         if (isset($exists['s_name'])) {
             osc_add_flash_message(sprintf(__('%s already was in the database'), $c_exists['s_name']), 'admin');
             return false;
         }
         $manager_region->insert(array("fk_c_country_code" => $r->country_code, "s_name" => $r->name));
     }
     unset($regions);
     unset($regions_json);
     $manager_city = new City();
     foreach ($country as $c) {
         $regions = $manager_region->findByConditions(array('fk_c_country_code' => $country['pk_c_code'], 's_name' => $region));
         $cities_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=city&country=' . urlencode($c) . '&region=' . urlencode($regions['s_name']) . '&term=all');
         $cities = json_decode($cities_json);
         if (!isset($cities->error)) {
             foreach ($cities as $ci) {
                 $manager_city->insert(array("fk_i_region_id" => $regions['pk_i_id'], "s_name" => $ci->name, "fk_c_country_code" => $ci->country_code));
             }
         }
         unset($cities);
         unset($cities_json);
     }
     osc_add_flash_message(sprintf(__('%s has been added as a region of %s'), $region, $country['s_name']), 'admin');
 }
예제 #12
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("plugins/add.php");
             break;
         case 'add_post':
             $package = Params::getFiles("package");
             $path = osc_plugins_path();
             (int) ($status = osc_unzip_file($package['tmp_name'], $path));
             switch ($status) {
                 case 0:
                     $msg = _m('The plugin folder is not writable');
                     break;
                 case 1:
                     $msg = _m('The plugin has been uploaded correctly');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the plugin');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'install':
             $pn = Params::getParam("plugin");
             Plugins::activate($pn);
             //run this after installing the plugin
             Plugins::runHook('install_' . $pn);
             osc_add_flash_message(_m('Plugin installed'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'uninstall':
             $pn = Params::getParam("plugin");
             Plugins::runHook($pn . '_uninstall');
             Plugins::deactivate($pn);
             osc_add_flash_message(_m('Plugin uninstalled'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'admin':
             global $active_plugins;
             $plugin = Params::getParam("plugin");
             if ($plugin != "") {
                 Plugins::runHook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             Plugins::runHook('admin_post');
         case 'renderplugin':
             global $active_plugins;
             $file = Params::getParam("file");
             if ($file != "") {
                 // We pass the GET variables (in case we have somes)
                 if (preg_match('|(.+?)\\?(.*)|', $file, $match)) {
                     $file = $match[1];
                     if (preg_match_all('|&([^=]+)=([^&]*)|', urldecode('&' . $match[2] . '&'), $get_vars)) {
                         for ($var_k = 0; $var_k < count($get_vars[1]); $var_k++) {
                             //$_GET[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             //$_REQUEST[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 //osc_renderPluginView($file);
                 $this->doView("plugins/view.php");
             }
             break;
         case 'configure':
             $plugin = Params::getParam("plugin");
             if ($plugin != '') {
                 $plugin_data = Plugins::getInfo($plugin);
                 $this->_exportVariableToView("categories", Category::newInstance()->toTreeAll());
                 $this->_exportVariableToView("selected", PluginCategory::newInstance()->listSelected($plugin_data['short_name']));
                 $this->_exportVariableToView("plugin_data", $plugin_data);
                 $this->doView("plugins/configuration.php");
             } else {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             }
             break;
         case 'configure_post':
             $plugin_short_name = Params::getParam("plugin_short_name");
             $categories = Params::getParam("categories");
             if ($plugin_short_name != "") {
                 Plugins::cleanCategoryFromPlugin($plugin_short_name);
                 if (isset($categories)) {
                     Plugins::addToCategoryPlugin($categories, $plugin_short_name);
                 }
             } else {
                 osc_add_flash_message(_m('No plugin selected'), 'admin');
                 $this->doView("plugins/index.php");
             }
             osc_add_flash_message(_m('Configuration was saved'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         default:
             $this->_exportVariableToView("plugins", Plugins::listAll());
             $this->doView("plugins/index.php");
     }
 }
예제 #13
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'bulk_actions':
             switch (Params::getParam('bulk_actions')) {
                 case 'activate_all':
                     $id = Params::getParam('id');
                     $value = 'ACTIVE';
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                             }
                         }
                         osc_add_flash_message(_m('The items have been activated'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'deactivate_all':
                     $id = Params::getParam('id');
                     $value = 'INACTIVE';
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                                 $item = $this->itemManager->findByPrimaryKey($_id);
                                 CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                             }
                         }
                         osc_add_flash_message(_m('The items have been deactivated'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'premium_all':
                     $id = Params::getParam('id');
                     $value = 1;
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $_id));
                             }
                         }
                         osc_add_flash_message(_m('The items have been marked as premium'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'depremium_all':
                     $id = Params::getParam('id');
                     $value = 0;
                     try {
                         if ($id) {
                             foreach ($id as $_id) {
                                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $_id));
                             }
                         }
                         osc_add_flash_message(_m('The changes have been made'), 'admin');
                     } catch (Exception $e) {
                         osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
                     }
                     break;
                 case 'delete_all':
                     $id = Params::getParam('id');
                     $success = false;
                     foreach ($id as $i) {
                         if ($i) {
                             $item = $this->itemManager->findByPrimaryKey($i);
                             $mItems = new ItemActions(true);
                             $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                         }
                     }
                     if ($success) {
                         osc_add_flash_message(_m('The item has been deleted'), 'admin');
                     } else {
                         osc_add_flash_message(_m('The item couldn\'t be deleted'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . "?page=items");
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'delete':
             //delete
             $id = Params::getParam('id');
             $success = false;
             foreach ($id as $i) {
                 if ($i) {
                     $item = $this->itemManager->findByPrimaryKey($i);
                     $mItems = new ItemActions(true);
                     $success = $mItems->delete($item['s_secret'], $item['pk_i_id']);
                 }
             }
             if ($success) {
                 osc_add_flash_message(_m('The item has been deleted'), 'admin');
             } else {
                 osc_add_flash_message(_m('The item couldn\'t be deleted'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status':
             //status
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array('ACTIVE', 'INACTIVE'))) {
                 return false;
             }
             try {
                 $this->itemManager->update(array('e_status' => $value), array('pk_i_id' => $id));
                 $item = $this->itemManager->findByPrimaryKey($id);
                 switch ($value) {
                     case 'ACTIVE':
                         osc_add_flash_message(_m('The item has been activated'), 'admin');
                         CategoryStats::newInstance()->increaseNumItems($item['fk_i_category_id']);
                         break;
                     case 'INACTIVE':
                         osc_add_flash_message(_m('The item has been deactivated'), 'admin');
                         CategoryStats::newInstance()->decreaseNumItems($item['fk_i_category_id']);
                         break;
                 }
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'status_premium':
             //status premium
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array(0, 1))) {
                 return false;
             }
             try {
                 $this->itemManager->update(array('b_premium' => $value), array('pk_i_id' => $id));
                 osc_add_flash_message(_m('Changes have been applied'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'item_edit':
             //require_once LIB_PATH . 'osclass/itemActions.php';
             $id = Params::getParam('id');
             $item = Item::newInstance()->findByPrimaryKey($id);
             if (count($item) <= 0) {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             }
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (count($countries) > 0) {
                 $regions = Region::newInstance()->getByCountry($item['fk_c_country_code']);
             }
             $cities = array();
             if (count($regions) > 0) {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $item['fk_i_region_id']);
             }
             $resources = Item::newInstance()->findResourcesByID($id);
             $this->_exportVariableToView("users", User::newInstance()->listAll());
             $this->_exportVariableToView("categories", Category::newInstance()->toTree());
             $this->_exportVariableToView("countries", $countries);
             $this->_exportVariableToView("regions", $regions);
             $this->_exportVariableToView("cities", $cities);
             $this->_exportVariableToView("currencies", Currency::newInstance()->listAll());
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->_exportVariableToView("item", $item);
             $this->_exportVariableToView("resources", $resources);
             $this->_exportVariableToView("new_item", FALSE);
             $this->doView('items/frm.php');
             break;
         case 'item_edit_post':
             $mItems = new ItemActions(true);
             $success = $mItems->edit();
             $id = Params::getParam('userId');
             if ($id != '') {
                 $user = User::newInstance()->findByPrimaryKey($id);
                 Item::newInstance()->update(array('fk_i_user_id' => $id, 's_contact_name' => $user['s_name'], 's_contact_email' => $user['s_email']), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
             } else {
                 Item::newInstance()->update(array('fk_i_user_id' => NULL, 's_contact_name' => Params::getParam('contactName'), 's_contact_email' => Params::getParam('contactEmail')), array('pk_i_id' => Params::getParam('id'), 's_secret' => Params::getParam('secret')));
             }
             osc_add_flash_message(_m('Changes saved correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'deleteResource':
             //delete resource
             $id = Params::getParam('id');
             $name = Params::getParam('name');
             $fkid = Params::getParam('fkid');
             // delete files
             osc_deleteResource($id);
             ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $fkid, 's_name' => $name));
             osc_add_flash_message(_m('Resource deleted'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             break;
         case 'post':
             //post
             $countries = Country::newInstance()->listAll();
             $regions = array();
             if (count($countries) > 0) {
                 $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']);
             }
             $cities = array();
             if (count($regions) > 0) {
                 $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']);
             }
             $this->_exportVariableToView("users", User::newInstance()->listAll());
             $this->_exportVariableToView("categories", Category::newInstance()->toTree());
             $this->_exportVariableToView("countries", $countries);
             $this->_exportVariableToView("regions", $regions);
             $this->_exportVariableToView("cities", $cities);
             $this->_exportVariableToView("currencies", Currency::newInstance()->listAll());
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->_exportVariableToView("item", array());
             $this->_exportVariableToView("resources", array());
             $this->_exportVariableToView("new_item", TRUE);
             $this->doView('items/frm.php');
             break;
         case 'post_item':
             //post item
             $mItem = new ItemActions(true);
             $success = $mItem->add();
             if ($success) {
                 osc_add_flash_message(_m('A new item has been added'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             } else {
                 osc_add_flash_message(_m('The item can\'t be added'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=items");
             }
             break;
         default:
             //default
             $catId = Params::getParam('catId');
             //preparing variables for the view
             $this->_exportVariableToView("items", $catId ? $this->itemManager->findByCategoryID($catId) : $this->itemManager->listAllWithCategories());
             $this->_exportVariableToView("catId", $catId);
             $this->_exportVariableToView("stat", Params::getParam('stat'));
             //calling the view...
             $this->doView('items/index.php');
     }
 }
예제 #14
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->_exportVariableToView("categories", $this->categoryManager->toTreeAll());
             $this->_exportVariableToView("languages", OSCLocale::newInstance()->listAllEnabled());
             $this->_exportVariableToView("category", array());
             $this->doView("categories/frm.php");
             break;
         case 'add_post':
             try {
                 // fields contain data of t_category
                 $fields['fk_i_parent_id'] = Params::getParam("fk_i_parent_id") != '' ? Params::getParam("fk_i_parent_id") : null;
                 $fields['i_expiration_days'] = Params::getParam("i_expiration_days") != '' ? Params::getParam("i_expiration_days") : 0;
                 $fields['i_position'] = Params::getParam("i_position") != '' ? Params::getParam("i_position") : 0;
                 $fields['b_enabled'] = Params::getParam("b_enabled") != '' ? 1 : 0;
                 $postParams = Params::getParamsAsArray();
                 foreach ($postParams as $k => $v) {
                     if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                         $aFieldsDescription[$m[1]][$m[2]] = $v;
                     }
                 }
                 $this->categoryManager->insert($fields, $aFieldsDescription);
                 osc_add_flash_message(_m('The category has been added'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('The category could\'t be added') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             break;
         case 'edit':
             $this->_exportVariableToView("category", $this->categoryManager->findByPrimaryKey(Params::getParam("id")));
             $this->_exportVariableToView("categories", $this->categoryManager->toTreeAll());
             $this->_exportVariableToView("languages", OSCLocale::newInstance()->listAllEnabled());
             $this->doView("categories/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $fields['fk_i_parent_id'] = Params::getParam("fk_i_parent_id") != '' ? Params::getParam("fk_i_parent_id") : null;
             $fields['i_expiration_days'] = Params::getParam("i_expiration_days") != '' ? Params::getParam("i_expiration_days") : 0;
             $fields['i_position'] = Params::getParam("i_position") != '' ? Params::getParam("i_position") : 0;
             $fields['b_enabled'] = Params::getParam("b_enabled") != '' ? 1 : 0;
             $postParams = Params::getParamsAsArray();
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             try {
                 $this->categoryManager->updateByPrimaryKey($fields, $aFieldsDescription, $id);
                 osc_add_flash_message(_m('The category has been updated.'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             if (!is_null($fields['fk_i_parent_id'])) {
                 $this->redirectTo(osc_admin_base_url(true) . '?page=categories&parentId=' . $fields['fk_i_parent_id']);
             } else {
                 $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             }
             break;
         case 'delete':
             $id = Params::getParam("id");
             try {
                 foreach ($id as $i) {
                     if (intval($i)) {
                         $this->categoryManager->deleteByPrimaryKey($i);
                     }
                 }
                 osc_add_flash_message(_m('The categories have been deleted'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             break;
         case 'enable':
             $id = Params::getParam("id");
             $enabled = Params::getParam("enabled") != '' ? Params::getParam("enabled") : 0;
             try {
                 if ($id != '') {
                     $this->categoryManager->update(array('b_enabled' => $enabled), array('pk_i_id' => $id));
                     if ($enabled == 1) {
                         $msg = _m('The category has been enabled');
                     } else {
                         $msg = _m('The category has been disabled');
                     }
                 } else {
                     $msg = _m('There was a problem with this page. The ID for the category hasn\'t been set');
                 }
                 osc_add_flash_message($msg, 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             break;
         case 'enable_selected':
             $ids = Params::getParam("id");
             try {
                 if ($ids != '') {
                     foreach ($ids as $id) {
                         //XXX: bad... needs refactoring.
                         $this->categoryManager->update(array('b_enabled' => 1), array('pk_i_id' => $id));
                     }
                 }
                 osc_add_flash_message(_m('The categories have been enabled'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             break;
         case 'disable_selected':
             $ids = Params::getParam("id");
             try {
                 if ($ids != '') {
                     foreach ($ids as $id) {
                         //XXX: bad... needs refactoring.
                         $this->categoryManager->update(array('b_enabled' => 0), array('pk_i_id' => $id));
                     }
                 }
                 osc_add_flash_message(_m('The selected categories have been disabled'), 'admin');
             } catch (Exception $e) {
                 osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=categories');
             break;
         default:
             $parentId = Params::getParam("parentId");
             if ($parentId != '') {
                 $this->_exportVariableToView("categories", $this->categoryManager->listWhere("a.fk_i_parent_id = %d ", $parentId));
                 $this->_exportVariableToView("parent", $this->categoryManager->findByPrimaryKey($parentId));
             } else {
                 $this->_exportVariableToView("categories", $this->categoryManager->listWhere("a.fk_i_parent_id IS NULL"));
             }
             $this->doView("categories/index.php");
     }
 }
예제 #15
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("appearance/add.php");
             break;
         case 'add_post':
             $filePackage = Params::getFiles('package');
             $path = osc_themes_path();
             (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
             switch ($status) {
                 case 0:
                     $msg = _m('The theme folder is not writable');
                     break;
                 case 1:
                     $msg = _m('The theme has been installed correctly');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the theme');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
             /*case 'delete':
                   $themes = Params::getParam('theme') ;
                   if ( isset( $themes ) && is_array( $themes ) ) {
                       foreach ($themes as $theme) {
                           if (!osc_deleteDir(THEMES_PATH . $theme))
                               osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $theme);
                       }
                   } else if (isset( $themes )) {
                       if (!osc_deleteDir(THEMES_PATH . $themes)){
                           osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $themes);
                       }
                   } else {
                       osc_add_flash_message( _m('No theme selected'));
                   }
                   $this->redirectTo( osc_admin_base_url(true) . "?page=appearance" );
               break;*/
         /*case 'delete':
               $themes = Params::getParam('theme') ;
               if ( isset( $themes ) && is_array( $themes ) ) {
                   foreach ($themes as $theme) {
                       if (!osc_deleteDir(THEMES_PATH . $theme))
                           osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $theme);
                   }
               } else if (isset( $themes )) {
                   if (!osc_deleteDir(THEMES_PATH . $themes)){
                       osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $themes);
                   }
               } else {
                   osc_add_flash_message( _m('No theme selected'));
               }
               $this->redirectTo( osc_admin_base_url(true) . "?page=appearance" );
           break;*/
         case 'widgets':
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/widgets.php');
             break;
         case 'add_widget':
             $this->doView('appearance/add_widget.php');
             break;
         case 'delete_widget':
             Widget::newInstance()->delete(array('pk_i_id' => Params::getParam('id')));
             osc_add_flash_message(_m('Widget removed correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'add_widget_post':
             Widget::newInstance()->insert(array('s_location' => Params::getParam('location'), 'e_kind' => 'html', 's_description' => Params::getParam('description'), 's_content' => Params::getParam('content')));
             osc_add_flash_message(_m('Widget added correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'activate':
             Preference::newInstance()->update(array('s_value' => Params::getParam('theme')), array('s_section' => 'osclass', 's_name' => 'theme'));
             osc_add_flash_message(_m('Theme activated correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         default:
             $themes = WebThemes::newInstance()->getListThemes();
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             //preparing variables for the view
             $this->_exportVariableToView("themes", $themes);
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/index.php');
     }
 }
예제 #16
0
 function doModel()
 {
     parent::doModel();
     switch ($this->action) {
         case 'add':
             // callin add view
             $this->doView('admins/add.php');
             break;
         case 'add_post':
             // adding a new admin
             $sPassword = Params::getParam('s_password');
             $sName = Params::getParam('s_name');
             $sEmail = Params::getParam('s_email');
             $sUserName = Params::getParam('s_username');
             // cleaning parameters
             $sPassword = strip_tags($sPassword);
             $sPassword = trim($sPassword);
             $sName = strip_tags($sName);
             $sName = trim($sName);
             $sEmail = strip_tags($sEmail);
             $sEmail = trim($sEmail);
             $sUserName = strip_tags($sUserName);
             $sUserName = trim($sUserName);
             // Checks for legit data
             if (!preg_match("/^[_a-z0-9-+]+(\\.[_a-z0-9-+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", $sEmail)) {
                 osc_add_flash_message(_m("Email invalid"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=add');
             }
             if ($sUserName == '') {
                 osc_add_flash_message(_m("Username invalid"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=add');
             }
             if ($sPassword == '') {
                 osc_add_flash_message(_m("Password invalid"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=add');
             }
             $admin = $this->adminManager->findByEmail($sEmail);
             if ($admin) {
                 osc_add_flash_message(_m("Email already in use"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=add');
             }
             $admin = $this->adminManager->findByUsername($sUserName);
             if ($admin) {
                 osc_add_flash_message(_m("Username already in use"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=add');
             }
             $array = array('s_password' => sha1($sPassword), 's_name' => $sName, 's_email' => $sEmail, 's_username' => $sUserName);
             $isInserted = $this->adminManager->insert($array);
             if ($isInserted) {
                 osc_add_flash_message(_m('The admin has been added'), 'admin');
             } else {
                 osc_add_flash_message(_m('There have been an error adding a new admin'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             break;
         case 'edit':
             // calling edit admin view
             $adminEdit = null;
             $adminId = Params::getParam('id');
             if (Params::getParam('id') != '') {
                 $adminEdit = $this->adminManager->findByPrimaryKey((int) $adminId);
             } elseif (Session::newInstance()->_get('adminId') != '') {
                 $adminEdit = $this->adminManager->findByPrimaryKey(Session::newInstance()->_get('adminId'));
             }
             if (count($adminEdit) == 0) {
                 osc_add_flash_message(_m('There is no admin admin with this id'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             }
             $this->_exportVariableToView("admin", $adminEdit);
             $this->doView('admins/edit.php');
             break;
         case 'edit_post':
             // updating a new admin
             $iUpdated = 0;
             $adminId = Params::getParam('id');
             $sPassword = Params::getParam('s_password');
             $sPassword2 = Params::getParam('s_password2');
             $sOldPassword = Params::getParam('old_password');
             $sName = Params::getParam('s_name');
             $sEmail = Params::getParam('s_email');
             $sUserName = Params::getParam('s_username');
             // cleaning parameters
             $sPassword = strip_tags($sPassword);
             $sPassword = trim($sPassword);
             $sPassword2 = strip_tags($sPassword2);
             $sPassword2 = trim($sPassword2);
             $sName = strip_tags($sName);
             $sName = trim($sName);
             $sEmail = strip_tags($sEmail);
             $sEmail = trim($sEmail);
             $sUserName = strip_tags($sUserName);
             $sUserName = trim($sUserName);
             // Checks for legit data
             if (!preg_match("/^[_a-z0-9-+]+(\\.[_a-z0-9-+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", $sEmail)) {
                 osc_add_flash_message(_m("Email invalid"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
             }
             if ($sUserName == '') {
                 osc_add_flash_message(_m("Username invalid"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
             }
             $aAdmin = $this->adminManager->findByPrimaryKey($adminId);
             if (count($aAdmin) == 0) {
                 osc_add_flash_message(_m('This admin doesn\'t exist'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             }
             if ($aAdmin['s_email'] != $sEmail) {
                 if ($this->adminManager->findByEmail($sEmail)) {
                     osc_add_flash_message(_m('Existing email'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
                 }
             }
             if ($aAdmin['s_username'] != $sUserName) {
                 if ($this->adminManager->findByUsername($sUserName)) {
                     osc_add_flash_message(_m('Existing username'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
                 }
             }
             $conditions = array('pk_i_id' => $adminId);
             $array = array();
             if ($sOldPassword != '') {
                 if ($sPassword == '') {
                     osc_add_flash_message(_m("Password invalid"), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
                 } else {
                     $firstCondition = sha1($sOldPassword) == $aAdmin['s_password'];
                     $secondCondition = $sPassword == $sPassword2;
                     if ($firstCondition && $secondCondition) {
                         $array['s_password'] = sha1($sPassword);
                     } else {
                         osc_add_flash_message(_m('The password couldn\'t be updated. Passwords don\'t match'), 'admin');
                         $this->redirectTo(osc_admin_base_url(true) . '?page=admins&action=edit&id=' . $adminId);
                     }
                 }
             }
             $array['s_name'] = Params::getParam('s_name');
             $array['s_username'] = $sUserName;
             $array['s_email'] = $sEmail;
             $iUpdated = $this->adminManager->update($array, $conditions);
             if ($iUpdated > 0) {
                 osc_add_flash_message(_m('The admin has been updated'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             break;
         case 'delete':
             // deleting and admin
             $isDeleted = false;
             $adminId = Params::getParam('id');
             if (!is_array($adminId)) {
                 osc_add_flash_message(_m('The admin id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             }
             // Verification to avoid an administrator trying to remove to itself
             if (in_array(Session::newInstance()->_get('adminId'), $adminId)) {
                 osc_add_flash_message(_m('The operation hasn\'t been completed. You\'re trying to remove yourself!'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             }
             $isDeleted = $this->adminManager->delete(array('pk_i_id IN (' . implode(', ', $adminId) . ')'));
             if ($isDeleted) {
                 osc_add_flash_message(_m('The admin has been deleted correctly'), 'admin');
             } else {
                 osc_add_flash_message(_m('The admin couldn\'t be deleted'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=admins');
             break;
         default:
             // calling manage admins view
             $admins = $this->adminManager->listAll();
             $this->_exportVariableToView("admins", $admins);
             $this->doView('admins/index.php');
             break;
     }
 }
예제 #17
0
 function doModel()
 {
     switch ($this->action) {
         case 'register':
             //register user
             $this->doView('user-register.php');
             break;
         case 'register_post':
             //register user
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(false);
             $success = $userActions->add();
             switch ($success) {
                 case 1:
                     osc_add_flash_message(_m('The user has been created. An activation email has been sent'));
                     $this->redirectTo(osc_base_url());
                     break;
                 case 2:
                     osc_add_flash_message(_m('Your account has been created successfully'));
                     $this->doView('user-login.php');
                     break;
                 case 3:
                     osc_add_flash_message(_m('The specified e-mail is already in use'));
                     $this->doView('user-register.php');
                     break;
                 case 4:
                     osc_add_flash_message(_m('The reCAPTCHA was not introduced correctly'));
                     $this->doView('user-register.php');
                     break;
             }
             break;
         case 'validate':
             //validate account
             $id = intval(Params::getParam('id'));
             $code = Params::getParam('code');
             $userManager = new User();
             $user = $userManager->findByIdSecret($id, $code);
             if ($user) {
                 if (!$user['b_enabled']) {
                     $userManager = new User();
                     $userManager->update(array('b_enabled' => '1'), array('pk_i_id' => $id, 's_secret' => $code));
                     $pageManager = new Page();
                     $locale = osc_current_user_locale();
                     $aPage = $pageManager->findByInternalName('email_user_registration');
                     $content = array();
                     if (isset($aPage['locale'][$locale]['s_title'])) {
                         $content = $aPage['locale'][$locale];
                     } else {
                         $content = current($aPage['locale']);
                     }
                     if (!is_null($content)) {
                         $words = array();
                         $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{WEB_TITLE}', '{WEB_URL}');
                         $words[] = array($user['s_name'], $user['s_email'], osc_page_title(), osc_base_url());
                         $title = osc_mailBeauty($content['s_title'], $words);
                         $body = osc_mailBeauty($content['s_text'], $words);
                         $emailParams = array('subject' => $title, 'to' => $user['s_email'], 'to_name' => $user['s_name'], 'body' => $body, 'alt_body' => $body);
                         osc_sendMail($emailParams);
                     }
                     osc_run_hook('validate_user', $user);
                     osc_add_flash_message(_m('Your account has been validated'));
                     // Auto-login
                     Session::newInstance()->_set('userId', $user['pk_i_id']);
                     Session::newInstance()->_set('userName', $user['s_name']);
                     Session::newInstance()->_set('userEmail', $user['s_email']);
                     $phone = $user['s_phone_mobile'] ? $user['s_phone_mobile'] : $user['s_phone_land'];
                     Session::newInstance()->_set('userPhone', $phone);
                 } else {
                     osc_add_flash_message(_m('Your account has already been activated'));
                 }
             } else {
                 osc_add_flash_message(_m('The link is not valid anymore. Sorry for the inconvenience!'));
             }
             $this->redirectTo(osc_base_url());
             break;
     }
 }
예제 #18
0
 function doModel()
 {
     switch ($this->action) {
         case 'login_post':
             //post execution for the login
             $admin = Admin::newInstance()->findByUsername(Params::getParam('user'));
             if ($admin) {
                 if ($admin["s_password"] == sha1(Params::getParam('password'))) {
                     if (Params::getParam('remember')) {
                         //this include contains de osc_genRandomPassword function
                         require_once osc_lib_path() . 'osclass/helpers/hSecurity.php';
                         $secret = osc_genRandomPassword();
                         Admin::newInstance()->update(array('s_secret' => $secret), array('pk_i_id' => $admin['pk_i_id']));
                         Cookie::newInstance()->set_expires(osc_time_cookie());
                         Cookie::newInstance()->push('oc_adminId', $admin['pk_i_id']);
                         Cookie::newInstance()->push('oc_adminSecret', $secret);
                         Cookie::newInstance()->push('oc_adminLocale', Params::getParam('locale'));
                         Cookie::newInstance()->set();
                     }
                     //we are logged in... let's go!
                     Session::newInstance()->_set('adminId', $admin['pk_i_id']);
                     Session::newInstance()->_set('adminUserName', $admin['s_username']);
                     Session::newInstance()->_set('adminName', $admin['s_name']);
                     Session::newInstance()->_set('adminEmail', $admin['s_email']);
                     Session::newInstance()->_set('adminLocale', Params::getParam('locale'));
                 } else {
                     osc_add_flash_message(_m('The password is incorrect'), 'admin');
                 }
             } else {
                 osc_add_flash_message(_m('That username does not exist'), 'admin');
             }
             //returning logged in to the main page...
             $this->redirectTo(osc_admin_base_url());
             break;
         case 'recover':
             //form to recover the password (in this case we have the form in /gui/)
             //#dev.conquer: we cannot use the doView here and only here
             $this->doView('gui/recover.php');
             break;
         case 'recover_post':
             //post execution to recover the password
             $admin = Admin::newInstance()->findByEmail(Params::getParam('email'));
             if ($admin) {
                 if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) {
                     if (!osc_check_recaptcha()) {
                         osc_add_flash_message(_m('The Recaptcha code is wrong'), 'admin');
                         $this->redirectTo(osc_admin_base_url(true) . '?page=login&action=recover');
                         return false;
                         // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                     }
                 }
                 require_once osc_lib_path() . 'osclass/helpers/hSecurity.php';
                 $newPassword = osc_genRandomPassword(40);
                 Admin::newInstance()->update(array('s_secret' => $newPassword), array('pk_i_id' => $admin['pk_i_id']));
                 $password_link = osc_forgot_admin_password_confirm_url($admin['pk_i_id'], $newPassword);
                 $aPage = Page::newInstance()->findByInternalName('email_user_forgot_password');
                 $content = array();
                 $locale = osc_current_user_locale();
                 if (isset($aPage['locale'][$locale]['s_title'])) {
                     $content = $aPage['locale'][$locale];
                 } else {
                     $content = current($aPage['locale']);
                 }
                 if (!is_null($content)) {
                     $words = array();
                     $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{WEB_TITLE}', '{IP_ADDRESS}', '{PASSWORD_LINK}', '{DATE_TIME}');
                     $words[] = array($admin['s_name'], $admin['s_email'], osc_page_title(), $_SERVER['REMOTE_ADDR'], $password_link, date(osc_time_format() . '  ' . osc_date_format()));
                     $title = osc_mailBeauty($content['s_title'], $words);
                     $body = osc_mailBeauty($content['s_text'], $words);
                     $emailParams = array('subject' => $title, 'to' => $admin['s_email'], 'to_name' => $admin['s_name'], 'body' => $body, 'alt_body' => $body);
                     osc_sendMail($emailParams);
                 }
             }
             osc_add_flash_message(_m('A new password has been sent to your e-mail'), 'admin');
             $this->redirectTo(osc_admin_base_url());
             break;
         case 'forgot':
             //form to recover the password (in this case we have the form in /gui/)
             $admin = Admin::newInstance()->findByIdSecret(Params::getParam('adminId'), Params::getParam('code'));
             if ($admin) {
                 $this->doView('gui/forgot_password.php');
             } else {
                 osc_add_flash_message(_m('Sorry, the link is not valid'), 'admin');
                 $this->redirectTo(osc_admin_base_url());
             }
             break;
         case 'forgot_post':
             $admin = Admin::newInstance()->findByIdSecret(Params::getParam('adminId'), Params::getParam('code'));
             if ($admin) {
                 if (Params::getParam('new_password') == Params::getParam('new_password2')) {
                     Admin::newInstance()->update(array('s_secret' => osc_genRandomPassword(), 's_password' => sha1(Params::getParam('new_password'))), array('pk_i_id' => $admin['pk_i_id']));
                     osc_add_flash_message(_m('The password has been changed'), 'admin');
                     $this->redirectTo(osc_admin_base_url());
                 } else {
                     osc_add_flash_message(_m('Error, the password don\'t match'), 'admin');
                     $this->redirectTo(osc_forgot_admin_password_confirm_url(Params::getParam('adminId'), Params::getParam('code')));
                 }
             } else {
                 osc_add_flash_message(_m('Sorry, the link is not valid'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url());
             break;
     }
 }
예제 #19
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'create':
             // callign create view
             $aCountries = array();
             $aRegions = array();
             $aCities = array();
             $aCountries = Country::newInstance()->listAll();
             if (isset($aCountries[0]['pk_c_code'])) {
                 $aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
             }
             if (isset($aRegions[0]['pk_i_id'])) {
                 $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
             }
             $this->_exportVariableToView("user", null);
             $this->_exportVariableToView("countries", $aCountries);
             $this->_exportVariableToView("regions", $aRegions);
             $this->_exportVariableToView("cities", $aCities);
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->doView("users/frm.php");
             break;
         case 'create_post':
             // creating the user...
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(true);
             $success = $userActions->add();
             switch ($success) {
                 case 1:
                     osc_add_flash_message(_m('The user has been created. We\'ve sent an activation e-mail'), 'admin');
                     break;
                 case 2:
                     osc_add_flash_message(_m('The user has been created and activated'), 'admin');
                     break;
                 case 3:
                     osc_add_flash_message(_m('Sorry, but that e-mail is already in use'), 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=users');
             break;
         case 'edit':
             // calling the edit view
             $aUser = array();
             $aCountries = array();
             $aRegions = array();
             $aCities = array();
             $aUser = $this->userManager->findByPrimaryKey(Params::getParam("id"));
             $aCountries = Country::newInstance()->listAll();
             $aRegions = array();
             if ($aUser['fk_c_country_code'] != '') {
                 $aRegions = Region::newInstance()->getByCountry($aUser['fk_c_country_code']);
             } else {
                 if (count($aCountries) > 0) {
                     $aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
                 }
             }
             $aCities = array();
             if ($aUser['fk_i_region_id'] != '') {
                 $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aUser['fk_i_region_id']);
             } else {
                 if (count($aRegions) > 0) {
                     $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
                 }
             }
             $this->_exportVariableToView("user", $aUser);
             $this->_exportVariableToView("countries", $aCountries);
             $this->_exportVariableToView("regions", $aRegions);
             $this->_exportVariableToView("cities", $aCities);
             $this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
             $this->doView("users/frm.php");
             break;
         case 'edit_post':
             // edit post
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(true);
             $success = $userActions->edit(Params::getParam("id"));
             switch ($success) {
                 case 1:
                     osc_add_flash_message(_m('Passwords don\'t match'), 'admin');
                     break;
                 case 2:
                     osc_add_flash_message(_m('The user has been updated and activated'), 'admin');
                     break;
                 default:
                     osc_add_flash_message(_m('The user has been updated'), 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=users');
             break;
         case 'activate':
             //activate
             $iUpdated = 0;
             $userId = Params::getParam('id');
             if (!is_array($userId)) {
                 osc_add_flash_message(_m('User id isn\'t in the correct format'), 'admin');
             }
             foreach ($userId as $id) {
                 $conditions = array('pk_i_id' => $id);
                 $values = array('b_enabled' => 1);
                 $iUpdated += $this->userManager->update($values, $conditions);
             }
             switch ($iUpdated) {
                 case 0:
                     $msg = _m('No user has been activated');
                     break;
                 case 1:
                     $msg = _m('One user has been activated');
                     break;
                 default:
                     $msg = sprintf(_m('%s users have been activated'), $iUpdated);
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=users');
             break;
         case 'deactivate':
             //deactivate
             $iUpdated = 0;
             $userId = Params::getParam('id');
             if (!is_array($userId)) {
                 osc_add_flash_message(_m('User id isn\'t in the correct format'), 'admin');
             }
             foreach ($userId as $id) {
                 $conditions = array('pk_i_id' => $id);
                 $values = array('b_enabled' => 0);
                 $iUpdated += $this->userManager->update($values, $conditions);
             }
             switch ($iUpdated) {
                 case 0:
                     $msg = _m('No user has been deactivated');
                     break;
                 case 1:
                     $msg = _m('One user has been deactivated');
                     break;
                 default:
                     $msg = sprintf(_m('%s users have been deactivated'), $iUpdated);
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=users');
             break;
         case 'delete':
             //delete
             $iDeleted = 0;
             $userId = Params::getParam('id');
             if (!is_array($userId)) {
                 osc_add_flash_message(_m('User id isn\'t in the correct format'), 'admin');
             }
             foreach ($userId as $id) {
                 if ($this->userManager->deleteUser($id)) {
                     $iDeleted++;
                 }
             }
             switch ($iDeleted) {
                 case 0:
                     $msg = _m('No user has been deleted');
                     break;
                 case 1:
                     $msg = _m('One user has been deleted');
                     break;
                 default:
                     $msg = sprintf(_m('%s users have been deleted'), $iDeleted);
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=users');
             break;
         default:
             // manage users view
             $aUsers = $this->userManager->listAll();
             $this->_exportVariableToView("users", $aUsers);
             $this->doView("users/index.php");
             break;
     }
 }
예제 #20
0
 function doModel()
 {
     switch ($this->action) {
         case 'dashboard':
             //dashboard...
             $max_items = Params::getParam('max_items') != '' ? Params::getParam('max_items') : 5;
             $aItems = Item::newInstance()->findByUserID(Session::newInstance()->_get('userId'), 0, $max_items);
             //Item::newInstance()->listWhere("fk_i_user_id = ".Session::newInstance()->_get('userId'));
             //calling the view...
             $this->_exportVariableToView('items', $aItems);
             $this->_exportVariableToView('max_items', $max_items);
             $this->doView('user-dashboard.php');
             break;
         case 'profile':
             //profile...
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             $aCountries = Country::newInstance()->listAll();
             $aRegions = array();
             if ($user['fk_c_country_code'] != '') {
                 $aRegions = Region::newInstance()->getByCountry($user['fk_c_country_code']);
             } elseif (count($aCountries) > 0) {
                 $aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
             }
             $aCities = array();
             if ($user['fk_i_region_id'] != '') {
                 $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $user['fk_i_region_id']);
             } else {
                 if (count($aRegions) > 0) {
                     $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
                 }
             }
             //calling the view...
             $this->_exportVariableToView('countries', $aCountries);
             $this->_exportVariableToView('regions', $aRegions);
             $this->_exportVariableToView('cities', $aCities);
             $this->_exportVariableToView('user', $user);
             $this->doView('user-profile.php');
             break;
         case 'profile_post':
             //profile post...
             $userId = Session::newInstance()->_get('userId');
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(false);
             $success = $userActions->edit($userId);
             // This has been moved to special area (only password changes)
             /*if( $success == 1 ) {
                   osc_add_flash_message( _m('Passwords don\'t match') ) ;
               } else {*/
             osc_add_flash_message(_m('Your profile has been updated successfully'));
             //}
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'alerts':
             //alerts
             $aAlerts = Alerts::newInstance()->getAlertsFromUser(Session::newInstance()->_get('userId'));
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             foreach ($aAlerts as $k => $a) {
                 $search = osc_unserialize(base64_decode($a['s_search']));
                 $search->limit(0, 3);
                 $aAlerts[$k]['items'] = $search->doSearch();
             }
             $this->_exportVariableToView('alerts', $aAlerts);
             View::newInstance()->_reset('alerts');
             $this->_exportVariableToView('user', $user);
             $this->doView('user-alerts.php');
             break;
         case 'change_email':
             //change email
             $this->doView('user-change_email.php');
             break;
         case 'change_email_post':
             //change email post
             if (!preg_match("/^[_a-z0-9-\\+]+(\\.[_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", Params::getParam('new_email'))) {
                 osc_add_flash_message(_m('The specified e-mail is not valid'));
                 $this->redirectTo(osc_change_user_email_url());
             } else {
                 $user = User::newInstance()->findByEmail(Params::getParam('new_email'));
                 if (!isset($user['pk_i_id'])) {
                     if (osc_user_validation_enabled()) {
                         $userEmailTmp = array();
                         $userEmailTmp['fk_i_user_id'] = Session::newInstance()->_get('userId');
                         $userEmailTmp['s_new_email'] = Params::getParam('new_email');
                         UserEmailTmp::newInstance()->insertOrUpdate($userEmailTmp);
                         $code = osc_genRandomPassword(30);
                         $date = date('Y-m-d H:i:s');
                         $userManager = new User();
                         $userManager->update(array('s_pass_code' => $code, 's_pass_date' => $date, 's_pass_ip' => $_SERVER['REMOTE_ADDR']), array('pk_i_id' => Session::newInstance()->_get('userId')));
                         $locale = osc_current_user_locale();
                         $aPage = Page::newInstance()->findByInternalName('email_new_email');
                         if (isset($aPage['locale'][$locale]['s_title'])) {
                             $content = $aPage['locale'][$locale];
                         } else {
                             $content = current($aPage['locale']);
                         }
                         if (!is_null($content)) {
                             $validation_url = osc_change_user_email_confirm_url(Session::newInstance()->_get('userId'), $code);
                             $words = array();
                             $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}');
                             $words[] = array(Session::newInstance()->_get('userName'), Params::getParam('new_email'), osc_base_url(), osc_page_title(), '<a href="' . $validation_url . '" >' . $validation_url . '</a>', $validation_url);
                             $title = osc_mailBeauty($content['s_title'], $words);
                             $body = osc_mailBeauty($content['s_text'], $words);
                             $params = array('subject' => $title, 'to' => Params::getParam('new_email'), 'to_name' => Session::newInstance()->_get('userName'), 'body' => $body, 'alt_body' => $body);
                             osc_sendMail($params);
                             osc_add_flash_message(_m('We have sent you an e-mail. Follow the instructions to validate the changes'));
                         } else {
                             osc_add_flash_message(_m('We tried to sent you an e-mail, but it failed. Please, contact the administrator'));
                         }
                         $this->redirectTo(osc_user_profile_url());
                     } else {
                         User::newInstance()->update(array('s_email' => Params::getParam('new_email')), array('pk_i_id' => Params::getParam('userId')));
                         osc_add_flash_message(_m('Your email has been changed successfully'));
                         $this->redirectTo(osc_user_profile_url());
                     }
                 } else {
                     osc_add_flash_message(_m('The specified e-mail is already in use'));
                     $this->redirectTo(osc_change_user_email_url());
                 }
             }
             break;
         case 'change_password':
             //change password
             $this->doView('user-change_password.php');
             break;
         case 'change_password_post':
             //change password post
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             if ($user['s_password'] != sha1(Params::getParam('password'))) {
                 osc_add_flash_message(_m('Current password doesn\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             } elseif (!Params::getParam('new_password')) {
                 osc_add_flash_message(_m('Passwords can\'t be empty'));
                 $this->redirectTo(osc_change_user_password_url());
             } elseif (Params::getParam('new_password') != Params::getParam('new_password2')) {
                 osc_add_flash_message(_m('Passwords don\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             User::newInstance()->update(array('s_password' => sha1(Params::getParam('new_password'))), array('pk_i_id' => Session::newInstance()->_get('userId')));
             osc_add_flash_message(_m('Password has been changed'));
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'items':
             // view items user
             $itemsPerPage = Params::getParam('itemsPerPage') != '' ? Params::getParam('itemsPerPage') : 5;
             $page = Params::getParam('iPage') != '' ? Params::getParam('iPage') : 0;
             $total_items = Item::newInstance()->countByUserID($_SESSION['userId']);
             $total_pages = ceil($total_items / $itemsPerPage);
             $items = Item::newInstance()->findByUserID($_SESSION['userId'], $page * $itemsPerPage, $itemsPerPage);
             $this->_exportVariableToView('items', $items);
             $this->_exportVariableToView('list_total_pages', $total_pages);
             $this->_exportVariableToView('list_total_items', $total_items);
             $this->_exportVariableToView('items_per_page', $itemsPerPage);
             $this->_exportVariableToView('list_page', $page);
             $this->doView('user-items.php');
             break;
         case 'unsub_alert':
             $email = Params::getParam('email');
             $alert = Params::getParam('alert');
             if ($email != '' && $alert != '') {
                 Alerts::newInstance()->delete(array('s_email' => $email, 's_search' => $alert));
                 osc_add_flash_message(__('Unsubscribed correctly.'));
             } else {
                 osc_add_flash_message(__('Ops! There was a problem trying to unsubscribe you. Please contact the administrator.'));
             }
             $this->redirectTo(osc_user_alerts_url());
             break;
     }
 }
예제 #21
0
function checkHoneyPot()
{
    if (Params::getParam('website') != "") {
        $return_url = Params::getParam('return_url');
        osc_add_flash_message("Theres seems to be trouble adding comment.");
        header('Location:' . htmlspecialchars_decode($return_url));
        break;
    }
}
예제 #22
0
 private function checkAllowedExt($aResources)
 {
     $success = true;
     require LIB_PATH . 'osclass/classes/mimes.php';
     if ($aResources != '') {
         // get allowedExt
         $aMimesAllowed = array();
         $aExt = explode(',', osc_allowed_extension());
         foreach ($aExt as $ext) {
             $mime = $mimes[$ext];
             if (is_array($mime)) {
                 foreach ($mime as $aux) {
                     if (!in_array($aux, $aMimesAllowed)) {
                         array_push($aMimesAllowed, $aux);
                     }
                 }
             } else {
                 if (!in_array($mime, $aMimesAllowed)) {
                     array_push($aMimesAllowed, $mime);
                 }
             }
         }
         foreach ($aResources['error'] as $key => $error) {
             $bool_img = false;
             if ($error == UPLOAD_ERR_OK) {
                 // check mime file
                 $fileMime = $aResources['type'][$key];
                 if (in_array($fileMime, $aMimesAllowed)) {
                     $bool_img = true;
                 }
                 if (!$bool_img && $success) {
                     $success = false;
                 }
             }
         }
         if (!$success) {
             osc_add_flash_message(_m("The file you tried to upload does not have an allowed extension"));
         }
     }
     return $success;
 }
예제 #23
0
/**
 * VERY BASIC
 * Perform a POST request, so we could launch fake-cron calls and other core-system calls without annoying the user
 */
function osc_doRequest($url, $_data)
{
    if (function_exists('fputs')) {
        // convert variables array to string:
        $data = array();
        while (list($n, $v) = each($_data)) {
            $data[] = "{$n}={$v}";
        }
        $data = implode('&', $data);
        // format --> test1=a&test2=b etc.
        // parse the given URL
        $url = parse_url($url);
        if ($url['scheme'] != 'http') {
            //die('Only HTTP request are supported !');
        }
        // extract host and path:
        $host = $url['host'];
        $path = $url['path'];
        // open a socket connection on port 80
        $fp = @fsockopen($host, 80);
        if ($fp !== false) {
            // send the request headers:
            fputs($fp, "POST {$path} HTTP/1.1\r\n");
            fputs($fp, "Host: {$host}\r\n");
            fputs($fp, "Referer: OSClass\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: " . strlen($data) . "\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $data);
            // close the socket connection:
            fclose($fp);
        } else {
            osc_add_flash_message(_m('Error, auto-cron is not working propertly'), 'admin');
        }
    }
}
예제 #24
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'bulk_actions':
             $id = Params::getParam('id');
             if ($id) {
                 switch (Params::getParam('bulk_actions')) {
                     case 'delete_all':
                         $this->itemCommentManager->delete(array(DB_CUSTOM_COND => 'pk_i_id IN (' . implode(', ', $id) . ')'));
                         osc_add_flash_message(_m('The comments have been deleted'), 'admin');
                         break;
                     case 'activate_all':
                         $value = 'ACTIVE';
                         foreach ($id as $_id) {
                             $this->itemCommentManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                         }
                         osc_add_flash_message(_m('The comments have been approved'), 'admin');
                         break;
                     case 'deactivate_all':
                         $value = 'INACTIVE';
                         foreach ($id as $_id) {
                             $this->itemCommentManager->update(array('e_status' => $value), array('pk_i_id' => $_id));
                         }
                         osc_add_flash_message(_m('The comments have been disapproved'), 'admin');
                         break;
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=comments");
             break;
         case 'status':
             $id = Params::getParam('id');
             $value = Params::getParam('value');
             if (!$id) {
                 return false;
             }
             $id = (int) $id;
             if (!is_numeric($id)) {
                 return false;
             }
             if (!in_array($value, array('ACTIVE', 'INACTIVE'))) {
                 return false;
             }
             $this->itemCommentManager->update(array('e_status' => $value), array('pk_i_id' => $id));
             if ($value == 'ACTIVE') {
                 osc_add_flash_message(_m('The comment has been approved'), 'admin');
             } else {
                 osc_add_flash_message(_m('The comment has been disapproved'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=comments");
             break;
         case 'comment_edit':
             $id = Params::getParam('id');
             $comment = ItemComment::newInstance()->findByPrimaryKey($id);
             $this->_exportVariableToView('comment', $comment);
             $this->doView('comments/frm.php');
             break;
         case 'comment_edit_post':
             $this->itemCommentManager->update(array('s_title' => Params::getParam('s_title'), 's_body' => Params::getParam('s_body'), 's_author_name' => Params::getParam('s_author_name'), 's_author_email' => Params::getParam('s_author_email')), array('pk_i_id' => Params::getParam('id')));
             osc_run_hook('item_edit_post');
             osc_add_flash_message(_m('Great! We just updated your comment'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=comments");
             break;
         case 'delete':
             $this->itemCommentManager->deleteByPrimaryKey(Params::getParam('id'));
             osc_add_flash_message(_m('The comment have been deleted'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=comments");
             break;
         default:
             if (Params::getParam('id') != '') {
                 $comments = $this->itemCommentManager->getAllComments(Params::getParam('id'));
             } else {
                 $comments = $this->itemCommentManager->getAllComments();
             }
             $this->_exportVariableToView('comments', $comments);
             //calling the view...
             $this->doView('comments/index.php');
     }
 }