0

目前我正在尝试将 osTicket 表单嵌入到我的网站中,以便用户可以提交集成到我的网站中的票证。

我在网上找到了一个 PHP 脚本,并在另一个线程的用户的帮助下,我让它工作了,所以当我在服务器上运行脚本时,它会打开一个包含 PHP 脚本中编写的所有信息的票证。我希望能够有一个 HTML 页面,它从 HTML 页面上的表单提交信息,以替换 PHP 脚本中的预设信息。

完成此操作的第一个想法是简单地从作为 osTicket 一部分的默认“提交票证”页面复制相关文件。我在网络浏览器中查看了源代码,并看到了与下载文件并在文本编辑器中查看不同的代码。

所以我使用的 PHP 脚本是:

<?php

# //Configuration: Enter the url and key. 
# url => URL to api/tickets.json # e.g http://yourdomain.com/s#upport/api/tickets.json
# key => API's Key (see admin panel o#n how to generate a key)
#


$config = array(
'url'=>'support.sinergycraft.net/tickets/api/tickets.json',
'key'=>'C2621CFA3E5F94B5396003218952DA0D'
);

#pre-checks
function_exists('curl_version') or die('CURL support required');

#set timeout
set_time_limit(30);

#Sample data for the ticket
# See https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md for full list of variables and options that you can pass.
$data = array("alert" => "true",
       "autorespond" => "true",
       "source" => "API",
       "name" => "Angry User",
       "email" => "api@osticket.com",
       "subject" => "Testing API 3",
       "message" => "MESSAGE HERE"
);
#Convert the above array into json to POST to the API with curl below.
$data_string = json_encode($data);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);

if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200)
exit(0);

echo $result;
exit(1);
?>

如果我像在此代码中所做的那样将表单链接到此:

<form id="ticketForm" method="post" action="new_ticket.php" enctype="multipart/form-data">

PHP脚本被称为new_ticket.php. 这将打开一个带有 PHP 中预填选项的工单,但不是用户在表单中输入的内容。

接下来,我认为我应该尝试使用从服务器下载的文件,而不是从查看源代码获得的代码。

当您单击链接制作新票时在浏览器中打开的文件被调用open.php,其内容如下:

<?php

    open.php


