示例#1
0
function submit_product_form($auto_select = array('store' => ''))
{
    global $LANG;
    if ($GLOBALS['me']) {
        if ($GLOBALS['me']->Stores > 0) {
            if (!(bool) \query\main::get_option('allow_products')) {
                return '<div class="info_form">' . $LANG['submit_prod_not_allowed'] . '</div>';
            }
            $form = '<div class="submit_product_form other_form">';
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_product_form']) && \site\utils::check_csrf($_POST['submit_product_form']['csrf'], 'submit_coupon_csrf')) {
                $pd = \site\utils::validate_user_data($_POST['submit_product_form']);
                try {
                    \user\main::submit_product($GLOBALS['me']->ID, $pd);
                    $form .= '<div class="success">' . $LANG['submit_cou_success'] . '</div>';
                    unset($pd);
                } catch (Exception $e) {
                    $form .= '<div class="error">' . $e->getMessage() . '</div>';
                }
            }
            $csrf = $_SESSION['submit_coupon_csrf'] = \site\utils::str_random(12);
            $form .= '<form method="POST" action="#" enctype="multipart/form-data">
  <div class="form_field"><label for="submit_product_form[store]">' . $LANG['submit_prod_addto'] . '</label>
  <div><select name="submit_product_form[store]" id="submit_product_form[store]">';
            foreach (stores_custom(array('user' => $GLOBALS['me']->ID, 'max' => 0)) as $v) {
                $form .= '<option value="' . $v->ID . '"' . (!isset($pd['store']) && !empty($auto_select['store']) && ($auto_select['store'] == $v->ID || $auto_select['store'] == $v->name) || isset($pd['store']) && $pd['store'] == $v->ID ? ' selected' : '') . '>' . $v->name . '</option>';
            }
            $form .= '</select></div>
  </div>
  <div class="form_field"><label for="submit_product_form[name]">' . $LANG['form_name'] . ':</label> <div><input type="text" name="submit_product_form[name]" id="submit_product_form[name]" value="' . (isset($pd['name']) ? $pd['name'] : '') . '" placeholder="' . $LANG['submit_prod_name_ph'] . '" required /></div></div>
  <div class="form_field"><label for="submit_product_form[price]">' . $LANG['form_price'] . ':</label> <div><input type="text" name="submit_product_form[price]" id="submit_product_form[price]" value="' . (isset($pd['price']) ? $pd['price'] : '') . '" placeholder="' . $LANG['submit_prod_price_ph'] . '" /></div></div>
  <div class="form_field"><label for="submit_product_form[old_price]">' . $LANG['form_old_price'] . ':</label> <div><input type="text" name="submit_product_form[old_price]" id="submit_product_form[old_price]" value="' . (isset($pd['old_price']) ? $pd['old_price'] : '') . '" placeholder="' . $LANG['submit_prod_oldprice_ph'] . '" /></div></div>
  <div class="form_field"><label for="submit_product_form[currency]">' . $LANG['currency'] . ':</label> <div><input type="text" name="submit_product_form[currency]" id="submit_product_form[currency]" value="' . (isset($pd['currency']) ? $pd['currency'] : CURRENCY) . '" /></div></div>
  <div class="form_field"><label for="submit_product_form[url]">' . $LANG['form_product_url'] . ':</label> <div><input type="text" name="submit_product_form[url]" id="submit_product_form[url]" value="' . (isset($pd['url']) ? $pd['url'] : '') . '" /></div></div>
  <div class="form_field"><label for="submit_product_form[description]">' . $LANG['form_description'] . ':</label> <div><textarea name="submit_product_form[description]" id="submit_product_form[description]" style="height:100px;">' . (isset($pd['description']) ? $pd['description'] : '') . '</textarea></div></div>
  <div class="form_field"><label for="submit_product_form[tags]">' . $LANG['form_tags'] . ':</label> <div><input type="text" name="submit_product_form[tags]" id="submit_product_form[tags]" value="' . (isset($pd['tags']) ? $pd['tags'] : '') . '" /></div></div>
  <div class="form_field"><label for="submit_product_form_image">' . $LANG['form_image'] . ':</label> <div><img src="' . product_avatar('') . '" alt="" style="width:90px; height:90px;" /> <input type="file" name="submit_product_form_image" id="submit_product_form_image" />
  <span>Note:* max width: 800px, max height: 800px.</span></div></div>
  <div class="form_field"><label for="submit_product_form[start]">' . $LANG['form_start_date'] . ':</label> <div><input type="date" name="submit_product_form[start]" id="submit_product_form[start]" value="' . (isset($pd['start']) ? $pd['start'] : '') . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="submit_product_form[start_hour]" value="' . (isset($pd['start_hour']) ? $pd['start_hour'] : '00:00') . '" style="width: 20%" /></div></div>
  <div class="form_field"><label for="submit_product_form[end]">' . $LANG['form_end_date'] . ':</label> <div><input type="date" name="submit_product_form[end]" id="submit_product_form[end]" value="' . (isset($pd['end']) ? $pd['end'] : '') . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="submit_product_form[end_hour]" value="' . (isset($pd['end_hour']) ? $pd['end_hour'] : '00:00') . '" style="width: 20%" /></div></div>
  <input type="hidden" name="submit_product_form[csrf]" value="' . $csrf . '" />
  <button>' . $LANG['submit_prod_button'] . '</button>
  </form>

  </div>';
            return $form;
        } else {
            return '<div class="info_form">' . $LANG['unavailable_form2'] . '</div>';
        }
    } else {
        return '<div class="info_form">' . $LANG['unavailable_form'] . '</div>';
    }
}