/** * Edits a organisation * * @param string $id */ public function editAction($id) { $organisation = Organisation::findFirstByid($id); if (!$organisation) { $this->flash->error("organisation was not found"); return $this->dispatcher->forward(array("controller" => "organisation", "action" => "index")); } $LoginList = \PRIME\Controllers\GetController::getLoginList(); $this->view->setVar('loginList', $LoginList); $this->view->id = $organisation->id; $this->tag->setDefault("id", $organisation->id); $this->tag->setDefault("name", $organisation->name); $database = OrgDatabase::findFirstByorganisation_id($id); $this->tag->setDefault("db_id", $database->id); $this->tag->setDefault("db_host", $database->db_host); $this->tag->setDefault("db_username", $database->db_username); $this->tag->setDefault("db_password", $database->db_password); $this->tag->setDefault("db_name", $database->db_name); $this->view->setVar("organisation_id", $organisation->id); $data = Login::find("organisation_id= " . $organisation->id); $this->view->setVar("logins", $data); $data = DataConnector::find("organisation_id= " . $organisation->id); $this->view->setVar("data_connectors", $data); $this->view->setVar("themeList", $this->getThemeList()); }
public function editType($type, $security_group) { $type_camel = str_replace('_', "", ucwords($type, "_")); $data_write = array(); $data_read = array(); $data_disable = array(); eval('$data_security=$security_group->Has' . $type_camel . ';'); if ($type == "org_database_table") { $database = OrgDatabase::findFirst("organisation_id=" . $security_group->organisation_id); $data_all = OrgDatabaseTable::find("org_database_id=" . $database->id); } else { eval('$data_all = PRIME\\Models\\' . $type_camel . '::find("organisation_id=' . $security_group->organisation_id . '");'); } if ($type == "users") { $id_string_left = "email"; $id_string_right = $type . "_email"; } else { $id_string_left = "id"; $id_string_right = $type . "_id"; } foreach ($data_all as $item_all) { $has_item = false; foreach ($data_security as $item) { if ($item_all->{$id_string_left} == $item->{$id_string_right}) { $has_item = true; if ($item->read_write == "true") { $data_write[] = $item_all; break; } else { $data_read[] = $item_all; break; } } } if (!$has_item) { $data_disable[] = $item_all; } } $item = array(); $item['name'] = $type; if ($type == "users") { $item['id'] = "email"; $item['title'] = "full_name"; } elseif ($type == "dashboard") { $item['id'] = "id"; $item['title'] = "title"; } else { $item['id'] = "id"; $item['title'] = "name"; } $item['write'] = $data_write; $item['read'] = $data_read; $item['disable'] = $data_disable; return $item; }
public function getUserDB() { $database = OrgDatabase::findFirstByorganisation_id($this->organisation_id); $host = $database->db_host; $mySqlUser = $database->db_username; $mySqlPassword = $database->db_password; $mySqlDatabase = $database->db_name; try { $db = new \PDO("mysql:dbname={$mySqlDatabase};host={$host};", $mySqlUser, $mySqlPassword, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); } catch (PDOException $ex) { die(json_encode(array('outcome' => false, 'message' => 'Database connection failed'))); } return $db; }
/** * Register authenticated user into session data * * @param Users $user */ private function _registerSession($user) { $organisation = Organisation::findFirstById($user->organisation_id); $database = OrgDatabase::findFirstByorganisation_id($user->organisation_id); $this->session->set('auth', array('email' => $user->email, 'image_path' => $user->image_path, 'role' => $user->role, 'full_name' => $user->full_name, 'organisation_id' => $user->organisation_id, 'theme' => $organisation->theme, 'db_name' => $database->db_name, 'organisation_name' => $organisation->name)); }
public function writeMysql($data_connector_id, $data, $queryType = "override", $primary_key = "auto") { $data_connector = DataConnector::findFirstByid($data_connector_id); $database = OrgDatabase::findFirstByorganisation_id($data_connector->organisation_id); $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array('host' => $database->db_host, 'username' => $database->db_username, 'password' => $database->db_password, 'dbname' => $database->db_name)); if ($queryType == "override") { $sql = "DROP TABLE IF EXISTS " . preg_replace("/[^A-Za-z0-9 ]/", "_", $data_connector->type) . "_" . $data_connector_id; } $sql = "CREATE TABLE IF NOT EXISTS " . preg_replace("/[^A-Za-z0-9 ]/", "_", $data_connector->type) . "_" . $data_connector_id . "("; foreach ($data['headings'] as $key => $column_name) { $type = gettype($data['0'][$key]); if ('string' == gettype($data['0'][$key])) { if (is_numeric($data['0'][$key])) { if ((int) $data['0'][$key] == (double) $data['0'][$key]) { $type = "integer"; } else { $type = "double"; } } else { if (strtotime($data['0'][$key]) != false) { $type = "date"; } else { } } } if ($type == "integer") { $sql = $sql . "`" . $column_name . "` int DEFAULT NULL, "; } elseif ($type == "double") { $sql = $sql . "`" . $column_name . "` real DEFAULT NULL, "; } elseif ($type == "date") { $sql = $sql . "`" . $column_name . "` datetime DEFAULT NULL, "; } else { $sql = $sql . "`" . $column_name . "` varchar(255) DEFAULT NULL, "; } } if ($primary_key == "auto") { $sql = $sql . "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY"; } elseif ($primary_key == "first") { $sql = $sql . "PRIMARY KEY (`" . reset($data['headings']) . "`)"; } else { $sql = $sql . "PRIMARY KEY (" . $primary_key . ")"; } $sql = $sql . ");"; $connection->query($sql); $rows = array(); $sql = "INSERT INTO " . preg_replace("/[^A-Za-z0-9 ]/", "_", $data_connector->type) . "_" . $data_connector_id . " (`" . implode("`,`", $data['headings']) . "`) VALUES "; foreach ($data as $row) { if (count($data['headings']) == count($row)) { $rows[] = "('" . implode("','", $row) . "')"; } } array_shift($rows); $sql = $sql . implode(", ", $rows) . " ON DUPLICATE KEY UPDATE "; $duplicate_values = array(); foreach ($data['headings'] as $column_name) { $duplicate_values[] = "`" . $column_name . "` =VALUES(`" . $column_name . "`)"; } $sql = $sql . implode(" ,", $duplicate_values) . ";"; $connection->query($sql); }