Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

base-admin.inc.php

Go to the documentation of this file.
00001 <?
00008 class BaseAdmin extends MyModule
00009 {
00015     public function init($page = null, $vars = null)
00016     {
00017         //parental init.
00018         parent::init($page, $vars);
00019 
00020         //gotta be logged in.
00021         $this->assertLogin();
00022 
00023         //seriously, you cant come in.
00024         global $me;
00025         if (!$me->isAdmin())
00026             throw new PageError('You must be an admin to access the Admin area. ;)');
00027     }
00028 
00040     public function getPagesXml()
00041     { 
00042         $xml = parent::getPagesXml();
00043 
00044         $xml .= <<<XML
00045             <page name="clearcache"/>
00046             <page name="deletecache">
00047                 <param name="key" required="1"/>
00048             </page>
00049             <page name="viewcache">
00050                 <param name="key" required="1"/>
00051             </page>
00052             <page name="hittracking" title="Hit Tracking">
00053             </page>
00054             <page name="clearhits"/>
00055 XML;
00056         return $xml;
00057     }
00058 
00062     public function initMainPage()
00063     {
00064         $this->pageTitle = 'Admin Homepage';
00065     }
00066 
00070     public function drawMainPage()
00071     {
00072 ?>
00073     <h3>Cache Management</h3>
00074     <ul>
00075         <li><?=$this->getLink(".deletekey", "Delete Key")?></li>
00076         <li><?=$this->getLink(".clearcache", "Clear Cache")?></li>
00077     </ul>
00078 
00079     <h3>Hit Tracking</h3>
00080     <ul>
00081         <li><?=$this->getLink(".hittracking", "View Stats")?></li>
00082         <li><?=$this->getLink(".clearhits", "Clear Hits")?></li>
00083     </ul>
00084 <?
00085     } 
00086 
00090     public function initClearCachePage()
00091     {
00092         $this->pageTitle = 'Clear the Cache';
00093     }
00094 
00098     public function drawClearCachePage()
00099     {
00100         $form = $this->createClearCacheForm();
00101 
00102         if ($form->isSubmitted())
00103         {
00104             $form->validate();
00105             if (!$form->hasError())
00106             {
00107                 CacheBot::flush();
00108                 echo "All entries in the cache have been deleted.  Have a nice day!";
00109             }
00110         }
00111 
00112         if ($form->needsDrawn())
00113             $form->draw();
00114     }
00115 
00121     public function createClearCacheForm()
00122     {
00123         $form = new Form();
00124         $form->action = $this->getUrl(".clearcache");
00125 
00126         $form->add("LabelField", "warning", array(
00127             "text" => "You are about to clear the entire cache for the whole website.  Are you sure you want to do this?"
00128         ));
00129         $form->addSubmit("Clear Cache");
00130 
00131         return $form;
00132     }
00133 
00137     public function initDeleteCachePage()
00138     {
00139         $key = base64_decode($this->params('key'));
00140         
00141         $this->pageTitle = "Delete Cache - $key";
00142     }
00143 
00147     public function drawDeleteCachePage()
00148     {
00149         $key = base64_decode($this->params('key'));
00150         
00151         $form = $this->createDeleteCacheForm($key);
00152 
00153         if ($form->isSubmitted())
00154         {
00155             $form->validate();
00156             if (!$form->hasError())
00157             {
00158                 CacheBot::delete($key);
00159                 echo "The key '$key' has been deleted from the cache.";
00160             }
00161         }
00162 
00163         if ($form->needsDrawn())
00164             $form->draw();
00165     }
00166 
00173     public function createDeleteCacheForm($key)
00174     {
00175         $form = new Form();
00176         $form->action = $this->getUrl(".deletecache?key=" . base64_encode($key));
00177 
00178         $form->add("StaticField", "warning", array(
00179             "text" => "Are you sure you want to delete the cache for <b>$key</b>?"
00180         ));
00181         $form->addSubmit("Delete Cache");
00182 
00183         return $form;
00184     }
00185 
00189     public function initViewCachePage()
00190     {
00191         $key = base64_decode($this->params('key'));
00192 
00193         $this->pageTitle = "View Cache - $key";
00194     }
00195 
00199     public function drawViewCachePage()
00200     {
00201         $key = base64_decode($this->params('key'));
00202         
00203         //get our data... use a large life so we dont accidentally delete it.
00204         $data = CacheBot::get($key, 1000000000);
00205         if ($data)
00206         {
00207             //show our delete link
00208             echo "<p>" . $this->getLink(".deletecache?key=" . base64_encode($key), "Delete Cache for $key") . "</p>";
00209 
00210             //show the data!
00211             Util::dump($data);
00212         }
00213         else
00214             echo "<p><b>Key $key not found!</b></p>";
00215     }
00216 
00220     public function drawHitTrackingPage()
00221     {
00222 ?>
00223     <h2>Popular Modules</h2>
00224     <table width="50%">
00225         <tr>
00226             <th>#</th>
00227             <th>Module</th>
00228             <th>Hits</th>
00229         </tr>
00230 <?
00231     $rs = dbQuery("
00232         SELECT count(module) AS module_hits, module
00233         FROM site_hits
00234         GROUP BY module
00235         ORDER BY module_hits DESC
00236         LIMIT 50
00237     ");
00238     $count = 0;
00239     while ($ar = dbFetchAssoc($rs))
00240     {
00241         $count++;
00242         echo "<tr><td>$count</td><td>$ar[module]</td><td>$ar[module_hits]</td></tr>";
00243     }
00244 ?>
00245     </table>
00246     
00247     <h2>Popular Pages</h2>
00248     <table width="50%">
00249         <tr>
00250             <th>#</th>
00251             <th>Module</th>
00252             <th>Page</th>
00253             <th>Hits</th>
00254         </tr>
00255 <?
00256     $rs = dbQuery("
00257         SELECT count(page) AS page_hits, module, page
00258         FROM site_hits
00259         GROUP BY module, page
00260         ORDER BY page_hits DESC
00261         LIMIT 50
00262     ");
00263     $count = 0;
00264     while ($ar = dbFetchAssoc($rs))
00265     {
00266         $count++;
00267         echo "<tr><td>$count</td><td>$ar[module]</td><td>$ar[page]</td><td>$ar[page_hits]</td></tr>";
00268     }
00269 ?>
00270     </table>
00271 <?
00272     }
00273     
00277     public function initClearHitsPage()
00278     {
00279         $this->pageTitle = 'Clear the Hit Tracking Table';
00280     }
00281 
00285     public function drawClearHitsPage()
00286     {
00287         $form = $this->createClearHitsForm();
00288 
00289         if ($form->isSubmitted())
00290         {
00291             $form->validate();
00292             if (!$form->hasError())
00293             {
00294                 $site = Site::getSite();
00295                 $site->clearHits();
00296                 
00297                 echo "All entries in the hit tracking table have been deleted.  Have a nice day!";
00298             }
00299         }
00300 
00301         if ($form->needsDrawn())
00302             $form->draw();
00303     }
00304 
00310     public function createClearHitsForm()
00311     {
00312         $form = new Form();
00313         $form->action = $this->getUrl(".clearhits");
00314 
00315         $form->add("LabelField", "warning", array(
00316             "text" => "You are about to clear the entire hit tracking data for the whole website.  Are you sure you want to do this?"
00317         ));
00318         $form->addSubmit("Clear Hits");
00319 
00320         return $form;
00321     }
00322 
00323 }
00324 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1