Example #1
0
 public function EditEntity($bo)
 {
     $db = new Database();
     $newID = UUID::newID();
     $ID = str_replace("sys", "", $bo["EntityName"]) . "id";
     if ($bo[$ID] != null) {
         $values = SqlHelper::GetUpdates(explode(",", $bo["EntityFields"]), $bo);
         $sql = 'UPDATE ' . $bo["EntityName"] . ' SET ' . $values . ' WHERE ' . $ID . ' = "' . $bo[$ID] . '"';
     } else {
         //
         $fields = str_replace($ID . ",", "", $bo["EntityFields"]);
         $values = SqlHelper::GetValues(explode(",", $fields), $bo);
         $sql = 'INSERT INTO ' . $bo["EntityName"] . '(' . $ID . ',' . $fields . ')' . ' VALUES("' . $newID . '",' . $values . ')';
         //table
         if ($bo["EntityName"] == 'sysentity') {
             $table = ';CREATE TABLE IF NOT EXISTS ' . $bo["Name"] . '(' . $bo["Name"] . 'ID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (' . $bo["Name"] . 'ID))ENGINE = InnoDB';
             $sql .= $table;
         }
         if ($bo["EntityName"] == 'sysproperty') {
             $result = $db->RunSQL('SELECT Name FROM SysEntity WHERE EntityID = ' . $bo["EntityID"]);
             $table = ';ALTER TABLE ' . $result[0]['Name'] . ' ADD COLUMN ' . $bo["Name"] . ' VARCHAR(45) NULL ';
             $sql .= $table;
         }
     }
     $result = $db->ExecuteSQL($sql);
     return $this->GetEntityView($bo["RefreshEntityViewID"], array("id" => $newID));
 }
Example #2
0
 public function GetCustomFields($bo)
 {
     $sql = ' SELECT  * FROM CustomField WHERE Archive = 0' . ($bo["filter"] != null ? ' AND Name LIKE "%' . $bo["filter"] . '%"' : "");
     $db = new Database();
     $result = $db->RunSQL($sql);
     $ret = JSONHelper::GetJSON($result, 'records');
     return $ret;
 }
Example #3
0
 public function EditEntity($bo)
 {
     $db = new Database();
     $newID = UUID::newID();
     $propertyID = UUID::newID();
     $ID = str_replace("sys", "", $bo["entityname"]) . "id";
     $ID_Field = str_replace("sys", "", $bo["name"]) . "id";
     //$sql = "START TRANSACTION;";
     if ($bo[$ID] != null) {
         $values = SqlHelper::GetUpdates(explode(",", $bo["EntityFields"]), $bo);
         $sql .= 'UPDATE ' . $bo["entityname"] . ' SET ' . $values . ' WHERE ' . $ID . ' = "' . $bo[$ID] . '"';
         //echo $sql;
     } else {
         //
         $fields = str_replace("," . $ID . ",", ",", "," . $bo["EntityFields"] . ",");
         $fields = substr($fields, 1, $fields . length - 1);
         $values = SqlHelper::GetValues(explode(",", $fields), $bo);
         $sql .= 'INSERT INTO ' . $bo["entityname"] . '(' . $ID . ',' . $fields . ') VALUES("' . $newID . '",' . $values . ')';
         //echo $sql;
         //table
         if ($bo["entityname"] == 'sysentity') {
             $sql .= ';INSERT INTO sysproperty(propertyid, entityid, name) VALUES("' . $propertyID . '","' . $newID . '", "' . $ID_Field . '")';
             $table = ';CREATE TABLE IF NOT EXISTS ' . $bo["name"] . '(' . $ID_Field . ' VARCHAR(100) NOT NULL, ' . ' createddate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, ' . 'PRIMARY KEY (' . $ID_Field . '))ENGINE = InnoDB';
             $sql .= $table;
             //echo $sql;
         }
         if ($bo["entityname"] == 'sysproperty' && !$bo["isonlyview"]) {
             $columnType = ' VARCHAR(255) NULL';
             if ($bo["xtype"] == "numberfield") {
                 $columnType = ' INT NULL';
             } else {
                 if ($bo["xtype"] == "datefield") {
                     $columnType = ' DATETIME NULL';
                 } else {
                     if ($bo["xtype"] == "textareafield") {
                         $columnType = ' TEXT NULL';
                     } else {
                         if ($bo["xtype"] == "checkboxfield") {
                             $columnType = ' BOOL NULL';
                         } else {
                             if ($bo["xtype"] == "htmleditor") {
                                 $columnType = ' TEXT NULL';
                             }
                         }
                     }
                 }
             }
             $result = $db->RunSQL('SELECT name FROM sysentity WHERE entityid = "' . $bo["entityid"] . '"');
             $table = ';ALTER TABLE ' . $result[0]['name'] . ' ADD COLUMN ' . $bo["name"] . ' ' . $columnType;
             $sql .= $table;
         }
     }
     //$sql .= ';COMMIT;';
     //echo $sql;
     $entity = array("entityViewID" => $bo["RefreshEntityViewID"]);
     $result = $db->ExecuteSQL($sql);
     return $this->GetEntityView($entity);
 }
