Пример #1
0
 /**
  *   Creates the product edit form.
  *
  *   Creates the form for editing a product.  If a product ID is supplied,
  *   then that product is read and becomes the current product.  If not,
  *   then the current product is edited.  If an empty product was created,
  *   then a new product is created here.
  *
  *   @uses   PAYPAL_getDocUrl()
  *   @uses   PAYPAL_errorMessage()
  *   @uses   PAYPAL_recurseCats()
  *   @param  integer $id     Optional ID, current record used if zero
  *   @return string          HTML for edit form
  */
 public function showForm($id = 0)
 {
     global $_TABLES, $_CONF, $_PP_CONF, $LANG_PP, $LANG24, $LANG_postmodes, $_SYSTEM;
     $id = (int) $id;
     if ($id > 0) {
         // If an id is passed in, then read that record
         if (!$this->Read($id)) {
             return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
         }
     }
     $id = $this->id;
     $T = new Template(PAYPAL_PI_PATH . '/templates');
     if ($_SYSTEM['framework'] == 'uikit') {
         $T->set_file('product', 'product_form.uikit.thtml');
     } else {
         $T->set_file('product', 'product_form.thtml');
     }
     // Set up the wysiwyg editor, if available
     switch (PLG_getEditorType()) {
         case 'ckeditor':
             $T->set_var('show_htmleditor', true);
             PLG_requestEditor('paypal', 'paypal_entry', 'ckeditor_paypal.thtml');
             PLG_templateSetVars('paypal_entry', $T);
             break;
         case 'tinymce':
             $T->set_var('show_htmleditor', true);
             PLG_requestEditor('paypal', 'paypal_entry', 'tinymce_paypal.thtml');
             PLG_templateSetVars('paypal_entry', $T);
             break;
         default:
             // don't support others right now
             $T->set_var('show_htmleditor', false);
             break;
     }
     // Add the current product ID to the form if it's an existing product.
     if ($id > 0) {
         $T->set_var('id', '<input type="hidden" name="id" value="' . $this->id . '" />');
         $retval = COM_startBlock($LANG_PP['edit'] . ': ' . $this->name);
     } else {
         $T->set_var('id', '');
         $retval = COM_startBlock($LANG_PP['new_product']);
     }
     $T->set_var(array('post_options' => $post_options, 'name' => htmlspecialchars($this->name, ENT_QUOTES, COM_getEncodingt()), 'category' => $this->cat_id, 'short_description' => htmlspecialchars($this->short_description, ENT_QUOTES, COM_getEncodingt()), 'description' => htmlspecialchars($this->description, ENT_QUOTES, COM_getEncodingt()), 'price' => sprintf('%.2f', $this->price), 'file' => htmlspecialchars($this->file, ENT_QUOTES, COM_getEncodingt()), 'expiration' => $this->expiration, 'pi_admin_url' => PAYPAL_ADMIN_URL, 'file_selection' => $this->FileSelector(), 'keywords' => htmlspecialchars($this->keywords, ENT_QUOTES, COM_getEncodingt()), 'cat_select' => PAYPAL_recurseCats('PAYPAL_callbackCatOptionList', $this->cat_id), 'currency' => $_PP_CONF['currency'], 'pi_url' => PAYPAL_URL, 'doc_url' => PAYPAL_getDocURL('product_form', $_CONF['language']), 'prod_type' => $this->prod_type, 'weight' => $this->weight, 'feat_chk' => $this->featured == 1 ? 'checked="checked"' : '', 'ena_chk' => $this->enabled == 1 ? 'checked="checked"' : '', 'tax_chk' => $this->taxable == 1 ? 'checked="checked"' : '', 'show_random_chk' => $this->show_random == 1 ? 'checked="checked"' : '', 'show_popular_chk' => $this->show_popular == 1 ? 'checked="checked"' : '', 'ship_sel_' . $this->shipping_type => 'selected="selected"', 'shipping_type' => $this->shipping_type, 'track_onhand' => $this->track_onhand, 'shipping_amt' => sprintf('%.2f', $this->shipping_amt), 'sel_comment_' . $this->comments_enabled => 'selected="selected"', 'rating_chk' => $this->rating_enabled == 1 ? 'checked="checked"' : '', 'trk_onhand_chk' => $this->track_onhand == 1 ? 'checked="checked"' : '', 'onhand' => $this->onhand, "oversell_sel{$this->oversell}" => 'selected="selected"', 'custom' => $this->custom, 'sale_price' => sprintf('%.2f', $this->sale_price), 'sale_beg' => $this->_InputDtFormat($this->sale_beg), 'sale_end' => $this->_InputDtFormat($this->sale_end), 'avail_beg' => $this->avail_beg, 'avail_end' => $this->avail_end));
     // Create the button type selections. New products get the default
     // button selected, existing products get the saved button selected
     // or "none" if there is no button.
     $T->set_block('product', 'BtnRow', 'BRow');
     $have_chk = false;
     foreach ($_PP_CONF['buttons'] as $key => $checked) {
         if ($key == $this->btn_type || $this->isNew && $checked) {
             $btn_chk = 'checked="checked"';
             $have_chk = true;
         } else {
             $btn_chk = '';
         }
         $T->set_var(array('btn_type' => $key, 'btn_chk' => $key == $this->btn_type || $this->isNew && $checked ? 'checked="checked"' : '', 'btn_name' => $LANG_PP['buttons'][$key]));
         $T->parse('BRow', 'BtnRow', true);
     }
     // Set the "none" selection if nothing was already selected
     $T->set_var('none_chk', $have_chk ? '' : 'checked="checked"');
     $T->set_block('product', 'ProdTypeRadio', 'ProdType');
     foreach ($LANG_PP['prod_types'] as $value => $text) {
         $T->set_var(array('type_val' => $value, 'type_txt' => $text, 'type_sel' => $this->prod_type == $value ? 'checked="checked"' : ''));
         $T->parse('ProdType', 'ProdTypeRadio', true);
     }
     /*$T->set_block('options', 'OptionRow', 'OptRow');
       for ($i = 0; $i < 7; $i++) {
           $T->set_var(array(
               'var'         => $i,
               'option_num'  => $i + 1,
               'on0_name' => $this->properties['options']['on0']['name'],
               'on0_string' => $this->properties['options']['on0'][$i]['string'],
               'on0_value' => $this->properties['options']['on0'][$i]['value'],
               'on1_name' => $this->properties['options']['on1']['name'],
               'on1_string' => $this->properties['options']['on1'][$i]['string'],
               'on1_value' => $this->properties['options']['on1'][$i]['value'],
           ) );
           $T->parse('OptRow', 'OptionRow', true);
       }*/
     if (!$this->isUsed()) {
         $T->set_var('candelete', 'true');
     }
     // 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('product', 'PhotoRow', 'PRow');
     $i = 0;
     // Get the existing photos.  Will only have photos with an
     // existing product entry.
     $photocount = 0;
     if ($this->id != NULL) {
         $sql = "SELECT img_id, filename \n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='" . $this->id . "'";
         $photo = DB_query($sql);
         // save the count of photos for later use
         if ($photo) {
             $photocount = DB_numRows($photo);
         }
         // While we're checking the ID, set it as a hidden value
         // for updating this record
         $T->set_var('product_id', $this->id);
     } else {
         $T->set_var('product_id', '');
     }
     // If there are any images, retrieve and display the thumbnails.
     if ($photocount > 0) {
         while ($prow = DB_fetchArray($photo)) {
             $i++;
             $T->set_var('img_url', PAYPAL_URL . "/images/products/{$prow['filename']}");
             $T->set_var('thumb_url', PAYPAL_ImageUrl($prow['filename']));
             $T->set_var('seq_no', $i);
             $T->set_var('del_img_url', PAYPAL_ADMIN_URL . '/index.php' . '?delete_img=x' . '&img_id=' . $prow['img_id'] . '&id=' . $this->id);
             $T->parse('PRow', 'PhotoRow', true);
         }
     } else {
         $T->parse('PRow', '');
     }
     // add upload fields for unused images
     $T->set_block('product', 'UploadFld', 'UFLD');
     for ($j = $i; $j < $_PP_CONF['max_images']; $j++) {
         $T->parse('UFLD', 'UploadFld', true);
     }
     $i = 0;
     foreach ($this->qty_discounts as $qty => $amt) {
         $T->set_var(array('disc_qty' . $i => $qty, 'disc_amt' . $i => $amt));
         $i++;
     }
     /*$sql = "SELECT cat_id, cat_name
               FROM {$_TABLES['paypal.categories']}
               WHERE enabled=1 AND parent_id=0";
       $res = DB_query($sql);*/
     /*$str = '';
       while ($A = DB_fetchArray($res, false)) {
           $str .= "<div><b>{$A['cat_name']}</b><br/>
                   <ul>" . 
                   PAYPAL_recurseCats('prodform_catoption', 0, $A['cat_id'],
                     '', '', '',
                     0, 0, array('<ol>', '</ol>')) .
                   "</ul></div>";
       }
       $T->set_var('catselect', $str);*/
     $retval .= $T->parse('output', 'product');
     /*@setcookie($_CONF['cookie_name'].'fckeditor', 
               SEC_createTokenGeneral('advancededitor'),
               time() + 1200, $_CONF['cookie_path'],
               $_CONF['cookiedomain'], $_CONF['cookiesecure']);
       */
     $retval .= COM_endBlock();
     return $retval;
 }
