public function array_to_csv($values) { $header = ""; $body = ""; $header = implode(CHAR_CSVEXPORT, $this->columns_title); foreach ($values as $value) { $rows = array(); foreach ($this->columns as $name) { if (isset($value[$name])) { $rows[] = OOB_validatetext::cleanToExport($value[$name]); } else { $rows[] = ""; } } $body .= implode(CHAR_CSVEXPORT, $rows); $body .= "\n"; } //end each $this->csv = $header . "\n" . $body; }
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; } }
*/ /* Url Handler for Admin MODULE */ global $ari; $handle = $ari->url->getVars(); switch ($handle[0]) { //-- case "selector": { if (OOB_validatetext::isClean($_POST['modulo']) && $_POST['modulo'] != "/" ) header( "Location: " . $ari->get('adminaddress') ."/" . $_POST['modulo']); else throw new OOB_exception('', "404", 'Selecione un modulo válido.'); break; } case "menu": { include ($ari->module->admindir() . DIRECTORY_SEPARATOR . "menu.php"); } break; case "newtab": {
/** 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! } }
<?php #OOB/N1 Framework [2008 - Nutus] - PM // Codigo por JPCOSEANI // Script que procesa los datos del FORM UPDATE ROLE global $ari; $ari->popup = 1; $resultado = array(); $resultado["errors"] = array(); $resultado["success"] = false; if (isset($_POST['id'])) { //id if (OOB_validatetext::isNumeric($_POST['id'])) { $role = new seguridad_role($_POST['id']); } else { throw new OOB_exception("INVALID_ID_VALUE", "501", "INVALID_ID_VALUE", false); } //nombre $role->set('name', $_POST['txt_nombre']); //descripcion $role->set('description', $_POST['txt_descripcion']); //anonimo if (isset($_POST['chk_anonimo'])) { $role->set('anonymous', ANONIMO); } else { $role->set('anonymous', NO_ANONIMO); } //confiable if (isset($_POST['chk_confiados'])) { $role->set('trustees', YES); } else {
/** Lista los usuarios miembros de los roles que se encuentran * en el array $roles pasado como paramentro y que tengan el * estado = USED, ademas lista los usuarios q se encuentren en algun * grupo q sea miembro del algun rol pasado como parametro * */ public static function listAllUsersFor($roles) { global $ari; $roles_array = array(); //si no es array el parametro lo transformo en uno if (!is_array($roles)) { $roles_array[0] = $roles; } else { $roles_array = $roles; } //recorro el array, y formo la clausula solo con los id // de los objetos seguridad_role para usarlo en la clausula in $in_string = ""; $flagFirst = true; foreach ($roles_array as $r) { if (is_a($r, "seguridad_role")) { if ($flagFirst) { $in_string .= $ari->db->qMagic($r->get('role')); $flagFirst = false; } else { $in_string .= ',' . $ari->db->qMagic($r->get('role')); } } //end if } //end foreach if ($in_string == "") { $ari->error->addError("seguridad_role", "INVALID_ROLE"); return false; } $savem = $ari->db->SetFetchMode(ADODB_FETCH_ASSOC); //armo la consulta para traer los usuarios miembros del rol $sql1 = "SELECT `OOB_User_User`.`ID`, `OOB_User_User`.`Uname`, \n\t\t\t\t\t `OOB_User_User`.`Password`, `OOB_User_User`.`Email`, \n\t\t\t\t `OOB_User_User`.`Connections`, `OOB_User_User`.`Status`, \n\t\t\t\t `OOB_User_User`.`EmployeeID` \n\t\t\t\tFROM `Security_UsersRole`, `OOB_User_User`\n WHERE `Security_UsersRole`.`UserID` = `OOB_User_User`.`ID`\n\t\t\t\tAND `Security_UsersRole`.`RoleID` IN ({$in_string}) \n\t\t\t\tAND `OOB_User_User`.`Status` = '" . USED . "' \n\t\t\t\t"; //armo la consulta para traer los usuarios miembros de algun grupo q sea //miembro de algun rol $sql2 = "SELECT `OOB_User_User`.`ID`, `OOB_User_User`.`Uname`, \n\t\t\t\t\t `OOB_User_User`.`Password`, `OOB_User_User`.`Email`, \n\t\t\t\t `OOB_User_User`.`Connections`, `OOB_User_User`.`Status`, \n\t\t\t\t `OOB_User_User`.`EmployeeID` \n\t\t\t\t FROM `OOB_User_User`, `Security_UsersGroup`\n\t\t\t\t WHERE `Security_UsersGroup`.`UserID` = `OOB_User_User`.`ID`\n\t\t\t\t AND `OOB_User_User`.`Status` = '" . USED . "' \n\t\t\t\t AND `Security_UsersGroup`.`GroupID` IN \n\t\t\t\t ( SELECT `Security_GroupsRole`.`GroupID` \n\t\t\t\t FROM `Security_GroupsRole` \n\t\t\t\t WHERE `Security_GroupsRole`.`RoleID` IN ({$in_string}) )\n\t\t\t\t ORDER BY 2"; $sql = $sql1 . " UNION " . $sql2; $rs = $ari->db->Execute($sql); $i = 0; $ari->db->SetFetchMode($savem); if ($rs && !$rs->EOF) { while (!$rs->EOF) { $return[$i] = new oob_user(ID_UNDEFINED); $return[$i]->set("user", $rs->fields["ID"]); $return[$i]->set("uname", $rs->fields["Uname"]); $return[$i]->set("password", $rs->fields["Password"]); $return[$i]->set("email", $rs->fields["Email"]); $return[$i]->set("maxcon", $rs->fields["Connections"]); $return[$i]->set("status", $rs->fields["Status"]); if (!empty($rs->fields['EmployeeID']) && OOB_validatetext::isNumeric($rs->fields['EmployeeID']) && $rs->fields['EmployeeID'] > ID_MINIMAL) { $return[$i]->set('employee', new personnel_employee($rs->fields['EmployeeID'])); } $i++; $rs->MoveNext(); } } else { $return = false; } $rs->Close(); return $return; }
$desde = false; if (isset($_POST['desdeYear']) && isset($_POST['desdeMonth']) && isset($_POST['desdeDay'])) { //begin if $fecha = $_POST['desdeYear'] . "-"; $fecha .= OOB_validatetext::addZero($_POST['desdeMonth']) . "-"; $fecha .= OOB_validatetext::addZero($_POST['desdeDay']); $fecha .= ' 00:00:00'; $desde = new Date($fecha); } //fecha hasta $hasta = false; if (isset($_POST['hastaYear']) && isset($_POST['hastaMonth']) && isset($_POST['hastaDay'])) { //begin if $fecha = $_POST['hastaYear'] . "-"; $fecha .= OOB_validatetext::addZero($_POST['hastaMonth']) . "-"; $fecha .= OOB_validatetext::addZero($_POST['hastaDay']); $fecha .= ' 23:59:59'; $hasta = new Date($fecha); } //VALIDACIONES $errores = array(); //verificar datos enviados duplicados if (!$sp->Validar()) { $errores[] = 'SENT_DUPLICATE_DATA'; } //validar fechas if ($desde) { if (!contenido_estructura::isValidDate($desde)) { $errores[] = "INVALID_DESDE"; } }
$ari->t->assign("newName", ""); $ari->t->assign("newNiceName", ""); } else { //verificar datos enviados duplicados if (!$sp->Validar()) { $ari->error->addError('seguridad_permission', 'SENT_DUPLICATE_DATA'); } $permiso = new seguridad_permission(); $permiso->set('modulename', $_POST['cboModulo']); $permiso->set('name', $_POST['txtName']); $permiso->set('nicename', $_POST['txtNiceName']); //stores? if ($permiso->store()) { header("Location: " . $ari->get("adminaddress") . '/seguridad/permission/new'); exit; } else { $ari->t->assign("form", true); $ari->t->assign("error", true); $errores = $ari->error->getErrorsfor("seguridad_permission"); foreach ($errores as $error) { $ari->t->assign($error, true); } //refrescar template $name = OOB_validatetext::inputHTML($_POST['txtName']); $ari->t->assign("newName", $name); $niceName = OOB_validatetext::inputHTML($_POST['txtNiceName']); $ari->t->assign("newNiceName", $niceName); } } $ari->t->assign("formElement", $sp->FormElement()); $ari->t->display($ari->module->admintpldir() . "/permission_new.tpl");
//cargo el array refrescados $r = 0; for ($k = 0; $k < count($_POST['modulo']); $k++) { //me fijo si el elemento posteado actual es del modulo q recorro //if ($_POST['modulo'][$k] == $m->name() && //OOB_validatetext :: isClean($_POST['accion'][$k]) && //OOB_validatetext :: isCorrectLength ($_POST['accion'][$k], 1, MAX_LENGTH) ) //me fijo si el elemento posteado actual es del modulo q recorro if ($_POST['modulo'][$k] == $m->name()) { //lo cargo en el array de refrescados $refrescados[$r]['row'] = $k * -1; $refrescados[$r]['modulo'] = $_POST['modulo'][$k]; $refrescados[$r]['permiso'] = $_POST['permiso'][$k]; $accion = OOB_validatetext::inputHTML($_POST['accion'][$k]); $refrescados[$r]['accion'] = $accion; $nicename = OOB_validatetext::inputHTML($_POST['nicename'][$k]); $refrescados[$r]['nicename'] = $nicename; $refrescados[$r]['inmenu'] = $_POST['inmenu'][$k]; //busco el nombre del permiso $refrescados[$r]['permisoName'] = ""; foreach ($objPermiso as $p) { if ($p->get('permission') == $_POST['permiso'][$k]) { $refrescados[$r]['permisoName'] = $p->get("nicename"); break; } } $r++; } //end if } //end for
global $ari; $handle = $ari->url->getVars(); $ari->t->caching = 0; $ari->popup = true; // valida pos $pos = 0; if (isset($_GET['pos']) && OOB_validatetext::isNumeric($_GET['pos']) && $_GET['pos'] > 0) { $pos = $_GET['pos']; } //levanta el limit $modulo = new oob_module("personnel"); $limit = $modulo->config()->get('limit', 'employee'); $ari->t->assign('limit', $limit); $ari->t->assign('total', oob_user::userCountNoAsigned()); $users = array(); if ($return = oob_user::listNoAssigned('uname', $pos, $limit)) { // show time $i = 0; foreach ($return as $u) { $users[$i]['id'] = $u->get('user'); $users[$i]['uname'] = $u->name(); $users[$i]['unameClean'] = OOB_validatetext::cleanToScript($u->name()); $users[$i]['email'] = $u->get('email'); $users[$i]['status'] = oob_user::getStatus($u->get('status')); ++$i; } } //end if $ari->t->assign("users", $users); // display $ari->t->display($ari->module->admintpldir() . "/user_selectforemployee.tpl");
* Created on 22/07/2008 * @author Pablo Micolini (pablo.micolini@nutus.com.ar) */ global $ari; $plantilla_bl = $ari->newTemplate(); $plantilla_bl->caching = 0; // dynamic content $language = $ari->get('agent')->getLang(); //var_dump($params);exit; //validar parametros del bloque $currency_selected = false; if (isset($params['currencyID']) && OOB_validatetext::isNumeric($params['currencyID']) && $params['currencyID'] > 0) { $currency_selected = $params['currencyID']; } $value = ''; if (isset($params['value']) && OOB_validatetext::isNumeric($params['value'])) { $value = $params['value']; } $prefix = 'currency'; if (isset($params['prefix'])) { $prefix = $params['prefix']; } if ($currencies = currency_currency::listCurrenciesForLanguage(USED, 'name', $operator = OPERATOR_EQUAL, $language)) { $i = 0; foreach ($currencies as $c) { $array_currencies[$c->get('id')] = $c->get('name') . " (" . $c->get('sign') . ")"; if ($currency_selected === false && $c->get('default') == YES) { $currency_selected = $c->get('id'); } $i++; }
$ari->t->assign("address_state_id", $state->get('id')); $ari->t->assign("address_state_name", $state->get('name')); } else { $errores[] = "NO_STATE"; } if (!isset($_POST['destiny'])) { $errores[] = "NO_DESTINY_OPTION"; } else { //verifico si el destino es uno nuevo o existente if ($_POST['destiny'] == ID_UNDEFINED) { //destino nuevo $destiny = new address_city(ID_UNDEFINED); $destiny->set("state", $state); $destiny->set("status", USED); if (isset($_POST['new_name'])) { $new_name = OOB_validatetext::inputHTML($_POST['new_name']); $ari->t->assign("new_name", $new_name); $destiny->set("name", $new_name); //$errores[] = "INVALID_DESTINY_NEW"; } //var_dump($destiny);exit; if (!$destiny->isValid()) { $errores[] = "INVALID_OBJECT"; } $new_city = true; } else { //destino existente if (isset($_POST['address_city'][0]) && $_POST['address_city'][0] != "" && $_POST['address_city'][0] != ID_UNDEFINED) { $destiny = new address_city($_POST['address_city'][0]); $ari->t->assign("address_city_id", $destiny->get('id')); $ari->t->assign("address_city_name", $destiny->get('name'));
/** * Returns true if successful, false if not. */ public function addChange($value, $date = false) { global $ari; $flagStore = true; if (!OOB_numeric::isValid($value)) { $flagStore = false; $ari->error->addError("currency_currency", "INVALID_VALUE"); } if (!$date) { $date = new Date(); } //valid and clean Date if (!OOB_validatetext::isValidDate($date)) { $flagStore = false; $ari->error->addError("currency_currency", "INVALID_DATE"); } else { $date = $ari->db->qMagic($date->format("%Y-%m-%d %H:%M:%S")); } $value = OOB_numeric::formatMySQL(trim($value)); if ($flagStore) { $value = $ari->db->qMagic($value); $id = $ari->db->qMagic($this->id); $ari->db->StartTrans(); $sql = "INSERT INTO Currency_Change\n\t\t\t\t ( Date, Value, CurrencyID)\n\t\t\t\t VALUES \n\t\t\t\t ( {$date},{$value},{$id} )\n\t\t\t\t "; //echo $sql; exit; $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); //return false; } else { return true; } } else { return false; } }
# # @copyright Pablo Micolini # @license BSD ######################################## */ global $ari; $handle = $ari->url->getVars(); $ari->t->caching = 0; if (isset($handle[1]) && $handle[1] == 'update') {$ari->t->assign('first',false);} else {$ari->t->assign('first',true);} if (isset($handle[2]) && OOB_validatetext::isClean($handle[2])) {$ari->t->assign('code',$handle[2]);} if (isset($_POST['recover'])) { $ari->t->assign('posted',true); $usuario = oob_user::lostPass($_POST['email']); if ($usuario == false) {$ari->t->assign('first',true); $ari->t->assign('error',true);} else { $from_address = $ari->config->get('email', 'main'); $from_name = $ari->config->get('name', 'main'); $plantilla = $ari->newTemplate(); $plantilla->caching = 0;
/** 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 }
/** * Ordena array * */ function quickSort(&$array, $low, $high, $numeric = false, $key = '', $reverse = false) { if ($low < $high) { $tmpLow = $low; $tmpHigh = $high + 1; $current = $array[$low]; $done = false; while (!$done) { while (++$tmpLow <= $high && OOB_validatetext::isLess($array[$tmpLow], $current, $numeric, $key)) { } while (OOB_validatetext::isGreater($array[--$tmpHigh], $current, $numeric, $key)) { } if ($tmpLow < $tmpHigh) { OOB_validatetext::swap($array, $tmpLow, $tmpHigh); } else { $done = true; } //end if } //end while OOB_validatetext::swap($array, $low, $tmpHigh); OOB_validatetext::quickSort($array, $low, $tmpHigh - 1, $numeric, $key); OOB_validatetext::quickSort($array, $tmpHigh + 1, $high, $numeric, $key); } //end if if ($reverse == ORDER_ASC) { $array = array_reverse($array); } }
/** * Get parents for the given node * */ public function getParents($node, $initialize = true) { global $ari; if (!is_a($node, 'OOB_tree_node')) { return false; } $tree_id = $ari->db->qMagic($this->id); $init = true; if (OOB_validatetext::isBool($initialize)) { $init = $initialize; } $nodeID = $ari->db->qMagic($node->id()); $nodeLeft = $ari->db->qMagic($node->left()); $nodeRight = $ari->db->qMagic($node->right()); # select all nodes where parent.leftvisit<=node.leftvisit and parent.rightvisit>=node.rightvisit # order by parent.leftvisit descending gives bottom up path $sql = "SELECT N.ID, N.ClassName, N.ObjectID, N.Left, N.Right \n\t\t\t\t FROM OOB_Tree_Node N\n\t\t\t\t WHERE N.TreeID = {$tree_id}\n\t\t\t\t AND N.Left <= {$nodeLeft}\n\t\t\t\t AND N.Right >= {$nodeRight}\n\t\t\t\t AND N.ID " . OPERATOR_DISTINCT . " {$nodeID}\t\n\t\t\t\t ORDER BY N.left ASC"; $savem = $ari->db->SetFetchMode(ADODB_FETCH_NUM); $rs = $ari->db->Execute($sql); $ari->db->SetFetchMode($savem); if (!$rs || $rs->EOF) { $result = false; // print "OOB_ROOT"; } else { $result = array(); while (!$rs->EOF) { // print "nodo: " . $rs->fields[0] . ",obj-id: " .$rs->fields[2]."<br>"; $result[] = new OOB_tree_node($rs->fields[0], $rs->fields[1], $rs->fields[2], $rs->fields[3], $rs->fields[4], $this->id, $init); $rs->MoveNext(); } } $rs->Close(); // var_dump ($result); return $result; }
private static function __SQLsearch($field, $comparison, $value, $connector, $type, $join_name) { global $ari; $table = static::getTable(); $operadores = array(); $operadores["eq"] = "="; $operadores["lt"] = "<"; $operadores["gt"] = ">"; $operadores["eqgt"] = ">="; $operadores["ltgt"] = "<="; $operadores["neq"] = "!="; $constraint = ""; //le agregue esto para que funcione la informacion adicional de contactos if ($table == 'contactos_informacion_adicional_control_value' && $field != 'control') { switch ($type) { case 'numeric': $constraint = 'isInt'; break; case 'date': $constraint = 'object-Date'; break; } } else { if (in_array($field, array('id', 'status')) && $type != 'list') { $constraint = 'isInt'; } elseif (in_array($field, array('id', 'status')) && $type == 'list') { $constraint = 'list'; } else { $constraint = static::$public_properties[$field]; } } switch ($constraint) { case 'isNumeric': case 'isFloat': case 'isInt': if (!is_numeric($value) && !is_float($value) && !OOB_validatetext::isInt($value)) { return false; } $operador_inicio = $operadores[$comparison]; $operador_fin = ""; break; case 'object-Date': $value = $ari->db->qMagic(date('Y-m-d', strtotime($value))); // @fixme : formato de fecha, revisar $operador_inicio = $operadores[$comparison]; $operador_fin = ""; break; case 'isArray': return false; // no valido break; case 'isBool': if ($value == true) { $value = 1; } else { $value = 0; } $operador_inicio = " = "; $operador_fin = ""; break; case 'list': // $value = $ari->db->qMagic($value) $operador_inicio = "IN ( "; $operador_fin = ") "; break; default: $value = $ari->db->qMagic('%' . $value . '%'); $operador_inicio = " LIKE "; $operador_fin = ""; break; } return ' ' . $connector . ' ' . $join_name . '.' . $field . ' ' . $operador_inicio . $value . $operador_fin; }
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; } }