Example #4
0
 public function UpdateDNFCode($bo)
 {
     $sql = 'SELECT rb.raceboatid, bs.formula as formula, rb.divisionid FROM raceboat rb INNER JOIN boatstatus bs ON bs.boatstatusid = rb.boatstatusid WHERE length(rb.boatstatusid) > 0 AND raceid = "' . $bo . '"';
     $db = new Database();
     $result = $db->RunSQL($sql);
     foreach ($result as $boat) {
         if (strpos($boat['formula'], 'CountS') !== false) {
             $sql = 'SELECT COUNT(*) as c FROM raceboat WHERE signondate is not null AND raceid = "' . $bo . '" and divisionid = "' . $boat['divisionid'] . '"';
             $result2 = $db->RunSQL($sql);
             $f = str_replace("CountS", $result2[0]['c'], $boat['formula']);
             $sql2 = 'UPDATE raceresult SET score = ' . $f . ' where raceboatid = "' . $boat['raceboatid'] . '"';
             $result2 = $db->RunSQL($sql2);
         }
         if (strpos($boat['formula'], 'CountR') !== false) {
             $sql = 'SELECT COUNT(*) as c FROM raceboat WHERE signondate is not null AND raceid = "' . $bo . '" and divisionid = "' . $boat['divisionid'] . '"';
             $result2 = $db->RunSQL($sql);
             $f = str_replace("CountR", $result2[0]['c'], $boat['formula']);
             $sql2 = 'UPDATE raceresult SET score = ' . $f . ' where raceboatid = "' . $boat['raceboatid'] . '"';
             $result2 = $db->RunSQL($sql2);
         }
         if (strpos($boat['formula'], 'CountFEx') !== false) {
             $sql = 'SELECT COUNT(*) as c FROM raceboat WHERE signondate is not null AND raceid = "' . $bo . '" and divisionid = "' . $boat['divisionid'] . '"';
             $result2 = $db->RunSQL($sql);
             $f = str_replace("CountFex", $result2[0]['c'], $boat['formula']);
             $sql2 = 'UPDATE raceresult SET score = ' . $f . ' where raceboatid = "' . $boat['raceboatid'] . '"';
             $result2 = $db->RunSQL($sql2);
         }
         if (strpos($boat['formula'], 'CountFInc') !== false) {
             $sql = 'SELECT COUNT(*) as c FROM raceboat WHERE signondate is not null AND raceid = "' . $bo . '" and divisionid = "' . $boat['divisionid'] . '"';
             $result2 = $db->RunSQL($sql);
             $f = str_replace("CountFInc", $result2[0]['c'], $boat['formula']);
             $sql2 = 'UPDATE raceresult SET score = ' . $f . ' where raceboatid = "' . $boat['raceboatid'] . '"';
             $result2 = $db->RunSQL($sql2);
         }
     }
     $ret = JSONHelper::GetJSON($result, 'records');
     return $ret;
 }
Example #5
0
 public function SaveBoatSeries($bo)
 {
     $db = new Database();
     //races
     $id = UUID::newID();
     $bo['raceseriesboatid'] = $id;
     $bo['status'] = 'New';
     $sql = SqlHelper::PrepareSQL($bo, 'insert into raceseriesboat(raceseriesboatid, raceseriesid, boatid, status, type)' . ' values("{raceseriesboatid}", "{raceseriesid}", "{boatid}", "{status}", "{type}")');
     $db->RunSQL($sql);
     $ret = JSONHelper::GetJSON(array("raceseriesboatid" => $id), 'result');
     return $ret;
 }