Пример #2
0
function FF_postEditor($postData, $forumData, $action, $viewMode)
{
    global $_CONF, $_TABLES, $_FF_CONF, $FF_userprefs, $_USER, $LANG_GF01, $LANG_GF02, $LANG_GF10, $REMOTE_ADDR;
    $retval = '';
    $editmoderator = false;
    $numAttachments = 0;
    $edit_val = '';
    $sticky_val = '';
    $locked_val = '';
    if (COM_isAnonUser()) {
        $uid = 1;
    } else {
        $uid = $_USER['uid'];
    }
    // initialize defaults
    if ($_FF_CONF['bbcode_disabled']) {
        $disable_bbcode_val = ' checked="checked"';
    } else {
        $disable_bbcode_val = '';
    }
    if ($_FF_CONF['smilies_disabled']) {
        $disable_smilies_val = ' checked="checked"';
    } else {
        $disable_smilies_val = '';
    }
    if ($_FF_CONF['urlparse_disabled']) {
        $disable_urlparse_val = ' checked="checked"';
    } else {
        $disable_urlparse_val = '';
    }
    // check postmode
    if (isset($postData['postmode'])) {
        // this means we are editing or previewing (or both)
        if (isset($postData['postmode_switch'])) {
            // means they selected a switch
            $chkpostmode = _ff_chkpostmode($postData['postmode'], $postData['postmode_switch']);
            if ($chkpostmode != $postData['postmode']) {
                $postData['postmode'] = $chkpostmode;
                $postData['postmode_switch'] = 0;
            }
        }
    } else {
        if ($_FF_CONF['post_htmlmode'] && $_FF_CONF['allow_html']) {
            $postData['postmode'] = 'html';
        } else {
            $postData['postmode'] = 'text';
        }
    }
    // verify postmode is allowed
    if ($postData['postmode'] == 'html' || $postData['postmode'] == 'HTML') {
        if ($_FF_CONF['allow_html'] || SEC_inGroup('Root') || SEC_hasRights('forum.html')) {
            $postData['postmode'] = 'html';
        } else {
            $postData['postmode'] = 'text';
        }
    }
    $postData['postmode_switch'] = 0;
    // action specific setup
    if ($action == 'edittopic' || $viewMode) {
        // need to see what options were checked...
        $status = 0;
        // get our options...
        if (isset($postData['disable_bbcode']) && $postData['disable_bbcode'] == 1) {
            $disable_bbcode_val = ' checked="checked"';
            $status += DISABLE_BBCODE;
        } else {
            $disable_bbcode_val = '';
        }
        if (isset($postData['disable_smilies']) && $postData['disable_smilies'] == 1) {
            $disable_smilies_val = ' checked="checked"';
            $status += DISABLE_SMILIES;
        } else {
            $disable_smilies_val = '';
        }
        if (isset($postData['disable_urlparse']) && $postData['disable_urlparse'] == 1) {
            $disable_urlparse_val = ' checked="checked"';
            $status += DISABLE_URLPARSE;
        } else {
            $disable_urlparse_val = '';
        }
    }
    // create our template
    $peTemplate = new Template($_CONF['path'] . 'plugins/forum/templates/');
    $peTemplate->set_file('posteditor', 'posteditor.thtml');
    if ($postData['postmode'] == 'html') {
        $peTemplate->set_var('html_mode', true);
    } else {
        $peTemplate->unset_var('html_mode');
    }
    if ($viewMode == PREVIEW_VIEW) {
        $peTemplate->set_var('preview_post', FF_previewPost($postData, $action));
    }
    $uniqueid = isset($postData['uniqueid']) ? COM_applyFilter($postData['uniqueid'], true) : mt_rand();
    $peTemplate->set_var('uniqueid', $uniqueid);
    if (SEC_inGroup($postData['use_attachment_grpid']) && $_FF_CONF['maxattachments'] > 0) {
        $peTemplate->set_var('use_attachments', true);
    }
    if ($action == 'newtopic') {
        $peTemplate->set_var('save_button', 'savetopic');
        $postmessage = $LANG_GF02['PostTopic'];
        $peTemplate->set_var('hidden_action', 'newtopic');
    }
    if ($action == 'edittopic') {
        $peTemplate->set_var('save_button', 'saveedit');
        if (isset($postData['forum']) && forum_modPermission($postData['forum'], $_USER['uid'], 'mod_edit')) {
            $editmoderator = true;
            $peTemplate->set_var('hidden_modedit', '1');
        } else {
            $peTemplate->set_var('hidden_modedit', '0');
            $editmoderator = false;
        }
        $postmessage = $LANG_GF02['EditTopic'];
        $peTemplate->set_var('hidden_action', 'edittopic');
        $peTemplate->set_var('hidden_editpost', 'yes');
        if ($editmoderator) {
            $username = $postData['name'];
        } elseif ($postData['uid'] > 1) {
            $username = COM_getDisplayName($postData['uid']);
        }
        $postData['comment'] = str_ireplace('</textarea>', '&lt;/textarea&gt;', $postData['comment']);
        if (isset($postData['pid'])) {
            $peTemplate->set_var('hidden_editpid', $postData['pid']);
        }
        $peTemplate->set_var('hidden_editid', $postData['id']);
        $edit_prompt = $LANG_GF02['msg190'] . '<br/><input type="checkbox" name="silentedit" ';
        if (isset($postData['silentedit']) && $postData['silentedit'] == 1 or !isset($postData['modedit']) and $_FF_CONF['silent_edit_default']) {
            $edit_prompt .= 'checked="checked" ';
            $edit_val = ' checked="checked" ';
        } else {
            $edit_val = '';
        }
        $edit_prompt .= 'value="1"/>';
        $peTemplate->set_var('attachments', '<div id="fileattachlist">' . _ff_showattachments($postData['id'], 'edit') . '</div>');
        $numAttachments = DB_Count($_TABLES['ff_attachments'], 'topic_id', $postData['id']);
        $allowedAttachments = $_FF_CONF['maxattachments'] - $numAttachments;
        $peTemplate->set_var('fcounter', $allowedAttachments);
    } else {
        $numAttachments = (int) DB_Count($_TABLES['ff_attachments'], 'topic_id', $uniqueid);
        $allowedAttachments = $_FF_CONF['maxattachments'] - $numAttachments;
        $peTemplate->set_var('fcounter', $allowedAttachments);
        $peTemplate->set_var('attachments', '');
        if ($uniqueid > 0) {
            $peTemplate->set_var('attachments', '<div id="fileattachlist">' . _ff_showattachments($uniqueid, 'edit') . '</div>');
        }
        $edit_prompt = '&nbsp;';
    }
    if ($action == 'newreply') {
        $peTemplate->set_var('save_button', 'savereply');
        $postmessage = $LANG_GF02['PostReply'];
        $peTemplate->set_var('hidden_action', 'newreply');
        if (!$viewMode) {
            $postData['subject'] = $LANG_GF01['RE'] . $postData['subject'];
        }
        $quoteid = isset($_GET['quoteid']) ? COM_applyFilter($_GET['quoteid'], true) : 0;
        $postData['mood'] = '';
        if ($quoteid > 0 && !$viewMode) {
            $quotesql = DB_query("SELECT * FROM {$_TABLES['ff_topic']} WHERE id=" . (int) $quoteid);
            $quotearray = DB_fetchArray($quotesql);
            $quotearray['name'] = urldecode($quotearray['name']);
            $quotearray['comment'] = $quotearray['comment'];
            $postData['comment'] = sprintf($_FF_CONF['quoteformat'], $quotearray['name'], $quotearray['comment']);
        }
        $postData['editpid'] = $postData['id'];
    }
    if ($_FF_CONF['use_sfs']) {
        $peTemplate->set_var('usesfs', 1);
    }
    if (COM_isAnonUser()) {
        if (!$_FF_CONF['use_sfs']) {
            $postData['email'] = '';
        }
        $peTemplate->set_var('anonymous_user', true);
        $peTemplate->set_var('post_message', $postmessage);
        $peTemplate->set_var('LANG_NAME', $LANG_GF02['msg33']);
        $peTemplate->set_var('name', htmlentities(strip_tags(COM_checkWords(trim(USER_sanitizeName(isset($postData['name']) ? $postData['name'] : ''))))), ENT_COMPAT, COM_getEncodingt());
        if (isset($postData['email'])) {
            $peTemplate->set_var('email', strip_tags($postData['email']));
        }
    } else {
        $peTemplate->set_var('member_user', true);
        $peTemplate->set_var('post_message', $postmessage);
        $peTemplate->set_var('LANG_NAME', $LANG_GF02['msg33']);
        if (!isset($username) or $username == '') {
            if ($action == 'edittopic') {
                if ($editmoderator) {
                    $username = $postData['name'];
                } else {
                    $username = COM_getDisplayName($_USER['uid']);
                }
            } else {
                $username = COM_getDisplayName($_USER['uid']);
            }
        }
        $peTemplate->set_var('username', $username);
        $peTemplate->set_var('xusername', urlencode($username));
    }
    $moodoptions = '';
    if ($_FF_CONF['show_moods']) {
        if (isset($postData['mood']) && $postData['mood'] != '') {
            $postData['mood'] = COM_applyFilter($postData['mood']);
        }
        if (!isset($postData['mood']) || $postData['mood'] == '') {
            $moodoptions = '<option value="" selected="selected">' . $LANG_GF01['NOMOOD'] . '</option>';
        }
        if ($dir = @opendir($_CONF['path_html'] . '/forum/images/moods')) {
            while (($file = readdir($dir)) !== false) {
                if (strlen($file) > 3 && substr(strtolower(trim($file)), -4, 4) == '.gif') {
                    $file = str_replace(array('.gif', '.jpg'), array('', ''), $file);
                    if (isset($postData['mood']) && $file == $postData['mood']) {
                        $moodoptions .= "<option selected=\"selected\">" . $file . "</option>";
                    } else {
                        $moodoptions .= "<option>" . $file . "</option>";
                    }
                } else {
                    $moodoptions .= '';
                }
            }
            closedir($dir);
        }
        $peTemplate->set_var('LANG_MOOD', $LANG_GF02['msg36']);
        $peTemplate->set_var('moodoptions', $moodoptions);
    }
    $sub_dot = '...';
    $sub_none = '';
    $postData['subject'] = str_replace($sub_dot, $sub_none, $postData['subject']);
    if ($_FF_CONF['allow_smilies']) {
        $peTemplate->set_var('smiley_enabled', true);
    }
    if ($_FF_CONF['allow_img_bbcode']) {
        $peTemplate->set_var('allow_img_bbcode', true);
    }
    // if this is the first time showing the new submission form - then check if notify option should be on
    if (!$viewMode) {
        if (isset($postData['editpid']) && $postData['editpid'] > 0) {
            $notifyTopicid = $postData['editpid'];
        } else {
            $notifyTopicid = $postData['id'];
        }
        if (!isset($postData['forum'])) {
            $postData['forum'] = '';
        }
        if (DB_getItem($_TABLES['ff_userprefs'], 'alwaysnotify', "uid=" . (int) $uid) == 1 or FF_isSubscribed($postData['forum'], $notifyTopicid, $uid)) {
            $postData['notify'] = 'on';
            // check and see if user has un-subscribed to this topic
            $nid = -$notifyTopicid;
            if ($notifyTopicid > 0 and DB_getItem($_TABLES['subscriptions'], 'id', "type='forum' AND category=" . (int) $postData['forum'] . " AND id={$nid} AND uid={$uid}") > 1) {
                $postData['notify'] = '';
            }
        } else {
            $postData['notify'] = '';
        }
    }
    if ($editmoderator) {
        if (isset($postData['notify']) && $postData['notify'] == 'on' or isset($postData['notify']) && $postData['notify'] == 'on') {
            $notify_val = 'checked="checked"';
        } else {
            $notify_val = '';
        }
        $notify_prompt = $LANG_GF02['msg38'] . '<br/><input type="checkbox" name="notify" value="on" ' . $notify_val . '/>';
        // check that this is the parent topic - only able to make it skicky or locked
        if (!isset($postData['pid']) || $postData['pid'] == 0) {
            if (!isset($locked_val) and !isset($sticky_val) and $action == 'edittopic') {
                if (!isset($postData['locked_switch']) and isset($postData['locked']) && $postData['locked'] == 1 or isset($postData['locked_switch']) && $postData['locked_switch'] == 1) {
                    $locked_val = 'checked="checked"';
                } else {
                    $locked_val = '';
                }
                if (!isset($postData['sticky_switch']) and isset($postData['sticky']) && $postData['sticky'] == 1 or isset($postData['sticky_switch']) && $postData['sticky_switch'] == 1) {
                    $sticky_val = 'checked="checked"';
                } else {
                    $sticky_val = '';
                }
            }
            $locked_prompt = $LANG_GF02['msg109'] . '<br/><input type="checkbox" name="locked_switch" ' . $locked_val . ' value="1"/>';
            $sticky_prompt = $LANG_GF02['msg61'] . '<br/><input type="checkbox" name="sticky_switch" ' . $sticky_val . ' value="1"/>';
        } else {
            $locked_prompt = '';
            $sticky_prompt = '';
        }
    } else {
        if ($uid > 1) {
            if (isset($postData['notify']) && $postData['notify'] == 'on') {
                $notify_val = 'checked="checked"';
            } else {
                $notify_val = '';
            }
            $notify_prompt = $LANG_GF02['msg38'] . '<br/><input type="checkbox" name="notify" ' . $notify_val . '/>';
            $locked_prompt = '';
        } else {
            $notify_prompt = '';
            $locked_prompt = '';
        }
    }
    if ($postData['postmode'] == 'html' || $postData['postmode'] == 'HTML') {
        $postmode_msg = $LANG_GF01['TEXTMODE'];
        $postData['postmode'] = 'html';
    } else {
        $peTemplate->unset_var('show_htmleditor');
        $postmode_msg = $LANG_GF01['HTMLMODE'];
    }
    if ($_FF_CONF['allow_html'] || SEC_inGroup('Root') || SEC_hasRights('forum.html')) {
        if ($action == 'edittopic') {
            $mode_prompt = $postmode_msg . '<br/><input type="checkbox" name="postmode_switch" value="1"/><input type="hidden" name="postmode" value="' . $postData['postmode'] . '"/>';
        }
    }
    if ($action == 'edittopic') {
        $peTemplate->set_var('bbcodeeditor', true);
    }
    $postData['subject'] = str_replace('"', '&quot;', $postData['subject']);
    if (!$_FF_CONF['allow_smilies']) {
        $smilies = '';
    } else {
        $smilies = forumPLG_showsmilies(0);
    }
    $disable_bbcode_prompt = $LANG_GF01['disable_bbcode'] . '&nbsp;<input type="checkbox" name="disable_bbcode" value="1" ' . $disable_bbcode_val . '/>';
    if ($_FF_CONF['allow_smilies']) {
        $disable_smilies_prompt = $LANG_GF01['disable_smilies'] . '&nbsp;<input type="checkbox" name="disable_smilies" value="1"' . $disable_smilies_val . ' />';
    } else {
        $disable_smilies_prompt = '';
    }
    $disable_urlparse_prompt = $LANG_GF01['disable_urlparse'] . '&nbsp;<input type="checkbox" name="disable_urlparse" value="1"' . $disable_urlparse_val . ' />';
    $peTemplate->set_var('comment', @htmlspecialchars($postData['comment'], ENT_QUOTES, COM_getEncodingt()));
    $peTemplate->set_var(array('edit_val' => $edit_val, 'sticky_val' => $sticky_val, 'postmode_msg' => $postmode_msg, 'notify_val' => $notify_val, 'disable_bbcode_val' => $disable_bbcode_val, 'disable_smilies_val' => $disable_smilies_val, 'disable_urlparse_val' => $disable_urlparse_val, 'bbcode_prompt' => $disable_bbcode_prompt, 'smilies_prompt' => $disable_smilies_prompt, 'urlparse_prompt' => $disable_urlparse_prompt, 'LANG_SUBJECT' => $LANG_GF01['SUBJECT'], 'LANG_OPTIONS' => $LANG_GF01['OPTIONS'], 'mode_prompt' => isset($mode_prompt) ? $mode_prompt : '', 'notify_prompt' => $notify_prompt, 'locked_prompt' => $locked_prompt, 'sticky_prompt' => isset($sticky_prompt) ? $sticky_prompt : '', 'edit_prompt' => $edit_prompt, 'LANG_SUBMIT' => $LANG_GF01['SUBMIT'], 'LANG_PREVIEW' => $LANG_GF01['PREVIEW'], 'subject' => $postData['subject'], 'smilies' => $smilies, 'LANG_attachments' => $LANG_GF10['attachments'], 'LANG_maxattachments' => sprintf($LANG_GF10['maxattachments'], $_FF_CONF['maxattachments']), 'postmode' => $postData['postmode']));
    // Check and see if the filemgmt plugin is installed and enabled
    if (function_exists('filemgmt_buildAccessSql') && $_FF_CONF['enable_fm_integration'] == 1) {
        $peTemplate->set_var('filemgmt_category_options', gf_makeFilemgmtCatSelect($uid));
        $peTemplate->set_var('LANG_usefilemgmt', $LANG_GF10['usefilemgmt']);
        $peTemplate->set_var('LANG_description', $LANG_GF10['description']);
        $peTemplate->set_var('LANG_category', $LANG_GF10['category']);
    } else {
        $peTemplate->set_var('show_filemgmt_option', 'none');
    }
    if (COM_isAnonUser()) {
        $peTemplate->set_var('hide_notify', 'none');
    }
    if (function_exists('plugin_templatesetvars_captcha')) {
        plugin_templatesetvars_captcha('forum', $peTemplate);
    } else {
        $peTemplate->set_var('captcha', '');
    }
    if ($postData['id'] > 0) {
        $peTemplate->set_var('topic_id', $postData['id']);
    }
    $peTemplate->set_var(array('navbreadcrumbsimg' => _ff_getImage('nav_breadcrumbs'), 'navtopicimg' => _ff_getImage('nav_topic'), 'form_action' => $_CONF['site_url'] . '/forum/createtopic.php', 'referer' => $forumData['referer'], 'forum_id' => $forumData['forum'], 'cat_name' => $postData['cat_name'], 'cat_id' => $forumData['forum_cat'], 'forum_name' => $postData['forum_name'], 'subject' => @htmlspecialchars($postData['subject'], ENT_QUOTES, COM_getEncodingt()), 'LANG_HOME' => $LANG_GF01['HOMEPAGE'], 'forum_home' => $LANG_GF01['INDEXPAGE'], 'hidden_id' => $postData['id'], 'page' => $forumData['page'], 'LANG_bhelp' => $LANG_GF01['b_help'], 'LANG_ihelp' => $LANG_GF01['i_help'], 'LANG_uhelp' => $LANG_GF01['u_help'], 'LANG_qhelp' => $LANG_GF01['q_help'], 'LANG_chelp' => $LANG_GF01['c_help'], 'LANG_lhelp' => $LANG_GF01['l_help'], 'LANG_ohelp' => $LANG_GF01['o_help'], 'LANG_phelp' => $LANG_GF01['p_help'], 'LANG_whelp' => $LANG_GF01['w_help'], 'LANG_ahelp' => $LANG_GF01['a_help'], 'LANG_shelp' => $LANG_GF01['s_help'], 'LANG_fhelp' => $LANG_GF01['f_help'], 'LANG_hhelp' => $LANG_GF01['h_help'], 'LANG_thelp' => $LANG_GF01['t_help'], 'LANG_ehelp' => $LANG_GF01['e_help'], 'LANG_code' => $LANG_GF01['CODE'], 'LANG_fontcolor' => $LANG_GF01['FONTCOLOR'], 'LANG_fontsize' => $LANG_GF01['FONTSIZE'], 'LANG_closetags' => $LANG_GF01['CLOSETAGS'], 'LANG_codetip' => $LANG_GF01['CODETIP'], 'LANG_tiny' => $LANG_GF01['TINY'], 'LANG_small' => $LANG_GF01['SMALL'], 'LANG_normal' => $LANG_GF01['NORMAL'], 'LANG_large' => $LANG_GF01['LARGE'], 'LANG_huge' => $LANG_GF01['HUGE'], 'LANG_default' => $LANG_GF01['DEFAULT'], 'LANG_dkred' => $LANG_GF01['DKRED'], 'LANG_red' => $LANG_GF01['RED'], 'LANG_orange' => $LANG_GF01['ORANGE'], 'LANG_brown' => $LANG_GF01['BROWN'], 'LANG_yellow' => $LANG_GF01['YELLOW'], 'LANG_green' => $LANG_GF01['GREEN'], 'LANG_olive' => $LANG_GF01['OLIVE'], 'LANG_cyan' => $LANG_GF01['CYAN'], 'LANG_blue' => $LANG_GF01['BLUE'], 'LANG_dkblue' => $LANG_GF01['DKBLUE'], 'LANG_indigo' => $LANG_GF01['INDIGO'], 'LANG_violet' => $LANG_GF01['VIOLET'], 'LANG_white' => $LANG_GF01['WHITE'], 'LANG_black' => $LANG_GF01['BLACK']));
    $peTemplate->set_var('token_name', CSRF_TOKEN);
    $peTemplate->set_var('token', SEC_createToken());
    $peTemplate->set_var('postmode', $postData['postmode']);
    $peTemplate->unset_var('show_htmleditor');
    if ($_FF_CONF['use_wysiwyg_editor'] && $postData['postmode'] == 'html') {
        // hook into wysiwyg here
        switch (PLG_getEditorType()) {
            case 'ckeditor':
                $peTemplate->set_var('show_htmleditor', true);
                PLG_requestEditor('forum', 'forum_entry', 'ckeditor_forum.thtml');
                PLG_templateSetVars('forum_entry', $peTemplate);
                break;
            case 'tinymce':
                $peTemplate->set_var('show_htmleditor', true);
                PLG_requestEditor('forum', 'forum_entry', 'tinymce_forum.thtml');
                PLG_templateSetVars('forum_entry', $peTemplate);
                break;
            default:
                // don't support others right now
                break;
        }
    }
    $peTemplate->parse('output', 'posteditor');
    $retval .= $peTemplate->finish($peTemplate->get_var('output'));
    $urlfor = 'advancededitor';
    if ($uid == 1) {
        $urlfor = 'advancededitor' . md5($REMOTE_ADDR);
    }
    SEC_setCookie($_CONF['cookie_name'] . 'adveditor', SEC_createTokenGeneral($urlfor), time() + 1200, $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure'], false);
    if (!isset($_POST['editpost'])) {
        $_POST['editpost'] = '';
    }
    if ($action != 'newtopic' && $_POST['editpost'] != 'yes' && ($action == 'newreply' || $viewMode)) {
        if ($FF_userprefs['showiframe']) {
            $retval .= "<iframe src=\"{$_CONF['site_url']}/forum/viewtopic.php?mode=preview&amp;showtopic=" . $postData['id'] . "&amp;onlytopic=1&amp;lastpost=true\" height=\"300\" width=\"100%\"></iframe>";
        }
    }
    return $retval;
}
Пример #3
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'));
}
Пример #4
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'));
}