• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/widgetFramework.class.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00017 abstract class widgetFramework
00018 {       
00019 
00020         public $widgetName; 
00021         public $widgetDescription; 
00022         public $widgetVersion; 
00023         public $widgetAuthor; 
00024         public $widgetId; 
00025         public $widgetInstanceId; 
00026         public $widgetPageId; 
00027         public $widgetLocation; 
00028         public $widgetOrder; 
00029         public $settings; 
00030         public $data; 
00031         public $defaultConfigs; 
00032         
00033         
00035         abstract public function initWidget();
00036         
00038         abstract public function getHTML();
00039         
00041         abstract public function getCommonHTML();
00042         
00050         public function __construct($widgetId,$widgetInstanceId,$pageId,$defaultconfigs)
00051         {
00052                 $this->widgetId=$widgetId;
00053                 $this->widgetInstanceId=$widgetInstanceId;
00054                 $this->pageId=$pageId;
00055                 $this->defaultConfigs=$defaultconfigs;
00056                 $this->loadWidget();
00057                 
00058                 
00059         } 
00060         
00067         public final function loadWidget()
00068         {
00069         
00071                 $query="SELECT `widget_name` AS 'name', `widget_description` AS 'description', `widget_version` AS 'version', `widget_author` AS 'author' FROM `".MYSQL_DATABASE_PREFIX."widgetsinfo` WHERE `widget_id`={$this->widgetId}";
00072                 $res=mysql_query($query);
00073                 if($res===false || mysql_num_rows($res)==0)
00074                 {
00075                         displayerror("Error in loading widget {$this->widgetName}");
00076                         return false;
00077                 }
00078                 $row=mysql_fetch_array($res);
00079                 
00080                 $this->widgetName=$row['name'];
00081                 $this->widgetDescription=$row['description'];
00082                 $this->widgetVersion=$row['version'];
00083                 $this->widgetAuthor=$row['author'];
00084                 
00086                 $query="SELECT `config_name` AS 'key', `config_value` AS 'value' FROM `".MYSQL_DATABASE_PREFIX."widgetsconfig` WHERE `widget_id`={$this->widgetId} AND `widget_instanceid` IN ({$this->widgetInstanceId},-1) ";
00087                 $res=mysql_query($query);
00088                 
00089                 if($res===false)
00090                 {
00091                         displayerror("Error in loading widget {$this->widgetName}");
00092                         return false;
00093                 }
00094                 $this->settings = array();
00095                 while($row=mysql_fetch_array($res))
00096                 {
00097                         $this->settings[$row['key']]=$row['value'];
00098                 }
00099                 
00101                 $query="SELECT `config_name` AS 'key', `config_default` AS 'value', `is_global` AS 'global' FROM `".MYSQL_DATABASE_PREFIX."widgetsconfiginfo` WHERE `widget_id`={$this->widgetId}";
00102                 
00103                 $res=mysql_query($query);
00104                 if($res===false)
00105                 {
00106                         displayerror("Error in loading widget {$this->widgetName}");
00107                         return false;
00108                 }
00109                 
00110                 while($row=mysql_fetch_array($res))
00111                 {
00112                         if(!isset($this->settings[$row['key']]))
00113                         {
00114                                 $this->settings[$row['key']]=$row['value'];
00115                                 
00117                                 if(($row['global']=='1' && $this->widgetInstanceId==-1) || ($row['global']=='0' && $this->widgetInstanceId!=-1))
00118                                 {
00119                                         $query="INSERT IGNORE INTO `".MYSQL_DATABASE_PREFIX."widgetsconfig` (`widget_id`,`widget_instanceid`,`config_name`,`config_value`) VALUES ({$this->widgetId}, {$this->widgetInstanceId}, '{$row['key']}', '{$row['value']}')";
00120                                         $res2=mysql_query($query);
00121                                         if($res2===false)
00122                                         {
00123                                                 displayerror("Error in loading widget {$this->widgetName}");
00124                                                 return false;
00125                                         }
00126                                 }
00127                         }
00128                 }
00129         
00131                 $query="SELECT `widget_datakey` AS 'key', `widget_datavalue` AS 'value' FROM `".MYSQL_DATABASE_PREFIX."widgetsdata` WHERE `widget_id`={$this->widgetId} AND`widget_instanceid` = {$this->widgetInstanceId}";
00132                 $res=mysql_query($query);
00133                 if($res===false)
00134                 {
00135                         displayerror("Error in loading widget {$this->widgetName}");
00136                         return false;
00137                 }
00138                 $this->data = array();
00139                 while($row=mysql_fetch_array($res))
00140                 {
00141                         $this->data[$row['key']]=$row['value'];
00142                 }
00143                 
00144                 return true;
00145                 
00146         }
00147         
00154         function validInstall()
00155         {
00156                 if(!isset($this->data['pragyan_widget_install']) || isset($this->data['pragyan_widget_install'])==0)
00157                         return false;
00158                 return true;
00159         }
00160         
00165         function installWidget()
00166         {
00167                 
00169                 $query = "DELETE FROM `".MYSQL_DATABASE_PREFIX."widgetsconfiginfo` WHERE `widget_id`={$this->widgetId}";
00170                 mysql_query($query);
00171                 
00172                 
00173                 $install=$this->setConfigs($this->defaultConfigs);
00174                 if($install==true)
00175                 {
00176                         displayinfo("{$this->widgetName} widget successfully installed!");
00177                         return $this->saveData('pragyan_widget_install','1');
00178                 }
00179                 return false;
00180         }
00181         
00187         public final function setConfigs($configs)
00188         {
00189                 $rank=0;
00190                 foreach($configs as $config)
00191                 {
00192                         $config['global']=(int)$config['global'];
00193                         
00194                         foreach($config as $key=>$value) $config[$key]=escape($value);
00195                         
00196                         $query="INSERT IGNORE INTO `".MYSQL_DATABASE_PREFIX."widgetsconfiginfo` (`widget_id`,`config_name`,`config_type`,`config_options`,`config_displaytext`,`config_default`,`is_global`,`config_rank`) VALUES ({$this->widgetId},'{$config['name']}','{$config['type']}','{$config['options']}','{$config['displaytext']}','{$config['default']}',{$config['global']},{$rank})";
00197                         
00198                         $rank++;
00199                         if(mysql_query($query)==false)
00200                         {
00201                                 displayerror("Error in saving configurations for the widget {$this->widgetName}");
00202                                 return false;
00203                         }
00204                 }
00205                 return true;
00206         }
00207         
00214         public final function saveSetting($key,$value)
00215         {
00216                 $value = escape($value);
00217                 $key = escape($key);
00218                 
00219                 $query="UPDATE `".MYSQL_DATABASE_PREFIX."widgetsconfig` SET `config_value`='$value' WHERE `config_name`='$key' AND `widget_id`={$this->widgetId} AND `widget_instanceid`={$this->widgetInstanceId}";
00220 
00221                 if(mysql_query($query)===false) {
00222                         displayerror("Error in saving setting for the widget {$this->widgetName}.");
00223                         return false; 
00224                 }
00225                 return true;
00226                 
00227         }
00228         
00235         public final function saveData($key,$value)
00236         {
00237                 $value = escape($value);
00238                 $key = escape($key);
00239                 
00240                 if(isset($this->data[$key]))
00241                         $query="UPDATE `".MYSQL_DATABASE_PREFIX."widgetsdata` SET `widget_datavalue`='$value' WHERE `widget_datakey`='$key' AND `widget_id`={$this->widgetId} AND `widget_instanceid`={$this->widgetInstanceId}";
00242                 else 
00243                         $query="INSERT INTO `".MYSQL_DATABASE_PREFIX."widgetsdata` (`widget_id`,`widget_instanceid`,`widget_datakey`,`widget_datavalue`) VALUES ({$this->widgetId},{$this->widgetInstanceId},'$key','$value')";
00244                 
00245                 if(mysql_query($query)===false)
00246                 {
00247                         displayerror("Error in saving data for the widget {$this->widgetName}.");
00248                         return false;
00249                 }
00250                 return true;
00251         }
00252         
00262         public final function createWidget($pageId,&$widgetLocation,&$widgetOrder)
00263         {
00265                 $defaultloc=1;
00266                 
00267                 $query="SELECT MAX(`widget_instanceid`) FROM `".MYSQL_DATABASE_PREFIX."widgets` WHERE `widget_id` = {$this->widgetId}";
00268                 $result=mysql_query($query);
00269                 if($result===false) return false;
00270                 $row1=mysql_fetch_row($result);
00271                 if($row1==NULL)
00272                  $row1[0]=0;
00273                 
00274                 $query="SELECT MAX(`widget_order`) FROM `".MYSQL_DATABASE_PREFIX."widgets` WHERE `page_id` = $pageId AND `widget_location` = $defaultloc";
00275                 $result=mysql_query($query);
00276                 if($result===false) return false;
00277                 $row2=mysql_fetch_array($result);
00278                 if($row2==NULL)
00279                  $row2[0]=0;
00280                 
00281                 $instanceId=$row1[0]+1; 
00282                 $widgetOrder=$row2[0]+1;
00283                 $widgetLocation=$defaultloc; 
00284                 
00285                 $query="INSERT INTO `".MYSQL_DATABASE_PREFIX."widgets` (`widget_id`,`widget_instanceid`,`page_id`,`widget_location`,`widget_order`) VALUES ({$this->widgetId},$instanceId,$pageId,$widgetLocation,$widgetOrder)";
00286                 
00287                 if(mysql_query($query)==false)
00288                         return false;
00289                 
00290         }
00291         
00292         
00293 }        
00294 ?>

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1