function curl($action, $params = array()) { $settings = sirportly_settings(); $url = ($settings['ssl'] == 'on' ? 'https://' : 'http://') . $settings['url']; $curl = curl_init(); $default_params = array('brand' => $settings['brand']); $params = array_merge($default_params, $params); $header = array('X-Auth-Token: ' . $settings['token'], 'X-Auth-Secret: ' . $settings['secret']); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_VERBOSE, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_URL, $url . $action); curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); $result = curl_exec($curl); $status_code = curl_getinfo($curl); $json = json_decode($result, true); curl_close($curl); logModuleCall("Sirportly", $action, $params, $result, $json); return array('status' => $status_code['http_code'], 'results' => $json); }
<?php define("CLIENTAREA", true); require "init.php"; $ca = new WHMCS_ClientArea(); $settings = sirportly_settings(); $ca->setPageTitle($whmcs->get_lang('supportticketsviewticket')); $ca->initPage(); global $CONFIG; if (!sirportly_enabled()) { die('Sirportly module not enabled.'); } if ($CONFIG['RequireLoginforClientTickets'] == 'on' && !$ca->isLoggedIn()) { header('Location: login.php'); } ## Close ticket if ($settings['close_ticket'] && $_GET['closeticket']) { $close = curl('/api/v2/tickets/update', array('ticket' => $_GET['tid'], 'status' => $settings['closed_status'])); if ($close['status'] != 200) { $ca->assign('errormessage', "Unable to close ticket, please contact support."); } else { header('Location: viewticket.php?tid=' . $_GET['tid'] . '&c=' . $_GET['c']); } } $ticket = curl('/api/v2/tickets/ticket', array('reference' => $_GET['tid'])); if ($ticket['results']['id'] != $_GET['c']) { header('Location: supporttickets.php'); } ## An update has been posted if ($_POST) { foreach ($_POST as $key => $value) {
function sirportly_output($vars) { echo ' <p> <strong>Options:</strong> <a href="addonmodules.php?module=sirportly">Data Source</a> | <a href="addonmodules.php?module=sirportly&action=support">Support Tickets</a> | <a href="addonmodules.php?module=sirportly&action=merge">Merge Contacts</a> </p>'; switch ($_GET['action']) { case 'merge': if ($_POST) { if (!$_POST['from'] || !$_POST['into']) { echo '<div class="errorbox"><strong>An Error Occured!</strong><br />Please select both a "from" and "to" contact.</div>'; } elseif (!$_POST['from'] or !$_POST['into'] or $_POST['from'] == $_POST['into']) { echo '<div class="errorbox"><strong>An Error Occured!</strong><br />You cannot merge contacts into themselves.</div>'; } else { $merge = sirportly_merge_contacts($_POST['from'], $_POST['into']); if ($merge['status'] != 200) { echo '<div class="errorbox"><strong>An Error Occured!</strong><br />' . $merge['results']['error'] . '</div>'; } else { echo '<div class="infobox"><strong>Success!</strong><br />Successfully merged the contacts.</div>'; } } } $sirportly_contacts = sirportly_contacts(); $whmcs_contacts = full_query("SELECT sc.customerid, wc.firstname, wc.lastname, wc.email FROM sirportly_customers sc LEFT JOIN tblclients wc ON sc.userid = wc.id"); echo ' <form method="POST" action="addonmodules.php?module=sirportly&action=merge"> <table class="form" width="100%" border="0" cellspacing="2" cellpadding="3"> <tr> <td width="100px" class="fieldlabel">Merge</td> <td class="fieldarea" width="100px"><select name="from">'; foreach ($sirportly_contacts as $key => $value) { echo '<option' . ($value['id'] == $_POST['from'] ? ' selected=selected' : '') . ' value="' . $value['id'] . '">' . $value['name'] . ' (' . $value['id'] . ')</option>'; } echo ' </select> </td> <td width="50px" class="fieldlabel">in to</td> <td class="fieldarea"width="100px"><select name="into">'; while ($contact = mysql_fetch_array($whmcs_contacts, MYSQL_ASSOC)) { echo '<option ' . ($contact['customerid'] == $_POST['into'] ? ' selected=selected' : '') . ' value="' . $contact['customerid'] . '">' . $contact['firstname'] . ' ' . $contact['lastname'] . ' (' . $contact['customerid'] . ')</option>'; } echo ' </select> </td> </tr></table> <p align="center"><input type="submit" value="Merge Contacts" /></p> </form>'; break; case 'support': if (!$vars['token'] || !$vars['secret']) { echo '<div class="errorbox"><strong>An Error Occured!</strong><br />Please enter your API Token and/or Secret.</div>'; return; } if ($_POST) { update_query('tbladdonmodules', array('value' => $_POST['brand']), array('module' => 'sirportly', 'setting' => 'brand')); update_query('tbladdonmodules', array('value' => $_POST['status']), array('module' => 'sirportly', 'setting' => 'status')); update_query('tbladdonmodules', array('value' => $_POST['priority']), array('module' => 'sirportly', 'setting' => 'priority')); update_query('tbladdonmodules', array('value' => $_POST['close_ticket']), array('module' => 'sirportly', 'setting' => 'close_ticket')); update_query('tbladdonmodules', array('value' => $_POST['closed_status']), array('module' => 'sirportly', 'setting' => 'closed_status')); echo '<div class="successbox"><strong>Success!</strong><br />Changes saved successfully.</div>'; } $sirportly_settings = sirportly_settings(); $brands = sirportly_brands($vars['token'], $vars['secret']); $status = sirportly_status($vars['token'], $vars['secret']); $priority = sirportly_priorities($vars['token'], $vars['secret']); echo '<p>By selecting a brand below all tickets opened via the client area will be submitted to Sirportly, <strong><u>NOT</u></strong> WHMCS, keep "Disabled" selected if you want to keep tickets within WHMCS.</p> <form method="POST" action="addonmodules.php?module=sirportly&action=support"> <table class="form" width="100%" border="0" cellspacing="2" cellpadding="3"> <tr> <td width="20%" class="fieldlabel">Brand</td> <td class="fieldarea"><select name="brand">'; foreach ($brands as $key => $value) { echo '<option' . ($sirportly_settings['brand'] == $key ? ' selected=selected' : '') . ' value="' . $key . '">' . $value . '</option>'; } echo ' </select> </td> </tr> <tr> <td width="20%" class="fieldlabel">New Ticket Status</td> <td class="fieldarea"><select name="status">'; foreach ($status as $key => $value) { echo '<option' . ($sirportly_settings['status'] == $key ? ' selected=selected' : '') . ' value="' . $key . '">' . $value . '</option>'; } echo '</select></td> </tr> <tr> <td width="20%" class="fieldlabel">Default Ticket Priority</td> <td class="fieldarea"><select name="priority">'; foreach ($priority as $key => $value) { echo '<option' . ($sirportly_settings['priority'] == $value['id'] ? ' selected=selected' : '') . ' value="' . $value['id'] . '">' . $value['name'] . '</option>'; } echo ' </select></td> </tr> <tr> <td width="20%" class="fieldlabel">Allow Clients to Close Tickets</td> <td class="fieldarea"><select name="close_ticket"> <option' . ($sirportly_settings['close_ticket'] == '1' ? ' selected=selected' : '') . ' value="1">Yes</option> <option' . ($sirportly_settings['close_ticket'] == '0' ? ' selected=selected' : '') . ' value="0">No</option> </select> </td> </tr> <tr> <td width="20%" class="fieldlabel">Closed Ticket Status</td> <td class="fieldarea"><select name="closed_status">'; foreach ($status as $key => $value) { echo '<option' . ($sirportly_settings['closed_status'] == $key ? ' selected=selected' : '') . ' value="' . $key . '">' . $value . '</option>'; } echo '</select></td> </tr> </table> <p align="center"><input type="submit" value="Save Changes" /></p> </form>'; break; default: if ($_POST) { unset($_POST['token']); mysql_query('TRUNCATE TABLE `sirportly`'); foreach ($_POST as $group_key => $group_value) { foreach ($group_value as $row_key => $row_value) { insert_query('sirportly', array('field_type' => $group_key, 'field_name' => $row_key)); } } echo '<div class="infobox"><strong>Changes Saved Successfully!</strong><br />Your changes have been saved.</div>'; } $current_fields = array(); $result = mysql_query("SELECT * FROM `sirportly`"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $current_fields[$row['1']][$row[2]] = $row[2]; } $tables = array('tblclients', 'tbldomains', 'tblhosting', 'tblinvoices'); $fields = array(); foreach ($tables as $key => $value) { $result = mysql_query("SHOW COLUMNS FROM `" . $value . "`"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $fields[$value][$row[0]] = $row[0]; } } unset($fields['tblclients']['email'], $fields['tblclients']['pwresetexpiry'], $fields['tblclients']['pwresetkey'], $fields['tbldomains']['userid'], $fields['tblhosting']['userid']); unset($fields['tblinvoices']['userid']); unset($fields['tblclients']['password']); echo '<form method="POST" action="addonmodules.php?module=sirportly"> <table class="form" width="100%" border="0" cellspacing="2" cellpadding="3"> <tr>'; foreach ($fields as $group_key => $group_value) { echo '<td width="20%" class="fieldlabel">' . sirportly_lang($group_key) . ' fields</td><td class="fieldarea">'; foreach ($group_value as $row_key => $row_value) { if (in_array($row_value, $current_fields[$group_key])) { echo '<label><input type="checkbox" checked name="' . $group_key . '[' . $row_value . ']" value="1" /> ' . sirportly_lang($row_value) . '</label>'; } else { echo '<label><input type="checkbox" name="' . $group_key . '[' . $row_value . ']" value="1" /> ' . sirportly_lang($row_value) . '</label>'; } } echo '</td></tr>'; } echo '</table><p align="center"><input type="submit" value="Save Changes" /></p></form>'; break; } }