コード例 #1
0
ファイル: umemberslist.php プロジェクト: Sajaki/wowroster
 /**
  * Prepare the data to build a memberlist.
  *
  * @param string $query
  *	The main SQL query for this list
  * @param array $where
  *  Default WHERE clauses. These are ANDed together
  * @param array $group
  *  GROUP BY columns. Should be the ID column of the listed scope (member_id on the default memberslist)
  * @param array order_first
  *  Initial order clauses, before any order clauses supplied by the UI
  * @param array order_last
  *  Trailing order clauses, after any order clauses supplied by the UI
  * @param array $fields
  *	Array with field data. See documentation.
  * @param string $listname
  *	The ID used by javascript to identify this memberstable.
  */
 function prepareData($query, $where, $group, $order_first, $order_last, $fields, $listname)
 {
     global $roster, $addon;
     $this->pageanat = $this->addon['config']['page_size'] > '0' ? true : false;
     // Save some info
     $this->listname = $listname;
     $this->fields = $fields;
     unset($fields);
     $cols = count($this->fields);
     // Pre-store server get params
     $get = (isset($_GET['s']) ? '&s=' . $_GET['s'] : '') . (isset($_GET['st']) ? '&st=' . $_GET['st'] : '');
     $get .= "&filter=" . ($this->addon['config']['openfilter'] ? "open" : "close");
     $get_s = isset($_GET['s']) ? $_GET['s'] : '';
     $get_st = isset($_GET['st']) ? $_GET['st'] : 0;
     $ert = $get;
     // Extract filters form $_GET
     $get_filter = array();
     $search_filter = array();
     foreach ($this->fields as $name => $data) {
         if (isset($_GET['filter_' . $name]) && !empty($_GET['filter_' . $name])) {
             $get_filter[$name] = $_GET['filter_' . $name];
             $search_filter[] = '( LOWER(' . $data['filt_field'] . ') LIKE LOWER( \'%' . $_GET['filter_' . $name] . '%\') )';
             $get .= '&filter_' . $name . '=' . htmlentities($get_filter[$name]);
         }
     }
     $filter_post = $get . (isset($_GET['alts']) ? '&alts=' . $_GET['alts'] : '');
     $roster->tpl->assign_vars(array('U_UNGROUP_ALTS' => makelink('&alts=ungroup' . $get), 'U_OPEN_ALTS' => makelink('&alts=open' . $get), 'U_CLOSE_ALTS' => makelink('&alts=close' . $get), 'U_FILTER_FORM' => makelink() . $filter_post, 'UR_FILTER_FORM' => 'guild-memberslist', 'U_CLOSE_FILTER' => makelink('guild-memberslist&filter=close' . $filter_post), 'U_OPEN_FILTER' => makelink('guild-memberslist&filter=open' . $filter_post), 'S_FILTER' => $this->addon['config']['openfilter'], 'S_GROUP_ALTS' => $this->addon['config']['group_alts'], 'B_PAGINATION' => $this->pageanat, 'COLS' => $cols + 1, 'LISTNAME' => $this->listname, 'ML_IMAGE_URL' => $this->addon['tpl_image_url']));
     // --[ Add filter SQL ]--
     /*
     foreach( $get_filter as $field => $filter )
     {
     	$data = $this->fields[$field];
     
     	if( isset( $data['filt_field'] ) )
     	{
     		$field = $data['filt_field'];
     	}
     
     	if( isset( $data['filter'] ) )
     	{
     		if( $data['filter'] !== false )
     		{
     			$where_clause = call_user_func($data['filter'], $field, $filter, (isset($DATA['passthrough']) ? $DATA['passthrough'] : array() ) );
     		}
     	}
     	else
     	{
     		$where_clause = $this->default_filter( $field, $filter );
     	}
     
     	if( !empty( $where_clause ) )
     	{
     		$where[] = $where_clause;
     	}
     }
     */
     if (!empty($where)) {
         $r = '';
         if (!empty($search_filter)) {
             $r = ' AND ' . implode(' AND ', $search_filter);
         }
         $query .= ' WHERE (' . implode(') AND (', $where) . ')' . $r;
         //$query .= ' WHERE ;
     }
     // --[ Add grouping SQL ]--
     if (!empty($group)) {
         $query .= ' GROUP BY ' . implode(',', $group);
     }
     // --[ Get number of rows ]--
     $num_rows = null;
     if ($this->addon['config']['page_size'] > 0) {
         // --[ Fetch number of rows. Trim down the query a bit for speed. ]--
         $rowsqry = 'SELECT * ' . substr($query, strpos($query, 'FROM'));
         $result = $roster->db->query($rowsqry);
         $data = $roster->db->fetch($result);
         $num_rows = $roster->db->num_rows($result);
         /*
         if ($num_rows > 1)
         {
         	$num_rows = $nn = 0;
         	while( $data = $roster->db->fetch($result, SQL_NUM) )
         	{
         		$nn++;
         	}
         	$num_rows = $nn;
         }
         */
     }
     // --[ Add sorting SQL ]--
     $order = $order_first;
     if (empty($get_s) && !empty($this->addon['config']['def_sort'])) {
         $get_s = $this->addon['config']['def_sort'];
     }
     foreach (explode(',', $get_s) as $sort) {
         if (empty($sort)) {
             continue;
         }
         if (strpos($sort, ':')) {
             list($field, $dir) = explode(':', $sort);
         } else {
             $field = $sort;
             $dir = 'a';
         }
         $ORDER_FIELD = $this->fields[$field];
         if ($dir == 'd' && isset($ORDER_FIELD['order_d'])) {
             foreach ($ORDER_FIELD['order_d'] as $order_field_sql) {
                 $order[] = $order_field_sql;
             }
         } elseif (isset($ORDER_FIELD['order'])) {
             foreach ($ORDER_FIELD['order'] as $order_field_sql) {
                 $order[] = $order_field_sql;
             }
         }
     }
     foreach ($order_last as $order_sql) {
         $order[] = $order_sql;
     }
     if (!empty($order)) {
         $query .= ' ORDER BY ' . implode(',', $order);
     }
     // --[ Add pagination SQL ]--
     if ($this->pageanat) {
         $query .= ' LIMIT ' . $get_st . ',' . $this->addon['config']['page_size'];
     }
     // --[ Query done, add to class vars ]--
     $this->query = $query;
     $num_pages = ceil($num_rows / $this->addon['config']['page_size']);
     // --[ Page list ]--
     if ($this->pageanat && $num_pages > 1) {
         $params = $get . '&alts=' . ($this->addon['config']['group_alts'] == 2 ? 'open' : ($this->addon['config']['group_alts'] == 1 ? 'close' : 'ungroup'));
         //paginate($params . '&st=', $num_rows, $this->addon['config']['page_size'], $get_st);
         paginate2($params . '&st=', $num_rows, $this->addon['config']['page_size'], $get_st, true, count($this->fields));
     } else {
         $roster->tpl->assign_vars(array('B_PAGINATION' => false));
     }
     // header row
     $current_col = 1;
     foreach ($this->fields as $field => $DATA) {
         // If this is a force invisible field, don't do anything with it.
         if ($DATA['display'] == 0 || $DATA['display'] == 1) {
             unset($this->fields[$field]);
             continue;
         }
         // See if there is a lang value for the header
         if (!empty($roster->locale->act[$DATA['lang_field']])) {
             $th_text = $roster->locale->act[$DATA['lang_field']];
         } else {
             $th_text = $DATA['lang_field'];
         }
         // click a sorted field again to reverse sort it
         // Don't add it if it is detected already
         if (!empty($get_s)) {
             $sorts = explode(',', $get_s);
         } else {
             $sorts = array();
         }
         if (false !== ($key = array_search($field, $sorts)) || false !== ($key = array_search($field . ':a', $sorts))) {
             unset($sorts[$key]);
             array_unshift($sorts, $field . ':d');
         } else {
             $key = array_search($field . ':d', $sorts);
             if ($key !== false) {
                 unset($sorts[$key]);
             }
             array_unshift($sorts, $field . ':a');
         }
         $newsort = implode(',', $sorts);
         $get = '&alts=' . ($this->addon['config']['group_alts'] == 2 ? 'open' : ($this->addon['config']['group_alts'] == 1 ? 'close' : 'ungroup')) . '&filter=' . ($this->addon['config']['openfilter'] ? 'open' : 'close') . '&s=' . $newsort;
         foreach ($get_filter as $key => $filter) {
             $get .= '&filter_' . $key . '=' . htmlentities($filter);
         }
         $roster->tpl->assign_block_vars('header_cell', array('LINK' => makelink($get), 'TEXT' => $th_text, 'ID' => false, 'B_FILTER' => !isset($DATA['filter']) || $DATA['filter'] !== false, 'FILTER' => isset($get_filter[$field]) ? htmlentities($get_filter[$field]) : '', 'NAME' => $field));
         $current_col++;
     }
     // end header row
     $output = '<div id="sortfilterCol" style="display:' . ($this->addon['config']['openfilter'] ? 'none' : 'inline') . ';">' . "\n" . border('sblue', 'start', "<div style=\"cursor:pointer;width:440px;\" onclick=\"swapShow('sortfilterCol','sortfilter')\"><img src=\"" . $roster->config['img_url'] . "plus.gif\" style=\"float:right;\" alt=\"+\"/>" . $roster->locale->act['memberssortfilter'] . "</div>") . "\n" . border('sblue', 'end') . "\n" . '</div>' . "\n" . '<div id="sortfilter" style="display:' . ($this->addon['config']['openfilter'] ? 'inline' : 'none') . ';">' . "\n" . border('sblue', 'start', "<div style=\"cursor:pointer;width:440px;\" onclick=\"swapShow('sortfilterCol','sortfilter')\"><img src=\"" . $roster->config['img_url'] . "minus.gif\" style=\"float:right;\" alt=\"-\"/>" . $roster->locale->act['memberssortfilter'] . "</div>") . "\n" . '<table><tr>' . "\n" . '<td class="membersHeader">' . $roster->locale->act['memberssort'] . '</td>' . "\n" . '<td class="membersHeader">' . $roster->locale->act['memberscolshow'] . '</td>' . "\n" . '<td class="membersHeader">' . $roster->locale->act['membersfilter'] . '</td>' . "\n" . '</tr>' . "\n" . '<tr><td rowspan="' . $cols . '">' . "\n";
     for ($i = 0; $i < 4; $i++) {
         $output .= '<select id="' . $this->listname . '_sort_' . $i . '" name="' . $this->listname . '_sort_' . $i . '">' . "\n" . $this->sortoptions . '</select><br />';
     }
     $output .= '<button onclick="dosort(6,\'' . $this->listname . '\'); return false;">Go</button>' . "\n" . '<input type="hidden" id="' . $this->listname . '_sort_4" name="' . $this->listname . '_sort_4" value="3_desc" />' . "\n" . '<input type="hidden" id="' . $this->listname . '_sort_5" name="' . $this->listname . '_sort_5" value="1_asc" />' . "\n" . '</td>' . "\n" . $this->sortFields . '</table>' . "\n" . border('sblue', 'end') . '</div>' . "\n";
     return $output;
 }
