| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | define("APP_DEBUG",false); |
|---|
| 4 | define("noStartup",true); |
|---|
| 5 | |
|---|
| 6 | require("../include/session.php"); |
|---|
| 7 | |
|---|
| 8 | class updater{ |
|---|
| 9 | |
|---|
| 10 | // database object |
|---|
| 11 | var $db; |
|---|
| 12 | |
|---|
| 13 | // module list |
|---|
| 14 | var $list; |
|---|
| 15 | |
|---|
| 16 | var $phpbmsSession; |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | function updater(){ |
|---|
| 20 | |
|---|
| 21 | $this->phpbmsSession = new phpbmsSession; |
|---|
| 22 | |
|---|
| 23 | if($this->phpbmsSession->loadDBSettings(false)){ |
|---|
| 24 | |
|---|
| 25 | @ include_once("include/db.php"); |
|---|
| 26 | |
|---|
| 27 | $this->db = new db(false); |
|---|
| 28 | $this->db->stopOnError = false; |
|---|
| 29 | $this->db->showError = false; |
|---|
| 30 | $this->db->logError = false; |
|---|
| 31 | |
|---|
| 32 | } else |
|---|
| 33 | $error = new appError(-300,"","",true,true,false); |
|---|
| 34 | |
|---|
| 35 | if(!$this->db->connect()) |
|---|
| 36 | $error = new appError(-400,"Could not connect to database server.\n\n".$this->db->getError(),"Database Error",true,true,false); |
|---|
| 37 | |
|---|
| 38 | if(!$this->db->selectSchema()) |
|---|
| 39 | $error = new appError(-410,"Could not open schema ".$this->db->schema,"Database Error", true, true, false); |
|---|
| 40 | |
|---|
| 41 | }//end function init |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | function buildList(){ |
|---|
| 45 | |
|---|
| 46 | $thedir = @ opendir("../modules/"); |
|---|
| 47 | |
|---|
| 48 | $modules = array(); |
|---|
| 49 | |
|---|
| 50 | //this helps build the modules array |
|---|
| 51 | // each included modules version.php should add to the |
|---|
| 52 | // array |
|---|
| 53 | while($entry = readdir($thedir)){ |
|---|
| 54 | |
|---|
| 55 | if($entry != "." && $entry != ".." && $entry != "base" && $entry != "sample" && is_dir("../modules/".$entry)){ |
|---|
| 56 | |
|---|
| 57 | if(file_exists("../modules/".$entry."/install/update.php") && file_exists("../modules/".$entry."/version.php")){ |
|---|
| 58 | |
|---|
| 59 | include("../modules/".$entry."/version.php"); |
|---|
| 60 | |
|---|
| 61 | }//endif |
|---|
| 62 | |
|---|
| 63 | }//endif |
|---|
| 64 | |
|---|
| 65 | }//end if |
|---|
| 66 | |
|---|
| 67 | //Next we add the base version in |
|---|
| 68 | include("../phpbmsversion.php"); |
|---|
| 69 | |
|---|
| 70 | //go retrieve current versions |
|---|
| 71 | foreach($modules as $key=>$value) |
|---|
| 72 | $modules[$key]["currentversion"] = $this->getCurrentVersion($key); |
|---|
| 73 | |
|---|
| 74 | $this->list = $modules; |
|---|
| 75 | |
|---|
| 76 | }//end function buildList |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | function getMySQLVersion(){ |
|---|
| 80 | |
|---|
| 81 | $querystatement = "SELECT VERSION() AS ver"; |
|---|
| 82 | $queryresult = $this->db->query($querystatement); |
|---|
| 83 | if($this->db->error) |
|---|
| 84 | $error = new appError(-425,"Could not retrieve mysql version. ","Database Error", true, true, false); |
|---|
| 85 | |
|---|
| 86 | $therecord = $this->db->fetchArray($queryresult); |
|---|
| 87 | |
|---|
| 88 | return $therecord["ver"]; |
|---|
| 89 | |
|---|
| 90 | }//endif |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | function getCurrentVersion($module){ |
|---|
| 94 | |
|---|
| 95 | $querystatement = " |
|---|
| 96 | SELECT |
|---|
| 97 | version |
|---|
| 98 | FROM |
|---|
| 99 | modules |
|---|
| 100 | WHERE |
|---|
| 101 | name = '".$module."'"; |
|---|
| 102 | |
|---|
| 103 | $queryresult = $this->db->query($querystatement); |
|---|
| 104 | if($this->db->error) |
|---|
| 105 | $error = new appError(-600,"Could not retrieve current version information for ".$module.": ".$this->db->error,"Cannot load module information",true,true,false); |
|---|
| 106 | |
|---|
| 107 | if($this->db->numRows($queryresult)){ |
|---|
| 108 | |
|---|
| 109 | $therecord = $this->db->fetchArray($queryresult); |
|---|
| 110 | |
|---|
| 111 | return floatval($therecord["version"]); |
|---|
| 112 | |
|---|
| 113 | } else |
|---|
| 114 | return 0; |
|---|
| 115 | |
|---|
| 116 | }//end function getCurrentVersion |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | function checkBaseUpdate(){ |
|---|
| 120 | |
|---|
| 121 | return ($this->list["base"]["version"] == $this->list["base"]["currentversion"]); |
|---|
| 122 | |
|---|
| 123 | }//end function showBaseUpdate |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | function showModulesUpdate(){ |
|---|
| 127 | |
|---|
| 128 | ?> |
|---|
| 129 | <table id="moduleTable" cellpadding="0" cellspacing="0" border="0"> |
|---|
| 130 | <thead> |
|---|
| 131 | <tr> |
|---|
| 132 | <th>module</th> |
|---|
| 133 | <th>file version</th> |
|---|
| 134 | <th>database version</th> |
|---|
| 135 | <th> </th> |
|---|
| 136 | </tr> |
|---|
| 137 | </thead> |
|---|
| 138 | <tbody> |
|---|
| 139 | <?php |
|---|
| 140 | |
|---|
| 141 | ksort($this->list); |
|---|
| 142 | |
|---|
| 143 | foreach($this->list as $key=>$module){ |
|---|
| 144 | |
|---|
| 145 | if($key != "base"){ |
|---|
| 146 | |
|---|
| 147 | ?> |
|---|
| 148 | <tr> |
|---|
| 149 | <td> |
|---|
| 150 | <h3><strong><?php echo $module["name"]?></strong></h3> |
|---|
| 151 | <p><?php echo $module["description"]?></p> |
|---|
| 152 | <p class="notes"><strong>Requirements:</strong><?php echo $module["requirements"]?></p> |
|---|
| 153 | </td> |
|---|
| 154 | <td><?php echo $module["version"] ?></td> |
|---|
| 155 | <td><?php echo $module["currentversion"] ?></td> |
|---|
| 156 | |
|---|
| 157 | <td class="moduleInstall"> |
|---|
| 158 | <?php |
|---|
| 159 | if($module["version"] != $module["currentversion"]){ |
|---|
| 160 | if($module["currentversion"] == 0) { |
|---|
| 161 | ?> |
|---|
| 162 | Not Installed |
|---|
| 163 | <?php |
|---|
| 164 | } else { |
|---|
| 165 | ?> |
|---|
| 166 | |
|---|
| 167 | <button class="Buttons moduleButtons" id="moduleButton<?php echo $key ?>">Update Module</button> |
|---|
| 168 | <p><span class="" id="Results<?php echo $key?>"></span></p> |
|---|
| 169 | |
|---|
| 170 | <?php }} else {?> |
|---|
| 171 | Versions Match<br /> |
|---|
| 172 | Update Unnecessary |
|---|
| 173 | <?php }//endif version!=currentversion ?> |
|---|
| 174 | </td> |
|---|
| 175 | </tr> |
|---|
| 176 | <?php |
|---|
| 177 | |
|---|
| 178 | }//end if |
|---|
| 179 | |
|---|
| 180 | }//end foreach |
|---|
| 181 | |
|---|
| 182 | ?></tbody></table><?php |
|---|
| 183 | |
|---|
| 184 | }//end function showModuleUpdate |
|---|
| 185 | |
|---|
| 186 | }//end class |
|---|
| 187 | ?> |
|---|