v7‰PNG
IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ±üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0AºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT
PK 9\*
db.xmlnu [
PK 9\W֨ library/HelpdeskMessage.phpnu [ _ticket)) {
$this->_ticket = $this->getDi()->helpdeskTicketTable->load($this->ticket_id);
}
return $this->_ticket;
}
public function setAttachments($attachments)
{
$this->attachments = $this->serializeIds($attachments);
}
public function getAttachments()
{
return $this->unserializeIds($this->attachments);
}
public function loadGetAttachments()
{
if (is_null($this->_attachments))
$this->_attachments = $this->getDi()->uploadTable->loadIds($this->getAttachments());
return $this->_attachments;
}
public function delete()
{
foreach ($this->loadGetAttachments() as $att) {
/* @var $att Upload */
if ($att->prefix == Bootstrap_Helpdesk::ATTACHMENT_UPLOAD_PREFIX)
$att->delete();
}
parent::delete();
}
}
class HelpdeskMessageTable extends Am_Table
{
protected $_key = 'message_id';
protected $_table = '?_helpdesk_message';
protected $_recordClass = 'HelpdeskMessage';
public function insert(array $values, $returnInserted = false)
{
if (empty($values['dattm']))
$values['dattm'] = $this->getDi()->sqlDateTime;
return parent::insert($values, $returnInserted);
}
function selectLast($num)
{
return $this->selectObjects("SELECT m.*,
u.user_id, u.name_f AS u_name_f, u.name_l AS u_name_l, u.login AS u_login, u.email AS u_email,
a.admin_id, a.name_f AS a_name_f, a.name_l AS a_name_l, a.login AS a_login, a.email AS a_email,
t.ticket_mask as ticket_mask, t.subject as subject
FROM ?_helpdesk_message m LEFT JOIN ?_helpdesk_ticket t USING (ticket_id)
LEFT JOIN ?_user u ON t.user_id = u.user_id
LEFT JOIN ?_admin a ON m.admin_id = a.admin_id
ORDER BY m.dattm DESC LIMIT ?d", $num);
}
}PK 9\wg g library/HelpdeskCategory.phpnu [ getTable()->getName();
$max = $this->getAdapter()->selectCell("SELECT MAX(sort_order) FROM {$table_name}");
$this->sort_order = $max + 1;
return parent::insert($reload);
}
public function delete()
{
$ret = parent::delete();
$table_name = $this->getTable()->getName();
$this->getAdapter()->query("UPDATE {$table_name}
SET sort_order=sort_order-1
WHERE sort_order>?", $this->sort_order);
return $ret;
}
}
class HelpdeskCategoryTable extends Am_Table
{
protected $_key = 'category_id';
protected $_table = '?_helpdesk_category';
protected $_recordClass = 'HelpdeskCategory';
function getOptions($include_disabled=false)
{
return $this->getAdapter()->selectCol("SELECT category_id AS ARRAY_KEY, title
FROM ?_helpdesk_category
WHERE 1 {AND is_disabled=?}
ORDER BY sort_order",
$include_disabled ? DBSIMPLE_SKIP : 0);
}
}PK 9\62 library/HelpdeskFaq.phpnu [ getTable()->getName();
$max = $this->getAdapter()->selectCell("SELECT MAX(sort_order) FROM {$table_name}");
$this->sort_order = $max + 1;
return parent::insert($reload);
}
public function delete()
{
$ret = parent::delete();
$table_name = $this->getTable()->getName();
$this->getAdapter()->query("UPDATE {$table_name}
SET sort_order=sort_order-1
WHERE sort_order>?", $this->sort_order);
return $ret;
}
}
class HelpdeskFaqTable extends Am_Table
{
protected $_key = 'faq_id';
protected $_table = '?_helpdesk_faq';
protected $_recordClass = 'HelpdeskFaq';
function getCategories()
{
return $this->_db->selectCol("SELECT DISTINCT category, category AS ?
FROM ?_helpdesk_faq
WHERE category IS NOT NULL
ORDER BY category", DBSIMPLE_ARRAY_KEY);
}
}
PK 9\rN&2 library/Am/Report/Helpdesk.phpnu [ title = ___('Count of User Messages in Helpdesk');
}
public function getPointField()
{
return 'hm.dattm';
}
/** @return Am_Query */
public function getQuery()
{
$q = new Am_Query($this->getDi()->helpdeskMessageTable, 'hm');
$q->clearFields();
$q->addField('COUNT(message_id)', 'cnt');
$q->addWhere('admin_id IS NULL');
return $q;
}
function getLines()
{
$ret = array();
$ret[] = new Am_Report_Line('cnt', ___('Count of Messages'));
return $ret;
}
}PK 9\b! + library/Am/Helpdesk/Strategy/Admin/User.phpnu [ getDi()->router;;
return $router->assemble(array(
'module' => 'helpdesk',
'controller' => $this->getControllerName(),
'user_id' => $this->getUserId()
) + $params, $route, true);
}
public function setUserId($user_id)
{
$this->user_id = $user_id;
}
public function getUserId()
{
return $this->user_id;
}
public function createNewTicketForm()
{
$form = parent::createNewTicketForm();
$user = $this->getDi()->userTable->load($this->getUserId());
$text = HTML_QuickForm2_Factory::createElement('html', 'loginOrEmail');
$text->setLabel(___('User'))
->setHtml(sprintf('
%s %s (%s)
',
$user->name_f,
$user->name_l,
$user->login
));
$text->toggleFrozen(true);
$form->insertBefore($text, $form->getElementById('loginOrEmail'));
$form->removeChild(
$form->getElementById('loginOrEmail')
);
$loginOrEmail = HTML_QuickForm2_Factory::createElement('hidden', 'loginOrEmail');
$loginOrEmail->setValue($user->login);
$form->addElement($loginOrEmail);
$user_id = HTML_QuickForm2_Factory::createElement('hidden', 'user_id');
$user_id->setValue($user->pk());
$form->addElement($user_id);
return $form;
}
}
PK 9\YT % library/Am/Helpdesk/Strategy/User.phpnu [ _identity = $user_id ? $user_id : $this->getDi()->auth->getUserId();
}
public function isMessageAvalable($message)
{
return!($message->type == 'comment' && $message->admin_id);
}
public function isMessageForReply($message)
{
if ($message->type == 'comment') {
return false;
} else {
return (boolean) $message->admin_id;
}
}
public function fillUpMessageIdentity($message)
{
return $message;
}
public function fillUpTicketIdentity($ticket, $request)
{
$ticket->user_id = $this->getIdentity();
return $ticket;
}
public function getTicketStatusAfterReply($message)
{
if ($message->type == 'comment') {
return $message->getTicket()->status;
} else {
return 'awaiting_admin_response';
}
}
public function onAfterInsertMessage($message, $ticket)
{
if ($this->getDi()->config->get('helpdesk.notify_new_message_admin', 1)) {
$user = $this->getUser($message->getTicket()->user_id);
$recepients[] = Am_Mail_Template::TO_ADMIN;
$exists = array($this->getDi()->config->get('admin_email') => 1);
if (($owner = $message->getTicket()->getOwner()) && !isset($exists[$owner->email])) {
$recepients[] = $owner;
$exists[$owner->email] = 1;
}
foreach ($message->getTicket()->getWatchers() as $w) {
if (!isset($exists[$w->email])) {
$recepients[] = $w;
$exists[$w->email] = 1;
}
}
foreach ($recepients as $recepient) {
if ($et = Am_Mail_Template::load('helpdesk.notify_new_message_admin')) {
$et->setTicket($message->getTicket());
$et->setUser($user);
$et->setMessage($message);
$et->setUrl($this->getDi()->url('helpdesk/admin/ticket/'.$message->getTicket()->ticket_mask,null,false,true));
$et->send($recepient);
}
}
}
}
public function onAfterInsertTicket($ticket)
{
if ($this->getDi()->config->get('helpdesk.new_ticket')) {
$user = $this->getUser($ticket->user_id);
if ($user->unsubscribed)
return;
$et = Am_Mail_Template::load('helpdesk.new_ticket', $user->lang);
if ($et) {
$et->setTicket($ticket);
$et->setUser($user);
$et->setUrl(sprintf('%s/helpdesk/ticket/%s',
$this->getDi()->config->get('root_surl'),
$ticket->ticket_mask)
);
$et->send($user);
}
}
}
public function onViewTicket($ticket)
{
if ($ticket->has_new) {
$ticket->updateQuick('has_new', 0);
}
}
public function getAdminName($message)
{
if ($this->getDi()->modules->get('helpdesk')->getConfig('disclosure_admin')) {
$admin = $this->getAdmin($message->admin_id);
return $admin ? $admin->getName() : ___('Administrator');
} else {
return ___('Administrator');
}
}
public function getTemplatePath()
{
return 'helpdesk';
}
public function getIdentity()
{
return $this->_identity;
}
public function canViewTicket($ticket)
{
return $ticket->user_id == $this->getIdentity();
}
public function canViewMessage($message)
{
return $message->getTicket()->user_id == $this->getIdentity();
}
public function canEditTicket($ticket)
{
return $ticket->user_id == $this->getIdentity() &&
$ticket->status != HelpdeskTicket::STATUS_CLOSED;
}
public function canEditMessage($message)
{
return $message->type == 'comment' &&
($message->getTicket()->user_id == $this->getIdentity());
}
public function canUseSnippets()
{
return false;
}
public function canUseFaq()
{
return false;
}
public function canEditOwner($ticket)
{
return false;
}
public function canEditWatcher($ticket)
{
return false;
}
public function canViewOwner($ticket)
{
return false;
}
public function canEditCategory($ticket)
{
return false;
}
public function createForm()
{
$form = new Am_Form();
$form->addCsrf();
$form->setAttribute('class', 'am-helpdesk-form');
return $form;
}
function getCategoryOptions()
{
$op = $this->getDi()->helpdeskCategoryTable->getOptions();
$user = $this->getUser($this->getIdentity());
foreach (array_keys($op) as $id) {
if (!$this->getDi()->resourceAccessTable->userHasAccess($user, $id, HelpdeskCategory::ACCESS_TYPE)) {
unset($op[$id]);
}
}
return $op;
}
public function createNewTicketForm()
{
$form = parent::createNewTicketForm();
if ($this->getDi()->helpdeskFaqTable->countBy()) {
$id = $form->getId();
$s_url = json_encode($this->getDi()->url('helpdesk/faq/suggest',null,false));
$form->addScript()->setScript(<<');
}
jQuery("#am-helpdesk-faq-q-result").empty();
return;
}
jQuery.get($s_url, {q:jQuery(this).val()}, function(html){
jQuery("#am-helpdesk-faq-q-result").empty().append(html);
})
return false;
});
CUT
);
}
return $form;
}
public function addUpload($form)
{
if (!$this->getDi()->modules->get('helpdesk')->getConfig('does_not_allow_attachments')) {
$t = Am_Html::escape(___('Add Attachments'));
$form->addHtml()->setHtml(<<$t
CUT
);
$form->addUpload('attachments', array('multiple' => 1), array('prefix' => Bootstrap_Helpdesk::ATTACHMENT_UPLOAD_PREFIX, 'secure' => true))
->setLabel(___('Attachments'))
->setJsOptions(<<assembleUrl(array(
'ticket' => $ticket->ticket_mask
), 'helpdesk-ticket');
}
public function newUrl()
{
return $this->assembleUrl(array(), 'helpdesk-new');
}
protected function getControllerName()
{
return 'index';
}
}PK 9\vxZ Z ) library/Am/Helpdesk/Strategy/Abstract.phpnu [ _di = $di;
}
/**
* @return Am_Di
*/
protected function getDi()
{
return $this->_di;
}
function onAfterInsertTicket($ticket)
{
}
public function assembleUrl($params, $route = 'default')
{
$router = $this->getDi()->router;;
return $router->assemble(array(
'module' => 'helpdesk',
'controller' => $this->getControllerName(),
) + $params, $route, true);
}
abstract public function ticketUrl($ticket);
abstract public function newUrl();
/**
* @return Am_Helpdesk_Strategy_Abstract
*/
public static function create(Am_Di $di)
{
return defined('AM_ADMIN') ?
($di->request->getControllerName() == 'admin-user' ?
new Am_Helpdesk_Strategy_Admin_User($di) :
new Am_Helpdesk_Strategy_Admin($di) ) :
new Am_Helpdesk_Strategy_User($di);
}
function getCategoryOptions()
{
return $this->getDi()->helpdeskCategoryTable->getOptions();
}
/**
* @return Am_Form
*/
public function createNewTicketForm()
{
$form = $this->createForm();
if ($options = $this->getCategoryOptions()) {
$form->addAdvradio('category_id')
->setLabel(___('Category of question'))
->loadOptions($options)
->addRule('required');
$fields = $this->getDi()->helpdeskTicketTable->customFields()->getAll();
foreach ($this->getDi()->helpdeskCategoryTable->findByIsDisabled(0) as $c) {
foreach (Am_Record::unserializeList($c->fields) as $fn) {
if (isset($fields[$fn])) {
$fields[$fn]->name = sprintf('category[%d][%s]',
$c->pk(), $_ = $fields[$fn]->name);
$fields[$fn]->addToQF2($form, array(), array(), HTML_QuickForm2_Rule::ONBLUR_CLIENT);
$fields[$fn]->name = $_;
}
}
}
$form->addScript()
->setScript(<<getDi()->helpdeskTicketTable->customFields()->getAll()) {
foreach ($fields as $field) {
$field->name = sprintf('additional[%s]', $_ = $field->name);
$field->addToQF2($form, array(), array(), HTML_QuickForm2_Rule::ONBLUR_CLIENT);
$field->name = $_;
}
}
$subject = $form->addText('subject', array('class' => 'row-wide el-wide'))
->setLabel(___('Subject'));
$subject->addRule('required');
$subject->addRule('maxlength', ___('Your subject is too verbose'), 255);
$subject->addRule('nonempty', ___('Subject can not be empty'));
$content = $form->addTextarea('content', array('class' => 'row-wide el-wide', 'rows' => 12))
->setLabel(___('Message'));
$content->addRule('required');
$content->addRule('nonempty', ___('Message can not be empty'));
$this->addUpload($form);
return $form;
}
function isShowAvatar()
{
return $this->getDi()->modules->get('helpdesk')->getConfig('show_gravatar') ||
($this->getDi()->plugins_misc->isEnabled('avatar') &&
$this->getDi()->modules->get('helpdesk')->getConfig('show_avatar'));
}
public function getAvatar($message)
{
if ($this->getDi()->plugins_misc->isEnabled('avatar') &&
$this->getDi()->modules->get('helpdesk')->getConfig('show_avatar')) {
if ($message->admin_id) {
return $this->getAdminAvatar($message);
} else {
return $this->getUserAvatar($message);
}
} elseif ($this->getDi()->modules->get('helpdesk')->getConfig('show_gravatar')) {
if ($message->admin_id) {
return $this->getAdminGravatar($message);
} else {
return $this->getUserGravatar($message);
}
} else {
return '';
}
}
public function getAdminGravatar($message)
{
$admin = $this->getAdmin($message->admin_id);
return $admin ?
sprintf('
',
'//www.gravatar.com/avatar/' . md5(strtolower(trim($admin->email))) . '?s=40&d=mm') :
'';
}
public function getUserGravatar($message)
{
$user = $this->getUser($message->getTicket()->user_id);
return $user ?
sprintf('
',
'//www.gravatar.com/avatar/' . md5(strtolower(trim($user->email))) . '?s=40&d=mm') :
'';
}
public function getAdminAvatar($message)
{
$admin = $this->getAdmin($message->admin_id);
return $admin ?
sprintf('
',
$this->getDi()->url('misc/avatar/' . $admin->avatar)) :
'';
}
public function getUserAvatar($message)
{
$user = $this->getUser($message->getTicket()->user_id);
return $user ?
sprintf('
',
$this->getDi()->url('misc/avatar/' . $user->avatar)) :
'';
}
public function getName($message)
{
return $message->admin_id ?
$this->getAdminName($message) :
$this->getUserName($message);
}
public function getUserName($message)
{
$user = $this->getUser($message->getTicket()->user_id);
$name = trim("{$user->name_f} {$user->name_l}");
return sprintf('%s%s',
$user->login,
$name ? sprintf(' (%s)', $name) : ''
);
}
protected function getAdmin($admin_id)
{
return $this->getDi()->adminTable->load($admin_id, false);
}
protected function getUser($user_id)
{
return $this->getDi()->userTable->load($user_id);
}
}PK 9\| &