Esempio n. 1
0
function _rowset_style($sql, $style, $prefix = '')
{
    $a = sql_rowset($sql);
    _rowset_foreach($a, $style, $prefix);
    return $a;
}
Esempio n. 2
0
    protected function _view_home()
    {
        global $core, $user;
        $v = $this->__(array('code', 'a' => 0, 'print' => 0, 'offset' => 0));
        if (f($v['code'])) {
            $sql = 'SELECT ticket_id
				FROM _tickets
				WHERE ticket_code = ?';
            $v['a'] = _field(sql_filter($sql, $v['code']), 'ticket_id');
        }
        $d = $this->init_ticket($v['a']);
        $d['ticket_owner'] = $d['ticket_contact'] == $user->v('user_id') ? true : false;
        $d['ticket_access'] = false;
        if ($user->v('is_founder') || $d['ticket_owner']) {
            $d['ticket_access'] = true;
        } else {
            $sql = 'SELECT g.group_id
				FROM _groups g, _groups_members m
				WHERE g.group_id = m.member_group
					AND m.member_uid = ?';
            if ($s_group_id = _rowset(sql_filter($sql, $user->v('user_id')), false, 'group_id')) {
                $sql = 'SELECT *
					FROM _groups g, _groups_members m, _tickets t
					WHERE t.ticket_id = ?
						AND g.group_id = m.member_group
						AND g.group_id = t.ticket_group
						AND t.ticket_group IN (??)';
                if (_fieldrow(sql_filter($sql, $d['ticket_id'], _implode(',', $s_group_id)))) {
                    $d['ticket_access'] = true;
                }
            }
        }
        if (!$d['ticket_access']) {
            $sql = 'SELECT *
				FROM _tickets t, _tickets_assign a
				WHERE t.ticket_id = ?
					AND t.ticket_id = a.assign_ticket
					AND a.user_id = ?';
            if (_fieldrow(sql_filter($sql, $d['ticket_id'], $user->v('user_id')))) {
                $d['ticket_access'] = true;
            }
        }
        if (!$d['ticket_access']) {
            _fatal();
        }
        $d['ticket_control'] = !$d['ticket_owner'] || $user->v('is_founder') ? true : false;
        $this->navigation('TICKET_VIEW', array('x1' => 'view', 'a' => $v['a'], 'offset' => $v['offset']));
        //
        $sql = 'SELECT cat_name
			FROM _tickets_cat
			WHERE cat_id = ?';
        $cat_name = _field(sql_filter($sql, $d['ticket_cat']), 'cat_name');
        $sql = 'SELECT user_firstname, user_lastname, user_username
			FROM _members
			WHERE user_id = ?';
        $ticket_author = _fieldrow(sql_filter($sql, $d['ticket_contact']));
        //
        $status_list = $this->init_status_list();
        $sql_show_public = $d['ticket_owner'] || $d['ticket_owner'] && $user->v('is_founder') ? true : false;
        //
        $sql = 'SELECT a.assign_id, a.assign_status, a.assign_end, m.user_id, m.user_username, m.user_firstname, m.user_lastname
			FROM _members m, _tickets_assign a
			WHERE m.user_id = a.user_id
				AND a.assign_ticket = ?
			ORDER BY m.user_firstname, m.user_lastname';
        $ticket_assign = _rowset(sql_filter($sql, $v['a']));
        foreach ($ticket_assign as $i => $row) {
            if (!$i) {
                _style('assigned');
            }
            if (!isset($status_list[$row['assign_status']])) {
                $row['assign_status'] = $d['ticket_status'];
            }
            _style('assigned.row', array('V_AID' => $row['assign_id'], 'V_ALIAS' => $row['user_username'], 'V_UID' => $row['user_id'], 'V_FULLNAME' => _fullname($row), 'U_PROFILE' => _link('contacts', array('m' => $row['user_username'])), 'V_STATUS' => $status_list[$row['assign_status']]['status_alias'], 'V_END' => $row['assign_end'] ? _format_date($row['assign_end']) : ''));
        }
        $sql = 'SELECT *
			FROM _groups
			ORDER BY group_name';
        $groups = _rowset($sql, 'group_id', 'group_name');
        _rowset_foreach(string_to_array_assoc($groups, w('group_id group_name')), 'groups');
        //
        if (!($category = $core->cache_load('tickets_cat'))) {
            $sql = 'SELECT *
				FROM _tickets_cat
				ORDER BY cat_name';
            $category = $core->cache_store(_rowset($sql));
        }
        $ticket_groups = explode(',', $user->auth_groups());
        foreach ($category as $i2 => $catrow) {
            if (!$catrow['cat_group'] || in_array($catrow['cat_group'], $ticket_groups)) {
                continue;
            }
            unset($category[$i2]);
        }
        _rowset_foreach($category, 'category');
        // Ticket notes
        $sql = 'SELECT n.*, m.user_id, m.user_username, m.user_firstname, m.user_lastname
			FROM _tickets_notes n, _members m
			WHERE n.ticket_id = ?
				??
				AND n.user_id = m.user_id
			ORDER BY n.note_time';
        $notes = _rowset(sql_filter($sql, $d['ticket_id'], $sql_show_public ? 'AND n.note_cc = 1 ' : ''));
        foreach ($notes as $i => $row) {
            if (!$i) {
                _style('notes');
            }
            $access = $row['note_cc'] ? 'public' : 'private';
            _style('notes.row', array('U_NOTE_EDIT' => _link($this->m(), array('x1' => 'note', 'x2' => 'modify', 'note' => $row['note_id'])), 'U_NOTE_REMOVE' => _link($this->m(), array('x1' => 'note', 'x2' => 'remove', 'note' => $row['note_id'])), 'V_NOTE_ID' => $row['note_id'], 'V_USERNAME' => _fullname($row), 'V_USERLINK' => _link('contacts', array('m' => $row['user_username'])), 'V_TIME' => _format_date($row['note_time']), 'V_TEXT' => _message($row['note_text']), 'V_ACCESS' => _lang($access), 'V_ACCESS_CLASS' => $row['note_cc'] ? 'green' : 'red'));
        }
        $sql = 'SELECT attach_id, attach_name, attach_extension, attach_size, attach_time
			FROM _tickets_attach
			WHERE attach_ticket = ?
			ORDER BY attach_name';
        $attachments = _rowset(sql_filter($sql, $d['ticket_id']));
        foreach ($attachments as $i => $row) {
            if (!$i) {
                _style('attachments');
            }
            switch ($row['attach_extension']) {
                case 'jpeg':
                case 'jpg':
                case 'gif':
                case 'png':
                    _style('attachments.image', array('ATTACH_LINK' => _link('space/f/' . $row['attach_name'], false, false), 'ATTACH_NAME' => $row['attach_name'], 'ATTACH_SIZE' => _filesize($row['attach_size'])));
                    break;
                default:
                    _style('attachments.normal', array('ATTACH_LINK' => _link('space/f/' . $row['attach_name'], false, false), 'ATTACH_NAME' => $row['attach_name'], 'ATTACH_SIZE' => _filesize($row['attach_size'])));
                    break;
            }
        }
        $author_fullname = _fullname($ticket_author);
        $sql = 'SELECT assign_status
			FROM _tickets_assign
			WHERE assign_ticket = ?
				AND user_id = ?';
        if ($assign_status = _field(sql_filter($sql, $d['ticket_id'], $user->v('user_id')), 'assign_status', 0)) {
            $d['ticket_status'] = $assign_status;
        }
        v_style(array('U_STATUS' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'status', 'ticket' => $v['a'])), 'U_GROUP' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'groups', 'a' => $v['a'])), 'U_ADD_NOTE' => _link($this->m(), array('x1' => 'note', 'x2' => 'create', 'ticket' => $v['a'])), 'U_CATEGORY' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'cat', 'ticket' => $v['a'])), 'U_TECH_ADD' => _link($this->m(), array('x1' => 'tech', 'x2' => 'add', 'ticket' => $v['a'])), 'U_TECH_QUERY' => _link($this->m(), array('x1' => 'tech', 'x2' => 'query', 'ticket' => $v['a'])), 'U_TECH_REMOVE' => _link($this->m(), array('x1' => 'tech', 'x2' => 'remove', 'ticket' => $v['a'])), 'U_REMOVE' => _link($this->m(), array('x1' => 'ticket', 'x2' => 'remove', 'ticket' => $v['a'])), 'U_PRINT' => _link($this->m(), array('x1' => 'view', 'a' => $v['a'], 'print' => 1)), 'V_ID' => $v['a'], 'V_DELETED' => $d['ticket_deleted'], 'V_STATUS' => $this->init_status($d['ticket_status']), 'V_STATUS_ID' => $d['ticket_status'], 'V_STATUS_NAME' => $status_list[$d['ticket_status']]['status_name'], 'V_GROUP_NAME' => $groups[$d['ticket_group']], 'V_CATEGORY' => $cat_name, 'V_TITLE' => $d['ticket_title'] != '' ? $d['ticket_title'] : _lang('TICKET_NO_SUBJECT'), 'V_TEXT' => _message($d['ticket_text']), 'V_START' => $d['ticket_start'] ? _format_date($d['ticket_start']) : '', 'V_END' => $d['ticket_end'] ? _format_date($d['ticket_end']) : '', 'V_IP' => $d['ticket_ip'], 'V_AUTHOR_NAME' => $author_fullname ? $author_fullname : _lang('USER_UNKNOWN'), 'V_AUTHOR_URL' => _link('contacts', array('m' => $ticket_author['user_username'])), 'V_SHOW_PUBLIC' => !$sql_show_public));
        $this->__home_common($v['offset']);
        if ($v['print']) {
            $this->_template('ticket.print');
        }
        return;
    }
Esempio n. 3
0
function _rowset_style($sql, $style, $prefix = '', $comp_orig = false, $comp_dest = false)
{
    $a = _rowset($sql);
    _rowset_foreach($a, $style, $prefix, $comp_orig, $comp_dest);
    return $a;
}