/** * Provide a form to edit a new or existing ad. * @param array $A Array of ad data for edit form * @param string $mode Edit mode * @param boolean $admin True for administrator edit, false for normal * @return string HTML for ad edit form */ function adEdit($A, $mode = 'edit', $admin = false) { global $_TABLES, $LANG_ADVT, $_CONF, $_CONF_ADVT, $LANG_ADMIN, $_USER, $LANG_ACCESS, $_GROUPS, $LANG12, $LANG24, $MESSAGE, $LANG_postmodes; USES_classifieds_class_adtype(); // Determine if this user is an admin. Deprecates the $admin parameter. $admin = SEC_hasRights($_CONF_ADVT['pi_name'] . '.admin') ? 1 : 0; // only valid users allowed if (COM_isAnonUser() || $_CONF_ADVT['usercanedit'] == 0 && !$admin) { return CLASSIFIEDS_errorMsg($LANG_ADVT['no_permission'], 'alert', $LANG_ADVT['access_denied']); } // We know that we need to have categories, so make sure some exist // before even trying to display the form. The category dropdown is // created later since it needs the existing cat_id, if any. if (DB_count($_TABLES['ad_category']) < 1) { return CLASSIFIEDS_errorMsg($LANG_ADVT['no_categories'], 'info'); } $time = time(); // used to compare now with expiration date if ($admin) { $T = new Template(CLASSIFIEDS_PI_PATH . '/templates/admin'); $T->set_file('adedit', "adminedit.thtml"); $action_url = CLASSIFIEDS_ADMIN_URL . '/index.php'; } else { $T = new Template(CLASSIFIEDS_PI_PATH . '/templates'); $T->set_file('adedit', "submitform.thtml"); $action_url = CLASSIFIEDS_URL . '/index.php'; } // 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; } switch ($mode) { case 'editsubmission': case 'moderate': $savemode = 'savesubmission'; $delete_img = 'delsubimg'; $delete_ad = 'deletesubmission'; $type = 'moderate'; $saveoption = $LANG_ADMIN['moderate']; $cancel_url = $_CONF['site_admin_url'] . '/moderation.php'; break; case 'edit': $savemode = 'savesubmission'; $delete_img = 'delsubimg'; $delete_ad = 'deletesubmission'; $saveoption = $LANG_ADMIN['save']; $type = 'submission'; $cancel_url = $action_url; break; case 'update_ad': default: $savemode = 'update_ad'; $delete_img = 'delete_img'; $delete_ad = 'delete_ad'; $saveoption = $LANG_ADMIN['save']; $type = ''; $cancel_url = $action_url; break; } // Admins (only) use this form for submissions as well as edits, // so we need to expect an empty array. if (empty($A['ad_id'])) { if (!$admin) { return CLASSIFIEDS_errorMsg($LANG_ADVT['no_permission'], 'alert', $LANG_ADVT['access_denied']); } $A['ad_id'] = COM_makeSid(); $A['subject'] = ''; $A['descript'] = ''; $A['price'] = ''; $A['url'] = ''; $A['exp_date'] = ''; $A['add_date'] = time(); $A['ad_type'] = 0; $A['perm_owner'] = $_CONF_ADVT['default_permissions'][0]; $A['perm_group'] = $_CONF_ADVT['default_permissions'][1]; $A['perm_members'] = $_CONF_ADVT['default_permissions'][2]; $A['perm_anon'] = $_CONF_ADVT['default_permissions'][3]; $A['uid'] = $_USER['uid']; if (isset($_REQUEST['cat'])) { $A['cat_id'] = intval($_REQUEST['cat']); } else { $A['cat_id'] = 0; } $catsql = "SELECT cat_id,perm_anon,keywords\n FROM {$_TABLES['ad_category']} "; if ($A['cat_id'] > 0) { $catsql .= "WHERE cat_id = {$A['cat_id']} "; } else { $catsql .= "ORDER BY cat_name ASC "; } $catsql .= "LIMIT 1"; $r = DB_query($catsql, 1); if ($r && DB_numRows($r) > 0) { $row = DB_fetchArray($r, false); $A['cat_id'] = $row['cat_id']; $A['keywords'] = trim($row['keywords']); } else { $A['cat_id'] = 0; $A['keywords'] = ''; } $A['owner_id'] = $_USER['uid']; // Set ad owner to current user for new ads $A['group_id'] = isset($_GROUPS['classifieds Admin']) ? $_GROUPS['classifieds Admin'] : SEC_getFeatureGroup('classifieds.edit'); $A['exp_sent'] = 0; // set expiration & duration info for a new ad $T->set_var('expiration_date', $LANG_ADVT['runfor']); // "run for: X days" $comments_enabled = $_CONF_ADVT['commentsupport'] == 1 ? 0 : 1; $T->set_var("sel_{$comments_enabled}", 'selected'); 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']); } $photocount = 0; // No photos yet with a new ad } else { // This is an existing ad with values already in $A $T->set_var('expiration_date', $LANG_ADVT['expiration']); $T->set_var('days', '0'); // Disable the perm_anon checkbox if it's disabled by the category. if (!$admin && DB_getItem($_TABLES['ad_category'], 'perm_anon', "cat_id='{$A['cat_id']}'") == '0') { $T->set_var('vis_disabled', 'disabled'); } // get the photo information $sql = "SELECT photo_id, filename \n FROM {$_TABLES['ad_photo']} \n WHERE ad_id='{$A['ad_id']}'"; $photo = DB_query($sql, 1); // save the count of photos for later use if ($photo) { $photocount = DB_numRows($photo); } else { $photocount = 0; } $comments_enabled = (int) $A['comments_enabled']; $T->set_var("sel_{$comments_enabled}", 'selected'); } // Get the max image size in MB and set the message $img_max = $_CONF['max_image_size'] / 1048576; // Show in MB // Sanitize entries from the database $A['subject'] = htmlspecialchars($A['subject']); $A['descript'] = htmlspecialchars($A['descript']); $A['keywords'] = htmlspecialchars($A['keywords']); $A['price'] = htmlspecialchars($A['price']); $A['url'] = htmlspecialchars($A['url']); $A['ad_type'] = (int) $A['ad_type']; // set expiration & duration based on existing info if ($A['exp_date'] == '') { $T->set_var('row_exp_date', ''); } else { if ($A['exp_date'] < $time) { $T->set_var('already_expired', $LANG_ADVT['already_expired']); } else { $T->set_var('row_exp_date', date("d M Y", $A['exp_date'])); } } $T->set_var(array('post_options' => $post_options, 'change_editormode' => 'onchange="change_editmode(this);"', 'glfusionStyleBasePath' => $_CONF['site_url'] . '/fckeditor', 'gltoken_name' => CSRF_TOKEN, 'gltoken' => SEC_createToken(), 'has_delbtn' => 'true', 'txt_photo' => "{$LANG_ADVT['photo']}<br />" . sprintf($LANG_ADVT['image_max'], $img_max), 'type' => $type, 'action_url' => $action_url, 'max_file_size' => $_CONF['max_image_size'], 'row_cat_id' => $A['cat_id'], 'row_ad_id' => $A['ad_id'], 'row_subject' => $A['subject'], 'row_descript' => $A['descript'], 'row_price' => $A['price'], 'row_url' => $A['url'], 'keywords' => $A['keywords'], 'exp_date' => $A['exp_date'], 'add_date' => $A['add_date'], 'ad_type_selection' => AdType::makeSelection($A['ad_type']), 'sel_list_catid' => CLASSIFIEDS_buildCatSelection($A['cat_id']), 'saveoption' => $saveoption, 'cancel_url' => $cancel_url)); // set expiration & duration based on existing info if ($A['exp_date'] == '') { $T->set_var('row_exp_date', ''); } else { if ($A['exp_date'] < $time) { $T->set_var('already_expired', $LANG_ADVT['already_expired']); } else { $T->set_var('row_exp_date', date("d M Y", $A['exp_date'])); } } // Set up permission editor on the admin template if needed. // Otherwise, set hidden values with existing permissions if ($admin) { // Set up owner selection $T->set_var(array('ownerselect' => CLASSIFIEDS_userDropdown($A['owner_id']), 'permissions_editor' => SEC_getPermissionsHTML($A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']), 'group_dropdown' => SEC_getGroupDropdown($A['group_id'], 3))); } else { $ownername = COM_getDisplayName($A['owner_id']); $T->set_var(array('owner_id' => $A['owner_id'], 'ownername' => $ownername, 'perm_owner' => $A['perm_owner'], 'perm_group' => $A['perm_group'], 'perm_members' => $A['perm_members'], 'perm_anon' => $A['perm_anon'], 'group_id' => $A['group_id'])); if ($A['perm_anon'] == 2) { $T->set_var('perm_anon_chk', 'checked'); } } // Set up the photo fields. Use $photocount defined above. // If there are photos, read the $photo result. Otherwise, // or if this is a new ad, just clear the photo area $T->set_block('adedit', 'PhotoRow', 'PRow'); $i = 0; if ($photocount > 0) { while ($prow = DB_fetchArray($photo, false)) { $i++; $T->set_var(array('img_url' => LGLIB_ImageUrl(CLASSIFIEDS_IMGPATH . '/' . $prow['filename'], $_CONF_ADVT['img_max_width'], $_CONF_ADVT['img_max_height']), 'thumb_url' => LGLIB_ImageUrl(CLASSIFIEDS_IMGPATH . '/' . $prow['filename'], $_CONF_ADVT['thumb_max_size'], $_CONF_ADVT['thumb_max_size']), 'seq_no' => $i, 'ad_id' => $A['ad_id'], 'del_img_url' => $action_url . "?mode={$delete_img}&mid={$prow['photo_id']}" . "&id={$A['ad_id']}")); $T->parse('PRow', 'PhotoRow', true); } } else { $T->parse('PRow', ''); } // add upload fields for unused images $T->set_block('adedit', 'UploadFld', 'UFLD'); for ($j = $i; $j < $_CONF_ADVT['imagecount']; $j++) { $T->parse('UFLD', 'UploadFld', true); } $T->parse('output', 'adedit'); return $T->finish($T->get_var('output')); }
/** * 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; }
/** * Seed the image cache with the product image thumbnails. * * @uses LGLIB_ImageUrl() * @return string Blank, error messages are now in parent::_errors */ private function MakeThumbs() { global $_PP_CONF; $thumbsize = (int) $_PP_CONF['max_thumb_size']; if ($thumbsize < 50) { $thumbsize = 100; } if (!is_array($this->_fileNames)) { return ''; } foreach ($this->_fileNames as $filename) { $src = "{$this->pathImage}/{$filename}"; $url = LGLIB_ImageUrl($src, $thumbsize, $thumbsize, true); if (!empty($url)) { $this->goodfiles[] = $filename; } else { $this->_addError("MakeThumbs() : {$filename} - {$msg}"); } } return ''; }