function save($id, $account) { // Update .... if (!$account['isNew']) { $this->db->update('person', ["firstname" => $account['firstname'], "lastname" => $account['lastname']], "id = '{$id}'"); $this->db->update('accountrole', ["role" => $account['role']], "accountid = '{$id}'"); if (isset($account['password']) && strlen($account['password']) > 5) { $this->db->update('account', ["password" => md5($account['password'])], "id = '{$id}'"); } else { $this->latestErr = "Password didn't match or shoter than 5 characters."; return false; } } else { $username = $account['username']; $this->db->from('account'); $this->db->where('username', $username); if (count($this->db->get()->result())) { $this->latestErr = "Email has already taken."; return false; } $this->db->insert('account', buildBaseParam(["id" => $id, "username" => $account['username'], "password" => md5($account['password']), "status" => 0], $id)); $this->db->insert('person', buildBaseParam(["id" => $id, "firstname" => $account['firstname'], "lastname" => $account['lastname']], $id)); $this->db->insert('accountrole', buildBaseParam(["id" => gen_uuid(), "accountid" => $id, "role" => strtolower($account['role'])], $id)); } return true; }
function save($id, $color) { // Update .... if (!$color['isNew']) { $this->db->update('pattern', ["name" => $color['name']], "id = '{$id}'"); } else { $this->db->insert('pattern', buildBaseParam(["id" => $id, "name" => $color['name']], $id)); } }
function save($id, $color) { // Update .... if (!$color['isNew']) { $this->db->update('color', ["name" => $color['name']], "id = '{$id}'"); } else { $this->db->insert('color', buildBaseParam(["id" => $id, "name" => $color['name']], $this->session->userdata('id'))); } }
function save($id, $record) { // Update .... if (!$record['isNew']) { $this->db->update('system', ["name" => $record['name'], "saleprice" => $record['saleprice'], "status" => $record['status'], "share" => $record['share']], "id = '{$id}'"); // Colors // Remove all colors first. $this->db->delete('systemdetail', ['systemid' => $id]); } else { $this->db->insert('system', buildBaseParam(["id" => $id = gen_uuid(), "name" => $record['name'], "saleprice" => $record['saleprice'], "status" => $record['status'], "share" => $record['share']], $this->session->userdata('id'))); } $selIngs = json_decode($record['selIngs']); $arrSelectedIngs = []; foreach ($selIngs as $key => $val) { if ($val->checked) { array_push($arrSelectedIngs, buildBaseParam(['systemid' => $id, 'ingredientid' => $key, 'extra' => $val->extra, 'factor' => $val->factor, 'id' => gen_uuid(), 'status' => 1], $this->session->userdata('id'))); } } // Re-add all colors. if (count($arrSelectedIngs)) { $this->db->insert_batch('systemdetail', $arrSelectedIngs); } }
function save($id, $ingredient) { // Update .... if (!$ingredient['isNew']) { $this->db->update('ingredient', ["name" => $ingredient['name'], "coverage" => $ingredient['coverage'], "purchaseprice" => $ingredient['purchaseprice']], "id = '{$id}'"); } else { $this->db->insert('ingredient', buildBaseParam(["id" => $id = gen_uuid(), "name" => $ingredient['name'], "coverage" => $ingredient['coverage'], "purchaseprice" => $ingredient['purchaseprice']], $this->session->userdata('id'))); } // Colors // Remove all colors first. $this->db->delete('ingredientcolor', ['ingredientid' => $id]); $selColors = json_decode($ingredient['selCols']); $arrSelectedColors = []; foreach ($selColors as $key => $val) { if ($val == 1) { array_push($arrSelectedColors, buildBaseParam(['colorid' => $key, 'ingredientid' => $id, 'id' => gen_uuid()], $this->session->userdata('id'))); } } // Re-add all colors. if (count($arrSelectedColors)) { $this->db->insert_batch('ingredientcolor', $arrSelectedColors); } // Patterns // Remove all patterns first. $this->db->delete('ingredientpattern', ['ingredientid' => $id]); $selPatterns = json_decode($ingredient['selPats']); $arrSelectedPatterns = []; foreach ($selPatterns as $key => $val) { if ($val == 1) { array_push($arrSelectedPatterns, buildBaseParam(['patternid' => $key, 'ingredientid' => $id, 'id' => gen_uuid()], $this->session->userdata('id'))); } } // Re-add all colors. if (count($arrSelectedPatterns)) { $this->db->insert_batch('ingredientpattern', $arrSelectedPatterns); } }