コード例 #2
0
ファイル: index.php プロジェクト: Sajaki/wowroster_dev
$member_id = $roster->data['member_id'];
$member_name = $roster->data['name'];
$member_realm = $roster->data['server'];
$member_str = $member_name . '@' . $roster->data['region'] . '-' . $member_realm;
$pageanat = $addon['config']['page_size'] > '0' ? true : false;
$get_s = isset($_GET['s']) ? $_GET['s'] : '';
$get_st = isset($_GET['st']) ? $_GET['st'] : 0;
$queryx = "SELECT * FROM `" . $roster->db->table('char_feed', $addon['basename']) . "` WHERE `member_id`='" . $member_id . "' ORDER BY `timestamp` DESC";
if ($pageanat) {
    $queryx .= ' LIMIT ' . $get_st . ',' . $addon['config']['page_size'];
}
$resultx = $roster->db->query($queryx);
if ($pageanat) {
    $q1 = "SELECT * FROM `" . $roster->db->table('char_feed', $addon['basename']) . "` WHERE `member_id`='" . $member_id . "'";
    $r1 = $roster->db->query($q1);
    $num_rows = $roster->db->num_rows($r1);
    $num_pages = ceil($num_rows / $addon['config']['page_size']);
}
// --[ Page list ]--
if ($pageanat && $num_pages > 1) {
    $params = '';
    paginate2($params . '&amp;st=', $num_rows, $addon['config']['page_size'], $get_st, true, null);
}
$rowg = $roster->db->fetch($resultx);
roster_add_css($addon['dir'] . 'style.css', 'module');
$roster->tpl->assign_vars(array('MBR_STR' => $member_str, 'B_PAGINATION' => $pageanat));
while ($info = $roster->db->fetch($resultx)) {
    $roster->tpl->assign_block_vars('feed', array('STR' => $feeds->{$info}['type']($info)));
}
$roster->tpl->set_filenames(array('feeds' => $addon['basename'] . '/feeds.html'));
$roster->tpl->display('feeds');