Beispiel #1
0
function osc_runAlert($type = null)
{
    if (!in_array($type, array('HOURLY', 'DAILY', 'WEEKLY', 'INSTANT'))) {
        return;
    }
    $internal_name = 'alert_email_hourly';
    switch ($type) {
        case 'HOURLY':
            $internal_name = 'alert_email_hourly';
            break;
        case 'DAILY':
            $internal_name = 'alert_email_daily';
            break;
        case 'WEEKLY':
            $internal_name = 'alert_email_weekly';
            break;
        case 'INSTANT':
            $internal_name = 'alert_email_instant';
            break;
    }
    $active = TRUE;
    $searches = Alerts::newInstance()->findByTypeGroup($type, $active);
    foreach ($searches as $s_search) {
        $a_search = Search::newInstance();
        // Get if there're new ads on this search
        $a_search = osc_unserialize(base64_decode($s_search['s_search']));
        $cron = Cron::newInstance()->getCronByType($type);
        if (is_array($cron)) {
            $last_exec = $cron['d_last_exec'];
        } else {
            $last_exec = '0000-00-00 00:00:00';
        }
        $a_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
        $totalItems = $a_search->count();
        $items = $a_search->doSearch();
        if (count($items) > 0) {
            //If we have new items from last check
            //Catch the user subscribed to this search
            $users = Alerts::newInstance()->findUsersBySearchAndType($s_search['s_search'], $type, $active);
            if (count($users) > 0) {
                $ads = "";
                foreach ($items as $item) {
                    $ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
                }
                foreach ($users as $user) {
                    osc_run_hook('hook_' . $internal_name, $user, $ads, $s_search);
                }
            }
        }
    }
}
Beispiel #2
0
 public function getRules()
 {
     return osc_unserialize(osc_rewrite_rules());
 }
Beispiel #3
0
/**
 * Gets the search object of a specific alert
 *
 * @return Search
 */
