phpBMS

root/trunk/phpbms/install/installajax.php

Revision 703, 10.5 KB (checked in by brieb, 2 years ago)
  • Rearranged payment processing routine to be more flexible. It now needs to save the sales order first
  • Added payment processing template so developers have a guide when putting together their payment scripts
  • It seems their might be some unintentional touching of other files in this commit;
Line 
1<?php
2/*
3 $Rev: 427 $ | $LastChangedBy: nate $
4 $LastChangedDate: 2008-08-13 12:09:00 -0600 (Wed, 13 Aug 2008) $
5 +-------------------------------------------------------------------------+
6 | Copyright (c) 2004 - 2010, Kreotek LLC                                  |
7 | All rights reserved.                                                    |
8 +-------------------------------------------------------------------------+
9 |                                                                         |
10 | Redistribution and use in source and binary forms, with or without      |
11 | modification, are permitted provided that the following conditions are  |
12 | met:                                                                    |
13 |                                                                         |
14 | - Redistributions of source code must retain the above copyright        |
15 |   notice, this list of conditions and the following disclaimer.         |
16 |                                                                         |
17 | - Redistributions in binary form must reproduce the above copyright     |
18 |   notice, this list of conditions and the following disclaimer in the   |
19 |   documentation and/or other materials provided with the distribution.  |
20 |                                                                         |
21 | - Neither the name of Kreotek LLC nor the names of its contributore may |
22 |   be used to endorse or promote products derived from this software     |
23 |   without specific prior written permission.                            |
24 |                                                                         |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS     |
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       |
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
28 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   |
30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        |
31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   |
32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   |
33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     |
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   |
35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    |
36 |                                                                         |
37 +-------------------------------------------------------------------------+
38*/
39define("APP_DEBUG",false);
40define("noStartup",true);
41
42require("install_include.php");
43require("../include/session.php");
44require("../include/common_functions.php");
45
46
47
48class installAjax extends installUpdateBase{
49
50        function testConnection(){
51
52                if($this->db->connect())
53                        return $this->returnJSON(true, "Connection to Database Established");
54                else
55                        return $this->returnJSON(false, $this->db->getError());
56
57
58        }//end function testConnection
59
60
61        function createDatabase(){
62
63                if(!$this->db->connect())
64                        return $this->returnJSON(false, "Could not connect to database ".$this->db->getError());
65
66                $createstatement = "CREATE DATABASE ".MYSQL_DATABASE;
67                $this->db->query($createstatement);
68
69                if($this->db->error)
70                        return $this->returnJSON(false, $this->db->error);
71                else
72                        return $this->returnJSON(true, "Database '".MYSQL_DATABASE."' created successfully");
73
74        }//end function createDatabase
75
76
77        function coreDataInstall($extras){
78
79                $extras = explode("::", $extras);
80
81                if(!$this->db->connect())
82                        return $this->returnJSON(false, "Could not connect to database ".$this->db->getError());
83
84                if(!$this->db->selectSchema())
85                        return $this->returnJSON(false, "Could not open database schema '".MYSQL_DATABASE."'");
86
87                $installer = new installer($this->db);
88
89                //Run create table sql file ocreate the tables
90                $tempReturn = $installer->processSQLFile("createtables.sql");
91
92                if($tempReturn !== true)
93                        return $this->returnJSON(false, $tempReturn);
94
95
96                // Create an array of table names.  Each one has a correspondng
97                // SQL file.  Each file consists of a series of insert statements
98                // (one per line) that populates that table.
99                $tables = array(
100                        "choices",
101                        "files",
102                        "menu",
103                        "tabs",
104                        "modules",
105                        "notes",
106                        "reports",
107                        "scheduler",
108                        "tablecolumns",
109                        "tabledefs",
110                        "tablefindoptions",
111                        "tablegroupings",
112                        "tableoptions",
113                        "tablesearchablefields",
114                        "smartsearches",
115                        "users",
116                        "settings",
117                        "widgets"
118                );
119
120                $thereturn = "";
121
122                //now we run the import for each file
123                foreach($tables as $table){
124
125                        $tempReturn = $installer->processSQLFile($table.".sql");
126
127                        if($tempReturn !== true)
128                                $thereturn .= $tempReturn;
129
130                }//end foreach
131
132                // next we need to generate the encrption seed and update the
133                // setting in the table
134                $newSeed = $this->generateRandomString(16);
135
136                $updatestatement = "
137                        UPDATE
138                                `settings`
139                        SET
140                                `value` = '".$newSeed."'
141                        WHERE
142                                `name` = 'encryption_seed'";
143
144                $this->db->query($updatestatement);
145                if($this->db->error)
146                        return $this->returnJSON(false, "Error Updating Encryption Seed: ".$this->db->error);
147
148                //finally we have to assign the admin password;
149
150                $newPass = $this->generateRandomString(8);
151
152                $updatestatement = "
153                        UPDATE
154                                `users`
155                        SET
156                                `email` = '".$extras[1]."',
157                                `password` = ENCODE('".$newPass."' , '".$newSeed."')
158                        WHERE
159                                `id` = 2";
160
161                $this->db->query($updatestatement);
162                if($this->db->error)
163                        return $this->returnJSON(false, "Error Updating Admin Password: ".$this->db->error);
164
165                //Update Application Name
166                $updatestatement = "
167                        UPDATE
168                                `settings`
169                        SET
170                                `value` = '".mysql_real_escape_string($extras["0"])."'
171                        WHERE
172                                `name` = 'application_name'";
173
174                $this->db->query($updatestatement);
175                if($this->db->error)
176                        return $this->returnJSON(false, "Error Updating Application Name Setting: ".$this->db->error);
177
178
179                //Update Application Uuid
180                $updatestatement = "
181                        UPDATE
182                                `settings`
183                        SET
184                                `value` = '".mysql_real_escape_string(uuid("sys:"))."'
185                        WHERE
186                                `name` = 'application_uuid'";
187
188                $this->db->query($updatestatement);
189                if($this->db->error)
190                        return $this->returnJSON(false, "Error Updating Application Uuid Setting: ".$this->db->error);
191
192                if($thereturn)
193                        return $this->returnJSON(false, $thereturn);
194                else{
195
196                        //Let's also sen an e-mail to the administrator with his password
197                        if($extras[1]){
198
199                                $to = $extras[1];
200                                $from = "From: DoNotReply@phpbms.org";
201                                $subject = "Your phpBMS login information";
202                                $message ="phpBMS Core Program was installed successfully.  Your initial login information is:
203
204        username: admin
205        password: ".$newPass."
206
207If you need further assistance, please use the community forum at http://www.phpbms.org/forum";
208
209                                //attempt to e-mail person
210                                @ mail($to, $subject, $message, $from);
211
212                        }//end if
213
214
215                        return $this->returnJSON(true, "Core Data Installed Successfully.", $newPass);
216
217                }//endif thereturn
218
219        }//end function coreDataInstall
220
221
222        function moduleInstall($module){
223               
224                if(!$this->db->connect())
225                        return $this->returnJSON(false, "Could not connect to database ".$this->db->getError());
226
227                if(!$this->db->selectSchema())
228                        return $this->returnJSON(false, "Could not open database schema '".MYSQL_DATABASE."'");
229
230                $moduleFile = "../modules/".$module."/install/install.php";
231                if(!file_exists($moduleFile))
232                        return $this->returnJSON(false, "Module install file '".$moduleFile."' does not exist.");
233
234                @ include_once($moduleFile);
235
236                return $theModule->install();
237
238        }//end function $module
239
240
241        function process($command, $extras = null){
242
243                $this->phpbmsSession = new phpbmsSession;
244
245                if($this->phpbmsSession->loadDBSettings(false)){
246
247                        @ include_once("include/db.php");
248
249                        $this->db = new db(false);
250                        $this->db->stopOnError = false;
251                        $this->db->showError = false;
252                        $this->db->logError = false;
253
254                } else {
255
256                        echo $this->returnJSON(false, "Could not open session.php file");
257                        exit;
258
259                }
260
261                switch($command){
262
263                        case "testconnection":
264                                echo $this->testConnection();
265                                break;
266
267                        case "createdatabase":
268                                echo $this->createDatabase();
269                                break;
270
271                        case "coredatainstall":
272                                echo $this->coreDataInstall($extras);
273                                break;
274
275                        case "moduleinstall":
276                                if(!$extras)
277                                        echo $this->returnJSON(false, "module not passed");
278                                echo $this->moduleInstall($extras);
279                                break;
280
281                        default:
282                                echo $this->returnJSON(false, "command not recognized");
283                                break;
284
285                }//endswitch
286
287        }//endfunction process
288
289
290        function generateRandomString($length){
291
292                $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345689";
293                $string = "";
294                $modChars = strlen($chars) - 1;
295
296                srand((double) microtime() * 1000000);
297
298                while(strlen($string) < $length){
299
300                        $num = rand() % $modChars;
301                        $string .= substr($chars, $num, 1);
302
303                }//endwhile
304
305                return $string;
306
307        }//endFunction generateRandomString
308
309}//end class installAjax
310
311
312
313class installModuleAjax extends installUpdateBase{
314
315        var $createTablesSQL = "createtables.sql";
316        var $tables = array();
317        var $pathToModule = "";
318
319
320        function installModuleAjax($db, $phpbmsSession, $pathToModule){
321
322                $this->db = $db;
323                $this->phpbmsSession = $phpbmsSession;
324                $this->pathToModule = $pathToModule;
325
326        }//end function
327
328
329        function install(){
330               
331                if(!$this->db->connect())
332                        return $this->returnJSON(false, "Could not connect to database ".$this->db->getError());
333
334                if(!$this->db->selectSchema())
335                        return $this->returnJSON(false, "Could not open database schema '".MYSQL_DATABASE."'");
336
337                $installer = new installer($this->db);
338
339                //Run create table sql file ocreate the tables
340                if(file_exists($this->pathToModule.$this->createTablesSQL)){
341                        $tempReturn = $installer->processSQLfile($this->pathToModule.$this->createTablesSQL);
342               
343                        if($tempReturn !== true)
344                                return $this->returnJSON(false, $tempReturn);
345                               
346                }//end if
347
348                $thereturn = "";
349
350                //now we run the import for each file
351                foreach($this->tables as $table){
352
353                        $tempReturn = $installer->processSQLFile($this->pathToModule.$table.".sql");
354
355                        if($tempReturn !== true)
356                                $thereturn .= $tempReturn;
357
358                }//end foreach
359
360                if($thereturn)
361                        return $this->returnJSON(false, $thereturn);
362                else
363                        return $this->returnJSON(true, "Module Installed");
364
365
366        }//end function install
367
368}//end class installModuleAjax
369
370
371
372// START PROCESSING
373//==============================================================================
374
375$installAjax = new installAjax();
376
377if(!isset($_GET["command"]))
378        echo $installAjax->returnJSON("failure", "No command given.");
379
380if(!isset($_GET["extras"]))
381        $installAjax->process($_GET["command"]);
382else
383        $installAjax->process($_GET["command"], $_GET["extras"]);
Note: See TracBrowser for help on using the browser.
Scanned by Orvant Copyright © 2010 Kreotek, LLC. All Rights reserved.