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