function benarkanRoleAcc() { $role2Acc = new Role2Account(); $arr = $role2Acc->getAll(); $arrSudah = array(); global $db; foreach ($arr as $n => $v) { if (!in_array($v->role_admin_id, $arrSudah)) { //kalau blom di kerjakan, add dan hapus $arrSudah[] = $v->role_admin_id; $q = "DELETE FROM {$role2Acc->table_name} WHERE role_admin_id = '{$v->role_admin_id}' AND rc_id != '{$v->rc_id}'"; echo $db->query($q, 0); } } }
public function loadRole() { global $db; //getRoles $r2a = new Role2Account(); $role2acc = $r2a->getRoles($this->admin_id); $_SESSION["roles"] = array(); foreach ($role2acc as $x) { $role = $x->role_id; if (!in_array($role, $_SESSION["roles"]) && isset($role)) { $_SESSION["roles"][] = $role; } } /* * LOAD smaller roles */ $r2r = new Role2Role(); $udahdi = array(); $sem = sizeof($_SESSION['roles']) ? $_SESSION["roles"] : array(); while (sizeof($sem) > 0) { $r = array_pop($sem); if (!in_array($r, $udahdi)) { $role2role = $r2r->getSmallerRoles($r); foreach ($role2role as $ri) { if (!in_array($ri->role_small, $_SESSION["roles"]) && $ri->role_small != "") { $_SESSION["roles"][] = $ri->role_small; $sem[] = $ri->role_small; } } $udahdi[] = $r; } } $this->roles = $_SESSION['roles']; }
public function updater() { $id = TextP::postP("id", ""); $name = TextP::postP("name", ""); $lvl = TextP::postP("lvl", ""); $org = TextP::postP("org", ""); $role = TextP::postP("role", ""); $json = array(); $json['post'] = $_POST; $json['isi'][] = $role; $json['isi'][] = $name; $json['isi'][] = $lvl; $json['isi'][] = $org; $json['isi'][] = $id; $json['bool'] = 0; if ($id == "" || $name == "" || $lvl == "" || $org == "" || $role == "") { $json['err'] = Lang::t('Please provide all data'); die(json_encode($json)); } $acc = new Account(); $acc->getByID($id); $acc->admin_nama_depan = urldecode($name); $acc->admin_role = urldecode($role); $acc->load = 1; $suc = $acc->save(); $json['isi'][] = $suc; //if($suc){ //update role2acc $role2acc = new Role2Account(); $arrR2c = $role2acc->getWhere("role_admin_id = '{$id}' LIMIT 0,1"); $role2acc->getByID($arrR2c[0]->rc_id); $role2acc->role_id = $role; $role2acc->load = 1; $suc2 = $role2acc->save(); $json['isi'][] = $suc2; //if($suc2){ //update lvl dan org $am = new AccountMeta(); $arrMeta = $am->getWhere("account_id = {$id}"); if (count($arrMeta) < 1) { //create new $am2 = new AccountMeta(); $am2->account_id = $id; $am2->meta_key = "RoleLevel"; $am2->meta_value = $lvl; $am2->save(); //create new $am2 = new AccountMeta(); $am2->account_id = $id; $am2->meta_key = "RoleOrganization"; $am2->meta_value = $org; $am2->save(); } else { foreach ($arrMeta as $mt) { if ($mt->meta_key == "RoleLevel") { $am2 = new AccountMeta(); $am2->getByID($mt->meta_id); $am2->meta_value = $lvl; $am2->load = 1; $am2->save(); } if ($mt->meta_key == "RoleOrganization") { $am2 = new AccountMeta(); $am2->getByID($mt->meta_id); $am2->meta_value = $org; $am2->load = 1; $am2->save(); } } } // } $json['bool'] = $suc2; //} die(json_encode($json)); }