PageRenderTime 208ms CodeModel.GetById 80ms app.highlight 81ms RepoModel.GetById 40ms app.codeStats 0ms

/wp-content/plugins/aqgeChart/AqgeChartOptionForm.php

https://bitbucket.org/aqge/deptandashboard
PHP | 402 lines | 322 code | 66 blank | 14 comment | 24 complexity | d6a18f309700808c707a7b361e52b021 MD5 | raw file
  1<?php
  2require_once  'AqgeChartQuery.php';
  3/*
  4 * To change this template, choose Tools | Templates
  5 * and open the template in the editor.
  6 */
  7
  8/**
  9 * Description of AqgeChartOptionForm
 10 *
 11 * @author aqge
 12 */
 13class AqgeChartOptionForm {
 14    //put your code here
 15    
 16function updateLink($id){
 17    return get_admin_url(1, 'admin.php?page='. get_admin_page_parent().'&update='.$id  ) ;
 18}
 19
 20function saveLink(){
 21    return get_admin_url(1, 'admin.php?page='. get_admin_page_parent() ) ;
 22}
 23
 24function deleteLink(){
 25    return get_admin_url(1, 'admin.php?page='. get_admin_page_parent().'&delete=true'   ) ;
 26}
 27
 28function getAttributes(){
 29    $pageOption=array(
 30          0=>array(
 31              'title'=>'Pengaturan Widget Distribusi Pangan',
 32              'jenis'=>'widget',
 33          ),
 34          1=>array(
 35              'title'=>'Pengaturan Table distribusi Pangan',
 36              'jenis'=>'Table'
 37          ),
 38        'dateformat'=>array('full')
 39      );
 40    return $pageOption;
 41}
 42
 43function aqge_chart_form($view){
 44      $model = new AqgeChartQuery; 
 45      $pageOption = $this->getAttributes();
 46      
 47      if(isset($_POST['aqge-chart-submit'])) {   
 48                $name = $_POST['aqge-chart-name'];
 49                $desc = $_POST['aqge-chart-desc'];
 50                $title = $_POST['aqge-chart-title']; 
 51                $tipe = $_POST['aqge-chart-datatype']; //pibc harga
 52                $start = explode('/', $_POST['aqge-chart-start'] );
 53                $end = explode('/', $_POST['aqge-chart-end']);
 54                $group = $_POST['aqge-chart-group']; //harian mingguan
 55                $select = isset( $_POST['aqge-chart-data-select'])? $_POST['aqge-chart-data-select']:array(0);
 56                $select_group = isset( $_POST['aqge-chart-data-home'])? $_POST['aqge-chart-data-home']:0;
 57                $id = isset($_POST['aqge-chart-id'])?$_POST['aqge-chart-id']:0;
 58
 59                $data = implode(',', $select);
 60                $kelompok = explode('-', $tipe);
 61                $option = $model->getOption($kelompok[0]);
 62                $mulai = date('Y-m-d', strtotime($start[2].'-'.$start[1].'-'.$start[0]));
 63                $selesai = date('Y-m-d', strtotime($end[2].'-'.$end[1].'-'.$end[0]));
 64
 65
 66                $model->_criteria =  array(
 67                            'start'=>$mulai,
 68                            'end'=>$selesai, 
 69                            'option'=>$kelompok[1],
 70                            'home'=>$select_group,
 71                            'data'=>$data,
 72                            'group'=>$option['group'][$group] ,
 73                            'order'=>$option['order'][$group] ,
 74                    );
 75
 76                 //khusus untuk BPS
 77                if($tipe=='bps-1' || $tipe=='bps-2' ){
 78                    $model->_criteria['start']=$start[2];
 79                    $model->_criteria['end']=$end[2];
 80                }
 81                
 82                            
 83                
 84                 $sql = $model->getSQL($kelompok[0] );
 85                
 86                 //special sql 
 87                 //if($tipe=='pibc-5')
 88                 //    $sql = $model->getSQL('pibcC');
 89
 90                 $model->saveQuery($name, $desc, $sql, $tipe, $title,$view, $group, $data,$mulai, $selesai, $id, $select_group );
 91
 92
 93            }
 94
 95$updatemodel =  false;
 96if(isset($_GET['update'])){
 97    $updatemodel = $model->getQueryByPk($_GET['update']);   
 98}
 99
100
101?>
102
103        <div class="wrap">
104            <?php echo screen_icon(); ?>
105            <h2><?php echo $pageOption[$view]['title']; ?></h2>
106            <p>selamat datang dipengaturan <?php echo $pageOption[$view]['jenis']; ?> distribusi pangan</p>
107            
108            <form action="<?php echo $this->saveLink(); ?>" method="post" id="aqge-chart-widget" class="aqge-form">
109                <div class="aqge-chart-left">
110                <!--Nama Pengenal-->
111                    <h4><label for="nama widget" >Nama pengenal <?php echo $pageOption[$view]['jenis']; ?> : </label>
112                    <input type="text" id="aqge-chart-widget-name" value="<?php echo ($updatemodel)?$updatemodel['name']:null; ?>" name="aqge-chart-name"/></h4>
113                    
114               <!--Keterangan Singkat-->
115                    <h4><label for="Deskripsi widget">Ketarangan singkat <?php echo $pageOption[$view]['jenis']; ?> : </label>
116                    <textarea id="aqge-chart-widget-desc" name="aqge-chart-desc"><?php echo ($updatemodel)?$updatemodel['desc']:null; ?></textarea></h4>
117                
118               <!--Judul--> 
119                    <h4><label for="judul widget">Judul yang tampil pada <?php echo $pageOption[$view]['jenis']; ?> : </label>
120                    <input type="text" id="aqge-chart-widget-title" value="<?php echo ($updatemodel)?$updatemodel['title']:null; ?>" name="aqge-chart-title" />  </h4>   
121                
122               <!--Pohon Pilihan Data-->
123                    <h4><label for="jenis data">Jenis Data <i>(pilih satu)</i></label>
124                    <div class="aqge-chart-tree-node-container">
125                        <?php  $treemodel = $model->getOptionTree(); ?>
126                                
127                        <ul class="aqge-chart-tree-node">
128                            <?php foreach($treemodel as $ikey=>$item) : ?>
129                            <li>
130                               
131                                <a href="#data" class="j-aqge-chart-tree-items"> 
132                                    <span class="aqge-chart-tree-collapsed"></span>
133                                   <?php echo $item['desc']; ?>
134                                </a>         
135                                <ul  style="display:<?php
136                                    if(!$updatemodel){
137                                        echo ($item['desc']=='pibc')?'block':'none' ;
138                                    } else {
139                                         $g = explode('-', $updatemodel['tipe']);
140                                        echo ($g[0]==$ikey)?'block':'none' ;
141                                    }                                
142                                ?>" >
143                                    <?php foreach($item['items'] as $key=>$subitem) : ?>
144                                    <li>
145                                        <label>
146                                      <input type="radio" id="aqge-chart-widget-datatype<?php echo $ikey.'-'.$key ;?>" 
147                                             value="<?php echo $ikey.'-'.$key ;?>" 
148                                             name="aqge-chart-datatype" 
149                                             <?php if($updatemodel && $updatemodel['tipe']==$ikey.'-'.$key) : ?>
150                                             checked="checked"
151                                             <?php endif; ?>
152                                             class="aqge-chart-option-item j-aqge-chart-option-item" />                                     
153                                        <?php echo $subitem; ?>
154                                          
155                                        </label>
156                                        <div class="clear"></div>
157                                    </li>
158                                    <?php endforeach; ?>
159                                </ul>
160                            </li>
161                            <?php endforeach; ?>
162                        </ul>
163                    </div>
164                </h4>
165                    
166                
167               <!--Periode Tanggal/ bulan/ tahun-->
168                    <h4><label for="tanggal laporan">Periode Laporan</label>
169                        <h3>
170                            <?php 
171                               if(!$updatemodel){
172                                    $fmulai= date('d/m/Y', strtotime('-1 week')); 
173                                    $fend = date('d/m/Y'); 
174                                    $fmulaih= date('Y-m-d', strtotime('-1 week')); 
175                                    $fendh = date('Y-m-d'); 
176                               } else {
177                                   $fmulai= date('d/m/Y', strtotime( $updatemodel['start'])); 
178                                   $fend = date('d/m/Y', strtotime( $updatemodel['end'])); 
179                                   $fmulaih= date('Y-m-d', strtotime( $updatemodel['start'])); 
180                                   $fendh = date('Y-m-d', strtotime( $updatemodel['end'])); 
181                               }
182                                  
183                               for($i=date('Y'); $i>=1990; $i--)
184                                $tahun[$i]=$i;
185                               
186                                for($j=1; $j<=12; $j++)
187                                $bulan[$j]=date('F', strtotime("1990-$j-1"));
188                               ?>
189                         
190                        <input type="hidden" id="aqge-chart-widget-start-hidden" name="aqge-chart-start-hidden" 
191                               value="<?php  echo  $fmulaih ?>"/>  
192                        
193                         <span class="j-aqge-periode j-ap-pibc-1 j-ap-pibc-2 j-ap-pibc-3 j-ap-pibc-4 j-ap-pibc-5 
194                              j-ap-daerah-0 j-ap-kemdag-0 j-ap-keramatjati-1 j-ap-keramatjati-2"> 
195                        <input type="text" id="aqge-chart-widget-start" name="aqge-chart-start" 
196                               value="<?php  echo  $fmulai ?>"/>  
197                         </span> 
198                        <!--other format-->
199                         <span class="j-aqge-periode j-ap-bps-3 j-ap-bps-4 j-ap-bps-5  ">
200                            <!--bulan -->
201                                <select id="aqge-chart-widget-start-bulan" name="aqge-chart-start-bulan" >
202                                    <?php foreach($bulan as $key=>$item): ?>
203                                    <?php    $selectbulan = (date('m', strtotime($fmulaih))==$key) ?'selected=selected':null; ?>
204                                    <option value="<?php echo $key; ?>" <?php echo $selectbulan; ?> ><?php echo $item; ?></option>
205                                    <?php endforeach; ?>
206                                </select>
207                         </span>
208                        
209                         <span class="j-aqge-periode j-ap-bps-1 j-ap-bps-2 j-ap-bps-3 j-ap-bps-4 j-ap-bps-5  "> 
210                            <!--tahun saja-->
211                                <select id="aqge-chart-widget-start-tahun" name="aqge-chart-start-tahun" >
212                                    <?php foreach($tahun as $key=>$item): ?>
213                                    <?php    $selectahun = (date('Y', strtotime($fmulaih))==$key) ?'selected=selected':null; ?>
214                                    <option value="<?php echo $key; ?>" <?php echo $selectahun; ?> ><?php echo $item; ?></option>
215                                    <?php endforeach; ?>
216                                </select>
217                         </span>  
218                            
219                        s/d
220                        <input type="hidden" id="aqge-chart-widget-end-hidden" name="aqge-chart-end-hidden" 
221                               value="<?php  echo  $fendh ?>"/>
222                          
223                         <span class="j-aqge-periode j-ap-pibc-1 j-ap-pibc-2 j-ap-pibc-3 j-ap-pibc-4 j-ap-pibc-5 
224                              j-ap-daerah-0 j-ap-kemdag-0 j-ap-keramatjati-1 j-ap-keramatjati-2">
225                        <input type="text" id="aqge-chart-widget-end" name="aqge-chart-end" 
226                               value="<?php  echo  $fend ?>"/>  
227                         </span>
228                       
229                        <!--other format-->
230                        <span class="j-aqge-periode j-ap-bps-3 j-ap-bps-4 j-ap-bps-5  ">
231                            <!--bulan -->
232                                <select id="aqge-chart-widget-end-bulan" name="aqge-chart-end-bulan" >
233                                    <?php foreach($bulan as $key=>$item): ?>
234                                    <?php    $selectbulan = (date('m', strtotime($fendh))==$key) ?'selected=selected':null; ?>
235                                    <option value="<?php echo $key; ?>" <?php echo $selectbulan; ?> ><?php echo $item; ?></option>
236                                    <?php endforeach; ?>
237                                </select>
238                        </span>
239                        
240                       <span class="j-aqge-periode j-ap-bps-1 j-ap-bps-2 j-ap-bps-3 j-ap-bps-4 j-ap-bps-5  "> 
241                            <!--tahun saja-->
242                                <select id="aqge-chart-widget-end-tahun" name="aqge-chart-end-tahun" >
243                                    <?php foreach($tahun as $key=>$item): ?>
244                                    <?php    $selectahun = (date('Y', strtotime($fendh))==$key) ?'selected=selected':null; ?>
245                                    <option value="<?php echo $key; ?>" <?php echo $selectahun; ?> ><?php echo $item; ?></option>
246                                    <?php endforeach; ?>
247                                </select>
248                       </span>
249                            
250                        </h3>
251                    </h4>    
252                    
253               
254               <!--Pilihan group by-->
255                    <h4><label for="tanggal laporan">Jenis Laporan</label>
256                          
257                       <?php $periode=array('Harian','Mingguan','Bulanan','Tahunan'); ?> 
258                        <select id="aqge-chart-widget-group" name="aqge-chart-group"  >
259                            <?php foreach($periode as $key=>$item):  ?>
260                            <option value="<?php echo $key+1; ?>"
261                                     <?php echo ($updatemodel && $updatemodel['grup']==($key+1))?'selected=selected':null; ?>
262                                    > <?php echo $item; ?></option>
263                            <?php endforeach; ?>
264                        </select>
265                         
266                    </h4>   
267                </div>
268                
269                
270                <!--Pilihan data Kanan-->
271                <div class="aqge-chart-right">
272                    <h4><label for="pilihan data" style="width:150px;">Pilihan data</label>
273                        <div class="aqge-chart-data-container">
274                            <?php $data=($updatemodel)?explode(',', $updatemodel['data']):array(0); ?>
275                            <?php $datagroup = array('pibc','kemdag','keramatjati','bps','daerah'); ?>
276                            <?php foreach($datagroup as $itemgroup):?>    
277                            <ul class="aqge-chart-datagroup j-aqge-chart-datagroup j-aqge-chart-datagroup<?php echo $itemgroup; ?>">
278                            <?php $datamodel = $model->getDataItems($itemgroup); ?>
279                                 
280                            <?php if($itemgroup=='kemdag'): ?>
281                            <?php $kemdagoption = $model->getDataItems('kemdagoption');?>   
282                                
283                                <div class="j-aqge-chart-data-item j-aqge-chart-data-item-kemdag-0">
284                                    <select class="j-aqge-chart-option-item-kemdag"  name="aqge-chart-data-home">
285                                        <option value="0">-pilih propinsi-</option>                                        
286                                        <?php foreach($kemdagoption as $optionitem): ?>
287                                        <option value="<?php echo $optionitem['id'];?>"
288                                                <?php   if($optionitem['id']==$updatemodel['home']):       ?>
289                                                selected="selected"
290                                                <?php endif; ?>
291                                                ><?php echo $optionitem['desc'];?></option>
292                                        <?php endforeach; ?>
293                                    </select>
294                                </div>
295                            <?php endif; ?>
296                                
297                            <?php if($itemgroup=='daerah'): ?>
298                            <?php $daerahoption = $model->getDataItems('daerahoption');?>   
299                                
300                                <div class="j-aqge-chart-data-item j-aqge-chart-data-item-daerah-0">
301                                    <select class="j-aqge-chart-option-item-daerah"  name="aqge-chart-data-home">
302                                        <option value="0">-pilih propinsi-</option>                                        
303                                        <?php foreach($daerahoption as $optionitem): ?>
304                                        <option value="<?php echo $optionitem['id'];?>"
305                                                <?php   if($optionitem['id']==$updatemodel['home']):       ?>
306                                                selected="selected"
307                                                <?php endif; ?>
308                                                ><?php echo $optionitem['desc'];?></option>
309                                        <?php endforeach; ?>
310                                    </select>
311                                </div>
312                            <?php endif; ?>    
313                                
314                            <?php foreach($datamodel as $key=>$dataitem) : //penjualan, harga, kemdag-N ?> 
315                                <li class="aqge-chart-data-item j-aqge-chart-data-item j-aqge-chart-data-item-<?php echo $itemgroup.'-'.$key; ?>"
316                                   >
317                                     
318                                    <h4><?php echo $dataitem['title']; ?> </h4>
319                                    <ul >
320                                        <?php foreach($dataitem['items'] as $datasub):?>
321                                        <li>     
322                                            <?php if(isset($datasub['add-title'])): ?>
323                                            <label class="aqge-item-add-title"><?php echo $datasub['add-title']; ?> </label>
324                                            <?php endif; ?>
325                                            
326                                            <label  class="<?php echo  isset($datasub['class'])?$datasub['class']:null; ?>"  >
327                                                <input type="checkbox" name="aqge-chart-data-select[]" 
328                                                       value="<?php echo $datasub['id']; ?>" 
329                                                       <?php //arti: sedang diupdate, group menu sama pibc-1 atau kemdag-0 dan hasil eplode id ada  ?>
330                                                       <?php if($updatemodel && ($itemgroup.'-'.$key==$updatemodel['tipe'] || 
331                                                                                        ($itemgroup.'-0'==$updatemodel['tipe'] && $key==$updatemodel['home'] ) )
332                                                               && in_array($datasub['id'],$data) ) : ?>
333                                                       checked="checked"
334                                                       <?php endif; ?>
335                                                       />
336                                                <?php echo $datasub['desc']; ?>
337                                            </label>
338                                             
339                                        </li>
340                                            <?php endforeach; ?>    
341                                    </ul>
342                                </li>
343                               <?php endforeach; ?>   
344                            </ul>     
345                            <?php endforeach; ?>     
346                            <div class="clear"></div>
347                        </div>
348                    </h4>
349                </div>
350                
351                
352                <!--Tombol submit-->
353                <div>
354                    <input type="hidden" name="aqge-chart-id" value="<?php echo ($updatemodel && $updatemodel['id']?$updatemodel['id']:null); ?>" />
355                    <input type="submit" name="aqge-chart-submit" value="save" class="button-primary"/>
356                </div>
357                    
358                
359            </form>
360            <hr/>
361            
362            
363            <!--Daftar record database-->
364            <div>
365                <h2>Daftar <?php echo $pageOption[$view]['jenis']; ?> tersimpan</h2>
366                <?php $listmodel = $model->listQuery($view); //widget ?>
367                <table class="wp-list-table widefat plugins" cellpadding="1" cellspacing="1">
368                    <thead>
369                        <tr>
370                            <th>Nama <?php echo $pageOption[$view]['jenis']; ?></th>
371                            <th>Info <?php echo $pageOption[$view]['jenis']; ?></th>
372                              
373                        </tr>
374                    </thead>
375                    <tbody>
376                    <?php foreach($listmodel as $item): ?>
377                    <tr>
378                        <td><?php echo $item['name']; ?></td>
379                        <td><?php echo $item['desc']; ?> 
380                            <br/> 
381                            
382                         <a href="#delete" class="j-aqge-chart-query-deleted aqge-chart-query-deleted aqge-chart-tool-link" 
383                            url="<?php echo $this->deleteLink(); ?>" data-id="<?php echo $item['id']; ?>">
384                             delete</a> |
385                             <a href="<?php echo $this->updateLink($item['id'] )  ; ?>" class="aqge-chart-query-updated  aqge-chart-tool-link" >
386                             update</a> |
387                             <a href="#view" class="j-aqge-chart-query-view aqge-chart-query-view  aqge-chart-tool-link" data-id="<?php echo $item['id']; ?>">
388                             view</a>
389                         </td>
390                    </tr>
391                    <?php endforeach; ?>
392                    </tbody>
393                </table>
394            
395            </div>
396        </div>
397        
398        <?php
399}
400}
401
402?>