Example #1
0
/**
 *  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) . "\">&lt;&lt;</a>");
    }
    if ($nextAd_id != '') {
        $detail->set_var('next', '<a href="' . CLASSIFIEDS_makeURL('detail', $nextAd_id) . "\">  &gt;&gt;</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;
}
Example #2
0
/**
 *  Create a category listing page showing the categories in block styling.
 *  @return string      HTML for category listing page
 */
function CLASSIFIEDS_catList_blocks()
{
    global $_CONF, $_TABLES, $LANG_ADVT, $_CONF_ADVT;
    global $CatListcolors;
    $T = new Template(CLASSIFIEDS_PI_PATH . '/templates');
    $T->set_file('page', 'catlist_blocks.thtml');
    $T->set_var('site_url', $_CONF['site_url']);
    $T->set_var('site_admin_url', $_CONF['site_admin_url']);
    // Get all the root categories
    $sql = "SELECT * FROM {$_TABLES['ad_category']} \n            WHERE papa_id='' " . COM_getPermSQL('AND', 0, 2) . " ORDER BY cat_name ASC";
    //echo $sql;die;
    $cats = DB_query($sql);
    if (!$cats) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
    }
    // If no root categories exist, display just return a message
    if (DB_numRows($cats) == 0) {
        $T->set_var('no_cat_found', "<p align=\"center\" class=\"headmsg\">\n            {$LANG_ADVT['no_cat_found']}</p>\n");
        $T->parse('output', 'page');
        return $T->finish($T->get_var('output'));
    }
    $max = count($CatListcolors);
    $i = 0;
    while ($catsrow = DB_fetchArray($cats)) {
        if ($catsrow['fgcolor'] == '' || $catsrow['bgcolor'] == '') {
            if ($i >= $max) {
                $i = 0;
            }
            $bgcolor = $CatListcolors[$i][0];
            $fgcolor = $CatListcolors[$i][1];
            $hdcolor = $CatListcolors[$i][2];
            $i++;
        } else {
            $fgcolor = $catsrow['fgcolor'];
            $bgcolor = $catsrow['bgcolor'];
        }
        // For each category, find the total ad count (including subcats)
        // and display the subcats below it.
        $T->set_block('page', 'CatDiv', 'Div');
        $T->set_var('bgcolor', $bgcolor);
        $T->set_var('fgcolor', $fgcolor);
        //$T->set_var('hdcolor', $hdcolor);
        $T->set_var('cat_url', CLASSIFIEDS_makeUrl('home', $catsrow['cat_id']));
        $T->set_var('cat_name', $catsrow['cat_name']);
        $T->set_var('cat_desc', $catsrow['description']);
        $T->set_var('cat_ad_count', findTotalAds($catsrow['cat_id']));
        if ($catsrow['image']) {
            $T->set_var('cat_image', CLASSIFIEDS_thumbUrl('cat/' . $catsrow['image']));
        } else {
            $T->set_var('cat_image', '');
        }
        $T->parse('Div', 'CatDiv', true);
    }
    $T->parse('output', 'page');
    return $T->finish($T->get_var('output'));
}
Example #3
0
 /**
  *  Creates the edit form
  *  @param integer $id Optional ID, current record used if zero
  *  @return string HTML for edit form
  */
 function showForm($type = 'advt')
 {
     global $_TABLES, $_CONF, $_CONF_ADVT, $LANG_ADVT, $_USER;
     $id = (int) $id;
     if ($id > 0) {
         $this->Read($id);
     }
     $base_url = $_CONF['site_url'] . '/' . $_CONF_ADVT['pi_name'];
     $T = new Template(CLASSIFIEDS_PI_PATH . '/templates');
     if ($type == 'advt') {
         // Called within the plugin
         $T->set_file('accountinfo', 'accountinfo.thtml');
     } else {
         // Called via glFusion account settings
         $T->set_file('accountinfo', 'account_settings.thtml');
     }
     $T->set_var(array('uinfo_address' => $this->getAddress(), 'uinfo_city' => $this->getCity(), 'uinfo_state' => $this->getState(), 'uinfo_tel' => $this->getTel(), 'uinfo_fax' => $this->getFax(), 'uinfo_postcode' => $this->getPostCode(), 'exp_notify_checked' => $this->getNotifyExp() == 1 ? 'checked="checked"' : '', 'cmt_notify_checked' => $this->getNotifyCmt() == 1 ? 'checked="checked"' : ''));
     $sql = "\n            SELECT \n                cat_id, notice_id\n            FROM \n                {$_TABLES['ad_notice']} \n            WHERE \n                uid='{$_USER['uid']}'";
     $notice = DB_query($sql);
     if (!$notice) {
         return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
     }
     if (0 == DB_numRows($notice)) {
         $T->set_var('no_autonotify_list', 'true');
     } else {
         while ($row = DB_fetchArray($notice)) {
             $T->set_block('accountinfo', 'AutoNotifyListBlk', 'NotifyList');
             $T->set_var(array('cat_id' => $row['cat_id'], 'cat_name' => CLASSIFIEDS_BreadCrumbs($row['cat_id'], false), 'pi_url' => $base_url));
             $T->parse('NotifyList', 'AutoNotifyListBlk', true);
         }
     }
     $T->parse('output', 'accountinfo');
     return $T->finish($T->get_var('output'));
 }