function osc_alert_search_object()
{
    return osc_unserialize(base64_decode(osc_alert_field('s_search')));
}
Beispiel #4
0
 function doModel()
 {
     switch ($this->action) {
         case 'dashboard':
             //dashboard...
             $max_items = Params::getParam('max_items') != '' ? Params::getParam('max_items') : 5;
             $aItems = Item::newInstance()->findByUserIDEnabled(Session::newInstance()->_get('userId'), 0, $max_items);
             //calling the view...
             $this->_exportVariableToView('items', $aItems);
             $this->_exportVariableToView('max_items', $max_items);
             $this->doView('user-dashboard.php');
             break;
         case 'profile':
             //profile...
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             $aCountries = Country::newInstance()->listAll();
             $aRegions = array();
             if ($user['fk_c_country_code'] != '') {
                 $aRegions = Region::newInstance()->findByCountry($user['fk_c_country_code']);
             } elseif (count($aCountries) > 0) {
                 $aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
             }
             $aCities = array();
             if ($user['fk_i_region_id'] != '') {
                 $aCities = City::newInstance()->findByRegion($user['fk_i_region_id']);
             } else {
                 if (count($aRegions) > 0) {
                     $aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
                 }
             }
             //calling the view...
             $this->_exportVariableToView('countries', $aCountries);
             $this->_exportVariableToView('regions', $aRegions);
             $this->_exportVariableToView('cities', $aCities);
             $this->_exportVariableToView('user', $user);
             $this->doView('user-profile.php');
             break;
         case 'profile_post':
             //profile post...
             $userId = Session::newInstance()->_get('userId');
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(false);
             $success = $userActions->edit($userId);
             osc_add_flash_ok_message(_m('Your profile has been updated successfully'));
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'alerts':
             //alerts
             $aAlerts = Alerts::newInstance()->findByUser(Session::newInstance()->_get('userId'));
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             foreach ($aAlerts as $k => $a) {
                 $search = osc_unserialize(base64_decode($a['s_search']));
                 $search->limit(0, 3);
                 $aAlerts[$k]['items'] = $search->doSearch();
             }
             $this->_exportVariableToView('alerts', $aAlerts);
             View::newInstance()->_reset('alerts');
             $this->_exportVariableToView('user', $user);
             $this->doView('user-alerts.php');
             break;
         case 'change_email':
             //change email
             $this->doView('user-change_email.php');
             break;
         case 'change_email_post':
             //change email post
             if (!preg_match("/^[_a-z0-9-\\+]+(\\.[_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", Params::getParam('new_email'))) {
                 osc_add_flash_error_message(_m('The specified e-mail is not valid'));
                 $this->redirectTo(osc_change_user_email_url());
             } else {
                 $user = User::newInstance()->findByEmail(Params::getParam('new_email'));
                 if (!isset($user['pk_i_id'])) {
                     $userEmailTmp = array();
                     $userEmailTmp['fk_i_user_id'] = Session::newInstance()->_get('userId');
                     $userEmailTmp['s_new_email'] = Params::getParam('new_email');
                     UserEmailTmp::newInstance()->insertOrUpdate($userEmailTmp);
                     $code = osc_genRandomPassword(30);
                     $date = date('Y-m-d H:i:s');
                     $userManager = new User();
                     $userManager->update(array('s_pass_code' => $code, 's_pass_date' => $date, 's_pass_ip' => $_SERVER['REMOTE_ADDR']), array('pk_i_id' => Session::newInstance()->_get('userId')));
                     $validation_url = osc_change_user_email_confirm_url(Session::newInstance()->_get('userId'), $code);
                     osc_run_hook('hook_email_new_email', Params::getParam('new_email'), $validation_url);
                     $this->redirectTo(osc_user_profile_url());
                 } else {
                     osc_add_flash_error_message(_m('The specified e-mail is already in use'));
                     $this->redirectTo(osc_change_user_email_url());
                 }
             }
             break;
         case 'change_password':
             //change password
             $this->doView('user-change_password.php');
             break;
         case 'change_password_post':
             //change password post
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             if (Params::getParam('password') == '' || Params::getParam('new_password') == '' || Params::getParam('new_password2') == '') {
                 osc_add_flash_warning_message(_m('Password cannot be blank'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             if ($user['s_password'] != sha1(Params::getParam('password'))) {
                 osc_add_flash_error_message(_m('Current password doesn\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             if (!Params::getParam('new_password')) {
                 osc_add_flash_error_message(_m('Passwords can\'t be empty'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             if (Params::getParam('new_password') != Params::getParam('new_password2')) {
                 osc_add_flash_error_message(_m('Passwords don\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             User::newInstance()->update(array('s_password' => sha1(Params::getParam('new_password'))), array('pk_i_id' => Session::newInstance()->_get('userId')));
             osc_add_flash_ok_message(_m('Password has been changed'));
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'items':
             // view items user
             $itemsPerPage = Params::getParam('itemsPerPage') != '' ? Params::getParam('itemsPerPage') : 5;
             $page = Params::getParam('iPage') != '' ? Params::getParam('iPage') : 0;
             $total_items = Item::newInstance()->countByUserIDEnabled($_SESSION['userId']);
             $total_pages = ceil($total_items / $itemsPerPage);
             $items = Item::newInstance()->findByUserIDEnabled($_SESSION['userId'], $page * $itemsPerPage, $itemsPerPage);
             $this->_exportVariableToView('items', $items);
             $this->_exportVariableToView('list_total_pages', $total_pages);
             $this->_exportVariableToView('list_total_items', $total_items);
             $this->_exportVariableToView('items_per_page', $itemsPerPage);
             $this->_exportVariableToView('list_page', $page);
             $this->doView('user-items.php');
             break;
         case '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_user_alerts_url());
             break;
         case 'deleteResource':
             $id = Params::getParam('id');
             $name = Params::getParam('name');
             $fkid = Params::getParam('fkid');
             osc_deleteResource($id);
             ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $fkid, 's_name' => $name));
             $this->redirectTo(osc_base_url(true) . "?page=item&action=item_edit&id=" . $fkid);
             break;
     }
 }
Beispiel #5
0
function osc_runAlert($type = null)
{
    if ($type == null) {
        return;
    }
    $internal_name = 'alert_email_hourly';
    switch ($type) {
        case 'HOURLY':
            $internal_name = 'alert_email_hourly';
            break;
        case 'DAILY':
            $internal_name = 'alert_email_daily';
            break;
        case 'WEEKLY':
            $internal_name = 'alert_email_weekly';
            break;
        case 'INSTANT':
            $internal_name = 'alert_email_instant';
            break;
    }
    $searches = Alerts::newInstance()->getAlertsByTypeGroup($type);
    foreach ($searches as $s_search) {
        $a_search = Search::newInstance();
        // Get if there're new ads on this search
        $a_search = osc_unserialize(base64_decode($s_search['s_search']));
        $crons = Cron::newInstance()->getCronByType($type);
        if (isset($crons[0])) {
            $last_exec = $crons[0]['d_last_exec'];
        } else {
            $last_exec = '0000-00-00 00:00:00';
        }
        $a_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' ", DB_TABLE_PREFIX, $last_exec));
        $totalItems = $a_search->count();
        $items = $a_search->doSearch();
        if (count($items) > 0) {
            //If we have new items from last check
            //Catch the user subscribed to this search
            $users = Alerts::newInstance()->getUsersBySearchAndType($s_search['s_search'], $type);
            if (count($users) > 0) {
                $prefLocale = osc_language();
                $page = Page::newInstance()->findByInternalName($internal_name);
                $page = Page::newInstance()->findByInternalName($internal_name);
                $page_description = $page['locale'];
                $_title = $page_description[$prefLocale]['s_title'];
                $_body = $page_description[$prefLocale]['s_text'];
                $ads = "";
                foreach ($items as $item) {
                    $ads .= '<a href="' . osc_item_url_ns($item['pk_i_id']) . '">' . $item['s_title'] . '</a><br/>';
                }
                foreach ($users as $user) {
                    if ($user['fk_i_user_id'] != 0) {
                        $user = User::newInstance()->findByPrimaryKey($user['fk_i_user_id']);
                    } else {
                        $user['s_name'] = $user['s_email'];
                    }
                    $unsub_link = osc_user_unsubscribe_alert_url($user['s_email'], $s_search['s_search']);
                    //osc_create_url(array('file' => 'user', 'action' => 'unsub_alert', 'email' => $user['s_email'], 'alert' => $s_search['s_search'])) ;
                    $unsub_link = '<a href="' . $unsub_link . '">unsubscribe alert</a>';
                    $words = array();
                    $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{ADS}', '{UNSUB_LINK}');
                    $words[] = array($user['s_name'], $user['s_email'], $ads, $unsub_link);
                    $title = osc_mailBeauty($_title, $words);
                    $body = osc_mailBeauty($_body, $words);
                    $params = array('subject' => $title, 'to' => $user['s_email'], 'to_name' => $user['s_name'], 'body' => $body, 'alt_body' => $body);
                    osc_sendMail($params);
                }
            }
        }
    }
}
Beispiel #6
0
 function doModel()
 {
     switch ($this->action) {
         case 'dashboard':
             //dashboard...
             $max_items = Params::getParam('max_items') != '' ? Params::getParam('max_items') : 5;
             $aItems = Item::newInstance()->findByUserID(Session::newInstance()->_get('userId'), 0, $max_items);
             //Item::newInstance()->listWhere("fk_i_user_id = ".Session::newInstance()->_get('userId'));
             //calling the view...
             $this->_exportVariableToView('items', $aItems);
             $this->_exportVariableToView('max_items', $max_items);
             $this->doView('user-dashboard.php');
             break;
         case 'profile':
             //profile...
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             $aCountries = Country::newInstance()->listAll();
             $aRegions = array();
             if ($user['fk_c_country_code'] != '') {
                 $aRegions = Region::newInstance()->getByCountry($user['fk_c_country_code']);
             } elseif (count($aCountries) > 0) {
                 $aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
             }
             $aCities = array();
             if ($user['fk_i_region_id'] != '') {
                 $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $user['fk_i_region_id']);
             } else {
                 if (count($aRegions) > 0) {
                     $aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
                 }
             }
             //calling the view...
             $this->_exportVariableToView('countries', $aCountries);
             $this->_exportVariableToView('regions', $aRegions);
             $this->_exportVariableToView('cities', $aCities);
             $this->_exportVariableToView('user', $user);
             $this->doView('user-profile.php');
             break;
         case 'profile_post':
             //profile post...
             $userId = Session::newInstance()->_get('userId');
             require_once LIB_PATH . 'osclass/UserActions.php';
             $userActions = new UserActions(false);
             $success = $userActions->edit($userId);
             // This has been moved to special area (only password changes)
             /*if( $success == 1 ) {
                   osc_add_flash_message( _m('Passwords don\'t match') ) ;
               } else {*/
             osc_add_flash_message(_m('Your profile has been updated successfully'));
             //}
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'alerts':
             //alerts
             $aAlerts = Alerts::newInstance()->getAlertsFromUser(Session::newInstance()->_get('userId'));
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             foreach ($aAlerts as $k => $a) {
                 $search = osc_unserialize(base64_decode($a['s_search']));
                 $search->limit(0, 3);
                 $aAlerts[$k]['items'] = $search->doSearch();
             }
             $this->_exportVariableToView('alerts', $aAlerts);
             View::newInstance()->_reset('alerts');
             $this->_exportVariableToView('user', $user);
             $this->doView('user-alerts.php');
             break;
         case 'change_email':
             //change email
             $this->doView('user-change_email.php');
             break;
         case 'change_email_post':
             //change email post
             if (!preg_match("/^[_a-z0-9-\\+]+(\\.[_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", Params::getParam('new_email'))) {
                 osc_add_flash_message(_m('The specified e-mail is not valid'));
                 $this->redirectTo(osc_change_user_email_url());
             } else {
                 $user = User::newInstance()->findByEmail(Params::getParam('new_email'));
                 if (!isset($user['pk_i_id'])) {
                     if (osc_user_validation_enabled()) {
                         $userEmailTmp = array();
                         $userEmailTmp['fk_i_user_id'] = Session::newInstance()->_get('userId');
                         $userEmailTmp['s_new_email'] = Params::getParam('new_email');
                         UserEmailTmp::newInstance()->insertOrUpdate($userEmailTmp);
                         $code = osc_genRandomPassword(30);
                         $date = date('Y-m-d H:i:s');
                         $userManager = new User();
                         $userManager->update(array('s_pass_code' => $code, 's_pass_date' => $date, 's_pass_ip' => $_SERVER['REMOTE_ADDR']), array('pk_i_id' => Session::newInstance()->_get('userId')));
                         $locale = osc_current_user_locale();
                         $aPage = Page::newInstance()->findByInternalName('email_new_email');
                         if (isset($aPage['locale'][$locale]['s_title'])) {
                             $content = $aPage['locale'][$locale];
                         } else {
                             $content = current($aPage['locale']);
                         }
                         if (!is_null($content)) {
                             $validation_url = osc_change_user_email_confirm_url(Session::newInstance()->_get('userId'), $code);
                             $words = array();
                             $words[] = array('{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}');
                             $words[] = array(Session::newInstance()->_get('userName'), Params::getParam('new_email'), osc_base_url(), osc_page_title(), '<a href="' . $validation_url . '" >' . $validation_url . '</a>', $validation_url);
                             $title = osc_mailBeauty($content['s_title'], $words);
                             $body = osc_mailBeauty($content['s_text'], $words);
                             $params = array('subject' => $title, 'to' => Params::getParam('new_email'), 'to_name' => Session::newInstance()->_get('userName'), 'body' => $body, 'alt_body' => $body);
                             osc_sendMail($params);
                             osc_add_flash_message(_m('We have sent you an e-mail. Follow the instructions to validate the changes'));
                         } else {
                             osc_add_flash_message(_m('We tried to sent you an e-mail, but it failed. Please, contact the administrator'));
                         }
                         $this->redirectTo(osc_user_profile_url());
                     } else {
                         User::newInstance()->update(array('s_email' => Params::getParam('new_email')), array('pk_i_id' => Params::getParam('userId')));
                         osc_add_flash_message(_m('Your email has been changed successfully'));
                         $this->redirectTo(osc_user_profile_url());
                     }
                 } else {
                     osc_add_flash_message(_m('The specified e-mail is already in use'));
                     $this->redirectTo(osc_change_user_email_url());
                 }
             }
             break;
         case 'change_password':
             //change password
             $this->doView('user-change_password.php');
             break;
         case 'change_password_post':
             //change password post
             $user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
             if ($user['s_password'] != sha1(Params::getParam('password'))) {
                 osc_add_flash_message(_m('Current password doesn\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             } elseif (!Params::getParam('new_password')) {
                 osc_add_flash_message(_m('Passwords can\'t be empty'));
                 $this->redirectTo(osc_change_user_password_url());
             } elseif (Params::getParam('new_password') != Params::getParam('new_password2')) {
                 osc_add_flash_message(_m('Passwords don\'t match'));
                 $this->redirectTo(osc_change_user_password_url());
             }
             User::newInstance()->update(array('s_password' => sha1(Params::getParam('new_password'))), array('pk_i_id' => Session::newInstance()->_get('userId')));
             osc_add_flash_message(_m('Password has been changed'));
             $this->redirectTo(osc_user_profile_url());
             break;
         case 'items':
             // view items user
             $itemsPerPage = Params::getParam('itemsPerPage') != '' ? Params::getParam('itemsPerPage') : 5;
             $page = Params::getParam('iPage') != '' ? Params::getParam('iPage') : 0;
             $total_items = Item::newInstance()->countByUserID($_SESSION['userId']);
             $total_pages = ceil($total_items / $itemsPerPage);
             $items = Item::newInstance()->findByUserID($_SESSION['userId'], $page * $itemsPerPage, $itemsPerPage);
             $this->_exportVariableToView('items', $items);
             $this->_exportVariableToView('list_total_pages', $total_pages);
             $this->_exportVariableToView('list_total_items', $total_items);
             $this->_exportVariableToView('items_per_page', $itemsPerPage);
             $this->_exportVariableToView('list_page', $page);
             $this->doView('user-items.php');
             break;
         case 'unsub_alert':
             $email = Params::getParam('email');
             $alert = Params::getParam('alert');
             if ($email != '' && $alert != '') {
                 Alerts::newInstance()->delete(array('s_email' => $email, 's_search' => $alert));
                 osc_add_flash_message(__('Unsubscribed correctly.'));
             } else {
                 osc_add_flash_message(__('Ops! There was a problem trying to unsubscribe you. Please contact the administrator.'));
             }
             $this->redirectTo(osc_user_alerts_url());
             break;
     }
 }