示例#1
0
 private function createHub($hubName, $username)
 {
     if (isset($hubName, $username)) {
         // Replace spaces with underscores
         $hubName = str_replace(" ", "_", $hubName);
         if (!empty(CREATE_HUB_SCRIPT)) {
             exec(CREATE_HUB_SCRIPT . ' "' . $hubName . '"', $outputArray, $return_val);
             if ($return_val == 0) {
                 // Cycle through the output
                 foreach ($outputArray as $output) {
                     // If the array is at the password block
                     if (strpos($output, 'Password: '******'Password: '******'', $output));
                         $stmt = $this->db_connection->prepare('SELECT id FROM clients WHERE username = ?');
                         if ($stmt->execute(array($username))) {
                             if ($userid = $stmt->fetchColumn()) {
                                 $stmt = null;
                                 $stmt = $this->db_connection->prepare('SELECT null FROM hubs WHERE name = ? AND client_id_fk = ?');
                                 if ($stmt->execute(array($hubName, $userid))) {
                                     if ($stmt->rowCount() == 0) {
                                         $stmt = null;
                                         $stmt = $this->db_connection->prepare('INSERT INTO hubs (name, password, client_id_fk, created) VALUES (?, ?, ?, ?)');
                                         if ($stmt->execute(array($hubName, $password, $userid, date('Y-m-d H:i:s')))) {
                                             return true;
                                         } else {
                                             throw new Exception('The hub creation failed due to a database error');
                                         }
                                     } else {
                                         throw new Exception('The hub ' . $hubName . ' already exists');
                                     }
                                 } else {
                                     throw new Exception('The hub creation failed due to a database error');
                                 }
                             } else {
                                 throw new Exception('The hub creation failed due to a database error');
                             }
                         } else {
                             throw new Exception('The hub creation failed due to a database error');
                         }
                         return $password;
                     }
                 }
             } elseif ($return_val == 2) {
                 throw new Exception('The hub name is already in use');
             }
         }
     }
     throw new Exception('The hub ' . $hubName . ' failed to be created');
 }