예제 #1
0
function submit_store_form($auto_select = array('store' => ''))
{
    global $LANG;
    if ($GLOBALS['me']) {
        if (!(bool) \query\main::get_option('allow_stores')) {
            return '<div class="info_form">' . $LANG['submit_store_not_allowed'] . '</div>';
        }
        $form = '<div class="submit_store_form other_form">';
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_store_form']) && \site\utils::check_csrf($_POST['submit_store_form']['csrf'], 'submit_store_csrf')) {
            $pd = \site\utils::validate_user_data($_POST['submit_store_form']);
            try {
                \user\main::submit_store($GLOBALS['me']->ID, $pd);
                $form .= '<div class="success">' . $LANG['submit_store_success'] . '</div>';
                unset($pd);
            } catch (Exception $e) {
                $form .= '<div class="error">' . $e->getMessage() . '</div>';
            }
        }
        $csrf = $_SESSION['submit_store_csrf'] = \site\utils::str_random(12);
        $form .= '<form method="POST" action="#" enctype="multipart/form-data">
  <div class="form_field"><label for="submit_store_form[category]">' . $LANG['form_category'] . '</label>
  <div><select name="submit_store_form[category]" id="submit_store_form[category]">';
        foreach (\query\main::group_categories(array('max' => 0)) as $cat) {
            $wcat = '<optgroup label="' . $cat['infos']->name . '">';
            $wcat .= '<option value="' . $cat['infos']->ID . '"' . (isset($pd['category']) && $pd['category'] == $cat['infos']->ID ? ' selected' : '') . '>' . $cat['infos']->name . '</option>';
            if (isset($cat['subcats'])) {
                foreach ($cat['subcats'] as $subcat) {
                    $wcat .= '<option value="' . $subcat->ID . '"' . (isset($pd['category']) && $pd['category'] == $cat['infos']->ID ? ' selected' : '') . '>' . $subcat->name . '</option>';
                }
            }
            $wcat .= '</optgroup>';
            $form .= $wcat;
        }
        $form .= '</select></div>
  </div>
  <div class="form_field"><label for="submit_store_form[name]">' . $LANG['form_name'] . ':</label> <div><input type="text" name="submit_store_form[name]" id="submit_store_form[name]" value="' . (isset($pd['name']) ? $pd['name'] : '') . '" placeholder="' . $LANG['submit_store_name_ph'] . '" required /></div></div>
  <div class="form_field"><label for="submit_store_form[url]">' . $LANG['form_store_url'] . ':</label> <div><input type="text" name="submit_store_form[url]" id="submit_store_form[url]" value="' . (isset($pd['url']) ? $pd['url'] : '') . '" placeholder="http://" required /></div></div>
  <div class="form_field"><label for="submit_store_form[description]">' . $LANG['form_description'] . ':</label> <div><textarea name="submit_store_form[description]" id="submit_store_form[description]" style="height:100px;">' . (isset($pd['description']) ? $pd['description'] : '') . '</textarea></div></div>
  <div class="form_field"><label for="submit_store_form[tags]">' . $LANG['form_tags'] . ':</label> <div><input type="text" name="submit_store_form[tags]" id="submit_store_form[tags]" value="' . (isset($pd['tags']) ? $pd['tags'] : '') . '" /></div></div>
  <div class="form_field"><label for="submit_store_form_logo">' . $LANG['form_logo'] . ':</label> <div><input type="file" name="submit_store_form_logo" id="submit_store_form_logo" />
  <span>Note:* max width: 600px, max height: 400px.</span></div></div>
  <input type="hidden" name="submit_store_form[csrf]" value="' . $csrf . '" />
  <button>' . $LANG['submit_store_button'] . '</button>
  </form>

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