Xataface HTML Reports Module 0.2
HTML Reports Module for Xataface
|
00001 <?php 00002 /* 00003 * Xataface HTML Reports Module 00004 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00034 class modules_htmlreports { 00035 00039 const REPORTS_TABLE = 'dataface__htmlreports_reports'; 00040 00041 00048 private $baseURL = null; 00049 00054 public static function getReportsTableSQL(){ 00055 00056 $sql = "create table `".self::REPORTS_TABLE."` ( 00057 `report_id` int(11) not null auto_increment primary key, 00058 `actiontool_name` varchar(255), 00059 `actiontool_category` varchar(255), 00060 `actiontool_label` varchar(255), 00061 `actiontool_permission` varchar(255), 00062 `icon` varchar(255), 00063 `tablename` varchar(255) not null, 00064 `template_css` text, 00065 `template_html` longtext not null, 00066 `default_view` varchar(255), 00067 `created_by` varchar(255), 00068 `private` tinyint(1) default 0, 00069 `date_created` datetime, 00070 `last_modified` datetime 00071 00072 00073 )"; 00074 00075 return $sql; 00076 00077 } 00078 00079 00080 00087 public static function q($sql){ 00088 if ( is_array($sql) ){ 00089 $res = null; 00090 foreach ($sql as $q){ 00091 $res = self::q($q); 00092 } 00093 return $res; 00094 } else { 00095 $res = mysql_query($sql, df_db()); 00096 if ( !$res ){ 00097 throw new Exception(mysql_error(df_db())); 00098 } 00099 return $res; 00100 } 00101 } 00102 00103 00113 public static function queryReports($sql){ 00114 try { 00115 return self::q($sql); 00116 } catch ( Exception $ex){ 00117 self::q(self::getReportsTableSQL()); 00118 return self::q($sql); 00119 } 00120 } 00121 00122 00123 00124 00129 public function __construct(){ 00130 //echo "here";exit; 00131 Dataface_Table::setBasePath(self::REPORTS_TABLE, dirname(__FILE__)); 00132 $conf =& Dataface_Application::getInstance()->_conf; 00133 if ( !isset($conf['_allowed_tables']) ){ 00134 $conf['_allowed_tables'] = array(); 00135 } 00136 $conf['_allowed_tables'][self::REPORTS_TABLE] = self::REPORTS_TABLE; 00137 00138 self::queryReports("select report_id from `".self::REPORTS_TABLE."` limit 1"); 00139 00140 // Now add reports as actions 00141 $query = Dataface_Application::getInstance()->getQuery(); 00142 00143 $sql = "select report_id, actiontool_name, actiontool_category, actiontool_label, tablename, created_by, `private`, date_created, last_modified from `".self::REPORTS_TABLE."` where `tablename`='".addslashes($query['-table'])."' limit 100"; 00144 $res = self::queryReports($sql); 00145 $reports = array(); 00146 $table = Dataface_Table::loadTable($query['-table']); 00147 $at = Dataface_ActionTool::getInstance(); 00148 00149 while ($row = mysql_fetch_assoc($res) ){ 00150 $report = new Dataface_Record(self::REPORTS_TABLE, $row); 00151 //$perms = $table->getPermissions(array('report'=>$report)); 00152 $icon = $this->getBaseURL().'/images/report_icon.png'; 00153 if ( $report->val('default_view') ){ 00154 $icon = $this->getBaseURL().'/images/'.basename($report->val('default_view')).'_icon.png'; 00155 00156 } 00157 if ( $report->val('icon') ){ 00158 $icon = $report->val('icon'); 00159 } 00160 //if ( @$perms['view report'] ){ 00161 $action = array( 00162 'name'=>$row['actiontool_name'], 00163 'label'=>$row['actiontool_label'], 00164 'category'=>$row['actiontool_category'], 00165 'url'=>'{$this->url(\'-action=htmlreports_view_report\')}&--report-id='.$row['report_id'], 00166 'table'=>$query['-table'], 00167 'icon'=>$icon, 00168 'permission' => $report->val('actiontool_permission') 00169 ); 00170 $at->addAction($row['actiontool_name'], $action); 00171 //} 00172 } 00173 00174 00175 00176 Dataface_Application::getInstance()->addHeadContent( 00177 '<script>XATAFACE_MODULES_HTMLREPORTS_URL="'.$this->getBaseURL().'";</script>' 00178 ); 00179 00180 00181 00182 00183 00184 00185 } 00186 00192 public function getBaseURL(){ 00193 if ( !isset($this->baseURL) ){ 00194 $this->baseURL = Dataface_ModuleTool::getInstance()->getModuleURL(__FILE__); 00195 } 00196 return $this->baseURL; 00197 } 00198 00199 00205 public function getReportById($id){ 00206 return df_get_record(self::REPORTS_TABLE, array('report_id'=>'='.$id)); 00207 } 00208 00209 00210 }