Beispiel #1
0
 /**
  * render listview and show
  * @param string $location base of controller class name
  */
 public function Render($location = '')
 {
     $date_format = 'Y/m/d H:i';
     // pre hook
     _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $location, $date_format);
     $date = TDate::GetInstance();
     $result = null;
     // show saerch or item
     if ($this->search != null || $this->relation != array()) {
         $result .= '<div class="listview-search row" action="' . UR_MP . $location . '" >';
         // show search here
         if ($this->search != null) {
             //            die($prefix);
             $result .= '<form class="grd12"  action="' . UR_MP . $location . '">';
             $result .= '<input type="text" name="search" class="search-box" placeholder="' . _lg('Search') . '..." />';
             $result .= '<input type="hidden" name="fields" class="search-fields" value="' . $this->search . '"  />';
             if (isset($_GET['filter'])) {
                 $result .= '<input type="hidden" name="filter" value="' . $_GET['filter'] . '"  />';
             }
             $result .= '&nbsp;<button><span class="fa fa-search"></span></button>';
             if (isset($_GET['search']) && $_GET['search'] != '') {
                 $result .= '&nbsp;<button onclick="$(this).parent().find(\'.search,.search-fields\').remove();"><span class="fa fa-close"></span></button>';
             }
             $result .= '</form>';
         }
         // relation info
         if ($this->relation != array()) {
             $md = new TModel($this->relation['table']);
             $result .= '<form class="grd12 "  action="' . UR_MP . $location . '">' . ($this->relation['ico'] != '' ? '<span class="fa fa-' . $this->relation['ico'] . '"></span>' : '') . '<select name="rel" class="rel">';
             $result .= '<option value="0" >' . _lg('Select an item to search') . '</option>';
             foreach ($md->Selectable($this->relation['title'], $this->relation['value']) as $item) {
                 $result .= '<option value="' . $item[0] . '" ' . (isset($_GET['rel']) && $_GET['rel'] == $item[0] ? 'selected="selected"' : '') . ' >' . $item[1] . '</option>';
             }
             $result .= '</select>';
             $result .= '<input type="hidden" name="typ" class="rel-type" value="' . $this->relation['rel_type'] . '" />';
             $result .= '&nbsp;<button><span class="fa fa-search"></span></button>';
             if (isset($_GET['rel']) && $_GET['rel'] != '') {
                 $result .= '&nbsp;<button onclick="$(this).parent().find(\'.rel,.rel-type\').remove();"><span class="fa fa-close"></span></button>';
             }
             $result .= '</form>';
         }
         $result .= '</div>';
     }
     // show all filter here
     if ($this->filter['title'] != array()) {
         $result .= '<div class="filter">';
         // get prefix
         $prefix = GetLinkPrefix('filter');
         // show title and no filter item named "All";
         $result .= '<span> ' . _lg('Filter') . ': </span> <a class="button" href="' . $prefix . '"> ' . _lg('All') . '</a>';
         // show filter lisr
         foreach ($this->filter['title'] as $key => $value) {
             $result .= '<a class="button" href="' . $prefix . 'filter=' . $this->filter['key'][$key] . ',' . $this->filter['value'][$key] . '">' . $value . '</a>';
         }
         $result .= '</div>';
     }
     // get order by column
     $prefix = GetLinkPrefix('order,desc');
     // get id order and choose good value for this
     if (isset($_GET['order']) && $_GET['order'] == $this->id) {
         $id_order = $prefix;
     } else {
         $id_order = $prefix . 'order=' . $this->id;
     }
     // show form head here when have bulk action
     if ($this->bulk_action['title'] != array()) {
         $result .= '<form method="post" action="' . UR_MP . $location . '/BulkAction">';
     }
     //start render listview header
     // start with bulk action checkbox and id header
     $result .= '<ul class="listview">
 <li class="pinned animate"> 
     <div  class="row">
         <div class="grd1"> <input type="checkbox" class="checkall" />  </div>
         <a href="' . $id_order . '"><div class="grd2 header"> ' . _lg('no.') . ' </div></a>';
     // show header column title
     foreach ($this->column['title'] as $key => $value) {
         if (substr($this->column['key'][$key], 0, 1) == '%') {
             $col_name = substr($this->column['key'][$key], 2);
         } else {
             $col_name = $this->column['key'][$key];
         }
         $result .= '<a href="' . $prefix . 'order=' . $col_name . (!isset($_GET['desc']) && isset($_GET['order']) && $_GET['order'] == $col_name ? '&desc=1' : '') . '"><div class="grd' . $this->column['size'][$key] . '">' . $value . '</div></a>';
     }
     // action haader
     $result .= '<div class="grd' . $this->action['size'] . '"> &nbsp; </div>';
     $result .= '</div>
 </li>';
     // show all records in this page
     foreach ($this->assoc_list as $record) {
         //start with bulk action checkbox and id
         $result .= '<li> 
     <div  class="row">';
         $result .= '<div class="grd1">' . PHP_EOL . ' <input type="checkbox" ' . 'class="listview-checkbox" name="id[]" value="' . $record[$this->id] . '" />' . PHP_EOL . ' </div>' . PHP_EOL;
         $result .= '<div class="grd2"> ' . $record[$this->id] . ' </div>';
         // show record columns added before by size
         foreach ($this->column['key'] as $key => $value) {
             if (strpos($value, ',') == false) {
                 $result .= PHP_EOL . '<div class="grd' . $this->column['size'][$key] . '">' . PHP_EOL;
                 switch (substr($value, 0, 2)) {
                     case '%i':
                         $a = substr($value, 2);
                         $result .= long2ip($record[$a]);
                         break;
                     case '%t':
                         $a = substr($value, 2);
                         $result .= $date->PDate($date_format, $record[$a]);
                         break;
                         // show array
                     // show array
                     case '%a':
                         $a = substr($value, 2);
                         $v = explode('|', $a);
                         $arr = $v[0];
                         global ${$arr};
                         $array = ${$arr};
                         $result .= $array[$record[$v[1]]];
                         break;
                     case '%1':
                     case '%2':
                     case '%3':
                     case '%4':
                     case '%5':
                     case '%6':
                     case '%7':
                     case '%8':
                     case '%9':
                         $p = substr($value, 1, 1);
                         $a = substr($value, 2);
                         $result .= sprintf($this->pattren[$p], $record[$a]);
                         break;
                     default:
                         $result .= $record[$value];
                         break;
                 }
                 $result .= '</div>' . PHP_EOL;
             } else {
                 $temp = explode(',', $value);
                 $result .= PHP_EOL . '<div class="grd' . $this->column['size'][$key] . '">';
                 foreach ($temp as $col) {
                     $result .= $record[$col] . PHP_EOL;
                 }
                 $result .= '</div>' . PHP_EOL;
             }
         }
         // add action to record
         $result .= PHP_EOL . '<div class="grd' . $this->action['size'] . ' c' . ($this->action['class'] == '' ? '' : $record[$this->action['class']]) . '">';
         $tmp = str_replace("%id%", $record[$this->id], $this->action['pattern']);
         if ($this->id == 'comment_id') {
             $result .= str_replace("%topic%", $record['comment_topic_id'], $tmp);
         } else {
             $result .= $tmp;
         }
         $result .= '</div>' . PHP_EOL;
         $result .= '</div>' . PHP_EOL . '</li>' . PHP_EOL;
     }
     $result .= '</ul>' . PHP_EOL;
     // if have bulk action show this after list view
     if ($this->bulk_action['title'] != array()) {
         $result .= '<div class="bulk-action">
                 <select name="action">';
         // list of bulk actions
         foreach ($this->bulk_action['function'] as $key => $value) {
             $result .= '<option  value="' . $value . ',' . $this->bulk_action['value'][$key] . '">' . $this->bulk_action['title'][$key] . '</option>';
         }
         $result .= '</select>';
         $result .= '<input type="submit" value="' . _lg('Bulk apply') . '" />' . '<div class="left" > ' . '<input type="button" value="' . _lg('Check All') . '" class="chkall" data-chekbox="listview-checkbox" /> ' . '<input type="button" value="' . _lg('Check None') . '" class="chknone" data-chekbox="listview-checkbox" /> ' . '<input type="button" value="' . _lg('Check Toggle') . '" class="chktoggle" data-chekbox="listview-checkbox" /> ' . '</div>' . '</div>' . '</form>';
     }
     // result hook
     _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result);
     echo $result;
 }