/** * Display an ad's detail * @param string $ad_id ID of ad to display */ function adDetail($ad_id = '') { global $_USER, $_TABLES, $_CONF, $LANG_ADVT, $_CONF_ADVT; USES_lib_comments(); // Determind if this is an administrator $admin = SEC_hasRights($_CONF_ADVT['pi_name'] . '.admin'); $ad_id = COM_sanitizeID($ad_id); if ($ad_id == '') { // An ad id is required for this function return CLASSIFIEDS_errorMsg($LANG_ADVT['missing_id'], 'alert'); } $srchval = isset($_GET['query']) ? trim($_GET['query']) : ''; // We use this in a few places here, so might as well just // figure it out once and save it. $perm_sql = COM_getPermSQL('AND', 0, 2, 'ad') . ' ' . COM_getPermSQL('AND', 0, 2, 'cat'); // get the ad information. $sql = "SELECT ad.*\n FROM {$_TABLES['ad_ads']} ad\n LEFT JOIN {$_TABLES['ad_category']} cat\n ON ad.cat_id = cat.cat_id\n WHERE ad_id='{$ad_id}'"; if (!$admin) { $sql .= $perm_sql; } $result = DB_query($sql); if (!$result || DB_numRows($result) < 1) { return CLASSIFIEDS_errorMsg($LANG_ADVT['no_ad_found'], 'note', 'Oops...'); } $ad = DB_fetchArray($result, false); // Check access to the ad. If granted, check that access isn't // blocked by any category. $my_access = CLASSIFIEDS_checkAccess($ad['ad_id'], $ad); if ($my_access >= 2) { $my_cat_access = CLASSIFIEDS_checkCatAccess($ad['cat_id'], false); if ($my_cat_access < $my_access) { $my_access = $my_cat_access; } } if ($my_access < 2) { return CLASSIFIEDS_errorMsg($LANG_ADVT['no_permission'], 'alert', $LANG_ADVT['access_denied']); } $cat = (int) $ad['cat_id']; // Increment the views counter $sql = "UPDATE {$_TABLES['ad_ads']} \n SET views = views + 1 \n WHERE ad_id='{$ad_id}'"; DB_query($sql); // Get the previous and next ads $condition = " AND ad.cat_id={$cat}"; if (!$admin) { $condition .= $perm_sql; } $sql = "SELECT ad_id\n FROM {$_TABLES['ad_ads']} ad\n LEFT JOIN {$_TABLES['ad_category']} cat\n ON ad.cat_id = cat.cat_id\n WHERE ad_id < '{$ad_id}' \n {$condition}\n ORDER BY ad_id DESC\n LIMIT 1"; $r = DB_query($sql); list($preAd_id) = DB_fetchArray($r, false); $sql = "SELECT ad_id\n FROM {$_TABLES['ad_ads']} ad\n LEFT JOIN {$_TABLES['ad_category']} cat\n ON ad.cat_id = cat.cat_id\n WHERE ad_id > '{$ad_id}' \n {$condition}\n ORDER BY ad_id ASC\n LIMIT 1"; $r = DB_query($sql); list($nextAd_id) = DB_fetchArray($r, false); // Get the user contact info. If none, just show the email link $sql = "SELECT * \n FROM {$_TABLES['ad_uinfo']} \n WHERE uid='{$ad['uid']}'"; //echo $sql; $result = DB_query($sql); $uinfo = array(); if ($result && DB_numRows($result) > 0) { $uinfo = DB_fetchArray($result); } else { $uinfo['uid'] = ''; $uinfo['address'] = ''; $uinfo['city'] = ''; $uinfo['state'] = ''; $uinfo['postal'] = ''; $uinfo['tel'] = ''; $uinfo['fax'] = ''; } // Get the hot results (most viewed ads) $time = time(); $sql = "SELECT ad.ad_id, ad.cat_id, ad.subject,\n cat.cat_id, cat.fgcolor, cat.bgcolor\n FROM {$_TABLES['ad_ads']} ad\n LEFT JOIN {$_TABLES['ad_category']} cat\n ON ad.cat_id = cat.cat_id\n WHERE ad.exp_date > {$time} \n {$perm_sql}\n ORDER BY views DESC \n LIMIT 4"; //echo $sql;die; $hotresult = DB_query($sql); // convert line breaks & others to html $patterns = array('/\\n/'); $replacements = array('<br />'); $ad['descript'] = PLG_replaceTags(COM_checkHTML($ad['descript'])); $ad['descript'] = preg_replace($patterns, $replacements, $ad['descript']); $ad['subject'] = strip_tags($ad['subject']); $ad['price'] = strip_tags($ad['price']); $ad['url'] = COM_sanitizeUrl($ad['url']); $ad['keywords'] = strip_tags($ad['keywords']); // Highlight search terms, if any if ($srchval != '') { $ad['subject'] = COM_highlightQuery($ad['subject'], $srchval); $ad['descript'] = COM_highlightQuery($ad['descript'], $srchval); } $detail = new Template(CLASSIFIEDS_PI_PATH . '/templates'); $detail->set_file('detail', 'detail.thtml'); if ($admin) { $base_url = CLASSIFIEDS_ADMIN_URL . '/index.php'; $del_link = $base_url . '?delete=ad&ad_id=' . $ad_id; $edit_link = $base_url . '?edit=ad&ad_id=' . $ad_id; } else { $base_url = CLASSIFIEDS_URL . '/index.php'; $del_link = $base_url . '?mode=Delete&id=' . $ad_id; $edit_link = $base_url . '?mode=editad&id=' . $ad_id; } // Set up the "add days" form if this user is the owner // or an admin if ($my_access == 3) { // How many days has the ad run? $max_add_days = CLASSIFIEDS_calcMaxAddDays(($ad['exp_date'] - $ad['add_date']) / 86400); if ($max_add_days > 0) { $detail->set_var('max_add_days', $max_add_days); } } if ($ad['exp_date'] < $time) { $detail->set_var('is_expired', 'true'); } USES_classifieds_class_category(); $detail->set_var(array('base_url' => $base_url, 'edit_link' => $edit_link, 'del_link' => $del_link, 'curr_loc' => adCategory::BreadCrumbs($cat, true), 'subject' => $ad['subject'], 'add_date' => date($_CONF['shortdate'], $ad['add_date']), 'exp_date' => date($_CONF['shortdate'], $ad['exp_date']), 'views_no' => $ad['views'], 'descript' => $ad['descript'], 'ad_type' => CLASSIFIEDS_getAdTypeString($ad['ad_type']), 'uinfo_address' => $uinfo['address'], 'uinfo_city' => $uinfo['city'], 'uinfo_state' => $uinfo['state'], 'uinfo_postcode' => $uinfo['postcode'], 'uinfo_tel' => $uinfo['tel'], 'uinfo_fax' => $uinfo['fax'], 'price' => $ad['price'], 'ad_id' => $ad_id, 'ad_url' => $ad['url'], 'username' => $_CONF_ADVT['disp_fullname'] == 1 ? COM_getDisplayName($ad['uid']) : DB_getItem($_TABLES['users'], 'username', "uid={$ad['uid']}"), 'fgcolor' => $ad['fgcolor'], 'bgcolor' => $ad['bgcolor'], 'cat_id' => $ad['cat_id'])); // Display a link to email the poster, or other message as needed $emailfromuser = DB_getItem($_TABLES['userprefs'], 'emailfromuser', "uid={$ad['uid']}"); if ($_CONF['emailuserloginrequired'] == 1 && COM_isAnonUser() || $emailfromuser < 1) { $detail->set_var('ad_uid', ''); } else { $detail->set_var('ad_uid', $ad['uid']); } if ($my_access == 3) { $detail->set_var('have_userlinks', 'true'); if ($admin || $_CONF_ADVT['usercanedit'] == 1) { $detail->set_var('have_editlink', 'true'); } else { $detail->set_var('have_editlink', ''); } } else { $detail->set_var('have_userlinks', ''); } // Retrieve the photos and put into the template $sql = "SELECT photo_id, filename\n FROM {$_TABLES['ad_photo']} \n WHERE ad_id='{$ad_id}'"; $photo = DB_query($sql); $photo_detail = ''; $detail->set_var('have_photo', ''); // assume no photo available if ($photo && DB_numRows($photo) >= 1) { while ($prow = DB_fetchArray($photo)) { $img_small = LGLIB_ImageUrl(CLASSIFIEDS_IMGPATH . '/' . $prow['filename'], $_CONF_ADVT['detail_img_width']); $img_disp = CLASSIFIEDS_dispUrl($prow['filename']); if (!empty($img_small)) { $detail->set_block('detail', 'PhotoBlock', 'PBlock'); $detail->set_var(array('tn_width' => $_CONF_ADVT['detail_img_width'], 'small_url' => $img_small, 'disp_url' => $img_disp)); $detail->parse('PBlock', 'PhotoBlock', true); $detail->set_var('have_photo', 'true'); } } } if (DB_count($_TABLES['ad_ads'], 'owner_id', (int) $ad['owner_id']) > 1) { $detail->set_var('byposter_url', CLASSIFIEDS_URL . '/index.php?' . "page=byposter&uid={$ad['owner_id']}"); } // Show previous and next ads if ($preAd_id != '') { $detail->set_var('previous', '<a href="' . CLASSIFIEDS_makeURL('detail', $preAd_id) . "\"><<</a>"); } if ($nextAd_id != '') { $detail->set_var('next', '<a href="' . CLASSIFIEDS_makeURL('detail', $nextAd_id) . "\"> >></a>"); } // Show the "hot results" $hot_data = ''; if ($hotresult) { $detail->set_block('detail', 'HotBlock', 'HBlock'); while ($hotrow = DB_fetchArray($hotresult)) { $detail->set_var(array('hot_title' => $hotrow['subject'], 'hot_url' => CLASSIFIEDS_makeURL('detail', $hotrow['ad_id']), 'hot_cat' => displayCat($hotrow['cat_id']))); /*$hot_data .= "<tr><td class=\"hottitle\"><a href=\"" . CLASSIFIEDS_makeURL('detail', $hotrow['ad_id']) . "\">{$hotrow['subject']}</a></small></td>\n"; $hot_data .= "<td class=\"hotcat\">( " . displayCat($hotrow['cat_id']) . " )</td></tr>\n";*/ } $detail->parse('HBlock', 'HotBlock', true); } $detail->set_var('whats_hot_row', $hot_data); // Show the user comments if (plugin_commentsupport_classifieds() && $ad['comments_enabled'] < 2) { $detail->set_var('usercomments', CMT_userComments($ad_id, $ad['subject'], 'classifieds', '', '', 0, 1, false, false, $ad['comments_enabled'])); //$detail->set_var('usercomments', CMT_userComments($ad_id, $subject, // 'classifieds')); } $detail->parse('output', 'detail'); $display = $detail->finish($detail->get_var('output')); return $display; }
/** * Display the ads under the given category ID. Also puts in the * subscription link and breadcrumbs. * @param integer $cat Category number to list * @return string HTML for category list */ function adListCat($cat = '') { global $_TABLES, $LANG_ADVT, $_CONF, $_USER, $_CONF_ADVT, $_GROUPS; global $CatListcolors; if ($cat == '') { return; } if (CLASSIFIEDS_checkCatAccess($cat) < 2) { return CLASSIFIEDS_errorMsg($LANG_ADVT['cat_unavailable'], 'alert'); } $T = new Template(CLASSIFIEDS_PI_PATH . '/templates'); $T->set_file('header', CLASSIFIEDS_getTemplate('adlisthdrCat')); $T->set_var('pi_url', $_CONF['site_url'] . '/' . $_CONF_ADVT['pi_name']); $sql = "SELECT image, owner_id, group_id, papa_id\n perm_owner, perm_group, perm_members, perm_anon\n FROM {$_TABLES['ad_category']}\n WHERE cat_id={$cat}"; $r = DB_query($sql); if (!$r || DB_numRows($r) < 1) { return; } $row = DB_fetchArray($r); $img_name = $row['image']; if ($img_name != '') { $T->set_var('catimg_url', CLASSIFIEDS_thumbUrl($img_name)); } // Set the breadcrumb navigation //$T->set_var('breadcrumbs', CLASSIFIEDS_BreadCrumbs($cat), true); USES_classifieds_class_category(); $T->set_var('breadcrumbs', adCategory::BreadCrumbs($cat), true); // if non-anonymous, allow the user to subscribe to this category if (!COM_isAnonUser()) { $result = DB_getItem($_TABLES['ad_notice'], 'count(*)', "uid = {$_USER['uid']} AND cat_id = {$cat}"); // Determine whether the user is subscribed to notifications for // this category and display a message and or link accordingly $subscribed = $result > 0 ? 1 : 0; if ($subscribed) { $T->set_var('subscribe_msg', '<a href="' . CLASSIFIEDS_makeURL('del_notice', $cat) . '">' . COM_createImage(CLASSIFIEDS_URL . '/images/unsubscribe.png', $LANG_ADVT['remove'], array('title' => $LANG_ADVT['you_are_subscribed'], 'class' => 'gl_mootip'))); } else { $T->set_var('subscribe_msg', '<a href="' . CLASSIFIEDS_makeURL('add_notice', $cat) . '">' . COM_createImage(CLASSIFIEDS_URL . '/images/subscribe.png', $LANG_ADVT['subscribe'], array('title' => $LANG_ADVT['subscribe'], 'class' => 'gl_mootip'))); } // Display a link to submit an ad to the current category $submit_url = ''; if (SEC_hasRights($_CONF_ADVT['pi_name'] . '.admin')) { $submit_url = $_CONF['site_admin_url'] . '/plugins/' . $_CONF_ADVT['pi_name'] . '/index.php?mode=edit&cat=' . $cat; } elseif (CLASSIFIEDS_checkCatAccess($cat, false, $row) == 3) { $submit_url = $_CONF['site_url'] . '/submit.php?type=' . $_CONF_ADVT['pi_name'] . '&cat=' . $cat; } $T->set_var('submit_url', $submit_url); } else { // Not-logged-in users can't subscribe or submit. $T->set_var('subscribe_msg', ''); $T->set_var('submit_msg', ''); } // This is a comma-separated string of category IDs for a SQL "IN" clause. // Start with the current category $cat_for_adlist = $cat; // Get the sub-categories which have this category as their parent USES_classifieds_class_category(); $subcats = adCategory::SubCats($cat); $listvals = ''; $max = count($CatListcolors); $i = 0; foreach ($subcats as $row) { // for each sub-category, add it to the list for getting ads $cat_for_adlist .= ",{$row['cat_id']}"; // only show the category selection for immediate children. if ($row['papa_id'] != $cat) { continue; } $T->set_block('header', 'SubCat', 'sCat'); if ($row['fgcolor'] == '' || $row['bgcolor'] == '') { if ($i >= $max) { $i = 0; } $T->set_var('bgcolor', $CatListcolors[$i][0]); $T->set_var('fgcolor', $CatListcolors[$i][1]); $i++; } else { $T->set_var('bgcolor', $row['bgcolor']); $T->set_var('fgcolor', $row['fgcolor']); } $T->set_var('subcat_url', CLASSIFIEDS_makeURL('list', $row['cat_id'])); $T->set_var('subcat_name', $row['cat_name']); $T->set_var('subcat_count', adCategory::TotalAds($row['cat_id'])); $T->parse('sCat', 'SubCat', true); } // Get the count of ads under this category $time = time(); $sql = "SELECT cat_id FROM {$_TABLES['ad_ads']}\n WHERE cat_id IN ({$cat_for_adlist})\n AND exp_date > {$time} " . COM_getPermSQL('AND', 0, 2); //echo $sql; $result = DB_query($sql); if (!$result) { return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert'); } $totalAds = DB_numRows($result); $where_clause = " ad.cat_id IN ({$cat_for_adlist})\n AND ad.exp_date > {$time} "; $T->parse('output', 'header'); $retval = $T->finish($T->get_var('output')); $retval .= adExpList('', $cat, $where_clause); return $retval; }
/** * Provide a form to edit a new or existing ad. * * @param string $mode Indication of where this is called from * @param array $A Array of ad data. * @return string HTML for submission form */ function CLASSIFIEDS_submitForm($mode = 'submit', $A) { global $_TABLES, $LANG_ADVT, $_CONF, $_CONF_ADVT, $_USER, $LANG_ACCESS, $_GROUPS, $LANG12, $LANG24, $LANG_ADMIN, $LANG_postmodes; USES_classifieds_class_adtype(); // only valid users allowed if (!CLASSIFIEDS_canSubmit()) { return CLASSIFIEDS_errorMsg($LANG_ADVT['login_required'], 'alert', $LANG_ADVT['access_denied']); } $time = time(); // used to compare now with expiration date $T = new Template(CLASSIFIEDS_PI_PATH . '/templates'); $T->set_file('adedit', "submit.thtml"); // Set up the wysiwyg editor, if available switch (PLG_getEditorType()) { case 'ckeditor': $T->set_var('show_htmleditor', true); PLG_requestEditor('classifieds', 'classifieds_entry', 'ckeditor_classifieds.thtml'); PLG_templateSetVars('classifieds_entry', $T); break; case 'tinymce': $T->set_var('show_htmleditor', true); PLG_requestEditor('classifieds', 'classifieds_entry', 'tinymce_classifieds.thtml'); PLG_templateSetVars('classifieds_entry', $T); break; default: // don't support others right now $T->set_var('show_htmleditor', false); break; } /*if (isset($_CONF['advanced_editor']) && $_CONF['advanced_editor'] == 1) { $editor_type = '_advanced'; $postmode_adv = 'selected="selected"'; $postmode_html = ''; } else { $editor_type = ''; $postmode_adv = ''; $postmode_html = 'selected="selected"'; } $post_options = ''; $T->set_file('adedit', "submit{$editor_type}.thtml"); if ($editor_type == '_advanced') { $T->set_var('show_adveditor',''); $T->set_var('show_htmleditor','none'); } else { $T->set_var('show_adveditor','none'); $T->set_var('show_htmleditor',''); } $T->set_var('glfusionStyleBasePath', $_CONF['site_url']. '/fckeditor'); $post_options .= "<option value=\"html\" $postmode_html>{$LANG_postmodes['html']}</option>"; $post_options .= "<option value=\"adveditor\" $postmode_adv>{$LANG24[86]}</option>"; $T->set_var('post_options',$post_options); $T->set_var('lang_postmode', $LANG24[4]); $T->set_var('change_editormode', 'onchange="change_editmode(this);"'); // Set the cookie for the advanced editor $T->set_var('gltoken_name', CSRF_TOKEN); $T->set_var('gltoken', SEC_createToken()); @setcookie ($_CONF['cookie_name'].'fckeditor', SEC_createTokenGeneral('advancededitor'), time() + 1200, $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']); */ // Get the category info from the form variable, if any. If not, // get the first category so we can get the keywords. // If no categories found, return an error. if (isset($A['catid'])) { $cat_id = intval($A['catid']); } elseif (isset($_REQUEST['cat'])) { $cat_id = intval($_REQUEST['cat']); } else { $cat_id = 0; } // Check permission to the desired category. If not valid, just // reset to zero if ($cat_id > 0 && CLASSIFIEDS_checkCatAccess($cat_id) < 3) { $cat_id = 0; } $catsql = "SELECT cat_id, perm_anon, keywords\n FROM {$_TABLES['ad_category']}\n WHERE 1=1 "; if ($cat_id > 0) { $catsql .= " AND cat_id={$cat_id} "; } $catsql .= COM_getPermSQL('AND', 0, 3) . " ORDER BY cat_name ASC\n LIMIT 1"; //echo $catsql;die; $r = DB_query($catsql); if (!$r || DB_numRows($r) == 0) { // No categories found, need to get some entered return CLASSIFIEDS_errorMsg($LANG_ADVT['no_categories'], 'info'); } $catrow = DB_fetchArray($r); // Set the category to the first found, if none specified if ($cat_id == 0) { $cat_id = intval($catrow['cat_id']); } // Get the keywords for the category IF there weren't any // already submitted if (empty($A['keywords'])) { $A['keywords'] = trim($catrow['keywords']); } $T->set_var('site_url', $_CONF['site_url']); // Get the max image size in MB and set the message $img_max = $_CONF['max_image_size'] / 1024 / 1024; $T->set_var('txt_photo', "{$LANG_ADVT['photo']}<br />" . sprintf($LANG_ADVT['image_max'], $img_max)); $base_url = "{$_CONF['site_url']}/{$_CONF_ADVT['pi_name']}/index.php"; $delete_img_url = $base_url . "?mode=delete_img"; if (!empty($A['ad_id'])) { $delete_img_url .= '&id=' . $A['ad_id']; $T->set_var('delete_btn', '<form action="' . $base_url . '?mode=' . $LANG_ADMIN['delete'] . '&id=' . $A['ad_id'] . '" method="post"> <input type="submit" name="mode" value="' . $LANG_ADMIN['delete'] . '"/></form>'); } // Set some of the form variables if they're already set. $T->set_var('row_price', $A['price']); $T->set_var('row_subject', $A['subject']); $T->set_var('row_descript', $A['descript']); $T->set_var('row_url', $A['url']); $T->set_var('ad_visibility', $LANG_ADVT['ad_visibility']); $T->set_var('max_file_size', $_CONF['max_image_size']); // Disable the "allow anon access" if the category disables it, // and override the checkbox if (intval($catrow['perm_anon']) > 0) { $T->set_var('vis_disabled', ''); if ($A['perm_anon'] == 2) { $T->set_var('perm_anon_chk', 'checked'); } else { $T->set_var('perm_anon_chk', ''); } } else { $T->set_var('vis_disabled', 'disabled'); $T->set_var('perm_anon_chk', ''); } $T->set_var('action_url', $_CONF['site_url'] . '/submit.php'); //$T->set_var('mode', $mode); $T->set_var('type', $_CONF_ADVT['pi_name']); $T->set_var('cancel_url', CLASSIFIEDS_URL); // set expiration & duration info for a new ad if ($_CONF_ADVT['purchase_enabled']) { USES_classifieds_class_userinfo(); $User = new adUserInfo(); $T->set_var('days', min($_CONF_ADVT['default_duration'], $User->getMaxDays())); } else { $T->set_var('days', $_CONF_ADVT['default_duration']); } $T->set_var('keywords', $A['keywords']); $T->set_var('ad_type_selection', AdType::makeSelection($A['ad_type'])); // default to a "for sale" ad /*if (empty($A['ad_type']) || $A['ad_type'] == 1) { $T->set_var('chk_sale', 'checked'); $T->set_var('chk_wanted', ''); } else { $T->set_var('chk_sale', ''); $T->set_var('chk_wanted', 'checked'); }*/ // Set up the category dropdown $T->set_var('sel_list_catid', CLASSIFIEDS_buildCatSelection($cat_id)); // add upload fields for images $T->set_block('adedit', 'UploadFld', 'UFLD'); for ($i = 0; $i < $_CONF_ADVT['imagecount']; $i++) { $T->parse('UFLD', 'UploadFld', true); } // Set the new_ad flag to trigger the use of "mode" in the form. $T->set_var('new_ad', 'true'); $T->parse('output', 'adedit'); return $T->finish($T->get_var('output')); }