require('client.inc.php');
define('SOURCE','Web'); //Ticket source.
$ticket = null;
$errors=array();
if ($_POST) {
    $vars = $_POST;
    $vars['deptId']=$vars['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected.
    if ($thisclient) {
        $vars['uid']=$thisclient->getId();
    } elseif($cfg->isCaptchaEnabled()) {
        if(!$_POST['captcha'])
            $errors['captcha']=__('Enter text shown on the image');
        elseif(strcmp($_SESSION['captcha'], md5(strtoupper($_POST['captcha']))))
            $errors['captcha']=__('Invalid - try again!');
    }

    $tform = TicketForm::objects()->one()->getForm($vars);
    $messageField = $tform->getField('message');
    $attachments = $messageField->getWidget()->getAttachments();
    if (!$errors && $messageField->isAttachmentsEnabled())
        $vars['cannedattachments'] = $attachments->getClean();

    // Drop the draft.. If there are validation errors, the content
    // submitted will be displayed back to the user
    Draft::deleteForNamespace('ticket.client.'.substr(session_id(), -12));
    //Ticket::create...checks for errors..
    if(($ticket=Ticket::create($vars, $errors, SOURCE))){
        $msg=__('Support ticket request created');
        // Drop session-backed form data
        unset($_SESSION[':form-data']);
        //Logged in...simply view the newly created ticket.
        if($thisclient && $thisclient->isValid()) {
            session_write_close();
            session_regenerate_id();
            @header('Location: tickets.php?id='.$ticket->getId());
        }
    }else{
        $errors['err']=$errors['err']?$errors['err']:__('Unable to create a ticket. Please correct errors below and try again!');
    }
}

//page
$nav->setActiveNav('new');
if ($cfg->isClientLoginRequired()) {
    if (!$thisclient) {
        require_once 'secure.inc.php';
    }
    elseif ($thisclient->isGuest()) {
        require_once 'login.php';
        exit();
    }
}

require(CLIENTINC_DIR.'header.inc.php');
if($ticket
        && (
            (($topic = $ticket->getTopic()) && ($page = $topic->getPage()))
            || ($page = $cfg->getThankYouPage())
        )) {
    // Thank the user and promise speedy resolution!
    echo Format::viewableImages($ticket->replaceVars($page->getBody()));
}
else {
    require(CLIENTINC_DIR.'open.inc.php');
}
require(CLIENTINC_DIR.'footer.inc.php');
?>

我尝试将其替换为我的 HTML 代码中的操作,而不是new_ticket.php但我仍然没有运气。

所以基本上我想做的是能够以 HTML 表单提交信息,并用 PHP 脚本中的预先编写的文本替换用户输入的内容。

最后,下面我提供了当我在 Web 浏览器中打开 open.php 文件时在视图 shource 中显示的内容。这是我为我的 HTML 文档复制表单的文件,我希望将数据提交给 PHP 脚本。

<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>SinergyCraft.net Support</title>
    <meta name="description" content="customer support platform">
    <meta name="keywords" content="osTicket, Customer support system, support ticket system">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="/tickets/css/osticket.css?ecb4f89" media="screen">
    <link rel="stylesheet" href="/tickets/assets/default/css/theme.css?ecb4f89" media="screen">
    <link rel="stylesheet" href="/tickets/assets/default/css/print.css?ecb4f89" media="print">
    <link rel="stylesheet" href="/tickets/scp/css/typeahead.css"
         media="screen" />
    <link type="text/css" href="/tickets/css/ui-lightness/jquery-ui-1.10.3.custom.min.css"
        rel="stylesheet" media="screen" />
    <link rel="stylesheet" href="/tickets/css/thread.css?ecb4f89" media="screen">
    <link rel="stylesheet" href="/tickets/css/redactor.css?ecb4f89" media="screen">
    <link type="text/css" rel="stylesheet" href="/tickets/css/font-awesome.min.css?ecb4f89">
    <link type="text/css" rel="stylesheet" href="/tickets/css/flags.css?ecb4f89">
    <link type="text/css" rel="stylesheet" href="/tickets/css/rtl.css?ecb4f89"/>
    <script type="text/javascript" src="/tickets/js/jquery-1.8.3.min.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/jquery-ui-1.10.3.custom.min.js?ecb4f89"></script>
    <script src="/tickets/js/osticket.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/filedrop.field.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/jquery.multiselect.min.js?ecb4f89"></script>
    <script src="/tickets/scp/js/bootstrap-typeahead.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/redactor.min.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/redactor-osticket.js?ecb4f89"></script>
    <script type="text/javascript" src="/tickets/js/redactor-fonts.js?ecb4f89"></script>

    <meta name="csrf_token" content="4f5df4c017ca804903b7b513210231cd8fd6d714" />
</head>
<body>
    <div id="container">
        <div id="header">
            <a class="pull-left" id="logo" href="/tickets/index.php"
            title="Support Center"><img src="/tickets/logo.php" border=0 alt="SinergyCraft.net Support"
                style="height: 5em"></a>
            <div class="pull-right flush-right">
            <p>
                         </p>
            <p>
            </p>
            </div>
        </div>
        <div class="clear"></div>
                <ul id="nav" class="flush-left">
            <li><a class=" home" href="/tickets/index.php">Support Center Home</a></li>
<li><a class="active new" href="/tickets/open.php">Open a New Ticket</a></li>
<li><a class=" status" href="/tickets/view.php">Check Ticket Status</a></li>
        </ul>
                <div id="content">

         <h1>Open a New Ticket</h1>
<p>Please fill in the form below to open a new ticket.</p>
<form id="ticketForm" method="post" action="open.php" enctype="multipart/form-data">
  <input type="hidden" name="__CSRFToken__" value="4f5df4c017ca804903b7b513210231cd8fd6d714" />  <input type="hidden" name="a" value="open">
  <table width="800" cellpadding="1" cellspacing="0" border="0">
    <tbody>
    <tr>
        <td class="required">Help Topic:</td>
        <td>
            <select id="topicId" name="topicId" onchange="javascript:
                    var data = $(':input[name]', '#dynamic-form').serialize();
                    $.ajax(
                      'ajax.php/form/help-topic/' + this.value,
                      {
                        data: data,
                        dataType: 'json',
                        success: function(json) {
                          $('#dynamic-form').empty().append(json.html);
                          $(document.head).append(json.media);
                        }
                      });">
                <option value="" selected="selected">&mdash; Select a Help Topic &mdash;</option>
                <option value="12" >Ban Site/Server</option><option value="1" >General Inquiry</option><option value="2" >Recruitment</option><option value="10" >Report a Problem</option><option value="11" >White List Me</option>            </select>
            <font class="error">*&nbsp;</font>
        </td>
    </tr>
    <tr><td colspan="2"><hr />
    <div class="form-header" style="margin-bottom:0.5em">
        <h3>Contact Information</h3>
    <em></em>
    </div>
    </td></tr>
            <tr>
                            <td><label for="b695be87472f918f" class="required">
                Email Address:</label></td><td>
                    <span style="display:inline-block">
        <input type="text"
            id="_b695be87472f918f"
            size="40" maxlength="64" placeholder=""            name="b695be87472f918f"
            value=""/>
        </span>
                                    <font class="error">*</font>
                        </td>
        </tr>
                <tr>
                            <td><label for="e6ac2c5b0fbeba20" class="required">
                Full Name:</label></td><td>
                    <span style="display:inline-block">
        <input type="text"
            id="_e6ac2c5b0fbeba20"
            size="40" maxlength="64" placeholder=""            name="e6ac2c5b0fbeba20"
            value=""/>
        </span>
                                    <font class="error">*</font>
                        </td>
        </tr>
            </tbody>
    <tbody id="dynamic-form">
            </tbody>
    <tbody>    <tr><td colspan="2"><hr />
    <div class="form-header" style="margin-bottom:0.5em">
            <link rel="stylesheet" type="text/css" href="/tickets/css/jquery.multiselect.css"/>    <h3>Ticket Details</h3>
    <em>Please Describe Your Issue</em>
    </div>
    </td></tr>
            <tr>
                            <td><label for="48b638e54863b978" class="required">
                Issue Summary:</label></td><td>
                    <span style="display:inline-block">
        <input type="text"
            id="_48b638e54863b978"
            size="40" maxlength="50" placeholder=""            name="48b638e54863b978"
            value=""/>
        </span>
                                    <font class="error">*</font>
                        </td>
        </tr>
                <tr>
                            <td colspan="2">
            <div style="margin-bottom:0.5em;margin-top:0.5em"><strong>Issue Details</strong>:</div>
        <textarea style="width:100%;" name="message"
            placeholder="Details on the reason(s) for opening the ticket."
                            data-draft-namespace="ticket.client"
                data-draft-object-id="ea999hv0kkq1"
                        class="richtext draft draft-delete ifhtml"
            cols="21" rows="8" style="width:80%;"></textarea>
    <div id="b6d716e83936ea511681b5" class="filedrop"><div class="files"></div>
            <div class="dropzone"><i class="icon-upload"></i>
            Drop files here or <a href="#" class="manual"> choose them </a>        <input type="file" multiple="multiple"
            id="file-b6d716e83936ea511681b5" style="display:none;"
            accept=""/>
        </div></div>
        <script type="text/javascript">
        $(function(){$('#b6d716e83936ea511681b5 .dropzone').filedropbox({
          url: 'ajax.php/form/upload/attach',
          link: $('#b6d716e83936ea511681b5').find('a.manual'),
          paramname: 'upload[]',
          fallback_id: 'file-b6d716e83936ea511681b5',
          allowedfileextensions: [],
          allowedfiletypes: [],
          maxfiles: 20,
          maxfilesize: 32,
          name: 'attach:21[]',
          files: []        });});
        </script>
        <link rel="stylesheet" type="text/css" href="/tickets/css/filedrop.css"/>                            <font class="error">*</font>
                        </td>
        </tr>
            </tbody>
    <tbody>
        <tr><td colspan=2>&nbsp;</td></tr>
    </tbody>
  </table>
<hr/>
  <p style="text-align:center;">
        <input type="submit" value="Create Ticket">
        <input type="reset" name="reset" value="Reset">
        <input type="button" name="cancel" value="Cancel" onclick="javascript:
            $('.richtext').each(function() {
                var redactor = $(this).data('redactor');
                if (redactor && redactor.opts.draftDelete)
                    redactor.deleteDraft();
            });
            window.location.href='index.php';">
  </p>
</form>
        </div>
    </div>
    <div id="footer">
        <p>Copyright &copy; 2015 SinergyCraft.net Support - All rights reserved.</p>
        <a id="poweredBy" href="http://osticket.com" target="_blank">Helpdesk software - powered by osTicket</a>
    </div>
<div id="overlay"></div>
<div id="loading">
    <h4>Please Wait!</h4>
    <p>Please wait... it will take a second!</p>
</div>
</body>
</html>

谢谢

4

1 回答 1

0

我可能在您的问题中遗漏了一些东西,但我认为您只需要在表单中添加更多内容,然后在 PHP 中提取变量:

HTML:

<form id="ticketForm" method="post" action="new_ticket.php" >
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="subject" />
<textarea name="message"></textarea>
<input type="submit" name="submit" value="send" />

(我想我可以在您的页面源转储中看到其中一些输入字段,但名称字段似乎是生成的,例如,name="b695be87472f918f"无论您使用 html name=' name ' 和 $_POST[' name '] 都需要匹配)。

然后在您的 PHP 代码中:

$data = array("alert" => "true",
   "autorespond" => "true",
   "source" => "API",
   "name" => $_POST['name'],
   "email" => $_POST['email'],
   "subject" => $_POST['subject'],
   "message" => $_POST['message']
 );

在实际使用它们之前对这些值进行一些验证可能是明智的。

于 2015-01-14T15:23:15.607 回答