Example #4
0
     break;
 case 'manage':
     // Manage ads.  Restricted to the user's own ads
     if ($isAnon) {
         $content .= CLASSIFIEDS_errorMsg($LANG_ADVT['login_required'], 'note');
     } else {
         $content .= adList(false);
     }
     $T->set_var('header', $LANG_ADVT['ads_mgnt']);
     $menu_opt = $LANG_ADVT['mnu_myads'];
     break;
 case 'account':
     // Update the user's account info
     // only valid users allowed
     if ($isAnon) {
         $content .= CLASSIFIEDS_errorMsg($LANG_ADVT['login_required'], 'alert', $LANG_ADVT['access_denied']);
         break;
     }
     USES_classifieds_class_userinfo();
     $U = new adUserInfo();
     $content .= $U->showForm('advt');
     $T->set_var('header', $LANG_ADVT['my_account']);
     $menu_opt = $LANG_ADVT['mnu_account'];
     break;
 case 'detail':
     // Display an ad's detail
     USES_classifieds_detail();
     $content .= adDetail($id);
     $T->set_var('header', $LANG_ADVT['detail']);
     $menu_opt = $LANG_ADVT['mnu_home'];
     if ($id != '') {
Example #5
0
 /**
  *   Calls itself recursively to find all sub-categories.
  *   Stores an array of category information in $subcats.
  *
  *   @param  integer $id         Current Category ID
  *   @param  integer $master_id  ID of top-level category being searched
  *   @return string              HTML for breadcrumbs
  */
 public static function SubCats($id, $master_id = 0)
 {
     global $_TABLES, $LANG_ADVT;
     static $subcats = array();
     $id = (int) $id;
     if ($id == 0) {
         return array();
     }
     // must have a valid category ID
     // On the initial call, $master_id is normally blank so set it to
     // the current $id. For recursive calls, $master_id will be provided.
     $master_id = (int) $master_id;
     if ($master_id == 0) {
         $master_id = $id;
     }
     if (isset($subcats[$id])) {
         return $subcats[$id];
     } else {
         $subcats[$id] = array();
     }
     $sql = "SELECT cat_name, cat_id, fgcolor, bgcolor, papa_id\n                FROM {$_TABLES['ad_category']} \n                WHERE papa_id={$id}";
     //echo $sql;die;
     $result = DB_query($sql);
     if (!$result) {
         return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
     }
     while ($row = DB_fetchArray($result, false)) {
         $subcats[$master_id][$row['cat_id']] = $row;
         $subcats[$id][$row['cat_id']]['total_ads'] = adCategory::TotalAds($row['cat_id']);
         $A = adCategory::SubCats($row['cat_id'], $master_id);
         if (!empty($A)) {
             array_merge($subcats[$id], $A);
         }
     }
     return $subcats[$master_id];
 }
Example #6
0
/**
 *  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'));
}
/**
*   Get an array of user info from the plugin's userinfo table
*   @param  string  $userid User ID to retrieve.  Blank for current user
*   @return array user info from our uinfo table
*   @deprecated
*/
function X_CLASSIFIEDS_getUserInfo($userid = 0)
{
    global $_USER, $_TABLES;
    if ($userid == 0) {
        $userid = $_USER['uid'];
    }
    $userid = (int) $userid;
    $result = DB_query("\n        SELECT \n            * \n        FROM \n            {$_TABLES['ad_uinfo']} \n        WHERE uid='{$userid}'\n    ");
    if (!$result) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
    }
    $userinfo = DB_fetchArray($result);
    return $userinfo;
}
Example #8
0
 /**
  *   Creates the edit form
  *
  *   @param  string  $type   Type of form, plugin or glFusion acct settings
  *   @return string HTML for edit form
  */
 function showForm($type = 'advt')
 {
     global $_TABLES, $_CONF, $_CONF_ADVT, $LANG_ADVT, $_USER, $_SYSTEM;
     $base_url = $_CONF['site_url'] . '/' . $_CONF_ADVT['pi_name'];
     $T = new Template(CLASSIFIEDS_PI_PATH . '/templates');
     $tpltype = $_SYSTEM['framework'] == 'uikit' ? '.uikit' : '';
     $T->set_file('accountinfo', "account_settings{$tpltype}.thtml");
     if ($type == 'advt') {
         // Called within the plugin
         //    $T->set_file('accountinfo', "accountinfo$tpltype.thtml");
     } else {
         // Called via glFusion account settings
         $T->set_var('profileedit', 'true');
         //    $T->set_file('accountinfo', "account_settings$tpltype.thtml");
     }
     $T->set_var(array('uid' => $this->uid, 'uinfo_address' => $this->address, 'uinfo_city' => $this->city, 'uinfo_state' => $this->state, 'uinfo_tel' => $this->tel, 'uinfo_fax' => $this->fax, 'uinfo_postcode' => $this->postcode, 'exp_notify_checked' => $this->notify_exp == 1 ? 'checked="checked"' : '', 'cmt_notify_checked' => $this->notify_comment == 1 ? 'checked="checked"' : ''));
     $sql = "SELECT cat_id, notice_id FROM {$_TABLES['ad_notice']} \n                WHERE uid='{$_USER['uid']}'";
     $notice = DB_query($sql);
     if (!$notice) {
         return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
     }
     if (0 == DB_numRows($notice)) {
         $T->set_var('no_autonotify_list', 'true');
     } else {
         while ($row = DB_fetchArray($notice)) {
             $T->set_block('accountinfo', 'AutoNotifyListBlk', 'NotifyList');
             $T->set_var(array('cat_id' => $row['cat_id'], 'cat_name' => CLASSIFIEDS_BreadCrumbs($row['cat_id'], false), 'pi_url' => $base_url));
             $T->parse('NotifyList', 'AutoNotifyListBlk', true);
         }
     }
     $T->parse('output', 'accountinfo');
     return $T->finish($T->get_var('output'));
 }
Example #9
0
/**
 *  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'));
}