Skip to content
Snippets Groups Projects
Commit 9217eda0 authored by Peter Rotich's avatar Peter Rotich
Browse files

Implement organization support

parent e68002c0
No related branches found
No related tags found
No related merge requests found
<?php
/*********************************************************************
ajax.orgs.php
Peter Rotich <peter@osticket.com>
Jared Hancock <jared@osticket.com>
Copyright (c) 2014 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
if(!defined('INCLUDE_DIR')) die('403');
include_once(INCLUDE_DIR.'class.ticket.php');
class OrgsAjaxAPI extends AjaxController {
function search($type = null) {
if(!isset($_REQUEST['q'])) {
Http::response(400, 'Query argument is required');
}
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25;
$orgs=array();
$escaped = db_input(strtolower($_REQUEST['q']), false);
$sql='SELECT DISTINCT org.id, org.name '
.' FROM '.ORGANIZATION_TABLE.' org '
.' LEFT JOIN '.FORM_ENTRY_TABLE.' entry ON (entry.object_type=\'O\' AND entry.object_id = org.id)
LEFT JOIN '.FORM_ANSWER_TABLE.' value ON (value.entry_id=entry.id) '
.' WHERE org.name LIKE \'%'.$escaped.'%\' OR value.value LIKE \'%'.$escaped.'%\''
.' ORDER BY org.created '
.' LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)){
while(list($id, $name)=db_fetch_row($res)) {
$orgs[] = array('name' => Format::htmlchars($name), 'info' => $name,
'id' => $id, '/bin/true' => $_REQUEST['q']);
}
}
return $this->json_encode(array_values($orgs));
}
function editOrg($id) {
global $thisstaff;
if(!$thisstaff)
Http::response(403, 'Login Required');
elseif(!($org = Organization::lookup($id)))
Http::response(404, 'Unknown organization');
$info = array(
'title' => sprintf('Update %s', $org->getName())
);
$forms = $org->getForms();
include(STAFFINC_DIR . 'templates/org.tmpl.php');
}
function updateOrg($id) {
global $thisstaff;
if(!$thisstaff)
Http::response(403, 'Login Required');
elseif(!($org = Organization::lookup($id)))
Http::response(404, 'Unknown organization');
$errors = array();
if($org->update($_POST, $errors))
Http::response(201, $org->to_json());
$forms = $org->getForms();
include(STAFFINC_DIR . 'templates/org.tmpl.php');
}
function delete($id) {
global $thisstaff;
if (!$thisstaff)
Http::response(403, 'Login Required');
elseif (!($org = Organization::lookup($id)))
Http::response(404, 'Unknown user');
$info = array();
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
if ($org->delete())
Http::response(204, 'Organization deleted successfully');
else
$info['error'] = 'Unable to delete organization - try again!';
}
include(STAFFINC_DIR . 'templates/org-delete.tmpl.php');
}
function addOrg() {
$info = array();
if ($_POST) {
$form = OrganizationForm::getDefaultForm()->getForm($_POST);
if (($org = Organization::fromForm($form)))
Http::response(201, $org->to_json());
$info = array('error' =>'Error adding organization - try again!');
}
$info['title'] = 'Add New Organization';
$info['search'] = false;
return self::_lookupform($form, $info);
}
function lookup() {
return self::_lookupform();
}
function selectOrg($id) {
if ($id) $org = Organization::lookup($id);
$info = array('title' => 'Select Organization');
ob_start();
include(STAFFINC_DIR . 'templates/org-lookup.tmpl.php');
$resp = ob_get_contents();
ob_end_clean();
return $resp;
}
static function _lookupform($form=null, $info=array()) {
if (!$info or !$info['title'])
$info += array('title' => 'Organization Lookup');
ob_start();
include(STAFFINC_DIR . 'templates/org-lookup.tmpl.php');
$resp = ob_get_contents();
ob_end_clean();
return $resp;
}
}
?>
...@@ -543,6 +543,7 @@ class UserAccountModel extends VerySimpleModel { ...@@ -543,6 +543,7 @@ class UserAccountModel extends VerySimpleModel {
class UserAccount extends UserAccountModel { class UserAccount extends UserAccountModel {
var $_options = null; var $_options = null;
var $_user; var $_user;
var $_org;
const CONFIRMED = 0x0001; const CONFIRMED = 0x0001;
const LOCKED = 0x0002; const LOCKED = 0x0002;
...@@ -616,6 +617,30 @@ class UserAccount extends UserAccountModel { ...@@ -616,6 +617,30 @@ class UserAccount extends UserAccountModel {
return $this->_user; return $this->_user;
} }
function getOrgId() {
return $this->get('org_id');
}
function getOrganization() {
if (!isset($this->_org))
$this->_org = Organization::lookup($this->getOrgId());
return $this->_org;
}
function setOrganization($org) {
if (!$org instanceof Organization)
return false;
$this->set('org_id', $org->getId());
$this->_org = null;
$this->save();
return true;
}
function sendResetEmail() { function sendResetEmail() {
return static::sendUnlockEmail('pwreset-client') === true; return static::sendUnlockEmail('pwreset-client') === true;
} }
......
<?php
if(!defined('OSTSCPINC') || !$thisstaff || !is_object($org)) die('Invalid path');
?>
<table width="940" cellpadding="2" cellspacing="0" border="0">
<tr>
<td width="50%" class="has_bottom_border">
<h2><a href="orgs.php?id=<?php echo $org->getId(); ?>"
title="Reload"><i class="icon-refresh"></i> <?php echo $org->getName(); ?></a></h2>
</td>
<td width="50%" class="right_align has_bottom_border">
<a id="org-delete" class="action-button org-action"
href="#orgs/<?php echo $org->getId(); ?>/delete"><i class="icon-trash"></i> Delete Organization</a>
</td>
</tr>
</table>
<table class="ticket_info" cellspacing="0" cellpadding="0" width="940" border="0">
<tr>
<td width="50">
<table border="0" cellspacing="" cellpadding="4" width="100%">
<tr>
<th width="100">Name:</th>
<td><b><a href="#orgs/<?php echo $org->getId();
?>/edit" class="org-action"><i
class="icon-edit"></i>&nbsp;<?php echo
$org->getName();
?></a></td>
</tr>
<tr>
<th>Users:</th>
<td> {num-here}
</td>
</tr>
</table>
</td>
<td width="50%" style="vertical-align:top">
<table border="0" cellspacing="" cellpadding="4" width="100%">
<tr>
<th>Created:</th>
<td><?php echo Format::db_datetime($org->getCreateDate()); ?></td>
</tr>
<tr>
<th>Updated:</th>
<td><?php echo Format::db_datetime($org->getUpdateDate()); ?></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<div class="clear"></div>
<ul class="tabs">
<li><a class="active" id="users_tab" href="#users"><i
class="icon-list-alt"></i>&nbsp;Users</a></li>
</ul>
<div id="users">
<div style="width:700px; float:left;">
<?php
if ($results) {
echo sprintf('<strong>Showing 1 - %d of %s</strong>',
count($results), count($results));
} else {
echo 'Organization does not have users';
}
?>
</div>
<div style="float:right;text-align:right;padding-right:5px;">
<b><a class="Icon newStaff" href="users.php?a=open&oid=<?php echo
$org->getId(); ?>"> Add New User</a></b>
</div>
<br/>
</div>
<script type="text/javascript">
$(function() {
$(document).on('click', 'a.org-action', function(e) {
e.preventDefault();
var url = 'ajax.php/'+$(this).attr('href').substr(1);
$.dialog(url, [201, 204], function (xhr) {
if (xhr.status == 204)
window.location.href = 'orgs.php';
else
window.location.href = window.location.href;
}, {
onshow: function() { $('#org-search').focus(); }
});
return false;
});
});
</script>
<?php
if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied');
$qstr='';
$select = 'SELECT org.* ';
$from = 'FROM '.ORGANIZATION_TABLE.' org ';
$where = ' WHERE 1 ';
if ($_REQUEST['query']) {
$from .=' LEFT JOIN '.FORM_ENTRY_TABLE.' entry
ON (entry.object_type=\'O\' AND entry.object_id = org.id)
LEFT JOIN '.FORM_ANSWER_TABLE.' value
ON (value.entry_id=entry.id) ';
$search = db_input(strtolower($_REQUEST['query']), false);
$where .= ' AND (
org.name LIKE \'%'.$search.'%\' OR value.value LIKE \'%'.$search.'%\'
)';
$qstr.='&query='.urlencode($_REQUEST['query']);
}
$sortOptions = array('name' => 'org.name',
'users' => 'users',
'create' => 'org.created',
'update' => 'org.updated');
$orderWays = array('DESC'=>'DESC','ASC'=>'ASC');
$sort= ($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])]) ? strtolower($_REQUEST['sort']) : 'name';
//Sorting options...
if ($sort && $sortOptions[$sort])
$order_column =$sortOptions[$sort];
$order_column = $order_column ?: 'org.name';
if ($_REQUEST['order'] && $orderWays[strtoupper($_REQUEST['order'])])
$order = $orderWays[strtoupper($_REQUEST['order'])];
$order=$order ?: 'ASC';
if ($order_column && strpos($order_column,','))
$order_column = str_replace(','," $order,",$order_column);
$x=$sort.'_sort';
$$x=' class="'.strtolower($order).'" ';
$order_by="$order_column $order ";
$total=db_count('SELECT count(DISTINCT org.id) '.$from.' '.$where);
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav=new Pagenate($total,$page,PAGE_LIMIT);
$pageNav->setURL('orgs.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order']));
//Ok..lets roll...create the actual query
$qstr.='&order='.($order=='DESC'?'ASC':'DESC');
$select .= ', count(DISTINCT user.id) as users ';
$from .= ' LEFT JOIN '.USER_ACCOUNT_TABLE.' user ON (user.org_id = org.id) ';
$query="$select $from $where GROUP BY org.id ORDER BY $order_by LIMIT ".$pageNav->getStart().",".$pageNav->getLimit();
//echo $query;
?>
<h2>Organizations</h2>
<div style="width:700px; float:left;">
<form action="orgs.php" method="get">
<?php csrf_token(); ?>
<input type="hidden" name="a" value="search">
<table>
<tr>
<td><input type="text" id="basic-org-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"
autocomplete="off" autocorrect="off" autocapitalize="off"></td>
<td><input type="submit" name="basic_search" class="button" value="Search"></td>
<!-- <td>&nbsp;&nbsp;<a href="" id="advanced-user-search">[advanced]</a></td> -->
</tr>
</table>
</form>
</div>
<div style="float:right;text-align:right;padding-right:5px;">
<b><a href="#orgs/add" class="Icon newDepartment add-org">Add New Organization</a></b></div>
<div class="clear"></div>
<?php
$showing = $search ? 'Search Results: ' : '';
$res = db_query($query);
if($res && ($num=db_num_rows($res)))
$showing .= $pageNav->showing();
else
$showing .= 'No organizations found!';
?>
<form action="orgs.php" method="POST" name="staff" >
<?php csrf_token(); ?>
<input type="hidden" name="do" value="mass_process" >
<input type="hidden" id="action" name="a" value="" >
<table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
<caption><?php echo $showing; ?></caption>
<thead>
<tr>
<th width="400"><a <?php echo $name_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=name">Name</a></th>
<th width="100"><a <?php echo $users_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=users">Users</a></th>
<th width="150"><a <?php echo $create_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=create">Created</a></th>
<th width="145"><a <?php echo $update_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=update">Updated</a></th>
</tr>
</thead>
<tbody>
<?php
if($res && db_num_rows($res)):
$ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null;
while ($row = db_fetch_array($res)) {
$sel=false;
if($ids && in_array($row['id'], $ids))
$sel=true;
?>
<tr id="<?php echo $row['id']; ?>">
<td>&nbsp; <a href="orgs.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a> </td>
<td>&nbsp;<?php echo $row['users']; ?></td>
<td><?php echo Format::db_date($row['created']); ?></td>
<td><?php echo Format::db_datetime($row['updated']); ?>&nbsp;</td>
</tr>
<?php
} //end of while.
endif; ?>
<tfoot>
<tr>
<td colspan="5"> &nbsp; </td>
</tr>
</tfoot>
</table>
<?php
if($res && $num): //Show options..
echo '<div>&nbsp;Page:'.$pageNav->getPageLinks().'&nbsp;</div>';
endif;
?>
</form>
<script type="text/javascript">
$(function() {
$('input#basic-org-search').typeahead({
source: function (typeahead, query) {
$.ajax({
url: "ajax.php/orgs/search?q="+query,
dataType: 'json',
success: function (data) {
typeahead.process(data);
}
});
},
onselect: function (obj) {
window.location.href = 'orgs.php?id='+obj.id;
},
property: "/bin/true"
});
$(document).on('click', 'a.add-org', function(e) {
e.preventDefault();
$.orgLookup('ajax.php/orgs/add', function (org) {
window.location.href = 'orgs.php?id='+org.id;
});
return false;
});
});
</script>
<?php
if (!$info['title'])
$info['title'] = 'Organization Lookup';
$msg_info = 'Search existing organizations or add a new one';
if ($info['search'] === false)
$msg_info = 'Complete the form below to add a new organization';
?>
<div id="the-lookup-form">
<h3><?php echo $info['title']; ?></h3>
<b><a class="close" href="#"><i class="icon-remove-circle"></i></a></b>
<hr/>
<div><p id="msg_info"><i class="icon-info-sign"></i>&nbsp; <?php echo $msg_info; ?></p></div>
<?php
if ($info['search'] !== false) { ?>
<div style="margin-bottom:10px;">
<input type="text" class="search-input" style="width:100%;"
placeholder="Search by name" id="org-search" autocorrect="off" autocomplete="off"/>
</div>
<?php
}
if ($info['error']) {
echo sprintf('<p id="msg_error">%s</p>', $info['error']);
} elseif ($info['warning']) {
echo sprintf('<p id="msg_warning">%s</p>', $info['warning']);
} elseif ($info['msg']) {
echo sprintf('<p id="msg_notice">%s</p>', $info['msg']);
} ?>
<div id="selected-org-info" style="display:<?php echo $org ? 'block' :'none'; ?>;margin:5px;">
<form method="post" class="org" action="<?php echo $info['action'] ?: '#orgs/lookup'; ?>">
<input type="hidden" id="org-id" name="orgid" value="<?php echo $org ? $org->getId() : 0; ?>"/>
<i class="icon-group icon-4x pull-left icon-border"></i>
<a class="action-button pull-right" style="overflow:inherit"
id="unselect-org" href="#"><i class="icon-remove"></i> Add New Organization</a>
<div><strong id="org-name"><?php echo $org ? Format::htmlchars($org->getName()) : ''; ?></strong></div>
<?php if ($org) { ?>
<table style="margin-top: 1em;">
<?php foreach ($org->getDynamicData() as $entry) { ?>
<tr><td colspan="2" style="border-bottom: 1px dotted black"><strong><?php
echo $entry->getForm()->get('title'); ?></strong></td></tr>
<?php foreach ($entry->getAnswers() as $a) { ?>
<tr style="vertical-align:top"><td style="width:30%;border-bottom: 1px dotted #ccc"><?php echo Format::htmlchars($a->getField()->get('label'));
?>:</td>
<td style="border-bottom: 1px dotted #ccc"><?php echo $a->display(); ?></td>
</tr>
<?php }
} ?>
</table>
<?php
} ?>
<div class="clear"></div>
<hr>
<p class="full-width">
<span class="buttons" style="float:left">
<input type="button" name="cancel" class="close" value="Cancel">
</span>
<span class="buttons" style="float:right">
<input type="submit" value="Continue">
</span>
</p>
</form>
</div>
<div id="new-org-form" style="display:<?php echo $org ? 'none' :'block'; ?>;">
<form method="post" class="org" action="<?php echo $info['action'] ?: '#orgs/add'; ?>">
<table width="100%" class="fixed">
<?php
if (!$form) $form = OrganizationForm::getInstance();
$form->render(true, 'Create New Organization'); ?>
</table>
<hr>
<p class="full-width">
<span class="buttons" style="float:left">
<input type="reset" value="Reset">
<input type="button" name="cancel" class="<?php echo $org ? 'cancel' : 'close' ?>" value="Cancel">
</span>
<span class="buttons" style="float:right">
<input type="submit" value="Add Organization">
</span>
</p>
</form>
</div>
<div class="clear"></div>
</div>
<script type="text/javascript">
$(function() {
var last_req;
$('#org-search').typeahead({
source: function (typeahead, query) {
if (last_req) last_req.abort();
last_req = $.ajax({
url: "ajax.php/orgs/search?q="+query,
dataType: 'json',
success: function (data) {
typeahead.process(data);
}
});
},
onselect: function (obj) {
$('#the-lookup-form').load(
'<?php echo $info['onselect'] ?: 'ajax.php/orgs/select'; ?>/'+encodeURIComponent(obj.id)
);
},
property: "/bin/true"
});
$('a#unselect-org').click( function(e) {
e.preventDefault();
$('div#selected-org-info').hide();
$('div#new-org-form').fadeIn({start: function(){ $('#org-search').focus(); }});
return false;
});
$(document).on('click', 'form.org input.cancel', function (e) {
e.preventDefault();
$('div#new-org-form').hide();
$('div#selected-org-info').fadeIn({start: function(){ $('#org-search').focus(); }});
return false;
});
});
</script>
<?php
if (!$info['title'])
$info['title'] = Format::htmlchars($org->getName());
?>
<h3><?php echo $info['title']; ?></h3>
<b><a class="close" href="#"><i class="icon-remove-circle"></i></a></b>
<hr/>
<?php
if ($info['error']) {
echo sprintf('<p id="msg_error">%s</p>', $info['error']);
} elseif ($info['msg']) {
echo sprintf('<p id="msg_notice">%s</p>', $info['msg']);
} ?>
<div id="org-profile" style="display:<?php echo $forms ? 'none' : 'block'; ?>;margin:5px;">
<i class="icon-group icon-4x pull-left icon-border"></i>
<?php
if ($account) { ?>
<a class="action-button pull-right user-action" style="overflow:inherit"
href="#users/<?php echo $account->getUserId(); ?>/org/<?php echo $org->getId(); ?>" ><i class="icon-user"></i> Change Organization</a>
<?php
} ?>
<div><b><a href="#" id="editorg"><i class="icon-edit"></i>&nbsp;<?php
echo Format::htmlchars($org->getName()); ?></a></b></div>
<table style="margin-top: 1em;">
<?php foreach ($org->getDynamicData() as $entry) {
?>
<tr><td colspan="2" style="border-bottom: 1px dotted black"><strong><?php
echo $entry->getForm()->get('title'); ?></strong></td></tr>
<?php foreach ($entry->getAnswers() as $a) { ?>
<tr style="vertical-align:top"><td style="width:30%;border-bottom: 1px dotted #ccc"><?php echo Format::htmlchars($a->getField()->get('label'));
?>:</td>
<td style="border-bottom: 1px dotted #ccc"><?php echo $a->display(); ?></td>
</tr>
<?php }
}
?>
</table>
<div class="clear"></div>
<hr>
<div class="faded">Last updated <b><?php echo Format::db_datetime($org->getUpdateDate()); ?> </b></div>
</div>
<div id="org-form" style="display:<?php echo $forms ? 'block' : 'none'; ?>;">
<div><p id="msg_info"><i class="icon-info-sign"></i>&nbsp; Please note that updates will be reflected system-wide.</p></div>
<?php
$action = $info['action'] ? $info['action'] : ('#orgs/'.$org->getId());
if ($ticket && $ticket->getOwnerId() == $user->getId())
$action = '#tickets/'.$ticket->getId().'/user';
?>
<form method="post" class="org" action="<?php echo $action; ?>">
<input type="hidden" name="id" value="<?php echo $org->getId(); ?>" />
<table width="100%">
<?php
if (!$forms) $forms = $org->getForms();
foreach ($forms as $form)
$form->render();
?>
</table>
<hr>
<p class="full-width">
<span class="buttons" style="float:left">
<input type="reset" value="Reset">
<input type="button" name="cancel" class="<?php
echo $account ? 'cancel' : 'close'; ?>" value="Cancel">
</span>
<span class="buttons" style="float:right">
<input type="submit" value="Update Organization">
</span>
</p>
</form>
</div>
<div class="clear"></div>
<script type="text/javascript">
$(function() {
$('a#editorg').click( function(e) {
e.preventDefault();
$('div#org-profile').hide();
$('div#org-form').fadeIn();
return false;
});
$(document).on('click', 'form.org input.cancel', function (e) {
e.preventDefault();
$('div#org-form').hide();
$('div#org-profile').fadeIn();
return false;
});
});
</script>
<?php <?php
if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'); if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path');
$account = $user->getAccount();
$org = $account ? $account->getOrganization() : null;
?> ?>
<table width="940" cellpadding="2" cellspacing="0" border="0"> <table width="940" cellpadding="2" cellspacing="0" border="0">
<tr> <tr>
...@@ -10,7 +14,7 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path' ...@@ -10,7 +14,7 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'
</td> </td>
<td width="50%" class="right_align has_bottom_border"> <td width="50%" class="right_align has_bottom_border">
<?php <?php
if ($user->getAccount()) { ?> if ($account) { ?>
<span class="action-button" data-dropdown="#action-dropdown-more"> <span class="action-button" data-dropdown="#action-dropdown-more">
<span ><i class="icon-cog"></i> More</span> <span ><i class="icon-cog"></i> More</span>
<i class="icon-caret-down"></i> <i class="icon-caret-down"></i>
...@@ -20,7 +24,7 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path' ...@@ -20,7 +24,7 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'
<a id="user-delete" class="action-button user-action" <a id="user-delete" class="action-button user-action"
href="#users/<?php echo $user->getId(); ?>/delete"><i class="icon-trash"></i> Delete User</a> href="#users/<?php echo $user->getId(); ?>/delete"><i class="icon-trash"></i> Delete User</a>
<?php <?php
if ($user->getAccount()) { ?> if ($account) { ?>
<a id="user-manage" class="action-button user-action" <a id="user-manage" class="action-button user-action"
href="#users/<?php echo $user->getId(); ?>/manage"><i class="icon-edit"></i> Manage Account</a> href="#users/<?php echo $user->getId(); ?>/manage"><i class="icon-edit"></i> Manage Account</a>
<?php <?php
...@@ -32,8 +36,8 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path' ...@@ -32,8 +36,8 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'
<div id="action-dropdown-more" class="action-dropdown anchor-right"> <div id="action-dropdown-more" class="action-dropdown anchor-right">
<ul> <ul>
<?php <?php
if ($user->getAccount()) { if ($account) {
if (!$user->getAccount()->isConfirmed()) { if (!$account->isConfirmed()) {
?> ?>
<li><a class="confirm-action" href="#confirmlink"><i <li><a class="confirm-action" href="#confirmlink"><i
class="icon-envelope"></i> Send Activation Email</a></li> class="icon-envelope"></i> Send Activation Email</a></li>
...@@ -73,10 +77,22 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path' ...@@ -73,10 +77,22 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'
</td> </td>
</tr> </tr>
<tr> <tr>
<th>Company:</th> <th>Organization:</th>
<td> <td>
<span id="user-<?php echo $user->getId(); <span id="user-<?php echo $user->getId(); ?>-org">
?>-org"><?php echo $user->getOrg(); ?></span> <?php
if ($org)
echo sprintf('<a href="#users/%d/org"
class="user-action">%s</a>',
$user->getId(), $org->getName());
elseif ($account)
echo sprintf('<a href="#users/%d/org"
class="user-action">Add Organization</a>',
$user->getId());
else
echo '&nbsp;';
?>
</span>
</td> </td>
</tr> </tr>
</table> </table>
......
...@@ -86,6 +86,21 @@ $dispatcher = patterns('', ...@@ -86,6 +86,21 @@ $dispatcher = patterns('',
url_post('^/(?P<id>\d+)/org$', 'updateOrg'), url_post('^/(?P<id>\d+)/org$', 'updateOrg'),
url_get('^/staff$', 'searchStaff') url_get('^/staff$', 'searchStaff')
)), )),
url('^/orgs', patterns('ajax.orgs.php:OrgsAjaxAPI',
url_get('^$', 'search'),
url_get('^/search$', 'search'),
url_get('^/(?P<id>\d+)$', 'getOrg'),
url_post('^/(?P<id>\d+)$', 'updateOrg'),
url_get('^/(?P<id>\d+)/edit$', 'editOrg'),
url_get('^/lookup/form$', 'lookup'),
url_post('^/lookup/form$', 'addOrg'),
url_get('^/add$', 'addOrg'),
url_post('^/add$', 'addOrg'),
url_get('^/select$', 'selectOrg'),
url_get('^/select/(?P<id>\d+)$', 'selectOrg'),
url_get('^/(?P<id>\d+)/delete$', 'delete'),
url_delete('^/(?P<id>\d+)/delete$', 'delete')
)),
url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI',
url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'), url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'),
url_post('^(?P<tid>\d+)/change-user$', 'changeUser'), url_post('^(?P<tid>\d+)/change-user$', 'changeUser'),
......
...@@ -501,6 +501,15 @@ $(document).ready(function(){ ...@@ -501,6 +501,15 @@ $(document).ready(function(){
}); });
}; };
$.orgLookup = function (url, cb) {
$.dialog(url, 201, function (xhr) {
var org = $.parseJSON(xhr.responseText);
if (cb) cb(org);
}, {
onshow: function() { $('#org-search').focus(); }
});
};
$('#advanced-search').delegate('#status', 'change', function() { $('#advanced-search').delegate('#status', 'change', function() {
switch($(this).val()) { switch($(this).val()) {
case 'closed': case 'closed':
......
<?php
/*********************************************************************
orgs.php
Peter Rotich <peter@osticket.com>
Jared Hancock <jared@osticket.com>
Copyright (c) 2006-2014 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require('staff.inc.php');
$org = null;
if ($_REQUEST['id'])
$org = Organization::lookup($_REQUEST['id']);
$page = $org? 'org-view.inc.php' : 'orgs.inc.php';
$nav->setTabActive('users');
require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page);
include(STAFFINC_DIR.'footer.inc.php');
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment