/** * Return an array with all data necessary for do the action (ADD OR EDIT) * @param <type> $is_add * @return array */ public function prepareData( $is_add ) { $aItem = array(); $data = array(); $userId = null; if( $this->is_admin ) { // user $data = User::newInstance()->findByEmail(Params::getParam('contactEmail')); if( isset($data['pk_i_id']) && is_numeric($data['pk_i_id']) ) { $userId = $data['pk_i_id']; } } else { $userId = Session::newInstance()->_get('userId'); if( $userId == '' ) { $userId = NULL; } elseif ($userId != NULL) { $data = User::newInstance()->findByPrimaryKey( $userId ); } } if( $userId != null ) { $aItem['contactName'] = $data['s_name']; $aItem['contactEmail'] = $data['s_email']; Params::setParam('contactName', $data['s_name']); Params::setParam('contactEmail', $data['s_email']); } else { $aItem['contactName'] = Params::getParam('contactName'); $aItem['contactEmail'] = Params::getParam('contactEmail'); } $aItem['userId'] = $userId; if( $is_add ) { // ADD if($this->is_admin) { $active = 'ACTIVE'; } else { if(osc_moderate_items()>0) { // HAS TO VALIDATE if(!osc_is_web_user_logged_in()) { // NO USER IS LOGGED, VALIDATE $active = 'INACTIVE'; } else { // USER IS LOGGED if(osc_logged_user_item_validation()) { //USER IS LOGGED, BUT NO NEED TO VALIDATE $active = 'ACTIVE'; } else { // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id()); if($user['i_items']<osc_moderate_items()) { $active = 'INACTIVE'; } else { $active = 'ACTIVE'; } } } } else if(osc_moderate_items()==0 ){ if(osc_is_web_user_logged_in() && osc_logged_user_item_validation() ) { $active = 'ACTIVE'; } else { $active = 'INACTIVE'; } } else { $active = 'ACTIVE'; } } $aItem['active'] = $active; } else { // EDIT $aItem['secret'] = Params::getParam('secret'); $aItem['idItem'] = Params::getParam('id'); } // get params $aItem['catId'] = Params::getParam('catId'); $aItem['countryId'] = Params::getParam('countryId'); $aItem['country'] = Params::getParam('country'); $aItem['region'] = Params::getParam('region'); $aItem['regionId'] = Params::getParam('regionId'); $aItem['city'] = Params::getParam('city'); $aItem['cityId'] = Params::getParam('cityId'); $aItem['price'] = (Params::getParam('price') != '') ? Params::getParam('price') : null; $aItem['cityArea'] = Params::getParam('cityArea'); $aItem['address'] = Params::getParam('address'); $aItem['currency'] = Params::getParam('currency'); $aItem['showEmail'] = (Params::getParam('showEmail') != '') ? 1 : 0; $aItem['title'] = Params::getParam('title'); $aItem['description'] = Params::getParam('description'); $aItem['photos'] = Params::getFiles('photos'); $ajax_photos = Params::getParam('ajax_photos'); $aItem['s_ip'] = get_ip(); $aItem['d_coord_lat'] = (Params::getParam('d_coord_lat') != '') ? Params::getParam('d_coord_lat') : null; $aItem['d_coord_long'] = (Params::getParam('d_coord_long') != '') ? Params::getParam('d_coord_long') : null; $aItem['s_zip'] = (Params::getParam('zip') != '') ? Params::getParam('zip') : null; // $ajax_photos is an array of filenames of the photos uploaded by ajax to a temporary folder // fake insert them into the array of the form-uploaded photos if(is_array($ajax_photos)) { foreach($ajax_photos as $photo) { if(file_exists(osc_content_path().'uploads/temp/'.$photo)) { $aItem['photos']['name'][] = $photo; $aItem['photos']['type'][] = 'image/*'; $aItem['photos']['tmp_name'][] = osc_content_path().'uploads/temp/'.$photo; $aItem['photos']['error'][] = UPLOAD_ERR_OK; $aItem['photos']['size'][] = 0; } } } if($is_add || $this->is_admin) { $dt_expiration = Params::getParam('dt_expiration'); if($dt_expiration==-1) { $aItem['dt_expiration'] = ''; } else if($dt_expiration!='' && (preg_match('|^([0-9]+)$|', $dt_expiration, $match) || preg_match('|([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})|', $dt_expiration, $match))) { $aItem['dt_expiration'] = $dt_expiration; } else { $_category = Category::newInstance()->findByPrimaryKey($aItem['catId']); $aItem['dt_expiration'] = $_category['i_expiration_days']; } unset($dt_expiration); } else { $aItem['dt_expiration'] = ''; }; // check params $country = Country::newInstance()->findByCode($aItem['countryId']); if( count($country) > 0 ) { $countryId = $country['pk_c_code']; $countryName = $country['s_name']; } else { $countryId = null; $countryName = $aItem['country']; } $aItem['countryId'] = $countryId; $aItem['countryName'] = $countryName; if( $aItem['regionId'] != '' ) { if( intval($aItem['regionId']) ) { $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']); if( count($region) > 0 ) { $regionId = $region['pk_i_id']; $regionName = $region['s_name']; } } } else { $regionId = null; $regionName = $aItem['region']; if( $aItem['countryId'] != '' ) { $auxRegion = Region::newInstance()->findByName($aItem['region'], $aItem['countryId'] ); if($auxRegion){ $regionId = $auxRegion['pk_i_id']; $regionName = $auxRegion['s_name']; } } } $aItem['regionId'] = $regionId; $aItem['regionName'] = $regionName; if( $aItem['cityId'] != '' ) { if( intval($aItem['cityId']) ) { $city = City::newInstance()->findByPrimaryKey($aItem['cityId']); if( count($city) > 0 ) { $cityId = $city['pk_i_id']; $cityName = $city['s_name']; } } } else { $cityId = null; $cityName = $aItem['city']; if( $aItem['countryId'] != '' ) { $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId'] ); if($auxCity){ $cityId = $auxCity['pk_i_id']; $cityName = $auxCity['s_name']; } } } $aItem['cityId'] = $cityId; $aItem['cityName'] = $cityName; if( $aItem['cityArea'] == '' ) { $aItem['cityArea'] = null; } if( $aItem['address'] == '' ) { $aItem['address'] = null; } if( !is_null($aItem['price']) ) { $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price'])); $price = str_replace(osc_locale_dec_point(), '.', $price); $aItem['price'] = $price*1000000; //$aItem['price'] = (float) $aItem['price']; } if( $aItem['catId'] == ''){ $aItem['catId'] = 0; } if( $aItem['currency'] == '' ) { $aItem['currency'] = null; } $this->data = $aItem; }
</div> <div class="num-moderated-items" > <div> <?php printf(__("After %s validated listings the user doesn't need to validate the listings any more"), '<input type="text" class="input-small" name="num_moderate_items" value="' . (osc_moderate_items() == -1 ? '' : osc_moderate_items()) . '" />'); ?> <div class="help-box"> <?php _e('If the value is zero, it means that each listing must be validated'); ?> </div> </div> <div class="separate-top-medium"> <label> <input type="checkbox" <?php echo osc_logged_user_item_validation() ? 'checked="checked"' : ''; ?> name="logged_user_item_validation" value="1" /> <?php _e("Logged in users don't need to validate their listings"); ?> </label> </div> </div> <div class="separate-top-medium"> <label> <input type="checkbox" <?php echo osc_recaptcha_items_enabled() == '0' ? '' : 'checked="checked"'; ?> name="enabled_recaptcha_items" value="1" /> <?php
/** * Return an array with all data necessary for do the action (ADD OR EDIT) * @param <type> $is_add * @return array */ public function prepareData($is_add) { $aItem = array(); // prepare user $userId = null; if ($this->is_admin) { if (Params::getParam('userId') != '') { $userId = Params::getParam('userId'); } } else { $userId = Session::newInstance()->_get('userId'); if ($userId == '') { $userId = NULL; } } if ($is_add) { // ADD if ($this->is_admin) { $active = 'ACTIVE'; } else { if (osc_moderate_items() > 0) { // HAS TO VALIDATE if (!osc_is_web_user_logged_in()) { // NO USER IS LOGGED, VALIDATE $active = 'INACTIVE'; } else { // USER IS LOGGED if (osc_logged_user_item_validation()) { //USER IS LOGGED, BUT NO NEED TO VALIDATE $active = 'ACTIVE'; } else { // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id()); if ($user['i_items'] < osc_moderate_items()) { $active = 'INACTIVE'; } else { $active = 'ACTIVE'; } } } } else { if (osc_moderate_items() == 0) { if (osc_is_web_user_logged_in() && osc_logged_user_item_validation()) { $active = 'ACTIVE'; } else { $active = 'INACTIVE'; } } else { $active = 'ACTIVE'; } } } if ($userId != null) { $data = User::newInstance()->findByPrimaryKey($userId); $aItem['contactName'] = $data['s_name']; $aItem['contactEmail'] = $data['s_email']; Params::setParam('contactName', $data['s_name']); Params::setParam('contactEmail', $data['s_email']); } else { $aItem['contactName'] = Params::getParam('contactName'); $aItem['contactEmail'] = Params::getParam('contactEmail'); } $aItem['active'] = $active; $aItem['userId'] = $userId; } else { // EDIT $aItem['secret'] = Params::getParam('secret'); $aItem['idItem'] = Params::getParam('id'); if ($userId != null) { $data = User::newInstance()->findByPrimaryKey($userId); $aItem['contactName'] = $data['s_name']; $aItem['contactEmail'] = $data['s_email']; Params::setParam('contactName', $data['s_name']); Params::setParam('contactEmail', $data['s_email']); } else { $aItem['contactName'] = Params::getParam('contactName'); $aItem['contactEmail'] = Params::getParam('contactEmail'); } $aItem['userId'] = $userId; } // get params $aItem['catId'] = Params::getParam('catId'); $aItem['countryId'] = Params::getParam('countryId'); $aItem['country'] = Params::getParam('country'); $aItem['region'] = Params::getParam('region'); $aItem['regionId'] = Params::getParam('regionId'); $aItem['city'] = Params::getParam('city'); $aItem['cityId'] = Params::getParam('cityId'); $aItem['price'] = Params::getParam('price') != '' ? Params::getParam('price') : null; $aItem['cityArea'] = Params::getParam('cityArea'); $aItem['address'] = Params::getParam('address'); $aItem['currency'] = Params::getParam('currency'); $aItem['showEmail'] = Params::getParam('showEmail') != '' ? 1 : 0; $aItem['title'] = Params::getParam('title'); $aItem['description'] = Params::getParam('description'); $aItem['photos'] = Params::getFiles('photos'); // check params $country = Country::newInstance()->findByCode($aItem['countryId']); if (count($country) > 0) { $countryId = $country['pk_c_code']; $countryName = $country['s_name']; } else { $countryId = null; $countryName = $aItem['country']; } $aItem['countryId'] = $countryId; $aItem['countryName'] = $countryName; if ($aItem['regionId'] != '') { if (intval($aItem['regionId'])) { $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']); if (count($region) > 0) { $regionId = $region['pk_i_id']; $regionName = $region['s_name']; } } } else { $regionId = null; $regionName = $aItem['region']; if ($aItem['countryId'] != '') { $auxRegion = Region::newInstance()->findByName($aItem['region'], $aItem['countryId']); if ($auxRegion) { $regionId = $auxRegion['pk_i_id']; $regionName = $auxRegion['s_name']; } } } $aItem['regionId'] = $regionId; $aItem['regionName'] = $regionName; if ($aItem['cityId'] != '') { if (intval($aItem['cityId'])) { $city = City::newInstance()->findByPrimaryKey($aItem['cityId']); if (count($city) > 0) { $cityId = $city['pk_i_id']; $cityName = $city['s_name']; } } } else { $cityId = null; $cityName = $aItem['city']; if ($aItem['countryId'] != '') { $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId']); if ($auxCity) { $cityId = $auxCity['pk_i_id']; $cityName = $auxCity['s_name']; } } } $aItem['cityId'] = $cityId; $aItem['cityName'] = $cityName; if ($aItem['cityArea'] == '') { $aItem['cityArea'] = null; } if ($aItem['address'] == '') { $aItem['address'] = null; } if (!is_null($aItem['price'])) { $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price'])); $price = str_replace(osc_locale_dec_point(), '.', $price); $aItem['price'] = $price * 1000000; //$aItem['price'] = (float) $aItem['price']; } if ($aItem['catId'] == '') { $aItem['catId'] = 0; } if ($aItem['currency'] == '') { $aItem['currency'] = null; } $this->data = $aItem; }
public function sendEmails($aItem) { $item = $aItem['item']; $title = $aItem['title']; $contactEmail = $aItem['contactEmail']; $contactName = $aItem['contactName']; View::newInstance()->_exportVariableToView('item', $item); $mPages = new Page(); $locale = osc_current_user_locale(); /** * Send email to user requesting item activation */ if (osc_item_validation_enabled() && (!osc_logged_user_item_validation() || !osc_is_web_user_logged_in())) { $aPage = $mPages->findByInternalName('email_item_validation'); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item_url = osc_item_url(); $all = ''; if (isset($item['locale'])) { foreach ($item['locale'] as $locale => $data) { $locale_name = OSCLocale::newInstance()->listWhere("pk_c_code = '" . $locale . "'"); $all .= '<br/>'; if (isset($locale_name[0]) && isset($locale_name[0]['s_name'])) { $all .= __('Language') . ': ' . $locale_name[0]['s_name'] . '<br/>'; } else { $all .= __('Language') . ': ' . $locale . '<br/>'; } $all .= __('Title') . ': ' . $data['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $data['s_description'] . '<br/>'; $all .= '<br/>'; } } else { $all .= __('Title') . ': ' . $item['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $item['s_description'] . '<br/>'; } // Format activation URL $validation_url = osc_item_activate_url($item['s_secret'], $item['pk_i_id']); $words = array(); $words[] = array('{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}'); $words[] = array($all, $item['s_description'], $item['s_country'], $item['f_price'], $item['s_region'], $item['s_city'], $item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], osc_base_url(), $item['s_title'], $item_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); $emailParams = array('subject' => $title, 'to' => $contactEmail, 'to_name' => $contactName, 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); } /** * Send email to admin about the new item */ if (osc_notify_new_item()) { $aPage = $mPages->findByInternalName('email_admin_new_item'); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item_url = osc_item_url(); $all = ''; if (isset($item['locale'])) { foreach ($item['locale'] as $locale => $data) { $locale_name = OSCLocale::newInstance()->listWhere("pk_c_code = '" . $locale . "'"); $all .= '<br/>'; if (isset($locale_name[0]) && isset($locale_name[0]['s_name'])) { $all .= __('Language') . ': ' . $locale_name[0]['s_name'] . '<br/>'; } else { $all .= __('Language') . ': ' . $locale . '<br/>'; } $all .= __('Title') . ': ' . $data['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $data['s_description'] . '<br/>'; $all .= '<br/>'; } } else { $all .= __('Title') . ': ' . $item['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $item['s_description'] . '<br/>'; } // Format activation URL $validation_url = osc_item_activate_url($item['s_secret'], $item['pk_i_id']); // Format admin edit URL $admin_edit_url = osc_item_admin_edit_url($item['pk_i_id']); $words = array(); $words[] = array('{EDIT_LINK}', '{EDIT_URL}', '{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}'); $words[] = array('<a href="' . $admin_edit_url . '" >' . $admin_edit_url . '</a>', $admin_edit_url, $all, $item['s_description'], $item['s_country'], $item['f_price'], $item['s_region'], $item['s_city'], $item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], osc_base_url(), $item['s_title'], $item_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); $emailParams = array('subject' => $title, 'to' => osc_contact_email(), 'to_name' => 'admin', 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); } }