public function mysql_save_from_post($post) { $post['oid'] = parent::mysql_save_from_post($post); $obj = self::from_mysql_id($post['oid']); if (array_key_exists('ids', $post) && array_key_exists('values', $post) && array_key_exists('rws', $post)) { for ($i = 0; $i < count($post['ids']); $i++) { $id = $post['ids'][$i]; $val = $post['values'][$i]; $rw = $post['rws'][$i]; if ($id != "" && $val != "" && $rw != "") { $right = UserTypeRight::from_property(array("UserType_id" => $obj->id, "Module_id" => $id), false); if ($right == null) { $right = new UserTypeRight(); $right->UserType_id = $obj->id; $right->Module_id = $id; } if ($rw == "r") { $right->read = $val; } if ($rw == "w") { $right->write = $val; } if ($rw == "o") { $right->ownership = $val; } $right->mysql_save(); } } } return $post['oid']; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); if ($this->id != 0) { $this->delete_object_links(TestVariable::get_mysql_table()); $i = 0; } $i = 0; if (array_key_exists("parameters", $post)) { foreach ($post["parameters"] as $param) { $p = json_decode($param); $var = new TestVariable(); $var->description = $p->description; $var->name = $p->name; $var->index = $i; $var->type = 0; $var->Test_id = $lid; $var->mysql_save(); $i++; } } if (array_key_exists("returns", $post)) { foreach ($post["returns"] as $ret) { $r = json_decode($ret); $var = new TestVariable(); $var->description = $r->description; $var->name = $r->name; $var->index = $i; $var->type = 1; $var->Test_id = $lid; $var->mysql_save(); $i++; } } if (array_key_exists("deleteLogs", $post)) { if ($post["deleteLogs"] == "*") { $sql = sprintf("DELETE FROM `%s` WHERE `Test_id`=%s", TestSessionLog::get_mysql_table(), $lid); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } else { $logs = json_decode($post["deleteLogs"]); foreach ($logs as $log) { $log = TestSessionLog::from_mysql_id($log); if ($log != null) { $log->mysql_delete(); } } } } $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); if ($this->id != 0) { $this->delete_object_links(CustomSectionVariable::get_mysql_table()); $i = 0; } if (array_key_exists("parameters", $post)) { foreach ($post["parameters"] as $param) { $p = json_decode($param); $var = new CustomSectionVariable(); $var->description = $p->description; $var->name = $p->name; $var->index = $i; $var->type = 0; $var->CustomSection_id = $lid; $var->mysql_save(); $i++; } } if (array_key_exists("returns", $post)) { foreach ($post["returns"] as $ret) { $r = json_decode($ret); $var = new CustomSectionVariable(); $var->description = $r->description; $var->name = $r->name; $var->index = $i; $var->type = 1; $var->CustomSection_id = $lid; $var->mysql_save(); $i++; } } $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); $tt = TestTemplate::from_property(array("Template_id" => $lid)); foreach ($tt as $elem) { $ts = TestSection::from_mysql_id($elem->TestSection_id); $vals = $ts->get_values(); $html = Template::output_html($obj->HTML, $vals, $obj->get_outputs(), $obj->get_inserts()); $elem->HTML = $html; $elem->mysql_save(); } } return $lid; }
public function mysql_save_from_post($post) { $is_new = $this->id == 0; if (array_key_exists("superuser", $post)) { $logged_user = User::get_logged_user(); if ($logged_user == null || $logged_user->superuser == 0) { $post['superuser'] = 0; } } $post['oid'] = parent::mysql_save_from_post($post); $obj = User::from_mysql_id($post['oid']); if ($post['modify_password'] == 1) { $obj->password = $obj->calculate_password_hash($post['password_hash']); $obj->mysql_save(); } if (array_key_exists("deleteShare", $post)) { $rows = json_decode($post["deleteShare"]); foreach ($rows as $row) { $share = UserShare::from_mysql_id($row); if ($share != null) { $share->mysql_delete(); } } } if (array_key_exists("updateShare", $post)) { $rows = json_decode($post["updateShare"], true); foreach ($rows as $row) { if ($row["id"] != 0) { $share = UserShare::from_mysql_id($row['id']); $share->invitee_id = $row['invitee_id']; $share->UserWorkspace_id = $row['workspace_id']; $share->mysql_save(); } else { $share = new UserShare(); $share->invitee_id = $row['invitee_id']; $share->UserWorkspace_id = $row['workspace_id']; $share->mysql_save(); } } } if ($is_new) { $ws = new UserWorkspace(); $ws->owner_id = $post['oid']; $ws->main = 1; $ws->name = "main"; $ws->mysql_save(); } else { if (array_key_exists("deleteWorkspace", $post)) { $rows = json_decode($post["deleteWorkspace"]); foreach ($rows as $row) { $ws = UserWorkspace::from_mysql_id($row); if ($ws != null) { $ws->mysql_delete(); } } } if (array_key_exists("updateWorkspace", $post)) { $rows = json_decode($post["updateWorkspace"], true); foreach ($rows as $row) { if ($row["id"] != 0) { $ws = UserWorkspace::from_mysql_id($row['id']); $ws->name = $row['name']; $ws->owner_id = $this->id; $ws->mysql_save(); } else { $ws = new UserWorkspace(); $ws->name = $row['name']; $ws->owner_id = $this->id; $ws->mysql_save(); } } } } return $post['oid']; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $validation = json_decode($obj->validate()); if ($validation->result == 0) { $obj->ini_r_code = $obj->get_QTI_ini_R_code(); $obj->response_proc_r_code = $obj->get_response_processing_R_code(); } $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $is_new = $this->id == 0; if ($is_new) { if (!Table::create_new_mysql_table($post['name'])) { return json_encode(array("result" => -6, "message" => mysql_error())); } } else { if ($this->name != $post['name']) { if (!$this->rename_mysql_table($post['name'])) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } $lid = parent::mysql_save_from_post($post); $obj = Table::from_mysql_id($lid); if (array_key_exists("deleteData", $post)) { if ($post["deleteData"] == "*") { $sql = sprintf("DELETE FROM `%s`", mysql_real_escape_string($obj->name)); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } else { $rows = json_decode($post["deleteData"]); foreach ($rows as $row) { $sql = sprintf("DELETE FROM `%s` WHERE id='%s'", mysql_real_escape_string($obj->name), mysql_real_escape_string($row)); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } } if (array_key_exists("deleteIndexes", $post)) { $indexes = json_decode($post["deleteIndexes"]); foreach ($indexes as $index) { $sql = sprintf("DROP INDEX `%s` ON `%s`", mysql_real_escape_string($index), mysql_real_escape_string($obj->name)); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } if (array_key_exists("deleteColumns", $post)) { $columns = json_decode($post["deleteColumns"]); foreach ($columns as $column) { $sql = sprintf("ALTER TABLE `%s` DROP COLUMN `%s`", mysql_real_escape_string($obj->name), mysql_real_escape_string($column)); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } if (array_key_exists("updateColumns", $post)) { $columns = json_decode($post["updateColumns"]); foreach ($columns as $column) { $col = TableColumn::from_ui($column); if ($column->id != "") { $sql = sprintf("ALTER TABLE `%s` CHANGE COLUMN `%s` `%s` %s", mysql_real_escape_string($obj->name), mysql_real_escape_string($column->id), mysql_real_escape_string($column->name), $col->get_definition()); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } else { $sql = sprintf("ALTER TABLE `%s` ADD COLUMN `%s` %s", mysql_real_escape_string($obj->name), mysql_real_escape_string($column->name), $col->get_definition()); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } } if (array_key_exists("updateIndexes", $post)) { $indexes = json_decode($post["updateIndexes"]); foreach ($indexes as $index) { $ind = TableIndex::from_ui($index); if ($index->id != "") { $sql = sprintf("ALTER TABLE `%s` DROP INDEX `%s`", mysql_real_escape_string($obj->name), mysql_real_escape_string($index->id)); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } $sql = sprintf("ALTER TABLE `%s` ADD %s", mysql_real_escape_string($obj->name), $ind->get_definition()); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } } $columns = $this->get_columns(); if (array_key_exists("updateData", $post)) { $rows = json_decode($post["updateData"], true); foreach ($rows as $row) { $set = ""; foreach ($row as $k => $v) { if ($k == "id") { continue; } if ($set != "") { $set .= ","; } if ($v == "") { $nullable = true; foreach ($columns as $col) { if ($col->name == $k) { $nullable = $col->null; } } if (!$nullable) { $set .= "`" . mysql_real_escape_string($k) . "`=''"; } else { $set .= "`" . mysql_real_escape_string($k) . "`=NULL"; } } else { $set .= "`" . mysql_real_escape_string($k) . "`='" . mysql_real_escape_string($v) . "'"; } } if ($row["id"] != null) { $sql = sprintf("UPDATE `%s` SET %s WHERE `id`=%s", mysql_real_escape_string($obj->name), $set, mysql_real_escape_string($row["id"])); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error())); } } else { $sql = sprintf("INSERT INTO `%s` SET %s", mysql_real_escape_string($obj->name), $set); if (!mysql_query($sql)) { return json_encode(array("result" => -6, "message" => mysql_error() . " " . $sql)); } } } } //hash if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $post['oid'] = parent::mysql_save_from_post($post); $obj = $this; if ($this->id == 0) { $obj = self::from_mysql_id($post['oid']); $obj->Owner_id = $post['oid']; $obj->mysql_save(); } if ($post['modify_password'] == 1) { $obj->password = $obj->calculate_password_hash($post['password_hash']); $obj->mysql_save(); } return $post['oid']; }
public function mysql_save_from_post($post) { $lid = parent::mysql_save_from_post($post); $sections = array(); if (isset($post['sections'])) { $sections = json_decode($post["sections"], true); } if ($this->id != 0) { $this->delete_sections(); $this->delete_templates(); $this->delete_object_links(TestVariable::get_mysql_table()); $i = 0; } else { $found = false; foreach ($sections as $section) { if ($section['counter'] == 1) { $found = true; break; } } if (!$found) { $start_section = new TestSection(); $start_section->TestSectionType_id = DS_TestSectionType::START; $start_section->Test_id = $lid; $start_section->counter = 1; $start_section->mysql_save(); } $found = false; foreach ($sections as $section) { if ($section['counter'] == 2) { $found = true; break; } } if (!$found) { $end_section = new TestSection(); $end_section->TestSectionType_id = DS_TestSectionType::END; $end_section->Test_id = $lid; $end_section->counter = 2; $end_section->mysql_save(); } } $i = 0; if (array_key_exists("parameters", $post)) { foreach ($post["parameters"] as $param) { $p = json_decode($param); $var = new TestVariable(); $var->description = $p->description; $var->name = $p->name; $var->index = $i; $var->type = 0; $var->Test_id = $lid; $var->mysql_save(); $i++; } } if (array_key_exists("returns", $post)) { foreach ($post["returns"] as $ret) { $r = json_decode($ret); $var = new TestVariable(); $var->description = $r->description; $var->name = $r->name; $var->index = $i; $var->type = 1; $var->Test_id = $lid; $var->mysql_save(); $i++; } } foreach ($sections as $section) { $s = new TestSection(); $s->counter = $section['counter']; $s->TestSectionType_id = $section['type']; $s->end = $section['end']; $s->Test_id = $lid; $s->parent_counter = $section['parent']; $slid = $s->mysql_save(); $vals = $section['value']; foreach ($vals as $k => $v) { $index = substr($k, 1); $value = $v; $sv = new TestSectionValue(); $sv->TestSection_id = $slid; $sv->index = $index; $sv->value = $value; $sv->mysql_save(); } if ($s->TestSectionType_id == DS_TestSectionType::LOAD_HTML_TEMPLATE) { $ts = TestSection::from_mysql_id($slid); $vals = $ts->get_values(); $template = Template::from_mysql_id($vals[0]); if ($template != null) { $html = Template::output_html($template->HTML, $vals, $template->get_outputs(), $template->get_inserts()); $test_template = new TestTemplate(); $test_template->Test_id = $lid; $test_template->TestSection_id = $slid; $test_template->Template_id = $vals[0]; $test_template->HTML = $html; $test_template->mysql_save(); } } } $sql = sprintf("DELETE FROM `%s` WHERE `Test_id`=%d", TestProtectedVariable::get_mysql_table(), $lid); mysql_query($sql); if (array_key_exists("protected", $post)) { foreach ($post['protected'] as $var) { $var = json_decode($var); $s = new TestProtectedVariable(); $s->name = $var->name; $s->Test_id = $lid; $slid = $s->mysql_save(); } } $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { $simulation = false; if (array_key_exists("save_simulation", $post) && $post['save_simulation'] == 1) { $simulation = true; } $lid = parent::mysql_save_from_post($post); if (!$simulation) { $this->mysql_delete_TableColumn(); } if (array_key_exists("cols", $post)) { if ($simulation) { $table_name = "`" . self::get_table_prefix() . "_temp_" . $lid . "`"; } else { $table_name = "`" . self::get_table_prefix() . "_" . $lid . "`"; } //table if (!$simulation) { $sql = "DROP TABLE IF EXISTS " . $table_name . ";"; mysql_query($sql); } $sql = "CREATE " . ($simulation ? "TEMPORARY" : "") . " TABLE " . $table_name . " ("; $i = 0; $timestamp = false; foreach ($post['cols'] as $col_json) { $col = json_decode($col_json); if ($i > 0) { $sql .= ","; } if (!$timestamp && $col->type == "timestamp") { $timestamp = true; $col->defaultValue = "CURRENT_TIMESTAMP"; $col->attributes = "on update current_timestamp"; $post['cols'][$i] = json_encode($col); } $sql .= "`" . $col->name . "` " . TableColumn::get_column_definition($col->type, $col->lengthValues, $col->attributes, $col->nullable, 0, $col->defaultValue); $i++; } $sql .= ") ENGINE = INNODB DEFAULT CHARSET=utf8;"; if (!mysql_query($sql)) { $message = mysql_error(); return json_encode(array("result" => -6, "message" => $message)); } //indexes if (array_key_exists("indexes", $post)) { foreach ($post['indexes'] as $index_json) { $index = json_decode($index_json); $columns = explode(",", $index->columns); $cols = ""; foreach ($columns as $column) { if ($cols != "") { $cols .= ","; } $cols .= "`" . $column . "`"; } $sql = sprintf("ALTER TABLE %s ADD %s(%s)", $table_name, $index->type, $cols); if (!mysql_query($sql)) { $message = mysql_error(); return json_encode(array("result" => -6, "message" => $message)); } } } //auto increment $auto_increment = false; foreach ($post['cols'] as $col_json) { $col = json_decode($col_json); if ($col->auto_increment == 1) { $auto_increment = true; self::$auto_increment_row_comparer_field = $col->name; $sql = sprintf("ALTER TABLE %s CHANGE `%s` `%s` %s", $table_name, $col->name, $col->name, TableColumn::get_column_definition($col->type, $col->lengthValues, $col->attributes, $col->nullable, $col->auto_increment, $col->defaultValue)); if (!mysql_query($sql)) { $message = mysql_error(); return json_encode(array("result" => -6, "message" => $message)); } } } //TableColumn $sql = "START TRANSACTION"; mysql_query($sql); $sql = sprintf("INSERT INTO `%s` (`index`,`name`,`Table_id`,`type`, `length`,`attributes`, `null`, `auto_increment`, `default_value`) VALUES ", TableColumn::get_mysql_table()); $i = 0; foreach ($post['cols'] as $col_json) { $col = json_decode($col_json); if ($i > 0) { $sql .= ","; } $sql .= "("; $sql .= $i + 1 . ",'" . mysql_real_escape_string($col->name) . "'," . $lid . ",'" . mysql_real_escape_string($col->type) . "', '" . mysql_real_escape_string($col->lengthValues) . "', '" . mysql_real_escape_string($col->attributes) . "', " . mysql_real_escape_string($col->nullable) . "," . mysql_real_escape_string($col->auto_increment) . ",'" . mysql_real_escape_string($col->defaultValue) . "'"; $sql .= ")"; $i++; } if (!mysql_query($sql)) { $message = mysql_error(); $sql = "ROLLBACK"; mysql_query($sql); return json_encode(array("result" => -6, "message" => $message)); } //TableIndex if (array_key_exists("indexes", $post)) { foreach ($post['indexes'] as $index_json) { $index = json_decode($index_json); $columns = explode(",", $index->columns); $ti = new TableIndex(); $ti->Table_id = $lid; $ti->type = $index->type; $ti_lid = $ti->mysql_save(); $i = 0; foreach ($columns as $col) { $tc = TableColumn::from_property(array("Table_id" => $lid, "name" => $col), false); $tic = new TableIndexColumn(); $tic->index = $i; $tic->TableIndex_id = $ti_lid; if ($tc != null) { $tic->TableColumn_id = $tc->id; } $tic->mysql_save(); $i++; } } } //data if (array_key_exists("rows", $post) && $post['rows'] != null && is_array($post['rows'])) { if ($auto_increment) { usort($post['rows'], "self::auto_increment_row_comparer"); } $sql = "INSERT INTO " . $table_name . " ("; $i = 0; foreach ($post['cols'] as $col_json) { if ($i > 0) { $sql .= ","; } $col = json_decode($col_json); $sql .= "`" . $col->name . "`"; $i++; } $sql .= ") VALUES "; for ($a = 0; $a < count($post['rows']); $a++) { $row = json_decode($post['rows'][$a]); if ($a > 0) { $sql .= ","; } $sql .= "("; $i = 0; foreach ($post['cols'] as $col_json) { $col = json_decode($col_json); $col_name = $col->name; if ($row->{$col_name} == "" && $col->nullable == 1) { $row->{$col_name} = null; } if ($i > 0) { $sql .= ","; } if ($row->{$col_name} !== null) { $sql .= "'" . mysql_real_escape_string($row->{$col_name}) . "'"; } else { $sql .= "NULL"; } $i++; } $sql .= ")"; } if (!mysql_query($sql)) { $message = mysql_error(); $sql = "ROLLBACK"; mysql_query($sql); return json_encode(array("result" => -6, "message" => $message)); } } } if (!$simulation) { $sql = "COMMIT"; mysql_query($sql); } else { $sql = "ROLLBACK"; mysql_query($sql); } //hash $obj = static::from_mysql_id($lid); if ($obj != null) { $xml_hash = $obj->calculate_xml_hash(); $obj->xml_hash = $xml_hash; $obj->mysql_save(); } return $lid; }
public function mysql_save_from_post($post) { if ($post['modify_password'] == 1) { $post['md5_password'] = md5($post['password']); } $post['oid'] = parent::mysql_save_from_post($post); if ($this->id == 0 && $post['oid'] != 0) { $obj = self::from_mysql_id($post['oid']); $obj->Owner_id = $post['oid']; $obj->mysql_save(); if ($post['send_credentials'] == 1) { mail($post['email'], "Concerto Platform login credentials.", nl2br($post['welcome']) . "<br/><br/>Your account has been created and you can now log in at: <b>" . Ini::$external_path . "admin</b><br/>Login: <b>" . $post['login'] . "</b><br/>Password: <b>" . $post['password'] . "</b>", "Content-type: text/html; charset=utf-8\r\nFrom: accounts@concerto-platform.org"); } } return $post['oid']; }