function __construct() { parent::__construct(); // check if is moderator and can enter to this page if ($this->isModerator()) { if (!in_array($this->page, osc_apply_filter('moderator_access', array('items', 'comments', 'media', 'login', 'admins', 'ajax', 'stats', '')))) { osc_add_flash_error_message(_m("You don't have enough permissions"), 'admin'); $this->redirectTo(osc_admin_base_url()); } } osc_run_hook('init_admin'); $config_version = str_replace('.', '', OSCLASS_VERSION); $config_version = preg_replace('|-.*|', '', $config_version); if ($config_version > osc_get_preference('version')) { if (get_class($this) == 'CAdminTools') { } else { if (get_class($this) != 'CAdminUpgrade') { $this->redirectTo(osc_admin_base_url(true) . '?page=upgrade'); } } } // show donation successful if (Params::getParam('donation') == 'successful') { osc_add_flash_ok_message(_m('Thank you very much for your donation'), 'admin'); } // enqueue scripts osc_enqueue_script('jquery'); osc_enqueue_script('jquery-ui'); osc_enqueue_script('admin-osc'); osc_enqueue_script('admin-ui-osc'); }
function doModel() { parent::doModel(); //specific things for this class switch ($this->action) { case 'add_post': if (Params::getParam('field_name') != '') { $field = $this->fieldManager->findByName(Params::getParam('field_name')); if (!isset($field['pk_i_id'])) { $slug = preg_replace('|([-]+)|', '-', preg_replace('|[^a-z0-9_-]|', '-', strtolower(Params::getParam("field_slug")))); $this->fieldManager->insertField(Params::getParam("field_name"), Params::getParam("field_type_new"), $slug, Params::getParam("field_required") == "1" ? 1 : 0, Params::getParam('field_options'), Params::getParam('categories')); osc_add_flash_ok_message(_m("New custom field added"), "admin"); } else { osc_add_flash_error_message(_m("Sorry, you already have one field with that name"), "admin"); } } else { osc_add_flash_error_message(_m("Name can not be empty"), "admin"); } $this->redirectTo(osc_admin_base_url(true) . "?page=cfields"); break; default: $categories = Category::newInstance()->toTreeAll(); $selected = array(); foreach ($categories as $c) { $selected[] = $c['pk_i_id']; foreach ($c['categories'] as $cc) { $selected[] = $cc['pk_i_id']; } } $this->_exportVariableToView("categories", $categories); $this->_exportVariableToView("default_selected", $selected); $this->_exportVariableToView("fields", $this->fieldManager->listAll()); $this->doView("fields/index.php"); } }
function doModel() { switch ($this->action) { case 'latestsearches': //calling the comments settings view $this->doView('settings/searches.php'); break; case 'latestsearches_post': // updating comment osc_csrf_check(); if (Params::getParam('save_latest_searches') == 'on') { osc_set_preference('save_latest_searches', 1); } else { osc_set_preference('save_latest_searches', 0); } if (Params::getParam('customPurge') == '') { osc_add_flash_error_message(_m('Custom number could not be left empty'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=latestsearches'); } else { osc_set_preference('purge_latest_searches', Params::getParam('customPurge')); osc_add_flash_ok_message(_m('Last search settings have been updated'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=latestsearches'); } break; } }
function adimporter_readxml($file) { $xml = new DOMDocument(); $xml->load($file); $listings = $xml->getElementsByTagName('listing'); $cat_info = array(); $meta_info = array(); $errormsg = ''; foreach ($listings as $klisting => $listing) { list($success, $cat_info, $meta_info) = adimporter_ad($listing, $cat_info, $meta_info); if ($success != 2) { //2 is the success code for active ads & 1 for inactive $errormsg .= sprintf(__("%s (Item %d)", "adimporter"), $success, $klisting) . "<br/>"; } $delete_images = glob(osc_content_path() . "downloads/adimporterimage_*"); foreach ($delete_images as $img) { @unlink($img); } } if ($errormsg != '') { osc_add_flash_error_message($errormsg, 'admin'); } else { osc_add_flash_ok_message(__('All ads were imported correctly', 'adimporter'), 'admin'); } }
function theme_classified_actions_admin() { switch (Params::getParam('action_specific')) { case 'upload_logo': $package = Params::getFiles('logo'); if ($package['error'] == UPLOAD_ERR_OK) { if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) { osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'classified'), 'admin'); } else { osc_add_flash_error_message(__("An error has occurred, please try again", 'classified'), 'admin'); } } else { osc_add_flash_error_message(__("An error has occurred, please try again", 'classified'), 'admin'); } header('Location: ' . osc_admin_render_theme_url('oc-content/themes/classified/admin/header.php')); exit; break; case 'remove': if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) { @unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg"); osc_add_flash_ok_message(__('The logo image has been removed', 'classified'), 'admin'); } else { osc_add_flash_error_message(__("Image not found", 'classified'), 'admin'); } header('Location: ' . osc_admin_render_theme_url('oc-content/themes/classified/admin/header.php')); exit; break; } }
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') && $user['b_enabled'] == 1) { $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_ok_message(_m('Your email has been changed successfully')); $this->redirectTo(osc_user_profile_url()); } else { osc_add_flash_error_message(_m('Sorry, the link is not valid')); $this->redirectTo(osc_base_url()); } } else { osc_add_flash_error_message(_m('Sorry, the link is not valid')); $this->redirectTo(osc_base_url()); } break; case 'activate_alert': $email = Params::getParam('email'); $secret = Params::getParam('secret'); $result = 0; if ($email != '' && $secret != '') { $result = Alerts::newInstance()->activate($email, $secret); } if ($result == 1) { osc_add_flash_ok_message(_m('Alert activated')); } else { osc_add_flash_error_message(_m('Ops! There was a problem trying to activate alert. Please contact the administrator')); } $this->redirectTo(osc_base_url(true)); break; case 'unsub_alert': $email = Params::getParam('email'); $secret = Params::getParam('secret'); if ($email != '' && $secret != '') { Alerts::newInstance()->delete(array('s_email' => $email, 'S_secret' => $secret)); osc_add_flash_ok_message(_m('Unsubscribed correctly')); } else { osc_add_flash_error_message(_m('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; } }
function __construct() { parent::__construct(); // check if is moderator and can enter to this page if ($this->isModerator()) { if (!in_array($this->page, array('items', 'comments', 'media', 'login', 'admins', 'ajax', 'stats', ''))) { osc_add_flash_error_message(_m("You don't have enough permissions"), 'admin'); $this->redirectTo(osc_admin_base_url()); } } osc_run_hook('init_admin'); // check if exist a new version each day if (time() - osc_last_version_check() > 24 * 3600) { $data = osc_file_get_contents('http://osclass.org/latest_version.php?callback=?'); $data = preg_replace('|^\\?\\((.*?)\\);$|', '$01', $data); $json = json_decode($data); if ($json->version > osc_version()) { osc_set_preference('update_core_json', $data); } else { osc_set_preference('update_core_json', ''); } osc_set_preference('last_version_check', time()); osc_reset_preferences(); } $config_version = str_replace('.', '', OSCLASS_VERSION); $config_version = preg_replace('|-.*|', '', $config_version); if ($config_version > Preference::newInstance()->get('version')) { if (get_class($this) == 'CAdminTools') { } else { if (get_class($this) != 'CAdminUpgrade') { $this->redirectTo(osc_admin_base_url(true) . '?page=upgrade'); } } } // show messages subscribed $status_subscribe = Params::getParam('subscribe_osclass'); if ($status_subscribe != '') { switch ($status_subscribe) { case -1: osc_add_flash_error_message(_m('Entered an invalid email'), 'admin'); break; case 0: osc_add_flash_warning_message(_m("You're already subscribed"), 'admin'); break; case 1: osc_add_flash_ok_message(_m('Subscribed correctly'), 'admin'); break; default: osc_add_flash_warning_message(_m("Error subscribing"), 'admin'); break; } } // show donation successful if (Params::getParam('donation') == 'successful') { osc_add_flash_ok_message(_m('Thank you very much for your donation'), 'admin'); } }
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_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm("yourName", $yourName); Session::newInstance()->_setForm("yourEmail", $yourEmail); Session::newInstance()->_setForm("subject", $subject); Session::newInstance()->_setForm("message_body", $message); $this->redirectTo(osc_contact_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) { osc_add_flash_error_message(_m('Please enter a correct email')); Session::newInstance()->_setForm("yourName", $yourName); Session::newInstance()->_setForm("subject", $subject); Session::newInstance()->_setForm("message_body", $message); $this->redirectTo(osc_contact_url()); } $message = sprintf(__("%s (%s) left this message : %s"), $yourName, $yourEmail, $message); $params = array('reply_to' => $yourEmail, '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_error_message(_m('There have been some errors sending the message')); $this->redirectTo(osc_contact_url()); } if (!move_uploaded_file($tmpName, $path)) { unset($path); } } if (isset($path)) { $params['attachment'] = $path; } osc_sendMail($params); osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!')); $this->redirectTo(osc_contact_url()); break; default: //contact $this->doView('contact.php'); } }
/** * Re-send the flash messages of the given section. Usefull for custom theme/plugins files. * * @param string $$section */ function osc_resend_flash_messages($section = "pubMessages") { $message = Session::newInstance()->_getMessage($section); if ($message["type"] == "info") { osc_add_flash_info_message($message['msg'], $section); } else { if ($message["type"] == "ok") { osc_add_flash_ok_message($message['msg'], $section); } else { osc_add_flash_error_message($message['msg'], $section); } } }
function doModel() { switch ($this->action) { case 'comments': //calling the comments settings view $this->doView('settings/comments.php'); break; case 'comments_post': // updating comment osc_csrf_check(); $iUpdated = 0; $enabledComments = Params::getParam('enabled_comments'); $enabledComments = $enabledComments != '' ? true : false; $moderateComments = Params::getParam('moderate_comments'); $moderateComments = $moderateComments != '' ? true : false; $numModerateComments = Params::getParam('num_moderate_comments'); $commentsPerPage = Params::getParam('comments_per_page'); $notifyNewComment = Params::getParam('notify_new_comment'); $notifyNewComment = $notifyNewComment != '' ? true : false; $notifyNewCommentUser = Params::getParam('notify_new_comment_user'); $notifyNewCommentUser = $notifyNewCommentUser != '' ? true : false; $regUserPostComments = Params::getParam('reg_user_post_comments'); $regUserPostComments = $regUserPostComments != '' ? true : false; $msg = ''; if (!osc_validate_int(Params::getParam("num_moderate_comments"))) { $msg .= _m("Number of moderate comments must only contain numeric characters") . "<br/>"; } if (!osc_validate_int(Params::getParam("comments_per_page"))) { $msg .= _m("Comments per page must only contain numeric characters") . "<br/>"; } if ($msg != '') { osc_add_flash_error_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments'); } $iUpdated += osc_set_preference('enabled_comments', $enabledComments); if ($moderateComments) { $iUpdated += osc_set_preference('moderate_comments', $numModerateComments); } else { $iUpdated += osc_set_preference('moderate_comments', '-1'); } $iUpdated += osc_set_preference('notify_new_comment', $notifyNewComment); $iUpdated += osc_set_preference('notify_new_comment_user', $notifyNewCommentUser); $iUpdated += osc_set_preference('comments_per_page', $commentsPerPage); $iUpdated += osc_set_preference('reg_user_post_comments', $regUserPostComments); if ($iUpdated > 0) { osc_add_flash_ok_message(_m("Comment settings have been updated"), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments'); break; } }
function __construct() { parent::__construct(); // check if is moderator and can enter to this page if( $this->isModerator() ) { if( !in_array($this->page, osc_apply_filter('moderator_access', array('items', 'comments', 'media', 'login', 'admins', 'ajax', 'stats',''))) ) { osc_add_flash_error_message(_m("You don't have enough permissions"), 'admin'); $this->redirectTo(osc_admin_base_url()); } } osc_run_hook( 'init_admin' ); // check if exist a new version each day if( (time() - osc_last_version_check()) > (24 * 3600) ) { $data = osc_file_get_contents('http://osclass.org/latest_version_v1.php?callback=?'); $data = preg_replace('|^\?\((.*?)\);$|', '$01', $data); $json = json_decode($data); if( $json->version > osc_version() ) { osc_set_preference( 'update_core_json', $data ); } else { osc_set_preference( 'update_core_json', '' ); } osc_set_preference( 'last_version_check', time() ); osc_reset_preferences(); } $config_version = str_replace('.', '', OSCLASS_VERSION); $config_version = preg_replace('|-.*|', '', $config_version); if( $config_version > osc_get_preference('version') ) { if(get_class($this) == 'CAdminTools') { } else { if(get_class($this) != 'CAdminUpgrade' ) $this->redirectTo(osc_admin_base_url(true) . '?page=upgrade'); } } // show donation successful if( Params::getParam('donation') == 'successful' ) { osc_add_flash_ok_message(_m('Thank you very much for your donation'), 'admin'); } // enqueue scripts osc_enqueue_script('jquery'); osc_enqueue_script('jquery-ui'); osc_enqueue_script('admin-osc'); osc_enqueue_script('admin-ui-osc'); }
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('', false); $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_ok_message(_m('The email/alert has been updated'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=emails"); } osc_add_flash_error_message(_m('You can\'t repeat internal name'), 'admin'); } else { osc_add_flash_error_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"); } }
function doModel() { switch ($this->action) { case 'mailserver': // calling the mailserver view $this->doView('settings/mailserver.php'); break; case 'mailserver_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=mailserver'); } osc_csrf_check(); // updating mailserver $iUpdated = 0; $mailserverAuth = Params::getParam('mailserver_auth'); $mailserverAuth = $mailserverAuth != '' ? true : false; $mailserverPop = Params::getParam('mailserver_pop'); $mailserverPop = $mailserverPop != '' ? true : false; $mailserverType = Params::getParam('mailserver_type'); $mailserverHost = Params::getParam('mailserver_host'); $mailserverPort = Params::getParam('mailserver_port'); $mailserverUsername = Params::getParam('mailserver_username'); $mailserverPassword = Params::getParam('mailserver_password', false, false); $mailserverSsl = Params::getParam('mailserver_ssl'); $mailserverMailFrom = Params::getParam('mailserver_mail_from'); $mailserverNameFrom = Params::getParam('mailserver_name_from'); if (!in_array($mailserverType, array('custom', 'gmail'))) { osc_add_flash_error_message(_m('Mail server type is incorrect'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=mailserver'); } $iUpdated += osc_set_preference('mailserver_auth', $mailserverAuth); $iUpdated += osc_set_preference('mailserver_pop', $mailserverPop); $iUpdated += osc_set_preference('mailserver_type', $mailserverType); $iUpdated += osc_set_preference('mailserver_host', $mailserverHost); $iUpdated += osc_set_preference('mailserver_port', $mailserverPort); $iUpdated += osc_set_preference('mailserver_username', $mailserverUsername); $iUpdated += osc_set_preference('mailserver_password', $mailserverPassword); $iUpdated += osc_set_preference('mailserver_ssl', $mailserverSsl); $iUpdated += osc_set_preference('mailserver_mail_from', $mailserverMailFrom); $iUpdated += osc_set_preference('mailserver_name_from', $mailserverNameFrom); if ($iUpdated > 0) { osc_add_flash_ok_message(_m('Mail server configuration has changed'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=mailserver'); break; } }
function theme_modern_actions_admin() { if (Params::getParam('file') == 'oc-content/themes/modern/admin/settings.php') { if (Params::getParam('donation') == 'successful') { osc_set_preference('donation', '1', 'modern_theme'); osc_reset_preferences(); } } switch (Params::getParam('action_specific')) { case 'settings': $footerLink = Params::getParam('footer_link'); $defaultLogo = Params::getParam('default_logo'); osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'modern_theme'); osc_set_preference('footer_link', $footerLink ? '1' : '0', 'modern_theme'); osc_set_preference('default_logo', $defaultLogo ? '1' : '0', 'modern_theme'); osc_add_flash_ok_message(__('Theme settings updated correctly', 'modern'), 'admin'); header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/settings.php')); exit; break; case 'upload_logo': $package = Params::getFiles('logo'); if ($package['error'] == UPLOAD_ERR_OK) { if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) { osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'modern'), 'admin'); } else { osc_add_flash_error_message(__("An error has occurred, please try again", 'modern'), 'admin'); } } else { osc_add_flash_error_message(__("An error has occurred, please try again", 'modern'), 'admin'); } header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/header.php')); exit; break; case 'remove': if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) { @unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg"); osc_add_flash_ok_message(__('The logo image has been removed', 'modern'), 'admin'); } else { osc_add_flash_error_message(__("Image not found", 'modern'), 'admin'); } header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/header.php')); exit; break; } }
/** * Re-send the flash messages of the given section. Usefull for custom theme/plugins files. * * @param string $$section */ function osc_resend_flash_messages($section = "pubMessages") { $messages = Session::newInstance()->_getMessage($section); if (is_array($messages)) { foreach ($messages as $message) { $message = Session::newInstance()->_getMessage($section); if(isset($message['msg'])) { if(isset($message["type"]) && $message["type"]=="info") { osc_add_flash_info_message($message['msg'], $section); } else if(isset($message["type"]) && $message["type"]=="ok") { osc_add_flash_ok_message($message['msg'], $section); } else { osc_add_flash_error_message($message['msg'], $section); } } } } }
private function checkAllowedExt($aResources) { $success = true; require LIB_PATH . 'osclass/mimes.php'; if($aResources != '') { // get allowedExt $aMimesAllowed = array(); $aExt = explode(',', osc_allowed_extension() ); foreach($aExt as $ext){ if(isset($mimes[$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(stripos($fileMime, "image/")!==FALSE) { if(function_exists("getimagesize")) { $info = getimagesize($aResources['tmp_name'][$key]); if(isset($info['mime'])) { $fileMime = $info['mime']; } else { $fileMime = ''; } }; }; if(in_array($fileMime,$aMimesAllowed)) { $bool_img = true; } if(!$bool_img && $success) {$success = false;} } } if(!$success){ osc_add_flash_error_message( _m("The file you tried to upload does not have a valid extension")); } } return $success; }
function doModel() { //calling the view... $locales = OSCLocale::newInstance()->listAllEnabled(); $this->_exportVariableToView('locales', $locales); switch ($this->action) { case 'item_add': // post if (osc_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $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()->findByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->findByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->findByRegion($this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->findByRegion($regions[0]['pk_i_id']); } } $this->_exportVariableToView('countries', $countries); $this->_exportVariableToView('regions', $regions); $this->_exportVariableToView('cities', $cities); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } if (Session::newInstance()->_getForm('countryId') != "") { $countryId = Session::newInstance()->_getForm('countryId'); $regions = Region::newInstance()->findByCountry($countryId); $this->_exportVariableToView('regions', $regions); if (Session::newInstance()->_getForm('regionId') != "") { $regionId = Session::newInstance()->_getForm('regionId'); $cities = City::newInstance()->findByRegion($regionId); $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_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $this->redirectTo(osc_base_url(true)); } $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(true); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_post_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (!osc_is_web_user_logged_in()) { $user = User::newInstance()->findByEmail($mItems->data['contactEmail']); // The user exists but it's not logged if (isset($user['pk_i_id'])) { foreach ($mItems->data as $key => $value) { Session::newInstance()->_keepForm($key); } osc_add_flash_error_message(_m('A user with that email address already exists, if it is you, please log in')); $this->redirectTo(osc_user_login_url()); } } // POST ITEM ( ADD ITEM ) $success = $mItems->add(); if ($success != 1 && $success != 2) { osc_add_flash_error_message($success); $this->redirectTo(osc_item_post_url()); } else { Session::newInstance()->_dropkeepForm('meta_' . $key); if ($success == 1) { osc_add_flash_ok_message(_m('Check your inbox to validate your listing')); } else { osc_add_flash_ok_message(_m('Your listing has been published')); } $itemId = Params::getParam('itemId'); $item = $this->itemManager->findByPrimaryKey($itemId); osc_run_hook('posted_item', $item); $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId')); View::newInstance()->_exportVariableToView('category', $category); $this->redirectTo(osc_search_category_url()); } break; case 'item_edit': // edit item $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'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $item = Item::newInstance()->findByPrimaryKey($id); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } $this->_exportVariableToView('item', $item); osc_run_hook("before_item_edit", $item); $this->doView('item-edit.php'); } else { // add a flash message [ITEM NO EXISTE] osc_add_flash_error_message(_m("Sorry, we don't have any listings 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'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $this->_exportVariableToView('item', $item[0]); $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(false); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_edit_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $success = $mItems->edit(); osc_run_hook('edited_item', Item::newInstance()->findByPrimaryKey($id)); if ($success == 1) { osc_add_flash_ok_message(_m("Great! We've just updated your listing")); View::newInstance()->_exportVariableToView("item", Item::newInstance()->findByPrimaryKey($id)); $this->redirectTo(osc_item_url()); } else { osc_add_flash_error_message($success); $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') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); // item doesn't exist if (count($item) == 0) { $this->do404(); return; } View::newInstance()->_exportVariableToView('item', $item[0]); if ($item[0]['b_active'] == 0) { // ACTIVETE ITEM $mItems = new ItemActions(false); $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']); if ($success) { osc_add_flash_ok_message(_m('The listing has been validated')); } else { osc_add_flash_error_message(_m("The listing can't be validated")); } } else { osc_add_flash_warning_message(_m('The listing 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') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($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_ok_message(_m('Your listing has been deleted')); } else { osc_add_flash_error_message(_m("The listing 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_error_message(_m("The listing you are trying to delete couldn't be deleted")); $this->redirectTo(osc_base_url()); } break; case 'mark': $id = Params::getParam('id'); $as = Params::getParam('as'); $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { // mark item if it's not a bot $mItem = new ItemActions(false); $mItem->mark($id, $as); break; } } osc_add_flash_ok_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': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("friendName", Params::getParam('friendName')); Session::newInstance()->_setForm("friendEmail", Params::getParam('friendEmail')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_send_friend_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $mItem = new ItemActions(false); $success = $mItem->send_friend(); if ($success) { Session::newInstance()->_clearVariables(); $this->redirectTo(osc_item_url()); } else { $this->redirectTo(osc_item_send_friend_url()); } break; case 'contact': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); if (empty($item)) { osc_add_flash_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } else { $this->_exportVariableToView('item', $item); if (osc_item_is_expired()) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } if (osc_reg_user_can_contact() && osc_is_web_user_logged_in() || !osc_reg_user_can_contact()) { $this->doView('item-contact.php'); } else { osc_add_flash_error_message(_m("You can't contact the seller, only registered users can")); $this->redirectTo(osc_item_url()); } } 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_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("phoneNumber", Params::getParam('phoneNumber')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); $this->redirectTo(osc_item_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (osc_isExpired($item['dt_expiration'])) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } $mItem = new ItemActions(false); $result = $mItem->contact(); if (is_string($result)) { osc_add_flash_error_message($result); } else { osc_add_flash_ok_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'); osc_add_flash_error_message($msg); break; case 1: $msg = _m('Your comment is awaiting moderation'); osc_add_flash_info_message($msg); break; case 2: $msg = _m('Your comment has been approved'); osc_add_flash_ok_message($msg); break; case 3: $msg = _m('Please fill the required field (email)'); osc_add_flash_warning_message($msg); break; case 4: $msg = _m('Please type a comment'); osc_add_flash_warning_message($msg); break; case 5: $msg = _m('Your comment has been marked as spam'); osc_add_flash_error_message($msg); break; } $this->redirectTo(osc_item_url()); 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_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } View::newInstance()->_exportVariableToView('item', $item); if ($this->userId == null) { osc_add_flash_error_message(_m('You must be logged in to delete a comment')); $this->redirectTo(osc_item_url()); } $commentManager = ItemComment::newInstance(); $aComment = $commentManager->findByPrimaryKey($commentId); if (count($aComment) == 0) { osc_add_flash_error_message(_m("The comment doesn't exist")); $this->redirectTo(osc_item_url()); } if ($aComment['b_active'] != 1) { osc_add_flash_error_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_error_message(_m('The comment was not added by you, you cannot delete it')); $this->redirectTo(osc_item_url()); } $commentManager->deleteByPrimaryKey($commentId); osc_add_flash_ok_message(_m('The comment has been deleted')); $this->redirectTo(osc_item_url()); break; default: // if there isn't ID, show an error 404 if (Params::getParam('id') == '') { $this->do404(); return; } if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); // if item doesn't exist show an error 404 if (count($item) == 0) { $this->do404(); return; } if ($item['b_active'] != 1) { if ($this->userId == $item['fk_i_user_id']) { osc_add_flash_warning_message(_m("The listing hasn't been validated. Please validate it in order to make it public")); } else { osc_add_flash_warning_message(_m("This listing hasn't been validated")); $this->redirectTo(osc_base_url(true)); } } else { if ($item['b_enabled'] == 0) { osc_add_flash_warning_message(_m('The listing has been suspended')); $this->redirectTo(osc_base_url(true)); } } if (!osc_is_admin_user_logged_in()) { require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { $mStats = new ItemStats(); $mStats->increase('i_num_views', $item['pk_i_id']); break; } } } 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'])); } if ($item['fk_i_user_id'] != '') { $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']); $this->_exportVariableToView('user', $user); } $this->_exportVariableToView('item', $item); osc_run_hook('show_item', $item); // redirect to the correct url just in case it has changed $itemURI = str_replace(osc_base_url(), '', osc_item_url()); $URI = preg_replace('|^' . REL_WEB_URL . '|', '', $_SERVER['REQUEST_URI']); // do not clean QUERY_STRING if permalink is not enabled if (osc_rewrite_enabled()) { $URI = str_replace('?' . $_SERVER['QUERY_STRING'], '', $URI); } else { $params_keep = array('page', 'id'); $params = array(); foreach (Params::getParamsAsArray('get') as $k => $v) { if (in_array($k, $params_keep)) { $params[] = "{$k}={$v}"; } } $URI = 'index.php?' . implode('&', $params); } // redirect to the correct url if ($itemURI != $URI) { $this->redirectTo(osc_base_url() . $itemURI); } $this->doView('item.php'); break; } }
function doModel() { switch ($this->action) { case 'login_post': //post execution for the login if (!osc_users_enabled()) { osc_add_flash_error_message(_m('Users are not enabled')); $this->redirectTo(osc_base_url()); } require_once LIB_PATH . 'osclass/UserActions.php'; $user = User::newInstance()->findByEmail(Params::getParam('email')); $url_redirect = osc_user_dashboard_url(); $page_redirect = ''; if (osc_rewrite_enabled()) { if (isset($_SERVER['HTTP_REFERER'])) { $request_uri = urldecode(preg_replace('@^' . osc_base_url() . '@', "", $_SERVER['HTTP_REFERER'])); $tmp_ar = explode("?", $request_uri); $request_uri = $tmp_ar[0]; $rules = Rewrite::newInstance()->listRules(); foreach ($rules as $match => $uri) { if (preg_match('#' . $match . '#', $request_uri, $m)) { $request_uri = preg_replace('#' . $match . '#', $uri, $request_uri); if (preg_match('|([&?]{1})page=([^&]*)|', '&' . $request_uri . '&', $match)) { $page_redirect = $match[2]; } break; } } } } else { if (preg_match('|[\\?&]page=([^&]+)|', $_SERVER['HTTP_REFERER'] . '&', $match)) { $page_redirect = $match[1]; } } if (Params::getParam('http_referer') != '') { Session::newInstance()->_setReferer(Params::getParam('http_referer')); $url_redirect = Params::getParam('http_referer'); } else { if (Session::newInstance()->_getReferer() != '') { Session::newInstance()->_setReferer(Session::newInstance()->_getReferer()); $url_redirect = Session::newInstance()->_getReferer(); } else { if ($page_redirect != '' && $page_redirect != 'login') { Session::newInstance()->_setReferer($_SERVER['HTTP_REFERER']); $url_redirect = $_SERVER['HTTP_REFERER']; } } } if (!$user) { osc_add_flash_error_message(_m('The username doesn\'t exist')); $this->redirectTo(osc_user_login_url()); } if ($user["s_password"] != sha1(Params::getParam('password'))) { osc_add_flash_error_message(_m('The password is incorrect')); $this->redirectTo(osc_user_login_url()); } $uActions = new UserActions(false); $logged = $uActions->bootstrap_login($user['pk_i_id']); if ($logged == 0) { osc_add_flash_error_message(_m('The username doesn\'t exist')); } else { if ($logged == 1) { osc_add_flash_error_message(_m('The user has not been validated yet')); } else { if ($logged == 2) { osc_add_flash_error_message(_m('The user has been suspended')); } else { if ($logged == 3) { 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(); } $this->redirectTo($url_redirect); } else { osc_add_flash_error_message(_m('This should never happens')); } } } } if (!$user['b_enabled']) { $this->redirectTo(osc_user_login_url()); } $this->redirectTo(osc_user_login_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'; // e-mail is incorrect if (!preg_match('|^[a-z0-9\\.\\_\\+\\-]+@[a-z0-9\\.\\-]+\\.[a-z]{2,3}$|i', Params::getParam('s_email'))) { osc_add_flash_error_message(_m('Invalid email address')); $this->redirectTo(osc_recover_user_password_url()); } $userActions = new UserActions(false); $success = $userActions->recover_password(); switch ($success) { case 0: // recover ok osc_add_flash_ok_message(_m('We have sent you an email with the instructions to reset your password')); $this->redirectTo(osc_base_url()); break; case 1: // e-mail does not exist osc_add_flash_error_message(_m('We were not able to identify you given the information provided')); $this->redirectTo(osc_recover_user_password_url()); break; case 2: // recaptcha wrong osc_add_flash_error_message(_m('The recaptcha code is wrong')); $this->redirectTo(osc_recover_user_password_url()); break; } 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_error_message(_m('Sorry, the link is not valid')); $this->redirectTo(osc_base_url()); } break; case 'forgot_post': if (Params::getParam('new_password') == '' || Params::getParam('new_password2') == '') { osc_add_flash_warning_message(_m('Password cannot be blank')); $this->redirectTo(osc_forgot_user_password_confirm_url(Params::getParam('userId'), Params::getParam('code'))); } $user = User::newInstance()->findByIdPasswordSecret(Params::getParam('userId'), Params::getParam('code')); if ($user['b_enabled'] == 1) { 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_ok_message(_m('The password has been changed')); $this->redirectTo(osc_user_login_url()); } else { osc_add_flash_error_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_error_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'); } }
function doModel() { parent::doModel(); //specific things for this class switch ($this->action) { case 'bulk_actions': osc_csrf_check(); $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) . ')')); foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->delete(array('pk_i_id' => $_id)); osc_add_hook("delete_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been deleted'), 'admin'); break; case 'activate_all': foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->update(array('b_active' => 1), array('pk_i_id' => $_id)); if ($iUpdated) { $this->sendCommentActivated($_id); } osc_add_hook("activate_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been approved'), 'admin'); break; case 'deactivate_all': foreach ($id as $_id) { $this->itemCommentManager->update(array('b_active' => 0), array('pk_i_id' => $_id)); osc_add_hook("deactivate_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been disapproved'), 'admin'); break; case 'enable_all': foreach ($id as $_id) { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 1), array('pk_i_id' => $_id)); if ($iUpdated) { $this->sendCommentActivated($_id); } osc_add_hook("enable_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been unblocked'), 'admin'); break; case 'disable_all': foreach ($id as $_id) { $this->itemCommentManager->update(array('b_enabled' => 0), array('pk_i_id' => $_id)); osc_add_hook("disable_comment", $_id); } osc_add_flash_ok_message(_m('The comments have been blocked'), 'admin'); break; default: if (Params::getParam("bulk_actions") != "") { osc_run_hook("item_bulk_" . Params::getParam("bulk_actions"), Params::getParam('id')); } break; } } $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'status': osc_csrf_check(); $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', 'ENABLE', 'DISABLE'))) { return false; } if ($value == 'ACTIVE') { $iUpdated = $this->itemCommentManager->update(array('b_active' => 1), array('pk_i_id' => $id)); if ($iUpdated) { $this->sendCommentActivated($id); } osc_add_hook("activate_comment", $id); osc_add_flash_ok_message(_m('The comment has been approved'), 'admin'); } else { if ($value == 'INACTIVE') { $iUpdated = $this->itemCommentManager->update(array('b_active' => 0), array('pk_i_id' => $id)); osc_add_hook("deactivate_comment", $id); osc_add_flash_ok_message(_m('The comment has been disapproved'), 'admin'); } else { if ($value == 'ENABLE') { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 1), array('pk_i_id' => $id)); osc_add_hook("enable_comment", $id); osc_add_flash_ok_message(_m('The comment has been enabled'), 'admin'); } else { if ($value == 'DISABLE') { $iUpdated = $this->itemCommentManager->update(array('b_enabled' => 0), array('pk_i_id' => $id)); osc_add_hook("disable_comment", $id); osc_add_flash_ok_message(_m('The comment has been disabled'), 'admin'); } } } } $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'comment_edit': $comment = ItemComment::newInstance()->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('comment', $comment); $this->doView('comments/frm.php'); break; case 'comment_edit_post': osc_csrf_check(); $msg = ''; if (!osc_validate_email(Params::getParam('authorEmail'), true)) { $msg .= _m('Email is not correct') . "<br/>"; } if (!osc_validate_text(Params::getParam('body'), 1, true)) { $msg .= _m('Comment is required') . "<br/>"; } if ($msg != '') { osc_add_flash_error_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=comments&action=comment_edit&id=" . Params::getParam('id')); } $this->itemCommentManager->update(array('s_title' => Params::getParam('title'), 's_body' => Params::getParam('body'), 's_author_name' => Params::getParam('authorName'), 's_author_email' => Params::getParam('authorEmail')), array('pk_i_id' => Params::getParam('id'))); osc_run_hook('edit_comment', Params::getParam('id')); osc_add_flash_ok_message(_m('Great! We just updated your comment'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; case 'delete': osc_csrf_check(); $this->itemCommentManager->deleteByPrimaryKey(Params::getParam('id')); osc_add_flash_ok_message(_m('The comment has been deleted'), 'admin'); osc_run_hook('delete_comment', Params::getParam('id')); $this->redirectTo(osc_admin_base_url(true) . "?page=comments"); break; default: require_once osc_lib_path() . "osclass/classes/datatables/CommentsDataTable.php"; // set default iDisplayLength if (Params::getParam('iDisplayLength') != '') { Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength')); Cookie::newInstance()->set(); } else { // set a default value if it's set in the cookie if (Cookie::newInstance()->get_value('listing_iDisplayLength') != '') { Params::setParam('iDisplayLength', Cookie::newInstance()->get_value('listing_iDisplayLength')); } else { Params::setParam('iDisplayLength', 10); } } $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength')); // Table header order by related if (Params::getParam('sort') == '') { Params::setParam('sort', 'date'); } if (Params::getParam('direction') == '') { Params::setParam('direction', 'desc'); } $page = (int) Params::getParam('iPage'); if ($page == 0) { $page = 1; } Params::setParam('iPage', $page); $params = Params::getParamsAsArray(); $commentsDataTable = new CommentsDataTable(); $commentsDataTable->table($params); $aData = $commentsDataTable->getData(); if (count($aData['aRows']) == 0 && $page != 1) { $total = (int) $aData['iTotalDisplayRecords']; $maxPage = ceil($total / (int) $aData['iDisplayLength']); $url = osc_admin_base_url(true) . '?' . Params::getServerParam('QUERY_STRING', false, false); if ($maxPage == 0) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url); $this->redirectTo($url); } if ($page > 1) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url); $this->redirectTo($url); } } $this->_exportVariableToView('aData', $aData); $this->_exportVariableToView('aRawRows', $commentsDataTable->rawRows()); $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'delete_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Delete'))), 'label' => __('Delete')), array('value' => 'activate_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Activate'))), 'label' => __('Activate')), array('value' => 'deactivate_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Deactivate'))), 'label' => __('Deactivate')), array('value' => 'disable_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Block'))), 'label' => __('Block')), array('value' => 'enable_all', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected comments?'), strtolower(__('Unblock'))), 'label' => __('Unblock'))); $bulk_options = osc_apply_filter("comment_bulk_filter", $bulk_options); $this->_exportVariableToView('bulk_options', $bulk_options); $this->doView('comments/index.php'); break; } }
function doModel() { switch ($this->action) { case 'add': // caliing add view $this->doView('languages/add.php'); break; case 'add_post': // adding a new language if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } osc_csrf_check(); $filePackage = Params::getFiles('package'); if (isset($filePackage['size']) && $filePackage['size'] != 0) { $path = osc_translations_path(); (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path)); @unlink($filePackage['tmp_name']); } else { $status = 3; } switch ($status) { case 0: $msg = _m('The translation folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; case 1: if (osc_checkLocales()) { $msg = _m('The language has been installed correctly'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('There was a problem adding the language'); osc_add_flash_error_message($msg, 'admin'); } break; case 2: $msg = _m('The zip file is not valid'); osc_add_flash_error_message($msg, 'admin'); break; case 3: $msg = _m('No file was uploaded'); osc_add_flash_warning_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=languages&action=add"); break; case -1: default: $msg = _m('There was a problem adding the language'); osc_add_flash_error_message($msg, 'admin'); break; } $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_error_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_error_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 osc_csrf_check(); $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'); $languageDecPoint = Params::getParam('s_dec_point'); $languageNumDec = Params::getParam('i_num_dec'); $languageThousandsSep = Params::getParam('s_thousands_sep'); $languageDateFormat = Params::getParam('s_date_format'); $languageStopWords = Params::getParam('s_stop_words'); // formatting variables if (!preg_match('/.{2}_.{2}/', $languageCode)) { osc_add_flash_error_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); $languageShortName = strip_tags($languageShortName); $languageShortName = trim($languageShortName); $languageDescription = strip_tags($languageDescription); $languageDescription = trim($languageDescription); $languageCurrencyFormat = strip_tags($languageCurrencyFormat); $languageCurrencyFormat = trim($languageCurrencyFormat); $languageDateFormat = strip_tags($languageDateFormat); $languageDateFormat = trim($languageDateFormat); $languageStopWords = strip_tags($languageStopWords); $languageStopWords = trim($languageStopWords); $msg = ''; if (!osc_validate_text($languageName)) { $msg .= _m("Language name field is required") . "<br/>"; } if (!osc_validate_text($languageShortName)) { $msg .= _m("Language short name field is required") . "<br/>"; } if (!osc_validate_text($languageDescription)) { $msg .= _m("Language description field is required") . "<br/>"; } if (!osc_validate_text($languageCurrencyFormat)) { $msg .= _m("Currency format field is required") . "<br/>"; } if (!osc_validate_int($languageNumDec)) { $msg .= _m("Number of decimals must only contain numeric characters") . "<br/>"; } if ($msg != '') { osc_add_flash_error_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages&action=edit&id=' . $languageCode); } $array = array('b_enabled' => $enabledWebstie, 'b_enabled_bo' => $enabledBackoffice, 's_name' => $languageName, 's_short_name' => $languageShortName, 's_description' => $languageDescription, 's_currency_format' => $languageCurrencyFormat, 's_dec_point' => $languageDecPoint, 'i_num_dec' => $languageNumDec, 's_thousands_sep' => $languageThousandsSep, 's_date_format' => $languageDateFormat, 's_stop_words' => $languageStopWords); $iUpdated = $this->localeManager->update($array, array('pk_c_code' => $languageCode)); if ($iUpdated > 0) { osc_add_flash_ok_message(sprintf(_m('%s has been updated'), $languageShortName), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'enable_selected': osc_csrf_check(); $msg = _m('Selected languages have been enabled for the website'); $iUpdated = 0; $aValues = array('b_enabled' => 1); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { osc_translate_categories($i); $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($iUpdated > 0) { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'disable_selected': osc_csrf_check(); $msg = _m('Selected languages have been disabled for the website'); $msg_warning = ''; $iUpdated = 0; $aValues = array('b_enabled' => 0); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { if (osc_language() == $i) { $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language()); continue; } $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($msg_warning != '') { if ($iUpdated > 0) { osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin'); } else { osc_add_flash_warning_message($msg_warning, 'admin'); } } else { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'enable_bo_selected': osc_csrf_check(); $msg = _m('Selected languages have been enabled for the backoffice (oc-admin)'); $iUpdated = 0; $aValues = array('b_enabled_bo' => 1); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { osc_translate_categories($i); $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($iUpdated > 0) { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'disable_bo_selected': osc_csrf_check(); $msg = _m('Selected languages have been disabled for the backoffice (oc-admin)'); $msg_warning = ''; $iUpdated = 0; $aValues = array('b_enabled_bo' => 0); $id = Params::getParam('id'); if (!is_array($id)) { osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); } foreach ($id as $i) { if (osc_language() == $i) { $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language()); continue; } $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i)); } if ($msg_warning != '') { if ($iUpdated > 0) { osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin'); } else { osc_add_flash_warning_message($msg_warning, 'admin'); } } else { osc_add_flash_ok_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=languages'); break; case 'delete': osc_csrf_check(); if (is_array(Params::getParam('id'))) { $default_lang = osc_language(); foreach (Params::getParam('id') as $code) { if ($default_lang != $code) { if ($this->localeManager->deleteLocale($code)) { if (!osc_deleteDir(osc_translations_path() . $code)) { osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed"), $code), 'admin'); } else { osc_add_flash_ok_message(sprintf(_m('Directory "%s" has been successfully removed'), $code), 'admin'); } } else { osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed;)"), $code), 'admin'); } } else { osc_add_flash_error_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: if (Params::getParam('checkUpdated') != '') { osc_admin_toolbar_update_languages(true); } if (Params::getParam("action") != "") { osc_run_hook("language_bulk_" . Params::getParam("action"), Params::getParam('id')); } // ----- if (Params::getParam('iDisplayLength') == '') { Params::setParam('iDisplayLength', 10); } // ? $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength')); $p_iPage = 1; if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') >= 1) { $p_iPage = Params::getParam('iPage'); } Params::setParam('iPage', $p_iPage); $aLanguages = OSCLocale::newInstance()->listAll(); // pagination $start = ($p_iPage - 1) * Params::getParam('iDisplayLength'); $limit = Params::getParam('iDisplayLength'); $count = count($aLanguages); $displayRecords = $limit; if ($start + $limit > $count) { $displayRecords = $start + $limit - $count; } // ---- $aLanguagesToUpdate = json_decode(osc_get_preference('languages_to_update')); $bLanguagesToUpdate = is_array($aLanguagesToUpdate) ? true : false; // ---- $aData = array(); $max = $start + $limit; if ($max > $count) { $max = $count; } for ($i = $start; $i < $max; $i++) { $l = $aLanguages[$i]; $row = array(); $row[] = '<input type="checkbox" name="id[]" value="' . $l['pk_c_code'] . '" />'; $options = array(); $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=edit&id=' . $l['pk_c_code'] . '">' . __('Edit') . '</a>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=' . ($l['b_enabled'] == 1 ? 'disable_selected' : 'enable_selected') . '&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . ($l['b_enabled'] == 1 ? __('Disable (website)') : __('Enable (website)')) . '</a> '; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&action=' . ($l['b_enabled_bo'] == 1 ? 'disable_bo_selected' : 'enable_bo_selected') . '&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . ($l['b_enabled_bo'] == 1 ? __('Disable (oc-admin)') : __('Enable (oc-admin)')) . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $l['pk_c_code'] . '\');" href="' . osc_admin_base_url(true) . '?page=languages&action=delete&id[]=' . $l['pk_c_code'] . '&' . osc_csrf_token_url() . '">' . __('Delete') . '</a>'; $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; $sUpdate = ''; // get languages to update from t_preference if ($bLanguagesToUpdate) { if (in_array($l['pk_c_code'], $aLanguagesToUpdate)) { $sUpdate = '<a class="btn-market-update btn-market-popup" href="#' . htmlentities($l['pk_c_code']) . '">' . __("Update here") . '</a>'; } } $row[] = $l['s_name'] . $sUpdate . $actions; $row[] = $l['s_short_name']; $row[] = $l['s_description']; $row[] = $l['b_enabled'] ? __('Yes') : __('No'); $row[] = $l['b_enabled_bo'] ? __('Yes') : __('No'); $aData[] = $row; } // ---- $array['iTotalRecords'] = $displayRecords; $array['iTotalDisplayRecords'] = count($aLanguages); $array['iDisplayLength'] = $limit; $array['aaData'] = $aData; $page = (int) Params::getParam('iPage'); if (count($array['aaData']) == 0 && $page != 1) { $total = (int) $array['iTotalDisplayRecords']; $maxPage = ceil($total / (int) $array['iDisplayLength']); $url = osc_admin_base_url(true) . '?' . $_SERVER['QUERY_STRING']; if ($maxPage == 0) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url); $this->redirectTo($url); } if ($page > 1) { $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url); $this->redirectTo($url); } } $this->_exportVariableToView('aLanguages', $array); $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'enable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (Website)'))), 'label' => __('Enable (Website)')), array('value' => 'disable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (Website)'))), 'label' => __('Disable (Website)')), array('value' => 'enable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (oc-admin)'))), 'label' => __('Enable (oc-admin)')), array('value' => 'disable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (oc-admin)'))), 'label' => __('Disable (oc-admin)')), array('value' => 'delete', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Delete'))), 'label' => __('Delete'))); $bulk_options = osc_apply_filter("language_bulk_filter", $bulk_options); $this->_exportVariableToView('bulk_options', $bulk_options); $this->doView('languages/index.php'); break; } }
<?php // check requirements if (!is_writable(ABS_PATH . 'oc-content/downloads/')) { osc_add_flash_error_message(sprintf(_m('<code>downloads</code> folder has to be writable, i.e.: <code>chmod a+w %soc-content/downloads/</code>'), ABS_PATH), 'admin'); } // fancybox osc_enqueue_script('fancybox'); osc_enqueue_style('fancybox', osc_assets_url('js/fancybox/jquery.fancybox.css')); osc_register_script('market-js', osc_current_admin_theme_js_url('market.js'), array('jquery', 'jquery-ui')); osc_enqueue_script('market-js'); osc_add_hook('admin_header', 'add_market_jsvariables'); function add_market_jsvariables() { $marketPage = Params::getParam("mPage"); $version_length = strlen(osc_version()); $main_version = substr(osc_version(), 0, $version_length - 2) . "." . substr(osc_version(), $version_length - 2, 1); if ($marketPage >= 1) { $marketPage--; } $action = Params::getParam("action"); $js_lang = array('by' => __('by'), 'ok' => __('Ok'), 'error_item' => __('There was a problem, try again later please'), 'wait_download' => __('Please wait until the download is completed'), 'downloading' => __('Downloading'), 'close' => __('Close'), 'download' => __('Download'), 'update' => __('Update'), 'last_update' => __('Last update'), 'downloads' => __('Downloads'), 'requieres_version' => __('Requires at least'), 'compatible_with' => __('Compatible up to'), 'screenshots' => __('Screenshots'), 'preview_theme' => __('Preview theme'), 'download_manually' => __('Download manually'), 'buy' => __('Buy'), 'proceed_anyway' => sprintf(__('Warning! This package is not compatible with your current version of Osclass (%s)'), $main_version), 'sure' => __('Are you sure?'), 'proceed_anyway_btn' => __('Ok, proceed anyway'), 'not_compatible' => sprintf(__('Warning! This theme is not compatible with your current version of Osclass (%s)'), $main_version), 'themes' => array('download_ok' => __('The theme has been downloaded correctly, proceed to activate or preview it.')), 'plugins' => array('download_ok' => __('The plugin has been downloaded correctly, proceed to install and configure.')), 'languages' => array('download_ok' => __('The language has been downloaded correctly, proceed to activate.'))); ?> <script type="text/javascript"> var theme = window.theme || {}; theme.adminBaseUrl = "<?php echo osc_admin_base_url(true); ?> "; theme.marketAjaxUrl = "<?php echo osc_admin_base_url(true);
public static function ajaxPayment() { $status = self::processPayment(); $data = payment_get_custom(Params::getParam('extra')); $product_type = explode('x', $data['product']); if ($status == PAYMENT_COMPLETED) { osc_add_flash_ok_message(sprintf(__('Success! Please write down this transaction ID in case you have any problem: %s', 'payment'), Params::getParam('stripe_transaction_id'))); if ($product_type[0] == 101) { $item = Item::newInstance()->findByPrimaryKey($product_type[2]); $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']); View::newInstance()->_exportVariableToView('category', $category); payment_js_redirect_to(osc_search_category_url()); } else { if ($product_type[0] == 201) { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-menu')); } else { View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($product_type[2])); payment_js_redirect_to(osc_item_url()); } } else { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-pack')); } else { // THIS SHOULD NOT HAPPEN payment_js_redirect_to(osc_base_path()); } } } } else { if ($status == PAYMENT_ALREADY_PAID) { osc_add_flash_warning_message(__('Warning! This payment was already paid', 'payment')); } else { osc_add_flash_error_message(_e('There were an error processing your payment', 'payment')); } if ($product_type[0] == 301) { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-pack')); } else { // THIS SHOULD NOT HAPPEN payment_js_redirect_to(osc_base_path()); } } else { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-menu')); } else { View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($product_type[2])); payment_js_redirect_to(osc_item_url()); } } } }
function theme_pop_actions_admin() { //if(OC_ADMIN) if (Params::getParam('file') == 'oc-content/themes/pop/admin/settings.php') { if (Params::getParam('donation') == 'successful') { osc_set_preference('donation', '1', 'pop_theme'); osc_reset_preferences(); } } switch (Params::getParam('subaction')) { case 'color-update': /* theme color staff here */ $aParams = Params::getParamsAsArray(); unset($aParams['page']); unset($aParams['action']); unset($aParams['file']); unset($aParams['CSRFName']); unset($aParams['CSRFToken']); osc_set_preference('pop-theme-colors', json_encode($aParams), 'pop_theme'); osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin'); osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/color_settings.php')); break; case 'color-restore': $aParams = pop_getColorScheme(true); osc_set_preference('pop-theme-colors', json_encode($aParams), 'pop_theme'); osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin'); osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/color_settings.php')); break; default: break; } switch (Params::getParam('action_specific')) { case 'settings': $footerLink = Params::getParam('footer_link'); osc_set_preference('pop_max_premium', Params::getParam('pop_max_premium'), 'pop_theme'); osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'pop_theme'); osc_set_preference('footer_link', $footerLink ? '1' : '0', 'pop_theme'); osc_set_preference('header-728x90', trim(Params::getParam('header-728x90', false, false, false)), 'pop_theme'); osc_set_preference('search-results-300x250', trim(Params::getParam('search-results-300x250', false, false, false)), 'pop_theme'); osc_set_preference('item-detail-300x250', trim(Params::getParam('item-detail-300x250', false, false, false)), 'pop_theme'); osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin'); osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/settings.php')); break; case 'upload_logo': $package = Params::getFiles('logo'); if ($package['error'] == UPLOAD_ERR_OK) { $img = ImageResizer::fromFile($package['tmp_name']); $ext = $img->getExt(); $logo_name = 'pop_logo'; $logo_name .= '.' . $ext; $path = osc_uploads_path() . $logo_name; move_uploaded_file($package['tmp_name'], $path); osc_set_preference('logo', $logo_name, 'pop_theme'); osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'pop'), 'admin'); } else { osc_add_flash_error_message(__("An error has occurred, please try again", 'pop'), 'admin'); } osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/header.php')); break; case 'remove': $logo = osc_get_preference('logo', 'pop_theme'); $path = osc_uploads_path() . $logo; if (file_exists($path)) { @unlink($path); osc_delete_preference('logo', 'pop_theme'); osc_reset_preferences(); osc_add_flash_ok_message(__('The logo image has been removed', 'pop'), 'admin'); } else { osc_add_flash_error_message(__("Image not found", 'pop'), 'admin'); } osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/header.php')); break; } }
function doModel() { switch ($this->action) { case 'contact_post': //contact_post osc_csrf_check(); $yourName = Params::getParam('yourName'); $yourEmail = Params::getParam('yourEmail'); $subject = Params::getParam('subject'); $message = Params::getParam('message'); if (osc_recaptcha_private_key() != '') { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm('yourName', $yourName); Session::newInstance()->_setForm('yourEmail', $yourEmail); Session::newInstance()->_setForm('subject', $subject); Session::newInstance()->_setForm('message_body', $message); $this->redirectTo(osc_contact_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $banned = osc_is_banned($yourEmail); if ($banned == 1) { osc_add_flash_error_message(_m('Your current email is not allowed')); $this->redirectTo(osc_contact_url()); } else { if ($banned == 2) { osc_add_flash_error_message(_m('Your current IP is not allowed')); $this->redirectTo(osc_contact_url()); } } $user = User::newInstance()->newInstance()->findByEmail($yourEmail); if (isset($user['b_active']) && ($user['b_active'] == 0 || $user['b_enabled'] == 0)) { osc_add_flash_error_message(_m('Your current email is not allowed')); $this->redirectTo(osc_contact_url()); } if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) { osc_add_flash_error_message(_m('Please enter a correct email')); Session::newInstance()->_setForm('yourName', $yourName); Session::newInstance()->_setForm('subject', $subject); Session::newInstance()->_setForm('message_body', $message); $this->redirectTo(osc_contact_url()); } $message_name = sprintf(__('Name: %s'), $yourName); $message_email = sprintf(__('Email: %s'), $yourEmail); $message_subject = sprintf(__('Subject: %s'), $subject); $message_body = sprintf(__('Message: %s'), $message); $message_date = sprintf(__('Date: %s at %s'), date('l F d, Y'), date('g:i a')); $message_IP = sprintf(__('IP Address: %s'), get_ip()); $message = <<<MESSAGE {$message_name} {$message_email} {$message_subject} {$message_body} {$message_date} {$message_IP} MESSAGE; $params = array('from' => osc_contact_email(), 'to' => osc_contact_email(), 'to_name' => osc_page_title(), 'reply_to' => $yourEmail, 'subject' => '[' . osc_page_title() . '] ' . __('Contact'), 'body' => nl2br($message)); $error = false; if (osc_contact_attachment()) { $attachment = Params::getFiles('attachment'); if (isset($attachment['error']) && $attachment['error'] == UPLOAD_ERR_OK) { $mime_array = array('text/php', 'text/x-php', 'application/php', 'application/x-php', 'application/x-httpd-php', 'application/x-httpd-php-source', 'application/x-javascript'); $resourceName = $attachment['name']; $tmpName = $attachment['tmp_name']; $resourceType = $attachment['type']; if (function_exists('mime_content_type')) { $resourceType = mime_content_type($tmpName); } if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $output = finfo_file($finfo, $tmpName); finfo_close($finfo); $output = explode("; ", $output); if (is_array($output)) { $output = $output[0]; } $resourceType = $output; } // check mime file if (!in_array($resourceType, $mime_array)) { $emailAttachment = array('path' => $tmpName, 'name' => $resourceName); $error = false; } else { $error = true; } // --- check mime file } else { $error = true; } } if (!$error) { if (isset($emailAttachment)) { $params['attachment'] = $emailAttachment; } osc_run_hook('pre_contact_post', $params); osc_sendMail(osc_apply_filter('contact_params', $params)); if (isset($tmpName)) { @unlink($tmpName); } osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!')); } else { osc_add_flash_error_message(_m('The file you tried to upload does not have a valid extension')); } $this->redirectTo(osc_contact_url()); break; default: //contact $this->doView('contact.php'); } }
<?php define('ABS_PATH', dirname(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))))) . '/'); define('OC_ADMIN', true); require_once ABS_PATH . 'oc-load.php'; if (osc_is_admin_user_logged_in() == FALSE) { die; } $model = new GzNewsModel(); $dao = GzNewsDao::newInstance(); $redirect_url = $_SERVER['HTTP_REFERER']; $gn_id = (int) Params::getParam('gn_id'); $from_form = (bool) Params::getParam('from_form'); if ($from_form) { $redirect_url = GzNewsUtils::getAdminIndexUrl(); } $success = $dao->deleteByPrimaryKey($gn_id); if ($success) { $model->removeFiles($gn_id); osc_add_flash_ok_message(__('The item was deleted successfully', 'gz_news'), 'admin'); } else { osc_add_flash_error_message('There were a problem while deleting the item', 'admin'); } $model->redirectTo($redirect_url);
function doModel() { switch ($this->action) { case 'logout': // unset only the required parameters in Session osc_run_hook('logout_admin'); $this->logout(); $this->redirectTo(osc_admin_base_url(true)); break; default: //default dashboard page (main page at oc-admin) $this->_exportVariableToView("numItemsPerCategory", osc_get_non_empty_categories()); $this->_exportVariableToView("numUsers", User::newInstance()->count()); $this->_exportVariableToView("numItems", Item::newInstance()->count()); // stats $items = array(); $stats_items = Stats::newInstance()->new_items_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $items[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_items as $item) { $items[$item['d_date']] = $item['num']; } $users = array(); $stats_users = Stats::newInstance()->new_users_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $users[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_users as $user) { $users[$user['d_date']] = $user['num']; } if (function_exists('disk_free_space')) { $freedisk = @disk_free_space(osc_uploads_path()); if ($freedisk !== false && $freedisk < 52428800) { //52428800 = 50*1024*1024 osc_add_flash_error_message(_m('You have very few free space left, users will not be able to upload pictures'), 'admin'); } } // show messages subscribed $status_subscribe = Params::getParam('subscribe_osclass'); if ($status_subscribe != '') { switch ($status_subscribe) { case -1: osc_add_flash_error_message(_m('Entered an invalid email'), 'admin'); break; case 0: osc_add_flash_warning_message(_m("You're already subscribed"), 'admin'); break; case 1: osc_add_flash_ok_message(_m('Subscribed correctly'), 'admin'); break; default: osc_add_flash_warning_message(_m("Error subscribing"), 'admin'); break; } } $this->_exportVariableToView("item_stats", $items); $this->_exportVariableToView("user_stats", $users); //calling the view... $this->doView('main/index.php'); } }
function errorHandler($pn) { if (false === is_null($aError = error_get_last())) { Plugins::deactivate($pn); osc_add_flash_error_message(sprintf(_m('There was a fatal error and the plugin was not installed.<br />Error: "%s" Line: %s<br/>File: %s'), $aError['message'], $aError['line'], $aError['file']), 'admin'); $this->redirectTo(osc_admin_base_url(true) . "?page=plugins"); } }
function fn_email_item_inquiry($aItem) { $id = $aItem['id']; $yourEmail = $aItem['yourEmail']; $yourName = $aItem['yourName']; $phoneNumber = $aItem['phoneNumber']; $message = $aItem['message']; $path = NULL; $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); $mPages = new Page(); $aPage = $mPages->findByInternalName('email_item_inquiry'); $locale = osc_current_user_locale(); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item_url = osc_item_url(); $item_url = '<a href="' . $item_url . '" >' . $item_url . '</a>'; $words = array(); $words[] = array('{CONTACT_NAME}', '{USER_NAME}', '{USER_EMAIL}', '{USER_PHONE}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{COMMENT}'); $words[] = array($item['s_contact_name'], $yourName, $yourEmail, $phoneNumber, '<a href="' . osc_base_url() . '" >' . osc_base_url() . '</a>', $item['s_title'], $item_url, $message); $title = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_item_inquiry_title', $content['s_title'])), $words); $body = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_item_inquiry_description', $content['s_text'])), $words); $from = osc_contact_email(); $from_name = osc_page_title(); $add_bbc = ''; if (osc_notify_contact_item()) { $add_bbc = osc_contact_email(); } $emailParams = array('add_bcc' => $add_bbc, 'from' => $from, 'from_name' => $from_name, 'subject' => $title, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body, 'alt_body' => $body, 'reply_to' => $yourEmail); if (osc_item_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_error_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)) { $emailParams['attachment'] = $path; } osc_sendMail($emailParams); @unlink($path); }
function doModel() { switch ($this->action) { case 'register': //register user $this->doView('user-register.php'); break; case 'register_post': //register user osc_csrf_check(); if (!osc_users_enabled()) { osc_add_flash_error_message(_m('Users are not enabled')); $this->redirectTo(osc_base_url()); } osc_run_hook('before_user_register'); $banned = osc_is_banned(Params::getParam('s_email')); if ($banned == 1) { osc_add_flash_error_message(_m('Your current email is not allowed')); $this->redirectTo(osc_register_account_url()); } else { if ($banned == 2) { osc_add_flash_error_message(_m('Your current IP is not allowed')); $this->redirectTo(osc_register_account_url()); } } require_once LIB_PATH . 'osclass/UserActions.php'; $userActions = new UserActions(false); $success = $userActions->add(); switch ($success) { case 1: osc_add_flash_ok_message(_m('The user has been created. An activation email has been sent')); $this->redirectTo(osc_base_url()); break; case 2: osc_add_flash_ok_message(_m('Your account has been created successfully')); $this->doView('user-login.php'); break; case 3: osc_add_flash_warning_message(_m('The specified e-mail is already in use')); $this->doView('user-register.php'); break; case 4: osc_add_flash_error_message(_m('The reCAPTCHA was not entered correctly')); $this->doView('user-register.php'); break; case 5: osc_add_flash_warning_message(_m('The email is not valid')); $this->doView('user-register.php'); break; case 6: osc_add_flash_warning_message(_m('The password cannot be empty')); $this->doView('user-register.php'); break; case 7: osc_add_flash_warning_message(_m("Passwords don't match")); $this->doView('user-register.php'); break; case 8: osc_add_flash_warning_message(_m("Username is already taken")); $this->doView('user-register.php'); break; case 9: osc_add_flash_warning_message(_m("The specified username is not valid, it contains some invalid words")); $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) { osc_add_flash_error_message(_m('The link is not valid anymore. Sorry for the inconvenience!')); $this->redirectTo(osc_base_url()); } if ($user['b_active'] == 1) { osc_add_flash_error_message(_m('Your account has already been validated')); $this->redirectTo(osc_base_url()); } $userManager = new User(); $userManager->update(array('b_active' => '1'), array('pk_i_id' => $id, 's_secret' => $code)); // 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); osc_run_hook('hook_email_user_registration', $user); osc_run_hook('validate_user', $user); osc_add_flash_ok_message(_m('Your account has been validated')); $this->redirectTo(osc_base_url()); break; } }
function doModel() { parent::doModel(); switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); } // calling $sql = Params::getFiles('sql'); if (isset($sql['size']) && $sql['size'] != 0) { $content_file = file_get_contents($sql['tmp_name']); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); if ($comm->importSQL($content_file)) { osc_add_flash_ok_message(_m('Import complete'), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin'); } } else { osc_add_flash_warning_message(_m('No file was uploaded'), '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': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); } $preferences = Preference::newInstance()->toArray(); $wat = new Watermark(); $aResources = ItemResource::newInstance()->getAllResources(); foreach ($aResources as $resource) { osc_run_hook('regenerate_image', $resource); $path = osc_content_path() . 'uploads/'; // comprobar que no haya original $img_original = $path . $resource['pk_i_id'] . "_original*"; $aImages = glob($img_original); // there is original image if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_normal = $path . $resource['pk_i_id'] . ".*"; $aImages = glob($img_normal); if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_thumbnail = $path . $resource['pk_i_id'] . "_thumbnail*"; $aImages = glob($img_thumbnail); $image_tmp = $aImages[0]; } } // extension preg_match('/\\.(.*)$/', $image_tmp, $matches); if (isset($matches[1])) { $extension = $matches[1]; // Create normal size $path_normal = $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '.jpg'; $size = explode('x', osc_normal_dimensions()); ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1])->saveToFile($path); if (osc_is_watermark_text()) { $wat->doWatermarkText($path, osc_watermark_text_color(), osc_watermark_text(), 'image/jpeg'); } elseif (osc_is_watermark_image()) { $wat->doWatermarkImage($path, 'image/jpeg'); } // Create preview $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_preview.jpg'; $size = explode('x', osc_preview_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // Create thumbnail $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_thumbnail.jpg'; $size = explode('x', osc_thumbnail_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // update resource info ItemResource::newInstance()->update(array('s_path' => 'oc-content/uploads/', 's_name' => osc_genRandomPassword(), 's_extension' => 'jpg', 's_content_type' => 'image/jpeg'), array('pk_i_id' => $resource['pk_i_id'])); osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id'])); // si extension es direfente a jpg, eliminar las imagenes con $extension si hay if ($extension != 'jpg') { $files_to_remove = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . "*" . $extension; $fs = glob($files_to_remove); if (is_array($fs)) { array_map("unlink", $fs); } } // .... } else { // no es imagen o imagen sin extesión } } osc_add_flash_ok_message(_m('Re-generation complete'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); break; case 'category': $this->doView('tools/category.php'); break; case 'category_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); } osc_update_cat_stats(); osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); break; case 'locations': $this->doView('tools/locations.php'); break; case 'locations_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); } $workToDo = LocationsTmp::newInstance()->count(); if ($workToDo > 0) { $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; } // we need populate location tmp table $aCountry = Country::newInstance()->listAll(); foreach ($aCountry as $country) { $aRegionsCountry = Region::newInstance()->getByCountry($country['pk_c_code']); LocationsTmp::newInstance()->insert(array('id_location' => $country['pk_c_code'], 'e_type' => 'COUNTRY')); foreach ($aRegionsCountry as $region) { $aCitiesRegion = City::newInstance()->getByRegion($region['pk_i_id']); LocationsTmp::newInstance()->insert(array('id_location' => $region['pk_i_id'], 'e_type' => 'REGION')); foreach ($aCitiesRegion as $city) { LocationsTmp::newInstance()->insert(array('id_location' => $city['pk_i_id'], 'e_type' => 'CITY')); } unset($aCitiesRegion); } unset($aRegionsCountry); } unset($aCountry); $workToDo = LocationsTmp::newInstance()->count(); Preference::newInstance()->replace('location_todo', $workToDo); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //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'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-sql_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql'; $path = sys_get_temp_dir() . "/"; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -5: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } $filename = "OSClass_backup." . date('YmdHis') . ".zip"; $path = sys_get_temp_dir() . "/"; if (osc_zip_folder(osc_base_path(), $path . $filename)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //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('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; case 'maintenance': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->doView('tools/maintenance.php'); break; } $mode = Params::getParam('mode'); if ($mode == 'on') { $maintenance_file = osc_base_path() . '.maintenance'; $fileHandler = @fopen($maintenance_file, 'w'); if ($fileHandler) { osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin'); } fclose($fileHandler); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } else { if ($mode == 'off') { $deleted = @unlink(osc_base_path() . '.maintenance'); if ($deleted) { osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } } $this->doView('tools/maintenance.php'); break; default: } }