narnianguy
Писатель
- Регистрация
- 21 Апр 2010
- Сообщения
- 3
- Реакции
- 5
Druzja,
Ya platil dezender.net 8-10 evro dlja decodinga listings.php. Oni dekodirovali versia 6 i kod rabotaet v glavnon stranitse, stranitsa listings t.e v stranitse resultata. No vot daet error kogda otkrivayu detail.php.
Tam chto to problema s etom:
Mojet kto to iz vas sdelaet poloniy dubugging do kontsa? Polniy kod:
Ya platil dezender.net 8-10 evro dlja decodinga listings.php. Oni dekodirovali versia 6 i kod rabotaet v glavnon stranitse, stranitsa listings t.e v stranitse resultata. No vot daet error kogda otkrivayu detail.php.
Tam chto to problema s etom:
PHP:
while ($j < count( $used )) {
if ($used[$j] == $val) {
$again = 1;
continue;
}
++$j;
}
PHP:
<?php
/**
*info deleted
*
*/
class listings {
var $id = null;
var $error = null;
var $clean = null;
var $array = null;
var $tmp = null;
var $edit = null;
var $no_listings = null;
function listings($id = 0) {
global $db;
if ($id) {
$this->id = $id;
$this->array = array( );
$this->array = $db->fetchAssoc( 'select * from ' . TABLE_ADS . ' where `id`=' . $id );
return null;
}
$this->edit = 0;
}
function getid() {
return $this->id;
}
function setedit($val) {
$this->edit = $val;
}
function setnolistings($no) {
$this->no_listings = $no;
}
function nolistings() {
return $this->no_listings;
}
function delete($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res_del = $db->query( 'delete from ' . TABLE_ADS . ( '' . ' where `id`=\'' . $id . '\'' ) );
$pics = new pictures( );
$pics->deletePictures( $id );
actions::deletelisting( $id );
coupons::deletelisting( $id );
$res_del = $db->query( 'delete from ' . TABLE_OPTIONS . ( '' . ' where `object_id`=\'' . $id . '\' and `option`!=\'store\'' ) );
global $settings;
if ($settings['nologin_enabled']) {
$db->query( 'delete from ' . TABLE_ADS_EXTENSION . ( '' . ' where `id`=' . $id ) );
}
$res_del = $db->query( 'delete from ' . TABLE_FAVOURITES . ( '' . ' where `ad_id`=\'' . $id . '\'' ) );
}
function expired($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res_del = $db->query( 'update ' . TABLE_ADS . ( '' . ' set active=0, pending=0 where `id`=\'' . $id . '\'' ) );
$this->deleteOptions( $id );
$db->query( 'update ' . TABLE_ADS . ( '' . ' set `featured`=0, `highlited` = 0, `priority` = 1000 where id=\'' . $id . '\'' ) );
return 1;
}
function isexpired($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$timestamp = date( 'Y-m-d H:i:s' );
$res = $db->query( 'select count(*) from ' . TABLE_ADS . ( '' . ' where `id`=\'' . $id . '\' and date_expires<\'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\' ' ) );
if (0 < $db->numRows( $res )) {
return 1;
}
return 0;
}
function deletecateg($categ) {
global $db;
$result = $db->fetchRowList( 'select id from ' . TABLE_ADS . ( '' . ' where category_id=\'' . $categ . '\'' ) );
foreach ($result as $row) {
$this->delete( $row );
}
}
function deletepackage($pkg) {
global $db;
$result = $db->fetchRowList( 'select id from ' . TABLE_ADS . ( '' . ' where package_id=\'' . $pkg . '\'' ) );
foreach ($result as $row) {
$this->delete( $row );
}
}
function deleteuser($user) {
global $db;
$result = $db->fetchRowList( 'select id from ' . TABLE_ADS . ( '' . ' where user_id=\'' . $user . '\'' ) );
foreach ($result as $row) {
$this->delete( $row );
}
}
function setcategory($id, $cat) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `category_id`=' . $cat . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setpackage($id, $pkg) {
global $db;
$no_days = packages::getnodays( $pkg );
if ($no_days != 0) {
$expire = '' . ', `date_expires` = date_add(`date_added`, interval \'' . $no_days . '\' day)';
} else {
$expire = ', `date_expires` = \'\'';
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `package_id`=' . $pkg . ' ' . $expire . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setuserpackage($id, $pkg) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `usr_pkg`=' . $pkg . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setuserid($id, $user_id) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `user_id`=' . $user_id . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setpriority($id, $pri) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `priority`=' . $pri . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setfeatured($id, $val) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `featured`=' . $val . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function sethighlited($id, $val) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `highlited`=' . $val . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function setvideo($id, $val) {
global $db;
if ($val == 0) {
$db->query( 'delete from ' . TABLE_OPTIONS . ( '' . ' where `object_id` = ' . $id . ' and `option` like \'video\'' ) );
return 1;
}
$this->addOption( $id, 'video' );
return 1;
}
function geturltitle($id) {
global $db;
global $crt_lang;
global $ads_settings;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '`';
}
}
$title = $db->fetchRow( '' . 'select ' . $title_var . ' from ' . TABLE_ADS . ( '' . ' where `id`=\'' . $id . '\'' ) );
return _urlencode( $title );
}
function gettitle($id) {
global $db;
global $crt_lang;
global $ads_settings;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '`';
}
}
$title = $db->fetchRow( '' . 'select ' . $title_var . ' from ' . TABLE_ADS . ( '' . ' where `id`=\'' . $id . '\'' ) );
return $title;
}
function gettitles($id) {
global $db;
$arr = array( );
global $crt_lang;
global $ads_settings;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '`';
}
}
$title = $db->fetchRow( '' . 'select ' . $title_var . ' from ' . TABLE_ADS . ( '' . ' where `id`=\'' . $id . '\'' ) );
$arr['title'] = $title;
$arr['url_title'] = _urlencode( $title );
return $arr;
}
function activate($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `active`=1, `user_approved`=1 where `id`=\'' . $id . '\'' ) );
$pending = $db->query( 'select pending from ' . TABLE_ADS . ( '' . ' where id=\'' . $id . '\'' ) );
if ($pending) {
$this->ActivatePending( $id );
}
if ($this->isExpired( $id )) {
$this->renew( $id );
}
}
function activatelisting($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `active`=1, pending=0 where `id`=\'' . $id . '\'' ) );
if ($this->isExpired( $id )) {
$this->renew( $id );
}
$res_actions = $db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type like \'newad\' or type like \'renewad\' and object_id=' . $id ) );
global $ads_settings;
if ($ads_settings['alerts_enabled']) {
$alert = new alerts( );
$alert->checkImmediate( $id, $this->getListing( $id ) );
}
return 1;
}
function activatepending($id) {
global $db;
global $lng;
$db->query( 'update ' . TABLE_ADS . ' set active=1, pending=0, `user_approved` = 1 where id=' . $id );
$db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type=\'newad\' or type=\'renewad\' and object_id = ' . $id ) );
$nologin = 0;
$user_id = $this->getUser( $id );
if ($user_id) {
$user = new users( );
$user_details = $user->getUser( $user_id );
$username = $user_details['username'];
$user_email = $user_details['email'];
$user_contact = $user_details['contact_name'];
if (!$user_contact) {
$user_contact = $username;
}
} else {
$user_details = $this->getOwnerInfo( $id );
$username = '';
$user_email = $user_details['mgm_email'];
$user_contact = $user_details['mgm_name'];
$key = $user_details['activation'];
$nologin = 1;
}
$mails = new mail_templates( );
$mail2send = new mails( $user_email, $user_contact );
$mail_array = $mails->getVal( 'ad_publish_status' );
$subject = $mail_array['subject'];
$msg = $mail_array['content'];
$smarty_info = new Smarty( );
$smarty_info = smartyshowdbval( $smarty_info );
$smarty_info->assign( 'value', $msg );
if (!$user_id) {
$smarty_info->assign( 'nologin', 1 );
}
$smarty_info->assign( 'username', $username );
$smarty_info->assign( 'contact_name', $user_contact );
$smarty_info->assign( 'id', $id );
$smarty_info->assign( 'ad_id', $id );
$smarty_info->assign( 'admin_activated', 1 );
$smarty_info->assign( 'status', $lng['general']['active'] );
$smarty_info->assign( 'active', 1 );
$plan_name = $this->getPackageName( $id );
$smarty_info->assign( 'plan_name', $plan_name );
global $seo_settings;
global $config_live_site;
$mail_settings_cl = new mail_settings( );
$mails_settings = $mail_settings_cl->getAll( );
$html_mails = $mails_settings['html_mails'];
if ($html_mails) {
$amp = '&';
} else {
$amp = '&';
}
if (( $seo_settings['enable_mod_rewrite'] && !$nologin )) {
$url_title = listings::geturltitle( $id );
$details_link = $config_live_site . '/' . $id . '-' . $url_title . '/details.html';
} else {
$details_link = $config_live_site . '/details.php?id=' . $id;
if ($nologin) {
$details_link .= $amp . 'key=' . $key;
}
}
if ($html_mails) {
$details_link = '<a href="' . $details_link . '">' . $details_link . '</a>';
}
$smarty_info->assign( 'details_link', $details_link );
$msg = $smarty_info->fetch( 'db_template.html' );
$smarty_info->assign( 'value', $subject );
$subject = $smarty_info->fetch( 'db_template.html' );
$mail2send->setSubject( $subject );
$mail2send->setMessage( $msg );
$mail2send->send( );
global $ads_settings;
if ($ads_settings['alerts_enabled']) {
$alert = new alerts( );
$alert->checkImmediate( $id, $this->getListing( $id ) );
}
}
function deactivate($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `active`=0 where `id`=\'' . $id . '\'' ) );
}
function userapprove($id) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `user_approved`=1 where `id`=\'' . $id . '\'' ) );
}
function nologinapprove($id) {
global $db;
global $settings;
if (!$id) {
$id = $this->id;
}
$this->userApprove( $id );
$actions = actions::getpendinglistingactions( $id );
$array_upgrades = array( 'featured', 'highlited', 'priority', 'video' );
$array_ad = array( 'newad', 'renewad' );
$upgrade = 0;
$ad_pending = 0;
foreach ($actions as $act) {
if (in_array( $act['type'], $array_upgrades )) {
$upgrade = 1;
}
if (in_array( $act['type'], $array_ad )) {
$ad_pending = 1;
continue;
}
}
if (( $ad_pending || $upgrade )) {
$this->makePending( $id );
$result = $db->fetchAssoc( 'SELECT `' . TABLE_ACTIONS . '`.invoice, `' . TABLE_PAYMENT_ACTIONS . '`.processor from `' . TABLE_ACTIONS . '` left join `' . TABLE_PAYMENT_ACTIONS . '` on `' . TABLE_PAYMENT_ACTIONS . '`.id = `' . TABLE_ACTIONS . '`.`invoice` where (`object_id` = ' . $id . ' and (`type` like \'newad\' or `type` like \'renewad\'))' );
$processor = $result['processor'];
$invoice_no = $result['invoice'];
$user_details = $this->getOwnerInfo( $id );
$contact_name = $user_details['mgm_name'];
global $seo_settings;
global $config_live_site;
$titles = $this->getTitles( $id );
if ($seo_settings['enable_mod_rewrite']) {
$url_title = $titles['url_title'];
$details_link = $config_live_site . '/' . $id . '-' . $url_title . '/details.html';
} else {
$details_link = $config_live_site . '/details.php?id=' . $id;
}
$mails = new mail_templates( );
$mail_array = $mails->getVal( 'admin_announce_pending' );
$smarty_info = new Smarty( );
$smarty_info = smartyshowdbval( $smarty_info );
$smarty_info->assign( 'value', $mail_array['subject'] );
$smarty_info->assign( 'processor', $processor );
$mail_subject = $smarty_info->fetch( 'db_template.html' );
$smarty_info->assign( 'value', $mail_array['content'] );
$smarty_info->assign( 'ad_id', $id );
$smarty_info->assign( 'details_link', $details_link );
$smarty_info->assign( 'ad_pending', $ad_pending );
$smarty_info->assign( 'upgrade', $upgrade );
$smarty_info->assign( 'invoice_no', $invoice_no );
$smarty_info->assign( 'nologin', 1 );
$smarty_info->assign( 'contact_name', $contact_name );
$mail_content = $smarty_info->fetch( 'db_template.html' );
$mail2admin = new mails( );
$mail2admin->setSubject( $mail_subject );
$mail2admin->setMessage( $mail_content );
$mail2admin->send( );
return null;
}
$this->ActivatePending( $id );
}
function marksold($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `sold`=1 where `id`=\'' . $id . '\'' ) );
}
function markunsold($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `sold`=0 where `id`=\'' . $id . '\'' ) );
}
function markrented($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `rented`=1 where `id`=\'' . $id . '\'' ) );
}
function markunrented($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `rented`=0 where `id`=\'' . $id . '\'' ) );
}
function addoption($id, $type, $noexp = 0) {
global $db;
$db->query( 'delete from ' . TABLE_OPTIONS . ( '' . ' where `object_id` = ' . $id . ' and `option` like \'' . $type . '\'' ) );
$timestamp = date( 'Y-m-d H:i:s' );
if (!$noexp) {
global $ads_settings;
switch ($type) {
case 'featured': {
$days_expires = $ads_settings['featured_expires'];
break;
}
case 'highlited': {
$days_expires = $ads_settings['highlited_expires'];
break;
}
case 'priority': {
$days_expires = $ads_settings['priorities_expires'];
break;
}
case 'video': {
$days_expires = $ads_settings['video_expires'];
}
}
if ($days_expires) {
$str_expires = '' . ' `date_expires` = date_add(\'' . $timestamp . '\', interval \'' . $days_expires . '\' day)';
} else {
$str_expires = ' `date_expires` = \'\'';
}
} else {
$str_expires = ' `date_expires` = \'\'';
}
$db->query( 'insert into ' . TABLE_OPTIONS . ( '' . ' set `object_id` = \'' . $id . '\', `option` = \'' . $type . '\', `date_added` = \'' . $timestamp . '\', ' . $str_expires . ' ' ) );
return 1;
}
function makefeatured($id) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `featured`=1 where `id`=\'' . $id . '\'' ) );
$this->addOption( $id, 'featured' );
$res_actions = $db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type like \'featured\' and object_id=' . $id ) );
}
function makehighlited($id) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `highlited`=1 where `id`=\'' . $id . '\'' ) );
$this->addOption( $id, 'highlited' );
$res_actions = $db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type like \'highlited\' and object_id=' . $id ) );
}
function enablepriority($id, $pri) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `priority`=' . $pri . ' where `id`=\'' . $id . '\'' ) );
$this->addOption( $id, 'priority' );
$res_actions = $db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type like \'priority\' and object_id=' . $id ) );
}
function enablevideo($id) {
global $db;
if (!$id) {
$id = $this->id;
}
$this->addOption( $id, 'video' );
$res_actions = $db->query( 'update ' . TABLE_ACTIONS . ( '' . ' set pending=0 where type like \'video\' and object_id=' . $id ) );
}
function videoenabled($id) {
global $db;
$no = $db->fetchRow( 'select count(`object_id`) from ' . TABLE_OPTIONS . ( '' . ' where `option` like \'video\' and `object_id` = \'' . $id . '\'' ) );
return $no;
}
function renew($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$pkg_id = $this->getPackage( $id );
if ($pkg_id) {
$pkg = new packages( );
$no_days = $pkg->getNoDays( $pkg_id );
} else {
global $ads_settings;
$no_days = $ads_settings['expires'];
}
$timestamp = date( 'Y-m-d H:i:s' );
if ($no_days != 0) {
$sql_exp = '' . '`date_expires` = date_add(\'' . $timestamp . '\', interval \'' . $no_days . '\' day)';
} else {
$sql_exp = '`date_expires` = null';
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `active`=1, date_added=\'' . $timestamp . '\', ' . $sql_exp . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function renewuser($id) {
global $db;
if (!$id) {
return null;
}
$pkg_id = $this->getPackage( $id );
if ($pkg_id) {
$pkg = new packages( );
$no_days = $pkg->getNoDays( $pkg_id );
} else {
global $ads_settings;
$no_days = $ads_settings['expires'];
}
$timestamp = date( 'Y-m-d H:i:s' );
if ($no_days != 0) {
$sql_exp = '' . '`date_expires` = date_add(\'' . $timestamp . '\', interval \'' . $no_days . '\' day)';
} else {
$sql_exp = '`date_expires` = null';
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set date_added=\'' . $timestamp . '\', ' . $sql_exp . ' where `id`=\'' . $id . '\'' ) );
return 1;
}
function makepending($id) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set pending=1, active=0 where `id`=\'' . $id . '\'' ) );
}
function ispending($id) {
global $db;
$pending = $db->query( 'select pending from ' . TABLE_ADS . ( '' . ' where id=\'' . $id . '\'' ) );
return $pending;
}
function getcategory($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$row = $db->fetchRow( 'select category_id from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (!$row) {
return 0;
}
return $row;
}
function getpackage($id) {
global $db;
if (!$id) {
$id = $this->id;
}
$row = $db->fetchRow( 'select package_id from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (!$row) {
return 0;
}
return $row;
}
function getpackagename($id) {
global $db;
global $crt_lang;
if (!$id) {
$id = $this->id;
}
$row = $db->fetchRow( 'select `name` from ' . TABLE_PACKAGES . '_lang left join ' . TABLE_ADS . ' on ' . TABLE_ADS . '.package_id = ' . TABLE_PACKAGES . '_lang.`id` where ' . TABLE_ADS . ( '' . '.id = \'' . $id . '\' and `lang_id` = \'' . $crt_lang . '\'' ) );
if (!$row) {
return 0;
}
return $row;
}
function getuserpackage($id) {
global $db;
if (!$id) {
$id = $this->id;
}
$row = $db->fetchRow( 'select usr_pkg from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (!$row) {
return 0;
}
return $row;
}
function getuser($id) {
global $db;
if (!$id) {
$id = $this->id;
}
$row = $db->fetchRow( 'select user_id from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (!$row) {
return 0;
}
return $row;
}
function getadoptions($id) {
global $db;
$result = $db->fetchAssoc( 'select `featured`, `highlited`, `priority`, ' . TABLE_PRIORITIES . '_lang.name as `priority_name`, ' . TABLE_OPTIONS . '.`object_id` as `enabled_video` from ' . TABLE_ADS . '
left join ' . TABLE_PRIORITIES . ' on ' . TABLE_ADS . '.`priority` = ' . TABLE_PRIORITIES . '.`order_no`
left join ' . TABLE_PRIORITIES . '_lang on ' . TABLE_PRIORITIES . '.`id` = ' . TABLE_PRIORITIES . '_lang.`id`
left join ' . TABLE_OPTIONS . ' on ' . TABLE_ADS . '.`id` = ' . TABLE_OPTIONS . '.`object_id` and `option` like \'video\'
where ' . TABLE_ADS . ( '' . '.`id` = ' . $id ) );
$result_ext = $db->fetchAssocList( 'select * from ' . TABLE_ACTIONS . ( '' . ' where `pending`=1 and `object_id` = ' . $id . ' and (`type` like \'featured\' or `type` like \'highlited\' or `type` like \'priority\' or `type` like \'video\')' ) );
foreach ($result_ext as $action) {
if ($action['type'] == 'featured') {
$result['pending_featured'] = 1;
}
if ($action['type'] == 'highlited') {
$result['pending_highlited'] = 1;
}
if ($action['type'] == 'priority') {
$result['pending_priority'] = 1;
$result['pending_priority_order'] = $action['extra'];
$pri = new priorities( );
$result['pending_priority_name'] = $pri->getNameByOrder( $action['extra'] );
}
if ($action['type'] == 'video') {
$result['pending_video'] = 1;
continue;
}
}
return $result;
}
function getnoactive($cat) {
global $db;
if (0 < $cat) {
$cat_str = '' . ' and category_id=\'' . $cat . '\'';
} else {
$cat_str = '';
}
$no = $db->fetchRow( 'select count(*) from ' . TABLE_ADS . ' where active=1' . $cat_str );
return $no;
}
function getnorecent() {
global $db;
global $ads_settings;
$days_recent = $ads_settings['days_recent'];
$timestamp = date( 'Y-m-d H:i:s' );
if (0 < $days_recent) {
$sql = 'select count(*) from ' . TABLE_ADS . ( '' . ' where active=1 and date_add(date_added, interval \'' . $days_recent . '\' day) > \'' . $timestamp . '\'' );
} else {
$sql = 'select count(*) from ' . TABLE_ADS . ' where active=1';
}
$no = $db->fetchRow( $sql );
return $no;
}
function getallactive($page, $ads_per_page, $order_by, $order_way, $cat) {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . ( '' . '.category_id=\'' . $cat . '\' and ' ) . TABLE_ADS . '.active=1';
if (!$order_by) {
$order_by = 'date_added';
}
if (!$order_way) {
$order_way = 'desc';
}
global $ads_settings;
if ($ads_settings['enable_priorities']) {
$order_by_str = 'order by priority asc, ' . $order_by . ' ' . $order_way;
} else {
$order_by_str = 'order by ' . $order_by . ' ' . $order_way;
}
$result = $this->getShortListings( $where, $order_by_str, '', $start, $ads_per_page );
return $result;
}
function getstorelistings($page, $ads_per_page, $order_by, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.active like \'1\'';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id like \'' . $crt_usr . '\'' );
}
if (!$order_by) {
$order_by = 'date_added';
}
if (!$order_way) {
$order_way = 'desc';
}
global $ads_settings;
if ($ads_settings['enable_priorities']) {
$order_by_str = 'order by priority asc, ' . $order_by . ' ' . $order_way;
} else {
$order_by_str = 'order by ' . $order_by . ' ' . $order_way;
}
$result = $this->getShortListings( $where, $order_by_str, '', $start, $ads_per_page );
return $result;
}
function getrecent($page, $ads_per_page, $order_by, $order_way) {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
global $ads_settings;
$days_recent = $ads_settings['days_recent'];
$timestamp = date( 'Y-m-d H:i:s' );
if (0 < $days_recent) {
$where = 'where date_add(' . TABLE_ADS . ( '' . '.date_added, interval \'' . $days_recent . '\' day) > \'' . $timestamp . '\' and ' ) . TABLE_ADS . '.active like \'1\'';
} else {
$where = 'where ' . TABLE_ADS . '.active like \'1\'';
}
if (!$order_by) {
$order_by = 'date_added';
}
$order_by_str = 'order by ' . $order_by;
if (!$order_way) {
$order_way = 'desc';
}
$result = $this->getShortListings( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getfeatured($no_featured, $where = '') {
global $db;
$where = 'where ' . TABLE_ADS . '.featured=1 and ' . TABLE_ADS . '.active like \'1\'' . $where;
$order_by_str = 'order by rand()';
$order_way = '';
$start = 0;
$ads_per_page = $no_featured;
$result = $this->getShortListings( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getlatest($no_latest, $where = '') {
global $db;
$where = 'where ' . TABLE_ADS . '.active like \'1\'' . $where;
$order_by_str = 'order by date_added desc';
$order_way = '';
$start = 0;
$ads_per_page = $no_latest;
$result = $this->getShortListings( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getrandom($no_random) {
global $db;
$where = 'where ' . TABLE_ADS . '.active=1';
$order_by_str = 'order by rand()';
$order_way = '';
$start = 0;
$ads_per_page = $no_random;
$result = $this->getShortListings( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getlist($list) {
global $db;
global $appearance_settings;
$where = 'where ' . TABLE_ADS . ( '' . '.`id` in (' . $list . ')' );
$order_by_str = '';
$order_way = '';
$start = 0;
$ads_per_page = $appearance_settings['ads_per_page'];
$result = $this->getShortListings( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getrandomvideo($no_random) {
global $db;
$where = ' where `object_id`';
$order_by_str = 'order by rand()';
$order_way = '';
$start = 0;
$ads_per_page = $no_random;
$result = $this->getListingsDetailed( $where, $order_by_str, $order_way, $start, $ads_per_page );
return $result;
}
function getlastlistings($no) {
global $db;
global $appearance_settings;
$date_format = $appearance_settings['date_format'];
global $crt_lang;
global $ads_settings;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '`';
}
}
$sql = 'select ' . TABLE_ADS . '.id, ' . TABLE_ADS . ( '' . '.' . $title_var . ', ' ) . TABLE_ADS . ( '' . '.user_id, date_format(`date_added`,\'' . $date_format . '\') as `date`, ' ) . TABLE_USERS . '.username as user from ' . TABLE_ADS . ' left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id order by date_added desc limit ' . $no;
$array_listings = $db->fetchAssocList( $sql );
return $array_listings;
}
function getlisting($id) {
global $db;
global $lng;
global $appearance_settings;
global $ads_settings;
global $settings;
$date_format = $appearance_settings['date_format'];
if (!$id) {
$id = $this->id;
}
global $crt_lang;
$mlang_vars = '';
$mlang = 0;
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$mlang = 1;
$mlang_vars = '' . ',`title_' . $crt_lang . '` as `title`, `description_' . $crt_lang . '` as `description` ';
}
}
$join_nologin = '';
$select_nologin = '';
if ($settings['nologin_enabled']) {
$join_nologin = ' left join ' . TABLE_ADS_EXTENSION . ' on ' . TABLE_ADS . '.id = ' . TABLE_ADS_EXTENSION . '.id';
$select_nologin = ', ' . TABLE_ADS_EXTENSION . '.mgm_email, ' . TABLE_ADS_EXTENSION . '.mgm_name';
}
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select ' . TABLE_ADS . ( '' . '.*' . $mlang_vars . ', date_format(' ) . TABLE_ADS . ( '' . '.`date_added`,\'' . $date_format . '\') as date_nice, date_format(' ) . TABLE_ADS . ( '' . '.`date_expires`,\'' . $date_format . '\') as date_expires_nice, (' ) . TABLE_ADS . ( '' . '.`date_expires`<\'' . $timestamp . '\' and ' ) . TABLE_ADS . '.`date_expires`!=\'0000-00-00 00:00:00\' and ' . TABLE_ADS . '.active=0) as expired, ' . TABLE_CATEGORIES . '_lang.name as category, ' . TABLE_PACKAGES . '_lang.name as package, ' . TABLE_PACKAGES . '.amount as amount, ' . TABLE_USERS . '.username as username,
(' . TABLE_OPTIONS . '.`object_id` is not null and ' . TABLE_OPTIONS . ( '' . '.`option` like \'video\') as `enable_video`' . $select_nologin . ' from ' ) . TABLE_ADS . '
left join ' . TABLE_CATEGORIES . '_lang on ( ' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id and ' . TABLE_CATEGORIES . ( '' . '_lang.`lang_id` = \'' . $crt_lang . '\')
left join ' ) . TABLE_PACKAGES . '_lang on (' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '_lang.id and ' . TABLE_PACKAGES . ( '' . '_lang.`lang_id` = \'' . $crt_lang . '\')
left join ' ) . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_OPTIONS . ' on ' . TABLE_ADS . '.`id` = ' . TABLE_OPTIONS . ( '' . '.`object_id` and `option` like \'video\'
' . $join_nologin . '
where ' ) . TABLE_ADS . ( '' . '.`id`=\'' . $id . '\'' );
$result = $db->fetchAssoc( $sql );
foreach ($result as $key => $value) {
$result[$key] = clean( $result[$key] );
}
if ($mlang) {
$default_title = '';
$default_description = '';
foreach ($languages as $l) {
$lang_id = $l['id'];
$result[$lang_id] = array( );
$result[$lang_id]['title'] = $result['title_' . $lang_id];
$result[$lang_id]['description'] = $result['description_' . $lang_id];
if ($l['default'] == 1) {
$default_title = $result['title_' . $lang_id];
$default_description = $result['description_' . $lang_id];
continue;
}
}
if (!$result['title']) {
$result['title'] = $default_title;
if (!$result['title']) {
foreach ($languages as $l) {
if ($result['title_' . $l['id']]) {
$result['title'] = $result['title_' . $l['id']];
break;
}
}
}
}
if (!$result['description']) {
$result['description'] = $default_description;
if (!$result['description']) {
foreach ($languages as $l) {
if ($result['description_' . $l['id']]) {
$result['description'] = $result['description_' . $l['id']];
break;
}
}
}
}
}
$result['description_formatted'] = str_replace( '
', '<br>', $result['description'] );
$pictures = new pictures( );
$result['images'] = $pictures->getPictures( $id );
$no_images = count( $result['images'] );
$result['max_height'] = 0;
$str_preload = '';
global $config_live_site;
$im = 0;
while ($im < $no_images) {
if ($im) {
$str_preload .= ',';
}
$str_preload .= $config_live_site . '/images/listings/bigThmb/' . $result['images'][$im]['picture'];
if ($result['max_height'] < $result['images'][$im]['thmb_height']) {
$result['max_height'] = $result['images'][$im]['thmb_height'];
}
++$im;
}
$result['preload_images'] = $str_preload;
$result['stock'] = sprintf( '%04d', $id );
$result['paid'] = 0;
if (0 < $result['amount']) {
$result['paid'] = 1;
}
$cat = new categories( );
$result['fieldset'] = $cat->getFieldset( $result['category_id'] );
$f = new fields( 'cf' );
$fields = $f->getAll( $result['fieldset'] );
foreach ($fields as $field) {
$fname = $field['caption'];
if (( $field['type'] == 'checkbox_group' || $field['type'] == 'multiselect' )) {
if ($result[$fname]) {
$result[$fname] = explode( '|', $result[$fname] );
continue;
}
$result[$fname] = array( );
continue;
}
if ($field['type'] == 'date') {
if (( $result[$fname] && $result[$fname] != '0000-00-00' )) {
$result['vis'][$fname] = format_date_str( $result[$fname], $field['date_format'] );
continue;
}
$result[$fname] = '';
continue;
}
if ($field['type'] == 'price') {
$result['formatted'][$fname] = format_price( $result[$fname] );
continue;
}
if ($field['validation_type'] == 'numeric') {
$result['formatted'][$fname] = format_numeric( $result[$fname] );
continue;
}
if ($field['type'] == 'textarea') {
$result['formatted'][$fname] = str_replace( '
', '<br>', $result[$fname] );
continue;
}
}
$result['price_curr'] = add_currency( format_price( $result['price'] ), $result['currency'] );
if (( $ads_settings['enable_priorities'] && $result['priority'] < 1000 )) {
$result['priority_name'] = priorities::getnamebyorder( $result['priority'] );
}
$users = new users( );
$result['user'] = $users->getUser( $result['user_id'] );
if ($result['language'] != $crt_lang) {
$language = new languages( );
$result = $language->translateFieldsElements( $result, 'cf' );
}
return $result;
}
function getnoshortlistings($where, $q_join = '') {
global $db;
$join_pictures = '';
if (strstr( $where, TABLE_ADS_PICTURES )) {
$join_pictures = 'left join ' . TABLE_ADS_PICTURES . ' on ' . TABLE_ADS . '.id=' . TABLE_ADS_PICTURES . '.ad_id ';
}
$join_users = '';
if (strstr( $where, TABLE_USERS )) {
$join_users = 'left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id ';
}
$sql = 'select count( distinct ' . TABLE_ADS . '.id)
from ' . TABLE_ADS . ( '' . '
' . $join_pictures . '
' . $join_users . '
' . $q_join . '
' ) . $where;
$no_ads = $db->fetchRow( $sql );
return $no_ads;
}
function getshortlistings($where, $order_by, $order_way, $general_row, $ads_per_page, $search = '', $q_vars = '', $q_join = '') {
global $db;
global $lng;
global $appearance_settings;
global $ads_settings;
$date_format = $appearance_settings['date_format'];
global $crt_lang;
$mlang = 0;
$mlang_vars = '';
$group_by = '';
$languages = languages::getactivelanguages( );
$no_languages = count( $languages );
if (( $ads_settings['translate_title_description'] && 1 < $no_languages )) {
$mlang = 1;
$mlang_vars = '' . ',`title_' . $crt_lang . '` as `title`, `description_' . $crt_lang . '` as `description` ';
}
$group_by = ' group by ' . TABLE_ADS . '.id ';
if ($ads_settings['enable_priorities']) {
$pri_name = ', ' . TABLE_PRIORITIES . '_lang.name as `priority_name`';
$pri_join = 'LEFT JOIN ' . TABLE_PRIORITIES . ' on ' . TABLE_ADS . '.priority=' . TABLE_PRIORITIES . '.order_no
LEFT JOIN ' . TABLE_PRIORITIES . '_lang on ' . TABLE_PRIORITIES . '.id=' . TABLE_PRIORITIES . '_lang.id ';
} else {
$pri_name = '';
$pri_join = '';
}
if ($ads_settings['enable_video']) {
$video = ', (' . TABLE_OPTIONS . '.`object_id` is not null and ' . TABLE_OPTIONS . '.`option` like \'video\') as `enable_video` ';
$video_join = ' left join ' . TABLE_OPTIONS . ' on ' . TABLE_ADS . '.`id` = ' . TABLE_OPTIONS . '.`object_id` and `option` like \'video\' ';
} else {
$video = '';
$video_join = '';
}
if ($where) {
$where .= ' and ';
} else {
$where = ' where ';
}
$where .= ' ( ' . TABLE_ADS_PICTURES . '.`id` is null or ' . TABLE_ADS_PICTURES . '.`order_no`<=1)';
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select ' . TABLE_ADS . ( '' . '.*' . $mlang_vars . ', ' ) . TABLE_ADS . '.id as adid, ' . TABLE_ADS_PICTURES . '.picture, ' . TABLE_ADS_PICTURES . '.`id` as `picture_id`, date_format(' . TABLE_ADS . ( '' . '.`date_added`,\'' . $date_format . '\') as date_nice, date_format(' ) . TABLE_ADS . ( '' . '.`date_expires`,\'' . $date_format . '\') as date_expires_nice, (' ) . TABLE_ADS . ( '' . '.date_expires < \'' . $timestamp . '\' and ' ) . TABLE_ADS . '.date_expires!=\'0000-00-00 00:00:00\' and ' . TABLE_ADS . '.active=0) as expired, ' . TABLE_CATEGORIES . '_lang.name as category, ' . TABLE_PACKAGES . '.amount as amount, ' . TABLE_USERS . ( '' . '.username as username ' . $pri_name . ' ' . $video . ' ' . $q_vars . ' from ' ) . TABLE_ADS . '
LEFT JOIN ' . TABLE_CATEGORIES . '_lang on (' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id and ' . TABLE_CATEGORIES . ( '' . '_lang.`lang_id` = \'' . $crt_lang . '\')
LEFT JOIN ' ) . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
LEFT JOIN ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
LEFT JOIN ' . TABLE_ADS_PICTURES . ' on ' . TABLE_ADS . '.id=' . TABLE_ADS_PICTURES . ( '' . '.ad_id
' . $pri_join . '
' . $video_join . '
' . $q_join . '
' ) . $where . $group_by . ' ' . $order_by . ' ' . $order_way . ' ';
if (0 < $ads_per_page) {
$sql .= ' limit ' . $general_row . ', ' . $ads_per_page;
}
$arr = $db->fetchAssocList( $sql );
$i = 0;
$result = array( );
$pictures = new pictures( );
$nopic = $ads_settings['nopic'];
if ($search) {
$search = str_replace( '(', '\(', $search );
$search = str_replace( ')', '\)', $search );
$search_array = explode( '%20', $search );
$no_words = count( $search_array );
} else {
$no_words = 0;
}
foreach ($arr as $row) {
$result[$i] = $row;
foreach ($result[$i] as $key => $value) {
$result[$i][$key] = clean( $result[$i][$key] );
}
if ($i % 2) {
$result[$i]['style'] = '_odd';
} else {
$result[$i]['style'] = '_even';
}
$result[$i]['id'] = $result[$i]['adid'];
if ($result[$i]['picture']) {
$result[$i]['image'] = 'images/listings/thmb/' . $result[$i]['picture'];
$result[$i]['image_id'] = $result[$i]['picture_id'];
} else {
$result[$i]['image'] = 'images/' . $nopic;
$result[$i]['image_id'] = 0;
}
$result[$i]['paid'] = 0;
if (0 < $result[$i]['amount']) {
$result[$i]['paid'] = 1;
}
$result[$i]['price_curr'] = add_currency( format_price( $result[$i]['price'] ), $result[$i]['currency'] );
if ($result[$i]['language'] != $crt_lang) {
$language = new languages( );
$result[$i] = $language->translateFieldsElements( $result[$i], 'cf' );
}
if ($ads_settings['location_fields']) {
$loc_fields = explode( ',', $ads_settings['location_fields'] );
$result[$i]['location_str'] = '';
$k = 0;
foreach ($loc_fields as $l) {
if (!$l) {
continue;
}
if ($result[$i][$l]) {
if ($k) {
$result[$i]['location_str'] .= ', ';
}
$result[$i]['location_str'] .= $result[$i][$l];
++$k;
continue;
}
}
}
if ($mlang) {
$default_title = '';
$default_description = '';
foreach ($languages as $l) {
$lang_id = $l['id'];
if ($l['default'] == 1) {
$default_title = $result[$i]['title_' . $lang_id];
$default_description = $result[$i]['description_' . $lang_id];
break;
}
}
if (!$result[$i]['title']) {
$result[$i]['title'] = $default_title;
if (!$result[$i]['title']) {
foreach ($languages as $l) {
if ($result[$i]['title_' . $l['id']]) {
$result[$i]['title'] = $result[$i]['title_' . $l['id']];
break;
}
}
}
}
if (!$result[$i]['description']) {
$result[$i]['description'] = $default_description;
if (!$result[$i]['description']) {
foreach ($languages as $l) {
if ($result[$i]['description_' . $l['id']]) {
$result[$i]['description'] = $result[$i]['description_' . $l['id']];
break;
}
}
}
}
}
$k = $no_words;
while (0 < $k) {
$w = trim( $search_array[$k - 1] );
if ($w != '') {
$result[$i]['description'] = preg_replace( '/' . $search_array[$k - 1] . '/i', '<font class="search">' . $search_array[$k - 1] . '</font>', $result[$i]['description'] );
$result[$i]['title'] = preg_replace( '/' . $search_array[$k - 1] . '/', '<font class="search">' . $search_array[$k - 1] . '</font>', $result[$i]['title'] );
}
--$k;
}
$result[$i]['stock'] = sprintf( '%04d', $result[$i]['adid'] );
$result[$i]['url_title'] = _urlencode( $result[$i]['title'] );
++$i;
}
return $result;
}
function getlistingsdetailed($where, $order_by = '', $order_way = '', $general_row = '', $ads_per_page = '') {
global $db;
global $lng;
global $appearance_settings;
global $ads_settings;
$newLine = '
';
$date_format = $appearance_settings['date_format'];
global $crt_lang;
$mlang = 0;
$mlang_vars = '';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$mlang = 1;
$mlang_vars = '' . ',`title_' . $crt_lang . '` as `title`, `description_' . $crt_lang . '` as `description` ';
}
}
if ($where) {
$where .= ' and ';
} else {
$where = ' where ';
}
$where .= ' ( ' . TABLE_ADS_PICTURES . '.`id` is null or ' . TABLE_ADS_PICTURES . '.`order_no`<=1)';
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select ' . TABLE_ADS . ( '' . '.*' . $mlang_vars . ', ' ) . TABLE_ADS . '.id as adid, ' . TABLE_ADS_PICTURES . '.picture, ' . TABLE_ADS_PICTURES . '.`id` as `picture_id`, date_format(' . TABLE_ADS . ( '' . '.`date_added`,\'' . $date_format . '\') as date_nice, date_format(' ) . TABLE_ADS . ( '' . '.`date_expires`,\'' . $date_format . '\') as date_expires_nice, (' ) . TABLE_ADS . ( '' . '.date_expires<\'' . $timestamp . '\' and ' ) . TABLE_ADS . '.date_expires!=\'0000-00-00 00:00:00\' and ' . TABLE_ADS . '.active=0) as expired, ' . TABLE_CATEGORIES . '_lang.name as category, ' . TABLE_PACKAGES . '_lang.name as package, ' . TABLE_PACKAGES . '.amount as amount, ' . TABLE_USERS . '.username as username, ' . TABLE_USERS_PACKAGES . '.pending as pending_package,
(' . TABLE_OPTIONS . '.`object_id` is not null and ' . TABLE_OPTIONS . '.`option` like \'video\') as `enable_video` from ' . TABLE_ADS . '
left join ' . TABLE_CATEGORIES . '_lang on (' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id and ' . TABLE_CATEGORIES . ( '' . '_lang.`lang_id` = \'' . $crt_lang . '\')
left join ' ) . TABLE_PACKAGES . '_lang on (' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '_lang.id and ' . TABLE_PACKAGES . ( '' . '_lang.`lang_id` = \'' . $crt_lang . '\')
left join ' ) . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
left join ' . TABLE_USERS_PACKAGES . ' on ' . TABLE_ADS . '.usr_pkg=' . TABLE_USERS_PACKAGES . '.id
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_ADS_PICTURES . ' on ' . TABLE_ADS . '.id=' . TABLE_ADS_PICTURES . '.ad_id
left join ' . TABLE_OPTIONS . ' on ' . TABLE_ADS . '.`id` = ' . TABLE_OPTIONS . '.`object_id` and `option` like \'video\'
' . $where;
if ($order_by) {
$sql .= ' ' . $order_by . ' ' . $order_way;
}
if (0 < $ads_per_page) {
$sql .= ' limit ' . $general_row . ', ' . $ads_per_page;
}
$arr = $db->fetchAssocList( $sql );
$i = 0;
$result = array( );
$pictures = new pictures( );
$nopic = $ads_settings['nopic'];
$currency_pos = $appearance_settings['currency_pos'];
foreach ($arr as $row) {
$result[$i] = $row;
foreach ($result[$i] as $key => $value) {
$result[$i][$key] = clean( $result[$i][$key] );
}
$result[$i]['id'] = $result[$i]['adid'];
$result[$i]['pending_actions'] = $db->fetchAssocList( 'SELECT `' . TABLE_ACTIONS . '`.*, `' . TABLE_PAYMENT_ACTIONS . '`.completed from `' . TABLE_ACTIONS . '` left join `' . TABLE_PAYMENT_ACTIONS . '` on `' . TABLE_PAYMENT_ACTIONS . '`.id = `' . TABLE_ACTIONS . '`.`invoice` where (`object_id` = ' . $row['id'] . ' and `pending` = 1 and (`type` like \'featured\' or `type` like \'highlited\' or `type` like \'priority\' or `type` like \'video\' or `type` like \'newad\' or `type` like \'renewad\')) or (`object_id` = \'' . $row['usr_pkg'] . '\' and `pending` = 1 and (`type` like \'newpkg\' or `type` like \'renewpkg\') ) order by `invoice` ,' . TABLE_ACTIONS . '.`date` desc' );
$result[$i]['pending_info'] = '';
if ($result[$i]['pending']) {
$result[$i]['style'] = '_pending';
$result[$i]['pending_info'] .= $lng['listings']['pending_ad'] . '<br />';
} else {
if ($i % 2) {
$result[$i]['style'] = '_odd';
} else {
$result[$i]['style'] = '_even';
}
}
foreach ($result[$i]['pending_actions'] as $action) {
if ($action['type'] == 'highlited') {
$result[$i]['pending_info'] .= $lng['listings']['pending_highlited'] . '<br />';
continue;
}
if ($action['type'] == 'featured') {
$result[$i]['pending_info'] .= $lng['listings']['pending_featured'] . '<br />';
continue;
}
if ($action['type'] == 'video') {
$result[$i]['pending_info'] .= $lng['listings']['pending_video'] . '<br />';
continue;
}
if ($action['type'] == 'priority') {
$result[$i]['pending_info'] .= $lng['listings']['pending_priority'] . ': ';
$result[$i]['pending_info'] .= priorities::getname( $action['extra'] ) . '<br />';
continue;
}
if (( $action['type'] == 'newpkg' || $action['type'] == 'renewpkg' )) {
$result[$i]['pending_info'] .= $lng['listings']['pending_subscription'] . '<br />';
continue;
}
}
$result[$i]['paid'] = 0;
if (0 < $result[$i]['amount']) {
$result[$i]['paid'] = 1;
}
if ($result[$i]['picture']) {
$result[$i]['image'] = 'images/listings/thmb/' . $result[$i]['picture'];
$result[$i]['image_id'] = $result[$i]['picture_id'];
} else {
$result[$i]['image'] = 'images/' . $nopic;
$result[$i]['image_id'] = 0;
}
if (0 < $result[$i]['price']) {
$result[$i]['price_formatted'] = format_price( $result[$i]['price'] );
$result[$i]['price_curr'] = add_currency( $result[$i]['price_formatted'], $result[$i]['currency'] );
} else {
$result[$i]['price_formatted'] = '';
$result[$i]['price_curr'] = '';
}
if ($ads_settings['location_fields']) {
$loc_fields = explode( ',', $ads_settings['location_fields'] );
$result[$i]['location_str'] = '';
$k = 0;
foreach ($loc_fields as $l) {
if (!$l) {
continue;
}
if ($result[$i][$l]) {
if ($k) {
$result[$i]['location_str'] .= ', ';
}
$result[$i]['location_str'] .= $result[$i][$l];
++$k;
continue;
}
}
}
if (( $ads_settings['enable_priorities'] && $result[$i]['priority'] < 1000 )) {
$result[$i]['priority_name'] = priorities::getnamebyorder( $result[$i]['priority'] );
}
$result[$i]['stock'] = sprintf( '%04d', $result[$i]['adid'] );
if ($mlang) {
$default_title = '';
foreach ($languages as $l) {
$lang_id = $l['id'];
$result[$i][$lang_id] = array( );
$result[$i][$lang_id]['title'] = $result[$i]['title_' . $lang_id];
if ($l['default'] == 1) {
$default_title = $result[$i]['title_' . $lang_id];
continue;
}
}
if (!$result[$i]['title']) {
$result[$i]['title'] = $default_title;
if (!$result[$i]['title']) {
foreach ($languages as $l) {
if ($result[$i]['title_' . $l['id']]) {
$result[$i]['title'] = $result[$i]['title_' . $l['id']];
break;
}
}
}
}
}
$result[$i]['url_title'] = _urlencode( $result[$i]['title'] );
if (!$result[$i]['user_id']) {
$user_details = $this->getOwnerInfo( $result[$i]['id'] );
$result[$i]['username'] = $user_details['mgm_email'];
$result[$i]['mgm_name'] = $user_details['mgm_name'];
$result[$i]['ip'] = $user_details['ip'];
}
++$i;
}
return $result;
}
function getshortlisting($id) {
global $db;
global $lng;
global $appearance_settings;
global $ads_settings;
$date_format = $appearance_settings['date_format'];
if (!$id) {
$id = $this->id;
}
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select ' . TABLE_ADS . '.*, ' . TABLE_ADS . '.id as adid, ' . TABLE_ADS_PICTURES . '.picture, ' . TABLE_ADS_PICTURES . '.`id` as `picture_id`, date_format(' . TABLE_ADS . ( '' . '.`date_added`,\'' . $date_format . '\') as date_nice, date_format(' ) . TABLE_ADS . ( '' . '.`date_expires`,\'' . $date_format . '\') as date_expires_nice, (' ) . TABLE_ADS . ( '' . '.date_expires<\'' . $timestamp . '\' and ' ) . TABLE_ADS . '.date_expires!=\'0000-00-00 00:00:00\' and ' . TABLE_ADS . '.active=0) as `expired`, ' . TABLE_CATEGORIES . '.name as category, ' . TABLE_PACKAGES . '.name as package, ' . TABLE_PACKAGES . '.amount as amount, ' . TABLE_USERS . '.username as username from ' . TABLE_ADS . '
left join ' . TABLE_CATEGORIES . ' on ' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '.id
left join ' . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_ADS_PICTURES . ' on ' . TABLE_ADS . '.id=' . TABLE_ADS_PICTURES . '.ad_id
where ' . TABLE_ADS . ( '' . '.id=\'' . $id . '\' ' );
$result = $db->fetchAssoc( $sql );
foreach ($result as $key => $value) {
$result[$key] = clean( $result[$key] );
}
$pictures = new pictures( );
$nopic = $ads_settings['nopic'];
$currency_pos = $appearance_settings['currency_pos'];
$result['id'] = $result['adid'];
$result['paid'] = 0;
if (0 < $result['amount']) {
$result['paid'] = 1;
}
if ($result['picture']) {
$result['image'] = 'images/listings/thmb/' . $result['picture'];
$result['image_id'] = $result['picture_id'];
} else {
$result['image'] = 'images/' . $nopic;
$result['image_id'] = 0;
}
$result['price_curr'] = add_currency( $result['price'], $result['currency'] );
$result['stock'] = sprintf( '%04d', $id );
return $result;
}
function searchlisting($id, $crt_usr = '') {
global $db;
$array_listings = array( );
if ($crt_usr) {
$where = '' . ' and `user_id`=\'' . $crt_usr . '\'';
} else {
$where = '';
}
$res = $db->query( 'select id from ' . TABLE_ADS . ( '' . ' where id=\'' . $id . '\'' ) . $where );
if ($db->numRows( $res )) {
$array_listings = $this->getListingsDetailed( 'where ' . TABLE_ADS . '.id=' . $id );
}
return $array_listings;
}
function getlistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
if ($crt_usr) {
$where = 'where ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
} else {
$where = '';
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnolistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS;
if ($crt_usr) {
$sql .= ' where user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getactivelistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.active like \'1\'';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id like \'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnoactivelistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where active=1';
if ($crt_usr) {
$sql .= ' and user_id like ' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getinactivelistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.active=0';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnoinactivelistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where active=0';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getpendinglistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = ' where ' . TABLE_ADS . '.`pending` = \'1\'';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . '.user_id=' . $crt_usr;
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnopendinglistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where pending=1';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getnounfinishedlistings($crt_usr = '') {
global $db;
if ($crt_usr) {
$usr_str = ' and user_id=' . $crt_usr;
} else {
$usr_str = '';
}
$no = $db->fetchRow( 'select count(*) from ' . TABLE_ADS . ' where user_approved=0' . $usr_str );
return $no;
}
function getfeaturedlistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.featured=1';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnofeaturedlistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where featured=1';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function gethighlitedlistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.highlited=1';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnohighlitedlistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where highlited=1';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getnoprioritieslistings($crt_usr = '') {
global $db;
$sql = 'select count(*) from ' . TABLE_ADS . ' where priority<1000';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getprioritieslistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = 'where ' . TABLE_ADS . '.priority<1000';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getexpiredlistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$timestamp = date( 'Y-m-d H:i:s' );
$where = 'where ' . TABLE_ADS . '.active=0 and ' . TABLE_ADS . ( '' . '.date_expires < \'' . $timestamp . '\' and ' ) . TABLE_ADS . '.date_expires!=\'0000-00-00 00:00:00\'';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = 'order by ' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnoexpiredlistings($crt_usr = '') {
global $db;
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select count(id) from ' . TABLE_ADS . ( '' . ' where active=0 and date_expires < \'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\' and date_expires is not null' );
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function getvideolistings($page, $ads_per_page, $order, $order_way, $crt_usr = '') {
global $db;
$start = ( $page - 1 ) * $ads_per_page;
$where = ' where `object_id` and ' . TABLE_ADS . '.video!=\'\' ';
if ($crt_usr) {
$where .= ' and ' . TABLE_ADS . ( '' . '.user_id=\'' . $crt_usr . '\'' );
}
if ($order) {
$order_by = ' order by ' . TABLE_ADS . '.' . $order;
} else {
$order_by = '';
}
$result = $this->getListingsDetailed( $where, $order_by, $order_way, $start, $ads_per_page );
return $result;
}
function getnovideolistings($crt_usr = '') {
global $db;
$sql = 'select count(' . TABLE_ADS . '.id) from ' . TABLE_ADS . ' left join ' . TABLE_OPTIONS . ' on ' . TABLE_ADS . '.`id`=' . TABLE_OPTIONS . '.`object_id` where `object_id` and ' . TABLE_ADS . '.video!=\'\' ';
if ($crt_usr) {
$sql .= ' and user_id=' . $crt_usr;
}
$no = $db->fetchRow( $sql );
return $no;
}
function geterror() {
return $this->error;
}
function adderror($str) {
$this->error .= $str;
}
function seterror($str) {
$this->error = $str;
}
function gettmp() {
return $this->tmp;
}
function count_words($string) {
$word_count = 0;
$cleaned_str = preg_replace( '/[^A-Z0-9]/i', ' ', $string );
$string = preg_replace( '/ +/', ' ', $string );
$string = explode( ' ', $string );
while (list( , $word ) = each( $string )) {
if (preg_match( '/[0-9A-ZA`-Ö?-y]/i', $word )) {
++$word_count;
continue;
}
}
return $word_count;
}
function check_form($id = '') {
global $db;
global $settings;
$auth = new auth( );
$is_admin = 0;
$nologin = 0;
if ($auth->loggedIn( )) {
$user_id = $auth->crtUserId( );
} else {
if ($auth->adminLoggedIn( )) {
$is_admin = 1;
} else {
if ($settings['nologin_enabled']) {
$user_id = 0;
$nologin = 1;
} else {
header( 'Location: not_authorized.php' );
exit( 0 );
}
}
}
global $lng;
$this->error = '';
$this->tmp = array( );
global $ads_settings;
$no_words = 0;
$no_pictures = 0;
$featured = 0;
$amount = 0;
if (!$id) {
if (!$_POST['category']) {
$this->addError( $lng['listings']['errors']['category_missing'] . '<br />' );
} else {
if (!is_numeric( $_POST['category'] )) {
$this->addError( $lng['listings']['errors']['invalid_category'] . '<br />' );
} else {
$category = escape( $_POST['category'] );
$categ = new categories( );
}
}
if (!$_POST['package']) {
$this->addError( $lng['listings']['errors']['package_missing'] . '<br />' );
} else {
if (!is_numeric( $_POST['package'] )) {
$this->addError( $lng['listings']['errors']['invalid_package'] . '<br />' );
} else {
$package_id = escape( $_POST['package'] );
}
}
if (( $is_admin && !$_POST['user_id'] )) {
$this->addError( $lng['listings']['errors']['user_missing'] . '<br />' );
}
} else {
$category = $this->getCategory( $id );
$categ = new categories( );
$package_id = $this->getPackage( $id );
}
if ($package_id) {
$pkg = new packages( );
$package = $pkg->getPackage( $package_id );
$no_words = $package['no_words'];
}
$def_lang = '';
$mlang_fields = 0;
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$def_lang = '_' . languages::getdefault( );
$mlang_fields = 1;
}
}
$description_array = array( 'description' );
$title_array = array( 'title' );
if ($mlang_fields) {
$description_array = array( );
$title_array = array( );
foreach ($languages as $l) {
array_push( $description_array, 'description_' . $l['id'] );
array_push( $title_array, 'title_' . $l['id'] );
}
}
$desc_exists = 0;
foreach ($description_array as $desc) {
if ($_POST[$desc]) {
$desc_exists = 1;
break;
}
}
if (!$desc_exists) {
$this->addError( $lng['listings']['errors']['content_missing'] . '<br />' );
}
$title_exists = 0;
foreach ($title_array as $t) {
if ($_POST[$t]) {
$title_exists = 1;
break;
}
}
if (!$title_exists) {
$this->addError( $lng['listings']['errors']['title_missing'] . '<br />' );
}
if (0 < $no_words) {
foreach ($description_array as $desc) {
if (!$_POST[$desc]) {
continue;
}
$wc = $this->count_words( $_POST[$desc] );
if ($no_words < $wc) {
$err = preg_replace( '/::MAX::/', '' . $no_words, $lng['listings']['errors']['words_quota_exceeded'] );
$this->addError( $err . '<br />' );
break;
}
}
}
$bd = 0;
foreach ($description_array as $desc) {
if (( $ads_settings['badwords_check'] == 1 && $_POST[$desc] )) {
$badword = new badwords( );
if (( $badword->check( $_POST[$desc] ) && $ads_settings['badwords_check_type'] == 1 )) {
$this->addError( $lng['listings']['errors']['badwords'] . '<br />' );
$bd = 1;
continue;
}
continue;
}
}
foreach ($title_array as $t) {
if (( $ads_settings['badwords_check'] == 1 && $_POST[$t] )) {
$badword = new badwords( );
if (( $badword->check( $_POST[$t] ) && $ads_settings['badwords_check_type'] == 1 )) {
if (!$bd) {
$this->addError( $lng['listings']['errors']['badwords'] . '<br />' );
continue;
}
continue;
}
continue;
}
}
if (( ( isset( $_POST['video'] ) && $_POST['video'] ) && !validator::valid_youtube( clean( $_POST['video'] ) ) )) {
$this->addError( $lng['listings']['errors']['invalid_youtube_video'] . '<br />' );
}
$fields = new fields( 'cf' );
$fields->setEdit( $this->edit );
if (( ( ( !$id && isset( $_POST['category'] ) ) && $_POST['category'] != '' ) || $id )) {
$cat = new categories( );
$fieldset = $cat->getFieldset( $category );
$fields->check_form_object( $fieldset );
if ($fields->getError( ) != '') {
$this->addError( $fields->getError( ) );
}
}
if (( !$id && $nologin )) {
$this->check_user_info( );
}
if (( ( $nologin && $settings['nologin_image_verification'] ) && ( !isset( $_POST['number'] ) || md5( $_POST['number'] ) != $_SESSION['image_value'] ) )) {
$this->addError( $lng['contact']['error']['invalid_validation_number'] . '<br/>' );
}
if ($this->getError( ) != '') {
if ($id) {
$this->tmp['id'] = $id;
}
foreach ($description_array as $f) {
if (isset( $_POST[$f] )) {
$this->tmp[$f] = clean( $_POST[$f] );
continue;
}
$this->tmp[$f] = '';
}
foreach ($title_array as $f) {
if (isset( $_POST[$f] )) {
$this->tmp[$f] = clean( $_POST[$f] );
continue;
}
$this->tmp[$f] = '';
}
foreach (array( 'currency' ) as $f) {
if (isset( $_POST[$f] )) {
$this->tmp[$f] = $_POST[$f];
continue;
}
$this->tmp[$f] = '';
}
if ($is_admin) {
if (isset( $_POST['user_id'] )) {
$this->tmp['user_id'] = $_POST['user_id'];
} else {
$this->tmp['user_id'] = '';
}
}
if (isset( $_POST['video'] )) {
$this->tmp['video'] = clean( $_POST['video'] );
} else {
$this->tmp['video'] = '';
}
if ($id) {
$this->tmp['enable_video'] = $this->videoEnabled( $id );
}
$this->tmp['tmp_fields'] = $fields->getTmp( );
foreach ($this->tmp['tmp_fields'] as $key => $value) {
$this->tmp[$key] = $value;
}
if ($ads_settings['add_meta_with_listings']) {
if (isset( $_POST['meta_keywords'] )) {
$this->tmp['meta_keywords'] = clean( $_POST['meta_keywords'] );
} else {
$this->tmp['meta_keywords'] = '';
}
if (isset( $_POST['meta_description'] )) {
$this->tmp['meta_description'] = clean( $_POST['meta_description'] );
} else {
$this->tmp['meta_description'] = '';
}
}
if ($nologin) {
if (!$id) {
if (isset( $_POST['mgm_email'] )) {
$this->tmp['mgm_email'] = clean( $_POST['mgm_email'] );
} else {
$this->tmp['mgm_email'] = '';
}
}
if (isset( $_POST['mgm_name'] )) {
$this->tmp['mgm_name'] = clean( $_POST['mgm_name'] );
return 1;
}
$this->tmp['mgm_name'] = '';
}
}
return 1;
}
function check_user_info() {
global $lng;
if (( !isset( $_POST['mgm_email'] ) || !$_POST['mgm_email'] )) {
$this->addError( $lng['listings']['error']['your_email_missing'] . '<br/>' );
return null;
}
if (( ( isset( $_POST['mgm_email'] ) && $_POST['mgm_email'] ) && !validator::valid_email( $_POST['mgm_email'] ) )) {
$this->addError( $lng['users']['errors']['invalid_email'] . '<br />' );
}
}
function add() {
global $db;
global $ads_settings;
global $settings;
global $crt_lang;
$auth = new auth( );
$is_admin = 0;
$clean['user_id'] = 0;
if ($auth->loggedIn( )) {
$clean['user_id'] = $auth->crtUserId( );
} else {
if ($auth->adminLoggedIn( )) {
$is_admin = 1;
$clean['user_id'] = escape( $_POST['user_id'] );
} else {
if (!$settings['nologin_enabled']) {
header( 'Location: not_authorized.php' );
exit( 0 );
}
}
}
$clean['category_id'] = escape( $_POST['category'] );
$categ = new categories( );
$fieldset = $categ->getFieldset( $clean['category_id'] );
$clean['package_id'] = escape( $_POST['package'] );
if (!$is_admin) {
$clean['usr_pkg'] = escape( $_POST['usr_pkg'] );
} else {
$clean['usr_pkg'] = 0;
}
$packages = new packages( );
$package = $packages->getPackage( $clean['package_id'] );
$clean['featured'] = $package['featured'];
$clean['highlited'] = $package['highlited'];
if ($package['priority']) {
$clean['priority'] = priorities::getorderno( $package['priority'] );
} else {
$clean['priority'] = 1000;
}
$clean['enable_video'] = $package['video'];
$no_days = $package['no_days'];
$this->clean = array( );
$this->check_form( );
if ($this->getError( ) != '') {
return 0;
}
$description_array = array( 'description' );
$title_array = array( 'title' );
$mlang = 0;
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$description_array = array( );
$title_array = array( );
foreach ($languages as $l) {
array_push( $description_array, 'description_' . $l['id'] );
array_push( $title_array, 'title_' . $l['id'] );
}
$mlang = 1;
}
}
$tags_list = tags_list( $ads_settings['allowed_html'] );
$no_desc_fields = 0;
foreach ($description_array as $desc) {
$clean[$desc] = escape( $_POST[$desc] );
if (( ( $clean[$desc] && $ads_settings['badwords_check'] ) && $ads_settings['badwords_check_type'] == 0 )) {
$badword = new badwords( );
if ($badword->check( $clean[$desc] )) {
$clean[$desc] = $badword->replace( $clean[$desc] );
}
}
if ($clean[$desc]) {
$clean[$desc] = strip_tags( $clean[$desc], $tags_list );
continue;
}
$no_desc_fields = 1;
}
$no_title_fields = 0;
foreach ($title_array as $t) {
$clean[$t] = escape( $_POST[$t] );
if ($clean[$t]) {
$clean[$t] = strip_tags( $clean[$t], $tags_list );
continue;
}
$no_title_fields = 1;
}
if ($mlang) {
if ($no_title_fields) {
if ($clean['title_' . $crt_lang]) {
$default_title = $clean['title_' . $crt_lang];
} else {
foreach ($languages as $l) {
if ($clean['title_' . $l['id']]) {
$default_title = $clean['title_' . $l['id']];
continue;
}
}
}
foreach ($languages as $l) {
if (!$clean['title_' . $l['id']]) {
$clean['title_' . $l['id']] = $default_title;
continue;
}
}
}
if ($no_desc_fields) {
if ($clean['description_' . $crt_lang]) {
$default_description = $clean['description_' . $crt_lang];
} else {
foreach ($languages as $l) {
if ($clean['description_' . $l['id']]) {
$default_description = $clean['description_' . $l['id']];
continue;
}
}
}
foreach ($languages as $l) {
if (!$clean['description_' . $l['id']]) {
$clean['description_' . $l['id']] = $default_description;
continue;
}
}
}
}
$fields = new fields( 'cf' );
if ($fields->fieldsetHasPrice( $fieldset )) {
if (isset( $_POST['currency'] )) {
$clean['currency'] = escape( $_POST['currency'] );
} else {
$clean['currency'] = '';
}
} else {
$clean['currency'] = '';
}
if ($ads_settings['add_meta_with_listings']) {
if (isset( $_POST['meta_keywords'] )) {
$clean['meta_keywords'] = escape( $_POST['meta_keywords'] );
} else {
$clean['meta_keywords'] = '';
}
if (isset( $_POST['meta_description'] )) {
$clean['meta_description'] = escape( $_POST['meta_description'] );
} else {
$clean['meta_description'] = '';
}
} else {
$clean['meta_keywords'] = '';
$clean['meta_description'] = '';
}
$clean['date_added'] = date( 'Y-m-d H:i:s' );
$insert_array = array( 'user_id', 'package_id', 'usr_pkg', 'category_id', 'currency', 'date_added', 'active', 'pending', 'featured', 'highlited', 'priority', 'meta_keywords', 'meta_description', 'language' );
if (!$mlang) {
array_push( $insert_array, 'description' );
array_push( $insert_array, 'title' );
} else {
foreach ($description_array as $desc) {
array_push( $insert_array, $desc );
}
foreach ($title_array as $t) {
array_push( $insert_array, $t );
}
}
global $crt_lang;
$clean['language'] = $crt_lang;
if (( ( isset( $_SESSION['action']['video'] ) && $_SESSION['action']['video']['value'] == 1 ) || ( $clean['package_id'] && packages::getvideo( $clean['package_id'] ) ) )) {
if (isset( $_POST['video'] )) {
$clean['video'] = escape( $_POST['video'] );
if (!strstr( $clean['video'], ' wmode="transparent"' )) {
$clean['video'] = str_replace( '></embed>', ' wmode="transparent"></embed>', $clean['video'] );
}
} else {
$clean['video'] = '';
}
$insert_array[count( $insert_array )] = 'video';
}
if ($is_admin) {
$clean['active'] = 1;
} else {
$clean['active'] = 0;
}
$clean['pending'] = 0;
$sql = 'insert into ' . TABLE_ADS . ' SET ';
$i = 0;
foreach ($insert_array as $f) {
if ($i) {
$sql .= ', ';
}
$sql .= '' . '`' . $f . '` = \'' . $clean[$f] . '\'';
++$i;
}
if ($no_days != 0) {
$sql .= ', `date_expires` = date_add(\'' . $clean['date_added'] . ( '' . '\', interval \'' . $no_days . '\' day)' );
}
$sql .= $fields->add_object( $fieldset );
$res = $db->query( $sql );
$id = $db->insertId( );
$this->last = $id;
if (( $settings['nologin_enabled'] && !$clean['user_id'] )) {
$this->addOwnerInfo( $id );
}
if ($clean['enable_video']) {
$this->addOption( $id, 'video', 1 );
}
if ($is_admin) {
$this->userApprove( $id );
global $ads_settings;
if ($ads_settings['alerts_enabled']) {
$alert = new alerts( );
$alert->checkImmediate( $id, $clean );
}
}
return $id;
}
function addownerinfo($id) {
global $settings;
global $db;
$mgm_email = escape( $_POST['mgm_email'] );
if (( isset( $_POST['mgm_name'] ) && $_POST['mgm_name'] )) {
$mgm_name = escape( $_POST['mgm_name'] );
} else {
$mgm_name = '';
}
$ip = $_SERVER['REMOTE_ADDR'];
$activation = generate_random( );
$res = $db->query( 'insert into ' . TABLE_ADS_EXTENSION . ( '' . ' set `id` = \'' . $id . '\', `mgm_email`=\'' . $mgm_email . '\', `mgm_name`=\'' . $mgm_name . '\', `ip`=\'' . $ip . '\', `activation`=\'' . $activation . '\'' ) );
return 1;
}
function editownerinfo($id) {
global $settings;
global $db;
if (( isset( $_POST['mgm_email'] ) && $_POST['mgm_email'] )) {
$mgm_email = escape( $_POST['mgm_email'] );
} else {
$mgm_email = '';
}
if (( isset( $_POST['mgm_name'] ) && $_POST['mgm_name'] )) {
$mgm_name = escape( $_POST['mgm_name'] );
} else {
$mgm_name = '';
}
$res = $db->query( 'update ' . TABLE_ADS_EXTENSION . ( '' . ' set `mgm_name`=\'' . $mgm_name . '\' where `id` = \'' . $id . '\'' ) );
if ($mgm_email) {
$res = $db->query( 'update ' . TABLE_ADS_EXTENSION . ( '' . ' set `mgm_email`=\'' . $mgm_email . '\' where `id` = \'' . $id . '\'' ) );
}
return 1;
}
function getownerinfo($id) {
global $db;
$array = $db->fetchAssoc( 'select * from ' . TABLE_ADS_EXTENSION . ( '' . ' where `id`=' . $id ) );
return $array;
}
function correctkey($id, $key) {
global $db;
$exists = $db->fetchRow( 'select count(*) from ' . TABLE_ADS_EXTENSION . ( '' . ' where `id`=' . $id . ' and `activation`=\'' . $key . '\'' ) );
return $exists;
}
function edit($id) {
global $db;
global $ads_settings;
global $settings;
global $crt_lang;
$category = $this->getCategory( $id );
$package = $this->getPackage( $id );
$categ = new categories( );
$fieldset = $categ->getFieldset( $category );
$auth = new auth( );
$is_admin = 0;
$user_id = 0;
if ($auth->loggedIn( )) {
$user_id = $auth->crtUserId( );
} else {
if ($auth->adminLoggedIn( )) {
$is_admin = 1;
} else {
if (!$settings['nologin_enabled']) {
header( 'Location: not_authorized.php' );
exit( 0 );
}
}
}
$this->clean = array( );
$this->check_form( $id );
if ($this->getError( ) != '') {
return 0;
}
$description_array = array( 'description' );
$title_array = array( 'title' );
$mlang = 0;
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$description_array = array( );
$title_array = array( );
foreach ($languages as $l) {
array_push( $description_array, 'description_' . $l['id'] );
array_push( $title_array, 'title_' . $l['id'] );
}
$mlang = 1;
}
}
$tags_list = tags_list( $ads_settings['allowed_html'] );
$no_desc_fields = 0;
foreach ($description_array as $desc) {
$clean[$desc] = escape( $_POST[$desc] );
if (( ( $clean[$desc] && $ads_settings['badwords_check'] ) && $ads_settings['badwords_check_type'] == 0 )) {
$badword = new badwords( );
if ($badword->check( $clean[$desc] )) {
$clean[$desc] = $badword->replace( $clean[$desc] );
}
}
if ($clean[$desc]) {
$clean[$desc] = strip_tags( $clean[$desc], $tags_list );
continue;
}
$no_desc_fields = 1;
}
$no_title_fields = 0;
foreach ($title_array as $t) {
$clean[$t] = escape( $_POST[$t] );
if ($clean[$t]) {
$clean[$t] = strip_tags( $clean[$t], $tags_list );
continue;
}
$no_title_fields = 1;
}
if ($mlang) {
if ($no_title_fields) {
if ($clean['title_' . $crt_lang]) {
$default_title = $clean['title_' . $crt_lang];
} else {
foreach ($languages as $l) {
if ($clean['title_' . $l['id']]) {
$default_title = $clean['title_' . $l['id']];
continue;
}
}
}
foreach ($languages as $l) {
if (!$clean['title_' . $l['id']]) {
$clean['title_' . $l['id']] = $default_title;
continue;
}
}
}
if ($no_desc_fields) {
if ($clean['description_' . $crt_lang]) {
$default_description = $clean['description_' . $crt_lang];
} else {
foreach ($languages as $l) {
if ($clean['description_' . $l['id']]) {
$default_description = $clean['description_' . $l['id']];
continue;
}
}
}
foreach ($languages as $l) {
if (!$clean['description_' . $l['id']]) {
$clean['description_' . $l['id']] = $default_description;
continue;
}
}
}
}
global $crt_lang;
$clean['language'] = $crt_lang;
$fields = new fields( 'cf' );
if ($fields->fieldsetHasPrice( $fieldset )) {
if (isset( $_POST['currency'] )) {
$clean['currency'] = escape( $_POST['currency'] );
} else {
$clean['currency'] = '';
}
} else {
$clean['currency'] = '';
}
if ($ads_settings['add_meta_with_listings']) {
if (isset( $_POST['meta_keywords'] )) {
$clean['meta_keywords'] = escape( $_POST['meta_keywords'] );
} else {
$clean['meta_keywords'] = '';
}
if (isset( $_POST['meta_description'] )) {
$clean['meta_description'] = escape( $_POST['meta_description'] );
} else {
$clean['meta_description'] = '';
}
} else {
$clean['meta_keywords'] = '';
$clean['meta_description'] = '';
}
$insert_array = array( 'currency', 'meta_keywords', 'meta_description', 'language' );
if (!$mlang) {
array_push( $insert_array, 'description' );
array_push( $insert_array, 'title' );
} else {
foreach ($description_array as $desc) {
array_push( $insert_array, $desc );
}
foreach ($title_array as $t) {
array_push( $insert_array, $t );
}
}
$enable_video = $this->videoEnabled( $id );
if (( ( $enable_video || ( isset( $_SESSION['action']['video'] ) && $_SESSION['action']['video']['value'] == 1 ) ) || packages::getvideo( $package ) )) {
if (isset( $_POST['video'] )) {
$clean['video'] = escape( $_POST['video'] );
if (!strstr( $clean['video'], ' wmode="transparent"' )) {
$clean['video'] = str_replace( '></embed>', ' wmode="transparent"></embed>', $clean['video'] );
}
} else {
$clean['video'] = '';
}
$insert_array[count( $insert_array )] = 'video';
}
$sql = 'update ' . TABLE_ADS . ' SET ';
$i = 0;
foreach ($insert_array as $f) {
if ($i) {
$sql .= ', ';
}
$sql .= '' . '`' . $f . '` = \'' . $clean[$f] . '\'';
++$i;
}
$fields->setEdit( $this->edit );
$sql .= $fields->add_object( $fieldset );
$sql .= ' where id=' . $id;
$res = $db->query( $sql );
if (( ( $settings['nologin_enabled'] && !$user_id ) && !$is_admin )) {
$this->editOwnerInfo( $id );
}
return 1;
}
function getlast() {
return $this->last;
}
function getdiscountcode($id) {
$res = mysql_query( 'select code from ' . TABLE_DISCOUNTS . ( '' . ' where object_id=' . $id . ' and type==\'newad\'' ) );
if (!mysql_num_rows( $res )) {
return 0;
}
return mysql_result( $res, 0 );
}
function getadvsearch($post_array, $page, $ads_per_page) {
global $db;
global $ads_settings;
$str_radius = '';
$str_zip = '';
$join_zip = '';
$fields = explode( ',', $ads_settings['search_in_fields'] );
$cf = new fields( 'cf' );
$custom_fields = $cf->getSearchFields( $post_array );
$language = new languages( );
$languages = $language->getActiveLanguages( );
$no_lang = count( $languages );
$set = array( );
global $crt_lang;
$el_fields = array( 'menu', 'radio', 'radio_group', 'checkbox_group', 'multiselect' );
$location_fields = explode( ',', $ads_settings['location_fields'] );
$where = ' where ' . TABLE_ADS . '.active=1';
foreach ($post_array as $key => $val) {
if ($val == '') {
continue;
}
switch ($key) {
case 'id': {
$where .= ' and ' . TABLE_ADS . '.id = "' . $val . '"';
break;
}
case 'category': {
$where .= ' and ' . TABLE_ADS . '.category_id in (' . $val . ')';
break;
}
case 'location': {
if (!count( $location_fields )) {
break;
}
$a = 0;
$where .= ' and ( ';
foreach ($location_fields as $loc) {
if ($a) {
$where .= ' or ';
}
$where .= ' ' . TABLE_ADS . '.' . $loc . ' like "' . $val . '"';
++$a;
}
$where .= ' )';
break;
}
case 'word': {
if (!count( $fields )) {
break;
}
$search_array = explode( ' ', $val );
$no_words = count( $search_array );
$where .= ' and (';
$k = 0;
$i = $no_words;
while (0 < $i) {
$w = trim( $search_array[$i - 1] );
if ($w != '') {
$j = 0;
foreach ($fields as $f) {
if ($k) {
$where .= ' or';
}
$where .= ' ' . TABLE_ADS . ( '' . '.' . $f . ' like \'%' . $w . '%\'' );
++$j;
++$k;
}
}
--$i;
}
$where .= ' )';
break;
}
case 'user_id': {
$where .= ' and ' . TABLE_ADS . '.user_id like "' . $val . '"';
break;
}
case 'price_low': {
}
case 'price_high': {
if (( isset( $set['price'] ) && $set['price'] )) {
break;
}
if (( $post_array['price_low'] != '' && $post_array['price_high'] != '' )) {
if (( is_numeric( $post_array['price_low'] ) && is_numeric( $post_array['price_high'] ) )) {
$where .= ' and ' . TABLE_ADS . '.price between ' . $post_array['price_low'] . ' and ' . $post_array['price_high'] . '';
}
} else {
if (( $post_array['price_low'] != '' && $post_array['price_high'] == '' )) {
if (is_numeric( $post_array['price_low'] )) {
$where .= ' and ' . TABLE_ADS . '.price >= ' . $post_array['price_low'];
}
} else {
if (( $post_array['price_high'] != '' && $post_array['price_low'] == '' )) {
if (is_numeric( $post_array['price_high'] )) {
$where .= ' and ' . TABLE_ADS . '.price <= ' . $post_array['price_high'];
}
}
}
}
$set['price'] = 1;
break;
}
case 'currency': {
$where .= ' and ' . TABLE_ADS . '.currency like "' . $val . '"';
break;
}
case 'with_pic': {
$where .= ' and ' . TABLE_ADS_PICTURES . '.id is not null ';
break;
}
case 'zip': {
global $modules_array;
if ($post_array['zip']) {
if (( ( ( in_array( 'areasearch', $modules_array ) && isset( $post_array['area'] ) ) && is_numeric( $post_array['area'] ) ) && 0 < $post_array['area'] )) {
$search_by_area = 1;
global $config_table_prefix;
$zip_loc = new areasearch( );
$zip_settings = $zip_loc->getSettings( );
if ($zip_settings['um'] == 'miles') {
$radius = $zip_loc->miles_to_km( $post_array['area'] );
} else {
$radius = $post_array['area'];
}
$coord = $zip_loc->getCoord( $post_array['zip'] );
if ($coord != 0) {
$str_zip = ', ((POW((69.1*(' . $config_table_prefix . 'zipcodes.lon-' . $coord['lon'] . ')*cos(' . $coord['lat'] . '/57.3)),"2")+POW((69.1*(' . $config_table_prefix . 'zipcodes.lat-' . $coord['lat'] . ')),"2"))/1.609) as distance ';
$where .= ' and (POW((69.1*(' . $config_table_prefix . 'zipcodes.lon-' . $coord['lon'] . ')*cos(' . $coord['lat'] . '/57.3)),"2")+POW((69.1*(' . $config_table_prefix . 'zipcodes.lat-' . $coord['lat'] . ')),"2"))<(' . $radius . '*' . $radius . ')';
$join_zip = ' left join ' . $config_table_prefix . 'zipcodes on ' . $config_table_prefix . 'zipcodes.zipcode=' . TABLE_ADS . '.zip';
} else {
$where .= ' and (' . TABLE_ADS . '.zip like "' . $post_array['zip'] . '" )';
}
} else {
$where .= ' and (' . TABLE_ADS . '.' . $key . ' like "' . $val . '" )';
}
}
break;
}
case 'area': {
}
case 'page': {
}
case 'order': {
}
case 'order_way': {
}
case 'search_x': {
}
case 'search_y': {
}
case 'Search': {
}
case 'search': {
}
case 'Submit_x': {
}
case 'Submit_y': {
}
case 'Submit': {
}
case 'x': {
}
case 'y': {
break;
}
default: {
global $default_fields_types;
if (( ( isset( $custom_fields[$crt_lang][$key]['type'] ) && $custom_fields[$crt_lang][$key]['type'] ) && !in_array( $custom_fields[$crt_lang][$key]['type'], $default_fields_types ) )) {
$new_type = $custom_fields[$crt_lang][$key]['type'];
$custom_obj = new $new_type( );
$where .= ' and ' . $custom_obj->getAdvSearch( TABLE_ADS, $val );
break;
}
if (( isset( $custom_fields[$crt_lang][$key]['search_type'] ) && $custom_fields[$crt_lang][$key]['search_type'] == 'interval' )) {
if ($custom_fields[$crt_lang][$key]['type'] == 'date') {
$sep = '"';
} else {
$sep = '';
}
$skey = preg_replace( '' . '/_low$/', '', $key );
$skey = preg_replace( '' . '/_high$/', '', $skey );
if (( isset( $set[$skey] ) && $set[$skey] )) {
break;
}
if (( ( isset( $post_array[$skey . '_low'] ) && $post_array[$skey . '_low'] != '' ) && ( isset( $post_array[$skey . '_high'] ) && $post_array[$skey . '_high'] != '' ) )) {
$where .= ' and ' . TABLE_ADS . '.' . $skey . ' between ' . $sep . $post_array[$skey . '_low'] . $sep . ' and ' . $sep . $post_array[$skey . '_high'] . $sep . '';
} else {
if (( ( isset( $post_array[$skey . '_low'] ) && $post_array[$skey . '_low'] != '' ) && ( !isset( $post_array[$skey . '_high'] ) || $post_array[$skey . '_high'] == '' ) )) {
$where .= ' and ' . TABLE_ADS . '.' . $skey . ' >= ' . $sep . $post_array[$skey . '_low'] . $sep;
} else {
if (( ( isset( $post_array[$skey . '_high'] ) && $post_array[$skey . '_high'] != '' ) && ( !isset( $post_array[$skey . '_low'] ) || $post_array[$skey . '_low'] == '' ) )) {
$where .= ' and ' . TABLE_ADS . '.' . $skey . ' <= ' . $sep . $post_array[$skey . '_high'] . $sep;
}
}
}
$set[$skey] = 1;
} else {
$q_translated = '';
if (( ( isset( $custom_fields[$crt_lang][$key]['type'] ) && $custom_fields[$crt_lang][$key]['type'] ) && 1 < $no_lang )) {
if (in_array( $custom_fields[$crt_lang][$key]['type'], $el_fields )) {
$crt_lang_elem = $custom_fields[$crt_lang][$key]['elements'];
$crt_lang_arr = explode( '|', $crt_lang_elem );
$index = 0 - 1;
$i = 0;
foreach ($crt_lang_arr as $el) {
if ($el == $val) {
$index = $i;
break;
}
++$i;
}
if ($index != 0 - 1) {
foreach ($languages as $l) {
if ($l['id'] == $crt_lang) {
continue;
}
$alt_lang_elem = $custom_fields[$l['id']][$key]['elements'];
$alt_lang_arr = explode( '|', $alt_lang_elem );
$alt_val = $alt_lang_arr[$index];
if ($custom_fields[$crt_lang][$key]['search_type'] == 'keyword') {
$q_translated .= ' or ' . TABLE_ADS . '.' . $key . ' like "%' . $alt_val . '%" ';
continue;
}
if (in_array( $custom_fields[$crt_lang][$key]['type'], array( 'multiselect', 'radio', 'radio_group' ) )) {
$q_translated .= ' or ' . TABLE_ADS . '.' . $key . ( '' . ' REGEXP \'\[\[:<:\]\]' . $val . '\[\[:>:\]\]\'' );
continue;
}
$q_translated .= ' or ' . TABLE_ADS . '.' . $key . ' like "' . $alt_val . '" ';
}
}
} else {
if ($custom_fields[$crt_lang][$key]['type'] == 'depending') {
$dep = new depending_fields( );
foreach ($languages as $l) {
$alt_val = $dep->translateField( $custom_fields[$crt_lang][$key]['dep_id'], $key, $crt_lang, $l['id'], $val );
if ($custom_fields[$crt_lang][$key]['search_type'] == 'keyword') {
$q_translated .= ' or ' . TABLE_ADS . '.' . $key . ' like "%' . $alt_val . '%" ';
continue;
}
$q_translated .= ' or ' . TABLE_ADS . '.' . $key . ' like "' . $alt_val . '" ';
}
}
}
}
if (isset( $custom_fields[$crt_lang][$key]['search_type'] )) {
if (( in_array( $custom_fields[$crt_lang][$key]['type'], array( 'multiselect', 'radio', 'radio_group' ) ) && $custom_fields[$crt_lang][$key]['search_type'] == 'default' )) {
$where .= ' and (' . TABLE_ADS . '.' . $key . ( '' . ' REGEXP \'\[\[:<:\]\]' . $val . '\[\[:>:\]\]\' ' ) . $q_translated . ')';
} else {
$compare = 'like';
if (( $custom_fields[$crt_lang][$key]['is_numeric'] || $custom_fields[$crt_lang][$key]['type'] == 'checkbox' )) {
$compare = '=';
}
if ($custom_fields[$crt_lang][$key]['search_type'] == 'keyword') {
$where .= ' and ( ' . TABLE_ADS . '.' . $key . ' like "%' . $val . '%" ' . $q_translated . ')';
} else {
if ($custom_fields[$crt_lang][$key]['search_type'] == 'default') {
$where .= ' and (' . TABLE_ADS . '.' . $key . ' ' . $compare . ' "' . $val . '" ' . $q_translated . ')';
}
}
}
}
}
break;
}
}
}
if ($ads_settings['enable_priorities']) {
$pri_ord = ' priority asc, ';
} else {
$pri_ord = '';
}
if (( isset( $post_array['order'] ) && $post_array['order'] )) {
$order_by = '' . ' order by ' . $pri_ord . $post_array['order'];
} else {
$order_by = '' . ' order by ' . $pri_ord . ' date_added';
}
if (( isset( $post_array['order_way'] ) && $post_array['order_way'] )) {
$order_way = $post_array['order_way'];
} else {
$order_way = ' desc';
}
$start = ( $page - 1 ) * $ads_per_page;
$no_listings = $this->getNoShortListings( $where, $join_zip );
$this->setNoListings( $no_listings );
if (( isset( $post_array['word'] ) && $post_array['word'] )) {
$keyword = $post_array['word'];
} else {
$keyword = '';
}
$result = $this->getShortListings( $where, $order_by, $order_way, $start, $ads_per_page, $keyword, $str_zip, $join_zip );
return $result;
}
function belongstouser($id, $user_id) {
global $db;
$res = $db->query( 'select user_id from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (!$db->numRows( $res )) {
return 0;
}
$user = $db->fetchRow( );
if ($user == $user_id) {
return 1;
}
return 0;
}
function incview($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set viewed=viewed+1 where id = \'' . $id . '\'' ) );
return 1;
}
function idexists($id = 0) {
global $db;
if (!$id) {
$id = $this->id;
}
$no = $db->fetchRow( 'select count(*) from ' . TABLE_ADS . ( '' . ' where id = \'' . $id . '\'' ) );
if (0 < $no) {
return 1;
}
return 0;
}
function getmetainfo($id) {
global $db;
global $ads_settings;
$page_info = array( 'title' => '', 'meta_keywords' => '', 'meta_description' => '' );
global $crt_lang;
$title_field = '`title`';
$description_field = '`description`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_field = '' . '`title_' . $crt_lang . '` as `title`';
$description_field = '' . '`description_' . $crt_lang . '` as `description`';
}
}
if ($ads_settings['add_meta_with_listings']) {
$page_info = $db->fetchAssoc( '' . 'select ' . $title_field . ', `meta_description`, `meta_keywords` from ' . TABLE_ADS . ' where ' . TABLE_ADS . '.id=\'' . $id . '\';' );
if ($page_info) {
foreach ($page_info as $key => $value) {
$page_info[$key] = clean( $value );
}
$page_info['title'] = $this->get_start_string( strip_tags( $page_info['title'] ), 65 );
}
}
if (( ( !$ads_settings['add_meta_with_listings'] || !$page_info['meta_keywords'] ) || !$page_info['meta_description'] )) {
global $extra_fields;
$str_extra_fields = '';
foreach ($extra_fields as $meta_field) {
$str_extra_fields .= ', ' . TABLE_ADS . ( '' . '.`' . $meta_field . '`' );
}
$sql = '' . 'select ' . $title_field . ', ' . TABLE_ADS . '.' . $description_field . $str_extra_fields . ', ' . TABLE_CATEGORIES . '_lang.`name` as `category` from ' . TABLE_ADS . ' left join ' . TABLE_CATEGORIES . '_lang on ' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id where ' . TABLE_ADS . '.id=\'' . $id . '\';';
$row_ads = $db->fetchAssoc( $sql );
if (!$page_info['title']) {
$page_info['title'] = $this->get_start_string( strip_tags( clean( $row_ads['title'] ) ), 60 );
}
if (!$page_info['meta_description']) {
$page_info['meta_description'] = $this->get_start_string( strip_tags( clean( $row_ads['description'] ) ), 200 );
}
if (!$page_info['meta_keywords']) {
foreach ($extra_fields as $meta_field) {
if ($row_ads[$meta_field]) {
$page_info['meta_keywords'] .= clean( $row_ads[$meta_field] ) . ', ';
continue;
}
}
if ($row_ads['category']) {
$page_info['meta_keywords'] .= clean( $row_ads['category'] ) . ', ';
}
$page_info['meta_keywords'] .= $this->shuffle_keys( clean( $row_ads['title'] ) ) . ', ' . $this->shuffle_keys( $this->start_words( strip_tags( clean( $row_ads['description'] ) ), 150 ) );
}
}
return $page_info;
}
function get_start_string($str, $len) {
if ($len < strlen( $str )) {
$ret = substr( $str, 0, $len ) . '...';
return $ret;
}
return $str;
}
function shuffle_keys($str) {
$clean_str = ereg_replace( '[^[:alnum:]+]', ' ', $str );
$keys = '';
$array_str = explode( ' ', trim( $clean_str ) );
$n = count( $array_str );
srand( (double)microtime( ) * 1000000 );
$i = 0;
$used = array( );
$values = array( );
$i = 0;
while ($i < $n) {
$used[$i] = '';
$values[$i] = '';
++$i;
}
$a = 0;
$i = 0;
while ($i < $n) {
$val = rand( 0, $n - 1 );
$again = 0;
$j = 0;
while ($j < count( $used )) {
if ($used[$j] == $val) {
$again = 1;
continue;
}
++$j;
}
if (!$again) {
$used[$a] = $val;
$values[$i] = trim( $array_str[$val] );
++$a;
}
++$i;
}
$first = 1;
$k = 0;
while ($k < $n) {
if (2 < strlen( trim( $array_str[$k] ) )) {
if (0 < $k) {
$first = 0;
}
if (!$first) {
$keys .= ', ';
}
$keys .= $array_str[$k];
}
++$k;
}
return $keys;
}
function start_words($str, $len) {
if ($len < strlen( $str )) {
$ret = substr( $str, 0, $len );
return $ret;
}
return $str;
}
function deleteexpired() {
global $db;
global $settings;
$delete_expired = $settings['delete_expired'];
$days_del_expired = $settings['days_del_expired'];
if (!$delete_expired) {
return null;
}
$timestamp = date( 'Y-m-d H:i:s' );
if (!$days_del_expired) {
$sql = 'select id from ' . TABLE_ADS . ( '' . ' where `active`=0 and `date_expires` <= \'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\'' );
} else {
$sql = 'select id from ' . TABLE_ADS . ( '' . ' where active=0 and date_expires <= \'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\' and date_expires is not null and date_add(`date_expires`, interval \'' . $days_del_expired . '\' day) <= \'' . $timestamp . '\'' );
}
$arr = $db->fetchRowList( $sql );
$listing = new listings( );
foreach ($arr as $l) {
$listing->delete( $l );
}
return 1;
}
function markexpired() {
global $db;
global $config_live_site;
global $ads_settings;
global $settings;
$send_mail = $settings['send_mail_to_user_when_expired'];
$mail_settings_cl = new mail_settings( );
$mails_settings = $mail_settings_cl->getAll( );
$html_mails = $mails_settings['html_mails'];
if ($send_mail) {
$mails = new mail_templates( );
$mail_array = $mails->getVal( 'listing_expired' );
}
global $crt_lang;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '` as `title`';
}
}
$timestamp = date( 'Y-m-d H:i:s' );
$result = $db->fetchAssocList( 'select ' . TABLE_ADS . ( '' . '.id, ' . $title_var . ', user_id, ' ) . TABLE_USERS . '.`username`, ' . TABLE_USERS . '.`email`, ' . TABLE_USERS . '.`contact_name` from ' . TABLE_ADS . '
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
where ' . TABLE_ADS . ( '' . '.active=1 and date_expires <= \'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\' and date_expires is not null;' ) );
foreach ($result as $row) {
$this->expired( $row['id'] );
if ($send_mail == 1) {
if ($row['user_id']) {
$user_id = $row['user_id'];
$username = $row['username'];
$user_email = $row['email'];
$user_contact = $row['contact_name'];
if (!$user_contact) {
$user_contact = $username;
}
} else {
if ($settings['nologin_enabled']) {
$user_id = 0;
$username = '';
$user_details = $this->getOwnerInfo( $row['id'] );
$user_contact = $user_details['mgm_name'];
$user_email = $user_details['mgm_email'];
$activation = $user_details['activation'];
} else {
continue;
}
}
$mail2send = new mails( $user_email, $user_contact );
$subject = $mail_array['subject'];
$msg = $mail_array['content'];
global $seo_settings;
if ($seo_settings['enable_mod_rewrite']) {
$url_title = _urlencode( $row['title'] );
$details_link = $config_live_site . '/' . $row['id'] . '-' . $url_title . '/details.html';
} else {
$details_link = $config_live_site . '/details.php?id=' . $row['id'];
}
if ($html_mails) {
$details_link = '<a href="' . $details_link . '">' . $details_link . '</a>';
}
if ($html_mails) {
$amp = '&';
} else {
$amp = '&';
}
$renew_link = $config_live_site . '/renewad.php?id=' . $row['id'];
if (!$user_id) {
$renew_link .= $amp . 'key=' . $activation;
}
if ($html_mails) {
$renew_link = '<a href="' . $renew_link . '">' . $renew_link . '</a>';
}
$smarty_info = new Smarty( );
$smarty_info = smartyshowdbval( $smarty_info );
$smarty_info->assign( 'value', $msg );
$smarty_info->assign( 'username', $username );
$smarty_info->assign( 'contact_name', $user_contact );
$smarty_info->assign( 'ad_id', $row['id'] );
$smarty_info->assign( 'renew_link', $renew_link );
$smarty_info->assign( 'details_link', $details_link );
$msg = $smarty_info->fetch( 'db_template.html' );
$smarty_info->assign( 'value', $subject );
$subject = $smarty_info->fetch( 'db_template.html' );
$mail2send->setSubject( $subject );
$mail2send->setMessage( $msg );
$mail2send->send( );
continue;
}
}
return 1;
}
function notifyexpired() {
global $db;
global $config_live_site;
global $ads_settings;
global $settings;
$days_notify = $settings['days_notify'];
if ($days_notify == 0) {
return null;
}
$mail_settings_cl = new mail_settings( );
$mails_settings = $mail_settings_cl->getAll( );
$html_mails = $mails_settings['html_mails'];
if ($html_mails) {
$amp = '&';
} else {
$amp = '&';
}
global $seo_settings;
global $crt_lang;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '` as `title`';
}
}
$mails = new mail_templates( );
$mail_array = $mails->getVal( 'listing_will_expire' );
$timestamp = date( 'Y-m-d H:i:s' );
$result = $db->fetchAssocList( 'select ' . TABLE_ADS . ( '' . '.id, ' . $title_var . ', user_id, ' ) . TABLE_USERS . '.`username`, ' . TABLE_USERS . '.`email`, ' . TABLE_USERS . '.`contact_name` from ' . TABLE_ADS . '
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
where ' . TABLE_ADS . ( '' . '.active=1 and datediff(date_expires,\'' . $timestamp . '\')=' . $days_notify . ' and date_added!=date_add(date_added, interval no_days day);' ) );
foreach ($result as $row) {
if ($row['user_id']) {
$user_id = $row['user_id'];
$username = $row['username'];
$user_email = $row['email'];
$user_contact = $row['contact_name'];
if (!$user_contact) {
$user_contact = $username;
}
} else {
if ($settings['nologin_enabled']) {
$user_id = 0;
$username = '';
$user_details = $this->getOwnerInfo( $row['id'] );
$user_contact = $user_details['mgm_name'];
$user_email = $user_details['mgm_email'];
$activation = $user_details['activation'];
} else {
continue;
}
}
$mail2send = new mails( $user_email, $user_contact );
$subject = $mail_array['subject'];
$msg = $mail_array['content'];
if ($seo_settings['enable_mod_rewrite']) {
$url_title = _urlencode( $row['title'] );
$details_link = $config_live_site . '/' . $row['id'] . '-' . $url_title . '/details.html';
} else {
$details_link = $config_live_site . '/details.php?id=' . $row['id'];
}
if (!$user_id) {
$details_link .= $amp . 'key=' . $activation;
}
if ($html_mails) {
$details_link = '<a href="' . $details_link . '">' . $details_link . '</a>';
}
$renew_link = $config_live_site . '/renewad.php?id=' . $row['id'];
if (!$user_id) {
$renew_link .= $amp . 'key=' . $activation;
}
if ($html_mails) {
$renew_link = '<a href="' . $renew_link . '">' . $renew_link . '</a>';
}
$smarty_info = new Smarty( );
$smarty_info = smartyshowdbval( $smarty_info );
$smarty_info->assign( 'value', $msg );
$smarty_info->assign( 'username', $username );
$smarty_info->assign( 'contact_name', $user_contact );
$smarty_info->assign( 'id', $row['id'] );
$smarty_info->assign( 'renew_link', $renew_link );
$smarty_info->assign( 'details_link', $details_link );
$smarty_info->assign( 'days_expire', $days_notify );
$msg = $smarty_info->fetch( 'db_template.html' );
$smarty_info->assign( 'value', $subject );
$subject = $smarty_info->fetch( 'db_template.html' );
$mail2send->setSubject( $subject );
$mail2send->setMessage( $msg );
$mail2send->send( );
}
return 1;
}
function getviewed($user_id = '') {
global $db;
if ($user_id != '') {
$str_usr = '' . ' where user_id=\'' . $user_id . '\'';
} else {
$str_usr = '';
}
$no = $db->fetchRow( 'select sum(viewed) from ' . TABLE_ADS . $str_usr );
if (!$no) {
return 0;
}
return $no;
}
function addcheckpaymentaction($id, $user_id, $type, $amount) {
global $db;
$timestamp = date( 'Y-m-d H:i:s' );
$res = $db->query( 'INSERT INTO ' . TABLE_PAYMENT_ACTIONS . ' SET `processor`=\'check\', user_id=\'' . $user_id . '\', ad_id=\'' . $id . ( '' . '\', type = \'' . $type . '\', amount = \'' . $amount . '\', date=\'' . $timestamp . '\'' ) );
$id = $db->insertId( );
return $id;
}
function strip_html_tags($str) {
$search = array( '@<script[^>]*?>.*?</script>@si', '@<style[^>]*?>.*?</style>@siU', '@<[\/\!]*?[^<>]*?>@si', '@<![\s\S]*?--[ \t\n\r]*>@' );
$text = preg_replace( $search, '', $str );
return $text;
}
function activatependingpackage($usr_pkg) {
global $db;
$array = $db->fetchAssocList( 'select ' . TABLE_ADS . '.`id` as `ad_id`, ' . TABLE_ADS . '.`active` as `ad_active`, ' . TABLE_USER_GROUPS . '.listing_pending, ' . TABLE_PACKAGES . '.`type` as `package_type` from ' . TABLE_ADS . '
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.`user_id` = ' . TABLE_USERS . '.`id`
left join ' . TABLE_USER_GROUPS . ' on ' . TABLE_USERS . '.`group` = ' . TABLE_USER_GROUPS . '.id
left join ' . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.`package_id` = ' . TABLE_PACKAGES . ( '' . '.id
where usr_pkg=\'' . $usr_pkg . '\' and pending=1' ) );
foreach ($array as $ad) {
if (( ( !$ad['listing_pending'] || $ad['package_type'] == 'ad' ) && !$ad['ad_active'] )) {
$this->Activate( $ad['ad_id'] );
continue;
}
}
}
function getallid($limit = 0) {
global $db;
if ($limit) {
$str_limit = ' limit ' . $limit;
} else {
$str_limit = '';
}
$array = $db->fetchRowList( 'select id from ' . TABLE_ADS . ' where active=1 order by date_added desc' . $str_limit );
return $array;
}
function getallsitemap($limit = 0) {
global $db;
global $crt_lang;
global $ads_settings;
$title_var = '`title`';
if ($ads_settings['translate_title_description']) {
$languages = languages::getactivelanguages( );
if (1 < count( $languages )) {
$title_var = '' . '`title_' . $crt_lang . '` as `title`';
}
}
if ($limit) {
$str_limit = ' limit ' . $limit;
} else {
$str_limit = '';
}
$array = $db->fetchAssocList( '' . 'select id, ' . $title_var . ' from ' . TABLE_ADS . ' where active=1 order by date_added desc' . $str_limit );
$i = 0;
$result = array( );
foreach ($array as $l) {
$result[$i] = $l;
$result[$i]['url_title'] = _urlencode( $result[$i]['title'] );
++$i;
}
return $result;
}
function addfavourite($ad_id) {
global $db;
$auth = new auth( );
if ($user_id = $auth->crtUserId( )) {
$res_exists = $db->query( 'select * from ' . TABLE_FAVOURITES . ( '' . ' where ad_id=' . $ad_id . ' and user_id=' . $user_id ) );
if (!$db->numRows( $res_exists )) {
$res = $db->query( 'insert into ' . TABLE_FAVOURITES . ( '' . ' values (' . $ad_id . ', ' . $user_id . ')' ) );
return 1;
}
} else {
if (!isset( $_SESSION['favourites'] )) {
$i = 0;
} else {
$i = count( $_SESSION['favourites'] );
}
$exists = 0;
$k = 0;
while ($k < $i) {
if ($_SESSION['favourites'][$k] == $ad_id) {
$exists = 1;
}
++$k;
}
if (!$exists) {
$_SESSION['favourites'][$i] = $ad_id;
}
}
return 1;
}
function getnofavourites() {
global $db;
$auth = new auth( );
if ($user_id = $auth->crtUserId( )) {
$no = $db->fetchRow( 'select count(*) from ' . TABLE_FAVOURITES . ( '' . ' where user_id=' . $user_id ) );
} else {
$no = count( $_SESSION['favourites'] );
}
return $no;
}
function deletefavourite($ad_id) {
global $db;
$auth = new auth( );
if ($user_id = $auth->crtUserId( )) {
$res_del = $db->query( 'delete from ' . TABLE_FAVOURITES . ' where `ad_id`="' . $ad_id . '" and user_id = "' . $user_id . '"' );
return null;
}
array_splice( $_SESSION['favourites'], array_search( $ad_id, $_SESSION['favourites'] ), 1 );
}
function getallfavourites($page, $ads_per_page, $order_by, $order_way) {
global $db;
$exists = 0;
$start = ( $page - 1 ) * $ads_per_page;
$auth = new auth( );
if ($user_id = $auth->crtUserId( )) {
$where = ' LEFT JOIN ' . TABLE_FAVOURITES . ' on ' . TABLE_ADS . '.id = ' . TABLE_FAVOURITES . '.ad_id where ' . TABLE_FAVOURITES . ( '' . '.`user_id` = \'' . $user_id . '\'' );
$exists = 1;
} else {
if (isset( $_SESSION['favourites'] )) {
$no = count( $_SESSION['favourites'] );
} else {
$no = 0;
}
$str_ids = ' (';
$k = 0;
while ($k < $no) {
if ($k) {
$str_ids .= ', ';
}
$str_ids .= $_SESSION['favourites'][$k];
++$k;
}
$str_ids .= ')';
if (0 < $no) {
$where = ' where ' . TABLE_ADS . '.`id` in ' . $str_ids . ' and ' . TABLE_ADS . '.`active` = 1';
$exists = 1;
}
}
if (!$order_by) {
$order_by = 'date_added';
}
$order_by = ' order by ' . $order_by;
if (!$order_way) {
$order_way = 'desc';
}
$result = array( );
if ($exists) {
$result = $this->getShortListings( $where, $order_by, $order_way, $start, $ads_per_page );
}
return $result;
}
function getfavouritesarray() {
global $db;
$auth = new auth( );
$arr = array( );
if ($user_id = $auth->crtUserId( )) {
$arr = $db->fetchRowList( 'select `ad_id` from ' . TABLE_FAVOURITES . ( '' . ' where `user_id` = \'' . $user_id . '\'' ) );
return $arr;
}
if (( isset( $_SESSION['favourites'] ) && $_SESSION['favourites'] )) {
$arr = $_SESSION['favourites'];
}
return $arr;
}
function gettablefields() {
global $db;
$extra_fields = array( 'pictures', 'date_formatted', 'date_expires_formatted', 'expired', 'category', 'plan', 'plan_amount', 'username', 'pending_package', 'invoice', 'price_formatted', 'stock' );
$fields = $db->getTableFields( TABLE_ADS );
$fields = array_merge( $fields, $extra_fields );
return $fields;
}
function gettablecsvfields($extra = 1) {
global $db;
$extra_fields = array( 'pictures', 'date_formatted', 'date_expires_formatted', 'expired', 'category', 'plan', 'plan_amount', 'username', 'pending_package', 'invoice', 'price_formatted', 'stock' );
$fields = $db->getTableCSVFields( TABLE_ADS );
if (!$extra) {
return $fields;
}
foreach ($extra_fields as $f) {
$fields .= ',' . $f;
}
return $fields;
}
function exportlistings($type) {
global $db;
global $lng;
global $appearance_settings;
global $ads_settings;
$date_format = $appearance_settings['date_format'];
$where = '';
$where_start = ' where';
if (( isset( $_POST[$type . '_category'] ) && is_numeric( $_POST[$type . '_category'] ) )) {
$where .= $where_start . ' ' . TABLE_ADS . '.`category_id` = \'' . $_POST[$type . '_category'] . '\'';
$where_start = ' and';
}
if (( isset( $_POST[$type . '_plan'] ) && is_numeric( $_POST[$type . '_plan'] ) )) {
$where .= $where_start . ' ' . TABLE_ADS . '.`package_id` = \'' . $_POST[$type . '_plan'] . '\'';
$where_start = ' and';
}
if (( isset( $_POST[$type . '_user'] ) && is_numeric( $_POST[$type . '_user'] ) )) {
$where .= $where_start . ' ' . TABLE_ADS . '.`user_id` = \'' . $_POST[$type . '_user'] . '\'';
$where_start = ' and';
}
if (( isset( $_POST[$type . '_date_start'] ) && $_POST[$type . '_date_start'] != '' )) {
$where .= $where_start . ' ' . TABLE_ADS . '.`date_added` > \'' . escape( $_POST[$type . '_date_start'] ) . '\'';
$where_start = ' and';
}
if (( isset( $_POST[$type . '_date_end'] ) && $_POST[$type . '_date_end'] != '' )) {
$where .= $where_start . ' ' . TABLE_ADS . '.`date_added` < \'' . escape( $_POST[$type . '_date_end'] ) . '\'';
$where_start = ' and';
}
if (isset( $_POST[$type . '_last'] )) {
$last = escape( $_POST[$type . '_last'] );
} else {
$last = '';
}
if (( isset( $_POST[$type . '_ad_order_by'] ) && $_POST[$type . '_ad_order_by'] != '' )) {
$order_by = escape( $_POST[$type . '_ad_order_by'] );
} else {
$order_by = TABLE_ADS . '.date_added';
}
if (( isset( $_POST[$type . '_ad_order_way'] ) && $_POST[$type . '_ad_order_way'] != '' )) {
$order_way = escape( $_POST[$type . '_ad_order_way'] );
} else {
$order_way = 'desc';
}
$timestamp = date( 'Y-m-d H:i:s' );
$sql = 'select ' . TABLE_ADS . '.*, ' . TABLE_ADS . ( '' . '.id as id, date_format(`date_added`,\'' . $date_format . '\') as date_formatted, date_format(`date_expires`,\'' . $date_format . '\') as date_expires_formatted, (date_expires<\'' . $timestamp . '\' and date_expires!=\'0000-00-00 00:00:00\' and ' ) . TABLE_ADS . '.active=0) as expired, ' . TABLE_CATEGORIES . '_lang.name as category, ' . TABLE_PACKAGES . '_lang.name as plan, ' . TABLE_PACKAGES . '.amount as plan_amount, ' . TABLE_USERS . '.username as username, ' . TABLE_USERS_PACKAGES . '.pending as pending_package, ' . TABLE_ACTIONS . '.`invoice` from ' . TABLE_ADS . '
left join ' . TABLE_CATEGORIES . '_lang on ' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id
left join ' . TABLE_PACKAGES . '_lang on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '_lang.id
left join ' . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id
left join ' . TABLE_USERS_PACKAGES . ' on ' . TABLE_ADS . '.usr_pkg=' . TABLE_USERS_PACKAGES . '.id
left join ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id
left join ' . TABLE_ACTIONS . ' on ' . TABLE_ADS . '.id=' . TABLE_ACTIONS . '.object_id
' . $where . ' and ( ' . TABLE_ACTIONS . '.`type` like \'newad\' or ' . TABLE_ACTIONS . '.`type` like \'renewad\' )
group by ' . TABLE_ADS . '.id
order by ' . $order_by . ' ' . $order_way . ' , ' . TABLE_ACTIONS . '.`date` desc';
if (0 < $last) {
$sql .= ' limit ' . $last;
}
return $sql;
}
function moveads($from, $to, $type) {
global $db;
if (( !$from || !$to )) {
return null;
}
if ($type == 'plan') {
$db->query( 'update ' . TABLE_ADS . ( '' . ' set `package_id` = ' . $to . ' where `package_id` = ' . $from ) );
return 1;
}
if ($type == 'categ') {
$db->query( 'update ' . TABLE_ADS . ( '' . ' set `category_id` = ' . $to . ' where `category_id` = ' . $from ) );
}
return 1;
}
function getoptions($id) {
global $db;
$array = $db->fetchAssoc( 'select `category_id`, `package_id`, `featured`, `highlited`,`priority` from ' . TABLE_ADS . ( '' . '
where `id`=' . $id ) );
$video = $db->fetchRow( 'select count(*) from ' . TABLE_OPTIONS . ( '' . ' where `option` like \'video\' and `object_id` = ' . $id ) );
if ($video) {
$array['video'] = 1;
} else {
$array['video'] = 0;
}
return $array;
}
function editoptions($id) {
global $db;
$featured = checkbox_value( 'featured' );
$highlited = checkbox_value( 'highlited' );
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `featured`=\'' . $featured . '\', `highlited`=\'' . $highlited . '\'where id=' . $id . ' ' ) );
if ($featured) {
$this->addOption( $id, 'featured' );
}
if ($highlited) {
$this->addOption( $id, 'highlited' );
}
if (( isset( $_POST['priority'] ) && is_numeric( $_POST['priority'] ) )) {
$priority = $_POST['priority'];
$res1 = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `priority`=\'' . $priority . '\' where id=' . $id . ' ' ) );
$this->addOption( $id, 'priority' );
}
$video = checkbox_value( 'video' );
$this->setVideo( $id, $video );
return 1;
}
function deleteoptions($id) {
global $db;
$db->query( 'delete from ' . TABLE_OPTIONS . ( '' . ' where `object_id` = \'' . $id . '\' and ( `option` like \'video\' or `option` like \'highlited\' or `option` like \'priority\' or `option` like \'featured\')' ) );
return 1;
}
function deleteunapproved() {
global $db;
$timestamp = date( 'Y-m-d H:i:s' );
$result = $db->fetchRowList( 'select id from ' . TABLE_ADS . ( '' . ' where `active`=0 and `user_approved`=0 and date_add(date_added, interval \'10\' day)<\'' . $timestamp . '\'' ) );
foreach ($result as $row) {
$this->delete( $row );
}
return 1;
}
function markexpiredoption() {
global $db;
global $config_live_site;
global $lng;
$mail_settings_cl = new mail_settings( );
$mails_settings = $mail_settings_cl->getAll( );
$html_mails = $mails_settings['html_mails'];
if ($html_mails) {
$amp = '&';
} else {
$amp = '&';
}
global $ads_settings;
global $settings;
$store_expires = $ads_settings['store_availability'];
$mails = new mail_templates( );
$users = new users( );
$store_mail_array = $mails->getVal( 'store_expired' );
$ad_mail_array = $mails->getVal( 'ad_options_expired' );
$timestamp = date( 'Y-m-d H:i:s' );
$result = $db->fetchAssocList( 'select * from ' . TABLE_OPTIONS . ( '' . ' where date_expires <= \'' . $timestamp . '\' and `date_expires`!=\'0000-00-00 00:00:00\' and `date_expires` is not null order by `object_id`;' ) );
$no_res = count( $result );
$user = new users( );
$i = 0;
while ($i < $no_res) {
$row = $result[$i];
if ($row['option'] == 'store') {
$mail_array = $store_mail_array;
$user_id = $row['object_id'];
} else {
$mail_array = $ad_mail_array;
$user_id = $this->getUser( $row['object_id'] );
}
if ($user_id) {
$user_details = $user->getContactData( $user_id );
$username = $user_details['username'];
$user_email = $user_details['email'];
$user_contact = $user_details['contact_name'];
if (!$user_contact) {
$user_contact = $username;
}
} else {
if (( $settings['nologin_enabled'] && $row['option'] != 'store' )) {
$user_id = 0;
$username = '';
$user_details = $this->getOwnerInfo( $row['object_id'] );
$user_contact = $user_details['mgm_name'];
$user_email = $user_details['mgm_email'];
$activation = $user_details['activation'];
} else {
continue;
}
}
$mail2send = new mails( $user_email, $user_contact );
$subject = $mail_array['subject'];
$msg = $mail_array['content'];
$id = $row['object_id'];
$smarty_info = new Smarty( );
$smarty_info = smartyshowdbval( $smarty_info );
$smarty_info->assign( 'value', $msg );
$smarty_info->assign( 'username', $username );
$smarty_info->assign( 'contact_name', $user_contact );
$smarty_info->assign( 'id', $id );
if ($row['option'] == 'store') {
$user->disableStore( $id );
} else {
$j = $i + 1;
$options_list = $lng['listings'][$row['option']];
$options_array = array( );
$options_array[0] = $row['option'];
$array_ad = array( 'featured', 'highlited', 'video', 'priority' );
while (( ( $j < $no_res && $result[$j]['object_id'] == $row['object_id'] ) && $result[$j]['option'] != 'store' )) {
$i = $j;
++$j;
$row = $result[$i];
$options_list .= ', ' . $lng['listings'][$row['option']];
$options_array[count( $options_array )] = $row['option'];
}
$this->removeOptions( $options_array, $row['object_id'] );
global $seo_settings;
if ($seo_settings['enable_mod_rewrite']) {
$url_title = listings::geturltitle( $id );
$details_link = $config_live_site . '/' . $id . '-' . $url_title . '/details.html';
} else {
$details_link = $config_live_site . '/details.php?id=' . $id;
}
if ($html_mails) {
$details_link = '<a href="' . $details_link . '">' . $details_link . '</a>';
}
$smarty_info->assign( 'details_link', $details_link );
$smarty_info->assign( 'expired_options', $options_list );
}
$msg = $smarty_info->fetch( 'db_template.html' );
$smarty_info->assign( 'value', $subject );
$subject = $smarty_info->fetch( 'db_template.html' );
$mail2send->setSubject( $subject );
$mail2send->setMessage( $msg );
$mail2send->send( );
++$i;
}
$timestamp = date( 'Y-m-d H:i:s' );
$result_del = $db->query( 'delete from ' . TABLE_OPTIONS . ( '' . ' where date_expires <= \'' . $timestamp . '\' and `date_expires`!=\'0000-00-00 00:00:00\' and `date_expires` is not null;' ) );
return 1;
}
function removeoptions($array, $id) {
global $db;
if (!count( $array )) {
return null;
}
$str = '';
foreach ($array as $row) {
switch ($row) {
case 'featured': {
if ($str) {
$str .= ', ';
}
$str .= '`featured` = 0';
break;
}
case 'priority': {
if ($str) {
$str .= ', ';
}
$str .= '`priority` = 1000';
break;
}
case 'highlited': {
if ($str) {
$str .= ', ';
}
$str .= '`highlited` = 0';
break;
}
case 'video': {
}
}
}
if ($str) {
$db->query( 'update ' . TABLE_ADS . ( '' . ' set ' . $str . ' where `id`=' . $id ) );
}
return 1;
}
function checklanguagefields() {
global $db;
$adss = new ads_settings( );
$ads_settings = $adss->getAll( );
$add_translation = $ads_settings['translate_title_description'];
$languages = languages::getactivelanguages( );
if (count( $languages ) == 1) {
$add_translation = 0;
}
$ad_fields = db_mysql::gettablecsvfields( TABLE_ADS );
$array_fields = explode( ',', $ad_fields );
$def_id = languages::getdefault( );
if (!$def_id) {
return null;
}
if (( in_array( 'description', $array_fields ) && $add_translation )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `description` `description_' . $def_id . '` text' ) );
}
if (( in_array( 'title', $array_fields ) && $add_translation )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `title` `title_' . $def_id . '` varchar(150)' ) );
}
if (( in_array( 'description_' . $def_id, $array_fields ) && !$add_translation )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `description_' . $def_id . '` `description` text' ) );
}
if (( in_array( 'title_' . $def_id, $array_fields ) && !$add_translation )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `title_' . $def_id . '` `title` varchar(150)' ) );
}
foreach ($languages as $l) {
$lid = $l['id'];
if ($lid == $def_id) {
continue;
}
if (!$lid) {
continue;
}
if (( $add_translation && !in_array( '' . 'description_' . $lid, $array_fields ) )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' add `description_' . $lid . '` text' ) );
} else {
if (( !$add_translation && in_array( '' . 'description_' . $lid, $array_fields ) )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' drop `description_' . $lid . '`' ) );
}
}
if (( $add_translation && !in_array( '' . 'title_' . $lid, $array_fields ) )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' add `title_' . $lid . '` text' ) );
continue;
}
if (( !$add_translation && in_array( '' . 'title_' . $lid, $array_fields ) )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' drop `title_' . $lid . '`' ) );
continue;
}
}
}
function deletelanguagefields($lang_id) {
global $ads_settings;
global $db;
$ad_fields = db_mysql::gettablecsvfields( TABLE_ADS );
$array_fields = explode( ',', $ad_fields );
if (in_array( '' . 'description_' . $lang_id, $array_fields )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' drop `description_' . $lang_id . '`' ) );
}
if (in_array( '' . 'title_' . $lang_id, $array_fields )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' drop `title_' . $lang_id . '`' ) );
}
$languages = languages::getactivelanguages( );
if (count( $languages ) != 1) {
return 1;
}
$def_id = languages::getdefault( );
if (!$def_id) {
return null;
}
if (in_array( 'description_' . $def_id, $array_fields )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `description_' . $def_id . '` `description` text' ) );
}
if (in_array( 'title_' . $def_id, $array_fields )) {
$db->query( 'ALTER TABLE ' . TABLE_ADS . ( '' . ' CHANGE `title_' . $def_id . '` `title` text' ) );
}
return 1;
}
function getdateexpires($id) {
global $db;
global $appearance_settings;
$date_format = $appearance_settings['date_format'];
$timestamp = date( 'Y-m-d H:i:s' );
$expires = $db->fetchAssoc( '' . 'select `date_expires`, date_format(`date_expires`,\'%e\') as `day`, date_format(`date_expires`,\'%c\') as `month`, date_format(`date_expires`,\'%Y\') as `year`, (`date_expires`<\'' . $timestamp . '\' and `date_expires`!=\'0000-00-00 00:00:00\' and active=0) as expired from ' . TABLE_ADS . ( '' . ' where `id`=' . $id ) );
return $expires;
}
function changeexpiredate($id) {
global $db;
global $appearance_settings;
$was_expired = $this->isExpired( $id );
$crt_date_expires = $db->fetchRow( 'select date_format(`date_expires`, \'%Y-%c-%e\') from ' . TABLE_ADS . ( '' . ' where `id`=' . $id ) );
if ($_POST['expires'] == 1) {
$expires = 1;
} else {
$expires = 0;
}
if ($expires) {
$day = escape( $_POST['expires_day'] );
$month = escape( $_POST['expires_month'] );
$year = escape( $_POST['expires_year'] );
$new_date_expires = '' . $year . '-' . $month . '-' . $day;
} else {
$new_date_expires = '';
}
if ($crt_date_expires != $new_date_expires) {
$db->query( 'update ' . TABLE_ADS . ( '' . ' set `date_expires` = \'' . $new_date_expires . '\' where id=' . $id . ' ' ) );
}
if ($was_expired) {
$timestamp = date( 'Y-m-d H:i:s' );
if ($expires) {
$renew = $db->fetchRow( '' . 'select \'' . $new_date_expires . '\'<\'' . $timestamp . '\' as renew' );
}
if (( !$expires || $renew )) {
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `active`=1 where `id`=\'' . $id . '\'' ) );
}
}
return 1;
}
function getnext($id, $cat) {
global $db;
if ($cat) {
$where_str = '' . 'and category_id=' . $cat;
} else {
$where_str = '';
}
$id = $db->fetchRow( 'select id from ' . TABLE_ADS . ( '' . ' where id<' . $id . ' ' ) . $where_str . ' order by id desc limit 1' );
return $id;
}
function isnologinad($id) {
global $db;
$user_id = $db->fetchRow( 'select user_id from ' . TABLE_ADS . ( '' . ' where `id` = ' . $id . ' ' ) );
if (!$user_id) {
return 1;
}
return 0;
}
function getvideo($id) {
global $db;
$video = $db->fetchRow( 'select video from ' . TABLE_ADS . ( '' . ' where `id` = ' . $id . ' ' ) );
return $video;
}
function savevideo($id, $video_code) {
global $db;
$res = $db->query( 'update ' . TABLE_ADS . ( '' . ' set `video` = \'' . $video_code . '\' where `id` = ' . $id . ' ' ) );
return 1;
}
}
?>