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; } }
foreach ($value as $row_key => $row_value) { if (in_array($row_key, $decrypt)) { $api = localAPI('decryptpassword', array('password2' => $result[$row_key]), $admin['id']); $apiresults[sirportly_lang($key)][$row_key] = $api['password']; } else { mb_detect_encoding($result[$row_key], "UTF-8") == "UTF-8" ? $apiresults[sirportly_lang($key)][$row_key] = $result[$row_key] : ($apiresults[sirportly_lang($key)][$row_key] = utf8_encode($result[$row_key])); } } } else { $res = array(); while ($result = mysql_fetch_array($query, MYSQL_ASSOC)) { $row = array(); foreach ($value as $row_key => $row_value) { if (in_array($row_key, $decrypt)) { $api = localAPI('decryptpassword', array('password2' => $result[$row_key]), $admin['id']); $row[$row_key] = $api['password']; } else { $row[$row_key] = $result[$row_key]; } } array_push($res, $row); } $apiresults[sirportly_lang($key)] = $res; } global $customadminpath; if ($key == 'tblclients') { $apiresults[sirportly_lang('tblclients')]['WHMCS URL'] = 'link:' . $CONFIG['SystemURL'] . '/' . $customadminpath . '/clientssummary.php?userid=' . $client['id'] . '|Click Here'; } } header('HTTP/1.1 200 OK'); echo json_encode($apiresults);