public static function isAttributeOfType($attribute, $type) { global $ari; if (OOB_validatetext::isCorrectLength($attribute, 1, MAX_LENGTH)) { $attribute = $ari->db->qMagic($attribute); $type = $ari->db->qMagic($type); $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT True \n\t\t\t FROM Data_Attribute, Data_TypeAttribute \n\t WHERE Data_TypeAttribute.AttributeID = Data_Attribute.ID\n\t AND Data_Attribute.Name = {$attribute}\n\t AND Data_TypeAttribute.TypeID = {$type}\n\t "; //echo $sql;echo "<br><br>"; $rs = $ari->db->Execute($sql); $i = 0; $ari->db->SetFetchMode($savem); if ($rs && !$rs->EOF) { $return = true; } else { $return = false; } $rs->Close(); return $return; } }
/** graba la accion en la base de datos*/ public function store() { global $ari; //clean vars and validation! $this->name = trim($this->name); $this->nicename = trim($this->nicename); //action if (!OOB_validatetext::isNumeric($this->action)) { $ari->error->addError("seguridad_action", "INVALID_ACTION"); } //name if (!OOB_validatetext::isClean($this->name) || !OOB_validatetext::isCorrectLength($this->name, 1, MAX_LENGTH)) { $ari->error->addError("seguridad_action", "INVALID_NAME"); } //nicename if (!OOB_validatetext::isClean($this->nicename) || !OOB_validatetext::isCorrectLength($this->nicename, 1, MAX_LENGTH)) { $ari->error->addError("seguridad_action", "INVALID_NICENAME"); } //permission if (!OOB_validatetext::isNumeric($this->permission->get('permission'))) { $ari->error->addError("seguridad_action", "INVALID_PERMISSION"); } //inmenu if (!OOB_validatetext::isNumeric($this->inmenu)) { $ari->error->addError("seguridad_action", "INVALID_INMENU"); } //valido q no exista la accion if ($this->action == ID_UNDEFINED) { //para nuevo busco uno con el mismo nombre $clausula = ""; } else { //si actualizo busco con el mismo nombre pero con el mismo id $clausula = " AND id <> {$this->action}"; } $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $name = $ari->db->qMagic($this->name); $permissionid = $ari->db->qMagic($this->permission->get('permission')); $sql = "SELECT true as accion FROM security_action \n\t\t\t WHERE name = {$name} and permissionid = {$permissionid} {$clausula}"; $rs = $ari->db->Execute($sql); $ari->db->SetFetchMode($savem); if (!$rs->EOF && !$rs == false) { $rs->Close(); $ari->error->addError("seguridad_action", "DUPLICATE_ACTION"); } // end if if (!$ari->error->getErrorsfor("seguridad_action")) { $name = $ari->db->qMagic($this->name); $nicename = $ari->db->qMagic($this->nicename); $inmenu = $ari->db->qMagic($this->inmenu); if ($this->action > ID_MINIMAL) { // update data $action_id = $ari->db->qMagic($this->action); $ari->db->StartTrans(); $sql = "UPDATE security_action\n\t\t\t\t\t SET Name = {$name},\n\t\t\t\t\t NiceName = {$nicename},\n\t\t\t\t\t PermissionID = {$permissionid},\n\t\t \t\t\t InMenu = {$inmenu},\n\t\t\t\t\t WHERE id = {$action_id}"; $ari->db->Execute($sql); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } else { // insert new and set actionid with new id $ari->db->StartTrans(); $sql = "INSERT INTO security_action \n\t\t\t\t \t (name,nicename,permissionid,inmenu)\n\t\t\t\t VALUES ({$name},\n\t\t\t\t\t\t\t\t{$nicename},\n\t\t\t\t\t\t\t\t{$permissionid},\n\t\t\t\t\t\t\t\t{$inmenu})"; $ari->db->Execute($sql); $this->action = $ari->db->Insert_ID(); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } //end if } else { // no validan los datos return false; //devuelve un objeto de error con los errores! } //end if }
/** Stores/Updates user group object in the DB */ public function store() { global $ari; $flagStore = true; //validate description if (!OOB_validatetext::isClean($this->description)) { $ari->error->addError("seguridad_group", "INVALID_DESCRIPTION"); $flagStore = false; } //validate the data! if (!OOB_validatetext::isClean($this->name) || !OOB_validatetext::isCorrectLength($this->name, 1, MAX_LENGTH)) { $ari->error->addError("seguridad_group", "INVALID_NAME"); $flagStore = false; } if ($this->group == ID_UNDEFINED) { //para nuevo busco uno con el mismo nombre $clausula = ""; } else { //si actualizo busco con el mismo nombre pero con el mismo id $clausula = " AND id <> '{$this->group}'"; } $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $name = $ari->db->qMagic($this->name); $sql = "SELECT true as cuenta FROM security_group WHERE name = {$name} {$clausula}"; $rs = $ari->db->Execute($sql); $ari->db->SetFetchMode($savem); if (!$rs->EOF && $rs) { if ($this->group == ID_UNDEFINED) { //para nuevo // si el grupo con el mismo nombre esta borrado lo activo, sino da instancio un error $sql = "SELECT id FROM security_group WHERE name = {$name} AND Status = '" . DELETED . "'"; $rs->Close(); $rs2 = $ari->db->Execute($sql); if (!$rs2->EOF) { //asigno el id del el objeto que volvi a activar $this->group = $rs2->fields[0]; $this->status = USED; } else { $ari->error->addError("seguridad_group", "DUPLICATE_GROUP"); $flagStore = false; } } else { $ari->error->addError("seguridad_group", "DUPLICATE_GROUP"); $flagStore = false; } } if ($flagStore) { $name = $ari->db->qMagic($this->name); $description = $ari->db->qMagic($this->description); $status = $ari->db->qMagic($this->status); $group_id = $ari->db->qMagic($this->group); if ($this->group > ID_MINIMAL) { // update data $ari->db->StartTrans(); $sql = "UPDATE security_group \n\t\t\t\t\t SET name = {$name}, \n\t\t\t\t\t \t description = {$description}, \n\t\t\t\t\t \t status = {$status} \n\t\t\t\t\t WHERE id = {$group_id}"; $ari->db->Execute($sql); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } else { // insert new and set usergroupid with new id $ari->db->StartTrans(); $sql = "INSERT INTO security_group \n\t\t\t\t\t ( name, description, status)\n\t\t\t\t\t VALUES ( {$name}, {$description}, {$status} )\n\t\t\t\t\t \t"; $ari->db->Execute($sql); $this->group = $ari->db->Insert_ID(); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } } else { // no validan los datos return false; //devuelve un objeto de error con los errores! } }
/** Guarda en la BD el objeto rol */ public function store() { global $ari; // clean vars ! if (!OOB_validatetext::isClean($this->name) || !OOB_validatetext::isCorrectLength($this->name, 1, MAX_LENGTH)) { $ari->error->addError("seguridad_role", "INVALID_NAME"); } if (!OOB_validatetext::isClean($this->description)) { $ari->error->addError("seguridad_role", "INVALID_DESCRIPTION"); } if ($this->role == ID_UNDEFINED) { //para nuevo busco uno con el mismo nombre $clausula = ""; } else { //si actualizo busco con el mismo nombre pero con el mismo id $clausula = " AND id <> {$this->role}"; } $name = $ari->db->qMagic($this->name); $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT true as cuenta FROM `Security_Role` \n\t\t\t WHERE `Name` = {$name} {$clausula}"; $rs = $ari->db->Execute($sql); $ari->db->SetFetchMode($savem); if (!$rs->EOF && $rs->fields[0] != 0) { if ($this->role == ID_UNDEFINED) { //para nuevo // si el rol con el mismo nombre esta borrado lo activo, sino da instancio un error $sql = "SELECT `ID` \n\t\t\t\t\t FROM `Security_Role` \n\t\t\t\t\t WHERE `Name` = {$name} \n\t\t\t\t\t AND `Status` = '" . DELETED . "'"; $rs->Close(); $rs2 = $ari->db->Execute($sql); if (!$rs2->EOF) { //asigno el id del el objeto que volvi a activar $this->role = $rs2->fields[0]; $this->status = USED; } else { $ari->error->addError("seguridad_role", "DUPLICATE_ROLE"); } } else { $ari->error->addError("seguridad_role", "DUPLICATE_ROLE"); } } if (!$ari->error->getErrorsfor("seguridad_role")) { $name = $ari->db->qMagic($this->name); $description = $ari->db->qMagic($this->description); $status = $ari->db->qMagic($this->status); $anonymous = $ari->db->qMagic($this->anonymous); $trustees = $ari->db->qMagic($this->trustees); $role = $ari->db->qMagic($this->role); if ($this->role > ID_MINIMAL) { // update data $ari->db->StartTrans(); $sql = "UPDATE `Security_Role` \n\t\t\t\t\t SET `Name` = {$name}, \n\t\t\t\t\t \t `Description` = {$description}, \n\t\t\t\t\t \t `Status` = {$status}, \n\t\t\t\t\t \t `Anonymous` = {$anonymous},\n\t\t\t\t\t \t `Trustees` = {$trustees}\n\t\t\t\t\t WHERE `ID` = {$role}"; $ari->db->Execute($sql); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } else { // insert new and set roleid with new id $ari->db->StartTrans(); $sql = "INSERT INTO `Security_Role` \n\t\t\t\t\t ( `Name`, `Description`, `Status`, `Anonymous`, `Trustees`)\n\t\t\t\t\t VALUES ( {$name}, {$description}, {$status}, {$anonymous}, {$trustees} )\n\t\t\t\t\t "; $ari->db->Execute($sql); $this->role = $ari->db->Insert_ID(); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } } else { return false; //devuelve un objeto de error con los errores! } }
/** Returns true if the languafe ê\ang is a member of the currency */ public function isMember($lang) { global $ari; if (OOB_validatetext::isCorrectLength($lang, 1, MAX_LENGTH)) { $lang = $ari->db->qMagic($lang); $sql = "SELECT True \n \t\t FROM Currency_CurrencyLanguage \n \t\t WHERE CurrencyID = '{$this->id}' \n \t\t AND Language = {$lang}"; $rs = $ari->db->Execute($sql); if (!$rs->EOF && $rs) { $return = true; } else { $return = false; } } else { $ari->error->addError("currency_currency", "INVALID_LANGUAGE"); } $rs->Close(); if (!$ari->error->getErrorsfor("currency_currency")) { return $return; } else { return false; } }
public function store($datos = array(), $type = "TYPE") { global $ari; // clean vars ! $this->name = trim($this->name); if (!OOB_validatetext::isClean($this->name) || !OOB_validatetext::isCorrectLength($this->name, 1, MAX_LENGTH)) { $ari->error->addError(strtolower($this->class), "INVALID_NAME"); } if (!OOB_validatetext::isClean($this->description) || !OOB_validatetext::isCorrectLength($this->description, 1, MAX_LENGTH)) { //$ari->error->addError (strtolower($this->class), "INVALID_DESCRIPTION"); } if (!$ari->error->getErrorsfor($this->class)) { $id = $ari->db->qMagic($this->id); $name = $ari->db->qMagic($this->name); if ($this->id == ID_UNDEFINED) { //para nuevo busco uno con el mismo nombre $clausula = ""; } else { //si actualizo busco con el mismo nombre pero con el mismo id $clausula = " AND id <> {$id} "; } $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT true as cuenta FROM {$this->table} WHERE `Name` = {$name} {$clausula}"; $rs = $ari->db->Execute($sql); $ari->db->SetFetchMode($savem); if (!$rs->EOF && $rs->fields[0] != 0) { if ($this->id == ID_UNDEFINED) { //para nuevo $status = $ari->db->qMagic(DELETED); // si el rol con el mismo nombre esta borrado lo activo, sino da instancio un error $sql = "SELECT id FROM {$this->table} WHERE `Name` = {$name} AND Status = {$status} "; $rs->Close(); $rs2 = $ari->db->Execute($sql); if (!$rs2->EOF) { //asigno el id del el objeto que volvi a activar $this->id = $rs2->fields[0]; $id = $ari->db->qMagic($this->id); // $this->status = USED; } else { $ari->error->addError(strtolower($this->class), "DUPLICATE_" . $type); } } else { $ari->error->addError(strtolower($this->class), "DUPLICATE_" . $type); } } } //-- if (!$ari->error->getErrorsfor($this->class)) { $name = $ari->db->qMagic($this->name); $description = $ari->db->qMagic($this->description); $status = $ari->db->qMagic($this->status); if ($this->id > ID_MINIMAL) { $update = ""; foreach ($datos as $item) { $item['value'] = $ari->db->qMagic($item['value']); $update .= ",`" . $item['field'] . "` = " . $item['value']; } // update data $ari->db->StartTrans(); $sql = "UPDATE {$this->table} \n\t\t\t\t\t SET `Name` = {$name}, `Description` = {$description}, \n\t\t\t\t\t\t `Status` = {$status} {$update} WHERE id = {$id}\n\t\t\t\t\t\t "; $ari->db->Execute($sql); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } else { // insert new and set roleid with new id $ari->db->StartTrans(); $fields = ""; $values = ""; foreach ($datos as $item) { $fields .= ",`" . $item['field'] . "`"; $item['value'] = $ari->db->qMagic($item['value']); $values .= "," . $item['value']; } $sql = "INSERT INTO {$this->table} \n\t\t\t\t\t ( `Name`, `Description`, `Status` {$fields})\n\t\t\t\t\t VALUES \n\t\t\t\t\t ( {$name}, {$description}, {$status} {$values})\n\t\t\t\t\t\t"; $ari->db->Execute($sql); $this->id = $ari->db->Insert_ID(); if (!$ari->db->CompleteTrans()) { throw new OOB_exception("Error en DB: {$ari->db->ErrorMsg()}", "010", "Error en la Base de Datos", false); } else { return true; } } } else { // no validan los datos return false; } }